# HG changeset patch # User sl # Date 1401899437 -7200 # Node ID cf5eba52cb1d07ddf1f9743c28a32396e4db2bb5 # Parent 1c2a7f56301926c41f357d5e1f675058bb05b273 Marquee loop can now be paused and resumed. Cleaning up our MiniDisplay coneection to render loop API. diff -r 1c2a7f563019 -r cf5eba52cb1d MarqueeText.qml --- a/MarqueeText.qml Wed Jun 04 08:12:37 2014 +0200 +++ b/MarqueeText.qml Wed Jun 04 18:30:37 2014 +0200 @@ -35,10 +35,11 @@ //Reset to zero and restart onStopped so that we keep looping //onStopped: {scrollingText.x=0;running=true;} - property int lengthInPixels:scrollingText.width-separatorText.width-scrollingText.x; + property int lengthInPixels:(scrollingText.width+separatorText.width)-scrollingText.x; property int durationInMs:(animation.lengthInPixels)*1000/pixelsPerSeconds; NumberAnimation { + id: animationScrollingTest target: scrollingText; properties: "x" from: scrollingText.x; @@ -68,22 +69,23 @@ MouseArea { id:mouseArea anchors.fill: parent - onClicked: {animation.running=!animation.running; - /* + onClicked: { + //animation.running=!animation.running; + if (!animation.running) { animation.start(); return; } if (animation.paused) { - console.log("resume") - animation.resume; + //console.log("resume") + animation.resume(); } else { - console.log("pause") - animation.pause; - }*/ + //console.log("pause") + animation.pause(); + } } } } 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++; } diff -r 1c2a7f563019 -r cf5eba52cb1d MiniDisplay/minidisplay.h --- a/MiniDisplay/minidisplay.h Wed Jun 04 08:12:37 2014 +0200 +++ b/MiniDisplay/minidisplay.h Wed Jun 04 18:30:37 2014 +0200 @@ -40,7 +40,8 @@ Q_INVOKABLE void renderWindow(QQuickWindow* aWindow); Q_INVOKABLE void renderImage(QImage* aImage); // - Q_INVOKABLE void connectWindow(QQuickWindow* aWindow, QJSValue aFunction); + Q_INVOKABLE void connectRenderLoop(QQuickWindow* aWindow, QJSValue aFunction); + Q_INVOKABLE void disconnectRenderLoop(); // Q_INVOKABLE void setPixel(int x, int y, bool on); @@ -105,6 +106,7 @@ QPoint iFramePosition; QJSValue iAfterAnimatingCallback; QQuickWindow* iWindow; + int iFrameCount; }; #endif // MINIDISPLAY_H diff -r 1c2a7f563019 -r cf5eba52cb1d TestsTab.qml --- a/TestsTab.qml Wed Jun 04 08:12:37 2014 +0200 +++ b/TestsTab.qml Wed Jun 04 18:30:37 2014 +0200 @@ -57,8 +57,7 @@ pixelsPerSeconds:50 anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter - text: "start ------ abcdefghijklmnopqrtaksdjfkdfjklsdjflksdjfklsjadfkljsad;flasjdlfjasdfjldsdfljf---- end" - //text: "start ------ end" + text: "start ---- ABCDEFGHIJKLMNOPQRSTUVWXYZ ---- end" separator: " | " } @@ -116,9 +115,12 @@ } - + //This function is called from C++ afterAnimating. + //It means it is called in sync with Qt render loop. + //Qt render loop tries to run at 60 FPS. function doFrame(frameCount) { + //Skip every second frame otherwise our UI lags. if (frameCount%2!=0) { return; @@ -181,23 +183,9 @@ } - //! [timer] - Timer { - id: timer - interval: frameWindow.timeoutInterval; running: false; repeat: true - property bool doFill: true - onTriggered: { - //visible = false - //frameWindow.doFrame(); - - //Signal our timeout - //frameWindow.timeout(); - } - } - //! [timer] Component.onCompleted: { visible = true; - display.connectWindow(frameWindow,doFrame); + display.connectRenderLoop(frameWindow,doFrame); } } @@ -273,27 +261,5 @@ checked: true onCheckedChanged: {display.frameDifferencing = checked;} } - - // - Rectangle { - border.width: 1 - border.color: "black" - color: "white" - anchors.horizontalCenter: parent.horizontalCenter - width: 250 - height: text.height + 10 - y:100 - MarqueeText { - id:text - width: 200 - pixelsPerSeconds:50 - anchors.verticalCenter: parent.verticalCenter - anchors.horizontalCenter: parent.horizontalCenter - text: "start ------ abcdefghijklmnopqrtaksdjfkdfjklsdjflksdjfklsjadfkljsad;flasjdlfjasdfjldsdfljf---- end" - //text: "start ------ end" - separator: " | " - } - } - } }