| 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 | |
| 32 | QT_BEGIN_NAMESPACE |
| 33 | |
| 34 | Q_DECLARE_LOGGING_CATEGORY(lcItemManagement) |
| 35 | |
| 36 | class QQuickAccessibleAttached; |
| 37 | |
| 38 | class Q_QUICKTEMPLATES2_EXPORT QQuickControlPrivate : public QQuickItemPrivate, public QQuickItemChangeListener |
| 39 | #if QT_CONFIG(accessibility) |
| 40 | , public QAccessible::ActivationObserver |
| 41 | #endif |
| 42 | { |
| 43 | public: |
| 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 | bool setLastFocusChangeReason(Qt::FocusReason) override; |
| 159 | |
| 160 | virtual qreal getContentWidth() const; |
| 161 | virtual qreal getContentHeight() const; |
| 162 | |
| 163 | void updateImplicitContentWidth(); |
| 164 | void updateImplicitContentHeight(); |
| 165 | void updateImplicitContentSize(); |
| 166 | |
| 167 | QPalette defaultPalette() const override; |
| 168 | |
| 169 | struct { |
| 170 | bool = false; |
| 171 | bool = false; |
| 172 | bool = false; |
| 173 | bool = false; |
| 174 | bool = false; |
| 175 | bool = false; |
| 176 | bool = false; |
| 177 | bool = false; |
| 178 | bool = false; |
| 179 | bool = false; |
| 180 | bool = false; |
| 181 | qreal = 0; |
| 182 | qreal = 0; |
| 183 | qreal = 0; |
| 184 | qreal = 0; |
| 185 | qreal = 0; |
| 186 | qreal = 0; |
| 187 | qreal = 0; |
| 188 | qreal = 0; |
| 189 | QFont ; |
| 190 | }; |
| 191 | QLazilyAllocated<ExtraData> ; |
| 192 | |
| 193 | bool hasHorizontalPadding = false; |
| 194 | bool hasVerticalPadding = false; |
| 195 | bool hasLocale = false; |
| 196 | bool wheelEnabled = false; |
| 197 | #if QT_CONFIG(quicktemplates2_hover) |
| 198 | bool hovered = false; |
| 199 | bool explicitHoverEnabled = false; |
| 200 | #endif |
| 201 | bool resizingBackground = false; |
| 202 | int touchId = -1; |
| 203 | qreal padding = 0; |
| 204 | qreal horizontalPadding = 0; |
| 205 | qreal verticalPadding = 0; |
| 206 | qreal implicitContentWidth = 0; |
| 207 | qreal implicitContentHeight = 0; |
| 208 | qreal spacing = 0; |
| 209 | QLocale locale; |
| 210 | QFont resolvedFont; |
| 211 | QQuickDeferredPointer<QQuickItem> background; |
| 212 | QQuickDeferredPointer<QQuickItem> contentItem; |
| 213 | }; |
| 214 | |
| 215 | QT_END_NAMESPACE |
| 216 | |
| 217 | #endif // QQUICKCONTROL_P_P_H |
| 218 | |