diff --git a/Proxmark3GUI.pro b/Proxmark3GUI.pro index 85feb73..08abf01 100644 --- a/Proxmark3GUI.pro +++ b/Proxmark3GUI.pro @@ -16,6 +16,7 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + common/myeventfilter.cpp \ main.cpp \ common/pm3process.cpp \ common/util.cpp \ @@ -27,6 +28,7 @@ SOURCES += \ ui/mf_attack_hardnesteddialog.cpp \ HEADERS += \ + common/myeventfilter.h \ common/pm3process.h \ common/util.h \ module/mifare.h \ diff --git a/common/myeventfilter.cpp b/common/myeventfilter.cpp new file mode 100644 index 0000000..b717ca3 --- /dev/null +++ b/common/myeventfilter.cpp @@ -0,0 +1,13 @@ +#include "myeventfilter.h" + +MyEventFilter::MyEventFilter(QEvent::Type filter) +{ + targetEventType = filter; +} + +bool MyEventFilter::eventFilter(QObject *obj, QEvent *event) +{ + if(event->type() == targetEventType) + emit eventHappened(obj, *event); + return QObject::eventFilter(obj, event); +} diff --git a/common/myeventfilter.h b/common/myeventfilter.h new file mode 100644 index 0000000..3ab624a --- /dev/null +++ b/common/myeventfilter.h @@ -0,0 +1,22 @@ +#ifndef MYEVENTFILTER_H +#define MYEVENTFILTER_H + +#include +#include + +class MyEventFilter : public QObject +{ + Q_OBJECT + +public: + explicit MyEventFilter(QEvent::Type filter); +protected: + bool eventFilter(QObject *obj, QEvent *event) override; + +signals: + void eventHappened(QObject* obj_addr, QEvent& event); +private: + QEvent::Type targetEventType; +}; + +#endif // MYEVENTFILTER_H diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 421a019..f3dbaac 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -29,6 +29,7 @@ MainWindow::MainWindow(QWidget *parent): util = new Util(this); mifare = new Mifare(ui, util, this); + keyEventFilter = new MyEventFilter(QEvent::KeyRelease); } MainWindow::~MainWindow() @@ -177,6 +178,36 @@ void MainWindow::sendMSG() // send command when pressing Enter on_Raw_sendCMDButton_clicked(); } +void MainWindow::on_Raw_CMDEdit_keyPressed(QObject* obj_addr, QEvent& event) +{ + if(obj_addr == ui->Raw_CMDEdit && event.type() == QEvent::KeyRelease) + { + QKeyEvent& keyEvent = static_cast(event); + if(keyEvent.key() == Qt::Key_Up) + { + if(stashedIndex > 0) + stashedIndex--; + else if(stashedIndex == -1) + stashedIndex = ui->Raw_CMDHistoryWidget->count() - 1; + } + else if(keyEvent.key() == Qt::Key_Down) + { + if(stashedIndex < ui->Raw_CMDHistoryWidget->count() - 1 && stashedIndex != -1) + stashedIndex++; + else if(stashedIndex == ui->Raw_CMDHistoryWidget->count() - 1) + stashedIndex = -1; + } + if(keyEvent.key() == Qt::Key_Up || keyEvent.key() == Qt::Key_Down) + { + ui->Raw_CMDEdit->blockSignals(true); + if(stashedIndex == -1) + ui->Raw_CMDEdit->setText(stashedCMDEditText); + else + ui->Raw_CMDEdit->setText(ui->Raw_CMDHistoryWidget->item(stashedIndex)->text()); + ui->Raw_CMDEdit->blockSignals(false); + } + } +} // ***************************************************** // ******************** mifare ******************** @@ -798,6 +829,8 @@ void MainWindow::MF_widgetReset() void MainWindow::uiInit() { connect(ui->Raw_CMDEdit, &QLineEdit::editingFinished, this, &MainWindow::sendMSG); + ui->Raw_CMDEdit->installEventFilter(keyEventFilter); + connect(keyEventFilter, &MyEventFilter::eventHappened, this, &MainWindow::on_Raw_CMDEdit_keyPressed); connectStatusBar = new QLabel(this); programStatusBar = new QLabel(this); @@ -1000,3 +1033,8 @@ void MainWindow::saveClientPath(const QString& path) settings->endGroup(); } // *********************************************** + +void MainWindow::on_Raw_CMDEdit_textChanged(const QString &arg1) +{ + stashedCMDEditText = arg1; +} diff --git a/ui/mainwindow.h b/ui/mainwindow.h index 2c7fcd5..91daafa 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -21,6 +21,7 @@ #include #include +#include "common/myeventfilter.h" #include "common/pm3process.h" #include "module/mifare.h" #include "common/util.h" @@ -49,6 +50,7 @@ public slots: void setStatusBar(QLabel* target, const QString& text); void onPM3StateChanged(bool st, const QString& info); void MF_onTypeChanged(int id, bool st); + void on_Raw_CMDEdit_keyPressed(QObject *obj_addr, QEvent &event); private slots: void on_PM3_connectButton_clicked(); @@ -150,6 +152,8 @@ private slots: void on_MF_selectTrailerBox_stateChanged(int arg1); void on_stopButton_clicked(); + void on_Raw_CMDEdit_textChanged(const QString &arg1); + private: Ui::MainWindow* ui; QButtonGroup* typeBtnGroup; @@ -160,6 +164,10 @@ private: QAction* myInfo; QAction* checkUpdate; QSettings* settings; + MyEventFilter* keyEventFilter; + + QString stashedCMDEditText; + int stashedIndex = -1; void uiInit(); diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index edd93f4..3279bd5 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -120,7 +120,7 @@ - 0 + 1 @@ -1198,6 +1198,9 @@ 0 + + Qt::NoFocus + Qt::ScrollBarAlwaysOn