Added history of user commands

This commit is contained in:
NeoTheFox 2015-03-10 18:39:09 +03:00
parent bf79613ffb
commit 6ae1651c0a
2 changed files with 36 additions and 0 deletions

View File

@ -20,6 +20,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->actionEEPROM_editor->setDisabled(true); ui->actionEEPROM_editor->setDisabled(true);
ui->extruderlcd->setPalette(Qt::red); ui->extruderlcd->setPalette(Qt::red);
ui->bedlcd->setPalette(Qt::red); ui->bedlcd->setPalette(Qt::red);
ui->sendtext->installEventFilter(this);
//Init baudrate combobox //Init baudrate combobox
ui->baudbox->addItem(QString::number(4800)); ui->baudbox->addItem(QString::number(4800));
@ -55,6 +56,8 @@ MainWindow::MainWindow(QWidget *parent) :
currentLine = 0; currentLine = 0;
readyRecieve = 1; readyRecieve = 1;
lastRecieved = 0; lastRecieved = 0;
userHistoryPos = 0;
userHistory.append("");
//Update serial ports //Update serial ports
serialupdate(); serialupdate();
@ -353,6 +356,8 @@ void MainWindow::homeall()
void MainWindow::on_sendbtn_clicked() void MainWindow::on_sendbtn_clicked()
{ {
injectCommand(ui->sendtext->text()); injectCommand(ui->sendtext->text());
userHistory.append(ui->sendtext->text());
userHistoryPos = 0;
} }
void MainWindow::on_fanonbtn_clicked() void MainWindow::on_fanonbtn_clicked()
@ -847,3 +852,31 @@ void MainWindow::recievedResend(int num)
{ {
if(!sendingChecksum) currentLine--; 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<QKeyEvent *>(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);
}

View File

@ -51,6 +51,8 @@ protected:
QSettings settings; QSettings settings;
QStringList recentFiles; QStringList recentFiles;
QStringList EEPROMSettings; QStringList EEPROMSettings;
QStringList userHistory;
bool eventFilter(QObject *target, QEvent *event);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
@ -72,6 +74,7 @@ private:
long int currentLine; long int currentLine;
unsigned long int lastRecieved; unsigned long int lastRecieved;
int readyRecieve; int readyRecieve;
int userHistoryPos;
unsigned long int sdBytes; unsigned long int sdBytes;
private slots: private slots: