Warning, /graphics/peruse/src/creator/qml/BookBasics.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.Layouts 1.4
0024 import QtQuick.Controls 2.12 as QtControls
0025 
0026 import org.kde.kirigami 2.13 as Kirigami
0027 
0028 import org.kde.peruse 0.1 as Peruse
0029 /**
0030  * @brief the page shows basic information about the book
0031  */
0032 Kirigami.ScrollablePage {
0033     id: root;
0034     property string categoryName: "bookBasics";
0035     property QtObject model;
0036     signal requestCategoryChange(string categoryName);
0037     title: i18nc("title of the basic book information page", "Your Book At A Glance");
0038     actions {
0039         main: saveBookAction;
0040     }
0041     Kirigami.Action {
0042         id: saveBookAction;
0043         text: i18nc("Saves the book to a file on disk", "Save Book");
0044         iconName: "document-save";
0045         onTriggered: root.model.saveBook();
0046         enabled: root.model ? root.model.hasUnsavedChanges : false;
0047     }
0048     ListView {
0049         model: root.model.fileEntries;
0050         header: ColumnLayout {
0051             width: ListView.view.width
0052             spacing: Kirigami.Units.gridUnit;
0053             Item {
0054                 id: bookCover;
0055                 Layout.alignment: Qt.AlignHCenter;
0056                 Layout.margins: Kirigami.Units.largeSpacing;
0057                 width: Kirigami.Units.gridUnit * 10;
0058                 height: width;
0059                 Rectangle {
0060                     id: coverOutline;
0061                     anchors.centerIn: coverImage;
0062                     width: Math.max(coverImage.paintedWidth, Kirigami.Units.iconSizes.large) + Kirigami.Units.smallSpacing * 2;
0063                     height: Math.max(coverImage.paintedHeight, Kirigami.Units.iconSizes.large) + Kirigami.Units.smallSpacing * 2;
0064                     color: Kirigami.Theme.backgroundColor;
0065                     border {
0066                         width: 2;
0067                         color: Kirigami.Theme.textColor;
0068                     }
0069                     radius: 2;
0070                 }
0071                 Kirigami.Icon {
0072                     id: coverImage;
0073                     anchors {
0074                         fill: parent;
0075                         margins: Kirigami.Units.largeSpacing;
0076                     }
0077                     source: bookModel.filename === "" ? "" : "image://comiccover/" + bookModel.filename;
0078                     placeholder: "application-vnd.oasis.opendocument.text";
0079                     fallback: "paint-unknown";
0080                 }
0081             }
0082             Kirigami.FormLayout {
0083                 Layout.fillWidth: true;
0084                 Layout.margins: Kirigami.Units.largeSpacing;
0085                 QtControls.Label {
0086                     Kirigami.FormData.label: i18nc("The descriptive label for a label which displays the title of the book", "Book Title:");
0087                     text: root.model ? root.model.title : "";
0088                 }
0089                 Kirigami.LinkButton {
0090                     Kirigami.FormData.label: i18nc("The descriptive label for a link which shows the number of pages in the book", "Pages:");
0091                     text: i18nc("A link which when clicked shows the book pages editor", "%1 total pages", root.model ? root.model.pageCount : 0);
0092                     onClicked: root.requestCategoryChange("book");
0093                 }
0094             }
0095             Kirigami.Heading {
0096                 Layout.fillWidth: true;
0097                 Layout.margins: Kirigami.Units.largeSpacing;
0098                 text: i18nc("Header for a list which shows every file contained in the archive which makes up this book", "Every File In The Book:");
0099             }
0100         }
0101         delegate: Kirigami.SwipeListItem {
0102             id: listItem;
0103             property int depth: (modelData.match(/\//g) || []).length;
0104             property bool isDirectory: root.model.fileEntryIsDirectory(modelData);
0105             property bool markedForDeletion: root.model.fileEntriesToDelete.includes(modelData);
0106             property int isReferenced: root.model.fileEntryReferenced(modelData);
0107             height: Kirigami.Units.iconSizes.huge + Kirigami.Units.smallSpacing * 2;
0108             supportsMouseEvents: true;
0109             onClicked: {
0110                 // Show a dialog with details for this file...
0111             }
0112             actions: [
0113                 Kirigami.Action {
0114                     text: listItem.markedForDeletion
0115                         ? i18nc("action which marks the file to be included next time the book is saved", "Include File")
0116                         : i18nc("action which marks the file to NOT be included next time the book is saved", "Mark File For Deletion");
0117                     iconName: listItem.markedForDeletion ? "list-add" : "list-remove"
0118                     onTriggered: {
0119                         root.model.markArchiveFileForDeletion(modelData, !listItem.markedForDeletion);
0120                     }
0121                     visible: !listItem.isDirectory;
0122                 }
0123             ]
0124             contentItem: RowLayout {
0125                 Layout.fillWidth: true;
0126                 Layout.fillHeight: true;
0127                 Repeater {
0128                     model: listItem.depth;
0129                     Rectangle {
0130                         Layout.fillHeight: true;
0131                         Layout.minimumWidth: 1;
0132                         Layout.maximumWidth: 1;
0133                         color: Kirigami.Theme.textColor;
0134                     }
0135                 }
0136                 Item {
0137                     id: thumbnail;
0138                     Layout.fillHeight: true;
0139                     Layout.minimumWidth: height;
0140                     Layout.maximumWidth: height;
0141                     Image {
0142                         id: coverImage;
0143                         anchors {
0144                             fill: parent;
0145                             margins: Kirigami.Units.smallSpacing;
0146                         }
0147                         asynchronous: true;
0148                         fillMode: Image.PreserveAspectFit;
0149                         source: root.model.previewForId(modelData);
0150                     }
0151                     Image {
0152                         anchors {
0153                             bottom: parent.bottom;
0154                             left: parent.left;
0155                         }
0156                         height: parent.height / 3;
0157                         width: height;
0158                         source: "image://icon/emblem-warning";
0159                         opacity: listItem.markedForDeletion && listItem.isReferenced > 0 ? 1 : 0;
0160                         Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
0161                     }
0162                     Image {
0163                         anchors {
0164                             bottom: parent.bottom;
0165                             right: parent.right;
0166                         }
0167                         height: parent.height / 3;
0168                         width: height;
0169                         source: "image://icon/package-remove";
0170                         opacity: listItem.markedForDeletion ? 1 : 0;
0171                         Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
0172                     }
0173                 }
0174                 ColumnLayout {
0175                     Layout.fillWidth: true;
0176                     Layout.fillHeight: true;
0177                     QtControls.Label {
0178                         Layout.fillWidth: true;
0179                         elide: Text.ElideMiddle;
0180                         text: {
0181                             if (listItem.depth === 0) {
0182                                 return modelData;
0183                             } else {
0184                                 var splitData = modelData.split("/");
0185                                 return splitData[splitData.length - 1];
0186                             }
0187                         }
0188                     }
0189                     QtControls.Label {
0190                         Layout.fillWidth: true;
0191                         visible: !listItem.isDirectory;
0192                         elide: Text.ElideRight;
0193                         text: {
0194                             if (listItem.isReferenced === 0) {
0195                                 return i18nc("If a file is not referenced at all", "Unreferenced file");
0196                             } else if (listItem.isReferenced === 1) {
0197                                 return i18nc("If a file is referenced by its full path", "Referenced by full path");
0198                             } else if (listItem.isReferenced === 2) {
0199                                 return i18nc("If a file is referenced partially, describe that", "Referenced by filename only");
0200                             } else {
0201                                 return i18nc("What happens if we have an unexpected reference amount", "%1 might be referenced, but in some way we've not accounted for");
0202                             }
0203                         }
0204                     }
0205                 }
0206             }
0207         }
0208     }
0209 }