Replace QTabWidget with QDockWidget

dock it(√)
doki(?)
pull/33/head
wh201906 4 years ago
parent ae9e4d1a4f
commit 799e00d66e

@ -2,6 +2,11 @@
Util::ClientType Util::clientType = CLIENTTYPE_OFFICIAL; 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) Util::Util(QObject *parent) : QObject(parent)
{ {
isRequiringOutput = false; isRequiringOutput = false;
@ -10,6 +15,7 @@ Util::Util(QObject *parent) : QObject(parent)
qRegisterMetaType<Util::ClientType>("Util::ClientType"); qRegisterMetaType<Util::ClientType>("Util::ClientType");
} }
void Util::processOutput(const QString& output) void Util::processOutput(const QString& output)
{ {
// qDebug() << "Util::processOutput:" << output; // qDebug() << "Util::processOutput:" << output;
@ -120,3 +126,22 @@ bool Util::chooseLanguage(QSettings* guiSettings, QMainWindow* window)
} }
return isOk; 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;
}

@ -13,6 +13,9 @@
#include <QSettings> #include <QSettings>
#include <QMainWindow> #include <QMainWindow>
#include <QInputDialog> #include <QInputDialog>
#include <QDockWidget>
#include "ui_mainwindow.h"
class Util : public QObject class Util : public QObject
{ {
@ -53,19 +56,23 @@ public:
QString execCMDWithOutput(const QString& cmd, ReturnTrigger trigger = 10000); QString execCMDWithOutput(const QString& cmd, ReturnTrigger trigger = 10000);
void delay(unsigned int msec); void delay(unsigned int msec);
static ClientType getClientType(); static ClientType getClientType();
static const int rawTabIndex = 2; static int rawTabIndex;
static QDockWidget* rawDockPtr;
static bool chooseLanguage(QSettings *guiSettings, QMainWindow *window); static bool chooseLanguage(QSettings *guiSettings, QMainWindow *window);
public slots: public slots:
void processOutput(const QString& output); void processOutput(const QString& output);
static void setClientType(Util::ClientType clientType); static void setClientType(Util::ClientType clientType);
void setRunningState(bool st); void setRunningState(bool st);
static void gotoRawTab();
static void setUI(Ui::MainWindow *ui);
static void setRawTab(QDockWidget* dockPtr, int tabIndex);
private: private:
bool isRequiringOutput; bool isRequiringOutput;
bool isRunning; bool isRunning;
QString* requiredOutput; QString* requiredOutput;
QTime timeStamp; QTime timeStamp;
static ClientType clientType; static ClientType clientType;
static Ui::MainWindow *ui;
signals: signals:
void refreshOutput(const QString& output); void refreshOutput(const QString& output);
void write(QString data); // connected to PM3Process::write(QString data); void write(QString data); // connected to PM3Process::write(QString data);

@ -14,7 +14,7 @@ void LF::read()
util->execCMD("lf read"); util->execCMD("lf read");
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("lf read -v"); util->execCMD("lf read -v");
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
util->execCMD("data plot"); util->execCMD("data plot");
} }
@ -24,7 +24,7 @@ void LF::sniff()
util->execCMD("lf snoop"); util->execCMD("lf snoop");
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("lf sniff -v"); util->execCMD("lf sniff -v");
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
util->execCMD("data plot"); util->execCMD("data plot");
} }
@ -34,7 +34,7 @@ void LF::search()
util->execCMD("lf search u"); util->execCMD("lf search u");
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("lf search -u"); util->execCMD("lf search -u");
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }
void LF::tune() void LF::tune()
@ -43,5 +43,5 @@ void LF::tune()
util->execCMD("hw tune l"); util->execCMD("hw tune l");
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("lf tune"); // TODO: if freq is set, append it as a parameter util->execCMD("lf tune"); // TODO: if freq is set, append it as a parameter
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }

