Warning, /graphics/peruse/src/app/qml/viewers/cbr.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * Copyright (C) 2015 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) version 3, or any
0008  * later version accepted by the membership of KDE e.V. (or its
0009  * successor approved by the membership of KDE e.V.), which shall
0010  * act as a proxy defined in Section 6 of version 3 of the license.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0019  *
0020  */
0021 
0022 import QtQuick 2.12
0023 import QtQuick.Controls 2.12 as QQC2
0024 import org.kde.kirigami 2.13 as Kirigami
0025 
0026 import org.kde.peruse 0.1 as Peruse
0027 /**
0028  * @brief a ViewerBase for CBR style books.
0029  * 
0030  * It is called from Book when the opened book is one of the following files:
0031  * - application/x-cbz
0032  * - application/x-cbr
0033  * - application/vnd.comicbook+zip
0034  * - application/vnd.comicbook+rar
0035  */
0036 ViewerBase {
0037     id: root;
0038     title: imageBrowser.model.title;
0039     pagesModel: imageBrowser.model;
0040     pageCount: imageBrowser.model.pageCount;
0041     property int languageCount: imageBrowser.model.acbfData? imageBrowser.model.acbfData.metaData.bookInfo.languages.length: 0;
0042     onRtlModeChanged: {
0043         if(rtlMode === true) {
0044             imageBrowser.layoutDirection = Qt.RightToLeft;
0045         }
0046         else {
0047             imageBrowser.layoutDirection = Qt.LeftToRight;
0048         }
0049         root.restoreCurrentPage();
0050     }
0051     onRestoreCurrentPage: {
0052         // This is un-pretty, quite obviously. But thanks to the ListView's inability to
0053         // stay in place when the geometry changes, well, this makes things simple.
0054         imageBrowser.positionViewAtIndex(imageBrowser.currentIndex, ListView.Center);
0055     }
0056 
0057     hasFrames: true;
0058     onNextFrame: imageBrowser.goNextFrame();
0059     onPreviousFrame: imageBrowser.goPreviousFrame();
0060 
0061     onCurrentPageChanged: {
0062         if(currentPage !== imageBrowser.currentIndex) {
0063             pageChangeAnimation.running = false;
0064             var currentPos = imageBrowser.contentX;
0065             var newPos;
0066             imageBrowser.positionViewAtIndex(currentPage, ListView.Center);
0067             imageBrowser.currentIndex = currentPage;
0068             newPos = imageBrowser.contentX;
0069             pageChangeAnimation.from = currentPos;
0070             pageChangeAnimation.to = newPos;
0071             pageChangeAnimation.running = true;
0072         }
0073     }
0074     NumberAnimation { id: pageChangeAnimation; target: imageBrowser; property: "contentX"; duration: applicationWindow().animationDuration; easing.type: Easing.InOutQuad; }
0075 
0076     viewerActions: [
0077         Kirigami.Action {
0078             shortcut: "Tab";
0079             visible: false;
0080             onTriggered: imageBrowser.switchToNextJump();
0081             enabled: !Kirigami.Settings.isMobile;
0082         },
0083         Kirigami.Action {
0084             shortcut: "Return";
0085             visible: false;
0086             onTriggered: imageBrowser.activateCurrentJump();
0087             enabled: !Kirigami.Settings.isMobile;
0088         },
0089         Kirigami.Action {
0090             id: translationsAction
0091             text: i18nc("A submenu which allows the user to chose between translations of the book", "Translations")
0092             visible: languageCount > 0;
0093             Kirigami.Action {
0094                 text: i18nc("The option used to show no translation should be used", "No Translation")
0095                 onTriggered: imageBrowser.currentLanguage = null
0096                 checked: imageBrowser.currentLanguage === null
0097                 checkable: true
0098                 QQC2.ActionGroup.group: translationSelectionGroup
0099             }
0100         }
0101     ]
0102     QQC2.ActionGroup { id: translationSelectionGroup }
0103     Component {
0104         id: translationActionEntry
0105         Kirigami.Action {
0106             id: control
0107             text: language.language
0108             visible: language.show
0109             property QtObject language
0110             onTriggered: { imageBrowser.currentLanguage = control.language; }
0111             checked: imageBrowser.currentLanguage && imageBrowser.currentLanguage === control.language
0112             checkable: true
0113             QQC2.ActionGroup.group: translationSelectionGroup
0114         }
0115     }
0116 
0117     Timer {
0118         id: initialPageChange;
0119         interval: applicationWindow().animationDuration;
0120         running: false;
0121         repeat: false;
0122         onTriggered: root.currentPage = imageBrowser.model.currentPage;
0123     }
0124     ImageBrowser {
0125         id: imageBrowser;
0126         anchors.fill: parent;
0127         property QtObject currentLanguage: null; // this should probably be read out of the system somehow, or we let the user pick a default preferred?
0128         model: Peruse.ArchiveBookModel {
0129             filename: root.file;
0130             qmlEngine: globalQmlEngine;
0131             onLoadingCompleted: {
0132                 root.loadingCompleted(success);
0133                 if (success) {
0134                     initialPageChange.start();
0135                     for (var i = 0 ; i < root.languageCount; ++i) {
0136                         var language = imageBrowser.model.acbfData.metaData.bookInfo.languages[i];
0137                         var action = translationActionEntry.createObject(translationsAction, {language: language});
0138                         translationsAction.children.push(action);
0139                     }
0140                 }
0141             }
0142         }
0143         onCurrentIndexChanged: {
0144             if(root.currentPage !== currentIndex) {
0145                 root.currentPage = currentIndex;
0146             }
0147         }
0148         onGoNextPage: root.goNextPage();
0149         onGoPreviousPage: root.goPreviousPage();
0150         onGoPage: root.goPage(pageNumber);
0151         onActivateExternalLink: root.activateExternalLink(link);
0152         imageWidth: root.width;
0153         imageHeight: root.height;
0154     }
0155 }