Changeset View
Changeset View
Standalone View
Standalone View
src/kcm/package/contents/ui/DeviceListItem.qml
Show All 18 Lines | |||||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | import QtQuick 2.0 | 21 | import QtQuick 2.0 | ||
22 | import QtQuick.Controls 1.0 | 22 | import QtQuick.Controls 1.0 | ||
23 | import QtQuick.Layouts 1.0 | 23 | import QtQuick.Layouts 1.0 | ||
24 | 24 | | |||
25 | import org.kde.kquickcontrolsaddons 2.0 | 25 | import org.kde.kquickcontrolsaddons 2.0 | ||
26 | 26 | | |||
27 | import org.kde.plasma.private.volume 0.1 | ||||
28 | | ||||
27 | ColumnLayout { | 29 | ColumnLayout { | ||
28 | id: delegate | 30 | id: delegate | ||
29 | width: parent.width | 31 | width: parent.width | ||
30 | 32 | | |||
31 | RowLayout { | 33 | RowLayout { | ||
32 | QIconItem { | 34 | QIconItem { | ||
33 | width: height | 35 | width: height | ||
34 | height: inputText.height | 36 | height: inputText.height | ||
Show All 33 Lines | 69 | RowLayout { | |||
68 | visible: portbox.count > 1 | 70 | visible: portbox.count > 1 | ||
69 | 71 | | |||
70 | Label { | 72 | Label { | ||
71 | text: i18n("Port") | 73 | text: i18n("Port") | ||
72 | } | 74 | } | ||
73 | 75 | | |||
74 | ComboBox { | 76 | ComboBox { | ||
75 | id: portbox | 77 | id: portbox | ||
78 | readonly property var ports: Ports | ||||
76 | Layout.fillWidth: true | 79 | Layout.fillWidth: true | ||
77 | model: Ports | | |||
78 | onModelChanged: currentIndex = ActivePortIndex | 80 | onModelChanged: currentIndex = ActivePortIndex | ||
79 | textRole: "description" | | |||
80 | currentIndex: ActivePortIndex | 81 | currentIndex: ActivePortIndex | ||
81 | onActivated: ActivePortIndex = index | 82 | onActivated: ActivePortIndex = index | ||
83 | | ||||
84 | onPortsChanged: { | ||||
broulik: You could also just use a JS Array for this since you're not making use of `ListModel`'s… | |||||
85 | var items = []; | ||||
86 | for (var i = 0; i < ports.length; ++i) { | ||||
87 | var port = ports[i]; | ||||
88 | var text = port.description; | ||||
89 | if (port.availability == Port.Unavailable) { | ||||
90 | if (port.name == "analog-output-speaker" || port.name == "analog-input-microphone-internal") { | ||||
91 | text += i18nc("Port is unavailable", " (unavailable)"); | ||||
broulik: Better cache port as variable:
```
var port = ports[i];
...
``` | |||||
92 | } else { | ||||
93 | text += i18nc("Port is unplugged", " (unplugged)"); | ||||
94 | } | ||||
95 | } | ||||
96 | items.push(text); | ||||
97 | } | ||||
98 | model = items; | ||||
99 | } | ||||
82 | } | 100 | } | ||
83 | } | 101 | } | ||
84 | 102 | | |||
85 | VolumeSlider {} | 103 | VolumeSlider {} | ||
86 | } | 104 | } | ||
87 | 105 | | |||
88 | ListItemSeperator { view: delegate.ListView.view } | 106 | ListItemSeperator { view: delegate.ListView.view } | ||
89 | } | 107 | } |
You could also just use a JS Array for this since you're not making use of ListModel's binding capabilities (you always clear and re-populate the model)