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/qquicktextarea.cpp | |
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/qquicktextarea.cpp')
-rw-r--r-- | src/quicktemplates2/qquicktextarea.cpp | 67 |
1 files changed, 66 insertions, 1 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); |