1/* 2 * Copyright (C) 2015 Dan Leinir Turthra Jensen <admin@leinir.dk> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) version 3, or any 8 * later version accepted by the membership of KDE e.V. (or its 9 * successor approved by the membership of KDE e.V.), which shall 10 * act as a proxy defined in Section 6 of version 3 of the license. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 19 * 20 */ 21 22import QtQuick 2.12 23 24import org.kde.peruse 0.1 as Peruse 25/** 26 * @brief a ViewerBase for CBR style books. 27 * 28 * It is called from Book when the opened book is one of the following files: 29 * - application/x-cbz 30 * - application/x-cbr 31 * - application/vnd.comicbook+zip 32 * - application/vnd.comicbook+rar 33 */ 34ViewerBase { 35 id: root; 36 title: imageBrowser.model.title; 37 pagesModel: imageBrowser.model; 38 pageCount: imageBrowser.model.pageCount; 39 onRtlModeChanged: { 40 if(rtlMode === true) { 41 imageBrowser.layoutDirection = Qt.RightToLeft; 42 } 43 else { 44 imageBrowser.layoutDirection = Qt.LeftToRight; 45 } 46 root.restoreCurrentPage(); 47 } 48 onRestoreCurrentPage: { 49 // This is un-pretty, quite obviously. But thanks to the ListView's inability to 50 // stay in place when the geometry changes, well, this makes things simple. 51 imageBrowser.positionViewAtIndex(imageBrowser.currentIndex, ListView.Center); 52 } 53 54 hasFrames: true; 55 onNextFrame: imageBrowser.goNextFrame(); 56 onPreviousFrame: imageBrowser.goPreviousFrame(); 57 58 onCurrentPageChanged: { 59 if(currentPage !== imageBrowser.currentIndex) { 60 pageChangeAnimation.running = false; 61 var currentPos = imageBrowser.contentX; 62 var newPos; 63 imageBrowser.positionViewAtIndex(currentPage, ListView.Center); 64 imageBrowser.currentIndex = currentPage; 65 newPos = imageBrowser.contentX; 66 pageChangeAnimation.from = currentPos; 67 pageChangeAnimation.to = newPos; 68 pageChangeAnimation.running = true; 69 } 70 } 71 NumberAnimation { id: pageChangeAnimation; target: imageBrowser; property: "contentX"; duration: applicationWindow().animationDuration; easing.type: Easing.InOutQuad; } 72 73 Timer { 74 id: initialPageChange; 75 interval: applicationWindow().animationDuration; 76 running: false; 77 repeat: false; 78 onTriggered: root.currentPage = imageBrowser.model.currentPage; 79 } 80 ImageBrowser { 81 id: imageBrowser; 82 anchors.fill: parent; 83 model: Peruse.ArchiveBookModel { 84 filename: root.file; 85 qmlEngine: globalQmlEngine; 86 onLoadingCompleted: { 87 root.loadingCompleted(success); 88 initialPageChange.start(); 89 } 90 } 91 onCurrentIndexChanged: { 92 if(root.currentPage !== currentIndex) { 93 root.currentPage = currentIndex; 94 } 95 } 96 onGoNextPage: root.goNextPage(); 97 onGoPreviousPage: root.goPreviousPage(); 98 imageWidth: root.width; 99 imageHeight: root.height; 100 } 101} 102