TestsTab.qml
author sl
Tue, 17 Jun 2014 09:49:12 +0200
changeset 36 f2a9369e7fb9
parent 34 f2c87f0cfabe
permissions -rw-r--r--
Adding reset function called when changing font.
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@34
     6
import QtQuick.Dialogs 1.1
sl@34
     7
import Qt.labs.settings 1.0
sl@15
     8
sl@0
     9
sl@0
    10
Item {
sl@17
    11
    id: testTab
sl@15
    12
    //width: 100
sl@15
    13
    //height: 62
sl@0
    14
    //SystemPalette { id: palette }
sl@0
    15
    clip: true
sl@15
    16
    //anchors.fill:parent
sl@0
    17
sl@34
    18
    Settings {
sl@35
    19
        property alias fontLineTop: marqueeLineTop.font;
sl@35
    20
        property alias fontLineBottom: marqueeLineBottom.font;
sl@34
    21
    }
sl@34
    22
sl@34
    23
sl@15
    24
sl@18
    25
    //This window is our VFD frame
sl@15
    26
    Window {
sl@24
    27
        id: frameWindow
sl@15
    28
        color: "transparent"
sl@24
    29
        title: "VFD Window"
sl@15
    30
        modality: Qt.NonModal
sl@24
    31
        //Splash screen type do not have any border which is what we want
sl@15
    32
        flags: Qt.SplashScreen
sl@21
    33
        //24 FPS
sl@21
    34
        //property int timeoutInterval: 41
sl@21
    35
        //32 FPS
sl@15
    36
    //! [splash-properties]
sl@15
    37
    //! [screen-properties]
sl@24
    38
        //Here comes some trick to keep our display frame within our app.
sl@24
    39
        //This make sure this window follows our app window.
sl@17
    40
        x: appWindow.x+appWindow.width-256-13
sl@17
    41
        y: appWindow.y+appWindow.height-64-30
sl@17
    42
sl@15
    43
    //! [screen-properties]
sl@15
    44
        width: rectangleScreen.width
sl@15
    45
        height: rectangleScreen.height
sl@29
    46
        //property int frameCounter:0;
sl@29
    47
        property int firstFrame:-1;
sl@15
    48
        property var startTime:new Date();
sl@15
    49
sl@15
    50
        Rectangle {
sl@15
    51
            id: rectangleScreen
sl@15
    52
            anchors.centerIn: parent
sl@15
    53
            width: 256
sl@15
    54
            height: 64
sl@15
    55
            color: "white"
sl@15
    56
            border.width:1
sl@15
    57
            border.color: "black"
sl@15
    58
            smooth: false
sl@15
    59
        }
sl@15
    60
sl@34
    61
        ColumnLayout {
sl@28
    62
sl@34
    63
            MarqueeText {
sl@34
    64
                id: marqueeLineTop
sl@34
    65
                width: 256
sl@35
    66
                height: 32
sl@35
    67
                pixelsPerSeconds:25
sl@34
    68
                //anchors.verticalCenter: parent.verticalCenter
sl@34
    69
                //anchors.horizontalCenter: parent.horizontalCenter
sl@34
    70
                text: "start ---- ABCDEFGHIJKLMNOPQRSTUVWXYZ ---- end"
sl@34
    71
                separator: " | "
sl@16
    72
            }
sl@16
    73
sl@34
    74
            MarqueeText {
sl@34
    75
                id: marqueeLineBottom
sl@34
    76
                width: 256
sl@35
    77
                height: 32
sl@35
    78
                pixelsPerSeconds:25
sl@34
    79
                //anchors.verticalCenter: parent.verticalCenter
sl@34
    80
                //anchors.horizontalCenter: parent.horizontalCenter
sl@34
    81
                text: "start ---- abcdefghijklmnopqrstuvwxyz-1234567890 ---- end"
sl@34
    82
                separator: " | "
sl@16
    83
            }
sl@16
    84
sl@29
    85
sl@15
    86
        }
sl@15
    87
sl@34
    88
sl@34
    89
sl@33
    90
        //This function is called from C++ afterAnimating.
sl@34
    91
sl@34
    92
sl@33
    93
        //It means it is called in sync with Qt render loop.
sl@33
    94
        //Qt render loop tries to run at 60 FPS.
sl@34
    95
        //We should not modify the content of our display window from here as will cause UI lags when runing 60 times per second.
sl@29
    96
        function doFrame(frameCount)
sl@29
    97
        {
sl@33
    98
            //Skip every second frame otherwise our UI lags.
sl@35
    99
            if (frameCount%4!=0)
sl@31
   100
            {
sl@34
   101
                //labelFrameTick.text="-";
sl@35
   102
                return;
sl@31
   103
            }
sl@34
   104
            //labelFrameTick.text="+";
sl@31
   105
sl@29
   106
            var current = new Date();
sl@29
   107
            var milliseconds = (current.getTime() - startTime.getTime());
sl@15
   108
sl@29
   109
            if (firstFrame==-1)
sl@29
   110
            {
sl@29
   111
                firstFrame=frameCount
sl@29
   112
            }
sl@29
   113
sl@29
   114
sl@35
   115
            var frameCounter=(frameCount-firstFrame)/4;
sl@29
   116
            labelFrameCount.text=frameCounter;
sl@29
   117
            labelTime.text=milliseconds/1000;
sl@29
   118
            labelTimePerFrame.text=(milliseconds/frameCounter).toFixed(3);
sl@29
   119
            labelFps.text=(1000/(milliseconds/frameCounter)).toFixed(0);
sl@29
   120
sl@29
   121
            if (checkBoxDoClear.checked)
sl@29
   122
            {
sl@29
   123
                display.clear();
sl@29
   124
            }
sl@29
   125
sl@29
   126
            if (checkBoxRenderToDisplay.checked)
sl@29
   127
            {
sl@29
   128
                if (checkBoxFillAndClearOnly.checked)
sl@29
   129
                {
sl@29
   130
                    //Trying to make it a worse case scenario for our frame diff algo
sl@29
   131
                    if (doFill)
sl@29
   132
                    {
sl@29
   133
                        display.fill();
sl@29
   134
                    }
sl@29
   135
                    else
sl@29
   136
                    {
sl@29
   137
                        display.clear();
sl@29
   138
                    }
sl@29
   139
sl@29
   140
                    if (frameCounter%2)
sl@29
   141
                    {
sl@29
   142
                        doFill=!doFill;
sl@29
   143
                    }
sl@29
   144
                }
sl@29
   145
                else if (checkBoxOnePixelOnly.checked)
sl@29
   146
                {
sl@29
   147
                    display.setPixel(0,0,frameCounter%2);
sl@29
   148
                }
sl@29
   149
                else
sl@29
   150
                {
sl@29
   151
                    display.renderWindow(frameWindow);
sl@29
   152
                }
sl@29
   153
sl@29
   154
                if (!checkBoxNoSwapBuffers.checked)
sl@29
   155
                {
sl@29
   156
                    display.swapBuffers();
sl@29
   157
                }
sl@29
   158
sl@29
   159
            }
sl@29
   160
        }
sl@15
   161
sl@15
   162
sl@15
   163
        Component.onCompleted: {
sl@29
   164
            visible = true;
sl@33
   165
            display.connectRenderLoop(frameWindow,doFrame);
sl@15
   166
        }
sl@15
   167
sl@15
   168
    }
sl@15
   169
sl@15
   170
sl@34
   171
    FontDialog {
sl@34
   172
        id: fontDialog
sl@34
   173
        visible: false
sl@34
   174
        modality: Qt.WindowModal
sl@34
   175
        scalableFonts: true
sl@34
   176
        nonScalableFonts: true
sl@34
   177
        monospacedFonts: true
sl@34
   178
        proportionalFonts: true
sl@34
   179
        title: qsTr("Choose a font")
sl@34
   180
        font: marqueeLineTop.font
sl@34
   181
        currentFont: marqueeLineTop.font
sl@34
   182
        //onCurrentFontChanged: { console.log("CurrentFontChanged: " + currentFont) }
sl@34
   183
        //onFontChanged: { console.log("FontChanged: " + font) }
sl@34
   184
        onAccepted: {
sl@34
   185
            //console.log("Accepted: " + font);
sl@34
   186
            marqueeLineTop.font = currentFont;
sl@34
   187
            marqueeLineBottom.font = currentFont;
sl@34
   188
        }
sl@34
   189
        //onRejected: { console.log("Rejected") }
sl@34
   190
    }
sl@34
   191
sl@34
   192
sl@34
   193
    GridLayout {
sl@34
   194
        //anchors.fill:parent
sl@34
   195
        anchors.centerIn: parent
sl@34
   196
        anchors.margins: 6
sl@34
   197
        //width:parent.width/2
sl@34
   198
        height:parent.height/2
sl@34
   199
sl@34
   200
        //spacing: 4
sl@34
   201
        columns: 4
sl@34
   202
sl@34
   203
            Button {
sl@34
   204
                text: qsTr("Render Window")
sl@34
   205
                onClicked: {
sl@34
   206
                    display.renderWindow(frameWindow);
sl@34
   207
                    display.swapBuffers();
sl@34
   208
                }
sl@15
   209
            }
sl@16
   210
sl@34
   211
            Button {
sl@34
   212
                text: qsTr("Reset stats")
sl@34
   213
                onClicked: {
sl@34
   214
                    frameWindow.startTime = new Date();
sl@34
   215
                    //frameWindow.frameCounter = 0;
sl@34
   216
                    frameWindow.firstFrame = -1;
sl@34
   217
                }
sl@16
   218
            }
sl@16
   219
sl@34
   220
            CheckBox {
sl@34
   221
                id: checkBoxDoClear
sl@34
   222
                text: qsTr("Do clear")
sl@34
   223
                checked: true
sl@16
   224
            }
sl@16
   225
sl@34
   226
            CheckBox {
sl@34
   227
                id: checkBoxRenderToDisplay
sl@34
   228
                text: qsTr("Render to display")
sl@34
   229
                checked: true
sl@34
   230
            }
sl@16
   231
sl@34
   232
            CheckBox {
sl@34
   233
                id: checkBoxFillAndClearOnly
sl@34
   234
                text: qsTr("Only fill and clear")
sl@34
   235
                checked: false
sl@34
   236
            }
sl@16
   237
sl@34
   238
            CheckBox {
sl@34
   239
                id: checkBoxNoSwapBuffers
sl@34
   240
                text: qsTr("No swap buffers")
sl@34
   241
                checked: false
sl@34
   242
            }
sl@16
   243
sl@34
   244
            CheckBox {
sl@34
   245
                id: checkBoxOnePixelOnly
sl@34
   246
                text: qsTr("One pixel only")
sl@34
   247
                checked: false
sl@34
   248
            }
sl@16
   249
sl@34
   250
            CheckBox {
sl@34
   251
                text: qsTr("Off-Screen")
sl@34
   252
                checked: true
sl@34
   253
                onCheckedChanged: {display.offScreenMode = checked;}
sl@34
   254
            }
sl@18
   255
sl@34
   256
            CheckBox {
sl@34
   257
                text: qsTr("Frame differencing")
sl@34
   258
                checked: true
sl@34
   259
                onCheckedChanged: {display.frameDifferencing = checked;}
sl@34
   260
            }
sl@23
   261
sl@34
   262
            Button {
sl@34
   263
                text: qsTr("Change font")
sl@34
   264
                onClicked: {
sl@34
   265
                    //We had to do this double magic cause otherwise our font list
sl@34
   266
                    //would not reflect our options.
sl@34
   267
                    fontDialog.setVisible(true);
sl@34
   268
                    fontDialog.open();
sl@34
   269
                }
sl@34
   270
            }
sl@34
   271
sl@34
   272
            Label {
sl@34
   273
                text: ""
sl@34
   274
                antialiasing: false
sl@34
   275
            }
sl@34
   276
sl@34
   277
            Label {
sl@34
   278
                text: ""
sl@34
   279
                antialiasing: false
sl@34
   280
            }
sl@34
   281
sl@34
   282
sl@34
   283
            Label {
sl@34
   284
                id: labelFrameTick
sl@34
   285
                text: "Frames:"
sl@34
   286
                antialiasing: false
sl@34
   287
            }
sl@34
   288
sl@34
   289
            Label {
sl@34
   290
                text: "Time (s):"
sl@34
   291
                antialiasing: false
sl@34
   292
            }
sl@34
   293
sl@34
   294
            Label {
sl@34
   295
                text: "Time/Frame (ms):"
sl@34
   296
                antialiasing: false
sl@34
   297
            }
sl@34
   298
sl@34
   299
            Label {
sl@34
   300
                text: "FPS:"
sl@34
   301
                antialiasing: false
sl@34
   302
            }
sl@34
   303
sl@34
   304
            Label {
sl@34
   305
                id: labelFrameCount
sl@34
   306
                text: "Frame Count"
sl@34
   307
                antialiasing: false
sl@34
   308
            }
sl@34
   309
sl@34
   310
            Label {
sl@34
   311
                id: labelTime
sl@34
   312
                text: "Time"
sl@34
   313
                antialiasing: false
sl@34
   314
            }
sl@34
   315
sl@34
   316
            Label {
sl@34
   317
                id: labelTimePerFrame
sl@34
   318
                text: "Time/Frame"
sl@34
   319
                antialiasing: false
sl@34
   320
            }
sl@34
   321
sl@34
   322
            Label {
sl@34
   323
                id: labelFps
sl@34
   324
                text: "FPS"
sl@34
   325
                antialiasing: false
sl@34
   326
            }
sl@34
   327
sl@15
   328
    }
sl@0
   329
}