OSDN Git Service

Ver0.26
[gefu/Gefu.git] / preferencedialog.cpp
1 #include "global.h"
2 #include "preferences.h"
3 #include "preferencedialog.h"
4 #include "ui_preferencedialog.h"
5
6 #include <QColorDialog>
7 #include <QDebug>
8 #include <QDir>
9 #include <QFileDialog>
10 #include <QFontDialog>
11 #include <QPainter>
12 #include <QStandardPaths>
13
14 ///////////////////////////////////////////////////////////////////////////////
15 /// \brief PreferenceDialog::PreferenceDialog
16 /// \param parent   親ウィジェット
17 ///
18 /// コンストラクタ
19 ///
20 PreferenceDialog::PreferenceDialog(QWidget *parent) :
21     QDialog(parent),
22     ui(new Ui::PreferenceDialog)
23 {
24     ui->setupUi(this);
25     ui->tabWidget->setCurrentIndex(0);
26     ui->lBoxSample->setText(QDir::homePath());
27     ui->fvHiddenSample->installEventFilter(this);
28     ui->fvMarkedSample->installEventFilter(this);
29     ui->fvNormalSample->installEventFilter(this);
30     ui->fvReadOnlySample->installEventFilter(this);
31     ui->fvSystemSample->installEventFilter(this);
32     ui->lBoxSample->installEventFilter(this);
33     ui->sBoxNormalSample->installEventFilter(this);
34     ui->sBoxUnmatchSample->installEventFilter(this);
35     ui->tvSample->installEventFilter(this);
36     ui->hvSample->installEventFilter(this);
37     ui->gvSample->installEventFilter(this);
38
39     connect(ui->fvNormal, SIGNAL(clicked()), this, SLOT(chooseColor()));
40     connect(ui->fvNormalBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
41     connect(ui->fvMarked, SIGNAL(clicked()), this, SLOT(chooseColor()));
42     connect(ui->fvMarkedBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
43     connect(ui->fvSystem, SIGNAL(clicked()), this, SLOT(chooseColor()));
44     connect(ui->fvHidden, SIGNAL(clicked()), this, SLOT(chooseColor()));
45     connect(ui->fvReadOnly, SIGNAL(clicked()), this, SLOT(chooseColor()));
46     connect(ui->lBoxBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
47     connect(ui->lBoxFg, SIGNAL(clicked()), this, SLOT(chooseColor()));
48     connect(ui->sBoxNormal, SIGNAL(clicked()), this, SLOT(chooseColor()));
49     connect(ui->sBoxNormalBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
50     connect(ui->sBoxUnmatch, SIGNAL(clicked()), this, SLOT(chooseColor()));
51     connect(ui->sBoxUnmatchBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
52     connect(ui->tvBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
53     connect(ui->tvCtrl, SIGNAL(clicked()), this, SLOT(chooseColor()));
54     connect(ui->tvFg, SIGNAL(clicked()), this, SLOT(chooseColor()));
55     connect(ui->hvBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
56     connect(ui->hvFg, SIGNAL(clicked()), this, SLOT(chooseColor()));
57     connect(ui->gvBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
58     connect(ui->allBg, SIGNAL(clicked()), this, SLOT(chooseColor()));
59     connect(ui->allFg, SIGNAL(clicked()), this, SLOT(chooseColor()));
60
61     connect(ui->fvFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
62     connect(ui->lBoxFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
63     connect(ui->sBoxFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
64     connect(ui->tvFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
65     connect(ui->hvFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
66     connect(ui->allFont, SIGNAL(clicked()), this, SLOT(chooseFont()));
67
68     connect(ui->browseArchiver, SIGNAL(clicked()), this, SLOT(choosePath()));
69     connect(ui->browseEditor, SIGNAL(clicked()), this, SLOT(choosePath()));
70     connect(ui->browseTerminal, SIGNAL(clicked()), this, SLOT(choosePath()));
71
72     connect(ui->exportAppearance, SIGNAL(clicked()), this, SLOT(exportAppearance()));
73     connect(ui->importAppearance, SIGNAL(clicked()), this, SLOT(importAppearance()));
74
75     Preferences prefs(this);
76
77     // [全般]
78     ui->checkUpdate->setChecked(prefs.isCheckUpdate());
79     ui->confirmQuit->setChecked(prefs.isConfirmQuit());
80     ui->moveAfterCreation->setChecked(prefs.isMoveAfterCreation());
81     ui->openAfterCreation->setChecked(prefs.isOpenAfterCreation());
82     ui->confirmCopy->setChecked(prefs.isConfirmCopy());
83     ui->confirmMove->setChecked(prefs.isConfirmMove());
84     ui->confirmDelete->setChecked(prefs.isConfirmDelete());
85     ui->confirmRename->setChecked(prefs.isConfirmRename());
86     ui->autoCloseCopy->setChecked(prefs.isAutoCloseCopy());
87     ui->autoCloseMove->setChecked(prefs.isAutoCloseMove());
88     ui->autoCloseDelete->setChecked(prefs.isAutoCloseDelete());
89     ui->autoCloseRename->setChecked(prefs.isAutoCloseRename());
90     QRadioButton *radio = findChild<QRadioButton*>("rb" + prefs.getCopyBehavior());
91     if (radio)
92         radio->setChecked(true);
93     else
94         ui->rbOverWriteIfNew->setChecked(true);
95     ui->preferExtensions->setPlainText(prefs.getPreferExtensions());
96     ui->resetOnBoot->setChecked(prefs.isReset());
97
98     // [外観(色)]
99     loadAppearance(prefs);
100
101     // [外観(フォント)]
102     setFont(ui->fvFontSpec, prefs.getFolderViewFont());
103     setFont(ui->lBoxFontSpec, prefs.getLocationBoxFont());
104     setFont(ui->sBoxFontSpec, prefs.getSearchBoxFont());
105     setFont(ui->tvFontSpec, prefs.getTextViewFont());
106     setFont(ui->hvFontSpec, prefs.getHexViewFont());
107
108     ui->lineHeight->setValue(prefs.getLineHeight());
109     ui->tvLineHeight->setValue(prefs.getTextViewLineHeight());
110
111     // [プログラムパス]
112     ui->editorPath->setText(prefs.getEditorPath());
113     ui->terminalPath->setText(prefs.getTerminalPath());
114     ui->archiverPath->setText(prefs.getArchiverPath());
115 }
116
117 ///////////////////////////////////////////////////////////////////////////////
118 /// \brief PreferenceDialog::~PreferenceDialog
119 ///
120 /// デストラクタ
121 ///
122 PreferenceDialog::~PreferenceDialog()
123 {
124     delete ui;
125 }
126
127 ///////////////////////////////////////////////////////////////////////////////
128 /// \brief PreferenceDialog::loadAppearance
129 /// \param prefs    プリファレンスオブジェクト
130 ///
131 /// 外観(色)設定を読み込みます。
132 ///
133 void PreferenceDialog::loadAppearance(Preferences &prefs)
134 {
135     setPalette(ui->fvNormalSample, QPalette::Base, prefs.getFolderViewBgColor());
136     setPalette(ui->fvNormalSample, QPalette::Text, prefs.getFolderViewFgColor());
137
138     setPalette(ui->fvMarkedSample, QPalette::Base, prefs.getFolderViewMarkedBgColor());
139     setPalette(ui->fvMarkedSample, QPalette::Text, prefs.getFolderViewMarkedFgColor());
140
141     setPalette(ui->fvSystemSample, QPalette::Base, prefs.getFolderViewBgColor());
142     setPalette(ui->fvSystemSample, QPalette::Text, prefs.getFolderViewSystemColor());
143
144     setPalette(ui->fvHiddenSample, QPalette::Base, prefs.getFolderViewBgColor());
145     setPalette(ui->fvHiddenSample, QPalette::Text, prefs.getFolderViewHiddenColor());
146
147     setPalette(ui->fvReadOnlySample, QPalette::Base, prefs.getFolderViewBgColor());
148     setPalette(ui->fvReadOnlySample, QPalette::Text, prefs.getFolderViewReadOnlyColor());
149
150     setPalette(ui->lBoxSample, QPalette::Base, prefs.getLocationBoxBgColor());
151     setPalette(ui->lBoxSample, QPalette::Text, prefs.getLocationBoxFgColor());
152
153     setPalette(ui->sBoxNormalSample, QPalette::Base, prefs.getSearchBoxBgColor());
154     setPalette(ui->sBoxNormalSample, QPalette::Text, prefs.getSearchBoxFgColor());
155
156     setPalette(ui->sBoxUnmatchSample, QPalette::Base, prefs.getSearchBoxUnmatchBgColor());
157     setPalette(ui->sBoxUnmatchSample, QPalette::Text, prefs.getSearchBoxUnmatchFgColor());
158
159     setPalette(ui->tvSample, QPalette::Base, prefs.getTextViewBgColor());
160     setPalette(ui->tvSample, QPalette::Text, prefs.getTextViewFgColor());
161     setPalette(ui->tvSample, QPalette::BrightText, prefs.getTextViewCtrlColor());
162
163     setPalette(ui->hvSample, QPalette::Base, prefs.getHexViewBgColor());
164     setPalette(ui->hvSample, QPalette::Text, prefs.getHexViewFgColor());
165
166     setPalette(ui->gvSample, QPalette::Base, prefs.getImageViewBgColor());
167
168     ui->darkFactor->setValue(prefs.getDarkFacotr());
169 }
170
171 ///////////////////////////////////////////////////////////////////////////////
172 /// \brief PreferenceDialog::saveAppearance
173 /// \param prefs    プリファレンスオブジェクト
174 ///
175 /// 外観(色)設定を保存します。
176 ///
177 void PreferenceDialog::saveAppearance(Preferences &prefs)
178 {
179     prefs.setFolderViewBgColor(ui->fvNormalSample->palette().base().color());
180     prefs.setFolderViewFgColor(ui->fvNormalSample->palette().text().color());
181
182     prefs.setFolderViewMarkedBgColor(ui->fvMarkedSample->palette().base().color());
183     prefs.setFolderViewMarkedFgColor(ui->fvMarkedSample->palette().text().color());
184
185     prefs.setFolderViewHiddenColor(ui->fvHiddenSample->palette().text().color());
186     prefs.setFolderViewReadOnlyColor(ui->fvReadOnlySample->palette().text().color());
187     prefs.setFolderViewSystemColor(ui->fvSystemSample->palette().text().color());
188
189     prefs.setLocationBoxBgColor(ui->lBoxSample->palette().base().color());
190     prefs.setLocationBoxFgColor(ui->lBoxSample->palette().text().color());
191
192     prefs.setSearchBoxBgColor(ui->sBoxNormalSample->palette().base().color());
193     prefs.setSearchBoxFgColor(ui->sBoxNormalSample->palette().text().color());
194
195     prefs.setSearchBoxUnmatchBgColor(ui->sBoxUnmatchSample->palette().base().color());
196     prefs.setSearchBoxUnmatchFgColor(ui->sBoxUnmatchSample->palette().text().color());
197
198     prefs.setTextViewBgColor(ui->tvSample->palette().base().color());
199     prefs.setTextViewFgColor(ui->tvSample->palette().text().color());
200     prefs.setTextViewCtrlColor(ui->tvSample->palette().brightText().color());
201
202     prefs.setHexViewBgColor(ui->hvSample->palette().base().color());
203     prefs.setHexViewFgColor(ui->hvSample->palette().text().color());
204
205     prefs.setImageViewBgColor(ui->gvSample->palette().base().color());
206
207     prefs.setDarkFacotr(ui->darkFactor->value());
208 }
209
210 ///////////////////////////////////////////////////////////////////////////////
211 /// \brief PreferenceDialog::setFont
212 /// \param label    ラベルオブジェクト
213 /// \param font     フォントオブジェクト
214 ///
215 /// ラベルにフォントを設定します。
216 ///
217 void PreferenceDialog::setFont(QLabel *label, const QFont &font)
218 {
219     label->setFont(font);
220     label->setText(QString("%1, %2pt").arg(font.family()).arg(font.pointSize()));
221 }
222
223 ///////////////////////////////////////////////////////////////////////////////
224 /// \brief PreferenceDialog::setPalette
225 /// \param w        ウィジェット
226 /// \param role     ロール
227 /// \param color    色
228 ///
229 /// パレットに色を設定します。
230 ///
231 void PreferenceDialog::setPalette(QWidget *w, QPalette::ColorRole role, const QColor &color)
232 {
233     QPalette pal = w->palette();
234     pal.setColor(role, color);
235     w->setPalette(pal);
236 }
237
238 ///////////////////////////////////////////////////////////////////////////////
239 /// \brief PreferenceDialog::chooseColor
240 ///
241 /// 色選択ダイアログを表示します。
242 ///
243 void PreferenceDialog::chooseColor()
244 {
245     QColor color;
246
247     if (sender() == ui->fvNormal) {
248         color = ui->fvNormalSample->palette().text().color();
249     }
250     else if (sender() == ui->fvNormalBg) {
251         color = ui->fvNormalSample->palette().base().color();
252     }
253     else if (sender() == ui->fvMarked) {
254         color = ui->fvMarkedSample->palette().text().color();
255     }
256     else if (sender() == ui->fvMarkedBg) {
257         color = ui->fvMarkedSample->palette().base().color();
258     }
259     else if (sender() == ui->fvSystem) {
260         color = ui->fvSystemSample->palette().text().color();
261     }
262     else if (sender() == ui->fvHidden) {
263         color = ui->fvHiddenSample->palette().text().color();
264     }
265     else if (sender() == ui->fvReadOnly) {
266         color = ui->fvReadOnlySample->palette().text().color();
267     }
268     else if (sender() == ui->lBoxBg) {
269         color = ui->lBoxSample->palette().base().color();
270     }
271     else if (sender() == ui->lBoxFg) {
272         color = ui->lBoxSample->palette().text().color();
273     }
274     else if (sender() == ui->sBoxNormal) {
275         color = ui->sBoxNormalSample->palette().text().color();
276     }
277     else if (sender() == ui->sBoxNormalBg) {
278         color = ui->sBoxNormalSample->palette().base().color();
279     }
280     else if (sender() == ui->sBoxUnmatch) {
281         color = ui->sBoxUnmatchSample->palette().text().color();
282     }
283     else if (sender() == ui->sBoxUnmatchBg) {
284         color = ui->sBoxUnmatchSample->palette().base().color();
285     }
286     else if (sender() == ui->tvBg) {
287         color = ui->tvSample->palette().base().color();
288     }
289     else if (sender() == ui->tvFg) {
290         color = ui->tvSample->palette().text().color();
291     }
292     else if (sender() == ui->tvCtrl) {
293         color = ui->tvSample->palette().brightText().color();
294     }
295     else if (sender() == ui->hvBg) {
296         color = ui->hvSample->palette().base().color();
297     }
298     else if (sender() == ui->hvFg) {
299         color = ui->hvSample->palette().text().color();
300     }
301     else if (sender() == ui->gvBg) {
302         color = ui->gvSample->palette().base().color();
303     }
304     else if (sender() == ui->allBg) {
305         color = ui->fvNormalSample->palette().base().color();
306     }
307     else if (sender() == ui->allFg) {
308         color = ui->fvNormalSample->palette().text().color();
309     }
310
311     color = QColorDialog::getColor(color, this, tr("色を選択"));
312     if (!color.isValid()) {
313         return;
314     }
315
316     QPalette pal;
317     if (sender() == ui->fvNormal) {
318         setPalette(ui->fvNormalSample, QPalette::Text, color);
319     }
320     else if (sender() == ui->fvNormalBg) {
321         setPalette(ui->fvNormalSample, QPalette::Base, color);
322         setPalette(ui->fvHiddenSample, QPalette::Base, color);
323         setPalette(ui->fvReadOnlySample, QPalette::Base, color);
324         setPalette(ui->fvSystemSample, QPalette::Base, color);
325     }
326     else if (sender() == ui->fvMarked) {
327         setPalette(ui->fvMarkedSample, QPalette::Text, color);
328     }
329     else if (sender() == ui->fvMarkedBg) {
330         setPalette(ui->fvMarkedSample, QPalette::Base, color);
331     }
332     else if (sender() == ui->fvSystem) {
333         setPalette(ui->fvSystemSample, QPalette::Text, color);
334     }
335     else if (sender() == ui->fvHidden) {
336         setPalette(ui->fvHiddenSample, QPalette::Text, color);
337     }
338     else if (sender() == ui->fvReadOnly) {
339         setPalette(ui->fvReadOnlySample, QPalette::Text, color);
340     }
341     else if (sender() == ui->lBoxBg) {
342         setPalette(ui->lBoxSample, QPalette::Base, color);
343     }
344     else if (sender() == ui->lBoxFg) {
345         setPalette(ui->lBoxSample, QPalette::Text, color);
346     }
347     else if (sender() == ui->sBoxNormal) {
348         setPalette(ui->sBoxNormalSample, QPalette::Text, color);
349     }
350     else if (sender() == ui->sBoxNormalBg) {
351         setPalette(ui->sBoxNormalSample, QPalette::Base, color);
352     }
353     else if (sender() == ui->sBoxUnmatch) {
354         setPalette(ui->sBoxUnmatchSample, QPalette::Text, color);
355     }
356     else if (sender() == ui->sBoxUnmatchBg) {
357         setPalette(ui->sBoxUnmatchSample, QPalette::Base, color);
358     }
359     else if (sender() == ui->tvBg) {
360         setPalette(ui->tvSample, QPalette::Base, color);
361     }
362     else if (sender() == ui->tvFg) {
363         setPalette(ui->tvSample, QPalette::Text, color);
364     }
365     else if (sender() == ui->tvCtrl) {
366         setPalette(ui->tvSample, QPalette::BrightText, color);
367     }
368     else if (sender() == ui->hvBg) {
369         setPalette(ui->hvSample, QPalette::Base, color);
370     }
371     else if (sender() == ui->hvFg) {
372         setPalette(ui->hvSample, QPalette::Text, color);
373     }
374     else if (sender() == ui->gvBg) {
375         setPalette(ui->gvSample, QPalette::Base, color);
376     }
377     else if (sender() == ui->allBg) {
378         setPalette(ui->fvNormalSample, QPalette::Base, color);
379         setPalette(ui->fvHiddenSample, QPalette::Base, color);
380         setPalette(ui->fvReadOnlySample, QPalette::Base, color);
381         setPalette(ui->fvSystemSample, QPalette::Base, color);
382         setPalette(ui->lBoxSample, QPalette::Base, color);
383         setPalette(ui->sBoxNormalSample, QPalette::Base, color);
384         setPalette(ui->tvSample, QPalette::Base, color);
385         setPalette(ui->hvSample, QPalette::Base, color);
386         setPalette(ui->gvSample, QPalette::Base, color);
387     }
388     else if (sender() == ui->allFg) {
389         setPalette(ui->fvNormalSample, QPalette::Text, color);
390         setPalette(ui->lBoxSample, QPalette::Text, color);
391         setPalette(ui->sBoxNormalSample, QPalette::Text, color);
392         setPalette(ui->tvSample, QPalette::Text, color);
393         setPalette(ui->hvSample, QPalette::Text, color);
394     }
395 }
396
397 ///////////////////////////////////////////////////////////////////////////////
398 /// \brief PreferenceDialog::chooseFont
399 ///
400 /// フォント選択ダイアログを表示します。
401 ///
402 void PreferenceDialog::chooseFont()
403 {
404     QFont font;
405     if (sender() == ui->fvFont) {
406         font = ui->fvFontSpec->font();
407     }
408     else if (sender() == ui->lBoxFont) {
409         font = ui->lBoxFontSpec->font();
410     }
411     else if (sender() == ui->sBoxFont) {
412         font = ui->sBoxFontSpec->font();
413     }
414     else if (sender() == ui->tvFont) {
415         font = ui->tvFontSpec->font();
416     }
417     else if (sender() == ui->hvFont) {
418         font = ui->hvFontSpec->font();
419     }
420     else if (sender() == ui->allFont) {
421         font = ui->fvFontSpec->font();
422     }
423
424     bool ok;
425     font = QFontDialog::getFont(&ok, font, this, tr("フォントを選択"));
426
427     if (!ok) {
428         return;
429     }
430
431     if (sender() == ui->fvFont) {
432         setFont(ui->fvFontSpec, font);
433     }
434     else if (sender() == ui->lBoxFont) {
435         setFont(ui->lBoxFontSpec, font);
436     }
437     else if (sender() == ui->sBoxFont) {
438         setFont(ui->sBoxFontSpec, font);
439     }
440     else if (sender() == ui->tvFont) {
441         setFont(ui->tvFontSpec, font);
442     }
443     else if (sender() == ui->hvFont) {
444         setFont(ui->hvFontSpec, font);
445     }
446     else if (sender() == ui->allFont) {
447         setFont(ui->fvFontSpec, font);
448         setFont(ui->lBoxFontSpec, font);
449         setFont(ui->sBoxFontSpec, font);
450         setFont(ui->tvFontSpec, font);
451         setFont(ui->hvFontSpec, font);
452     }
453 }
454
455 ///////////////////////////////////////////////////////////////////////////////
456 /// \brief PreferenceDialog::choosePath
457 ///
458 /// プログラム選択ダイアログを表示します。
459 ///
460 void PreferenceDialog::choosePath()
461 {
462     QStringList list = QStandardPaths::standardLocations(
463                 QStandardPaths::ApplicationsLocation);
464 #ifdef Q_OS_WIN
465     QString path = QFileDialog::getOpenFileName(
466                 this, tr("アプリケーションを選択"), getenv("PROGRAMFILES"),
467                 tr("実行ファイル (*.exe *.com *.bat *.pif);;すべてのファイル (*)"));
468 #elif defined(Q_OS_MAC)
469     QString path = QFileDialog::getOpenFileName(
470                 this, tr("アプリケーションを選択"), list.at(0),
471                 tr("実行ファイル (*.app);;すべてのファイル (*)"));
472 #else
473     QString path = QFileDialog::getOpenFileName(
474                 this, tr("アプリケーションを選択"), list.at(0),
475                 tr("すべてのファイル (*)"));
476 #endif
477     if (path.isEmpty()) {
478         return;
479     }
480
481     if (path.indexOf(" ") != -1) {
482         path = QQ(path);
483     }
484
485     if (sender() == ui->browseEditor) {
486         ui->editorPath->setText(path);
487     }
488     else if (sender() == ui->browseTerminal) {
489         ui->terminalPath->setText(path);
490     }
491     else if (sender() == ui->browseArchiver) {
492         ui->archiverPath->setText(path);
493     }
494 }
495
496 ///////////////////////////////////////////////////////////////////////////////
497 /// \brief PreferenceDialog::exportAppearance
498 ///
499 /// 「エクスポート」ボタンクリック時の処理を行います。
500 ///
501 void PreferenceDialog::exportAppearance()
502 {
503     QStringList list = QStandardPaths::standardLocations(
504                 QStandardPaths::DocumentsLocation);
505     QString path = QFileDialog::getSaveFileName(
506                 this, tr("ファイルを選択"), list.at(0) + "/gefu_appearance.ini",
507                 tr("設定ファイル (*.ini);;すべてのファイル (*)"));
508     if (path.isEmpty()) {
509         return;
510     }
511
512     Preferences prefs(path, this);
513     saveAppearance(prefs);
514 }
515
516 ///////////////////////////////////////////////////////////////////////////////
517 /// \brief PreferenceDialog::importAppearance
518 ///
519 /// 「インポート」ボタンクリック時の処理を行います。
520 ///
521 void PreferenceDialog::importAppearance()
522 {
523     QStringList list = QStandardPaths::standardLocations(
524                 QStandardPaths::DocumentsLocation);
525     QString path = QFileDialog::getOpenFileName(
526                 this, tr("ファイルを選択"), list.at(0),
527                 tr("設定ファイル (*.ini);;すべてのファイル (*)"));
528     if (path.isEmpty()) {
529         return;
530     }
531
532     Preferences prefs(path, this);
533     loadAppearance(prefs);
534 }
535
536 ///////////////////////////////////////////////////////////////////////////////
537 /// \brief PreferenceDialog::accept
538 ///
539 /// OKボタンクリック時の処理を行います。
540 ///
541 void PreferenceDialog::accept()
542 {
543     Preferences prefs(this);
544
545     // [全般]
546     prefs.setCheckUpdate(ui->checkUpdate->isChecked());
547     prefs.setConfirmQuit(ui->confirmQuit->isChecked());
548     prefs.setMoveAfterCreation(ui->moveAfterCreation->isChecked());
549     prefs.setOpenAfterCreation(ui->openAfterCreation->isChecked());
550     prefs.setConfirmCopy(ui->confirmCopy->isChecked());
551     prefs.setConfirmMove(ui->confirmMove->isChecked());
552     prefs.setConfirmDelete(ui->confirmDelete->isChecked());
553     prefs.setConfirmRename(ui->confirmRename->isChecked());
554     prefs.setAutoCloseCopy(ui->autoCloseCopy->isChecked());
555     prefs.setAutoCloseMove(ui->autoCloseMove->isChecked());
556     prefs.setAutoCloseDelete(ui->autoCloseDelete->isChecked());
557     prefs.setAutoCloseRename(ui->autoCloseRename->isChecked());
558
559     QAbstractButton *checked = ui->copyBehavior->checkedButton();
560     prefs.setCopyBehavior(checked->objectName().mid(2));
561
562     prefs.setPreferExtensions(ui->preferExtensions->toPlainText());
563     prefs.setReset(ui->resetOnBoot->isChecked());
564
565     // [外観(色)]
566     saveAppearance(prefs);
567
568     // [外観(フォント)]
569     prefs.setFolderViewFont(ui->fvFontSpec->font());
570     prefs.setLocationBoxFont(ui->lBoxFontSpec->font());
571     prefs.setSearchBoxFont(ui->sBoxFontSpec->font());
572     prefs.setTextViewFont(ui->tvFontSpec->font());
573     prefs.setHexViewFont(ui->hvFontSpec->font());
574
575     prefs.setLineHeight(ui->lineHeight->value());
576     prefs.setTextViewLineHeight(ui->tvLineHeight->value());
577
578     // [プログラムパス]
579     prefs.setEditorPath(ui->editorPath->text());
580     prefs.setTerminalPath(ui->terminalPath->text());
581     prefs.setArchiverPath(ui->archiverPath->text());
582
583     QDialog::accept();
584 }
585
586 ///////////////////////////////////////////////////////////////////////////////
587 /// \brief PreferenceDialog::eventFilter
588 /// \param obj      イベントが発生したオブジェクト
589 /// \param event    イベントオブジェクト
590 /// \return イベントを処理した場合はtrueを返します。
591 ///
592 bool PreferenceDialog::eventFilter(QObject *obj, QEvent *event)
593 {
594     if (event->type() == QEvent::Paint) {
595         QLineEdit *edit = static_cast<QLineEdit*>(obj);
596
597         QPainter painter(edit);
598
599         painter.fillRect(edit->rect(), edit->palette().base());
600         painter.setPen(edit->palette().text().color());
601         painter.drawText(edit->rect(), Qt::AlignVCenter, edit->text());
602
603         if (edit->objectName() == "tvSample") {
604             QRect rcCtrl(edit->rect());
605             int textWidth = edit->fontMetrics().width(edit->text());
606             rcCtrl.setLeft(edit->rect().left() + textWidth);
607             painter.setPen(edit->palette().brightText().color());
608             painter.drawText(rcCtrl, Qt::AlignVCenter, QChar(0x21B5));
609         }
610         return true;
611     }
612
613     return false;
614 }