aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickcontrol.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquickcontrol.cpp')
-rw-r--r--src/quicktemplates2/qquickcontrol.cpp119
1 files changed, 108 insertions, 11 deletions
diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp
index cb891ee9..d8088f24 100644
--- a/src/quicktemplates2/qquickcontrol.cpp
+++ b/src/quicktemplates2/qquickcontrol.cpp
@@ -109,7 +109,8 @@ QQuickControlPrivate::ExtraData::ExtraData()
}
QQuickControlPrivate::QQuickControlPrivate() :
- hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false), hasLocale(false), hovered(false), wheelEnabled(false),
+ hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false),
+ hasLocale(false), hovered(false), wheelEnabled(false), explicitHoverEnabled(false),
padding(0), topPadding(0), leftPadding(0), rightPadding(0), bottomPadding(0), spacing(0),
focusPolicy(Qt::NoFocus), focusReason(Qt::OtherFocusReason),
background(nullptr), contentItem(nullptr), accessibleAttached(nullptr)
@@ -214,6 +215,11 @@ void QQuickControlPrivate::resizeContent()
}
}
+QQuickItem *QQuickControlPrivate::getContentItem()
+{
+ return contentItem;
+}
+
#ifndef QT_NO_ACCESSIBILITY
void QQuickControlPrivate::accessibilityActiveChanged(bool active)
{
@@ -356,6 +362,62 @@ void QQuickControlPrivate::updateFontRecur(QQuickItem *item, const QFont &f)
}
}
+void QQuickControlPrivate::updateHoverEnabled(bool enabled, bool xplicit)
+{
+ Q_Q(QQuickControl);
+ if (!xplicit && explicitHoverEnabled)
+ return;
+
+ bool wasEnabled = q->isHoverEnabled();
+ explicitHoverEnabled = xplicit;
+ if (wasEnabled != enabled) {
+ q->setAcceptHoverEvents(enabled);
+ QQuickControlPrivate::updateHoverEnabledRecur(q, enabled);
+ emit q->hoverEnabledChanged();
+ }
+}
+
+void QQuickControlPrivate::updateHoverEnabledRecur(QQuickItem *item, bool enabled)
+{
+ const auto childItems = item->childItems();
+ for (QQuickItem *child : childItems) {
+ if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
+ QQuickControlPrivate::get(control)->updateHoverEnabled(enabled, false);
+ else
+ updateHoverEnabledRecur(child, enabled);
+ }
+}
+
+bool QQuickControlPrivate::calcHoverEnabled(const QQuickItem *item)
+{
+ const QQuickItem *p = item;
+ while (p) {
+ // QQuickPopupItem accepts hover events to avoid leaking them through.
+ // Don't inherit that to the children of the popup, but fallback to the
+ // environment variable or style hint.
+ if (qobject_cast<const QQuickPopupItem *>(p))
+ break;
+
+ if (const QQuickControl *control = qobject_cast<const QQuickControl *>(p))
+ return control->isHoverEnabled();
+
+ QVariant v = p->property("hoverEnabled");
+ if (v.isValid() && v.userType() == QMetaType::Bool)
+ return v.toBool();
+
+ p = p->parentItem();
+ }
+
+ bool ok = false;
+ int env = qEnvironmentVariableIntValue("QT_QUICK_CONTROLS_HOVER_ENABLED", &ok);
+ if (ok)
+ return env != 0;
+
+ // TODO: QQuickApplicationWindow::isHoverEnabled()
+
+ return QGuiApplication::styleHints()->useHoverEffects();
+}
+
QString QQuickControl::accessibleName() const
{
#ifndef QT_NO_ACCESSIBILITY
@@ -424,6 +486,8 @@ void QQuickControl::itemChange(QQuickItem::ItemChange change, const QQuickItem::
d->resolveFont();
if (!d->hasLocale)
d->updateLocale(QQuickControlPrivate::calcLocale(d->parentItem), false); // explicit=false
+ if (!d->explicitHoverEnabled)
+ d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem), false); // explicit=false
}
break;
case ItemActiveFocusHasChanged:
@@ -702,10 +766,13 @@ qreal QQuickControl::spacing() const
void QQuickControl::setSpacing(qreal spacing)
{
Q_D(QQuickControl);
- if (!qFuzzyCompare(d->spacing, spacing)) {
- d->spacing = spacing;
- emit spacingChanged();
- }
+ if (qFuzzyCompare(d->spacing, spacing))
+ return;
+
+ qreal oldSpacing = d->spacing;
+ d->spacing = spacing;
+ emit spacingChanged();
+ spacingChange(spacing, oldSpacing);
}
void QQuickControl::resetSpacing()
@@ -936,12 +1003,21 @@ void QQuickControl::setHovered(bool hovered)
d->hovered = hovered;
emit hoveredChanged();
+ hoverChange();
}
/*!
\qmlproperty bool QtQuick.Controls::Control::hoverEnabled
- This property determines whether the control accepts hover events. The default value is \c false.
+ This property determines whether the control accepts hover events. The default value
+ is \c Qt.styleHints.useHoverEffects.
+
+ Setting this property propagates the value to all child controls that do not have
+ \c hoverEnabled explicitly set.
+
+ You can also enable or disable hover effects for all Qt Quick Controls 2 applications
+ by setting the \c QT_QUICK_CONTROLS_HOVER_ENABLED \l {Supported Environment Variables
+ in Qt Quick Controls 2}{environment variable}.
\sa hovered
*/
@@ -954,11 +1030,20 @@ bool QQuickControl::isHoverEnabled() const
void QQuickControl::setHoverEnabled(bool enabled)
{
Q_D(QQuickControl);
- if (enabled == d->hoverEnabled)
+ if (d->explicitHoverEnabled && enabled == d->hoverEnabled)
return;
- setAcceptHoverEvents(enabled);
- emit hoverEnabledChanged();
+ d->updateHoverEnabled(enabled, true); // explicit=true
+}
+
+void QQuickControl::resetHoverEnabled()
+{
+ Q_D(QQuickControl);
+ if (!d->explicitHoverEnabled)
+ return;
+
+ d->explicitHoverEnabled = false;
+ d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem), false); // explicit=false
}
/*!
@@ -1062,8 +1147,8 @@ void QQuickControl::setBackground(QQuickItem *background)
*/
QQuickItem *QQuickControl::contentItem() const
{
- Q_D(const QQuickControl);
- return d->contentItem;
+ QQuickControlPrivate *d = const_cast<QQuickControlPrivate *>(d_func());
+ return d->getContentItem();
}
void QQuickControl::setContentItem(QQuickItem *item)
@@ -1097,6 +1182,8 @@ void QQuickControl::componentComplete()
QQuickItem::componentComplete();
if (!d->hasLocale)
d->locale = QQuickControlPrivate::calcLocale(d->parentItem);
+ if (!d->explicitHoverEnabled)
+ setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem));
#ifndef QT_NO_ACCESSIBILITY
if (!d->accessibleAttached && QAccessible::isActive())
accessibilityActiveChanged(true);
@@ -1198,11 +1285,21 @@ void QQuickControl::fontChange(const QFont &newFont, const QFont &oldFont)
Q_UNUSED(oldFont);
}
+void QQuickControl::hoverChange()
+{
+}
+
void QQuickControl::mirrorChange()
{
emit mirroredChanged();
}
+void QQuickControl::spacingChange(qreal newSpacing, qreal oldSpacing)
+{
+ Q_UNUSED(newSpacing);
+ Q_UNUSED(oldSpacing);
+}
+
void QQuickControl::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding)
{
Q_D(QQuickControl);