Changeset View
Changeset View
Standalone View
Standalone View
applets/kimpanel/package/contents/ui/main.qml
- This file was copied to applets/kimpanel/package/contents/ui/CompactRepresentation.qml.
Show All 18 Lines | |||||
19 | import QtQuick 2.0 | 19 | import QtQuick 2.0 | ||
20 | import QtQuick.Layouts 1.1 | 20 | import QtQuick.Layouts 1.1 | ||
21 | import org.kde.plasma.plasmoid 2.0 | 21 | import org.kde.plasma.plasmoid 2.0 | ||
22 | import org.kde.plasma.core 2.0 as PlasmaCore | 22 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
23 | import org.kde.plasma.components 2.0 as PlasmaComponents | 23 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
24 | import org.kde.kquickcontrolsaddons 2.0 | 24 | import org.kde.kquickcontrolsaddons 2.0 | ||
25 | 25 | | |||
26 | Item { | 26 | Item { | ||
27 | id: kimpanel | 27 | id: root | ||
28 | property int visibleButtons: 0 | | |||
29 | 28 | | |||
30 | property bool vertical: plasmoid.formFactor == PlasmaCore.Types.Vertical | 29 | Text { | ||
30 | id: textMetric | ||||
31 | visible: false | ||||
32 | // translated but not used, we just need length/height | ||||
33 | text: i18n("Arbitrary String Which Says Something") | ||||
34 | } | ||||
35 | | ||||
36 | Plasmoid.fullRepresentation: Item { | ||||
37 | id: dialogItem | ||||
38 | Layout.minimumWidth: units.gridUnit * 12 | ||||
39 | Layout.minimumHeight: units.gridUnit * 12 | ||||
40 | | ||||
41 | ListView { | ||||
42 | id: view | ||||
43 | anchors.fill: parent | ||||
44 | focus: true | ||||
31 | 45 | | |||
32 | LayoutMirroring.enabled: !vertical && Qt.application.layoutDirection === Qt.RightToLeft | 46 | model: dataSource.data["statusbar"]["LayoutList"] | ||
33 | LayoutMirroring.childrenInherit: true | | |||
34 | 47 | | |||
35 | Layout.minimumWidth: vertical ? units.iconSizes.small : items.implicitWidth | 48 | delegate: Item { | ||
36 | Layout.minimumHeight: !vertical ? units.iconSizes.small : items.implicitHeight | 49 | id: listdelegate | ||
37 | Layout.preferredHeight: Layout.minimumHeight | 50 | height: textMetric.paintedHeight * 2 | ||
38 | Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation | | |||
39 | 51 | | |||
40 | InputPanel { } | 52 | anchors { | ||
53 | left: parent.left | ||||
54 | right: parent.right | ||||
55 | } | ||||
41 | 56 | | |||
42 | Flow { | 57 | PlasmaCore.IconItem { | ||
43 | id: items | 58 | id: icon | ||
44 | width: parent.width | 59 | source: "checkmark" | ||
45 | height: parent.height | 60 | height: parent.height | ||
46 | x: (parent.width - childrenRect.width) / 2 | 61 | width: height | ||
47 | y: (parent.height - childrenRect.height) / 2 | 62 | visible: index == dataSource.data["statusbar"]["CurrentLayoutIndex"] | ||
48 | flow: kimpanel.vertical ? Flow.LeftToRight : Flow.TopToBottom | | |||
49 | | ||||
50 | property int iconSize: Math.min(units.iconSizeHints.panel, units.roundToIconSize(Math.min(width, height))) | | |||
51 | | ||||
52 | Repeater { | | |||
53 | model: ListModel { | | |||
54 | id: list | | |||
55 | dynamicRoles: true | | |||
56 | } | 63 | } | ||
57 | 64 | | |||
58 | delegate: Item { | 65 | PlasmaComponents.Label { | ||
59 | id: iconDelegate | 66 | text: model.description | ||
60 | width: items.iconSize | 67 | anchors { | ||
61 | height: items.iconSize | 68 | verticalCenter: parent.verticalCenter | ||
62 | StatusIcon { | 69 | left: icon.right | ||
63 | id: statusIcon | 70 | right: parent.right | ||
64 | anchors.centerIn: parent | 71 | leftMargin: 10 | ||
65 | width: items.iconSize | 72 | rightMargin: 10 | ||
66 | height: items.iconSize | | |||
67 | label: model.label | | |||
68 | tip: model.tip | | |||
69 | icon: model.icon | | |||
70 | hint: model.hint | | |||
71 | onTriggered : { | | |||
72 | if (button == Qt.LeftButton) { | | |||
73 | clickHandler(model.key); | | |||
74 | // clickHandler will trigger the menu, but we have to wait for | | |||
75 | // the menu data. So we have to set the visual parent ahead. | | |||
76 | actionMenu.visualParent = statusIcon; | | |||
77 | } else { | | |||
78 | contextMenu.open(statusIcon, {key: model.key, label: model.label}); | | |||
79 | } | | |||
80 | } | | |||
81 | } | | |||
82 | } | | |||
83 | } | | |||
84 | } | 73 | } | ||
85 | 74 | | |||
86 | function clickHandler(key) { | 75 | verticalAlignment: Text.AlignVCenter | ||
87 | var service = dataEngine.serviceForSource("statusbar"); | 76 | elide: Text.ElideRight | ||
88 | var operation = service.operationDescription("TriggerProperty"); | | |||
89 | operation.key = key; | | |||
90 | service.startOperationCall(operation); | | |||
91 | } | 77 | } | ||
92 | 78 | | |||
93 | function action(key) { | 79 | MouseArea { | ||
94 | var service = dataEngine.serviceForSource("statusbar"); | 80 | height: parent.height + 15 | ||
95 | var operation = service.operationDescription(key); | 81 | anchors { left: parent.left; right: parent.right;} | ||
96 | service.startOperationCall(operation); | 82 | hoverEnabled: true | ||
97 | } | | |||
98 | 83 | | |||
99 | function hideAction(key) { | 84 | onClicked: { | ||
100 | // We must use assignment to change the configuration property, | 85 | dataSource.data["statusbar"]["LayoutModels"].switchLayout(index); | ||
101 | // otherwise it won't get notified. | | |||
102 | var hiddenList = plasmoid.configuration.hiddenList; | | |||
103 | if (hiddenList.indexOf(key) === -1) { | | |||
104 | hiddenList.push(key); | | |||
105 | plasmoid.configuration.hiddenList = hiddenList; | | |||
106 | } | | |||
107 | timer.restart(); | | |||
108 | } | 86 | } | ||
109 | 87 | | |||
110 | function showAction(key) { | 88 | onEntered: { | ||
111 | // We must use assignment to change the configuration property, | 89 | view.currentIndex = index; | ||
112 | // otherwise it won't get notified. | | |||
113 | var hiddenList = plasmoid.configuration.hiddenList; | | |||
114 | var index = hiddenList.indexOf(key); | | |||
115 | if (index !== -1) { | | |||
116 | hiddenList.splice(index, 1); | | |||
117 | plasmoid.configuration.hiddenList = hiddenList; | | |||
118 | } | 90 | } | ||
119 | timer.restart(); | | |||
120 | } | 91 | } | ||
121 | | ||||
122 | function showMenu(menu, menuData) { | | |||
123 | if (!menuData) { | | |||
124 | return; | | |||
125 | } | 92 | } | ||
126 | 93 | | |||
127 | if (menuData["timestamp"] > menu.timestamp) { | 94 | highlight: PlasmaComponents.Highlight { | ||
128 | menu.timestamp = menuData["timestamp"]; | 95 | hover: true | ||
129 | var actionList = []; | | |||
130 | for (var i = 0; i < menuData["props"].length; i++ ) { | | |||
131 | actionList.push({"actionId": menuData["props"][i].key, "icon": menuData["props"][i].icon, "text": menuData["props"][i].label, hint: menuData["props"][i].hint}); | | |||
132 | } | | |||
133 | if (actionList.length > 0) { | | |||
134 | menu.actionList = actionList; | | |||
135 | menu.open(); | | |||
136 | } | | |||
137 | } | | |||
138 | } | 96 | } | ||
139 | 97 | | |||
140 | ActionMenu { | 98 | highlightMoveDuration: 250 | ||
141 | property var timestamp: 0; | 99 | highlightMoveVelocity: 2 | ||
142 | id: actionMenu | | |||
143 | onActionClicked: { | | |||
144 | clickHandler(actionId); | | |||
145 | } | 100 | } | ||
146 | } | 101 | } | ||
147 | 102 | | |||
148 | ContextMenu { | 103 | Plasmoid.compactRepresentation: CompactRepresentation { | ||
149 | id: contextMenu | 104 | dataEngine: dataSource | ||
150 | } | 105 | } | ||
151 | 106 | | |||
152 | Timer { | 107 | property int visibility: PlasmaCore.Types.HiddenStatus | ||
153 | id: timer | 108 | Plasmoid.status: visibility | ||
154 | interval: 50 | | |||
155 | onTriggered: { | | |||
156 | var data = dataEngine.data["statusbar"]["Properties"]; | | |||
157 | if (!data) { | | |||
158 | return; | | |||
159 | } | | |||
160 | var count = list.count; | | |||
161 | var c = 0, i; | | |||
162 | var hiddenActions = []; | | |||
163 | for (i = 0; i < data.length; i ++) { | | |||
164 | if (plasmoid.configuration.hiddenList.indexOf(data[i].key) !== -1) { | | |||
165 | hiddenActions.push({'key': data[i].key, | | |||
166 | 'icon': data[i].icon, | | |||
167 | 'label': data[i].label}); | | |||
168 | } else { | | |||
169 | c = c + 1; | | |||
170 | } | | |||
171 | } | | |||
172 | if (c < count) { | | |||
173 | list.remove(c, count - c); | | |||
174 | } | | |||
175 | kimpanel.visibleButtons = c; | | |||
176 | | ||||
177 | c = 0; | | |||
178 | for (i = 0; i < data.length; i ++) { | | |||
179 | if (plasmoid.configuration.hiddenList.indexOf(data[i].key) !== -1) { | | |||
180 | continue; | | |||
181 | } | | |||
182 | var itemData = {'key': data[i].key, | | |||
183 | 'icon': data[i].icon, | | |||
184 | 'label': data[i].label, | | |||
185 | 'tip': data[i].tip, | | |||
186 | 'hint': data[i].hint }; | | |||
187 | if (c < count) { | | |||
188 | list.set(c, itemData); | | |||
189 | } else { | | |||
190 | list.append(itemData); | | |||
191 | } | | |||
192 | c = c + 1; | | |||
193 | } | | |||
194 | contextMenu.actionList = hiddenActions; | | |||
195 | } | | |||
196 | } | | |||
197 | 109 | | |||
198 | PlasmaCore.DataSource { | 110 | PlasmaCore.DataSource { | ||
199 | id: dataEngine | 111 | id: dataSource | ||
200 | engine: "kimpanel" | 112 | engine: "kimpanel" | ||
201 | connectedSources: ["statusbar"] | 113 | connectedSources: ["statusbar"] | ||
202 | onDataChanged: { | 114 | onDataChanged: { | ||
203 | showMenu(actionMenu, dataEngine.data["statusbar"]["Menu"]); | 115 | root.visibility = dataSource.data["statusbar"]["Visibility"]? | ||
204 | var data = dataEngine.data["statusbar"]["Properties"]; | 116 | PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.HiddenStatus; | ||
205 | if (!data) { | | |||
206 | kimpanel.visibleButtons = 0; | | |||
207 | return; | | |||
208 | } | | |||
209 | | ||||
210 | timer.restart(); | | |||
211 | } | 117 | } | ||
212 | } | 118 | } | ||
213 | } | 119 | } | ||
214 | 120 | |