hide edit boxes when needed

This commit is contained in:
Marco Martin 2016-10-05 17:34:32 +02:00
parent 49cde86d37
commit efc09b0011

View file

@ -25,6 +25,7 @@ import org.kde.activities 0.1 as Activities
ColumnLayout { ColumnLayout {
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
id: newButton
Layout.fillWidth: true Layout.fillWidth: true
text: i18n("New Activity...") text: i18n("New Activity...")
onClicked: { onClicked: {
@ -50,84 +51,103 @@ ColumnLayout {
} }
} }
} }
ListView { MouseArea {
id: listView id: rootMouseArea
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
model: Activities.ActivityModel { drag.filterChildren: true
id: activityModel onClicked: newEdit.visible = false
} ListView {
delegate: MouseArea { id: listView
id: delegate anchors.fill: parent
drag { model: Activities.ActivityModel {
target: listView.count > 0 && !model.current? delegate : null id: activityModel
axis: Drag.XAxis }
} delegate: MouseArea {
PlasmaComponents.Highlight { id: delegate
visible: model.current drag {
anchors.fill:parent target: listView.count > 0 && !model.current? delegate : null
} axis: Drag.XAxis
SequentialAnimation {
id: positionAnim
property alias to: xAnim.to
XAnimator {
id: xAnim
target: delegate
from: delegate.x
duration: units.longDuration
easing.type: Easing.InOutQuad
} }
ScriptAction { PlasmaComponents.Highlight {
script: { visible: model.current
if (delegate.x < -delegate.width/2 || delegate.x > delegate.width/2) { anchors.fill:parent
activityModel.removeActivity(model.id, function() {}); }
Connections {
target: rootMouseArea
onClicked: {
if (!delegate.contains(rootMouseArea.mapToItem(delegate, mouse.x, mouse.y))) {
edit.visible = false;
} }
} }
} }
} Connections {
width: listView.width target: newButton
height: label.height onClicked: edit.visible = false;
onClicked: { }
listView.currentIndex = index; SequentialAnimation {
activityModel.setCurrentActivity(model.id, function() {}); id: positionAnim
} property alias to: xAnim.to
onPressAndHold: { XAnimator {
edit.visible = true id: xAnim
edit.focus = true target: delegate
} from: delegate.x
onReleased: { duration: units.longDuration
if (edit.visible) { 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.setCurrentActivity(model.id, function() {});
}
onPressAndHold: {
edit.visible = true
edit.focus = true 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;
} }
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;
}
positionAnim.running = true; positionAnim.running = true;
}
PlasmaComponents.Label {
id: label
text: model.name
x: units.smallSpacing
}
PlasmaComponents.TextField {
id: edit
visible: false
text: model.name
width: parent.width
onFocusChanged: {
if (!focus) {
visible = false
} }
PlasmaComponents.Label {
id: label
text: model.name
anchors.verticalCenter: parent.verticalCenter
x: units.smallSpacing
} }
onAccepted: { PlasmaComponents.TextField {
if (text != "") { id: edit
activityModel.setActivityName(model.id, text, function() {visible = false}); visible: false
text: model.name
width: parent.width
onFocusChanged: {
if (!focus) {
visible = false
}
}
onAccepted: {
if (text != "") {
activityModel.setActivityName(model.id, text, function() {visible = false});
}
} }
} }
} }