OSDN Git Service

TableView-Modelに変更(高速化)
authorMasayuki Satoh <miyabi.satoh@gmail.com>
Wed, 20 Aug 2014 05:08:23 +0000 (14:08 +0900)
committerMasayuki Satoh <miyabi.satoh@gmail.com>
Wed, 20 Aug 2014 05:08:23 +0000 (14:08 +0900)
12 files changed:
common.h
copymoveworker.cpp
copymoveworker.h
deleteworker.cpp
filetablemodel.cpp
filetableview.cpp
filetableview.h
folderpanel.cpp
folderpanel.h
folderpanel.ui
mainwindow.cpp
mainwindow.h

index 56c37db..6c75f95 100644 (file)
--- a/common.h
+++ b/common.h
@@ -1,18 +1,14 @@
 #ifndef COMMON_H\r
 #define COMMON_H\r
 \r
-#include <QString>\r
 #include <QMap>\r
-\r
 typedef QMap<QString, QString> StringMap;\r
 \r
 class MainWindow;\r
 extern MainWindow* getMainWnd();\r
-\r
 extern QString FilesizeToString(quint64 size);\r
 \r
-#define VERSION_STRING  "0.01"\r
-#define VERSION_VALUE   0.01\r
+#define VERSION_VALUE   0.02\r
 \r
 #define slash   QString("/")\r
 #define QQ(x)   ("\"" + (x) + "\"")\r
index 27dee16..972e435 100644 (file)
@@ -26,12 +26,12 @@ void CopyMoveWorker::operate()
         m_progressText->setText(tr("コピー準備中..."));\r
     }\r
 \r
