From c42b566a4c42697caffd57bd6d847648c94c71af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Thu, 14 Dec 2017 16:14:33 +0100 Subject: [PATCH] Move general options from AsmOptionsWidget to new GeneralOptionsWidget --- src/MainWindow.ui | 8 +- src/cutter.pro | 9 +- src/dialogs/preferences/AsmOptionsWidget.cpp | 37 ++++--- src/dialogs/preferences/AsmOptionsWidget.h | 8 +- src/dialogs/preferences/AsmOptionsWidget.ui | 46 ++++----- .../preferences/GeneralOptionsWidget.cpp | 53 ++++++++++ .../preferences/GeneralOptionsWidget.h | 38 ++++++++ .../preferences/GeneralOptionsWidget.ui | 97 +++++++++++++++++++ src/dialogs/preferences/PreferencesDialog.cpp | 27 ++---- src/dialogs/preferences/PreferencesDialog.h | 8 +- src/dialogs/preferences/PreferencesDialog.ui | 45 +-------- src/utils/Configuration.cpp | 2 +- src/utils/Configuration.h | 1 + 13 files changed, 257 insertions(+), 122 deletions(-) create mode 100644 src/dialogs/preferences/GeneralOptionsWidget.cpp create mode 100644 src/dialogs/preferences/GeneralOptionsWidget.h create mode 100644 src/dialogs/preferences/GeneralOptionsWidget.ui diff --git a/src/MainWindow.ui b/src/MainWindow.ui index b3ad5384..373e3be4 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -26,12 +26,12 @@ /* border: 2px solid white;*/ } -QTabBar +QMainWindow > QTabBar { qproperty-drawBase: 0; } -QTabBar::tab { +QMainWindow > QTabBar::tab { border-bottom-color: #2180a9; border-top-left-radius: 0px; border-top-right-radius: 0px; @@ -41,12 +41,12 @@ QTabBar::tab { margin-top: 3px; } -QTabBar::tab:selected { +QMainWindow > QTabBar::tab:selected { background: #2180a9; color: #FFFFFF; } -QTabBar::tab:hover { +QMainWindow > QTabBar::tab:hover { background: #2180a9; /* #3C879E; */ color: #FFFFFF; } diff --git a/src/cutter.pro b/src/cutter.pro index a3fd6ca2..4e256e3f 100644 --- a/src/cutter.pro +++ b/src/cutter.pro @@ -81,7 +81,8 @@ SOURCES += \ widgets/PseudocodeWidget.cpp \ widgets/VisualNavbar.cpp \ widgets/GraphView.cpp \ - dialogs/preferences/PreferencesDialog.cpp + dialogs/preferences/PreferencesDialog.cpp \ + dialogs/preferences/GeneralOptionsWidget.cpp HEADERS += \ cutter.h \ @@ -133,7 +134,8 @@ HEADERS += \ widgets/PseudocodeWidget.h \ widgets/VisualNavbar.h \ widgets/GraphView.h \ - dialogs/preferences/PreferencesDialog.h + dialogs/preferences/PreferencesDialog.h \ + dialogs/preferences/GeneralOptionsWidget.h FORMS += \ dialogs/AboutDialog.ui \ @@ -164,7 +166,8 @@ FORMS += \ widgets/HexdumpWidget.ui \ dialogs/SaveProjectDialog.ui \ widgets/PseudocodeWidget.ui \ - dialogs/preferences/PreferencesDialog.ui + dialogs/preferences/PreferencesDialog.ui \ + dialogs/preferences/GeneralOptionsWidget.ui RESOURCES += \ resources.qrc diff --git a/src/dialogs/preferences/AsmOptionsWidget.cpp b/src/dialogs/preferences/AsmOptionsWidget.cpp index 9f0c9d46..2a7b0ac3 100644 --- a/src/dialogs/preferences/AsmOptionsWidget.cpp +++ b/src/dialogs/preferences/AsmOptionsWidget.cpp @@ -20,27 +20,18 @@ AsmOptionsWidget::AsmOptionsWidget(PreferencesDialog *dialog, QWidget *parent) ui->syntaxComboBox->addItem(syntax, syntax); ui->syntaxComboBox->blockSignals(false); - // asm.offset=false would break reading the offset in DisassemblyWidget - // TODO: remove this when DisassemblyWidget::readDisassemblyOffset() allows it - ui->offsetCheckBox->setVisible(false); - updateAsmOptionsFromVars(); - updateFontFromConfig(); connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(updateAsmOptionsFromVars())); - connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(updateFontFromConfig())); - connect(dialog, SIGNAL(saveAsDefault()), this, SLOT(saveAsDefault())); - connect(dialog, SIGNAL(resetToDefault()), this, SLOT(resetToDefault())); + ui->buttonBox->addButton(tr("Save as Defaults"), QDialogButtonBox::ButtonRole::ApplyRole); + + //connect(dialog, SIGNAL(saveAsDefault()), this, SLOT(saveAsDefault())); + //connect(dialog, SIGNAL(resetToDefault()), this, SLOT(resetToDefault())); } AsmOptionsWidget::~AsmOptionsWidget() {} -void AsmOptionsWidget::updateFontFromConfig() -{ - QFont currentFont = Config()->getFont(); - ui->fontSelectionLabel->setText(currentFont.toString()); -} void AsmOptionsWidget::updateAsmOptionsFromVars() { @@ -220,12 +211,18 @@ void AsmOptionsWidget::on_varsubOnlyCheckBox_toggled(bool checked) triggerAsmOptionsChanged(); } -void AsmOptionsWidget::on_fontSelectionButton_clicked() + +void AsmOptionsWidget::on_buttonBox_clicked(QAbstractButton *button) { - QFont currentFont = Config()->getFont(); - bool ok; - QFont newFont = QFontDialog::getFont(&ok, currentFont, this); - if (ok) { - Config()->setFont(newFont); + switch (ui->buttonBox->buttonRole(button)) + { + case QDialogButtonBox::ButtonRole::ApplyRole: + saveAsDefault(); + break; + case QDialogButtonBox::ButtonRole::ResetRole: + resetToDefault(); + break; + default: + break; } -} +} \ No newline at end of file diff --git a/src/dialogs/preferences/AsmOptionsWidget.h b/src/dialogs/preferences/AsmOptionsWidget.h index 9929e6af..b0dc6016 100644 --- a/src/dialogs/preferences/AsmOptionsWidget.h +++ b/src/dialogs/preferences/AsmOptionsWidget.h @@ -1,6 +1,6 @@ -#ifndef ASMOPTIONSDIALOG_H -#define ASMOPTIONSDIALOG_H +#ifndef ASMOPTIONSWIDGET_H +#define ASMOPTIONSWIDGET_H #include #include @@ -32,7 +32,6 @@ private slots: void saveAsDefault(); void resetToDefault(); - void updateFontFromConfig(); void updateAsmOptionsFromVars(); void on_esilCheckBox_toggled(bool checked); @@ -48,7 +47,8 @@ private slots: void on_bblineCheckBox_toggled(bool checked); void on_varsubCheckBox_toggled(bool checked); void on_varsubOnlyCheckBox_toggled(bool checked); - void on_fontSelectionButton_clicked(); + + void on_buttonBox_clicked(QAbstractButton *button); }; diff --git a/src/dialogs/preferences/AsmOptionsWidget.ui b/src/dialogs/preferences/AsmOptionsWidget.ui index b208145d..ca78d7e5 100644 --- a/src/dialogs/preferences/AsmOptionsWidget.ui +++ b/src/dialogs/preferences/AsmOptionsWidget.ui @@ -11,30 +11,9 @@ - Disassembly Options + Disassembly - - QLayout::SetMinAndMaxSize - - - - - - - - - - - - - - Select font - - - - - @@ -159,6 +138,29 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::RestoreDefaults + + + diff --git a/src/dialogs/preferences/GeneralOptionsWidget.cpp b/src/dialogs/preferences/GeneralOptionsWidget.cpp new file mode 100644 index 00000000..2b373842 --- /dev/null +++ b/src/dialogs/preferences/GeneralOptionsWidget.cpp @@ -0,0 +1,53 @@ +#include +#include + +#include "GeneralOptionsWidget.h" +#include "ui_GeneralOptionsWidget.h" + +#include "PreferencesDialog.h" + +#include "utils/Helpers.h" +#include "utils/Configuration.h" + +GeneralOptionsWidget::GeneralOptionsWidget(PreferencesDialog *dialog, QWidget *parent) + : QDialog(parent), + ui(new Ui::GeneralOptionsWidget) +{ + ui->setupUi(this); + + updateFontFromConfig(); + updateThemeFromConfig(); + + connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(updateFontFromConfig())); + connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig())); +} + +GeneralOptionsWidget::~GeneralOptionsWidget() {} + +void GeneralOptionsWidget::updateFontFromConfig() +{ + QFont currentFont = Config()->getFont(); + ui->fontSelectionLabel->setText(currentFont.toString()); +} + +void GeneralOptionsWidget::updateThemeFromConfig() +{ + ui->themeComboBox->setCurrentIndex(Config()->getDarkTheme() ? 1 : 0); +} + +void GeneralOptionsWidget::on_fontSelectionButton_clicked() +{ + QFont currentFont = Config()->getFont(); + bool ok; + QFont newFont = QFontDialog::getFont(&ok, currentFont, this); + if (ok) { + Config()->setFont(newFont); + } +} + +void GeneralOptionsWidget::on_themeComboBox_currentIndexChanged(int index) +{ + disconnect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig())); + Config()->setDarkTheme(index == 1); + connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig())); +} diff --git a/src/dialogs/preferences/GeneralOptionsWidget.h b/src/dialogs/preferences/GeneralOptionsWidget.h new file mode 100644 index 00000000..8d979256 --- /dev/null +++ b/src/dialogs/preferences/GeneralOptionsWidget.h @@ -0,0 +1,38 @@ + +#ifndef GENERALOPTIONSWIDGET_H +#define GENERALOPTIONSWIDGET_H + +#include +#include +#include + +#include "cutter.h" + +class PreferencesDialog; + +namespace Ui +{ + class GeneralOptionsWidget; +} + +class GeneralOptionsWidget : public QDialog +{ + Q_OBJECT + +public: + explicit GeneralOptionsWidget(PreferencesDialog *dialog, QWidget *parent = nullptr); + ~GeneralOptionsWidget(); + +private: + std::unique_ptr ui; + +private slots: + void updateFontFromConfig(); + void updateThemeFromConfig(); + + void on_fontSelectionButton_clicked(); + void on_themeComboBox_currentIndexChanged(int index); +}; + + +#endif //ASMOPTIONSDIALOG_H diff --git a/src/dialogs/preferences/GeneralOptionsWidget.ui b/src/dialogs/preferences/GeneralOptionsWidget.ui new file mode 100644 index 00000000..f75f509e --- /dev/null +++ b/src/dialogs/preferences/GeneralOptionsWidget.ui @@ -0,0 +1,97 @@ + + + GeneralOptionsWidget + + + + 0 + 0 + 442 + 225 + + + + General + + + + QLayout::SetMinAndMaxSize + + + + + + + Font: + + + + + + + + + + 1 + 0 + + + + + + + + + + + + 0 + 0 + + + + Select font + + + + + + + + + Theme: + + + + + + + + 0 + 0 + + + + + Default + + + + + Dark + + + + + + + + + + Save as Default + + + + + + diff --git a/src/dialogs/preferences/PreferencesDialog.cpp b/src/dialogs/preferences/PreferencesDialog.cpp index 02089f55..252a5164 100644 --- a/src/dialogs/preferences/PreferencesDialog.cpp +++ b/src/dialogs/preferences/PreferencesDialog.cpp @@ -4,6 +4,7 @@ #include "PreferencesDialog.h" #include "ui_PreferencesDialog.h" +#include "GeneralOptionsWidget.h" #include "AsmOptionsWidget.h" #include "utils/Helpers.h" @@ -16,10 +17,10 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) { ui->setupUi(this); - ui->buttonBox->addButton(tr("Save as Defaults"), QDialogButtonBox::ButtonRole::ApplyRole); - - auto asmOptionsWidget = new AsmOptionsWidget(this); - ui->tabWidget->addTab(asmOptionsWidget, tr("Disassembly")); +#define ADD_TAB(c) { auto w = new c(this); ui->tabWidget->addTab(w, w->windowTitle()); } + ADD_TAB(GeneralOptionsWidget) + ADD_TAB(AsmOptionsWidget) +#undef ADD_TAB } PreferencesDialog::~PreferencesDialog() @@ -30,23 +31,11 @@ void PreferencesDialog::showSection(PreferencesDialog::Section section) { switch(section) { - case Section::Disassembly: + case Section::General: ui->tabWidget->setCurrentIndex(0); break; - } -} - -void PreferencesDialog::on_buttonBox_clicked(QAbstractButton *button) -{ - switch (ui->buttonBox->buttonRole(button)) - { - case QDialogButtonBox::ButtonRole::ApplyRole: - emit saveAsDefault(); - break; - case QDialogButtonBox::ButtonRole::ResetRole: - emit resetToDefault(); - break; - default: + case Section::Disassembly: + ui->tabWidget->setCurrentIndex(1); break; } } diff --git a/src/dialogs/preferences/PreferencesDialog.h b/src/dialogs/preferences/PreferencesDialog.h index 61279adb..afec7d43 100644 --- a/src/dialogs/preferences/PreferencesDialog.h +++ b/src/dialogs/preferences/PreferencesDialog.h @@ -18,21 +18,19 @@ class PreferencesDialog : public QDialog Q_OBJECT public: - enum class Section { Disassembly }; + enum class Section { General, Disassembly }; explicit PreferencesDialog(QWidget *parent = nullptr); ~PreferencesDialog(); void showSection(Section section); -signals: +/*signals: void saveAsDefault(); - void resetToDefault(); + void resetToDefault();*/ private: std::unique_ptr ui; - - void on_buttonBox_clicked(QAbstractButton *button); }; #endif //PREFERENCESDIALOG_H diff --git a/src/dialogs/preferences/PreferencesDialog.ui b/src/dialogs/preferences/PreferencesDialog.ui index a2b520e6..c495f9af 100644 --- a/src/dialogs/preferences/PreferencesDialog.ui +++ b/src/dialogs/preferences/PreferencesDialog.ui @@ -17,51 +17,8 @@ - - - - Qt::Horizontal - - - QDialogButtonBox::RestoreDefaults - - - - - - buttonBox - accepted() - PreferencesDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - PreferencesDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - + diff --git a/src/utils/Configuration.cpp b/src/utils/Configuration.cpp index 8d654aab..8e411bad 100644 --- a/src/utils/Configuration.cpp +++ b/src/utils/Configuration.cpp @@ -18,7 +18,7 @@ Configuration* Configuration::instance() void Configuration::loadInitial() { - setDarkTheme(s.value("dark").toBool()); + setDarkTheme(getDarkTheme()); } void Configuration::resetAll() diff --git a/src/utils/Configuration.h b/src/utils/Configuration.h index ca11d598..4f79f239 100644 --- a/src/utils/Configuration.h +++ b/src/utils/Configuration.h @@ -36,6 +36,7 @@ public: // Colors const QColor getColor(const QString &name) const; void setDarkTheme(bool set); + bool getDarkTheme() { return s.value("dark").toBool(); } // TODO Imho it's wrong doing it this way. Should find something else. bool getAsmESIL() const { return s.value("asm.esil", false).toBool(); }