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 the GNU General Public
8
License version 2 or at your option version 3 as published by
9
the Free Software Foundation.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
#include <QtXml/qdom.h>
26
#include <QtGui/QLCDNumber>
27
#include <QtGui/QHBoxLayout>
31
#include <ksgrd/SensorManager.h>
32
#include "StyleEngine.h"
34
#include "MultiMeter.h"
35
#include "MultiMeterSettings.h"
37
MultiMeter::MultiMeter(QWidget* parent, const QString& title, SharedSettings *workSheetSettings)
38
: KSGRD::SensorDisplay(parent, title, workSheetSettings)
41
mLowerLimit = mUpperLimit = 0.0;
42
mLowerLimitActive = mUpperLimitActive = false;
46
mNormalDigitColor = KSGRD::Style->firstForegroundColor();
47
mAlarmDigitColor = KSGRD::Style->alarmColor();
48
QLayout *layout = new QHBoxLayout(this);
49
mLcd = new QLCDNumber( this );
50
layout->addWidget(mLcd);
52
mLcd->setFrameStyle( QFrame::NoFrame );
53
mLcd->setSegmentStyle( QLCDNumber::Filled );
54
setDigitColor( KSGRD::Style->firstForegroundColor() );
55
mLcd->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
57
setBackgroundColor( KSGRD::Style->backgroundColor() );
59
/* All RMB clicks to the mLcd widget will be handled by
60
* SensorDisplay::eventFilter. */
61
mLcd->installEventFilter( this );
63
setPlotterWidget( mLcd );
65
setMinimumSize( 5, 5 );
68
bool MultiMeter::addSensor(const QString& hostName, const QString& sensorName,
69
const QString& sensorType, const QString& title)
71
if (sensorType != "integer" && sensorType != "float")
74
if(!sensors().isEmpty())
77
mIsFloat = (sensorType == "float");
78
mLcd->setSmallDecimalPoint( mIsFloat );
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
mLcd->setToolTip( QString("%1:%2").arg(hostName).arg(sensorName));
91
void MultiMeter::answerReceived(int id, const QList<QByteArray>& answerlist)
93
/* We received something, so the sensor is probably ok. */
94
sensorError(id, false);
96
if(!answerlist.isEmpty()) answer = answerlist[0];
100
KSGRD::SensorIntegerInfo info(answer);
101
setUnit(KSGRD::SensorMgr->translateUnit(info.unit()));
105
double val = answer.toDouble();
108
if (qAbs(val) >= 1) {
109
digits = (int) log10(qAbs(val)) + 1;
112
//Show two digits after the decimal point
116
//Add a digit for the negative sign
120
mLcd->setNumDigits(qMin(15,digits));
123
if (mLowerLimitActive && val < mLowerLimit)
125
setDigitColor(mAlarmDigitColor);
127
else if (mUpperLimitActive && val > mUpperLimit)
129
setDigitColor(mAlarmDigitColor);
132
setDigitColor(mNormalDigitColor);
136
bool MultiMeter::restoreSettings(QDomElement& element)
138
mLowerLimitActive = element.attribute("lowerLimitActive").toInt();
139
mLowerLimit = element.attribute("lowerLimit").toDouble();
140
mUpperLimitActive = element.attribute("upperLimitActive").toInt();
141
mUpperLimit = element.attribute("upperLimit").toDouble();
143
mNormalDigitColor = restoreColor(element, "normalDigitColor",
144
KSGRD::Style->firstForegroundColor());
145
mAlarmDigitColor = restoreColor(element, "mAlarmDigitColor",
146
KSGRD::Style->alarmColor());
147
setBackgroundColor(restoreColor(element, "backgroundColor",
148
KSGRD::Style->backgroundColor()));
150
addSensor(element.attribute("hostName"), element.attribute("sensorName"), (element.attribute("sensorType").isEmpty() ? "integer" : element.attribute("sensorType")), "");
152
SensorDisplay::restoreSettings(element);
157
bool MultiMeter::saveSettings(QDomDocument& doc, QDomElement& element)
159
if(!sensors().isEmpty()) {
160
element.setAttribute("hostName", sensors().at(0)->hostName());
161
element.setAttribute("sensorName", sensors().at(0)->name());
162
element.setAttribute("sensorType", sensors().at(0)->type());
164
element.setAttribute("showUnit", showUnit());
165
element.setAttribute("lowerLimitActive", (int) mLowerLimitActive);
166
element.setAttribute("lowerLimit", mLowerLimit);
167
element.setAttribute("upperLimitActive", (int) mUpperLimitActive);
168
element.setAttribute("upperLimit", mUpperLimit);
170
saveColor(element, "normalDigitColor", mNormalDigitColor);
171
saveColor(element, "mAlarmDigitColor", mAlarmDigitColor);
172
saveColor(element, "backgroundColor", mBackgroundColor);
174
SensorDisplay::saveSettings(doc, element);
179
void MultiMeter::configureSettings()
181
MultiMeterSettings dlg( this );
183
dlg.setTitle(title());
184
dlg.setShowUnit(showUnit());
185
dlg.setLowerLimitActive(mLowerLimitActive);
186
dlg.setLowerLimit(mLowerLimit);
187
dlg.setUpperLimitActive(mUpperLimitActive);
188
dlg.setUpperLimit(mUpperLimit);
189
dlg.setNormalDigitColor(mNormalDigitColor);
190
dlg.setAlarmDigitColor(mAlarmDigitColor);
191
dlg.setMeterBackgroundColor(mBackgroundColor);
194
setShowUnit( dlg.showUnit() );
195
setTitle( dlg.title() );
196
mLowerLimitActive = dlg.lowerLimitActive();
197
mLowerLimit = dlg.lowerLimit();
198
mUpperLimitActive = dlg.upperLimitActive();
199
mUpperLimit = dlg.upperLimit();
201
mNormalDigitColor = dlg.normalDigitColor();
202
mAlarmDigitColor = dlg.alarmDigitColor();
203
setBackgroundColor( dlg.meterBackgroundColor() );
209
void MultiMeter::applyStyle()
211
mNormalDigitColor = KSGRD::Style->firstForegroundColor();
212
setBackgroundColor( KSGRD::Style->backgroundColor() );
217
void MultiMeter::setDigitColor( const QColor& color )
219
QPalette palette = mLcd->palette();
220
palette.setColor( QPalette::WindowText, color );
221
mLcd->setPalette( palette );
224
void MultiMeter::setBackgroundColor( const QColor& color )
226
mBackgroundColor = color;
228
QPalette pal = mLcd->palette();
229
pal.setColor( mLcd->backgroundRole(), mBackgroundColor );
230
mLcd->setPalette( pal );
233
#include "MultiMeter.moc"