Skip to content

Commit 7b168da

Browse files
committed
Merge #271: Remove redundant MouseAreas from controls that are Buttons
80392a5 qml: remove redundant MouseAreas from controls that are Buttons (Jarol Rodriguez) Pull request description: For controls that are buttons, an additional `MouseArea` layer is unnecessary as they already have built-in event detection for actions such as [pressing](https://doc.qt.io/qt-6/qml-qtquick-controls2-abstractbutton.html#pressed-prop) and [hovering](https://doc.qt.io/qt-6/qml-qtquick-controls2-control.html#hovered-prop). By eliminating the redundant MouseAreas in the `ContinueButton`, `NavButton`, `OutlineButton`, `Setting`, and `TextButton` controls, we make their implementations cleaner. Previously, the `MouseArea` was utilized to set the controls' state, but now this is achieved through `when` statements that are bundled with the states themselves. [![Windows](https://img.shields.io/badge/OS-Windows-green)](https://api.cirrus-ci.com/v1/artifact/github/bitcoin-core/gui-qml/win64/insecure_win_gui.zip?branch=pull/271) [![Intel macOS](https://img.shields.io/badge/OS-Intel%20macOS-green)](https://api.cirrus-ci.com/v1/artifact/github/bitcoin-core/gui-qml/macos/insecure_mac_gui.zip?branch=pull/271) [![Apple Silicon macOS](https://img.shields.io/badge/OS-Apple%20Silicon%20macOS-green)](https://api.cirrus-ci.com/v1/artifact/github/bitcoin-core/gui-qml/macos_arm64/insecure_mac_arm64_gui.zip?branch=pull/271) [![ARM64 Android](https://img.shields.io/badge/OS-Android-green)](https://api.cirrus-ci.com/v1/artifact/github/bitcoin-core/gui-qml/android/insecure_android_apk.zip?branch=pull/271) ACKs for top commit: johnny9: ACK 80392a5 Tree-SHA512: 1bebc46d6a3b2449ae028e799611711197756c212899f831005b35881281b7f1a2a4d93b8cb39d683b9b90621928421e99c26491195a870b99eb260d08ce21b7
2 parents 1c7b1dc + 80392a5 commit 7b168da

File tree

7 files changed

+35
-114
lines changed

7 files changed

+35
-114
lines changed

src/qml/controls/ContinueButton.qml

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Button {
1010
font.family: "Inter"
1111
font.styleName: "Semi Bold"
1212
font.pixelSize: 18
13+
hoverEnabled: true
1314
contentItem: Text {
1415
text: parent.text
1516
font: parent.font
@@ -23,42 +24,20 @@ Button {
2324
implicitWidth: 300
2425
color: Theme.color.orange
2526
radius: 5
26-
state:"DEFAULT"
2727

2828
states: [
2929
State {
30-
name: "DEFAULT"
31-
PropertyChanges { target: bg; color: Theme.color.orange }
30+
name: "PRESSED"; when: root.pressed
31+
PropertyChanges { target: bg; color: Theme.color.orangeLight2 }
3232
},
3333
State {
34-
name: "HOVER"
34+
name: "HOVER"; when: root.hovered
3535
PropertyChanges { target: bg; color: Theme.color.orangeLight1 }
36-
},
37-
State {
38-
name: "PRESSED"
39-
PropertyChanges { target: bg; color: Theme.color.orangeLight2 }
4036
}
4137
]
4238

4339
Behavior on color {
4440
ColorAnimation { duration: 150 }
4541
}
4642
}
47-
MouseArea {
48-
anchors.fill: parent
49-
hoverEnabled: true
50-
onEntered: {
51-
root.background.state = "HOVER"
52-
}
53-
onExited: {
54-
root.background.state = "DEFAULT"
55-
}
56-
onPressed: {
57-
root.background.state = "PRESSED"
58-
}
59-
onReleased: {
60-
root.background.state = "DEFAULT"
61-
root.clicked()
62-
}
63-
}
6443
}

src/qml/controls/ExternalLink.qml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ AbstractButton {
1515
property url iconSource: "image://images/export"
1616
property int iconWidth: 22
1717
property int iconHeight: 22
18-
property color iconColor
19-
property color textColor
18+
property color iconColor: Theme.color.neutral9
19+
property color textColor: Theme.color.neutral7
2020
state: root.parentState
2121

2222
states: [
2323
State {
24-
name: "FILLED"
24+
name: "ACTIVE"
2525
PropertyChanges {
2626
target: root
27-
iconColor: Theme.color.neutral9
28-
textColor: Theme.color.neutral7
27+
iconColor: Theme.color.orange
28+
textColor: Theme.color.orange
2929
}
3030
},
3131
State {
@@ -35,14 +35,6 @@ AbstractButton {
3535
iconColor: Theme.color.orangeLight1
3636
textColor: Theme.color.orangeLight1
3737
}
38-
},
39-
State {
40-
name: "ACTIVE"
41-
PropertyChanges {
42-
target: root
43-
iconColor: Theme.color.orange
44-
textColor: Theme.color.orange
45-
}
4638
}
4739
]
4840

src/qml/controls/NavButton.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ AbstractButton {
1414
property url iconSource: ""
1515
property Rectangle iconBackground: null
1616
property color iconColor: Theme.color.neutral9
17-
17+
hoverEnabled: true
1818
topPadding: text_background.active ? 7 : 14
1919
bottomPadding: text_background.active ? 7 : 14
2020
rightPadding: text_background.active ? 22 : 14

src/qml/controls/OutlineButton.qml

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Button {
1010
font.family: "Inter"
1111
font.styleName: "Semi Bold"
1212
font.pixelSize: 18
13+
hoverEnabled: true
1314
contentItem: Text {
1415
text: parent.text
1516
font: parent.font
@@ -23,44 +24,24 @@ Button {
2324
implicitWidth: 340
2425
color: Theme.color.background
2526
radius: 5
26-
state:"DEFAULT"
2727
border {
2828
width: 1
29+
color: Theme.color.neutral6
30+
2931
Behavior on color {
3032
ColorAnimation { duration: 150 }
3133
}
3234
}
33-
34-
states: [
35-
State {
36-
name: "DEFAULT"
37-
PropertyChanges { target: bg; border.color: Theme.color.neutral6}
38-
},
39-
State {
40-
name: "HOVER"
41-
PropertyChanges { target: bg; border.color: Theme.color.neutral9 }
42-
},
43-
State {
44-
name: "PRESSED"
45-
PropertyChanges { target: bg; border.color: Theme.color.orangeLight2 }
46-
}
47-
]
4835
}
49-
MouseArea {
50-
anchors.fill: parent
51-
hoverEnabled: true
52-
onEntered: {
53-
root.background.state = "HOVER"
54-
}
55-
onExited: {
56-
root.background.state = "DEFAULT"
57-
}
58-
onPressed: {
59-
root.background.state = "PRESSED"
60-
}
61-
onReleased: {
62-
root.background.state = "DEFAULT"
63-
root.clicked()
36+
37+
states: [
38+
State {
39+
name: "PRESSED"; when: root.pressed
40+
PropertyChanges { target: bg; border.color: Theme.color.orangeLight2 }
41+
},
42+
State {
43+
name: "HOVER"; when: root.hovered
44+
PropertyChanges { target: bg; border.color: Theme.color.neutral9 }
6445
}
65-
}
46+
]
6647
}

src/qml/controls/Setting.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ AbstractButton {
1414
property alias loadedItem: action_loader.item
1515
property string description
1616
property color stateColor
17+
hoverEnabled: true
1718
state: "FILLED"
1819

1920
states: [

src/qml/controls/TextButton.qml

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import QtQuick.Controls 2.15
88
Button {
99
id: root
1010
property int textSize: 18
11-
property color textColor
12-
property color bgColor
11+
property color textColor: Theme.color.orange
12+
property color bgColor: Theme.color.background
1313
property bool bold: true
1414
property bool rightalign: false
1515
font.family: "Inter"
1616
font.styleName: bold ? "Semi Bold" : "Regular"
1717
font.pixelSize: root.textSize
1818
padding: 15
19-
state: "DEFAULT"
19+
hoverEnabled: true
2020
contentItem: Text {
2121
text: root.text
2222
font: root.font
@@ -37,45 +37,20 @@ Button {
3737
}
3838
states: [
3939
State {
40-
name: "DEFAULT"
40+
name: "PRESSED"; when: root.pressed
4141
PropertyChanges {
4242
target: root
43-
textColor: Theme.color.orange
44-
bgColor: Theme.color.background
43+
textColor: Theme.color.orangeLight2
44+
bgColor: Theme.color.neutral3
4545
}
4646
},
4747
State {
48-
name: "HOVER"
48+
name: "HOVER"; when: root.hovered
4949
PropertyChanges {
5050
target: root
5151
textColor: Theme.color.orangeLight1
5252
bgColor: Theme.color.neutral2
5353
}
54-
},
55-
State {
56-
name: "PRESSED"
57-
PropertyChanges {
58-
target: root
59-
textColor: Theme.color.orangeLight2
60-
bgColor: Theme.color.neutral3
61-
}
6254
}
6355
]
64-
MouseArea {
65-
anchors.fill: parent
66-
hoverEnabled: true
67-
onEntered: {
68-
root.state = "HOVER"
69-
}
70-
onExited: {
71-
root.state = "DEFAULT"
72-
}
73-
onPressed: {
74-
root.state = "PRESSED"
75-
}
76-
onReleased: {
77-
root.state = "DEFAULT"
78-
root.clicked()
79-
}
80-
}
8156
}

src/qml/controls/ValueInput.qml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,19 @@ TextInput {
1010
required property string parentState
1111
property string description: ""
1212
property int descriptionSize: 18
13-
property color textColor
13+
property color textColor: Theme.color.neutral9
14+
enabled: true
1415
state: root.parentState
1516

1617
states: [
1718
State {
18-
name: "FILLED"
19-
PropertyChanges {
20-
target: root
21-
enabled: true
22-
textColor: Theme.color.neutral9
23-
}
19+
name: "ACTIVE"
20+
PropertyChanges { target: root; textColor: Theme.color.orange }
2421
},
2522
State {
2623
name: "HOVER"
2724
PropertyChanges { target: root; textColor: Theme.color.orangeLight1 }
2825
},
29-
State {
30-
name: "ACTIVE"
31-
PropertyChanges { target: root; textColor: Theme.color.orange }
32-
},
3326
State {
3427
name: "DISABLED"
3528
PropertyChanges {

0 commit comments

Comments
 (0)