aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquicktextfield.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquicktextfield.cpp')
-rw-r--r--src/quicktemplates2/qquicktextfield.cpp129
1 files changed, 125 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquicktextfield.cpp b/src/quicktemplates2/qquicktextfield.cpp
index 610df907..2bb902a1 100644
--- a/src/quicktemplates2/qquicktextfield.cpp
+++ b/src/quicktemplates2/qquicktextfield.cpp
@@ -82,15 +82,41 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \qmlsignal QtQuick.Controls::TextField::pressAndHold(MouseEvent mouse)
+ \qmlsignal QtQuick.Controls::TextField::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::TextField::pressed(MouseEvent event)
+ \since QtQuick.Controls 2.1
+
+ This signal is emitted when the text field 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::TextField::released(MouseEvent event)
+ \since QtQuick.Controls 2.1
+
+ This signal is emitted when the text field 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
*/
QQuickTextFieldPrivate::QQuickTextFieldPrivate()
- : background(nullptr)
+ : hovered(false)
+ , explicitHoverEnabled(false)
+ , background(nullptr)
, focusReason(Qt::OtherFocusReason)
, accessibleAttached(nullptr)
{
@@ -152,6 +178,7 @@ QQuickTextField::QQuickTextField(QQuickItem *parent) :
Q_D(QQuickTextField);
d->pressHandler.control = this;
d->setImplicitResizeEnabled(false);
+ setAcceptedMouseButtons(Qt::AllButtons);
setActiveFocusOnTab(true);
#ifndef QT_NO_CURSOR
setCursor(Qt::IBeamCursor);
@@ -195,6 +222,21 @@ void QQuickTextFieldPrivate::inheritFont(const QFont &f)
emit q->fontChanged();
}
+void QQuickTextFieldPrivate::updateHoverEnabled(bool enabled, bool xplicit)
+{
+ Q_Q(QQuickTextField);
+ if (!xplicit && explicitHoverEnabled)
+ return;
+
+ bool wasEnabled = q->isHoverEnabled();
+ explicitHoverEnabled = xplicit;
+ if (wasEnabled != enabled) {
+ q->setAcceptHoverEvents(enabled);
+ QQuickControlPrivate::updateHoverEnabledRecur(q, enabled);
+ emit q->hoverEnabledChanged();
+ }
+}
+
void QQuickTextFieldPrivate::_q_readOnlyChanged(bool isReadOnly)
{
#ifndef QT_NO_ACCESSIBILITY
@@ -346,6 +388,64 @@ 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 (d->explicitHoverEnabled && enabled == d->hoverEnabled)
+ return;
+
+ d->updateHoverEnabled(enabled, true); // explicit=true
+}
+
+void QQuickTextField::resetHoverEnabled()
+{
+ Q_D(QQuickTextField);
+ if (!d->explicitHoverEnabled)
+ return;
+
+ d->explicitHoverEnabled = false;
+ d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem), false); // explicit=false
+}
+
void QQuickTextField::classBegin()
{
Q_D(QQuickTextField);
@@ -357,6 +457,8 @@ void QQuickTextField::componentComplete()
{
Q_D(QQuickTextField);
QQuickTextInput::componentComplete();
+ if (!d->explicitHoverEnabled)
+ setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem));
#ifndef QT_NO_ACCESSIBILITY
if (!d->accessibleAttached && QAccessible::isActive())
d->accessibilityActiveChanged(true);
@@ -370,8 +472,11 @@ void QQuickTextField::itemChange(QQuickItem::ItemChange change, const QQuickItem
{
Q_D(QQuickTextField);
QQuickTextInput::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 QQuickTextField::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
@@ -409,6 +514,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);