| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2017 Malte Veerman <[email protected]> * |
| 3 |
* * |
| 4 |
* This program is free software; you can redistribute it and/or modify it under * |
| 5 |
* the terms of the GNU General Public License as published by the Free Software * |
| 6 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 7 |
* version. * |
| 8 |
* * |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 10 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 11 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 12 |
* * |
| 13 |
* You should have received a copy of the GNU General Public License along with * |
| 14 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 15 |
****************************************************************************************/ |
| 16 |
|
| 17 |
import QtQuick 2.15 |
| 18 |
import QtQuick.Controls 2.15 |
| 19 |
import QtQuick.Layouts 1.15 |
| 20 |
import org.kde.kirigami 2.14 as Kirigami |
| 21 |
|
| 22 |
|
| 23 |
MouseArea { |
| 24 |
id: root |
| 25 |
|
| 26 |
property alias name: label.text |
| 27 |
property string appletId |
| 28 |
property var toolbar |
| 29 |
property var flickable |
| 30 |
property bool configEnabled: !!toolbar ? toolbar.configEnabled : false |
| 31 |
property bool held: false |
| 32 |
|
| 33 |
height: toolbar.height - Kirigami.Units.smallSpacing; |
| 34 |
anchors.verticalCenter: parent.verticalCenter |
| 35 |
implicitWidth: label.implicitWidth + Kirigami.Units.smallSpacing * 2 |
| 36 |
|
| 37 |
acceptedButtons: Qt.LeftButton |
| 38 |
hoverEnabled: true |
| 39 |
drag.target: held ? content : undefined |
| 40 |
drag.axis: Drag.XAxis |
| 41 |
cursorShape: configEnabled ? held ? Qt.ClosedHandCursor : Qt.PointingHandCursor : Qt.ArrowCursor |
| 42 |
pressAndHoldInterval: 200; |
| 43 |
|
| 44 |
onPressAndHold: if (configEnabled) { held = true; toolbarAppletRow.interactive = false; height = toolbar.height; } |
| 45 |
onReleased: { toolbarAppletRow.interactive = true; held = false; height = toolbar.height - Kirigami.Units.smallSpacing; } |
| 46 |
onPressed: if (!configEnabled) flickable.scrollToApplet(appletId) |
| 47 |
onImplicitWidthChanged: toolbar.resizeApplets() |
| 48 |
|
| 49 |
DropArea { |
| 50 |
anchors { |
| 51 |
fill: parent |
| 52 |
leftMargin: Kirigami.Units.smallSpacing |
| 53 |
rightMargin: Kirigami.Units.smallSpacing |
| 54 |
} |
| 55 |
|
| 56 |
onEntered: { |
| 57 |
AppletProxyModel.setAppletPlace(drag.source.appletId, AppletProxyModel.appletPlace(root.appletId)); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
Rectangle { |
| 62 |
id: content |
| 63 |
|
| 64 |
readonly property string appletId: root.appletId |
| 65 |
|
| 66 |
border.width: 1 |
| 67 |
color: root.pressed ? palette.highlight : palette.button |
| 68 |
border.color: root.containsMouse ? palette.highlight : palette.buttonText |
| 69 |
radius: Kirigami.Units.smallSpacing / 2 |
| 70 |
anchors { |
| 71 |
horizontalCenter: root.horizontalCenter |
| 72 |
verticalCenter: root.verticalCenter |
| 73 |
} |
| 74 |
width: root.width |
| 75 |
height: root.height |
| 76 |
|
| 77 |
Drag.active: root.held |
| 78 |
Drag.source: root |
| 79 |
Drag.hotSpot.x: width / 2 |
| 80 |
Drag.hotSpot.y: height / 2 |
| 81 |
|
| 82 |
states: State { |
| 83 |
when: root.held |
| 84 |
|
| 85 |
ParentChange { |
| 86 |
target: content |
| 87 |
parent: contextRoot |
| 88 |
} |
| 89 |
AnchorChanges { |
| 90 |
target: content |
| 91 |
anchors { |
| 92 |
horizontalCenter: undefined |
| 93 |
verticalCenter: undefined |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
Label { |
| 99 |
id: label |
| 100 |
color: Kirigami.Theme.textColor |
| 101 |
|
| 102 |
anchors { |
| 103 |
fill: parent |
| 104 |
leftMargin: Kirigami.Units.smallSpacing |
| 105 |
rightMargin: Kirigami.Units.smallSpacing |
| 106 |
} |
| 107 |
|
| 108 |
horizontalAlignment: Text.AlignHCenter |
| 109 |
verticalAlignment: Text.AlignVCenter |
| 110 |
clip: true |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
SystemPalette { |
| 115 |
id: palette |
| 116 |
} |
| 117 |
} |