Add QQuickAbstractButton::down

This property will determine whether or not the button is visually
pressed. Having such a distinction allows users more control over their
controls.

The patch also fixes the problem with ComboBox where pressing on the
ComboBox when it's open would cause a delegate in the popup to show as
being pressed.

Unless explicitly set, this property follows the value of the pressed
property. To return to the default value, set it to undefined.

Change-Id: I29ecf325ed2ede125613f0c878b0427937599866
Task-number: QTBUG-51005
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
This commit is contained in:
Mitch Curtis 2016-04-12 16:19:58 +02:00 committed by J-P Nurmi
parent 0fe0283308
commit eae24fccc5
46 changed files with 192 additions and 97 deletions

View File

@ -55,7 +55,7 @@ T.Button {
text: control.text
font: control.font
opacity: enabled || highlighted ? 1 : 0.3
color: control.checked || control.highlighted ? "#ffffff" : (control.activeKeyFocus ? "#0066ff" : (control.pressed ? "#26282a" : "#353637"))
color: control.checked || control.highlighted ? "#ffffff" : (control.activeKeyFocus ? "#0066ff" : (control.down ? "#26282a" : "#353637"))
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
@ -68,9 +68,9 @@ T.Button {
implicitHeight: 40
opacity: enabled ? 1 : (control.checked ? 0.2 : 0.3)
color: control.checked || control.highlighted ?
(control.activeKeyFocus ? (control.pressed ? "#599bff" : "#0066ff") : (control.pressed ? "#585a5c" : "#353637")) :
(control.activeKeyFocus ? (control.pressed ? "#cce0ff" : "#f0f6ff") : (control.pressed ? "#d6d6d6" : "#f6f6f6"))
border.color: control.activeKeyFocus ? "#0066ff" : (control.pressed ? "#26282a" : "#353637")
(control.activeKeyFocus ? (control.down ? "#599bff" : "#0066ff") : (control.down ? "#585a5c" : "#353637")) :
(control.activeKeyFocus ? (control.down ? "#cce0ff" : "#f0f6ff") : (control.down ? "#d6d6d6" : "#f6f6f6"))
border.color: control.activeKeyFocus ? "#0066ff" : (control.down ? "#26282a" : "#353637")
border.width: control.checked || control.highlighted ? 0 : (control.activeKeyFocus ? 2 : 1)
}
//! [background]

View File

@ -67,7 +67,7 @@ T.CheckBox {
text: control.text
font: control.font
color: control.pressed ? "#26282a" : "#353637"
color: control.down ? "#26282a" : "#353637"
elide: Text.ElideRight
visible: control.text
horizontalAlignment: Text.AlignLeft

View File

@ -79,8 +79,8 @@ T.CheckDelegate {
background: Rectangle {
implicitWidth: 100
implicitHeight: 40
visible: control.pressed || control.highlighted
color: control.pressed ? "#bdbebf" : "#eeeeee"
visible: control.down || control.highlighted
color: control.down ? "#bdbebf" : "#eeeeee"
}
//! [background]
}

View File

@ -44,9 +44,9 @@ Rectangle {
implicitWidth: 28
implicitHeight: 28
color: control.enabled ? (control.pressed ? (control.activeFocus ? "#cce0ff" : "#e4e4e4") : "#f6f6f6") : "#353637"
color: control.enabled ? (control.down ? (control.activeFocus ? "#cce0ff" : "#e4e4e4") : "#f6f6f6") : "#353637"
border.width: control.activeFocus ? 2 : 1
border.color: control.enabled ? (control.activeFocus ? "#0066ff" : (control.pressed ? "#26282a" : "#353637")) : "transparent"
border.color: control.enabled ? (control.activeFocus ? "#0066ff" : (control.down ? "#26282a" : "#353637")) : "transparent"
Image {
x: (parent.width - width) / 2

View File

@ -60,7 +60,7 @@ T.ComboBox {
autoExclusive: true
checked: control.currentIndex === index
highlighted: control.highlightedIndex === index
pressed: highlighted && control.pressed
down: highlighted && control.down
}
//! [delegate]
@ -85,7 +85,7 @@ T.ComboBox {
width: parent.width
height: parent.height
opacity: control.enabled ? 1.0 : 0.2
color: control.pressed || popup.visible ? "#585A5C" : "#353637"
color: control.down || popup.visible ? "#585A5C" : "#353637"
}
Image {

View File

@ -69,8 +69,8 @@ T.ItemDelegate {
background: Rectangle {
implicitWidth: 100
implicitHeight: 40
visible: control.pressed || control.highlighted
color: control.pressed ? "#bdbebf" : "#eeeeee"
visible: control.down || control.highlighted
color: control.down ? "#bdbebf" : "#eeeeee"
}
//! [background]
}

View File

@ -84,7 +84,7 @@ T.MenuItem {
y: 1
width: parent.width - 2
height: parent.height - 2
color: control.activeKeyFocus || control.pressed ? "#eeeeee" : "transparent"
color: control.activeKeyFocus || control.down ? "#eeeeee" : "transparent"
}
}
//! [background]

View File

@ -67,7 +67,7 @@ T.RadioButton {
text: control.text
font: control.font
color: control.pressed ? "#26282a" : "#353637"
color: control.down ? "#26282a" : "#353637"
elide: Text.ElideRight
visible: control.text
horizontalAlignment: Text.AlignLeft

View File

@ -78,8 +78,8 @@ T.RadioDelegate {
background: Rectangle {
implicitWidth: 100
implicitHeight: 40
visible: control.pressed || control.highlighted
color: control.pressed ? "#bdbebf" : "#eeeeee"
visible: control.down || control.highlighted
color: control.down ? "#bdbebf" : "#eeeeee"
}
//! [background]
}

View File

@ -41,9 +41,9 @@ Rectangle {
implicitHeight: 28
radius: width / 2
color: control.pressed ? (control.activeFocus ? "#cce0ff" : "#e4e4e4") : "#f6f6f6"
color: control.down ? (control.activeFocus ? "#cce0ff" : "#e4e4e4") : "#f6f6f6"
border.width: control.activeFocus ? 2 : 1
border.color: control.activeFocus ? "#0066ff" : (control.pressed ? "#26282a" : "#353637")
border.color: control.activeFocus ? "#0066ff" : (control.down ? "#26282a" : "#353637")
property Item control

View File

@ -64,7 +64,7 @@ T.SwipeDelegate {
verticalAlignment: Text.AlignVCenter
Behavior on x {
enabled: !control.pressed
enabled: !control.down
NumberAnimation {
easing.type: Easing.InOutCubic
duration: 400
@ -75,10 +75,10 @@ T.SwipeDelegate {
//! [background]
background: Rectangle {
color: control.pressed ? "#bdbebf" : "#eeeeee"
color: control.down ? "#bdbebf" : "#eeeeee"
Behavior on x {
enabled: !control.pressed
enabled: !control.down
NumberAnimation {
easing.type: Easing.InOutCubic
duration: 400

View File

@ -54,7 +54,7 @@ T.TabButton {
font: control.font
elide: Text.ElideRight
opacity: enabled ? 1 : 0.3
color: !control.checked ? "#ffffff" : control.pressed ? "#26282a" : "#353637"
color: !control.checked ? "#ffffff" : control.down ? "#26282a" : "#353637"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
@ -63,7 +63,7 @@ T.TabButton {
//! [background]
background: Rectangle {
implicitHeight: 40
color: control.pressed ? (control.checked ? "#e4e4e4" : "#585a5c") : (control.checked ? "transparent" : "#353637")
color: control.down ? (control.checked ? "#e4e4e4" : "#585a5c") : (control.checked ? "transparent" : "#353637")
}
//! [background]
}

View File

@ -65,8 +65,8 @@ T.ToolButton {
implicitHeight: 40
color: Qt.darker("#33333333", control.enabled && (control.checked || control.highlighted) ? 1.5 : 1.0)
opacity: control.pressed ? 1.0 : control.enabled && (control.checked || control.highlighted) ? 0.5 : 0
visible: control.pressed || (control.enabled && (control.checked || control.highlighted))
opacity: control.down ? 1.0 : control.enabled && (control.checked || control.highlighted) ? 0.5 : 0
visible: control.down || (control.enabled && (control.checked || control.highlighted))
}
//! [background]
}

View File

@ -31,5 +31,5 @@ import Qt.labs.controls 1.0
Button {
width: 80
text: "Pressed"
pressed: true
down: true
}

View File

@ -36,7 +36,7 @@ Item {
property Button button: children[0]
Binding { target: button; property: "pressed"; value: root.Window.active }
Binding { target: button; property: "down"; value: root.Window.active }
Binding { target: button.anchors; property: "bottom"; value: root.bottom }
Binding { target: button.anchors; property: "horizontalCenter"; value: root.horizontalCenter }

View File

@ -76,7 +76,7 @@ T.Button {
height: parent.height - 12
radius: 2
color: !control.enabled ? (control.highlighted ? control.Material.raisedHighlightedButtonDisabledColor : control.Material.raisedButtonDisabledColor) :
(control.pressed ? (control.highlighted ? control.Material.raisedHighlightedButtonPressColor : control.Material.raisedButtonPressColor) :
(control.down ? (control.highlighted ? control.Material.raisedHighlightedButtonPressColor : control.Material.raisedButtonPressColor) :
(control.activeKeyFocus ? (control.highlighted ? control.Material.raisedHighlightedButtonHoverColor : control.Material.raisedButtonHoverColor) :
(control.highlighted ? control.Material.raisedHighlightedButtonColor : control.Material.raisedButtonColor)))
@ -98,7 +98,7 @@ T.Button {
layer.effect: DropShadow {
verticalOffset: 1
color: control.Material.dropShadowColor
samples: control.pressed ? 15 : 9
samples: control.down ? 15 : 9
spread: 0.5
}
}

View File

@ -77,8 +77,8 @@ T.CheckDelegate {
//! [background]
background: Rectangle {
visible: control.pressed || control.highlighted
color: control.pressed ? control.Material.flatButtonPressColor : control.Material.listHighlightColor
visible: control.down || control.highlighted
color: control.down ? control.Material.flatButtonPressColor : control.Material.listHighlightColor
}
//! [background]
}

View File

@ -68,7 +68,7 @@ Rectangle {
height: width
control: control
colored: control.checked
opacity: control.pressed ? 1 : 0
opacity: control.down ? 1 : 0
}
// TODO: This needs to be transparent

View File

@ -58,7 +58,7 @@ T.ComboBox {
width: control.width
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
highlighted: control.highlightedIndex === index
pressed: highlighted && control.pressed
down: highlighted && control.down
}
//! [delegate]
@ -92,7 +92,7 @@ T.ComboBox {
layer.effect: DropShadow {
verticalOffset: 1
color: control.Material.dropShadowColor
samples: control.pressed ? 15 : 9
samples: control.down ? 15 : 9
spread: 0.5
}

View File

@ -68,8 +68,8 @@ T.ItemDelegate {
//! [background]
background: Rectangle {
visible: control.pressed || control.highlighted
color: control.pressed ? control.Material.flatButtonPressColor : control.Material.listHighlightColor
visible: control.down || control.highlighted
color: control.down ? control.Material.flatButtonPressColor : control.Material.listHighlightColor
}
//! [background]
}

View File

@ -79,8 +79,8 @@ T.MenuItem {
//! [background]
background: Rectangle {
implicitWidth: 200
visible: control.pressed || control.highlighted
color: control.pressed ? control.Material.flatButtonPressColor : control.Material.listHighlightColor
visible: control.down || control.highlighted
color: control.down ? control.Material.flatButtonPressColor : control.Material.listHighlightColor
}
//! [background]
}

View File

@ -76,8 +76,8 @@ T.RadioDelegate {
//! [background]
background: Rectangle {
visible: control.pressed || control.highlighted
color: control.pressed ? control.Material.flatButtonPressColor : control.Material.listHighlightColor
visible: control.down || control.highlighted
color: control.down ? control.Material.flatButtonPressColor : control.Material.listHighlightColor
}
//! [background]
}

View File

@ -43,7 +43,7 @@ Rectangle {
implicitHeight: 20
radius: width / 2
border.width: 2
border.color: control.checked || control.pressed ? control.Material.accentColor : control.Material.secondaryTextColor
border.color: control.checked || control.down ? control.Material.accentColor : control.Material.secondaryTextColor
color: "transparent"
property alias control: ripple.control
@ -54,7 +54,7 @@ Rectangle {
height: width
control: control
colored: control.checked
opacity: control.pressed || control.activeFocus ? 1 : 0
opacity: control.down || control.activeFocus ? 1 : 0
}
Rectangle {
@ -64,6 +64,6 @@ Rectangle {
height: 10
radius: width / 2
color: parent.border.color
visible: control.checked || control.pressed
visible: control.checked || control.down
}
}

View File

@ -66,7 +66,7 @@ T.SwipeDelegate {
verticalAlignment: Text.AlignVCenter
Behavior on x {
enabled: !control.pressed
enabled: !control.down
NumberAnimation {
easing.type: Easing.InOutCubic
duration: 400
@ -78,11 +78,11 @@ T.SwipeDelegate {
//! [background]
background: Rectangle {
color: !control.enabled ? control.Material.swipeDelegateDisabledColor :
(control.pressed ? control.Material.swipeDelegatePressColor :
(control.down ? control.Material.swipeDelegatePressColor :
(control.activeKeyFocus || control.hovered ? control.Material.swipeDelegateHoverColor : control.Material.swipeDelegateColor))
Behavior on x {
enabled: !control.pressed
enabled: !control.down
NumberAnimation {
easing.type: Easing.InOutCubic
duration: 400

View File

@ -54,7 +54,7 @@ T.TabButton {
text: control.text
font: control.font
elide: Text.ElideRight
color: !control.enabled ? control.Material.hintTextColor : control.pressed || control.checked ? control.Material.accentColor : control.Material.primaryTextColor
color: !control.enabled ? control.Material.hintTextColor : control.down || control.checked ? control.Material.accentColor : control.Material.primaryTextColor
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}

View File

@ -65,8 +65,8 @@ T.ToolButton {
implicitWidth: 48
implicitHeight: 48
color: control.pressed ? control.Material.flatButtonPressColor : control.Material.flatButtonFocusColor
visible: control.enabled && (control.pressed || control.activeKeyFocus || control.checked || control.highlighted)
color: control.down ? control.Material.flatButtonPressColor : control.Material.flatButtonFocusColor
visible: control.enabled && (control.down || control.activeKeyFocus || control.checked || control.highlighted)
}
//! [background]
}

View File

@ -71,7 +71,7 @@ T.Button {
implicitWidth: 32
implicitHeight: 32
color: control.pressed ? control.Universal.baseMediumLowColor :
color: control.down ? control.Universal.baseMediumLowColor :
control.enabled && (control.highlighted || control.checked) ? control.Universal.accent :
control.Universal.baseLowColor
}

View File

@ -81,8 +81,8 @@ T.CheckDelegate {
//! [background]
background: Rectangle {
visible: control.pressed || control.highlighted || control.activeFocus
color: control.pressed ? control.Universal.listMediumColor : control.Universal.altMediumLowColor
visible: control.down || control.highlighted || control.activeFocus
color: control.down ? control.Universal.listMediumColor : control.Universal.altMediumLowColor
Rectangle {
width: parent.width
height: parent.height

View File

@ -43,10 +43,10 @@ Rectangle {
implicitHeight: 20
color: !control.enabled ? "transparent" :
control.pressed && control.checkState !== Qt.PartiallyChecked ? control.Universal.baseMediumColor :
control.down && control.checkState !== Qt.PartiallyChecked ? control.Universal.baseMediumColor :
control.checkState === Qt.Checked ? control.Universal.accent : "transparent"
border.color: !control.enabled ? control.Universal.baseLowColor :
control.pressed ? control.Universal.baseMediumColor :
control.down ? control.Universal.baseMediumColor :
control.checked ? control.Universal.accent : control.Universal.baseMediumHighColor
border.width: 2 // CheckBoxBorderThemeThickness
@ -68,6 +68,6 @@ Rectangle {
visible: control.checkState === Qt.PartiallyChecked
color: !control.enabled ? control.Universal.baseLowColor :
control.pressed ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor
control.down ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor
}
}

View File

@ -60,7 +60,7 @@ T.ComboBox {
width: control.width
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
highlighted: control.highlightedIndex === index
pressed: highlighted && control.pressed
down: highlighted && control.down
}
//! [delegate]
@ -83,9 +83,9 @@ T.ComboBox {
border.width: 2 // ComboBoxBorderThemeThickness
border.color: !control.enabled ? control.Universal.baseLowColor :
control.pressed || popup.visible ? control.Universal.baseMediumLowColor : control.Universal.baseMediumLowColor
control.down || popup.visible ? control.Universal.baseMediumLowColor : control.Universal.baseMediumLowColor
color: !control.enabled ? control.Universal.baseLowColor :
control.pressed || popup.visible ? control.Universal.listMediumColor : control.Universal.altMediumLowColor
control.down || popup.visible ? control.Universal.listMediumColor : control.Universal.altMediumLowColor
Rectangle {
x: 2

View File

@ -67,7 +67,7 @@ T.Dial {
radius: width / 2
color: !control.enabled ? control.Universal.baseLowColor :
control.pressed ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor
control.down ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor
transform: [
Translate {

View File

@ -73,8 +73,8 @@ T.ItemDelegate {
//! [background]
background: Rectangle {
visible: control.pressed || control.highlighted || control.activeKeyFocus
color: control.pressed ? control.Universal.listMediumColor : control.Universal.altMediumLowColor
visible: control.down || control.highlighted || control.activeKeyFocus
color: control.down ? control.Universal.listMediumColor : control.Universal.altMediumLowColor
Rectangle {
width: parent.width
height: parent.height

View File

@ -75,7 +75,7 @@ T.MenuItem {
y: control.topPadding + (control.availableHeight - height) / 2
visible: control.checked
source: !control.checkable ? "" : "image://universal/checkmark/" + (!control.enabled ? control.Universal.baseLowColor : control.pressed ? control.Universal.baseHighColor : control.Universal.baseMediumHighColor)
source: !control.checkable ? "" : "image://universal/checkmark/" + (!control.enabled ? control.Universal.baseLowColor : control.down ? control.Universal.baseHighColor : control.Universal.baseMediumHighColor)
}
//! [indicator]
@ -85,7 +85,7 @@ T.MenuItem {
implicitHeight: 40
color: !control.enabled ? control.Universal.baseLowColor :
control.pressed ? control.Universal.listMediumColor : control.Universal.altMediumLowColor
control.down ? control.Universal.listMediumColor : control.Universal.altMediumLowColor
Rectangle {
x: 1; y: 1

View File

@ -83,8 +83,8 @@ T.RadioDelegate {
//! [background]
background: Rectangle {
visible: control.pressed || control.highlighted || control.activeFocus
color: control.pressed ? control.Universal.listMediumColor : control.Universal.altMediumLowColor
visible: control.down || control.highlighted || control.activeFocus
color: control.down ? control.Universal.listMediumColor : control.Universal.altMediumLowColor
Rectangle {
width: parent.width
height: parent.height

View File

@ -45,7 +45,7 @@ Rectangle {
border.width: 2 // RadioButtonBorderThemeThickness
border.color: control.checked ? "transparent" :
!control.enabled ? control.Universal.baseLowColor :
control.pressed ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor
control.down ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor
property var control
@ -59,7 +59,7 @@ Rectangle {
color: "transparent"
border.width: 2 // RadioButtonBorderThemeThickness
border.color: !control.enabled ? control.Universal.baseLowColor :
control.pressed ? control.Universal.baseMediumColor : control.Universal.accent
control.down ? control.Universal.baseMediumColor : control.Universal.accent
}
Rectangle {
@ -72,6 +72,6 @@ Rectangle {
radius: width / 2
opacity: control.checked ? 1 : 0
color: !control.enabled ? control.Universal.baseLowColor :
control.pressed ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor
control.down ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor
}
}

View File

@ -71,7 +71,7 @@ T.SwipeDelegate {
color: !control.enabled ? control.Universal.baseLowColor : control.Universal.baseHighColor
Behavior on x {
enabled: !control.pressed
enabled: !control.down
NumberAnimation {
easing.type: Easing.InOutCubic
duration: 400
@ -83,7 +83,7 @@ T.SwipeDelegate {
//! [background]
background: Rectangle {
color: !control.enabled ? control.Universal.chromeDisabledHighColor :
(control.pressed ? control.Universal.chromeHighColor :
(control.down ? control.Universal.chromeHighColor :
(control.activeKeyFocus || control.hovered ? control.Universal.chromeLowColor : control.Universal.chromeMediumColor))
Rectangle {
@ -95,7 +95,7 @@ T.SwipeDelegate {
}
Behavior on x {
enabled: !control.pressed
enabled: !control.down
NumberAnimation {
easing.type: Easing.InOutCubic
duration: 400

View File

@ -54,7 +54,7 @@ T.TabButton {
text: control.text
font: control.font
elide: Text.ElideRight
color: control.checked || control.pressed ? control.Universal.baseHighColor : control.Universal.baseLowColor
color: control.checked || control.down ? control.Universal.baseHighColor : control.Universal.baseLowColor
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}

View File

@ -67,7 +67,7 @@ T.ToolButton {
implicitWidth: 68
implicitHeight: 48 // AppBarThemeCompactHeight
color: control.pressed ? control.Universal.listMediumColor :
color: control.down ? control.Universal.listMediumColor :
control.enabled && (control.highlighted || control.checked) ? control.Universal.accent : "transparent"
}
//! [background]

View File

@ -106,7 +106,8 @@ static const int AUTO_REPEAT_INTERVAL = 100;
*/
QQuickAbstractButtonPrivate::QQuickAbstractButtonPrivate() :
pressed(false), checked(false), checkable(false), highlighted(false), autoExclusive(false), autoRepeat(false), wasHeld(false),
down(false), explicitDown(false), pressed(false), checked(false), checkable(false),
highlighted(false), autoExclusive(false), autoRepeat(false), wasHeld(false),
holdTimer(0), delayTimer(0), repeatTimer(0), repeatButton(Qt::NoButton), indicator(nullptr), group(nullptr)
{
}
@ -256,9 +257,51 @@ void QQuickAbstractButton::setText(const QString &text)
}
/*!
\qmlproperty bool Qt.labs.controls::AbstractButton::pressed
\qmlproperty bool Qt.labs.controls::AbstractButton::down
This property holds whether the button is pressed.
This property holds whether the button is visually down.
Unless explicitly set, this property follows the value of \l pressed. To
return to the default value, set this property to \c undefined.
\sa pressed
*/
bool QQuickAbstractButton::isDown() const
{
Q_D(const QQuickAbstractButton);
return d->down;
}
void QQuickAbstractButton::setDown(bool down)
{
Q_D(QQuickAbstractButton);
d->explicitDown = true;
if (d->down == down)
return;
d->down = down;
emit downChanged();
}
void QQuickAbstractButton::resetDown()
{
Q_D(QQuickAbstractButton);
if (!d->explicitDown)
return;
setDown(d->pressed);
d->explicitDown = false;
}
/*!
\qmlproperty bool Qt.labs.controls::AbstractButton::pressed
\readonly
This property holds whether the button is physically pressed. A button can
be pressed by either touch or key events.
\sa down
*/
bool QQuickAbstractButton::isPressed() const
{
@ -275,6 +318,11 @@ void QQuickAbstractButton::setPressed(bool isPressed)
d->pressed = isPressed;
setAccessibleProperty("pressed", isPressed);
emit pressedChanged();
if (!d->explicitDown) {
setDown(d->pressed);
d->explicitDown = false;
}
}
/*!

View File

@ -58,7 +58,8 @@ class Q_QUICKTEMPLATES2_EXPORT QQuickAbstractButton : public QQuickControl
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL)
Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL)
Q_PROPERTY(bool down READ isDown WRITE setDown NOTIFY downChanged RESET resetDown FINAL)
Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL)
Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY checkedChanged FINAL)
Q_PROPERTY(bool highlighted READ isHighlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL)
Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive NOTIFY autoExclusiveChanged FINAL)
@ -72,6 +73,10 @@ public:
QString text() const;
void setText(const QString &text);
bool isDown() const;
void setDown(bool down);
void resetDown();
bool isPressed() const;
void setPressed(bool pressed);
@ -104,6 +109,7 @@ Q_SIGNALS:
void pressAndHold();
void doubleClicked();
void textChanged();
void downChanged();
void pressedChanged();
void checkedChanged();
void highlightedChanged();

View File

@ -79,6 +79,8 @@ public:
QList<QQuickAbstractButton *> findExclusiveButtons() const;
QString text;
bool down;
bool explicitDown;
bool pressed;
bool checked;
bool checkable;

View File

@ -112,6 +112,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
\readonly
\qmlsignal void Qt.labs.controls::ComboBox::highlighted(int index)
This signal is emitted when the item at \a index in the popup list is highlighted by the user.
@ -450,7 +451,6 @@ void QQuickComboBox::setPressed(bool pressed)
}
/*!
\readonly
\qmlproperty int Qt.labs.controls::ComboBox::highlightedIndex
This property holds the index of the highlighted item in the combo box popup list.

View File

@ -57,7 +57,7 @@ TestCase {
property SignalSequenceSpy spy: SignalSequenceSpy {
target: control
signals: ["pressed", "released", "canceled", "clicked", "doubleClicked", "pressedChanged", "checkedChanged"]
signals: ["pressed", "released", "canceled", "clicked", "doubleClicked", "pressedChanged", "downChanged", "checkedChanged"]
}
}
}
@ -80,12 +80,15 @@ TestCase {
verify(control)
// click
control.spy.expectedSequence = [["pressedChanged", { "pressed": true }], "pressed"]
control.spy.expectedSequence = [["pressedChanged", { "pressed": true }],
["downChanged", { "down": true }],
"pressed"]
mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton)
compare(control.pressed, true)
verify(control.spy.success)
control.spy.expectedSequence = [["pressedChanged", { "pressed": false }],
["downChanged", { "down": false }],
"released",
"clicked"]
mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton)
@ -93,12 +96,15 @@ TestCase {
verify(control.spy.success)
// release outside
control.spy.expectedSequence = [["pressedChanged", { "pressed": true }], "pressed"]
control.spy.expectedSequence = [["pressedChanged", { "pressed": true }],
["downChanged", { "down": true }],
"pressed"]
mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton)
compare(control.pressed, true)
verify(control.spy.success)
control.spy.expectedSequence = [["pressedChanged", { "pressed": false }]]
control.spy.expectedSequence = [["pressedChanged", { "pressed": false }],
["downChanged", { "down": false }]]
mouseMove(control, control.width * 2, control.height * 2, 0, Qt.LeftButton)
compare(control.pressed, false)
verify(control.spy.success)
@ -119,14 +125,18 @@ TestCase {
// double click
control.spy.expectedSequence = [["pressedChanged", { "pressed": true }],
["downChanged", { "down": true }],
"pressed",
["pressedChanged", { "pressed": false }],
["downChanged", { "down": false }],
"released",
"clicked",
["pressedChanged", { "pressed": true }],
["downChanged", { "down": true }],
"pressed",
"doubleClicked",
["pressedChanged", { "pressed": false }],
["downChanged", { "down": false }],
"released",
"clicked"]
mouseDoubleClickSequence(control, control.width / 2, control.height / 2, Qt.LeftButton)
@ -144,8 +154,10 @@ TestCase {
// click
control.spy.expectedSequence = [["pressedChanged", { "pressed": true }],
["downChanged", { "down": true }],
"pressed",
["pressedChanged", { "pressed": false }],
["downChanged", { "down": false }],
"released",
"clicked"]
keyClick(Qt.Key_Space)
@ -185,6 +197,7 @@ TestCase {
var repeatCount = 2
var repeatSequence = [["pressedChanged", { "pressed": true }],
["downChanged", { "down": true }],
"pressed",
"released",
"clicked",
@ -201,6 +214,7 @@ TestCase {
verify(control.spy.success)
control.spy.expectedSequence = [["pressedChanged", { "pressed": false }],
["downChanged", { "down": false }],
"released",
"clicked"]
mouseRelease(control)
@ -216,6 +230,7 @@ TestCase {
verify(control.spy.success)
control.spy.expectedSequence = [["pressedChanged", { "pressed": false }],
["downChanged", { "down": false }],
"released",
"clicked"]
keyRelease(Qt.Key_Space)

View File

@ -644,7 +644,7 @@ TestCase {
autoExclusive: true
checked: _combobox.currentIndex === index
highlighted: _combobox.highlightedIndex === index
pressed: highlighted && _combobox.pressed
down: highlighted && _combobox.pressed
}
}
}

View File

@ -55,6 +55,11 @@ TestCase {
signalName: "pressedChanged"
}
SignalSpy {
id: downSpy
signalName: "downChanged"
}
SignalSpy {
id: clickedSpy
signalName: "clicked"
@ -97,47 +102,66 @@ TestCase {
verify(control)
pressedSpy.target = control
downSpy.target = control
clickedSpy.target = control
verify(pressedSpy.valid)
verify(downSpy.valid)
verify(clickedSpy.valid)
// check
mousePress(control, control.width / 2, control.height / 2, Qt.LeftToolButton)
compare(pressedSpy.count, 1)
compare(downSpy.count, 1)
compare(control.pressed, true)
compare(control.down, true)
mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftToolButton)
compare(clickedSpy.count, 1)
compare(pressedSpy.count, 2)
compare(downSpy.count, 2)
compare(control.pressed, false)
compare(control.down, false)
// uncheck
mousePress(control, control.width / 2, control.height / 2, Qt.LeftToolButton)
compare(pressedSpy.count, 3)
compare(downSpy.count, 3)
compare(control.pressed, true)
compare(control.down, true)
mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftToolButton)
compare(clickedSpy.count, 2)
compare(pressedSpy.count, 4)
compare(downSpy.count, 4)
compare(control.pressed, false)
compare(control.down, false)
// release outside
mousePress(control, control.width / 2, control.height / 2, Qt.LeftToolButton)
compare(pressedSpy.count, 5)
compare(downSpy.count, 5)
compare(control.pressed, true)
compare(control.down, true)
mouseMove(control, control.width * 2, control.height * 2, 0, Qt.LeftToolButton)
compare(control.pressed, false)
compare(control.down, false)
mouseRelease(control, control.width * 2, control.height * 2, Qt.LeftToolButton)
compare(clickedSpy.count, 2)
compare(pressedSpy.count, 6)
compare(downSpy.count, 6)
compare(control.pressed, false)
compare(control.down, false)
// right button
mousePress(control, control.width / 2, control.height / 2, Qt.RightButton)
compare(pressedSpy.count, 6)
compare(downSpy.count, 6)
compare(control.pressed, false)
compare(control.down, false)
mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton)
compare(clickedSpy.count, 2)
compare(pressedSpy.count, 6)
compare(downSpy.count, 6)
compare(control.pressed, false)
compare(control.down, false)
control.destroy()
}

View File

@ -96,7 +96,7 @@ ApplicationWindow {
}
ToolButton {
text: "Pressed"
pressed: true
down: true
hoverEnabled: true
ToolTip.text: text
ToolTip.delay: 1000
@ -141,7 +141,7 @@ ApplicationWindow {
}
TabButton {
text: "Pressed"
pressed: true
down: true
}
TabButton {
text: "Disabled"
@ -169,7 +169,7 @@ ApplicationWindow {
}
Button {
text: "Pressed"
pressed: true
down: true
}
Button {
text: "Checked"
@ -178,7 +178,7 @@ ApplicationWindow {
Button {
text: "CH + PR"
checked: true
pressed: true
down: true
}
Button {
text: "Disabled"
@ -201,7 +201,7 @@ ApplicationWindow {
Button {
text: "HI + PR"
highlighted: true
pressed: true
down: true
}
Button {
text: "HI + CH"
@ -211,7 +211,7 @@ ApplicationWindow {
Button {
text: "HI+CH+PR"
highlighted: true
pressed: true
down: true
checked: true
}
Button {
@ -233,7 +233,7 @@ ApplicationWindow {
}
CheckBox {
text: "Pressed"
pressed: true
down: true
}
CheckBox {
text: "Checked"
@ -242,7 +242,7 @@ ApplicationWindow {
CheckBox {
text: "CH + PR"
checked: true
pressed: true
down: true
}
CheckBox {
text: "Disabled"
@ -261,7 +261,7 @@ ApplicationWindow {
}
RadioButton {
text: "Pressed"
pressed: true
down: true
}
RadioButton {
text: "Checked"
@ -270,7 +270,7 @@ ApplicationWindow {
RadioButton {
text: "CH + PR"
checked: true
pressed: true
down: true
}
RadioButton {
text: "Disabled"
@ -289,7 +289,7 @@ ApplicationWindow {
}
Switch {
text: "Pressed"
pressed: true
down: true
}
Switch {
text: "Checked"
@ -298,7 +298,7 @@ ApplicationWindow {
Switch {
text: "CH + PR"
checked: true
pressed: true
down: true
}
Switch {
text: "Disabled"
@ -452,7 +452,7 @@ ApplicationWindow {
implicitHeight: normalComboBox.implicitHeight
ComboBox {
pressed: true
down: true
model: ListModel {
ListElement { text: "Pressed" }
}