~ci-train-bot/unity8/unity8-ubuntu-zesty-2026

« back to all changes in this revision

Viewing changes to qml/Stage/DecoratedWindow.qml

  • Committer: Bileto Bot
  • Author(s): Michael Zanetti
  • Date: 2016-10-24 11:34:08 UTC
  • mfrom: (2400.6.204 unity8-unified-spread)
  • Revision ID: ci-train-bot@canonical.com-20161024113408-7ul8ivww68dqm74v
Merge all Stages into one single codebase. Apply new spread visuals.

This deletes PhoneStage, TabletStage and DesktopStage, and merges all of the functionality into Stage. Also the spread visuals have been updated by design to work with all usage modes. (LP: #1489517, #1603914, #1635800)

Approved by: Lukáš Tinkl

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import QtQuick 2.4
18
18
import Ubuntu.Components 1.3
19
19
import Unity.Application 0.1
 
20
import "Spread/MathUtils.js" as MathUtils
20
21
 
21
22
FocusScope {
22
23
    id: root
23
24
 
24
 
    width: !counterRotate ? applicationWindow.width : applicationWindow.height
25
 
    height: visibleDecorationHeight + (!counterRotate ? applicationWindow.height : applicationWindow.width)
 
25
    // The DecoratedWindow takes requestedWidth/requestedHeight and asks its surface to be resized to that
 
26
    // (minus the window decoration size in case hasDecoration and showDecoration are true)
 
27
    // The surface might not be able to resize to the requested values. It will return its actual size
 
28
    // in implicitWidth/implicitHeight.
26
29
 
27
30
    property alias application: applicationWindow.application
28
31
    property alias surface: applicationWindow.surface
29
32
    readonly property alias focusedSurface: applicationWindow.focusedSurface
30
33
    property alias active: decoration.active
31
34
    readonly property alias title: applicationWindow.title
32
 
    property alias fullscreen: applicationWindow.fullscreen
33
35
    property alias maximizeButtonShown: decoration.maximizeButtonShown
 
36
    property alias interactive: applicationWindow.interactive
 
37
    readonly property alias orientationChangesEnabled: applicationWindow.orientationChangesEnabled
34
38
 
35
 
    readonly property bool decorationShown: !fullscreen
36
 
    property bool highlightShown: false
37
 
    property real shadowOpacity: 1
 
39
    // Changing this will actually add/remove a decoration, meaning, requestedHeight will take the decoration into account.
 
40
    property bool hasDecoration: true
 
41
    // This will temporarily show/hide the decoration without actually changing the surface's dimensions
 
42
    property real showDecoration: 1
 
43
    property bool animateDecoration: false
 
44
    property bool showHighlight: false
 
45
    property int highlightSize: units.gu(1)
 
46
    property real shadowOpacity: 0
 
47
    property bool darkening: false
38
48
 
39
49
    property real requestedWidth
40
50
    property real requestedHeight
 
51
    property real scaleToPreviewProgress: 0
 
52
    property int scaleToPreviewSize: units.gu(30)
41
53
 
42
54
    property alias surfaceOrientationAngle: applicationWindow.surfaceOrientationAngle
43
 
    readonly property real visibleDecorationHeight: root.decorationShown ? decoration.height : 0
 
55
    readonly property real decorationHeight: Math.min(d.visibleDecorationHeight, d.requestedDecorationHeight)
44
56
    readonly property bool counterRotate: surfaceOrientationAngle != 0 && surfaceOrientationAngle != 180
45
57
 
46
58
    readonly property int minimumWidth: !counterRotate ? applicationWindow.minimumWidth : applicationWindow.minimumHeight
47
 
    readonly property int minimumHeight: visibleDecorationHeight + (!counterRotate ? applicationWindow.minimumHeight : applicationWindow.minimumWidth)
 
59
    readonly property int minimumHeight: decorationHeight + (!counterRotate ? applicationWindow.minimumHeight : applicationWindow.minimumWidth)
48
60
    readonly property int maximumWidth: !counterRotate ? applicationWindow.maximumWidth : applicationWindow.maximumHeight
49
61
    readonly property int maximumHeight: (root.decorationShown && applicationWindow.maximumHeight > 0 ? decoration.height : 0)
50
62
                                         + (!counterRotate ? applicationWindow.maximumHeight : applicationWindow.maximumWidth)
66
78
    signal decorationPressed()
67
79
    signal decorationReleased()
68
80
 
 
81
    QtObject {
 
82
        id: d
 
83
        property int requestedDecorationHeight: root.hasDecoration ? decoration.height : 0
 
84
        Behavior on requestedDecorationHeight { enabled: root.animateDecoration; UbuntuNumberAnimation { } }
 
85
 
 
86
        property int visibleDecorationHeight: root.hasDecoration ? root.showDecoration * decoration.height : 0
 
87
        Behavior on visibleDecorationHeight { enabled: root.animateDecoration; UbuntuNumberAnimation { } }
 
88
    }
 
89
 
 
90
    StateGroup {
 
91
        states: [
 
92
            State {
 
93
                name: "normal"; when: root.scaleToPreviewProgress <= 0 && root.application.state === ApplicationInfoInterface.Running
 
94
                PropertyChanges {
 
95
                    target: root
 
96
                    implicitWidth: counterRotate ? applicationWindow.implicitHeight : applicationWindow.implicitWidth
 
97
                    implicitHeight: root.decorationHeight + (counterRotate ? applicationWindow.implicitWidth:  applicationWindow.implicitHeight)
 
98
                }
 
99
            },
 
100
            State {
 
101
                name: "normalSuspended"; when: root.scaleToPreviewProgress <= 0 && root.application.state !== ApplicationInfoInterface.Running
 
102
                extend: "normal"
 
103
                PropertyChanges {
 
104
                    target: root
 
105
                    implicitWidth: counterRotate ? applicationWindow.requestedHeight : applicationWindow.requestedWidth
 
106
                    implicitHeight: root.decorationHeight + (counterRotate ? applicationWindow.requestedWidth:  applicationWindow.requestedHeight)
 
107
                }
 
108
            },
 
109
            State {
 
110
                name: "preview"; when: root.scaleToPreviewProgress > 0
 
111
                PropertyChanges {
 
112
                    target: root
 
113
                    implicitWidth: MathUtils.linearAnimation(0, 1, applicationWindow.oldRequestedWidth, root.scaleToPreviewSize, root.scaleToPreviewProgress)
 
114
                    implicitHeight: MathUtils.linearAnimation(0, 1, applicationWindow.oldRequestedHeight, root.scaleToPreviewSize, root.scaleToPreviewProgress)
 
115
                }
 
116
                PropertyChanges {
 
117
                    target: applicationWindow;
 
118
                    requestedWidth: applicationWindow.oldRequestedWidth
 
119
                    requestedHeight: applicationWindow.oldRequestedHeight
 
120
                    width: MathUtils.linearAnimation(0, 1, applicationWindow.oldRequestedWidth, applicationWindow.minSize, root.scaleToPreviewProgress)
 
121
                    height: MathUtils.linearAnimation(0, 1, applicationWindow.oldRequestedHeight, applicationWindow.minSize, root.scaleToPreviewProgress)
 
122
                    itemScale: root.implicitWidth / width
 
123
                }
 
124
            }
 
125
        ]
 
126
    }
 
127
 
69
128
    Rectangle {
70
129
        id: selectionHighlight
 
130
        objectName: "selectionHighlight"
71
131
        anchors.fill: parent
72
 
        anchors.margins: -units.gu(1)
 
132
        anchors.margins: -root.highlightSize
73
133
        color: "white"
74
 
        opacity: highlightShown ? 0.15 : 0
75
 
    }
76
 
 
77
 
    Rectangle {
78
 
        anchors { left: selectionHighlight.left; right: selectionHighlight.right; bottom: selectionHighlight.bottom; }
79
 
        height: units.dp(2)
80
 
        color: theme.palette.normal.focus
81
 
        visible: highlightShown
 
134
        opacity: showHighlight ? 0.55 : 0
 
135
        visible: opacity > 0
82
136
    }
83
137
 
84
138
    BorderImage {
 
139
        id: dropShadow
85
140
        anchors {
86
 
            fill: root
 
141
            left: parent.left; top: parent.top; right: parent.right
87
142
            margins: active ? -units.gu(2) : -units.gu(1.5)
88
143
        }
89
 
        source: "graphics/dropshadow2gu.sci"
90
 
        opacity: root.shadowOpacity * .3
91
 
        visible: !fullscreen
 
144
        height: Math.min(applicationWindow.implicitHeight, applicationWindow.height) * applicationWindow.itemScale
 
145
                + root.decorationHeight * Math.min(1, root.showDecoration) + (active ? units.gu(4) : units.gu(3))
 
146
        source: "../graphics/dropshadow2gu.sci"
 
147
        opacity: root.shadowOpacity
92
148
    }
93
149
 
94
150
    WindowDecoration {
95
151
        id: decoration
96
 
        target: root.parent
 
152
        target: root.parent || null
97
153
        objectName: "appWindowDecoration"
98
154
        anchors { left: parent.left; top: parent.top; right: parent.right }
99
155
        height: units.gu(3)
100
156
        width: root.width
101
157
        title: applicationWindow.title
102
 
        visible: root.decorationShown
 
158
        opacity: root.hasDecoration ? Math.min(1, root.showDecoration) : 0
 
159
 
 
160
        Behavior on opacity { UbuntuNumberAnimation { } }
103
161
 
104
162
        onCloseClicked: root.closeClicked();
105
163
        onMaximizeClicked: { root.decorationPressed(); root.maximizeClicked(); }
126
184
    ApplicationWindow {
127
185
        id: applicationWindow
128
186
        objectName: "appWindow"
 
187
        anchors.left: parent.left
129
188
        anchors.top: parent.top
130
 
        anchors.topMargin: decoration.height
131
 
        anchors.left: parent.left
132
 
        readonly property real requestedHeightMinusDecoration: root.requestedHeight - root.visibleDecorationHeight
133
 
        requestedHeight: !counterRotate ? requestedHeightMinusDecoration : root.requestedWidth
134
 
        requestedWidth: !counterRotate ? root.requestedWidth : requestedHeightMinusDecoration
135
 
        interactive: true
 
189
        anchors.topMargin: root.decorationHeight * Math.min(1, root.showDecoration)
 
190
        width: implicitWidth
 
191
        height: implicitHeight
 
192
        requestedHeight: !counterRotate ? root.requestedHeight - d.requestedDecorationHeight : root.requestedWidth
 
193
        requestedWidth: !counterRotate ? root.requestedWidth : root.requestedHeight - d.requestedDecorationHeight
 
194
        property int oldRequestedWidth: requestedWidth
 
195
        property int oldRequestedHeight: requestedHeight
 
196
        onRequestedWidthChanged: oldRequestedWidth = requestedWidth
 
197
        onRequestedHeightChanged: oldRequestedHeight = requestedHeight
136
198
        focus: true
137
199
 
138
 
        transform: Rotation {
 
200
        property real itemScale: 1
 
201
        property real minSize: Math.min(root.scaleToPreviewSize, Math.min(requestedHeight, Math.min(requestedWidth, Math.min(implicitHeight, implicitWidth))))
 
202
 
 
203
        transform: [
 
204
            Rotation {
 
205
                id: rotationTransform
139
206
                readonly property int rotationAngle: applicationWindow.application &&
140
207
                                                     applicationWindow.application.rotatesWindowContents
141
208
                                                     ? ((360 - applicationWindow.surfaceOrientationAngle) % 360) : 0
152
219
                    else return 0;
153
220
                }
154
221
                angle: rotationAngle
155
 
        }
 
222
            },
 
223
            Scale {
 
224
                xScale: applicationWindow.itemScale
 
225
                yScale: applicationWindow.itemScale
 
226
            }
 
227
        ]
 
228
 
 
229
    }
 
230
 
 
231
    Rectangle {
 
232
        anchors.fill: parent
 
233
        color: "black"
 
234
        opacity: root.darkening && !root.showHighlight ? 0.05 : 0
 
235
        Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
156
236
    }
157
237
}