1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKCONTROL_P_P_H
5#define QQUICKCONTROL_P_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuickTemplates2/private/qquickcontrol_p.h>
19#include <QtQuickTemplates2/private/qquickdeferredpointer_p_p.h>
20#include <QtQuickTemplates2/private/qquicktheme_p.h>
21
22#include <QtQuick/private/qquickitem_p.h>
23#include <QtQuick/private/qquickitemchangelistener_p.h>
24#include <QtQml/private/qlazilyallocated_p.h>
25
26#if QT_CONFIG(accessibility)
27#include <QtGui/qaccessible.h>
28#endif
29
30#include <QtCore/qloggingcategory.h>
31
32QT_BEGIN_NAMESPACE
33
34Q_DECLARE_LOGGING_CATEGORY(lcItemManagement)
35
36class QQuickAccessibleAttached;
37
38class Q_QUICKTEMPLATES2_EXPORT QQuickControlPrivate : public QQuickItemPrivate,
39 public QSafeQuickItemChangeListener<QQuickControlPrivate>
40#if QT_CONFIG(accessibility)
41 , public QAccessible::ActivationObserver
42#endif
43{
44public:
45 Q_DECLARE_PUBLIC(QQuickControl)
46
47 QQuickControlPrivate();
48 ~QQuickControlPrivate();
49
50 static QQuickControlPrivate *get(QQuickControl *control)
51 {
52 return control->d_func();
53 }
54
55 void init();
56
57#if QT_CONFIG(quicktemplates2_multitouch)
58 virtual bool acceptTouch(const QTouchEvent::TouchPoint &point);
59#endif
60 virtual bool handlePress(const QPointF &point, ulong timestamp);
61 virtual bool handleMove(const QPointF &point, ulong timestamp);
62 virtual bool handleRelease(const QPointF &point, ulong timestamp);
63 virtual void handleUngrab();
64
65 void mirrorChange() override;
66
67 inline QMarginsF getPadding() const { return QMarginsF(getLeftPadding(), getTopPadding(), getRightPadding(), getBottomPadding()); }
68 inline qreal getTopPadding() const { return extra.isAllocated() && extra->hasTopPadding ? extra->topPadding : getVerticalPadding(); }
69 inline qreal getLeftPadding() const { return extra.isAllocated() && extra->hasLeftPadding ? extra->leftPadding : getHorizontalPadding(); }
70 inline qreal getRightPadding() const { return extra.isAllocated() && extra->hasRightPadding ? extra->rightPadding : getHorizontalPadding(); }
71 inline qreal getBottomPadding() const { return extra.isAllocated() && extra->hasBottomPadding ? extra->bottomPadding : getVerticalPadding(); }
72 inline qreal getHorizontalPadding() const { return hasHorizontalPadding ? horizontalPadding : padding; }
73 inline qreal getVerticalPadding() const { return hasVerticalPadding ? verticalPadding : padding; }
74
75 void setTopPadding(qreal value, bool reset = false);
76 void setLeftPadding(qreal value, bool reset = false);
77 void setRightPadding(qreal value, bool reset = false);
78 void setBottomPadding(qreal value, bool reset = false);
79 void setHorizontalPadding(qreal value, bool reset = false);
80 void setVerticalPadding(qreal value, bool reset = false);
81
82 inline QMarginsF getInset() const { return QMarginsF(getLeftInset(), getTopInset(), getRightInset(), getBottomInset()); }
83 inline qreal getTopInset() const { return extra.isAllocated() ? extra->topInset : 0; }
84 inline qreal getLeftInset() const { return extra.isAllocated() ? extra->leftInset : 0; }
85 inline qreal getRightInset() const { return extra.isAllocated() ? extra->rightInset : 0; }
86 inline qreal getBottomInset() const { return extra.isAllocated() ? extra->bottomInset : 0; }
87
88 void setTopInset(qreal value, bool reset = false);
89 void setLeftInset(qreal value, bool reset = false);
90 void setRightInset(qreal value, bool reset = false);
91 void setBottomInset(qreal value, bool reset = false);
92
93 virtual void resizeBackground();
94 virtual void resizeContent();
95
96 virtual QQuickItem *getContentItem();
97 void setContentItem_helper(QQuickItem *item, bool notify = true);
98
99#if QT_CONFIG(accessibility)
100 void accessibilityActiveChanged(bool active) override;
101 QAccessible::Role accessibleRole() const override;
102 static QQuickAccessibleAttached *accessibleAttached(const QObject *object);
103#endif
104
105 virtual void resolveFont();
106 void inheritFont(const QFont &font);
107 void updateFont(const QFont &font);
108 static void updateFontRecur(QQuickItem *item, const QFont &font);
109 inline void setFont_helper(const QFont &font) {
110 if (resolvedFont.resolveMask() == font.resolveMask() && resolvedFont == font)
111 return;
112 updateFont(font);
113 }
114 static QFont parentFont(const QQuickItem *item);
115
116 void updateLocale(const QLocale &l, bool e);
117 static void updateLocaleRecur(QQuickItem *item, const QLocale &l);
118 static QLocale calcLocale(const QQuickItem *item);
119
120#if QT_CONFIG(quicktemplates2_hover)
121 void updateHoverEnabled(bool enabled, bool xplicit);
122 static void updateHoverEnabledRecur(QQuickItem *item, bool enabled);
123 static bool calcHoverEnabled(const QQuickItem *item);
124#endif
125
126 static void warnIfCustomizationNotSupported(QObject *control, QQuickItem *item, const QString &propertyName);
127
128 virtual void cancelContentItem();
129 virtual void executeContentItem(bool complete = false);
130
131 virtual void cancelBackground();
132 virtual void executeBackground(bool complete = false);
133
134 enum class UnhideVisibility {
135 Show,
136 Hide
137 };
138
139 static void hideOldItem(QQuickItem *item);
140 static void unhideOldItem(QQuickControl *control, QQuickItem *item,
141 UnhideVisibility visibility = UnhideVisibility::Show);
142
143 void updateBaselineOffset();
144
145 static const ChangeTypes ImplicitSizeChanges;
146
147 void addImplicitSizeListener(QQuickItem *item, ChangeTypes changes = ImplicitSizeChanges);
148 void removeImplicitSizeListener(QQuickItem *item, ChangeTypes changes = ImplicitSizeChanges);
149
150 static void addImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes = ImplicitSizeChanges);
151 static void removeImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes = ImplicitSizeChanges);
152
153 void itemImplicitWidthChanged(QQuickItem *item) override;
154 void itemImplicitHeightChanged(QQuickItem *item) override;
155 void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) override;
156 void itemDestroyed(QQuickItem *item) override;
157 void itemFocusChanged(QQuickItem *item, Qt::FocusReason reason) override;
158
159 bool setLastFocusChangeReason(Qt::FocusReason) override;
160
161 virtual qreal getContentWidth() const;
162 virtual qreal getContentHeight() const;
163
164 void updateImplicitContentWidth();
165 void updateImplicitContentHeight();
166 void updateImplicitContentSize();
167
168 QPalette defaultPalette() const override;
169
170 struct ExtraData {
171 bool hasTopPadding = false;
172 bool hasLeftPadding = false;
173 bool hasRightPadding = false;
174 bool hasBottomPadding = false;
175 bool hasBaselineOffset = false;
176 bool hasTopInset = false;
177 bool hasLeftInset = false;
178 bool hasRightInset = false;
179 bool hasBottomInset = false;
180 bool hasBackgroundWidth = false;
181 bool hasBackgroundHeight = false;
182 qreal topPadding = 0;
183 qreal leftPadding = 0;
184 qreal rightPadding = 0;
185 qreal bottomPadding = 0;
186 qreal topInset = 0;
187 qreal leftInset = 0;
188 qreal rightInset = 0;
189 qreal bottomInset = 0;
190 QFont requestedFont;
191 };
192 QLazilyAllocated<ExtraData> extra;
193
194 bool hasHorizontalPadding = false;
195 bool hasVerticalPadding = false;
196 bool hasLocale = false;
197 bool wheelEnabled = false;
198#if QT_CONFIG(quicktemplates2_hover)
199 bool hovered = false;
200 bool explicitHoverEnabled = false;
201#endif
202 bool resizingBackground = false;
203 int touchId = -1;
204 qreal padding = 0;
205 qreal horizontalPadding = 0;
206 qreal verticalPadding = 0;
207 qreal implicitContentWidth = 0;
208 qreal implicitContentHeight = 0;
209 qreal spacing = 0;
210 QLocale locale;
211 QFont resolvedFont;
212 QQuickDeferredPointer<QQuickItem> background;
213 QQuickDeferredPointer<QQuickItem> contentItem;
214};
215
216QT_END_NAMESPACE
217
218#endif // QQUICKCONTROL_P_P_H
219

source code of qtdeclarative/src/quicktemplates/qquickcontrol_p_p.h