-    foreach (const QString &srcPath, *m_CopyList) {\r
+    foreach (const QFileInfo &info, *m_CopyList) {\r
         if (isStopRequested()) {\r
             emit canceled();\r
             return;\r
         }\r
-        Listup(srcPath, m_tgtDir);\r
+        Listup(info.absoluteFilePath(), m_tgtDir);\r
     }\r
 \r
     bool ret;\r
index df89af0..ade7f6a 100644 (file)
@@ -5,6 +5,7 @@
 #include "iworker.h"\r
 \r
 #include <QFileInfo>\r
+#include <QMap>\r
 \r
 class CopyMoveWorker : public IWorker\r
 {\r
@@ -12,7 +13,7 @@ class CopyMoveWorker : public IWorker
 public:\r
     explicit CopyMoveWorker(QObject *parent = 0);\r
 \r
-    void setCopyList(const QStringList *list) {\r
+    void setCopyList(const QFileInfoList *list) {\r
         m_CopyList = list;\r
     }\r
     void setTargetDir(const QString &path) {\r
@@ -29,13 +30,13 @@ public:
 \r
 signals:\r
     void askOverWrite(bool *bOk, int *prevCopyMethod, int *copyMethod, QString *alias,\r
-                      const QString srcPath, const QString tgtPath);\r
+                      const QString &srcPath, const QString &tgtPath);\r
 \r
 public slots:\r
     void operate();\r
 \r
 private:\r
-    const QStringList *m_CopyList;\r
+    const QFileInfoList *m_CopyList;\r
     QString m_tgtDir;\r
     StringMap m_CopyMap;\r
     QMutex m_AskingMutex;\r
index 0291108..d4b0232 100644 (file)
@@ -19,7 +19,7 @@ void DeleteWorker::operate()
             emit canceled();\r
             return;\r
         }\r
-        Listup(info.absolutePath());\r
+        Listup(info.absoluteFilePath());\r
     }\r
 \r
     bool ret;\r
index 834a046..3ccfa68 100644 (file)
@@ -3,6 +3,7 @@
 \r
 #include <QDateTime>\r
 #include <QDebug>\r
+#include <QBrush>\r
 #ifdef Q_OS_WIN32\r
     #include <windows.h>\r
 #endif\r
@@ -85,7 +86,16 @@ Qt::CheckState FileTableModel::checkState(const QModelIndex &index) const
 \r
 void FileTableModel::setCheckState(const QModelIndex &index, Qt::CheckState state)\r
 {\r
+    beginResetModel();\r
     m_checkStates[index.row()] = state;\r
+    if (state == Qt::Checked && index.row() == 0 &&\r
+        m_fileInfoList[0].fileName() == "..")\r
+    {\r
+        m_checkStates[0] = Qt::Unchecked;\r
+    }\r
+    endResetModel();;\r
+    emit dataChanged(index, this->index(index.row(), 3));\r
+\r
     stateChanged();\r
 }\r
 \r
@@ -93,6 +103,11 @@ void FileTableModel::setCheckStateAll(Qt::CheckState state)
 {\r
     beginResetModel();\r
     m_checkStates.fill(state);\r
+    if (state == Qt::Checked && m_fileInfoList.size() > 1 &&\r
+        m_fileInfoList[0].fileName() == "..")\r
+    {\r
+        m_checkStates[0] = Qt::Unchecked;\r
+    }\r
     endResetModel();\r
 \r
     stateChanged();\r
@@ -211,6 +226,18 @@ QVariant FileTableModel::data(const QModelIndex &index, int role) const
         }\r
         break;\r
 \r
+    case Qt::BackgroundRole:\r
+        if (checked) {\r
+            return QBrush(QColor(0, 196, 0));\r
+        }\r
+        break;\r
+\r
+    case Qt::ForegroundRole:\r
+        if (checked) {\r
+            return QBrush(QColor(196, 0, 0));\r
+        }\r
+        break;\r
+\r
     case Qt::CheckStateRole:\r
         if (index.column() == 0 && info.fileName() != "..") {\r
             return checked;\r
@@ -248,10 +275,15 @@ Qt::ItemFlags FileTableModel::flags(const QModelIndex &index) const
 \r
 bool FileTableModel::setData(const QModelIndex &index, const QVariant &value, int role)\r
 {\r
+    if (!index.isValid()) {\r
+        return false;\r
+    }\r
+\r
     switch (role) {\r
     case Qt::CheckStateRole:\r
         if (index.column() == 0) {\r
             m_checkStates[index.row()] = static_cast<Qt::CheckState>(value.toInt());\r
+            emit dataChanged(index, this->index(index.row(), 3));\r
             stateChanged();\r
             return true;\r
         }\r
index d388ad8..24b5170 100644 (file)
@@ -1,9 +1,11 @@
 #include "common.h"\r
+#include "copymoveworker.h"\r
 #include "deleteworker.h"\r
 #include "filetablemodel.h"\r
 #include "filetableview.h"\r
 #include "mainwindow.h"\r
 #include "operationdialog.h"\r
+#include "overwritedialog.h"\r
 #include "renamemultidialog.h"\r
 #include "renamesingledialog.h"\r
 #include "renameworker.h"\r
@@ -44,8 +46,9 @@ FileTableView::FileTableView(QWidget *parent) :
     connect(MENU_TRRIGGERED(mark_AllOff), this, SLOT(uncheckAllItems()));\r
     connect(MENU_TRRIGGERED(mark_Invert), this, SLOT(invertAllChecked()));\r
 \r
-    connect(MENU_TOGGLED(view_Hidden), this, SLOT(showHiddenFiles(bool)));\r
-    connect(MENU_TOGGLED(view_System), this, SLOT(showSystemFiles(bool)));\r
+    connect(MENU_TRRIGGERED(view_FromOther), this, SLOT(setPathFromOther()));\r
+    connect(MENU_TRRIGGERED(view_ToOther), this, SLOT(setPathToOther()));\r
+    connect(MENU_TRRIGGERED(view_Swap), this, SLOT(swapPath()));\r
     connect(MENU_TRRIGGERED(view_Sort), this, SLOT(setSort()));\r
 \r
     connect(MENU_TRRIGGERED(move_Back), this, SLOT(back()));\r
@@ -60,15 +63,33 @@ FileTableView::FileTableView(QWidget *parent) :
     connect(MENU_TRRIGGERED(move_Begin), this, SLOT(cursorToBegin()));\r
     connect(MENU_TRRIGGERED(move_End), this, SLOT(cursorToEnd()));\r
 \r
+    connect(MENU_TRRIGGERED(cmd_Copy), this, SLOT(cmdCopy()));\r
+    connect(MENU_TRRIGGERED(cmd_Move), this, SLOT(cmdMove()));\r
     connect(MENU_TRRIGGERED(cmd_Delete), this, SLOT(cmdDelete()));\r
     connect(MENU_TRRIGGERED(cmd_Rename), this, SLOT(cmdRename()));\r
     connect(MENU_TRRIGGERED(cmd_NewFile), this, SLOT(newFile()));\r
     connect(MENU_TRRIGGERED(cmd_NewFolder), this, SLOT(newFolder()));\r
 \r
+    connect(getMainWnd(), SIGNAL(showHiddenFiles(bool)),\r
+            this, SLOT(showHiddenFiles(bool)));\r
+    connect(getMainWnd(), SIGNAL(showSystemFiles(bool)),\r
+            this, SLOT(showSystemFiles(bool)));\r
+\r
     connect(this, SIGNAL(doubleClicked(QModelIndex)),\r
             this, SLOT(setRootIndex(QModelIndex)));\r
 \r
+    connect(this, SIGNAL(indexChanged(QString)),\r
+            getMainWnd(), SLOT(setStatusText(QString)));\r
 }\r
+\r
+FileTableView::~FileTableView()\r
+{\r
+    QSettings settings;\r
+    FileTableModel *m = static_cast<FileTableModel*>(model());\r
+\r
+    settings.setValue(side() + slash + IniKey_Dir, m->absolutePath());\r
+}\r
+\r
 QString FileTableView::side() const\r
 {\r
     return m_side;\r
@@ -79,6 +100,18 @@ void FileTableView::setSide(const QString &side)
     m_side = side;\r
 }\r
 \r
+void FileTableView::setRootPath(const QString &path)\r
+{\r
+    FileTableModel *m = static_cast<FileTableModel*>(model());\r
+    QFileInfo info(path);\r
+    if (info.isDir()) {\r
+        setUpdatesEnabled(false);\r
+        m->setPath(info.absoluteFilePath());\r
+        setUpdatesEnabled(true);\r
+\r
+        setCurrentIndex(m->index(0, 0));\r
+    }\r
+}\r
 \r
 QFileInfoList FileTableView::selectedItems() const\r
 {\r
@@ -154,6 +187,12 @@ void FileTableView::toggleChecked()
     FileTableModel *m = static_cast<FileTableModel*>(model());\r
 \r
     QModelIndex index = currentIndex();\r
+\r
+    qDebug() << "row = " << index.row();\r
+    qDebug() << "rowCount = " << m->rowCount();\r
+\r
+\r
+\r
     QFileInfo info = m->fileInfo(index);\r
     if (info.fileName() != "..") {\r
         if (m->checkState(index) == Qt::Checked) {\r
@@ -162,10 +201,13 @@ void FileTableView::toggleChecked()
         else {\r
             m->setCheckState(index, Qt::Checked);\r
         }\r
-        update(index);\r
     }\r
     // 最終行でなければ、次のアイテムに移動する\r
-    if (index.row() < m->rowCount() - 1) {\r
+    if (index.row() == m->rowCount() - 1) {\r
+        setCurrentIndex(index);\r
+    }\r
+    else if (index.row() < m->rowCount() - 1) {\r
+        qDebug() << "set = " << index.row() + 1;\r
         setCurrentIndex(m->index(index.row() + 1, 1));\r
     }\r
 }\r
@@ -174,16 +216,19 @@ void FileTableView::checkAllItems()
 {\r
     CHECK_FOCUS;\r
 \r
+    QModelIndex index = currentIndex();\r
     FileTableModel *m = static_cast<FileTableModel*>(model());\r
     setUpdatesEnabled(false);\r
     m->setCheckStateAll(Qt::Checked);\r
     setUpdatesEnabled(true);\r
+    setCurrentIndex(index);\r
 }\r
 \r
 void FileTableView::checkAllFiles()\r
 {\r
     CHECK_FOCUS;\r
 \r
+    QModelIndex index = currentIndex();\r
     FileTableModel *m = static_cast<FileTableModel*>(model());\r
     setUpdatesEnabled(false);\r
     for (int n = 0; n < m->rowCount(); n++) {\r
@@ -198,22 +243,26 @@ void FileTableView::checkAllFiles()
         update(index);\r
     }\r
     setUpdatesEnabled(true);\r
+    setCurrentIndex(index);\r
 }\r
 \r
 void FileTableView::uncheckAllItems()\r
 {\r
     CHECK_FOCUS;\r
 \r
+    QModelIndex index = currentIndex();\r
     FileTableModel *m = static_cast<FileTableModel*>(model());\r
     setUpdatesEnabled(false);\r
     m->setCheckStateAll(Qt::Unchecked);\r
     setUpdatesEnabled(true);\r
+    setCurrentIndex(index);\r
 }\r
 \r
 void FileTableView::invertAllChecked()\r
 {\r
     CHECK_FOCUS;\r
 \r
+    QModelIndex index = currentIndex();\r
     FileTableModel *m = static_cast<FileTableModel*>(model());\r
     setUpdatesEnabled(false);\r
     for (int n = 0; n < m->rowCount(); n++) {\r
@@ -227,12 +276,59 @@ void FileTableView::invertAllChecked()
         update(index);\r
     }\r
     setUpdatesEnabled(true);\r
+    setCurrentIndex(index);\r
 }\r
 \r
-void FileTableView::showHiddenFiles(bool show)\r
+void FileTableView::setPathFromOther()\r
 {\r
+    CHECK_FOCUS;\r
+\r
+    FileTableView *other = getMainWnd()->otherSideView(this);\r
+    if (other == NULL) {\r
+        return;\r
+    }\r
+\r
+    FileTableModel *mOther = static_cast<FileTableModel*>(other->model());\r
+\r
+    setRootPath(mOther->absolutePath());\r
+}\r
+\r
+void FileTableView::setPathToOther()\r
+{\r
+    CHECK_FOCUS;\r
+\r
+    FileTableView *other = getMainWnd()->otherSideView(this);\r
+    if (other == NULL) {\r
+        return;\r
+    }\r
+\r
+    FileTableModel *m = static_cast<FileTableModel*>(model());\r
+\r
+    other->setRootPath(m->absolutePath());\r
+}\r
+\r
+void FileTableView::swapPath()\r
+{\r
+    CHECK_FOCUS;\r
+\r
+    FileTableView *other = getMainWnd()->otherSideView(this);\r
+    if (other == NULL) {\r
+        return;\r
+    }\r
+\r
     FileTableModel *m = static_cast<FileTableModel*>(model());\r
+    FileTableModel *mOther = static_cast<FileTableModel*>(other->model());\r
 \r
+    QString path = m->absolutePath();\r
+    QString pathOther = mOther->absolutePath();\r
+\r
+    setRootPath(pathOther);\r
+    other->setRootPath(path);\r
+}\r
+\r
+void FileTableView::showHiddenFiles(bool show)\r
+{\r
+    FileTableModel *m = static_cast<FileTableModel*>(model());\r
     if (show) {\r
         m->setFilter(m->filter() | QDir::Hidden);\r
     }\r
@@ -248,7 +344,6 @@ void FileTableView::showHiddenFiles(bool show)
 void FileTableView::showSystemFiles(bool show)\r
 {\r
     FileTableModel *m = static_cast<FileTableModel*>(model());\r
-\r
     if (show) {\r
         m->setFilter(m->filter() | QDir::System);\r
     }\r
@@ -321,11 +416,8 @@ void FileTableView::showHidtory()
 void FileTableView::jumpToHome()\r
 {\r
     CHECK_FOCUS;\r
-    FileTableModel *m = static_cast<FileTableModel*>(model());\r
 \r
-    setUpdatesEnabled(false);\r
-    m->setPath(QDir::homePath());\r
-    setUpdatesEnabled(true);\r
+    setRootPath(QDir::homePath());\r
 }\r
 \r
 void FileTableView::jumpToParent()\r
@@ -336,19 +428,14 @@ void FileTableView::jumpToParent()
     QDir dir(m->absolutePath());\r
     dir.cdUp();\r
 \r
-    setUpdatesEnabled(false);\r
-    m->setPath(dir.absolutePath());\r
-    setUpdatesEnabled(true);\r
+    setRootPath(dir.absolutePath());\r
 }\r
 \r
 void FileTableView::jumpToRoot()\r
 {\r
     CHECK_FOCUS;\r
-    FileTableModel *m = static_cast<FileTableModel*>(model());\r
 \r
-    setUpdatesEnabled(false);\r
-    m->setPath(QDir::rootPath());\r
-    setUpdatesEnabled(true);\r
+    setRootPath(QDir::rootPath());\r
 }\r
 \r
 void FileTableView::jumpTo()\r
@@ -359,9 +446,7 @@ void FileTableView::jumpTo()
     QString path = QFileDialog::getExistingDirectory(\r
                 this, tr("フォルダを選択"), m->absolutePath());\r
     if (!path.isEmpty()) {\r
-        setUpdatesEnabled(false);\r
-        m->setPath(path);\r
-        setUpdatesEnabled(true);\r
+        setRootPath(path);\r
     }\r
 }\r
 \r
@@ -399,6 +484,56 @@ void FileTableView::cursorToEnd()
     setCurrentIndex(model()->index(model()->rowCount() - 1, 1));\r
 }\r
 \r
+void FileTableView::cmdCopy()\r
+{\r
+    CHECK_FOCUS;\r
+\r
+    QFileInfoList list = selectedItems();\r
+    if (list.isEmpty()) {\r
+        return;\r
+    }\r
+\r
+    FileTableView *other = getMainWnd()->otherSideView(this);\r
+    FileTableModel *mOther = static_cast<FileTableModel*>(other->model());\r
+    CopyMoveWorker *worker = new CopyMoveWorker();\r
+    connect(worker, SIGNAL(askOverWrite(bool*,int*,int*,QString*,QString,QString)),\r
+            this, SLOT(askOverWrite(bool*,int*,int*,QString*,QString,QString)));\r
+    worker->setCopyList(&list);\r
+    worker->setTargetDir(mOther->absolutePath());\r
+    worker->setMoveMode(false);\r
+\r
+    OperationDialog opDlg(this);\r
+    opDlg.setWindowTitle(tr("コピー"));\r
+    opDlg.setWorker(worker);\r
+\r
+    opDlg.exec();\r
+}\r
+\r
+void FileTableView::cmdMove()\r
+{\r
+    CHECK_FOCUS;\r
+\r
+    QFileInfoList list = selectedItems();\r
+    if (list.isEmpty()) {\r
+        return;\r
+    }\r
+\r
+    FileTableView *other = getMainWnd()->otherSideView(this);\r
+    FileTableModel *mOther = static_cast<FileTableModel*>(other->model());\r
+    CopyMoveWorker *worker = new CopyMoveWorker();\r
+    connect(worker, SIGNAL(askOverWrite(bool*,int*,int*,QString*,QString,QString)),\r
+            this, SLOT(askOverWrite(bool*,int*,int*,QString*,QString,QString)));\r
+    worker->setCopyList(&list);\r
+    worker->setTargetDir(mOther->absolutePath());\r
+    worker->setMoveMode(true);\r
+\r
+    OperationDialog opDlg(this);\r
+    opDlg.setWindowTitle(tr("移動"));\r
+    opDlg.setWorker(worker);\r
+\r
+    opDlg.exec();\r
+}\r
+\r
 void FileTableView::cmdDelete()\r
 {\r
     CHECK_FOCUS;\r
@@ -419,12 +554,12 @@ void FileTableView::cmdDelete()
                 this, tr("確認"),\r
                 msg + tr("を削除します<br/>よろしいですか?"));\r
     if (ret == QMessageBox::Yes) {\r
-        DeleteWorker worker;\r
-        worker.setDeleteList(&list);\r
+        DeleteWorker *worker = new DeleteWorker();\r
+        worker->setDeleteList(&list);\r
 \r
         OperationDialog opDlg(this);\r
         opDlg.setWindowTitle(tr("削除"));\r
-        opDlg.setWorker(&worker);\r
+        opDlg.setWorker(worker);\r
         opDlg.exec();\r
     }\r
 }\r
@@ -450,12 +585,12 @@ void FileTableView::cmdRename()
     dlg->setNames(list);\r
     int dlgResult = dlg->exec();\r
     if (dlgResult == QDialog::Accepted && !dlg->renameMap().isEmpty()) {\r
-        RenameWorker worker;\r
-        worker.setRenameMap(&dlg->renameMap());\r
+        RenameWorker *worker = new RenameWorker();\r
+        worker->setRenameMap(&dlg->renameMap());\r
 \r
         OperationDialog opDlg(this);\r
         opDlg.setWindowTitle(tr("名前を変更"));\r
-        opDlg.setWorker(&worker);\r
+        opDlg.setWorker(worker);\r
         opDlg.exec();\r
     }\r
 }\r
@@ -509,6 +644,29 @@ void FileTableView::XXX()
     qDebug() << sender()->objectName() << "に対するスロットは未実装です。";\r
 }\r
 \r
+void FileTableView::askOverWrite(bool *bOk, int *prevCopyMethod, int *copyMethod,\r
+                                 QString *alias, const QString &srcPath,\r
+                                 const QString &tgtPath)\r
+ {\r
+     OverWriteDialog dlg;\r
+     dlg.setCopyMethod(*prevCopyMethod);\r
+     dlg.setSameMethodChecked(*copyMethod != OverWriteDialog::Undefined);\r
+     dlg.setFileInfo(srcPath, tgtPath);\r
+     if (dlg.exec() == QDialog::Rejected) {\r
+         *bOk = false;\r
+     }\r
+     else {\r
+         *prevCopyMethod = dlg.copyMethod();\r
+         if (dlg.isSameMethodChecked()) {\r
+             *copyMethod = *prevCopyMethod;\r
+         }\r
+         *alias = dlg.alias();\r
+         *bOk = true;\r
+     }\r
+     CopyMoveWorker *worker = static_cast<CopyMoveWorker*>(sender());\r
+     worker->endAsking();\r
+ }\r
+\r
 void FileTableView::setRootIndex(const QModelIndex &index)\r
 {\r
     if (!index.isValid()) {\r
@@ -518,10 +676,7 @@ void FileTableView::setRootIndex(const QModelIndex &index)
     FileTableModel *m = static_cast<FileTableModel*>(model());\r
 \r
     if (m->isDir(index)) {\r
-        setUpdatesEnabled(false);\r
-        m->setPath(m->absoluteFilePath(index));\r
-        selectRow(0);\r
-        setUpdatesEnabled(true);\r
+        setRootPath(m->absoluteFilePath(index));\r
     }\r
 }\r
 \r
@@ -542,17 +697,30 @@ void FileTableView::keyPressEvent(QKeyEvent *event)
         foreach (QObject *obj, getMainWnd()->children()) {\r
             QAction *action = qobject_cast<QAction*>(obj);\r
             if (action) {\r
-                if (ksq == action->shortcut().toString()) {\r
-                    qDebug() << "emit " << ksq << " " << action->objectName();\r
-                    emit action->triggered();\r
-                    event->accept();\r
-                    return;\r
+                foreach (const QKeySequence &keySeq, action->shortcuts()) {\r
+                    if (ksq == keySeq.toString()) {\r
+                        qDebug() << "emit " << ksq << " " << action->objectName();\r
+                        emit action->triggered();\r
+                        event->accept();\r
+                        return;\r
+                    }\r
                 }\r
             }\r
         }\r
     }\r
 \r
-    qDebug() << ksq;\r
+    if (!ksq.isEmpty()) {\r
+        qDebug() << ksq;\r
+    }\r
     QTableView::keyPressEvent(event);\r
+}\r
+\r
+void FileTableView::currentChanged(const QModelIndex &current, const QModelIndex &previous)\r
+{\r
+    Q_UNUSED(previous);\r
+    selectRow(current.row());\r
+    QTableView::currentChanged(current, previous);\r
 \r
+    const FileTableModel *m = static_cast<const FileTableModel*>(current.model());\r
+    emit indexChanged(m->fileInfo(current).absoluteFilePath());\r
 }\r
index 5ad6faf..6033078 100644 (file)
@@ -9,9 +9,11 @@ class FileTableView : public QTableView
     Q_OBJECT\r
 public:\r
     explicit FileTableView(QWidget *parent = 0);\r
+    ~FileTableView();\r
 \r
     QString side() const;\r
     void setSide(const QString &side);\r
+    void setRootPath(const QString &path);\r
 \r
 private:\r
     QString m_side;\r
@@ -19,6 +21,7 @@ private:
     QFileInfoList selectedItems() const;\r
 \r
 signals:\r
+    void indexChanged(const QString &text);\r
 \r
 public slots:\r
     void setPath();\r
@@ -31,6 +34,9 @@ public slots:
     void uncheckAllItems();\r
     void invertAllChecked();\r
 \r
+    void setPathFromOther();\r
+    void setPathToOther();\r
+    void swapPath();\r
     void showHiddenFiles(bool show);\r
     void showSystemFiles(bool show);\r
     void setSort();\r
@@ -47,6 +53,8 @@ public slots:
     void cursorToBegin();\r
     void cursorToEnd();\r
 \r
+    void cmdCopy();\r
+    void cmdMove();\r
     void cmdDelete();\r
     void cmdRename();\r
     void newFile();\r
@@ -54,6 +62,11 @@ public slots:
 \r
     void XXX();\r
 \r
+private slots:\r
+    void askOverWrite(bool *bOk, int *prevCopyMethod, int *copyMethod,\r
+                      QString *alias, const QString &srcPath,\r
+                      const QString &tgtPath);\r
+\r
     // QAbstractItemView interface\r
 public slots:\r
     void setRootIndex(const QModelIndex &index);\r
@@ -61,6 +74,10 @@ public slots:
     // QWidget interface\r
 protected:\r
     void keyPressEvent(QKeyEvent *event);\r
+\r
+    // QAbstractItemView interface\r
+protected slots:\r
+    void currentChanged(const QModelIndex &current, const QModelIndex &previous);\r
 };\r
 \r
 #endif // FILETABLEVIEW_H\r
