2020-10-18 06:50:26 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Alex Spataru <https://github.com/alex-spataru>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
|
|
|
|
RowLayout {
|
2020-12-27 18:38:26 -06:00
|
|
|
id: root
|
2020-10-18 06:50:26 -05:00
|
|
|
spacing: app.spacing
|
|
|
|
|
|
|
|
//
|
|
|
|
// Custom properties
|
|
|
|
//
|
|
|
|
property alias label: _label
|
|
|
|
property alias indicator: _dot
|
|
|
|
property alias text: _label.text
|
|
|
|
property alias font: _label.font
|
|
|
|
property alias flashDuration: _timer.interval
|
|
|
|
property color onColor: Qt.rgba(215/255, 45/255, 96/255, 1)
|
|
|
|
property color offColor: Qt.rgba(45/255, 96/255, 115/255, 1)
|
|
|
|
|
|
|
|
//
|
|
|
|
// Turns on the LED for a short period of time
|
|
|
|
//
|
|
|
|
function flash() {
|
2020-12-27 18:38:26 -06:00
|
|
|
root.enabled = true
|
2020-10-18 06:50:26 -05:00
|
|
|
if (_timer.running)
|
|
|
|
_timer.restart()
|
|
|
|
else
|
|
|
|
_timer.start()
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Used to allow the flash behavior
|
|
|
|
//
|
|
|
|
Timer {
|
|
|
|
id: _timer
|
|
|
|
interval: 50
|
2020-12-27 18:38:26 -06:00
|
|
|
onTriggered: root.enabled = false
|
2020-10-18 06:50:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// LED indicator
|
|
|
|
//
|
|
|
|
Rectangle {
|
|
|
|
id: _dot
|
|
|
|
width: 18
|
|
|
|
height: 18
|
|
|
|
radius: width / 2
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
2020-12-27 18:38:26 -06:00
|
|
|
color: root.enabled ? root.onColor : root.offColor
|
2020-10-18 06:50:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// LED text
|
|
|
|
//
|
|
|
|
Label {
|
|
|
|
id: _label
|
|
|
|
font.family: app.monoFont
|
|
|
|
color: palette.highlightedText
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
}
|
|
|
|
}
|