Make UI customizable

pull/4/head
wh201906 5 years ago
parent 5cccb7b8bb
commit 3181848e75

@ -11,7 +11,8 @@ int main(int argc, char *argv[])
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w;
QSettings* settings = new QSettings("GUIsettings.ini", QSettings::IniFormat); 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") if(lang == "null")
{ {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@ -44,12 +45,13 @@ int main(int argc, char *argv[])
if(translator->load(lang.toString())) if(translator->load(lang.toString()))
{ {
a.installTranslator(translator); a.installTranslator(translator);
settings->setValue("lang", lang); settings->setValue("language", lang);
} }
else else
{ {
QMessageBox::information(&w, "Error", "Can't load " + lang.toString() + " as translation file."); QMessageBox::information(&w, "Error", "Can't load " + lang.toString() + " as translation file.");
} }
settings->endGroup();
delete settings; delete settings;
w.initUI(); w.initUI();
w.show(); w.show();

@ -15,6 +15,8 @@ MainWindow::MainWindow(QWidget *parent):
}); });
this->addAction(myInfo); this->addAction(myInfo);
settings = new QSettings("GUIsettings.ini", QSettings::IniFormat);
pm3Thread = new QThread(this); pm3Thread = new QThread(this);
pm3 = new PM3Process(pm3Thread); pm3 = new PM3Process(pm3Thread);
// pm3->moveToThread(pm3Thread); // pm3->moveToThread(pm3Thread);
@ -625,6 +627,28 @@ void MainWindow::uiInit()
ui->MF_keyWidget->installEventFilter(this); ui->MF_keyWidget->installEventFilter(this);
ui->MF_dataWidget->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<QGroupBox*>(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_Raw_CMDHistoryBox_stateChanged(Qt::Unchecked);
on_PM3_refreshPortButton_clicked(); on_PM3_refreshPortButton_clicked();
} }
@ -639,6 +663,14 @@ void MainWindow::signalInit()
connect(this, &MainWindow::killPM3, pm3, &PM3Process::kill); connect(this, &MainWindow::killPM3, pm3, &PM3Process::kill);
connect(util, &Util::write, pm3, &PM3Process::write); 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) void MainWindow::setStatusBar(QLabel* target, const QString & text)
@ -718,8 +750,22 @@ void MainWindow::setState(bool st)
ui->Raw_sendCMDButton->setEnabled(st); ui->Raw_sendCMDButton->setEnabled(st);
} }
// *********************************************** void MainWindow::on_GroupBox_clicked(bool checked)
{
QGroupBox* box = dynamic_cast<QGroupBox*>(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();
}
// ***********************************************

@ -16,6 +16,9 @@
#include <QMimeData> #include <QMimeData>
#include <QAction> #include <QAction>
#include <QDesktopServices> #include <QDesktopServices>
#include <QGroupBox>
#include <QSizePolicy>
#include <QSettings>
#include "common/pm3process.h" #include "common/pm3process.h"
#include "module/mifare.h" #include "module/mifare.h"
@ -132,6 +135,8 @@ private slots:
void on_MF_Sniff_saveButton_clicked(); void on_MF_Sniff_saveButton_clicked();
void on_GroupBox_clicked(bool checked);
private: private:
Ui::MainWindow* ui; Ui::MainWindow* ui;
QButtonGroup* typeBtnGroup; QButtonGroup* typeBtnGroup;
@ -139,6 +144,7 @@ private:
QLabel* programStatusBar; QLabel* programStatusBar;
QLabel* PM3VersionBar; QLabel* PM3VersionBar;
QAction* myInfo; QAction* myInfo;
QSettings* settings;
void uiInit(); void uiInit();

@ -317,7 +317,7 @@
<string>Card Type</string> <string>Card Type</string>
</property> </property>
<property name="checkable"> <property name="checkable">
<bool>false</bool> <bool>true</bool>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_10"> <layout class="QHBoxLayout" name="horizontalLayout_10">
<property name="topMargin"> <property name="topMargin">
@ -365,6 +365,9 @@
<property name="title"> <property name="title">
<string>File</string> <string>File</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_8"> <layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="topMargin"> <property name="topMargin">
<number>5</number> <number>5</number>
@ -436,6 +439,9 @@
<property name="title"> <property name="title">
<string>Attack</string> <string>Attack</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="topMargin"> <property name="topMargin">
<number>5</number> <number>5</number>
@ -519,6 +525,9 @@
<property name="title"> <property name="title">
<string>Read/Write</string> <string>Read/Write</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_12"> <layout class="QHBoxLayout" name="horizontalLayout_12">
@ -635,6 +644,9 @@
<property name="title"> <property name="title">
<string>Normal(Require Password)</string> <string>Normal(Require Password)</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<property name="topMargin"> <property name="topMargin">
<number>5</number> <number>5</number>
@ -713,6 +725,9 @@
<property name="title"> <property name="title">
<string>Chinese Magic Card(Without Password)</string> <string>Chinese Magic Card(Without Password)</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="topMargin"> <property name="topMargin">
<number>5</number> <number>5</number>
@ -818,6 +833,9 @@
<property name="title"> <property name="title">
<string>Simulate</string> <string>Simulate</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_11"> <layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="topMargin"> <property name="topMargin">
<number>5</number> <number>5</number>
@ -896,6 +914,9 @@
<property name="title"> <property name="title">
<string>Sniff</string> <string>Sniff</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="topMargin"> <property name="topMargin">
<number>5</number> <number>5</number>

Loading…
Cancel
Save