index 231f3cd..1c8eb90 100644 (file)
@@ -30,11 +30,7 @@ QString FilesizeToString(quint64 size)
 \r
 FolderPanel::FolderPanel(QWidget *parent) :\r
     QWidget(parent),\r
-    ui(new Ui::FolderPanel),\r
-    m_dir(),\r
-    m_IconFactory(),\r
-    m_fsWatcher(new QFileSystemWatcher(this)),\r
-    m_bUpdating(false)\r
+    ui(new Ui::FolderPanel)\r
 {\r
     ui->setupUi(this);\r
     ui->fileTable->setModel(new FileTableModel(this));\r
@@ -45,11 +41,12 @@ FolderPanel::FolderPanel(QWidget *parent) :
     header->setSectionResizeMode(1, QHeaderView::Stretch);\r
     header->setSectionResizeMode(2, QHeaderView::ResizeToContents);\r
     header->setSectionResizeMode(3, QHeaderView::ResizeToContents);\r
+\r
+    header->setDefaultSectionSize(header->minimumSectionSize());\r
 }\r
 \r
 FolderPanel::~FolderPanel()\r
 {\r
-    UninstallWatcher();\r
     delete ui;\r
 }\r
 \r
@@ -63,120 +60,6 @@ const QTableView *FolderPanel::fileTable() const
     return ui->fileTable;\r
 }\r
 \r
