1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#ifndef QQUICKCONTROL_P_P_H
38#define QQUICKCONTROL_P_P_H
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49//
50
51#include <QtQuickTemplates2/private/qquickcontrol_p.h>
52#include <QtQuickTemplates2/private/qquickdeferredpointer_p_p.h>
53#include <QtQuickTemplates2/private/qquicktheme_p.h>
54
55#include <QtQuick/private/qquickitem_p.h>
56#include <QtQuick/private/qquickitemchangelistener_p.h>
57#include <QtQml/private/qlazilyallocated_p.h>
58
59#if QT_CONFIG(accessibility)
60#include <QtGui/qaccessible.h>
61#endif
62
63QT_BEGIN_NAMESPACE
64
65class QQuickAccessibleAttached;
66
67class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickControlPrivate : public QQuickItemPrivate, public QQuickItemChangeListener
68#if QT_CONFIG(accessibility)
69 , public QAccessible::ActivationObserver
70#endif
71{
72 Q_DECLARE_PUBLIC(QQuickControl)
73
74public:
75 QQuickControlPrivate();
76 ~QQuickControlPrivate();
77
78 static QQuickControlPrivate *get(QQuickControl *control)
79 {
80 return control->d_func();
81 }
82
83 void init();
84
85#if QT_CONFIG(quicktemplates2_multitouch)
86 virtual bool acceptTouch(const QTouchEvent::TouchPoint &point);
87#endif
88 virtual void handlePress(const QPointF &point);
89 virtual void handleMove(const QPointF &point);
90 virtual void handleRelease(const QPointF &point);
91 virtual void handleUngrab();
92
93 void mirrorChange() override;
94
95 inline QMarginsF getPadding() const { return QMarginsF(getLeftPadding(), getTopPadding(), getRightPadding(), getBottomPadding()); }
96 inline qreal getTopPadding() const { return extra.isAllocated() && extra->hasTopPadding ? extra->topPadding : getVerticalPadding(); }
97 inline qreal getLeftPadding() const { return extra.isAllocated() && extra->hasLeftPadding ? extra->leftPadding : getHorizontalPadding(); }
98 inline qreal getRightPadding() const { return extra.isAllocated() && extra->hasRightPadding ? extra->rightPadding : getHorizontalPadding(); }
99 inline qreal getBottomPadding() const { return extra.isAllocated() && extra->hasBottomPadding ? extra->bottomPadding : getVerticalPadding(); }
100 inline qreal getHorizontalPadding() const { return hasHorizontalPadding ? horizontalPadding : padding; }
101 inline qreal getVerticalPadding() const { return hasVerticalPadding ? verticalPadding : padding; }
102
103 void setTopPadding(qreal value, bool reset = false);
104 void setLeftPadding(qreal value, bool reset = false);
105 void setRightPadding(qreal value, bool reset = false);
106 void setBottomPadding(qreal value, bool reset = false);
107 void setHorizontalPadding(qreal value, bool reset = false);
108 void setVerticalPadding(qreal value, bool reset = false);
109
110 inline QMarginsF getInset() const { return QMarginsF(getLeftInset(), getTopInset(), getRightInset(), getBottomInset()); }
111 inline qreal getTopInset() const { return extra.isAllocated() ? extra->topInset : 0; }
112 inline qreal getLeftInset() const { return extra.isAllocated() ? extra->leftInset : 0; }
113 inline qreal getRightInset() const { return extra.isAllocated() ? extra->rightInset : 0; }
114 inline qreal getBottomInset() const { return extra.isAllocated() ? extra->bottomInset : 0; }
115
116 void setTopInset(qreal value, bool reset = false);
117 void setLeftInset(qreal value, bool reset = false);
118 void setRightInset(qreal value, bool reset = false);
119 void setBottomInset(qreal value, bool reset = false);
120
121 void resizeBackground();
122 virtual void resizeContent();
123
124 virtual QQuickItem *getContentItem();
125 void setContentItem_helper(QQuickItem *item, bool notify = true);
126
127#if QT_CONFIG(accessibility)
128 void accessibilityActiveChanged(bool active) override;
129 QAccessible::Role accessibleRole() const override;
130 static QQuickAccessibleAttached *accessibleAttached(const QObject *object);
131#endif
132
133 virtual void resolveFont();
134 void inheritFont(const QFont &font);
135 void updateFont(const QFont &font);
136 static void updateFontRecur(QQuickItem *item, const QFont &font);
137 inline void setFont_helper(const QFont &font) {
138 if (resolvedFont.resolve() == font.resolve() && resolvedFont == font)
139 return;
140 updateFont(font);
141 }
142 static QFont parentFont(const QQuickItem *item);
143
144 virtual void resolvePalette();
145 void inheritPalette(const QPalette &palette);
146 void updatePalette(const QPalette &palette);
147 static void updatePaletteRecur(QQuickItem *item, const QPalette &palette);
148 inline void setPalette_helper(const QPalette &palette) {
149 if (resolvedPalette.resolve() == palette.resolve() && resolvedPalette == palette)
150 return;
151 updatePalette(palette);
152 }
153 static QPalette parentPalette(const QQuickItem *item);
154
155 void updateLocale(const QLocale &l, bool e);
156 static void updateLocaleRecur(QQuickItem *item, const QLocale &l);
157 static QLocale calcLocale(const QQuickItem *item);
158
159#if QT_CONFIG(quicktemplates2_hover)
160 void updateHoverEnabled(bool enabled, bool xplicit);
161 static void updateHoverEnabledRecur(QQuickItem *item, bool enabled);
162 static bool calcHoverEnabled(const QQuickItem *item);
163#endif
164
165 virtual void cancelContentItem();
166 virtual void executeContentItem(bool complete = false);
167
168 virtual void cancelBackground();
169 virtual void executeBackground(bool complete = false);
170
171 void updateBaselineOffset();
172
173 static const ChangeTypes ImplicitSizeChanges;
174
175 void addImplicitSizeListener(QQuickItem *item, ChangeTypes changes = ImplicitSizeChanges);
176 void removeImplicitSizeListener(QQuickItem *item, ChangeTypes changes = ImplicitSizeChanges);
177
178 static void addImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes = ImplicitSizeChanges);
179 static void removeImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes = ImplicitSizeChanges);
180
181 void itemImplicitWidthChanged(QQuickItem *item) override;
182 void itemImplicitHeightChanged(QQuickItem *item) override;
183 void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) override;
184 void itemDestroyed(QQuickItem *item) override;
185
186 virtual qreal getContentWidth() const;
187 virtual qreal getContentHeight() const;
188
189 void updateImplicitContentWidth();
190 void updateImplicitContentHeight();
191 void updateImplicitContentSize();
192
193 struct ExtraData {
194 bool hasTopPadding = false;
195 bool hasLeftPadding = false;
196 bool hasRightPadding = false;
197 bool hasBottomPadding = false;
198 bool hasBaselineOffset = false;
199 bool hasTopInset = false;
200 bool hasLeftInset = false;
201 bool hasRightInset = false;
202 bool hasBottomInset = false;
203 bool hasBackgroundWidth = false;
204 bool hasBackgroundHeight = false;
205 qreal topPadding = 0;
206 qreal leftPadding = 0;
207 qreal rightPadding = 0;
208 qreal bottomPadding = 0;
209 qreal topInset = 0;
210 qreal leftInset = 0;
211 qreal rightInset = 0;
212 qreal bottomInset = 0;
213 QFont requestedFont;
214 QPalette requestedPalette;
215 };
216 QLazilyAllocated<ExtraData> extra;
217
218 bool hasHorizontalPadding = false;
219 bool hasVerticalPadding = false;
220 bool hasLocale = false;
221 bool wheelEnabled = false;
222#if QT_CONFIG(quicktemplates2_hover)
223 bool hovered = false;
224 bool explicitHoverEnabled = false;
225#endif
226 bool resizingBackground = false;
227 int touchId = -1;
228 qreal padding = 0;
229 qreal horizontalPadding = 0;
230 qreal verticalPadding = 0;
231 qreal implicitContentWidth = 0;
232 qreal implicitContentHeight = 0;
233 qreal spacing = 0;
234 QLocale locale;
235 QFont resolvedFont;
236 QPalette resolvedPalette;
237 Qt::FocusPolicy focusPolicy = Qt::NoFocus;
238 Qt::FocusReason focusReason = Qt::OtherFocusReason;
239 QQuickDeferredPointer<QQuickItem> background;
240 QQuickDeferredPointer<QQuickItem> contentItem;
241};
242
243QT_END_NAMESPACE
244
245#endif // QQUICKCONTROL_P_P_H
246