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 
63 #include <QtCore/qloggingcategory.h>
64 
65 QT_BEGIN_NAMESPACE
66 
Q_DECLARE_LOGGING_CATEGORY(lcItemManagement)67 Q_DECLARE_LOGGING_CATEGORY(lcItemManagement)
68 
69 class QQuickAccessibleAttached;
70 
71 class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickControlPrivate : public QQuickItemPrivate, public QQuickItemChangeListener
72 #if QT_CONFIG(accessibility)
73     , public QAccessible::ActivationObserver
74 #endif
75 {
76     Q_DECLARE_PUBLIC(QQuickControl)
77 
78 public:
79     QQuickControlPrivate();
80     ~QQuickControlPrivate();
81 
82     static QQuickControlPrivate *get(QQuickControl *control)
83     {
84         return control->d_func();
85     }
86 
87     void init();
88 
89 #if QT_CONFIG(quicktemplates2_multitouch)
90     virtual bool acceptTouch(const QTouchEvent::TouchPoint &point);
91 #endif
92     virtual void handlePress(const QPointF &point);
93     virtual void handleMove(const QPointF &point);
94     virtual void handleRelease(const QPointF &point);
95     virtual void handleUngrab();
96 
97     void mirrorChange() override;
98 
99     inline QMarginsF getPadding() const { return QMarginsF(getLeftPadding(), getTopPadding(), getRightPadding(), getBottomPadding()); }
100     inline qreal getTopPadding() const { return extra.isAllocated() && extra->hasTopPadding ? extra->topPadding : getVerticalPadding(); }
101     inline qreal getLeftPadding() const { return extra.isAllocated() && extra->hasLeftPadding ? extra->leftPadding : getHorizontalPadding(); }
102     inline qreal getRightPadding() const { return extra.isAllocated() && extra->hasRightPadding ? extra->rightPadding : getHorizontalPadding(); }
103     inline qreal getBottomPadding() const { return extra.isAllocated() && extra->hasBottomPadding ? extra->bottomPadding : getVerticalPadding(); }
104     inline qreal getHorizontalPadding() const { return hasHorizontalPadding ? horizontalPadding : padding; }
105     inline qreal getVerticalPadding() const { return hasVerticalPadding ? verticalPadding : padding; }
106 
107     void setTopPadding(qreal value, bool reset = false);
108     void setLeftPadding(qreal value, bool reset = false);
109     void setRightPadding(qreal value, bool reset = false);
110     void setBottomPadding(qreal value, bool reset = false);
111     void setHorizontalPadding(qreal value, bool reset = false);
112     void setVerticalPadding(qreal value, bool reset = false);
113 
114     inline QMarginsF getInset() const { return QMarginsF(getLeftInset(), getTopInset(), getRightInset(), getBottomInset()); }
115     inline qreal getTopInset() const { return extra.isAllocated() ? extra->topInset : 0; }
116     inline qreal getLeftInset() const { return extra.isAllocated() ? extra->leftInset : 0; }
117     inline qreal getRightInset() const { return extra.isAllocated() ? extra->rightInset : 0; }
118     inline qreal getBottomInset() const { return extra.isAllocated() ? extra->bottomInset : 0; }
119 
120     void setTopInset(qreal value, bool reset = false);
121     void setLeftInset(qreal value, bool reset = false);
122     void setRightInset(qreal value, bool reset = false);
123     void setBottomInset(qreal value, bool reset = false);
124 
125     void resizeBackground();
126     virtual void resizeContent();
127 
128     virtual QQuickItem *getContentItem();
129     void setContentItem_helper(QQuickItem *item, bool notify = true);
130 
131 #if QT_CONFIG(accessibility)
132     void accessibilityActiveChanged(bool active) override;
133     QAccessible::Role accessibleRole() const override;
134     static QQuickAccessibleAttached *accessibleAttached(const QObject *object);
135 #endif
136 
137     virtual void resolveFont();
138     void inheritFont(const QFont &font);
139     void updateFont(const QFont &font);
140     static void updateFontRecur(QQuickItem *item, const QFont &font);
141     inline void setFont_helper(const QFont &font) {
142         if (resolvedFont.resolve() == font.resolve() && resolvedFont == font)
143             return;
144         updateFont(font);
145     }
146     static QFont parentFont(const QQuickItem *item);
147 
148     virtual void resolvePalette();
149     void inheritPalette(const QPalette &palette);
150     void updatePalette(const QPalette &palette);
151     static void updatePaletteRecur(QQuickItem *item, const QPalette &palette);
152     inline void setPalette_helper(const QPalette &palette) {
153         if (resolvedPalette.resolve() == palette.resolve() && resolvedPalette == palette)
154             return;
155         updatePalette(palette);
156     }
157     static QPalette parentPalette(const QQuickItem *item);
158 
159     void updateLocale(const QLocale &l, bool e);
160     static void updateLocaleRecur(QQuickItem *item, const QLocale &l);
161     static QLocale calcLocale(const QQuickItem *item);
162 
163 #if QT_CONFIG(quicktemplates2_hover)
164     void updateHoverEnabled(bool enabled, bool xplicit);
165     static void updateHoverEnabledRecur(QQuickItem *item, bool enabled);
166     static bool calcHoverEnabled(const QQuickItem *item);
167 #endif
168 
169     virtual void cancelContentItem();
170     virtual void executeContentItem(bool complete = false);
171 
172     virtual void cancelBackground();
173     virtual void executeBackground(bool complete = false);
174 
175     static void hideOldItem(QQuickItem *item);
176 
177     void updateBaselineOffset();
178 
179     static const ChangeTypes ImplicitSizeChanges;
180 
181     void addImplicitSizeListener(QQuickItem *item, ChangeTypes changes = ImplicitSizeChanges);
182     void removeImplicitSizeListener(QQuickItem *item, ChangeTypes changes = ImplicitSizeChanges);
183 
184     static void addImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes = ImplicitSizeChanges);
185     static void removeImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes = ImplicitSizeChanges);
186 
187     void itemImplicitWidthChanged(QQuickItem *item) override;
188     void itemImplicitHeightChanged(QQuickItem *item) override;
189     void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) override;
190     void itemDestroyed(QQuickItem *item) override;
191 
192     virtual qreal getContentWidth() const;
193     virtual qreal getContentHeight() const;
194 
195     void updateImplicitContentWidth();
196     void updateImplicitContentHeight();
197     void updateImplicitContentSize();
198 
199     struct ExtraData {
200         bool hasTopPadding = false;
201         bool hasLeftPadding = false;
202         bool hasRightPadding = false;
203         bool hasBottomPadding = false;
204         bool hasBaselineOffset = false;
205         bool hasTopInset = false;
206         bool hasLeftInset = false;
207         bool hasRightInset = false;
208         bool hasBottomInset = false;
209         bool hasBackgroundWidth = false;
210         bool hasBackgroundHeight = false;
211         qreal topPadding = 0;
212         qreal leftPadding = 0;
213         qreal rightPadding = 0;
214         qreal bottomPadding = 0;
215         qreal topInset = 0;
216         qreal leftInset = 0;
217         qreal rightInset = 0;
218         qreal bottomInset = 0;
219         QFont requestedFont;
220         QPalette requestedPalette;
221     };
222     QLazilyAllocated<ExtraData> extra;
223 
224     bool hasHorizontalPadding = false;
225     bool hasVerticalPadding = false;
226     bool hasLocale = false;
227     bool wheelEnabled = false;
228 #if QT_CONFIG(quicktemplates2_hover)
229     bool hovered = false;
230     bool explicitHoverEnabled = false;
231 #endif
232     bool resizingBackground = false;
233     bool pressWasTouch = false;
234     int touchId = -1;
235     QPointF previousPressPos;
236     qreal padding = 0;
237     qreal horizontalPadding = 0;
238     qreal verticalPadding = 0;
239     qreal implicitContentWidth = 0;
240     qreal implicitContentHeight = 0;
241     qreal spacing = 0;
242     QLocale locale;
243     QFont resolvedFont;
244     QPalette resolvedPalette;
245     Qt::FocusPolicy focusPolicy = Qt::NoFocus;
246     Qt::FocusReason focusReason = Qt::OtherFocusReason;
247     QQuickDeferredPointer<QQuickItem> background;
248     QQuickDeferredPointer<QQuickItem> contentItem;
249 };
250 
251 QT_END_NAMESPACE
252 
253 #endif // QQUICKCONTROL_P_P_H
254