-void FolderPanel::setCurrentFolder(const QString &path)\r
-{\r
-    QSettings settings;\r
-\r
-    getMainWnd()->setStatusText(tr("ファイルリストを更新中..."));\r
-    QString curDir = m_dir.absolutePath();\r
-    m_dir.setPath(QDir::cleanPath(path));\r
-    m_dir.canonicalPath();\r
-\r
-    QFileInfoList list = m_dir.entryInfoList();\r
-\r
-    if (list.empty()) {\r
-        QMessageBox::critical(\r
-                    this,\r
-                    tr("エラー"),\r
-                    tr("フォルダが存在しないか利用できません。"));\r
-        m_dir.setPath(curDir);\r
-        ui->locationField->setText(curDir);\r
-        getMainWnd()->setStatusText(tr("レディ"));\r
-        return;\r
-    }\r
-\r
-    // フォルダの変更監視\r
-    InstallWatcher();\r
-\r
-    // QtはWindowsのシステムファイル属性をうまく判定できていないため、\r
-    // GetFileAttributes APIを使ってフィルタする\r
-    bool showSystem;\r
-    showSystem = settings.value(IniKey_ShowSystem, false).toBool();\r
-\r
-    beginUpdate();\r
-//    ui->fileTable->model()->removeRows(0, ui->fileTable->rowCount());\r
-//    for (int i = 0; i < list.size(); i++) {\r
-//        QFileInfo info = list.at(i);\r
-//        if (info.fileName() == ".." && m_dir.isRoot()) {\r
-//            continue;\r
-//        }\r
-\r
-//#ifdef Q_OS_WIN32\r
-//        DWORD dwFlags = ::GetFileAttributes(info.absoluteFilePath().toStdWString().c_str());\r
-//        if (!showSystem && dwFlags != DWORD(-1) && (dwFlags & FILE_ATTRIBUTE_SYSTEM)) {\r
-//            continue;\r
-//        }\r
-//#endif\r
-\r
-//        int row = ui->fileTable->rowCount();\r
-//        ui->fileTable->insertRow(row);\r
-\r
-//        // ファイル名とアイコン\r
-//        QTableWidgetItem *iName = new QTableWidgetItem(info.fileName());\r
-//        iName->setFlags(iName->flags() ^ Qt::ItemIsEditable);\r
-//        if (info.fileName() == "..") {\r
-//            iName->setIcon(QIcon(":/images/Up.png"));\r
-//        }\r
-//        else {\r
-//            iName->setIcon(m_IconFactory.icon(info));\r
-//        }\r
-//        ui->fileTable->setItem(row, 1, iName);\r
-\r
-//        // サイズ\r
-//        QString str;\r
-//        if (info.isDir()) {\r
-//            str = tr("<DIR>");\r
-//        }\r
-//        else {\r
-//            str = FilesizeToString(info.size());\r
-//        }\r
-//        QTableWidgetItem *iSize = new QTableWidgetItem(str);\r
-//        iSize->setFlags(iSize->flags() ^ Qt::ItemIsEditable);\r
-//        iSize->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);\r
-//        ui->fileTable->setItem(row, 2, iSize);\r
-\r
-//        // 最終更新日時\r
-//        QTableWidgetItem *iDateTime = new QTableWidgetItem(\r
-//                    info.lastModified().toString("yy/MM/dd hh:mm"));\r
-//        iDateTime->setFlags(iDateTime->flags() ^ Qt::ItemIsEditable);\r
-//        ui->fileTable->setItem(row, 3, iDateTime);\r
-\r
-//        // シグナル処理の関係で、チェックボックスは最後に追加する\r
-//        QTableWidgetItem *iCheck = new QTableWidgetItem(tr(""));\r
-//        iCheck->setFlags(iCheck->flags() ^ Qt::ItemIsEditable);\r
-//        if (info.fileName() != "..") {\r
-//            iCheck->setFlags(iCheck->flags() | Qt::ItemIsUserCheckable);\r
-//            iCheck->setCheckState(Qt::Unchecked);\r
-//        }\r
-//        ui->fileTable->setItem(row, 0, iCheck);\r
-\r
-//    }\r
-    ui->fileTable->selectRow(0);\r
-    ui->fileTable->resizeRowsToContents();\r
-\r
-    ui->locationField->setText(m_dir.absolutePath());\r
-    getMainWnd()->setStatusText(tr("レディ"));\r
-    endUpdate();\r
-}\r
-\r
-void FolderPanel::InstallWatcher()\r
-{\r
-    UninstallWatcher();\r
-\r
-    m_fsWatcher = new QFileSystemWatcher(this);\r
-    m_fsWatcher->addPath(m_dir.absolutePath());\r
-    connect(m_fsWatcher, SIGNAL(directoryChanged(QString)),\r
-            this, SLOT(on_directoryChanged(QString)));\r
-}\r
-\r
-void FolderPanel::UninstallWatcher()\r
-{\r
-    if (m_fsWatcher != NULL) {\r
-        delete m_fsWatcher;\r
-    }\r
-    m_fsWatcher = NULL;\r
-}\r
-\r
 const QString FolderPanel::side() const\r
 {\r
     return ui->fileTable->side();\r
@@ -260,29 +143,7 @@ void FolderPanel::on_locationField_editingFinished()
     ui->locationField->blockSignals(true);\r
 \r
     QString path = ui->locationField->text();\r
-    setCurrentFolder(path);\r
+    ui->fileTable->setRootPath(path);\r
 \r
     ui->locationField->blockSignals(false);\r
 }\r
