Warning, /office/klevernotes/src/contents/ui/main.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2022 Louis Schul <schul9louis@gmail.com>
0003 
0004 import QtQuick 2.15
0005 
0006 import org.kde.kirigami 2.19 as Kirigami
0007 
0008 import org.kde.Klever 1.0
0009 
0010 import "qrc:/contents/ui/sideBar"
0011 
0012 Kirigami.ApplicationWindow {
0013     id: root
0014 
0015     readonly property NoteMapper noteMapper: noteMapper
0016     property string currentPageName: "Main"
0017 
0018     title: i18nc("@title:ApplicationWindow", "KleverNotes")
0019 
0020     minimumWidth: Kirigami.Settings.isMobile ? Kirigami.Units.gridUnit * 25 :  Kirigami.Units.gridUnit * 35
0021     minimumHeight: Kirigami.Units.gridUnit * 30
0022 
0023     globalDrawer: sideBar
0024     pageStack.columnView.columnResizeMode: Kirigami.ColumnView.SingleColumn
0025 
0026     onCurrentPageNameChanged: {
0027         if (!isMainPage()) {
0028             sideBar.close()
0029         } else if (pageStack.depth > 1){
0030             if (!sideBar.modal) sideBar.open()
0031             pageStack.pop()
0032         }
0033     }
0034     onClosing: {
0035         saveState() 
0036     }
0037     onXChanged: {
0038         saveWindowGeometryTimer.restart()
0039     }
0040     onYChanged: {
0041         saveWindowGeometryTimer.restart()
0042     }
0043     onWidthChanged: {
0044         saveWindowGeometryTimer.restart()
0045     }
0046     onHeightChanged: {
0047         saveWindowGeometryTimer.restart()
0048     }
0049     Component.onCompleted: {
0050         App.restoreWindowGeometry(root)
0051         switchToPage('Main')
0052     }
0053 
0054     // This timer allows to batch update the window size change to reduce
0055     // the io load and also work around the fact that x/y/width/height are
0056     // changed when loading the page and overwrite the saved geometry from
0057     // the previous session.
0058     Timer {
0059         id: saveWindowGeometryTimer
0060 
0061         interval: 1000
0062         onTriggered: App.saveWindowGeometry(root)
0063     }
0064 
0065     Kirigami.PagePool { 
0066         id: pagePool 
0067     }
0068 
0069     Sidebar { 
0070         id: sideBar 
0071     }
0072 
0073     NoteMapper { 
0074         id: noteMapper 
0075     }
0076 
0077     function saveState() {
0078         App.saveWindowGeometry(root)
0079         const mainPage = pageStack.get(0)
0080         const editor = mainPage.editorView.editor
0081         editor.saveNote(editor.text, editor.path)
0082         if (Config.noteMapEnabled) noteMapper.saveMap()
0083     }
0084 
0085     function getPage(name) {
0086         switch (name) {
0087             case "Main": return pagePool.loadPage("qrc:contents/ui/pages/MainPage.qml");
0088             case "Settings": return pagePool.loadPage("qrc:contents/ui/pages/SettingsPage.qml");
0089             case "Painting": return pagePool.loadPage("qrc:contents/ui/pages/PaintingPage.qml");
0090             case "Printing": return pagePool.loadPage("qrc:contents/ui/pages/PrintingPage.qml");
0091             case "About": return pagePool.loadPage("qrc:contents/ui/pages/AboutPage.qml");
0092         }
0093     }
0094 
0095     function switchToPage(pageName) {
0096         const page = getPage(pageName)
0097 
0098         pageStack.push(page)
0099 
0100         currentPageName = pageName
0101     }
0102 
0103     function isMainPage() {
0104         return currentPageName === "Main"
0105     }
0106 
0107     function showCheatSheet() {
0108         if (!isMainPage()) return
0109 
0110         const mainPage = pageStack.get(0)
0111         const editorView = mainPage.editorView
0112         editorView.cheatSheet.open() 
0113     }
0114 }