2019-04-03 06:07:15 +02:00
|
|
|
|
import QtQuick 2.0
|
|
|
|
|
import QtQuick.Controls 1.0
|
|
|
|
|
|
|
|
|
|
ApplicationWindow
|
|
|
|
|
{
|
|
|
|
|
visible: true
|
2019-10-21 08:36:31 +02:00
|
|
|
|
width: 4 * (100 + 5)
|
|
|
|
|
height: 5 * (100 + 5) + 200 + 30
|
2019-04-03 06:07:15 +02:00
|
|
|
|
title: qsTr("RPN Calculator")
|
|
|
|
|
|
|
|
|
|
//calculator
|
|
|
|
|
Column {
|
|
|
|
|
id: base;
|
|
|
|
|
spacing: 5;
|
|
|
|
|
width: 4 * (100 + 5)
|
2019-04-04 06:33:42 +02:00
|
|
|
|
height: 5 * (100 + 5) + 200 + 30
|
|
|
|
|
|
|
|
|
|
//quit button
|
|
|
|
|
Rectangle{
|
|
|
|
|
width: 100
|
|
|
|
|
height: 25
|
2019-10-07 09:19:26 +02:00
|
|
|
|
color: "#ff9494"
|
2019-04-04 06:33:42 +02:00
|
|
|
|
Text {text: "Quit"}
|
|
|
|
|
MouseArea {
|
|
|
|
|
onClicked: Qt.quit()
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-03 06:07:15 +02:00
|
|
|
|
|
|
|
|
|
//LCD
|
|
|
|
|
Rectangle {
|
2019-04-04 06:33:42 +02:00
|
|
|
|
objectName: "lcd";
|
|
|
|
|
color: "lightgray"
|
2019-04-03 06:07:15 +02:00
|
|
|
|
width: 4 * (100 + 5) - 5
|
|
|
|
|
height: 200
|
2019-04-04 06:33:42 +02:00
|
|
|
|
Text {
|
|
|
|
|
objectName: "lcd_text";
|
2019-04-04 07:32:15 +02:00
|
|
|
|
text: _calculator.lcdText
|
|
|
|
|
font: _fixedFont
|
2019-04-04 06:33:42 +02:00
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
}
|
2019-04-03 06:07:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Keyboard
|
|
|
|
|
Repeater {
|
|
|
|
|
model: 5;
|
|
|
|
|
//row
|
|
|
|
|
delegate: Row {
|
2019-04-04 06:33:42 +02:00
|
|
|
|
id: key_row
|
|
|
|
|
spacing: 5
|
|
|
|
|
objectName: index
|
2019-04-03 06:07:15 +02:00
|
|
|
|
//keys within row
|
|
|
|
|
Repeater {
|
|
|
|
|
model: 4;
|
|
|
|
|
delegate: Rectangle {
|
|
|
|
|
id: key_key;
|
|
|
|
|
width: 100;
|
|
|
|
|
height: 100;
|
2019-10-07 09:19:26 +02:00
|
|
|
|
color: getBackgroundColor(parent.objectName, index)
|
2019-04-03 06:07:15 +02:00
|
|
|
|
border { width: 1; color: "black" }
|
|
|
|
|
Text {
|
2019-10-07 09:19:26 +02:00
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
font.pointSize: 16
|
|
|
|
|
color: "gray"
|
|
|
|
|
text: {getShiftedText(parent.parent.objectName, index) + "<br><br>"}
|
|
|
|
|
textFormat: Text.RichText
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
}
|
|
|
|
|
Text {
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
font.pointSize: 24
|
|
|
|
|
text: {"<br>" + getText(parent.parent.objectName, index) + "<br>"}
|
|
|
|
|
textFormat: Text.RichText
|
2019-04-03 06:07:15 +02:00
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
}
|
2019-04-04 06:33:42 +02:00
|
|
|
|
MouseArea {
|
|
|
|
|
onClicked: _calculator.buttonClicked(parent.parent.objectName + "," + index)
|
|
|
|
|
anchors.fill: parent
|
2019-04-03 06:07:15 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-04 08:46:10 +02:00
|
|
|
|
|
|
|
|
|
function getText(row, col) {
|
|
|
|
|
var keys = [
|
2019-10-07 09:19:26 +02:00
|
|
|
|
["Shift", "x ⇄ y", "±", "←"],
|
|
|
|
|
["7", "8", "9", "÷"],
|
|
|
|
|
["4", "5", "6", "×"],
|
|
|
|
|
["1", "2", "3", "-"],
|
|
|
|
|
["0", ".", "Enter", "+"]
|
2019-04-04 08:46:10 +02:00
|
|
|
|
]
|
|
|
|
|
|
2019-10-07 09:19:26 +02:00
|
|
|
|
return "<b>" + keys[row][col] + "</b>"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getShiftedText(row, col) {
|
|
|
|
|
var shifted_keys = [
|
|
|
|
|
["Shift", "1/x", " √<span style=\"text-decoration: overline\">x</span> ", "CL<i>x</i>"],
|
|
|
|
|
["y<sup>x</sup> ", "ln(x)", "log(x)", ""],
|
2019-10-21 08:30:58 +02:00
|
|
|
|
["🔃", "e<sup>x</sup>", "10<sup>x</sup>", ""],
|
2019-10-07 09:19:26 +02:00
|
|
|
|
["", "", "", ""],
|
2019-10-21 08:30:58 +02:00
|
|
|
|
["off", "STO", "RCL", "LAST<i>x</i>"]
|
2019-10-07 09:19:26 +02:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
return "<small>" + shifted_keys[row][col] + "</small>"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getBackgroundColor(row, col) {
|
|
|
|
|
var background_color = [
|
|
|
|
|
["white", "white", "white", "#ff9494"],
|
|
|
|
|
["#eeeeee", "#eeeeee", "#eeeeee", "white"],
|
|
|
|
|
["#eeeeee", "#eeeeee", "#eeeeee", "white"],
|
|
|
|
|
["#eeeeee", "#eeeeee", "#eeeeee", "white"],
|
|
|
|
|
["#eeeeee", "#eeeeee", "white", "white"]
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
return background_color[row][col]
|
2019-04-04 08:46:10 +02:00
|
|
|
|
}
|
2019-04-03 06:07:15 +02:00
|
|
|
|
}
|