-\r
-void FolderPanel::on_directoryChanged(QString)\r
-{\r
-//    int row = ui->fileTable->currentRow();\r
-//    this->setCurrentFolder(m_dir.absolutePath());\r
-//    if (row >= ui->fileTable->rowCount()) {\r
-//        row = ui->fileTable->rowCount() - 1;\r
-//    }\r
-//    ui->fileTable->selectRow(row);\r
-}\r
-\r
-//void FolderPanel::on_fileTable_itemSelectionChanged()\r
-//{\r
-//    if (isUpdating()) {\r
-//        return;\r
-//    }\r
-\r
-//    int row = ui->fileTable->currentRow();\r
-//    if (0 <= row && row < ui->fileTable->rowCount()) {\r
-//        getMainWnd()->setStatusText(ui->fileTable->item(row, 1)->text());\r
-//    }\r
-//}\r
index d95effb..8d80485 100644 (file)
@@ -24,39 +24,15 @@ public:
     QTableView *fileTable();\r
     const QTableView* fileTable() const;\r
 \r
-    QDir* dir() { return &m_dir; }\r
-    const QDir* dir() const { return &m_dir; }\r
-\r
-    void setCurrentFolder(const QString &path);\r
-    void InstallWatcher();\r
-    void UninstallWatcher();\r
-\r
-    void beginUpdate() {\r
-        m_bUpdating = true;\r
-//        setUpdatesEnabled(false);\r
-    }\r
-    void endUpdate() {\r
-        m_bUpdating = false;\r
-//        setUpdatesEnabled(true);\r
-        //onUpdateMark(0, 0);\r
-    }\r
-    bool isUpdating() const { return m_bUpdating; }\r
-\r
     const QString side() const;\r
     void setSide(const QString &side);\r
 \r
 private:\r
     Ui::FolderPanel *ui;\r
