on xenial help sign in
Move the normalFoo properties around
commitcbad34d16457d580d145cc9b02c605cebc7a42ea authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateWed 23 Nov 2016, 16:43 (10 years ago) parent20c8771
4 files changed+30−39
qml/Stage/MoveHandler.qml+2−2 qml/Stage/Stage.qml+23 qml/Stage/WindowResizeArea.qml−33 qml/Stage/WindowStateSaver.qml+5−4
qml/Stage/MoveHandler.qml+2−2
@@ -85,8 +85,8 @@ QtObject {
8585 if (target.anyMaximized) {
8686 // keep distanceX relative to the normal window width minus the window control buttons (+spacing)
8787 // so that dragging it back doesn't make the window jump around to weird positions, away from the mouse pointer
88− priv.distanceX = MathUtils.clampAndProject(pos.x, 0, target.width, buttonsWidth, target.resizeArea.normalWidth);
89− priv.distanceY = MathUtils.clampAndProject(pos.y, 0, target.height, 0, target.resizeArea.normalHeight);
88+ priv.distanceX = MathUtils.clampAndProject(pos.x, 0, target.width, buttonsWidth, target.normalWidth);
89+ priv.distanceY = MathUtils.clampAndProject(pos.y, 0, target.height, 0, target.normalHeight);
9090 } else {
9191 priv.distanceX = pos.x;
9292 priv.distanceY = pos.y;
qml/Stage/Stage.qml+23
@@ -707,6 +707,29 @@ FocusScope {
707707 property real restoredX
708708 property real restoredY
709709
710+ // Keeps track of the window geometry while in normal or restored state
711+ // Useful when returning from some maxmized state or when saving the geometry while maximized
712+ // FIXME: find a better solution
713+ property real normalX: 0
714+ property real normalY: 0
715+ property real normalWidth: 0
716+ property real normalHeight: 0
717+ function updateNormalGeometry() {
718+ if (appDelegate.state == "normal" || appDelegate.state == "restored") {
719+ normalX = appDelegate.requestedX;
720+ normalY = appDelegate.requestedY;
721+ normalWidth = appDelegate.width;
722+ normalHeight = appDelegate.height;
723+ }
724+ }
725+ Connections {
726+ target: appDelegate
727+ onXChanged: appDelegate.updateNormalGeometry();
728+ onYChanged: appDelegate.updateNormalGeometry();
729+ onWidthChanged: appDelegate.updateNormalGeometry();
730+ onHeightChanged: appDelegate.updateNormalGeometry();
731+ }
732+
710733 Binding {
711734 target: appDelegate
712735 property: "y"
qml/Stage/WindowResizeArea.qml−33
@@ -27,8 +27,6 @@ MouseArea {
2727 hoverEnabled: target && !target.maximized // don't grab the resize under the panel
2828
2929 readonly property alias dragging: d.dragging
30− readonly property alias normalWidth: priv.normalWidth
31− readonly property alias normalHeight: priv.normalHeight
3230
3331 // The target item managed by this. Must be a parent or a sibling
3432 // The area will anchor to it and manage resize events
@@ -38,37 +36,6 @@ MouseArea {
3836 property int minWidth: 0
3937 property int minHeight: 0
4038
41− function init() {
42− priv.updateNormalGeometry();
43− }
44−
45− QtObject {
46− id: priv
47− objectName: "priv"
48−
49− property int normalX: 0
50− property int normalY: 0
51− property int normalWidth: 0
52− property int normalHeight: 0
53−
54− function updateNormalGeometry() {
55− if (root.target.state == "normal" || root.target.state == "restored") {
56− normalX = root.target.requestedX
57− normalY = root.target.requestedY
58− normalWidth = root.target.width
59− normalHeight = root.target.height
60− }
61− }
62− }
63−
64− Connections {
65− target: root.target
66− onXChanged: priv.updateNormalGeometry();
67− onYChanged: priv.updateNormalGeometry();
68− onWidthChanged: priv.updateNormalGeometry();
69− onHeightChanged: priv.updateNormalGeometry();
70− }
71−
7239 QtObject {
7340 id: d
7441
qml/Stage/WindowStateSaver.qml+5−4
@@ -44,9 +44,11 @@ QtObject {
4444 var windowState = WindowStateStorage.getState(target.appId, WindowStateStorage.WindowStateNormal)
4545 target.restore(false /* animated */, windowState);
4646
47+ target.updateNormalGeometry();
48+
4749 // initialize the x/y to restore to
48− target.restoredX = windowGeometry.x;
49− target.restoredY = windowGeometry.y;
50+ target.restoredX = target.normalX;
51+ target.restoredY = target.normalY;
5052 }
5153
5254 function save() {
@@ -56,7 +58,6 @@ QtObject {
5658 }
5759
5860 WindowStateStorage.saveState(target.appId, state & ~WindowStateStorage.WindowStateMinimized); // clear the minimized bit when saving
59− WindowStateStorage.saveGeometry(target.appId, Qt.rect(target.windowedX, target.windowedY,
60− target.windowedWidth, target.windowedHeight));
61+ WindowStateStorage.saveGeometry(target.appId, Qt.rect(target.normalX, target.normalY, target.normalWidth, target.normalHeight));
6162 }
6263}