From 0107662030f5ebf25a65fca39d203e821cfeb544 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 20 Oct 2016 15:43:54 -0400 Subject: Setup the calculator to automatically load the last result if the first char is an operator. --- src-qt5/desktop-utils/lumina-calculator/mainUI.cpp | 13 +++++++++++++ src-qt5/desktop-utils/lumina-calculator/mainUI.h | 1 + 2 files changed, 14 insertions(+) (limited to 'src-qt5/desktop-utils') diff --git a/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp b/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp index 49449586..a85bcf42 100644 --- a/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-calculator/mainUI.cpp @@ -16,10 +16,13 @@ #include #define BADVALUE NAN +#define OPS QString("+-*/x^") + 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->line_eq, SIGNAL(textEdited(const QString&)), this, SLOT(checkInput(const QString&)) ); 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())); @@ -93,6 +96,16 @@ void mainUI::copy_to_clipboard(QListWidgetItem *it){ QString txt = it->text(); QApplication::clipboard()->setText(txt); } + +void mainUI::checkInput(const QString &str){ + if(str.length()==1 && ui->list_results->count()>0){ + if(OPS.contains(str)){ + QString lastresult = ui->list_results->item( ui->list_results->count()-1)->text().section("=",0,0).simplified(); + ui->line_eq->setText( lastresult+str); + } + } +} + // ===================== // PRIVATE FUNCTIONS // ===================== diff --git a/src-qt5/desktop-utils/lumina-calculator/mainUI.h b/src-qt5/desktop-utils/lumina-calculator/mainUI.h index 50762677..b4636126 100644 --- a/src-qt5/desktop-utils/lumina-calculator/mainUI.h +++ b/src-qt5/desktop-utils/lumina-calculator/mainUI.h @@ -47,6 +47,7 @@ private slots: void insert_history(QListWidgetItem *it); void copy_to_clipboard(QListWidgetItem *it); + void checkInput(const QString&); private: Ui::mainUI *ui; -- cgit