DisplayTab.qml
author sl
Tue, 17 Jun 2014 09:49:12 +0200
changeset 36 f2a9369e7fb9
parent 17 aa257fdcd093
permissions -rw-r--r--
Adding reset function called when changing font.
     1 import QtQuick 2.2
     2 import QtQuick.Controls 1.2
     3 import MiniDisplay 1.0
     4 import QtQuick.Layouts 1.1
     5 import Qt.labs.settings 1.0
     6 
     7 
     8 
     9 Item {
    10     //width: 100
    11     //height: 62
    12     //SystemPalette { id: palette }
    13     clip: true
    14     //
    15     Component.onCompleted: {
    16         display.closing.connect(onDisplayClosing);
    17         display.opened.connect(onDisplayOpened);
    18         appWindow.closing.connect(onWindowClosing);
    19         if(checkBoxConnectOnStartUp.checked) display.open()
    20     }
    21 
    22     //We need to disconnect our signals to avoid receiving stray events
    23     Component.onDestruction: {
    24         disconnectDisplaySignals()
    25     }
    26     //
    27     Settings {
    28         property alias connectOnStratUp: checkBoxConnectOnStartUp.checked;
    29         property alias clearWhenDisconnecting: checkBoxClearWhenDisconnecting.checked;
    30         property alias clearWhenConnecting: checkBoxClearWhenConnecting.checked;
    31         property alias brightness: sliderBrightness.value;
    32     }
    33 
    34     function disconnectDisplaySignals()
    35     {
    36         display.closed.disconnect(onDisplayClosing);
    37         display.opened.disconnect(onDisplayOpened);
    38     }
    39 
    40     //Clear both front and back buffers
    41     function clearBuffers()
    42     {
    43         display.clear();
    44         display.swapBuffers();
    45         display.clear();
    46         display.swapBuffers();
    47     }
    48 
    49     function onWindowClosing()
    50     {
    51         //Clear both our frames
    52         onDisplayClosing();
    53         disconnectDisplaySignals();
    54     }
    55 
    56     function onDisplayClosing()
    57     {
    58         if (checkBoxClearWhenDisconnecting != null && checkBoxClearWhenDisconnecting.checked)
    59         {
    60             clearBuffers();
    61         }
    62     }
    63 
    64     function onDisplayOpened()
    65     {
    66         if (checkBoxClearWhenConnecting.checked)
    67         {
    68             clearBuffers();
    69         }
    70     }
    71 
    72     //
    73 
    74     Column {
    75         anchors.fill: parent
    76         anchors.margins: 8
    77         spacing: 8
    78 
    79 
    80         Button {
    81             id: buttonOpenClose
    82             text: display.isOpen ? qsTr("Disconnect") : qsTr("Connect")
    83             onClicked: display.isOpen ? display.close() : display.open()
    84         }
    85 
    86         Button {
    87             text: qsTr("Clear")
    88             onClicked: {display.clear(); display.swapBuffers();}
    89             enabled: display.isOpen
    90             activeFocusOnPress: false
    91         }
    92 
    93         Button {
    94             text: qsTr("Fill")
    95             onClicked: {display.fill(); display.swapBuffers();}
    96             enabled: display.isOpen
    97             activeFocusOnPress: false
    98         }
    99 
   100         CheckBox {
   101             id: checkBoxConnectOnStartUp
   102             text: qsTr("Connect on start-up")
   103         }
   104 
   105         CheckBox {
   106             id: checkBoxClearWhenDisconnecting
   107             text: qsTr("Clear when disconnecting")
   108         }
   109 
   110         CheckBox {
   111             id: checkBoxClearWhenConnecting
   112             text: qsTr("Clear when connecting")
   113         }
   114 
   115 
   116     } //ColumnLayout
   117 
   118     Slider {
   119         id: sliderBrightness
   120         anchors.margins: 8
   121         anchors.right: parent.right
   122         anchors.top: parent.top
   123         height:parent.height/2
   124         //
   125         orientation: Qt.Vertical
   126         minimumValue: display.minBrightness
   127         maximumValue: display.maxBrightness
   128         stepSize:1.0
   129         tickmarksEnabled: true
   130         onValueChanged: display.brightness = value
   131     }
   132 
   133 } //Item