-#include "common.h"\r
-#include "filetablemodel.h"\r
-#include "folderpanel.h"\r
-#include "mainwindow.h"\r
-#include "ui_folderpanel.h"\r
-#include <QCheckBox>\r
-#include <QMessageBox>\r
-#include <QKeyEvent>\r
-#include <QDebug>\r
-#include <QDateTime>\r
-#include <QDesktopServices>\r
-#include <QSettings>\r
-#ifdef Q_OS_WIN32\r
- #include <windows.h>\r
-#endif\r
-\r
-QString FilesizeToString(quint64 size)\r
-{\r
- if (size >= 1024 * 1024 * 1024) {\r
- return QString("%1GB").arg(int(10 * size / (1024 * 1024 * 1024)) / 10.0);\r
- }\r
- if (size >= 1024 * 1024) {\r
- return QString("%1MB").arg(int(10 * size / (1024 * 1024)) / 10.0);\r
- }\r
- if (size >= 1024) {\r
- return QString("%1KB").arg(int(10 * size / 1024) / 10.0);\r
- }\r
- return QString("%1B").arg(size);\r
-}\r
-\r
-FolderPanel::FolderPanel(QWidget *parent) :\r
- QWidget(parent),\r
- ui(new Ui::FolderPanel)\r
-{\r
- ui->setupUi(this);\r
- ui->fileTable->setModel(new FileTableModel(this));\r
-\r
- // リサイズ時の動作を設定する\r
- QHeaderView *header = ui->fileTable->horizontalHeader();\r
- header->setSectionResizeMode(0, QHeaderView::ResizeToContents);\r
- header->setSectionResizeMode(1, QHeaderView::Stretch);\r
- header->setSectionResizeMode(2, QHeaderView::ResizeToContents);\r
- header->setSectionResizeMode(3, QHeaderView::ResizeToContents);\r
- header->setDefaultSectionSize(header->minimumSectionSize());\r
-\r
- QHeaderView *vHeader = ui->fileTable->verticalHeader();\r
- vHeader->setDefaultSectionSize(vHeader->defaultSectionSize() * 0.75);\r
-}\r
-\r
-FolderPanel::~FolderPanel()\r
-{\r
- delete ui;\r
-}\r
-\r
-QTableView* FolderPanel::fileTable()\r
-{\r
- return ui->fileTable;\r
-}\r
-\r
-const QTableView *FolderPanel::fileTable() const\r
-{\r
- return ui->fileTable;\r
-}\r
-\r
-const QString FolderPanel::side() const\r
-{\r
- return ui->fileTable->side();\r
-}\r
-\r
-void FolderPanel::setSide(const QString &side)\r
-{\r
- ui->fileTable->setSide(side);\r
-\r
- QSettings settings;\r
- FileTableModel *model = new FileTableModel();\r
- connect(model, SIGNAL(rootChanged(QString)),\r
- ui->locationField, SLOT(setText(QString)));\r
- connect(model, SIGNAL(stateChanged(int,int,quint64)),\r
- this, SLOT(onStateChanged(int,int,quint64)));\r
-\r
- //>>>>> フィルタ初期化\r
- model->setFilter(QDir::NoDot | QDir::AllDirs | QDir::Files);\r
- if (settings.value(IniKey_ShowHidden, false).toBool()) {\r
- model->setFilter(model->filter() | QDir::Hidden);\r
- }\r
- if (settings.value(IniKey_ShowSystem, false).toBool()) {\r
- model->setFilter(model->filter() | QDir::System);\r
- }\r
- //>>>>> ソート順初期化\r
- model->setSorting(QDir::Name); // 0\r
- int sortBy = settings.value(side + slash + IniKey_SortBy, SortByName).toInt();\r
- switch (sortBy) {\r
- case SortByDate: model->setSorting(model->sorting() | QDir::Time); break;\r
- case SortBySize: model->setSorting(model->sorting() | QDir::Size); break;\r
- case SortByType: model->setSorting(model->sorting() | QDir::Type); break;\r
- default: model->setSorting(model->sorting() | QDir::Name); break;\r
- }\r
- // デフォルトだと文字列は昇順で、数値は降順…orz\r
- int orderBy = settings.value(side + slash + IniKey_OrderBy, OrderByDesc).toInt();\r
- if (((sortBy == SortByName || sortBy == SortByType) && orderBy == OrderByDesc) ||\r
- ((sortBy == SortByDate || sortBy == SortBySize) && orderBy == OrderByAsc))\r
- {\r
- model->setSorting(model->sorting() | QDir::Reversed);\r
- }\r
- // フォルダの位置\r
- switch (settings.value(side + slash + IniKey_PutDirs, PutDirsFirst).toInt()) {\r
- case PutDirsFirst: model->setSorting(model->sorting() | QDir::DirsFirst); break;\r
- case PutDirsLast: model->setSorting(model->sorting() | QDir::DirsLast); break;\r
- }\r
- // 大文字小文字の区別\r
- if (settings.value(side + slash + IniKey_IgnoreCase, true).toBool()) {\r
- model->setSorting(model->sorting() | QDir::IgnoreCase);\r
- }\r
- //>>>>> 監視フォルダ初期化\r
- QString key = side + slash + IniKey_Dir;\r
- QString path = settings.value(key, QDir::homePath()).toString();\r
-\r
- model->updateAppearance();\r
- ui->fileTable->setModel(model);\r
- ui->fileTable->setRootPath(path, true);\r
- ui->fileTable->selectRow(0);\r
-}\r
-\r
-void FolderPanel::updateAppearance()\r
-{\r
- QSettings settings;\r
- QPalette palette;\r
- QFont font;\r
-\r
- font = ui->locationField->font();\r
- font = settings.value(IniKey_BoxFont, font).value<QFont>();\r
- palette = ui->locationField->palette();\r
- palette.setColor(\r
- QPalette::Base,\r
- settings.value(IniKey_BoxColorBg, palette.base()).value<QColor>());\r
- palette.setColor(\r
- QPalette::Text,\r
- settings.value(IniKey_BoxColorFg, palette.text()).value<QColor>());\r
- ui->locationField->setFont(font);\r
- ui->locationField->setPalette(palette);\r
-\r
- palette = ui->fileTable->palette();\r
- palette.setColor(\r
- QPalette::Base,\r
- settings.value(IniKey_ViewColorBgNormal, palette.base()).value<QColor>());\r
- ui->fileTable->setPalette(palette);\r
-\r
- FileTableModel *model = static_cast<FileTableModel*>(ui->fileTable->model());\r
- if (model) {\r
- model->updateAppearance();\r
- }\r
-}\r
-\r
-void FolderPanel::onStateChanged(int checkedFolders, int checkedFiles, quint64 totalSize)\r
-{\r
- QString msg = "";\r
- if (checkedFolders > 0) {\r
- msg += tr("%1個のフォルダ ").arg(checkedFolders);\r
- }\r
- if (checkedFiles > 0) {\r
- msg += tr("%1個のファイル ").arg(checkedFiles);\r
- }\r
- if (msg.length() > 0) {\r
- msg += "を選択 合計 ";\r
- msg += FilesizeToString(totalSize);\r
- }\r
-\r
- ui->label->setText(msg);\r
-\r
-}\r
-\r
-void FolderPanel::on_locationField_editingFinished()\r
-{\r
- ui->locationField->blockSignals(true);\r
-\r
- QString path = ui->locationField->text();\r
- ui->fileTable->setRootPath(path, true);\r
-\r
- ui->locationField->blockSignals(false);\r
-}\r
+#include "common.h"
+#include "mainwindow.h"
+#include "searchbox.h"
+#include "locationbox.h"
+#include "folderpanel.h"
+#include "ui_folderpanel.h"
+
+#include <QDebug>
+
+FolderPanel::FolderPanel(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::FolderPanel)
+{
+ ui->setupUi(this);
+}
+
+FolderPanel::~FolderPanel()
+{
+ delete ui;
+}
+
+void FolderPanel::initialize(MainWindow *mainWnd)
+{
+ qDebug() << "FolderPanel::initialize();";
+
+ // シグナル&スロット
+ connect(ui->folderView, SIGNAL(dataChanged()), this, SLOT(dataChange()));
+ connect(ui->folderView, SIGNAL(doubleClicked(QModelIndex)), mainWnd, SLOT(open(QModelIndex)));
+ connect(ui->folderView, SIGNAL(dropAccepted(QFileInfoList)), mainWnd, SLOT(dropAccept(QFileInfoList)));
+ connect(ui->folderView, SIGNAL(currentChanged(QFileInfo)), mainWnd, SLOT(currentChange(QFileInfo)));
+ connect(ui->folderView, SIGNAL(itemFound()), mainWnd, SLOT(itemFound()));
+ connect(ui->folderView, SIGNAL(itemNotFound()), mainWnd, SLOT(itemNotFound()));
+ connect(ui->folderView, SIGNAL(retrieveFinished()), mainWnd, SLOT(retrieveFinish()));
+ connect(ui->folderView, SIGNAL(requestContextMenu(QContextMenuEvent*)), mainWnd, SLOT(showContextMenu(QContextMenuEvent*)));
+ connect(ui->folderView, SIGNAL(retrieveStarted(QString)), mainWnd, SLOT(retrieveStart(QString)));
+ connect(ui->folderView, SIGNAL(retrieveStarted(QString)), ui->locationBox, SLOT(setText(QString)));
+ connect(ui->searchBox, SIGNAL(textEdited(QString)), mainWnd, SLOT(searchItem(QString)));
+ connect(ui->searchBox, SIGNAL(returnPressed()), mainWnd, SLOT(returnPressInSearchBox()));
+
+ // 初期状態では検索ボックスは非表示
+ ui->searchBox->setVisible(false);
+
+ // ロケーションボックスを初期化する
+ ui->locationBox->initialize();
+
+ // フォルダビューを初期化する
+ ui->folderView->initialize();
+}
+
+LocationBox *FolderPanel::locationBox() const
+{
+ return ui->locationBox;
+}
+
+FolderView *FolderPanel::folderView() const
+{
+ return ui->folderView;
+}
+
+SearchBox *FolderPanel::searchBox() const
+{
+ return ui->searchBox;
+}
+
+QLabel *FolderPanel::filterLabel() const
+{
+ return ui->filterLabel;
+}
+
+void FolderPanel::setNameFilters(const QString &filters)
+{
+ QStringList list = filters.split(" ", QString::SkipEmptyParts);
+ if (list.isEmpty()) {
+ list << "*";
+ }
+ ui->folderView->setNameFilters(list);
+ showNameFilters();
+}
+
+void FolderPanel::showNameFilters()
+{
+ ui->filterLabel->setText(tr("フィルタ:") + ui->folderView->nameFilters().join(" "));
+}
+
+void FolderPanel::dataChange()
+{
+ qDebug() << "FolderPanel::dataChange();";
+
+ FolderView *view = static_cast<FolderView*>(sender());
+ Q_CHECK_PTR(view);
+
+ QFileInfoList list = view->checkedItems();
+ if (list.isEmpty()) {
+ showNameFilters();
+ }
+ else {
+ int numFolders = 0;
+ int numFiles = 0;
+ quint64 size = 0;
+ foreach (const QFileInfo &info, list) {
+ if (info.isDir()) {
+ numFolders++;
+ }
+ else {
+ numFiles++;
+ size += info.size();
+ }
+ }
+
+ QString msg = QString::null;
+ if (numFolders > 0) {
+ msg += tr("%1個のフォルダ ").arg(numFolders);
+ }
+ if (numFiles > 0) {
+ msg += tr("%1個のファイル ").arg(numFiles);
+ }
+
+ if (!msg.isEmpty()) {
+ msg += tr("を選択 合計%1").arg(FilesizeToString(size));
+ }
+
+ ui->filterLabel->setText(msg);
+ }
+}
+
+void FolderPanel::focusInEvent(QFocusEvent *)
+{
+ qDebug() << "FolderPanel::focusInEvent();";
+
+ ui->folderView->setFocus();
+}