7#include <QtGui/qstylehints.h>
8#include <QtGui/qguiapplication.h>
22#if QT_CONFIG(accessibility)
23#include <QtQuick/private/qquickaccessibleattached_p.h>
28Q_LOGGING_CATEGORY(lcItemManagement,
"qt.quick.controls.control.itemmanagement")
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
117const QQuickItemPrivate::ChangeTypes QQuickControlPrivate::ImplicitSizeChanges = QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed;
121 return reason == Qt::TabFocusReason || reason == Qt::BacktabFocusReason || reason == Qt::ShortcutFocusReason;
124QQuickControlPrivate::QQuickControlPrivate()
126#if QT_CONFIG(accessibility)
127 QAccessible::installActivationObserver(
this);
131QQuickControlPrivate::~QQuickControlPrivate()
135void QQuickControlPrivate::init()
138 QObject::connect(q, &QQuickItem::baselineOffsetChanged, q, &QQuickControl::baselineOffsetChanged);
141#if QT_CONFIG(quicktemplates2_multitouch)
142bool QQuickControlPrivate::acceptTouch(
const QTouchEvent::TouchPoint &point)
144 if (point.id() == touchId)
147 if (touchId == -1 && point.state() == QEventPoint::Pressed) {
148 touchId = point.id();
156bool QQuickControlPrivate::handlePress(
const QPointF &, ulong)
161bool QQuickControlPrivate::handleMove(
const QPointF &point, ulong)
163#if QT_CONFIG(quicktemplates2_hover)
165 q->setHovered(hoverEnabled && q->contains(point));
172bool QQuickControlPrivate::handleRelease(
const QPointF &, ulong)
178void QQuickControlPrivate::handleUngrab()
183void QQuickControlPrivate::mirrorChange()
189void QQuickControlPrivate::setTopPadding(qreal value,
bool reset)
192 const QMarginsF oldPadding = getPadding();
193 extra.value().topPadding = value;
194 extra.value().hasTopPadding = !reset;
195 if ((!reset && !qFuzzyCompare(oldPadding.top(), value)) || (reset && !qFuzzyCompare(oldPadding.top(), getVerticalPadding()))) {
196 emit q->topPaddingChanged();
197 emit q->availableHeightChanged();
198 q->paddingChange(getPadding(), oldPadding);
202void QQuickControlPrivate::setLeftPadding(qreal value,
bool reset)
205 const QMarginsF oldPadding = getPadding();
206 extra.value().leftPadding = value;
207 extra.value().hasLeftPadding = !reset;
208 if ((!reset && !qFuzzyCompare(oldPadding.left(), value)) || (reset && !qFuzzyCompare(oldPadding.left(), getHorizontalPadding()))) {
209 emit q->leftPaddingChanged();
210 emit q->availableWidthChanged();
211 q->paddingChange(getPadding(), oldPadding);
215void QQuickControlPrivate::setRightPadding(qreal value,
bool reset)
218 const QMarginsF oldPadding = getPadding();
219 extra.value().rightPadding = value;
220 extra.value().hasRightPadding = !reset;
221 if ((!reset && !qFuzzyCompare(oldPadding.right(), value)) || (reset && !qFuzzyCompare(oldPadding.right(), getHorizontalPadding()))) {
222 emit q->rightPaddingChanged();
223 emit q->availableWidthChanged();
224 q->paddingChange(getPadding(), oldPadding);
228void QQuickControlPrivate::setBottomPadding(qreal value,
bool reset)
231 const QMarginsF oldPadding = getPadding();
232 extra.value().bottomPadding = value;
233 extra.value().hasBottomPadding = !reset;
234 if ((!reset && !qFuzzyCompare(oldPadding.bottom(), value)) || (reset && !qFuzzyCompare(oldPadding.bottom(), getVerticalPadding()))) {
235 emit q->bottomPaddingChanged();
236 emit q->availableHeightChanged();
237 q->paddingChange(getPadding(), oldPadding);
241void QQuickControlPrivate::setHorizontalPadding(qreal value,
bool reset)
244 const QMarginsF oldPadding = getPadding();
245 const qreal oldHorizontalPadding = getHorizontalPadding();
246 horizontalPadding = value;
247 hasHorizontalPadding = !reset;
248 if ((!reset && !qFuzzyCompare(oldHorizontalPadding, value)) || (reset && !qFuzzyCompare(oldHorizontalPadding, padding))) {
249 const QMarginsF newPadding = getPadding();
250 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()))
251 emit q->leftPaddingChanged();
252 if (!qFuzzyCompare(newPadding.right(), oldPadding.right()))
253 emit q->rightPaddingChanged();
254 emit q->horizontalPaddingChanged();
255 emit q->availableWidthChanged();
256 q->paddingChange(newPadding, oldPadding);
260void QQuickControlPrivate::setVerticalPadding(qreal value,
bool reset)
263 const QMarginsF oldPadding = getPadding();
264 const qreal oldVerticalPadding = getVerticalPadding();
265 verticalPadding = value;
266 hasVerticalPadding = !reset;
267 if ((!reset && !qFuzzyCompare(oldVerticalPadding, value)) || (reset && !qFuzzyCompare(oldVerticalPadding, padding))) {
268 const QMarginsF newPadding = getPadding();
269 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()))
270 emit q->topPaddingChanged();
271 if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
272 emit q->bottomPaddingChanged();
273 emit q->verticalPaddingChanged();
274 emit q->availableHeightChanged();
275 q->paddingChange(newPadding, oldPadding);
279void QQuickControlPrivate::setTopInset(qreal value,
bool reset)
282 const QMarginsF oldInset = getInset();
283 extra.value().topInset = value;
284 extra.value().hasTopInset = !reset;
285 if (!qFuzzyCompare(oldInset.top(), value)) {
286 emit q->topInsetChanged();
287 q->insetChange(getInset(), oldInset);
291void QQuickControlPrivate::setLeftInset(qreal value,
bool reset)
294 const QMarginsF oldInset = getInset();
295 extra.value().leftInset = value;
296 extra.value().hasLeftInset = !reset;
297 if (!qFuzzyCompare(oldInset.left(), value)) {
298 emit q->leftInsetChanged();
299 q->insetChange(getInset(), oldInset);
303void QQuickControlPrivate::setRightInset(qreal value,
bool reset)
306 const QMarginsF oldInset = getInset();
307 extra.value().rightInset = value;
308 extra.value().hasRightInset = !reset;
309 if (!qFuzzyCompare(oldInset.right(), value)) {
310 emit q->rightInsetChanged();
311 q->insetChange(getInset(), oldInset);
315void QQuickControlPrivate::setBottomInset(qreal value,
bool reset)
318 const QMarginsF oldInset = getInset();
319 extra.value().bottomInset = value;
320 extra.value().hasBottomInset = !reset;
321 if (!qFuzzyCompare(oldInset.bottom(), value)) {
322 emit q->bottomInsetChanged();
323 q->insetChange(getInset(), oldInset);
327void QQuickControlPrivate::resizeBackground()
332 resizingBackground =
true;
334 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
335 bool changeWidth =
false;
336 bool changeHeight =
false;
337 if (((!p->widthValid() || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x()))
338 || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) {
339 const auto leftInset = getLeftInset();
340 if (!qt_is_nan(leftInset) && p->x.valueBypassingBindings() != leftInset) {
342 p->x.setValueBypassingBindings(leftInset);
343 p->dirty(DirtyType::Position);
345 changeWidth = !p->width.hasBinding();
347 if (((!p->heightValid() || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
348 || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) {
349 const auto topInset = getTopInset();
350 if (!qt_is_nan(topInset) && p->y.valueBypassingBindings() != topInset) {
352 p->y.setValueBypassingBindings(topInset);
353 p->dirty(DirtyType::Position);
355 changeHeight = !p->height.hasBinding();
357 if (changeHeight || changeWidth) {
358 auto newWidth = changeWidth ?
359 width.valueBypassingBindings() - getLeftInset() - getRightInset() :
360 p->width.valueBypassingBindings();
361 auto newHeight = changeHeight ?
362 height.valueBypassingBindings() - getTopInset() - getBottomInset() :
363 p->height.valueBypassingBindings();
364 background->setSize({newWidth, newHeight});
367 resizingBackground =
false;
370void QQuickControlPrivate::resizeContent()
374 contentItem->setPosition(QPointF(q->leftPadding(), q->topPadding()));
375 contentItem->setSize(QSizeF(q->availableWidth(), q->availableHeight()));
379QQuickItem *QQuickControlPrivate::getContentItem()
382 executeContentItem();
386void QQuickControlPrivate::setContentItem_helper(QQuickItem *item,
bool notify)
389 if (contentItem == item)
393 warnIfCustomizationNotSupported(q, item, QStringLiteral(
"contentItem"));
395 if (!contentItem.isExecuting())
398 QQuickItem *oldContentItem = contentItem;
399 if (oldContentItem) {
400 disconnect(oldContentItem, &QQuickItem::baselineOffsetChanged,
this, &QQuickControlPrivate::updateBaselineOffset);
401 QQuickItemPrivate::get(oldContentItem)->removeItemChangeListener(
this, QQuickControlPrivate::Focus);
402 removeImplicitSizeListener(oldContentItem);
406 q->contentItemChange(item, oldContentItem);
407 QQuickControlPrivate::hideOldItem(oldContentItem);
410 connect(contentItem.data(), &QQuickItem::baselineOffsetChanged,
this, &QQuickControlPrivate::updateBaselineOffset);
414 QQuickItemPrivate::get(item)->addItemChangeListener(
this, QQuickControlPrivate::Focus);
415 if (!item->parentItem())
416 item->setParentItem(q);
417 if (componentComplete)
419 addImplicitSizeListener(contentItem);
422 updateImplicitContentSize();
423 updateBaselineOffset();
425 if (notify && !contentItem.isExecuting())
426 emit q->contentItemChanged();
429qreal QQuickControlPrivate::getContentWidth()
const
431 return contentItem ? contentItem->implicitWidth() : 0;
434qreal QQuickControlPrivate::getContentHeight()
const
436 return contentItem ? contentItem->implicitHeight() : 0;
439void QQuickControlPrivate::updateImplicitContentWidth()
442 const qreal oldWidth = implicitContentWidth;
443 implicitContentWidth = getContentWidth();
444 if (!qFuzzyCompare(implicitContentWidth, oldWidth))
445 emit q->implicitContentWidthChanged();
448void QQuickControlPrivate::updateImplicitContentHeight()
451 const qreal oldHeight = implicitContentHeight;
452 implicitContentHeight = getContentHeight();
453 if (!qFuzzyCompare(implicitContentHeight, oldHeight))
454 emit q->implicitContentHeightChanged();
457void QQuickControlPrivate::updateImplicitContentSize()
460 const qreal oldWidth = implicitContentWidth;
461 const qreal oldHeight = implicitContentHeight;
462 implicitContentWidth = getContentWidth();
463 implicitContentHeight = getContentHeight();
464 if (!qFuzzyCompare(implicitContentWidth, oldWidth))
465 emit q->implicitContentWidthChanged();
466 if (!qFuzzyCompare(implicitContentHeight, oldHeight))
467 emit q->implicitContentHeightChanged();
470QPalette QQuickControlPrivate::defaultPalette()
const
472 return QQuickTheme::palette(QQuickTheme::System);
475#if QT_CONFIG(accessibility)
476void QQuickControlPrivate::accessibilityActiveChanged(
bool active)
479 return q->accessibilityActiveChanged(active);
482QAccessible::Role QQuickControlPrivate::accessibleRole()
const
484 Q_Q(
const QQuickControl);
485 return q->accessibleRole();
488QQuickAccessibleAttached *QQuickControlPrivate::accessibleAttached(
const QObject *object)
490 if (!QAccessible::isActive())
492 return QQuickAccessibleAttached::attachedProperties(object);
497
498
499
500
501
502QFont QQuickControlPrivate::parentFont(
const QQuickItem *item)
504 QQuickItem *p = item->parentItem();
506 if (QQuickControl *control = qobject_cast<QQuickControl *>(p))
507 return QQuickControlPrivate::get(control)->resolvedFont;
508 else if (QQuickLabel *label = qobject_cast<QQuickLabel *>(p))
509 return label->QQuickText::font();
510 else if (QQuickTextField *textField = qobject_cast<QQuickTextField *>(p))
511 return textField->QQuickTextInput::font();
512 else if (QQuickTextArea *textArea = qobject_cast<QQuickTextArea *>(p))
513 return textArea->QQuickTextEdit::font();
518 if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(item->window()))
519 return window->font();
521 return QQuickTheme::font(QQuickTheme::System);
525
526
527
528
529
530
531
532void QQuickControlPrivate::resolveFont()
535 inheritFont(parentFont(q));
538void QQuickControlPrivate::inheritFont(
const QFont &font)
541 QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font;
542 parentFont.setResolveMask(extra.isAllocated() ? extra->requestedFont.resolveMask() | font.resolveMask() : font.resolveMask());
544 const QFont defaultFont = q->defaultFont();
545 QFont resolvedFont = parentFont.resolve(defaultFont);
547 setFont_helper(resolvedFont);
551
552
553
554
555void QQuickControlPrivate::updateFont(
const QFont &font)
558 QFont oldFont = resolvedFont;
562 q->fontChange(font, oldFont);
564 QQuickControlPrivate::updateFontRecur(q, font);
567 emit q->fontChanged();
570void QQuickControlPrivate::updateFontRecur(QQuickItem *item,
const QFont &font)
572 const auto childItems = item->childItems();
573 for (QQuickItem *child : childItems) {
574 if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
575 QQuickControlPrivate::get(control)->inheritFont(font);
576 else if (QQuickLabel *label = qobject_cast<QQuickLabel *>(child))
577 QQuickLabelPrivate::get(label)->inheritFont(font);
578 else if (QQuickTextArea *textArea = qobject_cast<QQuickTextArea *>(child))
579 QQuickTextAreaPrivate::get(textArea)->inheritFont(font);
580 else if (QQuickTextField *textField = qobject_cast<QQuickTextField *>(child))
581 QQuickTextFieldPrivate::get(textField)->inheritFont(font);
583 QQuickControlPrivate::updateFontRecur(child, font);
587QLocale QQuickControlPrivate::calcLocale(
const QQuickItem *item)
589 for (
const QQuickItem *p = item; p; p = p->parentItem())
590 if (
const QQuickControl *control = qobject_cast<
const QQuickControl *>(p))
591 return control->locale();
594 if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(item->window()))
595 return window->locale();
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615void QQuickControlPrivate::warnIfCustomizationNotSupported(QObject *control, QQuickItem *item,
const QString &propertyName)
617 static const bool ignoreWarnings = [](){
618 return qEnvironmentVariableIntValue(
"QT_QUICK_CONTROLS_IGNORE_CUSTOMIZATION_WARNINGS");
623 if (!control->property(
"__notCustomizable").toBool()
624 || (item && item->property(
"__ignoreNotCustomizable").toBool()))
627 qmlWarning(item ? item : control).nospace() <<
"The current style does not support customization of this control "
628 <<
"(property: " << propertyName <<
" item: " << item <<
"). "
629 "Please customize a non-native style (such as Basic, Fusion, Material, etc). For more information, see: "
630 "https://doc.qt.io/qt-6/qtquickcontrols2-customize.html#customization-reference";
633void QQuickControlPrivate::updateLocale(
const QLocale &l,
bool e)
639 QLocale old = q->locale();
643 q->localeChange(l, old);
644 QQuickControlPrivate::updateLocaleRecur(q, l);
645 emit q->localeChanged();
649void QQuickControlPrivate::updateLocaleRecur(QQuickItem *item,
const QLocale &l)
651 const auto childItems = item->childItems();
652 for (QQuickItem *child : childItems) {
653 if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
654 QQuickControlPrivate::get(control)->updateLocale(l,
false);
656 updateLocaleRecur(child, l);
660#if QT_CONFIG(quicktemplates2_hover)
661void QQuickControlPrivate::updateHoverEnabled(
bool enabled,
bool xplicit)
664 if (!xplicit && explicitHoverEnabled)
667 bool wasEnabled = q->isHoverEnabled();
668 explicitHoverEnabled = xplicit;
669 if (wasEnabled != enabled) {
670 q->setAcceptHoverEvents(enabled);
671 QQuickControlPrivate::updateHoverEnabledRecur(q, enabled);
672 emit q->hoverEnabledChanged();
676void QQuickControlPrivate::updateHoverEnabledRecur(QQuickItem *item,
bool enabled)
678 const auto childItems = item->childItems();
679 for (QQuickItem *child : childItems) {
680 if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
681 QQuickControlPrivate::get(control)->updateHoverEnabled(enabled,
false);
683 updateHoverEnabledRecur(child, enabled);
687bool QQuickControlPrivate::calcHoverEnabled(
const QQuickItem *item)
689 const QQuickItem *p = item;
694 if (qobject_cast<
const QQuickPopupItem *>(p))
697 if (QQuickTemplatesUtils::isInteractiveControlType(p)) {
698 const QVariant hoverEnabledProperty = p->property(
"hoverEnabled");
699 Q_ASSERT(hoverEnabledProperty.isValid());
700 Q_ASSERT(hoverEnabledProperty.userType() == QMetaType::Bool);
701 return hoverEnabledProperty.toBool();
708 int env = qEnvironmentVariableIntValue(
"QT_QUICK_CONTROLS_HOVER_ENABLED", &ok);
714 return QGuiApplication::styleHints()->useHoverEffects();
720void QQuickControlPrivate::cancelContentItem()
723 quickCancelDeferred(q, contentItemName());
726void QQuickControlPrivate::executeContentItem(
bool complete)
729 if (contentItem.wasExecuted())
732 if (!contentItem || complete)
733 quickBeginDeferred(q, contentItemName(), contentItem);
735 quickCompleteDeferred(q, contentItemName(), contentItem);
738void QQuickControlPrivate::cancelBackground()
741 quickCancelDeferred(q, backgroundName());
744void QQuickControlPrivate::executeBackground(
bool complete)
747 if (background.wasExecuted())
750 if (!background || complete)
751 quickBeginDeferred(q, backgroundName(), background);
753 quickCompleteDeferred(q, backgroundName(), background);
757
758
759
760
761
762
763void QQuickControlPrivate::hideOldItem(QQuickItem *item)
768 qCDebug(lcItemManagement) <<
"hiding old item" << item;
770 item->setVisible(
false);
771 item->setParentItem(
nullptr);
773#if QT_CONFIG(accessibility)
775 QQuickAccessibleAttached *accessible = accessibleAttached(item);
777 accessible->setIgnored(
true);
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800void QQuickControlPrivate::unhideOldItem(QQuickControl *control, QQuickItem *item, UnhideVisibility visibility)
803 qCDebug(lcItemManagement) <<
"unhiding old item" << item;
805 item->setVisible(visibility == UnhideVisibility::Show);
806 item->setParentItem(control);
808#if QT_CONFIG(accessibility)
810 QQuickAccessibleAttached *accessible = accessibleAttached(item);
812 accessible->setIgnored(
false);
816void QQuickControlPrivate::updateBaselineOffset()
819 if (extra.isAllocated() && extra.value().hasBaselineOffset)
823 q->QQuickItem::setBaselineOffset(0);
825 q->QQuickItem::setBaselineOffset(getTopPadding() + contentItem->baselineOffset());
828void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item, ChangeTypes changes)
830 addImplicitSizeListener(item,
this, changes);
833void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item, ChangeTypes changes)
835 removeImplicitSizeListener(item,
this, changes);
838void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes)
840 if (!item || !listener)
842 QQuickItemPrivate::get(item)->addItemChangeListener(listener, changes);
845void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes)
847 if (!item || !listener)
849 QQuickItemPrivate::get(item)->removeItemChangeListener(listener, changes);
852void QQuickControlPrivate::itemImplicitWidthChanged(QQuickItem *item)
855 if (item == background)
856 emit q->implicitBackgroundWidthChanged();
857 else if (item == contentItem)
858 updateImplicitContentWidth();
861void QQuickControlPrivate::itemImplicitHeightChanged(QQuickItem *item)
864 if (item == background)
865 emit q->implicitBackgroundHeightChanged();
866 else if (item == contentItem)
867 updateImplicitContentHeight();
870void QQuickControlPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change,
const QRectF &diff)
873 if (resizingBackground || item != background || !change.sizeChange())
876 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
879 if (change.widthChange())
880 extra.value().hasBackgroundWidth = p->widthValid();
881 if (change.heightChange())
882 extra.value().hasBackgroundHeight = p->heightValid();
886void QQuickControlPrivate::itemDestroyed(QQuickItem *item)
889 if (item == background) {
890 background =
nullptr;
891 emit q->implicitBackgroundWidthChanged();
892 emit q->implicitBackgroundHeightChanged();
893 }
else if (item == contentItem) {
894 contentItem =
nullptr;
895 updateImplicitContentSize();
899void QQuickControlPrivate::itemFocusChanged(QQuickItem *item, Qt::FocusReason reason)
902 if (item == contentItem || item == q)
903 setLastFocusChangeReason(reason);
906bool QQuickControlPrivate::setLastFocusChangeReason(Qt::FocusReason reason)
909 Qt::FocusReason oldReason =
static_cast<Qt::FocusReason>(focusReason);
910 const auto focusReasonChanged = QQuickItemPrivate::setLastFocusChangeReason(reason);
911 if (focusReasonChanged)
912 emit q->focusReasonChanged();
913 if (isKeyFocusReason(oldReason) != isKeyFocusReason(reason))
914 emit q->visualFocusChanged();
916 return focusReasonChanged;
919QQuickControl::QQuickControl(QQuickItem *parent)
920 : QQuickItem(*(
new QQuickControlPrivate), parent)
926QQuickControl::QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent)
927 : QQuickItem(dd, parent)
933QQuickControl::~QQuickControl()
936 d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
937 d->removeImplicitSizeListener(d->contentItem);
939 QQuickItemPrivate::get(d->contentItem)->removeItemChangeListener(d, QQuickItemPrivate::Focus);
940#if QT_CONFIG(accessibility)
941 QAccessible::removeActivationObserver(d);
945void QQuickControl::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &value)
948 QQuickItem::itemChange(change, value);
950 case ItemEnabledHasChanged:
953 case ItemVisibleHasChanged:
954#if QT_CONFIG(quicktemplates2_hover)
955 if (!value.boolValue)
959 case ItemSceneChange:
960 case ItemParentHasChanged:
961 if ((change == ItemParentHasChanged && value.item) || (change == ItemSceneChange && value.window)) {
964 d->updateLocale(QQuickControlPrivate::calcLocale(d->parentItem),
false);
965#if QT_CONFIG(quicktemplates2_hover)
966 if (!d->explicitHoverEnabled)
967 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem),
false);
971 case ItemActiveFocusHasChanged:
972 if (isKeyFocusReason(
static_cast<Qt::FocusReason>(d->focusReason)))
973 emit visualFocusChanged();
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024QFont QQuickControl::font()
const
1026 Q_D(
const QQuickControl);
1027 QFont font = d->resolvedFont;
1029 font.setResolveMask(d->extra.value().requestedFont.resolveMask());
1033void QQuickControl::setFont(
const QFont &font)
1036 if (d->extra.value().requestedFont.resolveMask() == font.resolveMask() && d->extra.value().requestedFont == font)
1039 d->extra.value().requestedFont = font;
1043void QQuickControl::resetFont()
1049
1050
1051
1052
1053
1054
1055
1056
1057qreal QQuickControl::availableWidth()
const
1059 return qMax<qreal>(0.0, width() - leftPadding() - rightPadding());
1063
1064
1065
1066
1067
1068
1069
1070
1071qreal QQuickControl::availableHeight()
const
1073 return qMax<qreal>(0.0, height() - topPadding() - bottomPadding());
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115qreal QQuickControl::padding()
const
1117 Q_D(
const QQuickControl);
1121void QQuickControl::setPadding(qreal padding)
1124 if (qFuzzyCompare(d->padding, padding))
1127 const QMarginsF oldPadding = d->getPadding();
1128 const qreal oldVerticalPadding = d->getVerticalPadding();
1129 const qreal oldHorizontalPadding = d->getHorizontalPadding();
1131 d->padding = padding;
1132 emit paddingChanged();
1134 const QMarginsF newPadding = d->getPadding();
1135 const qreal newVerticalPadding = d->getVerticalPadding();
1136 const qreal newHorizontalPadding = d->getHorizontalPadding();
1138 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()))
1139 emit topPaddingChanged();
1140 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()))
1141 emit leftPaddingChanged();
1142 if (!qFuzzyCompare(newPadding.right(), oldPadding.right()))
1143 emit rightPaddingChanged();
1144 if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
1145 emit bottomPaddingChanged();
1146 if (!qFuzzyCompare(newVerticalPadding, oldVerticalPadding))
1147 emit verticalPaddingChanged();
1148 if (!qFuzzyCompare(newHorizontalPadding, oldHorizontalPadding))
1149 emit horizontalPaddingChanged();
1150 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()) || !qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
1151 emit availableHeightChanged();
1152 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()) || !qFuzzyCompare(newPadding.right(), oldPadding.right()))
1153 emit availableWidthChanged();
1155 paddingChange(newPadding, oldPadding);
1158void QQuickControl::resetPadding()
1164
1165
1166
1167
1168
1169
1170
1171qreal QQuickControl::topPadding()
const
1173 Q_D(
const QQuickControl);
1174 return d->getTopPadding();
1177void QQuickControl::setTopPadding(qreal padding)
1180 d->setTopPadding(padding);
1183void QQuickControl::resetTopPadding()
1186 d->setTopPadding(0,
true);
1190
1191
1192
1193
1194
1195
1196
1197qreal QQuickControl::leftPadding()
const
1199 Q_D(
const QQuickControl);
1200 return d->getLeftPadding();
1203void QQuickControl::setLeftPadding(qreal padding)
1206 d->setLeftPadding(padding);
1209void QQuickControl::resetLeftPadding()
1212 d->setLeftPadding(0,
true);
1216
1217
1218
1219
1220
1221
1222
1223qreal QQuickControl::rightPadding()
const
1225 Q_D(
const QQuickControl);
1226 return d->getRightPadding();
1229void QQuickControl::setRightPadding(qreal padding)
1232 d->setRightPadding(padding);
1235void QQuickControl::resetRightPadding()
1238 d->setRightPadding(0,
true);
1242
1243
1244
1245
1246
1247
1248
1249qreal QQuickControl::bottomPadding()
const
1251 Q_D(
const QQuickControl);
1252 return d->getBottomPadding();
1255void QQuickControl::setBottomPadding(qreal padding)
1258 d->setBottomPadding(padding);
1261void QQuickControl::resetBottomPadding()
1264 d->setBottomPadding(0,
true);
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278qreal QQuickControl::spacing()
const
1280 Q_D(
const QQuickControl);
1284void QQuickControl::setSpacing(qreal spacing)
1287 if (qFuzzyCompare(d->spacing, spacing))
1290 qreal oldSpacing = d->spacing;
1291 d->spacing = spacing;
1292 emit spacingChanged();
1293 spacingChange(spacing, oldSpacing);
1296void QQuickControl::resetSpacing()
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316QLocale QQuickControl::locale()
const
1318 Q_D(
const QQuickControl);
1322void QQuickControl::setLocale(
const QLocale &locale)
1325 if (d->hasLocale && d->locale == locale)
1328 d->updateLocale(locale,
true);
1331void QQuickControl::resetLocale()
1337 d->hasLocale =
false;
1338 d->updateLocale(QQuickControlPrivate::calcLocale(d->parentItem),
false);
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355bool QQuickControl::isMirrored()
const
1357 Q_D(
const QQuickControl);
1358 return d->isMirrored();
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386Qt::FocusReason QQuickControl::focusReason()
const
1388 Q_D(
const QQuickControl);
1389 return d->lastFocusChangeReason();
1392void QQuickControl::setFocusReason(Qt::FocusReason reason)
1395 d->setLastFocusChangeReason(reason);
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412bool QQuickControl::hasVisualFocus()
const
1414 Q_D(
const QQuickControl);
1415 return d->activeFocus && isKeyFocusReason(
static_cast<Qt::FocusReason>(d->focusReason));
1419
1420
1421
1422
1423
1424
1425
1426bool QQuickControl::isHovered()
const
1428#if QT_CONFIG(quicktemplates2_hover)
1429 Q_D(
const QQuickControl);
1436void QQuickControl::setHovered(
bool hovered)
1438#if QT_CONFIG(quicktemplates2_hover)
1440 if (hovered == d->hovered)
1443 d->hovered = hovered;
1444 emit hoveredChanged();
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466bool QQuickControl::isHoverEnabled()
const
1468#if QT_CONFIG(quicktemplates2_hover)
1469 Q_D(
const QQuickControl);
1470 return d->hoverEnabled;
1476void QQuickControl::setHoverEnabled(
bool enabled)
1478#if QT_CONFIG(quicktemplates2_hover)
1480 if (d->explicitHoverEnabled && enabled == d->hoverEnabled)
1483 d->updateHoverEnabled(enabled,
true);
1489void QQuickControl::resetHoverEnabled()
1491#if QT_CONFIG(quicktemplates2_hover)
1493 if (!d->explicitHoverEnabled)
1496 d->explicitHoverEnabled =
false;
1497 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem),
false);
1502
1503
1504
1505
1506
1507
1508
1509
1510bool QQuickControl::isWheelEnabled()
const
1512 Q_D(
const QQuickControl);
1513 return d->wheelEnabled;
1516void QQuickControl::setWheelEnabled(
bool enabled)
1519 if (d->wheelEnabled == enabled)
1522 d->wheelEnabled = enabled;
1523 emit wheelEnabledChanged();
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548QQuickItem *QQuickControl::background()
const
1550 QQuickControlPrivate *d =
const_cast<QQuickControlPrivate *>(d_func());
1552 d->executeBackground();
1553 return d->background;
1556void QQuickControl::setBackground(QQuickItem *background)
1559 if (d->background == background)
1562 QQuickControlPrivate::warnIfCustomizationNotSupported(
this, background, QStringLiteral(
"background"));
1564 if (!d->background.isExecuting())
1565 d->cancelBackground();
1567 const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
1568 const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
1570 if (d->extra.isAllocated()) {
1571 d->extra.value().hasBackgroundWidth =
false;
1572 d->extra.value().hasBackgroundHeight =
false;
1575 d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
1576 QQuickControlPrivate::hideOldItem(d->background);
1577 d->background = background;
1580 background->setParentItem(
this);
1581 if (qFuzzyIsNull(background->z()))
1582 background->setZ(-1);
1583 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
1584 if (p->widthValid() || p->heightValid()) {
1585 d->extra.value().hasBackgroundWidth = p->widthValid();
1586 d->extra.value().hasBackgroundHeight = p->heightValid();
1588 if (isComponentComplete())
1589 d->resizeBackground();
1590 d->addImplicitSizeListener(background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
1593 if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
1594 emit implicitBackgroundWidthChanged();
1595 if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
1596 emit implicitBackgroundHeightChanged();
1597 if (!d->background.isExecuting())
1598 emit backgroundChanged();
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631QQuickItem *QQuickControl::contentItem()
const
1633 QQuickControlPrivate *d =
const_cast<QQuickControlPrivate *>(d_func());
1634 if (!d->contentItem)
1635 d->setContentItem_helper(d->getContentItem(),
false);
1636 return d->contentItem;
1639void QQuickControl::setContentItem(QQuickItem *item)
1642 d->setContentItem_helper(item,
true);
1645qreal QQuickControl::baselineOffset()
const
1647 Q_D(
const QQuickControl);
1648 return d->baselineOffset;
1651void QQuickControl::setBaselineOffset(qreal offset)
1654 d->extra.value().hasBaselineOffset =
true;
1655 QQuickItem::setBaselineOffset(offset);
1658void QQuickControl::resetBaselineOffset()
1661 if (!d->extra.isAllocated() || !d->extra.value().hasBaselineOffset)
1664 if (d->extra.isAllocated())
1665 d->extra.value().hasBaselineOffset =
false;
1666 d->updateBaselineOffset();
1670
1671
1672
1673
1674
1675
1676
1677
1678qreal QQuickControl::horizontalPadding()
const
1680 Q_D(
const QQuickControl);
1681 return d->getHorizontalPadding();
1684void QQuickControl::setHorizontalPadding(qreal padding)
1687 d->setHorizontalPadding(padding);
1690void QQuickControl::resetHorizontalPadding()
1693 d->setHorizontalPadding(0,
true);
1697
1698
1699
1700
1701
1702
1703
1704
1705qreal QQuickControl::verticalPadding()
const
1707 Q_D(
const QQuickControl);
1708 return d->getVerticalPadding();
1711void QQuickControl::setVerticalPadding(qreal padding)
1714 d->setVerticalPadding(padding);
1717void QQuickControl::resetVerticalPadding()
1720 d->setVerticalPadding(0,
true);
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745qreal QQuickControl::implicitContentWidth()
const
1747 Q_D(
const QQuickControl);
1749 if (
auto *safeArea =
static_cast<QQuickSafeArea*>(
1750 qmlAttachedPropertiesObject<QQuickSafeArea>(
this,
false))) {
1756 static constexpr auto kLastKnownGoodImplicitWidth =
"_q_lastKnownGoodImplicitWidth";
1757 if (safeArea->detectedPossibleBindingLoop) {
1758 const auto lastImplicitWidth = safeArea->property(kLastKnownGoodImplicitWidth).value<
int>();
1759 return lastImplicitWidth - leftPadding() - rightPadding();
1761 safeArea->setProperty(kLastKnownGoodImplicitWidth, implicitWidth());
1765 return d->implicitContentWidth;
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790qreal QQuickControl::implicitContentHeight()
const
1792 Q_D(
const QQuickControl);
1794 if (
auto *safeArea =
static_cast<QQuickSafeArea*>(
1795 qmlAttachedPropertiesObject<QQuickSafeArea>(
this,
false))) {
1801 static constexpr auto kLastKnownGoodImplicitHeight =
"_q_lastKnownGoodImplicitHeight";
1802 if (safeArea->detectedPossibleBindingLoop) {
1803 const auto lastImplicitHeight = safeArea->property(kLastKnownGoodImplicitHeight).value<
int>();
1804 return lastImplicitHeight - topPadding() - bottomPadding();
1806 safeArea->setProperty(kLastKnownGoodImplicitHeight, implicitHeight());
1810 return d->implicitContentHeight;
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834qreal QQuickControl::implicitBackgroundWidth()
const
1836 Q_D(
const QQuickControl);
1839 return d->background->implicitWidth();
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863qreal QQuickControl::implicitBackgroundHeight()
const
1865 Q_D(
const QQuickControl);
1868 return d->background->implicitHeight();
1872
1873
1874
1875
1876
1877
1878
1879qreal QQuickControl::topInset()
const
1881 Q_D(
const QQuickControl);
1882 return d->getTopInset();
1885void QQuickControl::setTopInset(qreal inset)
1888 d->setTopInset(inset);
1891void QQuickControl::resetTopInset()
1894 d->setTopInset(0,
true);
1898
1899
1900
1901
1902
1903
1904
1905qreal QQuickControl::leftInset()
const
1907 Q_D(
const QQuickControl);
1908 return d->getLeftInset();
1911void QQuickControl::setLeftInset(qreal inset)
1914 d->setLeftInset(inset);
1917void QQuickControl::resetLeftInset()
1920 d->setLeftInset(0,
true);
1924
1925
1926
1927
1928
1929
1930
1931qreal QQuickControl::rightInset()
const
1933 Q_D(
const QQuickControl);
1934 return d->getRightInset();
1937void QQuickControl::setRightInset(qreal inset)
1940 d->setRightInset(inset);
1943void QQuickControl::resetRightInset()
1946 d->setRightInset(0,
true);
1950
1951
1952
1953
1954
1955
1956
1957qreal QQuickControl::bottomInset()
const
1959 Q_D(
const QQuickControl);
1960 return d->getBottomInset();
1963void QQuickControl::setBottomInset(qreal inset)
1966 d->setBottomInset(inset);
1969void QQuickControl::resetBottomInset()
1972 d->setBottomInset(0,
true);
1975void QQuickControl::classBegin()
1978 QQuickItem::classBegin();
1982void QQuickControl::componentComplete()
1985 d->executeBackground(
true);
1986 d->executeContentItem(
true);
1987 QQuickItem::componentComplete();
1988 d->resizeBackground();
1990 d->updateBaselineOffset();
1992 d->locale = QQuickControlPrivate::calcLocale(d->parentItem);
1993#if QT_CONFIG(quicktemplates2_hover)
1994 if (!d->explicitHoverEnabled)
1995 setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem));
1997#if QT_CONFIG(accessibility)
1998 if (QAccessible::isActive())
1999 accessibilityActiveChanged(
true);
2003QFont QQuickControl::defaultFont()
const
2005 return QQuickTheme::font(QQuickTheme::System);
2008void QQuickControl::focusInEvent(QFocusEvent *event)
2010 QQuickItem::focusInEvent(event);
2013void QQuickControl::focusOutEvent(QFocusEvent *event)
2015 QQuickItem::focusOutEvent(event);
2018#if QT_CONFIG(quicktemplates2_hover)
2019void QQuickControl::hoverEnterEvent(QHoverEvent *event)
2022 setHovered(d->hoverEnabled);
2026void QQuickControl::hoverMoveEvent(QHoverEvent *event)
2029 setHovered(d->hoverEnabled && contains(event->position()));
2033void QQuickControl::hoverLeaveEvent(QHoverEvent *event)
2040void QQuickControl::mousePressEvent(QMouseEvent *event)
2043 event->setAccepted(d->handlePress(event->position(), event->timestamp()));
2046void QQuickControl::mouseMoveEvent(QMouseEvent *event)
2049 event->setAccepted(d->handleMove(event->position(), event->timestamp()));
2052void QQuickControl::mouseReleaseEvent(QMouseEvent *event)
2055 event->setAccepted(d->handleRelease(event->position(), event->timestamp()));
2058void QQuickControl::mouseUngrabEvent()
2064#if QT_CONFIG(quicktemplates2_multitouch)
2065void QQuickControl::touchEvent(QTouchEvent *event)
2068 switch (event->type()) {
2069 case QEvent::TouchBegin:
2070 case QEvent::TouchUpdate:
2071 case QEvent::TouchEnd:
2072 for (
const QTouchEvent::TouchPoint &point : event->points()) {
2073 if (!d->acceptTouch(point))
2076 switch (point.state()) {
2077 case QEventPoint::Pressed:
2078 d->handlePress(point.position(), event->timestamp());
2080 case QEventPoint::Updated:
2081 d->handleMove(point.position(), event->timestamp());
2083 case QEventPoint::Released:
2084 d->handleRelease(point.position(), event->timestamp());
2092 case QEvent::TouchCancel:
2097 QQuickItem::touchEvent(event);
2102void QQuickControl::touchUngrabEvent()
2109#if QT_CONFIG(wheelevent)
2110void QQuickControl::wheelEvent(QWheelEvent *event)
2113 event->setAccepted(d->wheelEnabled);
2117void QQuickControl::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
2120 QQuickItem::geometryChange(newGeometry, oldGeometry);
2121 d->resizeBackground();
2123 if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width()))
2124 emit availableWidthChanged();
2125 if (!qFuzzyCompare(newGeometry.height(), oldGeometry.height()))
2126 emit availableHeightChanged();
2129void QQuickControl::enabledChange()
2133void QQuickControl::fontChange(
const QFont &newFont,
const QFont &oldFont)
2139#if QT_CONFIG(quicktemplates2_hover)
2140void QQuickControl::hoverChange()
2145void QQuickControl::mirrorChange()
2147 emit mirroredChanged();
2150void QQuickControl::spacingChange(qreal newSpacing, qreal oldSpacing)
2152 Q_UNUSED(newSpacing);
2153 Q_UNUSED(oldSpacing);
2156void QQuickControl::paddingChange(
const QMarginsF &newPadding,
const QMarginsF &oldPadding)
2159 Q_UNUSED(newPadding);
2160 Q_UNUSED(oldPadding);
2162 d->updateBaselineOffset();
2165void QQuickControl::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
2171void QQuickControl::localeChange(
const QLocale &newLocale,
const QLocale &oldLocale)
2173 Q_UNUSED(newLocale);
2174 Q_UNUSED(oldLocale);
2177void QQuickControl::insetChange(
const QMarginsF &newInset,
const QMarginsF &oldInset)
2182 d->resizeBackground();
2185#if QT_CONFIG(accessibility)
2186QAccessible::Role QQuickControl::accessibleRole()
const
2188 return QAccessible::NoRole;
2191void QQuickControl::accessibilityActiveChanged(
bool active)
2197 QQuickAccessibleAttached *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(
this,
true));
2198 Q_ASSERT(accessibleAttached);
2199 accessibleAttached->setRole(d->effectiveAccessibleRole());
2203QString QQuickControl::accessibleName()
const
2205#if QT_CONFIG(accessibility)
2206 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(
this))
2207 return accessibleAttached->name();
2212void QQuickControl::maybeSetAccessibleName(
const QString &name)
2214#if QT_CONFIG(accessibility)
2215 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(
this)) {
2216 if (!accessibleAttached->wasNameExplicitlySet())
2217 accessibleAttached->setNameImplicitly(name);
2224QVariant QQuickControl::accessibleProperty(
const char *propertyName)
2226#if QT_CONFIG(accessibility)
2227 if (QAccessible::isActive())
2228 return QQuickAccessibleAttached::property(
this, propertyName);
2230 Q_UNUSED(propertyName);
2234bool QQuickControl::setAccessibleProperty(
const char *propertyName,
const QVariant &value)
2236#if QT_CONFIG(accessibility)
2237 if (QAccessible::isActive())
2238 return QQuickAccessibleAttached::setProperty(
this, propertyName, value);
2240 Q_UNUSED(propertyName);
2247#include "moc_qquickcontrol_p.cpp"
Combined button and popup list for selecting options.
static bool isKeyFocusReason(Qt::FocusReason reason)
static QString contentItemName()