2014-12-09 15:07:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License or (at your option) version 3 or any later version
|
|
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
|
|
* defined in Section 14 of version 3 of the license.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2015-01-27 13:08:12 +00:00
|
|
|
import QtQuick 2.3
|
2014-12-09 15:07:27 +00:00
|
|
|
import QtQuick.Controls 1.2
|
2018-08-15 07:45:22 +00:00
|
|
|
import QtQuick.Controls 2.0 as QQC2
|
2014-12-09 15:07:27 +00:00
|
|
|
import QtQuick.Layouts 1.1
|
|
|
|
import org.kde.kwin.private.kdecoration 1.0 as KDecoration
|
|
|
|
import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons;
|
|
|
|
|
|
|
|
Item {
|
2015-09-24 12:21:52 +00:00
|
|
|
objectName: "buttonLayout"
|
2014-12-09 15:07:27 +00:00
|
|
|
Layout.preferredHeight: layout.height
|
|
|
|
KDecoration.Bridge {
|
|
|
|
id: bridgeItem
|
|
|
|
plugin: "org.kde.breeze"
|
|
|
|
}
|
|
|
|
KDecoration.Settings {
|
|
|
|
id: settingsItem
|
2015-10-20 12:22:05 +00:00
|
|
|
bridge: bridgeItem.bridge
|
2014-12-09 15:07:27 +00:00
|
|
|
}
|
2015-01-16 01:20:15 +00:00
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.topMargin: units.gridUnit / 2
|
|
|
|
border.width: Math.ceil(units.gridUnit / 16.0)
|
2017-03-21 18:45:45 +00:00
|
|
|
color: backgroundColor;
|
2015-01-16 01:20:15 +00:00
|
|
|
border.color: highlightColor;
|
|
|
|
ColumnLayout {
|
|
|
|
id: layout
|
2014-12-09 15:07:27 +00:00
|
|
|
width: parent.width
|
2015-01-16 01:20:15 +00:00
|
|
|
height: titlebarRect.height + availableGrid.height + dragHint.height + 5*layout.spacing
|
|
|
|
Rectangle {
|
|
|
|
id: titlebarRect
|
|
|
|
height: buttonPreviewRow.height + units.smallSpacing
|
2014-12-09 15:07:27 +00:00
|
|
|
Layout.fillWidth: true
|
2015-01-16 01:20:15 +00:00
|
|
|
border.width: Math.ceil(units.gridUnit / 16.0)
|
|
|
|
border.color: highlightColor
|
2017-03-21 18:45:45 +00:00
|
|
|
color: backgroundColor;
|
2015-01-16 01:20:15 +00:00
|
|
|
RowLayout {
|
|
|
|
id: buttonPreviewRow
|
|
|
|
anchors.top: parent.top;
|
|
|
|
anchors.left: parent.left;
|
|
|
|
anchors.right: parent.right;
|
|
|
|
anchors.margins: units.smallSpacing / 2
|
|
|
|
height: Math.max(units.iconSizes.small, titlebar.implicitHeight) + units.smallSpacing/2
|
|
|
|
ButtonGroup {
|
|
|
|
id: leftButtonsView
|
|
|
|
height: buttonPreviewRow.height
|
2017-02-10 09:52:48 +00:00
|
|
|
model: leftButtons
|
2015-01-16 01:20:15 +00:00
|
|
|
key: "decoButtonLeft"
|
2014-12-09 15:07:27 +00:00
|
|
|
}
|
2018-08-15 08:34:03 +00:00
|
|
|
QQC2.Label {
|
2018-04-18 09:57:30 +00:00
|
|
|
id: titlebar
|
2015-01-16 01:20:15 +00:00
|
|
|
Layout.fillWidth: true
|
2018-04-18 09:57:30 +00:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
font: titleFont
|
|
|
|
text: i18n("Titlebar")
|
2014-12-09 15:07:27 +00:00
|
|
|
}
|
2018-04-18 09:57:30 +00:00
|
|
|
|
2015-01-16 01:20:15 +00:00
|
|
|
ButtonGroup {
|
|
|
|
id: rightButtonsView
|
|
|
|
height: buttonPreviewRow.height
|
2017-02-10 09:52:48 +00:00
|
|
|
model: rightButtons
|
2015-01-16 01:20:15 +00:00
|
|
|
key: "decoButtonRight"
|
2014-12-09 15:07:27 +00:00
|
|
|
}
|
2018-04-18 09:57:30 +00:00
|
|
|
}
|
|
|
|
DropArea {
|
|
|
|
anchors.fill: buttonPreviewRow
|
|
|
|
keys: [ "decoButtonAdd", "decoButtonRight", "decoButtonLeft" ]
|
|
|
|
onEntered: {
|
|
|
|
drag.accept();
|
|
|
|
}
|
|
|
|
onDropped: {
|
|
|
|
var view = undefined;
|
|
|
|
var left = drag.x - (leftButtonsView.x + leftButtonsView.width);
|
|
|
|
var right = drag.x - rightButtonsView.x;
|
|
|
|
if (Math.abs(left) <= Math.abs(right)) {
|
|
|
|
view = leftButtonsView;
|
|
|
|
} else {
|
|
|
|
view = rightButtonsView;
|
2014-12-09 15:07:27 +00:00
|
|
|
}
|
2018-04-18 09:57:30 +00:00
|
|
|
if (!view) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var point = mapToItem(view, drag.x, drag.y);
|
|
|
|
var index = view.indexAt(point.x, point.y);
|
|
|
|
if (index == -1 && (view.x + view.width <= drag.x)) {
|
|
|
|
index = view.count - 1;
|
|
|
|
}
|
|
|
|
if (drop.keys.indexOf("decoButtonAdd") != -1) {
|
|
|
|
view.model.add(index, drag.source.type);
|
|
|
|
} else if (drop.keys.indexOf("decoButtonLeft") != -1) {
|
|
|
|
if (view == leftButtonsView) {
|
|
|
|
// move in same view
|
|
|
|
if (index != drag.source.itemIndex) {
|
|
|
|
drag.source.buttonsModel.move(drag.source.itemIndex, index);
|
2015-01-16 01:20:15 +00:00
|
|
|
}
|
2018-04-18 09:57:30 +00:00
|
|
|
} else {
|
|
|
|
// move to right view
|
|
|
|
view.model.add(index, drag.source.type);
|
|
|
|
drag.source.buttonsModel.remove(drag.source.itemIndex);
|
|
|
|
}
|
|
|
|
} else if (drop.keys.indexOf("decoButtonRight") != -1) {
|
|
|
|
if (view == rightButtonsView) {
|
|
|
|
// move in same view
|
|
|
|
if (index != drag.source.itemIndex) {
|
|
|
|
drag.source.buttonsModel.move(drag.source.itemIndex, index);
|
2015-01-16 01:20:15 +00:00
|
|
|
}
|
2018-04-18 09:57:30 +00:00
|
|
|
} else {
|
|
|
|
// move to right view
|
|
|
|
view.model.add(index, drag.source.type);
|
|
|
|
drag.source.buttonsModel.remove(drag.source.itemIndex);
|
2014-12-09 15:07:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-16 01:20:15 +00:00
|
|
|
Text {
|
|
|
|
id: iCannotBelieveIDoThis
|
|
|
|
text: "gnarf"
|
|
|
|
visible: false
|
|
|
|
}
|
|
|
|
GridView {
|
|
|
|
id: availableGrid
|
|
|
|
Layout.fillWidth: true
|
2017-02-10 09:52:48 +00:00
|
|
|
model: availableButtons
|
2015-01-16 01:20:15 +00:00
|
|
|
interactive: false
|
|
|
|
cellWidth: iconLabel.implicitWidth
|
|
|
|
cellHeight: units.iconSizes.small + iCannotBelieveIDoThis.implicitHeight + 4*units.smallSpacing
|
|
|
|
height: Math.ceil(cellHeight * 2.5)
|
|
|
|
delegate: Item {
|
|
|
|
id: availableDelegate
|
|
|
|
width: availableGrid.cellWidth
|
|
|
|
height: availableGrid.cellHeight
|
2018-04-18 09:57:30 +00:00
|
|
|
opacity: (leftButtonsView.dragging || rightButtonsView.dragging) ? 0.25 : 1.0
|
2015-01-16 01:20:15 +00:00
|
|
|
KDecoration.Button {
|
|
|
|
id: availableButton
|
|
|
|
anchors.centerIn: Drag.active ? undefined : parent
|
2015-10-20 12:22:05 +00:00
|
|
|
bridge: bridgeItem.bridge
|
2015-01-16 01:20:15 +00:00
|
|
|
settings: settingsItem
|
|
|
|
type: model["button"]
|
|
|
|
width: units.iconSizes.small
|
|
|
|
height: units.iconSizes.small
|
|
|
|
Drag.keys: [ "decoButtonAdd" ]
|
|
|
|
Drag.active: dragArea.drag.active
|
|
|
|
}
|
2018-08-15 07:45:22 +00:00
|
|
|
QQC2.Label {
|
2015-01-16 01:20:15 +00:00
|
|
|
id: iconLabel
|
|
|
|
text: model["display"]
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
elide: Text.ElideRight
|
2015-01-28 23:51:14 +00:00
|
|
|
wrapMode: Text.NoWrap
|
2015-01-16 01:20:15 +00:00
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
id: dragArea
|
|
|
|
anchors.fill: parent
|
|
|
|
drag.target: availableButton
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
onReleased: {
|
|
|
|
if (availableButton.Drag.target) {
|
|
|
|
availableButton.Drag.drop();
|
|
|
|
} else {
|
|
|
|
availableButton.Drag.cancel();
|
|
|
|
}
|
2014-12-09 15:07:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-18 09:57:30 +00:00
|
|
|
DropArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
keys: [ "decoButtonRemove" ]
|
|
|
|
onEntered: {
|
|
|
|
drag.accept();
|
|
|
|
}
|
|
|
|
onDropped: {
|
|
|
|
drag.source.buttonsModel.remove(drag.source.itemIndex);
|
|
|
|
}
|
|
|
|
ColumnLayout {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
visible: leftButtonsView.dragging || rightButtonsView.dragging
|
2018-08-15 08:34:03 +00:00
|
|
|
QQC2.Label {
|
2018-04-18 09:57:30 +00:00
|
|
|
text: i18n("Drop here to remove button")
|
2018-08-15 08:34:03 +00:00
|
|
|
font.weight: Font.Bold
|
2018-04-18 09:57:30 +00:00
|
|
|
}
|
|
|
|
KQuickControlsAddons.QIconItem {
|
|
|
|
id: icon
|
|
|
|
width: 64
|
|
|
|
height: 64
|
|
|
|
icon: "list-remove"
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
}
|
|
|
|
Item {
|
|
|
|
Layout.fillHeight: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-09 15:07:27 +00:00
|
|
|
}
|
2015-01-16 01:20:15 +00:00
|
|
|
Text {
|
|
|
|
id: dragHint
|
|
|
|
visible: !(leftButtonsView.dragging || rightButtonsView.dragging || availableGrid.dragging)
|
|
|
|
Layout.fillWidth: true
|
2017-03-21 18:45:45 +00:00
|
|
|
color: backgroundColor;
|
2015-01-16 01:20:15 +00:00
|
|
|
opacity: 0.66
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
verticalAlignment: Text.AlignTop
|
|
|
|
text: i18n("Drag buttons between here and the titlebar")
|
2014-12-09 15:07:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|