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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#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>());
setColor(ui->lbAddressFontColor, settings.value("AddressFontColor", QPalette::WindowText).value<QColor>());
setColor(ui->lbAsciiAreaColor, settings.value("AsciiAreaColor", this->palette().alternateBase().color()).value<QColor>());
setColor(ui->lbAsciiFontColor, settings.value("AsciiFontColor", QPalette::WindowText).value<QColor>());
setColor(ui->lbHexFontColor, settings.value("HexFontColor", QPalette::WindowText).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("AddressFontColor", ui->lbAddressFontColor->palette().color(QPalette::Background));
settings.setValue("AsciiAreaColor", ui->lbAsciiAreaColor->palette().color(QPalette::Background));
settings.setValue("AsciiFontColor", ui->lbAsciiFontColor->palette().color(QPalette::Background));
settings.setValue("HexFontColor", ui->lbHexFontColor->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_pbAddressFontColor_clicked()
{
QColor color = QColorDialog::getColor(ui->lbAddressFontColor->palette().color(QPalette::WindowText), this);
if (color.isValid())
setColor(ui->lbAddressFontColor, color);
}
void OptionsDialog::on_pbAsciiAreaColor_clicked()
{
QColor color = QColorDialog::getColor(ui->lbAsciiAreaColor->palette().color(QPalette::Background), this);
if (color.isValid())
setColor(ui->lbAsciiAreaColor, color);
}
void OptionsDialog::on_pbAsciiFontColor_clicked()
{
QColor color = QColorDialog::getColor(ui->lbAsciiFontColor->palette().color(QPalette::WindowText), this);
if (color.isValid())
setColor(ui->lbAsciiFontColor, color);
}
void OptionsDialog::on_pbHexFontColor_clicked()
{
QColor color = QColorDialog::getColor(ui->lbHexFontColor->palette().color(QPalette::WindowText), this);
if (color.isValid())
setColor(ui->lbHexFontColor, 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);
}
|