TestsTab.qml
author sl
Sun, 01 Jun 2014 21:15:33 +0200
changeset 23 1f607fa8542f
parent 22 ca9e48af31e6
child 24 783a937d3eb3
permissions -rw-r--r--
Adding an option to disable frame differencing.
     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         //parent: appWindow
    20         id: splash
    21         color: "transparent"
    22         title: "Splash Window"
    23         modality: Qt.NonModal
    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         //x: (Screen.width - rectangleScreen.width) / 2
    33         //y: (Screen.height - rectangleScreen.height) / 2
    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 var startTime:new Date();
    42 
    43         Rectangle {
    44             id: rectangleScreen
    45             anchors.centerIn: parent
    46             width: 256
    47             height: 64
    48             color: "white"
    49             border.width:1
    50             border.color: "black"
    51             smooth: false
    52         }
    53 
    54         GridLayout {
    55             anchors.fill:parent
    56             anchors.margins: 6
    57             //spacing: 4
    58             columns: 4
    59 
    60             Label {
    61                 text: "Frames:"
    62                 antialiasing: false
    63             }
    64 
    65             Label {
    66                 text: "Time (s):"
    67                 antialiasing: false
    68             }
    69 
    70             Label {
    71                 text: "Time/Frame (ms):"
    72                 antialiasing: false
    73             }
    74 
    75             Label {
    76                 text: "FPS:"
    77                 antialiasing: false
    78             }
    79 
    80             Label {
    81                 id: labelFrameCount
    82                 text: "Frame Count"
    83                 antialiasing: false
    84             }
    85 
    86             Label {
    87                 id: labelTime
    88                 text: "Time"
    89                 antialiasing: false
    90             }
    91 
    92             Label {
    93                 id: labelTimePerFrame
    94                 text: "Time/Frame"
    95                 antialiasing: false
    96             }
    97 
    98             Label {
    99                 id: labelFps
   100                 text: "FPS"
   101                 antialiasing: false
   102             }
   103 
   104         }
   105 
   106 
   107 
   108 
   109 
   110         //! [timer]
   111         Timer {
   112             id: timer
   113             interval: splash.timeoutInterval; running: true; repeat: true
   114             property bool doFill: true
   115             onTriggered: {
   116                 //visible = false
   117 
   118                 var current = new Date();
   119                 var milliseconds = (current.getTime() - splash.startTime.getTime());
   120 
   121                 splash.frameCounter++;
   122                 labelFrameCount.text=splash.frameCounter;
   123                 labelTime.text=milliseconds/1000;
   124                 labelTimePerFrame.text=(milliseconds/splash.frameCounter).toFixed(3);
   125                 labelFps.text=(1000/(milliseconds/splash.frameCounter)).toFixed(0);
   126 
   127                 if (checkBoxDoClear.checked)
   128                 {
   129                     display.clear();
   130                 }
   131 
   132                 if (checkBoxRenderToDisplay.checked)
   133                 {
   134                     if (checkBoxFillAndClearOnly.checked)
   135                     {
   136                         //Trying to make it a worse case scenario for our frame diff algo
   137                         if (doFill)
   138                         {
   139                             display.fill();
   140                         }
   141                         else
   142                         {
   143                             display.clear();
   144                         }
   145 
   146                         if (splash.frameCounter%2)
   147                         {
   148                             doFill=!doFill;
   149                         }
   150                     }
   151                     else if (checkBoxOnePixelOnly.checked)
   152                     {
   153                         display.setPixel(0,0,splash.frameCounter%2);
   154                     }
   155                     else
   156                     {
   157                         display.renderWindow(splash);
   158                     }
   159 
   160                     if (!checkBoxNoSwapBuffers.checked)
   161                     {
   162                         display.swapBuffers();
   163                     }
   164 
   165                 }
   166 
   167 
   168 
   169                 splash.timeout();
   170             }
   171         }
   172         //! [timer]
   173         Component.onCompleted: {
   174             visible = true
   175         }
   176 
   177     }
   178 
   179     Column {
   180         anchors.fill: parent
   181         anchors.margins: 8
   182         spacing: 8
   183 
   184         Button {
   185             text: qsTr("Render Window")
   186             onClicked: {
   187                 display.renderWindow(splash);
   188                 display.swapBuffers();
   189             }
   190         }
   191 
   192         Button {
   193             text: qsTr("Reset stats")
   194             onClicked: {
   195                 splash.startTime = new Date();
   196                 splash.frameCounter = 0;
   197             }
   198         }
   199 
   200         CheckBox {
   201             text: qsTr("Run timer")
   202             checked: true
   203             onCheckedChanged: {
   204                 (checked?timer.start():timer.stop())
   205             }
   206         }
   207 
   208         CheckBox {
   209             id: checkBoxDoClear
   210             text: qsTr("Do clear")
   211             checked: true
   212         }
   213 
   214         CheckBox {
   215             id: checkBoxRenderToDisplay
   216             text: qsTr("Render to display")
   217             checked: true
   218         }
   219 
   220         CheckBox {
   221             id: checkBoxFillAndClearOnly
   222             text: qsTr("Only fill and clear")
   223             checked: false
   224         }
   225 
   226         CheckBox {
   227             id: checkBoxNoSwapBuffers
   228             text: qsTr("No swap buffers")
   229             checked: false
   230         }
   231 
   232         CheckBox {
   233             id: checkBoxOnePixelOnly
   234             text: qsTr("One pixel only")
   235             checked: false
   236         }
   237 
   238         CheckBox {
   239             text: qsTr("Off-Screen")
   240             checked: true
   241             onCheckedChanged: {display.offScreenMode = checked;}
   242         }
   243 
   244         CheckBox {
   245             text: qsTr("Frame differencing")
   246             checked: true
   247             onCheckedChanged: {display.frameDifferencing = checked;}
   248         }
   249 
   250     }
   251 }