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
|
2018-06-26 13:53:07 +00:00
|
|
|
|
|
|
|
|
|
Grid {
|
2023-10-02 09:20:35 +00:00
|
|
|
|
id: root
|
2018-06-26 13:53:07 +00:00
|
|
|
|
columns: 3
|
2022-11-10 14:06:08 +00:00
|
|
|
|
columnSpacing: 2
|
|
|
|
|
rowSpacing: 2
|
2018-06-26 13:53:07 +00:00
|
|
|
|
|
2023-10-02 09:20:35 +00:00
|
|
|
|
required property Display display
|
|
|
|
|
|
|
|
|
|
function updateDimmed() {
|
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
|
children[i].dimmed = CalcEngine.isOperationDisabled(children[i].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 {
|
|
|
|
|
onPressed: function() {
|
2023-10-02 09:20:35 +00:00
|
|
|
|
CalcEngine.digitPressed(text, root.display)
|
|
|
|
|
root.updateDimmed()
|
2021-09-14 08:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
component OperatorButton: CalculatorButton {
|
|
|
|
|
onPressed: function() {
|
2023-10-02 09:20:35 +00:00
|
|
|
|
CalcEngine.operatorPressed(text, root.display)
|
|
|
|
|
root.updateDimmed()
|
2021-09-14 08:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
textColor: "#6da43d"
|
|
|
|
|
dimmable: true
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-02 09:20:35 +00:00
|
|
|
|
Component.onCompleted: updateDimmed()
|
|
|
|
|
|
2021-09-14 08:36:23 +00:00
|
|
|
|
DigitButton {
|
|
|
|
|
text: "7"
|
|
|
|
|
}
|
|
|
|
|
DigitButton {
|
|
|
|
|
text: "8"
|
|
|
|
|
}
|
|
|
|
|
DigitButton {
|
|
|
|
|
text: "9"
|
|
|
|
|
}
|
|
|
|
|
DigitButton {
|
|
|
|
|
text: "4"
|
|
|
|
|
}
|
|
|
|
|
DigitButton {
|
|
|
|
|
text: "5"
|
|
|
|
|
}
|
|
|
|
|
DigitButton {
|
|
|
|
|
text: "6"
|
|
|
|
|
}
|
|
|
|
|
DigitButton {
|
|
|
|
|
text: "1"
|
|
|
|
|
}
|
|
|
|
|
DigitButton {
|
|
|
|
|
text: "2"
|
|
|
|
|
}
|
|
|
|
|
DigitButton {
|
|
|
|
|
text: "3"
|
|
|
|
|
}
|
|
|
|
|
DigitButton {
|
|
|
|
|
text: "0"
|
|
|
|
|
}
|
|
|
|
|
DigitButton {
|
|
|
|
|
text: "."
|
|
|
|
|
dimmable: true
|
|
|
|
|
}
|
|
|
|
|
DigitButton {
|
|
|
|
|
text: " "
|
|
|
|
|
}
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "±"
|
|
|
|
|
}
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "−"
|
|
|
|
|
}
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "+"
|
|
|
|
|
}
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "√"
|
|
|
|
|
}
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "÷"
|
|
|
|
|
}
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "×"
|
|
|
|
|
}
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "C"
|
|
|
|
|
}
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: " "
|
|
|
|
|
}
|
|
|
|
|
OperatorButton {
|
|
|
|
|
text: "="
|
|
|
|
|
}
|
2018-06-26 13:53:07 +00:00
|
|
|
|
}
|