From 3181848e75cd8183aaae42fe7d5f09eef43f07c2 Mon Sep 17 00:00:00 2001 From: wh201906 Date: Sat, 13 Jun 2020 01:27:59 +0800 Subject: [PATCH] Make UI customizable --- main.cpp | 6 ++++-- ui/mainwindow.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++--- ui/mainwindow.h | 6 ++++++ ui/mainwindow.ui | 23 ++++++++++++++++++++- 4 files changed, 81 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index 5053128..999eb0b 100644 --- a/main.cpp +++ b/main.cpp @@ -11,7 +11,8 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); MainWindow w; QSettings* settings = new QSettings("GUIsettings.ini", QSettings::IniFormat); - QVariant lang = settings->value("lang", "null"); + settings->beginGroup("lang"); + QVariant lang = settings->value("language", "null"); if(lang == "null") { #ifdef Q_OS_WIN @@ -44,12 +45,13 @@ int main(int argc, char *argv[]) if(translator->load(lang.toString())) { a.installTranslator(translator); - settings->setValue("lang", lang); + settings->setValue("language", lang); } else { QMessageBox::information(&w, "Error", "Can't load " + lang.toString() + " as translation file."); } + settings->endGroup(); delete settings; w.initUI(); w.show(); diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 7259805..d35d0f8 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -15,6 +15,8 @@ MainWindow::MainWindow(QWidget *parent): }); this->addAction(myInfo); + settings = new QSettings("GUIsettings.ini", QSettings::IniFormat); + pm3Thread = new QThread(this); pm3 = new PM3Process(pm3Thread); // pm3->moveToThread(pm3Thread); @@ -625,6 +627,28 @@ void MainWindow::uiInit() ui->MF_keyWidget->installEventFilter(this); ui->MF_dataWidget->installEventFilter(this); + settings->beginGroup("UI_grpbox_preference"); + + QStringList boxNames = settings->allKeys(); + QGroupBox* boxptr; + foreach(QString name, boxNames) + { + boxptr = this->findChild(name); + if(boxptr == nullptr) + continue; + if(settings->value(name, true).toBool()) + { + boxptr->setMaximumHeight(16777215); + boxptr->setChecked(true); + } + else + { + boxptr->setMaximumHeight(20); + boxptr->setChecked(false); + } + } + settings->endGroup(); + on_Raw_CMDHistoryBox_stateChanged(Qt::Unchecked); on_PM3_refreshPortButton_clicked(); } @@ -639,6 +663,14 @@ void MainWindow::signalInit() connect(this, &MainWindow::killPM3, pm3, &PM3Process::kill); connect(util, &Util::write, pm3, &PM3Process::write); + + connect(ui->MF_typeGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked); + connect(ui->MF_fileGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked); + connect(ui->MF_RWGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked); + connect(ui->MF_normalGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked); + connect(ui->MF_UIDGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked); + connect(ui->MF_simGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked); + connect(ui->MF_sniffGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked); } void MainWindow::setStatusBar(QLabel* target, const QString & text) @@ -718,8 +750,22 @@ void MainWindow::setState(bool st) ui->Raw_sendCMDButton->setEnabled(st); } -// *********************************************** - - +void MainWindow::on_GroupBox_clicked(bool checked) +{ + QGroupBox* box = dynamic_cast(sender()); + settings->beginGroup("UI_grpbox_preference"); + if(checked) + { + box->setMaximumHeight(16777215); + settings->setValue(box->objectName(), true); + } + else + { + box->setMaximumHeight(20); + settings->setValue(box->objectName(), false); + } + settings->endGroup(); +} +// *********************************************** diff --git a/ui/mainwindow.h b/ui/mainwindow.h index 087fc5d..17bf42c 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -16,6 +16,9 @@ #include #include #include +#include +#include +#include #include "common/pm3process.h" #include "module/mifare.h" @@ -132,6 +135,8 @@ private slots: void on_MF_Sniff_saveButton_clicked(); + void on_GroupBox_clicked(bool checked); + private: Ui::MainWindow* ui; QButtonGroup* typeBtnGroup; @@ -139,6 +144,7 @@ private: QLabel* programStatusBar; QLabel* PM3VersionBar; QAction* myInfo; + QSettings* settings; void uiInit(); diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 8e90e42..f3b3ef7 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -317,7 +317,7 @@ Card Type - false + true @@ -365,6 +365,9 @@ File + + true + 5 @@ -436,6 +439,9 @@ Attack + + true + 5 @@ -519,6 +525,9 @@ Read/Write + + true + @@ -635,6 +644,9 @@ Normal(Require Password) + + true + 5 @@ -713,6 +725,9 @@ Chinese Magic Card(Without Password) + + true + 5 @@ -818,6 +833,9 @@ Simulate + + true + 5 @@ -896,6 +914,9 @@ Sniff + + true + 5