1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/*
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 <QSqlDatabase>
#include <QSqlQuery>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSplitter>
#include <QTreeView>
#include <QTabWidget>
#include <QPushButton>
#include <QScrollArea>
#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<FilesTreeModel*>(SmGlobals::instance()->model("FilesModel"));
mSeriesModel = static_cast<SeriesTreeModel*>(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<QVariant>() << "Movies" << -1 << DummyNode, root);
root->appendChild(movieDummy);
SmTreeItem *pictureDummy = new SmTreeItem(QList<QVariant>() << "Covers" << -1 << DummyNode, root);
root->appendChild(pictureDummy);
//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<QVariant> data;
data << filesQuery.value(0) << filesQuery.value(1);
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, 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::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;
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);
mFileView->setSelectionBehavior(QAbstractItemView::SelectRows);
mFileView->setSelectionMode(QAbstractItemView::SingleSelection);
connect(mFileView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(showPicture(QModelIndex,QModelIndex)));
mSplitter->addWidget(mFileView);
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);
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);
}
|