diff options
author | Arno <arno@disconnect.de> | 2016-11-10 18:10:30 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2016-11-10 18:10:30 +0100 |
commit | aa0cdc4493c0f0435a64cfa8cee010c7659dc8fa (patch) | |
tree | 0b10d02fd9e9b81f06e846aa515245cd5a54b8b6 /randomtab.cpp | |
parent | 54eaa7a4a883978a308d799e1f108bdce5e9c030 (diff) | |
download | SheMov-aa0cdc4493c0f0435a64cfa8cee010c7659dc8fa.tar.gz SheMov-aa0cdc4493c0f0435a64cfa8cee010c7659dc8fa.tar.bz2 SheMov-aa0cdc4493c0f0435a64cfa8cee010c7659dc8fa.zip |
Add Random file browser
Idea: Select random movies based on a selection of genres and actors in
a new tab, so you don't have the agony of choice.
This is just the basic layout. The selectors are filled and the buttons
are connected, but it doesn't select anything yet.
Diffstat (limited to 'randomtab.cpp')
-rw-r--r-- | randomtab.cpp | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/randomtab.cpp b/randomtab.cpp new file mode 100644 index 0000000..c94deec --- /dev/null +++ b/randomtab.cpp @@ -0,0 +1,161 @@ +/* + 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 <QGroupBox> +#include <QIntValidator> +#include <QLineEdit> +#include <QPushButton> +#include <QHBoxLayout> +#include <QVBoxLayout> +#include <QGridLayout> +#include <QSplitter> +#include <QStandardItemModel> +#include <QStandardItem> +#include <QTreeView> +#include <QSortFilterProxyModel> +#include <QSqlQuery> + +#include "randomtab.h" + +RandomTab::RandomTab(QWidget *parent) : QWidget(parent) { + mDb = QSqlDatabase::database("treedb"); + mGenreModel = new QStandardItemModel(this); + mActorModel = new QStandardItemModel(this); + setupModels(); + setupGui(); + clearAll(); +} + +void RandomTab::setupGui(){ + QGroupBox *numBox = new QGroupBox(tr("Select no.")); + mNumber = new QLineEdit; + QIntValidator *numValidator = new QIntValidator(1, 100, this); + mNumber->setValidator(numValidator); + mNumber->setText("10"); + QHBoxLayout *numL = new QHBoxLayout; + numL->addWidget(mNumber); + numBox->setLayout(numL); + + QGroupBox *genreBox = new QGroupBox(tr("Genres")); + mGenre1 = new QComboBox; + mGenre1->setModel(mGenreModel); + mGenre2 = new QComboBox; + mGenre2->setModel(mGenreModel); + mGenre3 = new QComboBox; + mGenre3->setModel(mGenreModel); + QVBoxLayout *genreL = new QVBoxLayout; + genreL->addWidget(mGenre1); + genreL->addWidget(mGenre2); + genreL->addWidget(mGenre3); + genreBox->setLayout(genreL); + + QGroupBox *actorBox = new QGroupBox(tr("Actors")); + mActor1 = new QComboBox; + mActor1->setModel(mActorModel); + mActor2 = new QComboBox; + mActor2->setModel(mActorModel); + mActor3 = new QComboBox; + mActor3->setModel(mActorModel); + QVBoxLayout *actorL = new QVBoxLayout; + actorL->addWidget(mActor1); + actorL->addWidget(mActor2); + actorL->addWidget(mActor3); + actorBox->setLayout(actorL); + + QGroupBox *actionBox = new QGroupBox(tr("Energize!")); + mRefresh = new QPushButton(QIcon(":/refresh.png"), tr("Refresh")); + connect(mRefresh, SIGNAL(clicked()), this, SLOT(refreshComboboxes())); + mClear = new QPushButton(QIcon(":/delete.png"), tr("Clear")); + connect(mClear, SIGNAL(clicked()), this, SLOT(clearAll())); + mSelect = new QPushButton(QIcon(":/huge_bra.png"), tr("Go!")); + connect(mSelect, SIGNAL(clicked()), this, SLOT(select())); + QGridLayout *actionL = new QGridLayout; + actionL->addWidget(mClear, 0, 0); + actionL->addWidget(mRefresh, 0, 1); + actionL->addWidget(mSelect, 1, 0, 2, 0); + actionBox->setLayout(actionL); + + QWidget *leftWidget = new QWidget; + QVBoxLayout *lwL = new QVBoxLayout; + lwL->addWidget(numBox); + lwL->addWidget(genreBox); + lwL->addWidget(actorBox); + lwL->addWidget(actionBox); + lwL->addStretch(); + leftWidget->setLayout(lwL); + + mFileView = new QTreeView; + mFileModel = new QStandardItemModel; + mFileProxy = new QSortFilterProxyModel; + mFileProxy->setSourceModel(mFileModel); + mFileView->setModel(mFileProxy); + + QWidget *rightWidget = new QWidget; + QVBoxLayout *rwL = new QVBoxLayout; + rwL->addWidget(mFileView); + rightWidget->setLayout(rwL); + + QSplitter *leftRightSplitter = new QSplitter(Qt::Horizontal); + leftRightSplitter->addWidget(leftWidget); + leftRightSplitter->addWidget(rightWidget); + leftRightSplitter->setStretchFactor(1, 4); + + QHBoxLayout *mainLayout = new QHBoxLayout; + mainLayout->addWidget(leftRightSplitter); + setLayout(mainLayout); +} + +void RandomTab::setupModels(){ + // Genres + mGenreModel->clear(); + QStandardItem *genreRoot = mGenreModel->invisibleRootItem(); + QStandardItem *noneG = new QStandardItem; + noneG->setText(tr("<none>")); + noneG->setData(-1, IdRole); + genreRoot->appendRow(noneG); + QSqlQuery genQ("SELECT tgenrename, igenres_id FROM genres ORDER BY tgenrename ASC", mDb); + while(genQ.next()){ + QStandardItem *i = new QStandardItem; + i->setText(genQ.value(0).toString()); + i->setData(genQ.value(1), IdRole); + genreRoot->appendRow(i); + } + + // Actors + mActorModel->clear(); + QStandardItem *actorRoot = mActorModel->invisibleRootItem(); + QStandardItem *noneA = new QStandardItem; + noneA->setText(tr("<none>")); + noneA->setData(-1, IdRole); + actorRoot->appendRow(noneA); + QSqlQuery actQ("SELECT tactorname, iactors_id FROM actors ORDER BY tactorname ASC", mDb); + while(actQ.next()){ + QStandardItem *i = new QStandardItem; + i->setText(actQ.value(0).toString()); + i->setData(actQ.value(1), IdRole); + actorRoot->appendRow(i); + } +} + +void RandomTab::clearAll(){ + mGenre1->setCurrentIndex(0); + mGenre2->setCurrentIndex(0); + mGenre3->setCurrentIndex(0); + mActor1->setCurrentIndex(0); + mActor2->setCurrentIndex(0); + mActor3->setCurrentIndex(0); +} + +void RandomTab::refreshComboboxes(){ + setupModels(); + clearAll(); +} + +void RandomTab::select(){ + +} |