Skip to content

Commit 67150ef

Browse files
committed
Merge #375: Improve peer delegate
c54c973 qml: change peer delegate layout (João Barbosa) 3c2d951 qml: improve peer delegate (João Barbosa) Pull request description: Use Qt `ItemDelegate` and use properties `down` and `hovered`, making it possible to drop the `MouseArea` Also improve the layout and elide the label that can overflow. fixes #372. ACKs for top commit: johnny9: ACK c54c973 Tree-SHA512: e9fe745100d0d5b17299601ce81c4dbb97ee714b0c9226a2b4b0761f6658f3475be79981e8ac37d62d444e54250a4215bd434c4ab0382b673d0a416432c032cb
2 parents 97fe0b7 + c54c973 commit 67150ef

File tree

1 file changed

+55
-70
lines changed

1 file changed

+55
-70
lines changed

src/qml/pages/node/Peers.qml

+55-70
Original file line numberDiff line numberDiff line change
@@ -153,55 +153,22 @@ Page {
153153
}
154154
}
155155

156-
delegate: Item {
156+
delegate: ItemDelegate {
157157
id: delegate
158158
required property int nodeId;
159159
required property string address;
160160
required property string subversion;
161161
required property string direction;
162162
required property string connectionType;
163163
required property string network;
164-
property color stateColor;
165-
implicitHeight: 60
166-
implicitWidth: listView.width
167-
state: "FILLED"
168-
169-
states: [
170-
State {
171-
name: "FILLED"
172-
PropertyChanges { target: delegate; stateColor: Theme.color.neutral9 }
173-
},
174-
State {
175-
name: "HOVER"
176-
PropertyChanges { target: delegate; stateColor: Theme.color.orangeLight1 }
177-
},
178-
State {
179-
name: "ACTIVE"
180-
PropertyChanges { target: delegate; stateColor: Theme.color.orange }
181-
}
182-
]
183-
184-
MouseArea {
185-
anchors.fill: parent
186-
hoverEnabled: AppMode.isDesktop
187-
onEntered: {
188-
delegate.state = "HOVER"
189-
}
190-
onExited: {
191-
delegate.state = "FILLED"
192-
}
193-
onPressed: {
194-
delegate.state = "ACTIVE"
195-
}
196-
onReleased: {
197-
if (mouseArea.containsMouse) {
198-
delegate.state = "HOVER"
199-
} else {
200-
delegate.state = "FILLED"
201-
}
164+
readonly property color stateColor: {
165+
if (delegate.down) {
166+
return Theme.color.orange
167+
} else if (delegate.hovered) {
168+
return Theme.color.orangeLight1
202169
}
170+
return Theme.color.neutral9
203171
}
204-
205172
Connections {
206173
target: peerListModelProxy
207174
function onSortByChanged(roleName) {
@@ -254,41 +221,59 @@ Page {
254221
quaternary.text = subversion
255222
}
256223
}
257-
258-
ColumnLayout {
259-
anchors.left: parent.left
260-
CoreText {
261-
Layout.alignment: Qt.AlignLeft
262-
id: primary
263-
font.pixelSize: 18
264-
color: delegate.stateColor
265-
}
266-
CoreText {
267-
Layout.alignment: Qt.AlignLeft
268-
id: tertiary
269-
font.pixelSize: 15
270-
color: Theme.color.neutral7
224+
leftPadding: 0
225+
rightPadding: 0
226+
topPadding: 0
227+
bottomPadding: 14
228+
width: listView.width
229+
background: Item {
230+
Separator {
231+
anchors.bottom: parent.bottom
232+
width: parent.width
271233
}
272234
}
273-
ColumnLayout {
274-
anchors.right: parent.right
275-
CoreText {
276-
Layout.alignment: Qt.AlignRight
277-
id: secondary
278-
font.pixelSize: 18
279-
color: delegate.stateColor
235+
contentItem: ColumnLayout {
236+
RowLayout {
237+
Layout.fillWidth: true
238+
spacing: 15
239+
CoreText {
240+
Layout.alignment: Qt.AlignLeft
241+
Layout.fillWidth: true
242+
Layout.preferredWidth: 0
243+
id: primary
244+
font.pixelSize: 18
245+
color: delegate.stateColor
246+
elide: Text.ElideMiddle
247+
wrapMode: Text.NoWrap
248+
horizontalAlignment: Text.AlignLeft
249+
}
250+
CoreText {
251+
Layout.alignment: Qt.AlignRight
252+
id: secondary
253+
font.pixelSize: 18
254+
color: delegate.stateColor
255+
}
280256
}
281-
CoreText {
282-
Layout.alignment: Qt.AlignRight
283-
id: quaternary
284-
font.pixelSize: 15
285-
color: Theme.color.neutral7
257+
RowLayout {
258+
CoreText {
259+
Layout.alignment: Qt.AlignLeft
260+
Layout.fillWidth: true
261+
Layout.preferredWidth: 0
262+
id: tertiary
263+
font.pixelSize: 15
264+
color: Theme.color.neutral7
265+
elide: Text.ElideMiddle
266+
wrapMode: Text.NoWrap
267+
horizontalAlignment: Text.AlignLeft
268+
}
269+
CoreText {
270+
Layout.alignment: Qt.AlignRight
271+
id: quaternary
272+
font.pixelSize: 15
273+
color: Theme.color.neutral7
274+
}
286275
}
287276
}
288-
Separator {
289-
anchors.bottom: parent.bottom
290-
width: parent.width
291-
}
292277
}
293278
}
294279
}

0 commit comments

Comments
 (0)