From 6ae1651c0af0e6b6f4b12bbe3b11006a353b5afe Mon Sep 17 00:00:00 2001 From: NeoTheFox Date: Tue, 10 Mar 2015 18:39:09 +0300 Subject: [PATCH] Added history of user commands --- mainwindow.cpp | 33 +++++++++++++++++++++++++++++++++ mainwindow.h | 3 +++ 2 files changed, 36 insertions(+) diff --git a/mainwindow.cpp b/mainwindow.cpp index 84f3b9a..870306d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -20,6 +20,7 @@ MainWindow::MainWindow(QWidget *parent) : ui->actionEEPROM_editor->setDisabled(true); ui->extruderlcd->setPalette(Qt::red); ui->bedlcd->setPalette(Qt::red); + ui->sendtext->installEventFilter(this); //Init baudrate combobox ui->baudbox->addItem(QString::number(4800)); @@ -55,6 +56,8 @@ MainWindow::MainWindow(QWidget *parent) : currentLine = 0; readyRecieve = 1; lastRecieved = 0; + userHistoryPos = 0; + userHistory.append(""); //Update serial ports serialupdate(); @@ -353,6 +356,8 @@ void MainWindow::homeall() void MainWindow::on_sendbtn_clicked() { injectCommand(ui->sendtext->text()); + userHistory.append(ui->sendtext->text()); + userHistoryPos = 0; } void MainWindow::on_fanonbtn_clicked() @@ -847,3 +852,31 @@ void MainWindow::recievedResend(int num) { if(!sendingChecksum) currentLine--; } + +bool MainWindow::eventFilter(QObject *obj, QEvent *event) +{ + if(obj == ui->sendtext && !userHistory.isEmpty()) + { + if(event->type() == QEvent::KeyPress) + { + QKeyEvent *keyEvent = static_cast(event); + + if (keyEvent->key() == Qt::Key_Up) + { + if(++userHistoryPos <= userHistory.size()-1) + ui->sendtext->setText(userHistory.at(userHistoryPos)); + else userHistoryPos--; + return true; + } + else if(keyEvent->key() == Qt::Key_Down) + { + if(--userHistoryPos >= 0) + ui->sendtext->setText(userHistory.at(userHistoryPos)); + else userHistoryPos++; + return true; + } + } + return false; + } + return QMainWindow::eventFilter(obj, event); +} diff --git a/mainwindow.h b/mainwindow.h index c068b92..e6ef7dc 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -51,6 +51,8 @@ protected: QSettings settings; QStringList recentFiles; QStringList EEPROMSettings; + QStringList userHistory; + bool eventFilter(QObject *target, QEvent *event); private: Ui::MainWindow *ui; @@ -72,6 +74,7 @@ private: long int currentLine; unsigned long int lastRecieved; int readyRecieve; + int userHistoryPos; unsigned long int sdBytes; private slots: