1 #include "colorsamplemodel.h"
3 #include "preferencedialog.h"
4 #include "ui_preferencedialog.h"
6 #include <QAbstractTableModel>
7 #include <QColorDialog>
14 PreferenceDialog::PreferenceDialog(QWidget *parent) :
16 ui(new Ui::PreferenceDialog),
20 m_model.setColorMap(&m_colorMap);
23 ui->tabWidget->setCurrentIndex(0);
24 ui->tabWidget->setTabText(0, "起動と終了");
25 ui->tabWidget->setTabText(1, "色とフォント");
26 ui->sampleEdit->setText(QDir::homePath());
27 ui->sampleTable->setModel(&m_model);
28 ui->sampleTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
29 ui->sampleTable->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
31 connect(ui->bootSize, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
32 connect(ui->sizeAbsolute, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
33 connect(ui->sizeRelative, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
34 connect(ui->bootPos, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
35 connect(ui->posAbsolute, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
36 connect(ui->posRelative, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
38 connect(ui->boxClrBg, SIGNAL(clicked()), this, SLOT(selectBoxColor()));
39 connect(ui->boxClrFg, SIGNAL(clicked()), this, SLOT(selectBoxColor()));
41 connect(ui->clrBgMark, SIGNAL(clicked()), this, SLOT(selectViewColor()));
42 connect(ui->clrBgNormal, SIGNAL(clicked()), this, SLOT(selectViewColor()));
43 connect(ui->clrFgHidden, SIGNAL(clicked()), this, SLOT(selectViewColor()));
44 connect(ui->clrFgMark, SIGNAL(clicked()), this, SLOT(selectViewColor()));
45 connect(ui->clrFgNormal, SIGNAL(clicked()), this, SLOT(selectViewColor()));
46 connect(ui->clrFgReadonly, SIGNAL(clicked()), this, SLOT(selectViewColor()));
47 connect(ui->clrFgSystem, SIGNAL(clicked()), this, SLOT(selectViewColor()));
49 connect(ui->boxFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(changeFont()));
50 connect(ui->boxFontBold, SIGNAL(clicked()), this, SLOT(changeFont()));
51 connect(ui->boxFontSize, SIGNAL(valueChanged(int)), this, SLOT(changeFont()));
53 connect(ui->viewFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(changeFont()));
54 connect(ui->viewFontBold, SIGNAL(clicked()), this, SLOT(changeFont()));
55 connect(ui->viewFontSize, SIGNAL(valueChanged(int)), this, SLOT(changeFont()));
64 QRadioButton *radioBtn;
68 ui->confirmExit->setChecked(settings.value(IniKey_ConfirmExit, true).toBool());
70 strValue = settings.value(IniKey_BootSizeSpec, "sizeLast").toString();
71 if (strValue.isEmpty()) {
72 ui->bootSize->setChecked(false);
75 ui->bootSize->setChecked(true);
76 radioBtn = findChild<QRadioButton*>(strValue);
77 if (radioBtn == NULL) {
78 radioBtn = ui->sizeLast;
80 radioBtn->setChecked(true);
82 size = settings.value(IniKey_BootSizeAbs, QSize(800, 600)).toSize();
83 ui->absoluteWidth->setValue(size.width());
84 ui->absoluteHeight->setValue(size.height());
85 size = settings.value(IniKey_BootSizeRel, QSize(50, 50)).toSize();
86 ui->relativeWidth->setValue(size.width());
87 ui->relativeHeight->setValue(size.height());
89 strValue = settings.value(IniKey_BootPosSpec, "posLast").toString();
90 if (strValue.isEmpty()) {
91 ui->bootPos->setChecked(false);
94 ui->bootPos->setChecked(true);
95 radioBtn = findChild<QRadioButton*>(strValue);
96 if (radioBtn == NULL) {
97 radioBtn = ui->posLast;
99 radioBtn->setChecked(true);
101 point = settings.value(IniKey_BootPosAbs, QPoint(0, 0)).toPoint();
102 ui->absoluteLeft->setValue(point.x());
103 ui->absoluteTop->setValue(point.y());
104 point = settings.value(IniKey_BootPosRel, QPoint(0, 0)).toPoint();
105 ui->relativeLeft->setValue(point.x());
106 ui->relativeTop->setValue(point.y());
108 ui->resetOnBoot->setChecked(settings.value(IniKey_ResetOnBoot, false).toBool());
112 palette = QPalette();
114 color = settings.value(IniKey_BoxColorBg, QPalette().base().color()).value<QColor>();
115 palette.setColor(QPalette::Base, color);
117 color = settings.value(IniKey_BoxColorFg, QPalette().text().color()).value<QColor>();
118 palette.setColor(QPalette::Text, color);
120 QFont defaultFont = ui->sampleEdit->font();
121 font = settings.value(IniKey_BoxFont, defaultFont).value<QFont>();
122 ui->boxFont->setCurrentText(font.family());
123 ui->boxFontBold->setChecked(font.bold());
124 ui->boxFontSize->setValue(font.pointSize());
126 ui->sampleEdit->setPalette(palette);
127 ui->sampleEdit->setFont(font);
130 color = settings.value(IniKey_ViewColorBgMark, DefaultMarkBgColor).value<QColor>();
131 m_colorMap["clrBgMark"] = color;
132 color = settings.value(IniKey_ViewColorBgNormal, QPalette().base().color()).value<QColor>();
133 m_colorMap["clrBgNormal"] = color;
135 color = settings.value(IniKey_ViewColorFgHidden, DefaultHiddenColor).value<QColor>();
136 m_colorMap["clrFgHidden"] = color;
137 color = settings.value(IniKey_ViewColorFgMark, DefaultMarkFgColor).value<QColor>();
138 m_colorMap["clrFgMark"] = color;
139 color = settings.value(IniKey_ViewColorFgNormal, QPalette().text().color()).value<QColor>();
140 m_colorMap["clrFgNormal"] = color;
141 color = settings.value(IniKey_ViewColorFgReadonly, DefaultReadonlyColor).value<QColor>();
142 m_colorMap["clrFgReadonly"] = color;
143 color = settings.value(IniKey_ViewColorFgSystem, DefaultSystemColor).value<QColor>();
144 m_colorMap["clrFgSystem"] = color;
146 defaultFont = ui->sampleTable->font();
147 font = settings.value(IniKey_ViewFont, defaultFont).value<QFont>();
148 ui->viewFont->setCurrentText(font.family());
149 ui->viewFontBold->setChecked(font.bold());
150 ui->viewFontSize->setValue(font.pointSize());
152 m_model.setFont(font);
156 PreferenceDialog::~PreferenceDialog()
161 void PreferenceDialog::changeFont()
165 if (sender() == ui->boxFont ||
166 sender() == ui->boxFontBold ||
167 sender() == ui->boxFontSize)
169 font.setBold(ui->boxFontBold->isChecked());
170 font.setPointSize(ui->boxFontSize->value());
171 font.setFamily(ui->boxFont->currentText());
172 ui->sampleEdit->setFont(font);
175 font.setBold(ui->viewFontBold->isChecked());
176 font.setPointSize(ui->viewFontSize->value());
177 font.setFamily(ui->viewFont->currentText());
178 m_model.setFont(font);
183 void PreferenceDialog::setControlsEnabled(bool enabled)
185 if (sender() == ui->bootSize) {
186 ui->sizeAbsolute->setEnabled(enabled);
187 ui->sizeLast->setEnabled(enabled);
188 ui->sizeRelative->setEnabled(enabled);
190 emit ui->sizeAbsolute->toggled(ui->sizeAbsolute->isChecked());
191 emit ui->sizeRelative->toggled(ui->sizeRelative->isChecked());
194 emit ui->sizeAbsolute->toggled(false);
195 emit ui->sizeRelative->toggled(false);
198 else if (sender() == ui->sizeAbsolute) {
199 ui->absoluteHeight->setEnabled(enabled);
200 ui->absoluteWidth->setEnabled(enabled);
202 else if (sender() == ui->sizeRelative) {
203 ui->relativeHeight->setEnabled(enabled);
204 ui->relativeWidth->setEnabled(enabled);
206 else if (sender() == ui->bootPos) {
207 ui->posAbsolute->setEnabled(enabled);
208 ui->posCenter->setEnabled(enabled);
209 ui->posLast->setEnabled(enabled);
210 ui->posRelative->setEnabled(enabled);
212 emit ui->posAbsolute->toggled(ui->posAbsolute->isChecked());
213 emit ui->posRelative->toggled(ui->posRelative->isChecked());
216 emit ui->posAbsolute->toggled(false);
217 emit ui->posRelative->toggled(false);
220 else if (sender() == ui->posAbsolute) {
221 ui->absoluteLeft->setEnabled(enabled);
222 ui->absoluteTop->setEnabled(enabled);
224 else if (sender() == ui->posRelative) {
225 ui->relativeLeft->setEnabled(enabled);
226 ui->relativeTop->setEnabled(enabled);
230 void PreferenceDialog::selectBoxColor()
233 QPalette palette = ui->sampleEdit->palette();
234 if (sender() == ui->boxClrBg) {
235 color = palette.background().color();
237 else if (sender() == ui->boxClrFg) {
238 color = palette.text().color();
241 color = QColorDialog::getColor(color, this, tr("色選択"));
242 if (!color.isValid()) {
246 if (sender() == ui->boxClrBg) {
247 palette.setColor(QPalette::Base, color);
248 ui->sampleEdit->setPalette(palette);
250 else if (sender() == ui->boxClrFg) {
251 palette.setColor(QPalette::Text, color);
252 ui->sampleEdit->setPalette(palette);
256 void PreferenceDialog::selectViewColor()
258 const QString objName = sender()->objectName();
259 QColor color = m_colorMap[objName];
261 color = QColorDialog::getColor(color, this, tr("色選択"));
262 if (!color.isValid()) {
266 m_colorMap[objName] = color;
270 void PreferenceDialog::accept()
273 QAbstractButton *selected;
277 settings.setValue(IniKey_ConfirmExit, ui->confirmExit->isChecked());
279 if (!ui->bootSize->isChecked()) {
280 settings.setValue(IniKey_BootSizeSpec, "");
283 selected = ui->sizeOptions->checkedButton();
284 settings.setValue(IniKey_BootSizeSpec, selected->objectName());
287 size = QSize(ui->absoluteWidth->value(), ui->absoluteHeight->value());
288 settings.setValue(IniKey_BootSizeAbs, size);
290 size = QSize(ui->relativeWidth->value(), ui->relativeHeight->value());
291 settings.setValue(IniKey_BootSizeRel, size);
294 if (!ui->bootPos->isChecked()) {
295 settings.setValue(IniKey_BootPosSpec, "");
298 selected = ui->posOptions->checkedButton();
299 settings.setValue(IniKey_BootPosSpec, selected->objectName());
302 pos = QPoint(ui->absoluteLeft->value(), ui->absoluteTop->value());
303 settings.setValue(IniKey_BootPosAbs, pos);
305 pos = QPoint(ui->relativeLeft->value(), ui->relativeTop->value());
306 settings.setValue(IniKey_BootPosRel, pos);
309 settings.setValue(IniKey_ResetOnBoot, ui->resetOnBoot->isChecked());
312 QFont font = ui->sampleEdit->font();
313 QPalette palette = ui->sampleEdit->palette();
314 settings.setValue(IniKey_BoxColorBg, palette.base().color());
315 settings.setValue(IniKey_BoxColorFg, palette.text().color());
316 settings.setValue(IniKey_BoxFont, font);
318 settings.setValue(IniKey_ViewColorBgMark, m_colorMap["clrBgMark"]);
319 settings.setValue(IniKey_ViewColorBgNormal, m_colorMap["clrBgNormal"]);
320 settings.setValue(IniKey_ViewColorFgHidden, m_colorMap["clrFgHidden"]);
321 settings.setValue(IniKey_ViewColorFgMark, m_colorMap["clrFgMark"]);
322 settings.setValue(IniKey_ViewColorFgNormal, m_colorMap["clrFgNormal"]);
323 settings.setValue(IniKey_ViewColorFgReadonly, m_colorMap["clrFgReadonly"]);
324 settings.setValue(IniKey_ViewColorFgSystem, m_colorMap["clrFgSystem"]);
325 settings.setValue(IniKey_ViewFont, m_model.font());