port to Documentview

This commit is contained in:
Marco Martin 2015-09-24 20:34:00 +02:00
parent 79622ee9a3
commit be805e906e
6 changed files with 48 additions and 383 deletions

View file

@ -33,10 +33,11 @@ MobileComponents.SplitDrawer {
property alias splitDrawerOpen: splitDrawer.open
property alias overlayDrawerOpen: resourceBrowser.open
//An alias doesn't work
property bool bookmarked: pageArea.delegate.bookmarked
property bool bookmarked: false
onBookmarkedChanged: {
pageArea.delegate.bookmarked = bookmarked
pageArea.page.bookmarked = bookmarked
}
drawer: Documents {
@ -48,126 +49,21 @@ MobileComponents.SplitDrawer {
anchors.fill: parent
visible: true
MouseEventListener {
Okular.DocumentView {
id: pageArea
document: documentItem
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 &&
(Math.abs(mouse.screenX - startMouseScreenX) > width/5) &&
Math.abs(mouse.screenX - startMouseScreenX) > Math.abs(mouse.screenY - startMouseScreenY)) {
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
}
}
onPageChanged: {
bookmarkConnection.target = page
splitDrawer.bookmarked = page.bookmarked
}
}
PlasmaComponents.ScrollBar {
flickableItem: pageArea.delegate.flickable
orientation: Qt.Vertical
anchors {
right: pageArea.right
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
}
//HACK
Connections {
id: bookmarkConnection
target: pageArea.page
onBookmarkedChanged: splitDrawer.bookmarked = pageArea.page.bookmarked
}
drawer: Item {

View file

@ -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
}
}
}

View file

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

View file

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

View file

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

View file

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