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.isAllocated() ? d->extra->requestedFont.resolveMask() : 0);
385 return font;
386}
387
388void QQuickTextField::setFont(const QFont &font)
389{
390 Q_D(QQuickTextField);
391 if (d->extra.isAllocated()
392 && d->extra.value().requestedFont.resolveMask() == font.resolveMask()
393 && d->extra.value().requestedFont == font)
394 return;
395
396 d->extra.value().requestedFont = font;
397 d->resolveFont();
398}
399
400/*!
401 \qmlproperty Item QtQuick.Controls::TextField::background
402
403 This property holds the background item.
404
405 \input qquickcontrol-background.qdocinc notes
406
407 \sa {Customizing TextField}
408*/
409QQuickItem *QQuickTextField::background() const
410{
411 QQuickTextFieldPrivate *d = const_cast<QQuickTextFieldPrivate *>(d_func());
412 if (!d->background)
413 d->executeBackground();
414 return d->background;
415}
416
417void QQuickTextField::setBackground(QQuickItem *background)
418{
419 Q_D(QQuickTextField);
420 if (d->background == background)
421 return;
422
423 QQuickControlPrivate::warnIfCustomizationNotSupported(this, background, QStringLiteral("background"));
424
425 if (!d->background.isExecuting())
426 d->cancelBackground();
427
428 const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
429 const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
430
431 if (d->extra.isAllocated()) {
432 d->extra.value().hasBackgroundWidth = false;
433 d->extra.value().hasBackgroundHeight = false;
434 }
435
436 QQuickControlPrivate::removeImplicitSizeListener(d->background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
437 QQuickControlPrivate::hideOldItem(d->background);
438 d->background = background;
439
440 if (background) {
441 background->setParentItem(this);
442 if (qFuzzyIsNull(background->z()))
443 background->setZ(-1);
444 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
445 if (p->widthValid() || p->heightValid()) {
446 d->extra.value().hasBackgroundWidth = p->widthValid();
447 d->extra.value().hasBackgroundHeight = p->heightValid();
448 }
449 if (isComponentComplete())
450 d->resizeBackground();
451 QQuickControlPrivate::addImplicitSizeListener(background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
452 }
453
454 if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
455 emit implicitBackgroundWidthChanged();
456 if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
457 emit implicitBackgroundHeightChanged();
458 if (!d->background.isExecuting())
459 emit backgroundChanged();
460}
461
462/*!
463 \qmlproperty string QtQuick.Controls::TextField::placeholderText
464
465 This property holds the hint that is displayed in the TextField before the user
466 enters text.
467*/
468QString QQuickTextField::placeholderText() const
469{
470 Q_D(const QQuickTextField);
471 return d->placeholder;
472}
473
474void QQuickTextField::setPlaceholderText(const QString &text)
475{
476 Q_D(QQuickTextField);
477 if (d->placeholder == text)
478 return;
479
480 d->placeholder = text;
481#if QT_CONFIG(accessibility)
482 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(this))
483 accessibleAttached->setDescriptionImplicitly(text);
484#endif
485 emit placeholderTextChanged();
486}
487
488/*!
489 \qmlproperty color QtQuick.Controls::TextField::placeholderTextColor
490 \since QtQuick.Controls 2.5 (Qt 5.12)
491
492 This property holds the color of placeholderText.
493
494 \sa placeholderText
495*/
496QColor QQuickTextField::placeholderTextColor() const
497{
498 Q_D(const QQuickTextField);
499 return d->placeholderColor;
500}
501
502void QQuickTextField::setPlaceholderTextColor(const QColor &color)
503{
504 Q_D(QQuickTextField);
505 if (d->placeholderColor == color)
506 return;
507
508 d->placeholderColor = color;
509 emit placeholderTextColorChanged();
510}
511
512/*!
513 \qmlproperty enumeration QtQuick.Controls::TextField::focusReason
514
515 This property holds the reason of the last focus change.
516
517 \note This property does not indicate whether the item has \l {Item::activeFocus}
518 {active focus}, but the reason why the item either gained or lost focus.
519
520 \value Qt.MouseFocusReason A mouse action occurred.
521 \value Qt.TabFocusReason The Tab key was pressed.
522 \value Qt.BacktabFocusReason A Backtab occurred. The input for this may include the Shift or Control keys; e.g. Shift+Tab.
523 \value Qt.ActiveWindowFocusReason The window system made this window either active or inactive.
524 \value Qt.PopupFocusReason The application opened/closed a pop-up that grabbed/released the keyboard focus.
525 \value Qt.ShortcutFocusReason The user typed a label's buddy shortcut
526 \value Qt.MenuBarFocusReason The menu bar took focus.
527 \value Qt.OtherFocusReason Another reason, usually application-specific.
528
529 \note Prefer \l {QtQuick.Controls::Control::focusReason} to this property.
530*/
531Qt::FocusReason QQuickTextField::focusReason() const
532{
533 Q_D(const QQuickTextField);
534 return d->lastFocusChangeReason();
535}
536
537void QQuickTextField::setFocusReason(Qt::FocusReason reason)
538{
539 Q_D(QQuickTextField);
540 d->setLastFocusChangeReason(reason);
541}
542
543/*!
544 \since QtQuick.Controls 2.1 (Qt 5.8)
545 \qmlproperty bool QtQuick.Controls::TextField::hovered
546 \readonly
547
548 This property holds whether the text field is hovered.
549
550 \sa hoverEnabled
551*/
552bool QQuickTextField::isHovered() const
553{
554#if QT_CONFIG(quicktemplates2_hover)
555 Q_D(const QQuickTextField);
556 return d->hovered;
557#else
558 return false;
559#endif
560}
561
562void QQuickTextField::setHovered(bool hovered)
563{
564#if QT_CONFIG(quicktemplates2_hover)
565 Q_D(QQuickTextField);
566 if (hovered == d->hovered)
567 return;
568
569 d->hovered = hovered;
570 emit hoveredChanged();
571 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(this, hovered);
572#else
573 Q_UNUSED(hovered);
574#endif
575}
576
577/*!
578 \since QtQuick.Controls 2.1 (Qt 5.8)
579 \qmlproperty bool QtQuick.Controls::TextField::hoverEnabled
580
581 This property determines whether the text field accepts hover events. The default value is \c false.
582
583 \sa hovered
584*/
585bool QQuickTextField::isHoverEnabled() const
586{
587#if QT_CONFIG(quicktemplates2_hover)
588 Q_D(const QQuickTextField);
589 return d->hoverEnabled;
590#else
591 return false;
592#endif
593}
594
595void QQuickTextField::setHoverEnabled(bool enabled)
596{
597#if QT_CONFIG(quicktemplates2_hover)
598 Q_D(QQuickTextField);
599 if (d->explicitHoverEnabled && enabled == d->hoverEnabled)
600 return;
601
602 d->updateHoverEnabled(enabled, true); // explicit=true
603#else
604 Q_UNUSED(enabled);
605#endif
606}
607
608void QQuickTextField::resetHoverEnabled()
609{
610#if QT_CONFIG(quicktemplates2_hover)
611 Q_D(QQuickTextField);
612 if (!d->explicitHoverEnabled)
613 return;
614
615 d->explicitHoverEnabled = false;
616 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem), false); // explicit=false
617#endif
618}
619
620void QQuickTextField::classBegin()
621{
622 Q_D(QQuickTextField);
623 QQuickTextInput::classBegin();
624 d->resolveFont();
625}
626
627/*!
628 \since QtQuick.Controls 2.5 (Qt 5.12)
629 \qmlproperty real QtQuick.Controls::TextField::implicitBackgroundWidth
630 \readonly
631
632 This property holds the implicit background width.
633
634 The value is equal to \c {background ? background.implicitWidth : 0}.
635
636 \sa implicitBackgroundHeight
637*/
638qreal QQuickTextField::implicitBackgroundWidth() const
639{
640 Q_D(const QQuickTextField);
641 if (!d->background)
642 return 0;
643 return d->background->implicitWidth();
644}
645
646/*!
647 \since QtQuick.Controls 2.5 (Qt 5.12)
648 \qmlproperty real QtQuick.Controls::TextField::implicitBackgroundHeight
649 \readonly
650
651 This property holds the implicit background height.
652
653 The value is equal to \c {background ? background.implicitHeight : 0}.
654
655 \sa implicitBackgroundWidth
656*/
657qreal QQuickTextField::implicitBackgroundHeight() const
658{
659 Q_D(const QQuickTextField);
660 if (!d->background)
661 return 0;
662 return d->background->implicitHeight();
663}
664
665/*!
666 \since QtQuick.Controls 2.5 (Qt 5.12)
667 \qmlproperty real QtQuick.Controls::TextField::topInset
668
669 This property holds the top inset for the background.
670
671 \sa {Control Layout}, bottomInset
672*/
673qreal QQuickTextField::topInset() const
674{
675 Q_D(const QQuickTextField);
676 return d->getTopInset();
677}
678
679void QQuickTextField::setTopInset(qreal inset)
680{
681 Q_D(QQuickTextField);
682 d->setTopInset(inset);
683}
684
685void QQuickTextField::resetTopInset()
686{
687 Q_D(QQuickTextField);
688 d->setTopInset(0, true);
689}
690
691/*!
692 \since QtQuick.Controls 2.5 (Qt 5.12)
693 \qmlproperty real QtQuick.Controls::TextField::leftInset
694
695 This property holds the left inset for the background.
696
697 \sa {Control Layout}, rightInset
698*/
699qreal QQuickTextField::leftInset() const
700{
701 Q_D(const QQuickTextField);
702 return d->getLeftInset();
703}
704
705void QQuickTextField::setLeftInset(qreal inset)
706{
707 Q_D(QQuickTextField);
708 d->setLeftInset(inset);
709}
710
711void QQuickTextField::resetLeftInset()
712{
713 Q_D(QQuickTextField);
714 d->setLeftInset(0, true);
715}
716
717/*!
718 \since QtQuick.Controls 2.5 (Qt 5.12)
719 \qmlproperty real QtQuick.Controls::TextField::rightInset
720
721 This property holds the right inset for the background.
722
723 \sa {Control Layout}, leftInset
724*/
725qreal QQuickTextField::rightInset() const
726{
727 Q_D(const QQuickTextField);
728 return d->getRightInset();
729}
730
731void QQuickTextField::setRightInset(qreal inset)
732{
733 Q_D(QQuickTextField);
734 d->setRightInset(inset);
735}
736
737void QQuickTextField::resetRightInset()
738{
739 Q_D(QQuickTextField);
740 d->setRightInset(0, true);
741}
742
743/*!
744 \since QtQuick.Controls 2.5 (Qt 5.12)
745 \qmlproperty real QtQuick.Controls::TextField::bottomInset
746
747 This property holds the bottom inset for the background.
748
749 \sa {Control Layout}, topInset
750*/
751qreal QQuickTextField::bottomInset() const
752{
753 Q_D(const QQuickTextField);
754 return d->getBottomInset();
755}
756
757void QQuickTextField::setBottomInset(qreal inset)
758{
759 Q_D(QQuickTextField);
760 d->setBottomInset(inset);
761}
762
763void QQuickTextField::resetBottomInset()
764{
765 Q_D(QQuickTextField);
766 d->setBottomInset(0, true);
767}
768
769void QQuickTextField::componentComplete()
770{
771 Q_D(QQuickTextField);
772 d->executeBackground(true);
773 QQuickTextInput::componentComplete();
774 d->resizeBackground();
775#if QT_CONFIG(quicktemplates2_hover)
776 if (!d->explicitHoverEnabled)
777 setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem));
778#endif
779}
780
781void QQuickTextField::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
782{
783 Q_D(QQuickTextField);
784 QQuickTextInput::itemChange(change, value);
785 switch (change) {
786 case ItemEnabledHasChanged:
787 break;
788 case ItemSceneChange:
789 case ItemParentHasChanged:
790 if ((change == ItemParentHasChanged && value.item) || (change == ItemSceneChange && value.window)) {
791 d->resolveFont();
792#if QT_CONFIG(quicktemplates2_hover)
793 if (!d->explicitHoverEnabled)
794 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem), false); // explicit=false
795#endif
796 }
797 break;
798 default:
799 break;
800 }
801}
802
803void QQuickTextField::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
804{
805 Q_D(QQuickTextField);
806 QQuickTextInput::geometryChange(newGeometry, oldGeometry);
807 d->resizeBackground();
808}
809
810void QQuickTextField::insetChange(const QMarginsF &newInset, const QMarginsF &oldInset)
811{
812 Q_D(QQuickTextField);
813 Q_UNUSED(newInset);
814 Q_UNUSED(oldInset);
815 d->resizeBackground();
816}
817QSGNode *QQuickTextField::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
818{
819 QQuickDefaultClipNode *clipNode = static_cast<QQuickDefaultClipNode *>(oldNode);
820 if (!clipNode)
821 clipNode = new QQuickDefaultClipNode(QRectF());
822
823 clipNode->setRect(clipRect().adjusted(leftPadding(), topPadding(), -rightPadding(), -bottomPadding()));
824 clipNode->update();
825
826 QSGNode *textNode = QQuickTextInput::updatePaintNode(clipNode->firstChild(), data);
827 if (!textNode->parent())
828 clipNode->appendChildNode(textNode);
829
830 return clipNode;
831}
832
833void QQuickTextField::focusInEvent(QFocusEvent *event)
834{
835 QQuickTextInput::focusInEvent(event);
836}
837
838void QQuickTextField::focusOutEvent(QFocusEvent *event)
839{
840 QQuickTextInput::focusOutEvent(event);
841}
842
843#if QT_CONFIG(quicktemplates2_hover)
844void QQuickTextField::hoverEnterEvent(QHoverEvent *event)
845{
846 Q_D(QQuickTextField);
847 QQuickTextInput::hoverEnterEvent(event);
848 setHovered(d->hoverEnabled);
849 event->ignore();
850}
851
852void QQuickTextField::hoverLeaveEvent(QHoverEvent *event)
853{
854 QQuickTextInput::hoverLeaveEvent(event);
855 setHovered(false);
856 event->ignore();
857}
858#endif
859
860void QQuickTextField::mousePressEvent(QMouseEvent *event)
861{
862 Q_D(QQuickTextField);
863 d->pressHandler.mousePressEvent(event);
864 if (d->pressHandler.isActive()) {
865 if (d->pressHandler.delayedMousePressEvent) {
866 QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent.get());
867 d->pressHandler.clearDelayedMouseEvent();
868 }
869 if (event->buttons() != Qt::RightButton)
870 QQuickTextInput::mousePressEvent(event);
871 }
872}
873
874void QQuickTextField::mouseMoveEvent(QMouseEvent *event)
875{
876 Q_D(QQuickTextField);
877 d->pressHandler.mouseMoveEvent(event);
878 if (d->pressHandler.isActive()) {
879 if (d->pressHandler.delayedMousePressEvent) {
880 QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent.get());
881 d->pressHandler.clearDelayedMouseEvent();
882 }
883 const bool isMouse = QQuickDeliveryAgentPrivate::isEventFromMouseOrTouchpad(event)
884 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
885 || d->selectByTouchDrag
886 #endif
887 ;
888 if (event->buttons() != Qt::RightButton && isMouse)
889 QQuickTextInput::mouseMoveEvent(event);
890 }
891}
892
893void QQuickTextField::mouseReleaseEvent(QMouseEvent *event)
894{
895 Q_D(QQuickTextField);
896 d->pressHandler.mouseReleaseEvent(event);
897 if (d->pressHandler.isActive()) {
898 if (d->pressHandler.delayedMousePressEvent) {
899 QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent.get());
900 d->pressHandler.clearDelayedMouseEvent();
901 }
902 if (event->buttons() != Qt::RightButton)
903 QQuickTextInput::mouseReleaseEvent(event);
904 }
905}
906
907void QQuickTextField::mouseDoubleClickEvent(QMouseEvent *event)
908{
909 Q_D(QQuickTextField);
910 if (d->pressHandler.delayedMousePressEvent) {
911 QQuickTextInput::mousePressEvent(d->pressHandler.delayedMousePressEvent.get());
912 d->pressHandler.clearDelayedMouseEvent();
913 }
914 if (event->buttons() != Qt::RightButton)
915 QQuickTextInput::mouseDoubleClickEvent(event);
916}
917
918void QQuickTextField::timerEvent(QTimerEvent *event)
919{
920 Q_D(QQuickTextField);
921 if (event->timerId() == d->pressHandler.timer.timerId())
922 d->pressHandler.timerEvent(event);
923 else
924 QQuickTextInput::timerEvent(event);
925}
926
927QT_END_NAMESPACE
928
929#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.