better behavior for the sliding panel

This commit is contained in:
Marco Martin 2014-10-23 17:00:24 +02:00
parent 9ba5bf8db8
commit afe58452ef
2 changed files with 30 additions and 16 deletions

View file

@ -215,10 +215,18 @@ Item {
font.pixelSize: height / 2 font.pixelSize: height / 2
} }
MouseArea { MouseArea {
property int oldMouseY: 0
anchors.fill: parent anchors.fill: parent
onPressed: slidingPanel.visible = true; onPressed: {
onPositionChanged: slidingPanel.offset = mouse.y; oldMouseY = mouse.y;
onReleased: slidingPanel.updateState(mouse.y); slidingPanel.visible = true;
}
onPositionChanged: {
slidingPanel.offset = slidingPanel.offset + (mouse.y - oldMouseY);
oldMouseY = mouse.y;
}
onReleased: slidingPanel.updateState();
} }
} }

View file

@ -29,14 +29,12 @@ Window {
color: "transparent" color: "transparent"
function updateState(y) { function updateState() {
var delta = offset - mouseArea.startOffset; var delta = offset - mouseArea.startOffset;
if (delta > units.gridUnit * 8) { if (delta > units.gridUnit * 8) {
mouseArea.state = "open"; mouseArea.state = "open";
mouseArea.startOffset = units.iconSizes.large;
} else if (delta < -units.gridUnit * 8) { } else if (delta < -units.gridUnit * 8) {
mouseArea.state = "closed"; mouseArea.state = "closed";
mouseArea.startOffset = units.iconSizes.large;
} else { } else {
mouseArea.state = mouseArea.startState; mouseArea.state = mouseArea.startState;
} }
@ -45,7 +43,8 @@ Window {
onVisibleChanged: { onVisibleChanged: {
if (visible) { if (visible) {
mouseArea.state = "dragging"; mouseArea.state = "draggingFromClosed";
mouseArea.startOffset = units.gridUnit * 4;
} }
} }
@ -57,25 +56,27 @@ Window {
clip: true clip: true
state: "closed" state: "closed"
property int startY: 0 property int oldMouseY: 0
property int startOffset: units.iconSizes.large; property int startOffset: units.iconSizes.large;
property string startState: "closed" property string startState: "closed"
onPressed: { onPressed: {
startState = state; startState = state;
startY = mouse.y;
startOffset = window.offset; startOffset = window.offset;
state = "dragging"; oldMouseY = mouse.y;
state = "draggingFromOpen";
window.offset = startOffset;
} }
onPositionChanged: { onPositionChanged: {
window.offset = Math.min(slidingArea.height, startOffset + (mouse.y - startY)); window.offset = window.offset + (mouse.y - oldMouseY);
oldMouseY = mouse.y;
} }
onReleased: window.updateState(mouse.y) onReleased: window.updateState()
Rectangle { Rectangle {
id: slidingArea id: slidingArea
width: parent.width width: parent.width
height: parent.height height: parent.height
y: -height + window.offset y: Math.min(0, -height + window.offset)
color: Qt.rgba(0, 0, 0, 0.7) color: Qt.rgba(0, 0, 0, 0.7)
Rectangle { Rectangle {
@ -106,16 +107,21 @@ Window {
} }
}, },
State { State {
name: "dragging" name: "draggingFromOpen"
},
State {
name: "draggingFromClosed"
PropertyChanges { PropertyChanges {
id: dragChange
target: window target: window
offset: mouseArea.startOffset offset: units.gridUnit * 4
} }
} }
] ]
transitions: [ transitions: [
Transition {
to: "draggingFromOpen"
},
Transition { Transition {
SequentialAnimation { SequentialAnimation {
PropertyAnimation { PropertyAnimation {