Warning, /plasma/kwin/src/kcms/decoration/ui/Buttons.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0003 SPDX-FileCopyrightText: 2019 Valerio Pilo <vpilo@coldshock.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 import QtQuick 0008 import QtQuick.Layouts 0009 import QtQuick.Controls as QQC2 0010 0011 import org.kde.kcmutils as KCM 0012 import org.kde.kirigami 2.20 as Kirigami 0013 import org.kde.kwin.private.kdecoration as KDecoration 0014 0015 // Fake Window 0016 Rectangle { 0017 id: baseLayout 0018 0019 readonly property int buttonIconSize: Kirigami.Units.iconSizes.medium 0020 readonly property int titleBarSpacing: Kirigami.Units.largeSpacing 0021 readonly property bool draggingTitlebarButtons: leftButtonsView.dragActive || rightButtonsView.dragActive 0022 readonly property bool hideDragHint: draggingTitlebarButtons || availableButtonsGrid.dragActive 0023 0024 color: palette.base 0025 radius: Kirigami.Units.smallSpacing 0026 0027 KDecoration.Bridge { 0028 id: bridgeItem 0029 plugin: "org.kde.breeze" 0030 } 0031 KDecoration.Settings { 0032 id: settingsItem 0033 bridge: bridgeItem.bridge 0034 } 0035 0036 ColumnLayout { 0037 anchors.fill: parent 0038 0039 // Fake titlebar 0040 Rectangle { 0041 Layout.fillWidth: true 0042 implicitHeight: buttonPreviewRow.implicitHeight + 2 * baseLayout.titleBarSpacing 0043 radius: Kirigami.Units.smallSpacing 0044 gradient: Gradient { 0045 GradientStop { position: 0.0; color: palette.midlight } 0046 GradientStop { position: 1.0; color: palette.window } 0047 } 0048 0049 RowLayout { 0050 id: buttonPreviewRow 0051 anchors { 0052 margins: baseLayout.titleBarSpacing 0053 left: parent.left 0054 right: parent.right 0055 top: parent.top 0056 } 0057 0058 ButtonGroup { 0059 id: leftButtonsView 0060 iconSize: baseLayout.buttonIconSize 0061 model: kcm.leftButtonsModel 0062 key: "decoButtonLeft" 0063 0064 Rectangle { 0065 visible: stateBindingButtonLeft.nonDefaultHighlightVisible 0066 anchors.fill: parent 0067 Layout.margins: Kirigami.Units.smallSpacing 0068 color: "transparent" 0069 border.color: Kirigami.Theme.neutralTextColor 0070 border.width: 1 0071 radius: Kirigami.Units.smallSpacing 0072 } 0073 0074 KCM.SettingStateBinding { 0075 id: stateBindingButtonLeft 0076 configObject: kcm.settings 0077 settingName: "buttonsOnLeft" 0078 } 0079 } 0080 0081 QQC2.Label { 0082 Layout.fillWidth: true 0083 horizontalAlignment: Text.AlignHCenter 0084 font.bold: true 0085 text: i18n("Titlebar") 0086 } 0087 ButtonGroup { 0088 id: rightButtonsView 0089 iconSize: baseLayout.buttonIconSize 0090 model: kcm.rightButtonsModel 0091 key: "decoButtonRight" 0092 0093 Rectangle { 0094 visible: stateBindingButtonRight.nonDefaultHighlightVisible 0095 anchors.fill: parent 0096 Layout.margins: Kirigami.Units.smallSpacing 0097 color: "transparent" 0098 border.color: Kirigami.Theme.neutralTextColor 0099 border.width: 1 0100 radius: Kirigami.Units.smallSpacing 0101 } 0102 0103 KCM.SettingStateBinding { 0104 id: stateBindingButtonRight 0105 configObject: kcm.settings 0106 settingName: "buttonsOnRight" 0107 } 0108 } 0109 } 0110 DropArea { 0111 id: titleBarDropArea 0112 anchors { 0113 fill: parent 0114 margins: -baseLayout.titleBarSpacing 0115 } 0116 keys: [ "decoButtonAdd", "decoButtonRight", "decoButtonLeft" ] 0117 onEntered: { 0118 drag.accept(); 0119 } 0120 onDropped: { 0121 var view = undefined; 0122 var left = drag.x - (leftButtonsView.x + leftButtonsView.width); 0123 var right = drag.x - rightButtonsView.x; 0124 if (Math.abs(left) <= Math.abs(right)) { 0125 if (leftButtonsView.enabled) { 0126 view = leftButtonsView; 0127 } 0128 } else { 0129 if (rightButtonsView.enabled) { 0130 view = rightButtonsView; 0131 } 0132 } 0133 if (!view) { 0134 return; 0135 } 0136 var point = mapToItem(view, drag.x, drag.y); 0137 var index = 0 0138 for(var childIndex = 0 ; childIndex < (view.count - 1) ; childIndex++) { 0139 var child = view.contentItem.children[childIndex] 0140 if (child.x > point.x) { 0141 break 0142 } 0143 index = childIndex + 1 0144 } 0145 if (drop.keys.indexOf("decoButtonAdd") !== -1) { 0146 view.model.add(index, drag.source.type); 0147 } else if (drop.keys.indexOf("decoButtonLeft") !== -1) { 0148 if (view === leftButtonsView) { 0149 // move in same view 0150 if (index !== drag.source.itemIndex) { 0151 drag.source.buttonsModel.move(drag.source.itemIndex, index); 0152 } 0153 } else { 0154 // move to right view 0155 view.model.add(index, drag.source.type); 0156 drag.source.buttonsModel.remove(drag.source.itemIndex); 0157 } 0158 } else if (drop.keys.indexOf("decoButtonRight") !== -1) { 0159 if (view === rightButtonsView) { 0160 // move in same view 0161 if (index !== drag.source.itemIndex) { 0162 drag.source.buttonsModel.move(drag.source.itemIndex, index); 0163 } 0164 } else { 0165 // move to left view 0166 view.model.add(index, drag.source.type); 0167 drag.source.buttonsModel.remove(drag.source.itemIndex); 0168 } 0169 } 0170 } 0171 } 0172 } 0173 GridView { 0174 id: availableButtonsGrid 0175 property bool dragActive: false 0176 Layout.fillWidth: true 0177 Layout.fillHeight: true 0178 Layout.minimumHeight: availableButtonsGrid.cellHeight * 2 0179 Layout.margins: Kirigami.Units.largeSpacing 0180 cellWidth: Kirigami.Units.gridUnit * 6 0181 cellHeight: Kirigami.Units.gridUnit * 6 0182 model: kcm.availableButtonsModel 0183 interactive: false 0184 0185 delegate: ColumnLayout { 0186 width: availableButtonsGrid.cellWidth - Kirigami.Units.largeSpacing 0187 height: availableButtonsGrid.cellHeight - Kirigami.Units.largeSpacing 0188 opacity: baseLayout.draggingTitlebarButtons ? 0.15 : 1.0 0189 0190 Rectangle { 0191 Layout.alignment: Qt.AlignHCenter 0192 color: palette.window 0193 radius: Kirigami.Units.smallSpacing 0194 implicitWidth: baseLayout.buttonIconSize + Kirigami.Units.largeSpacing 0195 implicitHeight: baseLayout.buttonIconSize + Kirigami.Units.largeSpacing 0196 0197 KDecoration.Button { 0198 id: availableButton 0199 anchors.centerIn: Drag.active ? undefined : parent 0200 bridge: bridgeItem.bridge 0201 settings: settingsItem 0202 type: model["button"] 0203 width: baseLayout.buttonIconSize 0204 height: baseLayout.buttonIconSize 0205 Drag.keys: [ "decoButtonAdd" ] 0206 Drag.active: dragArea.drag.active 0207 Drag.onActiveChanged: availableButtonsGrid.dragActive = Drag.active 0208 color: palette.windowText 0209 } 0210 MouseArea { 0211 id: dragArea 0212 anchors.fill: availableButton 0213 drag.target: availableButton 0214 cursorShape: Qt.SizeAllCursor 0215 onReleased: { 0216 if (availableButton.Drag.target) { 0217 availableButton.Drag.drop(); 0218 } else { 0219 availableButton.Drag.cancel(); 0220 } 0221 } 0222 } 0223 } 0224 QQC2.Label { 0225 id: iconLabel 0226 text: model["display"] 0227 Layout.fillWidth: true 0228 Layout.fillHeight: true 0229 horizontalAlignment: Text.AlignHCenter 0230 verticalAlignment: Text.AlignTop 0231 elide: Text.ElideRight 0232 wrapMode: Text.Wrap 0233 } 0234 } 0235 DropArea { 0236 anchors.fill: parent 0237 keys: [ "decoButtonRemove" ] 0238 onEntered: { 0239 drag.accept(); 0240 } 0241 onDropped: { 0242 drag.source.buttonsModel.remove(drag.source.itemIndex); 0243 } 0244 Kirigami.Heading { 0245 text: i18n("Drop button here to remove it") 0246 font.weight: Font.Bold 0247 level: 2 0248 anchors.centerIn: parent 0249 opacity: baseLayout.draggingTitlebarButtons ? 1.0 : 0.0 0250 } 0251 } 0252 } 0253 Text { 0254 id: dragHint 0255 readonly property real dragHintOpacitiy: enabled ? 1.0 : 0.3 0256 color: palette.windowText 0257 opacity: baseLayout.hideDragHint ? 0.0 : dragHintOpacitiy 0258 Layout.fillWidth: true 0259 Layout.margins: Kirigami.Units.gridUnit * 3 0260 horizontalAlignment: Text.AlignHCenter 0261 text: i18n("Drag buttons between here and the titlebar") 0262 } 0263 } 0264 }