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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/*
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 <QHBoxLayout>
#include <QVBoxLayout>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QPushButton>
#include <QLabel>
#include <QSqlQuery>
#include <QFileInfo>
#include <QFont>
#include <QApplication>
#include <QGridLayout>
#include <QLocale>
#include <QGraphicsTextItem>
#include <QGraphicsPixmapItem>
#include <QPixmap>
#include <QTreeView>
#include "moviepropertiesdialog.h"
#include "actormodel.h"
#include "helper.h"
MoviePropertiesDialog::MoviePropertiesDialog(int movid, QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f), mId(movid), mIndex(-1){
//gather data
covers();
QSqlQuery q1;
q1.prepare("SELECT ttitle, tfilename, cmd5sum, bisize, genre.tgenrename, iquality, idvd FROM movies, genre WHERE movies.igenreid = genre.igenreid AND movies.imovid = :id");
q1.bindValue(":id", mId);
q1.exec();
QString title, filename, md5, genre;
quint64 size(0);
qint32 quality, dvd;
quality = dvd = 0;
q1.exec();
while(q1.next()){
title = q1.value(0).toString();
filename = q1.value(1).toString();
md5 = q1.value(2).toString();
genre = q1.value(4).toString();
size = q1.value(3).toLongLong();
quality = q1.value(5).toInt();
dvd = q1.value(6).toInt();
}
//QStringList actors;
mActorModel = new ActorModel;
QSqlQuery q2;
q2.prepare("SELECT tactorname FROM actor, movieactormap WHERE movieactormap.iactorid = actor.iactorid AND movieactormap.imovid = :id");
q2.bindValue(":id", mId);
q2.exec();
while(q2.next()){
//actors << q2.value(0).toString();
mActorModel->addItem(q2.value(0));
}
//layout
QVBoxLayout *mainLayout = new QVBoxLayout;
mView = new QGraphicsView;
mScene = new QGraphicsScene(this);
mView->setScene(mScene);
mainLayout->addWidget(mView);
//cover buttons
QHBoxLayout *buttonPicLayout = new QHBoxLayout;
mPrev = new QPushButton(tr("Previous"));
connect(mPrev, SIGNAL(clicked()), this, SLOT(previousCover()));
mNext = new QPushButton(tr("Next"));
connect(mNext, SIGNAL(clicked()), this, SLOT(nextCover()));
buttonPicLayout->addWidget(mPrev);
buttonPicLayout->addStretch();
buttonPicLayout->addWidget(mNext);
mainLayout->addLayout(buttonPicLayout);
//actors
mActors = new QTreeView;
mActors->setRootIsDecorated(false);
mActors->setHeaderHidden(true);
mActors->setModel(mActorModel);
//properties
QGridLayout *propertiesGrid = new QGridLayout;
QFont font = qApp->font();
font.setWeight(QFont::Bold);
QLabel *l1 = new QLabel("Genre");
l1->setFont(font);
QLabel *l2 = new QLabel(genre);
propertiesGrid->addWidget(l1, 0, 0);
propertiesGrid->addWidget(l2, 0, 1);
QLabel *l3 = new QLabel(tr("Title"));
l3->setFont(font);
QLabel *l4 = new QLabel(title);
propertiesGrid->addWidget(l3, 1, 0);
propertiesGrid->addWidget(l4, 1, 1);
QLabel *l5 = new QLabel(tr("Filename"));
l5->setFont(font);
QLabel *l6 = new QLabel(filename);
propertiesGrid->addWidget(l5, 2, 0);
propertiesGrid->addWidget(l6, 2, 1);
QLabel *l7 = new QLabel(tr("MD5"));
l7->setFont(font);
QLabel *l8 = new QLabel(md5);
propertiesGrid->addWidget(l7, 3, 0);
propertiesGrid->addWidget(l8, 3, 1);
QLabel *l9 = new QLabel(tr("Size"));
l9->setFont(font);
QLocale l;
QLabel *l10 = new QLabel(l.toString(size));
propertiesGrid->addWidget(l9, 4, 0);
propertiesGrid->addWidget(l10, 4, 1);
QLabel *l11 = new QLabel(tr("Quality"));
l11->setFont(font);
QLabel *l12 = new QLabel(QString::number(quality));
propertiesGrid->addWidget(l11, 5, 0);
propertiesGrid->addWidget(l12, 5, 1);
QLabel *l13 = new QLabel(tr("Archived"));
l13->setFont(font);
QLabel *l14 = new QLabel;
if(dvd < 0){
l14->setText(tr("No - local"));
}else{
QString s = QString(tr("On DVD #%1")).arg(QString::number(dvd));
l14->setText(s);
}
propertiesGrid->addWidget(l13, 6, 0);
propertiesGrid->addWidget(l14, 6, 1);
QHBoxLayout *actorsPropertiesLayout = new QHBoxLayout;
actorsPropertiesLayout->addWidget(mActors);
actorsPropertiesLayout->addLayout(propertiesGrid);
mainLayout->addLayout(actorsPropertiesLayout);
//close button
mClose = new QPushButton(tr("Close"));
connect(mClose, SIGNAL(clicked()), this, SLOT(reject()));
QHBoxLayout *closeButtonLayout = new QHBoxLayout;
closeButtonLayout->addStretch();
closeButtonLayout->addWidget(mClose);
closeButtonLayout->addStretch();
mainLayout->addLayout(closeButtonLayout);
setLayout(mainLayout);
QString winTitle = QString("%1 - Properties of %2").arg(qApp->applicationName()).arg(title);
setWindowTitle(winTitle);
if(!mCovers.isEmpty()){
mIndex = 0;
}
setCover(mIndex);
}
MoviePropertiesDialog::~MoviePropertiesDialog() {
delete mActorModel;
}
void MoviePropertiesDialog::setCover(int index){
mScene->clear();
if((index < 0) || (index >= mCovers.size())){
QGraphicsTextItem *item = new QGraphicsTextItem(tr("No covers"));
QFont font = QFont("Courier new", 30 , QFont::Bold);
item->setFont(font);
item->setDefaultTextColor(Qt::red);
item->rotate(45);
mScene->addItem(item);
item->setPos(0, 0);
mNext->setEnabled(false);
mPrev->setEnabled(false);
}else{
QPixmap pm(mCovers.at(index));
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pm);
mScene->addItem(item);
item->setPos(0, 0);
}
}
void MoviePropertiesDialog::nextCover(){
if(mIndex < 0){
return;
}
++mIndex;
if(mIndex >= mCovers.size()){
mIndex = 0;
}
setCover(mIndex);
}
void MoviePropertiesDialog::previousCover(){
if(mIndex < 0){
return;
}
--mIndex;
if(mIndex < 0){
mIndex = mCovers.size() - 1;
}
setCover(mIndex);
}
void MoviePropertiesDialog::covers(){
QSqlQuery q;
q.prepare("SELECT tfilename, cmd5sum FROM covers WHERE imovid = :id");
q.bindValue(":id", mId);
q.exec();
while(q.next()){
QString path = Helper::createArchivePath(q.value(0).toString(), q.value(1).toString());
QFileInfo fi(path);
if(fi.exists()){
mCovers << path;
}
}
}
|