Changeset View
Standalone View
kcmkwin/kwinrules/package/contents/ui/OptionsComboBox.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2020 Ismael Asensio <isma.af@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | import QtQuick 2.12 | ||||
22 | import QtQuick.Layouts 1.12 | ||||
23 | import QtQuick.Controls 2.12 as QQC2 | ||||
24 | | ||||
25 | import org.kde.kirigami 2.10 as Kirigami | ||||
26 | | ||||
27 | | ||||
28 | QQC2.ComboBox { | ||||
29 | id: optionsCombo | ||||
30 | | ||||
31 | textRole: "text" | ||||
32 | //FIXME: After Qt 5.14 this can be replaced by the new implemented properties: | ||||
33 | // valueRole: "value"` | ||||
34 | // currentValue: model.value | ||||
35 | | ||||
36 | property var currentValue | ||||
37 | property var values: [] | ||||
38 | | ||||
39 | currentIndex: model.selectedIndex | ||||
40 | | ||||
41 | onActivated: (index) => { | ||||
42 | currentValue = values[index]; | ||||
broulik: Kudos for using `onActivated` rather than `onCurrentIndexChanged`! ;)
However, you can… | |||||
That approach fails for me (QCoreApplication::postEvent: Unexpected null receiver), even with some protections iasensio: That approach fails for me (`QCoreApplication::postEvent: Unexpected null receiver`), even with… | |||||
43 | } | ||||
44 | | ||||
45 | delegate: QQC2.ItemDelegate { | ||||
46 | readonly property bool reversed : Qt.application.layoutDirection === Qt.RightToLeft | ||||
47 | | ||||
48 | highlighted: optionsCombo.highlightedIndex == index | ||||
49 | width: parent.width | ||||
50 | | ||||
51 | LayoutMirroring.enabled: reversed | ||||
52 | LayoutMirroring.childrenInherit: true | ||||
53 | | ||||
54 | contentItem: RowLayout { | ||||
55 | Kirigami.Icon { | ||||
56 | source: model.icon | ||||
57 | Layout.preferredHeight: Kirigami.Units.iconSizes.small | ||||
58 | Layout.preferredWidth: Kirigami.Units.iconSizes.small | ||||
59 | } | ||||
60 | QQC2.Label { | ||||
61 | text: model.text | ||||
62 | color: highlighted ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor | ||||
Use %1 instead of the hardcoded number 1 for the singular case (there are languages where e.g. the number 21 uses the singular form) ngraham: Use `%1` instead of the hardcoded number 1 for the singular case (there are languages where e.g. | |||||
63 | Layout.fillWidth: true | ||||
64 | horizontalAlignment: Text.AlignLeft | ||||
65 | } | ||||
66 | } | ||||
67 | | ||||
68 | QQC2.ToolTip { | ||||
69 | text: model.description | ||||
Is this necessary to manually assign? I thought LayoutMirroring.enabled got set automatically? ngraham: Is this necessary to manually assign? I thought `LayoutMirroring.enabled` got set automatically? | |||||
You're right, it works automatically now! iasensio: You're right, it works automatically now!
It didn't previously for me, so maybe something was… | |||||
70 | visible: hovered && (model.description != "") | ||||
ngraham: would be nice if clicking anywhere in the row activated that row's checkbox | |||||
Hmm, this is not fixed yet for me. Probably you need to put a MouseArea inside the ItemDelegate that toggles the checkbox if clicked. ngraham: Hmm, this is not fixed yet for me. Probably you need to put a MouseArea inside the ItemDelegate… | |||||
oh, silly me! I did that on the main list selection when exporting.. will repeat it here iasensio: oh, silly me! I did that on the main list selection when exporting.. will repeat it here | |||||
71 | } | ||||
72 | | ||||
73 | Component.onCompleted: { | ||||
74 | values[index] = model.value; | ||||
75 | optionsCombo.popup.width = Math.max(implicitWidth, optionsCombo.width, optionsCombo.popup.width); | ||||
76 | } | ||||
77 | } | ||||
78 | } | ||||
Can you add a TODO or FIXME comment indicating that this works around https://bugs.kde.org/show_bug.cgi?id=403153? ngraham: Can you add a TODO or FIXME comment indicating that this works around https://bugs.kde. | |||||
Add braces, either on the same line, or in the more conventional multi-line style ngraham: Add braces, either on the same line, or in the more conventional multi-line style |
Kudos for using onActivated rather than onCurrentIndexChanged! ;)
However, you can probably make this a binding
or perhaps a string property, even