Warning, /graphics/peruse/src/creator/qml/Main.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.12
0024 import QtQuick.Controls 2.12 as QQC2
0025 import QtQuick.Window 2.12
0026 import QtQuick.Dialogs 1.3
0027 
0028 import org.kde.kirigami 2.7 as Kirigami
0029 
0030 import org.kde.peruse 0.1 as Peruse
0031 /**
0032  * @brief Main window of the application.
0033  * 
0034  * This splits the window in two sections:
0035  * - A section where you can modify a comic.
0036  * - A "global drawer" which can be used to select actions.
0037  * 
0038  * WelcomePage is the opening page and holds options to create a new comic.
0039  * CreateNewBook gives options for creating a new book from scratch.
0040  * Book is the actual book being modified.
0041  * Settings is the page with toggles and knobs for Peruse Creator config.
0042  */
0043 Kirigami.ApplicationWindow {
0044     id: mainWindow;
0045     property int animationDuration: 200;
0046     width: Math.min(Screen.desktopAvailableWidth * 0.6, Kirigami.Units.gridUnit * 80);
0047     height: Math.min(Screen.desktopAvailableHeight * 0.7, Kirigami.Units.gridUnit * 60);
0048     pageStack.initialPage: welcomePage;
0049     pageStack.defaultColumnWidth: pageStack.width
0050 
0051     Peruse.Config {
0052         id: peruseConfig;
0053     }
0054     function homeDir() {
0055         return peruseConfig.homeDir();
0056     }
0057 
0058     Peruse.ArchiveBookModel {
0059         id: bookModel;
0060         qmlEngine: globalQmlEngine;
0061         readWrite: true;
0062     }
0063 
0064     function openBook(bookFilename) {
0065         bookModel.filename = bookFilename;
0066         peruseConfig.bookOpened(bookFilename);
0067         mainWindow.changeCategory(bookPage);
0068         mainWindow.pageStack.currentItem.model = bookModel;
0069     }
0070 
0071     contextDrawer: Kirigami.ContextDrawer {}
0072     globalDrawer: Kirigami.GlobalDrawer {
0073         /// FIXME This causes the text to get cut off on the phone, however if the text is shorter
0074         /// it fails to expand the sidebar sufficiently to see all the action labels fully. Revisit
0075         /// this when switching to Kirigami
0076         title: i18nc("application title for the sidebar", "Peruse Creator");
0077         titleIcon: "peruse-creator";
0078         drawerOpen: true;
0079         modal: false;
0080         header: Kirigami.AbstractApplicationHeader {
0081             topPadding: Kirigami.Units.smallSpacing / 2;
0082             bottomPadding: Kirigami.Units.smallSpacing / 2;
0083             leftPadding: Kirigami.Units.smallSpacing
0084             rightPadding: Kirigami.Units.smallSpacing
0085             RowLayout {
0086                 anchors.fill: parent
0087 
0088                 Kirigami.Heading {
0089                     level: 1
0090                     text: i18n("Navigation")
0091                     Layout.fillWidth: true
0092                 }
0093 
0094                 QQC2.ToolButton {
0095                     icon.name: "go-home"
0096 
0097                     enabled: mainWindow.currentCategory !== "welcomePage";
0098                     onClicked: {
0099                         if (changeCategory(welcomePage)) {
0100                             pageStack.currentItem.updateRecent();
0101                         }
0102                     }
0103 
0104                     QQC2.ToolTip {
0105                         text: i18n("Switch to the welcome page")
0106                     }
0107                 }
0108             }
0109         }
0110         actions: [
0111             Kirigami.Action {
0112                 text: i18nc("Create a book", "Create a New Book...");
0113                 iconName: "document-new";
0114                 onTriggered: changeCategory(createNewBookPage);
0115             },
0116             Kirigami.Action {
0117                 text: i18nc("Open a book from somewhere on disk (uses the open dialog, or a drilldown on touch devices)", "Open Other...");
0118                 iconName: "document-open";
0119                 onTriggered: openOther();
0120             },
0121 
0122             Kirigami.Action {
0123                 id: bookActions;
0124                 visible: bookModel.filename !== "";
0125                 separator: true;
0126             },
0127             Kirigami.Action {
0128                 visible: bookActions.visible;
0129                 checked: mainWindow.currentCategory === "bookBasics";
0130                 text: bookModel.hasUnsavedChanges ? i18nc("The book's title when there are unsaved changes", "%1 (unsaved)", bookModel.title) : bookModel.title;
0131                 icon.source: bookModel.filename === "" ? "" : "image://comiccover/" + bookModel.filename;
0132                 onTriggered: changeCategory(bookBasicsPage, {model: bookModel});
0133             },
0134             Kirigami.Action {
0135                 visible: bookActions.visible;
0136                 checked: mainWindow.currentCategory === "book";
0137                 text: i18nc("Switch to the page which displays the pages in the current book", "Pages");
0138                 iconName: "view-pages-overview"
0139                 onTriggered: changeCategory(bookPage, {model: bookModel});
0140             },
0141             Kirigami.Action {
0142                 visible: bookActions.visible;
0143                 checked: mainWindow.currentCategory === "bookMetaInfo";
0144                 text: i18nc("Switch to the page where the user can edit the meta information for the entire book", "Metainfo");
0145                 iconName: "document-edit";
0146                 onTriggered: changeCategory(editMetaInfo, {model: bookModel});
0147             },
0148             Kirigami.Action {
0149                 visible: bookActions.visible;
0150                 checked: mainWindow.currentCategory === "bookReferences";
0151                 text: i18nc("Switch to the page where the user can edit the references (that is, snippets of information) found in the book", "References");
0152                 iconName: "documentation";
0153                 onTriggered: changeCategory(editReferences, {model: bookModel});
0154             },
0155             Kirigami.Action {
0156                 visible: bookActions.visible;
0157                 checked: mainWindow.currentCategory === "bookBinaries";
0158                 text: i18nc("Switch to the page where the user can work with the bits of binary data found in the book", "Embedded Data");
0159                 iconName: "document-multiple";
0160                 onTriggered: changeCategory(editBinaries, {model: bookModel});
0161             },
0162             Kirigami.Action {
0163                 visible: bookActions.visible;
0164                 checked: mainWindow.currentCategory === "bookStylesheet";
0165                 text: i18nc("Switch to the page where the user can work with the book's stylesheet", "Stylesheet");
0166                 iconName: "edit-paste-style";
0167                 onTriggered: changeCategory(editStylesheet, {model: bookModel});
0168             },
0169 
0170             Kirigami.Action {
0171                 separator: true;
0172             },
0173             Kirigami.Action {
0174                 text: i18nc("Open the settings page", "Settings");
0175                 iconName: "configure"
0176                 checked: mainWindow.currentCategory === "settingsPage";
0177                 onTriggered: changeCategory(settingsPage);
0178             },
0179             Kirigami.Action {
0180                 text: i18nc("Open the about page", "About");
0181                 iconName: "help-about"
0182                 checked: mainWindow.currentCategory === "aboutPage";
0183                 onTriggered: changeCategory(aboutPage);
0184             }
0185         ]
0186     }
0187 
0188     Component {
0189         id: welcomePage;
0190         WelcomePage { }
0191     }
0192 
0193     Component {
0194         id: createNewBookPage;
0195         CreateNewBook { }
0196     }
0197 
0198     Component {
0199         id: bookBasicsPage;
0200         BookBasics {
0201             onRequestCategoryChange: {
0202                 if (categoryName === "book") {
0203                     changeCategory(bookPage, {model: bookModel});
0204                 }
0205             }
0206         }
0207     }
0208 
0209     Component {
0210         id: bookPage;
0211         Book { }
0212     }
0213     Component {
0214         id: editMetaInfo;
0215         BookMetainfoPage { }
0216     }
0217     Component {
0218         id: editReferences;
0219         BookReferences { }
0220     }
0221     Component {
0222         id: editBinaries;
0223         BookBinaries { }
0224     }
0225     Component {
0226         id: editStylesheet;
0227         BookStylesheet { }
0228     }
0229 
0230     Component {
0231         id: settingsPage;
0232         Settings {
0233         }
0234     }
0235 
0236     Component {
0237         id: aboutPage;
0238         About {
0239         }
0240     }
0241 
0242     property string currentCategory: "welcomePage";
0243     function changeCategory(categoryItem, parameters) {
0244         // Clear all the way to the welcome page if we change the category...
0245         mainWindow.pageStack.clear();
0246         if (parameters === undefined) {
0247             mainWindow.pageStack.push(categoryItem);
0248         } else {
0249             mainWindow.pageStack.push(categoryItem, parameters);
0250         }
0251         currentCategory = mainWindow.pageStack.currentItem.categoryName;
0252     }
0253 
0254     function openOther() {
0255         openDlg.open();
0256     }
0257 
0258     FileDialog {
0259         id: openDlg;
0260         title: i18nc("@title:window standard file open dialog used to open a book not in the collection", "Please Choose a Book to Open");
0261         folder: mainWindow.homeDir();
0262         nameFilters: [
0263             i18nc("The file type filter for comic book archives", "Comic Book Archive zip format %1", "(*.cbz)"),
0264             i18nc("The file type filter for showing all files", "All files %1", "(*)")
0265         ]
0266         property int splitPos: osIsWindows ? 8 : 7;
0267         onAccepted: {
0268             if(openDlg.fileUrl.toString().substring(0, 7) === "file://") {
0269                 mainWindow.openBook(openDlg.fileUrl.toString().substring(splitPos), 0);
0270             }
0271         }
0272         onRejected: {
0273             // Just do nothing, we don't really care...
0274         }
0275     }
0276 
0277     Component.onCompleted: {
0278         if (fileToOpen !== "") {
0279              mainWindow.openBook(fileToOpen);
0280         }
0281     }
0282 }