~blue-shell/blue-shell/kde-workspace-systemsettings-qml

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import QtQuick 1.1
import org.kde.plasma.core 0.1 as PlasmaCore
import org.kde.plasma.components 0.1 as PlasmaComponents
import org.kde.qtextracomponents 0.1 as QtExtra
import SystemSettings 0.1

Flickable {
    id: root
    contentHeight: categoryList.height
    contentWidth: categoryList.width
    boundsBehavior: Flickable.StopAtBounds

    signal loadModule( string name )

    Component {
        id: menuItem

        ItemRect {
            id: frame

            width: icon.width * 3
            height: icon.height + label.height + 15

            Column {
                width: parent.width
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.verticalCenter: parent.verticalCenter

                QtExtra.QIconItem {
                    id: icon

                    anchors.horizontalCenter: parent.horizontalCenter

                    width: 32
                    height: 32

                    icon: model.DecorationRole
                }

                FocusRect {
                    id: focusRect

                    width: parent.width
                    height: label.paintedHeight + 3
                    anchors.horizontalCenter: icon.horizontalCenter

                    Text {
                        id: label

                        width: parent.width - 10
                        x: 5
                        height: parent.height

                        wrapMode: Text.WordWrap
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignBottom
                        text: model.DisplayRole
                    }
                }
            }

            property bool mouseOver: false
            property bool mousePressed: false

            MouseArea {
                id: mouseArea

                anchors.fill: parent

                hoverEnabled: true

                onEntered: {
                    mouseOver = true;
                }

                onExited: {
                    mouseOver = false;
                    //FIXME: Hack for testing, breaks down with double-click.
                    mousePressed = false;
                }

                onPressed: {
                    mousePressed = true;
                }

                onClicked: {
                    root.loadModule( model.DisplayRole )
                }
            }

           states: [
                State {
                    name: "selected+hovered"
                    when: mousePressed && mouseOver

                    PropertyChanges {
                        target: frame
                        hovered: true
                        selected: true
                    }
                    PropertyChanges {
                        target: label
                        color: "white"
                    }
                },
                State {
                    name: "selected"
                    when: mousePressed && !mouseOver

                    PropertyChanges {
                        target: frame
                        hovered: false
                        selected: true
                    }
                    PropertyChanges {
                        target: label
                        color: "white"
                    }
                },
                State {
                    name: "hovered"
                    when: !mousePressed && mouseOver

                    PropertyChanges {
                        target: frame
                        hovered: true
                        selected: false
                    }
                    PropertyChanges {
                        target: label
                        color: "black"
                    }
                },
                State {
                    name: "none"
                    when: !mouseOver

                    PropertyChanges {
                        target: frame
                        hovered: false
                        selected: false
                    }
                    PropertyChanges {
                        target: label
                        color: "black"
                    }
                }
            ]
        }
    }

    Component {
        id: categoryView

        CategoryBackground
        {
            anchors.left: parent.left
            anchors.right: parent.right
            height: categoryContents.height + 10


            Column {
                id: categoryContents
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.leftMargin: 5
                anchors.rightMargin: 5

                Text {
                    anchors.left: parent.left
                    anchors.leftMargin: 8
                    height: paintedHeight + 10
                    verticalAlignment: Text.AlignBottom
                    font.bold: true
                    opacity: 0.6
                    text: model.DisplayRole
                }

                VisualDataModel {
                    id: lense
                    model: menuModel
                    rootIndex: modelIndex(index)
                    delegate: menuItem

                    Component.onCompleted: {
                        lense.rootIndex = lense.modelIndex(index)
                    }
                }

                Flow {
                    anchors.left: parent.left
                    anchors.right: parent.right

                    Repeater { model: lense }
                }
            }
        }
    }

    Column {
        id: categoryList
        width: root.width

        Repeater {
            model: menuModel
            delegate: categoryView
        }
    }
}