Warning, /utilities/kalk/src/qml/BinaryCalculator.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2021-2022 Rohan Asokan <rohan.asokan@students.iiit.ac.in> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 import QtQuick 0005 import QtQuick.Layouts 0006 import QtQuick.Controls as Controls 0007 import Qt5Compat.GraphicalEffects 0008 import org.kde.kirigami as Kirigami 0009 0010 Kirigami.Page { 0011 id: initialPage 0012 0013 title: i18n("Programmer") 0014 0015 topPadding: 0 0016 leftPadding: 0 0017 rightPadding: 0 0018 bottomPadding: 0 0019 0020 actions: [ 0021 Kirigami.Action { 0022 icon.name: "edit-undo-symbolic" 0023 text: i18n("Undo") 0024 shortcut: "Ctrl+Z" 0025 enabled: inputManager.canUndo 0026 onTriggered: inputManager.undo() 0027 }, 0028 Kirigami.Action { 0029 icon.name: "edit-redo-symbolic" 0030 text: i18n("Redo") 0031 shortcut: "Ctrl+Shift+Z" 0032 enabled: inputManager.canRedo 0033 onTriggered: inputManager.redo() 0034 } 0035 ] 0036 0037 property int yTranslate: 0 0038 property real mainOpacity: 1 0039 0040 property color dropShadowColor: Qt.darker(Kirigami.Theme.backgroundColor, 1.15) 0041 property int keypadHeight: initialPage.height * 3 / 7 0042 property int screenHeight: initialPage.height - initialPage.keypadHeight 0043 0044 Keys.onPressed: event => { 0045 if (event.matches(StandardKey.Undo)) { 0046 inputManager.undo(); 0047 event.accepted = true; 0048 return; 0049 } else if (event.matches(StandardKey.Redo)) { 0050 inputManager.redo(); 0051 event.accepted = true; 0052 return; 0053 } 0054 0055 switch(event.key) { 0056 case Qt.Key_Delete: 0057 case Qt.Key_Backspace: 0058 inputManager.backspace(); break; 0059 case Qt.Key_0: 0060 inputManager.append("0"); break; 0061 case Qt.Key_1: 0062 inputManager.append("1"); break; 0063 case Qt.Key_Plus: 0064 inputManager.append("+"); break; 0065 case Qt.Key_Minus: 0066 inputManager.append("-"); break; 0067 case Qt.Key_Asterisk: 0068 inputManager.append("*"); break; 0069 case Qt.Key_Slash: 0070 inputManager.append("/"); break; 0071 case Qt.Key_Ampersand: 0072 inputManager.append("&"); break; 0073 case Qt.Key_Bar: 0074 inputManager.append("|"); break; 0075 case Qt.Key_AsciiCircum: 0076 inputManager.append("^"); break; 0077 case Qt.Key_Period: 0078 inputManager.append("."); break; 0079 case Qt.Key_Equal: 0080 case Qt.Key_Return: 0081 case Qt.Key_Enter: 0082 inputManager.equal(); break; 0083 } 0084 event.accepted = true; 0085 } 0086 0087 onIsCurrentPageChanged: { 0088 if (!inputManager.binaryMode) 0089 inputManager.binaryMode = true 0090 } 0091 0092 background: Rectangle { 0093 Kirigami.Theme.colorSet: Kirigami.Theme.Window 0094 Kirigami.Theme.inherit: false 0095 color: Kirigami.Theme.backgroundColor 0096 anchors.fill: parent 0097 opacity: mainOpacity 0098 } 0099 0100 ColumnLayout { 0101 anchors.fill: parent 0102 opacity: mainOpacity 0103 transform: Translate { y: yTranslate } 0104 spacing: 0 0105 0106 Item { 0107 id: outputScreen 0108 z: 1 0109 Layout.fillWidth: true 0110 Layout.alignment: Qt.AlignTop 0111 Layout.preferredHeight: initialPage.screenHeight 0112 0113 // top panel drop shadow 0114 RectangularGlow { 0115 anchors.fill: topPanelBackground 0116 anchors.topMargin: 1 0117 glowRadius: 4 0118 spread: 0.2 0119 color: dropShadowColor 0120 } 0121 Rectangle { 0122 id: topPanelBackground 0123 anchors.top: parent.top 0124 anchors.left: parent.left 0125 anchors.right: parent.right 0126 color: Kirigami.Theme.backgroundColor 0127 implicitHeight: outputScreen.height 0128 } 0129 0130 Column { 0131 id: outputColumn 0132 anchors.fill: parent 0133 anchors.margins: Kirigami.Units.largeSpacing 0134 spacing: initialPage.screenHeight / 8 0135 0136 Flickable { 0137 anchors.right: parent.right 0138 height: initialPage.screenHeight / 8 0139 width: Math.min(parent.width, contentWidth) 0140 contentHeight: expressionRow.height 0141 contentWidth: expressionRow.width 0142 flickableDirection: Flickable.HorizontalFlick 0143 Controls.Label { 0144 id: expressionRow 0145 horizontalAlignment: Text.AlignRight 0146 font.pointSize: initialPage.screenHeight * 0.1 / 1.5 0147 font.weight: Font.Light 0148 text: inputManager.expression 0149 color: Kirigami.Theme.disabledTextColor 0150 } 0151 onContentWidthChanged: { 0152 if(contentWidth > width) 0153 contentX = contentWidth - width; 0154 } 0155 } 0156 0157 Flickable { 0158 anchors.right: parent.right 0159 height: initialPage.screenHeight / 8 0160 width: Math.min(parent.width, contentWidth) 0161 contentHeight: resultBin.height 0162 contentWidth: resultBin.width + Kirigami.Units.gridUnit 0163 flickableDirection: Flickable.HorizontalFlick 0164 Controls.Label { 0165 id: resultBin 0166 horizontalAlignment: Text.AlignRight 0167 font.pointSize: initialPage.screenHeight * 0.1 0168 font.weight: Font.Light 0169 text: inputManager.binaryResult 0170 onTextChanged: resultFadeInAnimation.start() 0171 Controls.Label { 0172 visible: parent.text.length 0173 anchors.left: parent.right 0174 anchors.bottom: parent.bottom 0175 text: "2" 0176 font.pointSize: initialPage.screenHeight * 0.1 * 0.3 0177 font.weight: Font.Light 0178 color: Kirigami.Theme.disabledTextColor 0179 } 0180 } 0181 } 0182 0183 Flickable { 0184 anchors.right: parent.right 0185 height: initialPage.screenHeight / 8 0186 width: Math.min(parent.width, contentWidth) 0187 contentHeight: resultDec.height 0188 contentWidth: resultDec.width + Kirigami.Units.gridUnit 0189 flickableDirection: Flickable.HorizontalFlick 0190 Controls.Label { 0191 id: resultDec 0192 horizontalAlignment: Text.AlignRight 0193 font.pointSize: initialPage.screenHeight * 0.1 0194 font.weight: Font.Light 0195 text: inputManager.result 0196 onTextChanged: resultFadeInAnimation.start() 0197 Controls.Label { 0198 visible: parent.text.length 0199 anchors.left: parent.right 0200 anchors.bottom: parent.bottom 0201 text: "10" 0202 font.pointSize: initialPage.screenHeight * 0.1 * 0.3 0203 font.weight: Font.Light 0204 color: Kirigami.Theme.disabledTextColor 0205 } 0206 } 0207 } 0208 0209 Flickable { 0210 anchors.right: parent.right 0211 height: initialPage.screenHeight / 8 0212 width: Math.min(parent.width, contentWidth) 0213 contentHeight: resultHex.height 0214 contentWidth: resultHex.width + Kirigami.Units.gridUnit 0215 flickableDirection: Flickable.HorizontalFlick 0216 Controls.Label { 0217 id: resultHex 0218 horizontalAlignment: Text.AlignRight 0219 font.pointSize: initialPage.screenHeight * 0.1 0220 font.weight: Font.Light 0221 text: inputManager.hexResult 0222 onTextChanged: resultFadeInAnimation.start() 0223 Controls.Label { 0224 visible: parent.text.length 0225 anchors.left: parent.right 0226 anchors.bottom: parent.bottom 0227 text: "16" 0228 font.pointSize: initialPage.screenHeight * 0.1 * 0.3 0229 font.weight: Font.Light 0230 color: Kirigami.Theme.disabledTextColor 0231 } 0232 } 0233 } 0234 0235 NumberAnimation on opacity { 0236 id: resultFadeInAnimation 0237 from: 0.5 0238 to: 1 0239 duration: Kirigami.Units.shortDuration 0240 exclude: [expressionRow] 0241 } 0242 NumberAnimation on opacity { 0243 id: resultFadeOutAnimation 0244 from: 1 0245 to: 0 0246 duration: Kirigami.Units.shortDuration 0247 exclude: [expressionRow] 0248 } 0249 } 0250 } 0251 0252 // Binary Input Pad 0253 Item { 0254 property string expression: "" 0255 id: binaryInputPad 0256 Layout.fillHeight: true 0257 Layout.preferredWidth: initialPage.width 0258 Layout.alignment: Qt.AlignLeft 0259 0260 BinaryPad { 0261 id: binaryPad 0262 anchors.fill: parent 0263 anchors.margins: Kirigami.Units.smallSpacing 0264 // Uncomment next line for function overlay 0265 // anchors.rightMargin: Kirigami.Units.gridUnit * 1.5 0266 onPressed: text => { 0267 if (text === "DEL") { 0268 inputManager.backspace(); 0269 } else if (text === "=") { 0270 inputManager.equal(); 0271 resultFadeOutAnimation.start(); 0272 } else { 0273 inputManager.append(text); 0274 } 0275 } 0276 onClear: inputManager.clear() 0277 } 0278 } 0279 } 0280 }