1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/***************************************************************************
lmsensordockpanel.cpp - description
-------------------
begin : Tue Sep 18 2001
copyright : (C) 2001 by Miguel Novas
email : michaell@teleline.es
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <ntqpixmap.h>
#include <kstddirs.h>
#include <tdelocale.h>
#include <tdeconfig.h>
#include <kiconloader.h>
#include "lmsensordockpanel.h"
LMSensorDockPanel::LMSensorDockPanel(Sensor *newSensor, const char *name) : KSystemTray( 0, name )
{
strValue = "";
if(newSensor) {
sensor= newSensor;
updateConfig();
connect( newSensor, SIGNAL(valueChanged(double)) , this, SLOT(setValue(double)) );
connect( newSensor, SIGNAL(configChanged()) , this, SLOT(updateConfig()) );
setPixmap(0);
} else {
sensor= 0;
setPixmap(BarIcon("ksensorsdocked"));
}
}
LMSensorDockPanel::~LMSensorDockPanel()
{
}
void LMSensorDockPanel::setValue(double value)
{
if(sensor) {
switch(sensor->getType()) {
case Sensor::lmTemp:
strValue.sprintf("%2.0f",value);
break;
case Sensor::lmFan:
strValue.sprintf("%1.1f",value/1000);
break;
case Sensor::lmVoltage:
strValue.sprintf("%2.1f",value);
break;
}
update();
}
}
void LMSensorDockPanel::updateConfig()
{
colorAlarm = readColorAlarm (name());
colorNormal= readColorNormal(name());
setValue(sensor->getValue());
}
void LMSensorDockPanel::paintEvent ( TQPaintEvent *e )
{
if(sensor) {
int w= width();
int h= height();
TQPainter painter(this);
TQColor color= sensor->getAlarm() ? colorAlarm : colorNormal;
TQColor colorShadow= color.dark(200);
painter.setPen(color);
painter.drawLine(2, 2 , w-2,2 );
painter.drawLine(2, h-3, w-2,h-3);
painter.setPen(colorShadow);
painter.drawLine(3, 3 , w-3,3 );
painter.drawLine(3, h-4, w-3,h-4);
if(sensor->getType()==Sensor::lmTemp) {
TQLcd::draw(&painter,4,6,w-6, h-12,strValue.latin1(),TQLcd::drawShadow,&color,&colorShadow);
} else {
TQLcd::draw(&painter,1,7,w-1, h-14,strValue.latin1(),TQLcd::drawNumber|TQLcd::alignCenter|TQLcd::drawShadow,&color,&colorShadow);
}
} else {
KSystemTray::paintEvent(e);
}
}
void LMSensorDockPanel::mousePressEvent ( TQMouseEvent *e )
{
emit mouseEvent(e);
}
void LMSensorDockPanel::mouseReleaseEvent ( TQMouseEvent *e )
{
emit mouseEvent(e);
}
//*****************************************************************+
void LMSensorDockPanel::writeColorAlarm(const char *name, const TQColor &color)
{
TDEGlobal::config()->setGroup(name);
TDEGlobal::config()->writeEntry("colorAlarm",color);
}
void LMSensorDockPanel::writeColorNormal(const char *name,const TQColor &color)
{
TDEGlobal::config()->setGroup(name);
TDEGlobal::config()->writeEntry("colorNormal",color);
}
TQColor LMSensorDockPanel::readColorAlarm(const char *name)
{
TDEGlobal::config()->setGroup(name);
return TDEGlobal::config()->readColorEntry("colorAlarm" , &red );
}
TQColor LMSensorDockPanel::readColorNormal(const char *name)
{
TDEGlobal::config()->setGroup(name);
return TDEGlobal::config()->readColorEntry("colorNormal", &darkGreen);
}
void LMSensorDockPanel::writeShowInDock(const char *name, bool fShow)
{
TDEGlobal::config()->setGroup(name);
TDEGlobal::config()->writeEntry("showInDock",fShow);
}
bool LMSensorDockPanel::readShowInDock(const char *name)
{
TDEGlobal::config()->setGroup(name);
return TDEGlobal::config()->readBoolEntry("showInDock", false);
}
|