StatusLed¶
class nmeasim::app::StatusLed · Applications
A coloured indicator light with a short upper-case caption, as on an instrument panel: the run state, recording and the outputs in the status bar.
Inherits QWidget
Declared in src/app/widgets/status_led.hpp (line 25)
The light can blink.
The light is a disc 9 pixels across with a soft glow when lit; an unlit light is drawn in theme::Colors::inactive without glow. The caption is drawn in the widget font, bold, at 85 % of its size and slightly spaced, in theme::Colors::text when lit and theme::Colors::text_dim when not; the widget shows it as given and does not change its case. The widget repaints when theme::Theme::changed is emitted. It starts unlit, with no caption and not blinking.
Summary¶
Public member functions
| Name | Description |
|---|---|
StatusLed() |
Creates an unlit light with no caption. |
set_state() |
Sets the light colour and the caption. |
set_blinking() |
Starts or stops blinking, for example while recording. |
color() |
Returns the colour set by set_state. |
text() |
Returns the caption set by set_state. |
blinking() |
Returns whether the light is blinking. |
sizeHint() |
Returns the size that fits the light and the whole caption. |
minimumSizeHint() |
Returns the smallest size, which is sizeHint, so that layouts do not cut the caption off. |
Protected member functions
| Name | Description |
|---|---|
paintEvent() |
Paints the light, with its glow when lit, centred vertically at the left, and the caption to its right, in the colours of the current theme. |
Private data members
| Name | Description |
|---|---|
color_ |
Colour of the lit light; invalid for an unlit light. |
text_ |
Caption shown to the right of the light. |
blink_timer_ |
Toggles lit_ every 500 ms while the light blinks; stopped otherwise. |
lit_ |
Whether the blink cycle is in its lit phase; always true when not blinking. |
Public member functions¶
StatusLed()¶
explicit StatusLed(QWidget* parent = nullptr)
Creates an unlit light with no caption.
Parameters
| Name | Type | Description |
|---|---|---|
parent |
QWidget* |
Qt parent that owns the widget; null leaves ownership to the caller. |
Declared in src/app/widgets/status_led.hpp:32 · defined in src/app/widgets/status_led.cpp:43
set_state()¶
void set_state(const QColor& color, const QString& text)
Sets the light colour and the caption.
Does nothing when both are unchanged. A new caption also updates the size hint, so the layout makes room for it.
Parameters
| Name | Type | Description |
|---|---|---|
color |
const QColor& |
Colour of the lit light, usually one of the state colours of theme::Colors such as ok; an invalid QColor shows an unlit light. |
text |
const QString& |
Caption, short and upper case by convention, such as RUNNING; may be empty. |
Declared in src/app/widgets/status_led.hpp:43 · defined in src/app/widgets/status_led.cpp:52
set_blinking()¶
void set_blinking(bool blinking)
Starts or stops blinking, for example while recording.
A blinking light is on and off for 500 ms each, so it flashes once a second, and the caption dims with it. Starting or stopping restarts from the lit phase; a call that does not change the blinking state does nothing.
Parameters
| Name | Type | Description |
|---|---|---|
blinking |
bool |
True to blink, false to light steadily. |
Declared in src/app/widgets/status_led.hpp:51 · defined in src/app/widgets/status_led.cpp:65
color()¶
QColor color() const noexcept
Returns the colour set by set_state.
Returns QColor: The colour of the lit light; an invalid QColor for an unlit light.
Declared in src/app/widgets/status_led.hpp:56
text()¶
QString text() const noexcept
Returns the caption set by set_state.
Returns QString: The caption; empty before the first set_state.
Declared in src/app/widgets/status_led.hpp:60
blinking()¶
bool blinking() const noexcept
Returns whether the light is blinking.
Returns bool: True between set_blinking(true) and set_blinking(false).
Declared in src/app/widgets/status_led.hpp:64
sizeHint()¶
QSize sizeHint() const override
Returns the size that fits the light and the whole caption.
Returns QSize: 6 pixels of margin, the 9-pixel light, a 6-pixel gap, the caption width and 6 pixels of margin wide; the caption height or 9 pixels, whichever is larger, plus 4 pixels high.
Declared in src/app/widgets/status_led.hpp:71 · defined in src/app/widgets/status_led.cpp:78
minimumSizeHint()¶
QSize minimumSizeHint() const override
Returns the smallest size, which is sizeHint, so that layouts do not cut the caption off.
Returns QSize: The same size as sizeHint.
Declared in src/app/widgets/status_led.hpp:76
Protected member functions¶
paintEvent()¶
void paintEvent(QPaintEvent* event) override
Paints the light, with its glow when lit, centred vertically at the left, and the caption to its right, in the colours of the current theme.
Parameters
| Name | Type | Description |
|---|---|---|
event |
QPaintEvent* |
Paint event; not used, the whole widget is repainted. |
Declared in src/app/widgets/status_led.hpp:83 · defined in src/app/widgets/status_led.cpp:84
Private data members¶
color_¶
QColor color_
Colour of the lit light; invalid for an unlit light.
Declared in src/app/widgets/status_led.hpp:87
text_¶
QString text_
Caption shown to the right of the light.
Declared in src/app/widgets/status_led.hpp:89
blink_timer_¶
QTimer blink_timer_
Toggles lit_ every 500 ms while the light blinks; stopped otherwise.
Declared in src/app/widgets/status_led.hpp:91
lit_¶
bool lit_{true}
Whether the blink cycle is in its lit phase; always true when not blinking.
Declared in src/app/widgets/status_led.hpp:93