QtIndustrialWidgets 2.3.0
Modern, High-Performance Industrial Instruments & SCADA Widgets for Qt
Loading...
Searching...
No Matches
LedIndicator.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 Paolo Sereno <paolomsereno@gmail.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#pragma once
8
10#include <QtWidgets/QWidget>
11#include <memory>
12#include <QtGui/QColor>
13#include <QtCore/QTimer>
14
30namespace QtIndustrialWidgets {
31
32class LedIndicatorPrivate;
33
35{
36 Q_OBJECT
37
38 Q_PROPERTY(bool on READ isOn WRITE setOn NOTIFY stateChanged)
39 Q_PROPERTY(bool blinking READ isBlinking WRITE setBlinking NOTIFY blinkingChanged)
40 Q_PROPERTY(int blinkRateMs READ blinkRateMs WRITE setBlinkRateMs NOTIFY appearanceChanged)
41 Q_PROPERTY(QColor onColor READ onColor WRITE setOnColor NOTIFY appearanceChanged)
42 Q_PROPERTY(QColor offColor READ offColor WRITE setOffColor NOTIFY appearanceChanged)
43 Q_PROPERTY(QColor bezelColor READ bezelColor WRITE setBezelColor NOTIFY appearanceChanged)
44 Q_PROPERTY(bool bezelVisible READ isBezelVisible WRITE setBezelVisible NOTIFY appearanceChanged)
45 Q_PROPERTY(bool glowEffect READ hasGlowEffect WRITE setGlowEffect NOTIFY appearanceChanged)
46 Q_PROPERTY(LedShape shape READ shape WRITE setShape NOTIFY appearanceChanged)
47 Q_PROPERTY(QString labelText READ labelText WRITE setLabelText NOTIFY appearanceChanged)
48 Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY appearanceChanged)
49 Q_PROPERTY(bool clickable READ isClickable WRITE setClickable NOTIFY appearanceChanged)
50
51public:
53 enum class LedShape {
54 Circular,
55 Rectangular
56 };
57 Q_ENUM(LedShape)
58
59
63 explicit LedIndicator(QWidget *parent = nullptr);
69 explicit LedIndicator(const QColor &onColor, QWidget *parent = nullptr);
70 ~LedIndicator() override;
71
73 [[nodiscard]] bool isOn() const;
75 [[nodiscard]] bool isBlinking() const;
77 [[nodiscard]] int blinkRateMs() const;
79 [[nodiscard]] QColor onColor() const;
81 [[nodiscard]] QColor offColor() const;
83 [[nodiscard]] QColor bezelColor() const;
85 [[nodiscard]] bool isBezelVisible() const;
87 [[nodiscard]] bool hasGlowEffect() const;
89 [[nodiscard]] LedShape shape() const;
91 [[nodiscard]] QString labelText() const;
96 [[nodiscard]] QColor textColor() const;
98 [[nodiscard]] bool isClickable() const;
99
100 [[nodiscard]] QSize sizeHint() const override;
101 [[nodiscard]] QSize minimumSizeHint() const override;
102
103public Q_SLOTS:
105 void setOn(bool on);
107 void setOff();
109 void toggle();
111 void setBlinking(bool blinking);
113 void setBlinkRateMs(int rateMs);
115 void setOnColor(const QColor &color);
117 void setOffColor(const QColor &color);
119 void setBezelColor(const QColor &color);
121 void setBezelVisible(bool visible);
123 void setGlowEffect(bool glow);
125 void setShape(LedShape shape);
127 void setLabelText(const QString &text);
132 void setTextColor(const QColor &color);
134 void setClickable(bool clickable);
135
136Q_SIGNALS:
138 void stateChanged(bool on);
140 void blinkingChanged(bool blinking);
142 void clicked();
144 void appearanceChanged();
145
146protected:
147 void paintEvent(QPaintEvent *event) override;
148 void mousePressEvent(QMouseEvent *event) override;
149
150private Q_SLOTS:
151 void onBlinkTimeout();
152
153private:
154 [[nodiscard]] QColor calculateDefaultOffColor(const QColor &onCol) const;
155
156 std::unique_ptr<LedIndicatorPrivate> d_ptr;
157 Q_DECLARE_PRIVATE(LedIndicator)
158};
159
160} // namespace QtIndustrialWidgets
Definition LedIndicator.h:35
Definition AnalysisChart.h:21
Library export macros and version definitions for QtIndustrialWidgets.
#define QTINDUSTRIALWIDGETS_EXPORT
Export/import macro for shared library symbol visibility across dynamic linking boundaries.
Definition qtindustrialwidgets_global.h:25