99void QQuickAbstractButtonPrivate::init()
101 Q_Q(QQuickAbstractButton);
102 q->setActiveFocusOnTab(
true);
104 q->setFocusPolicy(Qt::TabFocus);
106 q->setFocusPolicy(Qt::StrongFocus);
108 q->setAcceptedMouseButtons(Qt::LeftButton);
109#if QT_CONFIG(quicktemplates2_multitouch)
110 q->setAcceptTouchEvents(
true);
113 q->setCursor(Qt::ArrowCursor);
115 setSizePolicy(QLayoutPolicy::Preferred, QLayoutPolicy::Fixed);
141bool QQuickAbstractButtonPrivate::handlePress(
const QPointF &point, ulong timestamp)
143 Q_Q(QQuickAbstractButton);
146 QQuickControlPrivate::handlePress(point, timestamp);
147 setPressPoint(point);
154 else if (touchId != -1 || Qt::LeftButton == (pressButtons & Qt::LeftButton))
161 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(q,
false);
166bool QQuickAbstractButtonPrivate::handleMove(
const QPointF &point, ulong timestamp)
168 Q_Q(QQuickAbstractButton);
169 QQuickControlPrivate::handleMove(point, timestamp);
171 q->setPressed(keepPressed || q->contains(point));
173 if (!pressed && autoRepeat)
175 else if (holdTimer > 0 && (!pressed || QLineF(pressPoint, point).length() > QGuiApplication::styleHints()->startDragDistance()))
180bool QQuickAbstractButtonPrivate::handleRelease(
const QPointF &point, ulong timestamp)
182 Q_Q(QQuickAbstractButton);
184 const int pressTouchId = touchId;
186 QQuickControlPrivate::handleRelease(point, timestamp);
187 bool wasPressed = pressed;
188 setPressPoint(point);
189 q->setPressed(
false);
190 pressButtons = Qt::NoButton;
192 const bool touchDoubleClick = pressTouchId != -1 && lastTouchReleaseTimestamp != 0
193 && QQuickDeliveryAgentPrivate::isWithinDoubleClickInterval(timestamp - lastTouchReleaseTimestamp)
194 && isDoubleClickConnected();
196 if (!wasHeld && (keepPressed || q->contains(point)))
200 if (wasHeld && pressTouchId != -1) {
203 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(q,
false);
207 if (!wasHeld && !wasDoubleClick)
208 trigger(touchDoubleClick);
218 if (!touchDoubleClick) {
221 if (pressTouchId != -1) {
225 lastTouchReleaseTimestamp = timestamp;
230 lastTouchReleaseTimestamp = 0;
233 wasDoubleClick =
false;
369void QQuickAbstractButtonPrivate::updateEffectiveIcon()
371 Q_Q(QQuickAbstractButton);
376 QQuickIcon newEffectiveIcon = action ? icon.resolve(action->icon()) : icon;
378 bool unchanged = newEffectiveIcon == effectiveIcon;
388 const bool actionIconColorResolved = QQuickIconPrivate::isResolved(action->icon(),
389 QQuickIconPrivate::ColorResolved);
390 const bool iconColorResolved = QQuickIconPrivate::isResolved(icon,
391 QQuickIconPrivate::ColorResolved);
393 unchanged = newEffectiveIcon == effectiveIcon;
397 if (unchanged && !iconColorResolved && actionIconColorResolved)
401 if (actionIconColorResolved)
402 newEffectiveIcon.resolveColor();
407 effectiveIcon = newEffectiveIcon;
412 if (action && !QQuickIconPrivate::isResolved(effectiveIcon, QQuickIconPrivate::ColorResolved)) {
414 if (QQuickIconPrivate::isResolved(action->icon(), QQuickIconPrivate::ColorResolved)) {
417 effectiveIcon.resolveColor();
421 emit q->iconChanged();
465void QQuickAbstractButtonPrivate::executeIndicator(
bool complete)
467 Q_Q(QQuickAbstractButton);
468 if (indicator.wasExecuted())
471 if (!indicator || complete)
472 quickBeginDeferred(q, indicatorName(), indicator);
474 quickCompleteDeferred(q, indicatorName(), indicator);
527QList<QQuickAbstractButton *> QQuickAbstractButtonPrivate::findExclusiveButtons()
const
529 QList<QQuickAbstractButton *> buttons;
531 QQmlListProperty<QQuickAbstractButton> groupButtons = group->buttons();
532 int count = groupButtons.count(&groupButtons);
533 for (
int i = 0; i < count; ++i) {
534 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(groupButtons.at(&groupButtons, i));
538 }
else if (parentItem) {
539 const auto childItems = parentItem->childItems();
540 for (QQuickItem *child : childItems) {
541 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(child);
542 if (button && button->autoExclusive() && !QQuickAbstractButtonPrivate::get(button)->group)
816void QQuickAbstractButton::setIndicator(QQuickItem *indicator)
818 Q_D(QQuickAbstractButton);
819 if (d->indicator == indicator)
822 QQuickControlPrivate::warnIfCustomizationNotSupported(
this, indicator, QStringLiteral(
"indicator"));
824 if (!d->indicator.isExecuting())
825 d->cancelIndicator();
827 const qreal oldImplicitIndicatorWidth = implicitIndicatorWidth();
828 const qreal oldImplicitIndicatorHeight = implicitIndicatorHeight();
830 d->removeImplicitSizeListener(d->indicator);
831 QQuickControlPrivate::hideOldItem(d->indicator);
832 d->indicator = indicator;
835 if (!indicator->parentItem())
836 indicator->setParentItem(
this);
837 indicator->setAcceptedMouseButtons(Qt::LeftButton);
838 d->addImplicitSizeListener(indicator);
841 if (!qFuzzyCompare(oldImplicitIndicatorWidth, implicitIndicatorWidth()))
842 emit implicitIndicatorWidthChanged();
843 if (!qFuzzyCompare(oldImplicitIndicatorHeight, implicitIndicatorHeight()))
844 emit implicitIndicatorHeightChanged();
845 if (!d->indicator.isExecuting())
846 emit indicatorChanged();
933void QQuickAbstractButton::setAction(QQuickAction *action)
935 Q_D(QQuickAbstractButton);
936 if (d->action == action)
939 const QString oldText = text();
941 if (QQuickAction *oldAction = d->action.data()) {
942 QQuickActionPrivate::get(oldAction)->unregisterItem(
this);
943 QObjectPrivate::disconnect(oldAction, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
944 QObjectPrivate::disconnect(oldAction, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
946 QObjectPrivate::disconnect(oldAction, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
947 disconnect(oldAction, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
948 disconnect(oldAction, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
949 disconnect(oldAction, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
953 QQuickActionPrivate::get(action)->registerItem(
this);
954 QObjectPrivate::connect(action, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
955 QObjectPrivate::connect(action, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
957 QObjectPrivate::connect(action, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
958 connect(action, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
959 connect(action, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
960 connect(action, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
962 setChecked(action->isChecked());
963 setCheckable(action->isCheckable());
964 setEnabled(action->isEnabled());
967#if QT_CONFIG(accessibility)
968 auto attached = qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(
this,
true));
970 attached->setProxying(qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(action,
true)));
975 if (oldText != text())
976 buttonChange(ButtonTextChange);
978 d->updateEffectiveIcon();
980 emit actionChanged();
1315void QQuickAbstractButton::timerEvent(QTimerEvent *event)
1317 Q_D(QQuickAbstractButton);
1318 QQuickControl::timerEvent(event);
1319 if (event->timerId() == d->holdTimer) {
1320 d->stopPressAndHold();
1322 emit pressAndHold();
1323 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(
this,
true);
1324 }
else if (event->timerId() == d->delayTimer) {
1325 d->startPressRepeat();
1326 }
else if (event->timerId() == d->repeatTimer) {
1330 }
else if (event->timerId() == d->animateTimer) {
1331 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1332 if (setFocusOnRelease && focusPolicy() & Qt::ClickFocus)
1333 forceActiveFocus(Qt::MouseFocusReason);
1334 d->handleRelease(QPointF(d->width / 2, d->height / 2), 0);
1335 killTimer(d->animateTimer);
1336 d->animateTimer = 0;