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