@ -106,7 +106,7 @@ QString Mifare::info(bool isRequiringOutput)
else else
{ {
util->execCMD("hf 14a info"); util->execCMD("hf 14a info");
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }
} }
return ""; return "";
@ -255,7 +255,7 @@ void Mifare::hardnested()
MF_Attack_hardnestedDialog dialog(cardType.block_size); MF_Attack_hardnestedDialog dialog(cardType.block_size);
connect(&dialog, &MF_Attack_hardnestedDialog::sendCMD, util, &Util::execCMD); connect(&dialog, &MF_Attack_hardnestedDialog::sendCMD, util, &Util::execCMD);
if(dialog.exec() == QDialog::Accepted) if(dialog.exec() == QDialog::Accepted)
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }
void Mifare::darkside() void Mifare::darkside()
@ -265,7 +265,7 @@ void Mifare::darkside()
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("hf mf darkside"); util->execCMD("hf mf darkside");
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }
void Mifare::sniff() void Mifare::sniff()
@ -275,7 +275,7 @@ void Mifare::sniff()
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("hf sniff"); util->execCMD("hf sniff");
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }
void Mifare::sniff14a() void Mifare::sniff14a()
@ -285,7 +285,7 @@ void Mifare::sniff14a()
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("hf 14a sniff"); util->execCMD("hf 14a sniff");
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }
void Mifare::list() void Mifare::list()
@ -295,7 +295,7 @@ void Mifare::list()
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("trace list -t mf"); 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) 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) if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL || Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("hf mf dump"); util->execCMD("hf mf dump");
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }
void Mifare::restore() void Mifare::restore()
{ {
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL || Util::getClientType() == Util::CLIENTTYPE_ICEMAN) if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL || Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("hf mf restore"); util->execCMD("hf mf restore");
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }
void Mifare::wipeC() void Mifare::wipeC()
@ -765,7 +765,7 @@ void Mifare::wipeC()
{ {
util->execCMD("hf mf cwipe"); util->execCMD("hf mf cwipe");
} }
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }
void Mifare::setParameterC() void Mifare::setParameterC()
@ -786,7 +786,7 @@ void Mifare::setParameterC()
MF_UID_parameterDialog dialog(lis[1].toUpper(), lis[2].toUpper(), lis[3].toUpper()); MF_UID_parameterDialog dialog(lis[1].toUpper(), lis[2].toUpper(), lis[3].toUpper());
connect(&dialog, &MF_UID_parameterDialog::sendCMD, util, &Util::execCMD); connect(&dialog, &MF_UID_parameterDialog::sendCMD, util, &Util::execCMD);
if(dialog.exec() == QDialog::Accepted) 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); MF_Sim_simDialog dialog(cardType.type, cardType.typeText);
connect(&dialog, &MF_Sim_simDialog::sendCMD, util, &Util::execCMD); connect(&dialog, &MF_Sim_simDialog::sendCMD, util, &Util::execCMD);
if(dialog.exec() == QDialog::Accepted) if(dialog.exec() == QDialog::Accepted)
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }
void Mifare::loadSniff(const QString& file) void Mifare::loadSniff(const QString& file)
@ -836,7 +836,7 @@ void Mifare::loadSniff(const QString& file)
util->execCMD("trace list -t mf"); util->execCMD("trace list -t mf");
} }
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }
void Mifare::saveSniff(const QString& file) void Mifare::saveSniff(const QString& file)
@ -846,7 +846,7 @@ void Mifare::saveSniff(const QString& file)
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("trace save -f " + file); util->execCMD("trace save -f " + file);
ui->funcTab->setCurrentIndex(Util::rawTabIndex); Util::gotoRawTab();
} }
void Mifare::data_syncWithDataWidget(bool syncAll, int block) void Mifare::data_syncWithDataWidget(bool syncAll, int block)

@ -31,6 +31,7 @@ MainWindow::MainWindow(QWidget *parent):
clientWorkingDir = new QDir; clientWorkingDir = new QDir;
util = new Util(this); util = new Util(this);
Util::setUI(ui);
mifare = new Mifare(ui, util, this); mifare = new Mifare(ui, util, this);
lf = new LF(ui, util, this); lf = new LF(ui, util, this);
@ -64,6 +65,7 @@ void MainWindow::initUI() // will be called by main.app
uiInit(); uiInit();
signalInit(); signalInit();
setState(false); setState(false);
dockInit();
} }
// ******************** basic functions ******************** // ******************** basic functions ********************
@ -1288,3 +1290,30 @@ void MainWindow::on_LF_Op_sniffButton_clicked()
lf->sniff(); lf->sniff();
setState(true); 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();
}

@ -24,6 +24,7 @@
#include <QScrollBar> #include <QScrollBar>
#include <QTimer> #include <QTimer>
#include <QDateTime> #include <QDateTime>
#include <QDockWidget>
#include "common/myeventfilter.h" #include "common/myeventfilter.h"
#include "common/pm3process.h" #include "common/pm3process.h"
@ -228,6 +229,8 @@ private:
LF* lf; LF* lf;
Util* util; Util* util;
QList<QDockWidget*> dockList;
MF_trailerDecoderDialog* decDialog; MF_trailerDecoderDialog* decDialog;
void signalInit(); void signalInit();
@ -236,6 +239,7 @@ private:
void setState(bool st); void setState(bool st);
void saveClientPath(const QString& path); void saveClientPath(const QString& path);
void onLFfreqConfChanged(int value, bool isCustomized); void onLFfreqConfChanged(int value, bool isCustomized);
void dockInit();
signals: signals:
void connectPM3(const QString& path, const QStringList args); void connectPM3(const QString& path, const QStringList args);
void reconnectPM3(); void reconnectPM3();

@ -130,7 +130,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>3</number>
</property> </property>
<widget class="QWidget" name="mifareTab"> <widget class="QWidget" name="mifareTab">
<attribute name="title"> <attribute name="title">

Loading…
Cancel
Save