summaryrefslogtreecommitdiffstats
path: root/archiveviewwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'archiveviewwidget.cpp')
-rw-r--r--archiveviewwidget.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/archiveviewwidget.cpp b/archiveviewwidget.cpp
new file mode 100644
index 0000000..9a0e76e
--- /dev/null
+++ b/archiveviewwidget.cpp
@@ -0,0 +1,96 @@
+/*
+ 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 <QComboBox>
+#include <QLineEdit>
+#include <QLineEdit>
+#include <QLabel>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QPushButton>
+#include <QApplication>
+
+#include "archiveviewwidget.h"
+#include "archivefileview.h"
+#include "moviemodel.h"
+#include "listmodel.h"
+#include "archiveproxy.h"
+
+ArchiveViewWidget::ArchiveViewWidget(MovieModel *model, ListModel *genre, ListModel *actors, QWidget *parent) : QWidget(parent), mMovieModel(model), mGenreModel(genre), mActorsModel(actors){
+ //filter bar
+ QHBoxLayout *filterLayout = new QHBoxLayout;
+ QLabel *l1 = new QLabel(tr("Filter by &genre"));
+ mGenre = new QComboBox;
+ l1->setBuddy(mGenre);
+ mGenre->setModel(mGenreModel);
+ connect(mGenre, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(setGenreFilter(const QString &)));
+ filterLayout->addWidget(l1);
+ filterLayout->addWidget(mGenre);
+ QLabel *l2 = new QLabel(tr("Filter by &actor"));
+ mActors = new QComboBox;
+ mActors->setModel(mActorsModel);
+ connect(mActors, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(setActorFilter(const QString &)));
+ l2->setBuddy(mActors);
+ filterLayout->addWidget(l2);
+ filterLayout->addWidget(mActors);
+ QLabel *l3 = new QLabel(tr("Filter by &title"));
+ mName = new QLineEdit;
+ l3->setBuddy(mName);
+ filterLayout->addWidget(l3);
+ filterLayout->addWidget(mName);
+ mFilter = new QPushButton(tr("Filter"));
+ connect(mFilter, SIGNAL(clicked()), this, SLOT(setFilter()));
+ filterLayout->addWidget(mFilter);
+ mClearFilter = new QPushButton(tr("Clear filter"));
+ filterLayout->addWidget(mClearFilter);
+
+ //treeview
+ mFileView = new ArchiveFileView;
+ mProxy = new ArchiveProxy(this);
+ mProxy->setSourceModel(mMovieModel);
+ mFileView->setModel(mProxy);
+ mFileView->setSortingEnabled(true);
+ mFileView->setItemsExpandable(false);
+ mFileView->setRootIsDecorated(false);
+ connect(mClearFilter, SIGNAL(clicked()), mProxy, SLOT(clearFilter()));
+
+ //main layout
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addLayout(filterLayout);
+ mainLayout->addWidget(mFileView);
+
+ connect(mFileView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex)), this, SLOT(rowChanged(const QModelIndex &, const QModelIndex &)));
+
+ setLayout(mainLayout);
+}
+
+void ArchiveViewWidget::setFilter(){
+ QString filter = mName->text().toLower();
+ if(filter.isEmpty()){
+ return;
+ }
+ mProxy->setFilter(filter, ArchiveProxy::TitleFilter);
+}
+
+void ArchiveViewWidget::setGenreFilter(const QString &filter){
+ mProxy->setFilter(filter, ArchiveProxy::GenreFilter);
+}
+
+void ArchiveViewWidget::setActorFilter(const QString &filter){
+ mProxy->setFilter(filter, ArchiveProxy::ActorFilter);
+}
+
+void ArchiveViewWidget::rowChanged(const QModelIndex &current, const QModelIndex & /*prev*/){
+ if(current.isValid()){
+ QModelIndex idx = current;
+ if(current.column() != 0){
+ idx = mProxy->index(current.row(), 0, current.parent());
+ }
+ QString title = QString(tr("%1 - %2")).arg(qApp->applicationName()).arg(idx.data().toString());
+ emit windowTitle(title);
+ }
+}