diff options
-rw-r--r-- | propertiesdialog.cpp | 39 | ||||
-rw-r--r-- | propertiesdialog.h | 7 | ||||
-rw-r--r-- | seriestreewidget.cpp | 5 | ||||
-rw-r--r-- | smglobals.cpp | 2 | ||||
-rw-r--r-- | smtreemodel.cpp | 6 |
5 files changed, 49 insertions, 10 deletions
diff --git a/propertiesdialog.cpp b/propertiesdialog.cpp index 332105d..485df6b 100644 --- a/propertiesdialog.cpp +++ b/propertiesdialog.cpp @@ -14,6 +14,7 @@ #include <QTreeView> #include <QTabWidget> #include <QPushButton> +#include <QScrollArea> #include "propertiesdialog.h" #include "smtreemodel.h" @@ -41,8 +42,6 @@ void PropertiesDialog::populate(int seriesPartId){ root->appendChild(movieDummy); SmTreeItem *pictureDummy = new SmTreeItem(QList<QVariant>() << "Covers" << -1 << DummyNode, root); root->appendChild(pictureDummy); - SmTreeItem *screenshotDummy = new SmTreeItem(QList<QVariant>() << "Screenshots" << -1 << DummyNode, root); - root->appendChild(screenshotDummy); //populate model QSqlDatabase db = QSqlDatabase::database("treedb"); @@ -52,7 +51,7 @@ void PropertiesDialog::populate(int seriesPartId){ if(filesQuery.exec()){ while(filesQuery.next()){ QList<QVariant> data; - data << filesQuery.value(0) << filesQuery.value(1);// << filesQuery.value(2); + data << filesQuery.value(0) << filesQuery.value(1); if(filesQuery.value(2).toInt() == FilesTreeModel::Movie){ data << MovieFileNode; SmTreeItem *dataItem = new SmTreeItem(data, movieDummy); @@ -67,7 +66,7 @@ void PropertiesDialog::populate(int seriesPartId){ mDisplayModel->setRoot(root); //setup caption - QModelIndex seriesIdx = mSeriesModel->findRecursive(seriesPartId, SeriesTreeModel::SeriesPartId, mSeriesModel->index(0, SeriesTreeModel::SeriesPartId, QModelIndex())); + QModelIndex seriesIdx = mSeriesModel->findRecursive(seriesPartId, SeriesTreeModel::SeriesPartId, QModelIndex()); Q_ASSERT(seriesIdx.isValid()); QString captionString = QString(tr("Properties for %1")).arg(mSeriesModel->index(seriesIdx.row(), SeriesTreeModel::Name, seriesIdx.parent()).data().toString()); mCaption->setText(captionString); @@ -79,6 +78,24 @@ void PropertiesDialog::populate(int seriesPartId){ mFileView->resizeColumnToContents(0); } +void PropertiesDialog::showPicture(QModelIndex current, QModelIndex previous){ + Q_UNUSED(previous); + QModelIndex fileIdIdx = mDisplayModel->index(current.row(), 1, current.parent()); + int fileId = fileIdIdx.data().toInt(); + QModelIndex nodeTypeIdx = mDisplayModel->index(current.row(), 2, current.parent()); + int nodeType = nodeTypeIdx.data().toInt(); + if(nodeType == MovieFileNode){ + QPixmap pic = SmGlobals::instance()->frameCache()->entry(current.data().toString()); + mPictureLabel->setPixmap(pic); + }else if(nodeType == PictureFileNode){ + QModelIndex fileIdx = mFilesModel->findRecursive(fileId, FilesTreeModel::FilesId, mFilesModel->index(0, 0, QModelIndex())); + if(fileIdx.isValid()){ + QString fullPath = fileIdx.data(FilesTreeModel::FullPathRole).toString(); + mPictureLabel->setPixmap(fullPath); + } + } +} + void PropertiesDialog::setupGui(){ //white caption QVBoxLayout *mainLayout = new QVBoxLayout; @@ -94,9 +111,19 @@ void PropertiesDialog::setupGui(){ mTab = new QTabWidget; mFileView = new QTreeView; mFileView->setModel(mDisplayModel); + mFileView->setSelectionBehavior(QAbstractItemView::SelectRows); + mFileView->setSelectionMode(QAbstractItemView::SingleSelection); + connect(mFileView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(showPicture(QModelIndex,QModelIndex))); mSplitter->addWidget(mFileView); - QWidget *dummyTab = new QWidget; - mTab->addTab(dummyTab, "Dummy"); + mPicTab = new QWidget; + QScrollArea *picScroll = new QScrollArea; + mPictureLabel = new QLabel; + //mPictureLabel->setScaledContents(true); + picScroll->setWidget(mPictureLabel); + QHBoxLayout *pictureLayout = new QHBoxLayout; + pictureLayout->addWidget(mPictureLabel); + mPicTab->setLayout(pictureLayout); + mTab->addTab(mPicTab, "Picture"); mSplitter->addWidget(mTab); mSplitter->setStretchFactor(0, 1); mSplitter->setStretchFactor(1, 3); diff --git a/propertiesdialog.h b/propertiesdialog.h index d881ec7..9d23dbd 100644 --- a/propertiesdialog.h +++ b/propertiesdialog.h @@ -8,6 +8,8 @@ #ifndef PROPERTIESDIALOG_H #define PROPERTIESDIALOG_H +#include <QModelIndex> + #include "smdialog.h" class SmTreeModel; @@ -27,6 +29,9 @@ class PropertiesDialog : public SmDialog { virtual ~PropertiesDialog(); void populate(int seriesPartId); + private slots: + void showPicture(QModelIndex current, QModelIndex previous); + private: void setupGui(); SmTreeModel *mDisplayModel; @@ -35,6 +40,8 @@ class PropertiesDialog : public SmDialog { int mCurrentId; QLabel *mCaption; QSplitter *mSplitter; + QWidget *mPicTab; + QLabel *mPictureLabel; QTreeView *mFileView; QTabWidget *mTab; QPushButton *mOk; diff --git a/seriestreewidget.cpp b/seriestreewidget.cpp index 7259157..decdfa4 100644 --- a/seriestreewidget.cpp +++ b/seriestreewidget.cpp @@ -350,9 +350,10 @@ void SeriesTreeWidget::expandItems(const QStringList &items){ void SeriesTreeWidget::editItem(){ QModelIndex current = mView->selectionModel()->currentIndex(); - if(current.data(SeriesTreeModel::TypeRole).toInt() == SeriesTreeModel::Part){ + QModelIndex real = mProxy->mapToSource(current); + if(real.data(SeriesTreeModel::TypeRole).toInt() == SeriesTreeModel::Part){ PropertiesDialog dlg(this); - dlg.populate(current.data(SeriesTreeModel::SeriesPartIdRole).toInt()); + dlg.populate(real.data(SeriesTreeModel::SeriesPartIdRole).toInt()); dlg.exec(); } /*QModelIndex real = mProxy->mapToSource(current); diff --git a/smglobals.cpp b/smglobals.cpp index 62e7537..5f26725 100644 --- a/smglobals.cpp +++ b/smglobals.cpp @@ -1,4 +1,4 @@ -/* + /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version diff --git a/smtreemodel.cpp b/smtreemodel.cpp index 743e8be..50a55d0 100644 --- a/smtreemodel.cpp +++ b/smtreemodel.cpp @@ -139,7 +139,8 @@ QModelIndex SmTreeModel::find(const QVariant &value, int column, const QModelInd QModelIndex SmTreeModel::findRecursive(const QVariant &value, int column, const QModelIndex &parent) const{ SmTreeItem *parentItem = 0; if(!parent.isValid()){ - return QModelIndex(); + //return QModelIndex(); + parentItem = mRootItem; }else{ parentItem = static_cast<SmTreeItem*>(parent.internalPointer()); } @@ -153,6 +154,9 @@ QModelIndex SmTreeModel::findRecursive(const QVariant &value, int column, const } } QModelIndex next = index(parent.row() + 1, column, parent.parent()); + if(!next.isValid()){ + return QModelIndex(); + } return findRecursive(value, column, next); } |