Commit 96f5e67f authored by luyikei's avatar luyikei

Add ThumbnailImageProvider

parent 367fecdf
......@@ -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 \
......
#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();
}
#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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment