107void QQuickAbstractButtonPrivate::init()
109 Q_Q(QQuickAbstractButton);
110 q->setActiveFocusOnTab(
true);
112 q->setFocusPolicy(Qt::TabFocus);
114 q->setFocusPolicy(Qt::StrongFocus);
116 q->setAcceptedMouseButtons(Qt::LeftButton);
117#if QT_CONFIG(quicktemplates2_multitouch)
118 q->setAcceptTouchEvents(
true);
121 q->setCursor(Qt::ArrowCursor);
123 setSizePolicy(QLayoutPolicy::Preferred, QLayoutPolicy::Fixed);
124 mnemonicEnabled = QGuiApplicationPrivate::platformTheme()->themeHint(
125 QPlatformTheme::MnemonicsEnabled).toBool();
151bool QQuickAbstractButtonPrivate::handlePress(
const QPointF &point, ulong timestamp)
153 Q_Q(QQuickAbstractButton);
156 QQuickControlPrivate::handlePress(point, timestamp);
157 setPressPoint(point);
164 else if (touchId != -1 || Qt::LeftButton == (pressButtons & Qt::LeftButton))
171 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(q,
false);
176bool QQuickAbstractButtonPrivate::handleMove(
const QPointF &point, ulong timestamp)
178 Q_Q(QQuickAbstractButton);
179 QQuickControlPrivate::handleMove(point, timestamp);
181 q->setPressed(keepPressed || q->contains(point));
183 if (!pressed && autoRepeat)
185 else if (holdTimer > 0 && (!pressed || QLineF(pressPoint, point).length() > QGuiApplication::styleHints()->startDragDistance()))
190bool QQuickAbstractButtonPrivate::handleRelease(
const QPointF &point, ulong timestamp)
192 Q_Q(QQuickAbstractButton);
194 const int pressTouchId = touchId;
196 QQuickControlPrivate::handleRelease(point, timestamp);
197 bool wasPressed = pressed;
198 setPressPoint(point);
199 q->setPressed(
false);
200 pressButtons = Qt::NoButton;
202 const bool touchDoubleClick = pressTouchId != -1 && lastTouchReleaseTimestamp != 0
203 && QQuickDeliveryAgentPrivate::isWithinDoubleClickInterval(timestamp - lastTouchReleaseTimestamp)
204 && isDoubleClickConnected();
206 if (!wasHeld && wasPressed && (keepPressed || q->contains(point)))
210 if (wasHeld && pressTouchId != -1) {
213 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(q,
false);
217 if (!wasHeld && !wasDoubleClick)
218 trigger(touchDoubleClick);
228 if (!touchDoubleClick) {
231 if (pressTouchId != -1) {
235 lastTouchReleaseTimestamp = timestamp;
240 lastTouchReleaseTimestamp = 0;
243 wasDoubleClick =
false;
424void QQuickAbstractButtonPrivate::updateEffectiveIcon()
426 Q_Q(QQuickAbstractButton);
431 QQuickIcon newEffectiveIcon = action ? icon.resolve(action->icon()) : icon;
433 bool unchanged = newEffectiveIcon == effectiveIcon;
443 const bool actionIconColorResolved = QQuickIconPrivate::isResolved(action->icon(),
444 QQuickIconPrivate::ColorResolved);
445 const bool iconColorResolved = QQuickIconPrivate::isResolved(icon,
446 QQuickIconPrivate::ColorResolved);
448 unchanged = newEffectiveIcon == effectiveIcon;
452 if (unchanged && !iconColorResolved && actionIconColorResolved)
456
457
458
459
460
461
462
463
464
465 if (actionIconColorResolved && !iconColorResolved) {
466 QQuickIconPrivate::setResolved(newEffectiveIcon,
467 QQuickIconPrivate::InheritedColorResolved);
473 effectiveIcon = newEffectiveIcon;
478 emit q->iconChanged();
502void QQuickAbstractButtonPrivate::trigger(
bool doubleClick)
504 Q_Q(QQuickAbstractButton);
505 const QScopedValueRollback<
bool> rollback(wasEnabledBeforeTrigger, effectiveEnable);
507 bool actionTriggered =
false;
508 if (action && action->isEnabled())
509 actionTriggered = QQuickActionPrivate::get(action)->trigger(q,
false);
513 if (!wasEnabledBeforeTrigger || actionTriggered)
519 emit q->doubleClicked();
599QList<QQuickAbstractButton *> QQuickAbstractButtonPrivate::findExclusiveButtons()
const
601 QList<QQuickAbstractButton *> buttons;
603 QQmlListProperty<QQuickAbstractButton> groupButtons = group->buttons();
604 int count = groupButtons.count(&groupButtons);
605 for (
int i = 0; i < count; ++i) {
606 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(groupButtons.at(&groupButtons, i));
610 }
else if (parentItem) {
611 const auto childItems = parentItem->childItems();
612 for (QQuickItem *child : childItems) {
613 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(child);
614 if (button && button->autoExclusive() && !QQuickAbstractButtonPrivate::get(button)->group)
888void QQuickAbstractButton::setIndicator(QQuickItem *indicator)
890 Q_D(QQuickAbstractButton);
891 if (d->indicator == indicator)
894 QQuickControlPrivate::warnIfCustomizationNotSupported(
this, indicator, QStringLiteral(
"indicator"));
896 if (!d->indicator.isExecuting())
897 d->cancelIndicator();
899 const qreal oldImplicitIndicatorWidth = implicitIndicatorWidth();
900 const qreal oldImplicitIndicatorHeight = implicitIndicatorHeight();
902 d->removeImplicitSizeListener(d->indicator);
903 QQuickControlPrivate::hideOldItem(d->indicator);
904 d->indicator = indicator;
907 if (!indicator->parentItem())
908 indicator->setParentItem(
this);
909 indicator->setAcceptedMouseButtons(Qt::LeftButton);
910 d->addImplicitSizeListener(indicator);
913 if (!qFuzzyCompare(oldImplicitIndicatorWidth, implicitIndicatorWidth()))
914 emit implicitIndicatorWidthChanged();
915 if (!qFuzzyCompare(oldImplicitIndicatorHeight, implicitIndicatorHeight()))
916 emit implicitIndicatorHeightChanged();
917 if (!d->indicator.isExecuting())
918 emit indicatorChanged();
1010void QQuickAbstractButton::setAction(QQuickAction *action)
1012 Q_D(QQuickAbstractButton);
1013 qCDebug(lcButtonAction) <<
this <<
"setAction called with" << action;
1014 if (d->action == action)
1017 const QString oldText = text();
1019 if (QQuickAction *oldAction = d->action.data()) {
1020 QQuickActionPrivate::get(oldAction)->unregisterItem(
this);
1021 QObjectPrivate::disconnect(oldAction, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
1022 QObjectPrivate::disconnect(oldAction, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
1024 QObjectPrivate::disconnect(oldAction, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
1025 disconnect(oldAction, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
1026 disconnect(oldAction, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
1027 disconnect(oldAction, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
1031 QQuickActionPrivate::get(action)->registerItem(
this);
1032 QObjectPrivate::connect(action, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
1033 QObjectPrivate::connect(action, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
1035 QObjectPrivate::connect(action, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
1036 connect(action, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
1037 connect(action, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
1038 connect(action, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
1040 setChecked(action->isChecked());
1041 setCheckable(action->isCheckable());
1042 setEnabled(action->isEnabled());
1045#if QT_CONFIG(accessibility)
1046 auto attached = qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(
this,
true));
1048 attached->setProxying(qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(action,
true)));
1053 if (oldText != text())
1054 buttonChange(ButtonTextChange);
1056 d->updateEffectiveIcon();
1058 emit actionChanged();
1405void QQuickAbstractButton::timerEvent(QTimerEvent *event)
1407 Q_D(QQuickAbstractButton);
1408 QQuickControl::timerEvent(event);
1409 if (event->timerId() == d->holdTimer) {
1410 d->stopPressAndHold();
1412 emit pressAndHold();
1413 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(
this,
true);
1414 }
else if (event->timerId() == d->delayTimer) {
1415 d->startPressRepeat();
1416 }
else if (event->timerId() == d->repeatTimer) {
1420 }
else if (event->timerId() == d->animateTimer) {
1421 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1422 if (setFocusOnRelease && focusPolicy() & Qt::ClickFocus)
1423 forceActiveFocus(Qt::MouseFocusReason);
1424 d->handleRelease(QPointF(d->width / 2, d->height / 2), 0);
1425 killTimer(d->animateTimer);
1426 d->animateTimer = 0;