UI: More configurable items

Code part
Fonts, opacity and theme are configurable now
Add dark theme for night owls
master
wh201906 2 years ago
parent 29bac475b5
commit 5b84e58ecb
No known key found for this signature in database

@ -31,6 +31,9 @@ int main(int argc, char *argv[])
QString languageFile = settings->value("extPath").toString(); QString languageFile = settings->value("extPath").toString();
QString languageName = settings->value("name").toString(); QString languageName = settings->value("name").toString();
settings->endGroup(); settings->endGroup();
settings->beginGroup("UI");
QString theme = settings->value("Theme_Name").toString();
settings->endGroup();
if(languageName == "") if(languageName == "")
{ {
if(Util::chooseLanguage(settings, &w)) if(Util::chooseLanguage(settings, &w))
@ -55,7 +58,35 @@ int main(int argc, char *argv[])
a.installTranslator(translator); a.installTranslator(translator);
else else
QMessageBox::information(&w, "Error", "Can't load " + languageFile + " as translation file."); QMessageBox::information(&w, "Error", "Can't load " + languageFile + " as translation file.");
QFile* themeFile = new QFile();
QTextStream* themeStream = new QTextStream();
QString qssString = a.styleSheet(); // default behavior
if(theme == "(none)")
;
else if(theme == "qdss_dark")
{
themeFile->setFileName(":/qdarkstyle/dark/darkstyle.qss");
themeFile->open(QFile::ReadOnly | QFile::Text);
themeStream->setDevice(themeFile);
qssString = themeStream->readAll();
}
else if(theme == "qdss_light")
{
themeFile->setFileName(":/qdarkstyle/light/lightstyle.qss");
themeFile->open(QFile::ReadOnly | QFile::Text);
themeStream->setDevice(themeFile);
qssString = themeStream->readAll();
}
a.setStyleSheet(qssString);
delete themeFile;
delete themeStream;
themeFile = nullptr;
themeStream = nullptr;
delete settings; delete settings;
settings = nullptr;
w.initUI(); w.initUI();
w.show(); w.show();
return a.exec(); return a.exec();

@ -528,18 +528,6 @@ void MainWindow::on_MF_trailerDecoderButton_clicked()
decDialog->show(); decDialog->show();
} }
void MainWindow::on_MF_fontButton_clicked()
{
bool isOK = false;
QFont font = QFontDialog::getFont(&isOK, ui->MF_keyWidget->font(), this, tr("Plz select the font of data widget and key widget"));
if(isOK)
{
ui->MF_keyWidget->setFont(font);
ui->MF_dataWidget->setFont(font);
}
}
void MainWindow::on_MF_dataWidget_itemChanged(QTableWidgetItem *item) void MainWindow::on_MF_dataWidget_itemChanged(QTableWidgetItem *item)
{ {
ui->MF_dataWidget->blockSignals(true); ui->MF_dataWidget->blockSignals(true);
@ -1076,6 +1064,10 @@ void MainWindow::uiInit()
ui->MF_keyWidget->installEventFilter(this); ui->MF_keyWidget->installEventFilter(this);
ui->MF_dataWidget->installEventFilter(this); ui->MF_dataWidget->installEventFilter(this);
ui->Set_UI_Theme_nameBox->addItem(tr("(None)"), "(none)");
ui->Set_UI_Theme_nameBox->addItem(tr("Dark"), "qdss_dark");
ui->Set_UI_Theme_nameBox->addItem(tr("Light"), "qdss_light");
settings->beginGroup("UI_grpbox_preference"); settings->beginGroup("UI_grpbox_preference");
QStringList boxNames = settings->allKeys(); QStringList boxNames = settings->allKeys();
@ -1147,6 +1139,49 @@ void MainWindow::uiInit()
ui->Set_Client_configFileBox->blockSignals(false); ui->Set_Client_configFileBox->blockSignals(false);
on_Set_Client_configFileBox_currentIndexChanged(ui->Set_Client_configFileBox->currentIndex()); on_Set_Client_configFileBox_currentIndexChanged(ui->Set_Client_configFileBox->currentIndex());
settings->beginGroup("UI");
ui->Set_UI_Opacity_Box->setValue(settings->value("Opacity", 100).toInt());
int themeId = ui->Set_UI_Theme_nameBox->findData(settings->value("Theme_Name", "(none)").toString());
ui->Set_UI_Theme_nameBox->setCurrentIndex((themeId == -1) ? 0 : themeId);
// QApplication::font() might return wrong result
// If fonts are not specified in config file, don't touch them.
QString tmpFontName;
int tmpFontSize;
bool fontValid = false, dataFontValid = false, CMDFontValid = false;
tmpFontName = settings->value("Font_Name", "").toString();
tmpFontSize = settings->value("Font_Size", -1).toInt();
if(!tmpFontName.isEmpty() && tmpFontSize != -1 && tmpFontName == QFont(tmpFontName).family())
{
ui->Set_UI_Font_nameBox->setCurrentFont(QFont(tmpFontName));
ui->Set_UI_Font_sizeBox->setValue(tmpFontSize);
fontValid = true;
}
// The default values should be the same as MF_dataWidget's and MF_keyWidget's.
tmpFontName = settings->value("DataFont_Name", "Consolas").toString();
tmpFontSize = settings->value("DataFont_Size", 12).toInt();
if(!tmpFontName.isEmpty() && tmpFontSize != -1 && tmpFontName == QFont(tmpFontName).family())
{
ui->Set_UI_DataFont_nameBox->setCurrentFont(QFont(tmpFontName));
ui->Set_UI_DataFont_sizeBox->setValue(tmpFontSize);
dataFontValid = true;
}
tmpFontName = settings->value("CMDFont_Name", "").toString();
tmpFontSize = settings->value("CMDFont_Size", -1).toInt();
if(!tmpFontName.isEmpty() && tmpFontSize != -1 && tmpFontName == QFont(tmpFontName).family())
{
ui->Set_UI_CMDFont_nameBox->setCurrentFont(QFont(tmpFontName));
ui->Set_UI_CMDFont_sizeBox->setValue(tmpFontSize);
CMDFontValid = true;
}
settings->endGroup();
if(fontValid)
on_Set_UI_Font_setButton_clicked();
if(dataFontValid)
on_Set_UI_DataFont_setButton_clicked();
if(CMDFontValid)
on_Set_UI_CMDFont_setButton_clicked();
ui->MF_RW_keyTypeBox->addItem("A", Mifare::KEY_A); ui->MF_RW_keyTypeBox->addItem("A", Mifare::KEY_A);
ui->MF_RW_keyTypeBox->addItem("B", Mifare::KEY_B); ui->MF_RW_keyTypeBox->addItem("B", Mifare::KEY_B);
@ -1184,6 +1219,8 @@ void MainWindow::signalInit()
connect(ui->MF_sniffGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked); connect(ui->MF_sniffGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked);
connect(stopButton, &QPushButton::clicked, this, &MainWindow::on_stopButton_clicked); connect(stopButton, &QPushButton::clicked, this, &MainWindow::on_stopButton_clicked);
connect(ui->Set_UI_Opacity_slider, &QSlider::valueChanged, ui->Set_UI_Opacity_Box, &QSpinBox::setValue);
} }
void MainWindow::setStatusBar(QLabel * target, const QString& text) void MainWindow::setStatusBar(QLabel * target, const QString& text)
@ -1496,3 +1533,63 @@ void MainWindow::on_Set_Client_configFileBox_currentIndexChanged(int index)
settings->endGroup(); settings->endGroup();
} }
void MainWindow::on_Set_UI_Opacity_Box_valueChanged(int arg1)
{
ui->Set_UI_Opacity_slider->blockSignals(true);
ui->Set_UI_Opacity_slider->setValue(arg1);
setWindowOpacity(arg1 / 100.0);
settings->beginGroup("UI");
settings->setValue("Opacity", ui->Set_UI_Opacity_Box->value());
settings->endGroup();
ui->Set_UI_Opacity_slider->blockSignals(false);
}
void MainWindow::on_Set_UI_Theme_setButton_clicked()
{
settings->beginGroup("UI");
settings->setValue("Theme_Name", ui->Set_UI_Theme_nameBox->currentData().toString());
settings->endGroup();
}
void MainWindow::on_Set_UI_Font_setButton_clicked()
{
QFont font = ui->Set_UI_Font_nameBox->currentFont();
font.setPointSize(ui->Set_UI_Font_sizeBox->value());
QApplication::setFont(font, "QWidget");
settings->beginGroup("UI");
settings->setValue("Font_Name", ui->Set_UI_Font_nameBox->currentFont().family());
settings->setValue("Font_Size", ui->Set_UI_Font_sizeBox->value());
settings->endGroup();
}
void MainWindow::on_Set_UI_DataFont_setButton_clicked()
{
QFont font = ui->Set_UI_DataFont_nameBox->currentFont();
font.setPointSize(ui->Set_UI_DataFont_sizeBox->value());
ui->MF_dataWidget->setFont(font);
ui->MF_keyWidget->setFont(font);
settings->beginGroup("UI");
settings->setValue("DataFont_Name", ui->Set_UI_DataFont_nameBox->currentFont().family());
settings->setValue("DataFont_Size", ui->Set_UI_DataFont_sizeBox->value());
settings->endGroup();
}
void MainWindow::on_Set_UI_CMDFont_setButton_clicked()
{
QFont font = ui->Set_UI_CMDFont_nameBox->currentFont();
font.setPointSize(ui->Set_UI_CMDFont_sizeBox->value());
ui->Raw_outputEdit->setFont(font);
settings->beginGroup("UI");
settings->setValue("CMDFont_Name", ui->Set_UI_CMDFont_nameBox->currentFont().family());
settings->setValue("CMDFont_Size", ui->Set_UI_CMDFont_sizeBox->value());
settings->endGroup();
}

