diff options
Diffstat (limited to 'src/quicktemplates2/qquicktextarea.cpp')
-rw-r--r-- | src/quicktemplates2/qquicktextarea.cpp | 143 |
1 files changed, 134 insertions, 9 deletions
diff --git a/src/quicktemplates2/qquicktextarea.cpp b/src/quicktemplates2/qquicktextarea.cpp index a66d7bf5..56a538ee 100644 --- a/src/quicktemplates2/qquicktextarea.cpp +++ b/src/quicktemplates2/qquicktextarea.cpp @@ -101,15 +101,40 @@ 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), explicitHoverEnabled(false), background(nullptr), + focusReason(Qt::OtherFocusReason), accessibleAttached(nullptr), flickable(nullptr) { #ifndef QT_NO_ACCESSIBILITY QAccessible::installActivationObserver(this); @@ -160,7 +185,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); @@ -180,7 +205,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); @@ -247,11 +272,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(); } @@ -285,6 +310,7 @@ QQuickTextArea::QQuickTextArea(QQuickItem *parent) : { Q_D(QQuickTextArea); setActiveFocusOnTab(true); + setAcceptedMouseButtons(Qt::AllButtons); d->setImplicitResizeEnabled(false); d->pressHandler.control = this; #ifndef QT_NO_CURSOR @@ -332,6 +358,21 @@ void QQuickTextAreaPrivate::inheritFont(const QFont &f) emit q->fontChanged(); } +void QQuickTextAreaPrivate::updateHoverEnabled(bool enabled, bool xplicit) +{ + Q_Q(QQuickTextArea); + if (!xplicit && explicitHoverEnabled) + return; + + bool wasEnabled = q->isHoverEnabled(); + explicitHoverEnabled = xplicit; + if (wasEnabled != enabled) { + q->setAcceptHoverEvents(enabled); + QQuickControlPrivate::updateHoverEnabledRecur(q, enabled); + emit q->hoverEnabledChanged(); + } +} + void QQuickTextAreaPrivate::_q_readOnlyChanged(bool isReadOnly) { #ifndef QT_NO_ACCESSIBILITY @@ -468,6 +509,64 @@ 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 (d->explicitHoverEnabled && enabled == d->hoverEnabled) + return; + + d->updateHoverEnabled(enabled, true); // explicit=true +} + +void QQuickTextArea::resetHoverEnabled() +{ + Q_D(QQuickTextArea); + if (!d->explicitHoverEnabled) + return; + + d->explicitHoverEnabled = false; + d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem), false); // explicit=false +} + bool QQuickTextArea::contains(const QPointF &point) const { Q_D(const QQuickTextArea); @@ -487,6 +586,8 @@ void QQuickTextArea::componentComplete() { Q_D(QQuickTextArea); QQuickTextEdit::componentComplete(); + if (!d->explicitHoverEnabled) + setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem)); #ifndef QT_NO_ACCESSIBILITY if (!d->accessibleAttached && QAccessible::isActive()) d->accessibilityActiveChanged(true); @@ -500,8 +601,11 @@ void QQuickTextArea::itemChange(QQuickItem::ItemChange change, const QQuickItem: { Q_D(QQuickTextArea); QQuickTextEdit::itemChange(change, value); - if (change == ItemParentHasChanged && value.item) + if (change == ItemParentHasChanged && value.item) { d->resolveFont(); + if (!d->explicitHoverEnabled) + d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem), false); // explicit=false + } } void QQuickTextArea::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) @@ -551,6 +655,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); @@ -560,7 +680,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(); } } |