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