diff options
Diffstat (limited to 'src/quicktemplates2')
58 files changed, 1428 insertions, 347 deletions
diff --git a/src/quicktemplates2/qquickapplicationwindow.cpp b/src/quicktemplates2/qquickapplicationwindow.cpp index 77cf5465..370f47bb 100644 --- a/src/quicktemplates2/qquickapplicationwindow.cpp +++ b/src/quicktemplates2/qquickapplicationwindow.cpp @@ -274,7 +274,7 @@ void QQuickApplicationWindowPrivate::updateFont(const QFont &f) void QQuickApplicationWindowPrivate::resolveFont() { - QFont resolvedFont = font.resolve(QQuickControlPrivate::themeFont(QPlatformTheme::SystemFont)); + QFont resolvedFont = font.resolve(QQuickTheme::themeFont(QQuickTheme::SystemFont)); setFont_helper(resolvedFont); } @@ -296,7 +296,7 @@ void QQuickApplicationWindowPrivate::updatePalette(const QPalette &p) void QQuickApplicationWindowPrivate::resolvePalette() { - QPalette resolvedPalette = palette.resolve(QQuickControlPrivate::themePalette(QPlatformTheme::SystemPalette)); + QPalette resolvedPalette = palette.resolve(QQuickTheme::themePalette(QQuickTheme::SystemPalette)); setPalette_helper(resolvedPalette); } @@ -691,7 +691,7 @@ void QQuickApplicationWindow::setFont(const QFont &font) if (d->font.resolve() == font.resolve() && d->font == font) return; - QFont resolvedFont = font.resolve(QQuickControlPrivate::themeFont(QPlatformTheme::SystemFont)); + QFont resolvedFont = font.resolve(QQuickTheme::themeFont(QQuickTheme::SystemFont)); d->setFont_helper(resolvedFont); } @@ -770,7 +770,7 @@ void QQuickApplicationWindow::setPalette(const QPalette &palette) if (d->palette.resolve() == palette.resolve() && d->palette == palette) return; - QPalette resolvedPalette = palette.resolve(QQuickControlPrivate::themePalette(QPlatformTheme::SystemPalette)); + QPalette resolvedPalette = palette.resolve(QQuickTheme::themePalette(QQuickTheme::SystemPalette)); d->setPalette_helper(resolvedPalette); } diff --git a/src/quicktemplates2/qquickbutton.cpp b/src/quicktemplates2/qquickbutton.cpp index a1bea792..f50736f1 100644 --- a/src/quicktemplates2/qquickbutton.cpp +++ b/src/quicktemplates2/qquickbutton.cpp @@ -102,12 +102,12 @@ QQuickButton::QQuickButton(QQuickButtonPrivate &dd, QQuickItem *parent) QFont QQuickButton::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::PushButtonFont); + return QQuickTheme::themeFont(QQuickTheme::PushButtonFont); } QPalette QQuickButton::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::ButtonPalette); + return QQuickTheme::themePalette(QQuickTheme::ButtonPalette); } /*! diff --git a/src/quicktemplates2/qquickcheckbox.cpp b/src/quicktemplates2/qquickcheckbox.cpp index c6519338..e1ca675e 100644 --- a/src/quicktemplates2/qquickcheckbox.cpp +++ b/src/quicktemplates2/qquickcheckbox.cpp @@ -189,12 +189,12 @@ void QQuickCheckBox::setCheckState(Qt::CheckState state) QFont QQuickCheckBox::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::CheckBoxFont); + return QQuickTheme::themeFont(QQuickTheme::CheckBoxFont); } QPalette QQuickCheckBox::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::CheckBoxPalette); + return QQuickTheme::themePalette(QQuickTheme::CheckBoxPalette); } void QQuickCheckBox::buttonChange(ButtonChange change) diff --git a/src/quicktemplates2/qquickcheckdelegate.cpp b/src/quicktemplates2/qquickcheckdelegate.cpp index b53877df..9d892154 100644 --- a/src/quicktemplates2/qquickcheckdelegate.cpp +++ b/src/quicktemplates2/qquickcheckdelegate.cpp @@ -176,7 +176,7 @@ void QQuickCheckDelegate::setCheckState(Qt::CheckState state) QFont QQuickCheckDelegate::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::ListViewFont); + return QQuickTheme::themeFont(QQuickTheme::ListViewFont); } void QQuickCheckDelegate::buttonChange(ButtonChange change) diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp index 3639bf2f..28d3506f 100644 --- a/src/quicktemplates2/qquickcombobox.cpp +++ b/src/quicktemplates2/qquickcombobox.cpp @@ -1705,12 +1705,12 @@ void QQuickComboBox::localeChange(const QLocale &newLocale, const QLocale &oldLo QFont QQuickComboBox::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::ComboMenuItemFont); + return QQuickTheme::themeFont(QQuickTheme::ComboMenuItemFont); } QPalette QQuickComboBox::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::ComboBoxPalette); + return QQuickTheme::themePalette(QQuickTheme::ComboBoxPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp index 9f796a70..03a92b00 100644 --- a/src/quicktemplates2/qquickcontrol.cpp +++ b/src/quicktemplates2/qquickcontrol.cpp @@ -50,9 +50,6 @@ #include "qquickapplicationwindow_p.h" #include "qquickdeferredexecute_p_p.h" -#include <QtGui/private/qguiapplication_p.h> -#include <QtGui/qpa/qplatformtheme.h> - #if QT_CONFIG(accessibility) #include <QtQuick/private/qquickaccessibleattached_p.h> #endif @@ -106,14 +103,20 @@ static bool isKeyFocusReason(Qt::FocusReason reason) } QQuickControlPrivate::ExtraData::ExtraData() -{ -} - -QQuickControlPrivate::QQuickControlPrivate() : hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false), + topPadding(0), + leftPadding(0), + rightPadding(0), + bottomPadding(0) +{ +} + +QQuickControlPrivate::QQuickControlPrivate() + : hasHorizontalPadding(false), + hasVerticalPadding(false), hasLocale(false), wheelEnabled(false), #if QT_CONFIG(quicktemplates2_hover) @@ -122,10 +125,8 @@ QQuickControlPrivate::QQuickControlPrivate() #endif touchId(-1), padding(0), - topPadding(0), - leftPadding(0), - rightPadding(0), - bottomPadding(0), + horizontalPadding(0), + verticalPadding(0), spacing(0), focusPolicy(Qt::NoFocus), focusReason(Qt::OtherFocusReason), @@ -207,56 +208,90 @@ void QQuickControlPrivate::mirrorChange() void QQuickControlPrivate::setTopPadding(qreal value, bool reset) { Q_Q(QQuickControl); - qreal oldPadding = q->topPadding(); - topPadding = value; - hasTopPadding = !reset; - if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { + const QMarginsF oldPadding = getPadding(); + extra.value().topPadding = value; + extra.value().hasTopPadding = !reset; + if ((!reset && !qFuzzyCompare(oldPadding.top(), value)) || (reset && !qFuzzyCompare(oldPadding.top(), getVerticalPadding()))) { emit q->topPaddingChanged(); emit q->availableHeightChanged(); - q->paddingChange(QMarginsF(leftPadding, topPadding, rightPadding, bottomPadding), - QMarginsF(leftPadding, oldPadding, rightPadding, bottomPadding)); + q->paddingChange(getPadding(), oldPadding); } } void QQuickControlPrivate::setLeftPadding(qreal value, bool reset) { Q_Q(QQuickControl); - qreal oldPadding = q->leftPadding(); - leftPadding = value; - hasLeftPadding = !reset; - if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { + const QMarginsF oldPadding = getPadding(); + extra.value().leftPadding = value; + extra.value().hasLeftPadding = !reset; + if ((!reset && !qFuzzyCompare(oldPadding.left(), value)) || (reset && !qFuzzyCompare(oldPadding.left(), getHorizontalPadding()))) { emit q->leftPaddingChanged(); emit q->availableWidthChanged(); - q->paddingChange(QMarginsF(leftPadding, topPadding, rightPadding, bottomPadding), - QMarginsF(oldPadding, topPadding, rightPadding, bottomPadding)); + q->paddingChange(getPadding(), oldPadding); } } void QQuickControlPrivate::setRightPadding(qreal value, bool reset) { Q_Q(QQuickControl); - qreal oldPadding = q->rightPadding(); - rightPadding = value; - hasRightPadding = !reset; - if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { + const QMarginsF oldPadding = getPadding(); + extra.value().rightPadding = value; + extra.value().hasRightPadding = !reset; + if ((!reset && !qFuzzyCompare(oldPadding.right(), value)) || (reset && !qFuzzyCompare(oldPadding.right(), getHorizontalPadding()))) { emit q->rightPaddingChanged(); emit q->availableWidthChanged(); - q->paddingChange(QMarginsF(leftPadding, topPadding, rightPadding, bottomPadding), - QMarginsF(leftPadding, topPadding, oldPadding, bottomPadding)); + q->paddingChange(getPadding(), oldPadding); } } void QQuickControlPrivate::setBottomPadding(qreal value, bool reset) { Q_Q(QQuickControl); - qreal oldPadding = q->bottomPadding(); - bottomPadding = value; - hasBottomPadding = !reset; - if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { + const QMarginsF oldPadding = getPadding(); + extra.value().bottomPadding = value; + extra.value().hasBottomPadding = !reset; + if ((!reset && !qFuzzyCompare(oldPadding.bottom(), value)) || (reset && !qFuzzyCompare(oldPadding.bottom(), getVerticalPadding()))) { emit q->bottomPaddingChanged(); emit q->availableHeightChanged(); - q->paddingChange(QMarginsF(leftPadding, topPadding, rightPadding, bottomPadding), - QMarginsF(leftPadding, topPadding, rightPadding, oldPadding)); + q->paddingChange(getPadding(), oldPadding); + } +} + +void QQuickControlPrivate::setHorizontalPadding(qreal value, bool reset) +{ + Q_Q(QQuickControl); + const QMarginsF oldPadding = getPadding(); + const qreal oldHorizontalPadding = getHorizontalPadding(); + horizontalPadding = value; + hasHorizontalPadding = !reset; + if ((!reset && !qFuzzyCompare(oldHorizontalPadding, value)) || (reset && !qFuzzyCompare(oldHorizontalPadding, padding))) { + const QMarginsF newPadding = getPadding(); + if (!qFuzzyCompare(newPadding.left(), oldPadding.left())) + emit q->leftPaddingChanged(); + if (!qFuzzyCompare(newPadding.right(), oldPadding.right())) + emit q->rightPaddingChanged(); + emit q->horizontalPaddingChanged(); + emit q->availableWidthChanged(); + q->paddingChange(newPadding, oldPadding); + } +} + +void QQuickControlPrivate::setVerticalPadding(qreal value, bool reset) +{ + Q_Q(QQuickControl); + const QMarginsF oldPadding = getPadding(); + const qreal oldVerticalPadding = getVerticalPadding(); + verticalPadding = value; + hasVerticalPadding = !reset; + if ((!reset && !qFuzzyCompare(oldVerticalPadding, value)) || (reset && !qFuzzyCompare(oldVerticalPadding, padding))) { + const QMarginsF newPadding = getPadding(); + if (!qFuzzyCompare(newPadding.top(), oldPadding.top())) + emit q->topPaddingChanged(); + if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom())) + emit q->bottomPaddingChanged(); + emit q->verticalPaddingChanged(); + emit q->availableHeightChanged(); + q->paddingChange(newPadding, oldPadding); } } @@ -362,21 +397,7 @@ QFont QQuickControlPrivate::parentFont(const QQuickItem *item) if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(item->window())) return window->font(); - return themeFont(QPlatformTheme::SystemFont); -} - -QFont QQuickControlPrivate::themeFont(QPlatformTheme::Font type) -{ - if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { - if (const QFont *font = theme->font(type)) { - QFont f = *font; - if (type == QPlatformTheme::SystemFont) - f.resolve(0); - return f; - } - } - - return QFont(); + return QQuickTheme::themeFont(QQuickTheme::SystemFont); } /*! @@ -467,21 +488,7 @@ QPalette QQuickControlPrivate::parentPalette(const QQuickItem *item) if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(item->window())) return window->palette(); - return themePalette(QPlatformTheme::SystemPalette); -} - -QPalette QQuickControlPrivate::themePalette(QPlatformTheme::Palette type) -{ - if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { - if (const QPalette *palette = theme->palette(type)) { - QPalette p = *palette; - if (type == QPlatformTheme::SystemPalette) - p.resolve(0); - return p; - } - } - - return QPalette(); + return QQuickTheme::themePalette(QQuickTheme::SystemPalette); } /*! @@ -866,10 +873,18 @@ void QQuickControl::setPadding(qreal padding) Q_D(QQuickControl); if (qFuzzyCompare(d->padding, padding)) return; - QMarginsF oldPadding(leftPadding(), topPadding(), rightPadding(), bottomPadding()); + + const QMarginsF oldPadding = d->getPadding(); + const qreal oldVerticalPadding = d->getVerticalPadding(); + const qreal oldHorizontalPadding = d->getHorizontalPadding(); + d->padding = padding; emit paddingChanged(); - QMarginsF newPadding(leftPadding(), topPadding(), rightPadding(), bottomPadding()); + + const QMarginsF newPadding = d->getPadding(); + const qreal newVerticalPadding = d->getVerticalPadding(); + const qreal newHorizontalPadding = d->getHorizontalPadding(); + if (!qFuzzyCompare(newPadding.top(), oldPadding.top())) emit topPaddingChanged(); if (!qFuzzyCompare(newPadding.left(), oldPadding.left())) @@ -878,10 +893,15 @@ void QQuickControl::setPadding(qreal padding) emit rightPaddingChanged(); if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom())) emit bottomPaddingChanged(); + if (!qFuzzyCompare(newVerticalPadding, oldVerticalPadding)) + emit verticalPaddingChanged(); + if (!qFuzzyCompare(newHorizontalPadding, oldHorizontalPadding)) + emit horizontalPaddingChanged(); if (!qFuzzyCompare(newPadding.top(), oldPadding.top()) || !qFuzzyCompare(newPadding.bottom(), oldPadding.bottom())) emit availableHeightChanged(); if (!qFuzzyCompare(newPadding.left(), oldPadding.left()) || !qFuzzyCompare(newPadding.right(), oldPadding.right())) emit availableWidthChanged(); + paddingChange(newPadding, oldPadding); } @@ -893,16 +913,15 @@ void QQuickControl::resetPadding() /*! \qmlproperty real QtQuick.Controls::Control::topPadding - This property holds the top padding. + This property holds the top padding. Unless explicitly set, the value + is equal to \c verticalPadding. - \sa {Control Layout}, padding, bottomPadding, availableHeight + \sa {Control Layout}, padding, bottomPadding, verticalPadding, availableHeight */ qreal QQuickControl::topPadding() const { Q_D(const QQuickControl); - if (d->hasTopPadding) - return d->topPadding; - return d->padding; + return d->getTopPadding(); } void QQuickControl::setTopPadding(qreal padding) @@ -920,16 +939,15 @@ void QQuickControl::resetTopPadding() /*! \qmlproperty real QtQuick.Controls::Control::leftPadding - This property holds the left padding. + This property holds the left padding. Unless explicitly set, the value + is equal to \c horizontalPadding. - \sa {Control Layout}, padding, rightPadding, availableWidth + \sa {Control Layout}, padding, rightPadding, horizontalPadding, availableWidth */ qreal QQuickControl::leftPadding() const { Q_D(const QQuickControl); - if (d->hasLeftPadding) - return d->leftPadding; - return d->padding; + return d->getLeftPadding(); } void QQuickControl::setLeftPadding(qreal padding) @@ -947,16 +965,15 @@ void QQuickControl::resetLeftPadding() /*! \qmlproperty real QtQuick.Controls::Control::rightPadding - This property holds the right padding. + This property holds the right padding. Unless explicitly set, the value + is equal to \c horizontalPadding. - \sa {Control Layout}, padding, leftPadding, availableWidth + \sa {Control Layout}, padding, leftPadding, horizontalPadding, availableWidth */ qreal QQuickControl::rightPadding() const { Q_D(const QQuickControl); - if (d->hasRightPadding) - return d->rightPadding; - return d->padding; + return d->getRightPadding(); } void QQuickControl::setRightPadding(qreal padding) @@ -974,16 +991,15 @@ void QQuickControl::resetRightPadding() /*! \qmlproperty real QtQuick.Controls::Control::bottomPadding - This property holds the bottom padding. + This property holds the bottom padding. Unless explicitly set, the value + is equal to \c verticalPadding. - \sa {Control Layout}, padding, topPadding, availableHeight + \sa {Control Layout}, padding, topPadding, verticalPadding, availableHeight */ qreal QQuickControl::bottomPadding() const { Q_D(const QQuickControl); - if (d->hasBottomPadding) - return d->bottomPadding; - return d->padding; + return d->getBottomPadding(); } void QQuickControl::setBottomPadding(qreal padding) @@ -1440,6 +1456,60 @@ void QQuickControl::resetPalette() setPalette(QPalette()); } +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Control::horizontalPadding + + This property holds the horizontal padding. Unless explicitly set, the value + is equal to \c padding. + + \sa {Control Layout}, padding, leftPadding, rightPadding, verticalPadding +*/ +qreal QQuickControl::horizontalPadding() const +{ + Q_D(const QQuickControl); + return d->getHorizontalPadding(); +} + +void QQuickControl::setHorizontalPadding(qreal padding) +{ + Q_D(QQuickControl); + d->setHorizontalPadding(padding); +} + +void QQuickControl::resetHorizontalPadding() +{ + Q_D(QQuickControl); + d->setHorizontalPadding(0, true); +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Control::verticalPadding + + This property holds the vertical padding. Unless explicitly set, the value + is equal to \c padding. + + \sa {Control Layout}, padding, topPadding, bottomPadding, horizontalPadding +*/ +qreal QQuickControl::verticalPadding() const +{ + Q_D(const QQuickControl); + return d->getVerticalPadding(); +} + +void QQuickControl::setVerticalPadding(qreal padding) +{ + Q_D(QQuickControl); + d->setVerticalPadding(padding); +} + +void QQuickControl::resetVerticalPadding() +{ + Q_D(QQuickControl); + d->setVerticalPadding(0, true); +} + void QQuickControl::classBegin() { Q_D(QQuickControl); @@ -1470,12 +1540,12 @@ void QQuickControl::componentComplete() QFont QQuickControl::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::SystemFont); + return QQuickTheme::themeFont(QQuickTheme::SystemFont); } QPalette QQuickControl::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::SystemPalette); + return QQuickTheme::themePalette(QQuickTheme::SystemPalette); } void QQuickControl::focusInEvent(QFocusEvent *event) diff --git a/src/quicktemplates2/qquickcontrol_p.h b/src/quicktemplates2/qquickcontrol_p.h index 6b2d48d6..cd317850 100644 --- a/src/quicktemplates2/qquickcontrol_p.h +++ b/src/quicktemplates2/qquickcontrol_p.h @@ -81,6 +81,9 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickControl : public QQuickItem Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL) // 2.3 (Qt 5.10) Q_PROPERTY(QPalette palette READ palette WRITE setPalette RESET resetPalette NOTIFY paletteChanged FINAL REVISION 3) + // 2.5 (Qt 5.12) + Q_PROPERTY(qreal horizontalPadding READ horizontalPadding WRITE setHorizontalPadding RESET resetHorizontalPadding NOTIFY horizontalPaddingChanged FINAL REVISION 5) + Q_PROPERTY(qreal verticalPadding READ verticalPadding WRITE setVerticalPadding RESET resetVerticalPadding NOTIFY verticalPaddingChanged FINAL REVISION 5) Q_CLASSINFO("DeferredPropertyNames", "background,contentItem") public: @@ -152,6 +155,15 @@ public: void setPalette(const QPalette &palette); void resetPalette(); + // 2.5 (Qt 5.12) + qreal horizontalPadding() const; + void setHorizontalPadding(qreal padding); + void resetHorizontalPadding(); + + qreal verticalPadding() const; + void setVerticalPadding(qreal padding); + void resetVerticalPadding(); + Q_SIGNALS: void fontChanged(); void availableWidthChanged(); @@ -174,6 +186,9 @@ Q_SIGNALS: void contentItemChanged(); // 2.3 (Qt 5.10) Q_REVISION(3) void paletteChanged(); + // 2.5 (Qt 5.12) + Q_REVISION(5) void horizontalPaddingChanged(); + Q_REVISION(5) void verticalPaddingChanged(); protected: virtual QFont defaultFont() const; diff --git a/src/quicktemplates2/qquickcontrol_p_p.h b/src/quicktemplates2/qquickcontrol_p_p.h index 7d040ded..250c383b 100644 --- a/src/quicktemplates2/qquickcontrol_p_p.h +++ b/src/quicktemplates2/qquickcontrol_p_p.h @@ -50,10 +50,10 @@ #include <QtQuickTemplates2/private/qquickcontrol_p.h> #include <QtQuickTemplates2/private/qquickdeferredpointer_p_p.h> +#include <QtQuickTemplates2/private/qquicktheme_p.h> #include <QtQuick/private/qquickitem_p.h> #include <QtQml/private/qlazilyallocated_p.h> -#include <qpa/qplatformtheme.h> #if QT_CONFIG(accessibility) #include <QtGui/qaccessible.h> @@ -89,10 +89,20 @@ public: void mirrorChange() override; + inline QMarginsF getPadding() const { return QMarginsF(getLeftPadding(), getTopPadding(), getRightPadding(), getBottomPadding()); } + inline qreal getTopPadding() const { return extra.isAllocated() && extra->hasTopPadding ? extra->topPadding : getVerticalPadding(); } + inline qreal getLeftPadding() const { return extra.isAllocated() && extra->hasLeftPadding ? extra->leftPadding : getHorizontalPadding(); } + inline qreal getRightPadding() const { return extra.isAllocated() && extra->hasRightPadding ? extra->rightPadding : getHorizontalPadding(); } + inline qreal getBottomPadding() const { return extra.isAllocated() && extra->hasBottomPadding ? extra->bottomPadding : getVerticalPadding(); } + inline qreal getHorizontalPadding() const { return hasHorizontalPadding ? horizontalPadding : padding; } + inline qreal getVerticalPadding() const { return hasVerticalPadding ? verticalPadding : padding; } + void setTopPadding(qreal value, bool reset = false); void setLeftPadding(qreal value, bool reset = false); void setRightPadding(qreal value, bool reset = false); void setBottomPadding(qreal value, bool reset = false); + void setHorizontalPadding(qreal value, bool reset = false); + void setVerticalPadding(qreal value, bool reset = false); void resizeBackground(); virtual void resizeContent(); @@ -116,7 +126,6 @@ public: updateFont(font); } static QFont parentFont(const QQuickItem *item); - static QFont themeFont(QPlatformTheme::Font type); virtual void resolvePalette(); void inheritPalette(const QPalette &palette); @@ -128,7 +137,6 @@ public: updatePalette(palette); } static QPalette parentPalette(const QQuickItem *item); - static QPalette themePalette(QPlatformTheme::Palette type); void updateLocale(const QLocale &l, bool e); static void updateLocaleRecur(QQuickItem *item, const QLocale &l); @@ -148,15 +156,21 @@ public: struct ExtraData { ExtraData(); + bool hasTopPadding; + bool hasLeftPadding; + bool hasRightPadding; + bool hasBottomPadding; + qreal topPadding; + qreal leftPadding; + qreal rightPadding; + qreal bottomPadding; QFont requestedFont; QPalette requestedPalette; }; QLazilyAllocated<ExtraData> extra; - bool hasTopPadding; - bool hasLeftPadding; - bool hasRightPadding; - bool hasBottomPadding; + bool hasHorizontalPadding; + bool hasVerticalPadding; bool hasLocale; bool wheelEnabled; #if QT_CONFIG(quicktemplates2_hover) @@ -165,10 +179,8 @@ public: #endif int touchId; qreal padding; - qreal topPadding; - qreal leftPadding; - qreal rightPadding; - qreal bottomPadding; + qreal horizontalPadding; + qreal verticalPadding; qreal spacing; QLocale locale; QFont resolvedFont; diff --git a/src/quicktemplates2/qquickdelaybutton.cpp b/src/quicktemplates2/qquickdelaybutton.cpp index 128f0c78..79bd738f 100644 --- a/src/quicktemplates2/qquickdelaybutton.cpp +++ b/src/quicktemplates2/qquickdelaybutton.cpp @@ -265,12 +265,12 @@ void QQuickDelayButton::nextCheckState() QFont QQuickDelayButton::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::PushButtonFont); + return QQuickTheme::themeFont(QQuickTheme::PushButtonFont); } QPalette QQuickDelayButton::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::ButtonPalette); + return QQuickTheme::themePalette(QQuickTheme::ButtonPalette); } QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquickdialogbuttonbox.cpp b/src/quicktemplates2/qquickdialogbuttonbox.cpp index f16f1b74..a69b006f 100644 --- a/src/quicktemplates2/qquickdialogbuttonbox.cpp +++ b/src/quicktemplates2/qquickdialogbuttonbox.cpp @@ -168,10 +168,16 @@ QT_BEGIN_NAMESPACE \sa accepted(), rejected(), helpRequested() */ +static QQuickDialogButtonBox::ButtonLayout platformButtonLayout() +{ + return QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::DialogButtonBoxLayout).value<QQuickDialogButtonBox::ButtonLayout>(); +} + QQuickDialogButtonBoxPrivate::QQuickDialogButtonBoxPrivate() : alignment(0), position(QQuickDialogButtonBox::Footer), standardButtons(QPlatformDialogHelper::NoButton), + buttonLayout(platformButtonLayout()), delegate(nullptr) { } @@ -258,6 +264,11 @@ void QQuickDialogButtonBoxPrivate::updateLayout() } struct ButtonLayout { + ButtonLayout(QPlatformDialogHelper::ButtonLayout layout) + : m_layout(QPlatformDialogHelper::buttonLayout(Qt::Horizontal, layout)) + { + } + bool operator()(QQuickAbstractButton *first, QQuickAbstractButton *second) { const QPlatformDialogHelper::ButtonRole firstRole = QQuickDialogPrivate::buttonRole(first); @@ -280,15 +291,10 @@ void QQuickDialogButtonBoxPrivate::updateLayout() return firstRole != QPlatformDialogHelper::InvalidRole; } - static const int *themeButtonLayout() - { - const int hint = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt(); - return QPlatformDialogHelper::buttonLayout(Qt::Horizontal, static_cast<QPlatformDialogHelper::ButtonLayout>(hint)); - } - const int *m_layout = themeButtonLayout(); + const int *m_layout; }; - std::sort(buttons.begin(), buttons.end(), ButtonLayout()); + std::sort(buttons.begin(), buttons.end(), ButtonLayout(static_cast<QPlatformDialogHelper::ButtonLayout>(buttonLayout))); for (int i = 0; i < buttons.count() - 1; ++i) q->insertItem(i, buttons.at(i)); @@ -580,6 +586,43 @@ QQuickDialogButtonBoxAttached *QQuickDialogButtonBox::qmlAttachedProperties(QObj return new QQuickDialogButtonBoxAttached(object); } +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty enumeration QtQuick.Controls::DialogButtonBox::buttonLayout + + This property holds the button layout policy to be used when arranging the buttons contained in the button box. + The default value is platform-specific. + + Available values: + \value DialogButtonBox.WinLayout Use a policy appropriate for applications on Windows. + \value DialogButtonBox.MacLayout Use a policy appropriate for applications on macOS. + \value DialogButtonBox.KdeLayout Use a policy appropriate for applications on KDE. + \value DialogButtonBox.GnomeLayout Use a policy appropriate for applications on GNOME. + \value DialogButtonBox.AndroidLayout Use a policy appropriate for applications on Android. +*/ +QQuickDialogButtonBox::ButtonLayout QQuickDialogButtonBox::buttonLayout() const +{ + Q_D(const QQuickDialogButtonBox); + return d->buttonLayout; +} + +void QQuickDialogButtonBox::setButtonLayout(ButtonLayout layout) +{ + Q_D(QQuickDialogButtonBox); + if (d->buttonLayout == layout) + return; + + d->buttonLayout = layout; + if (isComponentComplete()) + d->updateLayout(); + emit buttonLayoutChanged(); +} + +void QQuickDialogButtonBox::resetButtonLayout() +{ + setButtonLayout(platformButtonLayout()); +} + void QQuickDialogButtonBox::updatePolish() { Q_D(QQuickDialogButtonBox); diff --git a/src/quicktemplates2/qquickdialogbuttonbox_p.h b/src/quicktemplates2/qquickdialogbuttonbox_p.h index 1e3cdeef..df302e54 100644 --- a/src/quicktemplates2/qquickdialogbuttonbox_p.h +++ b/src/quicktemplates2/qquickdialogbuttonbox_p.h @@ -66,6 +66,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDialogButtonBox : public QQuickCont Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment RESET resetAlignment NOTIFY alignmentChanged FINAL) Q_PROPERTY(QPlatformDialogHelper::StandardButtons standardButtons READ standardButtons WRITE setStandardButtons NOTIFY standardButtonsChanged FINAL) Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) + // 2.5 (Qt 5.12) + Q_PROPERTY(ButtonLayout buttonLayout READ buttonLayout WRITE setButtonLayout RESET resetButtonLayout NOTIFY buttonLayoutChanged FINAL REVISION 5) Q_FLAGS(QPlatformDialogHelper::StandardButtons) public: @@ -94,6 +96,24 @@ public: static QQuickDialogButtonBoxAttached *qmlAttachedProperties(QObject *object); + // 2.5 (Qt 5.12) + + // ### TODO: use Q_ENUMS(QPlatformDialogHelper::ButtonLayout) + enum ButtonLayout { + UnknownLayout = -1, + WinLayout, + MacLayout, + KdeLayout, + GnomeLayout, + MacModelessLayout, + AndroidLayout + }; + Q_ENUM(ButtonLayout) + + ButtonLayout buttonLayout() const; + void setButtonLayout(ButtonLayout layout); + void resetButtonLayout(); + Q_SIGNALS: void accepted(); void rejected(); @@ -107,6 +127,8 @@ Q_SIGNALS: Q_REVISION(3) void applied(); Q_REVISION(3) void reset(); Q_REVISION(3) void discarded(); + // 2.5 (Qt 5.12) + Q_REVISION(5) void buttonLayoutChanged(); protected: void updatePolish() override; diff --git a/src/quicktemplates2/qquickdialogbuttonbox_p_p.h b/src/quicktemplates2/qquickdialogbuttonbox_p_p.h index 7247d591..3c761d6b 100644 --- a/src/quicktemplates2/qquickdialogbuttonbox_p_p.h +++ b/src/quicktemplates2/qquickdialogbuttonbox_p_p.h @@ -78,6 +78,7 @@ public: Qt::Alignment alignment; QQuickDialogButtonBox::Position position; QPlatformDialogHelper::StandardButtons standardButtons; + QQuickDialogButtonBox::ButtonLayout buttonLayout; QQmlComponent *delegate; }; diff --git a/src/quicktemplates2/qquickgroupbox.cpp b/src/quicktemplates2/qquickgroupbox.cpp index 4f4c5eed..4a8420b2 100644 --- a/src/quicktemplates2/qquickgroupbox.cpp +++ b/src/quicktemplates2/qquickgroupbox.cpp @@ -189,12 +189,12 @@ void QQuickGroupBox::componentComplete() QFont QQuickGroupBox::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::GroupBoxTitleFont); + return QQuickTheme::themeFont(QQuickTheme::GroupBoxTitleFont); } QPalette QQuickGroupBox::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::GroupBoxPalette); + return QQuickTheme::themePalette(QQuickTheme::GroupBoxPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickitemdelegate.cpp b/src/quicktemplates2/qquickitemdelegate.cpp index 044141f2..ac29936c 100644 --- a/src/quicktemplates2/qquickitemdelegate.cpp +++ b/src/quicktemplates2/qquickitemdelegate.cpp @@ -122,12 +122,12 @@ void QQuickItemDelegate::setHighlighted(bool highlighted) QFont QQuickItemDelegate::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::ItemViewFont); + return QQuickTheme::themeFont(QQuickTheme::ItemViewFont); } QPalette QQuickItemDelegate::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::ItemViewPalette); + return QQuickTheme::themePalette(QQuickTheme::ItemViewPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquicklabel.cpp b/src/quicktemplates2/qquicklabel.cpp index 41b2d93a..7a4ea8df 100644 --- a/src/quicktemplates2/qquicklabel.cpp +++ b/src/quicktemplates2/qquicklabel.cpp @@ -113,7 +113,7 @@ void QQuickLabelPrivate::inheritFont(const QFont &font) QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font; parentFont.resolve(extra.isAllocated() ? extra->requestedFont.resolve() | font.resolve() : font.resolve()); - const QFont defaultFont = QQuickControlPrivate::themeFont(QPlatformTheme::LabelFont); + const QFont defaultFont = QQuickTheme::themeFont(QQuickTheme::LabelFont); const QFont resolvedFont = parentFont.resolve(defaultFont); setFont_helper(resolvedFont); @@ -155,7 +155,7 @@ void QQuickLabelPrivate::inheritPalette(const QPalette &palette) QPalette parentPalette = extra.isAllocated() ? extra->requestedPalette.resolve(palette) : palette; parentPalette.resolve(extra.isAllocated() ? extra->requestedPalette.resolve() | palette.resolve() : palette.resolve()); - const QPalette defaultPalette = QQuickControlPrivate::themePalette(QPlatformTheme::LabelPalette); + const QPalette defaultPalette = QQuickTheme::themePalette(QQuickTheme::LabelPalette); const QPalette resolvedPalette = parentPalette.resolve(defaultPalette); setPalette_helper(resolvedPalette); diff --git a/src/quicktemplates2/qquickmenu.cpp b/src/quicktemplates2/qquickmenu.cpp index 5dbfe3d9..cd3b9db6 100644 --- a/src/quicktemplates2/qquickmenu.cpp +++ b/src/quicktemplates2/qquickmenu.cpp @@ -1432,12 +1432,12 @@ void QQuickMenu::timerEvent(QTimerEvent *event) QFont QQuickMenu::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::MenuFont); + return QQuickTheme::themeFont(QQuickTheme::MenuFont); } QPalette QQuickMenu::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::MenuPalette); + return QQuickTheme::themePalette(QQuickTheme::MenuPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickmenubar.cpp b/src/quicktemplates2/qquickmenubar.cpp index 8398633c..ee3d49f3 100644 --- a/src/quicktemplates2/qquickmenubar.cpp +++ b/src/quicktemplates2/qquickmenubar.cpp @@ -643,12 +643,12 @@ void QQuickMenuBar::itemRemoved(int index, QQuickItem *item) QFont QQuickMenuBar::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::MenuBarFont); + return QQuickTheme::themeFont(QQuickTheme::MenuBarFont); } QPalette QQuickMenuBar::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::MenuBarPalette); + return QQuickTheme::themePalette(QQuickTheme::MenuBarPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickmenubaritem.cpp b/src/quicktemplates2/qquickmenubaritem.cpp index cbf490b8..aa4f869a 100644 --- a/src/quicktemplates2/qquickmenubaritem.cpp +++ b/src/quicktemplates2/qquickmenubaritem.cpp @@ -167,12 +167,12 @@ void QQuickMenuBarItem::geometryChanged(const QRectF &newGeometry, const QRectF QFont QQuickMenuBarItem::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::MenuBarFont); + return QQuickTheme::themeFont(QQuickTheme::MenuBarFont); } QPalette QQuickMenuBarItem::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::MenuBarPalette); + return QQuickTheme::themePalette(QQuickTheme::MenuBarPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickmenuitem.cpp b/src/quicktemplates2/qquickmenuitem.cpp index 6693d4f8..318416ce 100644 --- a/src/quicktemplates2/qquickmenuitem.cpp +++ b/src/quicktemplates2/qquickmenuitem.cpp @@ -264,12 +264,12 @@ void QQuickMenuItem::componentComplete() QFont QQuickMenuItem::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::MenuItemFont); + return QQuickTheme::themeFont(QQuickTheme::MenuItemFont); } QPalette QQuickMenuItem::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::MenuPalette); + return QQuickTheme::themePalette(QQuickTheme::MenuPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickmenuseparator.cpp b/src/quicktemplates2/qquickmenuseparator.cpp index dee5287a..7b30c009 100644 --- a/src/quicktemplates2/qquickmenuseparator.cpp +++ b/src/quicktemplates2/qquickmenuseparator.cpp @@ -73,7 +73,7 @@ QQuickMenuSeparator::QQuickMenuSeparator(QQuickItem *parent) QPalette QQuickMenuSeparator::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::MenuPalette); + return QQuickTheme::themePalette(QQuickTheme::MenuPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickpage.cpp b/src/quicktemplates2/qquickpage.cpp index 8f34dca9..b8838f20 100644 --- a/src/quicktemplates2/qquickpage.cpp +++ b/src/quicktemplates2/qquickpage.cpp @@ -35,14 +35,14 @@ ****************************************************************************/ #include "qquickpage_p.h" -#include "qquickcontrol_p_p.h" +#include "qquickpane_p_p.h" #include "qquickpagelayout_p_p.h" QT_BEGIN_NAMESPACE /*! \qmltype Page - \inherits Control + \inherits Pane \instantiates QQuickPage \inqmlmodule QtQuick.Controls \since 5.7 @@ -84,44 +84,19 @@ QT_BEGIN_NAMESPACE {Focus Management in Qt Quick Controls 2} */ -class QQuickPagePrivate : public QQuickControlPrivate +class QQuickPagePrivate : public QQuickPanePrivate { Q_DECLARE_PUBLIC(QQuickPage) public: - QQuickPagePrivate(); - - QQuickItem *getContentItem() override; - - qreal contentWidth; - qreal contentHeight; QString title; QScopedPointer<QQuickPageLayout> layout; }; -QQuickPagePrivate::QQuickPagePrivate() - : contentWidth(0), - contentHeight(0) -{ -} - -QQuickItem *QQuickPagePrivate::getContentItem() -{ - Q_Q(QQuickPage); - if (QQuickItem *item = QQuickControlPrivate::getContentItem()) - return item; - return new QQuickItem(q); -} - QQuickPage::QQuickPage(QQuickItem *parent) - : QQuickControl(*(new QQuickPagePrivate), parent) + : QQuickPane(*(new QQuickPagePrivate), parent) { Q_D(QQuickPage); - setFlag(ItemIsFocusScope); - setAcceptedMouseButtons(Qt::AllButtons); -#if QT_CONFIG(cursor) - setCursor(Qt::ArrowCursor); -#endif d->layout.reset(new QQuickPageLayout(this)); } @@ -234,136 +209,31 @@ void QQuickPage::setFooter(QQuickItem *footer) emit footerChanged(); } -/*! - \qmlproperty list<Object> QtQuick.Controls::Page::contentData - \default - - This property holds the list of content data. - - The list contains all objects that have been declared in QML as children - of the container. - - \note Unlike \c contentChildren, \c contentData does include non-visual QML - objects. - - \sa Item::data, contentChildren -*/ -QQmlListProperty<QObject> QQuickPage::contentData() -{ - return QQmlListProperty<QObject>(contentItem(), nullptr, - QQuickItemPrivate::data_append, - QQuickItemPrivate::data_count, - QQuickItemPrivate::data_at, - QQuickItemPrivate::data_clear); -} - -/*! - \qmlproperty list<Item> QtQuick.Controls::Page::contentChildren - - This property holds the list of content children. - - The list contains all items that have been declared in QML as children - of the page. - - \note Unlike \c contentData, \c contentChildren does not include non-visual - QML objects. - - \sa Item::children, contentData -*/ -QQmlListProperty<QQuickItem> QQuickPage::contentChildren() -{ - return QQmlListProperty<QQuickItem>(contentItem(), nullptr, - QQuickItemPrivate::children_append, - QQuickItemPrivate::children_count, - QQuickItemPrivate::children_at, - QQuickItemPrivate::children_clear); -} - -/*! - \qmlproperty real QtQuick.Controls::Page::contentWidth - \since QtQuick.Controls 2.1 (Qt 5.8) - - This property holds the content width. It is used for calculating the total - implicit width of the page. - - \sa contentHeight -*/ -qreal QQuickPage::contentWidth() const -{ - Q_D(const QQuickPage); - return d->contentWidth; -} - -void QQuickPage::setContentWidth(qreal width) -{ - Q_D(QQuickPage); - if (qFuzzyCompare(d->contentWidth, width)) - return; - - d->contentWidth = width; - emit contentWidthChanged(); -} - -/*! - \qmlproperty real QtQuick.Controls::Page::contentHeight - \since QtQuick.Controls 2.1 (Qt 5.8) - - This property holds the content height. It is used for calculating the total - implicit height of the page. - - \sa contentWidth -*/ -qreal QQuickPage::contentHeight() const -{ - Q_D(const QQuickPage); - return d->contentHeight; -} - -void QQuickPage::setContentHeight(qreal height) -{ - Q_D(QQuickPage); - if (qFuzzyCompare(d->contentHeight, height)) - return; - - d->contentHeight = height; - emit contentHeightChanged(); -} - void QQuickPage::componentComplete() { Q_D(QQuickPage); - QQuickControl::componentComplete(); + QQuickPane::componentComplete(); d->layout->update(); } -void QQuickPage::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) -{ - QQuickControl::contentItemChange(newItem, oldItem); - if (oldItem) - disconnect(oldItem, &QQuickItem::childrenChanged, this, &QQuickPage::contentChildrenChanged); - if (newItem) - connect(newItem, &QQuickItem::childrenChanged, this, &QQuickPage::contentChildrenChanged); - emit contentChildrenChanged(); -} - void QQuickPage::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_D(QQuickPage); - QQuickControl::geometryChanged(newGeometry, oldGeometry); + QQuickPane::geometryChanged(newGeometry, oldGeometry); d->layout->update(); } void QQuickPage::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) { Q_D(QQuickPage); - QQuickControl::paddingChange(newPadding, oldPadding); + QQuickPane::paddingChange(newPadding, oldPadding); d->layout->update(); } void QQuickPage::spacingChange(qreal newSpacing, qreal oldSpacing) { Q_D(QQuickPage); - QQuickControl::spacingChange(newSpacing, oldSpacing); + QQuickPane::spacingChange(newSpacing, oldSpacing); d->layout->update(); } @@ -376,7 +246,7 @@ QAccessible::Role QQuickPage::accessibleRole() const void QQuickPage::accessibilityActiveChanged(bool active) { Q_D(QQuickPage); - QQuickControl::accessibilityActiveChanged(active); + QQuickPane::accessibilityActiveChanged(active); if (active) setAccessibleName(d->title); diff --git a/src/quicktemplates2/qquickpage_p.h b/src/quicktemplates2/qquickpage_p.h index 0789e996..49f9f85f 100644 --- a/src/quicktemplates2/qquickpage_p.h +++ b/src/quicktemplates2/qquickpage_p.h @@ -48,25 +48,22 @@ // We mean it. // -#include <QtQuickTemplates2/private/qquickcontrol_p.h> +#include <QtQuickTemplates2/private/qquickpane_p.h> #include <QtQml/qqmllist.h> QT_BEGIN_NAMESPACE class QQuickPagePrivate; -class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPage : public QQuickControl +class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPage : public QQuickPane { Q_OBJECT Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) Q_PROPERTY(QQuickItem *header READ header WRITE setHeader NOTIFY headerChanged FINAL) Q_PROPERTY(QQuickItem *footer READ footer WRITE setFooter NOTIFY footerChanged FINAL) - Q_PROPERTY(QQmlListProperty<QObject> contentData READ contentData FINAL) - Q_PROPERTY(QQmlListProperty<QQuickItem> contentChildren READ contentChildren NOTIFY contentChildrenChanged FINAL) // 2.1 (Qt 5.8) Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged FINAL REVISION 1) Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged FINAL REVISION 1) - Q_CLASSINFO("DefaultProperty", "contentData") public: explicit QQuickPage(QQuickItem *parent = nullptr); @@ -80,29 +77,14 @@ public: QQuickItem *footer() const; void setFooter(QQuickItem *footer); - QQmlListProperty<QObject> contentData(); - QQmlListProperty<QQuickItem> contentChildren(); - - // 2.1 (Qt 5.8) - qreal contentWidth() const; - void setContentWidth(qreal width); - - qreal contentHeight() const; - void setContentHeight(qreal height); - Q_SIGNALS: void titleChanged(); void headerChanged(); void footerChanged(); - void contentChildrenChanged(); - // 2.1 (Qt 5.8) - Q_REVISION(1) void contentWidthChanged(); - Q_REVISION(1) void contentHeightChanged(); protected: void componentComplete() override; - void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override; void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) override; void spacingChange(qreal newSpacing, qreal oldSpacing) override; diff --git a/src/quicktemplates2/qquickpane.cpp b/src/quicktemplates2/qquickpane.cpp index 8038f1b1..98c4d1f3 100644 --- a/src/quicktemplates2/qquickpane.cpp +++ b/src/quicktemplates2/qquickpane.cpp @@ -106,8 +106,12 @@ QT_BEGIN_NAMESPACE {Focus Management in Qt Quick Controls 2} */ +static const QQuickItemPrivate::ChangeTypes ImplicitSizeChanges = QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed; + QQuickPanePrivate::QQuickPanePrivate() - : contentWidth(0), + : hasContentWidth(false), + hasContentHeight(false), + contentWidth(0), contentHeight(0) { } @@ -120,6 +124,112 @@ QQuickItem *QQuickPanePrivate::getContentItem() return new QQuickItem(q); } +void QQuickPanePrivate::addImplicitSizeListener(QQuickItem *item) +{ + if (!item) + return; + + QQuickItemPrivate::get(item)->addItemChangeListener(this, ImplicitSizeChanges); +} + +void QQuickPanePrivate::removeImplicitSizeListener(QQuickItem *item) +{ + if (!item) + return; + + QQuickItemPrivate::get(item)->removeItemChangeListener(this, ImplicitSizeChanges); +} + +void QQuickPanePrivate::itemImplicitWidthChanged(QQuickItem *item) +{ + Q_Q(QQuickPane); + if (item == contentItem && updateContentWidth(item)) + emit q->contentWidthChanged(); +} + +void QQuickPanePrivate::itemImplicitHeightChanged(QQuickItem *item) +{ + Q_Q(QQuickPane); + if (item == contentItem && updateContentHeight(item)) + emit q->contentHeightChanged(); +} + +void QQuickPanePrivate::itemDestroyed(QQuickItem *item) +{ + if (item == contentItem) + updateContentSize(nullptr); +} + +void QQuickPanePrivate::contentChildrenChange() +{ + Q_Q(QQuickPane); + updateContentSize(contentItem); + emit q->contentChildrenChanged(); +} + +static qreal getContentWidth(QQuickItem *item) +{ + if (!item) + return 0; + + const qreal cw = item->implicitWidth(); + if (!qFuzzyIsNull(cw)) + return cw; + + const auto contentChildren = item->childItems(); + if (contentChildren.count() == 1) + return contentChildren.first()->implicitWidth(); + + return 0; +} + +static qreal getContentHeight(QQuickItem *item) +{ + if (!item) + return 0; + + const qreal ch = item->implicitHeight(); + if (!qFuzzyIsNull(ch)) + return ch; + + const auto contentChildren = item->childItems(); + if (contentChildren.count() == 1) + return contentChildren.first()->implicitHeight(); + + return 0; +} + +bool QQuickPanePrivate::updateContentWidth(QQuickItem *item) +{ + if (hasContentWidth) + return false; + + qreal oldContentWidth = contentWidth; + contentWidth = getContentWidth(item); + return !qFuzzyCompare(contentWidth, oldContentWidth); +} + +bool QQuickPanePrivate::updateContentHeight(QQuickItem *item) +{ + if (hasContentHeight) + return false; + + qreal oldContentHeight = contentHeight; + contentHeight = getContentHeight(item); + return !qFuzzyCompare(contentHeight, oldContentHeight); +} + +void QQuickPanePrivate::updateContentSize(QQuickItem *item) +{ + Q_Q(QQuickPane); + bool widthChanged = updateContentWidth(item); + bool heightChanged = updateContentHeight(item); + if (widthChanged) + emit q->contentWidthChanged(); + if (heightChanged) + emit q->contentHeightChanged(); +} + QQuickPane::QQuickPane(QQuickItem *parent) : QQuickControl(*(new QQuickPanePrivate), parent) { @@ -130,6 +240,12 @@ QQuickPane::QQuickPane(QQuickItem *parent) #endif } +QQuickPane::~QQuickPane() +{ + Q_D(QQuickPane); + d->removeImplicitSizeListener(d->contentItem); +} + QQuickPane::QQuickPane(QQuickPanePrivate &dd, QQuickItem *parent) : QQuickControl(dd, parent) { @@ -159,6 +275,7 @@ qreal QQuickPane::contentWidth() const void QQuickPane::setContentWidth(qreal width) { Q_D(QQuickPane); + d->hasContentWidth = true; if (qFuzzyCompare(d->contentWidth, width)) return; @@ -166,6 +283,17 @@ void QQuickPane::setContentWidth(qreal width) emit contentWidthChanged(); } +void QQuickPane::resetContentWidth() +{ + Q_D(QQuickPane); + if (!d->hasContentWidth) + return; + + d->hasContentHeight = false; + if (d->updateContentWidth(d->contentItem)) + emit contentWidthChanged(); +} + /*! \qmlproperty real QtQuick.Controls::Pane::contentHeight @@ -185,6 +313,7 @@ qreal QQuickPane::contentHeight() const void QQuickPane::setContentHeight(qreal height) { Q_D(QQuickPane); + d->hasContentHeight = true; if (qFuzzyCompare(d->contentHeight, height)) return; @@ -192,6 +321,17 @@ void QQuickPane::setContentHeight(qreal height) emit contentHeightChanged(); } +void QQuickPane::resetContentHeight() +{ + Q_D(QQuickPane); + if (!d->hasContentHeight) + return; + + d->hasContentHeight = false; + if (d->updateContentHeight(d->contentItem)) + emit contentHeightChanged(); +} + /*! \qmlproperty list<Object> QtQuick.Controls::Pane::contentData \default @@ -239,11 +379,17 @@ QQmlListProperty<QQuickItem> QQuickPane::contentChildren() void QQuickPane::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) { + Q_D(QQuickPane); QQuickControl::contentItemChange(newItem, oldItem); - if (oldItem) - disconnect(oldItem, &QQuickItem::childrenChanged, this, &QQuickPane::contentChildrenChanged); - if (newItem) - connect(newItem, &QQuickItem::childrenChanged, this, &QQuickPane::contentChildrenChanged); + if (oldItem) { + d->removeImplicitSizeListener(oldItem); + QObjectPrivate::disconnect(oldItem, &QQuickItem::childrenChanged, d, &QQuickPanePrivate::contentChildrenChange); + } + if (newItem) { + d->addImplicitSizeListener(newItem); + QObjectPrivate::connect(newItem, &QQuickItem::childrenChanged, d, &QQuickPanePrivate::contentChildrenChange); + } + d->updateContentSize(newItem); emit contentChildrenChanged(); } diff --git a/src/quicktemplates2/qquickpane_p.h b/src/quicktemplates2/qquickpane_p.h index 759c59d8..53bf7067 100644 --- a/src/quicktemplates2/qquickpane_p.h +++ b/src/quicktemplates2/qquickpane_p.h @@ -58,20 +58,23 @@ class QQuickPanePrivate; class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPane : public QQuickControl { Q_OBJECT - Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged FINAL) - Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged FINAL) + Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth RESET resetContentWidth NOTIFY contentWidthChanged FINAL) + Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight RESET resetContentHeight NOTIFY contentHeightChanged FINAL) Q_PROPERTY(QQmlListProperty<QObject> contentData READ contentData FINAL) Q_PROPERTY(QQmlListProperty<QQuickItem> contentChildren READ contentChildren NOTIFY contentChildrenChanged FINAL) Q_CLASSINFO("DefaultProperty", "contentData") public: explicit QQuickPane(QQuickItem *parent = nullptr); + ~QQuickPane(); qreal contentWidth() const; void setContentWidth(qreal width); + void resetContentWidth(); qreal contentHeight() const; void setContentHeight(qreal height); + void resetContentHeight(); QQmlListProperty<QObject> contentData(); QQmlListProperty<QQuickItem> contentChildren(); diff --git a/src/quicktemplates2/qquickpane_p_p.h b/src/quicktemplates2/qquickpane_p_p.h index 16a07f08..4d9a1747 100644 --- a/src/quicktemplates2/qquickpane_p_p.h +++ b/src/quicktemplates2/qquickpane_p_p.h @@ -49,12 +49,13 @@ // #include <QtQuickTemplates2/private/qquickcontrol_p_p.h> +#include <QtQuick/private/qquickitemchangelistener_p.h> QT_BEGIN_NAMESPACE class QQuickPane; -class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPanePrivate : public QQuickControlPrivate +class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPanePrivate : public QQuickControlPrivate, public QQuickItemChangeListener { Q_DECLARE_PUBLIC(QQuickPane) @@ -63,6 +64,21 @@ public: QQuickItem *getContentItem() override; + void addImplicitSizeListener(QQuickItem *item); + void removeImplicitSizeListener(QQuickItem *item); + + void itemImplicitWidthChanged(QQuickItem *item) override; + void itemImplicitHeightChanged(QQuickItem *item) override; + void itemDestroyed(QQuickItem *item) override; + + void contentChildrenChange(); + + bool updateContentWidth(QQuickItem *item); + bool updateContentHeight(QQuickItem *item); + void updateContentSize(QQuickItem *item); + + bool hasContentWidth; + bool hasContentHeight; qreal contentWidth; qreal contentHeight; }; diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index e3ab952d..c21b8b68 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -1294,11 +1294,12 @@ void QQuickPopup::resetPadding() /*! \qmlproperty real QtQuick.Controls::Popup::topPadding - This property holds the top padding. + This property holds the top padding. Unless explicitly set, the value + is equal to \c verticalPadding. \include qquickpopup-padding.qdocinc - \sa padding, bottomPadding, availableHeight + \sa padding, bottomPadding, verticalPadding, availableHeight */ qreal QQuickPopup::topPadding() const { @@ -1321,11 +1322,12 @@ void QQuickPopup::resetTopPadding() /*! \qmlproperty real QtQuick.Controls::Popup::leftPadding - This property holds the left padding. + This property holds the left padding. Unless explicitly set, the value + is equal to \c horizontalPadding. \include qquickpopup-padding.qdocinc - \sa padding, rightPadding, availableWidth + \sa padding, rightPadding, horizontalPadding, availableWidth */ qreal QQuickPopup::leftPadding() const { @@ -1348,11 +1350,12 @@ void QQuickPopup::resetLeftPadding() /*! \qmlproperty real QtQuick.Controls::Popup::rightPadding - This property holds the right padding. + This property holds the right padding. Unless explicitly set, the value + is equal to \c horizontalPadding. \include qquickpopup-padding.qdocinc - \sa padding, leftPadding, availableWidth + \sa padding, leftPadding, horizontalPadding, availableWidth */ qreal QQuickPopup::rightPadding() const { @@ -1375,11 +1378,12 @@ void QQuickPopup::resetRightPadding() /*! \qmlproperty real QtQuick.Controls::Popup::bottomPadding - This property holds the bottom padding. + This property holds the bottom padding. Unless explicitly set, the value + is equal to \c verticalPadding. \include qquickpopup-padding.qdocinc - \sa padding, topPadding, availableHeight + \sa padding, topPadding, verticalPadding, availableHeight */ qreal QQuickPopup::bottomPadding() const { @@ -2087,6 +2091,64 @@ void QQuickPopup::setExit(QQuickTransition *transition) emit exitChanged(); } +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Popup::horizontalPadding + + This property holds the horizontal padding. Unless explicitly set, the value + is equal to \c padding. + + \include qquickpopup-padding.qdocinc + + \sa padding, leftPadding, rightPadding, verticalPadding +*/ +qreal QQuickPopup::horizontalPadding() const +{ + Q_D(const QQuickPopup); + return d->popupItem->horizontalPadding(); +} + +void QQuickPopup::setHorizontalPadding(qreal padding) +{ + Q_D(QQuickPopup); + d->popupItem->setHorizontalPadding(padding); +} + +void QQuickPopup::resetHorizontalPadding() +{ + Q_D(QQuickPopup); + d->popupItem->resetHorizontalPadding(); +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Popup::verticalPadding + + This property holds the vertical padding. Unless explicitly set, the value + is equal to \c padding. + + \include qquickpopup-padding.qdocinc + + \sa padding, topPadding, bottomPadding, horizontalPadding +*/ +qreal QQuickPopup::verticalPadding() const +{ + Q_D(const QQuickPopup); + return d->popupItem->verticalPadding(); +} + +void QQuickPopup::setVerticalPadding(qreal padding) +{ + Q_D(QQuickPopup); + d->popupItem->setVerticalPadding(padding); +} + +void QQuickPopup::resetVerticalPadding() +{ + Q_D(QQuickPopup); + d->popupItem->resetVerticalPadding(); +} + bool QQuickPopup::filtersChildMouseEvents() const { Q_D(const QQuickPopup); @@ -2337,10 +2399,14 @@ void QQuickPopup::paddingChange(const QMarginsF &newPadding, const QMarginsF &ol if (bp) emit bottomPaddingChanged(); - if (lp || rp) + if (lp || rp) { + emit horizontalPaddingChanged(); emit availableWidthChanged(); - if (tp || bp) + } + if (tp || bp) { + emit verticalPaddingChanged(); emit availableHeightChanged(); + } } void QQuickPopup::paletteChange(const QPalette &newPalette, const QPalette &oldPalette) @@ -2359,12 +2425,12 @@ void QQuickPopup::spacingChange(qreal newSpacing, qreal oldSpacing) QFont QQuickPopup::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::SystemFont); + return QQuickTheme::themeFont(QQuickTheme::SystemFont); } QPalette QQuickPopup::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::SystemPalette); + return QQuickTheme::themePalette(QQuickTheme::SystemPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickpopup_p.h b/src/quicktemplates2/qquickpopup_p.h index 2a42ff27..9e2f3649 100644 --- a/src/quicktemplates2/qquickpopup_p.h +++ b/src/quicktemplates2/qquickpopup_p.h @@ -121,6 +121,9 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPopup : public QObject, public QQml Q_PROPERTY(bool mirrored READ isMirrored NOTIFY mirroredChanged FINAL REVISION 3) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL REVISION 3) Q_PROPERTY(QPalette palette READ palette WRITE setPalette RESET resetPalette NOTIFY paletteChanged FINAL REVISION 3) + // 2.5 (Qt 5.12) + Q_PROPERTY(qreal horizontalPadding READ horizontalPadding WRITE setHorizontalPadding RESET resetHorizontalPadding NOTIFY horizontalPaddingChanged FINAL) + Q_PROPERTY(qreal verticalPadding READ verticalPadding WRITE setVerticalPadding RESET resetVerticalPadding NOTIFY verticalPaddingChanged FINAL) Q_CLASSINFO("DeferredPropertyNames", "background,contentItem") Q_CLASSINFO("DefaultProperty", "contentData") @@ -304,6 +307,15 @@ public: void setPalette(const QPalette &palette); void resetPalette(); + // 2.5 (Qt 5.12) + qreal horizontalPadding() const; + void setHorizontalPadding(qreal padding); + void resetHorizontalPadding(); + + qreal verticalPadding() const; + void setVerticalPadding(qreal padding); + void resetVerticalPadding(); + public Q_SLOTS: void open(); void close(); @@ -359,6 +371,9 @@ Q_SIGNALS: Q_REVISION(3) void mirroredChanged(); Q_REVISION(3) void enabledChanged(); Q_REVISION(3) void paletteChanged(); + // 2.5 (Qt 5.12) + Q_REVISION(5) void horizontalPaddingChanged(); + Q_REVISION(5) void verticalPaddingChanged(); protected: QQuickPopup(QQuickPopupPrivate &dd, QObject *parent); diff --git a/src/quicktemplates2/qquickpopupitem.cpp b/src/quicktemplates2/qquickpopupitem.cpp index 566a5245..5c906312 100644 --- a/src/quicktemplates2/qquickpopupitem.cpp +++ b/src/quicktemplates2/qquickpopupitem.cpp @@ -97,7 +97,7 @@ void QQuickPopupItemPrivate::resolveFont() if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(popup->window())) inheritFont(window->font()); else - inheritFont(themeFont(QPlatformTheme::SystemFont)); + inheritFont(QQuickTheme::themeFont(QQuickTheme::SystemFont)); } void QQuickPopupItemPrivate::resolvePalette() @@ -105,7 +105,7 @@ void QQuickPopupItemPrivate::resolvePalette() if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(popup->window())) inheritPalette(window->palette()); else - inheritPalette(themePalette(QPlatformTheme::SystemPalette)); + inheritPalette(QQuickTheme::themePalette(QQuickTheme::SystemPalette)); } QQuickItem *QQuickPopupItemPrivate::getContentItem() diff --git a/src/quicktemplates2/qquickproxytheme.cpp b/src/quicktemplates2/qquickproxytheme.cpp new file mode 100644 index 00000000..f6e8f773 --- /dev/null +++ b/src/quicktemplates2/qquickproxytheme.cpp @@ -0,0 +1,170 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickproxytheme_p.h" + +#include <QtGui/private/qguiapplication_p.h> +#include <QtGui/qpixmap.h> +#include <QtGui/qfont.h> + +QT_BEGIN_NAMESPACE + +QQuickProxyTheme::QQuickProxyTheme(QPlatformTheme *theme) + : m_theme(theme ? theme : QGuiApplicationPrivate::platform_theme) +{ +} + +QQuickProxyTheme::~QQuickProxyTheme() +{ + if (QGuiApplicationPrivate::platform_theme == this) + QGuiApplicationPrivate::platform_theme = m_theme; +} + +QPlatformTheme *QQuickProxyTheme::theme() const +{ + return m_theme; +} + +QPlatformMenuItem *QQuickProxyTheme::createPlatformMenuItem() const +{ + if (m_theme) + return m_theme->createPlatformMenuItem(); + return QPlatformTheme::createPlatformMenuItem(); +} + +QPlatformMenu *QQuickProxyTheme::createPlatformMenu() const +{ + if (m_theme) + return m_theme->createPlatformMenu(); + return QPlatformTheme::createPlatformMenu(); +} + +QPlatformMenuBar *QQuickProxyTheme::createPlatformMenuBar() const +{ + if (m_theme) + return m_theme->createPlatformMenuBar(); + return QPlatformTheme::createPlatformMenuBar(); +} + +void QQuickProxyTheme::showPlatformMenuBar() +{ + if (m_theme) + m_theme->showPlatformMenuBar(); + QPlatformTheme::showPlatformMenuBar(); +} + +bool QQuickProxyTheme::usePlatformNativeDialog(QPlatformTheme::DialogType type) const +{ + if (m_theme) + return m_theme->usePlatformNativeDialog(type); + return QPlatformTheme::usePlatformNativeDialog(type); +} + +QPlatformDialogHelper *QQuickProxyTheme::createPlatformDialogHelper(QPlatformTheme::DialogType type) const +{ + if (m_theme) + return m_theme->createPlatformDialogHelper(type); + return QPlatformTheme::createPlatformDialogHelper(type); +} + +#ifndef QT_NO_SYSTEMTRAYICON +QPlatformSystemTrayIcon *QQuickProxyTheme::createPlatformSystemTrayIcon() const +{ + if (m_theme) + return m_theme->createPlatformSystemTrayIcon(); + return QPlatformTheme::createPlatformSystemTrayIcon(); +} +#endif + +const QPalette *QQuickProxyTheme::palette(QPlatformTheme::Palette type) const +{ + if (m_theme) + return m_theme->palette(type); + return QPlatformTheme::palette(type); +} + +const QFont *QQuickProxyTheme::font(QPlatformTheme::Font type) const +{ + if (m_theme) + return m_theme->font(type); + return QPlatformTheme::font(type); +} + +QVariant QQuickProxyTheme::themeHint(QPlatformTheme::ThemeHint hint) const +{ + if (m_theme) + return m_theme->themeHint(hint); + return QPlatformTheme::themeHint(hint); +} + +QPixmap QQuickProxyTheme::standardPixmap(QPlatformTheme::StandardPixmap sp, const QSizeF &size) const +{ + if (m_theme) + return m_theme->standardPixmap(sp, size); + return QPlatformTheme::standardPixmap(sp, size); +} + +QIcon QQuickProxyTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions) const +{ + if (m_theme) + return m_theme->fileIcon(fileInfo, iconOptions); + return QPlatformTheme::fileIcon(fileInfo, iconOptions); +} + +QIconEngine *QQuickProxyTheme::createIconEngine(const QString &iconName) const +{ + if (m_theme) + return m_theme->createIconEngine(iconName); + return QPlatformTheme::createIconEngine(iconName); +} + +#if QT_CONFIG(shortcut) +QList<QKeySequence> QQuickProxyTheme::keyBindings(QKeySequence::StandardKey key) const +{ + if (m_theme) + return m_theme->keyBindings(key); + return QPlatformTheme::keyBindings(key); +} +#endif + +QString QQuickProxyTheme::standardButtonText(int button) const +{ + if (m_theme) + return m_theme->standardButtonText(button); + return QPlatformTheme::standardButtonText(button); +} + +QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquickproxytheme_p.h b/src/quicktemplates2/qquickproxytheme_p.h new file mode 100644 index 00000000..f580f6c5 --- /dev/null +++ b/src/quicktemplates2/qquickproxytheme_p.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKPROXYTHEME_P_H +#define QQUICKPROXYTHEME_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtGui/qpa/qplatformtheme.h> +#include <QtQuickTemplates2/private/qtquicktemplates2global_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickProxyTheme : public QPlatformTheme +{ +public: + explicit QQuickProxyTheme(QPlatformTheme *theme = nullptr); + ~QQuickProxyTheme(); + + QPlatformTheme* theme() const; + + QPlatformMenuItem* createPlatformMenuItem() const override; + QPlatformMenu* createPlatformMenu() const override; + QPlatformMenuBar* createPlatformMenuBar() const override; + void showPlatformMenuBar() override; + + bool usePlatformNativeDialog(DialogType type) const override; + QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const override; + +#ifndef QT_NO_SYSTEMTRAYICON + QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const override; +#endif + + const QPalette *palette(Palette type = SystemPalette) const override; + + const QFont *font(Font type = SystemFont) const override; + + QVariant themeHint(ThemeHint hint) const override; + + QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const override; + QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions = 0) const override; + + QIconEngine *createIconEngine(const QString &iconName) const override; + +#if QT_CONFIG(shortcut) + QList<QKeySequence> keyBindings(QKeySequence::StandardKey key) const override; +#endif + + QString standardButtonText(int button) const override; + +private: + QPlatformTheme *m_theme; +}; + +QT_END_NAMESPACE + +#endif // QQUICKPROXYTHEME_P_H diff --git a/src/quicktemplates2/qquickradiobutton.cpp b/src/quicktemplates2/qquickradiobutton.cpp index 86be3ed6..1d6f6771 100644 --- a/src/quicktemplates2/qquickradiobutton.cpp +++ b/src/quicktemplates2/qquickradiobutton.cpp @@ -99,12 +99,12 @@ QQuickRadioButton::QQuickRadioButton(QQuickItem *parent) QFont QQuickRadioButton::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::RadioButtonFont); + return QQuickTheme::themeFont(QQuickTheme::RadioButtonFont); } QPalette QQuickRadioButton::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::RadioButtonPalette); + return QQuickTheme::themePalette(QQuickTheme::RadioButtonPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickradiodelegate.cpp b/src/quicktemplates2/qquickradiodelegate.cpp index fe603d36..fb55ba7c 100644 --- a/src/quicktemplates2/qquickradiodelegate.cpp +++ b/src/quicktemplates2/qquickradiodelegate.cpp @@ -100,7 +100,7 @@ QQuickRadioDelegate::QQuickRadioDelegate(QQuickItem *parent) QFont QQuickRadioDelegate::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::ListViewFont); + return QQuickTheme::themeFont(QQuickTheme::ListViewFont); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickslider.cpp b/src/quicktemplates2/qquickslider.cpp index 5ad3c036..86e2445a 100644 --- a/src/quicktemplates2/qquickslider.cpp +++ b/src/quicktemplates2/qquickslider.cpp @@ -95,6 +95,7 @@ public: value(0), position(0), stepSize(0), + touchDragThreshold(-1), // in QQuickWindowPrivate::dragOverThreshold, '-1' implies using styleHints::startDragDistance() live(true), pressed(false), orientation(Qt::Horizontal), @@ -121,6 +122,7 @@ public: qreal value; qreal position; qreal stepSize; + qreal touchDragThreshold; bool live; bool pressed; QPointF pressPoint; @@ -636,6 +638,37 @@ void QQuickSlider::decrease() setValue(d->value - step); } +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty qreal QtQuick.Controls::Slider::touchDragThreshold + + This property holds the threshold (in logical pixels) at which a touch drag event will be initiated. + The mouse drag threshold won't be affected. + The default value is \c Qt.styleHints.startDragDistance. + + \sa QStyleHints +*/ +qreal QQuickSlider::touchDragThreshold() const +{ + Q_D(const QQuickSlider); + return d->touchDragThreshold; +} + +void QQuickSlider::setTouchDragThreshold(qreal touchDragThreshold) +{ + Q_D(QQuickSlider); + if (d->touchDragThreshold == touchDragThreshold) + return; + + d->touchDragThreshold = touchDragThreshold; + emit touchDragThresholdChanged(); +} + +void QQuickSlider::resetTouchDragThreshold() +{ + setTouchDragThreshold(-1); +} + void QQuickSlider::keyPressEvent(QKeyEvent *event) { Q_D(QQuickSlider); @@ -704,9 +737,9 @@ void QQuickSlider::touchEvent(QTouchEvent *event) case Qt::TouchPointMoved: if (!keepTouchGrab()) { if (d->orientation == Qt::Horizontal) - setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().x() - d->pressPoint.x(), Qt::XAxis, &point)); + setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().x() - d->pressPoint.x(), Qt::XAxis, &point, qRound(d->touchDragThreshold))); else - setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().y() - d->pressPoint.y(), Qt::YAxis, &point)); + setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().y() - d->pressPoint.y(), Qt::YAxis, &point, qRound(d->touchDragThreshold))); } if (keepTouchGrab()) d->handleMove(point.pos()); diff --git a/src/quicktemplates2/qquickslider_p.h b/src/quicktemplates2/qquickslider_p.h index ee6bcffa..847e15ec 100644 --- a/src/quicktemplates2/qquickslider_p.h +++ b/src/quicktemplates2/qquickslider_p.h @@ -72,7 +72,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSlider : public QQuickControl Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3) Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3) Q_CLASSINFO("DeferredPropertyNames", "background,handle") - + // 2.5 (Qt 5.12) + Q_PROPERTY(qreal touchDragThreshold READ touchDragThreshold WRITE setTouchDragThreshold RESET resetTouchDragThreshold NOTIFY touchDragThresholdChanged FINAL REVISION 5) public: explicit QQuickSlider(QQuickItem *parent = nullptr); @@ -121,6 +122,11 @@ public: bool isHorizontal() const; bool isVertical() const; + // 2.5 (Qt 5.12) + qreal touchDragThreshold() const; + void setTouchDragThreshold(qreal touchDragThreshold); + void resetTouchDragThreshold(); + public Q_SLOTS: void increase(); void decrease(); @@ -139,6 +145,8 @@ Q_SIGNALS: // 2.2 (Qt 5.9) Q_REVISION(2) void moved(); Q_REVISION(2) void liveChanged(); + // 2.5 (Qt 5.12) + Q_REVISION(5) void touchDragThresholdChanged(); protected: void keyPressEvent(QKeyEvent *event) override; diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp index 04bdec43..8aa8ed5f 100644 --- a/src/quicktemplates2/qquickspinbox.cpp +++ b/src/quicktemplates2/qquickspinbox.cpp @@ -1024,12 +1024,12 @@ void QQuickSpinBox::localeChange(const QLocale &newLocale, const QLocale &oldLoc QFont QQuickSpinBox::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::EditorFont); + return QQuickTheme::themeFont(QQuickTheme::EditorFont); } QPalette QQuickSpinBox::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::TextLineEditPalette); + return QQuickTheme::themePalette(QQuickTheme::TextLineEditPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp index dcf93437..6c3d804b 100644 --- a/src/quicktemplates2/qquickswipedelegate.cpp +++ b/src/quicktemplates2/qquickswipedelegate.cpp @@ -1230,7 +1230,7 @@ void QQuickSwipeDelegate::geometryChanged(const QRectF &newGeometry, const QRect QFont QQuickSwipeDelegate::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::ListViewFont); + return QQuickTheme::themeFont(QQuickTheme::ListViewFont); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickswitch.cpp b/src/quicktemplates2/qquickswitch.cpp index da1f0408..db71e423 100644 --- a/src/quicktemplates2/qquickswitch.cpp +++ b/src/quicktemplates2/qquickswitch.cpp @@ -234,7 +234,7 @@ void QQuickSwitch::buttonChange(ButtonChange change) QPalette QQuickSwitch::defaultPalette() const { // ### TODO: add QPlatformTheme::SwitchPalette - return QQuickControlPrivate::themePalette(QPlatformTheme::CheckBoxPalette); + return QQuickTheme::themePalette(QQuickTheme::CheckBoxPalette); } QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquickswitchdelegate.cpp b/src/quicktemplates2/qquickswitchdelegate.cpp index d8ce8096..8b673662 100644 --- a/src/quicktemplates2/qquickswitchdelegate.cpp +++ b/src/quicktemplates2/qquickswitchdelegate.cpp @@ -202,7 +202,7 @@ void QQuickSwitchDelegate::touchEvent(QTouchEvent *event) QFont QQuickSwitchDelegate::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::ListViewFont); + return QQuickTheme::themeFont(QQuickTheme::ListViewFont); } void QQuickSwitchDelegate::mirrorChange() diff --git a/src/quicktemplates2/qquicktabbar.cpp b/src/quicktemplates2/qquicktabbar.cpp index cd0c5c45..e2cd06fc 100644 --- a/src/quicktemplates2/qquicktabbar.cpp +++ b/src/quicktemplates2/qquicktabbar.cpp @@ -443,7 +443,7 @@ void QQuickTabBar::itemRemoved(int index, QQuickItem *item) QPalette QQuickTabBar::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::TabBarPalette); + return QQuickTheme::themePalette(QQuickTheme::TabBarPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquicktabbutton.cpp b/src/quicktemplates2/qquicktabbutton.cpp index 617d4aea..59905a63 100644 --- a/src/quicktemplates2/qquicktabbutton.cpp +++ b/src/quicktemplates2/qquicktabbutton.cpp @@ -72,12 +72,12 @@ QQuickTabButton::QQuickTabButton(QQuickItem *parent) QFont QQuickTabButton::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::TabButtonFont); + return QQuickTheme::themeFont(QQuickTheme::TabButtonFont); } QPalette QQuickTabButton::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::TabBarPalette); + return QQuickTheme::themePalette(QQuickTheme::TabBarPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquicktextarea.cpp b/src/quicktemplates2/qquicktextarea.cpp index 319f7bbe..fb724225 100644 --- a/src/quicktemplates2/qquicktextarea.cpp +++ b/src/quicktemplates2/qquicktextarea.cpp @@ -194,7 +194,7 @@ void QQuickTextAreaPrivate::inheritFont(const QFont &font) QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font; parentFont.resolve(extra.isAllocated() ? extra->requestedFont.resolve() | font.resolve() : font.resolve()); - const QFont defaultFont = QQuickControlPrivate::themeFont(QPlatformTheme::EditorFont); + const QFont defaultFont = QQuickTheme::themeFont(QQuickTheme::EditorFont); const QFont resolvedFont = parentFont.resolve(defaultFont); setFont_helper(resolvedFont); @@ -236,7 +236,7 @@ void QQuickTextAreaPrivate::inheritPalette(const QPalette &palette) QPalette parentPalette = extra.isAllocated() ? extra->requestedPalette.resolve(palette) : palette; parentPalette.resolve(extra.isAllocated() ? extra->requestedPalette.resolve() | palette.resolve() : palette.resolve()); - const QPalette defaultPalette = QQuickControlPrivate::themePalette(QPlatformTheme::TextEditPalette); + const QPalette defaultPalette = QQuickTheme::themePalette(QQuickTheme::TextEditPalette); const QPalette resolvedPalette = parentPalette.resolve(defaultPalette); setPalette_helper(resolvedPalette); @@ -566,6 +566,30 @@ void QQuickTextArea::setPlaceholderText(const QString &text) } /*! + \qmlproperty color QtQuick.Controls::TextArea::placeholderTextColor + \since QtQuick.Controls 2.5 (Qt 5.12) + + This property holds the color of placeholderText. + + \sa placeholderText +*/ +QColor QQuickTextArea::placeholderTextColor() const +{ + Q_D(const QQuickTextArea); + return d->placeholderColor; +} + +void QQuickTextArea::setPlaceholderTextColor(const QColor &color) +{ + Q_D(QQuickTextArea); + if (d->placeholderColor == color) + return; + + d->placeholderColor = color; + emit placeholderTextColorChanged(); +} + +/*! \qmlproperty enumeration QtQuick.Controls::TextArea::focusReason \include qquickcontrol-focusreason.qdocinc diff --git a/src/quicktemplates2/qquicktextarea_p.h b/src/quicktemplates2/qquicktextarea_p.h index 5482ceae..346438ea 100644 --- a/src/quicktemplates2/qquicktextarea_p.h +++ b/src/quicktemplates2/qquicktextarea_p.h @@ -74,6 +74,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTextArea : public QQuickTextEdit // 2.3 (Qt 5.10) Q_PROPERTY(QPalette palette READ palette WRITE setPalette RESET resetPalette NOTIFY paletteChanged FINAL REVISION 3) Q_CLASSINFO("DeferredPropertyNames", "background") + // 2.5 (Qt 5.12) + Q_PROPERTY(QColor placeholderTextColor READ placeholderTextColor WRITE setPlaceholderTextColor NOTIFY placeholderTextColorChanged FINAL REVISION 5) public: explicit QQuickTextArea(QQuickItem *parent = nullptr); @@ -108,6 +110,10 @@ public: void setPalette(const QPalette &palette); void resetPalette(); + // 2.5 (Qt 5.12) + QColor placeholderTextColor() const; + void setPlaceholderTextColor(const QColor &color); + Q_SIGNALS: void fontChanged(); void implicitWidthChanged3(); @@ -123,6 +129,8 @@ Q_SIGNALS: Q_REVISION(1) void hoverEnabledChanged(); // 2.3 (Qt 5.10) Q_REVISION(3) void paletteChanged(); + // 2.5 (Qt 5.12) + Q_REVISION(5) void placeholderTextColorChanged(); protected: void classBegin() override; diff --git a/src/quicktemplates2/qquicktextarea_p_p.h b/src/quicktemplates2/qquicktextarea_p_p.h index 8621c61c..c271660a 100644 --- a/src/quicktemplates2/qquicktextarea_p_p.h +++ b/src/quicktemplates2/qquicktextarea_p_p.h @@ -142,6 +142,7 @@ public: QPalette resolvedPalette; QQuickDeferredPointer<QQuickItem> background; QString placeholder; + QColor placeholderColor; Qt::FocusReason focusReason; QQuickPressHandler pressHandler; QQuickFlickable *flickable; diff --git a/src/quicktemplates2/qquicktextfield.cpp b/src/quicktemplates2/qquicktextfield.cpp index 49f9b4c8..385ea48e 100644 --- a/src/quicktemplates2/qquicktextfield.cpp +++ b/src/quicktemplates2/qquicktextfield.cpp @@ -168,7 +168,7 @@ void QQuickTextFieldPrivate::inheritFont(const QFont &font) QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font; parentFont.resolve(extra.isAllocated() ? extra->requestedFont.resolve() | font.resolve() : font.resolve()); - const QFont defaultFont = QQuickControlPrivate::themeFont(QPlatformTheme::EditorFont); + const QFont defaultFont = QQuickTheme::themeFont(QQuickTheme::EditorFont); const QFont resolvedFont = parentFont.resolve(defaultFont); setFont_helper(resolvedFont); @@ -210,7 +210,7 @@ void QQuickTextFieldPrivate::inheritPalette(const QPalette &palette) QPalette parentPalette = extra.isAllocated() ? extra->requestedPalette.resolve(palette) : palette; parentPalette.resolve(extra.isAllocated() ? extra->requestedPalette.resolve() | palette.resolve() : palette.resolve()); - const QPalette defaultPalette = QQuickControlPrivate::themePalette(QPlatformTheme::TextLineEditPalette); + const QPalette defaultPalette = QQuickTheme::themePalette(QQuickTheme::TextLineEditPalette); const QPalette resolvedPalette = parentPalette.resolve(defaultPalette); setPalette_helper(resolvedPalette); @@ -428,6 +428,30 @@ void QQuickTextField::setPlaceholderText(const QString &text) } /*! + \qmlproperty color QtQuick.Controls::TextField::placeholderTextColor + \since QtQuick.Controls 2.5 (Qt 5.12) + + This property holds the color of placeholderText. + + \sa placeholderText +*/ +QColor QQuickTextField::placeholderTextColor() const +{ + Q_D(const QQuickTextField); + return d->placeholderColor; +} + +void QQuickTextField::setPlaceholderTextColor(const QColor &color) +{ + Q_D(QQuickTextField); + if (d->placeholderColor == color) + return; + + d->placeholderColor = color; + emit placeholderTextColorChanged(); +} + +/*! \qmlproperty enumeration QtQuick.Controls::TextField::focusReason \include qquickcontrol-focusreason.qdocinc diff --git a/src/quicktemplates2/qquicktextfield_p.h b/src/quicktemplates2/qquicktextfield_p.h index 4757bd2d..b2e77342 100644 --- a/src/quicktemplates2/qquicktextfield_p.h +++ b/src/quicktemplates2/qquicktextfield_p.h @@ -73,6 +73,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTextField : public QQuickTextInput // 2.3 (Qt 5.10) Q_PROPERTY(QPalette palette READ palette WRITE setPalette RESET resetPalette NOTIFY paletteChanged FINAL REVISION 3) Q_CLASSINFO("DeferredPropertyNames", "background") + // 2.5 (Qt 5.12) + Q_PROPERTY(QColor placeholderTextColor READ placeholderTextColor WRITE setPlaceholderTextColor NOTIFY placeholderTextColorChanged FINAL REVISION 5) public: explicit QQuickTextField(QQuickItem *parent = nullptr); @@ -101,6 +103,9 @@ public: QPalette palette() const; void setPalette(const QPalette &palette); void resetPalette(); + // 2.5 (Qt 5.12) + QColor placeholderTextColor() const; + void setPlaceholderTextColor(const QColor &color); Q_SIGNALS: void fontChanged(); @@ -117,6 +122,8 @@ Q_SIGNALS: Q_REVISION(1) void hoverEnabledChanged(); // 2.3 (Qt 5.10) Q_REVISION(3) void paletteChanged(); + // 2.5 (Qt 5.12) + Q_REVISION(5) void placeholderTextColorChanged(); protected: void classBegin() override; diff --git a/src/quicktemplates2/qquicktextfield_p_p.h b/src/quicktemplates2/qquicktextfield_p_p.h index 41843370..13a20e32 100644 --- a/src/quicktemplates2/qquicktextfield_p_p.h +++ b/src/quicktemplates2/qquicktextfield_p_p.h @@ -130,6 +130,7 @@ public: QPalette resolvedPalette; QQuickDeferredPointer<QQuickItem> background; QString placeholder; + QColor placeholderColor; Qt::FocusReason focusReason; QQuickPressHandler pressHandler; }; diff --git a/src/quicktemplates2/qquicktheme.cpp b/src/quicktemplates2/qquicktheme.cpp new file mode 100644 index 00000000..02389ed0 --- /dev/null +++ b/src/quicktemplates2/qquicktheme.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquicktheme_p.h" +#include "qquicktheme_p_p.h" + +#include <QtGui/qpa/qplatformtheme.h> +#include <QtGui/private/qguiapplication_p.h> + +QT_BEGIN_NAMESPACE + +QScopedPointer<QQuickTheme> QQuickThemePrivate::current; + +QQuickTheme::QQuickTheme() + : d_ptr(new QQuickThemePrivate) +{ +} + +QQuickTheme::~QQuickTheme() +{ +} + +QQuickTheme *QQuickTheme::current() +{ + return QQuickThemePrivate::current.data(); +} + +void QQuickTheme::setCurrent(QQuickTheme *theme) +{ + QQuickThemePrivate::current.reset(theme); +} + +QFont QQuickTheme::themeFont(Font type) +{ + const QFont *font = nullptr; + if (QQuickTheme *theme = current()) + font = theme->font(type); + else if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + font = theme->font(static_cast<QPlatformTheme::Font>(type)); + + if (font) { + QFont f = *font; + if (type == SystemFont) + f.resolve(0); + return f; + } + + return QFont(); +} + +QPalette QQuickTheme::themePalette(Palette type) +{ + const QPalette *palette = nullptr; + if (QQuickTheme *theme = current()) + palette = theme->palette(type); + else if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + palette = theme->palette(static_cast<QPlatformTheme::Palette>(type)); + + if (palette) { + QPalette f = *palette; + if (type == SystemPalette) + f.resolve(0); + return f; + } + + return QPalette(); +} + +const QFont *QQuickTheme::font(Font type) const +{ + Q_D(const QQuickTheme); + Q_UNUSED(type) + return d->defaultFont.data(); +} + +const QPalette *QQuickTheme::palette(Palette type) const +{ + Q_D(const QQuickTheme); + Q_UNUSED(type) + return d->defaultPalette.data(); +} + +void QQuickTheme::setDefaultFont(const QFont *defaultFont) +{ + Q_D(QQuickTheme); + d->defaultFont.reset(defaultFont); + resolveFonts(defaultFont ? *defaultFont : QFont()); +} + +void QQuickTheme::setDefaultPalette(const QPalette *defaultPalette) +{ + Q_D(QQuickTheme); + d->defaultPalette.reset(defaultPalette); + resolvePalettes(defaultPalette ? *defaultPalette : QPalette()); +} + +void QQuickTheme::resolveFonts(const QFont &defaultFont) +{ + Q_UNUSED(defaultFont) +} + +void QQuickTheme::resolvePalettes(const QPalette &defaultPalette) +{ + Q_UNUSED(defaultPalette) +} + +QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquicktheme_p.h b/src/quicktemplates2/qquicktheme_p.h new file mode 100644 index 00000000..f4efd359 --- /dev/null +++ b/src/quicktemplates2/qquicktheme_p.h @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKTHEME_P_H +#define QQUICKTHEME_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtQuickTemplates2/private/qtquicktemplates2global_p.h> +#include <QtCore/qscopedpointer.h> +#include <QtGui/qfont.h> +#include <QtGui/qpalette.h> + +QT_BEGIN_NAMESPACE + +class QQuickThemePrivate; + +class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTheme +{ +public: + QQuickTheme(); + virtual ~QQuickTheme(); + + static QQuickTheme *current(); + static void setCurrent(QQuickTheme *theme); + + enum Font { + SystemFont, + MenuFont, + MenuBarFont, + MenuItemFont, + MessageBoxFont, + LabelFont, + TipLabelFont, + StatusBarFont, + TitleBarFont, + MdiSubWindowTitleFont, + DockWidgetTitleFont, + PushButtonFont, + CheckBoxFont, + RadioButtonFont, + ToolButtonFont, + ItemViewFont, + ListViewFont, + HeaderViewFont, + ListBoxFont, + ComboMenuItemFont, + ComboLineEditFont, + SmallFont, + MiniFont, + FixedFont, + GroupBoxTitleFont, + TabButtonFont, + EditorFont, + NFonts + }; + + enum Palette { + SystemPalette, + ToolTipPalette, + ToolButtonPalette, + ButtonPalette, + CheckBoxPalette, + RadioButtonPalette, + HeaderPalette, + ComboBoxPalette, + ItemViewPalette, + MessageBoxLabelPelette, + MessageBoxLabelPalette = MessageBoxLabelPelette, + TabBarPalette, + LabelPalette, + GroupBoxPalette, + MenuPalette, + MenuBarPalette, + TextEditPalette, + TextLineEditPalette, + NPalettes + }; + + static QFont themeFont(Font type); + static QPalette themePalette(Palette type); + + virtual const QFont *font(Font type = SystemFont) const; + virtual const QPalette *palette(Palette type = SystemPalette) const; + + void setDefaultFont(const QFont *defaultFont); + void setDefaultPalette(const QPalette *defaultPalette); + +protected: + virtual void resolveFonts(const QFont &defaultFont); + virtual void resolvePalettes(const QPalette &defaultPalette); + +private: + Q_DISABLE_COPY(QQuickTheme) + Q_DECLARE_PRIVATE(QQuickTheme) + QScopedPointer<QQuickThemePrivate> d_ptr; +}; + +QT_END_NAMESPACE + +#endif // QQUICKTHEME_P_H diff --git a/src/quicktemplates2/qquicktheme_p_p.h b/src/quicktemplates2/qquicktheme_p_p.h new file mode 100644 index 00000000..b8cdc4aa --- /dev/null +++ b/src/quicktemplates2/qquicktheme_p_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKTHEME_P_P_H +#define QQUICKTHEME_P_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtQuickTemplates2/private/qquicktheme_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickThemePrivate +{ +public: + static QQuickThemePrivate *get(QQuickTheme *theme) + { + return theme->d_func(); + } + + static QScopedPointer<QQuickTheme> current; + QScopedPointer<const QFont> defaultFont; + QScopedPointer<const QPalette> defaultPalette; +}; + +QT_END_NAMESPACE + +#endif // QQUICKTHEME_P_P_H diff --git a/src/quicktemplates2/qquicktoolbar.cpp b/src/quicktemplates2/qquicktoolbar.cpp index 99775c6a..77288547 100644 --- a/src/quicktemplates2/qquicktoolbar.cpp +++ b/src/quicktemplates2/qquicktoolbar.cpp @@ -143,7 +143,7 @@ void QQuickToolBar::setPosition(Position position) QPalette QQuickToolBar::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::ToolButtonPalette); + return QQuickTheme::themePalette(QQuickTheme::ToolButtonPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquicktoolbutton.cpp b/src/quicktemplates2/qquicktoolbutton.cpp index f87a58b2..7a44792b 100644 --- a/src/quicktemplates2/qquicktoolbutton.cpp +++ b/src/quicktemplates2/qquicktoolbutton.cpp @@ -71,12 +71,12 @@ QQuickToolButton::QQuickToolButton(QQuickItem *parent) QFont QQuickToolButton::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::ToolButtonFont); + return QQuickTheme::themeFont(QQuickTheme::ToolButtonFont); } QPalette QQuickToolButton::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::ToolButtonPalette); + return QQuickTheme::themePalette(QQuickTheme::ToolButtonPalette); } QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquicktoolseparator.cpp b/src/quicktemplates2/qquicktoolseparator.cpp index 2ec7799f..80d5fc86 100644 --- a/src/quicktemplates2/qquicktoolseparator.cpp +++ b/src/quicktemplates2/qquicktoolseparator.cpp @@ -135,7 +135,7 @@ bool QQuickToolSeparator::isVertical() const QPalette QQuickToolSeparator::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::ToolButtonPalette); + return QQuickTheme::themePalette(QQuickTheme::ToolButtonPalette); } #if QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp index 1bf6ca55..b186d2b0 100644 --- a/src/quicktemplates2/qquicktooltip.cpp +++ b/src/quicktemplates2/qquicktooltip.cpp @@ -276,14 +276,39 @@ QQuickToolTipAttached *QQuickToolTip::qmlAttachedProperties(QObject *object) return new QQuickToolTipAttached(object); } +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlmethod void QtQuick.Controls::ToolTip::show(string text, int timeout = -1) + + This method shows the tooltip with \a text and \a timeout (milliseconds). +*/ +void QQuickToolTip::show(const QString &text, int ms) +{ + if (ms >= 0) + setTimeout(ms); + setText(text); + open(); +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlmethod void QtQuick.Controls::ToolTip::hide() + + This method hides the tooltip. +*/ +void QQuickToolTip::hide() +{ + close(); +} + QFont QQuickToolTip::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::TipLabelFont); + return QQuickTheme::themeFont(QQuickTheme::TipLabelFont); } QPalette QQuickToolTip::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::ToolTipPalette); + return QQuickTheme::themePalette(QQuickTheme::ToolTipPalette); } void QQuickToolTip::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) @@ -520,10 +545,8 @@ void QQuickToolTipAttached::show(const QString &text, int ms) tip->resetWidth(); tip->resetHeight(); tip->setParentItem(qobject_cast<QQuickItem *>(parent())); - tip->setTimeout(ms >= 0 ? ms : d->timeout); tip->setDelay(d->delay); - tip->setText(text); - tip->open(); + tip->show(text, ms >= 0 ? ms : d->timeout); } /*! diff --git a/src/quicktemplates2/qquicktooltip_p.h b/src/quicktemplates2/qquicktooltip_p.h index 60b02502..432bdd8e 100644 --- a/src/quicktemplates2/qquicktooltip_p.h +++ b/src/quicktemplates2/qquicktooltip_p.h @@ -84,6 +84,10 @@ Q_SIGNALS: void delayChanged(); void timeoutChanged(); +public Q_SLOTS: + Q_REVISION(5) void show(const QString &text, int ms = -1); + Q_REVISION(5) void hide(); + protected: QFont defaultFont() const override; QPalette defaultPalette() const override; diff --git a/src/quicktemplates2/qquicktumbler.cpp b/src/quicktemplates2/qquicktumbler.cpp index efa61dad..fa3a5ce4 100644 --- a/src/quicktemplates2/qquicktumbler.cpp +++ b/src/quicktemplates2/qquicktumbler.cpp @@ -70,7 +70,8 @@ QT_BEGIN_NAMESPACE The API is similar to that of views like \l ListView and \l PathView; a \l model and \l delegate can be set, and the \l count and \l currentItem - properties provide read-only access to information about the view. + properties provide read-only access to information about the view. To + position the view at a certain index, use \l positionViewAtIndex(). Unlike views like \l PathView and \l ListView, however, there is always a current item (when the model isn't empty). This means that when \l count is @@ -350,6 +351,8 @@ int QQuickTumbler::count() const The value of this property is \c -1 when \l count is equal to \c 0. In all other cases, it will be greater than or equal to \c 0. + + \sa currentItem, positionViewAtIndex() */ int QQuickTumbler::currentIndex() const { @@ -410,6 +413,8 @@ void QQuickTumbler::setCurrentIndex(int currentIndex) \readonly This property holds the item at the current index. + + \sa currentIndex, positionViewAtIndex() */ QQuickItem *QQuickTumbler::currentItem() const { @@ -511,6 +516,41 @@ bool QQuickTumbler::isMoving() const return d->view && d->view->property("moving").toBool(); } +/*! + \qmlmethod void QtQuick.Controls::Tumbler::positionViewAtIndex(int index, PositionMode mode) + \since QtQuick.Controls 2.5 (Qt 5.12) + + Positions the view so that the \a index is at the position specified by \a mode. + + For example: + + \code + positionViewAtIndex(10, Tumbler.Center) + \endcode + + If \l wrap is true (the default), the modes available to \l {PathView}'s + \l {PathView::}{positionViewAtIndex()} function + are available, otherwise the modes available to \l {ListView}'s + \l {ListView::}{positionViewAtIndex()} function + are available. + + \note There is a known limitation that using \c Tumbler.Beginning when \l + wrap is \c true will result in the wrong item being positioned at the top + of view. As a workaround, pass \c {index - 1}. + + \sa currentIndex +*/ +void QQuickTumbler::positionViewAtIndex(int index, QQuickTumbler::PositionMode mode) +{ + Q_D(QQuickTumbler); + if (!d->view) { + d->warnAboutIncorrectContentItem(); + return; + } + + QMetaObject::invokeMethod(d->view, "positionViewAtIndex", Q_ARG(int, index), Q_ARG(int, mode)); +} + void QQuickTumbler::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_D(QQuickTumbler); @@ -609,7 +649,7 @@ void QQuickTumblerPrivate::setupViewData(QQuickItem *newControlContentItem) return; if (viewContentItemType == QQuickTumblerPrivate::UnsupportedContentItemType) { - qWarning() << "Tumbler: contentItem must contain either a PathView or a ListView"; + warnAboutIncorrectContentItem(); return; } @@ -636,6 +676,12 @@ void QQuickTumblerPrivate::setupViewData(QQuickItem *newControlContentItem) calculateDisplacements(); } +void QQuickTumblerPrivate::warnAboutIncorrectContentItem() +{ + Q_Q(QQuickTumbler); + qmlWarning(q) << "Tumbler: contentItem must contain either a PathView or a ListView"; +} + void QQuickTumblerPrivate::syncCurrentIndex() { const int actualViewIndex = view->property("currentIndex").toInt(); @@ -784,12 +830,12 @@ void QQuickTumbler::updatePolish() QFont QQuickTumbler::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::ItemViewFont); + return QQuickTheme::themeFont(QQuickTheme::ItemViewFont); } QPalette QQuickTumbler::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::ItemViewPalette); + return QQuickTheme::themePalette(QQuickTheme::ItemViewPalette); } QQuickTumblerAttachedPrivate::QQuickTumblerAttachedPrivate() diff --git a/src/quicktemplates2/qquicktumbler_p.h b/src/quicktemplates2/qquicktumbler_p.h index 5d4df4a7..3f7c06db 100644 --- a/src/quicktemplates2/qquicktumbler_p.h +++ b/src/quicktemplates2/qquicktumbler_p.h @@ -100,6 +100,19 @@ public: // 2.2 (Qt 5.9) bool isMoving() const; + enum PositionMode { + Beginning, + Center, + End, + Visible, // ListView-only + Contain, + SnapPosition + }; + Q_ENUM(PositionMode) + + // 2.5 (Qt 5.12) + Q_REVISION(5) Q_INVOKABLE void positionViewAtIndex(int index, PositionMode mode); + Q_SIGNALS: void modelChanged(); void countChanged(); diff --git a/src/quicktemplates2/qquicktumbler_p_p.h b/src/quicktemplates2/qquicktumbler_p_p.h index 75b1a396..6f0879b3 100644 --- a/src/quicktemplates2/qquicktumbler_p_p.h +++ b/src/quicktemplates2/qquicktumbler_p_p.h @@ -105,6 +105,7 @@ public: void disconnectFromView(); void setupViewData(QQuickItem *newControlContentItem); + void warnAboutIncorrectContentItem(); void syncCurrentIndex(); void setCount(int newCount); diff --git a/src/quicktemplates2/quicktemplates2.pri b/src/quicktemplates2/quicktemplates2.pri index b2193ec0..c9ccc420 100644 --- a/src/quicktemplates2/quicktemplates2.pri +++ b/src/quicktemplates2/quicktemplates2.pri @@ -59,6 +59,7 @@ HEADERS += \ $$PWD/qquickpopuppositioner_p_p.h \ $$PWD/qquickpresshandler_p_p.h \ $$PWD/qquickprogressbar_p.h \ + $$PWD/qquickproxytheme_p.h \ $$PWD/qquickradiobutton_p.h \ $$PWD/qquickradiodelegate_p.h \ $$PWD/qquickrangeslider_p.h \ @@ -86,6 +87,8 @@ HEADERS += \ $$PWD/qquicktextarea_p_p.h \ $$PWD/qquicktextfield_p.h \ $$PWD/qquicktextfield_p_p.h \ + $$PWD/qquicktheme_p.h \ + $$PWD/qquicktheme_p_p.h \ $$PWD/qquicktoolbar_p.h \ $$PWD/qquicktoolbutton_p.h \ $$PWD/qquicktoolseparator_p.h \ @@ -133,6 +136,7 @@ SOURCES += \ $$PWD/qquickpopuppositioner.cpp \ $$PWD/qquickpresshandler.cpp \ $$PWD/qquickprogressbar.cpp \ + $$PWD/qquickproxytheme.cpp \ $$PWD/qquickradiobutton.cpp \ $$PWD/qquickradiodelegate.cpp \ $$PWD/qquickrangeslider.cpp \ @@ -155,6 +159,7 @@ SOURCES += \ $$PWD/qquicktabbutton.cpp \ $$PWD/qquicktextarea.cpp \ $$PWD/qquicktextfield.cpp \ + $$PWD/qquicktheme.cpp \ $$PWD/qquicktoolbar.cpp \ $$PWD/qquicktoolbutton.cpp \ $$PWD/qquicktoolseparator.cpp \ |