ConfigEntries.qml 11.4 KB
Newer Older
Marco Martin's avatar
Marco Martin committed
1
2
3
/*
 *  Copyright 2013 Sebastian Kügler <sebas@kde.org>
 *  Copyright 2014 Marco Martin <mart@kde.org>
4
 *  Copyright 2019 Konrad Materka <materka@gmail.com>
Marco Martin's avatar
Marco Martin committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  2.010-1301, USA.
 */

21
22
23
import QtQuick 2.5
import QtQuick.Controls 2.5 as QQC2
import QtQuick.Layouts 1.3
Marco Martin's avatar
Marco Martin committed
24

25
import org.kde.plasma.core 2.1 as PlasmaCore
Marco Martin's avatar
Marco Martin committed
26
import org.kde.kquickcontrols 2.0 as KQC
27
import org.kde.kirigami 2.10 as Kirigami
Marco Martin's avatar
Marco Martin committed
28

29
ColumnLayout {
Marco Martin's avatar
Marco Martin committed
30
31
32
33
34
35
    id: iconsPage

    signal configurationChanged

    property var cfg_shownItems: []
    property var cfg_hiddenItems: []
36
    property var cfg_extraItems: []
Marco Martin's avatar
Marco Martin committed
37
38
    property alias cfg_showAllItems: showAllCheckBox.checked

39
40
41
    QQC2.CheckBox {
        id: showAllCheckBox
        text: i18n("Always show all entries")
42
43
    }

44
45
46
47
48
49
50
51
52
53
54
55
56
    function categoryName(category) {
        switch (category) {
        case "ApplicationStatus":
            return i18n("Application Status")
        case "Communications":
            return i18n("Communications")
        case "SystemServices":
            return i18n("System Services")
        case "Hardware":
            return i18n("Hardware Control")
        case "UnknownCategory":
        default:
            return i18n("Miscellaneous")
57
        }
Marco Martin's avatar
Marco Martin committed
58
59
    }

60
61
    QQC2.ScrollView {
        id: scrollView
62

63
64
        Layout.fillWidth: true
        Layout.fillHeight: true
65
        contentHeight: itemsList.implicitHeight
Marco Martin's avatar
Marco Martin committed
66

67
        Component.onCompleted: scrollView.background.visible = true
Marco Martin's avatar
Marco Martin committed
68

69
70
        property bool scrollBarVisible: QQC2.ScrollBar.vertical && QQC2.ScrollBar.vertical.visible
        property var scrollBarWidth: scrollBarVisible ? QQC2.ScrollBar.vertical.width : 0
Marco Martin's avatar
Marco Martin committed
71

72
73
        ListView {
            id: itemsList
Marco Martin's avatar
Marco Martin committed
74

75
76
            property var visibilityColumnWidth: units.gridUnit
            property var keySequenceColumnWidth: units.gridUnit
Marco Martin's avatar
Marco Martin committed
77

78
79
80
            model: PlasmaCore.SortFilterModel {
                sourceModel: PlasmaCore.SortFilterModel {
                    sourceModel: plasmoid.nativeInterface.systemTrayModel
Marco Martin's avatar
Marco Martin committed
81

82
83
84
                    sortRole: "display"
                    sortColumn: 0
                    isSortLocaleAware: true
Marco Martin's avatar
Marco Martin committed
85
                }
86
87
88
89

                sortRole: "category"
                sortColumn: 0
                isSortLocaleAware: true
Marco Martin's avatar
Marco Martin committed
90
91
            }

92
            header: Kirigami.AbstractListItem {
Marco Martin's avatar
Marco Martin committed
93

94
95
96
97
98
99
100
                hoverEnabled: false

                RowLayout {
                    Kirigami.Heading {
                        text: i18nc("Name of the system tray entry", "Entry")
                        level: 2
                        Layout.fillWidth: true
Marco Martin's avatar
Marco Martin committed
101
                    }
102
103
104
105
106
                    Kirigami.Heading {
                        text: i18n("Visibility")
                        level: 2
                        Layout.preferredWidth: itemsList.visibilityColumnWidth
                        Component.onCompleted: itemsList.visibilityColumnWidth = Math.max(implicitWidth, itemsList.visibilityColumnWidth)
Marco Martin's avatar
Marco Martin committed
107
                    }
108
109
110
111
112
                    Kirigami.Heading {
                        text: i18n("Keyboard Shortcut")
                        level: 2
                        Layout.preferredWidth: itemsList.keySequenceColumnWidth
                        Component.onCompleted: itemsList.keySequenceColumnWidth = Math.max(implicitWidth, itemsList.keySequenceColumnWidth)
Marco Martin's avatar
Marco Martin committed
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
            section {
                property: "category"
                delegate: Kirigami.ListSectionHeader {
                    label: categoryName(section)
                }
            }

            delegate: Kirigami.AbstractListItem {

                highlighted: false
                hoverEnabled: false

                property bool isPlasmoid: model.itemType === "Plasmoid"

                contentItem: RowLayout {
                    RowLayout {
                        Layout.fillWidth: true

                        Kirigami.Icon {
                            width: units.iconSizes.small
                            height: width
                            source: model.decoration
                        }
                        QQC2.Label {
                            Layout.fillWidth: true
                            text: model.display
                            elide: Text.ElideRight
                            wrapMode: Text.NoWrap
                        }
                    }

                    QQC2.ComboBox {
                        id: visibilityComboBox

                        property var contentWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                                                            implicitContentWidth + leftPadding + rightPadding)
                        implicitWidth: Math.max(contentWidth, itemsList.visibilityColumnWidth)
                        Component.onCompleted: itemsList.visibilityColumnWidth = Math.max(implicitWidth, itemsList.visibilityColumnWidth)

                        enabled: (!showAllCheckBox.checked || isPlasmoid) && itemId
                        textRole: "text"
                        model: comboBoxModel()
Marco Martin's avatar
Marco Martin committed
159

160
161
                        currentIndex: {
                            var value
Marco Martin's avatar
Marco Martin committed
162

163
164
165
166
167
168
169
170
171
                            if (cfg_shownItems.indexOf(itemId) !== -1) {
                                value = "shown"
                            } else if (cfg_hiddenItems.indexOf(itemId) !== -1) {
                                value = "hidden"
                            } else if (isPlasmoid && cfg_extraItems.indexOf(itemId) === -1) {
                                value = "disabled"
                            } else {
                                value = "auto"
                            }
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
                            for (var i = 0; i < model.length; i++) {
                                if (model[i].value === value) {
                                    return i
                                }
                            }

                            return 0
                        }

                        property var currentValue: model[currentIndex].value

                        onActivated: {
                            var shownIndex = cfg_shownItems.indexOf(itemId)
                            var hiddenIndex = cfg_hiddenItems.indexOf(itemId)
                            var extraIndex = cfg_extraItems.indexOf(itemId)

                            switch (currentValue) {
                            case "auto":
                                if (shownIndex > -1) {
                                    cfg_shownItems.splice(shownIndex, 1)
                                }
                                if (hiddenIndex > -1) {
                                    cfg_hiddenItems.splice(hiddenIndex, 1)
                                }
                                if (extraIndex === -1) {
                                    cfg_extraItems.push(itemId)
                                }
                                break
                            case "shown":
                                if (shownIndex === -1) {
                                    cfg_shownItems.push(itemId)
                                }
                                if (hiddenIndex > -1) {
                                    cfg_hiddenItems.splice(hiddenIndex, 1)
                                }
                                if (extraIndex === -1) {
                                    cfg_extraItems.push(itemId)
                                }
                                break
                            case "hidden":
                                if (shownIndex > -1) {
                                    cfg_shownItems.splice(shownIndex, 1)
                                }
                                if (hiddenIndex === -1) {
                                    cfg_hiddenItems.push(itemId)
                                }
                                if (extraIndex === -1) {
                                    cfg_extraItems.push(itemId)
                                }
                                break
                            case "disabled":
                                if (extraIndex > -1) {
                                    cfg_extraItems.splice(extraIndex, 1)
                                }
                                break
                            }
Marco Martin's avatar
Marco Martin committed
229
230
                            iconsPage.configurationChanged()
                        }
231

232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
                        function comboBoxModel() {
                            var autoElement = {"value": "auto", "text": i18n("Shown when relevant")}
                            var shownElement = {"value": "shown", "text": i18n("Always shown")}
                            var hiddenElement = {"value": "hidden", "text": i18n("Always hidden")}
                            var disabledElement = {"value": "disabled", "text": i18n("Disabled")}

                            if (showAllCheckBox.checked) {
                                if (isPlasmoid) {
                                    return [autoElement, disabledElement]
                                } else {
                                    return [shownElement]
                                }
                            } else {
                                if (isPlasmoid) {
                                    return [autoElement, shownElement, hiddenElement, disabledElement]
                                } else {
                                    return [autoElement, shownElement, hiddenElement]
                                }
                            }
                        }
                    }
                    KQC.KeySequenceItem {
                        id: keySequenceItem
                        Layout.minimumWidth: itemsList.keySequenceColumnWidth
                        Layout.preferredWidth: itemsList.keySequenceColumnWidth
                        Component.onCompleted: itemsList.keySequenceColumnWidth = Math.max(implicitWidth, itemsList.keySequenceColumnWidth)

                        visible: isPlasmoid
                        enabled: visibilityComboBox.currentValue !== "disabled"
                        keySequence: model.applet ? model.applet.globalShortcut : ""
                        onKeySequenceChanged: {
                            if (model.applet && keySequence !== model.applet.globalShortcut) {
                                model.applet.globalShortcut = keySequence

                                itemsList.keySequenceColumnWidth = Math.max(implicitWidth, itemsList.keySequenceColumnWidth)
                            }
                        }
                    }
                    // Placeholder for when KeySequenceItem is not visible
                    Item {
                        Layout.minimumWidth: itemsList.keySequenceColumnWidth
                        Layout.maximumWidth: itemsList.keySequenceColumnWidth
                        visible: !keySequenceItem.visible
Marco Martin's avatar
Marco Martin committed
275
276
277
278
279
280
                    }
                }
            }
        }
    }
}