~ubuntu-branches/ubuntu/raring/plasma-mobile/raring-proposed

« back to all changes in this revision

Viewing changes to applications/filebrowser/imageviewerpart/contents/ui/ViewerPage.qml

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-07-17 12:04:43 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120717120443-q3ig9u2fnltx67yg
Tags: 2.0+git2012071701-0ubuntu1
* New upstream snapshot
* Remove build-dep on kde-runtime-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2011 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.0
 
21
import org.kde.metadatamodels 0.1 as MetadataModels
 
22
import org.kde.plasma.components 0.1 as PlasmaComponents
 
23
import org.kde.plasma.core 0.1 as PlasmaCore
 
24
import org.kde.plasma.mobilecomponents 0.1 as MobileComponents
 
25
import org.kde.plasma.slccomponents 0.1 as SlcComponents
 
26
import org.kde.qtextracomponents 0.1
 
27
 
 
28
 
 
29
PlasmaComponents.Page {
 
30
    id: viewerPage
 
31
    anchors.fill: parent
 
32
    property string path
 
33
 
 
34
    state: "toolsClosed"
 
35
 
 
36
    signal zoomIn
 
37
    signal zoomOut
 
38
 
 
39
    tools: Item {
 
40
        height: childrenRect.height
 
41
        PlasmaComponents.ToolButton {
 
42
            id: backIcon
 
43
            anchors.left: parent.left
 
44
            iconSource: "go-previous"
 
45
            width: theme.largeIconSize
 
46
            height: width
 
47
            flat: false
 
48
            onClicked: {
 
49
                //we want to tell the current image was closed
 
50
                resourceInstance.uri = ""
 
51
                fileBrowserRoot.goBack()
 
52
            }
 
53
        }
 
54
        Text {
 
55
            text: i18n("%1 (%2 of %3)", quickBrowserBar.currentItem.name, quickBrowserBar.currentIndex+1, quickBrowserBar.count)
 
56
            anchors.centerIn: parent
 
57
            font.pointSize: 14
 
58
            font.bold: true
 
59
            color: theme.textColor
 
60
            style: Text.Raised
 
61
            styleColor: theme.backgroundColor
 
62
        }
 
63
        Row {
 
64
            visible: !deviceCapabilitiesSource.data["Input"]["hasMultiTouch"]
 
65
            anchors.right: parent.right
 
66
            PlasmaComponents.ToolButton {
 
67
                iconSource: "zoom-in"
 
68
                width: theme.largeIconSize
 
69
                height: width
 
70
                flat: false
 
71
                onClicked: viewerPage.zoomIn()
 
72
            }
 
73
            PlasmaComponents.ToolButton {
 
74
                iconSource: "zoom-out"
 
75
                width: theme.largeIconSize
 
76
                height: width
 
77
                flat: false
 
78
                onClicked: viewerPage.zoomOut()
 
79
            }
 
80
        }
 
81
    }
 
82
 
 
83
    function loadFile(path)
 
84
    {
 
85
        if (path.length == 0) {
 
86
            return
 
87
        }
 
88
 
 
89
        if (String(path).indexOf("/") === 0) {
 
90
            path = "file://"+path
 
91
        }
 
92
 
 
93
        viewerPage.path = path
 
94
        //is in Nepomuk
 
95
        var index = metadataModel.find(path);
 
96
        if (index > -1) {
 
97
            fileBrowserRoot.model = metadataModel
 
98
            quickBrowserBar.currentIndex = index
 
99
            return
 
100
        } else {
 
101
            index = dirModel.indexForUrl(path)
 
102
            if (index > -1) {
 
103
                //is in dirModel
 
104
                fileBrowserRoot.model = dirModel
 
105
                quickBrowserBar.currentIndex = index
 
106
            //don't know where it is, just load
 
107
            } else {
 
108
                imageArea.delegate.source = path
 
109
            }
 
110
        }
 
111
    }
 
112
 
 
113
    PlasmaCore.DataSource {
 
114
        id: deviceCapabilitiesSource
 
115
        engine: "org.kde.devicecapabilities"
 
116
        interval: 0
 
117
        connectedSources: ["Input"]
 
118
    }
 
119
 
 
120
    //FIXME: HACK
 
121
    Connections {
 
122
        target: metadataModel
 
123
        onRunningChanged: {
 
124
            if (!running) {
 
125
                viewerPage.loadFile(viewerPage.path)
 
126
            }
 
127
        }
 
128
    }
 
129
 
 
130
    Rectangle {
 
131
        id: viewer
 
132
 
 
133
        color: "black"
 
134
        anchors.fill:  parent
 
135
    }
 
136
 
 
137
    MouseEventListener {
 
138
        id: imageArea
 
139
        anchors.fill: parent
 
140
        //enabled: !delegate.interactive
 
141
        property Item delegate: delegate1
 
142
        property Item oldDelegate: delegate2
 
143
        property bool incrementing: delegate.delta > 0
 
144
        Connections {
 
145
            target: imageArea.delegate
 
146
            onDeltaChanged: {
 
147
                imageArea.oldDelegate.delta = imageArea.delegate.delta
 
148
                if (imageArea.delegate.delta > 0) {
 
149
                    imageArea.oldDelegate.source = fileBrowserRoot.model.get(quickBrowserBar.currentIndex + 1).url
 
150
                } else if (imageArea.delegate.delta < 0) {
 
151
                    imageArea.oldDelegate.source =  fileBrowserRoot.model.get(quickBrowserBar.currentIndex - 1).url
 
152
                }
 
153
            }
 
154
        }
 
155
 
 
156
        property int startX
 
157
        property int starty
 
158
        onPressed: {
 
159
            startX = mouse.screenX
 
160
            startY = mouse.screenY
 
161
        }
 
162
        onReleased: {
 
163
            if (Math.abs(mouse.screenX - startX) < 20 &&
 
164
                Math.abs(mouse.screenY - startY) < 20) {
 
165
                if (viewerPage.state == "toolsOpen") {
 
166
                    viewerPage.state = "toolsClosed"
 
167
                } else {
 
168
                    viewerPage.state = "toolsOpen"
 
169
                }
 
170
            } else if (delegate.delta != 0 && delegate.doSwitch) {
 
171
                oldDelegate = delegate
 
172
                delegate = (delegate == delegate1) ? delegate2 : delegate1
 
173
                switchAnimation.running = true
 
174
            }
 
175
        }
 
176
        FullScreenDelegate {
 
177
            id: delegate2
 
178
            width: parent.width
 
179
            height: parent.height
 
180
        }
 
181
        FullScreenDelegate {
 
182
            id: delegate1
 
183
            width: parent.width
 
184
            height: parent.height
 
185
        }
 
186
        SequentialAnimation {
 
187
            id: switchAnimation
 
188
            NumberAnimation {
 
189
                target: imageArea.oldDelegate
 
190
                properties: "x"
 
191
                to: imageArea.incrementing ? -imageArea.oldDelegate.width : imageArea.oldDelegate.width
 
192
                easing.type: Easing.InQuad
 
193
                duration: 250
 
194
            }
 
195
            ScriptAction {
 
196
                script: {
 
197
                    if (imageArea.incrementing) {
 
198
                        quickBrowserBar.currentIndex += 1
 
199
                    } else {
 
200
                        quickBrowserBar.currentIndex -= 1
 
201
                    }
 
202
                    imageArea.oldDelegate.z = 0
 
203
                    imageArea.delegate.z = 10
 
204
                    imageArea.oldDelegate.x = 0
 
205
                    imageArea.delegate.x = 0
 
206
                }
 
207
            }
 
208
            ScriptAction {
 
209
                script: delegate1.delta = delegate2.delta = 0
 
210
            }
 
211
        }
 
212
    }
 
213
 
 
214
    QuickBrowserBar {
 
215
        id: quickBrowserBar
 
216
        model: fileBrowserRoot.model
 
217
        onCurrentIndexChanged: {
 
218
            var path = fileBrowserRoot.model.get(currentIndex).url
 
219
            imageArea.delegate.source = path
 
220
            viewerPage.path = path
 
221
            resourceInstance.uri = path
 
222
        }
 
223
    }
 
224
 
 
225
    states: [
 
226
        State {
 
227
            name: "toolsOpen"
 
228
            PropertyChanges {
 
229
                target: toolBar
 
230
                y: 0
 
231
            }
 
232
            PropertyChanges {
 
233
                target: quickBrowserBar
 
234
                y: fileBrowserRoot.height - quickBrowserBar.height
 
235
            }
 
236
        },
 
237
        State {
 
238
            name: "toolsClosed"
 
239
            PropertyChanges {
 
240
                target: toolBar
 
241
                y: -toolBar.height
 
242
            }
 
243
            PropertyChanges {
 
244
                target: quickBrowserBar
 
245
                y: fileBrowserRoot.height+20
 
246
            }
 
247
        }
 
248
    ]
 
249
 
 
250
    transitions: [
 
251
        Transition {
 
252
            NumberAnimation {
 
253
                properties: "y"
 
254
                easing.type: Easing.InOutQuad
 
255
                duration: 250
 
256
            }
 
257
        }
 
258
    ]
 
259
}
 
260