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->confirmExit->setChecked(settings.value(IniKey_ConfirmExit).toBool());
83 ui->bootSize->setChecked(true);
84 strValue = settings.value(IniKey_BootSizeSpec).toString();
85 radioBtn = findChild<QRadioButton*>(strValue);
86 if (radioBtn == NULL) {
87 radioBtn = ui->sizeRelative;
89 radioBtn->setChecked(true);
90 if (strValue.isEmpty()) {
91 ui->bootSize->setChecked(false);
93 size = settings.value(IniKey_BootSizeAbs).toSize();
94 ui->absoluteWidth->setValue(size.width());
95 ui->absoluteHeight->setValue(size.height());
96 size = settings.value(IniKey_BootSizeRel).toSize();
97 ui->relativeWidth->setValue(size.width());
98 ui->relativeHeight->setValue(size.height());
100 ui->bootPos->setChecked(true);
101 strValue = settings.value(IniKey_BootPosSpec).toString();
102 radioBtn = findChild<QRadioButton*>(strValue);
103 if (radioBtn == NULL) {
104 radioBtn = ui->posCenter;
106 radioBtn->setChecked(true);
107 if (strValue.isEmpty()) {
108 ui->bootPos->setChecked(false);
110 point = settings.value(IniKey_BootPosAbs).toPoint();
111 ui->absoluteLeft->setValue(point.x());
112 ui->absoluteTop->setValue(point.y());
113 point = settings.value(IniKey_BootPosRel).toPoint();
114 ui->relativeLeft->setValue(point.x());
115 ui->relativeTop->setValue(point.y());
117 ui->resetOnBoot->setChecked(settings.value(IniKey_ResetOnBoot).toBool());
119 //>>>>> 色とフォント、テキストビューア
120 loadAppearance(settings, false);
124 ui->confirmCopy->setChecked(settings.value(IniKey_ConfirmCopy).toBool());
125 ui->confirmDelete->setChecked(settings.value(IniKey_ConfirmDelete).toBool());
126 ui->confirmMove->setChecked(settings.value(IniKey_ConfirmMove).toBool());
127 ui->confirmRename->setChecked(settings.value(IniKey_ConfirmRename).toBool());
129 ui->autoCloseCopy->setChecked(settings.value(IniKey_AutoCloseCopy).toBool());
130 ui->autoCloseDelete->setChecked(settings.value(IniKey_AutoCloseDelete).toBool());
131 ui->autoCloseMove->setChecked(settings.value(IniKey_AutoCloseMove).toBool());
132 ui->autoCloseRename->setChecked(settings.value(IniKey_AutoCloseRename).toBool());
134 strValue = settings.value(IniKey_DefaultOnCopy).toString();
135 if (strValue.isEmpty()) {
136 strValue = "owDefIfNew";
138 radioBtn = findChild<QRadioButton*>(strValue);
139 if (radioBtn == NULL) {
140 radioBtn = ui->rbOverWriteIfNew;
142 radioBtn->setChecked(true);
143 ui->moveAfterCreate->setChecked(settings.value(IniKey_MoveAfterCreateFolder).toBool());
144 ui->openAfterCreate->setChecked(settings.value(IniKey_OpenAfterCreateFile).toBool());
148 ui->editorOpt->setText(settings.value(IniKey_EditorOption).toString());
149 ui->editorPath->setText(settings.value(IniKey_EditorPath).toString());
151 ui->termOpt->setText(settings.value(IniKey_TerminalOption).toString());
152 ui->termPath->setText(settings.value(IniKey_TerminalPath).toString());
155 ui->enableViewerIgnoreExt->setChecked(true);
156 ui->enableViewerIgnoreExt->setChecked(!settings.value(IniKey_ViewerForceOpen).toBool());
157 ui->viewerIgnoreExt->setPlainText(settings.value(IniKey_ViewerIgnoreExt).toString());
160 PreferenceDialog::~PreferenceDialog()
165 void PreferenceDialog::saveAppearance(QSettings &settings)
167 QFont font = ui->sampleEdit->font();
168 QPalette palette = ui->sampleEdit->palette();
169 settings.setValue(IniKey_BoxColorBg, palette.base().color());
170 settings.setValue(IniKey_BoxColorFg, palette.text().color());
171 settings.setValue(IniKey_BoxFont, font);
173 settings.setValue(IniKey_ViewColorBgMark, m_colorMap["clrBgMark"]);
174 settings.setValue(IniKey_ViewColorBgNormal, m_colorMap["clrBgNormal"]);
175 settings.setValue(IniKey_ViewColorFgHidden, m_colorMap["clrFgHidden"]);
176 settings.setValue(IniKey_ViewColorFgMark, m_colorMap["clrFgMark"]);
177 settings.setValue(IniKey_ViewColorFgNormal, m_colorMap["clrFgNormal"]);
178 settings.setValue(IniKey_ViewColorFgReadonly, m_colorMap["clrFgReadonly"]);
179 settings.setValue(IniKey_ViewColorFgSystem, m_colorMap["clrFgSystem"]);
180 settings.setValue(IniKey_ViewFont, m_model.font());
183 void PreferenceDialog::loadAppearance(QSettings &settings, bool import)
190 palette = QPalette();
192 color = settings.value(IniKey_BoxColorBg).value<QColor>();
193 palette.setColor(QPalette::Base, color);
195 color = settings.value(IniKey_BoxColorFg).value<QColor>();
196 palette.setColor(QPalette::Text, color);
198 font = settings.value(IniKey_BoxFont).value<QFont>();
199 ui->boxFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
201 ui->sampleEdit->setPalette(palette);
202 ui->sampleEdit->setFont(font);
206 color = settings.value(IniKey_ViewColorBgMark).value<QColor>();
207 m_colorMap["clrBgMark"] = color;
208 color = settings.value(IniKey_ViewColorBgNormal).value<QColor>();
209 m_colorMap["clrBgNormal"] = color;
211 color = settings.value(IniKey_ViewColorFgHidden).value<QColor>();
212 m_colorMap["clrFgHidden"] = color;
213 color = settings.value(IniKey_ViewColorFgMark).value<QColor>();
214 m_colorMap["clrFgMark"] = color;
215 color = settings.value(IniKey_ViewColorFgNormal).value<QColor>();
216 m_colorMap["clrFgNormal"] = color;
217 color = settings.value(IniKey_ViewColorFgReadonly).value<QColor>();
218 m_colorMap["clrFgReadonly"] = color;
219 color = settings.value(IniKey_ViewColorFgSystem).value<QColor>();
220 m_colorMap["clrFgSystem"] = color;
222 font = settings.value(IniKey_ViewFont).value<QFont>();
223 ui->viewFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
225 m_model.setFont(font);
230 if (settings.value(IniKey_ViewerInherit).toBool()) {
231 ui->viewerInherit->setChecked(true);
232 color = settings.value(IniKey_ViewColorBgNormal).value<QColor>();
233 palette.setColor(QPalette::Base, color);
234 color = settings.value(IniKey_ViewColorFgNormal).value<QColor>();
235 palette.setColor(QPalette::Text, color);
238 ui->viewerInherit->setChecked(false);
239 color = settings.value(IniKey_ViewerColorBg).value<QColor>();
240 palette.setColor(QPalette::Base, color);
241 color = settings.value(IniKey_ViewerColorFg).value<QColor>();
242 palette.setColor(QPalette::Text, color);
244 ui->viewerSample->setPalette(palette);
247 font = settings.value(IniKey_ViewerFont).value<QFont>();
248 ui->viewerFont->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
249 ui->viewerSample->setFont(font);
253 void PreferenceDialog::chooseFont()
257 QLabel *label = NULL;
259 if (sender() == ui->chooseViewerFont) {
260 font = ui->viewerSample->font();
262 else if (sender() == ui->chooseBoxFont) {
263 font = ui->sampleEdit->font();
265 else if (sender() == ui->chooseViewFont) {
266 font = m_model.font();
269 font = QFontDialog::getFont(&ok, font, this);
271 if (sender() == ui->chooseViewerFont) {
272 ui->viewerSample->setFont(font);
273 label = ui->viewerFont;
275 else if (sender() == ui->chooseBoxFont) {
276 ui->sampleEdit->setFont(font);
279 else if (sender() == ui->chooseViewFont) {
280 m_model.setFont(font);
282 label = ui->viewFont;
284 label->setText(tr("%1, %2pt").arg(font.family()).arg(font.pointSize()));
288 void PreferenceDialog::setControlsEnabled(bool enabled)
290 if (sender() == ui->bootSize) {
291 ui->sizeAbsolute->setEnabled(enabled);
292 ui->sizeLast->setEnabled(enabled);
293 ui->sizeRelative->setEnabled(enabled);
295 emit ui->sizeAbsolute->toggled(ui->sizeAbsolute->isChecked());
296 emit ui->sizeRelative->toggled(ui->sizeRelative->isChecked());
299 emit ui->sizeAbsolute->toggled(false);
300 emit ui->sizeRelative->toggled(false);
303 else if (sender() == ui->sizeAbsolute) {
304 ui->absoluteHeight->setEnabled(enabled);
305 ui->absoluteWidth->setEnabled(enabled);
307 else if (sender() == ui->sizeRelative) {
308 ui->relativeHeight->setEnabled(enabled);
309 ui->relativeWidth->setEnabled(enabled);
311 else if (sender() == ui->bootPos) {
312 ui->posAbsolute->setEnabled(enabled);
313 ui->posCenter->setEnabled(enabled);
314 ui->posLast->setEnabled(enabled);
315 ui->posRelative->setEnabled(enabled);
317 emit ui->posAbsolute->toggled(ui->posAbsolute->isChecked());
318 emit ui->posRelative->toggled(ui->posRelative->isChecked());
321 emit ui->posAbsolute->toggled(false);
322 emit ui->posRelative->toggled(false);
325 else if (sender() == ui->posAbsolute) {
326 ui->absoluteLeft->setEnabled(enabled);
327 ui->absoluteTop->setEnabled(enabled);
329 else if (sender() == ui->posRelative) {
330 ui->relativeLeft->setEnabled(enabled);
331 ui->relativeTop->setEnabled(enabled);
333 else if (sender() == ui->viewerInherit) {
334 ui->viewerClrBg->setEnabled(!enabled);
335 ui->viewerClrFg->setEnabled(!enabled);
337 else if (sender() == ui->enableViewerIgnoreExt) {
338 ui->viewerIgnoreExt->setEnabled(enabled);
342 void PreferenceDialog::setIgnoreExtDefault()
344 ui->viewerIgnoreExt->setPlainText(ViewerIgnoreExt());
347 void PreferenceDialog::selectBoxColor()
350 QPalette palette = ui->sampleEdit->palette();
351 if (sender() == ui->boxClrBg) {
352 color = palette.background().color();
354 else if (sender() == ui->boxClrFg) {
355 color = palette.text().color();
358 color = QColorDialog::getColor(color, this, tr("色選択"));
359 if (!color.isValid()) {
363 if (sender() == ui->boxClrBg) {
364 palette.setColor(QPalette::Base, color);
366 else if (sender() == ui->boxClrFg) {
367 palette.setColor(QPalette::Text, color);
369 ui->sampleEdit->setPalette(palette);
372 void PreferenceDialog::selectViewColor()
374 const QString objName = sender()->objectName();
375 QColor color = m_colorMap[objName];
377 color = QColorDialog::getColor(color, this, tr("色選択"));
378 if (!color.isValid()) {
382 m_colorMap[objName] = color;
386 void PreferenceDialog::selectViewerColor()
389 QPalette palette = ui->viewerSample->palette();
390 if (sender() == ui->viewerClrBg) {
391 color = palette.background().color();
393 else if (sender() == ui->viewerClrFg) {
394 color = palette.text().color();
397 color = QColorDialog::getColor(color, this, tr("色選択"));
398 if (!color.isValid()) {
402 if (sender() == ui->viewerClrBg) {
403 palette.setColor(QPalette::Base, color);
405 else if (sender() == ui->viewerClrFg) {
406 palette.setColor(QPalette::Text, color);
408 ui->viewerSample->setPalette(palette);
411 void PreferenceDialog::browseApp()
413 QStringList list = QStandardPaths::standardLocations(
414 QStandardPaths::ApplicationsLocation);
416 QString path = QFileDialog::getOpenFileName(
417 this, tr("アプリケーションを選択"), list.at(0),
418 tr("実行ファイル (*.exe *.com *.bat *.pif);;すべてのファイル (*)"));
419 #elif defined(Q_OS_MAC)
420 QString path = QFileDialog::getOpenFileName(
421 this, tr("アプリケーションを選択"), list.at(0),
422 tr("実行ファイル (*.app);;すべてのファイル (*)"));
424 QString path = QFileDialog::getOpenFileName(
425 this, tr("アプリケーションを選択"), list.at(0),
428 if (!path.isEmpty()) {
429 if (sender() == ui->editorBrowse) {
430 ui->editorPath->setText(path);
432 else if (sender() == ui->termBrowse) {
433 ui->termPath->setText(path);
438 void PreferenceDialog::importAppearance()
440 QStringList list = QStandardPaths::standardLocations(
441 QStandardPaths::DocumentsLocation);
442 QString path = QFileDialog::getOpenFileName(
443 this, tr("ファイルを選択"), list.at(0),
444 tr("設定ファイル (*.ini);;すべてのファイル (*)"));
445 if (path.isEmpty()) {
449 QSettings settings(path, QSettings::IniFormat);
450 loadAppearance(settings, true);
453 void PreferenceDialog::exportAppearance()
455 QStringList list = QStandardPaths::standardLocations(
456 QStandardPaths::DocumentsLocation);
457 QString path = QFileDialog::getSaveFileName(
458 this, tr("ファイルを選択"), list.at(0) + "/gefu_appearance.ini",
459 tr("設定ファイル (*.ini);;すべてのファイル (*)"));
460 if (path.isEmpty()) {
464 QSettings settings(path, QSettings::IniFormat);
465 saveAppearance(settings);
468 void PreferenceDialog::accept()
471 QAbstractButton *selected;
475 settings.setValue(IniKey_ConfirmExit, ui->confirmExit->isChecked());
477 if (!ui->bootSize->isChecked()) {
478 settings.setValue(IniKey_BootSizeSpec, "");
481 selected = ui->sizeOptions->checkedButton();
482 settings.setValue(IniKey_BootSizeSpec, selected->objectName());
485 size = QSize(ui->absoluteWidth->value(), ui->absoluteHeight->value());
486 settings.setValue(IniKey_BootSizeAbs, size);
488 size = QSize(ui->relativeWidth->value(), ui->relativeHeight->value());
489 settings.setValue(IniKey_BootSizeRel, size);
492 if (!ui->bootPos->isChecked()) {
493 settings.setValue(IniKey_BootPosSpec, "");
496 selected = ui->posOptions->checkedButton();
497 settings.setValue(IniKey_BootPosSpec, selected->objectName());
500 pos = QPoint(ui->absoluteLeft->value(), ui->absoluteTop->value());
501 settings.setValue(IniKey_BootPosAbs, pos);
503 pos = QPoint(ui->relativeLeft->value(), ui->relativeTop->value());
504 settings.setValue(IniKey_BootPosRel, pos);
507 settings.setValue(IniKey_ResetOnBoot, ui->resetOnBoot->isChecked());
510 saveAppearance(settings);
513 settings.setValue(IniKey_ConfirmCopy, ui->confirmCopy->isChecked());
514 settings.setValue(IniKey_ConfirmDelete, ui->confirmDelete->isChecked());
515 settings.setValue(IniKey_ConfirmMove, ui->confirmMove->isChecked());
516 settings.setValue(IniKey_ConfirmRename, ui->confirmRename->isChecked());
518 settings.setValue(IniKey_AutoCloseCopy, ui->autoCloseCopy->isChecked());
519 settings.setValue(IniKey_AutoCloseDelete, ui->autoCloseDelete->isChecked());
520 settings.setValue(IniKey_AutoCloseMove, ui->autoCloseMove->isChecked());
521 settings.setValue(IniKey_AutoCloseRename, ui->autoCloseRename->isChecked());
523 selected = ui->overwriteOptions->checkedButton();
524 settings.setValue(IniKey_DefaultOnCopy, selected->objectName());
526 settings.setValue(IniKey_MoveAfterCreateFolder, ui->moveAfterCreate->isChecked());
527 settings.setValue(IniKey_OpenAfterCreateFile, ui->openAfterCreate->isChecked());
530 settings.setValue(IniKey_EditorOption, ui->editorOpt->text().trimmed());
531 settings.setValue(IniKey_EditorPath, ui->editorPath->text().trimmed());
533 settings.setValue(IniKey_TerminalOption, ui->termOpt->text().trimmed());
534 settings.setValue(IniKey_TerminalPath, ui->termPath->text().trimmed());
537 settings.setValue(IniKey_ViewerFont, ui->viewerSample->font());
538 settings.setValue(IniKey_ViewerColorBg, ui->viewerSample->palette().base().color());
539 settings.setValue(IniKey_ViewerColorFg, ui->viewerSample->palette().text().color());
540 settings.setValue(IniKey_ViewerInherit, ui->viewerInherit->isChecked());
541 settings.setValue(IniKey_ViewerForceOpen, !ui->enableViewerIgnoreExt->isChecked());
542 QStringList list = ui->viewerIgnoreExt->toPlainText().split(",", QString::SkipEmptyParts);
543 QStringList::iterator it;
544 for (it = list.begin(); it != list.end(); it++) {
547 settings.setValue(IniKey_ViewerIgnoreExt, list.join(","));