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