aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickcontrol.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2018-02-21 23:11:25 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2018-04-12 09:13:58 +0000
commit5bd9d44bc7f78ca5946bdef788f1da63b2356a65 (patch)
tree4ec113f3d28a5796919073f0e249b1a0d7699029 /src/quicktemplates2/qquickcontrol.cpp
parent8428c9f4429139e3fa137400bd0721030416c8b2 (diff)
Control: add implicitBackgroundWidth|Height properties
[ChangeLog][Controls][Control] Added implicitBackgroundWidth and implicitBackgroundHeight properties that can be used to simplify complex implicit size bindings. Task-number: QTBUG-60156 Change-Id: Ia68df187c2a458c84de19f867d76a643134e8b69 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickcontrol.cpp')
-rw-r--r--src/quicktemplates2/qquickcontrol.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp
index 32147329..7a1bb496 100644
--- a/src/quicktemplates2/qquickcontrol.cpp
+++ b/src/quicktemplates2/qquickcontrol.cpp
@@ -97,6 +97,8 @@ QT_BEGIN_NAMESPACE
\sa ApplicationWindow, Container
*/
+static const QQuickItemPrivate::ChangeTypes ImplicitSizeChanges = QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed;
+
static bool isKeyFocusReason(Qt::FocusReason reason)
{
return reason == Qt::TabFocusReason || reason == Qt::BacktabFocusReason || reason == Qt::ShortcutFocusReason;
@@ -729,6 +731,44 @@ void QQuickControlPrivate::updateBaselineOffset()
q->QQuickItem::setBaselineOffset(getTopPadding() + contentItem->baselineOffset());
}
+void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item)
+{
+ if (!item)
+ return;
+ QQuickItemPrivate::get(item)->addItemChangeListener(this, ImplicitSizeChanges);
+}
+
+void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item)
+{
+ if (!item)
+ return;
+ QQuickItemPrivate::get(item)->removeItemChangeListener(this, ImplicitSizeChanges);
+}
+
+void QQuickControlPrivate::itemImplicitWidthChanged(QQuickItem *item)
+{
+ Q_Q(QQuickControl);
+ if (item == background)
+ emit q->implicitBackgroundWidthChanged();
+}
+
+void QQuickControlPrivate::itemImplicitHeightChanged(QQuickItem *item)
+{
+ Q_Q(QQuickControl);
+ if (item == background)
+ emit q->implicitBackgroundHeightChanged();
+}
+
+void QQuickControlPrivate::itemDestroyed(QQuickItem *item)
+{
+ Q_Q(QQuickControl);
+ if (item == background) {
+ background = nullptr;
+ emit q->implicitBackgroundWidthChanged();
+ emit q->implicitBackgroundHeightChanged();
+ }
+}
+
QQuickControl::QQuickControl(QQuickItem *parent)
: QQuickItem(*(new QQuickControlPrivate), parent)
{
@@ -743,6 +783,12 @@ QQuickControl::QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent)
d->init();
}
+QQuickControl::~QQuickControl()
+{
+ Q_D(QQuickControl);
+ d->removeImplicitSizeListener(d->background);
+}
+
void QQuickControl::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
{
Q_D(QQuickControl);
@@ -1361,15 +1407,26 @@ void QQuickControl::setBackground(QQuickItem *background)
if (!d->background.isExecuting())
d->cancelBackground();
+ const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
+ const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
+
+ d->removeImplicitSizeListener(d->background);
delete d->background;
d->background = background;
+
if (background) {
background->setParentItem(this);
if (qFuzzyIsNull(background->z()))
background->setZ(-1);
if (isComponentComplete())
d->resizeBackground();
+ d->addImplicitSizeListener(background);
}
+
+ if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
+ emit implicitBackgroundWidthChanged();
+ if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
+ emit implicitBackgroundHeightChanged();
if (!d->background.isExecuting())
emit backgroundChanged();
}
@@ -1563,6 +1620,44 @@ void QQuickControl::resetVerticalPadding()
d->setVerticalPadding(0, true);
}
+/*!
+ \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}.
+
+ \sa implicitBackgroundHeight
+*/
+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}.
+
+ \sa implicitBackgroundWidth
+*/
+qreal QQuickControl::implicitBackgroundHeight() const
+{
+ Q_D(const QQuickControl);
+ if (!d->background)
+ return 0;
+ return d->background->implicitHeight();
+}
+
void QQuickControl::classBegin()
{
Q_D(QQuickControl);