TestsTab.qml
author sl
Tue, 03 Jun 2014 18:35:43 +0200
changeset 31 e68f1542d9d3
parent 29 a42cc76a2d5a
child 32 1c2a7f563019
permissions -rw-r--r--
Frame culling now done in QML rather than CPP.
     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             if (frameCount%2!=0)
   123             {
   124                 return;
   125             }
   126 
   127             var current = new Date();
   128             var milliseconds = (current.getTime() - startTime.getTime());
   129 
   130             if (firstFrame==-1)
   131             {
   132                 firstFrame=frameCount
   133             }
   134 
   135 
   136             var frameCounter=frameCount-firstFrame;
   137             labelFrameCount.text=frameCounter;
   138             labelTime.text=milliseconds/1000;
   139             labelTimePerFrame.text=(milliseconds/frameCounter).toFixed(3);
   140             labelFps.text=(1000/(milliseconds/frameCounter)).toFixed(0);
   141 
   142             if (checkBoxDoClear.checked)
   143             {
   144                 display.clear();
   145             }
   146 
   147             if (checkBoxRenderToDisplay.checked)
   148             {
   149                 if (checkBoxFillAndClearOnly.checked)
   150                 {
   151                     //Trying to make it a worse case scenario for our frame diff algo
   152                     if (doFill)
   153                     {
   154                         display.fill();
   155                     }
   156                     else
   157                     {
   158                         display.clear();
   159                     }
   160 
   161                     if (frameCounter%2)
   162                     {
   163                         doFill=!doFill;
   164                     }
   165                 }
   166                 else if (checkBoxOnePixelOnly.checked)
   167                 {
   168                     display.setPixel(0,0,frameCounter%2);
   169                 }
   170                 else
   171                 {
   172                     display.renderWindow(frameWindow);
   173                 }
   174 
   175                 if (!checkBoxNoSwapBuffers.checked)
   176                 {
   177                     display.swapBuffers();
   178                 }
   179 
   180             }
   181         }
   182 
   183 
   184         //! [timer]
   185         Timer {
   186             id: timer
   187             interval: frameWindow.timeoutInterval; running: false; repeat: true
   188             property bool doFill: true
   189             onTriggered: {
   190                 //visible = false
   191                 //frameWindow.doFrame();
   192 
   193                 //Signal our timeout
   194                 //frameWindow.timeout();
   195             }
   196         }
   197         //! [timer]
   198         Component.onCompleted: {
   199             visible = true;
   200             display.connectWindow(frameWindow,doFrame);
   201         }
   202 
   203     }
   204 
   205     Column {
   206         anchors.fill: parent
   207         anchors.margins: 8
   208         spacing: 8
   209 
   210         Button {
   211             text: qsTr("Render Window")
   212             onClicked: {
   213                 display.renderWindow(frameWindow);
   214                 display.swapBuffers();
   215             }
   216         }
   217 
   218         Button {
   219             text: qsTr("Reset stats")
   220             onClicked: {
   221                 frameWindow.startTime = new Date();
   222                 //frameWindow.frameCounter = 0;
   223                 frameWindow.firstFrame = -1;
   224             }
   225         }
   226 
   227         CheckBox {
   228             text: qsTr("Run timer")
   229             checked: true
   230             onCheckedChanged: {
   231                 (checked?timer.start():timer.stop())
   232             }
   233         }
   234 
   235         CheckBox {
   236             id: checkBoxDoClear
   237             text: qsTr("Do clear")
   238             checked: true
   239         }
   240 
   241         CheckBox {
   242             id: checkBoxRenderToDisplay
   243             text: qsTr("Render to display")
   244             checked: true
   245         }
   246 
   247         CheckBox {
   248             id: checkBoxFillAndClearOnly
   249             text: qsTr("Only fill and clear")
   250             checked: false
   251         }
   252 
   253         CheckBox {
   254             id: checkBoxNoSwapBuffers
   255             text: qsTr("No swap buffers")
   256             checked: false
   257         }
   258 
   259         CheckBox {
   260             id: checkBoxOnePixelOnly
   261             text: qsTr("One pixel only")
   262             checked: false
   263         }
   264 
   265         CheckBox {
   266             text: qsTr("Off-Screen")
   267             checked: true
   268             onCheckedChanged: {display.offScreenMode = checked;}
   269         }
   270 
   271         CheckBox {
   272             text: qsTr("Frame differencing")
   273             checked: true
   274             onCheckedChanged: {display.frameDifferencing = checked;}
   275         }
   276 
   277         //
   278         Rectangle {
   279             border.width: 1
   280             border.color: "black"
   281             color: "white"
   282             anchors.horizontalCenter: parent.horizontalCenter
   283             width: 250
   284             height: text.height + 10
   285             y:100
   286             MarqueeText {
   287                 id:text
   288                 width: 200
   289                 pixelsPerSeconds:50
   290                 anchors.verticalCenter: parent.verticalCenter
   291                 anchors.horizontalCenter: parent.horizontalCenter
   292                 text: "start ------ abcdefghijklmnopqrtaksdjfkdfjklsdjflksdjfklsjadfkljsad;flasjdlfjasdfjldsdfljf---- end"
   293                 //text: "start ------ end"
   294                 separator: " | "
   295             }
   296         }
   297 
   298     }
   299 }