2016-09-05 14:05:48 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2016 Marco Martin <notmart@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 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 Library General Public License for more details
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
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
|
|
|
|
|
|
2016-10-05 13:15:28 +00:00
|
|
|
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;
|
2016-10-05 16:03:41 +00:00
|
|
|
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
|
2016-10-05 13:15:28 +00:00
|
|
|
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
|
2018-11-28 14:43:31 +00:00
|
|
|
preventStealing: true
|
2016-10-05 15:34:32 +00:00
|
|
|
drag {
|
2018-11-28 14:43:31 +00:00
|
|
|
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
|
|
|
|
|
duration: units.longDuration
|
|
|
|
|
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;
|
2016-10-07 10:53:10 +00:00
|
|
|
activityModel.startActivity(model.id, function() {
|
|
|
|
|
activityModel.setCurrentActivity(model.id, function() {
|
|
|
|
|
plasmoid.expanded = false;
|
|
|
|
|
});
|
2016-10-05 16:03:41 +00:00
|
|
|
});
|
2016-10-05 13:15:28 +00:00
|
|
|
}
|
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 13:15:28 +00:00
|
|
|
}
|
2016-10-05 15:34:32 +00:00
|
|
|
PlasmaComponents.Label {
|
|
|
|
|
id: label
|
|
|
|
|
text: model.name
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
x: units.smallSpacing
|
2016-10-05 13:15:28 +00:00
|
|
|
}
|
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-10-05 13:15:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-05 14:05:48 +00:00
|
|
|
}
|
|
|
|
|
}
|