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.
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@28
    60
            text: "start ------ abcdefghijklmnopqrtaksdjfkdfjklsdjflksdjfklsjadfkljsad;flasjdlfjasdfjldsdfljf---- end"
sl@28
    61
            //text: "start ------ end"
sl@28
    62
            separator: " | "
sl@28
    63
        }
sl@28
    64
sl@16
    65
        GridLayout {
sl@15
    66
            anchors.fill:parent
sl@15
    67
            anchors.margins: 6
sl@16
    68
            //spacing: 4
sl@16
    69
            columns: 4
sl@16
    70
sl@16
    71
            Label {
sl@16
    72
                text: "Frames:"
sl@16
    73
                antialiasing: false
sl@16
    74
            }
sl@16
    75
sl@16
    76
            Label {
sl@16
    77
                text: "Time (s):"
sl@16
    78
                antialiasing: false
sl@16
    79
            }
sl@16
    80
sl@16
    81
            Label {
sl@16
    82
                text: "Time/Frame (ms):"
sl@16
    83
                antialiasing: false
sl@16
    84
            }
sl@16
    85
sl@16
    86
            Label {
sl@16
    87
                text: "FPS:"
sl@16
    88
                antialiasing: false
sl@16
    89
            }
sl@15
    90
sl@15
    91
            Label {
sl@15
    92
                id: labelFrameCount
sl@15
    93
                text: "Frame Count"
sl@15
    94
                antialiasing: false
sl@15
    95
            }
sl@15
    96
sl@15
    97
            Label {
sl@15
    98
                id: labelTime
sl@15
    99
                text: "Time"
sl@15
   100
                antialiasing: false
sl@15
   101
            }
sl@15
   102
sl@16
   103
            Label {
sl@16
   104
                id: labelTimePerFrame
sl@16
   105
                text: "Time/Frame"
sl@16
   106
                antialiasing: false
sl@16
   107
            }
sl@16
   108
sl@16
   109
            Label {
sl@16
   110
                id: labelFps
sl@16
   111
                text: "FPS"
sl@16
   112
                antialiasing: false
sl@16
   113
            }
sl@16
   114
sl@29
   115
            //onA: {}
sl@29
   116
sl@15
   117
        }
sl@15
   118
sl@15
   119
sl@29
   120
        function doFrame(frameCount)
sl@29
   121
        {
sl@31
   122
            if (frameCount%2!=0)
sl@31
   123
            {
sl@31
   124
                return;
sl@31
   125
            }
sl@31
   126
sl@29
   127
            var current = new Date();
sl@29
   128
            var milliseconds = (current.getTime() - startTime.getTime());
sl@15
   129
sl@29
   130
            if (firstFrame==-1)
sl@29
   131
            {
sl@29
   132
                firstFrame=frameCount
sl@29
   133
            }
sl@29
   134
sl@29
   135
sl@29
   136
            var frameCounter=frameCount-firstFrame;
sl@29
   137
            labelFrameCount.text=frameCounter;
sl@29
   138
            labelTime.text=milliseconds/1000;
sl@29
   139
            labelTimePerFrame.text=(milliseconds/frameCounter).toFixed(3);
sl@29
   140
            labelFps.text=(1000/(milliseconds/frameCounter)).toFixed(0);
sl@29
   141
sl@29
   142
            if (checkBoxDoClear.checked)
sl@29
   143
            {
sl@29
   144
                display.clear();
sl@29
   145
            }
sl@29
   146
sl@29
   147
            if (checkBoxRenderToDisplay.checked)
sl@29
   148
            {
sl@29
   149
                if (checkBoxFillAndClearOnly.checked)
sl@29
   150
                {
sl@29
   151
                    //Trying to make it a worse case scenario for our frame diff algo
sl@29
   152
                    if (doFill)
sl@29
   153
                    {
sl@29
   154
                        display.fill();
sl@29
   155
                    }
sl@29
   156
                    else
sl@29
   157
                    {
sl@29
   158
                        display.clear();
sl@29
   159
                    }
sl@29
   160
sl@29
   161
                    if (frameCounter%2)
sl@29
   162
                    {
sl@29
   163
                        doFill=!doFill;
sl@29
   164
                    }
sl@29
   165
                }
sl@29
   166
                else if (checkBoxOnePixelOnly.checked)
sl@29
   167
                {
sl@29
   168
                    display.setPixel(0,0,frameCounter%2);
sl@29
   169
                }
sl@29
   170
                else
sl@29
   171
                {
sl@29
   172
                    display.renderWindow(frameWindow);
sl@29
   173
                }
sl@29
   174
sl@29
   175
                if (!checkBoxNoSwapBuffers.checked)
sl@29
   176
                {
sl@29
   177
                    display.swapBuffers();
sl@29
   178
                }
sl@29
   179
sl@29
   180
            }
sl@29
   181
        }
sl@15
   182
sl@15
   183
sl@15
   184
        //! [timer]
