From 90d74cbf6b4f346591dc5514436f3ab03612ae4b Mon Sep 17 00:00:00 2001 From: Masayuki Satoh Date: Mon, 25 Aug 2014 22:08:55 +0900 Subject: [PATCH] Ver0.11pre --- Gefu.pro | 21 +- README.md | 9 +- ReadMe.txt | 10 +- common.h | 4 +- copymoveworker.cpp | 61 ++- copymoveworker.h | 2 +- filetablemodel.cpp | 65 +-- filetablemodel.h | 10 +- folderview.cpp | 318 ++++++++++- folderview.h | 52 ++ historydialog.cpp | 2 +- historydialog.h | 8 +- locationbox.cpp | 25 + locationbox.h | 3 + main.cpp | 5 +- mainwindow.cpp | 1466 ++++++++++++++++++++++++++++++++++++++++++++------ mainwindow.h | 90 +++- mainwindow.ui | 301 +++++++++-- overwritedialog.cpp | 80 ++- overwritedialog.h | 21 +- overwritedialog.ui | 27 +- preferencedialog.cpp | 2 +- preferencedialog.ui | 1218 ++++++++++++++++------------------------- searchbox.cpp | 57 ++ searchbox.h | 10 + simpletextview.cpp | 21 +- 26 files changed, 2727 insertions(+), 1161 deletions(-) diff --git a/Gefu.pro b/Gefu.pro index bbe11af..a3babff 100644 --- a/Gefu.pro +++ b/Gefu.pro @@ -16,7 +16,6 @@ TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ - folderpanel.cpp \ renamesingledialog.cpp \ renamemultidialog.cpp \ operationdialog.cpp \ @@ -28,17 +27,16 @@ SOURCES += main.cpp\ copymoveworker.cpp \ sortdialog.cpp \ filetablemodel.cpp \ - filetableview.cpp \ history.cpp \ historydialog.cpp \ preferencedialog.cpp \ - clickablelabel.cpp \ colorsamplemodel.cpp \ - simpletextview.cpp + simpletextview.cpp \ + searchbox.cpp \ + folderview.cpp \ + locationbox.cpp HEADERS += mainwindow.h \ - folderpanel.h \ - singleton.hpp \ renamesingledialog.h \ renamemultidialog.h \ operationdialog.h \ @@ -51,16 +49,16 @@ HEADERS += mainwindow.h \ copymoveworker.h \ sortdialog.h \ filetablemodel.h \ - filetableview.h \ history.h \ historydialog.h \ preferencedialog.h \ - clickablelabel.h \ colorsamplemodel.h \ - simpletextview.h + simpletextview.h \ + searchbox.h \ + folderview.h \ + locationbox.h FORMS += mainwindow.ui \ - folderpanel.ui \ renamesingledialog.ui \ renamemultidialog.ui \ operationdialog.ui \ @@ -74,7 +72,8 @@ RESOURCES += \ OTHER_FILES += \ Gefu.rc \ - README.md + README.md \ + ReadMe.txt macx { ICON = ./images/Gefu.icns diff --git a/README.md b/README.md index dab55e0..9f9abbe 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,18 @@ Gefu is an Experimental File Utility. - オプション - ファンクションキー - キーバインドカスタマイズ -- ファイル検索 - 簡易画像ビューア - 簡易アーカイバ - 簡易FTPクライアント - SNS連携(タイムライン表示とか) ← ファイラーの機能か? -#### 2014/08/24 Ver0.10 +#### 2014/08/25 Ver0.11 公開 +- ファイル検索機能を実装。 +- 内部構造を大幅に変更。 + 各ビューで処理していたアクションを、メインウィンドウで処理するように変更。 +- 起動時の位置とサイズが常にデフォルト値になっていたのを修正。 + +#### 2014/08/24 Ver0.10 公開 - 環境設定ダイアログの変更 - コントロールの活性・非活性切り替えを修正。 - フォント選択をダイアログ使用に変更。 diff --git a/ReadMe.txt b/ReadMe.txt index e8ce75e..ca902eb 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -1,8 +1,8 @@ =============================================================================== Gefu(げふぅ) - Gefu is an Experimental File Utility - - Version 0.10 + Version 0.11 =============================================================================== - 2014/08/24 @miyabi_satoh + 2014/08/25 @miyabi_satoh ◇ 概要 ◇ @@ -89,6 +89,12 @@ Twitter: https://twitter.com/miyabi_satoh ◇ 履歴 ◇ +#### 2014/08/25 Ver0.11 +- ファイル検索機能を実装。 +- 内部構造を大幅に変更。 + (各ビューで処理していたアクションを、メインウィンドウで処理するように変更。) +- 起動時の位置とサイズが常にデフォルト値になっていたのを修正。 + #### 2014/08/24 Ver0.10 - SourceForge.jp でプロジェクト公開。 - 環境設定ダイアログの変更 diff --git a/common.h b/common.h index 7543459..54d56b0 100644 --- a/common.h +++ b/common.h @@ -5,11 +5,13 @@ typedef QMap StringMap; class MainWindow; +class QKeyEvent; extern MainWindow* getMainWnd(); extern QString FilesizeToString(quint64 size); extern QString ViewerIgnoreExt(); +extern QString KeyEventToSequence(const QKeyEvent *event); -#define VERSION_VALUE 0.10 +#define VERSION_VALUE 0.11 #define slash QString("/") #define QQ(x) ("\"" + QString(x) + "\"") diff --git a/copymoveworker.cpp b/copymoveworker.cpp index 41e28ac..f23ee70 100644 --- a/copymoveworker.cpp +++ b/copymoveworker.cpp @@ -35,13 +35,12 @@ void CopyMoveWorker::operate() } bool ret; - int copyMethod = OverWriteDialog::Undefined; - int prevCopyMethod = OverWriteDialog::Undefined; int successCount = 0; int skipCount = 0; int errorCount = 0; int errDelCount = 0; QString msg; + QString copyMethod; QString alias; StringMap::iterator it; for (it = m_CopyMap.begin(); it != m_CopyMap.end(); it++) { @@ -73,34 +72,31 @@ void CopyMoveWorker::operate() do { // コピーをスキップするのにbreakを使うがためのdo-while if (tgtInfo.exists()) { // 解決方法を選択 - if (copyMethod == OverWriteDialog::Undefined || - copyMethod == OverWriteDialog::Rename) - { - bool bOk; - m_Asking = true; - emit askOverWrite(&bOk, &prevCopyMethod, ©Method, &alias, - srcInfo.absoluteFilePath(), - tgtInfo.absoluteFilePath()); - while (isAsking()) { - this->thread()->msleep(100); - } + m_Asking = true; + emit askOverWrite(©Method, + &alias, + srcInfo.absoluteFilePath(), + tgtInfo.absoluteFilePath()); + + while (isAsking()) { + thread()->msleep(100); + } - if (!bOk) { - requestStop(); - msg = tr("%1個のファイルをコピーしました。").arg(successCount); - if (skipCount > 0) { - msg += tr("%1個のファイルをスキップしました。").arg(skipCount); - } - if (errorCount > 0) { - msg += tr("%1個のファイルをコピーできませんでした。").arg(errorCount); - } - m_progressText->setText(msg); - emit canceled(); - return; + // キャンセルされた? + if (isStopRequested()) { + msg = tr("%1個のファイルをコピーしました。").arg(successCount); + if (skipCount > 0) { + msg += tr("%1個のファイルをスキップしました。").arg(skipCount); } + if (errorCount > 0) { + msg += tr("%1個のファイルをコピーできませんでした。").arg(errorCount); + } + m_progressText->setText(msg); + emit canceled(); + return; } - if (prevCopyMethod == OverWriteDialog::OverWrite) { + if (copyMethod == "rbOverWrite") { if (srcInfo.absoluteFilePath() == tgtInfo.absoluteFilePath()) { emit success(tr("同一ファイルへの操作のためスキップ")); skipCount++; @@ -108,7 +104,7 @@ void CopyMoveWorker::operate() } QFile(tgtInfo.absoluteFilePath()).remove(); } - else if (prevCopyMethod == OverWriteDialog::OverWriteIfNew) { + else if (copyMethod == "rbOverWriteIfNew") { if (srcInfo.lastModified() <= tgtInfo.lastModified()) { emit success(tr("古いファイルのためスキップ")); skipCount++; @@ -121,7 +117,7 @@ void CopyMoveWorker::operate() } QFile(tgtInfo.absoluteFilePath()).remove(); } - else if (prevCopyMethod == OverWriteDialog::AppendNumber) { + else if (copyMethod == "rbAppendNumber") { QString baseName = tgtInfo.baseName(); QString suffix = tgtInfo.completeSuffix(); for (int n = 1; ; n++) { @@ -133,15 +129,19 @@ void CopyMoveWorker::operate() } emit operation(tr("=>") + tgtInfo.fileName() + tr("にリネーム")); } - else if (prevCopyMethod == OverWriteDialog::Skip) { + else if (copyMethod == "rbSkip") { emit success(tr("スキップ")); skipCount++; break; } - else if (prevCopyMethod == OverWriteDialog::Rename) { + else if (copyMethod == "rbRename") { tgtInfo.setFile(tgtInfo.absolutePath(), alias); emit operation(tr("=>") + tgtInfo.fileName() + tr("にリネーム")); } + else { + qDebug() << "Unknown method : " << copyMethod; + Q_ASSERT(false); + } } ret = QFile::copy(srcInfo.absoluteFilePath(), tgtInfo.absoluteFilePath()); @@ -155,7 +155,6 @@ void CopyMoveWorker::operate() emit error("元ファイルの削除に失敗"); } } - } else { errorCount++; diff --git a/copymoveworker.h b/copymoveworker.h index ade7f6a..7cdac09 100644 --- a/copymoveworker.h +++ b/copymoveworker.h @@ -29,7 +29,7 @@ public: } signals: - void askOverWrite(bool *bOk, int *prevCopyMethod, int *copyMethod, QString *alias, + void askOverWrite(QString *copyMethod, QString *alias, const QString &srcPath, const QString &tgtPath); public slots: diff --git a/filetablemodel.cpp b/filetablemodel.cpp index 06d4424..df135d2 100644 --- a/filetablemodel.cpp +++ b/filetablemodel.cpp @@ -26,6 +26,8 @@ FileTableModel::FileTableModel(QObject *parent) : m_HiddenBrush(), m_ReadonlyBrush() { + // デフォルトフィルタを設定する + setFilter(QDir::NoDot | QDir::AllDirs | QDir::Files); } bool FileTableModel::setPath(const QString &path) @@ -54,7 +56,6 @@ bool FileTableModel::setPath(const QString &path) } else { QFileInfoList::iterator it; - bool removeDotDot = false; for (it = m_fileInfoList.begin(); it != m_fileInfoList.end(); ) { #ifdef Q_OS_WIN32 if (!(filter() & QDir::System)){ @@ -73,27 +74,24 @@ bool FileTableModel::setPath(const QString &path) if (m_dir.isRoot()) { qDebug() << m_dir.absolutePath() << " is root."; it = m_fileInfoList.erase(it); - removeDotDot = true; continue; } } it++; } // ソート方法によらず、".."は必ず先頭にする - if (!removeDotDot) { - QFileInfoList::iterator itRoot = m_fileInfoList.end(); - for (it = m_fileInfoList.begin(); it != m_fileInfoList.end(); it++) { - if (it->fileName() == "..") { - itRoot = it; - break; - } - } - if (itRoot != m_fileInfoList.end()) { - QFileInfo info(*itRoot); - m_fileInfoList.erase(itRoot); - m_fileInfoList.push_front(info); + QFileInfoList::iterator itRoot = m_fileInfoList.end(); + for (it = m_fileInfoList.begin(); it != m_fileInfoList.end(); it++) { + if (it->fileName() == "..") { + itRoot = it; + break; } } + if (itRoot != m_fileInfoList.end()) { + QFileInfo info(*itRoot); + m_fileInfoList.erase(itRoot); + m_fileInfoList.push_front(info); + } } m_checkStates.resize(m_fileInfoList.size()); @@ -105,7 +103,7 @@ bool FileTableModel::setPath(const QString &path) m_fsWatcher = new QFileSystemWatcher(this); m_fsWatcher->addPath(path); connect(m_fsWatcher, SIGNAL(directoryChanged(QString)), - this, SIGNAL(listUpdated())); + this, SLOT(directoryChange(QString))); endResetModel(); @@ -149,36 +147,6 @@ void FileTableModel::setCheckStateAll(Qt::CheckState state) stateChanged(); } -#if 0 -bool FileTableModel::isDir(const QModelIndex &index) const -{ - if (!index.isValid()) { - qDebug() << "isDir() : index is invalid."; - return QString(); - } - return m_fileInfoList[index.row()].isDir(); -} - -const QString FileTableModel::absoluteFilePath(const QModelIndex &index) const -{ - if (!index.isValid()) { - qDebug() << "absoluteFilePath() : index is invalid."; - return QString(); - } -// return m_dir.absoluteFilePath(m_fileInfoList[index.row()].fileName()); - return m_fileInfoList[index.row()].absoluteFilePath(); -} - -const QString FileTableModel::fileName(const QModelIndex &index) const -{ - if (!index.isValid()) { - qDebug() << "fileName() : index is invalid."; - return QString(); - } - return m_fileInfoList[index.row()].fileName(); -} -#endif - QFileInfo FileTableModel::fileInfo(const QModelIndex &index) const { if (!index.isValid()) { @@ -207,6 +175,13 @@ void FileTableModel::updateAppearance() endResetModel(); } +void FileTableModel::directoryChange(const QString &path) +{ + qDebug() << "FileTableModel::directoryChange"; + + setPath(path); +} + void FileTableModel::stateChanged() { int numFolder = 0; diff --git a/filetablemodel.h b/filetablemodel.h index f21ea6e..321829c 100644 --- a/filetablemodel.h +++ b/filetablemodel.h @@ -31,22 +31,20 @@ public: void setCheckState(const QModelIndex &index, Qt::CheckState state); void setCheckStateAll(Qt::CheckState state); const QString absolutePath() const { return m_dir.absolutePath(); } -#if 0 - bool isDir(const QModelIndex &index) const; - const QString absoluteFilePath(const QModelIndex &index) const; - const QString fileName(const QModelIndex &index) const; -#endif + QFileInfoList checkedItems() const; QFileInfo fileInfo(const QModelIndex &index) const; void updateAppearance(); + QFont font() const { return m_font; } + signals: void rootChanged(const QString &root); void stateChanged(int checkedFoldrs, int checkedFiles, quint64 totalSize); - void listUpdated(); public slots: + void directoryChange(const QString &path); private: QDir m_dir; diff --git a/folderview.cpp b/folderview.cpp index 747bf01..1bcf8c5 100644 --- a/folderview.cpp +++ b/folderview.cpp @@ -1,6 +1,322 @@ +#include "common.h" #include "folderview.h" +#include +#include +#include +#include + +QString FilesizeToString(quint64 size) +{ + if (size >= 1024 * 1024 * 1024) { + return QString("%1GB").arg(int(10 * size / (1024 * 1024 * 1024)) / 10); + } + if (size >= 1024 * 1024) { + return QString("%1MB").arg(int(10 * size / (1024 * 1024)) / 10); + } + if (size >= 1024) { + return QString("%1KB").arg(int(10 * size / (1024)) / 10); + } + return QString("%1B").arg(size); +} + FolderView::FolderView(QWidget *parent) : - QTableView(parent) + QTableView(parent), + m_model() +{ + setModel(&m_model); +} + +QString FolderView::side() const +{ + if (this->objectName() == "folderView1") { + return QString("Left"); + } + else { + Q_ASSERT(this->objectName() == "folderView2"); + return QString("Right"); + } +} + +void FolderView::initialize() +{ + qDebug() << side() << "initialize"; + + QHeaderView *header; + // 列のリサイズモードを設定する + header = horizontalHeader(); + header->setSectionResizeMode(QHeaderView::ResizeToContents); + header->setSectionResizeMode(1, QHeaderView::Stretch); + + // 行の高さを設定する + header = verticalHeader(); + header->setDefaultSectionSize(QFontMetrics(m_model.font()).height() * 1.5); + + // 前回終了時のパスを開く + QSettings settings; + setPath(settings.value(side() + slash + IniKey_Dir).toString(), true); + + // 色とフォントを設定する + updateAppearance(); +} + +void FolderView::updateAppearance() +{ + qDebug() << side() << "updateAppearance"; + m_model.updateAppearance(); + + QSettings settings; + QPalette pal = palette(); + pal.setColor(QPalette::Base, settings.value(IniKey_ViewColorBgNormal).value()); + setPalette(pal); +} + +void FolderView::refresh() +{ + qDebug() << side() << "refresh"; + + int row = currentIndex().row(); + + setPath(m_model.absolutePath(), false); + + if (row < 0) { + row = 0; + } + else if (row >= m_model.rowCount()) { + row = m_model.rowCount() - 1; + } + setCurrentIndex(m_model.index(row, 0)); +} + +void FolderView::searchItem(const QString &text) +{ + qDebug() << "FolderView::searchItem" << text; + + for (int row = 0; row < m_model.rowCount(); row++) { + QModelIndex index = m_model.index(row, 0); + QString name = m_model.fileInfo(index).fileName().toLower(); + if (name.indexOf(text.toLower()) != -1) { + setCurrentIndex(index); + emit itemFound(this); + return; + } + } + + emit itemNotFound(this); +} + +void FolderView::searchNext(const QString &text) +{ + qDebug() << "FolderView::searchNext" << text; + + for (int row = currentIndex().row() + 1; row < m_model.rowCount(); row++) { + QModelIndex index = m_model.index(row, 0); + QString name = m_model.fileInfo(index).fileName().toLower(); + if (name.indexOf(text.toLower()) != -1) { + setCurrentIndex(index); + emit itemFound(this); + return; + } + } + + emit itemNotFound(this); +} + +void FolderView::searchPrev(const QString &text) +{ + qDebug() << side() << "searchPrev" << text; + + for (int row = currentIndex().row() - 1; row >= 0; row--) { + QModelIndex index = m_model.index(row, 0); + QString name = m_model.fileInfo(index).fileName().toLower(); + if (name.indexOf(text.toLower()) != -1) { + setCurrentIndex(index); + emit itemFound(this); + return; + } + } + + emit itemNotFound(this); +} + +void FolderView::setCheckStateAll(bool checked) { + qDebug() << side() << "markAll();"; + + QModelIndex current = currentIndex(); + + setUpdatesEnabled(false); + m_model.setCheckStateAll(checked ? Qt::Checked : Qt::Unchecked); + setUpdatesEnabled(true); + + setCurrentIndex(current); +} + +void FolderView::setCheckStateAllFiles() +{ + qDebug() << side() << "markAllFiles();"; + + QModelIndex current = currentIndex(); + + setUpdatesEnabled(false); + for (int n = 0; n < m_model.rowCount(); n++) { + QModelIndex index = m_model.index(n, 0); + QFileInfo info = m_model.fileInfo(index); + if (info.isDir()) { + m_model.setCheckState(index, Qt::Unchecked); + } + else { + m_model.setCheckState(index, Qt::Checked); + } + } + setUpdatesEnabled(true); + + setCurrentIndex(current); +} + +void FolderView::invertCheckState() +{ + qDebug() << side() << "invertCheckState();"; + + QModelIndex current = currentIndex(); + + setUpdatesEnabled(false); + for (int n = 0; n < m_model.rowCount(); n++) { + QModelIndex index = m_model.index(n, 0); + if (m_model.checkState(index) == Qt::Checked) { + m_model.setCheckState(index, Qt::Unchecked); + } + else { + m_model.setCheckState(index, Qt::Checked); + } + } + setUpdatesEnabled(true); + + setCurrentIndex(current); +} + +void FolderView::toggleCheckState(const QModelIndex &index) +{ + QFileInfo info = m_model.fileInfo(index); + if (info.fileName() != "..") { + if (m_model.checkState(index) == Qt::Checked) { + m_model.setCheckState(index, Qt::Unchecked); + } + else { + m_model.setCheckState(index, Qt::Checked); + } + } + // 最終行でなければ、次のアイテムに移動する + if (index.row() == m_model.rowCount() - 1) { + setCurrentIndex(index); + } + else if (index.row() < m_model.rowCount() - 1) { + setCurrentIndex(m_model.index(index.row() + 1, 1)); + } +} + +bool FolderView::historyBack() +{ + if (!m_history.isBegin()) { + setPath(m_history.back(), false); + return true; + } + return false; +} + +bool FolderView::historyForward() +{ + if (!m_history.isEnd()) { + setPath(m_history.forward(), false); + return true; + } + return false; +} + +QFileInfo FolderView::currentItem() const +{ + qDebug() << "FolderView::currentItem"; + + Q_ASSERT(currentIndex().isValid()); + + return m_model.fileInfo(currentIndex()); +} + +QFileInfoList FolderView::selectedItems() const +{ + qDebug() << side() << "selectedItems"; + + // マークされているアイテムを取得する + QFileInfoList list = m_model.checkedItems(); + + // 一つもマークされていなければ、カーソル位置のアイテムを取得する + if (list.isEmpty()) { + list << currentItem(); + } + + return list; +} + +void FolderView::setPath(const QString &path, bool addHistory) +{ + qDebug() << side() << "setPath" << path << addHistory; + + Q_ASSERT(QFileInfo(path).isDir()); + + emit retrieveStarted(path); + + setUpdatesEnabled(false); + m_model.setPath(path); + setCurrentIndex(m_model.index(0, 0)); + setUpdatesEnabled(true); + + if (addHistory) { + m_history.add(path); + } + + emit retrieveFinished(); +} + +void FolderView::setFilter(QDir::Filters filter, bool enable) +{ + qDebug() << side() << "setFilter" << enable; + + if (enable) { + m_model.setFilter(m_model.filter() | filter); + } + else { + m_model.setFilter(m_model.filter() ^ filter); + } +} + +void FolderView::setHistoryIndexAt(int index) +{ + m_history.setAt(index); + setPath(m_history.current(), false); +} + +void FolderView::setNameFilters(const QStringList &list) +{ + m_model.setNameFilters(list); + refresh(); +} + +void FolderView::setSorting(QDir::SortFlags flags) +{ + m_model.setSorting(flags); + refresh(); +} + +void FolderView::keyPressEvent(QKeyEvent *event) +{ + qDebug() << side() << "keyPressEvent"; + + emit keyPressed(this, event); + + if (!event->isAccepted()) { + QTableView::keyPressEvent(event); + } + else { + qDebug() << "KeyEvent accepted."; + } } diff --git a/folderview.h b/folderview.h index 1bf1731..3b23544 100644 --- a/folderview.h +++ b/folderview.h @@ -1,6 +1,9 @@ #ifndef FOLDERVIEW_H #define FOLDERVIEW_H +#include "filetablemodel.h" +#include "history.h" + #include class FolderView : public QTableView @@ -9,10 +12,59 @@ class FolderView : public QTableView public: explicit FolderView(QWidget *parent = 0); + QString side() const; + + // actions + void initialize(); + void updateAppearance(); + void refresh(); + + void searchItem(const QString &text); + void searchNext(const QString &text); + void searchPrev(const QString &text); + + void setCheckStateAll(bool checked); + void setCheckStateAllFiles(); + void invertCheckState(); + void toggleCheckState(const QModelIndex &index); + + bool historyBack(); + bool historyForward(); + + + // getter + QFileInfo currentItem() const; + QString dir() const { return m_model.absolutePath(); } + QFileInfoList selectedItems() const; + const History* history() const { return &m_history; } + QStringList nameFilters() const { return m_model.nameFilters(); } + + // setter + void setPath(const QString &path, bool addHistory); + void setFilter(QDir::Filters filter, bool enable); + void setHistoryIndexAt(int index); + void setNameFilters(const QStringList &list); + void setSorting(QDir::SortFlags flags); + +private: + FileTableModel m_model; + History m_history; + + signals: + void itemFound(FolderView *view); + void itemNotFound(FolderView *view); + void retrieveStarted(const QString &path); + void retrieveFinished(); + void keyPressed(FolderView *view, QKeyEvent *event); public slots: + + // QWidget interface +protected: + void keyPressEvent(QKeyEvent *event); + }; #endif // FOLDERVIEW_H diff --git a/historydialog.cpp b/historydialog.cpp index 02f5fb8..83c87d1 100644 --- a/historydialog.cpp +++ b/historydialog.cpp @@ -19,7 +19,7 @@ HistoryDialog::~HistoryDialog() delete ui; } -void HistoryDialog::setHistory(History *left, History *right) +void HistoryDialog::setHistory(const History *left, const History *right) { m_leftHistory = left; m_rightHistory = right; diff --git a/historydialog.h b/historydialog.h index 821c0f6..b48b014 100644 --- a/historydialog.h +++ b/historydialog.h @@ -17,7 +17,7 @@ public: explicit HistoryDialog(QWidget *parent = 0); ~HistoryDialog(); - void setHistory(History *left, History *right); + void setHistory(const History *left, const History *right); void setDefaultLeft(bool bLeft); int selectedIndex() const; @@ -25,9 +25,9 @@ public: private: Ui::HistoryDialog *ui; - History *m_leftHistory; - History *m_rightHistory; - History *m_displaying; + const History *m_leftHistory; + const History *m_rightHistory; + const History *m_displaying; private slots: void showLeftHistory(); diff --git a/locationbox.cpp b/locationbox.cpp index bbd0550..bd46ffa 100644 --- a/locationbox.cpp +++ b/locationbox.cpp @@ -1,6 +1,31 @@ +#include "common.h" #include "locationbox.h" +#include +#include + LocationBox::LocationBox(QWidget *parent) : QLineEdit(parent) { } + +void LocationBox::initialize() +{ + qDebug() << "LocationBox::initialize"; + + updateAppearance(); +} + +void LocationBox::updateAppearance() +{ + qDebug() << "LocationBox::updateAppearance"; + + QSettings settings; + + QPalette pal = palette(); + pal.setColor(QPalette::Base, settings.value(IniKey_BoxColorBg).value()); + pal.setColor(QPalette::Text, settings.value(IniKey_BoxColorFg).value()); + setPalette(pal); + + setFont(settings.value(IniKey_BoxFont).value()); +} diff --git a/locationbox.h b/locationbox.h index 0cd5449..6463311 100644 --- a/locationbox.h +++ b/locationbox.h @@ -9,6 +9,9 @@ class LocationBox : public QLineEdit public: explicit LocationBox(QWidget *parent = 0); + void initialize(); + void updateAppearance(); + signals: public slots: diff --git a/main.cpp b/main.cpp index e8d9796..1465830 100644 --- a/main.cpp +++ b/main.cpp @@ -32,14 +32,11 @@ int main(int argc, char *argv[]) // 各オプションのデフォルト値を設定する //>>>>> 起動と終了 - if (settings.value(IniKey_ConfirmExit, "").toString().isEmpty()) + if (settings.value(IniKey_ConfirmExit, "").toString().isEmpty()) { settings.setValue(IniKey_ConfirmExit, true); - if (settings.value(IniKey_BootSizeAbs, "").toString().isEmpty()) { settings.setValue(IniKey_BootSizeSpec, "sizeRelative"); settings.setValue(IniKey_BootSizeAbs, QSize(800,600)); settings.setValue(IniKey_BootSizeRel, QSize(75,75)); - } - if (settings.value(IniKey_BootPosAbs, "").toString().isEmpty()) { settings.setValue(IniKey_BootPosSpec, "posCenter"); settings.setValue(IniKey_BootPosAbs, QPoint(0, 0)); settings.setValue(IniKey_BootPosRel, QPoint(0, 0)); diff --git a/mainwindow.cpp b/mainwindow.cpp index 8febeeb..d2c121f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,8 +1,19 @@ #include "common.h" #include "mainwindow.h" #include "preferencedialog.h" -#include "filetableview.h" +#include "folderview.h" +#include "searchbox.h" +#include "locationbox.h" #include "ui_mainwindow.h" +#include "copymoveworker.h" +#include "operationdialog.h" +#include "overwritedialog.h" +#include "deleteworker.h" +#include "renameworker.h" +#include "renamesingledialog.h" +#include "renamemultidialog.h" +#include "historydialog.h" +#include "sortdialog.h" #include #include @@ -12,32 +23,84 @@ #include #include #include +#include +#include +#include +#include +#include + +MainWindow* getMainWnd() +{ + foreach (QWidget *w, qApp->topLevelWidgets()) { + if (w->objectName() == "MainWindow") { + return static_cast(w); + } + } + qDebug() << "MainWindow not found !?"; + return NULL; +} MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), - m_focusedView(NULL) + m_focusedView(NULL), + m_overwriteDialog(NULL) { ui->setupUi(this); - ui->RPanel->setSide("Right"); - ui->LPanel->setSide("Left"); - ui->LPanel->updateAppearance(); - ui->RPanel->updateAppearance(); - QSettings settings; - // メニュー項目の状態を初期化する - if (settings.value(IniKey_ShowHidden).toBool()) { - ui->view_Hidden->setChecked(true); - } - if (settings.value(IniKey_ShowSystem).toBool()) { - ui->view_System->setChecked(true); + m_overwriteDialog = new OverWriteDialog(this); + + initActionConnections(); + connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), this, SLOT(focusChange(QWidget*,QWidget*))); + connect(ui->textView, SIGNAL(viewFinished(QWidget*)), this, SLOT(viewFinish(QWidget*))); + + // テキストビューアは初期状態で非表示 + ui->textView->setVisible(false); + + for (int i = 1; i <= 2; i++) { + LocationBox *locationBox = findChild(QString("locationBox%1").arg(i)); + Q_CHECK_PTR(locationBox); + + FolderView *folderView = findChild(QString("folderView%1").arg(i)); + Q_CHECK_PTR(folderView); + + SearchBox *searchBox = findChild(QString("searchBox%1").arg(i)); + Q_CHECK_PTR(searchBox); + + // シグナル&スロット + connect(folderView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(open(QModelIndex))); + connect(folderView, SIGNAL(itemFound(FolderView*)), this, SLOT(itemFound(FolderView*))); + connect(folderView, SIGNAL(itemNotFound(FolderView*)), this, SLOT(itemNotFound(FolderView*))); + connect(folderView, SIGNAL(keyPressed(FolderView*,QKeyEvent*)), this, SLOT(keyPress(FolderView*,QKeyEvent*))); + connect(folderView, SIGNAL(retrieveFinished()), this, SLOT(retrieveFinish())); + connect(folderView, SIGNAL(retrieveStarted(QString)), this, SLOT(retrieveStart(QString))); + connect(searchBox, SIGNAL(textEdited(QString)), this, SLOT(searchItem(QString))); + connect(searchBox, SIGNAL(returnPressed()), this, SLOT(returnPressInSearchBox())); + + // 検索ボックスは初期状態で非表示 + searchBox->setVisible(false); + + // ロケーションボックスを初期化する + locationBox->initialize(); + + // フィルタを初期化する + setNameFilters(folderView); + + // ソートを初期化する + setSorting(folderView); + + // フォルダビューを初期化する + folderView->initialize(); + + folderView->repaint(); } - bool enabled; - enabled = !settings.value(IniKey_EditorPath).toString().isEmpty(); - ui->action_OpenEditor->setEnabled(enabled); - enabled = !settings.value(IniKey_TerminalPath).toString().isEmpty(); - ui->action_OpenTerminal->setEnabled(enabled); + QSettings settings; + // メニュー項目の状態を初期化する + ui->view_Hidden->setChecked(settings.value(IniKey_ShowHidden).toBool()); + ui->view_System->setChecked(settings.value(IniKey_ShowSystem).toBool()); + ui->action_OpenEditor->setEnabled(!settings.value(IniKey_EditorPath).toString().isEmpty()); + ui->action_OpenTerminal->setEnabled(!settings.value(IniKey_TerminalPath).toString().isEmpty()); // 追加のショートカットキーを設定する QList shortcuts; @@ -49,6 +112,7 @@ MainWindow::MainWindow(QWidget *parent) : shortcuts.append(QKeySequence("Shift+M")); ui->action_Exec->setShortcuts(shortcuts); + // MacだとShift+の形で認識されてしまうもの shortcuts = ui->view_Filter->shortcuts(); shortcuts.append(QKeySequence("Shift+*")); // マヂで!? ui->view_Filter->setShortcuts(shortcuts); @@ -61,23 +125,16 @@ MainWindow::MainWindow(QWidget *parent) : shortcuts.append(QKeySequence("Shift+?")); // マヂで!? ui->help_About->setShortcuts(shortcuts); - // シグナル/スロットを設定する - connect(ui->action_Setting, SIGNAL(triggered()), this, SLOT(showPreferenceDialog())); - connect(ui->action_Quit, SIGNAL(triggered()), this, SLOT(close())); - connect(ui->help_About, SIGNAL(triggered()), this, SLOT(about())); - connect(ui->view_Hidden, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles())); - connect(ui->view_System, SIGNAL(triggered()), this, SLOT(toggleShowSystemFiles())); - connect(ui->check_Update, SIGNAL(triggered()), this, SLOT(checkUpdate())); - connect(ui->plainTextEdit, SIGNAL(viewFinished(QWidget*)), this, SLOT(viewFinish(QWidget*))); - // ウィンドウタイトルを設定する setWindowTitle(tr("げふぅ v%1").arg(VERSION_VALUE)); + // ウィンドウアイコンを設定する -#if defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACX) +#if defined(Q_OS_MAC) setWindowIcon(QIcon(":/images/Gefu.icns")); #else setWindowIcon(QIcon(":/images/Gefu.png")); #endif + //>>>>> ウィンドウサイズと位置を設定する QString strValue; QPoint point = this->geometry().topLeft(); @@ -124,9 +181,6 @@ MainWindow::MainWindow(QWidget *parent) : if (settings.value(IniKey_CheckUpdates).toBool()) { checkUpdate(true); } - -// ui->splitter->setVisible(false); - ui->plainTextEdit->setVisible(false); } MainWindow::~MainWindow() @@ -134,220 +188,1282 @@ MainWindow::~MainWindow() delete ui; } -FileTableView *MainWindow::otherSideView(const FileTableView *view) const +FolderView* MainWindow::otherSideView(const FolderView *view) const { - QWidget *w = view->parentWidget(); - if (ui->LPanel == w) { - return ui->RPanel->findChild("fileTable"); - } - else if (ui->RPanel == w) { - return ui->LPanel->findChild("fileTable"); + qDebug() << "MainWindow::otherSideView()" << view->objectName(); + + if (view == ui->folderView1) { + return ui->folderView2; } - qDebug() << w->objectName(); - return NULL; + Q_ASSERT(view == ui->folderView2); + return ui->folderView1; } -void MainWindow::openRequest(const QFileInfo &info) +void MainWindow::focusChange(QWidget *old, QWidget *now) { - m_focusedView = QApplication::focusWidget(); + Q_UNUSED(old); + Q_UNUSED(now); + qDebug() << "MainWindow::focusChange"; - setUpdatesEnabled(false); + updateActions(); +} - foreach (QObject *obj, this->children()) { - QAction *action = qobject_cast(obj); - if (action) { - if (action->objectName() == "help_About" || - action->objectName() == "check_Update" || - action->objectName() == "copy_Fullpath" || - action->objectName() == "copy_Filename" || - action->objectName() == "action_Quit" || - action->objectName() == "action_Setting") - { - continue; - } - qDebug() << action->objectName(); - action->setEnabled(false); +void MainWindow::executeCommand() +{ + qDebug() << "MainWindow::executeCommand"; + + FolderView *v = folderView(); + Q_ASSERT(v); + + QFileInfoList list = v->selectedItems(); + QString command = QString::null; + foreach (const QFileInfo &info, list) { +#ifdef Q_OS_MAC + QString path = info.absoluteFilePath(); +#else + QString path = info.fileName(); +#endif + if (info.isExecutable()) { + command = QQ(path) + " " + command; + } + else { + command += " " + QQ(path); } } - ui->menu_File->setVisible(false); - ui->splitter->setVisible(false); - ui->plainTextEdit->setVisible(true); - ui->plainTextEdit->setFocus(); - - setUpdatesEnabled(true); + QInputDialog dlg(this); + dlg.setInputMode(QInputDialog::TextInput); + dlg.setWindowTitle(tr("コマンドを実行")); + dlg.setLabelText(tr("コマンド:")); + dlg.setTextValue(command); + dlg.resize(width() * 0.8, dlg.height()); - QFile file(info.absoluteFilePath()); - if (file.open(QIODevice::ReadOnly)) { - ui->plainTextEdit->setSource(file.readAll()); + int ret = dlg.exec(); + command = dlg.textValue(); + if (ret == QDialog::Accepted && !command.isEmpty()) { + startProcess(command, v->dir(), tr("コマンドの実行に失敗しました。")); } } -void MainWindow::showPreferenceDialog() +void MainWindow::historyBack() { - PreferenceDialog dlg(this); + qDebug() << "MainWindow::historyBack();"; - if (dlg.exec() == QDialog::Accepted) { - ui->LPanel->updateAppearance(); - ui->RPanel->updateAppearance(); + if (folderView()->historyBack()) { + updateActions(); + } +} - QSettings settings; - bool enabled; - enabled = !settings.value(IniKey_EditorPath).toString().isEmpty(); - ui->action_OpenEditor->setEnabled(enabled); +void MainWindow::historyForward() +{ + qDebug() << "MainWindow::historyForward();"; - enabled = !settings.value(IniKey_TerminalPath).toString().isEmpty(); - ui->action_OpenTerminal->setEnabled(enabled); + if (folderView()->historyForward()) { + updateActions(); } } -void MainWindow::toggleShowHiddenFiles() +void MainWindow::itemFound(FolderView *view) { - // キーボードがトリガーの場合、メニュー項目のチェック状態は - // 変わらない(Mac)ので、QSettingsを使う - QSettings settings; - bool show = !settings.value(IniKey_ShowHidden).toBool(); - settings.setValue(IniKey_ShowHidden, show); + qDebug() << "MainWindow::itemFound"; - ui->view_Hidden->setChecked(show); + SearchBox *box = searchBox(view); + QPalette pal = box->palette(); + pal.setColor(QPalette::Text, QPalette().text().color()); + box->setPalette(pal); +} + +void MainWindow::itemNotFound(FolderView *view) +{ + qDebug() << "MainWindow::itemNotFound"; - emit showHiddenFiles(show); + SearchBox *box = searchBox(view); + QPalette pal = box->palette(); + pal.setColor(QPalette::Text, Qt::red); + box->setPalette(pal); } -void MainWindow::toggleShowSystemFiles() +void MainWindow::markAll() { - // キーボードがトリガーの場合、メニュー項目のチェック状態は - // 変わらない(Mac)ので、QSettingsを使う - QSettings settings; - bool show = !settings.value(IniKey_ShowSystem).toBool(); - settings.setValue(IniKey_ShowSystem, show); + qDebug() << "MainWindow::markAll();"; - ui->view_System->setChecked(show); + folderView()->setCheckStateAll(true); +} + +void MainWindow::markAllFiles() +{ + qDebug() << "MainWindow::markAllFiles();"; - emit showSystemFiles(show); + folderView()->setCheckStateAllFiles(); } -void MainWindow::checkUpdate(bool silent) +void MainWindow::markAllOff() { - QNetworkAccessManager *manager = new QNetworkAccessManager(this); + qDebug() << "MainWindow::markAllOff();"; - if (silent) { - connect(manager, SIGNAL(finished(QNetworkReply*)), - this, SLOT(checkUpdateFinishedSilent(QNetworkReply*))); - } - else { - connect(manager, SIGNAL(finished(QNetworkReply*)), - this, SLOT(checkUpdateFinished(QNetworkReply*))); - } -#ifdef Q_OS_WIN - manager->get(QNetworkRequest(QUrl("http://miyabi.rakusaba.jp/wp-content/uploads/gefu_latest_win.html"))); -#elif defined(Q_OS_MAC) - manager->get(QNetworkRequest(QUrl("http://miyabi.rakusaba.jp/wp-content/uploads/gefu_latest_mac.html"))); -#endif + folderView()->setCheckStateAll(false); } -void MainWindow::checkUpdateFinished(QNetworkReply *reply) +void MainWindow::markInvert() { - checkUpdateFinished(reply, false); + qDebug() << "MainWindow::markInvert();"; + + folderView()->invertCheckState(); } -void MainWindow::checkUpdateFinished(QNetworkReply *reply, bool silent) +void MainWindow::markToggle() { - if (reply->error() == QNetworkReply::NoError) { - QString str = reply->readAll(); - str = str.split(QRegExp("[\r\n]"), QString::SkipEmptyParts).at(0); - QRegExp rx("Gefu([0-9]+)"); - rx.indexIn(str); - QString version = rx.cap(1); - if (version.toInt() > VERSION_VALUE * 100) { - QMessageBox::information( - this, tr("情報"), - tr("最新のバージョンが存在します。
") + - tr("こちらからダウンロードしてください。").arg(str)); + qDebug() << "MainWindow::markToggle();"; + + folderView()->toggleCheckState(folderView()->currentIndex()); +} + +void MainWindow::moveItems() +{ + qDebug() << "MainWindow::moveItems"; + + FolderView *v = folderView(); + QFileInfoList list = v->selectedItems(); + if (list.isEmpty()) { + return; + } + + QSettings settings; + if (settings.value(IniKey_ConfirmCopy).toBool()) { + if (QMessageBox::question(this, tr("確認"), tr("移動を実行しますか?")) + != QMessageBox::Yes) + { + return; } - else if (!silent) { - QMessageBox::information( - this, tr("情報"), - tr("お使いのバージョンは最新です。")); + } + + // 上書き確認ダイアログを初期化する + m_overwriteDialog->reset(); + + // ワーカースレッドを作成する + FolderView *other = otherSideView(v); + CopyMoveWorker *worker = new CopyMoveWorker(); + connect(worker, SIGNAL(askOverWrite(QString*,QString*,QString,QString)), + this, SLOT(askOverWrite(QString*,QString*,QString,QString))); + worker->setCopyList(&list); + worker->setTargetDir(other->dir()); + worker->setMoveMode(true); + + // 進捗ダイアログを表示して、処理を開始する + OperationDialog opDlg(this); + opDlg.setWindowTitle(tr("移動")); + opDlg.setWorker(worker); + opDlg.setAutoClose(settings.value(IniKey_AutoCloseCopy).toBool()); + + opDlg.exec(); + + settings.setValue(IniKey_AutoCloseCopy, opDlg.autoClose()); + + // 念のため、リフレッシュ + ui->folderView1->refresh(); + ui->folderView2->refresh(); +} + +void MainWindow::keyPress(FolderView *view, QKeyEvent *event) +{ + QString ksq = KeyEventToSequence(event); + if (ksq == "") { + event->ignore(); + return; + } + + qDebug() << "MainWindow::keyPress" << ksq; + + foreach (QObject *obj, children()) { + QAction *action = qobject_cast(obj); + if (!action) { + continue; + } + + foreach (const QKeySequence &k, action->shortcuts()) { + if (ksq == k.toString()) { + if (action->isEnabled()) { + if (action->isCheckable()) { + action->setChecked(!action->isChecked()); + } + else { + emit action->triggered(); + } + qDebug() << "emit" << action->objectName(); + } + event->accept(); + return; + } } } - else if (!silent){ - QMessageBox::critical( - this, tr("エラー"), - tr("最新バージョンのチェックに失敗しました。
") + - reply->errorString()); + + if (ksq == "Left" || ksq == "Right") { + if (view->side() == ksq) { + } + else { + otherSideView(view)->setFocus(); + } + event->accept(); + return; } + + event->ignore(); } -void MainWindow::checkUpdateFinishedSilent(QNetworkReply *reply) +void MainWindow::returnPressInSearchBox() { - checkUpdateFinished(reply, true); + qDebug() << "MainWindow::returnPressInSearchBox"; + + if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { + emit ui->action_SearchPrev->triggered(); + } + else { + emit ui->action_SearchNext->triggered(); + } } -void MainWindow::viewFinish(QWidget *sender) +void MainWindow::chooseFolder() { - setUpdatesEnabled(false); + qDebug() << "MainWindow::chooseFolder();"; - foreach (QObject *obj, this->children()) { - QAction *action = qobject_cast(obj); - if (action) { - action->setEnabled(true); - } + QString path = QFileDialog::getExistingDirectory( + this, tr("フォルダを選択"), folderView()->dir()); + if (!path.isEmpty()) { + folderView()->setPath(path, true); + updateActions(); } +} - sender->setVisible(false); - ui->splitter->setVisible(true); - m_focusedView->setFocus(); +void MainWindow::copyFilenameToClipboard() +{ + qDebug() << "MainWindow::copyFilenameToClipboard();"; - setUpdatesEnabled(true); + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(folderView()->currentItem().fileName()); } -void MainWindow::about() +void MainWindow::copyFullpathTpClipboard() { - QMessageBox::about( - this, - tr("げふぅ について"), - tr("

Gefu Ver%1

").arg(VERSION_VALUE) + - tr("
Gefu is an Experimental File Utility.
" - "(げふぅは実験的なファイルユーティリティです)
" - "

最新版の情報は喫茶[雅]で公開しています。

" - "

Copyright 2014 @miyabi_satoh All rights reserved.

")); + qDebug() << "MainWindow::copyFullpathTpClipboard();"; + + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(folderView()->currentItem().absoluteFilePath()); } -MainWindow* getMainWnd() +void MainWindow::askOverWrite(QString *copyMethod, + QString *alias, + const QString &srcPath, + const QString &tgtPath) { - foreach (QWidget *w, qApp->topLevelWidgets()) { - if (w->objectName() == "MainWindow") { - return static_cast(w); + qDebug() << "MainWindow::askOverWrite();"; + + CopyMoveWorker *worker = static_cast(sender()); + if (!m_overwriteDialog->isKeepSetting() || + m_overwriteDialog->copyMethod() == "rbRename") + { + m_overwriteDialog->setFileInfo(srcPath, tgtPath); + if (m_overwriteDialog->exec() == QDialog::Rejected) { + worker->requestStop(); } } - qDebug() << "MainWindow not found !?"; - return NULL; -} + *copyMethod = m_overwriteDialog->copyMethod(); + *alias = m_overwriteDialog->alias(); + worker->endAsking(); +} -void MainWindow::closeEvent(QCloseEvent *event) +void MainWindow::copyItems() { + qDebug() << "MainWindow::copyItems"; + + FolderView *v = folderView(); + QFileInfoList list = v->selectedItems(); + if (list.isEmpty()) { + return; + } + QSettings settings; + if (settings.value(IniKey_ConfirmCopy).toBool()) { + if (QMessageBox::question(this, tr("確認"), tr("コピーを実行しますか?")) + != QMessageBox::Yes) + { + return; + } + } - if (settings.value(IniKey_ConfirmExit).toBool()) { - QMessageBox msgBox; - QCheckBox *checkBox = new QCheckBox(); - checkBox->setText(tr("次回以降は確認しない")); - msgBox.setCheckBox(checkBox); - msgBox.setText(tr("終了しますか?")); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msgBox.setIcon(QMessageBox::Question); + // 上書き確認ダイアログを初期化する + m_overwriteDialog->reset(); - if (msgBox.exec() == QMessageBox::No) { - event->ignore(); + // ワーカースレッドを作成する + FolderView *other = otherSideView(v); + CopyMoveWorker *worker = new CopyMoveWorker(); + connect(worker, SIGNAL(askOverWrite(QString*,QString*,QString,QString)), + this, SLOT(askOverWrite(QString*,QString*,QString,QString))); + worker->setCopyList(&list); + worker->setTargetDir(other->dir()); + worker->setMoveMode(false); + + // 進捗ダイアログを表示して、処理を開始する + OperationDialog opDlg(this); + opDlg.setWindowTitle(tr("コピー")); + opDlg.setWorker(worker); + opDlg.setAutoClose(settings.value(IniKey_AutoCloseCopy).toBool()); + + opDlg.exec(); + + settings.setValue(IniKey_AutoCloseCopy, opDlg.autoClose()); + + // 念のため、リフレッシュ + ui->folderView1->refresh(); + ui->folderView2->refresh(); +} + +void MainWindow::createFile() +{ + qDebug() << "MainWindow::createFile"; + + bool bOk; + QString name = QInputDialog::getText( + this, tr("ファイルを作成"), tr("ファイル名:"), + QLineEdit::Normal, "", &bOk); + if (!bOk || name.isEmpty()) { + return; + } + + QDir dir(folderView()->dir()); + QFile file(dir.absoluteFilePath(name)); + if (!file.open(QIODevice::WriteOnly)) { + QMessageBox::critical( + this, tr("エラー"), + tr("ファイルの作成に失敗しました。")); + } + else { + file.close(); + + QSettings settings; + if (settings.value(IniKey_OpenAfterCreateFile).toBool()) { + openEditor(dir.absoluteFilePath(name)); + } + } +} + +void MainWindow::createFolder() +{ + qDebug() << "MainWindow::createFolder"; + + bool bOk; + QString name = QInputDialog::getText( + this, tr("フォルダを作成"), tr("フォルダ名:"), + QLineEdit::Normal, "", &bOk); + if (!bOk || name.isEmpty()) { + return; + } + + QDir dir(folderView()->dir()); + if (!dir.mkpath(name)) { + QMessageBox::critical( + this, tr("エラー"), + tr("フォルダの作成に失敗しました。")); + } + else { + QSettings settings; + if (settings.value(IniKey_MoveAfterCreateFolder).toBool()) { + folderView()->setPath(dir.absoluteFilePath(name), true); + updateActions(); + } + } +} + +void MainWindow::deleteItems() +{ + qDebug() << "MainWindow::deleteItems"; + + FolderView *v = folderView(); + QFileInfoList list = v->selectedItems(); + if (list.isEmpty()) { + return; + } + + QSettings settings; + if (settings.value(IniKey_ConfirmDelete).toBool()) { + QString msg; + if (list.size() == 1) { + msg = list[0].fileName(); + } + else { + msg = tr("%1個のアイテム").arg(list.size()); + } + int ret = QMessageBox::question( + this, tr("確認"), + msg + tr("を削除しますか?")); + if (ret != QMessageBox::Yes) { return; } - settings.setValue(IniKey_ConfirmExit, !checkBox->isChecked()); } - settings.setValue(IniKey_WindowGeometry, saveGeometry()); - settings.setValue(iniKey_WindowState, saveState()); - QMainWindow::closeEvent(event); + DeleteWorker *worker = new DeleteWorker(); + worker->setDeleteList(&list); + + OperationDialog opDlg(this); + opDlg.setWindowTitle(tr("削除")); + opDlg.setWorker(worker); + opDlg.setAutoClose(settings.value(IniKey_AutoCloseDelete).toBool()); + + opDlg.exec(); + + settings.setValue(IniKey_AutoCloseDelete, opDlg.autoClose()); + + // 念のため、リフレッシュ + ui->folderView1->refresh(); + ui->folderView2->refresh(); +} + +void MainWindow::open(const QModelIndex &index) +{ + Q_UNUSED(index); + qDebug() << "MainWindow::open"; + + FolderView *v = folderView(); + Q_ASSERT(v); + + QFileInfo info = v->currentItem(); + if (info.isDir()) { + v->setPath(info.absoluteFilePath(), true); + updateActions(); + return; + } + + 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()) { + shellExecute(); + return; + } + } + } + + setUpdatesEnabled(false); + + foreach (QObject *obj, this->children()) { + QAction *action = qobject_cast(obj); + if (action) { + if (action->objectName() == "help_About" || + action->objectName() == "check_Update" || + action->objectName() == "copy_Fullpath" || + action->objectName() == "copy_Filename" || + action->objectName() == "action_Quit" || + action->objectName() == "action_Setting") + { + continue; + } + action->setEnabled(false); + } + } + + m_focusedView = folderView(); + ui->splitter->setVisible(false); + ui->textView->setVisible(true); + ui->textView->setFocus(); + + setUpdatesEnabled(true); + + QFile file(info.absoluteFilePath()); + if (file.open(QIODevice::ReadOnly)) { + ui->textView->setSource(file.readAll()); + } +} + +void MainWindow::openEditor(const QString &path) +{ + qDebug() << "MainWindow::openEditor"; + + QSettings settings; + QString exe = settings.value(IniKey_EditorPath).toString(); + if (exe.isEmpty()) { + QMessageBox::critical( + this, tr("エラー"), + tr("外部エディタのパスが未定義です。")); + return; + } + + FolderView *v = folderView(); + Q_ASSERT(v); + + QFileInfoList list; + if (path.isEmpty()) { + list = v->selectedItems(); + } + else { + list << path; + } + + foreach (const QFileInfo &info, list) { + QString opt = settings.value(IniKey_EditorOption).toString(); + replaceVars(opt, info); + +#ifdef Q_OS_MAC + QString command = "open -a " + exe + " " + opt; +#else + QString command = QQ(exe) + " " + opt; +#endif + if (!startProcess(command, info.absolutePath(), tr("外部エディタの起動に失敗しました。"))) { + break; + } + } +} + +void MainWindow::openTerminal() +{ + qDebug() << "MainWindow::openTerminal"; + + QSettings settings; + QString exe = settings.value(IniKey_TerminalPath).toString(); + if (exe.isEmpty()) { + QMessageBox::critical( + this, tr("エラー"), + tr("ターミナルのパスが未定義です。")); + return; + } + + FolderView *v = folderView(); + Q_ASSERT(v); + + foreach (const QFileInfo &info, v->selectedItems()) { + QString opt = settings.value(IniKey_TerminalOption).toString(); + replaceVars(opt, info); + +#ifdef Q_OS_MAC + QString command = "open -a " + QQ(exe) + " --args " + opt; +#else + QString command = QQ(exe) + " " + opt; +#endif + if (!startProcess(command, info.absolutePath(), tr("ターミナルの起動に失敗しました。"))) { + break; + } + } +} + +void MainWindow::refresh() +{ + qDebug() << "MainWindow::refresh();"; + + folderView()->refresh(); + updateActions(); +} + +void MainWindow::renameItems() +{ + qDebug() << "MainWindow::renameItems"; + + FolderView *v = folderView(); + + QFileInfoList list = v->selectedItems(); + if (list.isEmpty()) { + return; + } + + IRenameDialog *dlg; + if (list.size() == 1) { + dlg = new RenameSingleDialog(this); + } + else { + dlg = new RenameMultiDialog(this); + } + dlg->setWorkingDirectory(v->dir()); + dlg->setNames(list); + int dlgResult = dlg->exec(); + if (dlgResult != QDialog::Accepted || dlg->renameMap().isEmpty()) { + return; + } + + QSettings settings; + if (settings.value(IniKey_ConfirmRename).toBool()) { + int ret = QMessageBox::question(this, tr("確認"), + tr("名前の変更を実行しますか?")); + if (ret != QMessageBox::Yes) { + return; + } + } + + RenameWorker *worker = new RenameWorker(); + worker->setRenameMap(&dlg->renameMap()); + + OperationDialog opDlg(this); + opDlg.setWindowTitle(tr("名前を変更")); + opDlg.setWorker(worker); + opDlg.setAutoClose(settings.value(IniKey_AutoCloseRename).toBool()); + + opDlg.exec(); + + settings.setValue(IniKey_AutoCloseRename, opDlg.autoClose()); +} + +void MainWindow::retrieveFinish() +{ + qDebug() << "MainWindow::retrieveFinish();"; + + ui->statusBar->showMessage(tr("レディ"), 5000); +} + +void MainWindow::retrieveStart(const QString &path) +{ + qDebug() << "MainWindow::retrieveStart();" << path; + + ui->statusBar->showMessage(tr("ファイルリストを取得しています...")); + if (sender() == ui->folderView1) { + ui->locationBox1->setText(path); + } + else { + Q_ASSERT(sender() == ui->folderView2); + ui->locationBox2->setText(path); + } +} + +void MainWindow::shellExecute() +{ + qDebug() << "MainWindow::shellExecute"; + + FolderView *v = folderView(); + Q_ASSERT(v); + + QFileInfoList list = v->selectedItems(); + foreach (const QFileInfo &info, list) { + QString path = QDir::toNativeSeparators(info.absoluteFilePath()); + QDesktopServices::openUrl(QUrl("file:///" + path)); + } +} + +void MainWindow::showFilterDialog() +{ + qDebug() << "MainWindow::showFilterDialog();"; + + QString filters = folderView()->nameFilters().join(" "); + + QInputDialog dlg(this); + dlg.setInputMode(QInputDialog::TextInput); + dlg.setWindowTitle(tr("フィルタを設定")); + dlg.setLabelText(tr("フィルタ:")); + dlg.setTextValue(filters); + dlg.resize(width() * 0.8, dlg.height()); + + if (dlg.exec() == QDialog::Accepted) { + setNameFilters(folderView(), dlg.textValue()); + } +} + +void MainWindow::showHistoryDialog() +{ + qDebug() << "MainWindow::showHistoryDialog();"; + + FolderView *v = folderView(); + FolderView *vOther = otherSideView(v); + + HistoryDialog dlg(this); + if (v->side() == "Left") { + dlg.setDefaultLeft(true); + dlg.setHistory(v->history(), vOther->history()); + } + else { + dlg.setDefaultLeft(false); + dlg.setHistory(vOther->history(), v->history()); + } + + if (dlg.exec() == QDialog::Accepted) { + if (v->side() == dlg.selectedSide()) { + v->setHistoryIndexAt(dlg.selectedIndex()); + } + else { + v->setPath(vOther->history()->at(dlg.selectedIndex()), true); + } + updateActions(); + } +} + +void MainWindow::showSortDialog() +{ + qDebug() << "MainWindow::showSortDialog();"; + + SortDialog dlg(this); + dlg.setRightOrLeft(folderView()->side()); + + if (dlg.exec() != QDialog::Accepted) { + return; + } + + setSorting(folderView()); +} + +void MainWindow::swapView() +{ + qDebug() << "MainWindow::swapView();"; + + QString dir1 = ui->folderView1->dir(); + QString dir2 = ui->folderView2->dir(); + + ui->folderView1->setPath(dir2, true); + ui->folderView2->setPath(dir1, true); + + updateActions(); +} + +void MainWindow::setSorting(FolderView *view) +{ + qDebug() << "MainWindow::setSorting();" << view->objectName(); + + QSettings settings; + QDir::SortFlags flags; + + int sortBy = settings.value(view->side() + slash + IniKey_SortBy).toInt(); + switch (sortBy) { + case SortByDate: flags |= QDir::Time; break; + case SortBySize: flags |= QDir::Size; break; + case SortByType: flags |= QDir::Type; break; + default: flags |= QDir::Name; break; + } + + // デフォルトだと文字列は昇順で、数値は降順…orz + int orderBy = settings.value(view->side() + slash + IniKey_OrderBy).toInt(); + if (((sortBy == SortByName || sortBy == SortByType) && orderBy == OrderByDesc) || + ((sortBy == SortByDate || sortBy == SortBySize) && orderBy == OrderByAsc)) + { + flags |= QDir::Reversed; + } + + switch (settings.value(view->side() + slash + IniKey_PutDirs).toInt()) { + case PutDirsFirst: flags |= QDir::DirsFirst; break; + case PutDirsLast: flags |= QDir::DirsLast; break; + } + + if (settings.value(view->side() + slash + IniKey_IgnoreCase).toBool()) { + flags |= QDir::IgnoreCase; + } + + view->setSorting(flags); +} + +void MainWindow::searchItem(const QString &text) +{ + qDebug() << "MainWindow::searchItem" << text; + + FolderView *v; + SearchBox *box; + if (ui->searchBox1->hasFocus()) { + v = ui->folderView1; + box = ui->searchBox1; + } + else { + Q_ASSERT(ui->searchBox2->hasFocus()); + v = ui->folderView2; + box = ui->searchBox2; + } + + if (text.right(1) == "/") { + box->setText(text.left(text.length() - 1)); + ui->action_Search->setChecked(false); + return; + } + + v->searchItem(box->text()); +} + +void MainWindow::searchNext() +{ + qDebug() << "MainWindow::searchNext"; + + FolderView *v = folderView(); + SearchBox *box = searchBox(v); + v->searchNext(box->text()); +} + +void MainWindow::searchPrev() +{ + qDebug() << "MainWindow::searchPrev"; + + FolderView *v = folderView(); + SearchBox *box = searchBox(v); + v->searchPrev(box->text()); +} + +void MainWindow::setCursorToBegin() +{ + qDebug() << "MainWindow::setCursorToBegin();"; + + FolderView *v = folderView(); + int row = 0; + v->setCurrentIndex(v->model()->index(row, 0)); +} + +void MainWindow::cursorDown() +{ + qDebug() << "MainWindow::cursorDown();"; + + FolderView *v = folderView(); + int row = v->currentIndex().row() + 1; + if (row < v->model()->rowCount()) { + v->setCurrentIndex(v->model()->index(row, 0)); + } +} + +void MainWindow::cursorUp() +{ + qDebug() << "MainWindow::cursorUp();"; + + FolderView *v = folderView(); + int row = v->currentIndex().row() - 1; + if (row >= 0) { + v->setCurrentIndex(v->model()->index(row, 0)); + } +} + +void MainWindow::setCursorToEnd() +{ + qDebug() << "MainWindow::setCursorToEnd();"; + + FolderView *v = folderView(); + int row = v->model()->rowCount() - 1; + v->setCurrentIndex(v->model()->index(row, 0)); +} + +void MainWindow::setPathFromOther() +{ + qDebug() << "MainWindow::setPathFromOther();"; + + FolderView *view = folderView(); + FolderView *other = otherSideView(view); + + view->setPath(other->dir(), true); + updateActions(); +} + +void MainWindow::setPathToHome() +{ + qDebug() << "MainWindow::setPathToHome();"; + + folderView()->setPath(QDir::homePath(), true); + updateActions(); +} + +void MainWindow::setPathToOther() +{ + qDebug() << "MainWindow::setPathToOther();"; + + FolderView *view = folderView(); + FolderView *other = otherSideView(view); + + other->setPath(view->dir(), true); + updateActions(); +} + +void MainWindow::setPathToParent() +{ + qDebug() << "MainWindow::setPathToParent();"; + + QDir dir(folderView()->dir()); + if (!dir.isRoot()) { + dir.cdUp(); + folderView()->setPath(dir.absolutePath(), true); + updateActions(); + } +} + +void MainWindow::setPathToRoot() +{ + qDebug() << "MainWindow::setPathToRoot();"; + + folderView()->setPath(QDir::rootPath(), true); + updateActions(); +} + +void MainWindow::toggleSearchBox(bool checked) +{ + qDebug() << "MainWindow::toggleSearchBox" << checked; + + FolderView *v; + SearchBox *box; + + if (checked) { + v = folderView(); + if (v == ui->folderView1) { + box = ui->searchBox1; + } + else { + Q_ASSERT(v == ui->folderView2); + box = ui->searchBox2; + } + + box->setVisible(true); + box->setFocus(); + box->selectAll(); + } + else { + if (ui->searchBox1->isVisible()) { + box = ui->searchBox1; + v = ui->folderView1; + } + else { + Q_ASSERT(ui->searchBox2->isVisible()); + box = ui->searchBox2; + v = ui->folderView2; + } + + if (box->hasFocus()) { + v->setFocus(); + } + box->setVisible(false); + } +} + +void MainWindow::openRequest(const QFileInfo &info) +{ + m_focusedView = QApplication::focusWidget(); + + QFile file(info.absoluteFilePath()); + if (file.open(QIODevice::ReadOnly)) { + ui->splitter->setVisible(false); + ui->textView->setVisible(true); + ui->textView->setFocus(); + ui->textView->setSource(file.readAll()); + } + else { + QMessageBox::critical( + this, tr("エラー"), + tr("ファイルの読み込みに失敗しました。")); + } +} + +void MainWindow::showPreferenceDialog() +{ + qDebug() << "MainWindow::showPreferenceDialog"; + + PreferenceDialog dlg(this); + if (dlg.exec() == QDialog::Accepted) { + ui->locationBox1->updateAppearance(); + ui->locationBox2->updateAppearance(); + ui->folderView1->updateAppearance(); + ui->folderView2->updateAppearance(); + + updateActions(); + } +} + +void MainWindow::toggleShowHiddenFiles(bool checked) +{ + qDebug() << "MainWindow::toggleShowHiddenFiles" << checked; + + ui->folderView1->setFilter(QDir::Hidden, checked); + ui->folderView1->refresh(); + + ui->folderView2->setFilter(QDir::Hidden, checked); + ui->folderView2->refresh(); +} + +void MainWindow::toggleShowSystemFiles(bool checked) +{ + qDebug() << "MainWindow::toggleShowSystemFiles" << checked; + + ui->folderView1->setFilter(QDir::System, checked); + ui->folderView1->refresh(); + + ui->folderView2->setFilter(QDir::System, checked); + ui->folderView2->refresh(); +} + +void MainWindow::checkUpdate(bool silent) +{ + qDebug() << "MainWindow::checkUpdate()" << silent; + + QNetworkAccessManager *manager = new QNetworkAccessManager(this); + + if (silent) { + connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(checkUpdateFinishedSilent(QNetworkReply*))); + } + else { + connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(checkUpdateFinished(QNetworkReply*))); + } +#ifdef Q_OS_WIN + manager->get(QNetworkRequest(QUrl("http://miyabi.rakusaba.jp/wp-content/uploads/gefu_latest_win.html"))); +#elif defined(Q_OS_MAC) + manager->get(QNetworkRequest(QUrl("http://miyabi.rakusaba.jp/wp-content/uploads/gefu_latest_mac.html"))); +#endif +} + +void MainWindow::checkUpdateFinishedSilent(QNetworkReply *reply) +{ + qDebug() << "MainWindow::checkUpdateFinishedSilent"; + + checkUpdateFinished(reply, true); +} + +void MainWindow::checkUpdateFinished(QNetworkReply *reply, bool silent) +{ + qDebug() << "MainWindow::checkUpdateFinished" << silent; + + if (reply->error() == QNetworkReply::NoError) { + QString str = reply->readAll(); + str = str.split(QRegExp("[\r\n]"), QString::SkipEmptyParts).at(0); + QRegExp rx("Gefu([0-9]+)"); + rx.indexIn(str); + QString version = rx.cap(1); + if (version.toInt() > VERSION_VALUE * 100) { + QMessageBox::information( + this, tr("情報"), + tr("最新のバージョンが存在します。
") + + tr("こちらからダウンロードしてください。").arg(str)); + } + else if (!silent) { + QMessageBox::information( + this, tr("情報"), + tr("お使いのバージョンは最新です。")); + } + } + else if (!silent){ + QMessageBox::critical( + this, tr("エラー"), + tr("最新バージョンのチェックに失敗しました。
") + + reply->errorString()); + } +} + +void MainWindow::viewFinish(QWidget *sender) +{ + qDebug() << "MainWindow::viewFinish();" << sender->objectName(); + + sender->setVisible(false); + ui->splitter->setVisible(true); + m_focusedView->setFocus(); +} + + +void MainWindow::initActionConnections() +{ + qDebug() << "MainWindow::initActionConnections"; + + connect(ui->action_Command, SIGNAL(triggered()), this, SLOT(executeCommand())); + connect(ui->action_Exec, SIGNAL(triggered()), this, SLOT(shellExecute())); + connect(ui->action_Open, SIGNAL(triggered()), this, SLOT(open())); + connect(ui->action_OpenEditor, SIGNAL(triggered()), this, SLOT(openEditor())); + connect(ui->action_OpenTerminal, SIGNAL(triggered()), this, SLOT(openTerminal())); + connect(ui->action_Quit, SIGNAL(triggered()), this, SLOT(close())); + connect(ui->action_Search, SIGNAL(toggled(bool)), this, SLOT(toggleSearchBox(bool))); + connect(ui->action_SearchNext, SIGNAL(triggered()), this, SLOT(searchNext())); + connect(ui->action_SearchPrev, SIGNAL(triggered()), this, SLOT(searchPrev())); + connect(ui->action_Setting, SIGNAL(triggered()), this, SLOT(showPreferenceDialog())); + connect(ui->check_Update, SIGNAL(triggered()), this, SLOT(checkUpdate())); + connect(ui->cmd_Copy, SIGNAL(triggered()), this, SLOT(copyItems())); + connect(ui->cmd_Delete, SIGNAL(triggered()), this, SLOT(deleteItems())); + connect(ui->cmd_Move, SIGNAL(triggered()), this, SLOT(moveItems())); + connect(ui->cmd_NewFile, SIGNAL(triggered()), this, SLOT(createFile())); + connect(ui->cmd_NewFolder, SIGNAL(triggered()), this, SLOT(createFolder())); + connect(ui->cmd_Rename, SIGNAL(triggered()), this, SLOT(renameItems())); + connect(ui->copy_Filename, SIGNAL(triggered()), this, SLOT(copyFilenameToClipboard())); + connect(ui->copy_Fullpath, SIGNAL(triggered()), this, SLOT(copyFullpathTpClipboard())); + connect(ui->help_About, SIGNAL(triggered()), this, SLOT(about())); + connect(ui->mark_All, SIGNAL(triggered()), this, SLOT(markAll())); + connect(ui->mark_AllFiles, SIGNAL(triggered()), this, SLOT(markAllFiles())); + connect(ui->mark_AllOff, SIGNAL(triggered()), this, SLOT(markAllOff())); + connect(ui->mark_Invert, SIGNAL(triggered()), this, SLOT(markInvert())); + connect(ui->mark_Toggle, SIGNAL(triggered()), this, SLOT(markToggle())); + connect(ui->move_Back, SIGNAL(triggered()), this, SLOT(historyBack())); + connect(ui->move_Begin, SIGNAL(triggered()), this, SLOT(setCursorToBegin())); + connect(ui->move_Down, SIGNAL(triggered()), this, SLOT(cursorDown())); + connect(ui->move_End, SIGNAL(triggered()), this, SLOT(setCursorToEnd())); + connect(ui->move_Forward, SIGNAL(triggered()), this, SLOT(historyForward())); + connect(ui->move_History, SIGNAL(triggered()), this, SLOT(showHistoryDialog())); + connect(ui->move_Home, SIGNAL(triggered()), this, SLOT(setPathToHome())); + connect(ui->move_Jump, SIGNAL(triggered()), this, SLOT(chooseFolder())); + connect(ui->move_Parent, SIGNAL(triggered()), this, SLOT(setPathToParent())); + connect(ui->move_Root, SIGNAL(triggered()), this, SLOT(setPathToRoot())); + connect(ui->move_Up, SIGNAL(triggered()), this, SLOT(cursorUp())); + connect(ui->view_Filter, SIGNAL(triggered()), this, SLOT(showFilterDialog())); + connect(ui->view_FromOther, SIGNAL(triggered()), this, SLOT(setPathFromOther())); + connect(ui->view_Hidden, SIGNAL(toggled(bool)), this, SLOT(toggleShowHiddenFiles(bool))); + connect(ui->view_Refresh, SIGNAL(triggered()), this, SLOT(refresh())); + connect(ui->view_Sort, SIGNAL(triggered()), this, SLOT(showSortDialog())); + connect(ui->view_Swap, SIGNAL(triggered()), this, SLOT(swapView())); + connect(ui->view_System, SIGNAL(toggled(bool)), this, SLOT(toggleShowSystemFiles(bool))); + connect(ui->view_ToOther, SIGNAL(triggered()), this, SLOT(setPathToOther())); +} + +FolderView *MainWindow::folderView() const +{ + qDebug() << "MainWindow::folderView"; + + QWidget *w = qApp->focusWidget(); + if (w == ui->folderView1 || w == ui->searchBox1 || w == ui->locationBox1) { + return ui->folderView1; + } + if (w == ui->folderView2 || w == ui->searchBox2 || w == ui->locationBox2) { + return ui->folderView2; + } + + qDebug() << w->objectName(); + return NULL; +} + +void MainWindow::replaceVars(QString &str, const QFileInfo info) +{ + qDebug() << "MainWindow::replaceVars" << str; + + str.replace("$B", info.completeBaseName()); + str.replace("$E", info.suffix()); + str.replace("$F", info.fileName()); + if (info.isDir()) { + str.replace("$D", info.absoluteFilePath()); + } + else { + str.replace("$D", info.absolutePath()); + } + str.replace("$P", info.absoluteFilePath()); +} + +SearchBox *MainWindow::searchBox(FolderView *view) const +{ + qDebug() << "MainWindow::searchBox()" << view->objectName(); + + if (view == ui->folderView1) { + return ui->searchBox1; + } + else { + Q_ASSERT(view == ui->folderView2); + return ui->searchBox2; + } +} + +bool MainWindow::startProcess(const QString &cmd, const QString &workDir, const QString &errMsg) +{ + qDebug() << "MainWindow::startProcess" << cmd << workDir << errMsg; + + QProcess process(this); + process.setWorkingDirectory(workDir); + if (!process.startDetached(cmd)) { + QMessageBox::critical(this, tr("エラー"), errMsg + "
" + cmd); + return false; + } + return true; +} + +void MainWindow::updateActions() +{ + qDebug() << "MainWindow::updateActions"; + + if (ui->textView->hasFocus()) { + // テキストビューア時 + setEnabledAllActions(false); + ui->action_Quit->setEnabled(true); + ui->action_Setting->setEnabled(true); + ui->check_Update->setEnabled(true); + ui->copy_Filename->setEnabled(true); + ui->copy_Fullpath->setEnabled(true); + ui->help_About->setEnabled(true); + } + else if (ui->searchBox1->hasFocus() || ui->searchBox2->hasFocus()) { + // ファイル検索時 + setEnabledAllActions(false); + ui->action_Search->setEnabled(true); + ui->action_SearchNext->setEnabled(true); + ui->action_SearchPrev->setEnabled(true); + ui->help_About->setEnabled(true); + ui->action_Quit->setEnabled(true); + } + else if (ui->folderView1->hasFocus() || ui->folderView2->hasFocus()) { + // 通常時 + setEnabledAllActions(true); + ui->action_SearchNext->setEnabled(false); + ui->action_SearchPrev->setEnabled(false); + + ui->move_Back->setEnabled(!folderView()->history()->isBegin()); + ui->move_Forward->setEnabled(!folderView()->history()->isEnd()); + + QSettings settings; + ui->action_OpenEditor->setEnabled(!settings.value(IniKey_EditorPath).toString().isEmpty()); + ui->action_OpenTerminal->setEnabled(!settings.value(IniKey_TerminalPath).toString().isEmpty()); + } +} + +void MainWindow::setEnabledAllActions(bool enable) +{ + qDebug() << "MainWindow::setEnabledAllActions();" << enable; + foreach (QObject *obj, children()) { + QAction *action = qobject_cast(obj); + if (action) { + action->setEnabled(enable); + } + } +} + +void MainWindow::setNameFilters(FolderView *view, const QString &filters) +{ + qDebug() << "MainWindow::setNameFilters();" << view->objectName() << filters; + + QStringList list = filters.split(" ", QString::SkipEmptyParts); + if (list.isEmpty()) { + list << "*"; + } + view->setNameFilters(list); + filterLabel(view)->setText(tr("フィルタ:") + list.join(" ")); +} + +QLabel *MainWindow::filterLabel(const FolderView *view) const +{ + qDebug() << "MainWindow::filterLabel()" << view->objectName(); + if (view == ui->folderView1) { + return ui->filterLabel1; + } + else { + Q_ASSERT(view == ui->folderView2); + return ui->filterLabel2; + } +} + +void MainWindow::about() +{ + QMessageBox::about( + this, + tr("げふぅ について"), + tr("

Gefu Ver%1

").arg(VERSION_VALUE) + + tr("
Gefu is an Experimental File Utility.
" + "(げふぅは実験的なファイルユーティリティです)
" + "

最新版の情報は喫茶[雅]で公開しています。

" + "

Copyright 2014 @miyabi_satoh All rights reserved.

")); +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ + QSettings settings; + + if (settings.value(IniKey_ConfirmExit).toBool()) { + QMessageBox msgBox; + QCheckBox *checkBox = new QCheckBox(); + checkBox->setText(tr("次回以降は確認しない")); + msgBox.setCheckBox(checkBox); + msgBox.setText(tr("終了しますか?")); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setIcon(QMessageBox::Question); + + if (msgBox.exec() == QMessageBox::No) { + event->ignore(); + return; + } + settings.setValue(IniKey_ConfirmExit, !checkBox->isChecked()); + } + + settings.setValue(QString("Left/") + IniKey_Dir, ui->folderView1->dir()); + settings.setValue(QString("Right/") + IniKey_Dir, ui->folderView2->dir()); + settings.setValue(IniKey_ShowHidden, ui->view_Hidden->isChecked()); + settings.setValue(IniKey_ShowSystem, ui->view_System->isChecked()); + settings.setValue(IniKey_WindowGeometry, saveGeometry()); + settings.setValue(iniKey_WindowState, saveState()); + QMainWindow::closeEvent(event); +} + + +void MainWindow::keyPressEvent(QKeyEvent *event) +{ + QString ksq = KeyEventToSequence(event); + qDebug() << ksq << " @MainWindow"; + + QMainWindow::keyPressEvent(event); } diff --git a/mainwindow.h b/mainwindow.h index 7b29346..a2b21ee 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,15 +2,21 @@ #define MAINWINDOW_H #include +#include #include -class FolderPanel; -class FileTableView; class QNetworkReply; +class FolderView; +class SearchBox; +class OverWriteDialog; +class QLabel; namespace Ui { class MainWindow; } +/////////////////////////////////////////////////////////////////////////////// +/// \brief The MainWindow class +/// class MainWindow : public QMainWindow { Q_OBJECT @@ -19,33 +25,101 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); - FileTableView* otherSideView(const FileTableView *view) const; + FolderView *otherSideView(const FolderView *view) const; signals: void showHiddenFiles(bool show); void showSystemFiles(bool show); public slots: + void askOverWrite(QString *copyMethod, QString *alias, + const QString &srcPath, const QString &tgtPath); + + void focusChange(QWidget * old, QWidget * now); + void keyPress(FolderView *view, QKeyEvent *event); + void returnPressInSearchBox(); + + void chooseFolder(); + void copyFilenameToClipboard(); + void copyFullpathTpClipboard(); + void copyItems(); + void createFile(); + void createFolder(); + void cursorDown(); + void cursorUp(); + void deleteItems(); + void executeCommand(); + void historyBack(); + void historyForward(); + void itemFound(FolderView *view); + void itemNotFound(FolderView *view); + void markAll(); + void markAllFiles(); + void markAllOff(); + void markInvert(); + void markToggle(); + void moveItems(); + void open(const QModelIndex &index = QModelIndex()); + void openEditor(const QString &path = QString()); + void openTerminal(); + void refresh(); + void renameItems(); + void retrieveFinish(); + void retrieveStart(const QString &path); + void searchItem(const QString& text); + void searchNext(); + void searchPrev(); + void setCursorToBegin(); + void setCursorToEnd(); + void setPathFromOther(); + void setPathToHome(); + void setPathToOther(); + void setPathToParent(); + void setPathToRoot(); + void shellExecute(); + void showFilterDialog(); + void showHistoryDialog(); + void showSortDialog(); + void swapView(); + void toggleSearchBox(bool checked); + + + -private slots: void openRequest(const QFileInfo &info); void showPreferenceDialog(); void about(); - void toggleShowHiddenFiles(); - void toggleShowSystemFiles(); + void toggleShowHiddenFiles(bool checked); + void toggleShowSystemFiles(bool checked); void checkUpdate(bool silent = false); - void checkUpdateFinished(QNetworkReply *reply); - void checkUpdateFinished(QNetworkReply *reply, bool silent); + void checkUpdateFinished(QNetworkReply *reply, bool silent = false); void checkUpdateFinishedSilent(QNetworkReply *reply); void viewFinish(QWidget *sender); private: Ui::MainWindow *ui; QWidget *m_focusedView; + OverWriteDialog *m_overwriteDialog; + + // action + void initActionConnections(); + static void replaceVars(QString &str, const QFileInfo info); + bool startProcess(const QString &cmd, const QString &workDir, const QString &errMsg); + void updateActions(); + void setEnabledAllActions(bool enable); + void setNameFilters(FolderView *view, const QString& filters = QString()); + void setSorting(FolderView *view); + + // getter + QLabel* filterLabel(const FolderView *view) const; + FolderView* folderView() const; + SearchBox* searchBox(FolderView *view) const; + // QWidget interface protected: void closeEvent(QCloseEvent *event); + void keyPressEvent(QKeyEvent *event); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index e8d44b2..3457703 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,19 +6,19 @@ 0 0 - 665 - 337 + 828 + 531 MainWindow - + :/images/Gefu.png:/images/Gefu.png - + 0 @@ -39,26 +39,158 @@ Qt::Horizontal - - - - 0 - 0 - - + + + + 0 + + + + + Qt::ClickFocus + + + + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOff + + + false + + + true + + + QAbstractItemView::DragDrop + + + Qt::CopyAction + + + false + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + Qt::ElideMiddle + + + false + + + false + + + false + + + false + + + + + + + Qt::ClickFocus + + + + + + + TextLabel + + + + - - - - 0 - 0 - - + + + + 0 + + + + + Qt::ClickFocus + + + + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOff + + + false + + + true + + + QAbstractItemView::DragDrop + + + Qt::CopyAction + + + false + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + Qt::ElideMiddle + + + false + + + false + + + false + + + false + + + + + + + Qt::ClickFocus + + + + + + + TextLabel + + + + - + @@ -213,9 +345,9 @@ false - + - + @@ -245,7 +377,7 @@ 0 0 - 665 + 828 22 @@ -259,6 +391,10 @@ + + + + @@ -338,7 +474,7 @@ - + :/images/Exit.png:/images/Exit.png @@ -356,7 +492,7 @@ - + :/images/Open.png:/images/Open.png @@ -371,7 +507,7 @@ - + :/images/Play.png:/images/Play.png @@ -386,7 +522,7 @@ - + :/images/Synchronize.png:/images/Synchronize.png @@ -420,7 +556,7 @@ - + :/images/Ok.png:/images/Ok.png @@ -435,7 +571,7 @@ - + :/images/Check boxes.png:/images/Check boxes.png @@ -450,7 +586,7 @@ - + :/images/Cancel.png:/images/Cancel.png @@ -476,7 +612,7 @@ - + :/images/Text replace.png:/images/Text replace.png @@ -491,7 +627,7 @@ - + :/images/Settings.png:/images/Settings.png @@ -534,7 +670,7 @@ - + :/images/Go down.png:/images/Go down.png @@ -549,7 +685,7 @@ - + :/images/Go up.png:/images/Go up.png @@ -564,7 +700,7 @@ - + :/images/Back.png:/images/Back.png @@ -579,7 +715,7 @@ - + :/images/Forward.png:/images/Forward.png @@ -605,7 +741,7 @@ - + :/images/Up.png:/images/Up.png @@ -620,7 +756,7 @@ - + :/images/Monitor.png:/images/Monitor.png @@ -635,7 +771,7 @@ - + :/images/Folder.png:/images/Folder.png @@ -650,7 +786,7 @@ - + :/images/Home.png:/images/Home.png @@ -687,7 +823,7 @@ - + :/images/Edit page.png:/images/Edit page.png @@ -702,7 +838,7 @@ - + :/images/Export.png:/images/Export.png @@ -717,7 +853,7 @@ - + :/images/Copy.png:/images/Copy.png @@ -732,7 +868,7 @@ - + :/images/Paste.png:/images/Paste.png @@ -744,7 +880,7 @@ - + :/images/Delete.png:/images/Delete.png @@ -759,7 +895,7 @@ - + :/images/Rename.png:/images/Rename.png @@ -774,7 +910,7 @@ - + :/images/New file.png:/images/New file.png @@ -789,7 +925,7 @@ - + :/images/Add folder.png:/images/Add folder.png @@ -804,7 +940,7 @@ - + :/images/Help.png:/images/Help.png @@ -836,7 +972,7 @@ - + :/images/Refresh.png:/images/Refresh.png @@ -862,7 +998,7 @@ - + :/images/Funnel.png:/images/Funnel.png @@ -908,21 +1044,72 @@ Shift+C + + + true + + + + :/images/Search.png:/images/Search.png + + + 検索 + + + 検索 + + + / + + + + + 次を検索 + + + 次を検索 + + + Return + + + + + 前を検索 + + + 前を検索 + + + Shift+Return + + - FolderPanel - QWidget -
folderpanel.h
- 1 -
- SimpleTextView QPlainTextEdit
simpletextview.h
+ + SearchBox + QLineEdit +
searchbox.h
+
+ + FolderView + QTableView +
folderview.h
+
+ + LocationBox + QLineEdit +
locationbox.h
+
- + + + diff --git a/overwritedialog.cpp b/overwritedialog.cpp index 55899f5..b5dc44e 100644 --- a/overwritedialog.cpp +++ b/overwritedialog.cpp @@ -1,8 +1,11 @@ +#include "common.h" #include "overwritedialog.h" #include "ui_overwritedialog.h" + #include #include #include +#include OverWriteDialog::OverWriteDialog(QWidget *parent) : QDialog(parent), @@ -11,15 +14,15 @@ OverWriteDialog::OverWriteDialog(QWidget *parent) : { ui->setupUi(this); - ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); - ui->tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); + QHeaderView *header = ui->tableWidget->horizontalHeader(); + header->setSectionResizeMode(QHeaderView::ResizeToContents); + header->setSectionResizeMode(0, QHeaderView::Stretch); connect(ui->rbAppendNumber, SIGNAL(clicked()), this, SLOT(onRenameOrElse())); connect(ui->rbOverWrite, SIGNAL(clicked()), this, SLOT(onRenameOrElse())); connect(ui->rbOverWriteIfNew, SIGNAL(clicked()), this, SLOT(onRenameOrElse())); connect(ui->rbRename, SIGNAL(clicked()), this, SLOT(onRenameOrElse())); connect(ui->rbSkip, SIGNAL(clicked()), this, SLOT(onRenameOrElse())); - } OverWriteDialog::~OverWriteDialog() @@ -27,32 +30,17 @@ OverWriteDialog::~OverWriteDialog() delete ui; } -void OverWriteDialog::setCopyMethod(int method) +void OverWriteDialog::reset() { - switch (method) { - case OverWriteDialog::OverWrite: - ui->rbOverWrite->setChecked(true); - break; - case OverWriteDialog::AppendNumber: - ui->rbAppendNumber->setChecked(true); - break; - case OverWriteDialog::Skip: - ui->rbSkip->setChecked(true); - break; - case OverWriteDialog::Rename: - ui->rbRename->setChecked(true); - ui->lineEdit->setFocus(); - break; - default: - ui->rbOverWriteIfNew->setChecked(true); - break; + QSettings settings; + QString method = settings.value(IniKey_DefaultOnCopy).toString(); + QRadioButton *radio = findChild(method); + if (radio == NULL) { + radio = ui->rbOverWriteIfNew; } - onRenameOrElse(); -} + radio->setChecked(true); -void OverWriteDialog::setSameMethodChecked(bool checked) -{ - ui->checkBox->setChecked(checked); + ui->keepSetting->setChecked(false); } void OverWriteDialog::setFileInfo(const QString srcPath, const QString tgtPath) @@ -62,50 +50,48 @@ void OverWriteDialog::setFileInfo(const QString srcPath, const QString tgtPath) m_tgtPath = tgtPath; ui->lineEdit->setText(tgtInfo.fileName()); + QTableWidgetItem *iSrcName = new QTableWidgetItem(srcInfo.fileName()); + iSrcName->setFlags(iSrcName->flags() ^ Qt::ItemIsEditable); + iSrcName->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); + ui->tableWidget->setItem(0, 0, iSrcName); + + QTableWidgetItem *iTgtName = new QTableWidgetItem(tgtInfo.fileName()); + iTgtName->setFlags(iTgtName->flags() ^ Qt::ItemIsEditable); + iTgtName->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); + ui->tableWidget->setItem(0, 0, iTgtName); + QTableWidgetItem *iSrcSize = new QTableWidgetItem(tr("%1 Bytes").arg(srcInfo.size())); iSrcSize->setFlags(iSrcSize->flags() ^ Qt::ItemIsEditable); iSrcSize->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); - ui->tableWidget->setItem(0, 0, iSrcSize); + ui->tableWidget->setItem(0, 1, iSrcSize); QTableWidgetItem *iTgtSize = new QTableWidgetItem(tr("%1 Bytes").arg(tgtInfo.size())); iTgtSize->setFlags(iTgtSize->flags() ^ Qt::ItemIsEditable); iTgtSize->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); - ui->tableWidget->setItem(1, 0, iTgtSize); + ui->tableWidget->setItem(1, 1, iTgtSize); QTableWidgetItem *iSrcDate = new QTableWidgetItem(srcInfo.lastModified().toString("yy/MM/dd hh:mm")); iSrcDate->setFlags(iSrcDate->flags() ^ Qt::ItemIsEditable); iSrcDate->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); - ui->tableWidget->setItem(0, 1, iSrcDate); + ui->tableWidget->setItem(0, 2, iSrcDate); QTableWidgetItem *iTgtDate = new QTableWidgetItem(tgtInfo.lastModified().toString("yy/MM/dd hh:mm")); iTgtDate->setFlags(iTgtDate->flags() ^ Qt::ItemIsEditable); iTgtDate->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); - ui->tableWidget->setItem(1, 1, iTgtDate); + ui->tableWidget->setItem(1, 2, iTgtDate); } -int OverWriteDialog::copyMethod() +QString OverWriteDialog::copyMethod() const { - if (ui->rbAppendNumber->isChecked()) { - return OverWriteDialog::AppendNumber; - } - if (ui->rbOverWrite->isChecked()) { - return OverWriteDialog::OverWrite; - } - if (ui->rbOverWriteIfNew->isChecked()) { - return OverWriteDialog::OverWriteIfNew; - } - if (ui->rbRename->isChecked()) { - return OverWriteDialog::Rename; - } - return OverWriteDialog::Skip; + return ui->method->checkedButton()->objectName(); } -bool OverWriteDialog::isSameMethodChecked() +bool OverWriteDialog::isKeepSetting() const { - return ui->checkBox->isChecked(); + return ui->keepSetting->isChecked(); } -const QString OverWriteDialog::alias() +const QString OverWriteDialog::alias() const { return ui->lineEdit->text(); } diff --git a/overwritedialog.h b/overwritedialog.h index e481d8c..6cdef3b 100644 --- a/overwritedialog.h +++ b/overwritedialog.h @@ -13,25 +13,18 @@ class OverWriteDialog : public QDialog Q_OBJECT public: - enum { - Undefined = 0x00, - OverWrite = 0x01, - OverWriteIfNew = 0x02, - AppendNumber = 0x04, - Skip = 0x08, - Rename = 0x10, - }; - explicit OverWriteDialog(QWidget *parent = 0); ~OverWriteDialog(); - void setCopyMethod(int method); - void setSameMethodChecked(bool checked); + void reset(); + + // setter void setFileInfo(const QString srcPath, const QString tgtPath); - int copyMethod(); - bool isSameMethodChecked(); - const QString alias(); + // getter + QString copyMethod() const; + bool isKeepSetting() const; + const QString alias() const; private slots: void onRenameOrElse(); diff --git a/overwritedialog.ui b/overwritedialog.ui index 19c0af1..7707349 100644 --- a/overwritedialog.ui +++ b/overwritedialog.ui @@ -53,7 +53,7 @@ 2 - 2 + 3 false @@ -73,6 +73,11 @@ + ファイル名 + + + + サイズ @@ -100,6 +105,9 @@ 上書き + + method + @@ -110,6 +118,9 @@ 新しければ上書き + + method + @@ -120,6 +131,9 @@ スキップ + + method + @@ -130,6 +144,9 @@ ファイル名末尾に数字を付与 + + method + @@ -140,6 +157,9 @@ 名前を変更 + + method + @@ -171,7 +191,7 @@ - + Qt::StrongFocus @@ -232,4 +252,7 @@ + + + diff --git a/preferencedialog.cpp b/preferencedialog.cpp index b0e2fc6..d050b10 100644 --- a/preferencedialog.cpp +++ b/preferencedialog.cpp @@ -137,7 +137,7 @@ PreferenceDialog::PreferenceDialog(QWidget *parent) : } radioBtn = findChild(strValue); if (radioBtn == NULL) { - radioBtn = ui->owDefIfNew; + radioBtn = ui->rbOverWriteIfNew; } radioBtn->setChecked(true); ui->moveAfterCreate->setChecked(settings.value(IniKey_MoveAfterCreateFolder).toBool()); diff --git a/preferencedialog.ui b/preferencedialog.ui index 3c45e8e..7860251 100644 --- a/preferencedialog.ui +++ b/preferencedialog.ui @@ -7,7 +7,7 @@ 0 0 549 - 478 + 524 @@ -17,7 +17,7 @@ - Dialog + 環境設定 @@ -26,775 +26,516 @@ Qt::StrongFocus - 4 + 2 起動と終了 - + - 4 - - - 4 - - - 4 - - - 4 - - - 4 + -1 - - - Qt::StrongFocus - - - 起動時のウィンドウサイズを指定する - - - - - + - 4 + -1 - - QLayout::SetFixedSize - - - 4 - - - 4 - - - 4 - - - 4 - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - + Qt::StrongFocus - 絶対指定 + 起動時のウィンドウサイズを指定する - - sizeOptions - - - - 4 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - 幅 - - - - - - - 9999 - - - - - - - px - - - - - - - + - 4 + -1 - - 4 - - - 4 - - - 4 - - - 4 - - - - - 高さ - - - - - - - 9999 - - - - - - - px - - - - + Qt::Horizontal + + QSizePolicy::Fixed + - 40 + 10 20 - - - - - - - - 4 - - - QLayout::SetMinimumSize - - - 4 - - - 4 - - - 4 - - - 4 - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - Qt::StrongFocus - - - 相対指定 - - - sizeOptions - - - - - - - 4 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - 幅 - - - - - - 100 + + + -1 - - - - - - % - - - - - - - - - 4 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - 高さ - - - - - - - 100 - - - - - - - % - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - 4 - - - QLayout::SetMinimumSize - - - 4 - - - 4 - - - 4 - - - 4 - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - Qt::StrongFocus - - - 前回終了時のサイズ - - - sizeOptions - - - - - - - - - Qt::StrongFocus - - - 起動時のウィンドウ位置を指定する - - - - - - - 4 - - - QLayout::SetFixedSize - - - 4 - - - 4 - - - 4 - - - 4 - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - Qt::StrongFocus - - - 絶対指定 - - - posOptions - - - - - - - 4 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - X - - - - - - - 9999 - - - - - - - px - - - - - - - - - 4 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - Y - - - - - - - 9999 - - - - - - - px - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 4 - - - QLayout::SetMinimumSize - - - 4 - - - 4 - - - 4 - - - 4 - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - + + + + + 0 + 24 + + + + Qt::StrongFocus + + + 絶対指定 + + + sizeOptions + + + + + + + + + 幅 + + + + + + + 9999 + + + + + + + px + + + + + + + + + + + 高さ + + + + + + + 9999 + + + + + + + px + + + + + + + + + + 0 + 0 + + + + + 0 + 24 + + + + Qt::StrongFocus + + + 相対指定 + + + sizeOptions + + + + + + + + + 幅 + + + + + + + 100 + + + + + + + % + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + + + 高さ + + + + + + + 100 + + + + + + + % + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + + 0 + 24 + + + + Qt::StrongFocus + + + 前回終了時のサイズ + + + sizeOptions + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + - + Qt::StrongFocus - 相対指定 + 起動時のウィンドウ位置を指定する - - posOptions - - - 4 - - - 4 - - - 4 - - - 4 - - - 4 - - - - X + + + Qt::Horizontal - - - - - - 100 + + QSizePolicy::Fixed - - - - - - % + + + 10 + 20 + - + - - - - - - 4 - - - 4 - - - 4 - - - 4 - - - 4 - - - - Y - - + + + + + + 0 + 24 + + + + Qt::StrongFocus + + + 絶対指定 + + + posOptions + + + + + + + + + X + + + + + + + 9999 + + + + + + + px + + + + + + + + + + + Y + + + + + + + 9999 + + + + + + + px + + + + + + + + + + 0 + 24 + + + + Qt::StrongFocus + + + 相対指定 + + + posOptions + + + + + + + + + X + + + + + + + 100 + + + + + + + % + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + + + Y + + + + + + + 100 + + + + + + + % + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + + 0 + 24 + + + + Qt::StrongFocus + + + 画面中央 + + + posOptions + + + + + + + + 0 + 24 + + + + Qt::StrongFocus + + + 前回終了時の位置 + + + posOptions + + + + - - - 100 + + + Qt::Horizontal - - - - - - % + + + 40 + 20 + - + - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - 4 - - - QLayout::SetMinimumSize - - - 4 - - - 4 - - - 4 - - - 4 - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - Qt::StrongFocus - - - 画面中央 - - - posOptions - - - - - - - - - 4 - - - QLayout::SetMinimumSize - - - 4 - - - 4 - - - 4 - - - 4 - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - Qt::StrongFocus - - - 前回終了時の位置 - - - posOptions - - - @@ -803,7 +544,7 @@ Qt::StrongFocus - 起動時に最新バージョンをチェックする。 + 起動時に最新バージョンをチェックする @@ -835,7 +576,7 @@ 20 - 1 + 45 @@ -1288,13 +1029,13 @@ - + ファイル操作 - 4 + -1 4 @@ -1315,7 +1056,7 @@ - 4 + -1 4 @@ -1392,7 +1133,7 @@ - 4 + -1 4 @@ -1481,10 +1222,10 @@ 4 - 4 + -1 - + Qt::StrongFocus @@ -1497,7 +1238,7 @@ - + Qt::StrongFocus @@ -1510,7 +1251,7 @@ - + Qt::StrongFocus @@ -1523,7 +1264,7 @@ - + Qt::StrongFocus @@ -1536,7 +1277,7 @@ - + Qt::StrongFocus @@ -1586,7 +1327,7 @@ - + パス設定 @@ -1835,7 +1576,7 @@ $P ... フルパス($D/$Fと同じ) optExplain - + テキストビューア @@ -2163,14 +1904,12 @@ ABCDEFGHIJKLMNOPQRSTUVWXYZ - tabWidget bootSize sizeAbsolute absoluteWidth absoluteHeight sizeRelative relativeWidth - relativeHeight sizeLast bootPos posAbsolute @@ -2178,7 +1917,6 @@ ABCDEFGHIJKLMNOPQRSTUVWXYZ absoluteTop posRelative relativeLeft - relativeTop posCenter posLast resetOnBoot @@ -2205,11 +1943,11 @@ ABCDEFGHIJKLMNOPQRSTUVWXYZ autoCloseMove autoCloseDelete autoCloseRename - owDefOverWrite - owDefIfNew - owDefSkip - owDefAppendNumber - owDefRename + rbOverWrite + rbOverWriteIfNew + rbSkip + rbAppendNumber + rbRename moveAfterCreate openAfterCreate editorPath @@ -2239,8 +1977,8 @@ ABCDEFGHIJKLMNOPQRSTUVWXYZ accept() - 248 - 254 + 254 + 473 157 @@ -2255,8 +1993,8 @@ ABCDEFGHIJKLMNOPQRSTUVWXYZ reject() - 316 - 260 + 322 + 473 286 @@ -2266,8 +2004,8 @@ ABCDEFGHIJKLMNOPQRSTUVWXYZ - + diff --git a/searchbox.cpp b/searchbox.cpp index 4748908..b78565f 100644 --- a/searchbox.cpp +++ b/searchbox.cpp @@ -1,6 +1,63 @@ +#include "common.h" +#include "mainwindow.h" #include "searchbox.h" +#include +#include +#include +#include + SearchBox::SearchBox(QWidget *parent) : QLineEdit(parent) { } + +void SearchBox::itemFound() +{ + QPalette palette = this->palette(); + palette.setColor(QPalette::Text, Qt::black); + setPalette(palette); +} + +void SearchBox::itemNotFound() +{ + QPalette palette = this->palette(); + palette.setColor(QPalette::Text, Qt::red); + setPalette(palette); +} + +void SearchBox::keyPressEvent(QKeyEvent *event) +{ +#if 0 + QString ksq = KeyEventToSequence(event); + + if (ksq == "/") { + QAction *action = getMainWnd()->findChild("action_Search"); + action->toggle(); + event->accept(); + return; + } + + QString textBefore = text(); + QLineEdit::keyPressEvent(event); + + + if (ksq == "Shift+Return"){ + qDebug() << ksq; + emit getMainWnd()->findChild("action_SearchPrev")->triggered(); + } + else if (ksq.indexOf("Return") != -1) { + qDebug() << ksq; + emit getMainWnd()->findChild("action_SearchNext")->triggered(); + } + else if (textBefore != text()) { + emit searchItem(text()); + } + else { + qDebug() << ksq; + } +#endif + + QLineEdit::keyPressEvent(event); + +} diff --git a/searchbox.h b/searchbox.h index d397e62..0f901df 100644 --- a/searchbox.h +++ b/searchbox.h @@ -10,9 +10,19 @@ public: explicit SearchBox(QWidget *parent = 0); signals: + void searchItem(const QString &text); + void searchNext(const QString &text); + void searchPrev(const QString &next); + +private slots: + void itemFound(); + void itemNotFound(); public slots: + // QWidget interface +protected: + void keyPressEvent(QKeyEvent *event); }; #endif // SEARCHBOX_H diff --git a/simpletextview.cpp b/simpletextview.cpp index 8b2815e..bd105d7 100644 --- a/simpletextview.cpp +++ b/simpletextview.cpp @@ -9,6 +9,18 @@ #include #include +QString KeyEventToSequence(const QKeyEvent *event) +{ + QString modifier = QString::null; + if (event->modifiers() & Qt::ShiftModifier) { modifier += "Shift+"; } + if (event->modifiers() & Qt::ControlModifier) { modifier += "Ctrl+"; } + if (event->modifiers() & Qt::AltModifier) { modifier += "Alt+"; } + if (event->modifiers() & Qt::MetaModifier) { modifier += "Meta+"; } + + QString key = QKeySequence(event->key()).toString(); + return QKeySequence(modifier + key).toString(); +} + SimpleTextView::SimpleTextView(QWidget *parent) : QPlainTextEdit(parent), m_convEUC(NULL), @@ -313,14 +325,7 @@ void SimpleTextView::back() void SimpleTextView::keyPressEvent(QKeyEvent *event) { - QString modifier = QString::null; - if (event->modifiers() & Qt::ShiftModifier) { modifier += "Shift+"; } - if (event->modifiers() & Qt::ControlModifier) { modifier += "Ctrl+"; } - if (event->modifiers() & Qt::AltModifier) { modifier += "Alt+"; } - if (event->modifiers() & Qt::MetaModifier) { modifier += "Meta+"; } - - QString key = QKeySequence(event->key()).toString(); - QString ksq = QKeySequence(modifier + key).toString(); + QString ksq = KeyEventToSequence(event); if (ksq == "Return" || ksq == "Backspace" || ksq == "W") { emit viewFinished(this); -- 2.11.0