shift-shell/applets/activities/contents/ui/main.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

151 lines
5.4 KiB
QML
Raw Normal View History

2016-09-05 14:05:48 +00:00
/*
2021-03-01 20:03:25 +00:00
* SPDX-FileCopyrightText: 2016 Marco Martin <notmart@gmail.com>
2016-09-05 14:05:48 +00:00
*
2021-03-01 20:03:25 +00:00
* SPDX-License-Identifier: LGPL-2.0-or-later
2016-09-05 14:05:48 +00:00
*/
2016-10-05 13:26:57 +00:00
import QtQuick 2.5
2016-09-05 14:05:48 +00:00
import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.activities 0.1 as Activities
ColumnLayout {
2016-10-05 14:47:16 +00:00
PlasmaComponents.ToolButton {
2016-10-05 15:34:32 +00:00
id: newButton
2016-10-05 14:47:16 +00:00
Layout.fillWidth: true
text: i18n("New Activity...")
onClicked: {
newEdit.visible = true;
newEdit.forceActiveFocus();
}
PlasmaComponents.TextField {
id: newEdit
visible: false
width: parent.width
onFocusChanged: {
if (!focus) {
visible = false
}
}
onAccepted: {
if (text != "") {
activityModel.addActivity(text, function(id) {
visible = false;
activityModel.setCurrentActivity(id, function() {
plasmoid.expanded = false;
});
2016-10-05 14:47:16 +00:00
});
}
}
}
}
2016-10-05 15:34:32 +00:00
MouseArea {
id: rootMouseArea
Layout.fillWidth: true
Layout.fillHeight: true
2016-10-05 15:34:32 +00:00
drag.filterChildren: true
onClicked: newEdit.visible = false
ListView {
id: listView
anchors.fill: parent
model: Activities.ActivityModel {
id: activityModel
}
delegate: MouseArea {
id: delegate
preventStealing: true
2016-10-05 15:34:32 +00:00
drag {
target: listView.count > 0 ? delegate : null
2016-10-05 15:34:32 +00:00
axis: Drag.XAxis
}
PlasmaComponents.Highlight {
visible: model.current
anchors.fill:parent
2016-10-05 13:26:57 +00:00
}
2016-10-05 15:34:32 +00:00
Connections {
target: rootMouseArea
onClicked: {
if (!delegate.contains(rootMouseArea.mapToItem(delegate, mouse.x, mouse.y))) {
edit.visible = false;
2016-10-05 13:26:57 +00:00
}
}
}
2016-10-05 15:34:32 +00:00
Connections {
target: newButton
onClicked: edit.visible = false;
}
SequentialAnimation {
id: positionAnim
property alias to: xAnim.to
XAnimator {
id: xAnim
target: delegate
from: delegate.x
2021-09-13 16:40:56 +00:00
duration: PlasmaCore.Units.longDuration
2016-10-05 15:34:32 +00:00
easing.type: Easing.InOutQuad
}
ScriptAction {
script: {
if (delegate.x < -delegate.width/2 || delegate.x > delegate.width/2) {
activityModel.removeActivity(model.id, function() {});
}
}
}
}
width: listView.width
height: Math.max(label.height, label.height)
onClicked: {
listView.currentIndex = index;
activityModel.startActivity(model.id, function() {
activityModel.setCurrentActivity(model.id, function() {
plasmoid.expanded = false;
});
});
}
2016-10-05 15:34:32 +00:00
onPressAndHold: {
edit.visible = true
edit.focus = true
2016-10-05 13:26:57 +00:00
}
2016-10-05 15:34:32 +00:00
onReleased: {
if (edit.visible) {
edit.focus = true
edit.forceActiveFocus()
}
if (delegate.x < -delegate.width/2) {
positionAnim.to = -delegate.width;
} else if (delegate.x > delegate.width/2) {
positionAnim.to = delegate.width;
} else {
positionAnim.to = 0;
}
2016-10-05 13:26:57 +00:00
2016-10-05 15:34:32 +00:00
positionAnim.running = true;
}
2016-10-05 15:34:32 +00:00
PlasmaComponents.Label {
id: label
text: model.name
anchors.verticalCenter: parent.verticalCenter
2021-09-13 16:40:56 +00:00
x: PlasmaCore.Units.smallSpacing
}
2016-10-05 15:34:32 +00:00
PlasmaComponents.TextField {
id: edit
visible: false
text: model.name
width: parent.width
onFocusChanged: {
if (!focus) {
visible = false
}
}
onAccepted: {
if (text != "") {
activityModel.setActivityName(model.id, text, function() {visible = false});
}
}
}
}
}
2016-09-05 14:05:48 +00:00
}
}