2
KSysGuard, the KDE System Guard
4
Copyright (c) 1999, 2000, 2001 Chris Schlaeger <cs@kde.org>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of version 2 of the GNU General Public
8
License as published by the Free Software Foundation.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
KSysGuard is currently maintained by Chris Schlaeger <cs@kde.org>.
20
Please do not commit any changes without consulting me first. Thanks!
22
$Id: MultiMeter.cc,v 1.5 2003/05/04 14:16:48 nhasan Exp $
29
#include <qlcdnumber.h>
34
#include <ksgrd/ColorPicker.h>
35
#include <ksgrd/SensorManager.h>
36
#include <ksgrd/StyleEngine.h>
38
#include "MultiMeter.moc"
39
#include "MultiMeterSettings.h"
41
MultiMeter::MultiMeter(QWidget* parent, const char* name,
42
const QString& title, double, double, bool nf)
43
: KSGRD::SensorDisplay(parent, name, title)
46
lowerLimit = upperLimit = 0;
47
lowerLimitActive = upperLimitActive = false;
50
normalDigitColor = KSGRD::Style->firstForegroundColor();
51
alarmDigitColor = KSGRD::Style->alarmColor();
53
lcd = new QLCDNumber(this, "meterLCD");
55
lcd = new QLCDNumber(frame(), "meterLCD");
57
lcd->setSegmentStyle(QLCDNumber::Filled);
58
setDigitColor(KSGRD::Style->backgroundColor());
59
lcd->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
60
QSizePolicy::Expanding, false));
62
setBackgroundColor(KSGRD::Style->backgroundColor());
63
/* All RMB clicks to the lcd widget will be handled by
64
* SensorDisplay::eventFilter. */
65
lcd->installEventFilter(this);
67
setPlotterWidget(lcd);
69
setMinimumSize(16, 16);
74
MultiMeter::addSensor(const QString& hostName, const QString& sensorName,
75
const QString& sensorType, const QString& title)
77
if (sensorType != "integer" && sensorType != "float")
80
registerSensor(new KSGRD::SensorProperties(hostName, sensorName, sensorType, title));
82
/* To differentiate between answers from value requests and info
83
* requests we use 100 for info requests. */
84
sendRequest(hostName, sensorName + "?", 100);
86
QToolTip::remove(lcd);
87
QToolTip::add(lcd, QString("%1:%2").arg(hostName).arg(sensorName));
94
MultiMeter::answerReceived(int id, const QString& answer)
96
/* We received something, so the sensor is probably ok. */
97
sensorError(id, false);
101
KSGRD::SensorIntegerInfo info(answer);
102
setUnit(KSGRD::SensorMgr->translateUnit(info.unit()));
106
double val = answer.toDouble();
107
int digits = (int) log10(val) + 1;
110
lcd->setNumDigits(2);
114
lcd->setNumDigits(digits);
116
lcd->setNumDigits(5);
120
if (lowerLimitActive && val < lowerLimit)
122
setDigitColor(alarmDigitColor);
124
else if (upperLimitActive && val > upperLimit)
126
setDigitColor(alarmDigitColor);
129
setDigitColor(normalDigitColor);
134
MultiMeter::resizeEvent(QResizeEvent*)
137
lcd->setGeometry(0, 0, width() - 1, height() - 1);
139
frame()->setGeometry(0, 0, width(), height());
143
MultiMeter::restoreSettings(QDomElement& element)
145
lowerLimitActive = element.attribute("lowerLimitActive").toInt();
146
lowerLimit = element.attribute("lowerLimit").toLong();
147
upperLimitActive = element.attribute("upperLimitActive").toInt();
148
upperLimit = element.attribute("upperLimit").toLong();
150
normalDigitColor = restoreColor(element, "normalDigitColor",
151
KSGRD::Style->firstForegroundColor());
152
alarmDigitColor = restoreColor(element, "alarmDigitColor",
153
KSGRD::Style->alarmColor());
154
setBackgroundColor(restoreColor(element, "backgroundColor",
155
KSGRD::Style->backgroundColor()));
157
addSensor(element.attribute("hostName"), element.attribute("sensorName"), (element.attribute("sensorType").isEmpty() ? "integer" : element.attribute("sensorType")), "");
159
SensorDisplay::restoreSettings(element);
167
MultiMeter::saveSettings(QDomDocument& doc, QDomElement& element, bool save)
169
element.setAttribute("hostName", sensors().at(0)->hostName());
170
element.setAttribute("sensorName", sensors().at(0)->name());
171
element.setAttribute("sensorType", sensors().at(0)->type());
172
element.setAttribute("showUnit", showUnit());
173
element.setAttribute("lowerLimitActive", (int) lowerLimitActive);
174
element.setAttribute("lowerLimit", (int) lowerLimit);
175
element.setAttribute("upperLimitActive", (int) upperLimitActive);
176
element.setAttribute("upperLimit", (int) upperLimit);
178
saveColor(element, "normalDigitColor", normalDigitColor);
179
saveColor(element, "alarmDigitColor", alarmDigitColor);
180
saveColor(element, "backgroundColor", lcd->backgroundColor());
182
SensorDisplay::saveSettings(doc, element);
191
MultiMeter::configureSettings()
193
mms = new MultiMeterSettings(this, "MultiMeterSettings");
195
mms->setTitle(title());
196
mms->setShowUnit(showUnit());
197
mms->setLowerLimitActive(lowerLimitActive);
198
mms->setLowerLimit(lowerLimit);
199
mms->setUpperLimitActive(upperLimitActive);
200
mms->setUpperLimit(upperLimit);
201
mms->setNormalDigitColor(normalDigitColor);
202
mms->setAlarmDigitColor(alarmDigitColor);
203
mms->setMeterBackgroundColor(lcd->backgroundColor());
205
connect(mms, SIGNAL(applyClicked()), SLOT(applySettings()));
215
MultiMeter::applySettings()
217
setShowUnit( mms->showUnit() );
218
setTitle(mms->title());
219
lowerLimitActive = mms->lowerLimitActive();
220
lowerLimit = mms->lowerLimit();
221
upperLimitActive = mms->upperLimitActive();
222
upperLimit = mms->upperLimit();
224
normalDigitColor = mms->normalDigitColor();
225
alarmDigitColor = mms->alarmDigitColor();
226
setBackgroundColor(mms->meterBackgroundColor());
233
MultiMeter::applyStyle()
235
normalDigitColor = KSGRD::Style->firstForegroundColor();
236
setBackgroundColor(KSGRD::Style->backgroundColor());
242
MultiMeter::setDigitColor(const QColor& col)
244
QPalette p = lcd->palette();
245
p.setColor(QColorGroup::Foreground, col);
250
MultiMeter::setBackgroundColor(const QColor& col)
252
lcd->setBackgroundColor(col);
254
QPalette p = lcd->palette();
255
p.setColor(QColorGroup::Light, col);
256
p.setColor(QColorGroup::Dark, col);