diff options
author | Arno <arno@disconnect.de> | 2018-08-26 20:35:23 +0200 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2018-08-26 20:35:23 +0200 |
commit | 68ee6a0ec973940eb4f799b00f6518a902cbc4e5 (patch) | |
tree | 41ddac1434482ae0a20686c8bc8c8231bf9aed36 | |
parent | 1aebcdcc41d60f891a12b70584d3ceb833d5bfdc (diff) | |
download | SheMov-68ee6a0ec973940eb4f799b00f6518a902cbc4e5.tar.gz SheMov-68ee6a0ec973940eb4f799b00f6518a902cbc4e5.tar.bz2 SheMov-68ee6a0ec973940eb4f799b00f6518a902cbc4e5.zip |
Implement custom Video player
Well, well, well. Due to several unforseen circumstances I ventured into
the sources again and implemented a Video player with Qt. Looks very
promising so far. There are some bugs to weed out, but I'm getting
there...
-rw-r--r-- | fswidget.cpp | 27 | ||||
-rw-r--r-- | fswidget.h | 1 | ||||
-rw-r--r-- | shemov.cpp | 1 | ||||
-rw-r--r-- | shemov.pro | 8 | ||||
-rw-r--r-- | smglobals.cpp | 24 | ||||
-rw-r--r-- | smglobals.h | 11 | ||||
-rw-r--r-- | videoviewer.cpp | 54 | ||||
-rw-r--r-- | videoviewer.h | 28 |
8 files changed, 136 insertions, 18 deletions
diff --git a/fswidget.cpp b/fswidget.cpp index c084c12..405d19d 100644 --- a/fswidget.cpp +++ b/fswidget.cpp @@ -19,6 +19,8 @@ #include <QProcess> #include <QSettings> #include <QApplication> +#include <QMediaPlayer> +#include <QMediaPlaylist> #include "fswidget.h" #include "helper.h" @@ -28,6 +30,7 @@ #include "fsproxy.h" #include "smview.h" #include "viewer.h" +#include "videoviewer.h" FSWidget::FSWidget(QWidget *parent) : QWidget(parent) { mMovieWizard = new NewMovieWizard(this); @@ -111,6 +114,8 @@ void FSWidget::setupWidget(){ toolbar->addAction(headerA); toolbar->addSeparator(); toolbar->addAction(SmGlobals::instance()->globalAction()); + QAction *playQtA = new QAction(QIcon(":/bizarre_amputee.png"), tr("Play with QT"), this); + connect(playQtA, &QAction::triggered, this, &FSWidget::playQt); QAction *playSelectedA = new QAction(QIcon(":/spreadingpants.png"), tr("Play selected"), this); connect(playSelectedA, &QAction::triggered, [=] { playSelected(1, QString()); }); playSelectedA->setShortcut(Qt::Key_Return); @@ -191,7 +196,7 @@ void FSWidget::setupWidget(){ mFileView->sortByColumn(0, Qt::AscendingOrder); connect(mFileView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &FSWidget::calculateSelectionChanged); - mFileView->addActions(QList<QAction*>() << playSelectedA << playRepeatMA << mPlayWithA << Helper::createSeparator(this) << backA << forwardA << Helper::createSeparator(this) << refreshA << deleteFilesA << Helper::createSeparator(this) << archiveMovieA << archivePicsA << Helper::createSeparator(this) << unpackA << previewA << selectFilterA << unselectAllA); + mFileView->addActions(QList<QAction*>() << playQtA << playSelectedA << playRepeatMA << mPlayWithA << Helper::createSeparator(this) << backA << forwardA << Helper::createSeparator(this) << refreshA << deleteFilesA << Helper::createSeparator(this) << archiveMovieA << archivePicsA << Helper::createSeparator(this) << unpackA << previewA << selectFilterA << unselectAllA); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(topWL); @@ -582,6 +587,26 @@ void FSWidget::playSelected(int count, QString player){ QProcess::startDetached(playerData.first, args); } +void FSWidget::playQt(){ + QModelIndexList selected = mFileView->selectionModel()->selectedRows(); + if(selected.isEmpty()){ + return; + } + QStringList paths; + for(const QModelIndex &idx : selected){ + paths << idx.data(FullPathRole).toString(); + } + VideoViewer *wv = new VideoViewer; + QMediaPlaylist *pl = wv->player()->playlist(); + pl->clear(); + for(const QString &p : paths){ + pl->addMedia(QUrl::fromLocalFile(p)); + } + pl->setCurrentIndex(0); + wv->setVisible(true); + wv->player()->play(); +} + void FSWidget::selectFilter(){ bool ok; QString retval = QInputDialog::getText(this, tr("File selection by regex!"), tr("Select"), QLineEdit::Normal, "mkv$", &ok); @@ -43,6 +43,7 @@ class FSWidget : public QWidget { void doubleClicked(const QModelIndex &idx); void preview(); void playSelected(int count, QString player); + void playQt(); void selectFilter(); void calculateSelectionChanged(); @@ -190,6 +190,7 @@ void SheMov::closeEvent(QCloseEvent *event){ SmGlobals *globals = SmGlobals::instance(); delete globals; QSqlDatabase::database("treedb").close(); + qApp->closeAllWindows(); event->accept(); } @@ -4,7 +4,7 @@ CONFIG += warn_on \ qt \ debug CONFIG -= release -QT += core gui widgets sql concurrent +QT += core gui widgets sql concurrent multimediawidgets DEFINES += QT_DEPRECATED_WARNINGS SOURCES = main.cpp \ shemov.cpp \ @@ -57,7 +57,8 @@ SOURCES = main.cpp \ mappingeditdialog.cpp \ mappingtreeproxy.cpp \ mappingtreeresultmodel.cpp \ - mappingdata.cpp + mappingdata.cpp \ + videoviewer.cpp HEADERS = \ shemov.h \ helper.h \ @@ -109,7 +110,8 @@ HEADERS = \ mappingeditdialog.h \ mappingtreeproxy.h \ mappingtreeresultmodel.h \ - mappingdata.h + mappingdata.h \ + videoviewer.h LIBS += -lmagic -lXfixes -lX11 -lMagick++-6.Q16HDRI INCLUDEPATH += /usr/include/ImageMagick-6/ RESOURCES = shemov.qrc diff --git a/smglobals.cpp b/smglobals.cpp index 7a909b6..278772e 100644 --- a/smglobals.cpp +++ b/smglobals.cpp @@ -13,6 +13,7 @@ #include "mappingtablemodel.h" #include "mappingtreemodel.h" #include "pictureviewer2.h" +#include "videoviewer.h" #include "picfilesmodel.h" #include "configurationdialog.h" #include "archivebrowsermodel.h" @@ -24,9 +25,12 @@ SmGlobals *SmGlobals::mInstance = nullptr; SmGlobals::~SmGlobals(){ - foreach(QAbstractItemModel *model, mModels.values()){ + for(QAbstractItemModel *model : mModels.values()){ model->deleteLater(); } + for(QWidget *w : mWidgets){ + w->close(); + } } SmGlobals *SmGlobals::instance(){ @@ -99,6 +103,14 @@ PictureViewer2 *SmGlobals::pictureViewer() { return mPictureViewer; } +VideoViewer *SmGlobals::videoViewer() { + if(!mVideoViewer){ + mVideoViewer = new VideoViewer; + mVideoViewer->setHidden(true); + } + return mVideoViewer; +} + QSize SmGlobals::cursorSize() { if(!mCursorSize.isValid()){ Display *dpy = XOpenDisplay(nullptr); @@ -117,7 +129,7 @@ QIcon SmGlobals::iconFor(const QString &type){ return retval; } -SmGlobals::SmGlobals() : mPictureViewer(nullptr), mArchiveController(nullptr){ +SmGlobals::SmGlobals() : mPictureViewer(nullptr), mVideoViewer(nullptr), mArchiveController(nullptr){ mIcons.insert("Dildo", ":/dildo.png"); mIcons.insert("Dick to left", ":/back_dick.png"); mIcons.insert("Dick pointing up", ":/up_dick.png"); @@ -158,14 +170,6 @@ SmGlobals::SmGlobals() : mPictureViewer(nullptr), mArchiveController(nullptr){ mReencReasons = s.value("ui/reasons").toStringList(); } -void SmGlobals::registerWidget(const QString &name, QWidget *w){ - mWidgets.insert(name, w); -} - -QWidget *SmGlobals::getRegisteredWidget(const QString &name){ - return mWidgets.value(name); -} - void SmGlobals::setReencReasons(const QStringList reasons){ mReencReasons = reasons; std::sort(mReencReasons.begin(), mReencReasons.end()); diff --git a/smglobals.h b/smglobals.h index c4eb6c3..83e63be 100644 --- a/smglobals.h +++ b/smglobals.h @@ -15,6 +15,7 @@ class QAbstractItemModel; class PictureViewer2; +class VideoViewer; class QPixmap; class SeriesTreeWidget; class ArchiveController; @@ -37,32 +38,34 @@ class SmGlobals : public QObject { static SmGlobals *instance(); QAbstractItemModel *model(const QString &which); PictureViewer2 *pictureViewer(); + VideoViewer *videoViewer(); void setArchiveController(ArchiveController *c) { mArchiveController = c; } ArchiveController *archiveController() { return mArchiveController; } QSize cursorSize(); QIcon iconFor(const QString &type); const QHash<QString, QString> & icons() const { return mIcons; } QHash<int, QString> filetypeMap() const { return mFiletypeMap; } - void registerWidget(const QString &name, QWidget *w); - QWidget *getRegisteredWidget(const QString &name); void setGlobalAction(QAction *a) { mGlobalActions = a; } QAction *globalAction() { return mGlobalActions; } QStringList reencReasons() const { return mReencReasons; } void setReencReasons(const QStringList reasons); + void addGlobalWidget(QWidget *w) { mWidgets.append(w); } + void removeGlobalWidget(QWidget *w) { mWidgets.removeAll(w); } private: SmGlobals(); SmGlobals(const SmGlobals &other); SmGlobals &operator=(const SmGlobals &other); static SmGlobals *mInstance; - QHash<QString, QAbstractItemModel*> mModels; + QHash<QString, QAbstractItemModel*> mModels; PictureViewer2 *mPictureViewer; + VideoViewer *mVideoViewer; SeriesTreeWidget *mSeriesTreeWidget; QSize mCursorSize; QHash<QString, QString> mIcons; ArchiveController *mArchiveController; QHash<int, QString> mFiletypeMap; - QHash<QString, QWidget*> mWidgets; + QList<QWidget*> mWidgets; QStringList mReencReasons; QAction *mGlobalActions; }; diff --git a/videoviewer.cpp b/videoviewer.cpp new file mode 100644 index 0000000..5430e9f --- /dev/null +++ b/videoviewer.cpp @@ -0,0 +1,54 @@ +/* + 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 <QMediaPlayer> +#include <QMediaPlaylist> +#include <QKeyEvent> +#include <QCloseEvent> + +#include "videoviewer.h" +#include "smglobals.h" + +VideoViewer::VideoViewer(QWidget *parent) : QVideoWidget(parent) { + mPlayer = new QMediaPlayer(this); + mPlayer->setVideoOutput(this); + QMediaPlaylist *playList = new QMediaPlaylist; + mPlayer->setPlaylist(playList); + SmGlobals::instance()->addGlobalWidget(this); +} + +void VideoViewer::keyPressEvent(QKeyEvent *e){ + int keyNum = e->key(); + if(keyNum == Qt::Key_Q){ + close(); + }else if(keyNum == Qt::Key_F){ + setFullScreen(isFullScreen() ? false : true); + }else if(keyNum == Qt::Key_Right){ + mPlayer->setPosition(mPlayer->position() + 5000); + }else if(keyNum == Qt::Key_Left){ + qint64 pos = mPlayer->position(); + mPlayer->setPosition(pos - 5000 < 0 ? 0 : pos - 5000); + }else if(keyNum == Qt::Key_Up){ + mPlayer->setPosition(mPlayer->position() + 60000); + }else if(keyNum == Qt::Key_Down){ + qint64 pos = mPlayer->position(); + mPlayer->setPosition(pos - 60000 < 0 ? 0 : pos - 60000); + }else if(keyNum == Qt::Key_N){ + mPlayer->playlist()->next(); + }else if(keyNum == Qt::Key_P){ + mPlayer->playlist()->previous(); + }else if(keyNum == Qt::Key_M){ + mPlayer->setMuted(mPlayer->isMuted() ? false : true); + } +} + +void VideoViewer::closeEvent(QCloseEvent *e){ + mPlayer->stop(); + SmGlobals::instance()->removeGlobalWidget(this); + deleteLater(); + e->accept(); +} diff --git a/videoviewer.h b/videoviewer.h new file mode 100644 index 0000000..223bc01 --- /dev/null +++ b/videoviewer.h @@ -0,0 +1,28 @@ +/* + 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. +*/ + +#ifndef VIDEOVIEWER_H +#define VIDEOVIEWER_H + +#include <QVideoWidget> + +class QMediaPlayer; + +class VideoViewer : public QVideoWidget { + public: + VideoViewer(QWidget *parent = nullptr); + QMediaPlayer* player() { return mPlayer; } + + protected: + virtual void keyPressEvent(QKeyEvent *e); + virtual void closeEvent(QCloseEvent *e); + + private: + QMediaPlayer *mPlayer; +}; + +#endif // VIDEOVIEWER_H |