|
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 #include <assert.h> |
|
24 #include "abstractmeter.h" |
|
25 #include "functions.h" |
|
26 |
|
27 AbstractMeter::AbstractMeter(QWidget * parent ) |
|
28 : WidgetWithBackground (parent) |
|
29 { |
|
30 m_min=m_minimum=0.0; |
|
31 m_max=m_maximum=1.0; |
|
32 m_digitOffset=1.0; |
|
33 m_nominal=0.25; |
|
34 m_critical=0.75; |
|
35 } |
|
36 |
|
37 |
|
38 bool AbstractMeter::calcMaxMin() |
|
39 { |
|
40 return range(m_minimum,m_maximum,m_min,m_max,8,true); |
|
41 } |
|
42 |
|
43 void AbstractMeter::setValue( double val ) |
|
44 { |
|
45 if ( m_value != val ) |
|
46 { |
|
47 m_value = val; |
|
48 update(); |
|
49 emit valueChanged(val); |
|
50 emit valueChanged((int)val); |
|
51 } |
|
52 } |
|
53 |
|
54 void AbstractMeter::setValue( int val ) |
|
55 { |
|
56 if ( m_value != val ) |
|
57 { |
|
58 m_value = val; |
|
59 update(); // Ciekawe czy tak jest lepiej ?? |
|
60 // to znaczy najpierw odmalować a potem generować sygnał ? |
|
61 emit valueChanged(val); |
|
62 emit valueChanged(double(val)); |
|
63 } |
|
64 } |
|
65 |
|
66 void AbstractMeter::setMinimum(double i) |
|
67 { |
|
68 if ((m_maximum - i) > 0.00001 ) |
|
69 { |
|
70 m_minimum = i; |
|
71 if (calcMaxMin()) updateWithBackground(); |
|
72 } |
|
73 } |
|
74 |
|
75 void AbstractMeter::setMaximum(double i) |
|
76 { |
|
77 if ( (i - m_minimum) > 0.00001 ) |
|
78 { |
|
79 m_maximum = i; |
|
80 if (calcMaxMin()) updateWithBackground(); |
|
81 } |
|
82 } |
|
83 |
|
84 |