QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskSubcontrolLayoutEngine.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_SUBCONTROL_LAYOUT_ENGINE_H
7#define QSK_SUBCONTROL_LAYOUT_ENGINE_H
8
9#include "QskGlobal.h"
10#include "QskLayoutEngine2D.h"
11#include "QskLayoutElement.h"
12#include "QskAspect.h"
13
14#include <qnamespace.h>
15#include <memory>
16
17class QskSkinnable;
18
19/*
20 For the moment this layout is tailored for arranging one text and one graphic
21 horizontally/vertically. Candidate for becoming something more general in the future..
22 */
24{
26
27 public:
29 {
30 public:
32
33 inline const QskSkinnable* skinnable() const { return m_skinnable; }
34 inline QskAspect::Subcontrol subControl() const { return m_subControl; }
35
36 inline void setSizePolicy(
37 QskSizePolicy::Policy horizontalPolicy,
38 QskSizePolicy::Policy verticalPolicy )
39 {
40 setSizePolicy( QskSizePolicy( horizontalPolicy, verticalPolicy ) );
41 }
42
43 inline void setSizePolicy( QskSizePolicy policy ) { m_sizePolicy = policy; }
44 inline QskSizePolicy sizePolicy() const override { return m_sizePolicy; }
45
46 virtual Qt::Alignment alignment() const override;
47
48 inline void setStretch( int stretch ) { m_stretch = stretch; }
49 inline int stretch() const { return m_stretch; }
50
51 inline void setGeometry( const QRectF& rect ) { m_geometry = rect; }
52 inline const QRectF& geometry() const { return m_geometry; }
53
54 void setMaximumSize( const QSizeF& );
55 void setMinimumSize( const QSizeF& );
56 void setPreferredSize( const QSizeF& );
57 void setFixedSize( const QSizeF& );
58
59 void setExplicitSizeHint( Qt::SizeHint, const QSizeF& );
60
61 private:
62 QSizeF sizeHint( Qt::SizeHint, const QSizeF& ) const override;
63 virtual QSizeF implicitSize( const QSizeF& ) const = 0;
64
65 int m_stretch = -1;
66
67 QskSizePolicy m_sizePolicy;
68
69 QSizeF m_explicitSizeHints[3];
70 QRectF m_geometry;
71
72 const QskSkinnable* m_skinnable;
73 const QskAspect::Subcontrol m_subControl;
74 };
75
77 {
78 public:
79 TextElement( const QskSkinnable* skinnable, QskAspect::Subcontrol subControl )
80 : LayoutElement( skinnable, subControl )
81 {
82 }
83
84 inline void setText( const QString& text ) { m_text = text; }
85 inline QString text() const { return m_text; }
86
87 private:
88 QSizeF implicitSize( const QSizeF& ) const override;
89 QString m_text;
90 };
91
93 {
94 public:
95 GraphicElement( const QskSkinnable* skinnable, QskAspect::Subcontrol subControl )
96 : LayoutElement( skinnable, subControl )
97 {
98 }
99
100 inline void setSourceSize( const QSizeF& size ) { m_sourceSize = size; }
101 inline QSizeF sourceSize() const { return m_sourceSize; }
102
103 QSizeF effectiveStrutSize() const;
104
105 private:
106 QSizeF implicitSize( const QSizeF& ) const override;
107
108 QSizeF m_sourceSize;
109 };
110
111 explicit QskSubcontrolLayoutEngine( Qt::Orientation );
113
114 Qt::Orientation orientation() const;
115 bool setOrientation( Qt::Orientation );
116
117 void setSpacing( qreal );
118 qreal spacing() const;
119
120 void addElement( LayoutElement* );
121 LayoutElement* elementAt( int ) const;
122 LayoutElement* element( QskAspect::Subcontrol ) const;
123
124 int count() const override final;
125
126 void setGraphicTextElements( const QskSkinnable*,
127 QskAspect::Subcontrol, const QString& text,
128 QskAspect::Subcontrol, const QSizeF& graphicSize );
129
130 GraphicElement* appendGraphicElement( const QskSkinnable*, QskAspect::Subcontrol, const QSizeF& );
131 TextElement* appendTextElement( const QskSkinnable*, QskAspect::Subcontrol, const QString& );
132
133 void setFixedContent( QskAspect::Subcontrol, Qt::Orientation, Qt::Alignment );
134
135 QRectF subControlRect( QskAspect::Subcontrol ) const;
136
137 private:
138 QskSizePolicy sizePolicyAt( int index ) const override;
139 void layoutItems() override;
140
141 int effectiveCount( Qt::Orientation ) const override;
142
143 void invalidateElementCache() override;
144
145 virtual void setupChain( Qt::Orientation,
146 const QskLayoutChain::Segments&, QskLayoutChain& ) const override;
147
148 class PrivateData;
149 std::unique_ptr< PrivateData > m_data;
150};
151
152#endif
Lookup key for a QskSkinHintTable.
Definition QskAspect.h:15
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
Definition QskAspect.h:104