Warning, /graphics/peruse/src/app/qml/viewers/folderofimages.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 
0024 import org.kde.peruse 0.1 as Peruse
0025 /**
0026  * @brief a ViewerBase for books that are folders with images.
0027  * 
0028  * It is called from Book when the opened book is one of the following files:
0029  * - inode/directory
0030  * - image/jpeg
0031  * - image/png
0032  */
0033 ViewerBase {
0034     id: root;
0035     property string title: imageBrowser.model.title;
0036     pagesModel: imageBrowser.model;
0037     pageCount: imageBrowser.model.pageCount;
0038     onRtlModeChanged: {
0039         if(rtlMode === true) {
0040             imageBrowser.layoutDirection = Qt.RightToLeft;
0041         }
0042         else {
0043             imageBrowser.layoutDirection = Qt.LeftToRight;
0044         }
0045     }
0046     onRestoreCurrentPage: {
0047         // This is un-pretty, quite obviously. But thanks to the ListView's inability to
0048         // stay in place when the geometry changes, well, this makes things simple.
0049         imageBrowser.positionViewAtIndex(imageBrowser.currentIndex, ListView.Center);
0050     }
0051 
0052     onCurrentPageChanged: {
0053         if(currentPage !== imageBrowser.currentIndex) {
0054             pageChangeAnimation.running = false;
0055             var currentPos = imageBrowser.contentX;
0056             var newPos;
0057             imageBrowser.positionViewAtIndex(currentPage, ListView.Center);
0058             imageBrowser.currentIndex = currentPage;
0059             newPos = imageBrowser.contentX;
0060             pageChangeAnimation.from = currentPos;
0061             pageChangeAnimation.to = newPos;
0062             pageChangeAnimation.running = true;
0063         }
0064     }
0065     NumberAnimation { id: pageChangeAnimation; target: imageBrowser; property: "contentX"; duration: applicationWindow().animationDuration; easing.type: Easing.InOutQuad; }
0066 
0067     Timer {
0068         id: initialPageChange;
0069         interval: applicationWindow().animationDuration;
0070         running: false;
0071         repeat: false;
0072         onTriggered: root.currentPage = imageBrowser.model.currentPage;
0073     }
0074     ImageBrowser {
0075         id: imageBrowser;
0076         anchors.fill: parent;
0077         model: Peruse.FolderBookModel {
0078             filename: root.file;
0079             onLoadingCompleted: {
0080                 root.loadingCompleted(success);
0081                 initialPageChange.start();
0082             }
0083         }
0084         onCurrentIndexChanged: {
0085             if(root.currentPage !== currentIndex) {
0086                 root.currentPage = currentIndex;
0087             }
0088         }
0089         onGoNextPage: root.goNextPage();
0090         onGoPreviousPage: root.goPreviousPage();
0091         imageWidth: root.width;
0092         imageHeight: root.height;
0093     }
0094 }