summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2013-08-11 08:01:22 +0200
committerArno <am@disconnect.de>2013-08-11 08:01:22 +0200
commit7b374095aaec92e0fb7044550903aa8e10522677 (patch)
tree82fa5c69f56db2a6def9923b50916dabbea53ce8
parentf597c802ab31560bcc200ab068675ecc34f423c9 (diff)
downloadSheMov-7b374095aaec92e0fb7044550903aa8e10522677.tar.gz
SheMov-7b374095aaec92e0fb7044550903aa8e10522677.tar.bz2
SheMov-7b374095aaec92e0fb7044550903aa8e10522677.zip
Implement preview
Show 4 frames of the selected movie in PictureViewer2.
-rw-r--r--archivecontroller.cpp14
-rw-r--r--archivecontroller.h1
-rw-r--r--helper.cpp40
-rw-r--r--helper.h2
-rw-r--r--pictureviewer2.cpp25
-rw-r--r--pictureviewer2.h1
-rw-r--r--shemov.cpp5
-rw-r--r--shemov.h1
8 files changed, 81 insertions, 8 deletions
diff --git a/archivecontroller.cpp b/archivecontroller.cpp
index 4475166..185b770 100644
--- a/archivecontroller.cpp
+++ b/archivecontroller.cpp
@@ -176,6 +176,20 @@ void ArchiveController::showProperties(){
dlg.exec();
}
+void ArchiveController::showPreview(){
+ QModelIndexList sel = mFileSelection->selectedRows(ArchiveFilesModel::FullPath);
+ if(sel.isEmpty()){
+ return;
+ }
+ QModelIndex first = sel.first();
+ QPixmap preview = Helper::preview(first.data().toString());
+ if(!preview.isNull()){
+ PictureViewer2 *pv = SmGlobals::instance()->pictureViewer();
+ pv->setPixmap(preview);
+ pv->show();
+ }
+}
+
void ArchiveController::addActionForTree(QAction *a){
mActionsForTree << a;
mArchiveTree->addAction(a);
diff --git a/archivecontroller.h b/archivecontroller.h
index 2fbde4e..2e8fc22 100644
--- a/archivecontroller.h
+++ b/archivecontroller.h
@@ -52,6 +52,7 @@ class ArchiveController : public QObject {
void editFileType();
void editFileNo();
void showProperties();
+ void showPreview();
void addActionForTree(QAction *a);
void readConfig();
diff --git a/helper.cpp b/helper.cpp
index 3856bfc..348c066 100644
--- a/helper.cpp
+++ b/helper.cpp
@@ -24,6 +24,8 @@
#include <QApplication>
#include <QJsonDocument>
#include <QJsonObject>
+#include <QPainter>
+#include <QDir>
#include <stdio.h>
@@ -250,6 +252,44 @@ namespace Helper {
return QJsonDocument::fromJson(ffData);
}
+ QPixmap preview(const QString &path){
+ QVariantMap m = ffmpegData(path);
+ int secs = m.value("duration").toDouble();
+ int interval = secs / 4;
+ QImage retval(640 * 2 + 40, 480 * 2 + 40, QImage::Format_ARGB32);
+ retval.fill(Qt::transparent);
+ QPainter p(&retval);
+ QImage img1 = snapshot(path, 20);
+ p.drawImage(0, 0, img1);
+ QImage img2 = snapshot(path, interval * 2);
+ p.drawImage(680, 0, img2);
+ QImage img3 = snapshot(path, interval * 3);
+ p.drawImage(0, 520, img3);
+ QImage img4 = snapshot(path, secs - 60);
+ p.drawImage(680, 520, img4);
+ QPixmap pmretval = QPixmap::fromImage(retval);
+ return pmretval;
+ }
+
+ QImage snapshot(const QString &path, int where){
+ QSettings s;
+ QString ffmpeg = s.value("paths/ffmpeg").toString();
+ QStringList args;
+ QTemporaryFile tf;
+ tf.open();
+ args << "-y" << "-ss" << QString::number(where) << "-i" << path << "-f" << "image2" << "-vframes" << "1" << tf.fileName();
+ QProcess ffproc;
+ ffproc.start(ffmpeg, args);
+ if(!ffproc.waitForStarted()){
+ return QImage();
+ }
+ if(ffproc.state() == QProcess::Running){
+ ffproc.waitForFinished();
+ }
+ QImage retval(tf.fileName());
+ return retval.scaledToWidth(640);
+ }
+
Duration::Duration() : mHours(0), mMinutes(0), mSeconds(0) {}
Duration::Duration(qint64 seconds){
diff --git a/helper.h b/helper.h
index 75aa811..4f70854 100644
--- a/helper.h
+++ b/helper.h
@@ -35,6 +35,8 @@ namespace Helper {
void centerWidget(QWidget *widget);
QVariantMap ffmpegData(const QString &path);
QJsonDocument streamData(const QString &path);
+ QPixmap preview(const QString &path);
+ QImage snapshot(const QString &path, int where);
class Duration {
public:
Duration();
diff --git a/pictureviewer2.cpp b/pictureviewer2.cpp
index 7a5ab14..e457865 100644
--- a/pictureviewer2.cpp
+++ b/pictureviewer2.cpp
@@ -5,18 +5,18 @@
2 of the License, or (at your option) any later version.
*/
-#include <QtWidgets/QDesktopWidget>
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QGraphicsScene>
-#include <QtWidgets/QGraphicsPixmapItem>
+#include <QDesktopWidget>
+#include <QApplication>
+#include <QGraphicsScene>
+#include <QGraphicsPixmapItem>
#include <QImage>
#include <QWheelEvent>
#include <QContextMenuEvent>
-#include <QtWidgets/QMenu>
+#include <QMenu>
#include <QTimer>
#include <QDateTime>
#include <QPainter>
-#include <QtWidgets/QStyleOptionGraphicsItem>
+#include <QStyleOptionGraphicsItem>
#include <QSettings>
#include <QTextDocument>
#include <QTextCursor>
@@ -24,9 +24,10 @@
#include <QDir>
#include <QFileInfo>
#include <QFileInfoList>
-#include <QtWidgets/QFileDialog>
+#include <QFileDialog>
#include <QFile>
-#include <QtWidgets/QMessageBox>
+#include <QTemporaryFile>
+#include <QMessageBox>
#include "pictureviewer2.h"
#include "picfilesmodel.h"
@@ -127,6 +128,14 @@ void PictureViewer2::setFile(const QString &fullPath){
setFile(pd);
}
+void PictureViewer2::setPixmap(const QPixmap &pm){
+ //ugly hack, I know....
+ QTemporaryFile tf;
+ QDataStream stream(&tf);
+ stream << pm;
+ setFile(tf.fileName());
+}
+
PicData PictureViewer2::picData(const QString &fullPath){
QFileInfo fi(fullPath);
if(!fi.exists()){
diff --git a/pictureviewer2.h b/pictureviewer2.h
index cfd6ce6..fbda34d 100644
--- a/pictureviewer2.h
+++ b/pictureviewer2.h
@@ -40,6 +40,7 @@ class PictureViewer2 : public QGraphicsView {
void addFiles(const QString &dir, bool clear = true);
void setFile(const PicData &file);
void setFile(const QString &fullPath);
+ void setPixmap(const QPixmap &pm);
PicData picData(const QString &fullPath);
virtual QSize sizeHint() const;
diff --git a/shemov.cpp b/shemov.cpp
index 472b64c..6e47575 100644
--- a/shemov.cpp
+++ b/shemov.cpp
@@ -610,6 +610,9 @@ void SheMov::createActions(){
// show properties
mArchiveFilesPropertiesA = new QAction(tr("Properties..."), this);
connect(mArchiveFilesPropertiesA, SIGNAL(triggered()), c, SLOT(showProperties()));
+ // preview
+ mArchiveFilesPreviewA = new QAction(tr("Preview..."), this);
+ connect(mArchiveFilesPreviewA, SIGNAL(triggered()), c, SLOT(showPreview()));
// db analyzer dialogs
// analyze actors
@@ -796,6 +799,8 @@ void SheMov::createMenus(){
c->archiveFiles()->addAction(mArchiveFilesTypeA);
c->archiveFiles()->addAction(mArchiveFilesFileNoA);
c->archiveFiles()->addAction(createSeparator());
+ c->archiveFiles()->addAction(mArchiveFilesPreviewA);
+ c->archiveFiles()->addAction(createSeparator());
c->archiveFiles()->addAction(mArchiveFilesPropertiesA);
QMenu *archiveFilesM = new QMenu(tr("Files"), this);
archiveFilesM->addActions(c->archiveFiles()->actions());
diff --git a/shemov.h b/shemov.h
index dd085d6..f87f955 100644
--- a/shemov.h
+++ b/shemov.h
@@ -153,6 +153,7 @@ class SheMov : public QMainWindow {
QAction *mArchiveFilesTypeA;
QAction *mArchiveFilesFileNoA;
QAction *mArchiveFilesPropertiesA;
+ QAction *mArchiveFilesPreviewA;
//DB analyze actions
QAction *mAnalyzeActorsA;