~ubuntu-branches/ubuntu/saucy/plasma-mobile/saucy

« back to all changes in this revision

Viewing changes to components/mobilecomponents/OverlayDrawer.qml

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-12-22 01:58:11 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20121222015811-zqq9spgc9e0gin07
Tags: 3.0-0ubuntu1
* New upstream release
* Update install files
* Run wrap-and-sort
* Add plasma-mobile-dev
* Drop plasma-active-keyboardcontainer

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2012 Marco Martin <mart@kde.org>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU Library General Public License as
 
6
 *   published by the Free Software Foundation; either version 2, or
 
7
 *   (at your option) any later version.
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU Library General Public License for more details
 
13
 *
 
14
 *   You should have received a copy of the GNU Library General Public
 
15
 *   License along with this program; if not, write to the
 
16
 *   Free Software Foundation, Inc.,
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
import QtQuick 1.1
 
21
import org.kde.plasma.components 0.1 as PlasmaComponents
 
22
import org.kde.plasma.core 0.1 as PlasmaCore
 
23
import org.kde.qtextracomponents 0.1
 
24
 
 
25
 
 
26
/**Documented API
 
27
Inherits:
 
28
        Page from org.kde.plasmacomponents
 
29
 
 
30
Imports:
 
31
        org.kde.plasma.core
 
32
        org.kde.plasma.components
 
33
        QtQuick 1.1
 
34
 
 
35
Description:
 
36
        Overlay Drawers are used to expose additional UI elements needed for small secondary tasks for which the main UI elements are not needed. For example in Okular Active, an Overlay Drawer is used to display thumbnails of all pages within a document along with a search field. This is used for the distinct task of navigating to another page.
 
37
 
 
38
Properties:
 
39
        bool open:
 
40
        If true the drawer is open showing the contents of the "drawer" component.
 
41
 
 
42
        Item page:
 
43
        It's the default property. it's the main content of the drawer page, the part that is always shown
 
44
 
 
45
        Item drawer:
 
46
        It's the part that can be pulled in and out, will act as a sidebar.
 
47
**/
 
