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_PRIVATE_EXPORT QQuickControlPrivate : public QQuickItemPrivate, public QQuickItemChangeListener
39#if QT_CONFIG(accessibility)
40 , public QAccessible::ActivationObserver
41#endif
42{
43public:
44 Q_DECLARE_PUBLIC(QQuickControl)
45
46 QQuickControlPrivate();
47 ~QQuickControlPrivate();
48
49 static QQuickControlPrivate *get(QQuickControl *control)
50 {
51 return control->d_func();
52 }
53
54 void init();
55
56#if QT_CONFIG(quicktemplates2_multitouch)
57 virtual bool acceptTouch(const QTouchEvent::TouchPoint &point);
58#endif
59 virtual bool handlePress(const QPointF &point, ulong timestamp);
60 virtual bool handleMove(const QPointF &point, ulong timestamp);
61 virtual bool handleRelease(const QPointF &point, ulong timestamp);
62 virtual void handleUngrab();
63
64 void mirrorChange() override;
65
66 inline QMarginsF getPadding() const { return QMarginsF(getLeftPadding(), getTopPadding(), getRightPadding(), getBottomPadding()); }
67 inline qreal getTopPadding() const { return extra.isAllocated() && extra->hasTopPadding ? extra->topPadding : getVerticalPadding(); }
68 inline qreal getLeftPadding() const { return extra.isAllocated() && extra->hasLeftPadding ? extra->leftPadding : getHorizontalPadding(); }
69 inline qreal getRightPadding() const { return extra.isAllocated() && extra->hasRightPadding ? extra->rightPadding : getHorizontalPadding(); }
70 inline qreal getBottomPadding() const { return extra.isAllocated() && extra->hasBottomPadding ? extra->bottomPadding : getVerticalPadding(); }
71 inline qreal getHorizontalPadding() const { return hasHorizontalPadding ? horizontalPadding : padding; }
72 inline qreal getVerticalPadding() const { return hasVerticalPadding ? verticalPadding : padding; }
73
74 void setTopPadding(qreal value, bool reset = false);
75 void setLeftPadding(qreal value, bool reset = false);
76 void setRightPadding(qreal value, bool reset = false);
77 void setBottomPadding(qreal value, bool reset = false);
78 void setHorizontalPadding(qreal value, bool reset = false);
79 void setVerticalPadding(qreal value, bool reset = false);
80
81 inline QMarginsF getInset() const { return QMarginsF(getLeftInset(), getTopInset(), getRightInset(), getBottomInset()); }
82 inline qreal getTopInset() const { return extra.isAllocated() ? extra->topInset : 0; }
83 inline qreal getLeftInset() const { return extra.isAllocated() ? extra->leftInset : 0; }
84 inline qreal getRightInset() const { return extra.isAllocated() ? extra->rightInset : 0; }
85 inline qreal getBottomInset() const { return extra.isAllocated() ? extra->bottomInset : 0; }
86
87 void setTopInset(qreal value, bool reset = false);
88 void setLeftInset(qreal value, bool reset = false);
89 void setRightInset(qreal value, bool reset = false);
90 void setBottomInset(qreal value, bool reset = false);
91
92 virtual void resizeBackground();
93 virtual void resizeContent();
94
95 virtual QQuickItem *getContentItem();
96 void setContentItem_helper(QQuickItem *item, bool notify = true);
97
98#if QT_CONFIG(accessibility)
99 void accessibilityActiveChanged(bool active) override;
100 QAccessible::Role accessibleRole() const override;
101 static QQuickAccessibleAttached *accessibleAttached(const QObject *object);
102#endif
103
104 virtual void resolveFont();
105 void inheritFont(const QFont &font);
106 void updateFont(const QFont &font);
107 static void updateFontRecur(QQuickItem *item, const QFont &font);
108 inline void setFont_helper(const QFont &font) {
109 if (resolvedFont.resolveMask() == font.resolveMask() && resolvedFont == font)
110 return;
111 updateFont(font);
112 }
113 static QFont parentFont(const QQuickItem *item);
114
115 void updateLocale(const QLocale &l, bool e);
116 static void updateLocaleRecur(QQuickItem *item, const QLocale &l);
117 static QLocale calcLocale(const QQuickItem *item);
118
119#if QT_CONFIG(quicktemplates2_hover)
120 void updateHoverEnabled(bool enabled, bool xplicit);
121 static void updateHoverEnabledRecur(QQuickItem *item, bool enabled);
122 static bool calcHoverEnabled(const QQuickItem *item);
123#endif
124
125 static void warnIfCustomizationNotSupported(QObject *control, QQuickItem *item, const QString &propertyName);
126
127 virtual void cancelContentItem();
128 virtual void executeContentItem(bool complete = false);
129
130 virtual void cancelBackground();
131 virtual void executeBackground(bool complete = false);
132
133 enum class UnhideVisibility {
134 Show,
135 Hide
136 };
137
138 static void hideOldItem(QQuickItem *item);
139 static void unhideOldItem(QQuickControl *control, QQuickItem *item,
140 UnhideVisibility visibility = UnhideVisibility::Show);
141
142 void updateBaselineOffset();
143
144 static const ChangeTypes ImplicitSizeChanges;
145
146 void addImplicitSizeListener(QQuickItem *item, ChangeTypes changes = ImplicitSizeChanges);
147 void removeImplicitSizeListener(QQuickItem *item, ChangeTypes changes = ImplicitSizeChanges);
148
149 static void addImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes = ImplicitSizeChanges);
150 static void removeImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes = ImplicitSizeChanges);
151
152 void itemImplicitWidthChanged(QQuickItem *item) override;
153 void itemImplicitHeightChanged(QQuickItem *item) override;
154 void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) override;
155 void itemDestroyed(QQuickItem *item) override;
156 void itemFocusChanged(QQuickItem *item, Qt::FocusReason reason) override;
157
158 virtual qreal getContentWidth() const;
159 virtual qreal getContentHeight() const;
160
161 void updateImplicitContentWidth();
162 void updateImplicitContentHeight();
163 void updateImplicitContentSize();
164
165 QPalette defaultPalette() const override;
166
167 struct ExtraData {
168 bool hasTopPadding = false;
169 bool hasLeftPadding = false;
170 bool hasRightPadding = false;
171 bool hasBottomPadding = false;
172 bool hasBaselineOffset = false;
173 bool hasTopInset = false;
174 bool hasLeftInset = false;
175 bool hasRightInset = false;
176 bool hasBottomInset = false;
177 bool hasBackgroundWidth = false;
178 bool hasBackgroundHeight = false;
179 qreal topPadding = 0;
180 qreal leftPadding = 0;
181 qreal rightPadding = 0;
182 qreal bottomPadding = 0;
183 qreal topInset = 0;
184 qreal leftInset = 0;
185 qreal rightInset = 0;
186 qreal bottomInset = 0;
187 QFont requestedFont;
188 };
189 QLazilyAllocated<ExtraData> extra;
190
191 bool hasHorizontalPadding = false;
192 bool hasVerticalPadding = false;
193 bool hasLocale = false;
194 bool wheelEnabled = false;
195#if QT_CONFIG(quicktemplates2_hover)
196 bool hovered = false;
197 bool explicitHoverEnabled = false;
198#endif
199 bool resizingBackground = false;
200 int touchId = -1;
201 qreal padding = 0;
202 qreal horizontalPadding = 0;
203 qreal verticalPadding = 0;
204 qreal implicitContentWidth = 0;
205 qreal implicitContentHeight = 0;
206 qreal spacing = 0;
207 QLocale locale;
208 QFont resolvedFont;
209 Qt::FocusPolicy focusPolicy = Qt::NoFocus;
210 Qt::FocusReason focusReason = Qt::OtherFocusReason;
211 QQuickDeferredPointer<QQuickItem> background;
212 QQuickDeferredPointer<QQuickItem> contentItem;
213};
214
215QT_END_NAMESPACE
216
217#endif // QQUICKCONTROL_P_P_H
218

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