port to Documentview

frameworks
Marco Martin 11 years ago
parent 79622ee9a3
commit be805e906e
  1. 130
      mobile/app/package/contents/ui/Browser.qml
  2. 240
      mobile/app/package/contents/ui/FullScreenDelegate.qml
  3. 1
      mobile/app/package/contents/ui/ThumbnailsBase.qml
  4. 53
      mobile/components/DocumentView.qml
  5. 5
      mobile/components/private/PageView.qml
  6. 2
      mobile/components/testDocumentView.qml

@ -33,10 +33,11 @@ MobileComponents.SplitDrawer {
property alias splitDrawerOpen: splitDrawer.open property alias splitDrawerOpen: splitDrawer.open
property alias overlayDrawerOpen: resourceBrowser.open property alias overlayDrawerOpen: resourceBrowser.open
//An alias doesn't work //An alias doesn't work
property bool bookmarked: pageArea.delegate.bookmarked property bool bookmarked: false
onBookmarkedChanged: { onBookmarkedChanged: {
pageArea.delegate.bookmarked = bookmarked pageArea.page.bookmarked = bookmarked
} }
drawer: Documents { drawer: Documents {
@ -48,126 +49,21 @@ MobileComponents.SplitDrawer {
anchors.fill: parent anchors.fill: parent
visible: true visible: true
MouseEventListener { Okular.DocumentView {
id: pageArea id: pageArea
document: documentItem
anchors.fill: parent anchors.fill: parent
clip: true
//enabled: !delegate.interactive
property Item delegate: delegate1
property Item oldDelegate: delegate2
property bool incrementing: delegate.delta > 0
property bool bookmarked: delegate.bookmarked
onBookmarkedChanged: {
splitDrawer.bookmarked = delegate.bookmarked;
}
Connections {
target: pageArea.delegate
onDeltaChanged: {
pageArea.oldDelegate.delta = pageArea.delegate.delta
if (pageArea.delegate.delta > 0) {
pageArea.oldDelegate.visible = true
pageArea.oldDelegate.pageNumber = pageArea.delegate.pageNumber + 1
documentItem.currentPage = pageArea.oldDelegate.pageNumber
pageArea.oldDelegate.visible = !(pageArea.delegate.pageNumber == documentItem.pageCount-1)
} else if (pageArea.delegate.delta < 0) {
pageArea.oldDelegate.pageNumber = pageArea.delegate.pageNumber - 1
documentItem.currentPage = pageArea.oldDelegate.pageNumber
pageArea.oldDelegate.visible = pageArea.delegate.pageNumber != 0
}
}
}
property int startMouseScreenX
property int startMouseScreenY
onPressed: {
startMouseScreenX = mouse.screenX
startMouseScreenY = mouse.screenY
}
onPositionChanged: {
if (Math.abs(mouse.screenX - startMouseScreenX) > width/5) {
delegate.pageSwitchEnabled = true
}
}
onReleased: {
delegate.pageSwitchEnabled = false
if (Math.abs(mouse.screenX - startMouseScreenX) < 20 &&
Math.abs(mouse.screenY - startMouseScreenY) < 20) {
} else if (oldDelegate.visible && delegate.delta != 0 && onPageChanged: {
(Math.abs(mouse.screenX - startMouseScreenX) > width/5) && bookmarkConnection.target = page
Math.abs(mouse.screenX - startMouseScreenX) > Math.abs(mouse.screenY - startMouseScreenY)) { splitDrawer.bookmarked = page.bookmarked
oldDelegate = delegate
delegate = (delegate == delegate1) ? delegate2 : delegate1
switchAnimation.running = true
}
}
FullScreenDelegate {
id: delegate2
width: parent.width
height: parent.height
}
FullScreenDelegate {
id: delegate1
width: parent.width
height: parent.height
Component.onCompleted: pageNumber = documentItem.currentPage
}
SequentialAnimation {
id: switchAnimation
NumberAnimation {
target: pageArea.oldDelegate
properties: "x"
to: pageArea.incrementing ? -pageArea.oldDelegate.width : pageArea.oldDelegate.width
easing.type: Easing.InQuad
duration: units.longDuration
}
ScriptAction {
script: {
pageArea.oldDelegate.z = 0
pageArea.delegate.z = 10
}
}
NumberAnimation {
target: pageArea.oldDelegate
properties: "x"
to: 0
easing.type: Easing.InQuad
duration: units.longDuration
}
ScriptAction {
script: {
pageArea.oldDelegate.x = 0
pageArea.delegate.x = 0
delegate1.delta = delegate2.delta = 0
}
}
} }
} }
PlasmaComponents.ScrollBar { //HACK
flickableItem: pageArea.delegate.flickable Connections {
orientation: Qt.Vertical id: bookmarkConnection
anchors { target: pageArea.page
right: pageArea.right onBookmarkedChanged: splitDrawer.bookmarked = pageArea.page.bookmarked
top: pageArea.top
bottom: pageArea.bottom
left: undefined
}
}
PlasmaComponents.ScrollBar {
flickableItem: pageArea.delegate.flickable
orientation: Qt.Horizontal
visible: pageArea.delegate.width > pageArea.width
anchors {
left: pageArea.left
right: pageArea.right
bottom: pageArea.bottom
top: undefined
}
} }
drawer: Item { drawer: Item {

@ -1,240 +0,0 @@
/*
* Copyright 2011 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.1
import QtGraphicalEffects 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.extras 2.0 as PlasmaExtra
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.mobilecomponents 0.2 as MobileComponents
import org.kde.kquickcontrolsaddons 2.0
import org.kde.okular 2.0 as Okular
MouseEventListener {
id: root
//+1: switch to next image on mouse release
//-1: switch to previous image on mouse release
//0: do nothing
property int delta
property Item flickable: mainFlickable
property bool pageSwitchEnabled: false
property alias document: mainPage.document
property alias pageNumber: mainPage.pageNumber
property Item pageItem: mainPage
property alias bookmarked: mainPage.bookmarked
onWheelMoved: {
if (wheel.modifiers == Qt.ControlModifier) {
var factor = wheel.delta > 0 ? 1.1 : 0.9
if (scale(factor)) {
pageArea.oldDelegate.scale(mainPage.width / mainPage.implicitWidth, true)
}
}
}
function scale(zoom, absolute) {
var newScale = absolute ? zoom : (mainPage.width / mainPage.implicitWidth) * zoom;
if (newScale < 0.3 || newScale > 3) {
return false
}
if (imageMargin.zooming) {
// pinch is happening!
mainPage.width = imageMargin.startWidth * zoom
mainPage.height = imageMargin.startHeight * zoom
} else if (absolute) {
// we were given an absolute, not a relative, scale
mainPage.width = mainPage.implicitWidth * zoom
mainPage.height = mainPage.implicitHeight * zoom
} else {
mainPage.width *= zoom
mainPage.height *= zoom
}
pageArea.oldDelegate.pageItem.width = mainPage.width;
pageArea.oldDelegate.pageItem.height = mainPage.height;
return true
}
Rectangle {
id: backgroundRectangle
x: -mainFlickable.contentX + mainPage.x
y: 0
anchors {
top: parent.top
bottom: parent.bottom
}
width: mainPage.width
color: "white"
LinearGradient {
width: units.gridUnit/2
anchors {
right: parent.left
top: parent.top
bottom: parent.bottom
}
start: Qt.point(0, 0)
end: Qt.point(units.gridUnit/2, 0)
gradient: Gradient {
GradientStop {
position: 0.0
color: "transparent"
}
GradientStop {
position: 0.7
color: Qt.rgba(0, 0, 0, 0.08)
}
GradientStop {
position: 1.0
color: Qt.rgba(0, 0, 0, 0.2)
}
}
}
LinearGradient {
width: units.gridUnit/2
anchors {
left: parent.right
top: parent.top
bottom: parent.bottom
}
start: Qt.point(0, 0)
end: Qt.point(units.gridUnit/2, 0)
gradient: Gradient {
GradientStop {
position: 0.0
color: Qt.rgba(0, 0, 0, 0.2)
}
GradientStop {
position: 0.3
color: Qt.rgba(0, 0, 0, 0.08)
}
GradientStop {
position: 1.0
color: "transparent"
}
}
}
Image {
source: "image://appbackgrounds/shadow-right"
fillMode: Image.TileVertically
opacity: 0.5
anchors {
left: parent.right
top: parent.top
bottom: parent.bottom
}
}
}
Flickable {
id: mainFlickable
property real ratio : width / height
anchors.fill: parent
width: parent.width
height: parent.height
contentWidth: imageMargin.width
contentHeight: imageMargin.height
boundsBehavior: Flickable.DragAndOvershootBounds
flickableDirection: Flickable.HorizontalAndVerticalFlick
onContentXChanged: {
if (atXBeginning && contentX < 0) {
root.delta = -1
} else if (atXEnd) {
root.delta = +1
} else {
root.delta = 0
}
}
PinchArea {
id: imageMargin
width: Math.max(mainFlickable.width+1, mainPage.width)
height: Math.max(mainFlickable.height, mainPage.height)
property real startWidth
property real startHeight
property real startY
property real startX
property bool zooming: false
onPinchStarted: {
startWidth = mainPage.width
startHeight = mainPage.height
zooming = true
startY = pinch.center.y
startX = pinch.center.x
pageArea.oldDelegate.visible = false
}
onPinchUpdated: {
var deltaWidth = mainPage.width < imageMargin.width ? ((startWidth * pinch.scale) - mainPage.width) : 0
var deltaHeight = mainPage.height < imageMargin.height ? ((startHeight * pinch.scale) - mainPage.height) : 0
if (root.scale(pinch.scale)) {
mainFlickable.contentY += pinch.previousCenter.y - pinch.center.y + startY * (pinch.scale - pinch.previousScale) - deltaHeight
mainFlickable.contentX += pinch.previousCenter.x - pinch.center.x + startX * (pinch.scale - pinch.previousScale) - deltaWidth
}
}
onPinchFinished: {
mainFlickable.returnToBounds()
pageArea.oldDelegate.scale(mainPage.width / mainPage.implicitWidth)
pageArea.oldDelegate.visible = true
zooming = false
}
Okular.PageItem {
id: mainPage
document: documentItem
flickable: mainFlickable
property real ratio: implicitWidth / implicitHeight
x: Math.round((parent.width - width) / 2)
y: Math.round((parent.height - height) / 2)
width: root.width
height: width / ratio
}
}
}
Image {
source: "bookmark.png"
anchors {
top: parent.top
right: backgroundRectangle.right
rightMargin: -5
topMargin: mainPage.bookmarked ? -30 : -120
}
Behavior on anchors.topMargin {
NumberAnimation {
duration: 250
}
}
MouseArea {
anchors {
fill: parent
margins: -8
}
onClicked: mainPage.bookmarked = !mainPage.bookmarked
}
}
}

@ -89,7 +89,6 @@ PlasmaComponents.Page {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
resultsGrid.currentIndex = index resultsGrid.currentIndex = index
pageArea.delegate.pageNumber = modelData
documentItem.currentPage = modelData documentItem.currentPage = modelData
resourceBrowser.open = false resourceBrowser.open = false

@ -18,6 +18,7 @@
*/ */
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 1.2 as QtControls
import org.kde.okular 2.0 import org.kde.okular 2.0
import "./private" import "./private"
@ -27,24 +28,32 @@ import "./private"
* It supports changing pages by a swipe gesture, pinch zoom * It supports changing pages by a swipe gesture, pinch zoom
* and flicking to scroll around * and flicking to scroll around
*/ */
Item { QtControls.ScrollView {
id: root id: root
width: 500 property DocumentItem document
height: 600 property PageItem page: mouseArea.currPageDelegate.pageItem
property DocumentItem documentItem
Flickable { Flickable {
id: flick id: flick
anchors.fill: parent
clip: true
Component.onCompleted: { Component.onCompleted: {
flick.contentWidth = flick.width flick.contentWidth = flick.width
flick.contentHeight = flick.width / mouseArea.currPageDelegate.pageRatio flick.contentHeight = flick.width / mouseArea.currPageDelegate.pageRatio
} }
onWidthChanged: { onWidthChanged: resizeTimer.restart()
flick.contentWidth = flick.width onHeightChanged: resizeTimer.restart()
flick.contentHeight = flick.width / mouseArea.currPageDelegate.pageRatio Connections {
target: root.document
onPathChanged: resizeTimer.restart()
}
Timer {
id: resizeTimer
interval: 250
onTriggered: {
flick.contentWidth = flick.width
flick.contentHeight = flick.width / mouseArea.currPageDelegate.pageRatio
}
} }
PinchArea { PinchArea {
@ -98,10 +107,10 @@ Item {
oldMouseY = pos.y; oldMouseY = pos.y;
} }
onReleased: { onReleased: {
if (root.documentItem.currentPage > 0 && if (root.document.currentPage > 0 &&
currPageDelegate.x > width/6) { currPageDelegate.x > width/6) {
switchAnimation.running = true; switchAnimation.running = true;
} else if (root.documentItem.currentPage < documentItem.pageCount-1 && } else if (root.document.currentPage < document.pageCount-1 &&
currPageDelegate.x < -width/6) { currPageDelegate.x < -width/6) {
switchAnimation.running = true; switchAnimation.running = true;
} else { } else {
@ -120,17 +129,17 @@ Item {
PageView { PageView {
id: page1 id: page1
document: root.documentItem document: root.document
z: 2 z: 2
} }
PageView { PageView {
id: page2 id: page2
document: root.documentItem document: root.document
z: 1 z: 1
} }
PageView { PageView {
id: page3 id: page3
document: root.documentItem document: root.document
z: 0 z: 0
} }
@ -138,7 +147,7 @@ Item {
Binding { Binding {
target: mouseArea.currPageDelegate target: mouseArea.currPageDelegate
property: "pageNumber" property: "pageNumber"
value: root.documentItem.currentPage value: root.document.currentPage
} }
Binding { Binding {
target: mouseArea.currPageDelegate target: mouseArea.currPageDelegate
@ -149,23 +158,23 @@ Item {
Binding { Binding {
target: mouseArea.prevPageDelegate target: mouseArea.prevPageDelegate
property: "pageNumber" property: "pageNumber"
value: root.documentItem.currentPage - 1 value: root.document.currentPage - 1
} }
Binding { Binding {
target: mouseArea.prevPageDelegate target: mouseArea.prevPageDelegate
property: "visible" property: "visible"
value: !mouseArea.incrementing && root.documentItem.currentPage > 0 value: !mouseArea.incrementing && root.document.currentPage > 0
} }
Binding { Binding {
target: mouseArea.nextPageDelegate target: mouseArea.nextPageDelegate
property: "pageNumber" property: "pageNumber"
value: root.documentItem.currentPage + 1 value: root.document.currentPage + 1
} }
Binding { Binding {
target: mouseArea.nextPageDelegate target: mouseArea.nextPageDelegate
property: "visible" property: "visible"
value: mouseArea.incrementing && root.documentItem.currentPage < documentItem.pageCount-1 value: mouseArea.incrementing && root.document.currentPage < document.pageCount-1
} }
SequentialAnimation { SequentialAnimation {
@ -194,12 +203,12 @@ Item {
var oldNext = mouseArea.nextPageDelegate; var oldNext = mouseArea.nextPageDelegate;
if (mouseArea.incrementing) { if (mouseArea.incrementing) {
root.documentItem.currentPage++; root.document.currentPage++;
mouseArea.currPageDelegate = oldNext; mouseArea.currPageDelegate = oldNext;
mouseArea.prevPageDelegate = oldCur; mouseArea.prevPageDelegate = oldCur;
mouseArea. nextPageDelegate = oldPrev; mouseArea. nextPageDelegate = oldPrev;
} else { } else {
root.documentItem.currentPage--; root.document.currentPage--;
mouseArea.currPageDelegate = oldPrev; mouseArea.currPageDelegate = oldPrev;
mouseArea.prevPageDelegate = oldCur; mouseArea.prevPageDelegate = oldCur;
mouseArea. nextPageDelegate = oldNext; mouseArea. nextPageDelegate = oldNext;

@ -19,11 +19,12 @@
import QtQuick 2.2 import QtQuick 2.2
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
import org.kde.okular 2.0 as Okular import org.kde.okular 2.0
Item { Item {
width: parent.width width: parent.width
height: parent.height height: parent.height
property PageItem pageItem: page
property alias document: page.document property alias document: page.document
property alias pageNumber: page.pageNumber property alias pageNumber: page.pageNumber
implicitWidth: page.implicitWidth implicitWidth: page.implicitWidth
@ -31,7 +32,7 @@ Item {
property real pageRatio: page.implicitWidth / page.implicitHeight property real pageRatio: page.implicitWidth / page.implicitHeight
property real scaleFactor: page.width / page.implicitWidth property real scaleFactor: page.width / page.implicitWidth
Okular.PageItem { PageItem {
id: page id: page
property bool sameOrientation: parent.width / parent.height > pageRatio property bool sameOrientation: parent.width / parent.height > pageRatio
anchors.centerIn: parent anchors.centerIn: parent

@ -30,6 +30,6 @@ Item {
} }
Okular.DocumentView { Okular.DocumentView {
anchors.fill: parent anchors.fill: parent
documentItem: docItem document: docItem
} }
} }
Loading…
Cancel
Save