[vlmc-devel] Add ThumbnailImageProvider

Yikai Lu git at videolan.org
Tue Aug 16 03:37:02 CEST 2016


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Mon Aug 15 20:21:45 2016 -0500| [96f5e67fb85f25fb910a5cecd7016f2953fd4c7b] | committer: Yikai Lu

Add ThumbnailImageProvider

> https://code.videolan.org/videolan/vlmc/commit/96f5e67fb85f25fb910a5cecd7016f2953fd4c7b
---

 Makefile.am                                 |  3 ++
 src/Gui/timeline/ThumbnailImageProvider.cpp | 47 +++++++++++++++++++++++++++++
 src/Gui/timeline/ThumbnailImageProvider.h   | 27 +++++++++++++++++
 3 files changed, 77 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index b3ec9e1..bad43f2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -209,6 +209,7 @@ vlmc_SOURCES += \
 	src/Gui/settings/SettingsDialog.cpp \
 	src/Gui/settings/StringWidget.cpp \
 	src/Gui/timeline/Timeline.cpp \
+	src/Gui/timeline/ThumbnailImageProvider.cpp \
 	src/Gui/widgets/ExtendedLabel.cpp \
 	src/Gui/widgets/FramelessButton.cpp \
 	src/Gui/widgets/NotificationZone.cpp \
@@ -249,6 +250,7 @@ vlmc_SOURCES += \
 	src/Gui/wizard/firstlaunch/Done.h \
 	src/Gui/wizard/OpenPage.h \
 	src/Gui/timeline/Timeline.h \
+	src/Gui/timeline/ThumbnailImageProvider.h \
 	src/Gui/About.h \
 	src/Gui/LanguageHelper.h \
 	src/Gui/library/ListViewController.h \
@@ -317,6 +319,7 @@ nodist_vlmc_SOURCES += \
 	src/Gui/preview/PreviewRuler.moc.cpp \
 	src/Gui/settings/PreferenceWidget.moc.cpp \
 	src/Gui/timeline/Timeline.moc.cpp \
+	src/Gui/timeline/ThumbnailImageProvider.moc.cpp \
 	src/Gui/settings/LanguageWidget.moc.cpp \
 	src/Gui/import/TagWidget.moc.cpp \
 	src/Gui/widgets/NotificationZone.moc.cpp \
diff --git a/src/Gui/timeline/ThumbnailImageProvider.cpp b/src/Gui/timeline/ThumbnailImageProvider.cpp
new file mode 100644
index 0000000..ed0e42b
--- /dev/null
+++ b/src/Gui/timeline/ThumbnailImageProvider.cpp
@@ -0,0 +1,47 @@
+#include "ThumbnailImageProvider.h"
+
+#include "Workflow/MainWorkflow.h"
+#include "Main/Core.h"
+
+ThumbnailImageProvider::ThumbnailImageProvider()
+    : QQuickImageProvider( QQuickImageProvider::Pixmap )
+{
+    connect( Core::instance()->workflow(), &MainWorkflow::thumbnailUpdated, this, [this]
+             ( const QString& uuid, quint32 pos, const QPixmap& pixmap )
+    {
+        auto id = uuid + "/" + QString::number( pos );
+
+        auto it = m_pixMap.find( id );
+        if ( it == m_pixMap.end() )
+            m_pixMap.insert( id, pixmap );
+
+        emit imageReady( uuid, pos );
+    }, Qt::DirectConnection );
+}
+
+QPixmap
+ThumbnailImageProvider::requestPixmap( const QString& id, QSize* size, const QSize& requestedSize )
+{
+    QString tmp = id;
+    tmp.replace( "%7B", "{" );
+    tmp.replace( "%7D", "}" );
+
+    auto it = m_pixMap.find( tmp );
+    if ( it == m_pixMap.end() )
+    {
+        *size = QSize( requestedSize.width(), requestedSize.height() );
+        return QPixmap( requestedSize );
+    }
+
+    auto pixmap = it.value();
+    *size = pixmap.size();
+    if ( requestedSize.isValid() == true )
+        return pixmap.scaled( requestedSize );
+    return pixmap;
+}
+
+bool
+ThumbnailImageProvider::hasImage( const QString& uuid, quint32 pos )
+{
+    return m_pixMap.find( uuid + "/" + QString::number( pos ) ) != m_pixMap.end();
+}
diff --git a/src/Gui/timeline/ThumbnailImageProvider.h b/src/Gui/timeline/ThumbnailImageProvider.h
new file mode 100644
index 0000000..2233e45
--- /dev/null
+++ b/src/Gui/timeline/ThumbnailImageProvider.h
@@ -0,0 +1,27 @@
+#ifndef THUMBNAILIMAGEPROVIDER_H
+#define THUMBNAILIMAGEPROVIDER_H
+
+#include <QMap>
+#include <QQuickImageProvider>
+
+class ThumbnailImageProvider : public QObject, public QQuickImageProvider
+{
+    Q_OBJECT
+
+public:
+    ThumbnailImageProvider();
+
+    virtual QPixmap requestPixmap( const QString& id, QSize* size, const QSize& requestedSize ) override;
+
+public slots:
+    bool    hasImage( const QString& uuid, quint32 pos );
+
+signals:
+    void    imageReady( const QString& uuid, quint32 pos );
+
+private:
+    // uuid/pos, pixmap
+    QMap<QString, QPixmap>  m_pixMap;
+};
+
+#endif // THUMBNAILIMAGEPROVIDER_H



More information about the Vlmc-devel mailing list