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()));
49 connect(ui->clrBgMark, SIGNAL(clicked()), this, SLOT(selectViewColor()));
50 connect(ui->clrBgNormal, SIGNAL(clicked()), this, SLOT(selectViewColor()));
51 connect(ui->clrFgHidden, SIGNAL(clicked()), this, SLOT(selectViewColor()));
52 connect(ui->clrFgMark, SIGNAL(clicked()), this, SLOT(selectViewColor()));
53 connect(ui->clrFgNormal, SIGNAL(clicked()), this, SLOT(selectViewColor()));
54 connect(ui->clrFgReadonly, SIGNAL(clicked()), this, SLOT(selectViewColor()));
55 connect(ui->clrFgSystem, SIGNAL(clicked()), this, SLOT(selectViewColor()));
57 connect(ui->chooseBoxFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
58 connect(ui->chooseViewFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
60 connect(ui->importAppearance, SIGNAL(clicked()), this, SLOT(importAppearance()));
61 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);
126 ui->confirmCopy->setChecked(settings.value(IniKey_ConfirmCopy).toBool());
127 ui->confirmDelete->setChecked(settings.value(IniKey_ConfirmDelete).toBool());
128 ui->confirmMove->setChecked(settings.value(IniKey_ConfirmMove).toBool());
129 ui->confirmRename->setChecked(settings.value(IniKey_ConfirmRename).toBool());
131 ui->autoCloseCopy->setChecked(settings.value(IniKey_AutoCloseCopy).toBool());
132 ui->autoCloseDelete->setChecked(settings.value(IniKey_AutoCloseDelete).toBool());
133 ui->autoCloseMove->setChecked(settings.value(IniKey_AutoCloseMove).toBool());
134 ui->autoCloseRename->setChecked(settings.value(IniKey_AutoCloseRename).toBool());
136 strValue = settings.value(IniKey_DefaultOnCopy).toString();
137 if (strValue.isEmpty()) {
138 strValue = "owDefIfNew";
140 radioBtn = findChild<QRadioButton*>(strValue);
141 if (radioBtn == NULL) {
142 radioBtn = ui->rbOverWriteIfNew;
144 radioBtn->setChecked(true);
145 ui->moveAfterCreate->setChecked(settings.value(IniKey_MoveAfterCreateFolder).toBool());
146 ui->openAfterCreate->setChecked(settings.value(IniKey_OpenAfterCreateFile).toBool());
150 ui->editorOpt->setText(settings.value(IniKey_EditorOption).toString());
151 ui->editorPath->setText(settings.value(IniKey_EditorPath).toString());
153 ui->termOpt->setText(settings.value(IniKey_TerminalOption).toString());
154 ui->termPath->setText(settings.value(IniKey_TerminalPath).toString());
157 ui->enableViewerIgnoreExt->setChecked(true);
158 ui->enableViewerIgnoreExt->setChecked(!settings.value(IniKey_ViewerForceOpen).toBool());
159 ui->viewerIgnoreExt->setPlainText(settings.value(IniKey_ViewerIgnoreExt).toString());
162 PreferenceDialog::~PreferenceDialog()
167 void PreferenceDialog::saveAppearance(QSettings &settings)
169 QFont font = ui->sampleEdit->font();
170 QPalette palette = ui->sampleEdit->palette();
171 settings.setValue(IniKey_BoxColorBg, palette.base().color());
172 settings.setValue(IniKey_BoxColorFg, palette.text().color());
173 settings.setValue(IniKey_BoxFont, font);
175 settings.setValue(IniKey_ViewColorBgMark, m_colorMap["clrBgMark"]);
176 settings.setValue(IniKey_ViewColorBgNormal, m_colorMap["clrBgNormal"]);
177 settings.setValue(IniKey_ViewColorFgHidden, m_colorMap["clrFgHidden"]);
178 settings.setValue(IniKey_ViewColorFgMark, m_colorMap["clrFgMark"]);
179 settings.setValue(IniKey_ViewColorFgNormal, m_colorMap["clrFgNormal"]);
180 settings.setValue(IniKey_ViewColorFgReadonly, m_colorMap["clrFgReadonly"]);
181 settings.setValue(IniKey_ViewColorFgSystem, m_colorMap["clrFgSystem"]);
182 settings.setValue(IniKey_ViewFont, m_model.font());
185 void PreferenceDialog::loadAppearance(QSettings &settings, bool import)
192 palette = QPalette();
194 color = settings.value(IniKey_BoxColorBg).value<QColor>();
195 palette.setColor(QPalette::Base, color);
197 color = settings.value(IniKey_BoxColorFg).value<QColor>();
198 palette.setColor(QPalette::Text, color);
200 font = settings.value(IniKey_BoxFont).value<QFont>();
201 ui->boxFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
203 ui->sampleEdit->setPalette(palette);
204 ui->sampleEdit->setFont(font);
208 color = settings.value(IniKey_ViewColorBgMark).value<QColor>();
209 m_colorMap["clrBgMark"] = color;
210 color = settings.value(IniKey_ViewColorBgNormal).value<QColor>();
211 m_colorMap["clrBgNormal"] = color;
213 color = settings.value(IniKey_ViewColorFgHidden).value<QColor>();
214 m_colorMap["clrFgHidden"] = color;
215 color = settings.value(IniKey_ViewColorFgMark).value<QColor>();
216 m_colorMap["clrFgMark"] = color;
217 color = settings.value(IniKey_ViewColorFgNormal).value<QColor>();
218 m_colorMap["clrFgNormal"] = color;
219 color = settings.value(IniKey_ViewColorFgReadonly).value<QColor>();
220 m_colorMap["clrFgReadonly"] = color;
221 color = settings.value(IniKey_ViewColorFgSystem).value<QColor>();
222 m_colorMap["clrFgSystem"] = color;
224 font = settings.value(IniKey_ViewFont).value<QFont>();
225 ui->viewFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
227 QHeaderView *header = ui->sampleTable->verticalHeader();
228 header->setDefaultSectionSize(QFontMetrics(font).height() * 1.5);
229 ui->sampleTable->setMinimumHeight(header->sectionSize(0) * 5);
230 ui->sampleTable->setMaximumHeight(ui->sampleTable->minimumHeight() + 2);
231 m_model.setFont(font);
236 if (settings.value(IniKey_ViewerInherit).toBool()) {
237 ui->viewerInherit->setChecked(true);
238 color = settings.value(IniKey_ViewColorBgNormal).value<QColor>();
239 palette.setColor(QPalette::Base, color);
240 color = settings.value(IniKey_ViewColorFgNormal).value<QColor>();
241 palette.setColor(QPalette::Text, color);
244 ui->viewerInherit->setChecked(false);
245 color = settings.value(IniKey_ViewerColorBg).value<QColor>();
246 palette.setColor(QPalette::Base, color);
247 color = settings.value(IniKey_ViewerColorFg).value<QColor>();
248 palette.setColor(QPalette::Text, color);
250 ui->viewerSample->setPalette(palette);
253 font = settings.value(IniKey_ViewerFont).value<QFont>();
254 ui->viewerFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
255 ui->viewerSample->setFont(font);
259 void PreferenceDialog::chooseFont()
263 QLabel *label = NULL;
265 if (sender() == ui->chooseViewerFont) {
266 font = ui->viewerSample->font();
268 else if (sender() == ui->chooseBoxFont) {
269 font = ui->sampleEdit->font();
271 else if (sender() == ui->chooseViewFont) {
272 font = m_model.font();
275 font = QFontDialog::getFont(&ok, font, this);
277 if (sender() == ui->chooseViewerFont) {
278 ui->viewerSample->setFont(font);
279 label = ui->viewerFont;
281 else if (sender() == ui->chooseBoxFont) {
282 ui->sampleEdit->setFont(font);
285 else if (sender() == ui->chooseViewFont) {
286 QHeaderView *header = ui->sampleTable->verticalHeader();
287 header->setDefaultSectionSize(QFontMetrics(font).height() * 1.5);
288 ui->sampleTable->setMinimumHeight(header->sectionSize(0) * 5);
289 ui->sampleTable->setMaximumHeight(ui->sampleTable->minimumHeight() + 2);
290 m_model.setFont(font);
292 label = ui->viewFont;
294 label->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
298 void PreferenceDialog::setControlsEnabled(bool enabled)
300 if (sender() == ui->bootSize) {
301 ui->sizeAbsolute->setEnabled(enabled);
302 ui->sizeLast->setEnabled(enabled);
303 ui->sizeRelative->setEnabled(enabled);
305 emit ui->sizeAbsolute->toggled(ui->sizeAbsolute->isChecked());
306 emit ui->sizeRelative->toggled(ui->sizeRelative->isChecked());
309 emit ui->sizeAbsolute->toggled(false);
310 emit ui->sizeRelative->toggled(false);
313 else if (sender() == ui->sizeAbsolute) {
314 ui->absoluteHeight->setEnabled(enabled);
315 ui->absoluteWidth->setEnabled(enabled);
317 else if (sender() == ui->sizeRelative) {
318 ui->relativeHeight->setEnabled(enabled);
319 ui->relativeWidth->setEnabled(enabled);
321 else if (sender() == ui->bootPos) {
322 ui->posAbsolute->setEnabled(enabled);
323 ui->posCenter->setEnabled(enabled);
324 ui->posLast->setEnabled(enabled);
325 ui->posRelative->setEnabled(enabled);
327 emit ui->posAbsolute->toggled(ui->posAbsolute->isChecked());
328 emit ui->posRelative->toggled(ui->posRelative->isChecked());
331 emit ui->posAbsolute->toggled(false);
332 emit ui->posRelative->toggled(false);
335 else if (sender() == ui->posAbsolute) {
336 ui->absoluteLeft->setEnabled(enabled);
337 ui->absoluteTop->setEnabled(enabled);
339 else if (sender() == ui->posRelative) {
340 ui->relativeLeft->setEnabled(enabled);
341 ui->relativeTop->setEnabled(enabled);
343 else if (sender() == ui->viewerInherit) {
344 ui->viewerClrBg->setEnabled(!enabled);
345 ui->viewerClrFg->setEnabled(!enabled);
347 QPalette pal = ui->viewerSample->palette();
349 pal.setColor(QPalette::Base, m_colorMap["clrBgNormal"]);
350 pal.setColor(QPalette::Text, m_colorMap["clrFgNormal"]);
354 pal.setColor(QPalette::Base, settings.value(IniKey_ViewerColorBg).value<QColor>());
355 pal.setColor(QPalette::Text, settings.value(IniKey_ViewerColorFg).value<QColor>());
357 ui->viewerSample->setPalette(pal);
359 else if (sender() == ui->enableViewerIgnoreExt) {
360 ui->viewerIgnoreExt->setEnabled(enabled);
364 void PreferenceDialog::setIgnoreExtDefault()
366 ui->viewerIgnoreExt->setPlainText(ViewerIgnoreExt());
369 void PreferenceDialog::selectBoxColor()
372 QPalette palette = ui->sampleEdit->palette();
373 if (sender() == ui->boxClrBg) {
374 color = palette.background().color();
376 else if (sender() == ui->boxClrFg) {
377 color = palette.text().color();
380 color = QColorDialog::getColor(color, this, tr("色選択"));
381 if (!color.isValid()) {
385 if (sender() == ui->boxClrBg) {
386 palette.setColor(QPalette::Base, color);
388 else if (sender() == ui->boxClrFg) {
389 palette.setColor(QPalette::Text, color);
391 ui->sampleEdit->setPalette(palette);
394 void PreferenceDialog::selectViewColor()
396 const QString objName = sender()->objectName();
397 QColor color = m_colorMap[objName];
399 color = QColorDialog::getColor(color, this, tr("色選択"));
400 if (!color.isValid()) {
404 m_colorMap[objName] = color;
408 void PreferenceDialog::selectViewerColor()
411 QPalette palette = ui->viewerSample->palette();
412 if (sender() == ui->viewerClrBg) {
413 color = palette.background().color();
415 else if (sender() == ui->viewerClrFg) {
416 color = palette.text().color();
419 color = QColorDialog::getColor(color, this, tr("色選択"));
420 if (!color.isValid()) {
424 if (sender() == ui->viewerClrBg) {
425 palette.setColor(QPalette::Base, color);
427 else if (sender() == ui->viewerClrFg) {
428 palette.setColor(QPalette::Text, color);
430 ui->viewerSample->setPalette(palette);
433 void PreferenceDialog::browseApp()
435 QStringList list = QStandardPaths::standardLocations(
436 QStandardPaths::ApplicationsLocation);
438 QString path = QFileDialog::getOpenFileName(
439 this, tr("アプリケーションを選択"), list.at(0),
440 tr("実行ファイル (*.exe *.com *.bat *.pif);;すべてのファイル (*)"));
441 #elif defined(Q_OS_MAC)
442 QString path = QFileDialog::getOpenFileName(
443 this, tr("アプリケーションを選択"), list.at(0),
444 tr("実行ファイル (*.app);;すべてのファイル (*)"));
446 QString path = QFileDialog::getOpenFileName(
447 this, tr("アプリケーションを選択"), list.at(0),
450 if (!path.isEmpty()) {
451 if (sender() == ui->editorBrowse) {
452 ui->editorPath->setText(path);
454 else if (sender() == ui->termBrowse) {
455 ui->termPath->setText(path);
460 void PreferenceDialog::importAppearance()
462 QStringList list = QStandardPaths::standardLocations(
463 QStandardPaths::DocumentsLocation);
464 QString path = QFileDialog::getOpenFileName(
465 this, tr("ファイルを選択"), list.at(0),
466 tr("設定ファイル (*.ini);;すべてのファイル (*)"));
467 if (path.isEmpty()) {
471 QSettings settings(path, QSettings::IniFormat);
472 loadAppearance(settings, true);
475 void PreferenceDialog::exportAppearance()
477 QStringList list = QStandardPaths::standardLocations(
478 QStandardPaths::DocumentsLocation);
479 QString path = QFileDialog::getSaveFileName(
480 this, tr("ファイルを選択"), list.at(0) + "/gefu_appearance.ini",
481 tr("設定ファイル (*.ini);;すべてのファイル (*)"));
482 if (path.isEmpty()) {
486 QSettings settings(path, QSettings::IniFormat);
487 saveAppearance(settings);
490 void PreferenceDialog::accept()
493 QAbstractButton *selected;
497 if (!ui->bootSize->isChecked()) {
498 settings.setValue(IniKey_BootSizeSpec, "");
501 selected = ui->sizeOptions->checkedButton();
502 settings.setValue(IniKey_BootSizeSpec, selected->objectName());
505 size = QSize(ui->absoluteWidth->value(), ui->absoluteHeight->value());
506 settings.setValue(IniKey_BootSizeAbs, size);
508 size = QSize(ui->relativeWidth->value(), ui->relativeHeight->value());
509 settings.setValue(IniKey_BootSizeRel, size);
512 if (!ui->bootPos->isChecked()) {
513 settings.setValue(IniKey_BootPosSpec, "");
516 selected = ui->posOptions->checkedButton();
517 settings.setValue(IniKey_BootPosSpec, selected->objectName());
520 pos = QPoint(ui->absoluteLeft->value(), ui->absoluteTop->value());
521 settings.setValue(IniKey_BootPosAbs, pos);
523 pos = QPoint(ui->relativeLeft->value(), ui->relativeTop->value());
524 settings.setValue(IniKey_BootPosRel, pos);
527 settings.setValue(IniKey_ResetOnBoot, ui->resetOnBoot->isChecked());
529 settings.setValue(IniKey_ConfirmExit, ui->confirmExit->isChecked());
531 settings.setValue(IniKey_CheckUpdates, ui->checkUpdates->isChecked());
534 saveAppearance(settings);
537 settings.setValue(IniKey_ConfirmCopy, ui->confirmCopy->isChecked());
538 settings.setValue(IniKey_ConfirmDelete, ui->confirmDelete->isChecked());
539 settings.setValue(IniKey_ConfirmMove, ui->confirmMove->isChecked());
540 settings.setValue(IniKey_ConfirmRename, ui->confirmRename->isChecked());
542 settings.setValue(IniKey_AutoCloseCopy, ui->autoCloseCopy->isChecked());
543 settings.setValue(IniKey_AutoCloseDelete, ui->autoCloseDelete->isChecked());
544 settings.setValue(IniKey_AutoCloseMove, ui->autoCloseMove->isChecked());
545 settings.setValue(IniKey_AutoCloseRename, ui->autoCloseRename->isChecked());
547 selected = ui->overwriteOptions->checkedButton();
548 settings.setValue(IniKey_DefaultOnCopy, selected->objectName());
550 settings.setValue(IniKey_MoveAfterCreateFolder, ui->moveAfterCreate->isChecked());
551 settings.setValue(IniKey_OpenAfterCreateFile, ui->openAfterCreate->isChecked());
554 settings.setValue(IniKey_EditorOption, ui->editorOpt->text().trimmed());
555 settings.setValue(IniKey_EditorPath, ui->editorPath->text().trimmed());
557 settings.setValue(IniKey_TerminalOption, ui->termOpt->text().trimmed());
558 settings.setValue(IniKey_TerminalPath, ui->termPath->text().trimmed());
561 settings.setValue(IniKey_ViewerFont, ui->viewerSample->font());
562 settings.setValue(IniKey_ViewerColorBg, ui->viewerSample->palette().base().color());
563 settings.setValue(IniKey_ViewerColorFg, ui->viewerSample->palette().text().color());
564 settings.setValue(IniKey_ViewerInherit, ui->viewerInherit->isChecked());
565 settings.setValue(IniKey_ViewerForceOpen, !ui->enableViewerIgnoreExt->isChecked());
566 QStringList list = ui->viewerIgnoreExt->toPlainText().split(",", QString::SkipEmptyParts);
567 QStringList::iterator it;
568 for (it = list.begin(); it != list.end(); it++) {
571 settings.setValue(IniKey_ViewerIgnoreExt, list.join(","));