-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptionsdialog.cpp
111 lines (93 loc) · 3.72 KB
/
optionsdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <QColorDialog>
#include <QFontDialog>
#include "optionsdialog.h"
#include "ui_optionsdialog.h"
OptionsDialog::OptionsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::OptionsDialog)
{
ui->setupUi(this);
readSettings();
writeSettings();
}
OptionsDialog::~OptionsDialog()
{
delete ui;
}
void OptionsDialog::show()
{
readSettings();
QWidget::show();
}
void OptionsDialog::accept()
{
writeSettings();
emit accepted();
QDialog::hide();
}
void OptionsDialog::readSettings()
{
QSettings settings;
ui->cbAddressArea->setChecked(settings.value("AddressArea", true).toBool());
ui->cbAsciiArea->setChecked(settings.value("AsciiArea", true).toBool());
ui->cbHighlighting->setChecked(settings.value("Highlighting", true).toBool());
ui->cbOverwriteMode->setChecked(settings.value("OverwriteMode", true).toBool());
ui->cbReadOnly->setChecked(settings.value("ReadOnly").toBool());
setColor(ui->lbHighlightingColor, settings.value("HighlightingColor", QColor(0xff, 0xff, 0x99, 0xff)).value<QColor>());
setColor(ui->lbAddressAreaColor, settings.value("AddressAreaColor", this->palette().alternateBase().color()).value<QColor>());
setColor(ui->lbSelectionColor, settings.value("SelectionColor", this->palette().highlight().color()).value<QColor>());
#ifdef Q_OS_WIN32
ui->leWidgetFont->setFont(settings.value("WidgetFont", QFont("Courier", 10)).value<QFont>());
#else
ui->leWidgetFont->setFont(settings.value("WidgetFont", QFont("Monospace", 10)).value<QFont>());
#endif
ui->sbAddressAreaWidth->setValue(settings.value("AddressAreaWidth", 4).toInt());
ui->sbBytesPerLine->setValue(settings.value("BytesPerLine", 16).toInt());
}
void OptionsDialog::writeSettings()
{
QSettings settings;
settings.setValue("AddressArea", ui->cbAddressArea->isChecked());
settings.setValue("AsciiArea", ui->cbAsciiArea->isChecked());
settings.setValue("Highlighting", ui->cbHighlighting->isChecked());
settings.setValue("OverwriteMode", ui->cbOverwriteMode->isChecked());
settings.setValue("ReadOnly", ui->cbReadOnly->isChecked());
settings.setValue("HighlightingColor", ui->lbHighlightingColor->palette().color(QPalette::Background));
settings.setValue("AddressAreaColor", ui->lbAddressAreaColor->palette().color(QPalette::Background));
settings.setValue("SelectionColor", ui->lbSelectionColor->palette().color(QPalette::Background));
settings.setValue("WidgetFont",ui->leWidgetFont->font());
settings.setValue("AddressAreaWidth", ui->sbAddressAreaWidth->value());
settings.setValue("BytesPerLine", ui->sbBytesPerLine->value());
}
void OptionsDialog::setColor(QWidget *widget, QColor color)
{
QPalette palette = widget->palette();
palette.setColor(QPalette::Background, color);
widget->setPalette(palette);
widget->setAutoFillBackground(true);
}
void OptionsDialog::on_pbHighlightingColor_clicked()
{
QColor color = QColorDialog::getColor(ui->lbHighlightingColor->palette().color(QPalette::Background), this);
if (color.isValid())
setColor(ui->lbHighlightingColor, color);
}
void OptionsDialog::on_pbAddressAreaColor_clicked()
{
QColor color = QColorDialog::getColor(ui->lbAddressAreaColor->palette().color(QPalette::Background), this);
if (color.isValid())
setColor(ui->lbAddressAreaColor, color);
}
void OptionsDialog::on_pbSelectionColor_clicked()
{
QColor color = QColorDialog::getColor(ui->lbSelectionColor->palette().color(QPalette::Background), this);
if (color.isValid())
setColor(ui->lbSelectionColor, color);
}
void OptionsDialog::on_pbWidgetFont_clicked()
{
bool ok;
QFont font = QFontDialog::getFont(&ok, ui->leWidgetFont->font(), this);
if (ok)
ui->leWidgetFont->setFont(font);
}