/* 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 "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 ¤t, 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); } }