diff options
Diffstat (limited to 'src/quicktemplates2/qquicktextarea.cpp')
-rw-r--r-- | src/quicktemplates2/qquicktextarea.cpp | 111 |
1 files changed, 103 insertions, 8 deletions
diff --git a/src/quicktemplates2/qquicktextarea.cpp b/src/quicktemplates2/qquicktextarea.cpp index 81552185..7c2e0f11 100644 --- a/src/quicktemplates2/qquicktextarea.cpp +++ b/src/quicktemplates2/qquicktextarea.cpp @@ -99,15 +99,39 @@ QT_BEGIN_NAMESPACE */ /*! - \qmlsignal QtQuick.Controls::TextArea::pressAndHold(MouseEvent mouse) + \qmlsignal QtQuick.Controls::TextArea::pressAndHold(MouseEvent event) This signal is emitted when there is a long press (the delay depends on the platform plugin). - The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y + The \l {MouseEvent}{event} parameter provides information about the press, including the x and y position of the press, and which button is pressed. + + \sa pressed, released +*/ + +/*! + \qmlsignal QtQuick.Controls::TextArea::pressed(MouseEvent event) + \since QtQuick.Controls 2.1 + + This signal is emitted when the text area is pressed by the user. + The \l {MouseEvent}{event} parameter provides information about the press, + including the x and y position of the press, and which button is pressed. + + \sa released, pressAndHold +*/ + +/*! + \qmlsignal QtQuick.Controls::TextArea::released(MouseEvent event) + \since QtQuick.Controls 2.1 + + This signal is emitted when the text area is released by the user. + The \l {MouseEvent}{event} parameter provides information about the release, + including the x and y position of the press, and which button is pressed. + + \sa pressed, pressAndHold */ 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); @@ -158,7 +182,7 @@ void QQuickTextAreaPrivate::attachFlickable(QQuickFlickable *item) QObject::connect(flickable, &QQuickFlickable::contentXChanged, q, &QQuickItem::update); QObject::connect(flickable, &QQuickFlickable::contentYChanged, q, &QQuickItem::update); - QQuickItemPrivate::get(flickable)->updateOrAddGeometryChangeListener(this, QQuickItemPrivate::SizeChange); + QQuickItemPrivate::get(flickable)->updateOrAddGeometryChangeListener(this, QQuickGeometryChange::Size); QObjectPrivate::connect(flickable, &QQuickFlickable::contentWidthChanged, this, &QQuickTextAreaPrivate::resizeFlickableControl); QObjectPrivate::connect(flickable, &QQuickFlickable::contentHeightChanged, this, &QQuickTextAreaPrivate::resizeFlickableControl); @@ -178,7 +202,7 @@ void QQuickTextAreaPrivate::detachFlickable() QObject::disconnect(flickable, &QQuickFlickable::contentXChanged, q, &QQuickItem::update); QObject::disconnect(flickable, &QQuickFlickable::contentYChanged, q, &QQuickItem::update); - QQuickItemPrivate::get(flickable)->updateOrRemoveGeometryChangeListener(this, QQuickItemPrivate::SizeChange); + QQuickItemPrivate::get(flickable)->updateOrRemoveGeometryChangeListener(this, QQuickGeometryChange::Size); QObjectPrivate::disconnect(flickable, &QQuickFlickable::contentWidthChanged, this, &QQuickTextAreaPrivate::resizeFlickableControl); QObjectPrivate::disconnect(flickable, &QQuickFlickable::contentHeightChanged, this, &QQuickTextAreaPrivate::resizeFlickableControl); @@ -245,11 +269,11 @@ void QQuickTextAreaPrivate::resizeFlickableContent() flickable->setContentHeight(q->contentHeight() + q->topPadding() + q->bottomPadding()); } -void QQuickTextAreaPrivate::itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) +void QQuickTextAreaPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) { Q_UNUSED(item); - Q_UNUSED(newGeometry); - Q_UNUSED(oldGeometry); + Q_UNUSED(change); + Q_UNUSED(diff); resizeFlickableControl(); } @@ -283,6 +307,7 @@ QQuickTextArea::QQuickTextArea(QQuickItem *parent) : { Q_D(QQuickTextArea); setActiveFocusOnTab(true); + setAcceptedMouseButtons(Qt::AllButtons); d->setImplicitResizeEnabled(false); d->pressHandler.control = this; #ifndef QT_NO_CURSOR @@ -474,6 +499,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(); +} + bool QQuickTextArea::contains(const QPointF &point) const { Q_D(const QQuickTextArea); @@ -554,6 +628,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); @@ -563,7 +653,12 @@ void QQuickTextArea::mousePressEvent(QMouseEvent *event) QQuickTextEdit::mousePressEvent(d->pressHandler.delayedMousePressEvent); d->pressHandler.clearDelayedMouseEvent(); } + // Calling the base class implementation will result in QQuickTextControl's + // press handler being called, which ignores events that aren't Qt::LeftButton. + const bool wasAccepted = event->isAccepted(); QQuickTextEdit::mousePressEvent(event); + if (wasAccepted) + event->accept(); } } |