-    QDir m_dir;\r
-    QFileIconProvider m_IconFactory;\r
-    QFileSystemWatcher *m_fsWatcher;\r
-    bool m_bUpdating;\r
 \r
 private slots:\r
     void onStateChanged(int checkedFolders, int checkedFiles, quint64 totalSize);\r
     void on_locationField_editingFinished();\r
-    void on_directoryChanged(QString);\r
-//    void on_fileTable_itemSelectionChanged();\r
 };\r
 \r
 #endif // FOLDERPANEL_H\r
index 60002bc..fc653b8 100644 (file)
@@ -48,6 +48,9 @@
    </item>\r
    <item>\r
     <widget class="FileTableView" name="fileTable">\r
+     <property name="verticalScrollBarPolicy">\r
+      <enum>Qt::ScrollBarAlwaysOn</enum>\r
+     </property>\r
      <property name="horizontalScrollBarPolicy">\r
       <enum>Qt::ScrollBarAlwaysOff</enum>\r
      </property>\r
index 95bd97c..559bfde 100644 (file)
@@ -24,8 +24,9 @@ MainWindow::MainWindow(QWidget *parent) :
     ui(new Ui::MainWindow)\r
 {\r
     ui->setupUi(this);\r
-    ui->LPanel->setSide("Left");\r
     ui->RPanel->setSide("Right");\r
+    ui->LPanel->setSide("Left");\r
+    ui->LPanel->fileTable()->setFocus();\r
 \r
     QSettings settings;\r
     // メニュー項目のチェック状態を初期化する\r
@@ -49,15 +50,8 @@ MainWindow::MainWindow(QWidget *parent) :
     connect(ui->action_Setting, SIGNAL(triggered()), this, SLOT(onActionSetting()));\r
     connect(ui->action_Quit, SIGNAL(triggered()), qApp, SLOT(quit()));\r
     connect(ui->help_About, SIGNAL(triggered()), this, SLOT(onHelpAbout()));\r
-\r
-\r
-//    connect(ui->view_FromOther, SIGNAL(triggered()), this, SLOT(onViewFromOther()));\r
-//    connect(ui->view_ToOther, SIGNAL(triggered()), this, SLOT(onViewToOther()));\r
-//    connect(ui->view_Swap, SIGNAL(triggered()), this, SLOT(onViewSwap()));\r
-\r
-//    connect(ui->cmd_Copy, SIGNAL(triggered()), this, SLOT(onCmdCopy()));\r
-//    connect(ui->cmd_Move, SIGNAL(triggered()), this, SLOT(onCmdMove()));\r
-\r
+    connect(ui->view_Hidden, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));\r
+    connect(ui->view_System, SIGNAL(triggered()), this, SLOT(toggleShowSystemFiles()));\r
 \r
     // ウィンドウタイトルを設定する\r
     setWindowTitle(tr("げふぅ v%1").arg(VERSION_VALUE));\r
