From: Masayuki Satoh Date: Mon, 25 Aug 2014 16:01:42 +0000 (+0900) Subject: Ver0.11 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=b443d2afc5c7970a72ce322243c8bdc7febb7a12;p=gefu%2FGefu.git Ver0.11 --- diff --git a/filetablemodel.cpp b/filetablemodel.cpp index df135d2..4b89099 100644 --- a/filetablemodel.cpp +++ b/filetablemodel.cpp @@ -107,9 +107,10 @@ bool FileTableModel::setPath(const QString &path) endResetModel(); - emit rootChanged(m_dir.absolutePath()); - stateChanged(); +// emit rootChanged(m_dir.absolutePath()); +// stateChanged(); + emit dataChanged(QModelIndex(), QModelIndex()); return !m_fileInfoList.isEmpty(); } @@ -130,7 +131,7 @@ void FileTableModel::setCheckState(const QModelIndex &index, Qt::CheckState stat endResetModel();; emit dataChanged(index, this->index(index.row(), 3)); - stateChanged(); +// stateChanged(); } void FileTableModel::setCheckStateAll(Qt::CheckState state) @@ -143,8 +144,9 @@ void FileTableModel::setCheckStateAll(Qt::CheckState state) m_checkStates[0] = Qt::Unchecked; } endResetModel(); + emit dataChanged(QModelIndex(), QModelIndex()); - stateChanged(); +// stateChanged(); } QFileInfo FileTableModel::fileInfo(const QModelIndex &index) const @@ -182,25 +184,25 @@ void FileTableModel::directoryChange(const QString &path) setPath(path); } -void FileTableModel::stateChanged() -{ - int numFolder = 0; - int numFile = 0; - quint64 totalSize = 0; - for (int n = 0; n < m_checkStates.size(); n++) { - if (m_checkStates[n] == Qt::Checked) { - if (m_fileInfoList[n].isDir()) { - numFolder++; - } - else { - numFile++; - totalSize += m_fileInfoList[n].size(); - } - } - } - - emit stateChanged(numFolder, numFile, totalSize); -} +//void FileTableModel::stateChanged() +//{ +// int numFolder = 0; +// int numFile = 0; +// quint64 totalSize = 0; +// for (int n = 0; n < m_checkStates.size(); n++) { +// if (m_checkStates[n] == Qt::Checked) { +// if (m_fileInfoList[n].isDir()) { +// numFolder++; +// } +// else { +// numFile++; +// totalSize += m_fileInfoList[n].size(); +// } +// } +// } + +// emit selectionChanged(numFolder, numFile, totalSize); +//} QFileInfoList FileTableModel::checkedItems() const { @@ -361,7 +363,7 @@ bool FileTableModel::setData(const QModelIndex &index, const QVariant &value, in if (index.column() == 0) { m_checkStates[index.row()] = static_cast(value.toInt()); emit dataChanged(index, this->index(index.row(), 3)); - stateChanged(); +// stateChanged(); return true; } break; diff --git a/filetablemodel.h b/filetablemodel.h index 321829c..3cbcfc7 100644 --- a/filetablemodel.h +++ b/filetablemodel.h @@ -40,8 +40,8 @@ public: QFont font() const { return m_font; } signals: - void rootChanged(const QString &root); - void stateChanged(int checkedFoldrs, int checkedFiles, quint64 totalSize); +// void rootChanged(const QString &root); + void selectionChanged(int checkedFoldrs, int checkedFiles, quint64 totalSize); public slots: void directoryChange(const QString &path); @@ -61,7 +61,7 @@ private: QBrush m_HiddenBrush; QBrush m_ReadonlyBrush; - void stateChanged(); +// void stateChanged(); // QAbstractItemModel interface public: diff --git a/folderview.cpp b/folderview.cpp index 1bcf8c5..c57c57e 100644 --- a/folderview.cpp +++ b/folderview.cpp @@ -5,6 +5,9 @@ #include #include #include +#include +#include +#include QString FilesizeToString(quint64 size) { @@ -22,9 +25,16 @@ QString FilesizeToString(quint64 size) FolderView::FolderView(QWidget *parent) : QTableView(parent), - m_model() + m_model(), + m_dragStartPos(), + m_dragging(false) { setModel(&m_model); + connect(&m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex))); + + setDragEnabled(true); + setAcceptDrops(true); + setDropIndicatorShown(true); } QString FolderView::side() const @@ -48,10 +58,6 @@ void FolderView::initialize() 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); @@ -69,6 +75,10 @@ void FolderView::updateAppearance() QPalette pal = palette(); pal.setColor(QPalette::Base, settings.value(IniKey_ViewColorBgNormal).value()); setPalette(pal); + + // 行の高さを設定する + QHeaderView *header = verticalHeader(); + header->setDefaultSectionSize(QFontMetrics(m_model.font()).height() * 1.5); } void FolderView::refresh() @@ -86,6 +96,7 @@ void FolderView::refresh() row = m_model.rowCount() - 1; } setCurrentIndex(m_model.index(row, 0)); + selectRow(row); } void FolderView::searchItem(const QString &text) @@ -97,12 +108,12 @@ void FolderView::searchItem(const QString &text) QString name = m_model.fileInfo(index).fileName().toLower(); if (name.indexOf(text.toLower()) != -1) { setCurrentIndex(index); - emit itemFound(this); + emit itemFound(); return; } } - emit itemNotFound(this); + emit itemNotFound(); } void FolderView::searchNext(const QString &text) @@ -114,12 +125,12 @@ void FolderView::searchNext(const QString &text) QString name = m_model.fileInfo(index).fileName().toLower(); if (name.indexOf(text.toLower()) != -1) { setCurrentIndex(index); - emit itemFound(this); + emit itemFound(); return; } } - emit itemNotFound(this); + emit itemNotFound(); } void FolderView::searchPrev(const QString &text) @@ -131,12 +142,12 @@ void FolderView::searchPrev(const QString &text) QString name = m_model.fileInfo(index).fileName().toLower(); if (name.indexOf(text.toLower()) != -1) { setCurrentIndex(index); - emit itemFound(this); + emit itemFound(); return; } } - emit itemNotFound(this); + emit itemNotFound(); } void FolderView::setCheckStateAll(bool checked) @@ -242,6 +253,13 @@ QFileInfo FolderView::currentItem() const return m_model.fileInfo(currentIndex()); } +QFileInfoList FolderView::checkedItems() const +{ + qDebug() << side() << "checkedItems()"; + + return m_model.checkedItems(); +} + QFileInfoList FolderView::selectedItems() const { qDebug() << side() << "selectedItems"; @@ -311,7 +329,7 @@ void FolderView::keyPressEvent(QKeyEvent *event) { qDebug() << side() << "keyPressEvent"; - emit keyPressed(this, event); + emit keyPressed(event); if (!event->isAccepted()) { QTableView::keyPressEvent(event); @@ -320,3 +338,110 @@ void FolderView::keyPressEvent(QKeyEvent *event) qDebug() << "KeyEvent accepted."; } } + +void FolderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) +{ + Q_UNUSED(topLeft); + Q_UNUSED(bottomRight); + Q_UNUSED(roles); + + emit dataChanged(); +} + +void FolderView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) +{ + Q_UNUSED(previous); + + emit currentChanged(m_model.fileInfo(current).absoluteFilePath()); +} + +void FolderView::mousePressEvent(QMouseEvent *event) +{ + if ((event->buttons() & Qt::LeftButton) || (event->buttons() & Qt::RightButton)) + { + m_dragStartPos = event->pos(); + } + + QTableView::mousePressEvent(event); +} + +void FolderView::mouseMoveEvent(QMouseEvent *event) +{ + if (!(event->buttons() & Qt::LeftButton) && + !(event->buttons() & Qt::RightButton)) + { + QTableView::mouseMoveEvent(event); + return; + } + if ((event->pos() - m_dragStartPos).manhattanLength() + < QApplication::startDragDistance()) + { + QTableView::mouseMoveEvent(event); + return; + } + + QFileInfoList list = selectedItems(); + if (list.isEmpty()) { + QTableView::mousePressEvent(event); + return; + } + + QList urls; + foreach (const QFileInfo &info, list) { + urls << QUrl::fromLocalFile(info.absoluteFilePath()); + } + + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + mimeData->setUrls(urls); + drag->setMimeData(mimeData); + + m_dragging = true; + if (event->buttons() & Qt::RightButton) { + drag->exec(Qt::CopyAction | Qt::MoveAction); + } + else { + drag->exec(Qt::CopyAction); + } + m_dragging = false; +} + +void FolderView::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + return; + } + + QTableView::dragEnterEvent(event); +} + +void FolderView::dropEvent(QDropEvent *event) +{ + qDebug() << side() << "dropEvent();"; + + if (m_dragging) { + event->ignore(); + return; + } + + QFileInfoList list; + foreach (const QUrl &url, event->mimeData()->urls()) { + QString path = QFileInfo(url.toLocalFile()).canonicalFilePath(); + if (!path.isEmpty()) { + list << path; + } + else { + qDebug() << "path is empty." << url; + } + } + + if (list.isEmpty()) { + event->ignore(); + return; + } + + event->acceptProposedAction(); + + emit dropAccepted(list); +} diff --git a/folderview.h b/folderview.h index 3b23544..61f2b0c 100644 --- a/folderview.h +++ b/folderview.h @@ -35,6 +35,7 @@ public: // getter QFileInfo currentItem() const; QString dir() const { return m_model.absolutePath(); } + QFileInfoList checkedItems() const; QFileInfoList selectedItems() const; const History* history() const { return &m_history; } QStringList nameFilters() const { return m_model.nameFilters(); } @@ -49,22 +50,33 @@ public: private: FileTableModel m_model; History m_history; - + QPoint m_dragStartPos; + bool m_dragging; signals: - void itemFound(FolderView *view); - void itemNotFound(FolderView *view); + void currentChanged(const QString &path); + void dataChanged(); + void dropAccepted(const QFileInfoList &list); + void itemFound(); + void itemNotFound(); void retrieveStarted(const QString &path); void retrieveFinished(); - void keyPressed(FolderView *view, QKeyEvent *event); + void keyPressed(QKeyEvent *event); public slots: + // QAbstractItemView interface +protected slots: + void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); + void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()); // QWidget interface protected: void keyPressEvent(QKeyEvent *event); - + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); }; #endif // FOLDERVIEW_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 3e9c359..d742ac8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -69,9 +69,12 @@ MainWindow::MainWindow(QWidget *parent) : // シグナル&スロット 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(dataChanged()), this, SLOT(dataChange())); + connect(folderView, SIGNAL(dropAccepted(QFileInfoList)), this, SLOT(dropAccept(QFileInfoList))); + connect(folderView, SIGNAL(currentChanged(QString)), ui->statusBar, SLOT(showMessage(QString))); + connect(folderView, SIGNAL(itemFound()), this, SLOT(itemFound())); + connect(folderView, SIGNAL(itemNotFound()), this, SLOT(itemNotFound())); + connect(folderView, SIGNAL(keyPressed(QKeyEvent*)), this, SLOT(keyPress(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))); @@ -180,8 +183,8 @@ MainWindow::MainWindow(QWidget *parent) : checkUpdate(true); } - ui->folderView1->repaint(); - ui->folderView2->repaint(); + ui->folderView1->refresh(); + ui->folderView2->refresh(); } MainWindow::~MainWindow() @@ -204,9 +207,12 @@ FolderView* MainWindow::otherSideView(const FolderView *view) const void MainWindow::focusChange(QWidget *old, QWidget *now) { Q_UNUSED(old); - Q_UNUSED(now); qDebug() << "MainWindow::focusChange"; + if (now == ui->folderView1 || now == ui->folderView2) { + ui->statusBar->showMessage(folderView()->currentItem().absoluteFilePath()); + } + updateActions(); } @@ -265,21 +271,21 @@ void MainWindow::historyForward() } } -void MainWindow::itemFound(FolderView *view) +void MainWindow::itemFound() { qDebug() << "MainWindow::itemFound"; - SearchBox *box = searchBox(view); + SearchBox *box = searchBox(static_cast(sender())); QPalette pal = box->palette(); pal.setColor(QPalette::Text, QPalette().text().color()); box->setPalette(pal); } -void MainWindow::itemNotFound(FolderView *view) +void MainWindow::itemNotFound() { qDebug() << "MainWindow::itemNotFound"; - SearchBox *box = searchBox(view); + SearchBox *box = searchBox(static_cast(sender())); QPalette pal = box->palette(); pal.setColor(QPalette::Text, Qt::red); box->setPalette(pal); @@ -366,7 +372,7 @@ void MainWindow::moveItems() ui->folderView2->refresh(); } -void MainWindow::keyPress(FolderView *view, QKeyEvent *event) +void MainWindow::keyPress(QKeyEvent *event) { QString ksq = KeyEventToSequence(event); if (ksq == "") { @@ -400,6 +406,7 @@ void MainWindow::keyPress(FolderView *view, QKeyEvent *event) } if (ksq == "Left" || ksq == "Right") { + FolderView *view = static_cast(sender()); if (view->side() == ksq) { setPathToParent(); } @@ -475,6 +482,85 @@ void MainWindow::askOverWrite(QString *copyMethod, worker->endAsking(); } +void MainWindow::dataChange() +{ + FolderView *view = static_cast(sender()); + QFileInfoList list = view->checkedItems(); + if (list.isEmpty()) { + showNameFilters(view); + } + else { + int numFolders = 0; + int numFiles = 0; + quint64 size = 0; + foreach (const QFileInfo &info, list) { + if (info.isDir()) { + numFolders++; + } + else { + numFiles++; + size += info.size(); + } + } + + QString msg = QString::null; + if (numFolders > 0) { + msg += tr("%1個のフォルダ ").arg(numFolders); + } + if (numFiles > 0) { + msg += tr("%1個のファイル ").arg(numFiles); + } + + if (!msg.isEmpty()) { + msg += tr("を選択 合計%1").arg(FilesizeToString(size)); + } + + filterLabel(view)->setText(msg); + } +} + +void MainWindow::dropAccept(const QFileInfoList &list) +{ + copyItems(list, static_cast(sender())->dir()); +} + +void MainWindow::copyItems(const QFileInfoList &list, const QString &tgtDir) +{ + QSettings settings; + if (settings.value(IniKey_ConfirmCopy).toBool()) { + if (QMessageBox::question(this, tr("確認"), tr("コピーを実行しますか?")) + != QMessageBox::Yes) + { + return; + } + } + + // 上書き確認ダイアログを初期化する + m_overwriteDialog->reset(); + + // ワーカースレッドを作成する + CopyMoveWorker *worker = new CopyMoveWorker(); + connect(worker, SIGNAL(askOverWrite(QString*,QString*,QString,QString)), + this, SLOT(askOverWrite(QString*,QString*,QString,QString))); + worker->setCopyList(&list); + worker->setTargetDir(tgtDir); + 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::copyItems() { qDebug() << "MainWindow::copyItems"; @@ -485,6 +571,9 @@ void MainWindow::copyItems() return; } + FolderView *other = otherSideView(v); + copyItems(list, other->dir()); +#if 0 QSettings settings; if (settings.value(IniKey_ConfirmCopy).toBool()) { if (QMessageBox::question(this, tr("確認"), tr("コピーを実行しますか?")) @@ -519,6 +608,7 @@ void MainWindow::copyItems() // 念のため、リフレッシュ ui->folderView1->refresh(); ui->folderView2->refresh(); +#endif } void MainWindow::createFile() @@ -946,6 +1036,11 @@ void MainWindow::setSorting(FolderView *view) view->setSorting(flags); } +void MainWindow::showNameFilters(FolderView *view) +{ + filterLabel(view)->setText(tr("フィルタ:") + view->nameFilters().join(" ")); +} + void MainWindow::searchItem(const QString &text) { qDebug() << "MainWindow::searchItem" << text; @@ -1405,7 +1500,7 @@ void MainWindow::setNameFilters(FolderView *view, const QString &filters) list << "*"; } view->setNameFilters(list); - filterLabel(view)->setText(tr("フィルタ:") + list.join(" ")); + showNameFilters(view); } QLabel *MainWindow::filterLabel(const FolderView *view) const diff --git a/mainwindow.h b/mainwindow.h index a2b21ee..dcb3bb3 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -35,10 +35,16 @@ public slots: void askOverWrite(QString *copyMethod, QString *alias, const QString &srcPath, const QString &tgtPath); + void dataChange(); + void dropAccept(const QFileInfoList &list); void focusChange(QWidget * old, QWidget * now); - void keyPress(FolderView *view, QKeyEvent *event); + void keyPress(QKeyEvent *event); void returnPressInSearchBox(); + void about(); + void checkUpdate(bool silent = false); + void checkUpdateFinished(QNetworkReply *reply, bool silent = false); + void checkUpdateFinishedSilent(QNetworkReply *reply); void chooseFolder(); void copyFilenameToClipboard(); void copyFullpathTpClipboard(); @@ -51,8 +57,8 @@ public slots: void executeCommand(); void historyBack(); void historyForward(); - void itemFound(FolderView *view); - void itemNotFound(FolderView *view); + void itemFound(); + void itemNotFound(); void markAll(); void markAllFiles(); void markAllOff(); @@ -79,21 +85,14 @@ public slots: void shellExecute(); void showFilterDialog(); void showHistoryDialog(); + void showPreferenceDialog(); void showSortDialog(); void swapView(); void toggleSearchBox(bool checked); - - - - - void openRequest(const QFileInfo &info); - void showPreferenceDialog(); - void about(); void toggleShowHiddenFiles(bool checked); void toggleShowSystemFiles(bool checked); - void checkUpdate(bool silent = false); - void checkUpdateFinished(QNetworkReply *reply, bool silent = false); - void checkUpdateFinishedSilent(QNetworkReply *reply); + + void openRequest(const QFileInfo &info); void viewFinish(QWidget *sender); private: @@ -109,13 +108,14 @@ private: void setEnabledAllActions(bool enable); void setNameFilters(FolderView *view, const QString& filters = QString()); void setSorting(FolderView *view); + void showNameFilters(FolderView *view); + void copyItems(const QFileInfoList &list, const QString &tgtDir); // getter QLabel* filterLabel(const FolderView *view) const; FolderView* folderView() const; SearchBox* searchBox(FolderView *view) const; - // QWidget interface protected: void closeEvent(QCloseEvent *event); diff --git a/simpletextview.cpp b/simpletextview.cpp index bd105d7..3a3d8f5 100644 --- a/simpletextview.cpp +++ b/simpletextview.cpp @@ -63,7 +63,7 @@ SimpleTextView::SimpleTextView(QWidget *parent) : m_convJIS->setShortcut(QKeySequence("J")); m_convSJIS->setShortcut(QKeySequence("S")); m_convUTF8->setShortcut(QKeySequence("U")); - m_convUTF8->setShortcut(QKeySequence("I")); + m_convUTF16->setShortcut(QKeySequence("I")); m_convUTF16BE->setShortcut(QKeySequence("J")); m_convUTF16LE->setShortcut(QKeySequence("N")); m_back->setShortcut(QKeySequence("Return"));