• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegraphics API Reference
  • KDE Home
  • Contact Us
 

okular

  • sources
  • kde-4.12
  • kdegraphics
  • okular
  • active
  • app
  • package
  • contents
  • ui
FullScreenDelegate.qml
Go to the documentation of this file.
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 General Public License as
6  * published by the Free Software Foundation; either version 2,
7  * or (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 General Public License for more details
13  *
14  * You should have received a copy of the GNU 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.core 0.1 as PlasmaCore
22 import org.kde.plasma.extras 0.1 as PlasmaExtra
23 import org.kde.plasma.components 0.1 as PlasmaComponents
24 import org.kde.plasma.mobilecomponents 0.1 as MobileComponents
25 import org.kde.qtextracomponents 0.1
26 import org.kde.okular 0.1 as Okular
27 
28 MouseEventListener {
29  id: root
30  //+1: switch to next image on mouse release
31  //-1: switch to previous image on mouse release
32  //0: do nothing
33  property int delta
34 
35 
36  property Item flickable: mainFlickable
37  property bool pageSwitchEnabled: false
38  property alias document: mainPage.document
39  property alias pageNumber: mainPage.pageNumber
40  property Item pageItem: mainPage
41 
42  onWheelMoved: {
43  if (wheel.modifiers == Qt.ControlModifier) {
44  var factor = wheel.delta > 0 ? 1.1 : 0.9
45  if (scale(factor)) {
46  pageArea.oldDelegate.scale(mainPage.width / mainPage.implicitWidth, true)
47  }
48  }
49  }
50 
51  function scale(zoom, absolute) {
52  var newScale = absolute ? zoom : (mainPage.width / mainPage.implicitWidth) * zoom;
53  if (newScale < 0.3 || newScale > 3) {
54  return false
55  }
56 
57  if (imageMargin.zooming) {
58  // pinch is happening!
59  mainPage.width = imageMargin.startWidth * zoom
60  mainPage.height = imageMargin.startHeight * zoom
61  } else if (absolute) {
62  // we were given an absolute, not a relative, scale
63  mainPage.width = mainPage.implicitWidth * zoom
64  mainPage.height = mainPage.implicitHeight * zoom
65  } else {
66  mainPage.width *= zoom
67  mainPage.height *= zoom
68  }
69 
70  return true
71  }
72 
73  Rectangle {
74  id: backgroundRectangle
75  x: -mainFlickable.contentX + mainPage.x
76  y: 0
77  anchors {
78  top: parent.top
79  bottom: parent.bottom
80  }
81  width: mainPage.width
82  color: "white"
83 
84  Image {
85  source: "image://appbackgrounds/shadow-left"
86  fillMode: Image.TileVertically
87  opacity: 0.5
88  anchors {
89  right: parent.left
90  top: parent.top
91  bottom: parent.bottom
92  }
93  }
94  Image {
95  source: "image://appbackgrounds/shadow-right"
96  fillMode: Image.TileVertically
97  opacity: 0.5
98  anchors {
99  left: parent.right
100  top: parent.top
101  bottom: parent.bottom
102  }
103  }
104  }
105 
106  Flickable {
107  id: mainFlickable
108  property real ratio : width / height
109  anchors.fill: parent
110  width: parent.width
111  height: parent.height
112  contentWidth: imageMargin.width
113  contentHeight: imageMargin.height
114 
115  onContentXChanged: {
116  if (atXBeginning && contentX < 0) {
117  root.delta = -1
118  } else if (atXEnd) {
119  root.delta = +1
120  } else {
121  root.delta = 0
122  }
123  }
124 
125  PinchArea {
126  id: imageMargin
127  width: Math.max(mainFlickable.width + (pageSwitchEnabled ? 1: 0), mainPage.width)
128  height: Math.max(mainFlickable.height, mainPage.height)
129 
130  property real startWidth
131  property real startHeight
132  property real startY
133  property real startX
134  property bool zooming: false
135  onPinchStarted: {
136  startWidth = mainPage.width
137  startHeight = mainPage.height
138  zooming = true
139  startY = pinch.center.y
140  startX = pinch.center.x
141  pageArea.oldDelegate.visible = false
142  }
143  onPinchUpdated: {
144  var deltaWidth = mainPage.width < imageMargin.width ? ((startWidth * pinch.scale) - mainPage.width) : 0
145  var deltaHeight = mainPage.height < imageMargin.height ? ((startHeight * pinch.scale) - mainPage.height) : 0
146  if (root.scale(pinch.scale)) {
147  mainFlickable.contentY += pinch.previousCenter.y - pinch.center.y + startY * (pinch.scale - pinch.previousScale) - deltaHeight
148  mainFlickable.contentX += pinch.previousCenter.x - pinch.center.x + startX * (pinch.scale - pinch.previousScale) - deltaWidth
149  }
150  }
151  onPinchFinished: {
152  mainFlickable.returnToBounds()
153  pageArea.oldDelegate.scale(mainPage.width / mainPage.implicitWidth)
154  pageArea.oldDelegate.visible = true
155  zooming = false
156  }
157 
158  Okular.PageItem {
159  id: mainPage
160  document: documentItem
161  flickable: mainFlickable
162  property real ratio: implicitWidth / implicitHeight
163 
164  x: Math.round((parent.width - width) / 2)
165  y: Math.round((parent.height - height) / 2)
166  width: implicitWidth
167  height: implicitHeight
168  }
169  }
170  }
171  Image {
172  source: "bookmark.png"
173  anchors {
174  top: parent.top
175  right: backgroundRectangle.right
176  rightMargin: -5
177  topMargin: mainPage.bookmarked ? -30 : -120
178  }
179  Behavior on anchors.topMargin {
180  NumberAnimation {
181  duration: 250
182  }
183  }
184 
185  MouseArea {
186  anchors {
187  fill: parent
188  margins: -8
189  }
190  onClicked: mainPage.bookmarked = !mainPage.bookmarked
191  }
192  }
193 }
MouseEventListener
Image
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:45:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okular

Skip menu "okular"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkdcraw
  •     libkexiv2
  •     libkipi
  •     libksane
  • okular

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal