TestsTab.qml
author sl
Tue, 03 Jun 2014 16:11:47 +0200
changeset 29 a42cc76a2d5a
parent 28 8297924aa384
child 31 e68f1542d9d3
permissions -rw-r--r--
Trying to get rid of our QML timer.
We now connect to our window after animation signal from C++.
It looks like it works much better now. Less UI lags smother animation.
     1 import QtQuick 2.2
     2 import QtQuick.Controls 1.2
     3 import QtQuick.Window 2.1
     4 import MiniDisplay 1.0
     5 import QtQuick.Layouts 1.1
     6 
     7 
     8 Item {
     9     id: testTab
    10     //width: 100
    11     //height: 62
    12     //SystemPalette { id: palette }
    13     clip: true
    14     //anchors.fill:parent
    15 
    16 
    17     //This window is our VFD frame
    18     Window {
    19         id: frameWindow
    20         color: "transparent"
    21         title: "VFD Window"
    22         modality: Qt.NonModal
    23         //Splash screen type do not have any border which is what we want
    24         flags: Qt.SplashScreen
    25         //24 FPS
    26         //property int timeoutInterval: 41
    27         //32 FPS
    28         property int timeoutInterval: 33
    29         signal timeout
    30     //! [splash-properties]
    31     //! [screen-properties]
    32         //Here comes some trick to keep our display frame within our app.
    33         //This make sure this window follows our app window.
    34         x: appWindow.x+appWindow.width-256-13
    35         y: appWindow.y+appWindow.height-64-30
    36 
    37     //! [screen-properties]
    38         width: rectangleScreen.width
    39         height: rectangleScreen.height
    40         //property int frameCounter:0;
    41         property int firstFrame:-1;
    42         property var startTime:new Date();
    43 
    44         Rectangle {
    45             id: rectangleScreen
    46             anchors.centerIn: parent
    47             width: 256
    48             height: 64
    49             color: "white"
    50             border.width:1
    51             border.color: "black"
    52             smooth: false
    53         }
    54 
    55         MarqueeText {
    56             width: 256
    57             pixelsPerSeconds:50
    58             anchors.verticalCenter: parent.verticalCenter
    59             anchors.horizontalCenter: parent.horizontalCenter
    60             text: "start ------ abcdefghijklmnopqrtaksdjfkdfjklsdjflksdjfklsjadfkljsad;flasjdlfjasdfjldsdfljf---- end"
    61             //text: "start ------ end"
    62             separator: " | "
    63         }
    64 
    65         GridLayout {
    66             anchors.fill:parent
    67             anchors.margins: 6
    68             //spacing: 4
    69             columns: 4
    70 
    71             Label {
    72                 text: "Frames:"
    73                 antialiasing: false
    74             }
    75 
    76             Label {
    77                 text: "Time (s):"
    78                 antialiasing: false
    79             }
    80 
    81             Label {
    82                 text: "Time/Frame (ms):"
    83                 antialiasing: false
    84             }
    85 
    86             Label {
    87                 text: "FPS:"
    88                 antialiasing: false
    89             }
    90 
    91             Label {
    92                 id: labelFrameCount
    93                 text: "Frame Count"
    94                 antialiasing: false
    95             }
    96 
    97             Label {
    98                 id: labelTime
    99                 text: "Time"
   100                 antialiasing: false
   101             }
   102 
   103             Label {
   104                 id: labelTimePerFrame
   105                 text: "Time/Frame"
   106                 antialiasing: false
   107             }
   108 
   109             Label {
   110                 id: labelFps
   111                 text: "FPS"
   112                 antialiasing: false
   113             }
   114 
   115             //onA: {}
   116 
   117         }
   118 
   119 
   120         function doFrame(frameCount)
   121         {
   122             var current = new Date();
   123             var milliseconds = (current.getTime() - startTime.getTime());
   124 
   125             if (firstFrame==-1)
   126             {
   127                 firstFrame=frameCount
   128             }
   129 
   130 
   131             var frameCounter=frameCount-firstFrame;
   132             labelFrameCount.text=frameCounter;
   133             labelTime.text=milliseconds/1000;
   134             labelTimePerFrame.text=(milliseconds/frameCounter).toFixed(3);
   135             labelFps.text=(1000/(milliseconds/frameCounter)).toFixed(0);
   136 
   137             if (checkBoxDoClear.checked)
   138             {
   139                 display.clear();
   140             }
   141 
   142             if (checkBoxRenderToDisplay.checked)
   143             {
   144                 if (checkBoxFillAndClearOnly.checked)
   145                 {
   146                     //Trying to make it a worse case scenario for our frame diff algo
   147                     if (doFill)
   148                     {
   149                         display.fill();
   150                     }
   151                     else
   152                     {
   153                         display.clear();
   154                     }
   155 
   156                     if (frameCounter%2)
   157                     {
   158                         doFill=!doFill;
   159                     }
   160                 }
   161                 else if (checkBoxOnePixelOnly.checked)
   162                 {
   163                     display.setPixel(0,0,frameCounter%2);
   164                 }
   165                 else
   166                 {
   167                     display.renderWindow(frameWindow);
   168                 }
   169 
   170                 if (!checkBoxNoSwapBuffers.checked)
   171                 {
   172                     display.swapBuffers();
   173                 }
   174 
   175             }
   176         }
   177 
   178 
   179         //! [timer]
   180         Timer {
   181             id: timer
   182             interval: frameWindow.timeoutInterval; running: false; repeat: true
   183             property bool doFill: true
   184             onTriggered: {
   185                 //visible = false
   186                 //frameWindow.doFrame();
   187 
   188                 //Signal our timeout
   189                 //frameWindow.timeout();
   190             }
   191         }
   192         //! [timer]
   193         Component.onCompleted: {
   194             visible = true;
   195             display.connectWindow(frameWindow,doFrame);
   196         }
   197 
   198     }
   199 
   200     Column {
   201         anchors.fill: parent
   202         anchors.margins: 8
   203         spacing: 8
   204 
   205         Button {
   206             text: qsTr("Render Window")
   207             onClicked: {
   208                 display.renderWindow(frameWindow);
   209                 display.swapBuffers();
   210             }
   211         }
   212 
   213         Button {
   214             text: qsTr("Reset stats")
   215             onClicked: {
   216                 frameWindow.startTime = new Date();
   217                 //frameWindow.frameCounter = 0;
   218                 frameWindow.firstFrame = -1;
   219             }
   220         }
   221 
   222         CheckBox {
   223             text: qsTr("Run timer")
   224             checked: true
   225             onCheckedChanged: {
   226                 (checked?timer.start():timer.stop())
   227             }
   228         }
   229 
   230         CheckBox {
   231             id: checkBoxDoClear
   232             text: qsTr("Do clear")
   233             checked: true
   234         }
   235 
   236         CheckBox {
   237             id: checkBoxRenderToDisplay
   238             text: qsTr("Render to display")
   239             checked: true
   240         }
   241 
   242         CheckBox {
   243             id: checkBoxFillAndClearOnly
   244             text: qsTr("Only fill and clear")
   245             checked: false
   246         }
   247 
   248         CheckBox {
   249             id: checkBoxNoSwapBuffers
   250             text: qsTr("No swap buffers")
   251             checked: false
   252         }
   253 
   254         CheckBox {
   255             id: checkBoxOnePixelOnly
   256             text: qsTr("One pixel only")
   257             checked: false
   258         }
   259 
   260         CheckBox {
   261             text: qsTr("Off-Screen")
   262             checked: true
   263             onCheckedChanged: {display.offScreenMode = checked;}
   264         }
   265 
   266         CheckBox {
   267             text: qsTr("Frame differencing")
   268             checked: true
   269             onCheckedChanged: {display.frameDifferencing = checked;}
   270         }
   271 
   272         //
   273         Rectangle {
   274             border.width: 1
   275             border.color: "black"
   276             color: "white"
   277             anchors.horizontalCenter: parent.horizontalCenter
   278             width: 250
   279             height: text.height + 10
   280             y:100
   281             MarqueeText {
   282                 id:text
   283                 width: 200
   284                 pixelsPerSeconds:50
   285                 anchors.verticalCenter: parent.verticalCenter
   286                 anchors.horizontalCenter: parent.horizontalCenter
   287                 text: "start ------ abcdefghijklmnopqrtaksdjfkdfjklsdjflksdjfklsjadfkljsad;flasjdlfjasdfjldsdfljf---- end"
   288                 //text: "start ------ end"
   289                 separator: " | "
   290             }
   291         }
   292 
   293     }
   294 }