mirror of
https://github.com/wh201906/Proxmark3GUI.git
synced 2024-11-10 08:55:43 +08:00
Support choose history command by Key_Up and Key_Down
This commit is contained in:
parent
f2d00ee088
commit
2f38d3c8c5
6 changed files with 87 additions and 1 deletions
|
@ -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 \
|
||||
|
|
13
common/myeventfilter.cpp
Normal file
13
common/myeventfilter.cpp
Normal file
|
@ -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);
|
||||
}
|
22
common/myeventfilter.h
Normal file
22
common/myeventfilter.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef MYEVENTFILTER_H
|
||||
#define MYEVENTFILTER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QKeyEvent>
|
||||
|
||||
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
|
|
@ -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<QKeyEvent&>(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;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <QSettings>
|
||||
#include <QPushButton>
|
||||
|
||||
#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();
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="mifareTab">
|
||||
<attribute name="title">
|
||||
|
@ -1198,6 +1198,9 @@
|
|||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
|
|
Loading…
Reference in a new issue