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