2 #include "preferences.h"
3 #include "mainwindow.h"
4 #include "folderpanel.h"
5 #include "ui_folderpanel.h"
11 ///////////////////////////////////////////////////////////////////////////////
12 /// \brief FolderPanel::FolderPanel
13 /// \param parent 親ウィジェット
17 FolderPanel::FolderPanel(QWidget *parent) :
19 ui(new Ui::FolderPanel),
23 ui->searchBox->setText("");
24 ui->searchBox->setVisible(false);
25 ui->thumbnailView->setVisible(false);
28 ///////////////////////////////////////////////////////////////////////////////
29 /// \brief FolderPanel::~FolderPanel
33 FolderPanel::~FolderPanel()
38 ///////////////////////////////////////////////////////////////////////////////
39 /// \brief FolderPanel::initialize
40 /// \param w メインウィンドウオブジェクト
44 void FolderPanel::initialize(MainWindow *w)
46 qDebug() << "FolderPanel::initialize();";
49 ui->folderView->initialize(w);
51 ui->thumbnailView->initialize(w);
53 connect(ui->bookmarkBtn, SIGNAL(clicked()), w, SLOT(onAddBookmark()));
56 ///////////////////////////////////////////////////////////////////////////////
57 /// \brief FolderPanel::itemView
58 /// \return アイテムビューを返します。
60 QAbstractItemView *FolderPanel::itemView() const
62 if (ui->thumbnailView->isVisible()) {
63 return ui->thumbnailView;
65 return ui->folderView;
68 ///////////////////////////////////////////////////////////////////////////////
69 /// \brief FolderPanel::model
70 /// \return 関連付けられたフォルダモデルを返します。
72 FolderModel *FolderPanel::model() const
74 return static_cast<FolderModel*>(ui->folderView->model());
77 ///////////////////////////////////////////////////////////////////////////////
78 /// \brief FolderPanel::setModel
83 void FolderPanel::setModel(FolderModel *m)
85 qDebug() << "FolderPanel::setModel()" << m;
87 model()->disconnect(this);
90 ui->folderView->setModel(m);
91 ui->thumbnailView->setModel(m);
94 connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
95 this, SLOT(model_dataChanged(QModelIndex,QModelIndex)));
96 connect(model(), SIGNAL(modelReset()), this, SLOT(model_Reset()));
99 model_dataChanged(QModelIndex(), QModelIndex());
103 ///////////////////////////////////////////////////////////////////////////////
104 /// \brief FolderPanel::toggleSearch
105 /// \param checked メニューのチェック状態
107 /// 検索ボックスの表示/非表示を切り替えます。
109 void FolderPanel::toggleSearch(bool checked)
111 qDebug() << "FolderPanel::toggleSearch()" << checked;
117 if (!model()->isActive()) {
121 ui->searchBox->setVisible(true);
122 ui->searchBox->setFocus();
123 ui->searchBox->selectAll();
126 if (!ui->searchBox->isVisible()) {
130 if (ui->searchBox->hasFocus()) {
131 itemView()->setFocus();
133 ui->searchBox->setVisible(false);
137 ///////////////////////////////////////////////////////////////////////////////
138 /// \brief FolderPanel::toggleView
139 /// \param checked メニューのチェック状態
141 /// リスト/サムネイルを切り替えます。
143 void FolderPanel::toggleView(bool checked)
145 QModelIndex index = itemView()->currentIndex();
147 ui->folderView->setVisible(false);
148 ui->thumbnailView->setVisible(true);
149 ui->thumbnailView->setFocus();
152 ui->thumbnailView->setVisible(false);
153 ui->folderView->setVisible(true);
154 ui->folderView->setFocus();
156 itemView()->setCurrentIndex(index);
159 ///////////////////////////////////////////////////////////////////////////////
160 /// \brief FolderPanel::updateAppearance
164 void FolderPanel::updateAppearance(const Preferences &prefs)
166 qDebug() << "FolderPanel::updateAppearance()";
170 pal = ui->filterLabel->palette();
171 pal.setColor(ui->filterLabel->backgroundRole(), prefs.folderViewBgColor(model()->isActive()));
172 pal.setColor(ui->filterLabel->foregroundRole(), prefs.folderViewFgColor(model()->isActive()));
173 ui->filterLabel->setAutoFillBackground(true);
174 ui->filterLabel->setPalette(pal);
176 pal = ui->locationBox->palette();
177 pal.setColor(QPalette::Base, prefs.locationBoxBgColor(model()->isActive()));
178 pal.setColor(QPalette::Text, prefs.locationBoxFgColor(model()->isActive()));
179 ui->locationBox->setPalette(pal);
180 ui->locationBox->setFont(prefs.getLocationBoxFont());
182 pal = ui->searchBox->palette();
183 pal.setColor(QPalette::Base, prefs.getSearchBoxBgColor());
184 pal.setColor(QPalette::Text, prefs.getSearchBoxFgColor());
185 ui->searchBox->setPalette(pal);
186 ui->searchBox->setFont(prefs.getSearchBoxFont());
188 pal = ui->folderView->palette();
189 pal.setColor(QPalette::Base, prefs.folderViewBgColor(model()->isActive()));
190 ui->folderView->setPalette(pal);
192 pal = ui->thumbnailView->palette();
193 pal.setColor(QPalette::Base, prefs.folderViewBgColor(model()->isActive()));
194 ui->thumbnailView->setPalette(pal);
196 QHeaderView *header = ui->folderView->verticalHeader();
197 QFont font = prefs.getFolderViewFont();
198 header->setDefaultSectionSize(QFontMetrics(font).height() * prefs.getLineHeight());
201 ///////////////////////////////////////////////////////////////////////////////
202 /// \brief FolderPanel::searchNext
203 /// \param step 次なら1, 前なら-1
205 /// 次または前のアイテムを検索します。
207 void FolderPanel::searchNext(int step)
209 qDebug() << "FolderPanel::searchNext()" << step;
211 QModelIndex index = model()->search(ui->searchBox->text(),
212 itemView()->currentIndex(),
214 showSearchResult(index);
217 ///////////////////////////////////////////////////////////////////////////////
218 /// \brief FolderPanel::setItemView
219 /// \param name "folderView"または"thumbnailView"
221 /// 指定されたビューを可視状態にします。
223 void FolderPanel::setItemView(const QString &name)
225 ui->folderView->setVisible(false);
226 ui->thumbnailView->setVisible(false);
227 findChild<QWidget*>(name)->setVisible(true);
230 ///////////////////////////////////////////////////////////////////////////////
231 /// \brief FolderPanel::showSearchResult
232 /// \param index 検索されたアイテム
236 void FolderPanel::showSearchResult(const QModelIndex &index)
238 Preferences prefs(this);
240 QPalette pal = ui->searchBox->palette();
241 if (index.isValid()) {
242 itemView()->setCurrentIndex(index);
243 pal.setColor(QPalette::Base, prefs.getSearchBoxBgColor());
244 pal.setColor(QPalette::Text, prefs.getSearchBoxFgColor());
247 pal.setColor(QPalette::Base, prefs.getSearchBoxUnmatchBgColor());
248 pal.setColor(QPalette::Text, prefs.getSearchBoxUnmatchFgColor());
250 ui->searchBox->setPalette(pal);
253 ///////////////////////////////////////////////////////////////////////////////
254 /// \brief FolderPanel::model_dataChanged
255 /// \param topLeft (使用しません)
256 /// \param bottomRight (使用しません)
258 /// アイテムの選択状態変更に伴う処理を行います。
260 void FolderPanel::model_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
263 Q_UNUSED(bottomRight);
265 QFileInfoList list = model()->markedItems();
266 if (list.isEmpty()) {
267 ui->filterLabel->setText(tr("フィルタ:%1").arg(model()->nameFilters().join(" ")));
272 qint64 totalSize = 0;
273 foreach (const QFileInfo &fi, list) {
279 totalSize += fi.size();
284 if (numFolders > 0) {
285 text += tr("%1個のフォルダ ").arg(numFolders);
288 text += tr("%1個のファイル ").arg(numFiles);
290 if (!text.isEmpty()) {
291 text += tr("を選択 合計%1").arg(fileSizeToString(totalSize));
293 ui->filterLabel->setText(text);
297 ///////////////////////////////////////////////////////////////////////////////
298 /// \brief FolderPanel::model_Reset
300 /// モデルリセット後の処理を行います。
302 void FolderPanel::model_Reset()
304 ui->locationBox->setText(model()->rootPath());
305 ui->filterLabel->setText(tr("フィルタ:%1").arg(model()->nameFilters().join(" ")));
308 ///////////////////////////////////////////////////////////////////////////////
309 /// \brief FolderPanel::on_searchBox_textEdited
310 /// \param arg1 入力テキスト
312 /// 検索ボックスのテキストが変更された場合の処理を行います。
314 void FolderPanel::on_searchBox_textEdited(const QString &arg1)
316 if (arg1.right(1) == "/") {
317 ui->searchBox->setText(arg1.left(arg1.size() - 1));
319 itemView()->setFocus();
322 showSearchResult(model()->search(arg1));