aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-11-29 12:57:53 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2016-12-02 12:18:20 +0000
commit0a37852dd814159d901791b9ea7f59a6dd21837c (patch)
tree861d676751013ac0427467840fafb6e9556e9241 /src
parent15fab6e8f81c7fd643f7c4e6a7979a2f66ec4060 (diff)
Add AbstractButton::toggled() signal
[ChangeLog][Controls][AbstractButton] Added a toggled() signal that is emitted whenever a checkable button is interactively toggled by the user by using either touch, mouse, or keys. Task-number: QTBUG-57203 Change-Id: If0b0d71d19cbed00f04d8a4309894a055c4254c6 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/imports/templates/qtquicktemplates2plugin.cpp1
-rw-r--r--src/quicktemplates2/qquickabstractbutton.cpp18
-rw-r--r--src/quicktemplates2/qquickabstractbutton_p.h1
-rw-r--r--src/quicktemplates2/qquickabstractbutton_p_p.h2
-rw-r--r--src/quicktemplates2/qquickswitch.cpp2
-rw-r--r--src/quicktemplates2/qquickswitchdelegate.cpp2
6 files changed, 23 insertions, 3 deletions
diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp
index ef6787f4..203cba30 100644
--- a/src/imports/templates/qtquicktemplates2plugin.cpp
+++ b/src/imports/templates/qtquicktemplates2plugin.cpp
@@ -223,6 +223,7 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri)
qmlRegisterType<QQuickTumbler, 1>(uri, 2, 1, "Tumbler");
// QtQuick.Templates 2.2 (new types and revisions in Qt 5.9)
+ qmlRegisterRevision<QQuickAbstractButton, 2>(uri, 2, 2);
qmlRegisterType<QQuickComboBox, 2>(uri, 2, 2, "ComboBox");
qmlRegisterType<QQuickDial, 2>(uri, 2, 2, "Dial");
qmlRegisterType<QQuickDrawer, 2>(uri, 2, 2, "Drawer");
diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp
index ffd8efa2..1724ead1 100644
--- a/src/quicktemplates2/qquickabstractbutton.cpp
+++ b/src/quicktemplates2/qquickabstractbutton.cpp
@@ -93,6 +93,13 @@ static const int AUTO_REPEAT_INTERVAL = 100;
*/
/*!
+ \since QtQuick.Controls 2.2
+ \qmlsignal QtQuick.Controls::AbstractButton::toggled()
+
+ This signal is emitted when a checkable button is interactively toggled by the user.
+*/
+
+/*!
\qmlsignal QtQuick.Controls::AbstractButton::pressAndHold()
This signal is emitted when the button is interactively pressed and held down by the user.
@@ -162,6 +169,15 @@ void QQuickAbstractButtonPrivate::stopPressRepeat()
}
}
+void QQuickAbstractButtonPrivate::toggle(bool value)
+{
+ Q_Q(QQuickAbstractButton);
+ const bool wasChecked = checked;
+ q->setChecked(value);
+ if (wasChecked != checked)
+ emit q->toggled();
+}
+
QQuickAbstractButton *QQuickAbstractButtonPrivate::findCheckedButton() const
{
Q_Q(const QQuickAbstractButton);
@@ -621,7 +637,7 @@ void QQuickAbstractButton::nextCheckState()
{
Q_D(QQuickAbstractButton);
if (d->checkable && (!d->checked || d->findCheckedButton() != this))
- setChecked(!d->checked);
+ d->toggle(!d->checked);
}
void QQuickAbstractButton::checkableChange()
diff --git a/src/quicktemplates2/qquickabstractbutton_p.h b/src/quicktemplates2/qquickabstractbutton_p.h
index 524dd130..00378bce 100644
--- a/src/quicktemplates2/qquickabstractbutton_p.h
+++ b/src/quicktemplates2/qquickabstractbutton_p.h
@@ -102,6 +102,7 @@ Q_SIGNALS:
void released();
void canceled();
void clicked();
+ Q_REVISION(2) void toggled();
void pressAndHold();
void doubleClicked();
void textChanged();
diff --git a/src/quicktemplates2/qquickabstractbutton_p_p.h b/src/quicktemplates2/qquickabstractbutton_p_p.h
index 688ad804..aa9d98d5 100644
--- a/src/quicktemplates2/qquickabstractbutton_p_p.h
+++ b/src/quicktemplates2/qquickabstractbutton_p_p.h
@@ -78,6 +78,8 @@ public:
QQuickAbstractButton *findCheckedButton() const;
QList<QQuickAbstractButton *> findExclusiveButtons() const;
+ void toggle(bool value);
+
QString text;
bool down;
bool explicitDown;
diff --git a/src/quicktemplates2/qquickswitch.cpp b/src/quicktemplates2/qquickswitch.cpp
index fa08a1d8..b967fe56 100644
--- a/src/quicktemplates2/qquickswitch.cpp
+++ b/src/quicktemplates2/qquickswitch.cpp
@@ -187,7 +187,7 @@ void QQuickSwitch::nextCheckState()
{
Q_D(QQuickSwitch);
if (keepMouseGrab())
- setChecked(d->position > 0.5);
+ d->toggle(d->position > 0.5);
else
QQuickAbstractButton::nextCheckState();
}
diff --git a/src/quicktemplates2/qquickswitchdelegate.cpp b/src/quicktemplates2/qquickswitchdelegate.cpp
index 81e282d9..4c0b430f 100644
--- a/src/quicktemplates2/qquickswitchdelegate.cpp
+++ b/src/quicktemplates2/qquickswitchdelegate.cpp
@@ -192,7 +192,7 @@ void QQuickSwitchDelegate::nextCheckState()
{
Q_D(QQuickSwitchDelegate);
if (keepMouseGrab())
- setChecked(d->position > 0.5);
+ d->toggle(d->position > 0.5);
else
QQuickItemDelegate::nextCheckState();
}