Warning, /utilities/kclock/src/kclock/qml/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * Copyright 2020 Han Young <hanyoung@protonmail.com>
0003  * Copyright 2020 Devin Lin <espidev@gmail.com>
0004  * Copyright 2019 Nick Reitemeyer <nick.reitemeyer@web.de>
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 import QtQuick
0010 import QtQuick.Controls
0011 import QtQuick.Layouts
0012 import org.kde.kirigami as Kirigami
0013 
0014 Kirigami.ApplicationWindow {
0015     id: root
0016 
0017     // needs to work with 360x720 (+ panel heights)
0018     minimumWidth: 300
0019     minimumHeight: minimumWidth + 1
0020     width: Kirigami.Settings.isMobile ? 360 : 550
0021     height: Kirigami.Settings.isMobile ? 720 : 500
0022 
0023     title: i18n("Clock")
0024 
0025     contextDrawer: Kirigami.ContextDrawer {}
0026 
0027     pageStack {
0028         globalToolBar {
0029             canContainHandles: true
0030             style: Kirigami.ApplicationHeaderStyle.ToolBar
0031             showNavigationButtons: Kirigami.ApplicationHeaderStyle.ShowBackButton;
0032         }
0033         popHiddenPages: true
0034 
0035         columnView.columnResizeMode: Kirigami.ColumnView.SingleColumn
0036     }
0037 
0038     property bool isWidescreen: root.width >= 500
0039     onIsWidescreenChanged: changeNav(isWidescreen);
0040 
0041     Kirigami.PagePool {
0042         id: pagePool
0043     }
0044 
0045     Component.onCompleted: {
0046         // initial page and nav type
0047         switchToPage(getPage("Time"), 1);
0048         changeNav(isWidescreen);
0049     }
0050 
0051     function switchToPage(page, depth) {
0052         // pop pages above depth
0053         while (pageStack.depth > depth) pageStack.pop();
0054         while (pageStack.layers.depth > 1) pageStack.layers.pop();
0055 
0056         // page switch animation
0057         yAnim.target = page;
0058         yAnim.properties = "yTranslate";
0059         anim.target = page;
0060         anim.properties = "contentItem.opacity";
0061         if (page.header) {
0062             anim.properties += ",header.opacity";
0063         }
0064         yAnim.restart();
0065         anim.restart();
0066 
0067         pageStack.push(page);
0068     }
0069 
0070     function getPage(name) {
0071         switch (name) {
0072             case "Time": return pagePool.loadPage("qrc:/qml/time/TimePage.qml");
0073             case "Timers": return pagePool.loadPage("qrc:/qml/timer/TimerListPage.qml");
0074             case "Stopwatch": return pagePool.loadPage("qrc:/qml/stopwatch/StopwatchPage.qml");
0075             case "Alarms": return pagePool.loadPage("qrc:/qml/alarm/AlarmListPage.qml");
0076             case "Settings": return pagePool.loadPage("qrc:/qml/settings/SettingsPage.qml");
0077             case "About": return pagePool.loadPage("qrc:/qml/components/AboutPage.qml");
0078         }
0079     }
0080 
0081     // switch between bottom toolbar and sidebar
0082     function changeNav(toWidescreen) {
0083         if (toWidescreen) {
0084             if (footer !== null) {
0085                 footer.destroy();
0086                 footer = null;
0087             }
0088             sidebarLoader.active = true;
0089             root.globalDrawer = sidebarLoader.item;
0090         } else {
0091             sidebarLoader.active = false;
0092             globalDrawer = null;
0093 
0094             let bottomToolbar = Qt.createComponent("qrc:/qml/components/BottomToolbar.qml")
0095             footer = bottomToolbar.createObject(root);
0096         }
0097     }
0098 
0099     // page switch animation
0100     NumberAnimation {
0101         id: anim
0102         from: 0
0103         to: 1
0104         duration: Kirigami.Units.veryLongDuration
0105         easing.type: Easing.InOutQuad
0106     }
0107     NumberAnimation {
0108         id: yAnim
0109         from: Kirigami.Units.gridUnit * 2
0110         to: 0
0111         duration: Kirigami.Units.longDuration * 3
0112         easing.type: Easing.OutExpo
0113     }
0114 
0115     Loader {
0116         id: sidebarLoader
0117         source: "qrc:/qml/components/Sidebar.qml"
0118         active: false
0119     }
0120 }