96void QQuickAbstractButtonPrivate::init()
98 Q_Q(QQuickAbstractButton);
99 q->setActiveFocusOnTab(
true);
101 q->setFocusPolicy(Qt::TabFocus);
103 q->setFocusPolicy(Qt::StrongFocus);
105 q->setAcceptedMouseButtons(Qt::LeftButton);
106#if QT_CONFIG(quicktemplates2_multitouch)
107 q->setAcceptTouchEvents(
true);
110 q->setCursor(Qt::ArrowCursor);
112 setSizePolicy(QLayoutPolicy::Preferred, QLayoutPolicy::Fixed);
158bool QQuickAbstractButtonPrivate::handleMove(
const QPointF &point, ulong timestamp)
160 Q_Q(QQuickAbstractButton);
161 QQuickControlPrivate::handleMove(point, timestamp);
163 q->setPressed(keepPressed || q->contains(point));
165 if (!pressed && autoRepeat)
167 else if (holdTimer > 0 && (!pressed || QLineF(pressPoint, point).length() > QGuiApplication::styleHints()->startDragDistance()))
172bool QQuickAbstractButtonPrivate::handleRelease(
const QPointF &point, ulong timestamp)
174 Q_Q(QQuickAbstractButton);
176 const int pressTouchId = touchId;
178 QQuickControlPrivate::handleRelease(point, timestamp);
179 bool wasPressed = pressed;
180 setPressPoint(point);
181 q->setPressed(
false);
182 pressButtons = Qt::NoButton;
184 const bool touchDoubleClick = pressTouchId != -1 && lastTouchReleaseTimestamp != 0
185 && QQuickDeliveryAgentPrivate::isWithinDoubleClickInterval(timestamp - lastTouchReleaseTimestamp)
186 && isDoubleClickConnected();
188 if (!wasHeld && (keepPressed || q->contains(point)))
193 if (!wasHeld && !wasDoubleClick)
194 trigger(touchDoubleClick);
204 if (!touchDoubleClick) {
207 if (pressTouchId != -1) {
211 lastTouchReleaseTimestamp = timestamp;
216 lastTouchReleaseTimestamp = 0;
219 wasDoubleClick =
false;
411void QQuickAbstractButtonPrivate::executeIndicator(
bool complete)
413 Q_Q(QQuickAbstractButton);
414 if (indicator.wasExecuted())
417 if (!indicator || complete)
418 quickBeginDeferred(q, indicatorName(), indicator);
420 quickCompleteDeferred(q, indicatorName(), indicator);
473QList<QQuickAbstractButton *> QQuickAbstractButtonPrivate::findExclusiveButtons()
const
475 QList<QQuickAbstractButton *> buttons;
477 QQmlListProperty<QQuickAbstractButton> groupButtons = group->buttons();
478 int count = groupButtons.count(&groupButtons);
479 for (
int i = 0; i < count; ++i) {
480 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(groupButtons.at(&groupButtons, i));
484 }
else if (parentItem) {
485 const auto childItems = parentItem->childItems();
486 for (QQuickItem *child : childItems) {
487 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(child);
488 if (button && button->autoExclusive() && !QQuickAbstractButtonPrivate::get(button)->group)
762void QQuickAbstractButton::setIndicator(QQuickItem *indicator)
764 Q_D(QQuickAbstractButton);
765 if (d->indicator == indicator)
768 QQuickControlPrivate::warnIfCustomizationNotSupported(
this, indicator, QStringLiteral(
"indicator"));
770 if (!d->indicator.isExecuting())
771 d->cancelIndicator();
773 const qreal oldImplicitIndicatorWidth = implicitIndicatorWidth();
774 const qreal oldImplicitIndicatorHeight = implicitIndicatorHeight();
776 d->removeImplicitSizeListener(d->indicator);
777 QQuickControlPrivate::hideOldItem(d->indicator);
778 d->indicator = indicator;
781 if (!indicator->parentItem())
782 indicator->setParentItem(
this);
783 indicator->setAcceptedMouseButtons(Qt::LeftButton);
784 d->addImplicitSizeListener(indicator);
787 if (!qFuzzyCompare(oldImplicitIndicatorWidth, implicitIndicatorWidth()))
788 emit implicitIndicatorWidthChanged();
789 if (!qFuzzyCompare(oldImplicitIndicatorHeight, implicitIndicatorHeight()))
790 emit implicitIndicatorHeightChanged();
791 if (!d->indicator.isExecuting())
792 emit indicatorChanged();
871void QQuickAbstractButton::setAction(QQuickAction *action)
873 Q_D(QQuickAbstractButton);
874 if (d->action == action)
877 const QString oldText = text();
879 if (QQuickAction *oldAction = d->action.data()) {
880 QQuickActionPrivate::get(oldAction)->unregisterItem(
this);
881 QObjectPrivate::disconnect(oldAction, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
882 QObjectPrivate::disconnect(oldAction, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
884 QObjectPrivate::disconnect(oldAction, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
885 disconnect(oldAction, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
886 disconnect(oldAction, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
887 disconnect(oldAction, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
891 QQuickActionPrivate::get(action)->registerItem(
this);
892 QObjectPrivate::connect(action, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
893 QObjectPrivate::connect(action, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
895 QObjectPrivate::connect(action, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
896 connect(action, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
897 connect(action, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
898 connect(action, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
900 setChecked(action->isChecked());
901 setCheckable(action->isCheckable());
902 setEnabled(action->isEnabled());
905#if QT_CONFIG(accessibility)
906 auto attached = qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(
this,
true));
908 attached->setProxying(qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(action,
true)));
913 if (oldText != text())
914 buttonChange(ButtonTextChange);
916 d->updateEffectiveIcon();
918 emit actionChanged();
1247void QQuickAbstractButton::timerEvent(QTimerEvent *event)
1249 Q_D(QQuickAbstractButton);
1250 QQuickControl::timerEvent(event);
1251 if (event->timerId() == d->holdTimer) {
1252 d->stopPressAndHold();
1254 emit pressAndHold();
1255 }
else if (event->timerId() == d->delayTimer) {
1256 d->startPressRepeat();
1257 }
else if (event->timerId() == d->repeatTimer) {
1261 }
else if (event->timerId() == d->animateTimer) {
1262 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1263 if (setFocusOnRelease && focusPolicy() & Qt::ClickFocus)
1264 forceActiveFocus(Qt::MouseFocusReason);
1265 d->handleRelease(QPointF(d->width / 2, d->height / 2), 0);
1266 killTimer(d->animateTimer);
1267 d->animateTimer = 0;