From: Masayuki Satoh Date: Sun, 14 Sep 2014 23:32:21 +0000 (+0900) Subject: 高速化の試み X-Git-Url: http://git.osdn.net/view?p=gefu%2FGefu.git;a=commitdiff_plain;h=98c2e8d474985928d572638faea22f909a39ba73 高速化の試み --- diff --git a/foldermodel.cpp b/foldermodel.cpp index 6b4cacc..43565f6 100644 --- a/foldermodel.cpp +++ b/foldermodel.cpp @@ -29,7 +29,9 @@ FolderModel::FolderModel(QObject *parent) : m_history(), m_historyPos(-1), m_pixmapCache(), - m_pixmapCacheMutex() + m_pixmapCacheMutex(), + m_Palette(), + m_font() { connect(&m_fsWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(fsWatcher_directoryChanged(QString))); } @@ -292,6 +294,25 @@ QModelIndex FolderModel::touch(const QString &name) } /////////////////////////////////////////////////////////////////////////////// +/// \brief FolderModel::updateAppearance +/// +/// 外観を変更します。 +/// +void FolderModel::updateAppearance(const Preferences &prefs) +{ + qDebug() << "FolderModel::updateAppearance()"; + + m_font = prefs.getFolderViewFont(); + m_Palette.setColor(QPalette::Base, prefs.folderViewBgColor(isActive())); + m_Palette.setColor(QPalette::Text, prefs.folderViewFgColor(isActive())); + m_Palette.setColor(QPalette::Highlight, prefs.folderViewMarkedBgColor(isActive())); + m_Palette.setColor(QPalette::HighlightedText, prefs.folderViewMarkedFgColor(isActive())); + m_Palette.setColor(QPalette::Dark, prefs.folderViewHiddenColor(isActive())); + m_Palette.setColor(QPalette::Light, prefs.folderViewReadOnlyColor(isActive())); + m_Palette.setColor(QPalette::Mid, prefs.folderViewSystemColor(isActive())); +} + +/////////////////////////////////////////////////////////////////////////////// /// \brief FolderModel::activeModel /// \return アクティブなモデルを返します。 /// @@ -461,8 +482,6 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const return QVariant(); } - Preferences prefs(const_cast(this)); - switch (role) { case Qt::DisplayRole: switch (index.column()) { @@ -496,7 +515,7 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const break; case Qt::FontRole: - return prefs.getFolderViewFont(); + return m_font; case Qt::TextAlignmentRole: switch (index.column()) { @@ -508,24 +527,24 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const case Qt::BackgroundRole: if (isMarked(index)) { - return QBrush(prefs.folderViewMarkedBgColor(isActive())); + return marked(); } - return QBrush(prefs.folderViewBgColor(isActive())); + return base(); case Qt::ForegroundRole: if (isMarked(index)) { - return QBrush(prefs.folderViewMarkedFgColor(isActive())); + return markedText(); } if (fileName(index) != ".." && Win32::hasSystemAttribute(filePath(index))) { - return QBrush(prefs.folderViewSystemColor(isActive())); + return system(); } if (fileName(index) != ".." && fileInfo(index).isHidden()) { - return QBrush(prefs.folderViewHiddenColor(isActive())); + return hidden(); } if (fileName(index) != ".." && !fileInfo(index).isWritable()) { - return QBrush(prefs.folderViewReadOnlyColor(isActive())); + return readOnly(); } - return QBrush(prefs.folderViewFgColor(isActive())); + return text(); case Qt::CheckStateRole: if (index.column() == Name && fileName(index) != "..") { diff --git a/foldermodel.h b/foldermodel.h index 478b2cf..23ddf3e 100644 --- a/foldermodel.h +++ b/foldermodel.h @@ -8,6 +8,8 @@ #include #include #include +#include +class Preferences; class FolderModel : public QAbstractTableModel { @@ -51,6 +53,7 @@ public: void setSorting(QDir::SortFlags sort); QDir::SortFlags sorting() const; QModelIndex touch(const QString &name); + void updateAppearance(const Preferences &prefs); static FolderModel* activeModel(); @@ -86,10 +89,20 @@ private: int m_historyPos; PixmapContainer m_pixmapCache; QMutex m_pixmapCacheMutex; + QPalette m_Palette; + QFont m_font; bool isDotFile(const QModelIndex &index) const; void setError(const QString &error = QString()); + const QBrush& base() const; + const QBrush& text() const; + const QBrush& marked() const; + const QBrush& markedText() const; + const QBrush& hidden() const; + const QBrush& readOnly() const; + const QBrush& system() const; + // QAbstractItemModel interface public: int rowCount(const QModelIndex &parent = QModelIndex()) const; @@ -211,4 +224,32 @@ inline void FolderModel::fsWatcher_directoryChanged(const QString &path) refresh(); } +inline const QBrush& FolderModel::base() const +{ + return m_Palette.base(); +} +inline const QBrush& FolderModel::text() const +{ + return m_Palette.text(); +} +inline const QBrush& FolderModel::marked() const +{ + return m_Palette.highlight(); +} +inline const QBrush& FolderModel::markedText() const +{ + return m_Palette.highlightedText(); +} +inline const QBrush& FolderModel::hidden() const +{ + return m_Palette.dark(); +} +inline const QBrush& FolderModel::readOnly() const +{ + return m_Palette.light(); +} +inline const QBrush& FolderModel::system() const +{ + return m_Palette.mid(); +} #endif // FOLDERMODEL_H diff --git a/folderpanel.cpp b/folderpanel.cpp index 78c1fd1..a9a4a9e 100644 --- a/folderpanel.cpp +++ b/folderpanel.cpp @@ -167,11 +167,10 @@ void FolderPanel::toggleView(bool checked) /// /// 外観を変更します。 /// -void FolderPanel::updateAppearance() +void FolderPanel::updateAppearance(const Preferences &prefs) { qDebug() << "FolderPanel::updateAppearance()"; - Preferences prefs(this); QPalette pal; pal = ui->locationBox->palette(); diff --git a/folderpanel.h b/folderpanel.h index d2ce27f..342425c 100644 --- a/folderpanel.h +++ b/folderpanel.h @@ -5,7 +5,7 @@ #include class FolderModel; class MainWindow; - +class Preferences; namespace Ui { class FolderPanel; @@ -28,7 +28,7 @@ public: void setModel(FolderModel *m); void toggleSearch(bool checked); void toggleView(bool checked); - void updateAppearance(); + void updateAppearance(const Preferences &prefs); private: Ui::FolderPanel *ui; diff --git a/folderview.cpp b/folderview.cpp index a9619fc..73d818e 100644 --- a/folderview.cpp +++ b/folderview.cpp @@ -42,8 +42,8 @@ void FolderView::initialize(MainWindow *w) qDebug() << "FolderView::initialize()"; connect(this, SIGNAL(doubleClicked(QModelIndex)), w, SLOT(onOpen(QModelIndex))); - connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), - w, SLOT(view_currentChanged(QModelIndex,QModelIndex))); +// connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), +// w, SLOT(view_currentChanged(QModelIndex,QModelIndex))); installEventFilter(w); viewport()->installEventFilter(w); diff --git a/mainwindow.cpp b/mainwindow.cpp index 97ea4d5..c6b44a0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -42,7 +42,8 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow), m_overwriteDialog(this), m_viewMode(ModeBasic), - m_prevMode(ModeBasic) + m_prevMode(ModeBasic), + m_actions() { ui->setupUi(this); connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), this, SLOT(app_focusChange(QWidget*,QWidget*))); @@ -101,6 +102,11 @@ MainWindow::MainWindow(QWidget *parent) : if (prefs.isCheckUpdate()) { onCheckUpdate(true); } + + ui->LPanel->updateAppearance(prefs); + ui->LPanel->model()->updateAppearance(prefs); + ui->RPanel->updateAppearance(prefs); + ui->RPanel->model()->updateAppearance(prefs); } /////////////////////////////////////////////////////////////////////////////// @@ -130,6 +136,8 @@ void MainWindow::app_focusChange(QWidget *old, QWidget *now) if (now && (now->objectName() == "folderView" || now->objectName() == "thumbnailView")) { + connect(focusItemView()->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), + this, SLOT(view_currentChanged(QModelIndex,QModelIndex))); FolderModel *m = static_cast(focusItemView()->model()); setActiveModel(m); ui->statusBar->showMessage(m->filePath(focusItemView()->currentIndex())); @@ -1460,9 +1468,19 @@ void MainWindow::onScaleDown() view->scaleDown(); } - ui->LPanel->updateAppearance(); - ui->RPanel->updateAppearance(); - ui->FPanel->updateAppearance(); + Preferences prefs(this); + if (ui->LPanel->isVisible()) { + ui->LPanel->updateAppearance(prefs); + ui->LPanel->model()->updateAppearance(prefs); + } + if (ui->RPanel->isVisible()) { + ui->RPanel->updateAppearance(prefs); + ui->RPanel->model()->updateAppearance(prefs); + } + if (ui->FPanel->isVisible()) { + ui->FPanel->updateAppearance(prefs); + ui->FPanel->model()->updateAppearance(prefs); + } } /////////////////////////////////////////////////////////////////////////////// @@ -1479,9 +1497,19 @@ void MainWindow::onScaleUp() view->scaleUp(); } - ui->LPanel->updateAppearance(); - ui->RPanel->updateAppearance(); - ui->FPanel->updateAppearance(); + Preferences prefs(this); + if (ui->LPanel->isVisible()) { + ui->LPanel->updateAppearance(prefs); + ui->LPanel->model()->updateAppearance(prefs); + } + if (ui->RPanel->isVisible()) { + ui->RPanel->updateAppearance(prefs); + ui->RPanel->model()->updateAppearance(prefs); + } + if (ui->FPanel->isVisible()) { + ui->FPanel->updateAppearance(prefs); + ui->FPanel->model()->updateAppearance(prefs); + } } /////////////////////////////////////////////////////////////////////////////// @@ -1512,6 +1540,8 @@ void MainWindow::initBookmarkMenu() SLOT(onOpenBookmark())); action->setData(n); } + + m_actions = findChildren(); } /////////////////////////////////////////////////////////////////////////////// @@ -1605,9 +1635,19 @@ void MainWindow::showPreferenceDialog() PreferenceDialog dlg(this); if (dlg.exec() == QDialog::Accepted) { - ui->LPanel->updateAppearance(); - ui->RPanel->updateAppearance(); - ui->FPanel->updateAppearance(); + Preferences prefs(this); + if (ui->LPanel->isVisible()) { + ui->LPanel->updateAppearance(prefs); + ui->LPanel->model()->updateAppearance(prefs); + } + if (ui->RPanel->isVisible()) { + ui->RPanel->updateAppearance(prefs); + ui->RPanel->model()->updateAppearance(prefs); + } + if (ui->FPanel->isVisible()) { + ui->FPanel->updateAppearance(prefs); + ui->FPanel->model()->updateAppearance(prefs); + } } } @@ -1846,9 +1886,19 @@ void MainWindow::setActiveModel(FolderModel *m) connect(ui->action_MarkInvert, SIGNAL(triggered()), activeModel(), SLOT(onMarkInvert())); connect(ui->action_Refresh, SIGNAL(triggered()), activeModel(), SLOT(refresh())); - ui->LPanel->updateAppearance(); - ui->RPanel->updateAppearance(); - ui->FPanel->updateAppearance(); + Preferences prefs(this); + if (ui->LPanel->isVisible()) { + ui->LPanel->updateAppearance(prefs); + ui->LPanel->model()->updateAppearance(prefs); + } + if (ui->RPanel->isVisible()) { + ui->RPanel->updateAppearance(prefs); + ui->RPanel->model()->updateAppearance(prefs); + } + if (ui->FPanel->isVisible()) { + ui->FPanel->updateAppearance(prefs); + ui->FPanel->model()->updateAppearance(prefs); + } } /////////////////////////////////////////////////////////////////////////////// @@ -2179,98 +2229,6 @@ void MainWindow::updateActions() ui->action_historyBack->setEnabled(!activeModel()->isHistoryBegin()); ui->action_HistoryForward->setEnabled(!activeModel()->isHistoryEnd()); - -#if 0 - FolderView *view; - if ((view = qobject_cast(w))) { - setEnabledAllActions(true); - qDebug() << ">>>>> フォルダビューの共通メニュー設定 <<<<<"; - ui->action_SearchNext->setEnabled(false); - ui->action_SearchPrev->setEnabled(false); - - // 「開く」アクションを変更する - QFileInfo info(activeModel()->fileInfo(view->currentIndex())); - if (info.isDir()) { - ui->action_Open->setIcon(QIcon("://images/Open.png")); - ui->action_Open->setText(tr("開く")); - ui->action_Open->setToolTip(tr("開く")); - } - else { - ui->action_Open->setIcon(QIcon("://images/Search text.png")); - ui->action_Open->setText(tr("内蔵ビューアで開く")); - ui->action_Open->setToolTip(tr("内蔵ビューアで開く")); - - QSettings settings; - if (!settings.value(IniKey_ViewerForceOpen).toBool()) { - QStringList list = settings.value(IniKey_ViewerIgnoreExt).toString().split(","); - foreach (const QString &ext, list) { - if (ext.toLower() == info.suffix().toLower()) { - ui->action_Open->setEnabled(false); - break; - } - } - } - } - - if (info.fileName() == ".." && activeModel()->markedItems().isEmpty()) { - // ファイル操作を抑止 - ui->action_Copy->setEnabled(false); - ui->action_Delete->setEnabled(false); - ui->action_Move->setEnabled(false); - ui->action_Rename->setEnabled(false); - } - - if (m_viewMode & ModeBasic) { - qDebug() << ">>>>> 通常モードのメニュー設定 <<<<<"; - ui->action_SearchNext->setEnabled(false); - ui->action_SearchPrev->setEnabled(false); - - ui->action_historyBack->setEnabled(!activeModel()->isHistoryBegin()); - ui->action_HistoryForward->setEnabled(!activeModel()->isHistoryEnd()); - - QSettings settings; - ui->action_OpenEditor->setEnabled(!settings.value(IniKey_PathEditor).toString().isEmpty()); - ui->action_OpenTerminal->setEnabled(!settings.value(IniKey_PathTerminal).toString().isEmpty()); - - } - else if (!otherSideFolderView(view)->isVisible()) { - qDebug() << ">>>>> ハーフモードのメニュー設定 <<<<<"; - ui->action_SyncPanel->setEnabled(false); - ui->action_SyncPanelTo->setEnabled(false); - ui->action_Copy->setEnabled(false); - ui->action_Move->setEnabled(false); - } - } - else if (qobject_cast(w)) { - qDebug() << ">>>>> 検索モードのメニュー設定 <<<<<"; - setEnabledAllActions(false); - ui->toggle_Search->setEnabled(true); - ui->action_SearchNext->setEnabled(true); - ui->action_SearchPrev->setEnabled(true); - ui->action_About->setEnabled(true); - } - else if (qobject_cast(w) || - qobject_cast(w)) - { - qDebug() << ">>>>> ビューアモードのメニュー設定 <<<<<"; - setEnabledAllActions(false); - ui->action_Quit->setEnabled(true); - ui->action_Setting->setEnabled(true); - ui->action_CheckUpdate->setEnabled(true); - ui->view_FontSizeDown->setEnabled(true); - ui->view_FontSizeUp->setEnabled(true); - ui->action_KeyDown->setEnabled(true); - ui->action_KeyEnd->setEnabled(true); - ui->action_KeyHome->setEnabled(true); - ui->action_KeyUp->setEnabled(true); - ui->action_About->setEnabled(true); - ui->key_Left->setEnabled(true); - ui->key_Right->setEnabled(true); - if (m_viewMode == ModePreview) { - ui->view_HalfMode->setEnabled(true); - } - } -#endif } /////////////////////////////////////////////////////////////////////////////// @@ -2282,7 +2240,7 @@ void MainWindow::updateActions() void MainWindow::setEnabledAllActions(bool enable) { qDebug() << "MainWindow::setEnabledAllActions()" << enable; - foreach (QAction *action, findChildren()) { + foreach (QAction *action, m_actions) { action->setEnabled(enable); } } diff --git a/mainwindow.h b/mainwindow.h index bfef3e2..0c0612c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -98,6 +98,7 @@ public slots: void view_statusChanged(const QString &text); private: + typedef QList ActionList; enum Mode { ModeBasic, // 二画面モード ModeFull, // 単画面モード @@ -108,6 +109,7 @@ private: OverWriteDialog m_overwriteDialog; Mode m_viewMode; Mode m_prevMode; + ActionList m_actions; FolderModel* activeModel() const; Panel* activePanel() const; diff --git a/panel.cpp b/panel.cpp index c39332f..f1793fb 100644 --- a/panel.cpp +++ b/panel.cpp @@ -132,11 +132,10 @@ void Panel::setViewItem(const QModelIndex &index) /// /// 外観を変更します。 /// -void Panel::updateAppearance() +void Panel::updateAppearance(const Preferences &prefs) { qDebug() << "Panel::updateAppearance()"; - Preferences prefs(this); QPalette pal; pal = ui->imageView->palette(); @@ -149,7 +148,7 @@ void Panel::updateAppearance() ui->textView->setPalette(pal); ui->textView->setFont(prefs.getTextViewFont()); - ui->folderPanel->updateAppearance(); + ui->folderPanel->updateAppearance(prefs); } /////////////////////////////////////////////////////////////////////////////// diff --git a/panel.h b/panel.h index d10cb2c..2c6bb54 100644 --- a/panel.h +++ b/panel.h @@ -6,6 +6,7 @@ class MainWindow; class FolderPanel; class FolderModel; +class Preferences; namespace Ui { class Panel; @@ -24,7 +25,7 @@ public: FolderModel* model() const; void setModel(FolderModel *m); void setViewItem(const QModelIndex &index = QModelIndex()); - void updateAppearance(); + void updateAppearance(const Preferences &prefs); QWidget* visibleView() const; private: diff --git a/preferences.cpp b/preferences.cpp index 32fb146..5317abc 100644 --- a/preferences.cpp +++ b/preferences.cpp @@ -150,7 +150,7 @@ QString Preferences::getBookmarkPath(int n) const return value(Key_BookmarkPath(n)).toString(); } -QColor Preferences::folderViewFgColor(bool active) +QColor Preferences::folderViewFgColor(bool active) const { int darkFactor = 100; if (!active) { @@ -159,7 +159,7 @@ QColor Preferences::folderViewFgColor(bool active) return getFolderViewFgColor().darker(darkFactor); } -QColor Preferences::folderViewBgColor(bool active) +QColor Preferences::folderViewBgColor(bool active) const { int darkFactor = 100; if (!active) { @@ -168,7 +168,7 @@ QColor Preferences::folderViewBgColor(bool active) return getFolderViewBgColor().darker(darkFactor); } -QColor Preferences::folderViewMarkedFgColor(bool active) +QColor Preferences::folderViewMarkedFgColor(bool active) const { int darkFactor = 100; if (!active) { @@ -177,7 +177,7 @@ QColor Preferences::folderViewMarkedFgColor(bool active) return getFolderViewMarkedFgColor().darker(darkFactor); } -QColor Preferences::folderViewMarkedBgColor(bool active) +QColor Preferences::folderViewMarkedBgColor(bool active) const { int darkFactor = 100; if (!active) { @@ -186,7 +186,7 @@ QColor Preferences::folderViewMarkedBgColor(bool active) return getFolderViewMarkedBgColor().darker(darkFactor); } -QColor Preferences::folderViewSystemColor(bool active) +QColor Preferences::folderViewSystemColor(bool active) const { int darkFactor = 100; if (!active) { @@ -195,7 +195,7 @@ QColor Preferences::folderViewSystemColor(bool active) return getFolderViewSystemColor().darker(darkFactor); } -QColor Preferences::folderViewHiddenColor(bool active) +QColor Preferences::folderViewHiddenColor(bool active) const { int darkFactor = 100; if (!active) { @@ -204,7 +204,7 @@ QColor Preferences::folderViewHiddenColor(bool active) return getFolderViewHiddenColor().darker(darkFactor); } -QColor Preferences::folderViewReadOnlyColor(bool active) +QColor Preferences::folderViewReadOnlyColor(bool active) const { int darkFactor = 100; if (!active) { @@ -213,7 +213,7 @@ QColor Preferences::folderViewReadOnlyColor(bool active) return getFolderViewReadOnlyColor().darker(darkFactor); } -QColor Preferences::locationBoxFgColor(bool active) +QColor Preferences::locationBoxFgColor(bool active) const { int darkFactor = 100; if (!active) { @@ -222,7 +222,7 @@ QColor Preferences::locationBoxFgColor(bool active) return getLocationBoxFgColor().darker(darkFactor); } -QColor Preferences::locationBoxBgColor(bool active) +QColor Preferences::locationBoxBgColor(bool active) const { int darkFactor = 100; if (!active) { diff --git a/preferences.h b/preferences.h index 04d3dd0..677240f 100644 --- a/preferences.h +++ b/preferences.h @@ -38,15 +38,15 @@ public: QString getBookmarkEntry(int n) const; QString getBookmarkPath(int n) const; - QColor folderViewFgColor(bool active); - QColor folderViewBgColor(bool active); - QColor folderViewMarkedFgColor(bool active); - QColor folderViewMarkedBgColor(bool active); - QColor folderViewSystemColor(bool active); - QColor folderViewHiddenColor(bool active); - QColor folderViewReadOnlyColor(bool active); - QColor locationBoxFgColor(bool active); - QColor locationBoxBgColor(bool active); + QColor folderViewFgColor(bool active) const; + QColor folderViewBgColor(bool active) const; + QColor folderViewMarkedFgColor(bool active) const; + QColor folderViewMarkedBgColor(bool active) const; + QColor folderViewSystemColor(bool active) const; + QColor folderViewHiddenColor(bool active) const; + QColor folderViewReadOnlyColor(bool active) const; + QColor locationBoxFgColor(bool active) const; + QColor locationBoxBgColor(bool active) const; DECLARE_BOOL(CheckUpdate); DECLARE_BOOL(ConfirmQuit); @@ -92,8 +92,6 @@ public: DECLARE_OBJECT(QFont, SearchBoxFont); DECLARE_OBJECT(QFont, TextViewFont); - - signals: public slots: diff --git a/thumbnailview.cpp b/thumbnailview.cpp index 335bd4a..f4b6c67 100644 --- a/thumbnailview.cpp +++ b/thumbnailview.cpp @@ -36,8 +36,8 @@ void ThumbnailView::initialize(MainWindow *w) qDebug() << "ThumbnailView::initialize()"; connect(this, SIGNAL(doubleClicked(QModelIndex)), w, SLOT(onOpen(QModelIndex))); - connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), - w, SLOT(view_currentChanged(QModelIndex,QModelIndex))); +// connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), +// w, SLOT(view_currentChanged(QModelIndex,QModelIndex))); installEventFilter(w); viewport()->installEventFilter(w);