You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
259 lines
6.8 KiB
259 lines
6.8 KiB
15 years ago
|
/*
|
||
|
KSysGuard, the KDE System Guard
|
||
|
|
||
|
Copyright (c) 1999, 2000, 2001 Chris Schlaeger <cs@kde.org>
|
||
|
|
||
|
This program is free software; you can redistribute it and/or
|
||
|
modify it under the terms of version 2 of the GNU General Public
|
||
|
License as published by the Free Software Foundation.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; if not, write to the Free Software
|
||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
|
||
|
KSysGuard is currently maintained by Chris Schlaeger <cs@kde.org>.
|
||
|
Please do not commit any changes without consulting me first. Thanks!
|
||
|
|
||
|
*/
|
||
|
|
||
|
#include <math.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
15 years ago
|
#include <tqdom.h>
|
||
|
#include <tqlcdnumber.h>
|
||
|
#include <tqtooltip.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
#include <ksgrd/SensorManager.h>
|
||
|
#include <ksgrd/StyleEngine.h>
|
||
|
|
||
|
#include "MultiMeter.moc"
|
||
|
#include "MultiMeterSettings.h"
|
||
|
|
||
15 years ago
|
MultiMeter::MultiMeter(TQWidget* parent, const char* name,
|
||
|
const TQString& title, double, double, bool nf, bool isApplet)
|
||
15 years ago
|
: KSGRD::SensorDisplay(parent, name, title, nf, isApplet)
|
||
|
{
|
||
|
setShowUnit( true );
|
||
|
lowerLimit = upperLimit = 0;
|
||
|
lowerLimitActive = upperLimitActive = false;
|
||
|
|
||
|
normalDigitColor = KSGRD::Style->firstForegroundColor();
|
||
|
alarmDigitColor = KSGRD::Style->alarmColor();
|
||
|
if (noFrame())
|
||
15 years ago
|
lcd = new TQLCDNumber(this, "meterLCD");
|
||
15 years ago
|
else
|
||
15 years ago
|
lcd = new TQLCDNumber(frame(), "meterLCD");
|
||
13 years ago
|
TQ_CHECK_PTR(lcd);
|
||
15 years ago
|
lcd->setSegmentStyle(TQLCDNumber::Filled);
|
||
15 years ago
|
setDigitColor(KSGRD::Style->backgroundColor());
|
||
13 years ago
|
lcd->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding,
|
||
15 years ago
|
TQSizePolicy::Expanding, false));
|
||
15 years ago
|
|
||
|
setBackgroundColor(KSGRD::Style->backgroundColor());
|
||
|
/* All RMB clicks to the lcd widget will be handled by
|
||
|
* SensorDisplay::eventFilter. */
|
||
|
lcd->installEventFilter(this);
|
||
|
|
||
|
setPlotterWidget(lcd);
|
||
|
|
||
|
setMinimumSize(5, 5);
|
||
|
setModified(false);
|
||
|
}
|
||
|
|
||
|
bool
|
||
15 years ago
|
MultiMeter::addSensor(const TQString& hostName, const TQString& sensorName,
|
||
|
const TQString& sensorType, const TQString& title)
|
||
15 years ago
|
{
|
||
|
if (sensorType != "integer" && sensorType != "float")
|
||
|
return (false);
|
||
|
|
||
|
registerSensor(new KSGRD::SensorProperties(hostName, sensorName, sensorType, title));
|
||
|
|
||
|
/* To differentiate between answers from value requests and info
|
||
|
* requests we use 100 for info requests. */
|
||
|
sendRequest(hostName, sensorName + "?", 100);
|
||
|
|
||
15 years ago
|
TQToolTip::remove(lcd);
|
||
|
TQToolTip::add(lcd, TQString("%1:%2").arg(hostName).arg(sensorName));
|
||
15 years ago
|
|
||
|
setModified(true);
|
||
|
return (true);
|
||
|
}
|
||
|
|
||
|
void
|
||
15 years ago
|
MultiMeter::answerReceived(int id, const TQString& answer)
|
||
15 years ago
|
{
|
||
|
/* We received something, so the sensor is probably ok. */
|
||
|
sensorError(id, false);
|
||
|
|
||
|
if (id == 100)
|
||
|
{
|
||
|
KSGRD::SensorIntegerInfo info(answer);
|
||
|
setUnit(KSGRD::SensorMgr->translateUnit(info.unit()));
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
double val = answer.toDouble();
|
||
|
int digits = (int) log10(val) + 1;
|
||
|
|
||
|
if (noFrame())
|
||
|
if (digits > 4)
|
||
|
lcd->setNumDigits(4);
|
||
|
else
|
||
|
lcd->setNumDigits(digits);
|
||
|
else
|
||
|
{
|
||
|
if (digits > 5)
|
||
|
lcd->setNumDigits(digits);
|
||
|
else
|
||
|
lcd->setNumDigits(5);
|
||
|
}
|
||
|
|
||
|
lcd->display(val);
|
||
|
if (lowerLimitActive && val < lowerLimit)
|
||
|
{
|
||
|
setDigitColor(alarmDigitColor);
|
||
|
}
|
||
|
else if (upperLimitActive && val > upperLimit)
|
||
|
{
|
||
|
setDigitColor(alarmDigitColor);
|
||
|
}
|
||
|
else
|
||
|
setDigitColor(normalDigitColor);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
15 years ago
|
MultiMeter::resizeEvent(TQResizeEvent*)
|
||
15 years ago
|
{
|
||
|
if (noFrame())
|
||
|
lcd->setGeometry(0, 0, width(), height());
|
||
|
else
|
||
|
frame()->setGeometry(0, 0, width(), height());
|
||
|
}
|
||
|
|
||
|
bool
|
||
15 years ago
|
MultiMeter::restoreSettings(TQDomElement& element)
|
||
15 years ago
|
{
|
||
|
lowerLimitActive = element.attribute("lowerLimitActive").toInt();
|
||
|
lowerLimit = element.attribute("lowerLimit").toLong();
|
||
|
upperLimitActive = element.attribute("upperLimitActive").toInt();
|
||
|
upperLimit = element.attribute("upperLimit").toLong();
|
||
|
|
||
|
normalDigitColor = restoreColor(element, "normalDigitColor",
|
||
|
KSGRD::Style->firstForegroundColor());
|
||
|
alarmDigitColor = restoreColor(element, "alarmDigitColor",
|
||
|
KSGRD::Style->alarmColor());
|
||
|
setBackgroundColor(restoreColor(element, "backgroundColor",
|
||
|
KSGRD::Style->backgroundColor()));
|
||
|
|
||
|
addSensor(element.attribute("hostName"), element.attribute("sensorName"), (element.attribute("sensorType").isEmpty() ? "integer" : element.attribute("sensorType")), "");
|
||
|
|
||
|
SensorDisplay::restoreSettings(element);
|
||
|
|
||
|
setModified(false);
|
||
|
|
||
|
return (true);
|
||
|
}
|
||
|
|
||
|
bool
|
||
15 years ago
|
MultiMeter::saveSettings(TQDomDocument& doc, TQDomElement& element, bool save)
|
||
15 years ago
|
{
|
||
13 years ago
|
element.setAttribute("hostName", sensors().at(0)->hostName());
|
||
|
element.setAttribute("sensorName", sensors().at(0)->name());
|
||
|
element.setAttribute("sensorType", sensors().at(0)->type());
|
||
15 years ago
|
element.setAttribute("showUnit", showUnit());
|
||
|
element.setAttribute("lowerLimitActive", (int) lowerLimitActive);
|
||
|
element.setAttribute("lowerLimit", (int) lowerLimit);
|
||
|
element.setAttribute("upperLimitActive", (int) upperLimitActive);
|
||
|
element.setAttribute("upperLimit", (int) upperLimit);
|
||
|
|
||
|
saveColor(element, "normalDigitColor", normalDigitColor);
|
||
|
saveColor(element, "alarmDigitColor", alarmDigitColor);
|
||
|
saveColor(element, "backgroundColor", lcd->backgroundColor());
|
||
|
|
||
|
SensorDisplay::saveSettings(doc, element);
|
||
|
|
||
|
if (save)
|
||
|
setModified(false);
|
||
|
|
||
|
return (true);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
MultiMeter::configureSettings()
|
||
|
{
|
||
|
mms = new MultiMeterSettings(this, "MultiMeterSettings");
|
||
13 years ago
|
TQ_CHECK_PTR(mms);
|
||
15 years ago
|
mms->setTitle(title());
|
||
|
mms->setShowUnit(showUnit());
|
||
|
mms->setLowerLimitActive(lowerLimitActive);
|
||
|
mms->setLowerLimit(lowerLimit);
|
||
|
mms->setUpperLimitActive(upperLimitActive);
|
||
|
mms->setUpperLimit(upperLimit);
|
||
|
mms->setNormalDigitColor(normalDigitColor);
|
||
|
mms->setAlarmDigitColor(alarmDigitColor);
|
||
|
mms->setMeterBackgroundColor(lcd->backgroundColor());
|
||
|
|
||
15 years ago
|
connect(mms, TQT_SIGNAL(applyClicked()), TQT_SLOT(applySettings()));
|
||
15 years ago
|
|
||
|
if (mms->exec())
|
||
|
applySettings();
|
||
|
|
||
|
delete mms;
|
||
|
mms = 0;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
MultiMeter::applySettings()
|
||
|
{
|
||
|
setShowUnit( mms->showUnit() );
|
||
|
setTitle(mms->title());
|
||
|
lowerLimitActive = mms->lowerLimitActive();
|
||
|
lowerLimit = mms->lowerLimit();
|
||
|
upperLimitActive = mms->upperLimitActive();
|
||
|
upperLimit = mms->upperLimit();
|
||
|
|
||
|
normalDigitColor = mms->normalDigitColor();
|
||
|
alarmDigitColor = mms->alarmDigitColor();
|
||
|
setBackgroundColor(mms->meterBackgroundColor());
|
||
|
|
||
13 years ago
|
repaint();
|
||
15 years ago
|
setModified(true);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
MultiMeter::applyStyle()
|
||
|
{
|
||
|
normalDigitColor = KSGRD::Style->firstForegroundColor();
|
||
|
setBackgroundColor(KSGRD::Style->backgroundColor());
|
||
13 years ago
|
repaint();
|
||
15 years ago
|
setModified(true);
|
||
|
}
|
||
|
|
||
|
void
|
||
15 years ago
|
MultiMeter::setDigitColor(const TQColor& col)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPalette p = lcd->palette();
|
||
|
p.setColor(TQColorGroup::Foreground, col);
|
||
15 years ago
|
lcd->setPalette(p);
|
||
|
}
|
||
|
|
||
|
void
|
||
15 years ago
|
MultiMeter::setBackgroundColor(const TQColor& col)
|
||
15 years ago
|
{
|
||
|
lcd->setBackgroundColor(col);
|
||
|
|
||
15 years ago
|
TQPalette p = lcd->palette();
|
||
|
p.setColor(TQColorGroup::Light, col);
|
||
|
p.setColor(TQColorGroup::Dark, col);
|
||
15 years ago
|
lcd->setPalette(p);
|
||
|
}
|