Commit 5e3d81ec authored by Shawn Rutledge's avatar Shawn Rutledge Committed by The Qt Project
Browse files

Fix various bugs in calqlatr


It's still not a great example but at least it's somewhat usable now.
- added files to .pro so you see them all in Creator
- keypad is fixed size and the "tape" takes up the rest, so you can
  resize the window to be able to see long numbers
- you can flick the ListView (MouseArea not on top of the whole thing!)
- ListView scrolls to the bottom when you add numbers past the point
  that scrolling is necessary to see them
- Clear, sqrt and +/- keys are functional

Task-number: QTBUG-26556
Change-Id: I485e4123ad6c24ca64bad3efc3acfc14587268d8
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: default avatarAlan Alpert <aalpert@blackberry.com>
parent 251a267f
dev 5.10 5.11 5.12 5.12.1 5.12.10 5.12.11 5.12.12 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.12.7 5.12.8 5.12.9 5.13 5.13.0 5.13.1 5.13.2 5.14 5.14.0 5.14.1 5.14.2 5.15 5.15.0 5.15.1 5.15.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.9.8 6.0 6.0.0 6.1 6.1.0 6.1.1 6.1.2 6.1.3 6.2 6.2.0 6.2.1 6.2.2 old/5.1 old/5.2 wip/cmake wip/dbus wip/gc wip/itemviews wip/nacl wip/new-backend wip/pointerhandler wip/propertycache-refactor wip/qquickdeliveryagent wip/scenegraphng wip/tizen wip/webassembly v5.15.0-alpha1 v5.14.1 v5.14.0 v5.14.0-rc2 v5.14.0-rc1 v5.14.0-beta3 v5.14.0-beta2 v5.14.0-beta1 v5.14.0-alpha1 v5.13.2 v5.13.1 v5.13.0 v5.13.0-rc3 v5.13.0-rc2 v5.13.0-rc1 v5.13.0-beta4 v5.13.0-beta3 v5.13.0-beta2 v5.13.0-beta1 v5.13.0-alpha1 v5.12.7 v5.12.6 v5.12.5 v5.12.4 v5.12.3 v5.12.2 v5.12.1 v5.12.0 v5.12.0-rc2 v5.12.0-rc1 v5.12.0-beta4 v5.12.0-beta3 v5.12.0-beta2 v5.12.0-beta1 v5.12.0-alpha1 v5.11.3 v5.11.2 v5.11.1 v5.11.0 v5.11.0-rc2 v5.11.0-rc1 v5.11.0-beta4 v5.11.0-beta3 v5.11.0-beta2 v5.11.0-beta1 v5.11.0-alpha1 v5.10.1 v5.10.0 v5.10.0-rc3 v5.10.0-rc2 v5.10.0-rc1 v5.10.0-beta4 v5.10.0-beta3 v5.10.0-beta2 v5.10.0-beta1 v5.10.0-alpha1 v5.9.9 v5.9.8 v5.9.7 v5.9.6 v5.9.5 v5.9.4 v5.9.3 v5.9.2 v5.9.1 v5.9.0 v5.9.0-rc2 v5.9.0-rc1 v5.9.0-beta4 v5.9.0-beta3 v5.9.0-beta2 v5.9.0-beta1 v5.9.0-alpha1 v5.8.0 v5.8.0-rc1 v5.8.0-beta1 v5.8.0-alpha1 v5.7.1 v5.7.0 v5.7.0-rc1 v5.7.0-beta1 v5.7.0-alpha1 v5.6.3 v5.6.2 v5.6.1 v5.6.1-1 v5.6.0 v5.6.0-rc1 v5.6.0-beta1 v5.6.0-alpha1 v5.5.1 v5.5.0 v5.5.0-rc1 v5.5.0-beta1 v5.5.0-alpha1 v5.4.2 v5.4.1 v5.4.0 v5.4.0-rc1 v5.4.0-beta1 v5.4.0-alpha1 v5.3.2 v5.3.1 v5.3.0 v5.3.0-rc1 v5.3.0-beta1 v5.3.0-alpha1 v5.2.1 v5.2.0 v5.2.0-rc1 v5.2.0-beta1 v5.2.0-alpha1 v5.1.1 v5.1.0 v5.1.0-rc2 v5.1.0-rc1
No related merge requests found
Showing with 50 additions and 10 deletions
......@@ -6,5 +6,24 @@ SOURCES += main.cpp
RESOURCES += calqlatr.qrc \
../../shared/shared.qrc
OTHER_FILES = calqlatr.qml \
content/Button.qml \
content/Display.qml \
content/NumberPad.qml \
content/StyleLabel.qml \
content/audio/touch.wav \
content/calculator.js \
content/images/icon-back.png \
content/images/icon-close.png \
content/images/icon-settings.png \
content/images/logo.png \
content/images/paper-edge-left.png \
content/images/paper-edge-right.png \
content/images/paper-grip.png \
content/images/settings-selected-a.png \
content/images/settings-selected-b.png \
content/images/touch-green.png \
content/images/touch-white.png
target.path = $$[QT_INSTALL_EXAMPLES]/quick/demos/calqlatr
INSTALLS += target
......@@ -57,7 +57,7 @@ Rectangle {
Item {
id: pad
width: window.width * 0.58
width: 180
NumberPad { y: 10; anchors.horizontalCenter: parent.horizontalCenter }
}
......@@ -77,7 +77,7 @@ Rectangle {
Display {
id: display
x: -16
width: window.width * 0.42
width: window.width - pad.width
height: parent.height
MouseArea {
......@@ -85,7 +85,12 @@ Rectangle {
property real oldP: 0
property bool rewind: false
anchors.fill: parent
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
height: 50
onPositionChanged: {
var reverse = startX > window.width / 2
var mx = mapToItem(window, mouse.x).x
......
......@@ -42,23 +42,38 @@ import QtQuick 2.0
Item {
id: display
property bool enteringDigits: false
function displayOperator(operator)
{
listView.model.append({ "operator": operator, "operand": "" })
enteringDigits = true
}
function newLine(operator, operand)
{
listView.model.append({ "operator": operator, "operand": operand })
enteringDigits = false
listView.positionViewAtEnd()
}
function appendDigit(digit)
{
if (!listView.model.count)
if (!enteringDigits)
listView.model.append({ "operator": "", "operand": "" })
var i = listView.model.count - 1;
listView.model.get(i).operand = listView.model.get(i).operand + digit;
enteringDigits = true
}
function clear()
{
if (enteringDigits) {
var i = listView.model.count - 1
if (i >= 0)
listView.model.remove(i)
enteringDigits = false
}
}
Item {
......@@ -87,6 +102,7 @@ Item {
}
Image {
id: grip
source: "images/paper-grip.png"
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
......@@ -97,7 +113,7 @@ Item {
id: listView
x: 16; y: 30
width: display.width
height: display.height
height: display.height - 50 - y
delegate: Item {
height: 20
width: parent.width
......
......@@ -60,7 +60,7 @@ Grid {
Button { text: "±"; color: "#6da43d"; operator: true }
Button { text: ""; color: "#6da43d"; operator: true }
Button { text: "+"; color: "#6da43d"; operator: true }
Button { text: " "; color: "#6da43d"; operator: true }
Button { text: ""; color: "#6da43d"; operator: true }
Button { text: "÷"; color: "#6da43d"; operator: true }
Button { text: "×"; color: "#6da43d"; operator: true }
Button { text: "C"; color: "#6da43d"; operator: true }
......
......@@ -84,7 +84,7 @@ function operatorPressed(op)
} else if (previousOperator == "×") {
digits = Number(curVal) * Number(digits.valueOf())
} else if (previousOperator == "÷") {
digits = Number(Number(curVal) / Number(digits.valueOf())).toString()
digits = Number(curVal) / Number(digits.valueOf())
} else if (previousOperator == "=") {
}
......@@ -110,9 +110,9 @@ function operatorPressed(op)
digits = (Math.abs(digits.valueOf())).toString()
} else if (op == "Int") {
digits = (Math.floor(digits.valueOf())).toString()
} else if (op == window.plusminus) {
} else if (op == "±") {
digits = (digits.valueOf() * -1).toString()
} else if (op == window.squareRoot) {
} else if (op == "") {
digits = (Math.sqrt(digits.valueOf())).toString()
} else if (op == "mc") {
memory = 0;
......@@ -130,7 +130,7 @@ function operatorPressed(op)
} else if (op == "Off") {
Qt.quit();
} else if (op == "C") {
digits = "0"
display.clear()
} else if (op == "AC") {
curVal = 0
memory = 0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment