8#include <QtGui/qstylehints.h>
9#include <QtGui/qguiapplication.h>
24#if QT_CONFIG(accessibility)
25#include <QtQuick/private/qquickaccessibleattached_p.h>
30Q_LOGGING_CATEGORY(lcItemManagement,
"qt.quick.controls.control.itemmanagement")
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
116
117
119const QQuickItemPrivate::ChangeTypes QQuickControlPrivate::ImplicitSizeChanges = QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed;
123 return reason == Qt::TabFocusReason || reason == Qt::BacktabFocusReason || reason == Qt::ShortcutFocusReason;
126QQuickControlPrivate::QQuickControlPrivate()
128#if QT_CONFIG(accessibility)
129 QAccessible::installActivationObserver(
this);
133QQuickControlPrivate::~QQuickControlPrivate()
137void QQuickControlPrivate::init()
140 QObject::connect(q, &QQuickItem::baselineOffsetChanged, q, &QQuickControl::baselineOffsetChanged);
141#if QT_CONFIG(accessibility)
146#if QT_CONFIG(quicktemplates2_multitouch)
147bool QQuickControlPrivate::acceptTouch(
const QTouchEvent::TouchPoint &point)
149 if (point.id() == touchId)
152 if (touchId == -1 && point.state() == QEventPoint::Pressed) {
153 touchId = point.id();
161bool QQuickControlPrivate::handlePress(
const QPointF &, ulong)
166bool QQuickControlPrivate::handleMove(
const QPointF &point, ulong)
168#if QT_CONFIG(quicktemplates2_hover)
170 q->setHovered(hoverEnabled && q->contains(point));
177bool QQuickControlPrivate::handleRelease(
const QPointF &, ulong)
183void QQuickControlPrivate::handleUngrab()
188void QQuickControlPrivate::mirrorChange()
194void QQuickControlPrivate::setTopPadding(qreal value,
bool reset)
197 const QMarginsF oldPadding = getPadding();
198 extra.value().topPadding = value;
199 extra.value().hasTopPadding = !reset;
200 if ((!reset && !qFuzzyCompare(oldPadding.top(), value)) || (reset && !qFuzzyCompare(oldPadding.top(), getVerticalPadding()))) {
201 emit q->topPaddingChanged();
202 emit q->availableHeightChanged();
203 q->paddingChange(getPadding(), oldPadding);
207void QQuickControlPrivate::setLeftPadding(qreal value,
bool reset)
210 const QMarginsF oldPadding = getPadding();
211 extra.value().leftPadding = value;
212 extra.value().hasLeftPadding = !reset;
213 if ((!reset && !qFuzzyCompare(oldPadding.left(), value)) || (reset && !qFuzzyCompare(oldPadding.left(), getHorizontalPadding()))) {
214 emit q->leftPaddingChanged();
215 emit q->availableWidthChanged();
216 q->paddingChange(getPadding(), oldPadding);
220void QQuickControlPrivate::setRightPadding(qreal value,
bool reset)
223 const QMarginsF oldPadding = getPadding();
224 extra.value().rightPadding = value;
225 extra.value().hasRightPadding = !reset;
226 if ((!reset && !qFuzzyCompare(oldPadding.right(), value)) || (reset && !qFuzzyCompare(oldPadding.right(), getHorizontalPadding()))) {
227 emit q->rightPaddingChanged();
228 emit q->availableWidthChanged();
229 q->paddingChange(getPadding(), oldPadding);
233void QQuickControlPrivate::setBottomPadding(qreal value,
bool reset)
236 const QMarginsF oldPadding = getPadding();
237 extra.value().bottomPadding = value;
238 extra.value().hasBottomPadding = !reset;
239 if ((!reset && !qFuzzyCompare(oldPadding.bottom(), value)) || (reset && !qFuzzyCompare(oldPadding.bottom(), getVerticalPadding()))) {
240 emit q->bottomPaddingChanged();
241 emit q->availableHeightChanged();
242 q->paddingChange(getPadding(), oldPadding);
246void QQuickControlPrivate::setHorizontalPadding(qreal value,
bool reset)
249 const QMarginsF oldPadding = getPadding();
250 const qreal oldHorizontalPadding = getHorizontalPadding();
251 horizontalPadding = value;
252 hasHorizontalPadding = !reset;
253 if ((!reset && !qFuzzyCompare(oldHorizontalPadding, value)) || (reset && !qFuzzyCompare(oldHorizontalPadding, padding))) {
254 const QMarginsF newPadding = getPadding();
255 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()))
256 emit q->leftPaddingChanged();
257 if (!qFuzzyCompare(newPadding.right(), oldPadding.right()))
258 emit q->rightPaddingChanged();
259 emit q->horizontalPaddingChanged();
260 emit q->availableWidthChanged();
261 q->paddingChange(newPadding, oldPadding);
265void QQuickControlPrivate::setVerticalPadding(qreal value,
bool reset)
268 const QMarginsF oldPadding = getPadding();
269 const qreal oldVerticalPadding = getVerticalPadding();
270 verticalPadding = value;
271 hasVerticalPadding = !reset;
272 if ((!reset && !qFuzzyCompare(oldVerticalPadding, value)) || (reset && !qFuzzyCompare(oldVerticalPadding, padding))) {
273 const QMarginsF newPadding = getPadding();
274 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()))
275 emit q->topPaddingChanged();
276 if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
277 emit q->bottomPaddingChanged();
278 emit q->verticalPaddingChanged();
279 emit q->availableHeightChanged();
280 q->paddingChange(newPadding, oldPadding);
284void QQuickControlPrivate::setTopInset(qreal value,
bool reset)
287 const QMarginsF oldInset = getInset();
288 extra.value().topInset = value;
289 extra.value().hasTopInset = !reset;
290 if (!qFuzzyCompare(oldInset.top(), value)) {
291 emit q->topInsetChanged();
292 q->insetChange(getInset(), oldInset);
296void QQuickControlPrivate::setLeftInset(qreal value,
bool reset)
299 const QMarginsF oldInset = getInset();
300 extra.value().leftInset = value;
301 extra.value().hasLeftInset = !reset;
302 if (!qFuzzyCompare(oldInset.left(), value)) {
303 emit q->leftInsetChanged();
304 q->insetChange(getInset(), oldInset);
308void QQuickControlPrivate::setRightInset(qreal value,
bool reset)
311 const QMarginsF oldInset = getInset();
312 extra.value().rightInset = value;
313 extra.value().hasRightInset = !reset;
314 if (!qFuzzyCompare(oldInset.right(), value)) {
315 emit q->rightInsetChanged();
316 q->insetChange(getInset(), oldInset);
320void QQuickControlPrivate::setBottomInset(qreal value,
bool reset)
323 const QMarginsF oldInset = getInset();
324 extra.value().bottomInset = value;
325 extra.value().hasBottomInset = !reset;
326 if (!qFuzzyCompare(oldInset.bottom(), value)) {
327 emit q->bottomInsetChanged();
328 q->insetChange(getInset(), oldInset);
332void QQuickControlPrivate::resizeBackground()
337 resizingBackground =
true;
339 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
340 bool changeWidth =
false;
341 bool changeHeight =
false;
342 if (((!p->widthValid() || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x()))
343 || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) {
344 const auto leftInset = getLeftInset();
345 if (!qt_is_nan(leftInset) && p->x.valueBypassingBindings() != leftInset) {
347 p->x.setValueBypassingBindings(leftInset);
348 p->dirty(DirtyType::Position);
350 changeWidth = !p->width.hasBinding();
352 if (((!p->heightValid() || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
353 || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) {
354 const auto topInset = getTopInset();
355 if (!qt_is_nan(topInset) && p->y.valueBypassingBindings() != topInset) {
357 p->y.setValueBypassingBindings(topInset);
358 p->dirty(DirtyType::Position);
360 changeHeight = !p->height.hasBinding();
362 if (changeHeight || changeWidth) {
363 auto newWidth = changeWidth ?
364 width.valueBypassingBindings() - getLeftInset() - getRightInset() :
365 p->width.valueBypassingBindings();
366 auto newHeight = changeHeight ?
367 height.valueBypassingBindings() - getTopInset() - getBottomInset() :
368 p->height.valueBypassingBindings();
369 background->setSize({newWidth, newHeight});
372 resizingBackground =
false;
375void QQuickControlPrivate::resizeContent()
379 contentItem->setPosition(QPointF(q->leftPadding(), q->topPadding()));
380 contentItem->setSize(QSizeF(q->availableWidth(), q->availableHeight()));
384QQuickItem *QQuickControlPrivate::getContentItem()
387 executeContentItem();
391void QQuickControlPrivate::setContentItem_helper(QQuickItem *item,
bool notify)
394 if (contentItem == item)
398 warnIfCustomizationNotSupported(q, item, QStringLiteral(
"contentItem"));
400 if (!contentItem.isExecuting())
403 QQuickItem *oldContentItem = contentItem;
404 if (oldContentItem) {
405 disconnect(oldContentItem, &QQuickItem::baselineOffsetChanged,
this, &QQuickControlPrivate::updateBaselineOffset);
406 QQuickItemPrivate::get(oldContentItem)->removeItemChangeListener(
this, QQuickControlPrivate::Focus);
407 removeImplicitSizeListener(oldContentItem);
411 q->contentItemChange(item, oldContentItem);
412 QQuickControlPrivate::hideOldItem(oldContentItem);
415 connect(contentItem.data(), &QQuickItem::baselineOffsetChanged,
this, &QQuickControlPrivate::updateBaselineOffset);
419 QQuickItemPrivate::get(item)->addItemChangeListener(
this, QQuickControlPrivate::Focus);
420 if (!item->parentItem())
421 item->setParentItem(q);
422 if (componentComplete)
424 addImplicitSizeListener(contentItem);
427 updateImplicitContentSize();
428 updateBaselineOffset();
430 if (notify && !contentItem.isExecuting())
431 emit q->contentItemChanged();
434qreal QQuickControlPrivate::getContentWidth()
const
436 return contentItem ? contentItem->implicitWidth() : 0;
439qreal QQuickControlPrivate::getContentHeight()
const
441 return contentItem ? contentItem->implicitHeight() : 0;
444void QQuickControlPrivate::updateImplicitContentWidth()
447 const qreal oldWidth = implicitContentWidth;
448 implicitContentWidth = getContentWidth();
449 if (!qFuzzyCompare(implicitContentWidth, oldWidth))
450 emit q->implicitContentWidthChanged();
453void QQuickControlPrivate::updateImplicitContentHeight()
456 const qreal oldHeight = implicitContentHeight;
457 implicitContentHeight = getContentHeight();
458 if (!qFuzzyCompare(implicitContentHeight, oldHeight))
459 emit q->implicitContentHeightChanged();
462void QQuickControlPrivate::updateImplicitContentSize()
465 const qreal oldWidth = implicitContentWidth;
466 const qreal oldHeight = implicitContentHeight;
467 implicitContentWidth = getContentWidth();
468 implicitContentHeight = getContentHeight();
469 if (!qFuzzyCompare(implicitContentWidth, oldWidth))
470 emit q->implicitContentWidthChanged();
471 if (!qFuzzyCompare(implicitContentHeight, oldHeight))
472 emit q->implicitContentHeightChanged();
475QPalette QQuickControlPrivate::defaultPalette()
const
477 return QQuickTheme::palette(QQuickTheme::System);
480#if QT_CONFIG(accessibility)
481void QQuickControlPrivate::accessibilityActiveChanged(
bool active)
484 return q->accessibilityActiveChanged(active);
487QAccessible::Role QQuickControlPrivate::accessibleRole()
const
489 Q_Q(
const QQuickControl);
490 return q->accessibleRole();
493QQuickAccessibleAttached *QQuickControlPrivate::accessibleAttached(
const QObject *object)
495 if (!QAccessible::isActive())
497 return QQuickAccessibleAttached::attachedProperties(object);
502
503
504
505
506
507QFont QQuickControlPrivate::parentFont(
const QQuickItem *item)
509 QQuickItem *p = item->parentItem();
511 if (QQuickControl *control = qobject_cast<QQuickControl *>(p))
512 return QQuickControlPrivate::get(control)->resolvedFont;
513 else if (QQuickLabel *label = qobject_cast<QQuickLabel *>(p))
514 return label->QQuickText::font();
515 else if (QQuickTextField *textField = qobject_cast<QQuickTextField *>(p))
516 return textField->QQuickTextInput::font();
517 else if (QQuickTextArea *textArea = qobject_cast<QQuickTextArea *>(p))
518 return textArea->QQuickTextEdit::font();
523 if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(item->window()))
524 return window->font();
526 return QQuickTheme::font(QQuickTheme::System);
530
531
532
533
534
535
536
537void QQuickControlPrivate::resolveFont()
540 inheritFont(parentFont(q));
543void QQuickControlPrivate::inheritFont(
const QFont &font)
546 QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font;
547 parentFont.setResolveMask(extra.isAllocated() ? extra->requestedFont.resolveMask() | font.resolveMask() : font.resolveMask());
549 const QFont defaultFont = q->defaultFont();
550 QFont resolvedFont = parentFont.resolve(defaultFont);
552 setFont_helper(resolvedFont);
556
557
558
559
560void QQuickControlPrivate::updateFont(
const QFont &font)
563 QFont oldFont = resolvedFont;
567 q->fontChange(font, oldFont);
569 QQuickControlPrivate::updateFontRecur(q, font);
572 emit q->fontChanged();
575void QQuickControlPrivate::updateFontRecur(QQuickItem *item,
const QFont &font)
577 const auto childItems = item->childItems();
578 for (QQuickItem *child : childItems) {
579 if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
580 QQuickControlPrivate::get(control)->inheritFont(font);
581 else if (QQuickLabel *label = qobject_cast<QQuickLabel *>(child))
582 QQuickLabelPrivate::get(label)->inheritFont(font);
583 else if (QQuickTextArea *textArea = qobject_cast<QQuickTextArea *>(child))
584 QQuickTextAreaPrivate::get(textArea)->inheritFont(font);
585 else if (QQuickTextField *textField = qobject_cast<QQuickTextField *>(child))
586 QQuickTextFieldPrivate::get(textField)->inheritFont(font);
588 QQuickControlPrivate::updateFontRecur(child, font);
592QLocale QQuickControlPrivate::calcLocale(
const QQuickItem *item)
594 for (
const QQuickItem *p = item; p; p = p->parentItem())
595 if (
const QQuickControl *control = qobject_cast<
const QQuickControl *>(p))
596 return control->locale();
599 if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(item->window()))
600 return window->locale();
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620void QQuickControlPrivate::warnIfCustomizationNotSupported(QObject *control, QQuickItem *item,
const QString &propertyName)
622 static const bool ignoreWarnings = [](){
623 return qEnvironmentVariableIntValue(
"QT_QUICK_CONTROLS_IGNORE_CUSTOMIZATION_WARNINGS");
628 if (!control->property(
"__notCustomizable").toBool()
629 || (item && item->property(
"__ignoreNotCustomizable").toBool()))
632 qmlWarning(item ? item : control).nospace() <<
"The current style does not support customization of this control "
633 <<
"(property: " << propertyName <<
" item: " << item <<
"). "
634 "Please customize a non-native style (such as Basic, Fusion, Material, etc). For more information, see: "
635 "https://doc.qt.io/qt-6/qtquickcontrols2-customize.html#customization-reference";
638void QQuickControlPrivate::updateLocale(
const QLocale &l,
bool e)
644 QLocale old = q->locale();
648 q->localeChange(l, old);
649 QQuickControlPrivate::updateLocaleRecur(q, l);
650 emit q->localeChanged();
654void QQuickControlPrivate::updateLocaleRecur(QQuickItem *item,
const QLocale &l)
656 const auto childItems = item->childItems();
657 for (QQuickItem *child : childItems) {
658 if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
659 QQuickControlPrivate::get(control)->updateLocale(l,
false);
661 updateLocaleRecur(child, l);
665#if QT_CONFIG(quicktemplates2_hover)
666void QQuickControlPrivate::updateHoverEnabled(
bool enabled,
bool xplicit)
669 if (!xplicit && explicitHoverEnabled)
672 bool wasEnabled = q->isHoverEnabled();
673 explicitHoverEnabled = xplicit;
674 if (wasEnabled != enabled) {
675 q->setAcceptHoverEvents(enabled);
676 QQuickControlPrivate::updateHoverEnabledRecur(q, enabled);
677 emit q->hoverEnabledChanged();
681void QQuickControlPrivate::updateHoverEnabledRecur(QQuickItem *item,
bool enabled)
683 const auto childItems = item->childItems();
684 for (QQuickItem *child : childItems) {
685 if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
686 QQuickControlPrivate::get(control)->updateHoverEnabled(enabled,
false);
688 updateHoverEnabledRecur(child, enabled);
692bool QQuickControlPrivate::calcHoverEnabled(
const QQuickItem *item)
694 const QQuickItem *p = item;
699 if (qobject_cast<
const QQuickPopupItem *>(p))
702 auto *applicationWindow = qobject_cast<QQuickApplicationWindow *>(p->window());
703 if (applicationWindow) {
704 const auto *applicationWindowPrivate = QQuickApplicationWindowPrivate::get(applicationWindow);
705 if (p == applicationWindowPrivate->control) {
713 if (QQuickTemplatesUtils::isInteractiveControlType(p)) {
714 const QVariant hoverEnabledProperty = p->property(
"hoverEnabled");
715 Q_ASSERT(hoverEnabledProperty.isValid());
716 Q_ASSERT(hoverEnabledProperty.userType() == QMetaType::Bool);
717 return hoverEnabledProperty.toBool();
724 int env = qEnvironmentVariableIntValue(
"QT_QUICK_CONTROLS_HOVER_ENABLED", &ok);
730 return QGuiApplication::styleHints()->useHoverEffects();
736void QQuickControlPrivate::cancelContentItem()
739 quickCancelDeferred(q, contentItemName());
742void QQuickControlPrivate::executeContentItem(
bool complete)
745 if (contentItem.wasExecuted())
748 if (!contentItem || complete)
749 quickBeginDeferred(q, contentItemName(), contentItem);
751 quickCompleteDeferred(q, contentItemName(), contentItem);
754void QQuickControlPrivate::cancelBackground()
757 quickCancelDeferred(q, backgroundName());
760void QQuickControlPrivate::executeBackground(
bool complete)
763 if (background.wasExecuted())
766 if (!background || complete)
767 quickBeginDeferred(q, backgroundName(), background);
769 quickCompleteDeferred(q, backgroundName(), background);
773
774
775
776
777
778
779void QQuickControlPrivate::hideOldItem(QQuickItem *item)
784 qCDebug(lcItemManagement) <<
"hiding old item" << item;
786 item->setVisible(
false);
787 item->setParentItem(
nullptr);
789#if QT_CONFIG(accessibility)
791 QQuickAccessibleAttached *accessible = accessibleAttached(item);
793 accessible->setIgnored(
true);
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816void QQuickControlPrivate::unhideOldItem(QQuickControl *control, QQuickItem *item, UnhideVisibility visibility)
819 qCDebug(lcItemManagement) <<
"unhiding old item" << item;
821 item->setVisible(visibility == UnhideVisibility::Show);
822 item->setParentItem(control);
824#if QT_CONFIG(accessibility)
826 QQuickAccessibleAttached *accessible = accessibleAttached(item);
828 accessible->setIgnored(
false);
832void QQuickControlPrivate::updateBaselineOffset()
835 if (extra.isAllocated() && extra.value().hasBaselineOffset)
839 q->QQuickItem::setBaselineOffset(0);
841 q->QQuickItem::setBaselineOffset(getTopPadding() + contentItem->baselineOffset());
844void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item, ChangeTypes changes)
846 addImplicitSizeListener(item,
this, changes);
849void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item, ChangeTypes changes)
851 removeImplicitSizeListener(item,
this, changes);
854void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes)
856 if (!item || !listener)
858 QQuickItemPrivate::get(item)->addItemChangeListener(listener, changes);
861void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item, QQuickItemChangeListener *listener, ChangeTypes changes)
863 if (!item || !listener)
865 QQuickItemPrivate::get(item)->removeItemChangeListener(listener, changes);
868void QQuickControlPrivate::itemImplicitWidthChanged(QQuickItem *item)
871 if (item == background)
872 emit q->implicitBackgroundWidthChanged();
873 else if (item == contentItem)
874 updateImplicitContentWidth();
877void QQuickControlPrivate::itemImplicitHeightChanged(QQuickItem *item)
880 if (item == background)
881 emit q->implicitBackgroundHeightChanged();
882 else if (item == contentItem)
883 updateImplicitContentHeight();
886void QQuickControlPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change,
const QRectF &diff)
889 if (resizingBackground || item != background || !change.sizeChange())
892 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
895 if (change.widthChange())
896 extra.value().hasBackgroundWidth = p->widthValid();
897 if (change.heightChange())
898 extra.value().hasBackgroundHeight = p->heightValid();
902void QQuickControlPrivate::itemDestroyed(QQuickItem *item)
905 if (item == background) {
906 background =
nullptr;
907 emit q->implicitBackgroundWidthChanged();
908 emit q->implicitBackgroundHeightChanged();
909 }
else if (item == contentItem) {
910 contentItem =
nullptr;
911 updateImplicitContentSize();
915void QQuickControlPrivate::itemFocusChanged(QQuickItem *item, Qt::FocusReason reason)
918 if (item == contentItem || item == q)
919 setLastFocusChangeReason(reason);
922bool QQuickControlPrivate::setLastFocusChangeReason(Qt::FocusReason reason)
925 Qt::FocusReason oldReason =
static_cast<Qt::FocusReason>(focusReason);
926 const auto focusReasonChanged = QQuickItemPrivate::setLastFocusChangeReason(reason);
927 if (focusReasonChanged)
928 emit q->focusReasonChanged();
929 if (isKeyFocusReason(oldReason) != isKeyFocusReason(reason))
930 emit q->visualFocusChanged();
932 return focusReasonChanged;
935QQuickControl::QQuickControl(QQuickItem *parent)
936 : QQuickItem(*(
new QQuickControlPrivate), parent)
942QQuickControl::QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent)
943 : QQuickItem(dd, parent)
949QQuickControl::~QQuickControl()
952 d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
953 d->removeImplicitSizeListener(d->contentItem);
955 QQuickItemPrivate::get(d->contentItem)->removeItemChangeListener(d, QQuickItemPrivate::Focus);
956#if QT_CONFIG(accessibility)
957 QAccessible::removeActivationObserver(d);
961void QQuickControl::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &value)
964 QQuickItem::itemChange(change, value);
966 case ItemEnabledHasChanged:
969 case ItemVisibleHasChanged:
970#if QT_CONFIG(quicktemplates2_hover)
971 if (!value.boolValue)
975 case ItemSceneChange:
976 case ItemParentHasChanged:
977 if ((change == ItemParentHasChanged && value.item) || (change == ItemSceneChange && value.window)) {
980 d->updateLocale(QQuickControlPrivate::calcLocale(d->parentItem),
false);
981#if QT_CONFIG(quicktemplates2_hover)
982 if (!d->explicitHoverEnabled)
983 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem),
false);
987 case ItemActiveFocusHasChanged:
988 if (isKeyFocusReason(
static_cast<Qt::FocusReason>(d->focusReason)))
989 emit visualFocusChanged();
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
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040QFont QQuickControl::font()
const
1042 Q_D(
const QQuickControl);
1043 QFont font = d->resolvedFont;
1045 font.setResolveMask(d->extra.value().requestedFont.resolveMask());
1049void QQuickControl::setFont(
const QFont &font)
1052 if (d->extra.value().requestedFont.resolveMask() == font.resolveMask() && d->extra.value().requestedFont == font)
1055 d->extra.value().requestedFont = font;
1059void QQuickControl::resetFont()
1065
1066
1067
1068
1069
1070
1071
1072
1073qreal QQuickControl::availableWidth()
const
1075 return qMax<qreal>(0.0, width() - leftPadding() - rightPadding());
1079
1080
1081
1082
1083
1084
1085
1086
1087qreal QQuickControl::availableHeight()
const
1089 return qMax<qreal>(0.0, height() - topPadding() - bottomPadding());
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131qreal QQuickControl::padding()
const
1133 Q_D(
const QQuickControl);
1137void QQuickControl::setPadding(qreal padding)
1140 if (qFuzzyCompare(d->padding, padding))
1143 const QMarginsF oldPadding = d->getPadding();
1144 const qreal oldVerticalPadding = d->getVerticalPadding();
1145 const qreal oldHorizontalPadding = d->getHorizontalPadding();
1147 d->padding = padding;
1148 emit paddingChanged();
1150 const QMarginsF newPadding = d->getPadding();
1151 const qreal newVerticalPadding = d->getVerticalPadding();
1152 const qreal newHorizontalPadding = d->getHorizontalPadding();
1154 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()))
1155 emit topPaddingChanged();
1156 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()))
1157 emit leftPaddingChanged();
1158 if (!qFuzzyCompare(newPadding.right(), oldPadding.right()))
1159 emit rightPaddingChanged();
1160 if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
1161 emit bottomPaddingChanged();
1162 if (!qFuzzyCompare(newVerticalPadding, oldVerticalPadding))
1163 emit verticalPaddingChanged();
1164 if (!qFuzzyCompare(newHorizontalPadding, oldHorizontalPadding))
1165 emit horizontalPaddingChanged();
1166 if (!qFuzzyCompare(newPadding.top(), oldPadding.top()) || !qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()))
1167 emit availableHeightChanged();
1168 if (!qFuzzyCompare(newPadding.left(), oldPadding.left()) || !qFuzzyCompare(newPadding.right(), oldPadding.right()))
1169 emit availableWidthChanged();
1171 paddingChange(newPadding, oldPadding);
1174void QQuickControl::resetPadding()
1180
1181
1182
1183
1184
1185
1186
1187qreal QQuickControl::topPadding()
const
1189 Q_D(
const QQuickControl);
1190 return d->getTopPadding();
1193void QQuickControl::setTopPadding(qreal padding)
1196 d->setTopPadding(padding);
1199void QQuickControl::resetTopPadding()
1202 d->setTopPadding(0,
true);
1206
1207
1208
1209
1210
1211
1212
1213qreal QQuickControl::leftPadding()
const
1215 Q_D(
const QQuickControl);
1216 return d->getLeftPadding();
1219void QQuickControl::setLeftPadding(qreal padding)
1222 d->setLeftPadding(padding);
1225void QQuickControl::resetLeftPadding()
1228 d->setLeftPadding(0,
true);
1232
1233
1234
1235
1236
1237
1238
1239qreal QQuickControl::rightPadding()
const
1241 Q_D(
const QQuickControl);
1242 return d->getRightPadding();
1245void QQuickControl::setRightPadding(qreal padding)
1248 d->setRightPadding(padding);
1251void QQuickControl::resetRightPadding()
1254 d->setRightPadding(0,
true);
1258
1259
1260
1261
1262
1263
1264
1265qreal QQuickControl::bottomPadding()
const
1267 Q_D(
const QQuickControl);
1268 return d->getBottomPadding();
1271void QQuickControl::setBottomPadding(qreal padding)
1274 d->setBottomPadding(padding);
1277void QQuickControl::resetBottomPadding()
1280 d->setBottomPadding(0,
true);
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294qreal QQuickControl::spacing()
const
1296 Q_D(
const QQuickControl);
1300void QQuickControl::setSpacing(qreal spacing)
1303 if (qFuzzyCompare(d->spacing, spacing))
1306 qreal oldSpacing = d->spacing;
1307 d->spacing = spacing;
1308 emit spacingChanged();
1309 spacingChange(spacing, oldSpacing);
1312void QQuickControl::resetSpacing()
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332QLocale QQuickControl::locale()
const
1334 Q_D(
const QQuickControl);
1338void QQuickControl::setLocale(
const QLocale &locale)
1341 if (d->hasLocale && d->locale == locale)
1344 d->updateLocale(locale,
true);
1347void QQuickControl::resetLocale()
1353 d->hasLocale =
false;
1354 d->updateLocale(QQuickControlPrivate::calcLocale(d->parentItem),
false);
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371bool QQuickControl::isMirrored()
const
1373 Q_D(
const QQuickControl);
1374 return d->isMirrored();
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402Qt::FocusReason QQuickControl::focusReason()
const
1404 Q_D(
const QQuickControl);
1405 return d->lastFocusChangeReason();
1408void QQuickControl::setFocusReason(Qt::FocusReason reason)
1411 d->setLastFocusChangeReason(reason);
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428bool QQuickControl::hasVisualFocus()
const
1430 Q_D(
const QQuickControl);
1431 return d->activeFocus && isKeyFocusReason(
static_cast<Qt::FocusReason>(d->focusReason));
1435
1436
1437
1438
1439
1440
1441
1442bool QQuickControl::isHovered()
const
1444#if QT_CONFIG(quicktemplates2_hover)
1445 Q_D(
const QQuickControl);
1452void QQuickControl::setHovered(
bool hovered)
1454#if QT_CONFIG(quicktemplates2_hover)
1456 if (hovered == d->hovered)
1459 d->hovered = hovered;
1460 emit hoveredChanged();
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482bool QQuickControl::isHoverEnabled()
const
1484#if QT_CONFIG(quicktemplates2_hover)
1485 Q_D(
const QQuickControl);
1486 return d->hoverEnabled;
1492void QQuickControl::setHoverEnabled(
bool enabled)
1494#if QT_CONFIG(quicktemplates2_hover)
1496 if (d->explicitHoverEnabled && enabled == d->hoverEnabled)
1499 d->updateHoverEnabled(enabled,
true);
1505void QQuickControl::resetHoverEnabled()
1507#if QT_CONFIG(quicktemplates2_hover)
1509 if (!d->explicitHoverEnabled)
1512 d->explicitHoverEnabled =
false;
1513 d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem),
false);
1518
1519
1520
1521
1522
1523
1524
1525
1526bool QQuickControl::isWheelEnabled()
const
1528 Q_D(
const QQuickControl);
1529 return d->wheelEnabled;
1532void QQuickControl::setWheelEnabled(
bool enabled)
1535 if (d->wheelEnabled == enabled)
1538 d->wheelEnabled = enabled;
1539 emit wheelEnabledChanged();
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564QQuickItem *QQuickControl::background()
const
1566 QQuickControlPrivate *d =
const_cast<QQuickControlPrivate *>(d_func());
1568 d->executeBackground();
1569 return d->background;
1572void QQuickControl::setBackground(QQuickItem *background)
1575 if (d->background == background)
1578 QQuickControlPrivate::warnIfCustomizationNotSupported(
this, background, QStringLiteral(
"background"));
1580 if (!d->background.isExecuting())
1581 d->cancelBackground();
1583 const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
1584 const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
1586 if (d->extra.isAllocated()) {
1587 d->extra.value().hasBackgroundWidth =
false;
1588 d->extra.value().hasBackgroundHeight =
false;
1591 d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
1592 QQuickControlPrivate::hideOldItem(d->background);
1593 d->background = background;
1596 background->setParentItem(
this);
1597 if (qFuzzyIsNull(background->z()))
1598 background->setZ(-1);
1599 QQuickItemPrivate *p = QQuickItemPrivate::get(background);
1600 if (p->widthValid() || p->heightValid()) {
1601 d->extra.value().hasBackgroundWidth = p->widthValid();
1602 d->extra.value().hasBackgroundHeight = p->heightValid();
1604 if (isComponentComplete())
1605 d->resizeBackground();
1606 d->addImplicitSizeListener(background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
1609 if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
1610 emit implicitBackgroundWidthChanged();
1611 if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
1612 emit implicitBackgroundHeightChanged();
1613 if (!d->background.isExecuting())
1614 emit backgroundChanged();
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647QQuickItem *QQuickControl::contentItem()
const
1649 QQuickControlPrivate *d =
const_cast<QQuickControlPrivate *>(d_func());
1650 if (!d->contentItem)
1651 d->setContentItem_helper(d->getContentItem(),
false);
1652 return d->contentItem;
1655void QQuickControl::setContentItem(QQuickItem *item)
1658 d->setContentItem_helper(item,
true);
1661qreal QQuickControl::baselineOffset()
const
1663 Q_D(
const QQuickControl);
1664 return d->baselineOffset;
1667void QQuickControl::setBaselineOffset(qreal offset)
1670 d->extra.value().hasBaselineOffset =
true;
1671 QQuickItem::setBaselineOffset(offset);
1674void QQuickControl::resetBaselineOffset()
1677 if (!d->extra.isAllocated() || !d->extra.value().hasBaselineOffset)
1680 if (d->extra.isAllocated())
1681 d->extra.value().hasBaselineOffset =
false;
1682 d->updateBaselineOffset();
1686
1687
1688
1689
1690
1691
1692
1693
1694qreal QQuickControl::horizontalPadding()
const
1696 Q_D(
const QQuickControl);
1697 return d->getHorizontalPadding();
1700void QQuickControl::setHorizontalPadding(qreal padding)
1703 d->setHorizontalPadding(padding);
1706void QQuickControl::resetHorizontalPadding()
1709 d->setHorizontalPadding(0,
true);
1713
1714
1715
1716
1717
1718
1719
1720
1721qreal QQuickControl::verticalPadding()
const
1723 Q_D(
const QQuickControl);
1724 return d->getVerticalPadding();
1727void QQuickControl::setVerticalPadding(qreal padding)
1730 d->setVerticalPadding(padding);
1733void QQuickControl::resetVerticalPadding()
1736 d->setVerticalPadding(0,
true);
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761qreal QQuickControl::implicitContentWidth()
const
1763 Q_D(
const QQuickControl);
1765 if (
auto *safeArea =
static_cast<QQuickSafeArea*>(
1766 qmlAttachedPropertiesObject<QQuickSafeArea>(
this,
false))) {
1772 static constexpr auto kLastKnownGoodImplicitWidth =
"_q_lastKnownGoodImplicitWidth";
1773 if (safeArea->detectedPossibleBindingLoop) {
1774 const auto lastImplicitWidth = safeArea->property(kLastKnownGoodImplicitWidth).value<
int>();
1775 return lastImplicitWidth - leftPadding() - rightPadding();
1777 safeArea->setProperty(kLastKnownGoodImplicitWidth, implicitWidth());
1781 return d->implicitContentWidth;
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806qreal QQuickControl::implicitContentHeight()
const
1808 Q_D(
const QQuickControl);
1810 if (
auto *safeArea =
static_cast<QQuickSafeArea*>(
1811 qmlAttachedPropertiesObject<QQuickSafeArea>(
this,
false))) {
1817 static constexpr auto kLastKnownGoodImplicitHeight =
"_q_lastKnownGoodImplicitHeight";
1818 if (safeArea->detectedPossibleBindingLoop) {
1819 const auto lastImplicitHeight = safeArea->property(kLastKnownGoodImplicitHeight).value<
int>();
1820 return lastImplicitHeight - topPadding() - bottomPadding();
1822 safeArea->setProperty(kLastKnownGoodImplicitHeight, implicitHeight());
1826 return d->implicitContentHeight;
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850qreal QQuickControl::implicitBackgroundWidth()
const
1852 Q_D(
const QQuickControl);
1855 return d->background->implicitWidth();
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879qreal QQuickControl::implicitBackgroundHeight()
const
1881 Q_D(
const QQuickControl);
1884 return d->background->implicitHeight();
1888
1889
1890
1891
1892
1893
1894
1895qreal QQuickControl::topInset()
const
1897 Q_D(
const QQuickControl);
1898 return d->getTopInset();
1901void QQuickControl::setTopInset(qreal inset)
1904 d->setTopInset(inset);
1907void QQuickControl::resetTopInset()
1910 d->setTopInset(0,
true);
1914
1915
1916
1917
1918
1919
1920
1921qreal QQuickControl::leftInset()
const
1923 Q_D(
const QQuickControl);
1924 return d->getLeftInset();
1927void QQuickControl::setLeftInset(qreal inset)
1930 d->setLeftInset(inset);
1933void QQuickControl::resetLeftInset()
1936 d->setLeftInset(0,
true);
1940
1941
1942
1943
1944
1945
1946
1947qreal QQuickControl::rightInset()
const
1949 Q_D(
const QQuickControl);
1950 return d->getRightInset();
1953void QQuickControl::setRightInset(qreal inset)
1956 d->setRightInset(inset);
1959void QQuickControl::resetRightInset()
1962 d->setRightInset(0,
true);
1966
1967
1968
1969
1970
1971
1972
1973qreal QQuickControl::bottomInset()
const
1975 Q_D(
const QQuickControl);
1976 return d->getBottomInset();
1979void QQuickControl::setBottomInset(qreal inset)
1982 d->setBottomInset(inset);
1985void QQuickControl::resetBottomInset()
1988 d->setBottomInset(0,
true);
1991void QQuickControl::classBegin()
1994 QQuickItem::classBegin();
1998void QQuickControl::componentComplete()
2001 d->executeBackground(
true);
2002 d->executeContentItem(
true);
2003 QQuickItem::componentComplete();
2004 d->resizeBackground();
2006 d->updateBaselineOffset();
2008 d->locale = QQuickControlPrivate::calcLocale(d->parentItem);
2009#if QT_CONFIG(quicktemplates2_hover)
2010 if (!d->explicitHoverEnabled)
2011 setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem));
2013#if QT_CONFIG(accessibility)
2014 if (QAccessible::isActive())
2015 accessibilityActiveChanged(
true);
2019QFont QQuickControl::defaultFont()
const
2021 return QQuickTheme::font(QQuickTheme::System);
2024void QQuickControl::focusInEvent(QFocusEvent *event)
2026 QQuickItem::focusInEvent(event);
2029void QQuickControl::focusOutEvent(QFocusEvent *event)
2031 QQuickItem::focusOutEvent(event);
2034#if QT_CONFIG(quicktemplates2_hover)
2035void QQuickControl::hoverEnterEvent(QHoverEvent *event)
2038 setHovered(d->hoverEnabled);
2042void QQuickControl::hoverMoveEvent(QHoverEvent *event)
2045 setHovered(d->hoverEnabled && contains(event->position()));
2049void QQuickControl::hoverLeaveEvent(QHoverEvent *event)
2056void QQuickControl::mousePressEvent(QMouseEvent *event)
2059 event->setAccepted(d->handlePress(event->position(), event->timestamp()));
2062void QQuickControl::mouseMoveEvent(QMouseEvent *event)
2065 event->setAccepted(d->handleMove(event->position(), event->timestamp()));
2068void QQuickControl::mouseReleaseEvent(QMouseEvent *event)
2071 event->setAccepted(d->handleRelease(event->position(), event->timestamp()));
2074void QQuickControl::mouseUngrabEvent()
2080#if QT_CONFIG(quicktemplates2_multitouch)
2081void QQuickControl::touchEvent(QTouchEvent *event)
2084 switch (event->type()) {
2085 case QEvent::TouchBegin:
2086 case QEvent::TouchUpdate:
2087 case QEvent::TouchEnd:
2088 for (
const QTouchEvent::TouchPoint &point : event->points()) {
2089 if (!d->acceptTouch(point))
2092 switch (point.state()) {
2093 case QEventPoint::Pressed:
2094 d->handlePress(point.position(), event->timestamp());
2096 case QEventPoint::Updated:
2097 d->handleMove(point.position(), event->timestamp());
2099 case QEventPoint::Released:
2100 d->handleRelease(point.position(), event->timestamp());
2108 case QEvent::TouchCancel:
2113 QQuickItem::touchEvent(event);
2118void QQuickControl::touchUngrabEvent()
2125#if QT_CONFIG(wheelevent)
2126void QQuickControl::wheelEvent(QWheelEvent *event)
2129 event->setAccepted(d->wheelEnabled);
2133void QQuickControl::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
2136 QQuickItem::geometryChange(newGeometry, oldGeometry);
2137 d->resizeBackground();
2139 if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width()))
2140 emit availableWidthChanged();
2141 if (!qFuzzyCompare(newGeometry.height(), oldGeometry.height()))
2142 emit availableHeightChanged();
2145void QQuickControl::enabledChange()
2149void QQuickControl::fontChange(
const QFont &newFont,
const QFont &oldFont)
2155#if QT_CONFIG(quicktemplates2_hover)
2156void QQuickControl::hoverChange()
2161void QQuickControl::mirrorChange()
2163 emit mirroredChanged();
2166void QQuickControl::spacingChange(qreal newSpacing, qreal oldSpacing)
2168 Q_UNUSED(newSpacing);
2169 Q_UNUSED(oldSpacing);
2172void QQuickControl::paddingChange(
const QMarginsF &newPadding,
const QMarginsF &oldPadding)
2175 Q_UNUSED(newPadding);
2176 Q_UNUSED(oldPadding);
2178 d->updateBaselineOffset();
2181void QQuickControl::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
2187void QQuickControl::localeChange(
const QLocale &newLocale,
const QLocale &oldLocale)
2189 Q_UNUSED(newLocale);
2190 Q_UNUSED(oldLocale);
2193void QQuickControl::insetChange(
const QMarginsF &newInset,
const QMarginsF &oldInset)
2198 d->resizeBackground();
2201#if QT_CONFIG(accessibility)
2202QAccessible::Role QQuickControl::accessibleRole()
const
2204 return QAccessible::NoRole;
2207void QQuickControl::accessibilityActiveChanged(
bool active)
2213 QQuickAccessibleAttached *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(
this,
true));
2214 Q_ASSERT(accessibleAttached);
2215 accessibleAttached->setRole(d->effectiveAccessibleRole());
2219QString QQuickControl::accessibleName()
const
2221#if QT_CONFIG(accessibility)
2222 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(
this))
2223 return accessibleAttached->name();
2228void QQuickControl::maybeSetAccessibleName(
const QString &name)
2230#if QT_CONFIG(accessibility)
2231 if (QQuickAccessibleAttached *accessibleAttached = QQuickControlPrivate::accessibleAttached(
this)) {
2232 if (!accessibleAttached->wasNameExplicitlySet())
2233 accessibleAttached->setNameImplicitly(name);
2240QVariant QQuickControl::accessibleProperty(
const char *propertyName)
2242#if QT_CONFIG(accessibility)
2243 if (QAccessible::isActive())
2244 return QQuickAccessibleAttached::property(
this, propertyName);
2246 Q_UNUSED(propertyName);
2250bool QQuickControl::setAccessibleProperty(
const char *propertyName,
const QVariant &value)
2252#if QT_CONFIG(accessibility)
2253 if (QAccessible::isActive())
2254 return QQuickAccessibleAttached::setProperty(
this, propertyName, value);
2256 Q_UNUSED(propertyName);
2263#include "moc_qquickcontrol_p.cpp"
Combined button and popup list for selecting options.
static bool isKeyFocusReason(Qt::FocusReason reason)
static QString contentItemName()