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->browseArchiver, SIGNAL(clicked()), this, SLOT(browseApp()));
63 connect(ui->browseEditor, SIGNAL(clicked()), this, SLOT(browseApp()));
64 connect(ui->browseTerminal, SIGNAL(clicked()), this, SLOT(browseApp()));
66 connect(ui->chooseViewerFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
67 connect(ui->viewerClrBg, SIGNAL(clicked()), this, SLOT(selectViewerColor()));
68 connect(ui->viewerClrFg, SIGNAL(clicked()), this, SLOT(selectViewerColor()));
69 connect(ui->viewerInherit, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
70 connect(ui->enableViewerIgnoreExt, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool)));
71 connect(ui->defaultIgnoreExt, SIGNAL(clicked()), this, SLOT(setIgnoreExtDefault()));
73 // 現在の設定で各コントロールを初期化する
78 QRadioButton *radioBtn;
82 ui->bootSize->setChecked(true);
83 strValue = settings.value(IniKey_BootSizeSpec).toString();
84 radioBtn = findChild<QRadioButton*>(strValue);
85 if (radioBtn == NULL) {
86 radioBtn = ui->sizeRelative;
88 radioBtn->setChecked(true);
89 if (strValue.isEmpty()) {
90 ui->bootSize->setChecked(false);
92 size = settings.value(IniKey_BootSizeAbs).toSize();
93 ui->absoluteWidth->setValue(size.width());
94 ui->absoluteHeight->setValue(size.height());
95 size = settings.value(IniKey_BootSizeRel).toSize();
96 ui->relativeWidth->setValue(size.width());
97 ui->relativeHeight->setValue(size.height());
99 ui->bootPos->setChecked(true);
100 strValue = settings.value(IniKey_BootPosSpec).toString();
101 radioBtn = findChild<QRadioButton*>(strValue);
102 if (radioBtn == NULL) {
103 radioBtn = ui->posCenter;
105 radioBtn->setChecked(true);
106 if (strValue.isEmpty()) {
107 ui->bootPos->setChecked(false);
109 point = settings.value(IniKey_BootPosAbs).toPoint();
110 ui->absoluteLeft->setValue(point.x());
111 ui->absoluteTop->setValue(point.y());
112 point = settings.value(IniKey_BootPosRel).toPoint();
113 ui->relativeLeft->setValue(point.x());
114 ui->relativeTop->setValue(point.y());
116 ui->resetOnBoot->setChecked(settings.value(IniKey_ResetOnBoot).toBool());
118 ui->checkUpdates->setChecked(settings.value(IniKey_CheckUpdates).toBool());
120 ui->confirmExit->setChecked(settings.value(IniKey_ConfirmExit).toBool());
122 //>>>>> 色とフォント、テキストビューア
123 loadAppearance(settings, false);
124 ui->dark->setValue(settings.value(IniKey_Darkness).toInt());
128 ui->confirmCopy->setChecked(settings.value(IniKey_ConfirmCopy).toBool());
129 ui->confirmDelete->setChecked(settings.value(IniKey_ConfirmDelete).toBool());
130 ui->confirmMove->setChecked(settings.value(IniKey_ConfirmMove).toBool());
131 ui->confirmRename->setChecked(settings.value(IniKey_ConfirmRename).toBool());
133 ui->autoCloseCopy->setChecked(settings.value(IniKey_AutoCloseCopy).toBool());
134 ui->autoCloseDelete->setChecked(settings.value(IniKey_AutoCloseDelete).toBool());
135 ui->autoCloseMove->setChecked(settings.value(IniKey_AutoCloseMove).toBool());
136 ui->autoCloseRename->setChecked(settings.value(IniKey_AutoCloseRename).toBool());
138 strValue = settings.value(IniKey_DefaultOnCopy).toString();
139 if (strValue.isEmpty()) {
140 strValue = "owDefIfNew";
142 radioBtn = findChild<QRadioButton*>(strValue);
143 if (radioBtn == NULL) {
144 radioBtn = ui->rbOverWriteIfNew;
146 radioBtn->setChecked(true);
147 ui->moveAfterCreate->setChecked(settings.value(IniKey_MoveAfterCreateFolder).toBool());
148 ui->openAfterCreate->setChecked(settings.value(IniKey_OpenAfterCreateFile).toBool());
152 ui->editorPath->setText(settings.value(IniKey_PathEditor).toString());
154 ui->terminalPath->setText(settings.value(IniKey_PathTerminal).toString());
156 ui->archiverPath->setText(settings.value(IniKey_PathArchiver).toString());
159 ui->enableViewerIgnoreExt->setChecked(true);
160 ui->enableViewerIgnoreExt->setChecked(!settings.value(IniKey_ViewerForceOpen).toBool());
161 ui->viewerIgnoreExt->setPlainText(settings.value(IniKey_ViewerIgnoreExt).toString());
164 PreferenceDialog::~PreferenceDialog()
169 void PreferenceDialog::saveAppearance(QSettings &settings)
171 QFont font = ui->sampleEdit->font();
172 QPalette palette = ui->sampleEdit->palette();
173 settings.setValue(IniKey_BoxColorBg, palette.base().color());
174 settings.setValue(IniKey_BoxColorFg, palette.text().color());
175 settings.setValue(IniKey_BoxFont, font);
177 settings.setValue(IniKey_ViewColorBgMark, m_colorMap["clrBgMark"]);
178 settings.setValue(IniKey_ViewColorBgNormal, m_colorMap["clrBgNormal"]);
179 settings.setValue(IniKey_ViewColorFgHidden, m_colorMap["clrFgHidden"]);
180 settings.setValue(IniKey_ViewColorFgMark, m_colorMap["clrFgMark"]);
181 settings.setValue(IniKey_ViewColorFgNormal, m_colorMap["clrFgNormal"]);
182 settings.setValue(IniKey_ViewColorFgReadonly, m_colorMap["clrFgReadonly"]);
183 settings.setValue(IniKey_ViewColorFgSystem, m_colorMap["clrFgSystem"]);
184 settings.setValue(IniKey_ViewFont, m_model.font());
187 void PreferenceDialog::loadAppearance(QSettings &settings, bool import)
194 palette = QPalette();
196 color = settings.value(IniKey_BoxColorBg).value<QColor>();
197 palette.setColor(QPalette::Base, color);
199 color = settings.value(IniKey_BoxColorFg).value<QColor>();
200 palette.setColor(QPalette::Text, color);
202 font = settings.value(IniKey_BoxFont).value<QFont>();
203 ui->boxFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
205 ui->sampleEdit->setPalette(palette);
206 ui->sampleEdit->setFont(font);
210 color = settings.value(IniKey_ViewColorBgMark).value<QColor>();
211 m_colorMap["clrBgMark"] = color;
212 color = settings.value(IniKey_ViewColorBgNormal).value<QColor>();
213 m_colorMap["clrBgNormal"] = color;
215 color = settings.value(IniKey_ViewColorFgHidden).value<QColor>();
216 m_colorMap["clrFgHidden"] = color;
217 color = settings.value(IniKey_ViewColorFgMark).value<QColor>();
218 m_colorMap["clrFgMark"] = color;
219 color = settings.value(IniKey_ViewColorFgNormal).value<QColor>();
220 m_colorMap["clrFgNormal"] = color;
221 color = settings.value(IniKey_ViewColorFgReadonly).value<QColor>();
222 m_colorMap["clrFgReadonly"] = color;
223 color = settings.value(IniKey_ViewColorFgSystem).value<QColor>();
224 m_colorMap["clrFgSystem"] = color;
226 font = settings.value(IniKey_ViewFont).value<QFont>();
227 ui->viewFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
229 QHeaderView *header = ui->sampleTable->verticalHeader();
230 header->setDefaultSectionSize(QFontMetrics(font).height() * 1.5);
231 ui->sampleTable->setMinimumHeight(header->sectionSize(0) * 5);
232 ui->sampleTable->setMaximumHeight(ui->sampleTable->minimumHeight() + 2);
233 m_model.setFont(font);
238 if (settings.value(IniKey_ViewerInherit).toBool()) {
239 ui->viewerInherit->setChecked(true);
240 color = settings.value(IniKey_ViewColorBgNormal).value<QColor>();
241 palette.setColor(QPalette::Base, color);
242 color = settings.value(IniKey_ViewColorFgNormal).value<QColor>();
243 palette.setColor(QPalette::Text, color);
246 ui->viewerInherit->setChecked(false);
247 color = settings.value(IniKey_ViewerColorBg).value<QColor>();
248 palette.setColor(QPalette::Base, color);
249 color = settings.value(IniKey_ViewerColorFg).value<QColor>();
250 palette.setColor(QPalette::Text, color);
252 ui->viewerSample->setPalette(palette);
255 font = settings.value(IniKey_ViewerFont).value<QFont>();
256 ui->viewerFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
257 ui->viewerSample->setFont(font);
261 void PreferenceDialog::chooseFont()
265 QLabel *label = NULL;
267 if (sender() == ui->chooseViewerFont) {
268 font = ui->viewerSample->font();
270 else if (sender() == ui->chooseBoxFont) {
271 font = ui->sampleEdit->font();
273 else if (sender() == ui->chooseViewFont) {
274 font = m_model.font();
277 font = QFontDialog::getFont(&ok, font, this);
279 if (sender() == ui->chooseViewerFont) {
280 ui->viewerSample->setFont(font);
281 label = ui->viewerFont;
283 else if (sender() == ui->chooseBoxFont) {
284 ui->sampleEdit->setFont(font);
287 else if (sender() == ui->chooseViewFont) {
288 QHeaderView *header = ui->sampleTable->verticalHeader();
289 header->setDefaultSectionSize(QFontMetrics(font).height() * 1.5);
290 ui->sampleTable->setMinimumHeight(header->sectionSize(0) * 5);
291 ui->sampleTable->setMaximumHeight(ui->sampleTable->minimumHeight() + 2);
292 m_model.setFont(font);
294 label = ui->viewFont;
296 label->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
300 void PreferenceDialog::setControlsEnabled(bool enabled)
302 if (sender() == ui->bootSize) {
303 ui->sizeAbsolute->setEnabled(enabled);
304 ui->sizeLast->setEnabled(enabled);
305 ui->sizeRelative->setEnabled(enabled);
307 emit ui->sizeAbsolute->toggled(ui->sizeAbsolute->isChecked());
308 emit ui->sizeRelative->toggled(ui->sizeRelative->isChecked());
311 emit ui->sizeAbsolute->toggled(false);
312 emit ui->sizeRelative->toggled(false);
315 else if (sender() == ui->sizeAbsolute) {
316 ui->absoluteHeight->setEnabled(enabled);
317 ui->absoluteWidth->setEnabled(enabled);
319 else if (sender() == ui->sizeRelative) {
320 ui->relativeHeight->setEnabled(enabled);
321 ui->relativeWidth->setEnabled(enabled);
323 else if (sender() == ui->bootPos) {
324 ui->posAbsolute->setEnabled(enabled);
325 ui->posCenter->setEnabled(enabled);
326 ui->posLast->setEnabled(enabled);
327 ui->posRelative->setEnabled(enabled);
329 emit ui->posAbsolute->toggled(ui->posAbsolute->isChecked());
330 emit ui->posRelative->toggled(ui->posRelative->isChecked());
333 emit ui->posAbsolute->toggled(false);
334 emit ui->posRelative->toggled(false);
337 else if (sender() == ui->posAbsolute) {
338 ui->absoluteLeft->setEnabled(enabled);
339 ui->absoluteTop->setEnabled(enabled);
341 else if (sender() == ui->posRelative) {
342 ui->relativeLeft->setEnabled(enabled);
343 ui->relativeTop->setEnabled(enabled);
345 else if (sender() == ui->viewerInherit) {
346 ui->viewerClrBg->setEnabled(!enabled);
347 ui->viewerClrFg->setEnabled(!enabled);
349 QPalette pal = ui->viewerSample->palette();
351 pal.setColor(QPalette::Base, m_colorMap["clrBgNormal"]);
352 pal.setColor(QPalette::Text, m_colorMap["clrFgNormal"]);
356 pal.setColor(QPalette::Base, settings.value(IniKey_ViewerColorBg).value<QColor>());
357 pal.setColor(QPalette::Text, settings.value(IniKey_ViewerColorFg).value<QColor>());
359 ui->viewerSample->setPalette(pal);
361 else if (sender() == ui->enableViewerIgnoreExt) {
362 ui->viewerIgnoreExt->setEnabled(enabled);
366 void PreferenceDialog::setIgnoreExtDefault()
368 ui->viewerIgnoreExt->setPlainText(ViewerIgnoreExt());
371 void PreferenceDialog::selectBoxColor()
374 QPalette palette = ui->sampleEdit->palette();
375 if (sender() == ui->boxClrBg) {
376 color = palette.background().color();
378 else if (sender() == ui->boxClrFg) {
379 color = palette.text().color();
382 color = QColorDialog::getColor(color, this, tr("色選択"));
383 if (!color.isValid()) {
387 if (sender() == ui->boxClrBg) {
388 palette.setColor(QPalette::Base, color);
390 else if (sender() == ui->boxClrFg) {
391 palette.setColor(QPalette::Text, color);
393 ui->sampleEdit->setPalette(palette);
396 void PreferenceDialog::selectViewColor()
398 const QString objName = sender()->objectName();
399 QColor color = m_colorMap[objName];
401 color = QColorDialog::getColor(color, this, tr("色選択"));
402 if (!color.isValid()) {
406 m_colorMap[objName] = color;
410 void PreferenceDialog::selectViewerColor()
413 QPalette palette = ui->viewerSample->palette();
414 if (sender() == ui->viewerClrBg) {
415 color = palette.background().color();
417 else if (sender() == ui->viewerClrFg) {
418 color = palette.text().color();
421 color = QColorDialog::getColor(color, this, tr("色選択"));
422 if (!color.isValid()) {
426 if (sender() == ui->viewerClrBg) {
427 palette.setColor(QPalette::Base, color);
429 else if (sender() == ui->viewerClrFg) {
430 palette.setColor(QPalette::Text, color);
432 ui->viewerSample->setPalette(palette);
435 void PreferenceDialog::browseApp()
437 QStringList list = QStandardPaths::standardLocations(
438 QStandardPaths::ApplicationsLocation);
440 QString path = QFileDialog::getOpenFileName(
441 this, tr("アプリケーションを選択"), getenv("PROGRAMFILES"),
442 tr("実行ファイル (*.exe *.com *.bat *.pif);;すべてのファイル (*)"));
443 #elif defined(Q_OS_MAC)
444 QString path = QFileDialog::getOpenFileName(
445 this, tr("アプリケーションを選択"), list.at(0),
446 tr("実行ファイル (*.app);;すべてのファイル (*)"));
448 QString path = QFileDialog::getOpenFileName(
449 this, tr("アプリケーションを選択"), list.at(0),
452 if (!path.isEmpty()) {
453 if (path.indexOf(" ") != -1) {
457 if (sender() == ui->browseEditor) {
458 ui->editorPath->setText(path);
460 else if (sender() == ui->browseTerminal) {
461 ui->terminalPath->setText(path);
463 else if (sender() == ui->browseArchiver) {
464 ui->archiverPath->setText(path);
469 void PreferenceDialog::importAppearance()
471 QStringList list = QStandardPaths::standardLocations(
472 QStandardPaths::DocumentsLocation);
473 QString path = QFileDialog::getOpenFileName(
474 this, tr("ファイルを選択"), list.at(0),
475 tr("設定ファイル (*.ini);;すべてのファイル (*)"));
476 if (path.isEmpty()) {
480 QSettings settings(path, QSettings::IniFormat);
481 loadAppearance(settings, true);
484 void PreferenceDialog::exportAppearance()
486 QStringList list = QStandardPaths::standardLocations(
487 QStandardPaths::DocumentsLocation);
488 QString path = QFileDialog::getSaveFileName(
489 this, tr("ファイルを選択"), list.at(0) + "/gefu_appearance.ini",
490 tr("設定ファイル (*.ini);;すべてのファイル (*)"));
491 if (path.isEmpty()) {
495 QSettings settings(path, QSettings::IniFormat);
496 saveAppearance(settings);
499 void PreferenceDialog::accept()
502 QAbstractButton *selected;
506 if (!ui->bootSize->isChecked()) {
507 settings.setValue(IniKey_BootSizeSpec, "");
510 selected = ui->sizeOptions->checkedButton();
511 settings.setValue(IniKey_BootSizeSpec, selected->objectName());
514 size = QSize(ui->absoluteWidth->value(), ui->absoluteHeight->value());
515 settings.setValue(IniKey_BootSizeAbs, size);
517 size = QSize(ui->relativeWidth->value(), ui->relativeHeight->value());
518 settings.setValue(IniKey_BootSizeRel, size);
521 if (!ui->bootPos->isChecked()) {
522 settings.setValue(IniKey_BootPosSpec, "");
525 selected = ui->posOptions->checkedButton();
526 settings.setValue(IniKey_BootPosSpec, selected->objectName());
529 pos = QPoint(ui->absoluteLeft->value(), ui->absoluteTop->value());
530 settings.setValue(IniKey_BootPosAbs, pos);
532 pos = QPoint(ui->relativeLeft->value(), ui->relativeTop->value());
533 settings.setValue(IniKey_BootPosRel, pos);
536 settings.setValue(IniKey_ResetOnBoot, ui->resetOnBoot->isChecked());
538 settings.setValue(IniKey_ConfirmExit, ui->confirmExit->isChecked());
540 settings.setValue(IniKey_CheckUpdates, ui->checkUpdates->isChecked());
543 saveAppearance(settings);
544 settings.setValue(IniKey_Darkness, ui->dark->value());
547 settings.setValue(IniKey_ConfirmCopy, ui->confirmCopy->isChecked());
548 settings.setValue(IniKey_ConfirmDelete, ui->confirmDelete->isChecked());
549 settings.setValue(IniKey_ConfirmMove, ui->confirmMove->isChecked());
550 settings.setValue(IniKey_ConfirmRename, ui->confirmRename->isChecked());
552 settings.setValue(IniKey_AutoCloseCopy, ui->autoCloseCopy->isChecked());
553 settings.setValue(IniKey_AutoCloseDelete, ui->autoCloseDelete->isChecked());
554 settings.setValue(IniKey_AutoCloseMove, ui->autoCloseMove->isChecked());
555 settings.setValue(IniKey_AutoCloseRename, ui->autoCloseRename->isChecked());
557 selected = ui->overwriteOptions->checkedButton();
558 settings.setValue(IniKey_DefaultOnCopy, selected->objectName());
560 settings.setValue(IniKey_MoveAfterCreateFolder, ui->moveAfterCreate->isChecked());
561 settings.setValue(IniKey_OpenAfterCreateFile, ui->openAfterCreate->isChecked());
564 settings.setValue(IniKey_PathEditor, ui->editorPath->text().trimmed());
565 settings.setValue(IniKey_PathTerminal, ui->terminalPath->text().trimmed());
566 settings.setValue(IniKey_PathArchiver, ui->archiverPath->text().trimmed());
569 settings.setValue(IniKey_ViewerFont, ui->viewerSample->font());
570 settings.setValue(IniKey_ViewerColorBg, ui->viewerSample->palette().base().color());
571 settings.setValue(IniKey_ViewerColorFg, ui->viewerSample->palette().text().color());
572 settings.setValue(IniKey_ViewerInherit, ui->viewerInherit->isChecked());
573 settings.setValue(IniKey_ViewerForceOpen, !ui->enableViewerIgnoreExt->isChecked());
574 QStringList list = ui->viewerIgnoreExt->toPlainText().split(",", QString::SkipEmptyParts);
575 QStringList::iterator it;
576 for (it = list.begin(); it != list.end(); it++) {
579 settings.setValue(IniKey_ViewerIgnoreExt, list.join(","));