Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquicktextfield.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
11
12#include <QtQuick/private/qquickitem_p.h>
13#include <QtQuick/private/qquicktextinput_p.h>
14#include <QtQuick/private/qquickclipnode_p.h>
15
16#if QT_CONFIG(accessibility)
17#include <QtQuick/private/qquickaccessibleattached_p.h>
18#endif
19
21
22using namespace Qt::StringLiterals;
23
24/*!
25 \qmltype TextField
26 \inherits TextInput
27//! \nativetype QQuickTextField
28 \inqmlmodule QtQuick.Controls
29 \since 5.7
30 \ingroup qtquickcontrols-input
31 \brief Single-line text input field.
32
33 TextField is a single line text editor. TextField extends TextInput with
34 a \l {placeholderText}{placeholder text} functionality, and adds decoration.
35
36 \table
37 \row \li \image qtquickcontrols-textfield-normal.png
38 {Text field in normal state}
39 \li A text field in its normal state.
40 \row \li \image qtquickcontrols-textfield-focused.png
41 {Text field in focused state with highlight}
42 \li A text field that has active focus.
43 \row \li \image qtquickcontrols-textfield-disabled.png
44 {Text field in disabled state}
45 \li A text field that is disabled.
46 \endtable
47
48 \code
49 TextField {
50 placeholderText: qsTr("Enter name")
51 }
52 \endcode
53
54 \sa TextArea, {Customizing TextField}, {Input Controls}
55*/
56
57/*!
58 \qmlsignal QtQuick.Controls::TextField::pressAndHold(MouseEvent event)
59
60 This signal is emitted when there is a long press (the delay depends on the platform plugin).
61 The \a event parameter provides information about the press, including the x and y
62 coordinates of the press, and which button is pressed.
63
64 \sa pressed, released
65*/
66
67/*!
68 \qmlsignal QtQuick.Controls::TextField::pressed(MouseEvent event)
69 \since QtQuick.Controls 2.1 (Qt 5.8)
70
71 This signal is emitted when the text field is pressed by the user.
72 The \a event parameter provides information about the press,
73 including the x and y coordinates of the press, and which button
74 is pressed.
75
76 \sa released, pressAndHold
77*/
78
79/*!
80 \qmlsignal QtQuick.Controls::TextField::released(MouseEvent event)
81 \since QtQuick.Controls 2.1 (Qt 5.8)
82
83 This signal is emitted when the text field is released by the user.
84 The \a event parameter provides information about the release,
85 including the x and y coordinates of the press, and which button
86 is pressed.
87
88 \sa pressed, pressAndHold
89*/
90
91QQuickTextFieldPrivate::QQuickTextFieldPrivate()
92{
93}
94
98
99void QQuickTextFieldPrivate::setTopInset(qreal value, bool reset)
100{
101 Q_Q(QQuickTextField);
102 const QMarginsF oldInset = getInset();
103 extra.value().topInset = value;
104 extra.value().hasTopInset = !reset;
105 if (!qFuzzyCompare(oldInset.top(), value)) {
106 emit q->topInsetChanged();
107 q->insetChange(getInset(), oldInset);
108 }
109}
110
111void QQuickTextFieldPrivate::setLeftInset(qreal value, bool reset)
112{
113 Q_Q(QQuickTextField);
114 const QMarginsF oldInset = getInset();
115 extra.value().leftInset = value;
116 extra.value().hasLeftInset = !reset;
117 if (!qFuzzyCompare(oldInset.left(), value)) {
118 emit q->leftInsetChanged();
119 q->insetChange(getInset(), oldInset);
120 }
121}
122
123void QQuickTextFieldPrivate::setRightInset(qreal value, bool reset)
124{
125 Q_Q(QQuickTextField);
126 const QMarginsF oldInset = getInset();
127 extra.value().rightInset = value;
128 extra.value().hasRightInset = !reset;
129 if (!qFuzzyCompare(oldInset.right(), value)) {
130 emit q->rightInsetChanged();
131 q->insetChange(getInset(), oldInset);
132 }
133}
134
135void QQuickTextFieldPrivate::setBottomInset(qreal value, bool reset)
136{
137 Q_Q(QQuickTextField);
138 const QMarginsF oldInset = getInset();
139 extra.value().bottomInset = value;
140 extra.value().hasBottomInset = !reset;
141 if (!qFuzzyCompare(oldInset.bottom(), value)) {
142 emit q->bottomInsetChanged();
143 q->insetChange(getInset(), oldInset);
144 }
145}
146
148{
149 if (!background)
150 return;
151
152 resizingBackground = true;
153
154 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
155 if (((!p->widthValid() || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x()))
156 || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) {
157 const bool wasWidthValid = p->widthValid();
158 background->setX(getLeftInset());
159 background->setWidth(width - getLeftInset() - getRightInset());
160 // If the user hadn't previously set the width, that shouldn't change when we set it for them.
161 if (!wasWidthValid)
162 p->widthValidFlag = false;
163 }
164 if (((!p->heightValid() || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
165 || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) {
166 const bool wasHeightValid = p->heightValid();
167 background->setY(getTopInset());
168 background->setHeight(height - getTopInset() - getBottomInset());
169 if (!wasHeightValid)
170 p->heightValidFlag = false;
171 }
172
173 resizingBackground = false;
174}
175
176/*!
177 \internal
178
179 Determine which font is implicitly imposed on this control by its ancestors
180 and QGuiApplication::font, resolve this against its own font (attributes from
181 the implicit font are copied over). Then propagate this font to this
182 control's children.
183*/
185{
186 Q_Q(QQuickTextField);
187 inheritFont(QQuickControlPrivate::parentFont(q));
188}
189
190void QQuickTextFieldPrivate::inheritFont(const QFont &font)
191{
192 QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font;
193 parentFont.setResolveMask(extra.isAllocated() ? extra->requestedFont.resolveMask() | font.resolveMask() : font.resolveMask());
194
195 const QFont defaultFont = QQuickTheme::font(QQuickTheme::TextField);
196 QFont resolvedFont = parentFont.resolve(defaultFont);
197
198 setFont_helper(resolvedFont);
199}
200
201/*!
202 \internal
203
204 Assign \a font to this control, and propagate it to all children.
205*/
206void QQuickTextFieldPrivate::updateFont(const QFont &font)
207{
208 Q_Q(QQuickTextField);
209 QFont oldFont = sourceFont;
210 q->QQuickTextInput::setFont(font);
211
212 QQuickControlPrivate::updateFontRecur(q, font);
213
214 if (oldFont != font)
215 emit q->fontChanged();
216}
217
218#if QT_CONFIG(quicktemplates2_hover)
219void QQuickTextFieldPrivate::updateHoverEnabled(bool enabled, bool xplicit)
220{
221 Q_Q(QQuickTextField);
222 if (!xplicit && explicitHoverEnabled)
223 return;
224
225 bool wasEnabled = q->isHoverEnabled();
226 explicitHoverEnabled = xplicit;
227 if (wasEnabled != enabled) {
228 q->setAcceptHoverEvents(enabled);
229 QQuickControlPrivate::updateHoverEnabledRecur(q, enabled);
230 emit q->hoverEnabledChanged();
231 }
232}
233#endif
234
236{
237 return QQuickItemPrivate::getImplicitWidth();
238}
239
241{
242 return QQuickItemPrivate::getImplicitHeight();
243}
244
246{
247 Q_Q(QQuickTextField);
248 QQuickItemPrivate::implicitWidthChanged();
249 emit q->implicitWidthChanged3();
250}
251
253{
254 Q_Q(QQuickTextField);
255 QQuickItemPrivate::implicitHeightChanged();
256 emit q->implicitHeightChanged3();
257}
258
260{
261 QQuickTextInputPrivate::readOnlyChanged(isReadOnly);
262#if QT_CONFIG(cursor)
263 q_func()->setCursor(isReadOnly && !selectByMouse ? Qt::ArrowCursor : Qt::IBeamCursor);
264#endif
265}
266
267#if QT_CONFIG(accessibility)
268void QQuickTextFieldPrivate::accessibilityActiveChanged(bool active)
269{
270 QQuickTextInputPrivate::accessibilityActiveChanged(active);
271
272 if (!active)
273 return;
274 Q_Q(QQuickTextField);
275 QQuickAccessibleAttached *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q, true));
276 Q_ASSERT(accessibleAttached);
277 accessibleAttached->setDescriptionImplicitly(placeholder);
278}
279
280#endif
281
283{
284 Q_Q(QQuickTextField);
285 quickCancelDeferred(q, backgroundName());
286}
287
289{
290 Q_Q(QQuickTextField);
291 if (background.wasExecuted())
292 return;
293
294 if (!background || complete)
295 quickBeginDeferred(q, backgroundName(), background);
296 if (complete)
297 quickCompleteDeferred(q, backgroundName(), background);
298}
299
300void QQuickTextFieldPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff)
301{
302 Q_UNUSED(diff);
303 if (resizingBackground || item != background || !change.sizeChange())
304 return;
305
306 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
307 // QTBUG-71875: only allocate the extra data if we have to.
308 // resizeBackground() relies on the value of extra.isAllocated()
309 // as part of its checks to see whether it should resize the background or not.
310 if (p->widthValid() || extra.isAllocated())
311 extra.value().hasBackgroundWidth = p->widthValid();
312 if (p->heightValid() || extra.isAllocated())
313 extra.value().hasBackgroundHeight = p->heightValid();
315}
316
318{
319 Q_Q(QQuickTextField);
320 if (item == background)
321 emit q->implicitBackgroundWidthChanged();
322}
323
325{
326 Q_Q(QQuickTextField);
327 if (item == background)
328 emit q->implicitBackgroundHeightChanged();
329}
330
332{
333 Q_Q(QQuickTextField);
334 if (item == background) {
335 background = nullptr;
336 emit q->implicitBackgroundWidthChanged();
337 emit q->implicitBackgroundHeightChanged();
338 }
339}
340
342{
343 return QQuickTheme::palette(QQuickTheme::TextField);
344}
345
347{
348 Q_Q(QQuickTextField);
349 const auto focusReasonChanged = QQuickItemPrivate::setLastFocusChangeReason(reason);
350 if (focusReasonChanged)
351 emit q->focusReasonChanged();
352
353 return focusReasonChanged;
354}
355
356QQuickTextField::QQuickTextField(QQuickItem *parent)
357 : QQuickTextInput(*(new QQuickTextFieldPrivate), parent)
358{
359 Q_D(QQuickTextField);
360 d->pressHandler.control = this;
361 d->setImplicitResizeEnabled(false);
362 setAcceptedMouseButtons(Qt::AllButtons);
363 setActiveFocusOnTab(true);
364#if QT_CONFIG(cursor)
365 setCursor(Qt::IBeamCursor);
366#endif
367#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
368 if (qEnvironmentVariable("QT_QUICK_CONTROLS_TEXT_SELECTION_BEHAVIOR") == u"old"_s)
369 QQuickTextInput::setOldSelectionDefault();
370#endif
371}
372
373QQuickTextField::~QQuickTextField()
374{
375 Q_D(QQuickTextField);
376 QQuickControlPrivate::removeImplicitSizeListener(d->background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
377}
378
379QFont QQuickTextField::font() const
380{
381 Q_D(const QQuickTextField);
382 QFont font = QQuickTextInput::font();
383 // The resolve mask should inherit from the requestedFont
384 font.setResolveMask(d->extra.value().requestedFont.resolveMask());
385 return font;
386}
387
388void QQuickTextField::setFont(const QFont &font)
389{
390 Q_D(QQuickTextField);
391 if (d->extra.value().requestedFont.resolveMask() == font.resolveMask() && d->extra.value().requestedFont == font)
392 return;
393
394 d->extra.value().requestedFont = font;
395 d->resolveFont();
396}
397
398/*!
399 \qmlproperty Item QtQuick.Controls::TextField::background
400
401 This property holds the background item.
402
403 \input qquickcontrol-background.qdocinc notes
404
405 \sa {Customizing TextField}
406*/
407QQuickItem *QQuickTextField::background() const
408{
409 QQuickTextFieldPrivate *d = const_cast<QQuickTextFieldPrivate *>(d_func());
410 if (!d->background)
411 d->executeBackground();
412 return d->background;
413}
414
415void QQuickTextField::setBackground(QQuickItem *background)
416{
417 Q_D(QQuickTextField);
418 if (d->background == background)
419 return;
420
421 QQuickControlPrivate::warnIfCustomizationNotSupported(this, background, QStringLiteral("background"));
422
423 if (!d->background.isExecuting())
424 d->cancelBackground();
425
426 const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
427 const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
428
429 if (d->extra.isAllocated()) {
430 d->extra.value().hasBackgroundWidth = false;
431 d->extra.value().hasBackgroundHeight = false;
432 }
433
434 QQuickControlPrivate::removeImplicitSizeListener(d->background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
435 QQuickControlPrivate::hideOldItem(d->background);
436 d->background = background;
437
438 if (background) {
439 background->setParentItem(this);
440 if (qFuzzyIsNull(background->z()))
441 background->setZ(-1);
442 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
443 if (p->widthValid() || p->heightValid()) {
444 d->extra.value().hasBackgroundWidth = p->widthValid();
445 d->extra.value().hasBackgroundHeight = p->heightValid();
446 }
447 if (isComponentComplete())
448 d->resizeBackground();
449 QQuickControlPrivate::addImplicitSizeListener(background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
450 }
451
452 if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
453 emit implicitBackgroundWidthChanged();
454 if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
455 emit implicitBackgroundHeightChanged();
456 if (!d->background.isExecuting())
457 emit backgroundChanged();
458}
459
460/*!
461 \qmlproperty string QtQuick.Controls::TextField::placeholderText
462
463 This property holds the hint that is displayed in the TextField before the user
464 enters text.
465*/
466QString QQuickTextField::placeholderText() const
467{
468 Q_D(const QQuickTextField);
469 return d->placeholder;
470}
471
472void QQuickTextField::setPlaceholderText(const QString &text)
473{
474 Q_D(QQuickTextField);
475 if (d->placeholder == text)
476 return;
477
478 d->placeholder = text;
479#if QT_CONFIG(accessibility)
480 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(this))
481 accessibleAttached->setDescriptionImplicitly(text);
482#endif
483 emit placeholderTextChanged();
484}
485
486/*!
487 \qmlproperty color QtQuick.Controls::TextField::placeholderTextColor
488 \since QtQuick.Controls 2.5 (Qt 5.12)
489
490 This property holds the color of placeholderText.
491
492 \sa placeholderText
493*/
494QColor QQuickTextField::placeholderTextColor() const
495{
496 Q_D(const QQuickTextField);
497 return d->placeholderColor;
498}
499
500void QQuickTextField::setPlaceholderTextColor(const QColor &color)
501{
502 Q_D(QQuickTextField);
503 if (d->placeholderColor == color)
504 return;
505
506 d->placeholderColor = color;
507 emit placeholderTextColorChanged();
508}
509
510/*!
511 \qmlproperty enumeration QtQuick.Controls::TextField::focusReason
512
513 This property holds the reason of the last focus change.
514
515 \note This property does not indicate whether the item has \l {Item::activeFocus}
516 {active focus}, but the reason why the item either gained or lost focus.
517
518 \value Qt.MouseFocusReason A mouse action occurred.
519 \value Qt.TabFocusReason The Tab key was pressed.
520 \value Qt.BacktabFocusReason A Backtab occurred. The input for this may include the Shift or Control keys; e.g. Shift+Tab.
521 \value Qt.ActiveWindowFocusReason The window system made this window either active or inactive.
522 \value Qt.PopupFocusReason The application opened/closed a pop-up that grabbed/released the keyboard focus.
523 \value Qt.ShortcutFocusReason The user typed a label's buddy shortcut
524 \value Qt.MenuBarFocusReason The menu bar took focus.
525 \value Qt.OtherFocusReason Another reason, usually application-specific.
526
527 \note Prefer \l {QtQuick.Controls::Control::focusReason} to this property.
528*/
529Qt::FocusReason QQuickTextField::focusReason() const
530{
531 Q_D(const QQuickTextField);
532 return d->lastFocusChangeReason();
533}
534
535void QQuickTextField::setFocusReason(Qt::FocusReason reason)
536{
537 Q_D(QQuickTextField);
538 d->setLastFocusChangeReason(reason);
539}
540
541/*!
542 \since QtQuick.Controls 2.1 (Qt 5.8)
543 \qmlproperty bool QtQuick.Controls::TextField::hovered
544 \readonly
545
546 This property holds whether the text field is hovered.
547
548 \sa hoverEnabled
549*/
550bool QQuickTextField::isHovered() const
551{
552#if QT_CONFIG(quicktemplates2_hover)
553 Q_D(const QQuickTextField);
554 return d->hovered;
555#else
556 return false;
557#endif
558}
559
560void QQuickTextField::setHovered(bool hovered)
561{
562#if QT_CONFIG(quicktemplates2_hover)
563 Q_D(QQuickTextField);
564 if (hovered == d->hovered)
565 return;
566
567 d->hovered = hovered;
568 emit hoveredChanged();
569 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(this, hovered);
570#else
571 Q_UNUSED(hovered);
572#endif
573}
574
575/*!
576 \since QtQuick.Controls 2.1 (Qt 5.8)
577 \qmlproperty bool QtQuick.Controls::TextField::hoverEnabled
578
579 This property determines whether the text field accepts hover events. The default value is \c false.
580
581 \sa hovered
582*/
583bool QQuickTextField::isHoverEnabled() const
584{
585#if QT_CONFIG(quicktemplates2_hover)
586 Q_D(const QQuickTextField);
587 return d->hoverEnabled;
588#else
589 return false;
590#endif
591}
592
593void QQuickTextField::setHoverEnabled(bool enabled)
594{
595#if QT_CONFIG(quicktemplates2_hover)
596 Q_D(QQuickTextField);
597 if (d->explicitHoverEnabled && enabled == d->hoverEnabled)
598 return;
599
600 d->updateHoverEnabled(enabled, true); // explicit=true
601#else
602 Q_UNUSED(enabled);
603#endif
604}
605
606void QQuickTextField::resetHoverEnabled()
607{
608#if QT_CONFIG(quicktemplates2_hover)
609 Q_D(QQuickTextField);
610 if (!d->explicitHoverEnabled)
611 return;
612
613 d->explicitHoverEnabled = false;
614 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem), false); // explicit=false
615#endif
616}
617
618void QQuickTextField::classBegin()
619{
620 Q_D(QQuickTextField);
621 QQuickTextInput::classBegin();
622 d->resolveFont();
623}
624
625/*!
626 \since QtQuick.Controls 2.5 (Qt 5.12)
627 \qmlproperty real QtQuick.Controls::TextField::implicitBackgroundWidth
628 \readonly
629
630 This property holds the implicit background width.
631
632 The value is equal to \c {background ? background.implicitWidth : 0}.
633
634 \sa implicitBackgroundHeight
635*/
636qreal QQuickTextField::implicitBackgroundWidth() const
637{
638 Q_D(const QQuickTextField);
639 if (!d->background)
640 return 0;
641 return d->background->implicitWidth();
642}
643
644/*!
645 \since QtQuick.Controls 2.5 (Qt 5.12)
646 \qmlproperty real QtQuick.Controls::TextField::implicitBackgroundHeight
647 \readonly
648
649 This property holds the implicit background height.
650
651 The value is equal to \c {background ? background.implicitHeight : 0}.
652
653 \sa implicitBackgroundWidth
654*/
655qreal QQuickTextField::implicitBackgroundHeight() const
656{
657 Q_D(const QQuickTextField);
658 if (!d->background)
659 return 0;
660 return d->background->implicitHeight();
661}
662
663/*!
664 \since QtQuick.Controls 2.5 (Qt 5.12)
665 \qmlproperty real QtQuick.Controls::TextField::topInset
666
667 This property holds the top inset for the background.
668
669 \sa {Control Layout}, bottomInset
670*/
671qreal QQuickTextField::topInset() const
672{
673 Q_D(const QQuickTextField);
674 return d->getTopInset();
675}
676
677void QQuickTextField::setTopInset(qreal inset)
678{
679 Q_D(QQuickTextField);
680 d->setTopInset(inset);
681}
682
683void QQuickTextField::resetTopInset()
684{
685 Q_D(QQuickTextField);
686 d->setTopInset(0, true);
687}
688
689/*!
690 \since QtQuick.Controls 2.5 (Qt 5.12)
691 \qmlproperty real QtQuick.Controls::TextField::leftInset
692
693 This property holds the left inset for the background.
694
695 \sa {Control Layout}, rightInset
696*/
697qreal QQuickTextField::leftInset() const
698{
699 Q_D(const QQuickTextField);
700 return d->getLeftInset();
701}
702
703void QQuickTextField::setLeftInset(qreal inset)
704{
705 Q_D(QQuickTextField);
706 d->setLeftInset(inset);
707}
708
709void QQuickTextField::resetLeftInset()
710{
711 Q_D(QQuickTextField);
712 d->setLeftInset(0, true);
713}
714
715/*!
716 \since QtQuick.Controls 2.5 (Qt 5.12)
717 \qmlproperty real QtQuick.Controls::TextField::rightInset
718
719 This property holds the right inset for the background.
720
721 \sa {Control Layout}, leftInset
722*/
723qreal QQuickTextField::rightInset() const
724{
725 Q_D(const QQuickTextField);
726 return d->getRightInset();
727}
728
729void QQuickTextField::setRightInset(qreal inset)
730{
731 Q_D(QQuickTextField);
732 d->setRightInset(inset);
733}
734
735void QQuickTextField::resetRightInset()
736{
737 Q_D(QQuickTextField);
738 d->setRightInset(0, true);
739}
740
741/*!
742 \since QtQuick.Controls 2.5 (Qt 5.12)
743 \qmlproperty real QtQuick.Controls::TextField::bottomInset
744
745 This property holds the bottom inset for the background.
746
747 \sa {Control Layout}, topInset
748*/
749qreal QQuickTextField::bottomInset() const
750{
751 Q_D(const QQuickTextField);
752 return d->getBottomInset();
753}
754
755void QQuickTextField::setBottomInset(qreal inset)
756{
757 Q_D(QQuickTextField);
758 d->setBottomInset(inset);
759}
760
761void QQuickTextField::resetBottomInset()
762{
763 Q_D(QQuickTextField);
764 d->setBottomInset(0, true);
765}
766
767void QQuickTextField::componentComplete()
768{
769 Q_D(QQuickTextField);
770 d->executeBackground(true);
771 QQuickTextInput::componentComplete();
772 d->resizeBackground();
773#if QT_CONFIG(quicktemplates2_hover)
774 if (!d->explicitHoverEnabled)
775 setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem));
776#endif
777}
778
779void QQuickTextField::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
780{
781 Q_D(QQuickTextField);
782 QQuickTextInput::itemChange(change, value);
783 switch (change) {
784 case ItemEnabledHasChanged:
785 break;
786 case ItemSceneChange:
787 case ItemParentHasChanged:
788 if ((change == ItemParentHasChanged && value.item) || (change == ItemSceneChange && value.window)) {
789 d->resolveFont();
790#if QT_CONFIG(quicktemplates2_hover)
791 if (!d->explicitHoverEnabled)
792 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem), false); // explicit=false
793#endif
794 }
795 break;
796 default:
797 break;
798 }
799}
800
801void QQuickTextField::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
802{
803 Q_D(QQuickTextField);
804 QQuickTextInput::geometryChange(newGeometry, oldGeometry);
805 d->resizeBackground();
806}
807
808void QQuickTextField::insetChange(const QMarginsF &newInset, const QMarginsF &oldInset)
809{
810 Q_D(QQuickTextField);
811 Q_UNUSED(newInset);
812 Q_UNUSED(oldInset);
813 d->resizeBackground();
814}
815QSGNode *QQuickTextField::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
816{
817 QQuickDefaultClipNode *clipNode = static_cast<QQuickDefaultClipNode *>(oldNode);
818 if (!clipNode)
819 clipNode = new QQuickDefaultClipNode(QRectF());
820
821 clipNode->setRect(clipRect().adjusted(leftPadding(), topPadding(), -rightPadding(), -bottomPadding()));
822 clipNode->update();
823
824 QSGNode *textNode = QQuickTextInput::updatePaintNode(clipNode->firstChild(), data);
825 if (!textNode->parent())
826 clipNode->appendChildNode(textNode);
827
828 return clipNode;
829}
830
831void QQuickTextField::focusInEvent(QFocusEvent *event)
832{
833 QQuickTextInput::focusInEvent(event);
834}
835
836void QQuickTextField::focusOutEvent(QFocusEvent *event)
837{
838 QQuickTextInput::focusOutEvent(event);
839}
840
841#if QT_CONFIG(quicktemplates2_hover)
842void QQuickTextField::hoverEnterEvent(QHoverEvent *event)
843{
844 Q_D(QQuickTextField);
845 QQuickTextInput::hoverEnterEvent(event);
846 setHovered(d->hoverEnabled);
847 event->ignore();
848}
849
850void QQuickTextField::hoverLeaveEvent(QHoverEvent *event)
851{
852 QQuickTextInput::hoverLeaveEvent(event);
853 setHovered(false);
854 event->ignore();
855}
856#endif
857
858void QQuickTextField::mousePressEvent(QMouseEvent *event)
859{
860 Q_D(QQuickTextField);
861 d->pressHandler.mousePressEvent(event);
862 if (d->pressHandler.isActive()) {
863 if (d->pressHandler.delayedMousePressEvent) {
864 QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent.get());
865 d->pressHandler.clearDelayedMouseEvent();
866 }
867 if (event->buttons() != Qt::RightButton)
868 QQuickTextInput::mousePressEvent(event);
869 }
870}
871
872void QQuickTextField::mouseMoveEvent(QMouseEvent *event)
873{
874 Q_D(QQuickTextField);
875 d->pressHandler.mouseMoveEvent(event);
876 if (d->pressHandler.isActive()) {
877 if (d->pressHandler.delayedMousePressEvent) {
878 QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent.get());
879 d->pressHandler.clearDelayedMouseEvent();
880 }
881 const bool isMouse = QQuickDeliveryAgentPrivate::isEventFromMouseOrTouchpad(event)
882 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
883 || d->selectByTouchDrag
884 #endif
885 ;
886 if (event->buttons() != Qt::RightButton && isMouse)
887 QQuickTextInput::mouseMoveEvent(event);
888 }
889}
890
891void QQuickTextField::mouseReleaseEvent(QMouseEvent *event)
892{
893 Q_D(QQuickTextField);
894 d->pressHandler.mouseReleaseEvent(event);
895 if (d->pressHandler.isActive()) {
896 if (d->pressHandler.delayedMousePressEvent) {
897 QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent.get());
898 d->pressHandler.clearDelayedMouseEvent();
899 }
900 if (event->buttons() != Qt::RightButton)
901 QQuickTextInput::mouseReleaseEvent(event);
902 }
903}
904
905void QQuickTextField::mouseDoubleClickEvent(QMouseEvent *event)
906{
907 Q_D(QQuickTextField);
908 if (d->pressHandler.delayedMousePressEvent) {
909 QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent.get());
910 d->pressHandler.clearDelayedMouseEvent();
911 }
912 if (event->buttons() != Qt::RightButton)
913 QQuickTextInput::mouseDoubleClickEvent(event);
914}
915
916void QQuickTextField::timerEvent(QTimerEvent *event)
917{
918 Q_D(QQuickTextField);
919 if (event->timerId() == d->pressHandler.timer.timerId())
920 d->pressHandler.timerEvent(event);
921 else
922 QQuickTextInput::timerEvent(event);
923}
924
925QT_END_NAMESPACE
926
927#include "moc_qquicktextfield_p.cpp"
void executeBackground(bool complete=false)
void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) override
qreal getImplicitHeight() const override
void setBottomInset(qreal value, bool reset=false)
void inheritFont(const QFont &font)
void setRightInset(qreal value, bool reset=false)
void itemImplicitWidthChanged(QQuickItem *item) override
virtual void readOnlyChanged(bool isReadOnly) override
void itemImplicitHeightChanged(QQuickItem *item) override
void setLeftInset(qreal value, bool reset=false)
qreal getImplicitWidth() const override
void implicitHeightChanged() override
void setTopInset(qreal value, bool reset=false)
void itemDestroyed(QQuickItem *item) override
void implicitWidthChanged() override
void updateFont(const QFont &font)
QPalette defaultPalette() const override
bool setLastFocusChangeReason(Qt::FocusReason reason) override
Combined button and popup list for selecting options.