diff options
Diffstat (limited to 'moviepropertiesdialog.cpp')
-rw-r--r-- | moviepropertiesdialog.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/moviepropertiesdialog.cpp b/moviepropertiesdialog.cpp index 64a21ac..92b8a0c 100644 --- a/moviepropertiesdialog.cpp +++ b/moviepropertiesdialog.cpp @@ -6,7 +6,9 @@ #include <QSqlDatabase> #include <QSqlQuery> #include <QIntValidator> +#include <QCompleter> #include <QStandardItemModel> +#include <QAction> #include <QGridLayout> #include <QHBoxLayout> #include <QVBoxLayout> @@ -14,8 +16,11 @@ #include "moviepropertiesdialog.h" #include "smview.h" +#include "sminputdialog.h" MoviePropertiesDialog::MoviePropertiesDialog(QWidget *parent) : QDialog(parent){ + mActorDlg = new SmInputDialog(tr("Actor"), this); + mGenreDlg = new SmInputDialog(tr("Genre"), this); setupDialog(); } @@ -64,6 +69,10 @@ void MoviePropertiesDialog::setupDialog(){ mActorV->setAlternatingRowColors(true); mActorM = new QStandardItemModel; mActorV->setModel(mActorM); + QAction *addActorA = new QAction(QIcon(":/spreadingpants.png"), tr("Add actor..."), this); + connect(addActorA, &QAction::triggered, [=] { addItem(mActorDlg, mActorM, QIcon(":/diaper.png")); }); + QAction *removeActorA = new QAction(QIcon(":/delete.png"), tr("Remove actor"), this); + mActorV->addActions(QList<QAction*>() << addActorA << removeActorA); QGroupBox *actorsGB = new QGroupBox(tr("Actors")); QHBoxLayout *actorsGBL = new QHBoxLayout; actorsGBL->addWidget(mActorV); @@ -73,6 +82,10 @@ void MoviePropertiesDialog::setupDialog(){ mGenreV->setAlternatingRowColors(true); mGenreM = new QStandardItemModel; mGenreV->setModel(mGenreM); + QAction *addGenreA = new QAction(QIcon(":/spreadingpants.png"), tr("Add genre..."), this); + connect(addGenreA, &QAction::triggered, [=] { addItem(mGenreDlg, mGenreM, QIcon(":/dick_in_cage.png")); }); + QAction *removeGenreA = new QAction(QIcon(":/delete.png"), tr("Remove genre"), this); + mGenreV->addActions(QList<QAction*>() << addGenreA << removeGenreA); QGroupBox *genresGB = new QGroupBox(tr("Genres")); QHBoxLayout *genresGBL = new QHBoxLayout; genresGBL->addWidget(mGenreV); @@ -147,5 +160,48 @@ void MoviePropertiesDialog::init(int seriesPartsId){ i->setData(genresQ.value(1), GenreIdRole); genresRootItem->appendRow(i); } + QStringList seriesNames; + QSqlQuery allSeriesNamesQ("SELECT tseries_name FROM series", db); + while(allSeriesNamesQ.next()){ + seriesNames << allSeriesNamesQ.value(0).toString(); + } + QCompleter *snCompleter = new QCompleter(seriesNames); + mSeriesNameLE->setCompleter(snCompleter); + QStringList actorNames; + QSqlQuery allActorsQ("SELECT tactorname FROM actors", db); + while(allActorsQ.next()){ + actorNames << allActorsQ.value(0).toString(); + } + QCompleter *actorCompleter = new QCompleter(actorNames, mActorDlg); + mActorDlg->setCompleter(actorCompleter); + QStringList genreNames; + QSqlQuery allGenresQ("SELECT tgenrename FROM genres", db); + while(allGenresQ.next()){ + genreNames << allGenresQ.value(0).toString(); + } + QCompleter *genreCompleter = new QCompleter(genreNames, mGenreDlg); + mGenreDlg->setCompleter(genreCompleter); +} +void MoviePropertiesDialog::addItem(SmInputDialog *dlg, QStandardItemModel *model, QIcon icon){ + int retval = dlg->exec(); + if(retval == QDialog::Accepted){ + QString itemName = dlg->text().toLower(); + int idx = 0; + while(idx != model->rowCount()){ + QStandardItem *curItem = model->item(idx, 0); + if(curItem->text() == itemName){ + return; + } + if(curItem->text() > itemName){ + break; + } + ++idx; + } + QStandardItem *newItem = new QStandardItem; + newItem->setEditable(false); + newItem->setIcon(icon); + newItem->setText(itemName); + model->insertRow(idx, newItem); + } } |