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();
536QList<QQuickAbstractButton *> QQuickAbstractButtonPrivate::findExclusiveButtons()
const
538 QList<QQuickAbstractButton *> buttons;
540 QQmlListProperty<QQuickAbstractButton> groupButtons = group->buttons();
541 int count = groupButtons.count(&groupButtons);
542 for (
int i = 0; i < count; ++i) {
543 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(groupButtons.at(&groupButtons, i));
547 }
else if (parentItem) {
548 const auto childItems = parentItem->childItems();
549 for (QQuickItem *child : childItems) {
550 QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton *>(child);
551 if (button && button->autoExclusive() && !QQuickAbstractButtonPrivate::get(button)->group)
825void QQuickAbstractButton::setIndicator(QQuickItem *indicator)
827 Q_D(QQuickAbstractButton);
828 if (d->indicator == indicator)
831 QQuickControlPrivate::warnIfCustomizationNotSupported(
this, indicator, QStringLiteral(
"indicator"));
833 if (!d->indicator.isExecuting())
834 d->cancelIndicator();
836 const qreal oldImplicitIndicatorWidth = implicitIndicatorWidth();
837 const qreal oldImplicitIndicatorHeight = implicitIndicatorHeight();
839 d->removeImplicitSizeListener(d->indicator);
840 QQuickControlPrivate::hideOldItem(d->indicator);
841 d->indicator = indicator;
844 if (!indicator->parentItem())
845 indicator->setParentItem(
this);
846 indicator->setAcceptedMouseButtons(Qt::LeftButton);
847 d->addImplicitSizeListener(indicator);
850 if (!qFuzzyCompare(oldImplicitIndicatorWidth, implicitIndicatorWidth()))
851 emit implicitIndicatorWidthChanged();
852 if (!qFuzzyCompare(oldImplicitIndicatorHeight, implicitIndicatorHeight()))
853 emit implicitIndicatorHeightChanged();
854 if (!d->indicator.isExecuting())
855 emit indicatorChanged();
942void QQuickAbstractButton::setAction(QQuickAction *action)
944 Q_D(QQuickAbstractButton);
945 qCDebug(lcButtonAction) <<
this <<
"setAction called with" << action;
946 if (d->action == action)
949 const QString oldText = text();
951 if (QQuickAction *oldAction = d->action.data()) {
952 QQuickActionPrivate::get(oldAction)->unregisterItem(
this);
953 QObjectPrivate::disconnect(oldAction, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
954 QObjectPrivate::disconnect(oldAction, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
956 QObjectPrivate::disconnect(oldAction, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
957 disconnect(oldAction, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
958 disconnect(oldAction, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
959 disconnect(oldAction, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
963 QQuickActionPrivate::get(action)->registerItem(
this);
964 QObjectPrivate::connect(action, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click);
965 QObjectPrivate::connect(action, &QQuickAction::textChanged, d, &QQuickAbstractButtonPrivate::actionTextChange);
967 QObjectPrivate::connect(action, &QQuickAction::iconChanged, d, &QQuickAbstractButtonPrivate::updateEffectiveIcon);
968 connect(action, &QQuickAction::checkedChanged,
this, &QQuickAbstractButton::setChecked);
969 connect(action, &QQuickAction::checkableChanged,
this, &QQuickAbstractButton::setCheckable);
970 connect(action, &QQuickAction::enabledChanged,
this, &QQuickItem::setEnabled);
972 setChecked(action->isChecked());
973 setCheckable(action->isCheckable());
974 setEnabled(action->isEnabled());
977#if QT_CONFIG(accessibility)
978 auto attached = qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(
this,
true));
980 attached->setProxying(qobject_cast<QQuickAccessibleAttached*>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(action,
true)));
985 if (oldText != text())
986 buttonChange(ButtonTextChange);
988 d->updateEffectiveIcon();
990 emit actionChanged();
1325void QQuickAbstractButton::timerEvent(QTimerEvent *event)
1327 Q_D(QQuickAbstractButton);
1328 QQuickControl::timerEvent(event);
1329 if (event->timerId() == d->holdTimer) {
1330 d->stopPressAndHold();
1332 emit pressAndHold();
1333 QQuickToolTipAttachedPrivate::maybeSetVisibleImplicitly(
this,
true);
1334 }
else if (event->timerId() == d->delayTimer) {
1335 d->startPressRepeat();
1336 }
else if (event->timerId() == d->repeatTimer) {
1340 }
else if (event->timerId() == d->animateTimer) {
1341 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1342 if (setFocusOnRelease && focusPolicy() & Qt::ClickFocus)
1343 forceActiveFocus(Qt::MouseFocusReason);
1344 d->handleRelease(QPointF(d->width / 2, d->height / 2), 0);
1345 killTimer(d->animateTimer);
1346 d->animateTimer = 0;