diff --git a/README.md b/README.md index abc9faa..062ccb0 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,8 @@ results are stored there. Pointing history list line inserts result to the expre Pointing and holding history line recalls the whole expression for editing. Below the history list is expression editing field. It can be edited either by calculator key panes -or normal virtual keyboard. - -xxx Below the expression editor is label field used for function usage parameters and autocalc results. +or normal virtual keyboard. Popup message above edit field displays current result or possible +error message. #### Keyboard and pulley menu diff --git a/android-speedcrunch.pro b/android-speedcrunch.pro index 60391ff..67db2d8 100644 --- a/android-speedcrunch.pro +++ b/android-speedcrunch.pro @@ -1,16 +1,35 @@ +# This file is part of the SpeedCrunch project +# Copyright (C) 2014 @qwazix +# Copyright (C) 2018 Mikko Syrjä +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. QT += quick qml CONFIG += c++11 -# PKGCONFIG += sailfishapp -# INCLUDEPATH += /usr/include/sailfishapp +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS -#TARGETPATH = /usr/bin -#target.path = $$TARGETPATH - -#DEPLOYMENT_PATH = /usr/share/$$TARGET -#qml.files = qml -#qml.path = $$DEPLOYMENT_PATH +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 DEFINES += SPEEDCRUNCH_VERSION=\\\"master\\\" @@ -121,6 +140,12 @@ DISTFILES += \ RESOURCES += qml.qrc +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Additional import path used to resolve QML modules just for Qt Quick Designer +QML_DESIGNER_IMPORT_PATH = + # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin diff --git a/qml/Calculator.qml b/qml/Calculator.qml index 363b158..a3c2b6c 100644 --- a/qml/Calculator.qml +++ b/qml/Calculator.qml @@ -4,6 +4,7 @@ import QtQuick.Controls 2.3 Page { property int keyboardheight: parent.height * (landscape ? 60 : 45) / 100 + property string notification: "" property alias history: historyview property alias editor: textfield @@ -118,6 +119,23 @@ Page inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase; placeholderText: "expression" cursorVisible: true + ToolTip + { + parent: textfield + x: parent.x + font.pixelSize: fontsizelist + closePolicy: Popup.NoAutoClose + visible: (swipe.currentIndex === 1 && notification !== "" && textfield.text !== "") + text: notification + } + onTextChanged: + { + var result = manager.autoCalc(text); + if ( manager.autoCalc(text) !== "NaN" ) + notification = "= " + result + else + notification = manager.getError() + } Keys.onReturnPressed: { setDefaultFocus() } } Rectangle @@ -209,29 +227,11 @@ Page if ( textfield.text !== "" ) { var result = manager.calculate(textfield.text) - var assign = manager.getAssignId() if ( result === "NaN" ) - { - var error = manager.getError() - if ( error.length ) - { -// notification.previewSummary = "Evaluation error" -// notification.previewBody = error - } - else if ( assign.length ) - { - latestExpression = manager.autoFix(textfield.text) - latestResult = "" - historyview.updateHistory() - functions.updateFunctions() -// notification.previewSummary = "Function added" -// notification.previewBody = "" - textfield.text = "" - } -// notification.publish() - } + notification = manager.getError() else { + var assign = manager.getAssignId() latestExpression = manager.autoFix(textfield.text) latestResult = result historyview.updateHistory() diff --git a/qml/Functions.qml b/qml/Functions.qml index 0d34000..f6638a4 100644 --- a/qml/Functions.qml +++ b/qml/Functions.qml @@ -32,7 +32,13 @@ Page background: Rectangle { radius: cornerradius; color: settingscolor } font.pixelSize: fontsize model: [ "All", "Functions", "Units", "Constants", "User defined" ] - delegate: ItemDelegate { text: modelData; font.pixelSize: fontsize } + delegate: ItemDelegate + { + text: modelData; + width: parent.width + font.pixelSize: fontsize + highlighted: ListView.isCurrentItem + } onCurrentIndexChanged: { if ( currentIndex == 0 ) { filtertype = "a" } @@ -139,8 +145,8 @@ Page functionlist.currentIndex = -1 if ( popupmenu.opened ) popupmenu.close() - else if ( acceptclic ) - insert() +// else if ( acceptclic ) +// insert() } onPressed: { diff --git a/qml/Settings.qml b/qml/Settings.qml index 14ec37d..c85382a 100644 --- a/qml/Settings.qml +++ b/qml/Settings.qml @@ -41,7 +41,13 @@ Page "Scientific decimal", "Binary", "Octal", "Hexadecimal" ] // model: [ "General decimal", "Fixed decimal", "Engineering decimal", // "Scientific decimal", "Binary", "Octal", "Hexadecimal", "Sexagesimal" ] - delegate: ItemDelegate { text: modelData; font.pixelSize: fontsize } + delegate: ItemDelegate + { + text: modelData; + width: parent.width + font.pixelSize: fontsize + highlighted: ListView.isCurrentItem + } onCurrentIndexChanged: { if ( initialized ) @@ -87,7 +93,13 @@ Page background: Rectangle { radius: cornerradius; color: settingscolor } font.pixelSize: fontsize model: [ "Automatic", "0", "1", "2", "3", "4", "6", "8", "12", "16", "20" ] - delegate: ItemDelegate { text: modelData; font.pixelSize: fontsize } + delegate: ItemDelegate + { + text: modelData; + width: parent.width + font.pixelSize: fontsize + highlighted: ListView.isCurrentItem + } onCurrentIndexChanged: { if ( initialized ) switch ( currentIndex ) @@ -139,7 +151,13 @@ Page font.pixelSize: fontsize model: [ "Degree", "Radian" ] // model: [ "Degree", "Radian", "Gradian" ] - delegate: ItemDelegate { text: modelData; font.pixelSize: fontsize } + delegate: ItemDelegate + { + text: modelData; + width: parent.width + font.pixelSize: fontsize + highlighted: ListView.isCurrentItem + } onCurrentIndexChanged: { if ( initialized ) @@ -173,7 +191,13 @@ Page background: Rectangle { radius: cornerradius; color: settingscolor } font.pixelSize: fontsize model: [ "Disabled", "Cartesian", "Polar" ] - delegate: ItemDelegate { text: modelData; font.pixelSize: fontsize } + delegate: ItemDelegate + { + text: modelData; + width: parent.width + font.pixelSize: fontsize + highlighted: ListView.isCurrentItem + } onCurrentIndexChanged: { if ( initialized ) @@ -219,7 +243,13 @@ Page background: Rectangle { radius: cornerradius; color: settingscolor } font.pixelSize: fontsize model: [ "Small", "Medium", "Large" ] - delegate: ItemDelegate { text: modelData; font.pixelSize: fontsize } + delegate: ItemDelegate + { + text: modelData; + width: parent.width + font.pixelSize: fontsize + highlighted: ListView.isCurrentItem + } onCurrentIndexChanged: { if ( initialized ) diff --git a/qml/android-speedcrunch.qml b/qml/android-speedcrunch.qml index ba4cc51..44a764e 100644 --- a/qml/android-speedcrunch.qml +++ b/qml/android-speedcrunch.qml @@ -21,6 +21,7 @@ ApplicationWindow property int cornerradius: width / buttoncols / 15 property int itemspacing: width / buttoncols / 15 + property alias functions: functions property alias history: calculator.history property alias editor: calculator.editor property alias keyboard: calculator.keyboard @@ -119,6 +120,7 @@ ApplicationWindow editor.cursorPosition = pos + value.length } } +// MenuSeparator { } MenuItem { text: qsTr("Clear history") diff --git a/src/manager.cpp b/src/manager.cpp index ab46306..2c692cc 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -136,14 +136,14 @@ void Manager::saveSession() //! Auto calculate expression. /*! \param input Expression. - \return Result string. + \return Result string or NaN for error. */ QString Manager::autoCalc(const QString& input) { const QString expression = evaluator->autoFix(input); evaluator->setExpression(expression); Quantity quantity = evaluator->evalNoAssign(); - if ( quantity.isNan() ) + if ( quantity.isNan() || !evaluator->error().isEmpty() ) return "NaN"; return NumberFormatter::format(quantity); } @@ -161,20 +161,22 @@ QString Manager::autoFix(const QString& input) //! Calculate expression. /*! \param input Expression. - \return Result string. + \return Result string or NaN for error. */ QString Manager::calculate(const QString& input) { - const QString expression = evaluator->autoFix(input); + QString expression = evaluator->autoFix(input); evaluator->setExpression(expression); Quantity quantity = evaluator->evalUpdateAns(); + if ( !evaluator->error().isEmpty() ) + return "NaN"; if ( quantity.isNan() ) { if ( evaluator->isUserFunctionAssign() ) { updateRecent(evaluator->getAssignId() + "()"); - if ( evaluator->error().isEmpty() ) - session->addHistoryEntry(HistoryEntry(expression, quantity)); + session->addHistoryEntry(HistoryEntry(expression, quantity)); + return "0"; } return "NaN"; } @@ -196,6 +198,8 @@ QString Manager::getError() { QString error = evaluator->error(); error.remove("").remove(""); + if ( error.isEmpty() && !evaluator->isValid() ) + error = "compile error"; return error; }