Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwindecoration/package/contents/ui/Buttons.qml
- This file was moved from kcmkwin/kwindecoration/qml/Buttons.qml.
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright 2014 Martin Gräßlin <mgraesslin@kde.org> | 2 | * Copyright 2014 Martin Gräßlin <mgraesslin@kde.org> | ||
3 | * Copyright (c) 2019 Valerio Pilo <vpilo@coldshock.net> | ||||
3 | * | 4 | * | ||
4 | * This program is free software; you can redistribute it and/or | 5 | * 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 | * modify it under the terms of the GNU General Public License as | ||
6 | * published by the Free Software Foundation; either version 2 of | 7 | * published by the Free Software Foundation; either version 2 of | ||
7 | * the License or (at your option) version 3 or any later version | 8 | * 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 | * 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 | * 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 | * defined in Section 14 of version 3 of the license. | ||
11 | * | 12 | * | ||
12 | * This program is distributed in the hope that it will be useful, | 13 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | 16 | * GNU General Public License for more details. | ||
16 | * | 17 | * | ||
17 | * You should have received a copy of the GNU General Public License | 18 | * 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 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 20 | */ | ||
20 | import QtQuick 2.3 | 21 | import QtQuick 2.7 | ||
21 | import QtQuick.Controls 1.2 | 22 | import QtQuick.Layouts 1.3 | ||
22 | import QtQuick.Controls 2.0 as QQC2 | 23 | import QtQuick.Controls 2.4 as Controls | ||
23 | import QtQuick.Layouts 1.1 | 24 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
24 | import org.kde.kwin.private.kdecoration 1.0 as KDecoration | 25 | import org.kde.kwin.private.kdecoration 1.0 as KDecoration | ||
25 | import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons; | | |||
26 | 26 | | |||
27 | Item { | 27 | ColumnLayout { | ||
28 | objectName: "buttonLayout" | 28 | Layout.fillWidth: true | ||
29 | Layout.preferredHeight: layout.height | 29 | Layout.fillHeight: true | ||
30 | property int buttonIconSize: units.iconSizes.medium | ||||
31 | property int titleBarSpacing: units.iconSizes.smallMedium | ||||
32 | | ||||
30 | KDecoration.Bridge { | 33 | KDecoration.Bridge { | ||
31 | id: bridgeItem | 34 | id: bridgeItem | ||
32 | plugin: "org.kde.breeze" | 35 | plugin: "org.kde.breeze" | ||
33 | } | 36 | } | ||
34 | KDecoration.Settings { | 37 | KDecoration.Settings { | ||
35 | id: settingsItem | 38 | id: settingsItem | ||
36 | bridge: bridgeItem.bridge | 39 | bridge: bridgeItem.bridge | ||
37 | } | 40 | } | ||
41 | | ||||
38 | Rectangle { | 42 | Rectangle { | ||
39 | anchors.fill: parent | 43 | Layout.fillWidth: true | ||
40 | border.width: Math.ceil(units.gridUnit / 16.0) | 44 | color: palette.base | ||
41 | border.color: highlightColor | 45 | radius: units.smallSpacing | ||
42 | color: baseColor | 46 | height: fakeWindow.height | ||
47 | Layout.margins: units.smallSpacing | ||||
48 | | ||||
43 | ColumnLayout { | 49 | ColumnLayout { | ||
44 | id: layout | 50 | id: fakeWindow | ||
45 | width: parent.width | 51 | width: parent.width | ||
46 | height: titlebarRect.height + availableGrid.height + dragHint.height + 5*layout.spacing | 52 | | ||
47 | Rectangle { | 53 | Rectangle { | ||
48 | id: titlebarRect | 54 | id: titleBar | ||
49 | height: buttonPreviewRow.height + units.smallSpacing | | |||
50 | border.width: Math.ceil(units.gridUnit / 16.0) | | |||
51 | border.color: highlightColor | | |||
52 | color: backgroundColor | | |||
53 | Layout.fillWidth: true | 55 | Layout.fillWidth: true | ||
54 | Layout.topMargin: -border.width // prevent a double top border | 56 | height: buttonPreviewRow.height + 2 * titleBarSpacing | ||
57 | radius: units.smallSpacing | ||||
58 | gradient: Gradient { | ||||
59 | GradientStop { position: 0.0; color: palette.midlight } | ||||
60 | GradientStop { position: 1.0; color: palette.window } | ||||
61 | } | ||||
62 | | ||||
55 | RowLayout { | 63 | RowLayout { | ||
56 | id: buttonPreviewRow | 64 | id: buttonPreviewRow | ||
57 | anchors.top: parent.top; | 65 | anchors { | ||
58 | anchors.left: parent.left; | 66 | margins: titleBarSpacing | ||
59 | anchors.right: parent.right; | 67 | left: parent.left | ||
60 | anchors.margins: units.smallSpacing / 2 | 68 | right: parent.right | ||
61 | height: Math.max(units.iconSizes.small, titlebar.implicitHeight) + units.smallSpacing/2 | 69 | top: parent.top | ||
70 | } | ||||
71 | | ||||
62 | ButtonGroup { | 72 | ButtonGroup { | ||
63 | id: leftButtonsView | 73 | id: leftButtonsView | ||
64 | height: buttonPreviewRow.height | 74 | iconSize: buttonIconSize | ||
65 | model: leftButtons | 75 | model: kcm.leftButtonsModel | ||
66 | key: "decoButtonLeft" | 76 | key: "decoButtonLeft" | ||
67 | } | 77 | } | ||
68 | QQC2.Label { | 78 | Controls.Label { | ||
69 | id: titlebar | 79 | id: titleBarLabel | ||
70 | Layout.fillWidth: true | 80 | Layout.fillWidth: true | ||
71 | horizontalAlignment: Text.AlignHCenter | 81 | horizontalAlignment: Text.AlignHCenter | ||
72 | font: titleFont | 82 | font.bold: true | ||
73 | text: i18n("Titlebar") | 83 | text: i18n("Titlebar") | ||
74 | } | 84 | } | ||
75 | | ||||
76 | ButtonGroup { | 85 | ButtonGroup { | ||
77 | id: rightButtonsView | 86 | id: rightButtonsView | ||
78 | height: buttonPreviewRow.height | 87 | iconSize: buttonIconSize | ||
79 | model: rightButtons | 88 | model: kcm.rightButtonsModel | ||
80 | key: "decoButtonRight" | 89 | key: "decoButtonRight" | ||
81 | } | 90 | } | ||
82 | } | 91 | } | ||
83 | DropArea { | 92 | DropArea { | ||
93 | id: titleBarDropArea | ||||
84 | anchors { | 94 | anchors { | ||
85 | fill: titlebarRect | 95 | fill: parent | ||
86 | leftMargin: -units.iconSizes.small | 96 | margins: -titleBarSpacing | ||
87 | topMargin: -units.iconSizes.small | | |||
88 | rightMargin: +units.iconSizes.small | | |||
89 | bottomMargin: +units.iconSizes.small | | |||
90 | } | 97 | } | ||
91 | keys: [ "decoButtonAdd", "decoButtonRight", "decoButtonLeft" ] | 98 | keys: [ "decoButtonAdd", "decoButtonRight", "decoButtonLeft" ] | ||
92 | onEntered: { | 99 | onEntered: { | ||
93 | drag.accept(); | 100 | drag.accept(); | ||
94 | } | 101 | } | ||
95 | onDropped: { | 102 | onDropped: { | ||
96 | var view = undefined; | 103 | var view = undefined; | ||
97 | var left = drag.x - (leftButtonsView.x + leftButtonsView.width); | 104 | var left = drag.x - (leftButtonsView.x + leftButtonsView.width); | ||
98 | var right = drag.x - rightButtonsView.x; | 105 | var right = drag.x - rightButtonsView.x; | ||
99 | if (Math.abs(left) <= Math.abs(right)) { | 106 | if (Math.abs(left) <= Math.abs(right)) { | ||
100 | view = leftButtonsView; | 107 | view = leftButtonsView; | ||
101 | } else { | 108 | } else { | ||
102 | view = rightButtonsView; | 109 | view = rightButtonsView; | ||
103 | } | 110 | } | ||
104 | if (!view) { | 111 | if (!view) { | ||
105 | return; | 112 | return; | ||
106 | } | 113 | } | ||
107 | var point = mapToItem(view, drag.x, drag.y); | 114 | var point = mapToItem(view, drag.x, drag.y); | ||
108 | var index = view.indexAt(point.x, point.y); | 115 | var index = 0 | ||
109 | if (index == -1 && (view.x + view.width <= drag.x)) { | 116 | for(var childIndex = 0 ; childIndex < (view.count - 1) ; childIndex++) { | ||
110 | index = view.count - 1; | 117 | var child = view.contentItem.children[childIndex] | ||
118 | if (child.x > point.x) { | ||||
119 | break | ||||
120 | } | ||||
121 | index = childIndex + 1 | ||||
111 | } | 122 | } | ||
112 | if (drop.keys.indexOf("decoButtonAdd") != -1) { | 123 | if (drop.keys.indexOf("decoButtonAdd") != -1) { | ||
113 | view.model.add(index, drag.source.type); | 124 | view.model.add(index, drag.source.type); | ||
114 | } else if (drop.keys.indexOf("decoButtonLeft") != -1) { | 125 | } else if (drop.keys.indexOf("decoButtonLeft") != -1) { | ||
115 | if (view == leftButtonsView) { | 126 | if (view == leftButtonsView) { | ||
116 | // move in same view | 127 | // move in same view | ||
117 | if (index != drag.source.itemIndex) { | 128 | if (index != drag.source.itemIndex) { | ||
118 | drag.source.buttonsModel.move(drag.source.itemIndex, index); | 129 | drag.source.buttonsModel.move(drag.source.itemIndex, index); | ||
Show All 14 Lines | 142 | } else { | |||
133 | view.model.add(index, drag.source.type); | 144 | view.model.add(index, drag.source.type); | ||
134 | drag.source.buttonsModel.remove(drag.source.itemIndex); | 145 | drag.source.buttonsModel.remove(drag.source.itemIndex); | ||
135 | } | 146 | } | ||
136 | } | 147 | } | ||
137 | } | 148 | } | ||
138 | } | 149 | } | ||
139 | } | 150 | } | ||
140 | GridView { | 151 | GridView { | ||
141 | id: availableGrid | 152 | id: availableButtonsGrid | ||
142 | Layout.fillWidth: true | 153 | Layout.fillWidth: true | ||
143 | model: availableButtons | 154 | Layout.minimumHeight: availableButtonsGrid.cellHeight * 2 | ||
155 | Layout.margins: units.largeSpacing | ||||
156 | model: kcm.availableButtonsModel | ||||
144 | interactive: false | 157 | interactive: false | ||
145 | height: Math.ceil(cellHeight * 3) | | |||
146 | delegate: Item { | 158 | delegate: Item { | ||
147 | id: availableDelegate | 159 | id: availableDelegate | ||
148 | Layout.margins: units.gridUnit | 160 | Layout.margins: units.largeSpacing | ||
149 | width: availableGrid.cellWidth | 161 | width: availableButtonsGrid.cellWidth | ||
150 | height: availableGrid.cellHeight | 162 | height: availableButtonsGrid.cellHeight | ||
151 | opacity: (leftButtonsView.dragging || rightButtonsView.dragging) ? 0.25 : 1.0 | 163 | opacity: (leftButtonsView.dragging || rightButtonsView.dragging) ? 0.25 : 1.0 | ||
164 | Rectangle { | ||||
165 | id: availableButtonFrame | ||||
166 | anchors.horizontalCenter: parent.horizontalCenter | ||||
167 | color: palette.window | ||||
168 | radius: units.smallSpacing | ||||
169 | width: buttonIconSize + units.largeSpacing | ||||
170 | height: buttonIconSize + units.largeSpacing | ||||
171 | | ||||
152 | KDecoration.Button { | 172 | KDecoration.Button { | ||
153 | id: availableButton | 173 | id: availableButton | ||
154 | anchors.centerIn: Drag.active ? undefined : parent | 174 | anchors.centerIn: Drag.active ? undefined : availableButtonFrame | ||
155 | bridge: bridgeItem.bridge | 175 | bridge: bridgeItem.bridge | ||
156 | settings: settingsItem | 176 | settings: settingsItem | ||
157 | type: model["button"] | 177 | type: model["button"] | ||
158 | width: units.iconSizes.small | 178 | width: buttonIconSize | ||
159 | height: units.iconSizes.small | 179 | height: buttonIconSize | ||
160 | Drag.keys: [ "decoButtonAdd" ] | 180 | Drag.keys: [ "decoButtonAdd" ] | ||
161 | Drag.active: dragArea.drag.active | 181 | Drag.active: dragArea.drag.active | ||
162 | } | 182 | color: palette.windowText | ||
163 | QQC2.Label { | | |||
164 | id: iconLabel | | |||
165 | text: model["display"] | | |||
166 | horizontalAlignment: Text.AlignHCenter | | |||
167 | verticalAlignment: Text.AlignTop | | |||
168 | anchors.bottom: parent.bottom | | |||
169 | anchors.left: parent.left | | |||
170 | anchors.right: parent.right | | |||
171 | elide: Text.ElideRight | | |||
172 | wrapMode: Text.Wrap | | |||
173 | height: 2 * dragHint.implicitHeight + lineHeight | | |||
174 | } | 183 | } | ||
175 | MouseArea { | 184 | MouseArea { | ||
176 | id: dragArea | 185 | id: dragArea | ||
177 | anchors.fill: availableButton | 186 | anchors.fill: availableButton | ||
178 | drag.target: availableButton | 187 | drag.target: availableButton | ||
179 | cursorShape: Qt.SizeAllCursor | 188 | cursorShape: Qt.SizeAllCursor | ||
180 | onReleased: { | 189 | onReleased: { | ||
181 | if (availableButton.Drag.target) { | 190 | if (availableButton.Drag.target) { | ||
182 | availableButton.Drag.drop(); | 191 | availableButton.Drag.drop(); | ||
183 | } else { | 192 | } else { | ||
184 | availableButton.Drag.cancel(); | 193 | availableButton.Drag.cancel(); | ||
185 | } | 194 | } | ||
186 | } | 195 | } | ||
187 | } | 196 | } | ||
188 | } | 197 | } | ||
198 | Controls.Label { | ||||
199 | id: iconLabel | ||||
200 | text: model["display"] | ||||
201 | horizontalAlignment: Text.AlignHCenter | ||||
202 | verticalAlignment: Text.AlignTop | ||||
203 | anchors.top: availableButtonFrame.bottom | ||||
204 | anchors.topMargin: units.smallSpacing | ||||
205 | anchors.left: parent.left | ||||
206 | anchors.right: parent.right | ||||
207 | elide: Text.ElideRight | ||||
208 | wrapMode: Text.Wrap | ||||
209 | height: 2 * implicitHeight + lineHeight | ||||
210 | } | ||||
211 | } | ||||
189 | DropArea { | 212 | DropArea { | ||
190 | anchors.fill: parent | 213 | anchors.fill: parent | ||
191 | keys: [ "decoButtonRemove" ] | 214 | keys: [ "decoButtonRemove" ] | ||
192 | onEntered: { | 215 | onEntered: { | ||
193 | drag.accept(); | 216 | drag.accept(); | ||
194 | } | 217 | } | ||
195 | onDropped: { | 218 | onDropped: { | ||
196 | drag.source.buttonsModel.remove(drag.source.itemIndex); | 219 | drag.source.buttonsModel.remove(drag.source.itemIndex); | ||
197 | } | 220 | } | ||
198 | ColumnLayout { | 221 | ColumnLayout { | ||
199 | anchors.centerIn: parent | 222 | anchors.centerIn: parent | ||
200 | opacity: (leftButtonsView.dragging || rightButtonsView.dragging) ? 1.0 : 0.0 | 223 | opacity: (leftButtonsView.dragging || rightButtonsView.dragging) ? 1.0 : 0.0 | ||
201 | QQC2.Label { | 224 | Controls.Label { | ||
202 | text: i18n("Drop here to remove button") | 225 | text: i18n("Drop here to remove button") | ||
203 | font.weight: Font.Bold | 226 | font.weight: Font.Bold | ||
204 | Layout.bottomMargin: units.smallSpacing | 227 | Layout.bottomMargin: units.smallSpacing | ||
205 | } | 228 | } | ||
206 | KQuickControlsAddons.QIconItem { | 229 | PlasmaCore.IconItem { | ||
207 | id: icon | 230 | id: icon | ||
208 | width: units.iconSizes.smallMedium | 231 | width: units.iconSizes.smallMedium | ||
209 | height: units.iconSizes.smallMedium | 232 | height: units.iconSizes.smallMedium | ||
210 | icon: "emblem-remove" | | |||
211 | Layout.alignment: Qt.AlignHCenter | 233 | Layout.alignment: Qt.AlignHCenter | ||
234 | source: "emblem-remove" | ||||
212 | } | 235 | } | ||
213 | Item { | 236 | Item { | ||
214 | Layout.fillHeight: true | 237 | Layout.fillHeight: true | ||
215 | } | 238 | } | ||
216 | } | 239 | } | ||
217 | } | 240 | } | ||
218 | } | 241 | } | ||
219 | Text { | 242 | Text { | ||
220 | id: dragHint | 243 | id: dragHint | ||
221 | opacity: (leftButtonsView.dragging || rightButtonsView.dragging || availableGrid.dragging) ? 0.0 : 0.50 | 244 | color: palette.windowText | ||
245 | opacity: (leftButtonsView.dragging || rightButtonsView.dragging || availableButtonsGrid.dragging) ? 0.0 : 1.0 | ||||
222 | Layout.fillWidth: true | 246 | Layout.fillWidth: true | ||
223 | Layout.bottomMargin: units.smallSpacing | 247 | Layout.topMargin: titleBarSpacing | ||
248 | Layout.bottomMargin: titleBarSpacing | ||||
224 | horizontalAlignment: Text.AlignHCenter | 249 | horizontalAlignment: Text.AlignHCenter | ||
225 | verticalAlignment: Text.AlignTop | | |||
226 | wrapMode: Text.NoWrap | 250 | wrapMode: Text.NoWrap | ||
227 | text: i18n("Drag buttons between here and the titlebar") | 251 | text: i18n("Drag buttons between here and the titlebar") | ||
228 | } | 252 | } | ||
229 | } | 253 | } | ||
230 | } | 254 | } | ||
231 | } | 255 | } |