From babd84407a6a3475694268a3966f47a683e4d3cd Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 5 Oct 2016 17:52:52 -0400 Subject: Add a new Lumina project: desktop-utils/lumina-calculator This is just a very basic calculator at the moment. It still need more buttons/icons/features/etc added to it, but the algorithm and mathematics are already functional for evaluation expressions containing: Addition/Subtraction (+/-) Multiplication/Division( * or x, and /) Order of operations when mixing operations, including expressions within parentheses --- .../lumina-calculator/lumina-calculator.pro | 92 ++++++++++++++++++++++ src-qt5/desktop-utils/lumina-calculator/main.cpp | 19 +++++ src-qt5/desktop-utils/lumina-calculator/mainUI.cpp | 92 ++++++++++++++++++++++ src-qt5/desktop-utils/lumina-calculator/mainUI.h | 33 ++++++++ src-qt5/desktop-utils/lumina-calculator/mainUI.ui | 54 +++++++++++++ 5 files changed, 290 insertions(+) create mode 100644 src-qt5/desktop-utils/lumina-calculator/lumina-calculator.pro create mode 100644 src-qt5/desktop-utils/lumina-calculator/main.cpp create mode 100644 src-qt5/desktop-utils/lumina-calculator/mainUI.cpp create mode 100644 src-qt5/desktop-utils/lumina-calculator/mainUI.h create mode 100644 src-qt5/desktop-utils/lumina-calculator/mainUI.ui (limited to 'src-qt5/desktop-utils/lumina-calculator') diff --git a/src-qt5/desktop-utils/lumina-calculator/lumina-calculator.pro b/src-qt5/desktop-utils/lumina-calculator/lumina-calculator.pro new file mode 100644 index 00000000..8c36c516 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-calculator/lumina-calculator.pro @@ -0,0 +1,92 @@ +include("$${PWD}/../../OS-detect.pri") + +QT += core gui widgets + +TARGET = lumina-calculator +target.path = $${L_BINDIR} + +HEADERS += mainUI.h + +SOURCES += main.cpp \ + mainUI.cpp + +FORMS += mainUI.ui + +LIBS += -lLuminaUtils + +DEPENDPATH += ../../libLumina + +TRANSLATIONS = i18n/l-calc_af.ts \ + i18n/l-calc_ar.ts \ + i18n/l-calc_az.ts \ + i18n/l-calc_bg.ts \ + i18n/l-calc_bn.ts \ + i18n/l-calc_bs.ts \ + i18n/l-calc_ca.ts \ + i18n/l-calc_cs.ts \ + i18n/l-calc_cy.ts \ + i18n/l-calc_da.ts \ + i18n/l-calc_de.ts \ + i18n/l-calc_el.ts \ + i18n/l-calc_en_GB.ts \ + i18n/l-calc_en_ZA.ts \ + i18n/l-calc_es.ts \ + i18n/l-calc_et.ts \ + i18n/l-calc_eu.ts \ + i18n/l-calc_fa.ts \ + i18n/l-calc_fi.ts \ + i18n/l-calc_fr.ts \ + i18n/l-calc_fr_CA.ts \ + i18n/l-calc_gl.ts \ + i18n/l-calc_he.ts \ + i18n/l-calc_hi.ts \ + i18n/l-calc_hr.ts \ + i18n/l-calc_hu.ts \ + i18n/l-calc_id.ts \ + i18n/l-calc_is.ts \ + i18n/l-calc_it.ts \ + i18n/l-calc_ja.ts \ + i18n/l-calc_ka.ts \ + i18n/l-calc_ko.ts \ + i18n/l-calc_lt.ts \ + i18n/l-calc_lv.ts \ + i18n/l-calc_mk.ts \ + i18n/l-calc_mn.ts \ + i18n/l-calc_ms.ts \ + i18n/l-calc_mt.ts \ + i18n/l-calc_nb.ts \ + i18n/l-calc_nl.ts \ + i18n/l-calc_pa.ts \ + i18n/l-calc_pl.ts \ + i18n/l-calc_pt.ts \ + i18n/l-calc_pt_BR.ts \ + i18n/l-calc_ro.ts \ + i18n/l-calc_ru.ts \ + i18n/l-calc_sk.ts \ + i18n/l-calc_sl.ts \ + i18n/l-calc_sr.ts \ + i18n/l-calc_sv.ts \ + i18n/l-calc_sw.ts \ + i18n/l-calc_ta.ts \ + i18n/l-calc_tg.ts \ + i18n/l-calc_th.ts \ + i18n/l-calc_tr.ts \ + i18n/l-calc_uk.ts \ + i18n/l-calc_uz.ts \ + i18n/l-calc_vi.ts \ + i18n/l-calc_zh_CN.ts \ + i18n/l-calc_zh_HK.ts \ + i18n/l-calc_zh_TW.ts \ + i18n/l-calc_zu.ts + +dotrans.path=$${L_SHAREDIR}/lumina-desktop/i18n/ +dotrans.extra=cd i18n && $${LRELEASE} -nounfinished *.ts && cp *.qm $(INSTALL_ROOT)$${L_SHAREDIR}/lumina-desktop/i18n/ + +#desktop.files=lumina-calculator.desktop +#desktop.path=$${L_SHAREDIR}/applications/ + +INSTALLS += target + +WITH_I18N{ + INSTALLS += dotrans +} diff --git a/src-qt5/desktop-utils/lumina-calculator/main.cpp b/src-qt5/desktop-utils/lumina-calculator/main.cpp new file mode 100644 index 00000000..af252cb3 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-calculator/main.cpp @@ -0,0 +1,19 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2016, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include +#include + +#include "mainUI.h" + +int main(int argc, char *argv[]) { + QApplication a(argc, argv); + + //Now start the window + mainUI W; + W.show(); + return a.exec(); +} diff --git a/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp b/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp new file mode 100644 index 00000000..18d2cfdd --- /dev/null +++ b/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp @@ -0,0 +1,92 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2016, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "mainUI.h" +#include "ui_mainUI.h" + +#include + +#define VALIDSYMBOLS QString("+-*x/.") + +#include +#define BADVALUE NAN + +mainUI::mainUI() : QMainWindow(), ui(new Ui::mainUI()){ + ui->setupUi(this); + connect(ui->tool_start, SIGNAL(clicked()), this, SLOT(start_calc()) ); + connect(ui->line_eq, SIGNAL(returnPressed()), this, SLOT(start_calc()) ); + ui->line_eq->setFocus(); +} + +mainUI::~mainUI(){ + +} + +void mainUI::start_calc(){ + if(ui->line_eq->text().isEmpty()){ return; } //nothing to do + double result = strToNumber(ui->line_eq->text()); + if(result!=result){ return; } //bad calculation - NaN's values are special in that they don't equal itself + QString res = "%1 \t(%2)"; + ui->list_results->addItem(res.arg(QString::number(result), ui->line_eq->text())); + ui->list_results->scrollToItem( ui->list_results->item( ui->list_results->count()-1) ); + ui->line_eq->clear(); +} + +double mainUI::performOperation(double LHS, double RHS, QChar symbol){ + if(symbol== '+'){ return (LHS+RHS); } + else if(symbol== '-'){ return (LHS-RHS); } + else if(symbol== '*' || symbol=='x'){ return (LHS*RHS); } + else if(symbol== '/'){ return (LHS/RHS); } + //else if(symbol== '%'){ return (LHS%RHS); } + qDebug() << "Invalid Symbol:" << symbol; + return BADVALUE; +} + +double mainUI::strToNumber(QString str){ + //Look for perentheses first + qDebug() << "String to Number: " << str; + if(str.indexOf("(")>=0){ + //qDebug() << "Found Parenthesis"; + int start = str.indexOf("("); + int need = 1; + int end = -1; + for(int i=start+1; i0; i++){ + if(str[i]=='('){ need++; } + else if(str[i]==')'){ need--; } + //qDebug() << "Check char:" << str[i] << need; + if(need==0){ end = i; } + } + if(end0){ return performOperation( strToNumber(str.left(sym)), strToNumber(str.right(str.length()-sym-1)), str[sym]); } + if(sym==0){ return BADVALUE; } + //Now look for multiply/divide + symbols.clear(); symbols << "x" << "*" << "/"; + for(int i=0; i0){ return performOperation( strToNumber(str.left(sym)), strToNumber(str.right(str.length()-sym-1)), str[sym]); } + if(sym==0){ return BADVALUE; } + + //Could not find any operations - must be a raw number + //qDebug() << "Found Number:" << str.toDouble(); + return str.toDouble(); +} diff --git a/src-qt5/desktop-utils/lumina-calculator/mainUI.h b/src-qt5/desktop-utils/lumina-calculator/mainUI.h new file mode 100644 index 00000000..96414252 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-calculator/mainUI.h @@ -0,0 +1,33 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2016, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_CALCULATOR_MAIN_UI_H +#define _LUMINA_CALCULATOR_MAIN_UI_H + +#include +#include +#include + +namespace Ui{ + class mainUI; +}; + +class mainUI : public QMainWindow{ + Q_OBJECT +public: + mainUI(); + ~mainUI(); + +private slots: + void start_calc(); + +private: + Ui::mainUI *ui; + + double performOperation(double LHS, double RHS, QChar symbol); + double strToNumber(QString str); //this is highly-recursive +}; +#endif diff --git a/src-qt5/desktop-utils/lumina-calculator/mainUI.ui b/src-qt5/desktop-utils/lumina-calculator/mainUI.ui new file mode 100644 index 00000000..0e52f4db --- /dev/null +++ b/src-qt5/desktop-utils/lumina-calculator/mainUI.ui @@ -0,0 +1,54 @@ + + + mainUI + + + + 0 + 0 + 245 + 149 + + + + Calculator + + + + + + + + + + + + + + + ... + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + -- cgit From 6cdd979279875d5f60f8772eeae55bec372ef581 Mon Sep 17 00:00:00 2001 From: JT Pennington Date: Thu, 13 Oct 2016 14:44:12 -0400 Subject: add buttons --- src-qt5/desktop-utils/lumina-calculator/mainUI.ui | 192 +++++++++++++++++++--- 1 file changed, 165 insertions(+), 27 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-calculator') diff --git a/src-qt5/desktop-utils/lumina-calculator/mainUI.ui b/src-qt5/desktop-utils/lumina-calculator/mainUI.ui index 0e52f4db..2ca316ed 100644 --- a/src-qt5/desktop-utils/lumina-calculator/mainUI.ui +++ b/src-qt5/desktop-utils/lumina-calculator/mainUI.ui @@ -6,48 +6,186 @@ 0 0 - 245 - 149 + 255 + 376 Calculator - - - - - - + + + + 9 + 9 + 241 + 361 + + + + Qt::Vertical + + + - + - + + + + + + + + C + + + false + + + + + + + + + + + + + 7 + + + + + + + 8 + + + + + + + 9 + + + + + + + / + + + + + + + 4 + + + + + + + 5 + + + + + + + 6 + + + + + + + * + + + + + + + 1 + + + + + + + 2 + + + + + + + 3 + + + + + + + - + + + + + + + 0 + + + + + + + . + + + + + + + = + + + + + - ... + + - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + + + list_results + button_7 + button_8 + button_9 + button_Divide + button_4 + button_5 + button_6 + button_Multiply + button_1 + button_2 + button_3 + button_Subtract + button_0 + button_Decimal + button_Equal + button_Add + line_eq - -- cgit From 850d4681f0da8b2b68f9382b3883a584be5dd712 Mon Sep 17 00:00:00 2001 From: JT Pennington Date: Thu, 13 Oct 2016 14:44:50 -0400 Subject: add buttons --- src-qt5/desktop-utils/lumina-calculator/mainUI.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src-qt5/desktop-utils/lumina-calculator') diff --git a/src-qt5/desktop-utils/lumina-calculator/mainUI.h b/src-qt5/desktop-utils/lumina-calculator/mainUI.h index 96414252..0d99c83a 100644 --- a/src-qt5/desktop-utils/lumina-calculator/mainUI.h +++ b/src-qt5/desktop-utils/lumina-calculator/mainUI.h @@ -23,10 +23,27 @@ public: private slots: void start_calc(); + void clear_calc(); + void captureButton1(); + void captureButton2(); + void captureButton3(); + void captureButton4(); + void captureButton5(); + void captureButton6(); + void captureButton7(); + void captureButton8(); + void captureButton9(); + void captureButton0(); + void captureButtonSubtract(); + void captureButtonAdd(); + void captureButtonDivide(); + void captureButtonMultiply(); +// void captureButtonEqual(); + void captureButtonDecimal(); + private: Ui::mainUI *ui; - double performOperation(double LHS, double RHS, QChar symbol); double strToNumber(QString str); //this is highly-recursive }; -- cgit From 2db8cc67307a1c33ea982de36a10793efcfff6e1 Mon Sep 17 00:00:00 2001 From: JT Pennington Date: Thu, 13 Oct 2016 14:45:19 -0400 Subject: add buttons --- src-qt5/desktop-utils/lumina-calculator/mainUI.cpp | 43 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-calculator') diff --git a/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp b/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp index 18d2cfdd..f759f5c6 100644 --- a/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp @@ -16,13 +16,30 @@ mainUI::mainUI() : QMainWindow(), ui(new Ui::mainUI()){ ui->setupUi(this); - connect(ui->tool_start, SIGNAL(clicked()), this, SLOT(start_calc()) ); + connect(ui->tool_clear, SIGNAL(clicked()), this, SLOT(clear_calc()) ); connect(ui->line_eq, SIGNAL(returnPressed()), this, SLOT(start_calc()) ); + connect (ui->button_1, SIGNAL (clicked()), this, SLOT (captureButton1())); + connect (ui->button_2, SIGNAL (clicked()), this, SLOT (captureButton2())); + connect (ui->button_3, SIGNAL (clicked()), this, SLOT (captureButton3())); + connect (ui->button_4, SIGNAL (clicked()), this, SLOT (captureButton4())); + connect (ui->button_5, SIGNAL (clicked()), this, SLOT (captureButton5())); + connect (ui->button_6, SIGNAL (clicked()), this, SLOT (captureButton6())); + connect (ui->button_7, SIGNAL (clicked()), this, SLOT (captureButton7())); + connect (ui->button_8, SIGNAL (clicked()), this, SLOT (captureButton8())); + connect (ui->button_9, SIGNAL (clicked()), this, SLOT (captureButton9())); + connect (ui->button_0, SIGNAL (clicked()), this, SLOT (captureButton0())); + connect (ui->button_Subtract, SIGNAL (clicked()), this, SLOT (captureButtonSubtract())); + connect (ui->button_Add, SIGNAL (clicked()), this, SLOT (captureButtonAdd())); + connect (ui->button_Divide, SIGNAL (clicked()), this, SLOT (captureButtonDivide())); + connect (ui->button_Multiply, SIGNAL (clicked()), this, SLOT (captureButtonMultiply())); + connect (ui->button_Decimal, SIGNAL (clicked()), this, SLOT (captureButtonDecimal())); + connect (ui->button_Equal, SIGNAL (clicked()), this, SLOT (start_calc())); + + ui->line_eq->setFocus(); } mainUI::~mainUI(){ - } void mainUI::start_calc(){ @@ -35,6 +52,28 @@ void mainUI::start_calc(){ ui->line_eq->clear(); } +void mainUI::clear_calc(){ + ui->line_eq->clear(); + ui->line_eq->setFocus(); +} + +void mainUI::captureButton1(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_1->text()); } +void mainUI::captureButton2(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_2->text()); } +void mainUI::captureButton3(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_3->text()); } +void mainUI::captureButton4(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_4->text()); } +void mainUI::captureButton5(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_5->text()); } +void mainUI::captureButton6(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_6->text()); } +void mainUI::captureButton7(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_7->text()); } +void mainUI::captureButton8(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_8->text()); } +void mainUI::captureButton9(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_9->text()); } +void mainUI::captureButton0(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_0->text()); } +void mainUI::captureButtonSubtract(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_Subtract->text()); } +void mainUI::captureButtonAdd(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_Add->text()); } +void mainUI::captureButtonDivide(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_Divide->text()); } +void mainUI::captureButtonMultiply(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_Multiply->text()); } +//void mainUI::captureButtonEqual(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_Equal->text()); } +void mainUI::captureButtonDecimal(){ ui->line_eq->setText(ui->line_eq->text() += ui->button_Decimal->text()); } + double mainUI::performOperation(double LHS, double RHS, QChar symbol){ if(symbol== '+'){ return (LHS+RHS); } else if(symbol== '-'){ return (LHS-RHS); } -- cgit From 12417274b55f86acaa88cceb89b731b3a1398b36 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 13 Oct 2016 16:54:17 -0400 Subject: Add a title/icon for the lumina-calculator window. --- src-qt5/desktop-utils/lumina-calculator/mainUI.cpp | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-calculator') diff --git a/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp b/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp index f759f5c6..244a7f3e 100644 --- a/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp @@ -8,6 +8,7 @@ #include "ui_mainUI.h" #include +#include #define VALIDSYMBOLS QString("+-*x/.") @@ -18,24 +19,25 @@ mainUI::mainUI() : QMainWindow(), ui(new Ui::mainUI()){ ui->setupUi(this); connect(ui->tool_clear, SIGNAL(clicked()), this, SLOT(clear_calc()) ); connect(ui->line_eq, SIGNAL(returnPressed()), this, SLOT(start_calc()) ); - connect (ui->button_1, SIGNAL (clicked()), this, SLOT (captureButton1())); - connect (ui->button_2, SIGNAL (clicked()), this, SLOT (captureButton2())); - connect (ui->button_3, SIGNAL (clicked()), this, SLOT (captureButton3())); - connect (ui->button_4, SIGNAL (clicked()), this, SLOT (captureButton4())); - connect (ui->button_5, SIGNAL (clicked()), this, SLOT (captureButton5())); - connect (ui->button_6, SIGNAL (clicked()), this, SLOT (captureButton6())); - connect (ui->button_7, SIGNAL (clicked()), this, SLOT (captureButton7())); - connect (ui->button_8, SIGNAL (clicked()), this, SLOT (captureButton8())); - connect (ui->button_9, SIGNAL (clicked()), this, SLOT (captureButton9())); - connect (ui->button_0, SIGNAL (clicked()), this, SLOT (captureButton0())); - connect (ui->button_Subtract, SIGNAL (clicked()), this, SLOT (captureButtonSubtract())); - connect (ui->button_Add, SIGNAL (clicked()), this, SLOT (captureButtonAdd())); - connect (ui->button_Divide, SIGNAL (clicked()), this, SLOT (captureButtonDivide())); - connect (ui->button_Multiply, SIGNAL (clicked()), this, SLOT (captureButtonMultiply())); - connect (ui->button_Decimal, SIGNAL (clicked()), this, SLOT (captureButtonDecimal())); - connect (ui->button_Equal, SIGNAL (clicked()), this, SLOT (start_calc())); - + connect(ui->button_1, SIGNAL (clicked()), this, SLOT (captureButton1())); + connect(ui->button_2, SIGNAL (clicked()), this, SLOT (captureButton2())); + connect(ui->button_3, SIGNAL (clicked()), this, SLOT (captureButton3())); + connect(ui->button_4, SIGNAL (clicked()), this, SLOT (captureButton4())); + connect(ui->button_5, SIGNAL (clicked()), this, SLOT (captureButton5())); + connect(ui->button_6, SIGNAL (clicked()), this, SLOT (captureButton6())); + connect(ui->button_7, SIGNAL (clicked()), this, SLOT (captureButton7())); + connect(ui->button_8, SIGNAL (clicked()), this, SLOT (captureButton8())); + connect(ui->button_9, SIGNAL (clicked()), this, SLOT (captureButton9())); + connect(ui->button_0, SIGNAL (clicked()), this, SLOT (captureButton0())); + connect(ui->button_Subtract, SIGNAL (clicked()), this, SLOT (captureButtonSubtract())); + connect(ui->button_Add, SIGNAL (clicked()), this, SLOT (captureButtonAdd())); + connect(ui->button_Divide, SIGNAL (clicked()), this, SLOT (captureButtonDivide())); + connect(ui->button_Multiply, SIGNAL (clicked()), this, SLOT (captureButtonMultiply())); + connect(ui->button_Decimal, SIGNAL (clicked()), this, SLOT (captureButtonDecimal())); + connect(ui->button_Equal, SIGNAL (clicked()), this, SLOT (start_calc())); + this->setWindowTitle(tr("Calculator")); + this->setWindowIcon( LXDG::findIcon("accessories-calculator","") ); ui->line_eq->setFocus(); } @@ -86,7 +88,7 @@ double mainUI::performOperation(double LHS, double RHS, QChar symbol){ double mainUI::strToNumber(QString str){ //Look for perentheses first - qDebug() << "String to Number: " << str; + //qDebug() << "String to Number: " << str; if(str.indexOf("(")>=0){ //qDebug() << "Found Parenthesis"; int start = str.indexOf("("); -- cgit