blob: 0a0083159391a219c224caeb665fad886669ebb1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
import QtQuick
import qs.Common
import qs.Widgets
Flow {
id: root
property var model: []
property int currentIndex: 0
property int chipHeight: 32
property int chipPadding: Theme.spacingM
property bool showCheck: true
property bool showCounts: true
signal selectionChanged(int index)
spacing: Theme.spacingS
width: parent ? parent.width : 400
Repeater {
model: root.model
Rectangle {
id: chip
required property var modelData
required property int index
property bool selected: index === root.currentIndex
property bool hovered: mouseArea.containsMouse
property bool pressed: mouseArea.pressed
property string label: typeof modelData === "string" ? modelData : (modelData.label || "")
property int count: typeof modelData === "object" ? (modelData.count || 0) : 0
property bool showCount: root.showCounts && count > 0
width: contentRow.implicitWidth + root.chipPadding * 2
height: root.chipHeight
radius: height / 2
color: selected ? Theme.primary : Theme.surfaceVariant
Behavior on color {
ColorAnimation {
duration: Theme.shortDuration
easing.type: Theme.standardEasing
}
}
Rectangle {
anchors.fill: parent
radius: parent.radius
color: {
if (pressed)
return chip.selected ? Theme.primaryPressed : Theme.surfaceTextHover;
if (hovered)
return chip.selected ? Theme.primaryHover : Theme.surfaceTextHover;
return "transparent";
}
Behavior on color {
ColorAnimation {
duration: Theme.shorterDuration
easing.type: Theme.standardEasing
}
}
}
DankRipple {
id: chipRipple
cornerRadius: chip.radius
rippleColor: chip.selected ? Theme.primaryText : Theme.surfaceVariantText
}
Row {
id: contentRow
anchors.centerIn: parent
spacing: Theme.spacingXS
DankIcon {
name: "check"
size: 16
anchors.verticalCenter: parent.verticalCenter
color: Theme.primaryText
visible: root.showCheck && chip.selected
}
StyledText {
text: chip.label + (chip.showCount ? " (" + chip.count + ")" : "")
font.pixelSize: Theme.fontSizeSmall
font.weight: chip.selected ? Font.Medium : Font.Normal
color: chip.selected ? Theme.primaryText : Theme.surfaceVariantText
anchors.verticalCenter: parent.verticalCenter
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onPressed: mouse => chipRipple.trigger(mouse.x, mouse.y)
onClicked: {
root.currentIndex = chip.index;
root.selectionChanged(chip.index);
}
}
}
}
}
|