@@ -66,16 +60,10 @@ MainWindow::MainWindow(QWidget *parent) :
 \r
     // ウィンドウ初期サイズを設定する\r
     resize(800, 600);\r
-\r
 }\r
 \r
 MainWindow::~MainWindow()\r
 {\r
-    QSettings settings;\r
-\r
-    settings.setValue(IniKey_LeftDir, ui->LPanel->dir()->absolutePath());\r
-    settings.setValue(IniKey_RightDir, ui->RPanel->dir()->absolutePath());\r
-\r
     delete ui;\r
 }\r
 \r
@@ -98,207 +86,37 @@ FileTableView *MainWindow::otherSideView(const FileTableView *view) const
     return NULL;\r
 }\r
 \r
-FolderPanel* MainWindow::activePanel()\r
-{\r
-    if (ui->LPanel->fileTable()->hasFocus()) {\r
-        return ui->LPanel;\r
-    }\r
-    if (ui->RPanel->fileTable()->hasFocus()) {\r
-        return ui->RPanel;\r
-    }\r
-\r
-    return NULL;\r
-}\r
-\r
-FolderPanel* MainWindow::inactivePanel()\r
-{\r
-    FolderPanel *fp = activePanel();\r
-    if (fp == ui->LPanel) {\r
-        return ui->RPanel;\r
-    }\r
-    if (fp == ui->RPanel) {\r
-        return ui->LPanel;\r
-    }\r
-\r
-    return NULL;\r
-}\r
-\r
-///\r
-/// \brief MainWindow::onActionSetting\r
-///\r
-/// 環境設定ダイアログを表示します(Z)\r
-///\r
 void MainWindow::onActionSetting()\r
 {\r
     QMessageBox::information(this, tr("情報"), tr("環境設定機能は未実装です。"));\r
 }\r
 \r
-\r
-///\r
-/// \brief MainWindow::onViewFromOther\r
-///\r
-/// 隣のパネルと同じフォルダを表示します(O)\r
-///\r
-void MainWindow::onViewFromOther()\r
-{\r
-    FolderPanel *fp1 = activePanel();\r
-    FolderPanel *fp2 = inactivePanel();\r
-    if (fp1 == NULL || fp2 == NULL) {\r
-        return;\r
-    }\r
-\r
-    fp1->setCurrentFolder(fp2->dir()->absolutePath());\r
-}\r
-\r
-///\r
-/// \brief MainWindow::onViewToOther\r
-///\r
-/// 隣のパネルに同じフォルダを表示します(Shift + O)\r
-///\r
-void MainWindow::onViewToOther()\r
+void MainWindow::toggleShowHiddenFiles()\r
 {\r
-    FolderPanel *fp1 = activePanel();\r
-    FolderPanel *fp2 = inactivePanel();\r
-    if (fp1 == NULL || fp2 == NULL) {\r
-        return;\r
-    }\r
-\r
-    fp2->setCurrentFolder(fp1->dir()->absolutePath());\r
-}\r
-\r
-\r
-///\r
-/// \brief MainWindow::onViewSwap\r
-///\r
-/// パネルの表示内容を交換します(W)\r
-///\r
-void MainWindow::onViewSwap()\r
-{\r
-    FolderPanel *fp1 = activePanel();\r
-    FolderPanel *fp2 = inactivePanel();\r
-    if (fp1 == NULL || fp2 == NULL) {\r
-        return;\r
-    }\r
-\r
-    QString path1 = fp1->dir()->absolutePath();\r
-    QString path2 = fp2->dir()->absolutePath();\r
-\r
-    fp1->setCurrentFolder(path2);\r
-    fp2->setCurrentFolder(path1);\r
-}\r
-\r
-\r
-///\r
-/// \brief MainWindow::onCmdMove\r
-///\r
-/// ファイルを移動します(Ctrl + M)\r
-///\r
-void MainWindow::onCmdMove()\r
-{\r
-    FolderPanel *fp = activePanel();\r
-    if (!fp) {\r
-        return;\r
-    }\r
-\r
-//    QStringList list = selectedItems(fp);\r
-//    if (list.isEmpty()) {\r
-//        return;\r
-//    }\r
-\r
-//    CopyMoveWorker *worker = new CopyMoveWorker();\r
-//    connect(worker, SIGNAL(askOverWrite(bool*,int*,int*,QString*,QString,QString)),\r
-//            this, SLOT(onAskOverWrite(bool*,int*,int*,QString*,QString,QString)));\r
-//    worker->setCopyList(&list);\r
-//    worker->setTargetDir(inactivePanel()->dir()->absolutePath());\r
-//    worker->setMoveMode(true);\r
-\r
-//    OperationDialog opDlg(this);\r
-//    opDlg.setWindowTitle(tr("移動"));\r
-//    opDlg.setWorker(worker);\r
+    // キーボードがトリガーの場合、メニュー項目のチェック状態は\r
+    // 変わらないので、QSettingsを使う\r
+    QSettings settings;\r
+    bool show = !settings.value(IniKey_ShowHidden, false).toBool();\r
+    settings.setValue(IniKey_ShowHidden, show);\r
 \r
-//    ui->LPanel->UninstallWatcher();\r
-//    ui->RPanel->UninstallWatcher();\r
-//    opDlg.exec();\r
-//    ui->LPanel->setCurrentFolder(ui->LPanel->dir()->absolutePath());\r
-//    ui->RPanel->setCurrentFolder(ui->RPanel->dir()->absolutePath());\r
+    ui->view_Hidden->setChecked(show);\r
 \r
+    emit showHiddenFiles(show);\r
 }\r
 \r
