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