diff options
-rw-r--r-- | moviepropertiesdialog.cpp | 56 | ||||
-rw-r--r-- | moviepropertiesdialog.h | 4 | ||||
-rw-r--r-- | shemov.pro | 6 | ||||
-rw-r--r-- | sminputdialog.cpp | 37 | ||||
-rw-r--r-- | sminputdialog.h | 22 |
5 files changed, 123 insertions, 2 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); + } } diff --git a/moviepropertiesdialog.h b/moviepropertiesdialog.h index 2d37b57..75aff95 100644 --- a/moviepropertiesdialog.h +++ b/moviepropertiesdialog.h @@ -7,6 +7,7 @@ class QLineEdit; class QRadioButton; class SmView; class QStandardItemModel; +class SmInputDialog; class MoviePropertiesDialog : public QDialog { public: @@ -18,6 +19,7 @@ class MoviePropertiesDialog : public QDialog { private: void setupDialog(); + void addItem(SmInputDialog *dlg, QStandardItemModel *model, QIcon icon); QLineEdit *mSeriesNameLE; QLineEdit *mSubtitleLE; QLineEdit *mCommentLE; @@ -30,6 +32,8 @@ class MoviePropertiesDialog : public QDialog { SmView *mGenreV; QStandardItemModel *mGenreM; int mSeriesPartsId; + SmInputDialog *mActorDlg; + SmInputDialog *mGenreDlg; }; #endif // MOVIEPROPERTIESDIALOG_H @@ -47,7 +47,8 @@ SOURCES = main.cpp \ viewer.cpp \ moviewidget.cpp \ smview.cpp \ - moviepropertiesdialog.cpp + moviepropertiesdialog.cpp \ + sminputdialog.cpp HEADERS = \ shemov.h \ helper.h \ @@ -89,7 +90,8 @@ HEADERS = \ viewer.h \ moviewidget.h \ smview.h \ - moviepropertiesdialog.h + moviepropertiesdialog.h \ + sminputdialog.h LIBS += -lmagic -lXfixes -lX11 -lMagick++-6.Q16HDRI INCLUDEPATH += /usr/include/ImageMagick-6/ RESOURCES = shemov.qrc diff --git a/sminputdialog.cpp b/sminputdialog.cpp new file mode 100644 index 0000000..6a97ca4 --- /dev/null +++ b/sminputdialog.cpp @@ -0,0 +1,37 @@ +#include <QLabel> +#include <QLineEdit> +#include <QPushButton> +#include <QCompleter> +#include <QHBoxLayout> +#include <QVBoxLayout> + +#include "sminputdialog.h" + +SmInputDialog::SmInputDialog(const QString &label, QWidget *parent) : QDialog(parent){ + QLabel *thisL = new QLabel(label); + mLE = new QLineEdit; + QPushButton *cancelPB = new QPushButton(tr("Cancel")); + connect(cancelPB, &QPushButton::clicked, this, &SmInputDialog::reject); + QPushButton *acceptPB = new QPushButton(tr("OK")); + connect(acceptPB, &QPushButton::clicked, this, &SmInputDialog::accept); + QHBoxLayout *topL = new QHBoxLayout; + topL->addWidget(thisL); + topL->addWidget(mLE); + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addStretch(); + buttonLayout->addWidget(cancelPB); + buttonLayout->addWidget(acceptPB); + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(topL); + mainLayout->addLayout(buttonLayout); + setLayout(mainLayout); +} + +void SmInputDialog::setText(QString &text){ + mLE->setText(text); +} + +void SmInputDialog::setCompleter(QCompleter *completer){ + mLE->completer()->deleteLater(); + mLE->setCompleter(completer); +} diff --git a/sminputdialog.h b/sminputdialog.h new file mode 100644 index 0000000..5b80b9c --- /dev/null +++ b/sminputdialog.h @@ -0,0 +1,22 @@ +#ifndef SMINPUTDIALOG_H +#define SMINPUTDIALOG_H + +#include <QDialog> + +class QLineEdit; +class QCompleter; + +class SmInputDialog : public QDialog { + public: + explicit SmInputDialog(const QString &label, QWidget *parent = nullptr); + void setText(QString &text); + const QString text() const { return mLE->text(); } + void setCompleter(QCompleter *completer); + + private: + void setupDialog(); + QLineEdit *mLE; + QCompleter *mCompleter; +}; + +#endif // SMINPUTDIALOG_H |