Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Commit

Permalink
Snapshot feature supported only with Qt >= 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
RSATom committed May 25, 2015
1 parent 174279f commit 5e591aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/QmlChimera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
#include <QDir>
#include <QTextCodec>
#include <QtQml>

#ifdef SNAPSHOT_ENABLED
#include <QQuickItemGrabResult>
#endif

#include <QmlVlc/QmlVlc.h>

Expand Down Expand Up @@ -220,15 +223,20 @@ void QmlChimera::goHome()

void QmlChimera::takeSnapshot( QQuickItem* item )
{
#ifdef SNAPSHOT_ENABLED
m_itemGrabResult = item->grabToImage();
if( m_itemGrabResult ) {
connect( m_itemGrabResult.data(), &QQuickItemGrabResult::ready,
this, &QmlChimera::grabResultReady );
}
#else
qWarning( "Snapshot feature does not supported by used Qt version" );
#endif
}

void QmlChimera::grabResultReady()
{
#ifdef SNAPSHOT_ENABLED
QImage snapshot = m_itemGrabResult->image();

QByteArray snapshotData;
Expand All @@ -239,4 +247,5 @@ void QmlChimera::grabResultReady()
m_itemGrabResult.reset();

Q_EMIT snapshotReady( QString::fromLatin1( snapshotData.toBase64() ) );
#endif
}
6 changes: 6 additions & 0 deletions src/QmlChimera.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

#include "Chimera.h"

#if ( QT_VERSION >= QT_VERSION_CHECK( 5, 4, 0 ) )
#define SNAPSHOT_ENABLED 1
#endif

FB_FORWARD_PTR( QmlChimera )
class QmlChimera
: public QObject, public Chimera
Expand Down Expand Up @@ -106,5 +110,7 @@ private Q_SLOTS:
protected:
QmlVlcSurfacePlayerProxy* m_qmlVlcPlayer;
std::string m_qmlError;
#ifdef SNAPSHOT_ENABLED
QSharedPointer<QQuickItemGrabResult> m_itemGrabResult;
#endif
};

0 comments on commit 5e591aa

Please sign in to comment.