105void QQuickAbstractButtonPrivate::init()
107 Q_Q(QQuickAbstractButton);
108 q->setActiveFocusOnTab(
true);
110 q->setFocusPolicy(Qt::TabFocus);
112 q->setFocusPolicy(Qt::StrongFocus);
114 q->setAcceptedMouseButtons(Qt::LeftButton);
115#if QT_CONFIG(quicktemplates2_multitouch)
116 q->setAcceptTouchEvents(
true);
119 q->setCursor(Qt::ArrowCursor);
121 setSizePolicy(QLayoutPolicy::Preferred, QLayoutPolicy::Fixed);
122 mnemonicEnabled = QGuiApplicationPrivate::platformTheme()->themeHint(
123 QPlatformTheme::MnemonicsEnabled).toBool();
149bool QQuickAbstractButtonPrivate::handlePress(
const QPointF &point, ulong timestamp)
151 Q_Q(QQuickAbstractButton);
154 QQuickControlPrivate::handlePress(point, timestamp);
155 setPressPoint(point);
162 else if (touchId != -1 || Qt::LeftButton == (pressButtons & Qt::LeftButton))
169 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(q,
false);
174bool QQuickAbstractButtonPrivate::handleMove(
const QPointF &point, ulong timestamp)
176 Q_Q(QQuickAbstractButton);
177 QQuickControlPrivate::handleMove(point, timestamp);
179 q->setPressed(keepPressed || q->contains(point));
181 if (!pressed && autoRepeat)
183 else if (holdTimer > 0 && (!pressed || QLineF(pressPoint, point).length() > QGuiApplication::styleHints()->startDragDistance()))
188bool QQuickAbstractButtonPrivate::handleRelease(
const QPointF &point, ulong timestamp)
190 Q_Q(QQuickAbstractButton);
192 const int pressTouchId = touchId;
194 QQuickControlPrivate::handleRelease(point, timestamp);
195 bool wasPressed = pressed;
196 setPressPoint(point);
197 q->setPressed(
false);
198 pressButtons = Qt::NoButton;
200 const bool touchDoubleClick = pressTouchId != -1 && lastTouchReleaseTimestamp != 0
201 && QQuickDeliveryAgentPrivate::isWithinDoubleClickInterval(timestamp - lastTouchReleaseTimestamp)
202 && isDoubleClickConnected();
204 if (!wasHeld && wasPressed && (keepPressed || q->contains(point)))
208 if (wasHeld && pressTouchId != -1) {
211 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(q,
false);
215 if (!wasHeld && !wasDoubleClick)
216 trigger(touchDoubleClick);
226 if (!touchDoubleClick) {
229 if (pressTouchId != -1) {
233 lastTouchReleaseTimestamp = timestamp;
238 lastTouchReleaseTimestamp = 0;
241 wasDoubleClick =
false;
416void QQuickAbstractButtonPrivate::updateEffectiveIcon()
418 Q_Q(QQuickAbstractButton);
423 QQuickIcon newEffectiveIcon = action ? icon.resolve(action->icon()) : icon;
425 bool unchanged = newEffectiveIcon == effectiveIcon;
435 const bool actionIconColorResolved = QQuickIconPrivate::isResolved(action->icon(),
436 QQuickIconPrivate::ColorResolved);
437 const bool iconColorResolved = QQuickIconPrivate::isResolved(icon,
438 QQuickIconPrivate::ColorResolved);
440 unchanged = newEffectiveIcon == effectiveIcon;
444 if (unchanged && !iconColorResolved && actionIconColorResolved)
448 if (actionIconColorResolved)
449 newEffectiveIcon.resolveColor();
454 effectiveIcon = newEffectiveIcon;
459 if (action && !QQuickIconPrivate::isResolved(effectiveIcon, QQuickIconPrivate::ColorResolved)) {
461 if (QQuickIconPrivate::isResolved(action->icon(), QQuickIconPrivate::ColorResolved)) {
464 effectiveIcon.resolveColor();
468 emit q->iconChanged();
492void QQuickAbstractButtonPrivate::trigger(
bool doubleClick)
494 Q_Q(QQuickAbstractButton);
495 const QScopedValueRollback<
bool> rollback(wasEnabledBeforeTrigger, effectiveEnable);
497 bool actionTriggered =
false;
498 if (action && action->isEnabled())
499 actionTriggered = QQuickActionPrivate::get(action)->trigger(q,
false);
503 if (!wasEnabledBeforeTrigger || actionTriggered)
509 emit q->doubleClicked();
589QList<QQuickAbstractButton *> QQuickAbstractButtonPrivate::findExclusiveButtons()
const
591 QList<QQuickAbstractButton *> buttons;
593 QQmlListProperty<QQuickAbstractButton> groupButtons = group->buttons();
594 int count = groupButtons.count(&groupButtons);
595 for (
int i = 0; i < count; ++i) {
596 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(groupButtons.at(&groupButtons, i));
600 }
else if (parentItem) {
601 const auto childItems = parentItem->childItems();
602 for (QQuickItem *child : childItems) {
603 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(child);
604 if (button && button->autoExclusive() && !QQuickAbstractButtonPrivate::get(button)->group)
878void QQuickAbstractButton::setIndicator(QQuickItem *indicator)
880 Q_D(QQuickAbstractButton);
881 if (d->indicator == indicator)
884 QQuickControlPrivate::warnIfCustomizationNotSupported(
this, indicator, QStringLiteral(
"indicator"));
886 if (!d->indicator.isExecuting())
887 d->cancelIndicator();
889 const qreal oldImplicitIndicatorWidth = implicitIndicatorWidth();
890 const qreal oldImplicitIndicatorHeight = implicitIndicatorHeight();
892 d->removeImplicitSizeListener(d->indicator);
893 QQuickControlPrivate::hideOldItem(d->indicator);
894 d->indicator = indicator;
897 if (!indicator->parentItem())
898 indicator->setParentItem(
this);
899 indicator->setAcceptedMouseButtons(Qt::LeftButton);
900 d->addImplicitSizeListener(indicator);
903 if (!qFuzzyCompare(oldImplicitIndicatorWidth, implicitIndicatorWidth()))
904 emit implicitIndicatorWidthChanged();
905 if (!qFuzzyCompare(oldImplicitIndicatorHeight, implicitIndicatorHeight()))
906 emit implicitIndicatorHeightChanged();
907 if (!d->indicator.isExecuting())
908 emit indicatorChanged();
995void QQuickAbstractButton::setAction(QQuickAction *action)
997 Q_D(QQuickAbstractButton);
998 qCDebug(lcButtonAction) <<
this <<
"setAction called with" << action;
999 if (d->action == action)
1002 const QString oldText = text();
1004 if (QQuickAction *oldAction = d->action.data()) {
1005 QQuickActionPrivate::get(oldAction)->unregisterItem(
this);
1006 QObjectPrivate::disconnect(oldAction, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
1007 QObjectPrivate::disconnect(oldAction, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
1009 QObjectPrivate::disconnect(oldAction, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
1010 disconnect(oldAction, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
1011 disconnect(oldAction, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
1012 disconnect(oldAction, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
1016 QQuickActionPrivate::get(action)->registerItem(
this);
1017 QObjectPrivate::connect(action, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
1018 QObjectPrivate::connect(action, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
1020 QObjectPrivate::connect(action, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
1021 connect(action, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
1022 connect(action, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
1023 connect(action, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
1025 setChecked(action->isChecked());
1026 setCheckable(action->isCheckable());
1027 setEnabled(action->isEnabled());
1030#if QT_CONFIG(accessibility)
1031 auto attached = qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(
this,
true));
1033 attached->setProxying(qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(action,
true)));
1038 if (oldText != text())
1039 buttonChange(ButtonTextChange);
1041 d->updateEffectiveIcon();
1043 emit actionChanged();
1378void QQuickAbstractButton::timerEvent(QTimerEvent *event)
1380 Q_D(QQuickAbstractButton);
1381 QQuickControl::timerEvent(event);
1382 if (event->timerId() == d->holdTimer) {
1383 d->stopPressAndHold();
1385 emit pressAndHold();
1386 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(
this,
true);
1387 }
else if (event->timerId() == d->delayTimer) {
1388 d->startPressRepeat();
1389 }
else if (event->timerId() == d->repeatTimer) {
1393 }
else if (event->timerId() == d->animateTimer) {
1394 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1395 if (setFocusOnRelease && focusPolicy() & Qt::ClickFocus)
1396 forceActiveFocus(Qt::MouseFocusReason);
1397 d->handleRelease(QPointF(d->width / 2, d->height / 2), 0);
1398 killTimer(d->animateTimer);
1399 d->animateTimer = 0;