@ -128,8 +128,6 @@ private slots:
void on_MF_keyWidget_itemChanged(QTableWidgetItem *item); void on_MF_keyWidget_itemChanged(QTableWidgetItem *item);
void on_MF_fontButton_clicked();
void on_MF_UID_wipeButton_clicked(); void on_MF_UID_wipeButton_clicked();
void on_MF_UID_aboutUIDButton_clicked(); void on_MF_UID_aboutUIDButton_clicked();
@ -212,6 +210,16 @@ private slots:
void on_Set_Client_configFileBox_currentIndexChanged(int index); void on_Set_Client_configFileBox_currentIndexChanged(int index);
void on_Set_UI_Opacity_Box_valueChanged(int arg1);
void on_Set_UI_Theme_setButton_clicked();
void on_Set_UI_Font_setButton_clicked();
void on_Set_UI_DataFont_setButton_clicked();
void on_Set_UI_CMDFont_setButton_clicked();
private: private:
Ui::MainWindow* ui; Ui::MainWindow* ui;
QButtonGroup* MFCardTypeBtnGroup; QButtonGroup* MFCardTypeBtnGroup;

@ -315,19 +315,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="MF_fontButton">
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Set Fonts</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer_2"> <spacer name="verticalSpacer_2">
<property name="orientation"> <property name="orientation">

Loading…
Cancel
Save