-///\r
-/// \brief MainWindow::onCmdCopy\r
-///\r
-/// ファイルをコピーします(Ctrl + C)\r
-///\r
-void MainWindow::onCmdCopy()\r
+void MainWindow::toggleShowSystemFiles()\r
 {\r
-    FolderPanel *fp = activePanel();\r
-    if (!fp) {\r
-        return;\r
-    }\r
-\r
-//    QStringList list = selectedItems(fp);\r
-//    if (list.isEmpty()) {\r
-//        return;\r
-//    }\r
-\r
-//    CopyMoveWorker *worker = new CopyMoveWorker();\r
-//    connect(worker, SIGNAL(askOverWrite(bool*,int*,int*,QString*,QString,QString)),\r
-//            this, SLOT(onAskOverWrite(bool*,int*,int*,QString*,QString,QString)));\r
-//    worker->setCopyList(&list);\r
-//    worker->setTargetDir(inactivePanel()->dir()->absolutePath());\r
-//    worker->setMoveMode(false);\r
-\r
-//    OperationDialog opDlg(this);\r
-//    opDlg.setWindowTitle(tr("コピー"));\r
-//    opDlg.setWorker(worker);\r
-\r
-//    ui->LPanel->UninstallWatcher();\r
-//    ui->RPanel->UninstallWatcher();\r
-//    opDlg.exec();\r
-//    ui->LPanel->setCurrentFolder(ui->LPanel->dir()->absolutePath());\r
-//    ui->RPanel->setCurrentFolder(ui->RPanel->dir()->absolutePath());\r
+    // キーボードがトリガーの場合、メニュー項目のチェック状態は\r
+    // 変わらないので、QSettingsを使う\r
+    QSettings settings;\r
+    bool show = !settings.value(IniKey_ShowSystem, false).toBool();\r
+    settings.setValue(IniKey_ShowSystem, show);\r
 \r
-}\r
+    ui->view_System->setChecked(show);\r
 \r
-///\r
-/// \brief MainWindow::onAskOverWrite\r
-/// \param bOk\r
-/// \param prevCopyMethod\r
-/// \param copyMethod\r
-/// \param alias\r
-/// \param srcPath\r
-/// \param tgtPath\r
-///\r
-/// 上書き処理の方法をユーザに問い合わせます\r
-///\r
-void MainWindow::onAskOverWrite(bool *bOk, int *prevCopyMethod, int *copyMethod,\r
-                                QString *alias, const QString srcPath,\r
-                                const QString tgtPath)\r
-{\r
-    OverWriteDialog dlg;\r
-    dlg.setCopyMethod(*prevCopyMethod);\r
-    dlg.setSameMethodChecked(*copyMethod != OverWriteDialog::Undefined);\r
-    dlg.setFileInfo(srcPath, tgtPath);\r
-    if (dlg.exec() == QDialog::Rejected) {\r
-        *bOk = false;\r
-    }\r
-    else {\r
-        *prevCopyMethod = dlg.copyMethod();\r
-        if (dlg.isSameMethodChecked()) {\r
-            *copyMethod = *prevCopyMethod;\r
-        }\r
-        *alias = dlg.alias();\r
-        *bOk = true;\r
-    }\r
-    CopyMoveWorker *worker = static_cast<CopyMoveWorker*>(sender());\r
-    worker->endAsking();\r
+    emit showSystemFiles(show);\r
 }\r
 \r
-///\r
-/// \brief MainWindow::onHelpAbout\r
-///\r
-/// アプリケーションの概要を表示します(?)\r
-///\r
 void MainWindow::onHelpAbout()\r
 {\r
     QMessageBox::about(\r
@@ -310,12 +128,6 @@ void MainWindow::onHelpAbout()
                    "<p>Copyright 2014 @miyabi_satoh All rights reserved.</p>"));\r
 }\r
 \r
-///\r
-/// \brief getMainWnd\r
-/// \return メインウィンドウのポインタ\r
-///\r
-/// メインウィンドウを取得します\r
-///\r
 MainWindow* getMainWnd()\r
 {\r
     foreach (QWidget *w, qApp->topLevelWidgets()) {\r
index 13049bc..a072187 100644 (file)
@@ -18,28 +18,23 @@ public:
     explicit MainWindow(QWidget *parent = 0);\r
     ~MainWindow();\r
 \r
-    void setStatusText(const QString &str);\r
     FileTableView* otherSideView(const FileTableView *view) const;\r
 \r
+signals:\r
+    void showHiddenFiles(bool show);\r
+    void showSystemFiles(bool show);\r
+\r
 public slots:\r
+    void setStatusText(const QString &str);\r
     void onActionSetting();\r
-    void onViewFromOther();\r
-    void onViewToOther();\r
-    void onViewSwap();\r
-    void onCmdMove();\r
-    void onCmdCopy();\r
     void onHelpAbout();\r
 \r
 private slots:\r
-    void onAskOverWrite(bool *bOk, int *prevCopyMethod, int *copyMethod,\r
-                        QString *alias, const QString srcPath, const QString tgtPath);\r
+    void toggleShowHiddenFiles();\r
+    void toggleShowSystemFiles();\r
 \r
 private:\r
     Ui::MainWindow *ui;\r
-\r
-    FolderPanel* activePanel();\r
-    FolderPanel* inactivePanel();\r
 };\r
 \r
-\r
 #endif // MAINWINDOW_H\r