102void QQuickAbstractButtonPrivate::init()
104 Q_Q(QQuickAbstractButton);
105 q->setActiveFocusOnTab(
true);
107 q->setFocusPolicy(Qt::TabFocus);
109 q->setFocusPolicy(Qt::StrongFocus);
111 q->setAcceptedMouseButtons(Qt::LeftButton);
112#if QT_CONFIG(quicktemplates2_multitouch)
113 q->setAcceptTouchEvents(
true);
116 q->setCursor(Qt::ArrowCursor);
118 setSizePolicy(QLayoutPolicy::Preferred, QLayoutPolicy::Fixed);
144bool QQuickAbstractButtonPrivate::handlePress(
const QPointF &point, ulong timestamp)
146 Q_Q(QQuickAbstractButton);
149 QQuickControlPrivate::handlePress(point, timestamp);
150 setPressPoint(point);
157 else if (touchId != -1 || Qt::LeftButton == (pressButtons & Qt::LeftButton))
164 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(q,
false);
169bool QQuickAbstractButtonPrivate::handleMove(
const QPointF &point, ulong timestamp)
171 Q_Q(QQuickAbstractButton);
172 QQuickControlPrivate::handleMove(point, timestamp);
174 q->setPressed(keepPressed || q->contains(point));
176 if (!pressed && autoRepeat)
178 else if (holdTimer > 0 && (!pressed || QLineF(pressPoint, point).length() > QGuiApplication::styleHints()->startDragDistance()))
183bool QQuickAbstractButtonPrivate::handleRelease(
const QPointF &point, ulong timestamp)
185 Q_Q(QQuickAbstractButton);
187 const int pressTouchId = touchId;
189 QQuickControlPrivate::handleRelease(point, timestamp);
190 bool wasPressed = pressed;
191 setPressPoint(point);
192 q->setPressed(
false);
193 pressButtons = Qt::NoButton;
195 const bool touchDoubleClick = pressTouchId != -1 && lastTouchReleaseTimestamp != 0
196 && QQuickDeliveryAgentPrivate::isWithinDoubleClickInterval(timestamp - lastTouchReleaseTimestamp)
197 && isDoubleClickConnected();
199 if (!wasHeld && wasPressed && (keepPressed || q->contains(point)))
203 if (wasHeld && pressTouchId != -1) {
206 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(q,
false);
210 if (!wasHeld && !wasDoubleClick)
211 trigger(touchDoubleClick);
221 if (!touchDoubleClick) {
224 if (pressTouchId != -1) {
228 lastTouchReleaseTimestamp = timestamp;
233 lastTouchReleaseTimestamp = 0;
236 wasDoubleClick =
false;
372void QQuickAbstractButtonPrivate::updateEffectiveIcon()
374 Q_Q(QQuickAbstractButton);
379 QQuickIcon newEffectiveIcon = action ? icon.resolve(action->icon()) : icon;
381 bool unchanged = newEffectiveIcon == effectiveIcon;
391 const bool actionIconColorResolved = QQuickIconPrivate::isResolved(action->icon(),
392 QQuickIconPrivate::ColorResolved);
393 const bool iconColorResolved = QQuickIconPrivate::isResolved(icon,
394 QQuickIconPrivate::ColorResolved);
396 unchanged = newEffectiveIcon == effectiveIcon;
400 if (unchanged && !iconColorResolved && actionIconColorResolved)
404 if (actionIconColorResolved)
405 newEffectiveIcon.resolveColor();
410 effectiveIcon = newEffectiveIcon;
415 if (action && !QQuickIconPrivate::isResolved(effectiveIcon, QQuickIconPrivate::ColorResolved)) {
417 if (QQuickIconPrivate::isResolved(action->icon(), QQuickIconPrivate::ColorResolved)) {
420 effectiveIcon.resolveColor();
424 emit q->iconChanged();
448void QQuickAbstractButtonPrivate::trigger(
bool doubleClick)
450 Q_Q(QQuickAbstractButton);
451 const QScopedValueRollback<
bool> rollback(wasEnabledBeforeTrigger, effectiveEnable);
453 bool actionTriggered =
false;
454 if (action && action->isEnabled())
455 actionTriggered = QQuickActionPrivate::get(action)->trigger(q,
false);
459 if (!wasEnabledBeforeTrigger || actionTriggered)
465 emit q->doubleClicked();
545QList<QQuickAbstractButton *> QQuickAbstractButtonPrivate::findExclusiveButtons()
const
547 QList<QQuickAbstractButton *> buttons;
549 QQmlListProperty<QQuickAbstractButton> groupButtons = group->buttons();
550 int count = groupButtons.count(&groupButtons);
551 for (
int i = 0; i < count; ++i) {
552 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(groupButtons.at(&groupButtons, i));
556 }
else if (parentItem) {
557 const auto childItems = parentItem->childItems();
558 for (QQuickItem *child : childItems) {
559 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(child);
560 if (button && button->autoExclusive() && !QQuickAbstractButtonPrivate::get(button)->group)
834void QQuickAbstractButton::setIndicator(QQuickItem *indicator)
836 Q_D(QQuickAbstractButton);
837 if (d->indicator == indicator)
840 QQuickControlPrivate::warnIfCustomizationNotSupported(
this, indicator, QStringLiteral(
"indicator"));
842 if (!d->indicator.isExecuting())
843 d->cancelIndicator();
845 const qreal oldImplicitIndicatorWidth = implicitIndicatorWidth();
846 const qreal oldImplicitIndicatorHeight = implicitIndicatorHeight();
848 d->removeImplicitSizeListener(d->indicator);
849 QQuickControlPrivate::hideOldItem(d->indicator);
850 d->indicator = indicator;
853 if (!indicator->parentItem())
854 indicator->setParentItem(
this);
855 indicator->setAcceptedMouseButtons(Qt::LeftButton);
856 d->addImplicitSizeListener(indicator);
859 if (!qFuzzyCompare(oldImplicitIndicatorWidth, implicitIndicatorWidth()))
860 emit implicitIndicatorWidthChanged();
861 if (!qFuzzyCompare(oldImplicitIndicatorHeight, implicitIndicatorHeight()))
862 emit implicitIndicatorHeightChanged();
863 if (!d->indicator.isExecuting())
864 emit indicatorChanged();
951void QQuickAbstractButton::setAction(QQuickAction *action)
953 Q_D(QQuickAbstractButton);
954 qCDebug(lcButtonAction) <<
this <<
"setAction called with" << action;
955 if (d->action == action)
958 const QString oldText = text();
960 if (QQuickAction *oldAction = d->action.data()) {
961 QQuickActionPrivate::get(oldAction)->unregisterItem(
this);
962 QObjectPrivate::disconnect(oldAction, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
963 QObjectPrivate::disconnect(oldAction, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
965 QObjectPrivate::disconnect(oldAction, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
966 disconnect(oldAction, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
967 disconnect(oldAction, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
968 disconnect(oldAction, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
972 QQuickActionPrivate::get(action)->registerItem(
this);
973 QObjectPrivate::connect(action, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
974 QObjectPrivate::connect(action, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
976 QObjectPrivate::connect(action, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
977 connect(action, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
978 connect(action, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
979 connect(action, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
981 setChecked(action->isChecked());
982 setCheckable(action->isCheckable());
983 setEnabled(action->isEnabled());
986#if QT_CONFIG(accessibility)
987 auto attached = qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(
this,
true));
989 attached->setProxying(qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(action,
true)));
994 if (oldText != text())
995 buttonChange(ButtonTextChange);
997 d->updateEffectiveIcon();
999 emit actionChanged();
1334void QQuickAbstractButton::timerEvent(QTimerEvent *event)
1336 Q_D(QQuickAbstractButton);
1337 QQuickControl::timerEvent(event);
1338 if (event->timerId() == d->holdTimer) {
1339 d->stopPressAndHold();
1341 emit pressAndHold();
1342 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(
this,
true);
1343 }
else if (event->timerId() == d->delayTimer) {
1344 d->startPressRepeat();
1345 }
else if (event->timerId() == d->repeatTimer) {
1349 }
else if (event->timerId() == d->animateTimer) {
1350 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1351 if (setFocusOnRelease && focusPolicy() & Qt::ClickFocus)
1352 forceActiveFocus(Qt::MouseFocusReason);
1353 d->handleRelease(QPointF(d->width / 2, d->height / 2), 0);
1354 killTimer(d->animateTimer);
1355 d->animateTimer = 0;