TestsTab.qml
author sl
Mon, 02 Jun 2014 21:56:03 +0200
changeset 28 8297924aa384
parent 26 bb3f9b3c6416
child 29 a42cc76a2d5a
permissions -rw-r--r--
Putting our marquee control on our display.
     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 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         MarqueeText {
    55             width: 256
    56             pixelsPerSeconds:50
    57             anchors.verticalCenter: parent.verticalCenter
    58             anchors.horizontalCenter: parent.horizontalCenter
    59             text: "start ------ abcdefghijklmnopqrtaksdjfkdfjklsdjflksdjfklsjadfkljsad;flasjdlfjasdfjldsdfljf---- end"
    60             //text: "start ------ end"
    61             separator: " | "
    62         }
    63 
    64         GridLayout {
    65             anchors.fill:parent
    66             anchors.margins: 6
    67             //spacing: 4
    68             columns: 4
    69 
    70             Label {
    71                 text: "Frames:"
    72                 antialiasing: false
    73             }
    74 
    75             Label {
    76                 text: "Time (s):"
    77                 antialiasing: false
    78             }
    79 
    80             Label {
    81                 text: "Time/Frame (ms):"
    82                 antialiasing: false
    83             }
    84 
    85             Label {
    86                 text: "FPS:"
    87                 antialiasing: false
    88             }
    89 
    90             Label {
    91                 id: labelFrameCount
    92                 text: "Frame Count"
    93                 antialiasing: false
    94             }
    95 
    96             Label {
    97                 id: labelTime
    98                 text: "Time"
    99                 antialiasing: false
   100             }
   101 
   102             Label {
   103                 id: labelTimePerFrame
   104                 text: "Time/Frame"
   105                 antialiasing: false
   106             }
   107 
   108             Label {
   109                 id: labelFps
   110                 text: "FPS"
   111                 antialiasing: false
   112             }
   113 
   114         }
   115 
   116 
   117 
   118 
   119 
   120         //! [timer]
   121         Timer {
   122             id: timer
   123             interval: frameWindow.timeoutInterval; running: true; repeat: true
   124             property bool doFill: true
   125             onTriggered: {
   126                 //visible = false
   127 
   128                 var current = new Date();
   129                 var milliseconds = (current.getTime() - frameWindow.startTime.getTime());
   130 
   131                 frameWindow.frameCounter++;
   132                 labelFrameCount.text=frameWindow.frameCounter;
   133                 labelTime.text=milliseconds/1000;
   134                 labelTimePerFrame.text=(milliseconds/frameWindow.frameCounter).toFixed(3);
   135                 labelFps.text=(1000/(milliseconds/frameWindow.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 (frameWindow.frameCounter%2)
   157                         {
   158                             doFill=!doFill;
   159                         }
   160                     }
   161                     else if (checkBoxOnePixelOnly.checked)
   162                     {
   163                         display.setPixel(0,0,frameWindow.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                 //Signal our timeout
   178                 frameWindow.timeout();
   179             }
   180         }
   181         //! [timer]
   182         Component.onCompleted: {
   183             visible = true
   184         }
   185 
   186     }
   187 
   188     Column {
   189         anchors.fill: parent
   190         anchors.margins: 8
   191         spacing: 8
   192 
   193         Button {
   194             text: qsTr("Render Window")
   195             onClicked: {
   196                 display.renderWindow(frameWindow);
   197                 display.swapBuffers();
   198             }
   199         }
   200 
   201         Button {
   202             text: qsTr("Reset stats")
   203             onClicked: {
   204                 frameWindow.startTime = new Date();
   205                 frameWindow.frameCounter = 0;
   206             }
   207         }
   208 
   209         CheckBox {
   210             text: qsTr("Run timer")
   211             checked: true
   212             onCheckedChanged: {
   213                 (checked?timer.start():timer.stop())
   214             }
   215         }
   216 
   217         CheckBox {
   218             id: checkBoxDoClear
   219             text: qsTr("Do clear")
   220             checked: true
   221         }
   222 
   223         CheckBox {
   224             id: checkBoxRenderToDisplay
   225             text: qsTr("Render to display")
   226             checked: true
   227         }
   228 
   229         CheckBox {
   230             id: checkBoxFillAndClearOnly
   231             text: qsTr("Only fill and clear")
   232             checked: false
   233         }
   234 
   235         CheckBox {
   236             id: checkBoxNoSwapBuffers
   237             text: qsTr("No swap buffers")
   238             checked: false
   239         }
   240 
   241         CheckBox {
   242             id: checkBoxOnePixelOnly
   243             text: qsTr("One pixel only")
   244             checked: false
   245         }
   246 
   247         CheckBox {
   248             text: qsTr("Off-Screen")
   249             checked: true
   250             onCheckedChanged: {display.offScreenMode = checked;}
   251         }
   252 
   253         CheckBox {
   254             text: qsTr("Frame differencing")
   255             checked: true
   256             onCheckedChanged: {display.frameDifferencing = checked;}
   257         }
   258 
   259         //
   260         Rectangle {
   261             border.width: 1
   262             border.color: "black"
   263             color: "white"
   264             anchors.horizontalCenter: parent.horizontalCenter
   265             width: 250
   266             height: text.height + 10
   267             y:100
   268             MarqueeText {
   269                 id:text
   270                 width: 200
   271                 pixelsPerSeconds:50
   272                 anchors.verticalCenter: parent.verticalCenter
   273                 anchors.horizontalCenter: parent.horizontalCenter
   274                 text: "start ------ abcdefghijklmnopqrtaksdjfkdfjklsdjflksdjfklsjadfkljsad;flasjdlfjasdfjldsdfljf---- end"
   275                 //text: "start ------ end"
   276                 separator: " | "
   277             }
   278         }
   279 
   280     }
   281 }