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