QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskControl.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_CONTROL_H
7#define QSK_CONTROL_H
8
9#include "QskItem.h"
10#include "QskSkinnable.h"
11#include "QskAspect.h"
12#include "QskGradient.h"
13#include "QskSizePolicy.h"
14#include "QskPlacementPolicy.h"
15
16#include <qlocale.h>
17#include <memory>
18
19class QskControlPrivate;
20class QskGestureEvent;
21
22class QSK_EXPORT QskControl : public QskItem, public QskSkinnable
23{
24 Q_OBJECT
25
26 Q_PROPERTY( QLocale locale READ locale
27 WRITE setLocale RESET resetLocale NOTIFY localeChanged )
28
29 Q_PROPERTY( QskAspect::Section section READ section
30 WRITE setSection RESET resetSection NOTIFY sectionChanged )
31
32 Q_PROPERTY( bool autoLayoutChildren READ autoLayoutChildren
33 WRITE setAutoLayoutChildren )
34
35 Q_PROPERTY( bool visibleToLayout READ isVisibleToLayout )
36
37 Q_PROPERTY( QskMargins margins READ margins
38 WRITE setMargins RESET resetMargins NOTIFY marginsChanged )
39
40 Q_PROPERTY( QskGradient background READ background
41 WRITE setBackground RESET resetBackground NOTIFY backgroundChanged )
42
43 Q_PROPERTY( QskSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy )
44 Q_PROPERTY( QskPlacementPolicy placementPolicy READ placementPolicy
45 WRITE setPlacementPolicy RESET resetPlacementPolicy )
46
47 Q_PROPERTY( QSizeF minimumSize READ minimumSize WRITE setMinimumSize )
48 Q_PROPERTY( QSizeF maximumSize READ maximumSize WRITE setMaximumSize )
49 Q_PROPERTY( QSizeF preferredSize READ preferredSize WRITE setPreferredSize )
50 Q_PROPERTY( QSizeF sizeConstraint READ sizeConstraint )
51
52 using Inherited = QskItem;
53
54 public:
55 QSK_SUBCONTROLS( Background )
56 QSK_STATES( Disabled, Hovered, Focused )
57
58 QskControl( QQuickItem* parent = nullptr );
59 ~QskControl() override;
60
61 void setMargins( qreal );
62 void setMargins( qreal, qreal, qreal, qreal );
63 void setMargins( const QMarginsF& );
64 void resetMargins();
65 QMarginsF margins() const;
66
67 void setBackground( const QskGradient& );
68 void resetBackground();
69 QskGradient background() const;
70
71 void setBackgroundColor( const QColor& );
72
73 QRectF contentsRect() const;
74 QRectF layoutRect() const;
75
76 virtual QRectF layoutRectForSize( const QSizeF& ) const;
77
78 virtual QRectF focusIndicatorRect() const;
79 virtual QRectF focusIndicatorClipRect() const;
80
81 using QskSkinnable::subControlRect;
82 QRectF subControlRect( QskAspect::Subcontrol ) const;
83 QRectF subControlRect( const QSizeF&, QskAspect::Subcontrol ) const;
84
85 using QskSkinnable::subControlContentsRect;
86 QRectF subControlContentsRect( QskAspect::Subcontrol ) const;
87 QRectF subControlContentsRect( const QSizeF&, QskAspect::Subcontrol ) const;
88
89 void setAutoLayoutChildren( bool );
90 bool autoLayoutChildren() const;
91
92 void setSection( QskAspect::Section );
93 void resetSection();
94 QskAspect::Section section() const override final;
95
96 void setSizePolicy( QskSizePolicy );
97 void setSizePolicy( QskSizePolicy::Policy, QskSizePolicy::Policy );
98 void setSizePolicy( Qt::Orientation, QskSizePolicy::Policy );
99
100 QskSizePolicy sizePolicy() const;
101 QskSizePolicy::Policy sizePolicy( Qt::Orientation ) const;
102
103 // hints for how to be treated by layouts
104 void setLayoutAlignmentHint( Qt::Alignment );
105 Qt::Alignment layoutAlignmentHint() const;
106
107 void setPlacementPolicy( QskPlacementPolicy );
108 void setPlacementPolicy( QskPlacementPolicy::Policy, QskPlacementPolicy::Policy );
109 void setPlacementPolicy( Qsk::Visibilities, QskPlacementPolicy::Policy );
110 void resetPlacementPolicy();
111
112 QskPlacementPolicy placementPolicy() const;
113 QskPlacementPolicy::Policy placementPolicy( Qsk::Visibility ) const;
114
115 QskPlacementPolicy::Policy effectivePlacementPolicy() const;
116
117 bool isVisibleToLayout() const;
118
119 void setMinimumSize( const QSizeF& );
120 void setMinimumSize( qreal width, qreal height );
121 void setMinimumWidth( qreal width );
122 void setMinimumHeight( qreal height );
123
124 void setMaximumSize( const QSizeF& );
125 void setMaximumSize( qreal width, qreal height );
126 void setMaximumWidth( qreal width );
127 void setMaximumHeight( qreal height );
128
129 void setPreferredSize( const QSizeF& );
130 void setPreferredSize( qreal width, qreal height );
131 void setPreferredWidth( qreal width );
132 void setPreferredHeight( qreal height );
133
134 void setFixedSize( const QSizeF& );
135 void setFixedSize( qreal width, qreal height );
136 void setFixedWidth( qreal width );
137 void setFixedHeight( qreal height );
138
139 void setExplicitSizeHint( Qt::SizeHint, const QSizeF& );
140 void setExplicitSizeHint( Qt::SizeHint, qreal width, qreal height );
141 void resetExplicitSizeHint( Qt::SizeHint );
142
143 QSizeF minimumSize() const;
144 QSizeF maximumSize() const;
145 QSizeF preferredSize() const;
146
147 QSizeF explicitSizeHint( Qt::SizeHint ) const;
148 QSizeF implicitSizeHint( Qt::SizeHint, const QSizeF& constraint ) const;
149
150 QSizeF sizeHint() const;
151 qreal heightForWidth( qreal width ) const;
152 qreal widthForHeight( qreal height ) const;
153
154 QSizeF effectiveSizeHint( Qt::SizeHint,
155 const QSizeF& constraint = QSizeF() ) const;
156
157 QSizeF sizeConstraint( Qt::SizeHint, const QSizeF& constraint = QSizeF() ) const;
158 QSizeF sizeConstraint() const;
159
160 QLocale locale() const;
161 void resetLocale();
162
163 QVector< QskAspect::Subcontrol > subControls() const;
164
165 Q_SIGNALS:
166 void backgroundChanged();
167 void sectionChanged( QskAspect::Section );
168 void marginsChanged( const QMarginsF& );
169 void focusIndicatorRectChanged();
170 void localeChanged( const QLocale& );
171
172 public Q_SLOTS:
173 void setLocale( const QLocale& );
174
175 protected:
176 bool event( QEvent* ) override;
177
178 virtual void gestureEvent( QskGestureEvent* );
179
180 void hoverEnterEvent( QHoverEvent* ) override;
181 void hoverLeaveEvent( QHoverEvent* ) override;
182
183 bool childMouseEventFilter( QQuickItem*, QEvent* ) override;
184
185 void itemChange( ItemChange, const ItemChangeData& ) override;
186 void geometryChange( const QRectF&, const QRectF& ) override;
187
188 void initSizePolicy( QskSizePolicy::Policy, QskSizePolicy::Policy );
189
190 // called from updatePolish
191 virtual void updateResources();
192 virtual void updateLayout();
193
194 virtual QSizeF contentsSizeHint( Qt::SizeHint, const QSizeF& ) const;
195 virtual QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const;
196
197 private:
198 void updateInputMethod( Qt::InputMethodQueries ) = delete; // use qskUpdateInputMethod
199
200 QSGNode* updateItemPaintNode( QSGNode* ) override final;
201 void updateItemPolish() override final;
202
203 QskControl* owningItem() const override final;
204
205 private:
206 Q_DECLARE_PRIVATE( QskControl )
207};
208
209inline QSizeF QskControl::sizeConstraint() const
210{
211 return sizeConstraint( Qt::PreferredSize, QSizeF() );
212}
213
214inline QSizeF QskControl::sizeHint() const
215{
216 return effectiveSizeHint( Qt::PreferredSize );
217}
218
219inline QSizeF QskControl::minimumSize() const
220{
221 return effectiveSizeHint( Qt::MinimumSize );
222}
223
224inline QSizeF QskControl::maximumSize() const
225{
226 return effectiveSizeHint( Qt::MaximumSize );
227}
228
229inline QSizeF QskControl::preferredSize() const
230{
231 return effectiveSizeHint( Qt::PreferredSize );
232}
233
234inline QskControl* qskControlCast( QObject* object )
235{
236 return qobject_cast< QskControl* >( object );
237}
238
239inline const QskControl* qskControlCast( const QObject* object )
240{
241 return qobject_cast< const QskControl* >( object );
242}
243
244#endif
Lookup key for a QskSkinHintTable.
Definition QskAspect.h:15
Base class of all controls.
Definition QskControl.h:23
QSizeF maximumSize
Definition QskControl.h:48
QSizeF minimumSize
Definition QskControl.h:47
QSizeF preferredSize
Definition QskControl.h:49
QSizeF sizeHint() const
Definition QskControl.h:214
Global definitions.