summaryrefslogtreecommitdiffstats
path: root/archiveiteminfoedit.cpp
blob: 70e5afe245e5ef50aa9d0c69badca0a08906e366 (plain)
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
/*
  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 <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QTreeView>
#include <QComboBox>
#include <QSpinBox>
#include <QLineEdit>
#include <QSplitter>
#include <QModelIndex>

#include "archiveiteminfoedit.h"
#include "fileinfomodel.h"
#include "actorwidget.h"
#include "listmodelsingleton.h"
#include "listeditor.h"
#include "moviemodel.h"


ArchiveItemInfoEdit::ArchiveItemInfoEdit(QWidget *parent) : QWidget(parent){
	//Models
	mGenreModel = ListModelSingleton::instance()->model("genre");
	mActorModel = ListModelSingleton::instance()->model("actor");

	//InfoWidget
	QWidget *infoWidget = new QWidget;
	QVBoxLayout *infoWidgetLayout = new QVBoxLayout;

	//Movie Information
	QLabel *infoCaption = new QLabel(tr("Movie Information"));
	infoWidgetLayout->addWidget(infoCaption);
	mInfoView = new QTreeView;
	mInfoModel = new FileInfoModel;
	mInfoView->setModel(mInfoModel);
	infoWidgetLayout->addWidget(mInfoView);

	//Actor Information
	mActorView = new ActorWidget;
	infoWidgetLayout->addWidget(mActorView);

	//Genre Information
	QLabel *genreLabel = new QLabel(tr("Select genre"));
	mGenre = new QComboBox;
	mGenre->setModel(mGenreModel);
	QHBoxLayout *genreLayout = new QHBoxLayout;
	genreLayout->addWidget(genreLabel);
	genreLayout->addWidget(mGenre);
	infoWidgetLayout->addLayout(genreLayout);

	//Quality, Series, Part + DVD Infomation
	QHBoxLayout *miscInfoLayout = new QHBoxLayout;

	//Quality
	QLabel *qualityLabel = new QLabel(tr("Quality"));
	mQuality = new QSpinBox;
	mQuality->setMinimum(0);
	mQuality->setMaximum(10);
	miscInfoLayout->addWidget(qualityLabel);
	miscInfoLayout->addWidget(mQuality);

	//DVD
	QLabel *dvdLabel = new QLabel(tr("DVD no."));
	mDvd = new QSpinBox;
	mDvd->setMinimum(-1);
	mDvd->setMaximum(1000);
	miscInfoLayout->addWidget(dvdLabel);
	miscInfoLayout->addWidget(mDvd);
	miscInfoLayout->addStretch();

	//Series
	QLabel *seriesLabel = new QLabel(tr("Series no."));
	mSeries = new QSpinBox;
	mSeries->setMinimum(-1);
	mSeries->setMaximum(1000);
	miscInfoLayout->addWidget(seriesLabel);
	miscInfoLayout->addWidget(mSeries);

	//Part
	QLabel *partLabel = new QLabel(tr("Part no."));
	mPart = new QSpinBox;
	mPart->setMinimum(-1);
	mPart->setMaximum(100);
	miscInfoLayout->addWidget(partLabel);
	miscInfoLayout->addWidget(mPart);

	//Add to infoWidget
	infoWidgetLayout->addLayout(miscInfoLayout);

	//Title
	QHBoxLayout *titleLayout = new QHBoxLayout;
	QLabel *titleLabel = new QLabel(tr("Movie title"));
	mTitle = new QLineEdit;
	titleLayout->addWidget(titleLabel);
	titleLayout->addWidget(mTitle);
	infoWidgetLayout->addLayout(titleLayout);

	//Create widget
	infoWidget->setLayout(infoWidgetLayout);

	//ListEditorWidget
	QWidget *editorWidget = new QWidget;
	QVBoxLayout *editorWidgetLayout = new QVBoxLayout;

	//GenreEditor
	ListEditor *genreEditor = new ListEditor(mGenreModel);
	editorWidgetLayout->addWidget(genreEditor);

	//ActorEditor
	ListEditor *actorEditor = new ListEditor(mActorModel);
	editorWidgetLayout->addWidget(actorEditor);
	connect(actorEditor, SIGNAL(itemAdded(QString)), this, SLOT(addActor(QString)));
	editorWidgetLayout->addStretch();

	//Create widget
	editorWidget->setLayout(editorWidgetLayout);

	//Splitter
	QSplitter *splitter = new QSplitter;
	splitter->addWidget(infoWidget);
	splitter->addWidget(editorWidget);

	//Create this widget
	QVBoxLayout *mainLayout = new QVBoxLayout;
	mainLayout->addWidget(splitter);
	setLayout(mainLayout);
}

void ArchiveItemInfoEdit::setup(const QModelIndex &idx) {
	//Movie Info
	QString title = QString(idx.data().toString());
	mInfoModel->clear();
	mInfoModel->addIndex(title, idx);
	mInfoView->resizeColumnToContents(0);
	mInfoView->setHeaderHidden(true);
	mInfoView->expandAll();

	//Actors
	mActorView->clear();
	QStringList actors = idx.data(MovieModel::ActorsRole).toStringList();
	qSort(actors);
	foreach(QString a, actors){
		mActorView->addActor(a);
	}
}

const QString ArchiveItemInfoEdit::genre() const {
	return mGenre->currentText();
}

const QString ArchiveItemInfoEdit::title() const {
	return mTitle->text().trimmed().toLower();
}

const QStringList ArchiveItemInfoEdit::actors() const {
	return mActorView->actors();
}

int ArchiveItemInfoEdit::quality() const {
	return mQuality->value();
}

int ArchiveItemInfoEdit::dvd() const {
	return mDvd->value();
}

int ArchiveItemInfoEdit::series() const {
	return mSeries->value();
}

int ArchiveItemInfoEdit::part() const {
	return mPart->value();
}

void ArchiveItemInfoEdit::setGenre(const QString &genre){
	QModelIndex idx = mGenreModel->index(genre);
	if(idx.isValid()){
		mGenre->setCurrentIndex(idx.row());
	}
}

void ArchiveItemInfoEdit::setTitle(const QString &title){
	mTitle->setText(title);
}

void ArchiveItemInfoEdit::setQuality(int quality){
	mQuality->setValue(quality);
}

void ArchiveItemInfoEdit::setDvd(int dvd){
	mDvd->setValue(dvd);
}

void ArchiveItemInfoEdit::setSeries(int series){
	mSeries->setValue(series);
}

void ArchiveItemInfoEdit::setPart(int part){
	mPart->setValue(part);
}

void ArchiveItemInfoEdit::addActor(const QString &actor){
	mActorView->addActor(actor);
}