Warning, /utilities/daykountdown/src/contents/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: (C) 2021 Carl Schwan <carl@carlschwan.eu>
0003 * SPDX-FileCopyrightText: (C) 2021 Claudio Cambra <claudio.cambra@gmail.com>
0004 *
0005 * SPDX-LicenseRef: GPL-3.0-or-later
0006 */
0007
0008 // Includes relevant modules used by the QML
0009 import QtQuick 2.6
0010 import QtQuick.Controls 2.15 as Controls
0011 import QtQuick.Layouts 1.2
0012 import QtQuick.Dialogs 1.3
0013 import org.kde.kirigami 2.13 as Kirigami
0014 import org.kde.kirigamiaddons.formcard 1.0 as FormCard
0015 import org.kde.daykountdown.private 1.0
0016
0017 // Base element, provides basic features needed for all kirigami applications
0018 Kirigami.ApplicationWindow {
0019 // ID provides unique identifier to reference this element
0020 id: root
0021
0022 // Window title
0023 title: i18nc("@title:window", "Day Kountdown")
0024
0025 property date nowDate: new Date()
0026 property bool calPageOpen: false
0027
0028 Timer {
0029 interval: 60000
0030 running: true
0031 repeat: true
0032 onTriggered: nowDate = new Date()
0033 }
0034
0035 // Global drawer element with app-wide actions
0036 globalDrawer: Kirigami.GlobalDrawer {
0037 // Makes drawer a small menu rather than sliding pane
0038 isMenu: true
0039 actions: [
0040 Kirigami.Action {
0041 text: i18n("Import")
0042 icon.name: "document-open"
0043 shortcut: StandardKey.Open
0044 onTriggered: {
0045 ImportExport.fetchKountdowns();
0046 for(var i in ImportExport.Kountdowns) {
0047 KountdownModel.addKountdown(
0048 ImportExport.Kountdowns[i].name,
0049 ImportExport.Kountdowns[i].description,
0050 new Date(ImportExport.Kountdowns[i].date),
0051 ImportExport.Kountdowns[i].colour
0052 );
0053 }
0054 }
0055 },
0056 Kirigami.Action {
0057 text: i18n("Export")
0058 icon.name: "document-save"
0059 shortcut: StandardKey.Save
0060 onTriggered: ImportExport.exportFile()
0061 },
0062 Kirigami.Action {
0063 text: i18n("Clear all kountdowns")
0064 icon.name: "edit-clear"
0065 onTriggered: removeAllDialog.open()
0066 },
0067 Kirigami.Action {
0068 text: i18n("Settings")
0069 icon.name: "settings-configure"
0070 onTriggered: pageStack.layers.push("SettingsPage.qml")
0071 enabled: pageStack.layers.currentItem.title !== i18n("Settings")
0072 },
0073 Kirigami.Action {
0074 text: i18n("About DayKountdown")
0075 icon.name: "help-about"
0076 onTriggered: pageStack.layers.push(aboutPage)
0077 enabled: pageStack.layers.currentItem.title !== i18n("About")
0078 },
0079 Kirigami.Action {
0080 text: i18n("Quit")
0081 icon.name: "application-exit"
0082 shortcut: StandardKey.Quit
0083 onTriggered: Qt.quit()
0084 }
0085 ]
0086 }
0087
0088 Component {
0089 id: aboutPage
0090 FormCard.AboutPage {
0091 aboutData: AboutData.aboutData
0092 }
0093 }
0094
0095 MessageDialog {
0096 id: removeAllDialog
0097 title: i18nc("@title:window", "Remove all kountdowns")
0098 icon: StandardIcon.Warning
0099 text: i18n("Are you sure you want to delete all your kountdowns?")
0100 standardButtons: Dialog.Yes | Dialog.Cancel
0101 onAccepted: KountdownModel.removeAllKountdowns()
0102 }
0103
0104 // Fetches item from addEditSheet.qml and does action on signal
0105 // Cool thing about signals: they expose the variables defined in them to the function that is listening to them
0106 AddEditSheet {
0107 id: addEditSheet
0108 onEdited: KountdownModel.editKountdown(
0109 index,
0110 name,
0111 description,
0112 kdate,
0113 colour
0114 );
0115 onAdded: KountdownModel.addKountdown(
0116 name,
0117 description,
0118 kdate,
0119 colour
0120 );
0121 onRemoved: KountdownModel.removeKountdown(index)
0122 }
0123
0124 SystemPalette { id: palette; colorGroup: SystemPalette.Active }
0125 // Function called by 'edit' button on card
0126 function openPopulateSheet(mode, index = -1, listName = "", listDesc = "", listDate = nowDate, colour = palette.text) {
0127 addEditSheet.mode = mode
0128 addEditSheet.colour = colour;
0129 addEditSheet.index = index;
0130 addEditSheet.name = listName
0131 addEditSheet.description = listDesc
0132 addEditSheet.kdate = listDate
0133 addEditSheet.open()
0134 }
0135
0136 // Initial page to be loaded on app load
0137 pageStack.initialPage: KountdownsPage {}
0138
0139 Kirigami.Page {
0140 id: calPage
0141 visible: false
0142
0143 Loader {
0144 id: calPageLoader
0145 anchors.fill: parent
0146 asynchronous: true
0147 active: false
0148 visible: calPage.visible
0149 source: Qt.resolvedUrl("EventsCalendarPage.qml")
0150 onLoaded: {
0151 applicationWindow().pageStack.pop() // Pop out the loadingPage
0152 root.pageStack.push(calPage)
0153 calPage.visible = true
0154 }
0155 }
0156 }
0157
0158 Kirigami.Page {
0159 id: loadingPage
0160 visible: calPageOpen
0161 Controls.BusyIndicator {
0162 anchors.fill: parent
0163 running: loadingPage.visible
0164 }
0165 }
0166
0167 function showCalendar() {
0168 calPageOpen = !calPageOpen
0169 if (calPageOpen == false) {
0170 calPageLoader.active = false
0171 applicationWindow().pageStack.pop() // Pop out calPage
0172 } else {
0173 calPageLoader.active = true
0174 root.pageStack.push(loadingPage)
0175 }
0176 }
0177 }