From 799e00d66e1b982bd11341f3a043cb75ee2f01a2 Mon Sep 17 00:00:00 2001 From: wh201906 Date: Mon, 22 Feb 2021 15:57:32 +0800 Subject: [PATCH] Replace QTabWidget with QDockWidget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dock it(√) doki(?) --- common/util.cpp | 25 +++++++++++++++++++++++++ common/util.h | 11 +++++++++-- module/lf.cpp | 8 ++++---- module/mifare.cpp | 26 +++++++++++++------------- ui/mainwindow.cpp | 29 +++++++++++++++++++++++++++++ ui/mainwindow.h | 4 ++++ ui/mainwindow.ui | 2 +- 7 files changed, 85 insertions(+), 20 deletions(-) diff --git a/common/util.cpp b/common/util.cpp index 9e360b4..573c5f9 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -2,6 +2,11 @@ Util::ClientType Util::clientType = CLIENTTYPE_OFFICIAL; +int Util::rawTabIndex = 0; +QDockWidget* Util::rawDockPtr = nullptr; +Ui::MainWindow* Util::ui = nullptr; + + Util::Util(QObject *parent) : QObject(parent) { isRequiringOutput = false; @@ -10,6 +15,7 @@ Util::Util(QObject *parent) : QObject(parent) qRegisterMetaType("Util::ClientType"); } + void Util::processOutput(const QString& output) { // qDebug() << "Util::processOutput:" << output; @@ -120,3 +126,22 @@ bool Util::chooseLanguage(QSettings* guiSettings, QMainWindow* window) } return isOk; } + +void Util::gotoRawTab() +{ + Util::ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::rawDockPtr->setVisible(true); + Util::rawDockPtr->raise(); +} + +void Util::setUI(Ui::MainWindow *ui) +{ + Util::ui = ui; +} + + +void Util::setRawTab(QDockWidget *dockPtr, int tabIndex) +{ + Util::rawDockPtr = dockPtr; + Util::rawTabIndex = tabIndex; +} diff --git a/common/util.h b/common/util.h index 96bd114..211e5e0 100644 --- a/common/util.h +++ b/common/util.h @@ -13,6 +13,9 @@ #include #include #include +#include + +#include "ui_mainwindow.h" class Util : public QObject { @@ -53,19 +56,23 @@ public: QString execCMDWithOutput(const QString& cmd, ReturnTrigger trigger = 10000); void delay(unsigned int msec); static ClientType getClientType(); - static const int rawTabIndex = 2; + static int rawTabIndex; + static QDockWidget* rawDockPtr; static bool chooseLanguage(QSettings *guiSettings, QMainWindow *window); public slots: void processOutput(const QString& output); static void setClientType(Util::ClientType clientType); void setRunningState(bool st); - + static void gotoRawTab(); + static void setUI(Ui::MainWindow *ui); + static void setRawTab(QDockWidget* dockPtr, int tabIndex); private: bool isRequiringOutput; bool isRunning; QString* requiredOutput; QTime timeStamp; static ClientType clientType; + static Ui::MainWindow *ui; signals: void refreshOutput(const QString& output); void write(QString data); // connected to PM3Process::write(QString data); diff --git a/module/lf.cpp b/module/lf.cpp index 2907293..0eb9316 100644 --- a/module/lf.cpp +++ b/module/lf.cpp @@ -14,7 +14,7 @@ void LF::read() util->execCMD("lf read"); else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) util->execCMD("lf read -v"); - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); util->execCMD("data plot"); } @@ -24,7 +24,7 @@ void LF::sniff() util->execCMD("lf snoop"); else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) util->execCMD("lf sniff -v"); - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); util->execCMD("data plot"); } @@ -34,7 +34,7 @@ void LF::search() util->execCMD("lf search u"); else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) util->execCMD("lf search -u"); - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } void LF::tune() @@ -43,5 +43,5 @@ void LF::tune() util->execCMD("hw tune l"); else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) util->execCMD("lf tune"); // TODO: if freq is set, append it as a parameter - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } diff --git a/module/mifare.cpp b/module/mifare.cpp index 2ca057e..2d46a4c 100644 --- a/module/mifare.cpp +++ b/module/mifare.cpp @@ -106,7 +106,7 @@ QString Mifare::info(bool isRequiringOutput) else { util->execCMD("hf 14a info"); - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } } return ""; @@ -255,7 +255,7 @@ void Mifare::hardnested() MF_Attack_hardnestedDialog dialog(cardType.block_size); connect(&dialog, &MF_Attack_hardnestedDialog::sendCMD, util, &Util::execCMD); if(dialog.exec() == QDialog::Accepted) - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } void Mifare::darkside() @@ -265,7 +265,7 @@ void Mifare::darkside() else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) util->execCMD("hf mf darkside"); - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } void Mifare::sniff() @@ -275,7 +275,7 @@ void Mifare::sniff() else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) util->execCMD("hf sniff"); - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } void Mifare::sniff14a() @@ -285,7 +285,7 @@ void Mifare::sniff14a() else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) util->execCMD("hf 14a sniff"); - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } void Mifare::list() @@ -295,7 +295,7 @@ void Mifare::list() else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) util->execCMD("trace list -t mf"); - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, TargetType targetType, int waitTime) @@ -742,14 +742,14 @@ void Mifare::dump() { if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL || Util::getClientType() == Util::CLIENTTYPE_ICEMAN) util->execCMD("hf mf dump"); - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } void Mifare::restore() { if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL || Util::getClientType() == Util::CLIENTTYPE_ICEMAN) util->execCMD("hf mf restore"); - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } void Mifare::wipeC() @@ -765,7 +765,7 @@ void Mifare::wipeC() { util->execCMD("hf mf cwipe"); } - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } void Mifare::setParameterC() @@ -786,7 +786,7 @@ void Mifare::setParameterC() MF_UID_parameterDialog dialog(lis[1].toUpper(), lis[2].toUpper(), lis[3].toUpper()); connect(&dialog, &MF_UID_parameterDialog::sendCMD, util, &Util::execCMD); if(dialog.exec() == QDialog::Accepted) - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } } @@ -823,7 +823,7 @@ void Mifare::simulate() MF_Sim_simDialog dialog(cardType.type, cardType.typeText); connect(&dialog, &MF_Sim_simDialog::sendCMD, util, &Util::execCMD); if(dialog.exec() == QDialog::Accepted) - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } void Mifare::loadSniff(const QString& file) @@ -836,7 +836,7 @@ void Mifare::loadSniff(const QString& file) util->execCMD("trace list -t mf"); } - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } void Mifare::saveSniff(const QString& file) @@ -846,7 +846,7 @@ void Mifare::saveSniff(const QString& file) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) util->execCMD("trace save -f " + file); - ui->funcTab->setCurrentIndex(Util::rawTabIndex); + Util::gotoRawTab(); } void Mifare::data_syncWithDataWidget(bool syncAll, int block) diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 9091e94..62f27f5 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -31,6 +31,7 @@ MainWindow::MainWindow(QWidget *parent): clientWorkingDir = new QDir; util = new Util(this); + Util::setUI(ui); mifare = new Mifare(ui, util, this); lf = new LF(ui, util, this); @@ -64,6 +65,7 @@ void MainWindow::initUI() // will be called by main.app uiInit(); signalInit(); setState(false); + dockInit(); } // ******************** basic functions ******************** @@ -1288,3 +1290,30 @@ void MainWindow::on_LF_Op_sniffButton_clicked() lf->sniff(); setState(true); } + +void MainWindow::dockInit() +{ + setDockNestingEnabled(true); + QDockWidget* dock; + QWidget* widget; + int count = ui->funcTab->count(); + qDebug() << "dock count" << count; + for(int i = 0; i < count; i++) + { + dock = new QDockWidget(ui->funcTab->tabText(0), this); + qDebug() << "dock name" << ui->funcTab->tabText(0); + dock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);// movable is necessary, otherwise the dock cannot be dragged + dock->setAllowedAreas(Qt::BottomDockWidgetArea); + widget = ui->funcTab->widget(0); + dock->setWidget(widget); + if(widget->objectName() == "rawTab") + Util::setRawTab(dock, i); + addDockWidget(Qt::BottomDockWidgetArea, dock); + if(!dockList.isEmpty()) + tabifyDockWidget(dockList[0], dock); + dockList.append(dock); + } + ui->funcTab->setVisible(false); + dockList[0]->setVisible(true); + dockList[0]->raise(); +} diff --git a/ui/mainwindow.h b/ui/mainwindow.h index 550f30e..6fc8078 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "common/myeventfilter.h" #include "common/pm3process.h" @@ -228,6 +229,8 @@ private: LF* lf; Util* util; + QList dockList; + MF_trailerDecoderDialog* decDialog; void signalInit(); @@ -236,6 +239,7 @@ private: void setState(bool st); void saveClientPath(const QString& path); void onLFfreqConfChanged(int value, bool isCustomized); + void dockInit(); signals: void connectPM3(const QString& path, const QStringList args); void reconnectPM3(); diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 773fecc..0be8763 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -130,7 +130,7 @@ - 1 + 3