1 #include "foldermodel.h"
3 #include "preferences.h"
5 #include <QApplication>
7 #include <QDesktopWidget>
9 ///////////////////////////////////////////////////////////////////////////////
10 /// \brief DefaultPreferExtensions
11 /// \return 外部アプリを優先する拡張子のデフォルトを返します。
13 QString DefaultPreferExtensions()
18 list << "ico" << "ai" << "psd" << "xcf" << "tif" << "tiff" << "wmf";
20 list << "wav" << "mp3" << "ogg" << "midi" << "mid" << "aif" << "aiff";
21 list << "mov" << "mpg" << "mpeg" << "wma" << "wmv" << "asf" << "avi";
22 list << "flac" << "mkv";
24 list << "exe" << "com" << "msi" << "scr";
26 list << "lzh" << "zip" << "cab" << "tar" << "rar" << "gz" << "tgz";
27 list << "bz2" << "xz" << "jar" << "7z" << "dmg";
29 list << "pdf" << "doc" << "docx" << "xls" << "xlsx" << "ppt" << "pptx";
31 list << "ttf" << "ttc";
35 return list.join(",");
38 ///////////////////////////////////////////////////////////////////////////////
39 /// \brief DefaultFixedFont
40 /// \return デフォルトの固定幅フォントを返します。
42 QFont DefaultFixedFont()
44 QFont font = qApp->font();
46 font.setFamily("MS ゴシック");
47 #elif defined(Q_OS_MAC)
48 font.setFamily("Monaco");
54 ///////////////////////////////////////////////////////////////////////////////
55 /// \brief Preferences::Preferences
56 /// \param parent 親オブジェクト
60 Preferences::Preferences(QObject *parent) :
61 QSettings(QSettings::IniFormat,
63 qApp->organizationName(),
64 qApp->applicationName(),
69 ///////////////////////////////////////////////////////////////////////////////
70 /// \brief Preferences::Preferences
71 /// \param path 設定ファイルのパス
72 /// \param parent 親オブジェクト
76 Preferences::Preferences(const QString &path, QObject *parent) :
77 QSettings(path, QSettings::IniFormat, parent)
81 #define Key_Filter(side) (side + "/Filter")
82 #define Key_NameFilter(side) (side + "/NameFilter")
83 #define Key_Sort(side) (side + "/Sort")
84 #define Key_Path(side) (side + "/Path")
85 ///////////////////////////////////////////////////////////////////////////////
86 /// \brief Preferences::restoreModel
87 /// \param side "Left" or "Right"
88 /// \param m フォルダモデルオブジェクト
92 void Preferences::restoreModel(const QString &side, FolderModel *m)
94 qDebug() << "Preferences::restoreModel()" << side;
96 int filter = value(Key_Filter(side), 0).toInt();
97 filter |= QDir::NoDot | QDir::AllDirs | QDir::Files;
98 m->setFilter(QFlag(filter));
100 QString nameFilter = value(Key_NameFilter(side), "*").toString();
101 m->setNameFilters(nameFilter.split(" ", QString::SkipEmptyParts));
103 int sort = QDir::Name | QDir::DirsFirst | QDir::IgnoreCase;
104 sort = value(Key_Sort(side), sort).toInt();
105 m->setSorting(QFlag(sort));
107 QString path = QDir::homePath();
108 path = value(Key_Path(side), path).toString();
109 m->setRootPath(path);
112 ///////////////////////////////////////////////////////////////////////////////
113 /// \brief Preferences::saveModel
114 /// \param side "Left" or "Right"
115 /// \param m フォルダモデルオブジェクト
119 void Preferences::saveModel(const QString &side, const FolderModel *m)
121 qDebug() << "Preferences::saveModel()" << side;
123 setValue(Key_Filter(side), static_cast<int>(m->filter()));
124 setValue(Key_Sort(side), static_cast<int>(m->sorting()));
125 setValue(Key_Path(side), m->rootPath());
128 #define Key_WindowGeometry "WindowGeometry"
129 #define Key_WindowState "WindowState"
130 ///////////////////////////////////////////////////////////////////////////////
131 /// \brief Preferences::restoreWindow
132 /// \param w メインウィンドウオブジェクト
134 /// メインウィンドウの状態を復元します。
136 void Preferences::restoreWindow(QMainWindow *w)
138 qDebug() << "Preferences::restoreWindow()";
140 QByteArray geometry = value(Key_WindowGeometry).toByteArray();
141 if (geometry.isNull()) {
142 QSize size(700, 400);
144 point.setX((qApp->desktop()->width() - size.width()) / 2);
145 point.setY((qApp->desktop()->height() - size.height()) / 2);
146 w->setGeometry(QRect(point, size));
149 w->restoreGeometry(geometry);
152 QByteArray state = value(Key_WindowState).toByteArray();
153 if (!state.isEmpty()) {
154 w->restoreState(state);
158 ///////////////////////////////////////////////////////////////////////////////
159 /// \brief Preferences::saveWindow
160 /// \param w メインウィンドウオブジェクト
162 /// メインウィンドウの状態を保存します。
164 void Preferences::saveWindow(const QMainWindow *w)
166 setValue(Key_WindowGeometry, w->saveGeometry());
167 setValue(Key_WindowState, w->saveState());
170 #define Key_BookmarkEntry(i) QString("Bookmark/Entry%1").arg(i)
171 #define Key_BookmarkPath(i) QString("Bookmark/Path%1").arg(i)
172 ///////////////////////////////////////////////////////////////////////////////
173 /// \brief Preferences::addBookmark
179 void Preferences::addBookmark(const QString &name, const QString &path)
182 for (n = 1; !value(Key_BookmarkEntry(n)).isNull(); n++)
185 setValue(Key_BookmarkEntry(n), name);
186 setValue(Key_BookmarkPath(n), path);
189 ///////////////////////////////////////////////////////////////////////////////
190 /// \brief Preferences::clearBookmark
194 void Preferences::clearBookmark()
196 beginGroup("Bookmark");
201 ///////////////////////////////////////////////////////////////////////////////
202 /// \brief Preferences::getBookmarkEntry
204 /// \return n番目のブックマーク名を取得します。
206 QString Preferences::getBookmarkEntry(int n) const
208 return value(Key_BookmarkEntry(n)).toString();
211 ///////////////////////////////////////////////////////////////////////////////
212 /// \brief Preferences::getBookmarkPath
214 /// \return n番目のブックマークパスを取得します。
216 QString Preferences::getBookmarkPath(int n) const
218 return value(Key_BookmarkPath(n)).toString();
221 ///////////////////////////////////////////////////////////////////////////////
222 /// \brief Preferences::folderViewFgColor
223 /// \param active アクティブならtrue
224 /// \return フォルダービューの文字色を返します。
226 QColor Preferences::folderViewFgColor(bool active) const
228 int darkFactor = 100;
230 darkFactor += getDarkFacotr() * 100;
232 return getFolderViewFgColor().darker(darkFactor);
235 ///////////////////////////////////////////////////////////////////////////////
236 /// \brief Preferences::folderViewBgColor
237 /// \param active アクティブならtrue
238 /// \return フォルダービューの背景色を返します。
240 QColor Preferences::folderViewBgColor(bool active) const
242 int darkFactor = 100;
244 darkFactor += getDarkFacotr() * 100;
246 return getFolderViewBgColor().darker(darkFactor);
249 ///////////////////////////////////////////////////////////////////////////////
250 /// \brief Preferences::folderViewMarkedFgColor
251 /// \param active アクティブならtrue
252 /// \return フォルダービューのマーク文字色を返します。
254 QColor Preferences::folderViewMarkedFgColor(bool active) const
256 int darkFactor = 100;
258 darkFactor += getDarkFacotr() * 100;
260 return getFolderViewMarkedFgColor().darker(darkFactor);
263 ///////////////////////////////////////////////////////////////////////////////
264 /// \brief Preferences::folderViewMarkedBgColor
265 /// \param active アクティブならtrue
266 /// \return フォルダービューのマーク背景色を返します。
268 QColor Preferences::folderViewMarkedBgColor(bool active) const
270 int darkFactor = 100;
272 darkFactor += getDarkFacotr() * 100;
274 return getFolderViewMarkedBgColor().darker(darkFactor);
277 ///////////////////////////////////////////////////////////////////////////////
278 /// \brief Preferences::folderViewSystemColor
279 /// \param active アクティブならtrue
280 /// \return システム属性の文字色を返します。
282 QColor Preferences::folderViewSystemColor(bool active) const
284 int darkFactor = 100;
286 darkFactor += getDarkFacotr() * 100;
288 return getFolderViewSystemColor().darker(darkFactor);
291 ///////////////////////////////////////////////////////////////////////////////
292 /// \brief Preferences::folderViewHiddenColor
293 /// \param active アクティブならtrue
294 /// \return 隠し属性の文字色を返します。
296 QColor Preferences::folderViewHiddenColor(bool active) const
298 int darkFactor = 100;
300 darkFactor += getDarkFacotr() * 100;
302 return getFolderViewHiddenColor().darker(darkFactor);
305 ///////////////////////////////////////////////////////////////////////////////
306 /// \brief Preferences::folderViewReadOnlyColor
307 /// \param active アクティブならtrue
308 /// \return 読取専用属性の文字色を返します。
310 QColor Preferences::folderViewReadOnlyColor(bool active) const
312 int darkFactor = 100;
314 darkFactor += getDarkFacotr() * 100;
316 return getFolderViewReadOnlyColor().darker(darkFactor);
319 ///////////////////////////////////////////////////////////////////////////////
320 /// \brief Preferences::locationBoxFgColor
321 /// \param active アクティブならtrue
322 /// \return ロケーションボックスの文字色を返します。
324 QColor Preferences::locationBoxFgColor(bool active) const
326 int darkFactor = 100;
328 darkFactor += getDarkFacotr() * 100;
330 return getLocationBoxFgColor().darker(darkFactor);
333 ///////////////////////////////////////////////////////////////////////////////
334 /// \brief Preferences::locationBoxBgColor
335 /// \param active アクティブならtrue
336 /// \return ロケーションボックスの背景色を返します。
338 QColor Preferences::locationBoxBgColor(bool active) const
340 int darkFactor = 100;
342 darkFactor += getDarkFacotr() * 100;
344 return getLocationBoxBgColor().darker(darkFactor);
347 #define IMPLEMENT_BOOL(key, defVal) \
348 bool Preferences::is##key() const { \
349 return value(#key, def##key()).toBool(); \
351 bool Preferences::def##key() const { \
354 void Preferences::set##key(bool value) { \
355 setValue(#key, value); \
358 IMPLEMENT_BOOL(Reset, false)
359 IMPLEMENT_BOOL(CheckUpdate, true)
360 IMPLEMENT_BOOL(ConfirmQuit, true)
361 IMPLEMENT_BOOL(ConfirmCopy, true)
362 IMPLEMENT_BOOL(AutoCloseCopy, false)
363 IMPLEMENT_BOOL(ConfirmMove, true)
364 IMPLEMENT_BOOL(AutoCloseMove, false)
365 IMPLEMENT_BOOL(ConfirmDelete, true)
366 IMPLEMENT_BOOL(AutoCloseDelete, false)
367 IMPLEMENT_BOOL(ConfirmRename, true)
368 IMPLEMENT_BOOL(AutoCloseRename, false)
369 IMPLEMENT_BOOL(OpenAfterCreation, false)
370 IMPLEMENT_BOOL(MoveAfterCreation, false)
372 #define IMPLEMENT_STRING(key, defVal) \
373 QString Preferences::get##key() const { \
374 return value(#key, def##key()).toString(); \
376 QString Preferences::def##key() const { \
379 void Preferences::set##key(const QString &value) { \
380 setValue(#key, value); \
385 #elif defined(Q_OS_MAC)
386 IMPLEMENT_STRING(ArchiverPath, QQ("/System/Library/CoreServices/Archive Utility.app"))
387 IMPLEMENT_STRING(EditorPath, "/Applications/TextEdit.app")
388 IMPLEMENT_STRING(TerminalPath, "/Applications/Utilities/Terminal.app --args -c cd")
390 IMPLEMENT_STRING(ArchiverPath, QQ("C:/Program Files/Lhaplus/Lhaplus.exe"))
391 IMPLEMENT_STRING(EditorPath, "notepad.exe")
392 IMPLEMENT_STRING(TerminalPath, "cmd.exe /k cd")
395 IMPLEMENT_STRING(CopyBehavior, "OverWriteIfNew")
396 IMPLEMENT_STRING(PreferExtensions, DefaultPreferExtensions())
398 #define IMPLEMENT_COLOR(key, defVal) \
399 QColor Preferences::get##key() const { \
400 return value("Appearance/"#key, def##key()).value<QColor>(); \
402 QColor Preferences::def##key() const { \
405 void Preferences::set##key(const QColor &value) { \
406 setValue("Appearance/"#key, value); \
409 IMPLEMENT_COLOR(FolderViewFgColor, QPalette().text().color())
410 IMPLEMENT_COLOR(FolderViewBgColor, QPalette().base().color())
411 IMPLEMENT_COLOR(FolderViewMarkedFgColor, QColor(128, 0, 0))
412 IMPLEMENT_COLOR(FolderViewMarkedBgColor, QColor(0, 192, 0))
413 IMPLEMENT_COLOR(FolderViewSystemColor, QColor(128, 0, 128))
414 IMPLEMENT_COLOR(FolderViewHiddenColor, QColor(128, 128, 128))
415 IMPLEMENT_COLOR(FolderViewReadOnlyColor, QColor(0, 128, 0))
416 IMPLEMENT_COLOR(LocationBoxFgColor, QPalette().text().color())
417 IMPLEMENT_COLOR(LocationBoxBgColor, QPalette().base().color())
418 IMPLEMENT_COLOR(SearchBoxFgColor, QPalette().text().color())
419 IMPLEMENT_COLOR(SearchBoxBgColor, QPalette().base().color())
420 IMPLEMENT_COLOR(SearchBoxUnmatchFgColor, QColor(255, 0, 0))
421 IMPLEMENT_COLOR(SearchBoxUnmatchBgColor, QPalette().base().color())
422 IMPLEMENT_COLOR(TextViewFgColor, QPalette().text().color())
423 IMPLEMENT_COLOR(TextViewCtrlColor, Qt::cyan)
424 IMPLEMENT_COLOR(TextViewBgColor, QPalette().base().color())
425 IMPLEMENT_COLOR(HexViewFgColor, getTextViewFgColor())
426 IMPLEMENT_COLOR(HexViewBgColor, getTextViewBgColor())
427 IMPLEMENT_COLOR(ImageViewBgColor, QPalette().base().color())
429 #define IMPLEMENT_DOUBLE(key, defVal) \
430 double Preferences::get##key() const { \
431 return value("Appearance/"#key, def##key()).toDouble(); \
433 double Preferences::def##key() const { \
436 void Preferences::set##key(double value) { \
437 setValue("Appearance/"#key, value); \
440 IMPLEMENT_DOUBLE(DarkFacotr, 0)
441 IMPLEMENT_DOUBLE(LineHeight, 1.5)
442 IMPLEMENT_DOUBLE(TextViewLineHeight, 1.0)
444 #define IMPLEMENT_FONT(key, defVal) \
445 QFont Preferences::get##key() const { \
446 return value("Appearance/"#key, def##key()).value<QFont>(); \
448 QFont Preferences::def##key() const { \
451 void Preferences::set##key(const QFont &value) { \
452 setValue("Appearance/"#key, value); \
455 IMPLEMENT_FONT(FolderViewFont, DefaultFixedFont())
456 IMPLEMENT_FONT(LocationBoxFont, DefaultFixedFont())
457 IMPLEMENT_FONT(SearchBoxFont, DefaultFixedFont())
458 IMPLEMENT_FONT(TextViewFont, DefaultFixedFont())
459 IMPLEMENT_FONT(HexViewFont, getTextViewFont())