From f427305bb038ab3af27fb8a1a17827732c3713f3 Mon Sep 17 00:00:00 2001 From: Arno Date: Mon, 22 Aug 2011 16:31:05 +0200 Subject: First draft of PropertiesDialog Kinda mock-up of new PropertiesDialog. The caption label works, though for some reason I can't set a background image via Stylesheets. It also shows the files belonging to the SeriesPart. --- propertiesdialog.cpp | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 propertiesdialog.cpp (limited to 'propertiesdialog.cpp') diff --git a/propertiesdialog.cpp b/propertiesdialog.cpp new file mode 100644 index 0000000..332105d --- /dev/null +++ b/propertiesdialog.cpp @@ -0,0 +1,115 @@ +/* + 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 + 2 of the License, or (at your option) any later version. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "propertiesdialog.h" +#include "smtreemodel.h" +#include "smtreeitem.h" +#include "filestreemodel.h" +#include "seriestreemodel.h" +#include "smglobals.h" + +PropertiesDialog::PropertiesDialog(QWidget *parent, Qt::WindowFlags f) : SmDialog(parent, f), mCurrentId(-1) { + //init model + const QStringList headers = QStringList() << "Name" << "Id" << "NodeType"; + mDisplayModel = new SmTreeModel(headers, this); + mFilesModel = static_cast(SmGlobals::instance()->model("FilesModel")); + mSeriesModel = static_cast(SmGlobals::instance()->model("SeriesModel")); + setupGui(); +} + +PropertiesDialog::~PropertiesDialog() {} + +void PropertiesDialog::populate(int seriesPartId){ + //prepare items + mCurrentId = seriesPartId; + SmTreeItem *root = new SmTreeItem(3); + SmTreeItem *movieDummy = new SmTreeItem(QList() << "Movies" << -1 << DummyNode, root); + root->appendChild(movieDummy); + SmTreeItem *pictureDummy = new SmTreeItem(QList() << "Covers" << -1 << DummyNode, root); + root->appendChild(pictureDummy); + SmTreeItem *screenshotDummy = new SmTreeItem(QList() << "Screenshots" << -1 << DummyNode, root); + root->appendChild(screenshotDummy); + + //populate model + QSqlDatabase db = QSqlDatabase::database("treedb"); + QSqlQuery filesQuery(db); + filesQuery.prepare("SELECT tfilename, ifiles_id, sifiletype FROM files WHERE iseriespart_id = :id"); + filesQuery.bindValue(":id", mCurrentId); + if(filesQuery.exec()){ + while(filesQuery.next()){ + QList data; + data << filesQuery.value(0) << filesQuery.value(1);// << filesQuery.value(2); + if(filesQuery.value(2).toInt() == FilesTreeModel::Movie){ + data << MovieFileNode; + SmTreeItem *dataItem = new SmTreeItem(data, movieDummy); + movieDummy->appendChild(dataItem); + }else{ + data << PictureFileNode; + SmTreeItem *dataItem = new SmTreeItem(data, pictureDummy); + pictureDummy->appendChild(dataItem); + } + } + } + mDisplayModel->setRoot(root); + + //setup caption + QModelIndex seriesIdx = mSeriesModel->findRecursive(seriesPartId, SeriesTreeModel::SeriesPartId, mSeriesModel->index(0, 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); + + //make it usable + mFileView->expandAll(); + mFileView->setColumnHidden(1, true); + mFileView->setColumnHidden(2, true); + mFileView->resizeColumnToContents(0); +} + +void PropertiesDialog::setupGui(){ + //white caption + QVBoxLayout *mainLayout = new QVBoxLayout; + QString topStyleSheet = QString("QFrame#caption { background-color: white; border: 1px solid black; font-weight: bold; padding-left: 10px; padding-top: 4px; padding-bottom: 4px;}"); + mCaption = new QLabel; + mCaption->setFrameShape(QFrame::StyledPanel); + mCaption->setObjectName("caption"); + mCaption->setStyleSheet(topStyleSheet); + mainLayout->addWidget(mCaption); + + //data + QSplitter *mSplitter = new QSplitter; + mTab = new QTabWidget; + mFileView = new QTreeView; + mFileView->setModel(mDisplayModel); + mSplitter->addWidget(mFileView); + QWidget *dummyTab = new QWidget; + mTab->addTab(dummyTab, "Dummy"); + mSplitter->addWidget(mTab); + mSplitter->setStretchFactor(0, 1); + mSplitter->setStretchFactor(1, 3); + mainLayout->addWidget(mSplitter); + + //button bar + QHBoxLayout *buttonLayout = new QHBoxLayout; + mOk = new QPushButton(tr("Ok")); + mCancel = new QPushButton(tr("Cancel")); + buttonLayout->addStretch(); + buttonLayout->addWidget(mOk); + buttonLayout->addWidget(mCancel); + connect(mCancel, SIGNAL(clicked()), this, SLOT(reject())); + mainLayout->addLayout(buttonLayout); + setLayout(mainLayout); +} -- cgit v1.2.3-70-g09d2