summaryrefslogtreecommitdiffstats
path: root/fswidget.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2018-04-02 21:36:19 +0200
committerArno <arno@disconnect.de>2018-04-02 21:37:47 +0200
commit3afe6efd51edaa02a989418c825182f41b7c8ab6 (patch)
treebf0eaa5456d759609c5ce2ef57b77bb84d467bbb /fswidget.cpp
parent096cf7474907cbdd7ab2c67ea57f19ebdab805d4 (diff)
downloadSheMov-3afe6efd51edaa02a989418c825182f41b7c8ab6.tar.gz
SheMov-3afe6efd51edaa02a989418c825182f41b7c8ab6.tar.bz2
SheMov-3afe6efd51edaa02a989418c825182f41b7c8ab6.zip
FSWidget: Implement select and deselect files
Select files by CTRL+k, deselect everything with CTRL+k (for kill). Select all with the global shortcut CTRL+a. Learned some interesting things: First, QAction shortcuts won't work if you don't add them to any actions(), even if it has a parent. So subclass QTreeView for the context menu and add an InvisibleAction enum. Don't show the QAction if it has that flag in data(). This has a nice side effect: the context menu isn't shown any more when you right-click outside the FSView. Second: The debugger was quite confused with equal SLOT names in different classes when using the new connect syntax. It dropped me off in totally wrong classes, confusing me at first, too :(
Diffstat (limited to 'fswidget.cpp')
-rw-r--r--fswidget.cpp36
1 files changed, 28 insertions, 8 deletions
diff --git a/fswidget.cpp b/fswidget.cpp
index 53df90f..8624902 100644
--- a/fswidget.cpp
+++ b/fswidget.cpp
@@ -24,6 +24,7 @@
#include "newmoviewizard.h"
#include "newpicsdialog.h"
#include "fsproxy.h"
+#include "fsview.h"
#include "viewer.h"
FSWidget::FSWidget(QWidget *parent) : QWidget(parent) {
@@ -82,6 +83,14 @@ void FSWidget::setupWidget(){
}
QAction *playRepeatMA = new QAction(tr("Play repeat"), this);
playRepeatMA->setMenu(repeatMenu);
+ QAction *selectFilterA = new QAction(tr("Select by filter..."), this);
+ connect(selectFilterA, &QAction::triggered, this, &FSWidget::selectFilter);
+ selectFilterA->setShortcut(tr("CTRL+j"));
+ selectFilterA->setData(FSView::InvisibleAction);
+ QAction *unselectAllA = new QAction(tr("unselect all..."), this);
+ connect(unselectAllA, &QAction::triggered, [=] { mFileView->selectionModel()->clear(); });
+ unselectAllA->setShortcut(tr("CTRL+k"));
+ unselectAllA->setData(FSView::InvisibleAction);
QIcon plusIcon = Helper::icon(QColor(255,85,255), '+');
QIcon minusIcon = Helper::icon(QColor(255,85,255), '-');
@@ -133,7 +142,7 @@ void FSWidget::setupWidget(){
topWL->addWidget(mFilterCB);
topWL->addWidget(filterTB);
- mFileView = new QTreeView;
+ mFileView = new FSView;
mFileView->setAlternatingRowColors(true);
mFileView->setSortingEnabled(true);
mFileView->setUniformRowHeights(true);
@@ -146,7 +155,7 @@ void FSWidget::setupWidget(){
mFileView->setModel(mProxy);
mFileView->sortByColumn(0, Qt::AscendingOrder);
- addActions(QList<QAction*>() << playSelectedA << playRepeatMA << Helper::createSeparator(this) << backA << forwardA << Helper::createSeparator(this) << refreshA << deleteFilesA << Helper::createSeparator(this) << archiveMovieA << archivePicsA << unpackA << previewA);
+ mFileView->addActions(QList<QAction*>() << playSelectedA << playRepeatMA << Helper::createSeparator(this) << backA << forwardA << Helper::createSeparator(this) << refreshA << deleteFilesA << Helper::createSeparator(this) << archiveMovieA << archivePicsA << unpackA << previewA << selectFilterA << unselectAllA);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topWL);
@@ -160,12 +169,6 @@ FSWidget::~FSWidget(){
writeSettings();
}
-void FSWidget::contextMenuEvent(QContextMenuEvent *e){
- QMenu contextMenu(this);
- contextMenu.addActions(actions());
- contextMenu.exec(e->globalPos());
-}
-
void FSWidget::readSettings(){
QSettings s;
QStringList dirs = s.value("fs/dirs").toStringList();
@@ -522,3 +525,20 @@ void FSWidget::playSelected(int count){
}
QProcess::startDetached(playerData.first, args);
}
+
+void FSWidget::selectFilter(){
+ bool ok;
+ QString retval = QInputDialog::getText(this, tr("File selection by regex!"), tr("Select"), QLineEdit::Normal, "mkv$", &ok);
+ if(!ok){
+ return;
+ }
+ mFileView->selectionModel()->clearSelection();
+ QRegExp re(retval);
+ for(int i = 0; i < mProxy->rowCount(); ++i){
+ QModelIndex nameIdx = mProxy->index(i, 0);
+ if(re.indexIn(nameIdx.data().toString()) != -1){
+ mFileView->selectionModel()->select(nameIdx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
+ }
+ }
+
+}