diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-23 16:10:16 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-25 08:35:48 +0000 |
commit | 718f6def0b2c4d84bdc8ebdc9633697885747feb (patch) | |
tree | 3d74569c992ccc40860f2cc5d914930a053da231 /src | |
parent | d0ab538c1ffadecfe0aa7130918726de7126dd16 (diff) |
Control: add hoverEnabled and hovered properties
Change-Id: I35946b9f13ef78ce7bdfbad9706de3e96bd48ea4
Task-number: QTBUG-50003
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/controls/plugins.qmltypes | 2 | ||||
-rw-r--r-- | src/imports/templates/plugins.qmltypes | 2 | ||||
-rw-r--r-- | src/templates/qquickcontrol.cpp | 63 | ||||
-rw-r--r-- | src/templates/qquickcontrol_p.h | 13 | ||||
-rw-r--r-- | src/templates/qquickcontrol_p_p.h | 1 |
5 files changed, 79 insertions, 2 deletions
diff --git a/src/imports/controls/plugins.qmltypes b/src/imports/controls/plugins.qmltypes index 27cefe97..dbb70704 100644 --- a/src/imports/controls/plugins.qmltypes +++ b/src/imports/controls/plugins.qmltypes @@ -187,6 +187,8 @@ Module { Property { name: "mirrored"; type: "bool"; isReadonly: true } Property { name: "focusPolicy"; type: "Qt::FocusPolicy" } Property { name: "focusReason"; type: "Qt::FocusReason" } + Property { name: "hovered"; type: "bool"; isReadonly: true } + Property { name: "hoverEnabled"; type: "bool" } Property { name: "wheelEnabled"; type: "bool" } Property { name: "background"; type: "QQuickItem"; isPointer: true } Property { name: "contentItem"; type: "QQuickItem"; isPointer: true } diff --git a/src/imports/templates/plugins.qmltypes b/src/imports/templates/plugins.qmltypes index 11f6a50a..d194f28d 100644 --- a/src/imports/templates/plugins.qmltypes +++ b/src/imports/templates/plugins.qmltypes @@ -181,6 +181,8 @@ Module { Property { name: "mirrored"; type: "bool"; isReadonly: true } Property { name: "focusPolicy"; type: "Qt::FocusPolicy" } Property { name: "focusReason"; type: "Qt::FocusReason" } + Property { name: "hovered"; type: "bool"; isReadonly: true } + Property { name: "hoverEnabled"; type: "bool" } Property { name: "wheelEnabled"; type: "bool" } Property { name: "background"; type: "QQuickItem"; isPointer: true } Property { name: "contentItem"; type: "QQuickItem"; isPointer: true } diff --git a/src/templates/qquickcontrol.cpp b/src/templates/qquickcontrol.cpp index e509ec3f..9dbe4181 100644 --- a/src/templates/qquickcontrol.cpp +++ b/src/templates/qquickcontrol.cpp @@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE */ QQuickControlPrivate::QQuickControlPrivate() : - hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false), hasLocale(false), wheelEnabled(false), + hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false), hasLocale(false), hovered(false), wheelEnabled(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) @@ -809,6 +809,53 @@ void QQuickControl::setFocusReason(Qt::FocusReason reason) } /*! + \qmlproperty bool Qt.labs.controls::Control::hovered + \readonly + + This property holds whether the control is hovered. + + \sa hoverEnabled +*/ +bool QQuickControl::isHovered() const +{ + Q_D(const QQuickControl); + return d->hovered; +} + +void QQuickControl::setHovered(bool hovered) +{ + Q_D(QQuickControl); + if (hovered == d->hovered) + return; + + d->hovered = hovered; + emit hoveredChanged(); +} + +/*! + \qmlproperty bool Qt.labs.controls::Control::hoverEnabled + + This property determines whether the control accepts hover events. The default value is \c false. + + \sa hovered +*/ +bool QQuickControl::isHoverEnabled() const +{ + Q_D(const QQuickControl); + return d->hoverEnabled; +} + +void QQuickControl::setHoverEnabled(bool enabled) +{ + Q_D(QQuickControl); + if (enabled == d->hoverEnabled) + return; + + setAcceptHoverEvents(enabled); + emit hoverEnabledChanged(); +} + +/*! \qmlproperty bool Qt.labs.controls::Control::wheelEnabled This property determines whether the control handles wheel events. The default value is \c false. @@ -923,6 +970,20 @@ void QQuickControl::focusOutEvent(QFocusEvent *event) setFocusReason(event->reason()); } +void QQuickControl::hoverEnterEvent(QHoverEvent *event) +{ + Q_D(QQuickControl); + setHovered(d->hoverEnabled); + event->setAccepted(d->hoverEnabled); +} + +void QQuickControl::hoverLeaveEvent(QHoverEvent *event) +{ + Q_D(QQuickControl); + setHovered(false); + event->setAccepted(d->hoverEnabled); +} + void QQuickControl::mousePressEvent(QMouseEvent *event) { Q_D(QQuickControl); diff --git a/src/templates/qquickcontrol_p.h b/src/templates/qquickcontrol_p.h index 55116dc1..e232dd73 100644 --- a/src/templates/qquickcontrol_p.h +++ b/src/templates/qquickcontrol_p.h @@ -72,6 +72,8 @@ class Q_LABSTEMPLATES_EXPORT QQuickControl : public QQuickItem Q_PROPERTY(bool mirrored READ isMirrored NOTIFY mirroredChanged FINAL) Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy NOTIFY focusPolicyChanged FINAL) Q_PROPERTY(Qt::FocusReason focusReason READ focusReason WRITE setFocusReason NOTIFY focusReasonChanged FINAL) + Q_PROPERTY(bool hovered READ isHovered NOTIFY hoveredChanged FINAL) + Q_PROPERTY(bool hoverEnabled READ isHoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged FINAL) Q_PROPERTY(bool wheelEnabled READ isWheelEnabled WRITE setWheelEnabled NOTIFY wheelEnabledChanged FINAL) Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL) Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL) @@ -122,6 +124,12 @@ public: Qt::FocusReason focusReason() const; void setFocusReason(Qt::FocusReason reason); + bool isHovered() const; + void setHovered(bool hovered); + + bool isHoverEnabled() const; + void setHoverEnabled(bool enabled); + bool isWheelEnabled() const; void setWheelEnabled(bool enabled); @@ -145,6 +153,8 @@ Q_SIGNALS: void mirroredChanged(); void focusPolicyChanged(); void focusReasonChanged(); + void hoveredChanged(); + void hoverEnabledChanged(); void wheelEnabledChanged(); void backgroundChanged(); void contentItemChanged(); @@ -160,7 +170,8 @@ protected: void focusInEvent(QFocusEvent *event) override; void focusOutEvent(QFocusEvent *event) override; - + void hoverEnterEvent(QHoverEvent *event) override; + void hoverLeaveEvent(QHoverEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; diff --git a/src/templates/qquickcontrol_p_p.h b/src/templates/qquickcontrol_p_p.h index ef4cd17e..c6e405e6 100644 --- a/src/templates/qquickcontrol_p_p.h +++ b/src/templates/qquickcontrol_p_p.h @@ -112,6 +112,7 @@ public: bool hasRightPadding; bool hasBottomPadding; bool hasLocale; + bool hovered; bool wheelEnabled; qreal padding; qreal topPadding; |