From 3365a371e6b21f02010d5bdcebb76943202c5683 Mon Sep 17 00:00:00 2001 From: Masayuki Satoh Date: Thu, 21 Aug 2014 20:14:51 +0900 Subject: [PATCH] Ver0.03 --- Gefu.pro | 13 +- README.md | 17 +- clickablelabel.cpp | 6 + clickablelabel.h | 5 + colorsamplemodel.cpp | 82 +++++ colorsamplemodel.h | 27 ++ common.h | 37 ++- filetablemodel.cpp | 62 +++- filetablemodel.h | 12 + folderpanel.cpp | 31 ++ folderpanel.h | 2 + main.cpp | 5 + mainwindow.cpp | 85 ++++- mainwindow.h | 4 + preferencedialog.cpp | 316 ++++++++++++++++++- preferencedialog.h | 15 + preferencedialog.ui | 877 +++++++++++++++++++++++++++++++++++++++++++++++++-- 17 files changed, 1540 insertions(+), 56 deletions(-) diff --git a/Gefu.pro b/Gefu.pro index ef2c85e..047c213 100644 --- a/Gefu.pro +++ b/Gefu.pro @@ -28,7 +28,10 @@ SOURCES += main.cpp\ filetablemodel.cpp \ filetableview.cpp \ history.cpp \ - historydialog.cpp + historydialog.cpp \ + preferencedialog.cpp \ + clickablelabel.cpp \ + colorsamplemodel.cpp HEADERS += mainwindow.h \ folderpanel.h \ @@ -47,7 +50,10 @@ HEADERS += mainwindow.h \ filetablemodel.h \ filetableview.h \ history.h \ - historydialog.h + historydialog.h \ + preferencedialog.h \ + clickablelabel.h \ + colorsamplemodel.h FORMS += mainwindow.ui \ folderpanel.ui \ @@ -56,7 +62,8 @@ FORMS += mainwindow.ui \ operationdialog.ui \ overwritedialog.ui \ sortdialog.ui \ - historydialog.ui + historydialog.ui \ + preferencedialog.ui RESOURCES += \ resource.qrc diff --git a/README.md b/README.md index a3659da..4d677d7 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,24 @@ Gefu Gefu is Experimental File Utility. ### TODO -- 環境設定ダイアログ +- オプション + - ファンクションキー +- ドラッグ&ドロップ - 簡易テキストビューア - 簡易画像ビューア +- 簡易アーカイバ +- SNS連携(タイムライン表示とか) + +#### 2014/08/21 Ver0.03 公開 +- 環境設定ダイアログおよびオプションを実装。 + - 終了時の確認ダイアログ。 + - 起動時のウィンドウ位置・サイズ。 + - 起動時に設定をリセット。 + - 色とフォントの設定。 #### 2014/08/20 Ver0.02 公開 - QTableWidget -> QTableView + Modelへ変更し高速化。 -- フォルダ履歴機能を実装 +- フォルダ履歴機能を実装。 - 行の高さを調整。 - マーク時の背景色、前景色を変更。 - ウィンドウの位置・サイズを保存するようにした。 @@ -25,4 +36,4 @@ Gefu is Experimental File Utility. - ソート方法の選択機能を追加。 #### 2014/08/18 Ver0.00 公開 -- 新規 +- 新規。 diff --git a/clickablelabel.cpp b/clickablelabel.cpp index 0682ddf..52442a8 100644 --- a/clickablelabel.cpp +++ b/clickablelabel.cpp @@ -4,3 +4,9 @@ ClickableLabel::ClickableLabel(QWidget *parent) : QLabel(parent) { } + + +void ClickableLabel::mouseReleaseEvent(QMouseEvent *) +{ + emit clicked(); +} diff --git a/clickablelabel.h b/clickablelabel.h index 94fe249..81abe05 100644 --- a/clickablelabel.h +++ b/clickablelabel.h @@ -10,9 +10,14 @@ public: explicit ClickableLabel(QWidget *parent = 0); signals: + void clicked(); public slots: + + // QWidget interface +protected: + void mouseReleaseEvent(QMouseEvent *); }; #endif // CLICKABLELABEL_H diff --git a/colorsamplemodel.cpp b/colorsamplemodel.cpp index f997a68..7a0fb40 100644 --- a/colorsamplemodel.cpp +++ b/colorsamplemodel.cpp @@ -1,6 +1,88 @@ #include "colorsamplemodel.h" +#include + ColorSampleModel::ColorSampleModel(QObject *parent) : QAbstractTableModel(parent) { } + +void ColorSampleModel::setFont(const QFont &font) +{ + m_font = font; +} + +int ColorSampleModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return 3; +} + +int ColorSampleModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return 2; +} + +QVariant ColorSampleModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) { + return QVariant(); + } + + const QString strText[3][2] = { + { tr("通常"), tr("システム") }, + { tr("マーク"), tr("隠し属性") }, + { tr(""), tr("読取専用") } + }; + + switch (role) { + case Qt::DisplayRole: + return strText[index.row()][index.column()]; + + case Qt::FontRole: + return m_font; + break; + + case Qt::BackgroundRole: + switch (index.column()) { + case 0: + switch (index.row()) { + case 0: return QBrush(m_colorMap->value("clrBgNormal")); + case 1: return QBrush(m_colorMap->value("clrBgMark")); + } + break; + + case 1: + switch (index.row()) { + case 0: + case 1: + case 2: + return QBrush(m_colorMap->value("clrBgNormal")); + } + break; + } + break; + + case Qt::ForegroundRole: + switch (index.column()) { + case 0: + switch (index.row()) { + case 0: return QBrush(m_colorMap->value("clrFgNormal")); + case 1: return QBrush(m_colorMap->value("clrFgMark")); + } + break; + + case 1: + switch (index.row()) { + case 0: return QBrush(m_colorMap->value("clrFgSystem")); + case 1: return QBrush(m_colorMap->value("clrFgHidden")); + case 2: return QBrush(m_colorMap->value("clrFgReadonly")); + } + break; + } + break; + } + + return QVariant(); +} diff --git a/colorsamplemodel.h b/colorsamplemodel.h index 8476947..0593383 100644 --- a/colorsamplemodel.h +++ b/colorsamplemodel.h @@ -2,6 +2,10 @@ #define COLORSAMPLEMODEL_H #include +#include +#include + +typedef QMap ColorMap; class ColorSampleModel : public QAbstractTableModel { @@ -9,10 +13,33 @@ class ColorSampleModel : public QAbstractTableModel public: explicit ColorSampleModel(QObject *parent = 0); + const QFont& font() { return m_font; } + void setFont(const QFont &font); + + void setColorMap(ColorMap *colorMap) { + m_colorMap = colorMap; + } + + void update() { + beginResetModel(); + endResetModel(); + } + +private: + ColorMap *m_colorMap; + QFont m_font; + signals: public slots: + + // QAbstractItemModel interface +public: + int rowCount(const QModelIndex &parent) const; + int columnCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; }; + #endif // COLORSAMPLEMODEL_H diff --git a/common.h b/common.h index 6e4bf33..06847a7 100644 --- a/common.h +++ b/common.h @@ -8,14 +8,34 @@ class MainWindow; extern MainWindow* getMainWnd(); extern QString FilesizeToString(quint64 size); -#define VERSION_VALUE 0.02 +#define VERSION_VALUE 0.03 #define slash QString("/") #define QQ(x) ("\"" + (x) + "\"") #define IniKey_ShowHidden "Common/ShowHidden" #define IniKey_ShowSystem "Common/ShowSystem" +#define IniKey_ConfirmExit "BootAndExit/ConfirmExit" +#define IniKey_BootSizeSpec "BootAndExit/SizeSpec" +#define IniKey_BootSizeRel "BootAndExit/SizeRel" +#define IniKey_BootSizeAbs "BootAndExit/SizeAbs" +#define IniKey_BootPosSpec "BootAndExit/PosSpec" +#define IniKey_BootPosRel "BootAndExit/PosRel" +#define IniKey_BootPosAbs "BootAndExit/PosAbs" +#define IniKey_ResetOnBoot "BootAndExit/Reset" +#define IniKey_BoxColorFg "Appearance/BoxColorFg" +#define IniKey_BoxColorBg "Appearance/BoxColorBg" +#define IniKey_BoxFont "Appearance/BoxFont" +#define IniKey_ViewFont "Appearance/ViewFont" +#define IniKey_ViewColorBgNormal "Appearance/ViewColorBgNormal" +#define IniKey_ViewColorBgMark "Appearance/ViewColorBgMark" +#define IniKey_ViewColorFgNormal "Appearance/ViewColorFgNormal" +#define IniKey_ViewColorFgMark "Appearance/ViewColorFgMark" +#define IniKey_ViewColorFgSystem "Appearance/ViewColorFgSystem" +#define IniKey_ViewColorFgHidden "Appearance/ViewColorFgHidden" +#define IniKey_ViewColorFgReadonly "Appearance/ViewColorFgReadonly" #define IniKey_WindowGeometry "Window/Geometry" +#define iniKey_WindowState "Window/State" #define IniSec_Left "Left" #define IniSec_Right "Right" #define IniKey_Dir "dir" @@ -23,16 +43,6 @@ extern QString FilesizeToString(quint64 size); #define IniKey_OrderBy "OrderBy" #define IniKey_PutDirs "PutDirs" #define IniKey_IgnoreCase "IgnoreCase" -#define IniKey_LeftDir IniSec_Left"/"IniKey_Dir -#define IniKey_LeftSortBy IniSec_Left"/"IniKey_SortBy -#define IniKey_LeftOrderBy IniSec_Left"/"IniKey_OrderBy -#define IniKey_LeftPutDirs IniSec_Left"/"IniKey_PutDirs -#define IniKey_LeftIgnoreCase IniSec_Left"/"IniKey_IgnoreCase -#define IniKey_RightDir IniSec_Right"/"IniKey_Dir -#define IniKey_RightSortBy IniSec_Right"/"IniKey_SortBy -#define IniKey_RightOrderBy IniSec_Right"/"IniKey_OrderBy -#define IniKey_RightPutDirs IniSec_Right"/"IniKey_PutDirs -#define IniKey_RightIgnoreCase IniSec_Right"/"IniKey_IgnoreCase #define SortByName QDir::Name #define SortByDate QDir::Time @@ -46,5 +56,10 @@ extern QString FilesizeToString(quint64 size); #define PutDirsLast QDir::DirsLast #define PutDirsDefault 0 +#define DefaultMarkBgColor QColor(0, 192, 0) +#define DefaultMarkFgColor QColor(128, 0, 0) +#define DefaultSystemColor QColor(128, 0, 128) +#define DefaultHiddenColor QColor(128, 128, 128) +#define DefaultReadonlyColor QColor(0, 128, 0) #endif // COMMON_H diff --git a/filetablemodel.cpp b/filetablemodel.cpp index 0b70005..aa41e46 100644 --- a/filetablemodel.cpp +++ b/filetablemodel.cpp @@ -3,7 +3,9 @@ #include #include -#include +#include +#include +#include #ifdef Q_OS_WIN32 #include #endif @@ -14,7 +16,15 @@ FileTableModel::FileTableModel(QObject *parent) : m_fileInfoList(), m_checkStates(), m_IconFactory(), - m_fsWatcher(NULL) + m_fsWatcher(NULL), + m_font(), + m_NormalBrush(), + m_NormalTextBrush(), + m_MarkBrush(), + m_MarkTextBrush(), + m_SystemBrush(), + m_HiddenBrush(), + m_ReadonlyBrush() { } @@ -134,6 +144,27 @@ QFileInfo FileTableModel::fileInfo(const QModelIndex &index) const return m_fileInfoList[index.row()]; } +#define Brush(x, y, z) QBrush((x).value((y), (z)).value()); + + +void FileTableModel::updateAppearance() +{ + QSettings settings; + QPalette palette(QApplication::palette("QTableView")); + + m_font = settings.value(IniKey_ViewFont, QApplication::font()).value(); + m_NormalBrush = Brush(settings, IniKey_ViewColorBgNormal, palette.base()); + m_NormalTextBrush = Brush(settings, IniKey_ViewColorFgNormal, palette.text()); + m_MarkBrush = Brush(settings, IniKey_ViewColorBgMark, DefaultMarkBgColor); + m_MarkTextBrush = Brush(settings, IniKey_ViewColorFgMark, DefaultMarkFgColor); + m_SystemBrush = Brush(settings, IniKey_ViewColorFgSystem, DefaultSystemColor); + m_HiddenBrush = Brush(settings, IniKey_ViewColorFgHidden, DefaultHiddenColor); + m_ReadonlyBrush = Brush(settings, IniKey_ViewColorFgReadonly, DefaultReadonlyColor); + + beginResetModel(); + endResetModel(); +} + void FileTableModel::stateChanged() { int numFolder = 0; @@ -220,6 +251,9 @@ QVariant FileTableModel::data(const QModelIndex &index, int role) const } break; + case Qt::FontRole: + return m_font; + case Qt::TextAlignmentRole: switch (index.column()) { case 0: @@ -233,15 +267,31 @@ QVariant FileTableModel::data(const QModelIndex &index, int role) const case Qt::BackgroundRole: if (checked) { - return QBrush(QColor(0, 196, 0)); + return m_MarkBrush; } - break; + return m_NormalBrush; case Qt::ForegroundRole: if (checked) { - return QBrush(QColor(196, 0, 0)); + return m_MarkTextBrush; } - break; +#ifdef Q_OS_WIN32 + { + DWORD dwFlags = ::GetFileAttributes( + info.absoluteFilePath().toStdWString().c_str()); + if (dwFlags != DWORD(-1) && (dwFlags & FILE_ATTRIBUTE_SYSTEM) == FILE_ATTRIBUTE_SYSTEM)) + { + return m_SystemBrush; + } + } +#endif + if (info.isHidden() && info.fileName() != "..") { + return m_HiddenBrush; + } + if (!info.isWritable()) { + return m_ReadonlyBrush; + } + return m_NormalTextBrush; case Qt::CheckStateRole: if (index.column() == 0 && info.fileName() != "..") { diff --git a/filetablemodel.h b/filetablemodel.h index 22109b3..39f4ee4 100644 --- a/filetablemodel.h +++ b/filetablemodel.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include class FileTableModel : public QAbstractTableModel { @@ -30,6 +32,8 @@ public: QFileInfoList checkedItems() const; QFileInfo fileInfo(const QModelIndex &index) const; + void updateAppearance(); + signals: void rootChanged(const QString &root); void stateChanged(int checkedFoldrs, int checkedFiles, quint64 totalSize); @@ -43,6 +47,14 @@ private: QVector m_checkStates; QFileIconProvider m_IconFactory; QFileSystemWatcher *m_fsWatcher; + QFont m_font; + QBrush m_NormalBrush; + QBrush m_NormalTextBrush; + QBrush m_MarkBrush; + QBrush m_MarkTextBrush; + QBrush m_SystemBrush; + QBrush m_HiddenBrush; + QBrush m_ReadonlyBrush; void stateChanged(); diff --git a/folderpanel.cpp b/folderpanel.cpp index d4bbc00..470b20c 100644 --- a/folderpanel.cpp +++ b/folderpanel.cpp @@ -115,11 +115,42 @@ void FolderPanel::setSide(const QString &side) QString key = side + slash + IniKey_Dir; QString path = settings.value(key, QDir::homePath()).toString(); + model->updateAppearance(); ui->fileTable->setModel(model); ui->fileTable->setRootPath(path, true); ui->fileTable->selectRow(0); } +void FolderPanel::updateAppearance() +{ + QSettings settings; + QPalette palette; + QFont font; + + font = ui->locationField->font(); + font = settings.value(IniKey_BoxFont, font).value(); + palette = ui->locationField->palette(); + palette.setColor( + QPalette::Base, + settings.value(IniKey_BoxColorBg, palette.base()).value()); + palette.setColor( + QPalette::Text, + settings.value(IniKey_BoxColorFg, palette.text()).value()); + ui->locationField->setFont(font); + ui->locationField->setPalette(palette); + + palette = ui->fileTable->palette(); + palette.setColor( + QPalette::Base, + settings.value(IniKey_ViewColorBgNormal, palette.base()).value()); + ui->fileTable->setPalette(palette); + + FileTableModel *model = static_cast(ui->fileTable->model()); + if (model) { + model->updateAppearance(); + } +} + void FolderPanel::onStateChanged(int checkedFolders, int checkedFiles, quint64 totalSize) { QString msg = ""; diff --git a/folderpanel.h b/folderpanel.h index 8d80485..6d7c2f4 100644 --- a/folderpanel.h +++ b/folderpanel.h @@ -27,6 +27,8 @@ public: const QString side() const; void setSide(const QString &side); + void updateAppearance(); + private: Ui::FolderPanel *ui; diff --git a/main.cpp b/main.cpp index 872b46d..b2e731f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,4 @@ +#include "common.h" #include "mainwindow.h" #include #include @@ -11,6 +12,10 @@ int main(int argc, char *argv[]) a.setWindowIcon(QIcon(":/images/Gefu.png")); QSettings::setDefaultFormat(QSettings::IniFormat); + QSettings settings; + if (settings.value(IniKey_ResetOnBoot, false).toBool()) { + settings.clear(); + } MainWindow w; w.show(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 9bd1350..80a23a4 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,6 +7,7 @@ #include "renamesingledialog.h" #include "renameworker.h" #include "sortdialog.h" +#include "preferencedialog.h" #include "ui_mainwindow.h" #include #include @@ -18,6 +19,8 @@ #include #include #include +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -26,6 +29,8 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); ui->RPanel->setSide("Right"); ui->LPanel->setSide("Left"); + ui->LPanel->updateAppearance(); + ui->RPanel->updateAppearance(); ui->LPanel->fileTable()->setFocus(); QSettings settings; @@ -48,7 +53,7 @@ MainWindow::MainWindow(QWidget *parent) : // シグナル/スロットを設定する connect(ui->action_Setting, SIGNAL(triggered()), this, SLOT(onActionSetting())); - connect(ui->action_Quit, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(ui->action_Quit, SIGNAL(triggered()), this, SLOT(close())); connect(ui->help_About, SIGNAL(triggered()), this, SLOT(onHelpAbout())); connect(ui->view_Hidden, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles())); connect(ui->view_System, SIGNAL(triggered()), this, SLOT(toggleShowSystemFiles())); @@ -57,21 +62,49 @@ MainWindow::MainWindow(QWidget *parent) : setWindowTitle(tr("げふぅ v%1").arg(VERSION_VALUE)); // ウィンドウアイコンを設定する setWindowIcon(QIcon(":/images/Gefu.png")); - // ウィンドウサイズと位置を設定する - QRect rc = settings.value(IniKey_WindowGeometry, QRect()).toRect(); - if (rc != QRect()) { - this->setGeometry(rc); + //>>>>> ウィンドウサイズと位置を設定する + QString strValue; + QPoint point = this->geometry().topLeft(); + QSize size = this->geometry().size(); + //>>>> 前回の位置・サイズ・状態を復元する + restoreGeometry(settings.value(IniKey_WindowGeometry).toByteArray()); + restoreState(settings.value(iniKey_WindowState).toByteArray()); + //>>>> INIファイルの設定から復元する + //>>> サイズ + strValue = settings.value(IniKey_BootSizeSpec, "").toString(); + if (strValue == "sizeAbsolute") { + size = settings.value(IniKey_BootSizeAbs).toSize(); + } + else if (strValue == "sizeRelative") { + size = settings.value(IniKey_BootSizeRel).toSize(); + size.setWidth(size.width() * QApplication::desktop()->width() / 100.0); + size.setHeight(size.height() * QApplication::desktop()->height() / 100.0); + } + else if (strValue == "sizeLast") { + size = this->geometry().size(); + } + //>>> 位置 + strValue = settings.value(IniKey_BootPosSpec, "").toString(); + if (strValue == "posAbsolute") { + point = settings.value(IniKey_BootPosAbs).toPoint(); + } + else if (strValue == "posRelative") { + point = settings.value(IniKey_BootPosRel).toPoint(); + point.setX(point.x() * QApplication::desktop()->width() / 100.0); + point.setY(point.y() * QApplication::desktop()->height() / 100.0); + } + else if (strValue == "posLast") { + point = this->geometry().topLeft(); } else { - this->resize(800, 600); + point.setX((QApplication::desktop()->width() - size.width()) / 2); + point.setY((QApplication::desktop()->height() - size.height()) / 2); } + this->setGeometry(QRect(point, size)); } MainWindow::~MainWindow() { - QSettings settings; - settings.setValue(IniKey_WindowGeometry, this->geometry()); - delete ui; } @@ -91,7 +124,12 @@ FileTableView *MainWindow::otherSideView(const FileTableView *view) const void MainWindow::onActionSetting() { - QMessageBox::information(this, tr("情報"), tr("環境設定機能は未実装です。")); + PreferenceDialog dlg(this); + + if (dlg.exec() == QDialog::Accepted) { + ui->LPanel->updateAppearance(); + ui->RPanel->updateAppearance(); + } } void MainWindow::toggleShowHiddenFiles() @@ -141,3 +179,30 @@ MainWindow* getMainWnd() qDebug() << "MainWindow not found !?"; return NULL; } + + +void MainWindow::closeEvent(QCloseEvent *event) +{ + qDebug() << "closeEvent();"; + + QSettings settings; + + if (settings.value(IniKey_ConfirmExit, true).toBool()) { + QMessageBox msgBox; + QCheckBox *checkBox = new QCheckBox(); + checkBox->setText(tr("次回以降は確認しない")); + msgBox.setCheckBox(checkBox); + msgBox.setText(tr("終了しますか?")); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + + if (msgBox.exec() == QMessageBox::No) { + event->ignore(); + return; + } + settings.setValue(IniKey_ConfirmExit, !checkBox->isChecked()); + } + + settings.setValue(IniKey_WindowGeometry, saveGeometry()); + settings.setValue(iniKey_WindowState, saveState()); + QMainWindow::closeEvent(event); +} diff --git a/mainwindow.h b/mainwindow.h index d4e6710..10fb6c4 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -34,6 +34,10 @@ private slots: private: Ui::MainWindow *ui; + + // QWidget interface +protected: + void closeEvent(QCloseEvent *event); }; #endif // MAINWINDOW_H diff --git a/preferencedialog.cpp b/preferencedialog.cpp index 427b509..7cfb1f6 100644 --- a/preferencedialog.cpp +++ b/preferencedialog.cpp @@ -1,14 +1,328 @@ +#include "colorsamplemodel.h" +#include"common.h" #include "preferencedialog.h" #include "ui_preferencedialog.h" +#include +#include +#include +#include +#include + + + PreferenceDialog::PreferenceDialog(QWidget *parent) : QDialog(parent), - ui(new Ui::PreferenceDialog) + ui(new Ui::PreferenceDialog), + m_model(), + m_colorMap() { + m_model.setColorMap(&m_colorMap); + ui->setupUi(this); + ui->tabWidget->setCurrentIndex(0); + ui->tabWidget->setTabText(0, "起動と終了"); + ui->tabWidget->setTabText(1, "色とフォント"); + ui->sampleEdit->setText(QDir::homePath()); + ui->sampleTable->setModel(&m_model); + ui->sampleTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + ui->sampleTable->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); + + connect(ui->bootSize, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool))); + connect(ui->sizeAbsolute, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool))); + connect(ui->sizeRelative, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool))); + connect(ui->bootPos, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool))); + connect(ui->posAbsolute, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool))); + connect(ui->posRelative, SIGNAL(toggled(bool)), this, SLOT(setControlsEnabled(bool))); + + connect(ui->boxClrBg, SIGNAL(clicked()), this, SLOT(selectBoxColor())); + connect(ui->boxClrFg, SIGNAL(clicked()), this, SLOT(selectBoxColor())); + + connect(ui->clrBgMark, SIGNAL(clicked()), this, SLOT(selectViewColor())); + connect(ui->clrBgNormal, SIGNAL(clicked()), this, SLOT(selectViewColor())); + connect(ui->clrFgHidden, SIGNAL(clicked()), this, SLOT(selectViewColor())); + connect(ui->clrFgMark, SIGNAL(clicked()), this, SLOT(selectViewColor())); + connect(ui->clrFgNormal, SIGNAL(clicked()), this, SLOT(selectViewColor())); + connect(ui->clrFgReadonly, SIGNAL(clicked()), this, SLOT(selectViewColor())); + connect(ui->clrFgSystem, SIGNAL(clicked()), this, SLOT(selectViewColor())); + + connect(ui->boxFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(changeFont())); + connect(ui->boxFontBold, SIGNAL(clicked()), this, SLOT(changeFont())); + connect(ui->boxFontSize, SIGNAL(valueChanged(int)), this, SLOT(changeFont())); + + connect(ui->viewFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(changeFont())); + connect(ui->viewFontBold, SIGNAL(clicked()), this, SLOT(changeFont())); + connect(ui->viewFontSize, SIGNAL(valueChanged(int)), this, SLOT(changeFont())); + + QSettings settings; + QString strValue; + QSize size; + QPoint point; + QColor color; + QPalette palette; + QFont font; + QRadioButton *radioBtn; + + //>>>>> 起動と終了 + // 終了時の確認ダイアログ + ui->confirmExit->setChecked(settings.value(IniKey_ConfirmExit, true).toBool()); + // 起動時のサイズ + strValue = settings.value(IniKey_BootSizeSpec, "sizeLast").toString(); + if (strValue.isEmpty()) { + ui->bootSize->setChecked(false); + } + else { + ui->bootSize->setChecked(true); + radioBtn = findChild(strValue); + if (radioBtn == NULL) { + radioBtn = ui->sizeLast; + } + radioBtn->setChecked(true); + } + size = settings.value(IniKey_BootSizeAbs, QSize(800, 600)).toSize(); + ui->absoluteWidth->setValue(size.width()); + ui->absoluteHeight->setValue(size.height()); + size = settings.value(IniKey_BootSizeRel, QSize(50, 50)).toSize(); + ui->relativeWidth->setValue(size.width()); + ui->relativeHeight->setValue(size.height()); + // 起動時の位置 + strValue = settings.value(IniKey_BootPosSpec, "posLast").toString(); + if (strValue.isEmpty()) { + ui->bootPos->setChecked(false); + } + else { + ui->bootPos->setChecked(true); + radioBtn = findChild(strValue); + if (radioBtn == NULL) { + radioBtn = ui->posLast; + } + radioBtn->setChecked(true); + } + point = settings.value(IniKey_BootPosAbs, QPoint(0, 0)).toPoint(); + ui->absoluteLeft->setValue(point.x()); + ui->absoluteTop->setValue(point.y()); + point = settings.value(IniKey_BootPosRel, QPoint(0, 0)).toPoint(); + ui->relativeLeft->setValue(point.x()); + ui->relativeTop->setValue(point.y()); + // 起動時の設定削除 + ui->resetOnBoot->setChecked(settings.value(IniKey_ResetOnBoot, false).toBool()); + + //>>>>> 色とフォント + //>>>> アドレスボックス + palette = QPalette(); + // 背景色 + color = settings.value(IniKey_BoxColorBg, QPalette().base().color()).value(); + palette.setColor(QPalette::Background, color); + // 文字色 + color = settings.value(IniKey_BoxColorFg, QPalette().text().color()).value(); + palette.setColor(QPalette::Text, color); + // フォント + QFont defaultFont = ui->sampleEdit->font(); + font = settings.value(IniKey_BoxFont, defaultFont).value(); + ui->boxFont->setCurrentText(font.family()); + ui->boxFontBold->setChecked(font.bold()); + ui->boxFontSize->setValue(font.pointSize()); + // サンプル表示 + ui->sampleEdit->setPalette(palette); + ui->sampleEdit->setFont(font); + //>>>> ファイルビュー + // 背景色 + color = settings.value(IniKey_ViewColorBgMark, DefaultMarkBgColor).value(); + m_colorMap["clrBgMark"] = color; + color = settings.value(IniKey_ViewColorBgNormal, QPalette().base().color()).value(); + m_colorMap["clrBgNormal"] = color; + // 文字色 + color = settings.value(IniKey_ViewColorFgHidden, DefaultHiddenColor).value(); + m_colorMap["clrFgHidden"] = color; + color = settings.value(IniKey_ViewColorFgMark, DefaultMarkFgColor).value(); + m_colorMap["clrFgMark"] = color; + color = settings.value(IniKey_ViewColorFgNormal, QPalette().text().color()).value(); + m_colorMap["clrFgNormal"] = color; + color = settings.value(IniKey_ViewColorFgReadonly, DefaultReadonlyColor).value(); + m_colorMap["clrFgReadonly"] = color; + color = settings.value(IniKey_ViewColorFgSystem, DefaultSystemColor).value(); + m_colorMap["clrFgSystem"] = color; + // フォント + defaultFont = ui->sampleTable->font(); + font = settings.value(IniKey_ViewFont, defaultFont).value(); + ui->viewFont->setCurrentText(font.family()); + ui->viewFontBold->setChecked(font.bold()); + ui->viewFontSize->setValue(font.pointSize()); + // サンプル表示 + m_model.setFont(font); + m_model.update(); } PreferenceDialog::~PreferenceDialog() { delete ui; } + +void PreferenceDialog::changeFont() +{ + QFont font; + + if (sender() == ui->boxFont || + sender() == ui->boxFontBold || + sender() == ui->boxFontSize) + { + font.setBold(ui->boxFontBold->isChecked()); + font.setPointSize(ui->boxFontSize->value()); + font.setFamily(ui->boxFont->currentText()); + ui->sampleEdit->setFont(font); + } + else { + font.setBold(ui->viewFontBold->isChecked()); + font.setPointSize(ui->viewFontSize->value()); + font.setFamily(ui->viewFont->currentText()); + m_model.setFont(font); + m_model.update(); + } +} + +void PreferenceDialog::setControlsEnabled(bool enabled) +{ + if (sender() == ui->bootSize) { + ui->sizeAbsolute->setEnabled(enabled); + ui->sizeLast->setEnabled(enabled); + ui->sizeRelative->setEnabled(enabled); + if (enabled) { + emit ui->sizeAbsolute->toggled(ui->sizeAbsolute->isChecked()); + emit ui->sizeRelative->toggled(ui->sizeRelative->isChecked()); + } + else { + emit ui->sizeAbsolute->toggled(false); + emit ui->sizeRelative->toggled(false); + } + } + else if (sender() == ui->sizeAbsolute) { + ui->absoluteHeight->setEnabled(enabled); + ui->absoluteWidth->setEnabled(enabled); + } + else if (sender() == ui->sizeRelative) { + ui->relativeHeight->setEnabled(enabled); + ui->relativeWidth->setEnabled(enabled); + } + else if (sender() == ui->bootPos) { + ui->posAbsolute->setEnabled(enabled); + ui->posCenter->setEnabled(enabled); + ui->posLast->setEnabled(enabled); + ui->posRelative->setEnabled(enabled); + if (enabled) { + emit ui->posAbsolute->toggled(ui->posAbsolute->isChecked()); + emit ui->posRelative->toggled(ui->posRelative->isChecked()); + } + else { + emit ui->posAbsolute->toggled(false); + emit ui->posRelative->toggled(false); + } + } + else if (sender() == ui->posAbsolute) { + ui->absoluteLeft->setEnabled(enabled); + ui->absoluteTop->setEnabled(enabled); + } + else if (sender() == ui->posRelative) { + ui->relativeLeft->setEnabled(enabled); + ui->relativeTop->setEnabled(enabled); + } +} + +void PreferenceDialog::selectBoxColor() +{ + QColor color; + QPalette palette = ui->sampleEdit->palette(); + if (sender() == ui->boxClrBg) { + color = palette.background().color(); + } + else if (sender() == ui->boxClrFg) { + color = palette.text().color(); + } + + color = QColorDialog::getColor(color, this, tr("色選択")); + if (!color.isValid()) { + return; + } + + if (sender() == ui->boxClrBg) { + palette.setColor(QPalette::Base, color); + ui->sampleEdit->setPalette(palette); + } + else if (sender() == ui->boxClrFg) { + palette.setColor(QPalette::Text, color); + ui->sampleEdit->setPalette(palette); + } +} + +void PreferenceDialog::selectViewColor() +{ + const QString objName = sender()->objectName(); + QColor color = m_colorMap[objName]; + + color = QColorDialog::getColor(color, this, tr("色選択")); + if (!color.isValid()) { + return; + } + + m_colorMap[objName] = color; + m_model.update(); +} + +void PreferenceDialog::accept() +{ + QSettings settings; + QAbstractButton *selected; + + //>>>>> 起動と終了 + // 終了時の確認ダイアログ + settings.setValue(IniKey_ConfirmExit, ui->confirmExit->isChecked()); + // 起動時のサイズ + if (!ui->bootSize->isChecked()) { + settings.setValue(IniKey_BootSizeSpec, ""); + } + else { + selected = ui->sizeOptions->checkedButton(); + settings.setValue(IniKey_BootSizeSpec, selected->objectName()); + QSize size; + // 絶対指定 + size = QSize(ui->absoluteWidth->value(), ui->absoluteHeight->value()); + settings.setValue(IniKey_BootSizeAbs, size); + // 相対指定 + size = QSize(ui->relativeWidth->value(), ui->relativeHeight->value()); + settings.setValue(IniKey_BootSizeRel, size); + } + // 起動時の位置 + if (!ui->bootPos->isChecked()) { + settings.setValue(IniKey_BootPosSpec, ""); + } + else { + selected = ui->posOptions->checkedButton(); + settings.setValue(IniKey_BootPosSpec, selected->objectName()); + // 絶対指定 + QPoint pos; + pos = QPoint(ui->absoluteLeft->value(), ui->absoluteTop->value()); + settings.setValue(IniKey_BootPosAbs, pos); + // 相対指定 + pos = QPoint(ui->relativeLeft->value(), ui->relativeTop->value()); + settings.setValue(IniKey_BootPosRel, pos); + } + // 起動時の設定削除 + settings.setValue(IniKey_ResetOnBoot, ui->resetOnBoot->isChecked()); + + //>>>>> 色とフォント + QFont font = ui->sampleEdit->font(); + QPalette palette = ui->sampleEdit->palette(); + settings.setValue(IniKey_BoxColorBg, palette.base().color()); + settings.setValue(IniKey_BoxColorFg, palette.text().color()); + settings.setValue(IniKey_BoxFont, font); + + settings.setValue(IniKey_ViewColorBgMark, m_colorMap["clrBgMark"]); + settings.setValue(IniKey_ViewColorBgNormal, m_colorMap["clrBgNormal"]); + settings.setValue(IniKey_ViewColorFgHidden, m_colorMap["clrFgHidden"]); + settings.setValue(IniKey_ViewColorFgMark, m_colorMap["clrFgMark"]); + settings.setValue(IniKey_ViewColorFgNormal, m_colorMap["clrFgNormal"]); + settings.setValue(IniKey_ViewColorFgReadonly, m_colorMap["clrFgReadonly"]); + settings.setValue(IniKey_ViewColorFgSystem, m_colorMap["clrFgSystem"]); + settings.setValue(IniKey_ViewFont, m_model.font()); + + QDialog::accept(); +} diff --git a/preferencedialog.h b/preferencedialog.h index 414f4e8..867abaf 100644 --- a/preferencedialog.h +++ b/preferencedialog.h @@ -1,7 +1,10 @@ #ifndef PREFERENCEDIALOG_H #define PREFERENCEDIALOG_H +#include "colorsamplemodel.h" + #include +#include namespace Ui { class PreferenceDialog; @@ -17,6 +20,18 @@ public: private: Ui::PreferenceDialog *ui; + ColorSampleModel m_model; + ColorMap m_colorMap; + +private slots: + void changeFont(); + void setControlsEnabled(bool enabled); + void selectBoxColor(); + void selectViewColor(); + + // QDialog interface +public slots: + void accept(); }; #endif // PREFERENCEDIALOG_H diff --git a/preferencedialog.ui b/preferencedialog.ui index 0b5e46c..070dc1e 100644 --- a/preferencedialog.ui +++ b/preferencedialog.ui @@ -1,38 +1,867 @@ + - - - PreferenceDialog 0 0 - 400 - 300 + 687 + 531 + + + 0 + 0 + + Dialog - - - - 30 - 240 - 341 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + + 0 + + + + Tab 1 + + + + + + 終了時に確認ダイアログを表示する + + + + + + + 起動時のウィンドウサイズを指定する + + + + + + + -1 + + + QLayout::SetFixedSize + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + 絶対指定 + + + sizeOptions + + + + + + + + + 幅 + + + + + + + 9999 + + + + + + + px + + + + + + + + + + + 高さ + + + + + + + 9999 + + + + + + + px + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + QLayout::SetMinimumSize + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + 相対指定 + + + sizeOptions + + + + + + + + + 幅 + + + + + + + 100 + + + + + + + % + + + + + + + + + + + 高さ + + + + + + + 100 + + + + + + + % + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QLayout::SetMinimumSize + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + 前回終了時のサイズ + + + sizeOptions + + + + + + + + + 起動時のウィンドウ位置を指定する + + + + + + + -1 + + + QLayout::SetFixedSize + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + 絶対指定 + + + posOptions + + + + + + + + + X + + + + + + + 9999 + + + + + + + px + + + + + + + + + + + Y + + + + + + + 9999 + + + + + + + px + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + QLayout::SetMinimumSize + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + 相対指定 + + + posOptions + + + + + + + + + X + + + + + + + 100 + + + + + + + % + + + + + + + + + + + Y + + + + + + + 100 + + + + + + + % + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QLayout::SetMinimumSize + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + 画面中央 + + + posOptions + + + + + + + + + QLayout::SetMinimumSize + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + 前回終了時の位置 + + + posOptions + + + + + + + + + 次回起動時に設定ファイルをクリアする + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Tab 2 + + + + + + アドレスボックス + + + + + + + + フォント + + + + + + + true + + + + + + + 1 + + + + + + + pt + + + + + + + 太字 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + 文字色 + + + + + + + 背景色 + + + + + + + サンプルテキスト + + + + + + + + + + + + ファイルビュー + + + + + + + + フォント + + + + + + + + + + 1 + + + + + + + pt + + + + + + + 太字 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + 文字色 + + + + + + + + 通常 + + + + + + + マーク + + + + + + + + + + + システム + + + + + + + 隠し属性 + + + + + + + 読取専用 + + + + + + + + + + + + 背景色 + + + + + + 通常 + + + + + + + マーク + + + + + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 3 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + - + + tabWidget + confirmExit + bootSize + sizeAbsolute + absoluteWidth + absoluteHeight + sizeRelative + relativeWidth + relativeHeight + sizeLast + bootPos + posAbsolute + absoluteLeft + absoluteTop + posRelative + relativeLeft + relativeTop + posCenter + posLast + boxFont + boxFontSize + boxFontBold + viewFont + viewFontSize + viewFontBold + @@ -68,4 +897,8 @@ + + + + -- 2.11.0