Warning, /utilities/kalk/src/qml/UnitConverter.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: 2021 Devin Lin <espidev@gmail.com 0004 * 0005 * SPDX-License-Identifier: GPL-3.0-or-later 0006 */ 0007 import QtQuick 0008 import QtQuick.Layouts 0009 import QtQuick.Controls as Controls 0010 import org.kde.kirigami as Kirigami 0011 import Qt5Compat.GraphicalEffects 0012 0013 Kirigami.Page { 0014 id: unitConverter 0015 title: i18n("Converter") 0016 topPadding: 0 0017 leftPadding: 0 0018 rightPadding: 0 0019 bottomPadding: 0 0020 0021 property int yTranslate: 0 0022 property real mainOpacity: 1 0023 property color dropShadowColor: Qt.darker(Kirigami.Theme.backgroundColor, 1.15) 0024 property int screenHeight: unitConverter.height * 0.5 0025 property int flexPointSize: Math.max(Math.min(screenHeight / 14, width / 24), Kirigami.Theme.defaultFont.pointSize - 3) 0026 0027 Keys.onPressed: event => { 0028 switch(event.key) { 0029 case Qt.Key_Delete: 0030 case Qt.Key_Backspace: 0031 unitNumberPad.pressed("DEL"); break; 0032 case Qt.Key_0: 0033 unitNumberPad.pressed("0"); break; 0034 case Qt.Key_1: 0035 unitNumberPad.pressed("1"); break; 0036 case Qt.Key_2: 0037 unitNumberPad.pressed("2"); break; 0038 case Qt.Key_3: 0039 unitNumberPad.pressed("3"); break; 0040 case Qt.Key_4: 0041 unitNumberPad.pressed("4"); break; 0042 case Qt.Key_5: 0043 unitNumberPad.pressed("5"); break; 0044 case Qt.Key_6: 0045 unitNumberPad.pressed("6"); break; 0046 case Qt.Key_7: 0047 unitNumberPad.pressed("7"); break; 0048 case Qt.Key_8: 0049 unitNumberPad.pressed("8"); break; 0050 case Qt.Key_9: 0051 unitNumberPad.pressed("9"); break; 0052 case Qt.Key_Period: 0053 unitNumberPad.pressed("."); break; 0054 case Qt.Key_Equal: 0055 case Qt.Key_Return: 0056 case Qt.Key_Enter: 0057 inputManager.equal(); break; 0058 } 0059 event.accepted = true; 0060 } 0061 0062 actions: Kirigami.Action { 0063 id: category 0064 icon.name: "category" 0065 text: i18n("Category") 0066 onTriggered: categories.open(); 0067 } 0068 0069 Component { 0070 id: delegateComponent 0071 Controls.Label { 0072 text: modelData 0073 opacity: 0.4 + Math.max(0, 1 - Math.abs(Controls.Tumbler.displacement)) * 0.6 0074 horizontalAlignment: Text.AlignHCenter 0075 font.bold: Controls.Tumbler.displacement === 0 0076 font.pointSize: flexPointSize 0077 } 0078 } 0079 0080 Item { 0081 anchors.fill: parent 0082 opacity: mainOpacity 0083 transform: Translate { y: yTranslate } 0084 0085 // top panel drop shadow 0086 RectangularGlow { 0087 anchors.fill: topPanelBackground 0088 anchors.topMargin: 1 0089 z: -2 0090 glowRadius: 4 0091 spread: 0.2 0092 color: dropShadowColor 0093 } 0094 0095 Rectangle { 0096 id: topPanelBackground 0097 z: -1 0098 color: Kirigami.Theme.backgroundColor 0099 anchors.left: parent.left 0100 anchors.right: parent.right 0101 anchors.top: parent.top 0102 implicitHeight: topPanel.height 0103 } 0104 0105 ColumnLayout { 0106 anchors.fill: parent 0107 spacing: 0 0108 0109 ColumnLayout { 0110 id: topPanel 0111 Layout.fillWidth: true 0112 0113 RowLayout { 0114 Layout.fillHeight: true 0115 Layout.fillWidth: true 0116 0117 Controls.Tumbler { 0118 id: fromTumbler 0119 Layout.fillWidth: true 0120 Layout.fillHeight: true 0121 Layout.maximumHeight: unitConverter.screenHeight * 0.5 0122 wrap: false 0123 0124 model: unitModel.typeList 0125 currentIndex: unitModel.fromUnitIndex 0126 delegate: delegateComponent 0127 onCurrentIndexChanged: { 0128 unitModel.fromUnitIndex = currentIndex; 0129 } 0130 } 0131 0132 Controls.ToolButton { 0133 icon.name: "gtk-convert" 0134 icon.height: unitConverter.screenHeight * 0.15 0135 icon.width: unitConverter.screenHeight * 0.15 0136 onClicked: { 0137 let tmp = fromTumbler.currentIndex; 0138 fromTumbler.currentIndex = toTumbler.currentIndex; 0139 toTumbler.currentIndex = tmp; 0140 } 0141 } 0142 0143 Controls.Tumbler { 0144 id: toTumbler 0145 Layout.fillWidth: true 0146 Layout.fillHeight: true 0147 Layout.maximumHeight: unitConverter.screenHeight * 0.5 0148 wrap: false 0149 0150 model: unitModel.typeList 0151 currentIndex: unitModel.toUnitIndex 0152 delegate: delegateComponent 0153 onCurrentIndexChanged: { 0154 unitModel.toUnitIndex = currentIndex; 0155 } 0156 } 0157 } 0158 0159 Kirigami.Separator { 0160 Layout.fillWidth: true 0161 } 0162 0163 GridLayout { 0164 columns: unitConverter.width > unitConverter.height ? 3 : 1 0165 Layout.fillWidth: true 0166 Layout.alignment: Qt.AlignHCenter 0167 0168 Controls.Label { 0169 Layout.fillWidth: true 0170 font.pointSize: flexPointSize 0171 text: unitModel.value 0172 color: Kirigami.Theme.textColor 0173 horizontalAlignment: Text.AlignHCenter 0174 } 0175 0176 Controls.Label { 0177 visible: parent.columns > 1 || unitConverter.height > 250 0178 Layout.fillWidth: true 0179 font.pointSize: flexPointSize 0180 text: "=" 0181 color: Kirigami.Theme.textColor 0182 horizontalAlignment: Text.AlignHCenter 0183 } 0184 0185 Controls.Label { 0186 Layout.fillWidth: true 0187 font.pointSize: flexPointSize 0188 text: unitModel.result 0189 color: Kirigami.Theme.textColor 0190 horizontalAlignment: Text.AlignHCenter 0191 } 0192 } 0193 } 0194 0195 PortraitPad { 0196 id: unitNumberPad 0197 Layout.fillHeight: true 0198 Layout.fillWidth: true 0199 Layout.margins: Kirigami.Units.smallSpacing 0200 pureNumber: true 0201 onPressed: text => { 0202 if (text === "DEL") { 0203 unitModel.value = unitModel.value.slice(0, unitModel.value.length - 1); 0204 } else { 0205 unitModel.value += text; 0206 } 0207 } 0208 onClear: { 0209 unitModel.value = ""; 0210 } 0211 } 0212 } 0213 } 0214 0215 background: Rectangle { 0216 opacity: mainOpacity 0217 0218 Kirigami.Theme.colorSet: Kirigami.Theme.Window 0219 Kirigami.Theme.inherit: false 0220 color: Kirigami.Theme.backgroundColor 0221 anchors.fill: parent 0222 } 0223 0224 Controls.Dialog { 0225 id: categories 0226 modal: true 0227 focus: true 0228 width: Math.min(parent.width, 400) 0229 x: parent.width / 2 - width / 2 0230 0231 contentItem: Controls.ScrollView { 0232 ListView { 0233 id: listview 0234 model: unitModel 0235 clip: true 0236 delegate: Controls.RadioDelegate { 0237 width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin 0238 text: modelData 0239 checked: index === unitModel.currentIndex 0240 onClicked: { 0241 category.text = text; 0242 unitModel.currentIndex = index; 0243 categories.close(); 0244 } 0245 } 0246 0247 Component.onCompleted: category.text = listview.currentItem.text 0248 } 0249 0250 Component.onCompleted: background.visible = true 0251 } 0252 } 0253 }