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>
13 #include <QFontDialog>
15 PreferenceDialog::PreferenceDialog(QWidget *parent) :
17 ui(new Ui::PreferenceDialog),
21 m_model.setColorMap(&m_colorMap);
24 ui->tabWidget->setCurrentIndex(0);
26 ui->sampleEdit->setText(QDir::homePath());
28 ui->sampleTable->setModel(&m_model);
31 header = ui->sampleTable->horizontalHeader();
32 header->setSectionResizeMode(0, QHeaderView::Stretch);
33 header->setSectionResizeMode(1, QHeaderView::ResizeToContents);
34 header->setSectionResizeMode(2, QHeaderView::ResizeToContents);
35 header = ui->sampleTable->verticalHeader();
36 header->setDefaultSectionSize(header->defaultSectionSize() * 0.75);
39 connect(ui->bootSize, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
40 connect(ui->sizeAbsolute, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
41 connect(ui->sizeRelative, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
42 connect(ui->bootPos, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
43 connect(ui->posAbsolute, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
44 connect(ui->posRelative, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
46 connect(ui->boxClrBg, SIGNAL(clicked()), this, SLOT(selectBoxColor()));
47 connect(ui->boxClrFg, SIGNAL(clicked()), this, SLOT(selectBoxColor()));
48 connect(ui->chooseBoxFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
50 connect(ui->clrBgMark, SIGNAL(clicked()), this, SLOT(selectViewColor()));
51 connect(ui->clrBgNormal, SIGNAL(clicked()), this, SLOT(selectViewColor()));
52 connect(ui->clrFgHidden, SIGNAL(clicked()), this, SLOT(selectViewColor()));
53 connect(ui->clrFgMark, SIGNAL(clicked()), this, SLOT(selectViewColor()));
54 connect(ui->clrFgNormal, SIGNAL(clicked()), this, SLOT(selectViewColor()));
55 connect(ui->clrFgReadonly, SIGNAL(clicked()), this, SLOT(selectViewColor()));
56 connect(ui->clrFgSystem, SIGNAL(clicked()), this, SLOT(selectViewColor()));
57 connect(ui->chooseViewFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
59 connect(ui->importAppearance, SIGNAL(clicked()), this, SLOT(importAppearance()));
60 connect(ui->exportAppearance, SIGNAL(clicked()), this, SLOT(exportAppearance()));
62 connect(ui->termBrowse, SIGNAL(clicked()), this, SLOT(browseApp()));
63 connect(ui->editorBrowse, SIGNAL(clicked()), this, SLOT(browseApp()));
65 connect(ui->chooseViewerFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
66 connect(ui->viewerClrBg, SIGNAL(clicked()), this, SLOT(selectViewerColor()));
67 connect(ui->viewerClrFg, SIGNAL(clicked()), this, SLOT(selectViewerColor()));
68 connect(ui->viewerInherit, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
69 connect(ui->enableViewerIgnoreExt, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
70 connect(ui->defaultIgnoreExt, SIGNAL(clicked()), this, SLOT(setIgnoreExtDefault()));
72 // 現在の設定で各コントロールを初期化する
77 QRadioButton *radioBtn;
81 ui->bootSize->setChecked(true);
82 strValue = settings.value(IniKey_BootSizeSpec).toString();
83 radioBtn = findChild<QRadioButton*>(strValue);
84 if (radioBtn == NULL) {
85 radioBtn = ui->sizeRelative;
87 radioBtn->setChecked(true);
88 if (strValue.isEmpty()) {
89 ui->bootSize->setChecked(false);
91 size = settings.value(IniKey_BootSizeAbs).toSize();
92 ui->absoluteWidth->setValue(size.width());
93 ui->absoluteHeight->setValue(size.height());
94 size = settings.value(IniKey_BootSizeRel).toSize();
95 ui->relativeWidth->setValue(size.width());
96 ui->relativeHeight->setValue(size.height());
98 ui->bootPos->setChecked(true);
99 strValue = settings.value(IniKey_BootPosSpec).toString();
100 radioBtn = findChild<QRadioButton*>(strValue);
101 if (radioBtn == NULL) {
102 radioBtn = ui->posCenter;
104 radioBtn->setChecked(true);
105 if (strValue.isEmpty()) {
106 ui->bootPos->setChecked(false);
108 point = settings.value(IniKey_BootPosAbs).toPoint();
109 ui->absoluteLeft->setValue(point.x());
110 ui->absoluteTop->setValue(point.y());
111 point = settings.value(IniKey_BootPosRel).toPoint();
112 ui->relativeLeft->setValue(point.x());
113 ui->relativeTop->setValue(point.y());
115 ui->resetOnBoot->setChecked(settings.value(IniKey_ResetOnBoot).toBool());
117 ui->checkUpdates->setChecked(settings.value(IniKey_CheckUpdates).toBool());
119 ui->confirmExit->setChecked(settings.value(IniKey_ConfirmExit).toBool());
121 //>>>>> 色とフォント、テキストビューア
122 loadAppearance(settings, false);
123 ui->dark->setValue(settings.value(IniKey_Darkness).toInt());
127 ui->confirmCopy->setChecked(settings.value(IniKey_ConfirmCopy).toBool());
128 ui->confirmDelete->setChecked(settings.value(IniKey_ConfirmDelete).toBool());
129 ui->confirmMove->setChecked(settings.value(IniKey_ConfirmMove).toBool());
130 ui->confirmRename->setChecked(settings.value(IniKey_ConfirmRename).toBool());
132 ui->autoCloseCopy->setChecked(settings.value(IniKey_AutoCloseCopy).toBool());
133 ui->autoCloseDelete->setChecked(settings.value(IniKey_AutoCloseDelete).toBool());
134 ui->autoCloseMove->setChecked(settings.value(IniKey_AutoCloseMove).toBool());
135 ui->autoCloseRename->setChecked(settings.value(IniKey_AutoCloseRename).toBool());
137 strValue = settings.value(IniKey_DefaultOnCopy).toString();
138 if (strValue.isEmpty()) {
139 strValue = "owDefIfNew";
141 radioBtn = findChild<QRadioButton*>(strValue);
142 if (radioBtn == NULL) {
143 radioBtn = ui->rbOverWriteIfNew;
145 radioBtn->setChecked(true);
146 ui->moveAfterCreate->setChecked(settings.value(IniKey_MoveAfterCreateFolder).toBool());
147 ui->openAfterCreate->setChecked(settings.value(IniKey_OpenAfterCreateFile).toBool());
151 ui->editorOpt->setText(settings.value(IniKey_EditorOption).toString());
152 ui->editorPath->setText(settings.value(IniKey_EditorPath).toString());
154 ui->termOpt->setText(settings.value(IniKey_TerminalOption).toString());
155 ui->termPath->setText(settings.value(IniKey_TerminalPath).toString());
158 ui->enableViewerIgnoreExt->setChecked(true);
159 ui->enableViewerIgnoreExt->setChecked(!settings.value(IniKey_ViewerForceOpen).toBool());
160 ui->viewerIgnoreExt->setPlainText(settings.value(IniKey_ViewerIgnoreExt).toString());
163 PreferenceDialog::~PreferenceDialog()
168 void PreferenceDialog::saveAppearance(QSettings &settings)
170 QFont font = ui->sampleEdit->font();
171 QPalette palette = ui->sampleEdit->palette();
172 settings.setValue(IniKey_BoxColorBg, palette.base().color());
173 settings.setValue(IniKey_BoxColorFg, palette.text().color());
174 settings.setValue(IniKey_BoxFont, font);
176 settings.setValue(IniKey_ViewColorBgMark, m_colorMap["clrBgMark"]);
177 settings.setValue(IniKey_ViewColorBgNormal, m_colorMap["clrBgNormal"]);
178 settings.setValue(IniKey_ViewColorFgHidden, m_colorMap["clrFgHidden"]);
179 settings.setValue(IniKey_ViewColorFgMark, m_colorMap["clrFgMark"]);
180 settings.setValue(IniKey_ViewColorFgNormal, m_colorMap["clrFgNormal"]);
181 settings.setValue(IniKey_ViewColorFgReadonly, m_colorMap["clrFgReadonly"]);
182 settings.setValue(IniKey_ViewColorFgSystem, m_colorMap["clrFgSystem"]);
183 settings.setValue(IniKey_ViewFont, m_model.font());
186 void PreferenceDialog::loadAppearance(QSettings &settings, bool import)
193 palette = QPalette();
195 color = settings.value(IniKey_BoxColorBg).value<QColor>();
196 palette.setColor(QPalette::Base, color);
198 color = settings.value(IniKey_BoxColorFg).value<QColor>();
199 palette.setColor(QPalette::Text, color);
201 font = settings.value(IniKey_BoxFont).value<QFont>();
202 ui->boxFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
204 ui->sampleEdit->setPalette(palette);
205 ui->sampleEdit->setFont(font);
209 color = settings.value(IniKey_ViewColorBgMark).value<QColor>();
210 m_colorMap["clrBgMark"] = color;
211 color = settings.value(IniKey_ViewColorBgNormal).value<QColor>();
212 m_colorMap["clrBgNormal"] = color;
214 color = settings.value(IniKey_ViewColorFgHidden).value<QColor>();
215 m_colorMap["clrFgHidden"] = color;
216 color = settings.value(IniKey_ViewColorFgMark).value<QColor>();
217 m_colorMap["clrFgMark"] = color;
218 color = settings.value(IniKey_ViewColorFgNormal).value<QColor>();
219 m_colorMap["clrFgNormal"] = color;
220 color = settings.value(IniKey_ViewColorFgReadonly).value<QColor>();
221 m_colorMap["clrFgReadonly"] = color;
222 color = settings.value(IniKey_ViewColorFgSystem).value<QColor>();
223 m_colorMap["clrFgSystem"] = color;
225 font = settings.value(IniKey_ViewFont).value<QFont>();
226 ui->viewFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
228 QHeaderView *header = ui->sampleTable->verticalHeader();
229 header->setDefaultSectionSize(QFontMetrics(font).height() * 1.5);
230 ui->sampleTable->setMinimumHeight(header->sectionSize(0) * 5);
231 ui->sampleTable->setMaximumHeight(ui->sampleTable->minimumHeight() + 2);
232 m_model.setFont(font);
237 if (settings.value(IniKey_ViewerInherit).toBool()) {
238 ui->viewerInherit->setChecked(true);
239 color = settings.value(IniKey_ViewColorBgNormal).value<QColor>();
240 palette.setColor(QPalette::Base, color);
241 color = settings.value(IniKey_ViewColorFgNormal).value<QColor>();
242 palette.setColor(QPalette::Text, color);
245 ui->viewerInherit->setChecked(false);
246 color = settings.value(IniKey_ViewerColorBg).value<QColor>();
247 palette.setColor(QPalette::Base, color);
248 color = settings.value(IniKey_ViewerColorFg).value<QColor>();
249 palette.setColor(QPalette::Text, color);
251 ui->viewerSample->setPalette(palette);
254 font = settings.value(IniKey_ViewerFont).value<QFont>();
255 ui->viewerFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
256 ui->viewerSample->setFont(font);
260 void PreferenceDialog::chooseFont()
264 QLabel *label = NULL;
266 if (sender() == ui->chooseViewerFont) {
267 font = ui->viewerSample->font();
269 else if (sender() == ui->chooseBoxFont) {
270 font = ui->sampleEdit->font();
272 else if (sender() == ui->chooseViewFont) {
273 font = m_model.font();
276 font = QFontDialog::getFont(&ok, font, this);
278 if (sender() == ui->chooseViewerFont) {
279 ui->viewerSample->setFont(font);
280 label = ui->viewerFont;
282 else if (sender() == ui->chooseBoxFont) {
283 ui->sampleEdit->setFont(font);
286 else if (sender() == ui->chooseViewFont) {
287 QHeaderView *header = ui->sampleTable->verticalHeader();
288 header->setDefaultSectionSize(QFontMetrics(font).height() * 1.5);
289 ui->sampleTable->setMinimumHeight(header->sectionSize(0) * 5);
290 ui->sampleTable->setMaximumHeight(ui->sampleTable->minimumHeight() + 2);
291 m_model.setFont(font);
293 label = ui->viewFont;
295 label->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
299 void PreferenceDialog::setControlsEnabled(bool enabled)
301 if (sender() == ui->bootSize) {
302 ui->sizeAbsolute->setEnabled(enabled);
303 ui->sizeLast->setEnabled(enabled);
304 ui->sizeRelative->setEnabled(enabled);
306 emit ui->sizeAbsolute->toggled(ui->sizeAbsolute->isChecked());
307 emit ui->sizeRelative->toggled(ui->sizeRelative->isChecked());
310 emit ui->sizeAbsolute->toggled(false);
311 emit ui->sizeRelative->toggled(false);
314 else if (sender() == ui->sizeAbsolute) {
315 ui->absoluteHeight->setEnabled(enabled);
316 ui->absoluteWidth->setEnabled(enabled);
318 else if (sender() == ui->sizeRelative) {
319 ui->relativeHeight->setEnabled(enabled);
320 ui->relativeWidth->setEnabled(enabled);
322 else if (sender() == ui->bootPos) {
323 ui->posAbsolute->setEnabled(enabled);
324 ui->posCenter->setEnabled(enabled);
325 ui->posLast->setEnabled(enabled);
326 ui->posRelative->setEnabled(enabled);
328 emit ui->posAbsolute->toggled(ui->posAbsolute->isChecked());
329 emit ui->posRelative->toggled(ui->posRelative->isChecked());
332 emit ui->posAbsolute->toggled(false);
333 emit ui->posRelative->toggled(false);
336 else if (sender() == ui->posAbsolute) {
337 ui->absoluteLeft->setEnabled(enabled);
338 ui->absoluteTop->setEnabled(enabled);
340 else if (sender() == ui->posRelative) {
341 ui->relativeLeft->setEnabled(enabled);
342 ui->relativeTop->setEnabled(enabled);
344 else if (sender() == ui->viewerInherit) {
345 ui->viewerClrBg->setEnabled(!enabled);
346 ui->viewerClrFg->setEnabled(!enabled);
348 QPalette pal = ui->viewerSample->palette();
350 pal.setColor(QPalette::Base, m_colorMap["clrBgNormal"]);
351 pal.setColor(QPalette::Text, m_colorMap["clrFgNormal"]);
355 pal.setColor(QPalette::Base, settings.value(IniKey_ViewerColorBg).value<QColor>());
356 pal.setColor(QPalette::Text, settings.value(IniKey_ViewerColorFg).value<QColor>());
358 ui->viewerSample->setPalette(pal);
360 else if (sender() == ui->enableViewerIgnoreExt) {
361 ui->viewerIgnoreExt->setEnabled(enabled);
365 void PreferenceDialog::setIgnoreExtDefault()
367 ui->viewerIgnoreExt->setPlainText(ViewerIgnoreExt());
370 void PreferenceDialog::selectBoxColor()
373 QPalette palette = ui->sampleEdit->palette();
374 if (sender() == ui->boxClrBg) {
375 color = palette.background().color();
377 else if (sender() == ui->boxClrFg) {
378 color = palette.text().color();
381 color = QColorDialog::getColor(color, this, tr("色選択"));
382 if (!color.isValid()) {
386 if (sender() == ui->boxClrBg) {
387 palette.setColor(QPalette::Base, color);
389 else if (sender() == ui->boxClrFg) {
390 palette.setColor(QPalette::Text, color);
392 ui->sampleEdit->setPalette(palette);
395 void PreferenceDialog::selectViewColor()
397 const QString objName = sender()->objectName();
398 QColor color = m_colorMap[objName];
400 color = QColorDialog::getColor(color, this, tr("色選択"));
401 if (!color.isValid()) {
405 m_colorMap[objName] = color;
409 void PreferenceDialog::selectViewerColor()
412 QPalette palette = ui->viewerSample->palette();
413 if (sender() == ui->viewerClrBg) {
414 color = palette.background().color();
416 else if (sender() == ui->viewerClrFg) {
417 color = palette.text().color();
420 color = QColorDialog::getColor(color, this, tr("色選択"));
421 if (!color.isValid()) {
425 if (sender() == ui->viewerClrBg) {
426 palette.setColor(QPalette::Base, color);
428 else if (sender() == ui->viewerClrFg) {
429 palette.setColor(QPalette::Text, color);
431 ui->viewerSample->setPalette(palette);
434 void PreferenceDialog::browseApp()
436 QStringList list = QStandardPaths::standardLocations(
437 QStandardPaths::ApplicationsLocation);
439 QString path = QFileDialog::getOpenFileName(
440 this, tr("アプリケーションを選択"), list.at(0),
441 tr("実行ファイル (*.exe *.com *.bat *.pif);;すべてのファイル (*)"));
442 #elif defined(Q_OS_MAC)
443 QString path = QFileDialog::getOpenFileName(
444 this, tr("アプリケーションを選択"), list.at(0),
445 tr("実行ファイル (*.app);;すべてのファイル (*)"));
447 QString path = QFileDialog::getOpenFileName(
448 this, tr("アプリケーションを選択"), list.at(0),
451 if (!path.isEmpty()) {
452 if (sender() == ui->editorBrowse) {
453 ui->editorPath->setText(path);
455 else if (sender() == ui->termBrowse) {
456 ui->termPath->setText(path);
461 void PreferenceDialog::importAppearance()
463 QStringList list = QStandardPaths::standardLocations(
464 QStandardPaths::DocumentsLocation);
465 QString path = QFileDialog::getOpenFileName(
466 this, tr("ファイルを選択"), list.at(0),
467 tr("設定ファイル (*.ini);;すべてのファイル (*)"));
468 if (path.isEmpty()) {
472 QSettings settings(path, QSettings::IniFormat);
473 loadAppearance(settings, true);
476 void PreferenceDialog::exportAppearance()
478 QStringList list = QStandardPaths::standardLocations(
479 QStandardPaths::DocumentsLocation);
480 QString path = QFileDialog::getSaveFileName(
481 this, tr("ファイルを選択"), list.at(0) + "/gefu_appearance.ini",
482 tr("設定ファイル (*.ini);;すべてのファイル (*)"));
483 if (path.isEmpty()) {
487 QSettings settings(path, QSettings::IniFormat);
488 saveAppearance(settings);
491 void PreferenceDialog::accept()
494 QAbstractButton *selected;
498 if (!ui->bootSize->isChecked()) {
499 settings.setValue(IniKey_BootSizeSpec, "");
502 selected = ui->sizeOptions->checkedButton();
503 settings.setValue(IniKey_BootSizeSpec, selected->objectName());
506 size = QSize(ui->absoluteWidth->value(), ui->absoluteHeight->value());
507 settings.setValue(IniKey_BootSizeAbs, size);
509 size = QSize(ui->relativeWidth->value(), ui->relativeHeight->value());
510 settings.setValue(IniKey_BootSizeRel, size);
513 if (!ui->bootPos->isChecked()) {
514 settings.setValue(IniKey_BootPosSpec, "");
517 selected = ui->posOptions->checkedButton();
518 settings.setValue(IniKey_BootPosSpec, selected->objectName());
521 pos = QPoint(ui->absoluteLeft->value(), ui->absoluteTop->value());
522 settings.setValue(IniKey_BootPosAbs, pos);
524 pos = QPoint(ui->relativeLeft->value(), ui->relativeTop->value());
525 settings.setValue(IniKey_BootPosRel, pos);
528 settings.setValue(IniKey_ResetOnBoot, ui->resetOnBoot->isChecked());
530 settings.setValue(IniKey_ConfirmExit, ui->confirmExit->isChecked());
532 settings.setValue(IniKey_CheckUpdates, ui->checkUpdates->isChecked());
535 saveAppearance(settings);
536 settings.setValue(IniKey_Darkness, ui->dark->value());
539 settings.setValue(IniKey_ConfirmCopy, ui->confirmCopy->isChecked());
540 settings.setValue(IniKey_ConfirmDelete, ui->confirmDelete->isChecked());
541 settings.setValue(IniKey_ConfirmMove, ui->confirmMove->isChecked());
542 settings.setValue(IniKey_ConfirmRename, ui->confirmRename->isChecked());
544 settings.setValue(IniKey_AutoCloseCopy, ui->autoCloseCopy->isChecked());
545 settings.setValue(IniKey_AutoCloseDelete, ui->autoCloseDelete->isChecked());
546 settings.setValue(IniKey_AutoCloseMove, ui->autoCloseMove->isChecked());
547 settings.setValue(IniKey_AutoCloseRename, ui->autoCloseRename->isChecked());
549 selected = ui->overwriteOptions->checkedButton();
550 settings.setValue(IniKey_DefaultOnCopy, selected->objectName());
552 settings.setValue(IniKey_MoveAfterCreateFolder, ui->moveAfterCreate->isChecked());
553 settings.setValue(IniKey_OpenAfterCreateFile, ui->openAfterCreate->isChecked());
556 settings.setValue(IniKey_EditorOption, ui->editorOpt->text().trimmed());
557 settings.setValue(IniKey_EditorPath, ui->editorPath->text().trimmed());
559 settings.setValue(IniKey_TerminalOption, ui->termOpt->text().trimmed());
560 settings.setValue(IniKey_TerminalPath, ui->termPath->text().trimmed());
563 settings.setValue(IniKey_ViewerFont, ui->viewerSample->font());
564 settings.setValue(IniKey_ViewerColorBg, ui->viewerSample->palette().base().color());
565 settings.setValue(IniKey_ViewerColorFg, ui->viewerSample->palette().text().color());
566 settings.setValue(IniKey_ViewerInherit, ui->viewerInherit->isChecked());
567 settings.setValue(IniKey_ViewerForceOpen, !ui->enableViewerIgnoreExt->isChecked());
568 QStringList list = ui->viewerIgnoreExt->toPlainText().split(",", QString::SkipEmptyParts);
569 QStringList::iterator it;
570 for (it = list.begin(); it != list.end(); it++) {
573 settings.setValue(IniKey_ViewerIgnoreExt, list.join(","));