2023-10-02 09:20:35 +00:00
|
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
2022-06-03 11:26:02 +00:00
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2018-06-26 13:53:07 +00:00
|
|
|
|
|
2023-10-02 09:20:35 +00:00
|
|
|
|
pragma ComponentBehavior: Bound
|
|
|
|
|
|
2020-12-01 12:57:32 +00:00
|
|
|
|
import QtQuick
|
2023-10-02 09:20:35 +00:00
|
|
|
|
import "calculator.js" as CalcEngine
|
2023-10-31 13:48:04 +00:00
|
|
|
|
import QtQuick.Layouts
|
2018-06-26 13:53:07 +00:00
|
|
|
|
|
2023-10-31 13:48:04 +00:00
|
|
|
|
Item {
|
|
|
|
|
id: controller
|
|
|
|
|
implicitWidth: isPortraitMode ? portraitModeWidth : landscapeModeWidth
|
|
|
|
|
implicitHeight: mainGrid.height
|
2018-06-26 13:53:07 +00:00
|
|
|
|
|
2023-10-31 13:48:04 +00:00
|
|
|
|
readonly property color qtGreenColor: "#2CDE85"
|
|
|
|
|
readonly property color backspaceRedColor: "#DE2C2C"
|
|
|
|
|
readonly property int spacing: 5
|
2023-10-02 09:20:35 +00:00
|
|
|
|
|
2023-10-31 13:48:04 +00:00
|
|
|
|
property bool isPortraitMode: root.isPortraitMode
|
|
|
|
|
property int portraitModeWidth: mainGrid.width
|
|
|
|
|
property int landscapeModeWidth: scientificGrid.width + mainGrid.width
|
|
|
|
|
|
2025-06-27 12:13:06 +00:00
|
|
|
|
function updateDimmed() {
|
|
|
|
|
for (let i = 0; i < mainGrid.children.length; i++) {
|
|
|
|
|
mainGrid.children[i].dimmed = root.isButtonDisabled(mainGrid.children[i].text);
|
2023-10-31 13:48:04 +00:00
|
|
|
|
}
|
2025-06-27 12:13:06 +00:00
|
|
|
|
for (let j = 0; j < scientificGrid.children.length; j++) {
|
|
|
|
|
scientificGrid.children[j].dimmed = root.isButtonDisabled(
|
|
|
|
|
scientificGrid.children[j].text);
|
2021-09-14 08:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-26 13:53:07 +00:00
|
|
|
|
|
2021-09-14 08:36:23 +00:00
|
|
|
|
component DigitButton: CalculatorButton {
|
2023-10-31 13:48:04 +00:00
|
|
|
|
onReleased: {
|
2025-06-27 12:13:06 +00:00
|
|
|
|
root.digitPressed(text);
|
|
|
|
|
updateDimmed();
|
2021-09-14 08:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
component OperatorButton: CalculatorButton {
|
2023-10-31 13:48:04 +00:00
|
|
|
|
onReleased: {
|
2025-06-27 12:13:06 +00:00
|
|
|
|
root.operatorPressed(text);
|
|
|
|
|
updateDimmed();
|
2021-09-14 08:36:23 +00:00
|
|
|
|
}
|
2023-10-31 13:48:04 +00:00
|
|
|
|
textColor: controller.qtGreenColor
|
|
|
|
|
implicitWidth: 48
|
2021-09-14 08:36:23 +00:00
|
|
|
|
dimmable: true
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-02 09:20:35 +00:00
|
|
|
|
Component.onCompleted: updateDimmed()
|
|
|
|
|
|
2023-10-31 13:48:04 +00:00
|
|
|
|
Rectangle {
|
|
|
|
|
id: numberPad
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
radius: 8
|
|
|
|
|
color: "transparent"
|
|
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
|
spacing: controller.spacing
|
|
|
|
|
|
|
|
|
|
GridLayout {
|
|
|
|
|
id: scientificGrid
|
|
|
|
|
columns: 3
|
|
|
|
|
columnSpacing: controller.spacing
|
|
|
|
|
rowSpacing: controller.spacing
|
|
|
|
|
visible: !isPortraitMode
|
|
|
|
|
|
2024-03-18 09:31:00 +00:00
|
|
|
|
OperatorButton { text: "x²" }
|
|
|
|
|
OperatorButton { text: "⅟x" }
|
2023-10-31 13:48:04 +00:00
|
|
|
|
OperatorButton { text: "√" }
|
2024-03-18 09:31:00 +00:00
|
|
|
|
OperatorButton { text: "x³" }
|
|
|
|
|
OperatorButton { text: "sin" }
|
|
|
|
|
OperatorButton { text: "|x|" }
|
|
|
|
|
OperatorButton { text: "log" }
|
|
|
|
|
OperatorButton { text: "cos" }
|
2023-10-31 13:48:04 +00:00
|
|
|
|
DigitButton {
|
|
|
|
|
text: "e"
|
|
|
|
|
dimmable: true
|
|
|
|
|
implicitWidth: 48
|
|
|
|
|
}
|
2024-03-18 09:31:00 +00:00
|
|
|
|
OperatorButton { text: "ln" }
|
|
|
|
|
OperatorButton { text: "tan" }
|
2023-10-31 13:48:04 +00:00
|
|
|
|
DigitButton {
|
|
|
|
|
text: "π"
|
|
|
|
|
dimmable: true
|
|
|
|
|
implicitWidth: 48
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GridLayout {
|
|
|
|
|
id: mainGrid
|
|
|
|
|
columns: 5
|
|
|
|
|
columnSpacing: controller.spacing
|
|
|
|
|
rowSpacing: controller.spacing
|
|
|
|
|
|
|
|
|
|
BackspaceButton {}
|
|
|
|
|
DigitButton { text: "7" }
|
|
|
|
|
DigitButton { text: "8" }
|
|
|
|
|
DigitButton { text: "9" }
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "÷"
|
|
|
|
|
implicitWidth: 38
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "AC"
|
|
|
|
|
textColor: controller.backspaceRedColor
|
|
|
|
|
accentColor: controller.backspaceRedColor
|
|
|
|
|
}
|
|
|
|
|
DigitButton { text: "4" }
|
|
|
|
|
DigitButton { text: "5" }
|
|
|
|
|
DigitButton { text: "6" }
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "×"
|
|
|
|
|
implicitWidth: 38
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "="
|
|
|
|
|
implicitHeight: 81
|
|
|
|
|
Layout.rowSpan: 2
|
|
|
|
|
}
|
|
|
|
|
DigitButton { text: "1" }
|
|
|
|
|
DigitButton { text: "2" }
|
|
|
|
|
DigitButton { text: "3" }
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "−"
|
|
|
|
|
implicitWidth: 38
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "±"
|
|
|
|
|
implicitWidth: 38
|
|
|
|
|
}
|
|
|
|
|
DigitButton { text: "0" }
|
|
|
|
|
DigitButton {
|
|
|
|
|
text: "."
|
|
|
|
|
dimmable: true
|
|
|
|
|
}
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "+"
|
|
|
|
|
implicitWidth: 38
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // RowLayout
|
2021-09-14 08:36:23 +00:00
|
|
|
|
}
|
2018-06-26 13:53:07 +00:00
|
|
|
|
}
|