48
PlasmaComponents.Page {
 
49
    id: root
 
50
    anchors.fill: parent
 
51
 
 
52
    default property alias page: mainPage.data
 
53
    property alias drawer: drawerPage.data
 
54
    property alias open: browserFrame.open
 
55
 
 
56
 
 
57
    MouseEventListener {
 
58
        id: mainPage
 
59
        property int startMouseScreenX: 0
 
60
        property int startMouseScreenY: 0
 
61
        onPressed: {
 
62
            startMouseScreenX = mouse.screenX
 
63
            startMouseScreenY = mouse.screenY
 
64
        }
 
65
        onReleased: {
 
66
            if (Math.abs(mouse.screenX - startMouseScreenX) > 20 ||
 
67
                Math.abs(mouse.screenY - startMouseScreenY) > 20) {
 
68
                return
 
69
            }
 
70
            if (browserFrame.state != "Hidden") {
 
71
                browserFrame.state = "Hidden"
 
72
            } else {
 
73
                browserFrame.state = "Closed"
 
74
            }
 
75
        }
 
76
        anchors.fill: parent
 
77
    }
 
78
 
 
79
    Image {
 
80
        id: browserFrame
 
81
        z: 100
 
82
        source: "image://appbackgrounds/standard"
 
83
        fillMode: Image.Tile
 
84
        anchors {
 
85
            top: parent.top
 
86
            bottom: parent.bottom
 
87
        }
 
88
 
 
89
        width: parent.width - handleGraphics.width
 
90
        state: "Hidden"
 
91
        onStateChanged: open = (state == "Open" || mouseEventListener.startState == "Open")
 
92
        property bool open: false
 
93
        onOpenChanged: openChangedTimer.restart()
 
94
 
 
95
        Timer {
 
96
            id: openChangedTimer
 
97
            interval: 0
 
98
            onTriggered: {
 
99
                if (open) {
 
100
                    browserFrame.state = "Open"
 
101
                } else {
 
102
                    browserFrame.state = "Closed"
 
103
                }
 
104
            }
 
105
        }
 
106
 
 
107
 
 
108
        Image {
 
109
            source: "image://appbackgrounds/shadow-left"
 
110
            fillMode: Image.TileVertically
 
111
            anchors {
 
112
                right: parent.left
 
113
                top: parent.top
 
114
                bottom: parent.bottom
 
115
                rightMargin: -1
 
116
            }
 
117
        }
 
118
        PlasmaCore.FrameSvgItem {
 
119
            id: handleGraphics
 
120
            imagePath: "dialogs/background"
 
121
            enabledBorders: "LeftBorder|TopBorder|BottomBorder"
 
122
            width: handleIcon.width + margins.left + margins.right + 4
 
123
            height: handleIcon.width * 1.6 + margins.top + margins.bottom + 4
 
124
            anchors {
 
125
                right: parent.left
 
126
                verticalCenter: parent.verticalCenter
 
127
            }
 
128
 
 
129
            PlasmaCore.SvgItem {
 
130
                id: handleIcon
 
131
                svg: PlasmaCore.Svg {imagePath: "toolbar-icons/show"}
 
132
                elementId: "show-menu"
 
133
                x: parent.margins.left
 
134
                y: parent.margins.top
 
135
                width: theme.smallMediumIconSize
 
136
                height: width
 
137
                anchors.verticalCenter: parent.verticalCenter
 
138
            }
 
139
        }
 
140
 
 
141
        MouseEventListener {
 
142
            id: mouseEventListener
 
143
            anchors {
 
144
                top: parent.top
 
145
                bottom: parent.bottom
 
146
                left: handleGraphics.left
 
147
                right: parent.right
 
148
            }
 
149
 
 
150
            property int startBrowserFrameX
 
151
            property real oldMouseScreenX
 
152
            property bool toggle: false
 
153
            property bool startDragging: false
 
154
            property string startState
 
155
 
 
156
            onPressed: {
 
157
                startBrowserFrameX = browserFrame.x
 
158
                oldMouseScreenX = mouse.screenX
 
159
                startMouseScreenX = mouse.screenX
 
160
                toggle = (mouse.x < handleGraphics.width)
 
161
                startDragging = false
 
162
                startState = browserFrame.state
 
163
                browserFrame.state = "Dragging"
 
164
                toggle = mouse.x < handleGraphics.width
 
165
            }
 
166
            onPositionChanged: {
 
167
                //mouse over handle and didn't move much
 
168
                if (mouse.x > handleGraphics.width ||
 
169
                    Math.abs(mouse.screenX - startMouseScreenX) > 20) {
 
170
                    toggle = false
 
171
                }
 
172
                if (mouse.x < handleGraphics.width ||
 
173
                    Math.abs(mouse.screenX - startMouseScreenX) > root.width / 5) {
 
174
                    startDragging = true
 
175
                }
 
176
                if (startDragging) {
 
177
                    browserFrame.x = Math.max(root.width - browserFrame.width, browserFrame.x + mouse.screenX - oldMouseScreenX)
 
178
                }
 
179
                oldMouseScreenX = mouse.screenX
 
180
            }
 
181
            onReleased: {
 
182
                //If one condition for toggle is satisfied toggle, otherwise do an animation that resets the original position
 
183
                if (toggle || Math.abs(browserFrame.x - startBrowserFrameX) > root.width / 3) {
 
184
                    browserFrame.state = startState == "Open" ? "Closed" : "Open"
 
185
                } else {
 
186
                    browserFrame.state = startState
 
187
                }
 
188
            }
 
189
 
 
190
            Item {
 
191
                id: drawerPage
 
192
                anchors {
 
193
                    fill: parent
 
194
                    leftMargin: handleGraphics.width
 
195
                }
 
196
                clip: true
 
197
            }
 
198
        }
 
199
 
 
200
        states: [
 
201
            State {
 
202
                name: "Open"
 
203
                PropertyChanges {
 
204
                    target: browserFrame
 
205
                    x: handleGraphics.width
 
206
                }
 
207
 
 
208
            },
 
209
            State {
 
210
                name: "Dragging"
 
211
                //workaround for a quirkiness of the state machine
 
212
                //if no x binding gets defined in this state x will be set to whatever last x it had last time it was in this state
 
213
                PropertyChanges {
 
214
                    target: browserFrame
 
215
                    x: mouseEventListener.startBrowserFrameX
 
216
                }
 
217
            },
 
218
            State {
 
219
                name: "Closed"
 
220
                PropertyChanges {
 
221
                    target: browserFrame
 
222
                    x: root.width
 
223
                }
 
224
            },
 
225
            State {
 
226
                name: "Hidden"
 
227
                PropertyChanges {
 
228
                    target: browserFrame
 
229
                    x: root.width + handleGraphics.width
 
230
                }
 
231
            }
 
232
        ]
 
233
 
 
234
        transitions: [
 
235
            Transition {
 
236
                //Exclude Dragging
 
237
                to: "Open,Closed,Hidden"
 
238
                NumberAnimation {
 
239
                    properties: "x"
 
240
                    duration: 250
 
241
                    easing.type: Easing.InOutQuad
 
242
                }
 
243
            }
 
244
        ]
 
245
    }
 
246
}
 
247