cutter/src/dialogs/preferences/PreferencesDialog.cpp

102 lines
2.7 KiB
C++
Raw Normal View History

#include "PreferencesDialog.h"
#include "ui_PreferencesDialog.h"
#include "AppearanceOptionsWidget.h"
#include "AsmOptionsWidget.h"
#include "GraphOptionsWidget.h"
#include "DebugOptionsWidget.h"
2019-03-16 12:41:45 +00:00
#include "PluginsOptionsWidget.h"
#include "PreferenceCategory.h"
2018-10-17 07:55:53 +00:00
#include "common/Helpers.h"
#include "common/Configuration.h"
2019-03-16 12:41:45 +00:00
#include <QDialogButtonBox>
PreferencesDialog::PreferencesDialog(QWidget *parent)
2018-03-21 20:32:32 +00:00
: QDialog(parent),
ui(new Ui::PreferencesDialog)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
QList<PreferenceCategory> prefs {
{
2019-03-16 12:41:45 +00:00
tr("Disassembly"),
new AsmOptionsWidget(this),
QIcon(":/img/icons/disas_light.svg"),
{
{
"Graph",
new GraphOptionsWidget(this),
QIcon(":/img/icons/graph_light.svg")
},
}
},
{
2019-03-16 12:41:45 +00:00
tr("Debug"),
new DebugOptionsWidget(this),
QIcon(":/img/icons/bug_light.svg")
},
{
2019-03-16 12:41:45 +00:00
tr("Appearance"),
new AppearanceOptionsWidget(this),
QIcon(":/img/icons/polar_light.svg")
2019-03-16 12:41:45 +00:00
},
{
tr("Plugins"),
new PluginsOptionsWidget(this),
QIcon(":/img/icons/plugins_light.svg")
}
};
for (auto &c : prefs)
c.addItem(*ui->configCategories, *ui->configPanel);
connect(ui->configCategories,
SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
this, SLOT(changePage(QTreeWidgetItem *, QTreeWidgetItem *)));
connect(ui->saveButtons,
SIGNAL(accepted()),
this, SLOT(close()));
QTreeWidgetItem *defitem = ui->configCategories->topLevelItem(0);
ui->configCategories->setCurrentItem(defitem, 0);
}
PreferencesDialog::~PreferencesDialog()
{
}
void PreferencesDialog::showSection(PreferencesDialog::Section section)
{
QTreeWidgetItem *defitem;
2018-03-21 20:32:32 +00:00
switch (section) {
case Section::Appearance:
ui->configPanel->setCurrentIndex(0);
defitem = ui->configCategories->topLevelItem(0);
ui->configCategories->setCurrentItem(defitem, 0);
2018-03-21 20:32:32 +00:00
break;
case Section::Disassembly:
ui->configPanel->setCurrentIndex(1);
defitem = ui->configCategories->topLevelItem(1);
ui->configCategories->setCurrentItem(defitem, 1);
2018-03-21 20:32:32 +00:00
break;
}
}
void PreferencesDialog::changePage(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
if (!current)
current = previous;
int index = current->data(0, Qt::UserRole).toInt();
if (index)
ui->configPanel->setCurrentIndex(index - 1);
}