diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-06-29 10:53:01 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-06-29 13:22:48 +0000 |
commit | a07606a56b1bc8d277ef5cfc394178b660a0c30c (patch) | |
tree | d0c567613ec0149f09ef77662144b2e72b2472fb /src/quicktemplates2 | |
parent | f379e58bf51f1b32782a54f455401b86c83c3ee4 (diff) |
Add hover support to TextArea & TextField
Task-number: QTBUG-50003
Change-Id: Ie101ba8840fba2a7503da8de77d9cf2a3c91d562
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquicktextarea.cpp | 67 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktextarea_p.h | 12 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktextarea_p_p.h | 1 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktextfield.cpp | 68 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktextfield_p.h | 12 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktextfield_p_p.h | 1 |
6 files changed, 159 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquicktextarea.cpp b/src/quicktemplates2/qquicktextarea.cpp index 11fe7393..7bda34f5 100644 --- a/src/quicktemplates2/qquicktextarea.cpp +++ b/src/quicktemplates2/qquicktextarea.cpp @@ -107,7 +107,7 @@ QT_BEGIN_NAMESPACE */ QQuickTextAreaPrivate::QQuickTextAreaPrivate() - : background(nullptr), focusReason(Qt::OtherFocusReason), accessibleAttached(nullptr), flickable(nullptr) + : hovered(false), background(nullptr), focusReason(Qt::OtherFocusReason), accessibleAttached(nullptr), flickable(nullptr) { #ifndef QT_NO_ACCESSIBILITY QAccessible::installActivationObserver(this); @@ -471,6 +471,55 @@ void QQuickTextArea::setFocusReason(Qt::FocusReason reason) emit focusReasonChanged(); } +/*! + \since QtQuick.Controls 2.1 + \qmlproperty bool QtQuick.Controls::TextArea::hovered + \readonly + + This property holds whether the text area is hovered. + + \sa hoverEnabled +*/ +bool QQuickTextArea::isHovered() const +{ + Q_D(const QQuickTextArea); + return d->hovered; +} + +void QQuickTextArea::setHovered(bool hovered) +{ + Q_D(QQuickTextArea); + if (hovered == d->hovered) + return; + + d->hovered = hovered; + emit hoveredChanged(); +} + +/*! + \since QtQuick.Controls 2.1 + \qmlproperty bool QtQuick.Controls::TextArea::hoverEnabled + + This property determines whether the text area accepts hover events. The default value is \c true. + + \sa hovered +*/ +bool QQuickTextArea::isHoverEnabled() const +{ + Q_D(const QQuickTextArea); + return d->hoverEnabled; +} + +void QQuickTextArea::setHoverEnabled(bool enabled) +{ + Q_D(QQuickTextArea); + if (enabled == d->hoverEnabled) + return; + + setAcceptHoverEvents(enabled); + emit hoverEnabledChanged(); +} + void QQuickTextArea::classBegin() { Q_D(QQuickTextArea); @@ -543,6 +592,22 @@ void QQuickTextArea::focusOutEvent(QFocusEvent *event) setFocusReason(event->reason()); } +void QQuickTextArea::hoverEnterEvent(QHoverEvent *event) +{ + Q_D(QQuickTextArea); + QQuickTextEdit::hoverEnterEvent(event); + setHovered(d->hoverEnabled); + event->setAccepted(d->hoverEnabled); +} + +void QQuickTextArea::hoverLeaveEvent(QHoverEvent *event) +{ + Q_D(QQuickTextArea); + QQuickTextEdit::hoverLeaveEvent(event); + setHovered(false); + event->setAccepted(d->hoverEnabled); +} + void QQuickTextArea::mousePressEvent(QMouseEvent *event) { Q_D(QQuickTextArea); diff --git a/src/quicktemplates2/qquicktextarea_p.h b/src/quicktemplates2/qquicktextarea_p.h index 571b91c6..f52bb01c 100644 --- a/src/quicktemplates2/qquicktextarea_p.h +++ b/src/quicktemplates2/qquicktextarea_p.h @@ -67,6 +67,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTextArea : public QQuickTextEdit Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL) Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText NOTIFY placeholderTextChanged FINAL) Q_PROPERTY(Qt::FocusReason focusReason READ focusReason WRITE setFocusReason NOTIFY focusReasonChanged FINAL) + Q_PROPERTY(bool hovered READ isHovered NOTIFY hoveredChanged FINAL REVISION 1) + Q_PROPERTY(bool hoverEnabled READ isHoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged FINAL REVISION 1) public: explicit QQuickTextArea(QQuickItem *parent = nullptr); @@ -86,6 +88,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); + Q_SIGNALS: void fontChanged(); void implicitWidthChanged3(); @@ -93,6 +101,8 @@ Q_SIGNALS: void backgroundChanged(); void placeholderTextChanged(); void focusReasonChanged(); + Q_REVISION(1) void hoveredChanged(); + Q_REVISION(1) void hoverEnabledChanged(); void pressAndHold(QQuickMouseEvent *event); protected: @@ -105,6 +115,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/quicktemplates2/qquicktextarea_p_p.h b/src/quicktemplates2/qquicktextarea_p_p.h index 8af5d0d7..40277b4f 100644 --- a/src/quicktemplates2/qquicktextarea_p_p.h +++ b/src/quicktemplates2/qquicktextarea_p_p.h @@ -102,6 +102,7 @@ public: QAccessible::Role accessibleRole() const override; #endif + bool hovered; QFont font; QQuickItem *background; QString placeholder; diff --git a/src/quicktemplates2/qquicktextfield.cpp b/src/quicktemplates2/qquicktextfield.cpp index 18a5932a..44da850a 100644 --- a/src/quicktemplates2/qquicktextfield.cpp +++ b/src/quicktemplates2/qquicktextfield.cpp @@ -90,7 +90,8 @@ QT_BEGIN_NAMESPACE */ QQuickTextFieldPrivate::QQuickTextFieldPrivate() - : background(nullptr) + : hovered(false) + , background(nullptr) , focusReason(Qt::OtherFocusReason) , accessibleAttached(nullptr) { @@ -347,6 +348,55 @@ void QQuickTextField::setFocusReason(Qt::FocusReason reason) emit focusReasonChanged(); } +/*! + \since QtQuick.Controls 2.1 + \qmlproperty bool QtQuick.Controls::TextField::hovered + \readonly + + This property holds whether the text field is hovered. + + \sa hoverEnabled +*/ +bool QQuickTextField::isHovered() const +{ + Q_D(const QQuickTextField); + return d->hovered; +} + +void QQuickTextField::setHovered(bool hovered) +{ + Q_D(QQuickTextField); + if (hovered == d->hovered) + return; + + d->hovered = hovered; + emit hoveredChanged(); +} + +/*! + \since QtQuick.Controls 2.1 + \qmlproperty bool QtQuick.Controls::TextField::hoverEnabled + + This property determines whether the text field accepts hover events. The default value is \c false. + + \sa hovered +*/ +bool QQuickTextField::isHoverEnabled() const +{ + Q_D(const QQuickTextField); + return d->hoverEnabled; +} + +void QQuickTextField::setHoverEnabled(bool enabled) +{ + Q_D(QQuickTextField); + if (enabled == d->hoverEnabled) + return; + + setAcceptHoverEvents(enabled); + emit hoverEnabledChanged(); +} + void QQuickTextField::classBegin() { Q_D(QQuickTextField); @@ -407,6 +457,22 @@ void QQuickTextField::focusOutEvent(QFocusEvent *event) setFocusReason(event->reason()); } +void QQuickTextField::hoverEnterEvent(QHoverEvent *event) +{ + Q_D(QQuickTextField); + QQuickTextInput::hoverEnterEvent(event); + setHovered(d->hoverEnabled); + event->setAccepted(d->hoverEnabled); +} + +void QQuickTextField::hoverLeaveEvent(QHoverEvent *event) +{ + Q_D(QQuickTextField); + QQuickTextInput::hoverLeaveEvent(event); + setHovered(false); + event->setAccepted(d->hoverEnabled); +} + void QQuickTextField::mousePressEvent(QMouseEvent *event) { Q_D(QQuickTextField); diff --git a/src/quicktemplates2/qquicktextfield_p.h b/src/quicktemplates2/qquicktextfield_p.h index a3bcb69c..851435a7 100644 --- a/src/quicktemplates2/qquicktextfield_p.h +++ b/src/quicktemplates2/qquicktextfield_p.h @@ -66,6 +66,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTextField : public QQuickTextInput Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL) Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText NOTIFY placeholderTextChanged FINAL) Q_PROPERTY(Qt::FocusReason focusReason READ focusReason WRITE setFocusReason NOTIFY focusReasonChanged FINAL) + Q_PROPERTY(bool hovered READ isHovered NOTIFY hoveredChanged FINAL REVISION 1) + Q_PROPERTY(bool hoverEnabled READ isHoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged FINAL REVISION 1) public: explicit QQuickTextField(QQuickItem *parent = nullptr); @@ -83,6 +85,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); + Q_SIGNALS: void fontChanged(); void implicitWidthChanged3(); @@ -90,6 +98,8 @@ Q_SIGNALS: void backgroundChanged(); void placeholderTextChanged(); void focusReasonChanged(); + Q_REVISION(1) void hoveredChanged(); + Q_REVISION(1) void hoverEnabledChanged(); void pressAndHold(QQuickMouseEvent *mouse); protected: @@ -102,6 +112,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/quicktemplates2/qquicktextfield_p_p.h b/src/quicktemplates2/qquicktextfield_p_p.h index 293b53de..dd355145 100644 --- a/src/quicktemplates2/qquicktextfield_p_p.h +++ b/src/quicktemplates2/qquicktextfield_p_p.h @@ -93,6 +93,7 @@ public: QAccessible::Role accessibleRole() const override; #endif + bool hovered; QFont font; QQuickItem *background; QString placeholder; |