|
1 /*************************************************************************** |
|
2 * Copyright (C) 2006-2008 by Tomasz Ziobrowski * |
|
3 * http://www.3electrons.com * |
|
4 * e-mail: t.ziobrowski@3electrons.com * |
|
5 * * |
|
6 * * |
|
7 * This program is free software; you can redistribute it and/or modify * |
|
8 * it under the terms of the GNU General Public License as published by * |
|
9 * the Free Software Foundation; either version 2 of the License, or * |
|
10 * (at your option) any later version. * |
|
11 * * |
|
12 * This program is distributed in the hope that it will be useful, * |
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|
15 * GNU General Public License for more details. * |
|
16 * * |
|
17 * You should have received a copy of the GNU General Public License * |
|
18 * along with this program; if not, write to the * |
|
19 * Free Software Foundation, Inc., * |
|
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
|
21 ***************************************************************************/ |
|
22 |
|
23 #ifndef ABSTRACTMETER_H |
|
24 #define ABSTRACTMETER_H |
|
25 |
|
26 #include "widgetwithbackground.h" |
|
27 |
|
28 /** |
|
29 * Abstract class for Meter/Gauge classes |
|
30 */ |
|
31 class AbstractMeter : public WidgetWithBackground |
|
32 { |
|
33 Q_OBJECT |
|
34 Q_PROPERTY (double minimum READ minimum WRITE setMinimum ) |
|
35 Q_PROPERTY (double maximum READ maximum WRITE setMaximum ) |
|
36 Q_PROPERTY (double value READ value WRITE setValue ) |
|
37 Q_PROPERTY (double nominal READ nominal WRITE setNominal); |
|
38 Q_PROPERTY (double critical READ critical WRITE setCritical); |
|
39 |
|
40 Q_PROPERTY (QString prefix READ prefix WRITE setPrefix) |
|
41 Q_PROPERTY (QString suffix READ suffix WRITE setSuffix) |
|
42 Q_PROPERTY (QFont valueFont READ valueFont WRITE setValueFont) |
|
43 Q_PROPERTY (double valueOffset READ valueOffset WRITE setValueOffset) |
|
44 Q_PROPERTY (QFont digitFont READ digitFont WRITE setDigitFont) |
|
45 Q_PROPERTY (double digitOffset READ digitOffset WRITE setDigitOffset) |
|
46 |
|
47 |
|
48 public: |
|
49 |
|
50 AbstractMeter(QWidget *parent = 0); |
|
51 virtual ~AbstractMeter() {}; |
|
52 |
|
53 double minimum() const { return m_minimum; } |
|
54 void setMinimum(double i); |
|
55 double maximum() const { return m_maximum; } |
|
56 void setMaximum(double i); |
|
57 double value() const { return m_value;} |
|
58 |
|
59 double nominal() const { return m_nominal; } |
|
60 void setNominal(double i) { m_nominal = i; updateWithBackground();} |
|
61 double critical() const { return m_critical; } |
|
62 void setCritical(double i) { m_critical = i; updateWithBackground();} |
|
63 |
|
64 QFont valueFont() const { return m_valueFont; } |
|
65 void setValueFont(QFont f){ m_valueFont = f; updateWithBackground(); } |
|
66 |
|
67 double valueOffset() const { return m_valueOffset; } |
|
68 void setValueOffset(double v){ m_valueOffset = v; updateWithBackground();} |
|
69 |
|
70 double digitOffset() const { return m_digitOffset; } |
|
71 void setDigitOffset(double v){ m_digitOffset = v; updateWithBackground();} |
|
72 |
|
73 QFont digitFont() const { return m_digitFont; } |
|
74 void setDigitFont(QFont f){ m_digitFont = f; updateWithBackground(); } |
|
75 |
|
76 QString prefix() const { return m_prefix; } |
|
77 void setPrefix(QString s) { m_prefix = s; updateWithBackground(); } |
|
78 |
|
79 QString suffix() const { return m_suffix; } |
|
80 void setSuffix(QString s) { m_suffix = s; updateWithBackground(); } |
|
81 |
|
82 public slots: |
|
83 void setValue(int val); |
|
84 void setValue(double val); |
|
85 signals: |
|
86 void valueChanged(int val); |
|
87 void valueChanged(double val); |
|
88 |
|
89 protected: |
|
90 |
|
91 /** |
|
92 * Calculate m_max and m_min values shown on scale |
|
93 * @return true if m_max or m_min has been changed |
|
94 */ |
|
95 |
|
96 bool calcMaxMin(); |
|
97 |
|
98 /** Starting value on meter this value is less than m_minimum */ |
|
99 double m_min; |
|
100 /** Endgind value on meter this value is more than m_maximum*/ |
|
101 double m_max; |
|
102 |
|
103 /** Minimum that has to be on scale */ |
|
104 double m_minimum; |
|
105 /** Maximum that has to be on scale */ |
|
106 double m_maximum; |
|
107 |
|
108 /** Current value */ |
|
109 double m_value; |
|
110 |
|
111 /** Nominal value (allowed value) by convention mark by green look to manometer and thermometer widgets */ |
|
112 double m_nominal; |
|
113 /** Critical value (maximum allowed value) by convention mark by red */ |
|
114 double m_critical; |
|
115 |
|
116 /** Used to place value string on component */ |
|
117 double m_valueOffset; |
|
118 /** Used to place scale digits offset. On manometer distance from the center on thermometer distance form left */ |
|
119 double m_digitOffset; |
|
120 |
|
121 /** Font used to display value */ |
|
122 QFont m_valueFont; |
|
123 /** Font used to display scale digit/numbers */ |
|
124 QFont m_digitFont; |
|
125 |
|
126 /** Prefix added to value string like Speed */ |
|
127 QString m_prefix; |
|
128 /** Postfix added to value string like km/h or mph */ |
|
129 QString m_suffix; |
|
130 |
|
131 };// AbstractMeter |
|
132 |
|
133 #endif // ABSTRACTMETER_H_ |