sl@15
   185
        Timer {
sl@16
   186
            id: timer
sl@29
   187
            interval: frameWindow.timeoutInterval; running: false; repeat: true
sl@22
   188
            property bool doFill: true
sl@15
   189
            onTriggered: {
sl@15
   190
                //visible = false
sl@29
   191
                //frameWindow.doFrame();
sl@16
   192
sl@24
   193
                //Signal our timeout
sl@29
   194
                //frameWindow.timeout();
sl@15
   195
            }
sl@15
   196
        }
sl@15
   197
        //! [timer]
sl@15
   198
        Component.onCompleted: {
sl@29
   199
            visible = true;
sl@29
   200
            display.connectWindow(frameWindow,doFrame);
sl@15
   201
        }
sl@15
   202
sl@15
   203
    }
sl@15
   204
sl@15
   205
    Column {
sl@15
   206
        anchors.fill: parent
sl@15
   207
        anchors.margins: 8
sl@15
   208
        spacing: 8
sl@15
   209
sl@15
   210
        Button {
sl@15
   211
            text: qsTr("Render Window")
sl@15
   212
            onClicked: {
sl@24
   213
                display.renderWindow(frameWindow);
sl@15
   214
                display.swapBuffers();
sl@15
   215
            }
sl@15
   216
        }
sl@16
   217
sl@16
   218
        Button {
sl@16
   219
            text: qsTr("Reset stats")
sl@16
   220
            onClicked: {
sl@24
   221
                frameWindow.startTime = new Date();
sl@29
   222
                //frameWindow.frameCounter = 0;
sl@29
   223
                frameWindow.firstFrame = -1;
sl@16
   224
            }
sl@16
   225
        }
sl@16
   226
sl@16
   227
        CheckBox {
sl@16
   228
            text: qsTr("Run timer")
sl@16
   229
            checked: true
sl@16
   230
            onCheckedChanged: {
sl@16
   231
                (checked?timer.start():timer.stop())
sl@16
   232
            }
sl@16
   233
        }
sl@16
   234
sl@16
   235
        CheckBox {
sl@16
   236
            id: checkBoxDoClear
sl@16
   237
            text: qsTr("Do clear")
sl@16
   238
            checked: true
sl@16
   239
        }
sl@16
   240
sl@16
   241
        CheckBox {
sl@16
   242
            id: checkBoxRenderToDisplay
sl@16
   243
            text: qsTr("Render to display")
sl@16
   244
            checked: true
sl@16
   245
        }
sl@16
   246
sl@16
   247
        CheckBox {
sl@23
   248
            id: checkBoxFillAndClearOnly
sl@21
   249
            text: qsTr("Only fill and clear")
sl@16
   250
            checked: false
sl@16
   251
        }
sl@16
   252
sl@16
   253
        CheckBox {
sl@16
   254
            id: checkBoxNoSwapBuffers
sl@16
   255
            text: qsTr("No swap buffers")
sl@16
   256
            checked: false
sl@16
   257
        }
sl@16
   258
sl@16
   259
        CheckBox {
sl@16
   260
            id: checkBoxOnePixelOnly
sl@16
   261
            text: qsTr("One pixel only")
sl@16
   262
            checked: false
sl@16
   263
        }
sl@18
   264
sl@18
   265
        CheckBox {
sl@18
   266
            text: qsTr("Off-Screen")
sl@18
   267
            checked: true
sl@18
   268
            onCheckedChanged: {display.offScreenMode = checked;}
sl@18
   269
        }
sl@23
   270
sl@23
   271
        CheckBox {
sl@23
   272
            text: qsTr("Frame differencing")
sl@23
   273
            checked: true
sl@23
   274
            onCheckedChanged: {display.frameDifferencing = checked;}
sl@23
   275
        }
sl@23
   276
sl@25
   277
        //
sl@25
   278
        Rectangle {
sl@28
   279
            border.width: 1
sl@26
   280
            border.color: "black"
sl@28
   281
            color: "white"
sl@26
   282
            anchors.horizontalCenter: parent.horizontalCenter
sl@26
   283
            width: 250
sl@26
   284
            height: text.height + 10
sl@26
   285
            y:100
sl@26
   286
            MarqueeText {
sl@26
   287
                id:text
sl@26
   288
                width: 200
sl@26
   289
                pixelsPerSeconds:50
sl@26
   290
                anchors.verticalCenter: parent.verticalCenter
sl@25
   291
                anchors.horizontalCenter: parent.horizontalCenter
sl@26
   292
                text: "start ------ abcdefghijklmnopqrtaksdjfkdfjklsdjflksdjfklsjadfkljsad;flasjdlfjasdfjldsdfljf---- end"
sl@26
   293
                //text: "start ------ end"
sl@26
   294
                separator: " | "
sl@25
   295
            }
sl@26
   296
        }
sl@25
   297
sl@15
   298
    }
sl@0
   299
}