Move general options from AsmOptionsWidget to new GeneralOptionsWidget

This commit is contained in:
Florian Märkl 2017-12-14 16:14:33 +01:00
parent 94750ea15b
commit c42b566a4c
13 changed files with 257 additions and 122 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}
}
}

View File

@ -1,6 +1,6 @@
#ifndef ASMOPTIONSDIALOG_H
#define ASMOPTIONSDIALOG_H
#ifndef ASMOPTIONSWIDGET_H
#define ASMOPTIONSWIDGET_H
#include <QDialog>
#include <QPushButton>
@ -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);
};

View File

@ -11,30 +11,9 @@
</rect>
</property>
<property name="windowTitle">
<string>Disassembly Options</string>
<string>Disassembly</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum>
</property>
<item>
<layout class="QHBoxLayout" name="fontSelectionLayout">
<item>
<widget class="QLabel" name="fontSelectionLabel">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fontSelectionButton">
<property name="text">
<string>Select font</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="esilCheckBox">
<property name="text">
@ -159,6 +138,29 @@
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::RestoreDefaults</set>
</property>
</widget>
</item>
</layout>
<action name="actionSaveAsDefault">
<property name="text">

View File

@ -0,0 +1,53 @@
#include <QLabel>
#include <QFontDialog>
#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()));
}

View File

@ -0,0 +1,38 @@
#ifndef GENERALOPTIONSWIDGET_H
#define GENERALOPTIONSWIDGET_H
#include <QDialog>
#include <QPushButton>
#include <memory>
#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::GeneralOptionsWidget> ui;
private slots:
void updateFontFromConfig();
void updateThemeFromConfig();
void on_fontSelectionButton_clicked();
void on_themeComboBox_currentIndexChanged(int index);
};
#endif //ASMOPTIONSDIALOG_H

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GeneralOptionsWidget</class>
<widget class="QWidget" name="GeneralOptionsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>442</width>
<height>225</height>
</rect>
</property>
<property name="windowTitle">
<string>General</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum>
</property>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="fontLabel">
<property name="text">
<string>Font:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="fontSelectionLayout">
<item>
<widget class="QLabel" name="fontSelectionLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fontSelectionButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Select font</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="themeLabel">
<property name="text">
<string>Theme:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="themeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Default</string>
</property>
</item>
<item>
<property name="text">
<string>Dark</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
<action name="actionSaveAsDefault">
<property name="text">
<string>Save as Default</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -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;
}
}

View File

@ -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::PreferencesDialog> ui;
void on_buttonBox_clicked(QAbstractButton *button);
};
#endif //PREFERENCESDIALOG_H

View File

@ -17,51 +17,8 @@
<item>
<widget class="QTabWidget" name="tabWidget"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::RestoreDefaults</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PreferencesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PreferencesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>

View File

@ -18,7 +18,7 @@ Configuration* Configuration::instance()
void Configuration::loadInitial()
{
setDarkTheme(s.value("dark").toBool());
setDarkTheme(getDarkTheme());
}
void Configuration::resetAll()

View File

@ -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(); }