Warning, /utilities/kalk/src/qml/main.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com>
0003 * SPDX-FileCopyrightText: 2020 cahfofpai
0004 *
0005 * SPDX-License-Identifier: GPL-3.0-or-later
0006 */
0007 import QtQuick 2.7
0008 import QtQuick.Layouts 1.1
0009 import QtQuick.Controls 2.15 as Controls
0010 import Qt.labs.platform 1.0
0011 import Qt.labs.settings 1.0
0012 import org.kde.kirigami 2.13 as Kirigami
0013
0014 Kirigami.ApplicationWindow {
0015 id: root
0016 title: 'Kalk'
0017 visible: true
0018 minimumWidth: 150
0019 minimumHeight: 200
0020 width: 300
0021 height: 450
0022 readonly property int columnWidth: Kirigami.Units.gridUnit * 13
0023 wideScreen: width > columnWidth * 3
0024
0025 pageStack.globalToolBar.canContainHandles: true
0026 pageStack.globalToolBar.style: Kirigami.ApplicationHeaderStyle.ToolBar
0027 pageStack.globalToolBar.showNavigationButtons: Kirigami.ApplicationHeaderStyle.ShowBackButton;
0028 pageStack.popHiddenPages: true
0029
0030 Kirigami.PagePool {
0031 id: mainPagePool
0032 }
0033
0034 // page switch animation
0035 NumberAnimation {
0036 id: anim
0037 from: 0
0038 to: 1
0039 duration: Kirigami.Units.longDuration * 2
0040 easing.type: Easing.InOutQuad
0041 }
0042 NumberAnimation {
0043 id: yAnim
0044 from: Kirigami.Units.gridUnit * 3
0045 to: 0
0046 duration: Kirigami.Units.longDuration * 3
0047 easing.type: Easing.OutQuint
0048 }
0049
0050 function pageAnimation(page) {
0051 // page switch animation
0052 yAnim.target = page;
0053 yAnim.properties = "yTranslate";
0054 anim.target = page;
0055 anim.properties = "mainOpacity";
0056 yAnim.restart();
0057 anim.restart();
0058 }
0059
0060 globalDrawer: Kirigami.OverlayDrawer {
0061 id: drawer
0062 width: 300
0063 height: root.height
0064 enabled: Kirigami.Settings.isMobile
0065
0066 // for desktop menu
0067 property bool isMenu: true
0068 property list<QtObject> actions: [
0069 Kirigami.PagePoolAction {
0070 text: i18n("Calculator")
0071 icon.name: "accessories-calculator"
0072 pagePool: mainPagePool
0073 page: "qrc:/qml/CalculationPage.qml"
0074 onTriggered: pageAnimation(pageItem())
0075 },
0076 Kirigami.PagePoolAction {
0077 text: i18n("Converter")
0078 icon.name: "gtk-convert"
0079 page: "qrc:/qml/UnitConverter.qml"
0080 pagePool: mainPagePool
0081 onTriggered: pageAnimation(pageItem())
0082 },
0083 Kirigami.PagePoolAction {
0084 text: i18n("Programmer")
0085 icon.name: "format-text-code"
0086 pagePool: mainPagePool
0087 page: "qrc:/qml/BinaryCalculator.qml"
0088 onTriggered: pageAnimation(pageItem())
0089 },
0090 Kirigami.PagePoolAction {
0091 text: i18n("Settings")
0092 icon.name: "settings-configure"
0093 pagePool: mainPagePool
0094 page: "qrc:/qml/SettingsPage.qml"
0095 onTriggered: pageAnimation(pageItem())
0096 },
0097 Kirigami.PagePoolAction {
0098 text: i18n("About")
0099 icon.name: "help-about"
0100 page: "qrc:/qml/AboutPage.qml"
0101 pagePool: mainPagePool
0102 }
0103 ]
0104
0105 // for mobile sidebar
0106 handleClosedIcon.source: null
0107 handleOpenIcon.source: null
0108
0109 Kirigami.Theme.colorSet: Kirigami.Theme.Window
0110 Kirigami.Theme.inherit: false
0111
0112 contentItem: ColumnLayout {
0113 id: column
0114 spacing: 0
0115
0116 // allows for lazy loading of pages compared to using a binding
0117 property string currentlyChecked: i18n("Calculator")
0118
0119 Kirigami.Heading {
0120 text: i18n("Calculator")
0121 type: Kirigami.Heading.Secondary
0122 Layout.margins: Kirigami.Units.gridUnit
0123 }
0124
0125 SidebarButton {
0126 text: i18n("Calculator")
0127 icon.name: "accessories-calculator"
0128 Layout.fillWidth: true
0129 Layout.minimumHeight: Kirigami.Units.gridUnit * 2
0130 Layout.bottomMargin: Kirigami.Units.smallSpacing
0131 checked: column.currentlyChecked === text
0132 onClicked: {
0133 column.currentlyChecked = text;
0134
0135 let page = mainPagePool.loadPage("qrc:/qml/CalculationPage.qml");
0136 while (pageStack.depth > 0) pageStack.pop();
0137 pageStack.push(page);
0138 pageAnimation(page);
0139 drawer.close();
0140 }
0141 }
0142
0143 SidebarButton {
0144 text: i18n("Converter")
0145 icon.name: "gtk-convert"
0146 Layout.fillWidth: true
0147 Layout.minimumHeight: Kirigami.Units.gridUnit * 2
0148 Layout.bottomMargin: Kirigami.Units.smallSpacing
0149 checked: column.currentlyChecked === text
0150 onClicked: {
0151 column.currentlyChecked = text;
0152
0153 let page = mainPagePool.loadPage("qrc:/qml/UnitConverter.qml");
0154 while (pageStack.depth > 0) pageStack.pop();
0155 pageStack.push(page);
0156 pageAnimation(page);
0157 drawer.close();
0158 }
0159 }
0160
0161 SidebarButton {
0162 text: i18n("Binary Calculator")
0163 icon.name: "format-text-code"
0164 Layout.fillWidth: true
0165 Layout.minimumHeight: Kirigami.Units.gridUnit * 2
0166 Layout.bottomMargin: Kirigami.Units.smallSpacing
0167 checked: column.currentlyChecked === text
0168 onClicked: {
0169 column.currentlyChecked = text;
0170
0171 let page = mainPagePool.loadPage("qrc:/qml/BinaryCalculator.qml");
0172 while (pageStack.depth > 0) pageStack.pop();
0173 pageStack.push(page);
0174 pageAnimation(page);
0175 drawer.close();
0176 }
0177 }
0178
0179 Item { Layout.fillHeight: true }
0180 Kirigami.Separator {
0181 Layout.fillWidth: true
0182 Layout.margins: Kirigami.Units.smallSpacing
0183 }
0184
0185 SidebarButton {
0186 text: i18n("Settings")
0187 icon.name: "settings-configure"
0188 Layout.fillWidth: true
0189 Layout.minimumHeight: Kirigami.Units.gridUnit * 2
0190 Layout.bottomMargin: Kirigami.Units.smallSpacing
0191 checked: column.currentlyChecked === text
0192 onClicked: {
0193 column.currentlyChecked = text;
0194
0195 let page = mainPagePool.loadPage("qrc:/qml/SettingsPage.qml");
0196 while (pageStack.depth > 0) pageStack.pop();
0197 pageStack.push(page);
0198 pageAnimation(page);
0199 drawer.close();
0200 }
0201 }
0202
0203 SidebarButton {
0204 text: i18n("About")
0205 icon.name: "help-about"
0206 Layout.fillWidth: true
0207 Layout.minimumHeight: Kirigami.Units.gridUnit * 2
0208 Layout.bottomMargin: Kirigami.Units.smallSpacing
0209 checked: column.currentlyChecked === text
0210 onClicked: {
0211 column.currentlyChecked = text;
0212
0213 let page = mainPagePool.loadPage("qrc:/qml/AboutPage.qml")
0214 while (pageStack.depth > 0) pageStack.pop();
0215 pageStack.push(page);
0216 pageAnimation(page);
0217 drawer.close();
0218 }
0219 }
0220 }
0221 }
0222
0223 pageStack.initialPage: mainPagePool.loadPage("qrc:/qml/CalculationPage.qml")
0224 }