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();
468void QQuickAbstractButtonPrivate::executeIndicator(
bool complete)
470 Q_Q(QQuickAbstractButton);
471 if (indicator.wasExecuted())
474 if (!indicator || complete)
475 quickBeginDeferred(q, indicatorName(), indicator);
477 quickCompleteDeferred(q, indicatorName(), indicator);
530QList<QQuickAbstractButton *> QQuickAbstractButtonPrivate::findExclusiveButtons()
const
532 QList<QQuickAbstractButton *> buttons;
534 QQmlListProperty<QQuickAbstractButton> groupButtons = group->buttons();
535 int count = groupButtons.count(&groupButtons);
536 for (
int i = 0; i < count; ++i) {
537 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(groupButtons.at(&groupButtons, i));
541 }
else if (parentItem) {
542 const auto childItems = parentItem->childItems();
543 for (QQuickItem *child : childItems) {
544 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(child);
545 if (button && button->autoExclusive() && !QQuickAbstractButtonPrivate::get(button)->group)
819void QQuickAbstractButton::setIndicator(QQuickItem *indicator)
821 Q_D(QQuickAbstractButton);
822 if (d->indicator == indicator)
825 QQuickControlPrivate::warnIfCustomizationNotSupported(
this, indicator, QStringLiteral(
"indicator"));
827 if (!d->indicator.isExecuting())
828 d->cancelIndicator();
830 const qreal oldImplicitIndicatorWidth = implicitIndicatorWidth();
831 const qreal oldImplicitIndicatorHeight = implicitIndicatorHeight();
833 d->removeImplicitSizeListener(d->indicator);
834 QQuickControlPrivate::hideOldItem(d->indicator);
835 d->indicator = indicator;
838 if (!indicator->parentItem())
839 indicator->setParentItem(
this);
840 indicator->setAcceptedMouseButtons(Qt::LeftButton);
841 d->addImplicitSizeListener(indicator);
844 if (!qFuzzyCompare(oldImplicitIndicatorWidth, implicitIndicatorWidth()))
845 emit implicitIndicatorWidthChanged();
846 if (!qFuzzyCompare(oldImplicitIndicatorHeight, implicitIndicatorHeight()))
847 emit implicitIndicatorHeightChanged();
848 if (!d->indicator.isExecuting())
849 emit indicatorChanged();
936void QQuickAbstractButton::setAction(QQuickAction *action)
938 Q_D(QQuickAbstractButton);
939 qCDebug(lcAction) <<
this <<
"setAction called with" << action;
940 if (d->action == action)
943 const QString oldText = text();
945 if (QQuickAction *oldAction = d->action.data()) {
946 QQuickActionPrivate::get(oldAction)->unregisterItem(
this);
947 QObjectPrivate::disconnect(oldAction, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
948 QObjectPrivate::disconnect(oldAction, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
950 QObjectPrivate::disconnect(oldAction, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
951 disconnect(oldAction, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
952 disconnect(oldAction, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
953 disconnect(oldAction, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
957 QQuickActionPrivate::get(action)->registerItem(
this);
958 QObjectPrivate::connect(action, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
959 QObjectPrivate::connect(action, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
961 QObjectPrivate::connect(action, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
962 connect(action, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
963 connect(action, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
964 connect(action, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
966 setChecked(action->isChecked());
967 setCheckable(action->isCheckable());
968 setEnabled(action->isEnabled());
971#if QT_CONFIG(accessibility)
972 auto attached = qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(
this,
true));
974 attached->setProxying(qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(action,
true)));
979 if (oldText != text())
980 buttonChange(ButtonTextChange);
982 d->updateEffectiveIcon();
984 emit actionChanged();
1319void QQuickAbstractButton::timerEvent(QTimerEvent *event)
1321 Q_D(QQuickAbstractButton);
1322 QQuickControl::timerEvent(event);
1323 if (event->timerId() == d->holdTimer) {
1324 d->stopPressAndHold();
1326 emit pressAndHold();
1327 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(
this,
true);
1328 }
else if (event->timerId() == d->delayTimer) {
1329 d->startPressRepeat();
1330 }
else if (event->timerId() == d->repeatTimer) {
1334 }
else if (event->timerId() == d->animateTimer) {
1335 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1336 if (setFocusOnRelease && focusPolicy() & Qt::ClickFocus)
1337 forceActiveFocus(Qt::MouseFocusReason);
1338 d->handleRelease(QPointF(d->width / 2, d->height / 2), 0);
1339 killTimer(d->animateTimer);
1340 d->animateTimer = 0;