1 #include "colorsamplemodel.h"
3 #include "preferencedialog.h"
4 #include "ui_preferencedialog.h"
6 #include <QAbstractTableModel>
7 #include <QColorDialog>
11 #include <QFileDialog>
12 #include <QStandardPaths>
14 PreferenceDialog::PreferenceDialog(QWidget *parent) :
16 ui(new Ui::PreferenceDialog),
20 m_model.setColorMap(&m_colorMap);
23 ui->tabWidget->setCurrentIndex(0);
24 ui->sampleEdit->setText(QDir::homePath());
25 ui->sampleTable->setModel(&m_model);
26 ui->sampleTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
27 ui->sampleTable->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
29 connect(ui->bootSize, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
30 connect(ui->sizeAbsolute, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
31 connect(ui->sizeRelative, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
32 connect(ui->bootPos, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
33 connect(ui->posAbsolute, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
34 connect(ui->posRelative, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
36 connect(ui->boxClrBg, SIGNAL(clicked()), this, SLOT(selectBoxColor()));
37 connect(ui->boxClrFg, SIGNAL(clicked()), this, SLOT(selectBoxColor()));
39 connect(ui->clrBgMark, SIGNAL(clicked()), this, SLOT(selectViewColor()));
40 connect(ui->clrBgNormal, SIGNAL(clicked()), this, SLOT(selectViewColor()));
41 connect(ui->clrFgHidden, SIGNAL(clicked()), this, SLOT(selectViewColor()));
42 connect(ui->clrFgMark, SIGNAL(clicked()), this, SLOT(selectViewColor()));
43 connect(ui->clrFgNormal, SIGNAL(clicked()), this, SLOT(selectViewColor()));
44 connect(ui->clrFgReadonly, SIGNAL(clicked()), this, SLOT(selectViewColor()));
45 connect(ui->clrFgSystem, SIGNAL(clicked()), this, SLOT(selectViewColor()));
47 connect(ui->boxFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(changeFont()));
48 connect(ui->boxFontBold, SIGNAL(clicked()), this, SLOT(changeFont()));
49 connect(ui->boxFontSize, SIGNAL(valueChanged(int)), this, SLOT(changeFont()));
51 connect(ui->viewFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(changeFont()));
52 connect(ui->viewFontBold, SIGNAL(clicked()), this, SLOT(changeFont()));
53 connect(ui->viewFontSize, SIGNAL(valueChanged(int)), this, SLOT(changeFont()));
55 connect(ui->importAppearance, SIGNAL(clicked()), this, SLOT(importAppearance()));
56 connect(ui->exportAppearance, SIGNAL(clicked()), this, SLOT(exportAppearance()));
57 connect(ui->termBrowse, SIGNAL(clicked()), this, SLOT(browseApp()));
58 connect(ui->editorBrowse, SIGNAL(clicked()), this, SLOT(browseApp()));
64 QRadioButton *radioBtn;
68 ui->confirmExit->setChecked(settings.value(IniKey_ConfirmExit).toBool());
70 strValue = settings.value(IniKey_BootSizeSpec).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).toSize();
83 ui->absoluteWidth->setValue(size.width());
84 ui->absoluteHeight->setValue(size.height());
85 size = settings.value(IniKey_BootSizeRel).toSize();
86 ui->relativeWidth->setValue(size.width());
87 ui->relativeHeight->setValue(size.height());
89 strValue = settings.value(IniKey_BootPosSpec).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).toPoint();
102 ui->absoluteLeft->setValue(point.x());
103 ui->absoluteTop->setValue(point.y());
104 point = settings.value(IniKey_BootPosRel).toPoint();
105 ui->relativeLeft->setValue(point.x());
106 ui->relativeTop->setValue(point.y());
108 ui->resetOnBoot->setChecked(settings.value(IniKey_ResetOnBoot).toBool());
111 loadAppearance(settings);
115 ui->confirmCopy->setChecked(settings.value(IniKey_ConfirmCopy).toBool());
116 ui->confirmDelete->setChecked(settings.value(IniKey_ConfirmDelete).toBool());
117 ui->confirmMove->setChecked(settings.value(IniKey_ConfirmMove).toBool());
118 ui->confirmRename->setChecked(settings.value(IniKey_ConfirmRename).toBool());
120 ui->autoCloseCopy->setChecked(settings.value(IniKey_AutoCloseCopy).toBool());
121 ui->autoCloseDelete->setChecked(settings.value(IniKey_AutoCloseDelete).toBool());
122 ui->autoCloseMove->setChecked(settings.value(IniKey_AutoCloseMove).toBool());
123 ui->autoCloseRename->setChecked(settings.value(IniKey_AutoCloseRename).toBool());
125 strValue = settings.value(IniKey_DefaultOnCopy).toString();
126 if (strValue.isEmpty()) {
127 strValue = "owDefIfNew";
129 radioBtn = findChild<QRadioButton*>(strValue);
130 if (radioBtn == NULL) {
131 radioBtn = ui->owDefIfNew;
133 radioBtn->setChecked(true);
134 ui->moveAfterCreate->setChecked(settings.value(IniKey_MoveAfterCreateFolder).toBool());
135 ui->openAfterCreate->setChecked(settings.value(IniKey_OpenAfterCreateFile).toBool());
139 ui->editorOpt->setText(settings.value(IniKey_EditorOption).toString());
140 ui->editorPath->setText(settings.value(IniKey_EditorPath).toString());
142 ui->termOpt->setText(settings.value(IniKey_TerminalOption).toString());
143 ui->termPath->setText(settings.value(IniKey_TerminalPath).toString());
146 PreferenceDialog::~PreferenceDialog()
151 void PreferenceDialog::saveAppearance(QSettings &settings)
153 QFont font = ui->sampleEdit->font();
154 QPalette palette = ui->sampleEdit->palette();
155 settings.setValue(IniKey_BoxColorBg, palette.base().color());
156 settings.setValue(IniKey_BoxColorFg, palette.text().color());
157 settings.setValue(IniKey_BoxFont, font);
159 settings.setValue(IniKey_ViewColorBgMark, m_colorMap["clrBgMark"]);
160 settings.setValue(IniKey_ViewColorBgNormal, m_colorMap["clrBgNormal"]);
161 settings.setValue(IniKey_ViewColorFgHidden, m_colorMap["clrFgHidden"]);
162 settings.setValue(IniKey_ViewColorFgMark, m_colorMap["clrFgMark"]);
163 settings.setValue(IniKey_ViewColorFgNormal, m_colorMap["clrFgNormal"]);
164 settings.setValue(IniKey_ViewColorFgReadonly, m_colorMap["clrFgReadonly"]);
165 settings.setValue(IniKey_ViewColorFgSystem, m_colorMap["clrFgSystem"]);
166 settings.setValue(IniKey_ViewFont, m_model.font());
169 void PreferenceDialog::loadAppearance(QSettings &settings)
176 palette = QPalette();
178 color = settings.value(IniKey_BoxColorBg).value<QColor>();
179 palette.setColor(QPalette::Base, color);
181 color = settings.value(IniKey_BoxColorFg).value<QColor>();
182 palette.setColor(QPalette::Text, color);
184 font = settings.value(IniKey_BoxFont).value<QFont>();
185 ui->boxFont->setCurrentText(font.family());
186 ui->boxFontBold->setChecked(font.bold());
187 ui->boxFontSize->setValue(font.pointSize());
189 ui->sampleEdit->setPalette(palette);
190 ui->sampleEdit->setFont(font);
193 color = settings.value(IniKey_ViewColorBgMark).value<QColor>();
194 m_colorMap["clrBgMark"] = color;
195 color = settings.value(IniKey_ViewColorBgNormal).value<QColor>();
196 m_colorMap["clrBgNormal"] = color;
198 color = settings.value(IniKey_ViewColorFgHidden).value<QColor>();
199 m_colorMap["clrFgHidden"] = color;
200 color = settings.value(IniKey_ViewColorFgMark).value<QColor>();
201 m_colorMap["clrFgMark"] = color;
202 color = settings.value(IniKey_ViewColorFgNormal).value<QColor>();
203 m_colorMap["clrFgNormal"] = color;
204 color = settings.value(IniKey_ViewColorFgReadonly).value<QColor>();
205 m_colorMap["clrFgReadonly"] = color;
206 color = settings.value(IniKey_ViewColorFgSystem).value<QColor>();
207 m_colorMap["clrFgSystem"] = color;
209 font = settings.value(IniKey_ViewFont).value<QFont>();
210 ui->viewFont->setCurrentText(font.family());
211 ui->viewFontBold->setChecked(font.bold());
212 ui->viewFontSize->setValue(font.pointSize());
214 m_model.setFont(font);
219 void PreferenceDialog::changeFont()
223 if (sender() == ui->boxFont ||
224 sender() == ui->boxFontBold ||
225 sender() == ui->boxFontSize)
227 font.setBold(ui->boxFontBold->isChecked());
228 font.setPointSize(ui->boxFontSize->value());
229 font.setFamily(ui->boxFont->currentText());
230 ui->sampleEdit->setFont(font);
233 font.setBold(ui->viewFontBold->isChecked());
234 font.setPointSize(ui->viewFontSize->value());
235 font.setFamily(ui->viewFont->currentText());
236 m_model.setFont(font);
241 void PreferenceDialog::setControlsEnabled(bool enabled)
243 if (sender() == ui->bootSize) {
244 ui->sizeAbsolute->setEnabled(enabled);
245 ui->sizeLast->setEnabled(enabled);
246 ui->sizeRelative->setEnabled(enabled);
248 emit ui->sizeAbsolute->toggled(ui->sizeAbsolute->isChecked());
249 emit ui->sizeRelative->toggled(ui->sizeRelative->isChecked());
252 emit ui->sizeAbsolute->toggled(false);
253 emit ui->sizeRelative->toggled(false);
256 else if (sender() == ui->sizeAbsolute) {
257 ui->absoluteHeight->setEnabled(enabled);
258 ui->absoluteWidth->setEnabled(enabled);
260 else if (sender() == ui->sizeRelative) {
261 ui->relativeHeight->setEnabled(enabled);
262 ui->relativeWidth->setEnabled(enabled);
264 else if (sender() == ui->bootPos) {
265 ui->posAbsolute->setEnabled(enabled);
266 ui->posCenter->setEnabled(enabled);
267 ui->posLast->setEnabled(enabled);
268 ui->posRelative->setEnabled(enabled);
270 emit ui->posAbsolute->toggled(ui->posAbsolute->isChecked());
271 emit ui->posRelative->toggled(ui->posRelative->isChecked());
274 emit ui->posAbsolute->toggled(false);
275 emit ui->posRelative->toggled(false);
278 else if (sender() == ui->posAbsolute) {
279 ui->absoluteLeft->setEnabled(enabled);
280 ui->absoluteTop->setEnabled(enabled);
282 else if (sender() == ui->posRelative) {
283 ui->relativeLeft->setEnabled(enabled);
284 ui->relativeTop->setEnabled(enabled);
288 void PreferenceDialog::selectBoxColor()
291 QPalette palette = ui->sampleEdit->palette();
292 if (sender() == ui->boxClrBg) {
293 color = palette.background().color();
295 else if (sender() == ui->boxClrFg) {
296 color = palette.text().color();
299 color = QColorDialog::getColor(color, this, tr("色選択"));
300 if (!color.isValid()) {
304 if (sender() == ui->boxClrBg) {
305 palette.setColor(QPalette::Base, color);
306 ui->sampleEdit->setPalette(palette);
308 else if (sender() == ui->boxClrFg) {
309 palette.setColor(QPalette::Text, color);
310 ui->sampleEdit->setPalette(palette);
314 void PreferenceDialog::selectViewColor()
316 const QString objName = sender()->objectName();
317 QColor color = m_colorMap[objName];
319 color = QColorDialog::getColor(color, this, tr("色選択"));
320 if (!color.isValid()) {
324 m_colorMap[objName] = color;
328 void PreferenceDialog::browseApp()
330 QStringList list = QStandardPaths::standardLocations(
331 QStandardPaths::ApplicationsLocation);
333 QString path = QFileDialog::getOpenFileName(
334 this, tr("アプリケーションを選択"), list.at(0),
335 tr("実行ファイル (*.exe *.com *.bat *.pif);;すべてのファイル (*)"));
336 #elif defined(Q_OS_MAC)
337 QString path = QFileDialog::getOpenFileName(
338 this, tr("アプリケーションを選択"), list.at(0),
339 tr("実行ファイル (*.app);;すべてのファイル (*)"));
341 QString path = QFileDialog::getOpenFileName(
342 this, tr("アプリケーションを選択"), list.at(0),
345 if (!path.isEmpty()) {
346 if (sender() == ui->editorBrowse) {
347 ui->editorPath->setText(path);
349 else if (sender() == ui->termBrowse) {
350 ui->termPath->setText(path);
355 void PreferenceDialog::importAppearance()
357 QStringList list = QStandardPaths::standardLocations(
358 QStandardPaths::DocumentsLocation);
359 QString path = QFileDialog::getOpenFileName(
360 this, tr("ファイルを選択"), list.at(0),
361 tr("設定ファイル (*.ini);;すべてのファイル (*)"));
362 if (path.isEmpty()) {
366 QSettings settings(path, QSettings::IniFormat);
367 loadAppearance(settings);
370 void PreferenceDialog::exportAppearance()
372 QStringList list = QStandardPaths::standardLocations(
373 QStandardPaths::DocumentsLocation);
374 QString path = QFileDialog::getSaveFileName(
375 this, tr("ファイルを選択"), list.at(0) + "/gefu_appearance.ini",
376 tr("設定ファイル (*.ini);;すべてのファイル (*)"));
377 if (path.isEmpty()) {
381 QSettings settings(path, QSettings::IniFormat);
382 saveAppearance(settings);
385 void PreferenceDialog::accept()
388 QAbstractButton *selected;
392 settings.setValue(IniKey_ConfirmExit, ui->confirmExit->isChecked());
394 if (!ui->bootSize->isChecked()) {
395 settings.setValue(IniKey_BootSizeSpec, "");
398 selected = ui->sizeOptions->checkedButton();
399 settings.setValue(IniKey_BootSizeSpec, selected->objectName());
402 size = QSize(ui->absoluteWidth->value(), ui->absoluteHeight->value());
403 settings.setValue(IniKey_BootSizeAbs, size);
405 size = QSize(ui->relativeWidth->value(), ui->relativeHeight->value());
406 settings.setValue(IniKey_BootSizeRel, size);
409 if (!ui->bootPos->isChecked()) {
410 settings.setValue(IniKey_BootPosSpec, "");
413 selected = ui->posOptions->checkedButton();
414 settings.setValue(IniKey_BootPosSpec, selected->objectName());
417 pos = QPoint(ui->absoluteLeft->value(), ui->absoluteTop->value());
418 settings.setValue(IniKey_BootPosAbs, pos);
420 pos = QPoint(ui->relativeLeft->value(), ui->relativeTop->value());
421 settings.setValue(IniKey_BootPosRel, pos);
424 settings.setValue(IniKey_ResetOnBoot, ui->resetOnBoot->isChecked());
427 saveAppearance(settings);
430 settings.setValue(IniKey_ConfirmCopy, ui->confirmCopy->isChecked());
431 settings.setValue(IniKey_ConfirmDelete, ui->confirmDelete->isChecked());
432 settings.setValue(IniKey_ConfirmMove, ui->confirmMove->isChecked());
433 settings.setValue(IniKey_ConfirmRename, ui->confirmRename->isChecked());
435 settings.setValue(IniKey_AutoCloseCopy, ui->autoCloseCopy->isChecked());
436 settings.setValue(IniKey_AutoCloseDelete, ui->autoCloseDelete->isChecked());
437 settings.setValue(IniKey_AutoCloseMove, ui->autoCloseMove->isChecked());
438 settings.setValue(IniKey_AutoCloseRename, ui->autoCloseRename->isChecked());
440 selected = ui->overwriteOptions->checkedButton();
441 settings.setValue(IniKey_DefaultOnCopy, selected->objectName());
443 settings.setValue(IniKey_MoveAfterCreateFolder, ui->moveAfterCreate->isChecked());
444 settings.setValue(IniKey_OpenAfterCreateFile, ui->openAfterCreate->isChecked());
447 settings.setValue(IniKey_EditorOption, ui->editorOpt->text().trimmed());
448 settings.setValue(IniKey_EditorPath, ui->editorPath->text().trimmed());
450 settings.setValue(IniKey_TerminalOption, ui->termOpt->text().trimmed());
451 settings.setValue(IniKey_TerminalPath, ui->termPath->text().trimmed());