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 QtGraphicalEffects 1.0 as Effects | ||
25 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
24 | import org.kde.kwin.private.kdecoration 1.0 as KDecoration | 26 | import org.kde.kwin.private.kdecoration 1.0 as KDecoration | ||
25 | import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons; | | |||
26 | 27 | | |||
27 | Item { | 28 | ColumnLayout { | ||
28 | objectName: "buttonLayout" | 29 | Layout.fillWidth: true | ||
29 | Layout.preferredHeight: layout.height | 30 | Layout.fillHeight: true | ||
31 | property int buttonIconSize: units.iconSizes.medium | ||||
32 | property int titleBarSpacing: units.iconSizes.smallMedium | ||||
33 | | ||||
30 | KDecoration.Bridge { | 34 | KDecoration.Bridge { | ||
31 | id: bridgeItem | 35 | id: bridgeItem | ||
32 | plugin: "org.kde.breeze" | 36 | plugin: "org.kde.breeze" | ||
33 | } | 37 | } | ||
34 | KDecoration.Settings { | 38 | KDecoration.Settings { | ||
35 | id: settingsItem | 39 | id: settingsItem | ||
36 | bridge: bridgeItem.bridge | 40 | bridge: bridgeItem.bridge | ||
37 | } | 41 | } | ||
42 | | ||||
38 | Rectangle { | 43 | Rectangle { | ||
39 | anchors.fill: parent | 44 | Layout.fillWidth: true | ||
40 | border.width: Math.ceil(units.gridUnit / 16.0) | 45 | color: palette.base | ||
41 | border.color: highlightColor | 46 | radius: units.smallSpacing | ||
42 | color: baseColor | 47 | height: fakeWindow.height | ||
48 | Layout.margins: units.smallSpacing | ||||
49 | | ||||
43 | ColumnLayout { | 50 | ColumnLayout { | ||
44 | id: layout | 51 | id: fakeWindow | ||
45 | width: parent.width | 52 | width: parent.width | ||
46 | height: titlebarRect.height + availableGrid.height + dragHint.height + 5*layout.spacing | 53 | | ||
47 | Rectangle { | 54 | Rectangle { | ||
48 | id: titlebarRect | 55 | 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 | 56 | Layout.fillWidth: true | ||
54 | Layout.topMargin: -border.width // prevent a double top border | 57 | height: buttonPreviewRow.height + 2 * titleBarSpacing | ||
58 | radius: units.smallSpacing | ||||
59 | gradient: Gradient { | ||||
60 | GradientStop { position: 0.0; color: palette.midlight } | ||||
61 | GradientStop { position: 1.0; color: palette.window } | ||||
62 | } | ||||
63 | | ||||
55 | RowLayout { | 64 | RowLayout { | ||
56 | id: buttonPreviewRow | 65 | id: buttonPreviewRow | ||
57 | anchors.top: parent.top; | 66 | anchors { | ||
58 | anchors.left: parent.left; | 67 | margins: titleBarSpacing | ||
59 | anchors.right: parent.right; | 68 | left: parent.left | ||
60 | anchors.margins: units.smallSpacing / 2 | 69 | right: parent.right | ||
61 | height: Math.max(units.iconSizes.small, titlebar.implicitHeight) + units.smallSpacing/2 | 70 | top: parent.top | ||
71 | } | ||||
72 | | ||||
62 | ButtonGroup { | 73 | ButtonGroup { | ||
63 | id: leftButtonsView | 74 | id: leftButtonsView | ||
64 | height: buttonPreviewRow.height | 75 | iconSize: buttonIconSize | ||
65 | model: leftButtons | 76 | model: kcm.leftButtonsModel | ||
66 | key: "decoButtonLeft" | 77 | key: "decoButtonLeft" | ||
67 | } | 78 | } | ||
68 | QQC2.Label { | 79 | Controls.Label { | ||
69 | id: titlebar | 80 | id: titleBarLabel | ||
70 | Layout.fillWidth: true | 81 | Layout.fillWidth: true | ||
71 | horizontalAlignment: Text.AlignHCenter | 82 | horizontalAlignment: Text.AlignHCenter | ||
72 | font: titleFont | 83 | font.bold: true | ||
73 | text: i18n("Titlebar") | 84 | text: i18n("Titlebar") | ||
74 | } | 85 | } | ||
75 | | ||||
76 | ButtonGroup { | 86 | ButtonGroup { | ||
77 | id: rightButtonsView | 87 | id: rightButtonsView | ||
78 | height: buttonPreviewRow.height | 88 | iconSize: buttonIconSize | ||
79 | model: rightButtons | 89 | model: kcm.rightButtonsModel | ||
80 | key: "decoButtonRight" | 90 | key: "decoButtonRight" | ||
81 | } | 91 | } | ||
82 | } | 92 | } | ||
83 | DropArea { | 93 | DropArea { | ||
94 | id: titleBarDropArea | ||||
84 | anchors { | 95 | anchors { | ||
85 | fill: titlebarRect | 96 | fill: parent | ||
86 | leftMargin: -units.iconSizes.small | 97 | margins: -titleBarSpacing | ||
87 | topMargin: -units.iconSizes.small | | |||
88 | rightMargin: +units.iconSizes.small | | |||
89 | bottomMargin: +units.iconSizes.small | | |||
90 | } | 98 | } | ||
91 | keys: [ "decoButtonAdd", "decoButtonRight", "decoButtonLeft" ] | 99 | keys: [ "decoButtonAdd", "decoButtonRight", "decoButtonLeft" ] | ||
92 | onEntered: { | 100 | onEntered: { | ||
93 | drag.accept(); | 101 | drag.accept(); | ||
94 | } | 102 | } | ||
95 | onDropped: { | 103 | onDropped: { | ||
96 | var view = undefined; | 104 | var view = undefined; | ||
97 | var left = drag.x - (leftButtonsView.x + leftButtonsView.width); | 105 | var left = drag.x - (leftButtonsView.x + leftButtonsView.width); | ||
98 | var right = drag.x - rightButtonsView.x; | 106 | var right = drag.x - rightButtonsView.x; | ||
99 | if (Math.abs(left) <= Math.abs(right)) { | 107 | if (Math.abs(left) <= Math.abs(right)) { | ||
100 | view = leftButtonsView; | 108 | view = leftButtonsView; | ||
101 | } else { | 109 | } else { | ||
102 | view = rightButtonsView; | 110 | view = rightButtonsView; | ||
103 | } | 111 | } | ||
104 | if (!view) { | 112 | if (!view) { | ||
105 | return; | 113 | return; | ||
106 | } | 114 | } | ||
107 | var point = mapToItem(view, drag.x, drag.y); | 115 | var point = mapToItem(view, drag.x, drag.y); | ||
108 | var index = view.indexAt(point.x, point.y); | 116 | var index = 0 | ||
109 | if (index == -1 && (view.x + view.width <= drag.x)) { | 117 | for(var childIndex = 0 ; childIndex < (view.count - 1) ; childIndex++) { | ||
110 | index = view.count - 1; | 118 | var child = view.contentItem.children[childIndex] | ||
119 | if (child.x > point.x) { | ||||
120 | break | ||||
121 | } | ||||
122 | index = childIndex + 1 | ||||
111 | } | 123 | } | ||
112 | if (drop.keys.indexOf("decoButtonAdd") != -1) { | 124 | if (drop.keys.indexOf("decoButtonAdd") != -1) { | ||
113 | view.model.add(index, drag.source.type); | 125 | view.model.add(index, drag.source.type); | ||
114 | } else if (drop.keys.indexOf("decoButtonLeft") != -1) { | 126 | } else if (drop.keys.indexOf("decoButtonLeft") != -1) { | ||
115 | if (view == leftButtonsView) { | 127 | if (view == leftButtonsView) { | ||
116 | // move in same view | 128 | // move in same view | ||
117 | if (index != drag.source.itemIndex) { | 129 | if (index != drag.source.itemIndex) { | ||
118 | drag.source.buttonsModel.move(drag.source.itemIndex, index); | 130 | drag.source.buttonsModel.move(drag.source.itemIndex, index); | ||
Show All 14 Lines | 143 | } else { | |||
133 | view.model.add(index, drag.source.type); | 145 | view.model.add(index, drag.source.type); | ||
134 | drag.source.buttonsModel.remove(drag.source.itemIndex); | 146 | drag.source.buttonsModel.remove(drag.source.itemIndex); | ||
135 | } | 147 | } | ||
136 | } | 148 | } | ||
137 | } | 149 | } | ||
138 | } | 150 | } | ||
139 | } | 151 | } | ||
140 | GridView { | 152 | GridView { | ||
141 | id: availableGrid | 153 | id: availableButtonsGrid | ||
142 | Layout.fillWidth: true | 154 | Layout.fillWidth: true | ||
143 | model: availableButtons | 155 | Layout.minimumHeight: availableButtonsGrid.cellHeight * 2 | ||
156 | Layout.margins: units.largeSpacing | ||||
157 | model: kcm.availableButtonsModel | ||||
144 | interactive: false | 158 | interactive: false | ||
145 | height: Math.ceil(cellHeight * 3) | | |||
146 | delegate: Item { | 159 | delegate: Item { | ||
147 | id: availableDelegate | 160 | id: availableDelegate | ||
148 | Layout.margins: units.gridUnit | 161 | Layout.margins: units.largeSpacing | ||
149 | width: availableGrid.cellWidth | 162 | width: availableButtonsGrid.cellWidth | ||
150 | height: availableGrid.cellHeight | 163 | height: availableButtonsGrid.cellHeight | ||
151 | opacity: (leftButtonsView.dragging || rightButtonsView.dragging) ? 0.25 : 1.0 | 164 | opacity: (leftButtonsView.dragging || rightButtonsView.dragging) ? 0.25 : 1.0 | ||
165 | Rectangle { | ||||
166 | id: availableButtonFrame | ||||
167 | anchors.horizontalCenter: parent.horizontalCenter | ||||
168 | color: palette.window | ||||
169 | radius: units.smallSpacing | ||||
170 | width: buttonIconSize + units.largeSpacing | ||||
171 | height: buttonIconSize + units.largeSpacing | ||||
172 | | ||||
152 | KDecoration.Button { | 173 | KDecoration.Button { | ||
153 | id: availableButton | 174 | id: availableButton | ||
154 | anchors.centerIn: Drag.active ? undefined : parent | 175 | anchors.centerIn: Drag.active ? undefined : availableButtonFrame | ||
155 | bridge: bridgeItem.bridge | 176 | bridge: bridgeItem.bridge | ||
156 | settings: settingsItem | 177 | settings: settingsItem | ||
157 | type: model["button"] | 178 | type: model["button"] | ||
158 | width: units.iconSizes.small | 179 | width: buttonIconSize | ||
159 | height: units.iconSizes.small | 180 | height: buttonIconSize | ||
160 | Drag.keys: [ "decoButtonAdd" ] | 181 | Drag.keys: [ "decoButtonAdd" ] | ||
161 | Drag.active: dragArea.drag.active | 182 | Drag.active: dragArea.drag.active | ||
183 | color: palette.windowText | ||||
162 | } | 184 | } | ||
163 | QQC2.Label { | 185 | Effects.DropShadow { | ||
164 | id: iconLabel | 186 | anchors.fill: availableButton | ||
165 | text: model["display"] | 187 | horizontalOffset: 3 | ||
166 | horizontalAlignment: Text.AlignHCenter | 188 | verticalOffset: 3 | ||
167 | verticalAlignment: Text.AlignTop | 189 | radius: 8 | ||
168 | anchors.bottom: parent.bottom | 190 | color: palette.shadow | ||
169 | anchors.left: parent.left | 191 | opacity: 0.7 | ||
170 | anchors.right: parent.right | 192 | source: availableButton | ||
171 | elide: Text.ElideRight | | |||
172 | wrapMode: Text.Wrap | | |||
173 | height: 2 * dragHint.implicitHeight + lineHeight | | |||
174 | } | 193 | } | ||
175 | MouseArea { | 194 | MouseArea { | ||
176 | id: dragArea | 195 | id: dragArea | ||
177 | anchors.fill: availableButton | 196 | anchors.fill: availableButton | ||
178 | drag.target: availableButton | 197 | drag.target: availableButton | ||
179 | cursorShape: Qt.SizeAllCursor | 198 | cursorShape: Qt.SizeAllCursor | ||
180 | onReleased: { | 199 | onReleased: { | ||
181 | if (availableButton.Drag.target) { | 200 | if (availableButton.Drag.target) { | ||
182 | availableButton.Drag.drop(); | 201 | availableButton.Drag.drop(); | ||
183 | } else { | 202 | } else { | ||
184 | availableButton.Drag.cancel(); | 203 | availableButton.Drag.cancel(); | ||
185 | } | 204 | } | ||
186 | } | 205 | } | ||
187 | } | 206 | } | ||
188 | } | 207 | } | ||
208 | Controls.Label { | ||||
209 | id: iconLabel | ||||
210 | text: model["display"] | ||||
211 | horizontalAlignment: Text.AlignHCenter | ||||
212 | verticalAlignment: Text.AlignTop | ||||
213 | anchors.top: availableButtonFrame.bottom | ||||
214 | anchors.topMargin: units.smallSpacing | ||||
215 | anchors.left: parent.left | ||||
216 | anchors.right: parent.right | ||||
217 | elide: Text.ElideRight | ||||
218 | wrapMode: Text.Wrap | ||||
219 | height: 2 * implicitHeight + lineHeight | ||||
220 | } | ||||
221 | } | ||||
189 | DropArea { | 222 | DropArea { | ||
190 | anchors.fill: parent | 223 | anchors.fill: parent | ||
191 | keys: [ "decoButtonRemove" ] | 224 | keys: [ "decoButtonRemove" ] | ||
192 | onEntered: { | 225 | onEntered: { | ||
193 | drag.accept(); | 226 | drag.accept(); | ||
194 | } | 227 | } | ||
195 | onDropped: { | 228 | onDropped: { | ||
196 | drag.source.buttonsModel.remove(drag.source.itemIndex); | 229 | drag.source.buttonsModel.remove(drag.source.itemIndex); | ||
197 | } | 230 | } | ||
198 | ColumnLayout { | 231 | ColumnLayout { | ||
199 | anchors.centerIn: parent | 232 | anchors.centerIn: parent | ||
200 | opacity: (leftButtonsView.dragging || rightButtonsView.dragging) ? 1.0 : 0.0 | 233 | opacity: (leftButtonsView.dragging || rightButtonsView.dragging) ? 1.0 : 0.0 | ||
201 | QQC2.Label { | 234 | Controls.Label { | ||
202 | text: i18n("Drop here to remove button") | 235 | text: i18n("Drop here to remove button") | ||
203 | font.weight: Font.Bold | 236 | font.weight: Font.Bold | ||
204 | Layout.bottomMargin: units.smallSpacing | 237 | Layout.bottomMargin: units.smallSpacing | ||
205 | } | 238 | } | ||
206 | KQuickControlsAddons.QIconItem { | 239 | PlasmaCore.IconItem { | ||
207 | id: icon | 240 | id: icon | ||
208 | width: units.iconSizes.smallMedium | 241 | width: units.iconSizes.smallMedium | ||
209 | height: units.iconSizes.smallMedium | 242 | height: units.iconSizes.smallMedium | ||
210 | icon: "emblem-remove" | | |||
211 | Layout.alignment: Qt.AlignHCenter | 243 | Layout.alignment: Qt.AlignHCenter | ||
244 | source: "emblem-remove" | ||||
212 | } | 245 | } | ||
213 | Item { | 246 | Item { | ||
214 | Layout.fillHeight: true | 247 | Layout.fillHeight: true | ||
215 | } | 248 | } | ||
216 | } | 249 | } | ||
217 | } | 250 | } | ||
218 | } | 251 | } | ||
219 | Text { | 252 | Text { | ||
220 | id: dragHint | 253 | id: dragHint | ||
221 | opacity: (leftButtonsView.dragging || rightButtonsView.dragging || availableGrid.dragging) ? 0.0 : 0.50 | 254 | color: palette.highlight | ||
255 | opacity: (leftButtonsView.dragging || rightButtonsView.dragging || availableButtonsGrid.dragging) ? 0.0 : 1.0 | ||||
222 | Layout.fillWidth: true | 256 | Layout.fillWidth: true | ||
223 | Layout.bottomMargin: units.smallSpacing | 257 | Layout.topMargin: titleBarSpacing | ||
258 | Layout.bottomMargin: titleBarSpacing | ||||
224 | horizontalAlignment: Text.AlignHCenter | 259 | horizontalAlignment: Text.AlignHCenter | ||
225 | verticalAlignment: Text.AlignTop | | |||
226 | wrapMode: Text.NoWrap | 260 | wrapMode: Text.NoWrap | ||
227 | text: i18n("Drag buttons between here and the titlebar") | 261 | text: i18n("Drag buttons between here and the titlebar") | ||
228 | } | 262 | } | ||
229 | } | 263 | } | ||
230 | } | 264 | } | ||
231 | } | 265 | } |