diff options
-rw-r--r-- | archiveviewwidget.cpp | 68 | ||||
-rw-r--r-- | archiveviewwidget.h | 1 |
2 files changed, 36 insertions, 33 deletions
diff --git a/archiveviewwidget.cpp b/archiveviewwidget.cpp index 9be3a10..37eca17 100644 --- a/archiveviewwidget.cpp +++ b/archiveviewwidget.cpp @@ -17,6 +17,8 @@ #include <QSettings> #include <QProcess> +#include <QDebug> + #include "archiveviewwidget.h" #include "archivefileview.h" #include "moviemodel.h" @@ -68,6 +70,8 @@ ArchiveViewWidget::ArchiveViewWidget(MovieModel *model, ListModel *genre, ListMo mFileView->setSortingEnabled(true); mFileView->setItemsExpandable(false); mFileView->setRootIsDecorated(false); + mFileView->setSelectionBehavior(QAbstractItemView::SelectRows); + mFileView->setSelectionMode(QAbstractItemView::ExtendedSelection); mFileView->setColumnHidden(MovieItem::Md5Sum, true); connect(mClearFilter, SIGNAL(clicked()), mProxy, SLOT(clearFilter())); connect(mMovieModel, SIGNAL(moviesChanged()), mProxy, SLOT(invalidate())); @@ -77,34 +81,26 @@ ArchiveViewWidget::ArchiveViewWidget(MovieModel *model, ListModel *genre, ListMo mainLayout->addLayout(filterLayout); mainLayout->addWidget(mFileView); - connect(mFileView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex)), this, SLOT(rowChanged(const QModelIndex &, const QModelIndex &))); + connect(mFileView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex)), this, SLOT(rowChanged(const QModelIndex &, const QModelIndex &))); connect(mFileView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(showMovie(const QModelIndex &))); setLayout(mainLayout); } void ArchiveViewWidget::editFile(){ - QModelIndexList selected = mFileView->selectionModel()->selectedRows(); - if(!selected.isEmpty()){ - QModelIndex idx = selected.at(0); - QModelIndex real = mProxy->mapToSource(idx); - mEditDialog->setMovie(real); - mEditDialog->show(); - mEditDialog->raise(); - mEditDialog->activateWindow(); - } + QModelIndex real = getSourceColumnZero(); + mEditDialog->setMovie(real); + mEditDialog->show(); + mEditDialog->raise(); + mEditDialog->activateWindow(); } void ArchiveViewWidget::editCovers(){ - QModelIndexList selected = mFileView->selectionModel()->selectedRows(); - if(!selected.isEmpty()){ - QModelIndex idx = selected.at(0); - QModelIndex real = mProxy->mapToSource(idx); - mCoverEditDialog->setMovie(real); - mCoverEditDialog->show(); - mCoverEditDialog->raise(); - mCoverEditDialog->activateWindow(); - } + QModelIndex real = getSourceColumnZero(); + mCoverEditDialog->setMovie(real); + mCoverEditDialog->show(); + mCoverEditDialog->raise(); + mCoverEditDialog->activateWindow(); } void ArchiveViewWidget::addMovie(){ @@ -153,12 +149,7 @@ void ArchiveViewWidget::showMovie(const QModelIndex &movie){ } void ArchiveViewWidget::properties(){ - QModelIndexList selected = fileView()->selectionModel()->selectedRows(); - if(selected.isEmpty()){ - return; - } - QModelIndex idx = selected.at(0); - QModelIndex real = mProxy->mapToSource(idx); + QModelIndex real = getSourceColumnZero(); int movid = real.data(MovieModel::IdRole).toInt(); MoviePropertiesDialog dlg(movid, this); dlg.exec(); @@ -180,13 +171,24 @@ void ArchiveViewWidget::setActorFilter(const QString &filter){ mProxy->setFilter(filter, ArchiveProxy::ActorFilter); } -void ArchiveViewWidget::rowChanged(const QModelIndex ¤t, const QModelIndex & /*prev*/){ - if(current.isValid()){ - QModelIndex idx = current; - if(current.column() != 0){ - idx = mProxy->index(current.row(), 0, current.parent()); - } - QString title = QString(tr("%1 - %2")).arg(qApp->applicationName()).arg(idx.data().toString()); - emit windowTitle(title); +void ArchiveViewWidget::rowChanged(const QModelIndex &/*current*/, const QModelIndex & /*prev*/){ + QModelIndex idx = getSourceColumnZero(); + QString title = QString(tr("%1 - %2")).arg(qApp->applicationName()).arg(idx.data().toString()); + emit windowTitle(title); +} + +const QModelIndex ArchiveViewWidget::getSourceColumnZero(){ + QModelIndex retval; + QModelIndex idx = mFileView->currentIndex(); + if(idx.column() != 0){ + idx = mProxy->index(idx.row(), 0); } + QModelIndex real = mProxy->mapToSource(idx); + if(real.column() != 0){ + retval = mMovieModel->index(real.row(), 0); + }else{ + retval = real; + } + return retval; } + diff --git a/archiveviewwidget.h b/archiveviewwidget.h index 1e7e06a..fd2cf55 100644 --- a/archiveviewwidget.h +++ b/archiveviewwidget.h @@ -50,6 +50,7 @@ class ArchiveViewWidget : public QWidget { void rowChanged(const QModelIndex ¤t, const QModelIndex &prev); private: + const QModelIndex getSourceColumnZero(); QComboBox *mGenre; QComboBox *mActors; QLineEdit *mName; |