QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskItem.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_ITEM_H
7#define QSK_ITEM_H
8
9#include "QskGlobal.h"
10#include <qquickitem.h>
11
12class QskItemPrivate;
15
16class QSK_EXPORT QskItem : public QQuickItem
17{
18 Q_OBJECT
19
20 Q_PROPERTY( QRectF geometry READ geometry WRITE setGeometry )
21 Q_PROPERTY( QRectF rect READ rect )
22
23 Q_PROPERTY( bool tabFence READ isTabFence
24 WRITE setTabFence NOTIFY itemFlagsChanged )
25
26 Q_PROPERTY( bool polishOnResize READ polishOnResize
27 WRITE setPolishOnResize NOTIFY itemFlagsChanged FINAL )
28
29 Q_PROPERTY( bool polishOnParentResize READ polishOnParentResize
30 WRITE setPolishOnParentResize NOTIFY itemFlagsChanged FINAL )
31
32 Q_PROPERTY( Qt::FocusPolicy focusPolicy READ focusPolicy
33 WRITE setFocusPolicy NOTIFY focusPolicyChanged )
34
35 Q_PROPERTY( bool wheelEnabled READ isWheelEnabled
36 WRITE setWheelEnabled NOTIFY wheelEnabledChanged )
37
38 Q_PROPERTY( bool visibleToParent READ isVisibleToParent )
39 Q_PROPERTY( bool hasChildItems READ hasChildItems )
40 Q_PROPERTY( bool initiallyPainted READ isInitiallyPainted )
41
42 Q_PROPERTY( UpdateFlags updateFlags READ updateFlags NOTIFY updateFlagsChanged )
43
44 using Inherited = QQuickItem;
45
46 public:
48 {
49 DeferredUpdate = 1 << 0,
50 DeferredPolish = 1 << 1,
51 DeferredLayout = 1 << 2,
52 CleanupOnVisibility = 1 << 3,
53
54 PreferRasterForTextures = 1 << 4,
55
56 DebugForceBackground = 1 << 7
57 };
58
59 Q_ENUM( UpdateFlag )
60 Q_DECLARE_FLAGS( UpdateFlags, UpdateFlag )
61
62 ~QskItem() override;
63
64 const char* className() const;
65
66 bool isVisibleTo( const QQuickItem* ) const;
67 bool isVisibleToParent() const;
68
69 bool hasChildItems() const;
70
71 QRectF rect() const;
72 QSizeF implicitSize() const;
73
74 void setGeometry( qreal x, qreal y, qreal width, qreal height );
75 void setGeometry( const QPointF&, const QSizeF& );
76 QRectF geometry() const;
77
78 using QQuickItem::setPosition;
79 using QQuickItem::setSize;
80
81 void setPosition( qreal x, qreal y );
82 void setSize( qreal width, qreal height );
83
84 void setPolishOnResize( bool );
85 bool polishOnResize() const;
86
87 void setPolishOnParentResize( bool );
88 bool polishOnParentResize() const;
89
90 void setFocusPolicy( Qt::FocusPolicy );
91 Qt::FocusPolicy focusPolicy() const;
92
93 void setTabFence( bool );
94 bool isTabFence() const;
95
96 void setWheelEnabled( bool );
97 bool isWheelEnabled() const;
98
99 void setLayoutMirroring( bool on, bool childrenInherit = false );
100 void resetLayoutMirroring();
101 bool layoutMirroring() const;
102
103 void resetUpdateFlags();
104 UpdateFlags updateFlags() const;
105
106 void setUpdateFlag( UpdateFlag, bool on = true );
107 void resetUpdateFlag( UpdateFlag );
108 bool testUpdateFlag( UpdateFlag ) const;
109
110 void classBegin() override;
111 void componentComplete() override;
112 void releaseResources() override;
113
114 bool isPolishScheduled() const;
115 bool isUpdateNodeScheduled() const;
116 bool isInitiallyPainted() const;
117
118 bool maybeUnresized() const;
119
120 Q_SIGNALS:
121 void wheelEnabledChanged( bool );
122 void focusPolicyChanged( Qt::FocusPolicy );
123
125 void updateFlagsChanged( UpdateFlags );
126
127 public Q_SLOTS:
128 void setGeometry( const QRectF& );
129
130 void show();
131 void hide();
132
133 void setHidden( bool );
134 void setDisabled( bool );
135
136 void resetImplicitSize();
137
138#ifdef Q_MOC_RUN
139 // methods from QQuickItem, we want to be available as string based slots
140 void setVisible( bool );
141 void setEnabled( bool );
142#endif
143
144 protected:
145 QskItem( QskItemPrivate&, QQuickItem* = nullptr );
146
147 bool event( QEvent* ) override;
148
149 virtual void changeEvent( QEvent* );
150 virtual void geometryChangeEvent( QskGeometryChangeEvent* );
151 virtual void windowChangeEvent( QskWindowChangeEvent* );
152
153 void mouseUngrabEvent() override;
154 void touchUngrabEvent() override;
155
156#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
157 void windowDeactivateEvent() override;
158#endif
159
160 void itemChange( ItemChange, const ItemChangeData& ) override;
161#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
162 void geometryChange( const QRectF&, const QRectF& ) override;
163#else
164 // using geometryChange also for Qt5
165 void geometryChanged( const QRectF&, const QRectF& ) override final;
166 virtual void geometryChange( const QRectF&, const QRectF& );
167#endif
168
169 virtual void aboutToShow(); // called in updatePolish
170
171 private:
172 // don't use boundingRect - it seems to be deprecated
173 QRectF boundingRect() const override final { return rect(); }
174
175 /*
176 childrenRect()/childrenRectChanged does not make much sense
177 in a system, where the parent is responsible for laying out
178 its children.
179 */
180 void childrenRect() = delete;
181
182 void setActiveFocusOnTab( bool ) = delete; // use setFocusPolicy
183 void applyUpdateFlag( UpdateFlag, bool on );
184
185 QSGNode* updatePaintNode( QSGNode*, UpdatePaintNodeData* ) override final;
186 virtual QSGNode* updateItemPaintNode( QSGNode* );
187
188 void updatePolish() override final;
189 virtual void updateItemPolish();
190
191 Q_DECLARE_PRIVATE( QskItem )
192};
193
194inline bool QskItem::hasChildItems() const
195{
196 return !childItems().isEmpty();
197}
198
199inline void QskItem::setGeometry( const QPointF& pos, const QSizeF& size )
200{
201 setGeometry( pos.x(), pos.y(), size.width(), size.height() );
202}
203
204inline void QskItem::setGeometry( const QRectF& rect )
205{
206 setGeometry( rect.x(), rect.y(), rect.width(), rect.height() );
207}
208
209inline void QskItem::setPosition( qreal x, qreal y )
210{
211 QQuickItem::setPosition( QPointF( x, y ) );
212}
213
214inline void QskItem::setSize( qreal width, qreal height )
215{
216 QQuickItem::setSize( QSizeF( width, height ) );
217}
218
219inline QSizeF QskItem::implicitSize() const
220{
221 return QSizeF( implicitWidth(), implicitHeight() );
222}
223
224Q_DECLARE_OPERATORS_FOR_FLAGS( QskItem::UpdateFlags )
225Q_DECLARE_METATYPE( QskItem::UpdateFlags )
226
227#endif
QSizeF implicitSize() const
Definition QskItem.h:219
UpdateFlag
Definition QskItem.h:48
void itemFlagsChanged()
void updateFlagsChanged(UpdateFlags)
void setGeometry(qreal x, qreal y, qreal width, qreal height)
Definition QskItem.cpp:330