QtIndustrialWidgets 2.3.0
Modern, High-Performance Industrial Instruments & SCADA Widgets for Qt
Loading...
Searching...
No Matches
SevenSegmentDisplay.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
33namespace QtIndustrialWidgets {
34
35class SevenSegmentDisplayPrivate;
36
38{
39 Q_OBJECT
40
41 Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged)
42 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
43 Q_PROPERTY(int digitCount READ digitCount WRITE setDigitCount NOTIFY appearanceChanged)
44 Q_PROPERTY(int decimalPlaces READ decimalPlaces WRITE setDecimalPlaces NOTIFY appearanceChanged)
45 Q_PROPERTY(bool showLeadingZeros READ showLeadingZeros WRITE setShowLeadingZeros NOTIFY appearanceChanged)
46 Q_PROPERTY(bool showDecimalPoint READ showDecimalPoint WRITE setShowDecimalPoint NOTIFY appearanceChanged)
47 Q_PROPERTY(double skewAngle READ skewAngle WRITE setSkewAngle NOTIFY appearanceChanged)
48 Q_PROPERTY(double segmentWidthRatio READ segmentWidthRatio WRITE setSegmentWidthRatio NOTIFY appearanceChanged)
49 Q_PROPERTY(QColor activeSegmentColor READ activeSegmentColor WRITE setActiveSegmentColor NOTIFY appearanceChanged)
50 Q_PROPERTY(QColor inactiveSegmentColor READ inactiveSegmentColor WRITE setInactiveSegmentColor NOTIFY appearanceChanged)
51 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY appearanceChanged)
52 Q_PROPERTY(QColor bezelColor READ bezelColor WRITE setBezelColor NOTIFY appearanceChanged)
53 Q_PROPERTY(bool bezelVisible READ isBezelVisible WRITE setBezelVisible NOTIFY appearanceChanged)
54
55public:
60 explicit SevenSegmentDisplay(QWidget *parent = nullptr);
61 ~SevenSegmentDisplay() override;
62
64 [[nodiscard]] double value() const;
66 [[nodiscard]] QString text() const;
68 [[nodiscard]] int digitCount() const;
70 [[nodiscard]] int decimalPlaces() const;
72 [[nodiscard]] bool showLeadingZeros() const;
74 [[nodiscard]] bool showDecimalPoint() const;
76 [[nodiscard]] double skewAngle() const;
78 [[nodiscard]] double segmentWidthRatio() const;
79
81 [[nodiscard]] QColor activeSegmentColor() const;
83 [[nodiscard]] QColor inactiveSegmentColor() const;
85 [[nodiscard]] QColor backgroundColor() const;
87 [[nodiscard]] QColor bezelColor() const;
89 [[nodiscard]] bool isBezelVisible() const;
90
91 [[nodiscard]] QSize sizeHint() const override;
92 [[nodiscard]] QSize minimumSizeHint() const override;
93
94public Q_SLOTS:
96 void setValue(double value);
98 void setText(const QString &text);
100 void display(double value);
102 void display(int value);
104 void display(const QString &text);
105
107 void setDigitCount(int count);
109 void setDecimalPlaces(int places);
111 void setShowLeadingZeros(bool show);
113 void setShowDecimalPoint(bool show);
115 void setSkewAngle(double angle);
117 void setSegmentWidthRatio(double ratio);
118
120 void setActiveSegmentColor(const QColor &color);
122 void setInactiveSegmentColor(const QColor &color);
124 void setBackgroundColor(const QColor &color);
126 void setBezelColor(const QColor &color);
128 void setBezelVisible(bool visible);
129
130Q_SIGNALS:
132 void valueChanged(double value);
134 void textChanged(const QString &text);
136 void appearanceChanged();
137
138protected:
139 void paintEvent(QPaintEvent *event) override;
140
141private:
142 void updateFormattedText();
143 static quint8 encodeChar(QChar ch);
144 void drawDigit(QPainter &painter, const QRectF &rect, quint8 mask, bool hasDecimalPoint) const;
145
146 std::unique_ptr<SevenSegmentDisplayPrivate> d_ptr;
147 Q_DECLARE_PRIVATE(SevenSegmentDisplay)
148};
149
150} // namespace QtIndustrialWidgets
Definition SevenSegmentDisplay.h:38
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