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->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<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;
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: