Toolbox Qt
Loading...
Searching...
No Matches
gaugetarget.h
1#ifndef TBQ_WIDGETS_GAUGETARGET_H
2#define TBQ_WIDGETS_GAUGETARGET_H
3
4#include "toolboxqt/toolboxqt_global.h"
5
6#include <QWidget>
7
8namespace tbq
9{
10
11class TOOLBOXQT_EXPORT GaugeTargetStyle
12{
13 Q_GADGET
14
15public:
16 enum GaugeElement
17 {
18 GAUGE_ZONE_BAR = 0,
19 GAUGE_ZONE_TOLERANCE,
20 GAUGE_MARK_TARGET_CURSOR,
21 GAUGE_MARK_TARGET_TEXT,
22 GAUGE_MARK_VALUE_CURSOR_OK,
23 GAUGE_MARK_VALUE_CURSOR_KO,
24 GAUGE_MARK_VALUE_TEXT_OK,
25 GAUGE_MARK_VALUE_TEXT_KO,
26
27 GAUGE_NB_ELEMENTS
28 };
29 Q_ENUM(GaugeElement)
30
31public:
33
34public:
35 QColor getColor(GaugeElement idElement) const;
36 int getMargins() const;
37 double getMarkFactor() const;
38
39public:
40 void reset();
41
42 void setColor(GaugeElement idElement, const QColor &color);
43 void setMargins(int margins);
44 void setMarkFactor(double factor);
45
46private:
47 QHash<GaugeElement, QColor> m_mapColors;
48 int m_margins = 0;
49 double m_markFactor = 0.0;
50};
51
52class TOOLBOXQT_EXPORT GaugeTarget : public QWidget
53{
54 Q_OBJECT
55
56public:
57 explicit GaugeTarget(QWidget *parent = nullptr);
58
59public:
60 bool isInTolerance() const;
61 GaugeTargetStyle getStyle() const;
62
63public:
64 void setValue(int value);
65
66 void setRange(int min, int max);
67 void setTarget(int target, int tolerance);
68 void setTarget(int target, int tolerance, int range);
69
70 void setStyle(const GaugeTargetStyle &style);
71
72public:
73 QSize sizeHint() const override;
74
75protected:
76 void paintEvent(QPaintEvent *event) override;
77
78private:
79 void updateProperties();
80 int findPixelFromValue(const QRect &zoneDraw, int value) const;
81
82 QRect calcZoneMarkText(const QFontMetrics &ftInfos, const QRect &zoneDraw, const QLine &mark, const QString &txt, bool atTop);
83
84private:
85 int m_value = 0;
86
87 int m_min = 0;
88 int m_max = 0;
89 int m_tolLow = 0;
90 int m_tolHigh = 0;
91 int m_target = 0;
92
93 GaugeTargetStyle m_style;
94};
95
96} // namespace tbq
97
98#endif // TBQ_WIDGETS_GAUGETARGET_H
A gauge used to determine how close we are from a target value.
Definition gaugetarget.h:53
Allow to set style of a GaugeTarget widget.
Definition gaugetarget.h:12
Namespace used for ToolBoxQt library.
Definition array2d.h:12