diff -r 1c2a7f563019 -r cf5eba52cb1d MiniDisplay/minidisplay.cpp --- a/MiniDisplay/minidisplay.cpp Wed Jun 04 08:12:37 2014 +0200 +++ b/MiniDisplay/minidisplay.cpp Wed Jun 04 18:30:37 2014 +0200 @@ -5,7 +5,12 @@ const int KMaxReadAttempt=100; MiniDisplay::MiniDisplay(QQuickItem *parent): - QQuickItem(parent),iReadAttempt(0),iBrightness(iDisplay.MaxBrightness()) + QQuickItem(parent), + iReadAttempt(0), + iBrightness(iDisplay.MaxBrightness()), + iAfterAnimatingCallback(NULL), + iWindow(NULL), + iFrameCount(0) { // By default, QQuickItem does not draw anything. If you subclass // QQuickItem to create a visual item, you will need to uncomment the @@ -53,6 +58,7 @@ } } iDisplay.Close(); + disconnectRenderLoop(); emit closed(); emit statusChanged(); } @@ -201,10 +207,15 @@ /** - * @brief MiniDisplay::connectWindow - * @param aWindow +Connect to the render loop of the given window. +This is achieved using the afterAnimating event. +If any JavaScript callback is provided it will be called on every frame. + +@brief MiniDisplay::connectRenderLoop +@param aWindow The window to connect to. +@param aFunction An optional JavaScript callback function */ -void MiniDisplay::connectWindow(QQuickWindow* aWindow, QJSValue aFunction) +void MiniDisplay::connectRenderLoop(QQuickWindow* aWindow, QJSValue aFunction) { QObject::connect(aWindow, SIGNAL(afterAnimating()), this, SLOT(onAfterAnimating())); @@ -214,11 +225,28 @@ } /** - * @brief MiniDisplay::onAfterAnimating - */ + +@brief MiniDisplay::disconnectRenderLoop +*/ +void MiniDisplay::disconnectRenderLoop() +{ + if (iWindow) + { + QObject::disconnect(iWindow, SIGNAL(afterAnimating()),this, SLOT(onAfterAnimating())); + iWindow = NULL; + iAfterAnimatingCallback = NULL; + iFrameCount=0; + } + +} + +/** +Once connected to a window render loop this is called on every frame. + +@brief MiniDisplay::onAfterAnimating +*/ void MiniDisplay::onAfterAnimating() { - static int frame=0; //qDebug() << frame << "MiniDisplay::onAfterAnimating"; /* if (iAfterAnimatingCallback.isCallable()) @@ -235,11 +263,11 @@ { if (iAfterAnimatingCallback.isCallable()) { - iAfterAnimatingCallback.call(QJSValueList() << frame); + iAfterAnimatingCallback.call(QJSValueList() << iFrameCount); } } - frame++; + iFrameCount++; }