diff options
Diffstat (limited to 'src/quicktemplates2/qquickcontrol.cpp')
-rw-r--r-- | src/quicktemplates2/qquickcontrol.cpp | 776 |
1 files changed, 678 insertions, 98 deletions
diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp index 4ac12dc4..26e28ebe 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 @@ -79,15 +76,48 @@ QT_BEGIN_NAMESPACE The \l {Item::}{implicitWidth} and \l {Item::}{implicitHeight} of a control are typically based on the implicit sizes of the background and the content - item plus any \l {Control::}{padding}. These properties determine how large + item plus any insets and paddings. These properties determine how large the control will be when no explicit \l {Item::}{width} or \l {Item::}{height} is specified. + The geometry of the \l {Control::}{contentItem} is determined by the padding. + The following example reserves 10px padding between the boundaries of the + control and its content: + + \code + Control { + padding: 10 + + contentItem: Text { + text: "Content" + } + } + \endcode + The \l {Control::}{background} item fills the entire width and height of the - control, unless an explicit size has been given for it. + control, unless insets or an explicit size have been given for it. Background + insets are useful for extending the touchable/interactive area of a control + without affecting its visual size. This is often used on touch devices to + ensure that a control is not too small to be interacted with by the user. + Insets affect the size of the control, and hence will affect how much space + they take up in a layout, for example. - The geometry of the \l {Control::}{contentItem} is determined by the - padding. + Negative insets can be used to make the background larger than the control. + The following example uses negative insets to place a shadow outside the + control's boundaries: + + \code + Control { + topInset: -2 + leftInset: -2 + rightInset: -6 + bottomInset: -6 + + background: BorderImage { + source: ":/images/shadowed-background.png" + } + } + \endcode \section1 Event Handling @@ -100,6 +130,8 @@ QT_BEGIN_NAMESPACE \sa ApplicationWindow, Container */ +const QQuickItemPrivate::ChangeTypes QQuickControlPrivate::ImplicitSizeChanges = QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed; + static bool isKeyFocusReason(Qt::FocusReason reason) { return reason == Qt::TabFocusReason || reason == Qt::BacktabFocusReason || reason == Qt::ShortcutFocusReason; @@ -119,6 +151,12 @@ QQuickControlPrivate::~QQuickControlPrivate() #endif } +void QQuickControlPrivate::init() +{ + Q_Q(QQuickControl); + QObject::connect(q, &QQuickItem::baselineOffsetChanged, q, &QQuickControl::baselineOffsetChanged); +} + #if QT_CONFIG(quicktemplates2_multitouch) bool QQuickControlPrivate::acceptTouch(const QTouchEvent::TouchPoint &point) { @@ -182,75 +220,163 @@ 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::resizeBackground() +void QQuickControlPrivate::setHorizontalPadding(qreal value, bool reset) { Q_Q(QQuickControl); - if (background) { - QQuickItemPrivate *p = QQuickItemPrivate::get(background); - if (!p->widthValid && qFuzzyIsNull(background->x())) { - background->setWidth(q->width()); - p->widthValid = false; - } - if (!p->heightValid && qFuzzyIsNull(background->y())) { - background->setHeight(q->height()); - p->heightValid = false; - } + 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); + } +} + +void QQuickControlPrivate::setTopInset(qreal value, bool reset) +{ + Q_Q(QQuickControl); + const QMarginsF oldInset = getInset(); + extra.value().topInset = value; + extra.value().hasTopInset = !reset; + if (!qFuzzyCompare(oldInset.top(), value)) { + emit q->topInsetChanged(); + q->insetChange(getInset(), oldInset); + } +} + +void QQuickControlPrivate::setLeftInset(qreal value, bool reset) +{ + Q_Q(QQuickControl); + const QMarginsF oldInset = getInset(); + extra.value().leftInset = value; + extra.value().hasLeftInset = !reset; + if (!qFuzzyCompare(oldInset.left(), value)) { + emit q->leftInsetChanged(); + q->insetChange(getInset(), oldInset); + } +} + +void QQuickControlPrivate::setRightInset(qreal value, bool reset) +{ + Q_Q(QQuickControl); + const QMarginsF oldInset = getInset(); + extra.value().rightInset = value; + extra.value().hasRightInset = !reset; + if (!qFuzzyCompare(oldInset.right(), value)) { + emit q->rightInsetChanged(); + q->insetChange(getInset(), oldInset); + } +} + +void QQuickControlPrivate::setBottomInset(qreal value, bool reset) +{ + Q_Q(QQuickControl); + const QMarginsF oldInset = getInset(); + extra.value().bottomInset = value; + extra.value().hasBottomInset = !reset; + if (!qFuzzyCompare(oldInset.bottom(), value)) { + emit q->bottomInsetChanged(); + q->insetChange(getInset(), oldInset); + } +} + +void QQuickControlPrivate::resizeBackground() +{ + if (!background) + return; + + resizingBackground = true; + + QQuickItemPrivate *p = QQuickItemPrivate::get(background); + if (((!p->widthValid || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x())) + || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) { + background->setX(getLeftInset()); + background->setWidth(width - getLeftInset() - getRightInset()); + } + if (((!p->heightValid || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y())) + || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) { + background->setY(getTopInset()); + background->setHeight(height - getTopInset() - getBottomInset()); + } + + resizingBackground = false; +} + void QQuickControlPrivate::resizeContent() { Q_Q(QQuickControl); @@ -276,21 +402,73 @@ void QQuickControlPrivate::setContentItem_helper(QQuickItem *item, bool notify) if (!contentItem.isExecuting()) cancelContentItem(); - q->contentItemChange(item, contentItem); - delete contentItem; + QQuickItem *oldContentItem = contentItem; + if (oldContentItem) { + disconnect(oldContentItem, &QQuickItem::baselineOffsetChanged, this, &QQuickControlPrivate::updateBaselineOffset); + removeImplicitSizeListener(oldContentItem); + } + contentItem = item; + q->contentItemChange(item, oldContentItem); + delete oldContentItem; if (item) { + connect(contentItem, &QQuickItem::baselineOffsetChanged, this, &QQuickControlPrivate::updateBaselineOffset); if (!item->parentItem()) item->setParentItem(q); if (componentComplete) resizeContent(); + addImplicitSizeListener(contentItem); } + updateImplicitContentSize(); + updateBaselineOffset(); + if (notify && !contentItem.isExecuting()) emit q->contentItemChanged(); } +qreal QQuickControlPrivate::getContentWidth() const +{ + return contentItem ? contentItem->implicitWidth() : 0; +} + +qreal QQuickControlPrivate::getContentHeight() const +{ + return contentItem ? contentItem->implicitHeight() : 0; +} + +void QQuickControlPrivate::updateImplicitContentWidth() +{ + Q_Q(QQuickControl); + const qreal oldWidth = implicitContentWidth; + implicitContentWidth = getContentWidth(); + if (!qFuzzyCompare(implicitContentWidth, oldWidth)) + emit q->implicitContentWidthChanged(); +} + +void QQuickControlPrivate::updateImplicitContentHeight() +{ + Q_Q(QQuickControl); + const qreal oldHeight = implicitContentHeight; + implicitContentHeight = getContentHeight(); + if (!qFuzzyCompare(implicitContentHeight, oldHeight)) + emit q->implicitContentHeightChanged(); +} + +void QQuickControlPrivate::updateImplicitContentSize() +{ + Q_Q(QQuickControl); + const qreal oldWidth = implicitContentWidth; + const qreal oldHeight = implicitContentHeight; + implicitContentWidth = getContentWidth(); + implicitContentHeight = getContentHeight(); + if (!qFuzzyCompare(implicitContentWidth, oldWidth)) + emit q->implicitContentWidthChanged(); + if (!qFuzzyCompare(implicitContentHeight, oldHeight)) + emit q->implicitContentHeightChanged(); +} + #if QT_CONFIG(accessibility) void QQuickControlPrivate::accessibilityActiveChanged(bool active) { @@ -337,21 +515,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::font(QQuickTheme::System); } /*! @@ -442,21 +606,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::palette(QQuickTheme::System); } /*! @@ -672,14 +822,108 @@ void QQuickControlPrivate::executeBackground(bool complete) quickCompleteDeferred(q, backgroundName(), background); } +void QQuickControlPrivate::updateBaselineOffset() +{ + Q_Q(QQuickControl); + if (extra.isAllocated() && extra.value().hasBaselineOffset) + return; + + if (!contentItem) + q->QQuickItem::setBaselineOffset(0); + else + q->QQuickItem::setBaselineOffset(getTopPadding() + contentItem->baselineOffset()); +} + +void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item, ChangeTypes changes) +{ + addImplicitSizeListener(item, this, changes); +} + +void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item, ChangeTypes changes) +{ + removeImplicitSizeListener(item, this, changes); +} + +void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes) +{ + if (!item || !listener) + return; + QQuickItemPrivate::get(item)->addItemChangeListener(listener, changes); +} + +void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes) +{ + if (!item || !listener) + return; + QQuickItemPrivate::get(item)->removeItemChangeListener(listener, changes); +} + +void QQuickControlPrivate::itemImplicitWidthChanged(QQuickItem *item) +{ + Q_Q(QQuickControl); + if (item == background) + emit q->implicitBackgroundWidthChanged(); + else if (item == contentItem) + updateImplicitContentWidth(); +} + +void QQuickControlPrivate::itemImplicitHeightChanged(QQuickItem *item) +{ + Q_Q(QQuickControl); + if (item == background) + emit q->implicitBackgroundHeightChanged(); + else if (item == contentItem) + updateImplicitContentHeight(); +} + +void QQuickControlPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) +{ + Q_UNUSED(diff); + if (resizingBackground || item != background || !change.sizeChange()) + return; + + QQuickItemPrivate *p = QQuickItemPrivate::get(item); + // Only set hasBackgroundWidth/Height if it was a width/height change, + // otherwise we're prevented from setting a width/height in the future. + if (change.widthChange()) + extra.value().hasBackgroundWidth = p->widthValid; + if (change.heightChange()) + extra.value().hasBackgroundHeight = p->heightValid; + resizeBackground(); +} + +void QQuickControlPrivate::itemDestroyed(QQuickItem *item) +{ + Q_Q(QQuickControl); + if (item == background) { + background = nullptr; + emit q->implicitBackgroundWidthChanged(); + emit q->implicitBackgroundHeightChanged(); + } else if (item == contentItem) { + contentItem = nullptr; + updateImplicitContentSize(); + } +} + QQuickControl::QQuickControl(QQuickItem *parent) : QQuickItem(*(new QQuickControlPrivate), parent) { + Q_D(QQuickControl); + d->init(); } QQuickControl::QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent) : QQuickItem(dd, parent) { + Q_D(QQuickControl); + d->init(); +} + +QQuickControl::~QQuickControl() +{ + Q_D(QQuickControl); + d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry); + d->removeImplicitSizeListener(d->contentItem); } void QQuickControl::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) @@ -861,10 +1105,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())) @@ -873,10 +1125,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); } @@ -888,16 +1145,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) @@ -915,16 +1171,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) @@ -942,16 +1197,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) @@ -969,16 +1223,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) @@ -1311,15 +1564,36 @@ void QQuickControl::setBackground(QQuickItem *background) if (!d->background.isExecuting()) d->cancelBackground(); + const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth(); + const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight(); + + if (d->extra.isAllocated()) { + d->extra.value().hasBackgroundWidth = false; + d->extra.value().hasBackgroundHeight = false; + } + + d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry); delete d->background; d->background = background; + if (background) { background->setParentItem(this); if (qFuzzyIsNull(background->z())) background->setZ(-1); + QQuickItemPrivate *p = QQuickItemPrivate::get(background); + if (p->widthValid || p->heightValid) { + d->extra.value().hasBackgroundWidth = p->widthValid; + d->extra.value().hasBackgroundHeight = p->heightValid; + } if (isComponentComplete()) d->resizeBackground(); + d->addImplicitSizeListener(background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry); } + + if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth())) + emit implicitBackgroundWidthChanged(); + if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight())) + emit implicitBackgroundHeightChanged(); if (!d->background.isExecuting()) emit backgroundChanged(); } @@ -1366,6 +1640,30 @@ void QQuickControl::setContentItem(QQuickItem *item) d->setContentItem_helper(item, true); } +qreal QQuickControl::baselineOffset() const +{ + Q_D(const QQuickControl); + return d->baselineOffset; +} + +void QQuickControl::setBaselineOffset(qreal offset) +{ + Q_D(QQuickControl); + d->extra.value().hasBaselineOffset = true; + QQuickItem::setBaselineOffset(offset); +} + +void QQuickControl::resetBaselineOffset() +{ + Q_D(QQuickControl); + if (!d->extra.isAllocated() || !d->extra.value().hasBaselineOffset) + return; + + if (d->extra.isAllocated()) + d->extra.value().hasBaselineOffset = false; + d->updateBaselineOffset(); +} + /*! \since QtQuick.Controls 2.3 (Qt 5.10) \qmlproperty palette QtQuick.Controls::Control::palette @@ -1435,6 +1733,278 @@ 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); +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Control::implicitContentWidth + \readonly + + This property holds the implicit content width. + + For basic controls, the value is equal to \c {contentItem ? contentItem.implicitWidth : 0}. + For types that inherit Container or Pane, the value is calculated based on the content children. + + This is typically used, together with \l implicitBackgroundWidth, to calculate + the \l {Item::}{implicitWidth}: + + \code + Control { + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + implicitContentWidth + leftPadding + rightPadding) + } + \endcode + + \sa implicitContentHeight, implicitBackgroundWidth +*/ +qreal QQuickControl::implicitContentWidth() const +{ + Q_D(const QQuickControl); + return d->implicitContentWidth; +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Control::implicitContentHeight + \readonly + + This property holds the implicit content height. + + For basic controls, the value is equal to \c {contentItem ? contentItem.implicitHeight : 0}. + For types that inherit Container or Pane, the value is calculated based on the content children. + + This is typically used, together with \l implicitBackgroundHeight, to calculate + the \l {Item::}{implicitHeight}: + + \code + Control { + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + implicitContentHeight + topPadding + bottomPadding) + } + \endcode + + \sa implicitContentWidth, implicitBackgroundHeight +*/ +qreal QQuickControl::implicitContentHeight() const +{ + Q_D(const QQuickControl); + return d->implicitContentHeight; +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Control::implicitBackgroundWidth + \readonly + + This property holds the implicit background width. + + The value is equal to \c {background ? background.implicitWidth : 0}. + + This is typically used, together with \l implicitContentWidth, to calculate + the \l {Item::}{implicitWidth}: + + \code + Control { + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + implicitContentWidth + leftPadding + rightPadding) + } + \endcode + + \sa implicitBackgroundHeight, implicitContentWidth +*/ +qreal QQuickControl::implicitBackgroundWidth() const +{ + Q_D(const QQuickControl); + if (!d->background) + return 0; + return d->background->implicitWidth(); +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Control::implicitBackgroundHeight + \readonly + + This property holds the implicit background height. + + The value is equal to \c {background ? background.implicitHeight : 0}. + + This is typically used, together with \l implicitContentHeight, to calculate + the \l {Item::}{implicitHeight}: + + \code + Control { + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + implicitContentHeight + topPadding + bottomPadding) + } + \endcode + + \sa implicitBackgroundWidth, implicitContentHeight +*/ +qreal QQuickControl::implicitBackgroundHeight() const +{ + Q_D(const QQuickControl); + if (!d->background) + return 0; + return d->background->implicitHeight(); +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Control::topInset + + This property holds the top inset for the background. + + \sa {Control Layout}, bottomInset +*/ +qreal QQuickControl::topInset() const +{ + Q_D(const QQuickControl); + return d->getTopInset(); +} + +void QQuickControl::setTopInset(qreal inset) +{ + Q_D(QQuickControl); + d->setTopInset(inset); +} + +void QQuickControl::resetTopInset() +{ + Q_D(QQuickControl); + d->setTopInset(0, true); +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Control::leftInset + + This property holds the left inset for the background. + + \sa {Control Layout}, rightInset +*/ +qreal QQuickControl::leftInset() const +{ + Q_D(const QQuickControl); + return d->getLeftInset(); +} + +void QQuickControl::setLeftInset(qreal inset) +{ + Q_D(QQuickControl); + d->setLeftInset(inset); +} + +void QQuickControl::resetLeftInset() +{ + Q_D(QQuickControl); + d->setLeftInset(0, true); +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Control::rightInset + + This property holds the right inset for the background. + + \sa {Control Layout}, leftInset +*/ +qreal QQuickControl::rightInset() const +{ + Q_D(const QQuickControl); + return d->getRightInset(); +} + +void QQuickControl::setRightInset(qreal inset) +{ + Q_D(QQuickControl); + d->setRightInset(inset); +} + +void QQuickControl::resetRightInset() +{ + Q_D(QQuickControl); + d->setRightInset(0, true); +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Control::bottomInset + + This property holds the bottom inset for the background. + + \sa {Control Layout}, topInset +*/ +qreal QQuickControl::bottomInset() const +{ + Q_D(const QQuickControl); + return d->getBottomInset(); +} + +void QQuickControl::setBottomInset(qreal inset) +{ + Q_D(QQuickControl); + d->setBottomInset(inset); +} + +void QQuickControl::resetBottomInset() +{ + Q_D(QQuickControl); + d->setBottomInset(0, true); +} + void QQuickControl::classBegin() { Q_D(QQuickControl); @@ -1451,6 +2021,7 @@ void QQuickControl::componentComplete() QQuickItem::componentComplete(); d->resizeBackground(); d->resizeContent(); + d->updateBaselineOffset(); if (!d->hasLocale) d->locale = QQuickControlPrivate::calcLocale(d->parentItem); #if QT_CONFIG(quicktemplates2_hover) @@ -1465,12 +2036,12 @@ void QQuickControl::componentComplete() QFont QQuickControl::defaultFont() const { - return QQuickControlPrivate::themeFont(QPlatformTheme::SystemFont); + return QQuickTheme::font(QQuickTheme::System); } QPalette QQuickControl::defaultPalette() const { - return QQuickControlPrivate::themePalette(QPlatformTheme::SystemPalette); + return QQuickTheme::palette(QQuickTheme::System); } void QQuickControl::focusInEvent(QFocusEvent *event) @@ -1632,6 +2203,7 @@ void QQuickControl::paddingChange(const QMarginsF &newPadding, const QMarginsF & Q_UNUSED(newPadding); Q_UNUSED(oldPadding); d->resizeContent(); + d->updateBaselineOffset(); } void QQuickControl::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) @@ -1652,6 +2224,14 @@ void QQuickControl::paletteChange(const QPalette &newPalette, const QPalette &ol Q_UNUSED(oldPalette); } +void QQuickControl::insetChange(const QMarginsF &newInset, const QMarginsF &oldInset) +{ + Q_D(QQuickControl); + Q_UNUSED(newInset); + Q_UNUSED(oldInset); + d->resizeBackground(); +} + #if QT_CONFIG(accessibility) QAccessible::Role QQuickControl::accessibleRole() const { |