Warning, /graphics/peruse/src/creator/qml/Book.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 that deals with editing the book.
0031 *
0032 * This is primarily a list of pages that can be moved around. These are inside
0033 * Kirigami ListSwipeItems.
0034 *
0035 * This also has a button to add pages, which calls up AddPageSheet.
0036 * And a button to edit the book metadata, which calls up BookMetainfoPage.
0037 */
0038 Kirigami.ScrollablePage {
0039 id: root;
0040 property string categoryName: "book";
0041 property alias model: bookList.model;
0042 title: i18nc("title of the main book editor page", "Pages in %1", root.model && root.model.title !== "" ? root.model.title : "");
0043
0044 actions {
0045 main: addPageSheet.opened ? closeAddPageSheetAction : saveBookAction;
0046 right: addPageSheet.opened ? null : addPageAction;
0047 }
0048 Kirigami.Action {
0049 id: saveBookAction;
0050 text: i18nc("Saves the book to a file on disk", "Save Book");
0051 iconName: "document-save";
0052 onTriggered: root.model.saveBook();
0053 enabled: root.model ? root.model.hasUnsavedChanges : false;
0054 }
0055 Kirigami.Action {
0056 id: addPageAction;
0057 text: i18nc("adds a new page at the end of the book", "Add Page");
0058 iconName: "list-add";
0059 onTriggered: addPage(root.model.pageCount);
0060 }
0061 Kirigami.Action {
0062 id: closeAddPageSheetAction;
0063 text: i18nc("closes the add page sheet", "Do not Add a Page");
0064 iconName: "dialog-cancel";
0065 onTriggered: addPageSheet.close();
0066 }
0067
0068 function addPage(afterWhatIndex) {
0069 addPageSheet.addPageAfter = afterWhatIndex;
0070 addPageSheet.open();
0071 }
0072
0073 ListView {
0074 id: bookList;
0075 Component {
0076 id: editBookPage;
0077 BookPage {
0078 model: root.model;
0079 onSave: {
0080 bookList.updateTitle(index, currentPage.title(""));
0081 }
0082 }
0083 }
0084 function updateTitle(index, title) {
0085 //Need to add feature to update data here.
0086 }
0087
0088 delegate: Kirigami.SwipeListItem {
0089 id: listItem;
0090 height: Kirigami.Units.iconSizes.huge + Kirigami.Units.smallSpacing * 2;
0091 supportsMouseEvents: true;
0092 onClicked: ;
0093 actions: [
0094 Kirigami.Action {
0095 text: i18nc("swap the position of this page with the previous one", "Move Up");
0096 iconName: "go-up"
0097 onTriggered: { root.model.swapPages(model.index, model.index - 1); }
0098 enabled: model.index > 0;
0099 visible: enabled;
0100 },
0101 Kirigami.Action {
0102 text: i18nc("swap the position of this page with the next one", "Move Down");
0103 iconName: "go-down"
0104 onTriggered: { root.model.swapPages(model.index, model.index + 1); }
0105 enabled: model.index < root.model.pageCount - 1;
0106 visible: enabled;
0107 },
0108 Kirigami.Action {
0109 text: i18nc("remove the page from the book", "Delete Page");
0110 iconName: "list-remove"
0111 onTriggered: root.model.removePage(model.index);
0112 },
0113 Kirigami.Action {
0114 text: i18nc("add a page to the book after this one", "Add Page After This");
0115 iconName: "list-add"
0116 onTriggered: root.addPage(model.index);
0117 },
0118 Kirigami.Action {
0119 text: i18nc("Edit page data such as title, frames, etc.", "Edit Page");
0120 iconName: "document-edit";
0121 onTriggered: {
0122 pageStack.push(editBookPage, { index: model.index, pageUrl: model.url })
0123 }
0124 }
0125
0126 ]
0127 contentItem: RowLayout {
0128 Layout.fillWidth: true;
0129 Layout.fillHeight: true;
0130 Item {
0131 id: bookCover;
0132 Layout.fillHeight: true;
0133 Layout.minimumWidth: height;
0134 Layout.maximumWidth: height;
0135 Image {
0136 id: coverImage;
0137 anchors {
0138 fill: parent;
0139 margins: Kirigami.Units.smallSpacing;
0140 }
0141 asynchronous: true;
0142 fillMode: Image.PreserveAspectFit;
0143 source: model.url;
0144 }
0145 }
0146 QtControls.Label {
0147 Layout.fillWidth: true;
0148 Layout.fillHeight: true;
0149 text: model.title;
0150 }
0151 }
0152 }
0153 Rectangle {
0154 id: processingBackground;
0155 anchors.fill: parent;
0156 opacity: root.model && root.model.processing ? 0.5 : 0;
0157 Behavior on opacity { NumberAnimation { duration: mainWindow.animationDuration; } }
0158 MouseArea {
0159 anchors.fill: parent;
0160 enabled: parent.opacity > 0;
0161 onClicked: { }
0162 }
0163 Kirigami.PlaceholderMessage {
0164 anchors.centerIn: parent
0165 width: parent.width - (Kirigami.Units.largeSpacing * 4)
0166 text: root.model ? root.model.processingDescription : "";
0167 }
0168 }
0169 QtControls.BusyIndicator {
0170 anchors {
0171 horizontalCenter: processingBackground.horizontalCenter;
0172 top: parent.top
0173 topMargin: x;
0174 }
0175 running: processingBackground.opacity > 0;
0176 visible: running;
0177 }
0178 }
0179
0180 AddPageSheet {
0181 id: addPageSheet;
0182 model: root.model ? root.model : null;
0183 }
0184 }