diff options
author | Arno <am@disconnect.de> | 2010-07-24 17:15:00 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-07-24 17:15:00 +0200 |
commit | ad322157891cec53a7b660629d7c244e75df81d5 (patch) | |
tree | 0ffbc54d683f6e8c4925b669bb1732ac52cae0de /filestreewidget.cpp | |
parent | b465c59cce7418968f268b9888a8236be281fda5 (diff) | |
download | SheMov-ad322157891cec53a7b660629d7c244e75df81d5.tar.gz SheMov-ad322157891cec53a7b660629d7c244e75df81d5.tar.bz2 SheMov-ad322157891cec53a7b660629d7c244e75df81d5.zip |
Act on doubleClick in FileTreeWidget
When doubleclicking a picture in FileTreeWidget the pictureViewer
is shown. Doubleclicking a movie file launches the default movie
player.
Since PictureViewer is now used in FileSystemWidget and
ArchiveTreeView a global instance is needed. The appropriate place
for this is a singleton. Since we already had a singleton for
QAbstractItemModels I renamed it to SmGlobals and added a function
to return a PictureViewer object. Renaming it was quite easy
thanks to QtCreator's ability to rename variable names.
Diffstat (limited to 'filestreewidget.cpp')
-rw-r--r-- | filestreewidget.cpp | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/filestreewidget.cpp b/filestreewidget.cpp index 89de946..2d41e34 100644 --- a/filestreewidget.cpp +++ b/filestreewidget.cpp @@ -16,20 +16,22 @@ #include <QLabel> #include <QSpinBox> #include <QPushButton> +#include <QProcess> #include <QDebug> #include "filestreewidget.h" -#include "smmodelsingleton.h" +#include "smglobals.h" #include "filestreemodel.h" #include "seriestreemodel.h" #include "helper.h" +#include "pictureviewer.h" FilesTreeWidget::FilesTreeWidget(QWidget *parent) : QWidget(parent), mSelectedSize(0){ //the view mView = new FilesTreeView; mView->setSelectionMode(QAbstractItemView::ExtendedSelection); - mModel = static_cast<FilesTreeModel*>(SmModelSingleton::instance()->model("FilesModel")); + mModel = static_cast<FilesTreeModel*>(SmGlobals::instance()->model("FilesModel")); mProxy = new FilesTreeSortModel(this); mProxy->setSourceModel(mModel); mView->setModel(mProxy); @@ -37,14 +39,16 @@ FilesTreeWidget::FilesTreeWidget(QWidget *parent) : QWidget(parent), mSelectedSi QItemSelectionModel *selModel = mView->selectionModel(); connect(selModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(fileSelectionChanged(QModelIndex,QModelIndex))); connect(selModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(fileSelectionChanged(QItemSelection,QItemSelection))); + connect(mView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(itemDoubleClicked(QModelIndex))); //layout QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(mView); setLayout(mainLayout); - //series model - mSeriesModel = static_cast<SeriesTreeModel*>(SmModelSingleton::instance()->model("SeriesModel")); + //globals + mSeriesModel = static_cast<SeriesTreeModel*>(SmGlobals::instance()->model("SeriesModel")); + mPictureViewer = SmGlobals::instance()->pictureViewer(); } void FilesTreeWidget::moveToBurn(){ @@ -149,6 +153,31 @@ void FilesTreeWidget::fileSelectionChanged(const QModelIndex ¤t, const QMo } } +void FilesTreeWidget::itemDoubleClicked(const QModelIndex &index){ + int dvdNo = index.data(FilesTreeModel::DvdNoRole).toInt(); + if(dvdNo != -1){ + QString msg = QString(tr("%1 is archived on DVD %2.")).arg(index.data().toString()).arg(QString::number(index.data(FilesTreeModel::DvdNoRole).toInt())); + QMessageBox::critical(this, tr("Error"), msg); + return; + } + QString file = index.data(FilesTreeModel::FullPathRole).toString(); + QString mimeType = Helper::mimeType(file); + if(mimeType.startsWith("image")){ + mPictureViewer->showPic(file); + return; + }else{ + QPair<QString, QStringList> data = Helper::programData("movieviewer", QString()); + if(data.first.isEmpty()){ + QMessageBox::critical(this, tr("Error"), tr("No viedeo viewer configured.")); + return; + } + QString program = data.first; + QStringList args = data.second; + args << file; + QProcess::startDetached(program, args); + } +} + void FilesTreeWidget::fileSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected){ QModelIndexList sel = selected.indexes(); QModelIndexList desel = deselected.indexes(); @@ -199,7 +228,7 @@ DvdNoDialog::DvdNoDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f spinBoxLayout->addWidget(l1); spinBoxLayout->addWidget(mDvdNo); mDvdNo->setMinimum(-1); - SeriesTreeModel *seriesModel = static_cast<SeriesTreeModel*>(SmModelSingleton::instance()->model("SeriesModel")); + SeriesTreeModel *seriesModel = static_cast<SeriesTreeModel*>(SmGlobals::instance()->model("SeriesModel")); int nextDvdNo = seriesModel->findNextDvdNo(); mDvdNo->setValue(nextDvdNo); |