X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=folderpanel.cpp;h=0b168c837bf6881af61328fd978912ac46babfe0;hb=606ff8dc1c1abcd474d99f32eab21c6869554ed7;hp=1420f80e3b061d8978480da004df88e6c16ce130;hpb=cb33f51cb5589822ed22c0e39fb10e17ef3b8d6c;p=gefu%2FGefu.git diff --git a/folderpanel.cpp b/folderpanel.cpp index 1420f80..0b168c8 100644 --- a/folderpanel.cpp +++ b/folderpanel.cpp @@ -1,42 +1,324 @@ +#include "global.h" +#include "preferences.h" +#include "mainwindow.h" #include "folderpanel.h" #include "ui_folderpanel.h" +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::FolderPanel +/// \param parent 親ウィジェット +/// +/// コンストラクタ +/// FolderPanel::FolderPanel(QWidget *parent) : QWidget(parent), - ui(new Ui::FolderPanel) + ui(new Ui::FolderPanel), + m_mainWnd(NULL) { ui->setupUi(this); - // 初期状態では検索ボックスは非表示 + ui->searchBox->setText(""); ui->searchBox->setVisible(false); + ui->thumbnailView->setVisible(false); } +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::~FolderPanel +/// +/// デストラクタ +/// FolderPanel::~FolderPanel() { delete ui; } -LocationBox *FolderPanel::locationBox() const +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::initialize +/// \param w メインウィンドウオブジェクト +/// +/// 初期化処理を行います。 +/// +void FolderPanel::initialize(MainWindow *w) { - return ui->locationBox; + qDebug() << "FolderPanel::initialize();"; + + // フォルダビューを初期化する + ui->folderView->initialize(w); + // サムネイルビューを初期化する + ui->thumbnailView->initialize(w); + + connect(ui->bookmarkBtn, SIGNAL(clicked()), w, SLOT(onAddBookmark())); } -FolderView *FolderPanel::folderView() const +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::itemView +/// \return アイテムビューを返します。 +/// +QAbstractItemView *FolderPanel::itemView() const { + if (ui->thumbnailView->isVisible()) { + return ui->thumbnailView; + } return ui->folderView; } -SearchBox *FolderPanel::serachBox() const +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::model +/// \return 関連付けられたフォルダモデルを返します。 +/// +FolderModel *FolderPanel::model() const +{ + return static_cast(ui->folderView->model()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::setModel +/// \param m 設定するモデル +/// +/// モデルを設定します。 +/// +void FolderPanel::setModel(FolderModel *m) +{ + qDebug() << "FolderPanel::setModel()" << m; + if (model()) { + model()->disconnect(this); + } + + ui->folderView->setModel(m); + ui->thumbnailView->setModel(m); + + if (model()) { + connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), + this, SLOT(model_dataChanged(QModelIndex,QModelIndex))); + connect(model(), SIGNAL(modelReset()), this, SLOT(model_Reset())); + + model_Reset(); + model_dataChanged(QModelIndex(), QModelIndex()); + } +} + +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::toggleSearch +/// \param checked メニューのチェック状態 +/// +/// 検索ボックスの表示/非表示を切り替えます。 +/// +void FolderPanel::toggleSearch(bool checked) { - return ui->searchBox; + qDebug() << "FolderPanel::toggleSearch()" << checked; + if (!isVisible()) { + return; + } + + if (checked) { + if (!model()->isActive()) { + return; + } + + ui->searchBox->setVisible(true); + ui->searchBox->setFocus(); + ui->searchBox->selectAll(); + } + else { + if (!ui->searchBox->isVisible()) { + return; + } + + if (ui->searchBox->hasFocus()) { + itemView()->setFocus(); + } + ui->searchBox->setVisible(false); + } } -QLabel *FolderPanel::filterLabel() const +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::toggleView +/// \param checked メニューのチェック状態 +/// +/// リスト/サムネイルを切り替えます。 +/// +void FolderPanel::toggleView(bool checked) { - return ui->filterLabel; + QModelIndex index = itemView()->currentIndex(); + if (checked) { + ui->folderView->setVisible(false); + ui->thumbnailView->setVisible(true); + ui->thumbnailView->setFocus(); + } + else { + ui->thumbnailView->setVisible(false); + ui->folderView->setVisible(true); + ui->folderView->setFocus(); + } + itemView()->setCurrentIndex(index); } +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::updateAppearance +/// +/// 外観を変更します。 +/// +void FolderPanel::updateAppearance(const Preferences &prefs) +{ + qDebug() << "FolderPanel::updateAppearance()"; + + QPalette pal; + + pal = ui->filterLabel->palette(); + pal.setColor(ui->filterLabel->backgroundRole(), prefs.folderViewBgColor(model()->isActive())); + pal.setColor(ui->filterLabel->foregroundRole(), prefs.folderViewFgColor(model()->isActive())); + ui->filterLabel->setAutoFillBackground(true); + ui->filterLabel->setPalette(pal); + + pal = ui->locationBox->palette(); + pal.setColor(QPalette::Base, prefs.locationBoxBgColor(model()->isActive())); + pal.setColor(QPalette::Text, prefs.locationBoxFgColor(model()->isActive())); + ui->locationBox->setPalette(pal); + ui->locationBox->setFont(prefs.getLocationBoxFont()); + + pal = ui->searchBox->palette(); + pal.setColor(QPalette::Base, prefs.getSearchBoxBgColor()); + pal.setColor(QPalette::Text, prefs.getSearchBoxFgColor()); + ui->searchBox->setPalette(pal); + ui->searchBox->setFont(prefs.getSearchBoxFont()); + + pal = ui->folderView->palette(); + pal.setColor(QPalette::Base, prefs.folderViewBgColor(model()->isActive())); + ui->folderView->setPalette(pal); + + pal = ui->thumbnailView->palette(); + pal.setColor(QPalette::Base, prefs.folderViewBgColor(model()->isActive())); + ui->thumbnailView->setPalette(pal); + + QHeaderView *header = ui->folderView->verticalHeader(); + QFont font = prefs.getFolderViewFont(); + header->setDefaultSectionSize(QFontMetrics(font).height() * prefs.getLineHeight()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::searchNext +/// \param step 次なら1, 前なら-1 +/// +/// 次または前のアイテムを検索します。 +/// +void FolderPanel::searchNext(int step) +{ + qDebug() << "FolderPanel::searchNext()" << step; + + QModelIndex index = model()->search(ui->searchBox->text(), + itemView()->currentIndex(), + step); + showSearchResult(index); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::setItemView +/// \param name "folderView"または"thumbnailView" +/// +/// 指定されたビューを可視状態にします。 +/// +void FolderPanel::setItemView(const QString &name) +{ + ui->folderView->setVisible(false); + ui->thumbnailView->setVisible(false); + findChild(name)->setVisible(true); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::showSearchResult +/// \param index 検索されたアイテム +/// +/// 検索結果を表示します。 +/// +void FolderPanel::showSearchResult(const QModelIndex &index) +{ + Preferences prefs(this); + + QPalette pal = ui->searchBox->palette(); + if (index.isValid()) { + itemView()->setCurrentIndex(index); + pal.setColor(QPalette::Base, prefs.getSearchBoxBgColor()); + pal.setColor(QPalette::Text, prefs.getSearchBoxFgColor()); + } + else { + pal.setColor(QPalette::Base, prefs.getSearchBoxUnmatchBgColor()); + pal.setColor(QPalette::Text, prefs.getSearchBoxUnmatchFgColor()); + } + ui->searchBox->setPalette(pal); +} + +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::model_dataChanged +/// \param topLeft (使用しません) +/// \param bottomRight (使用しません) +/// +/// アイテムの選択状態変更に伴う処理を行います。 +/// +void FolderPanel::model_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) +{ + Q_UNUSED(topLeft); + Q_UNUSED(bottomRight); + + QFileInfoList list = model()->markedItems(); + if (list.isEmpty()) { + ui->filterLabel->setText(tr("フィルタ:%1").arg(model()->nameFilters().join(" "))); + } + else { + int numFolders = 0; + int numFiles = 0; + qint64 totalSize = 0; + foreach (const QFileInfo &fi, list) { + if (fi.isDir()) { + ++numFolders; + } + else { + ++numFiles; + totalSize += fi.size(); + } + } + + QString text; + if (numFolders > 0) { + text += tr("%1個のフォルダ ").arg(numFolders); + } + if (numFiles > 0) { + text += tr("%1個のファイル ").arg(numFiles); + } + if (!text.isEmpty()) { + text += tr("を選択 合計%1").arg(fileSizeToString(totalSize)); + } + ui->filterLabel->setText(text); + } +} + +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::model_Reset +/// +/// モデルリセット後の処理を行います。 +/// +void FolderPanel::model_Reset() +{ + ui->locationBox->setText(model()->rootPath()); + ui->filterLabel->setText(tr("フィルタ:%1").arg(model()->nameFilters().join(" "))); +} -void FolderPanel::focusInEvent(QFocusEvent *) +/////////////////////////////////////////////////////////////////////////////// +/// \brief FolderPanel::on_searchBox_textEdited +/// \param arg1 入力テキスト +/// +/// 検索ボックスのテキストが変更された場合の処理を行います。 +/// +void FolderPanel::on_searchBox_textEdited(const QString &arg1) { - ui->folderView->setFocus(); + if (arg1.right(1) == "/") { + ui->searchBox->setText(arg1.left(arg1.size() - 1)); + // 検索終了 + itemView()->setFocus(); + } + else { + showSearchResult(model()->search(arg1)); + } }