summaryrefslogtreecommitdiff
path: root/core
Unidiff
Diffstat (limited to 'core') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/battery.cpp104
-rw-r--r--core/applets/batteryapplet/battery.h3
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp407
-rw-r--r--core/applets/batteryapplet/batterystatus.h12
4 files changed, 270 insertions, 256 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp
index 98b61b5..0d3d190 100644
--- a/core/applets/batteryapplet/battery.cpp
+++ b/core/applets/batteryapplet/battery.cpp
@@ -35,12 +35,11 @@
35 35
36using namespace Opie::Ui; 36using namespace Opie::Ui;
37BatteryMeter::BatteryMeter( QWidget *parent ) 37BatteryMeter::BatteryMeter( QWidget *parent )
38 : QWidget( parent ), charging(false) 38: QWidget( parent ), charging(false) {
39{
40 ps = new PowerStatus; 39 ps = new PowerStatus;
41 startTimer( 10000 ); 40 startTimer( 10000 );
42 41
43 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); 42 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) );
44 setFixedHeight( AppLnk::smallIconSize() ); 43 setFixedHeight( AppLnk::smallIconSize() );
45 44
46 chargeTimer = new QTimer( this ); 45 chargeTimer = new QTimer( this );
@@ -52,20 +51,16 @@ BatteryMeter::BatteryMeter( QWidget *parent )
52 style = c.readNumEntry( "Style", 0 ); 51 style = c.readNumEntry( "Style", 0 );
53} 52}
54 53
55BatteryMeter::~BatteryMeter() 54BatteryMeter::~BatteryMeter() {
56{
57 delete ps; 55 delete ps;
58} 56}
59 57
60QSize BatteryMeter::sizeHint() const 58QSize BatteryMeter::sizeHint() const {
61{
62 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); 59 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() );
63} 60}
64 61
65void BatteryMeter::mousePressEvent( QMouseEvent* e ) 62void BatteryMeter::mousePressEvent( QMouseEvent* e ) {
66{ 63 if ( e->button() == RightButton ) {
67 if ( e->button() == RightButton )
68 {
69 style = 1-style; 64 style = 1-style;
70 Config c( "qpe" ); 65 Config c( "qpe" );
71 c.setGroup( "Battery" ); 66 c.setGroup( "Battery" );
@@ -75,58 +70,64 @@ void BatteryMeter::mousePressEvent( QMouseEvent* e )
75 QWidget::mousePressEvent( e ); 70 QWidget::mousePressEvent( e );
76} 71}
77 72
78void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) 73void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) {
79{
80 if ( batteryView && batteryView->isVisible() ) { 74 if ( batteryView && batteryView->isVisible() ) {
81 delete (QWidget *) batteryView; 75 batteryView->hide();
82 } else { 76 } else {
83 if ( !batteryView ) batteryView = new BatteryStatus( ps ); 77 if ( !batteryView ) {
84 QPEApplication::showWidget( batteryView ); 78 batteryView = new BatteryStatus( ps, 0, WStyle_StaysOnTop | WType_Popup );
79 batteryView->setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
80 }
81
82 QRect r(batteryView->pos(),batteryView->sizeHint());
83 QPoint curPos = this->mapToGlobal ( rect().topLeft() );
84
85 int lp = qApp->desktop()->width() - batteryView->sizeHint().width();
86 r.moveTopLeft( QPoint(lp, curPos.y()-batteryView->sizeHint().height()-1) );
87 batteryView->setGeometry(r);
88
85 batteryView->raise(); 89 batteryView->raise();
86 batteryView->showMaximized(); 90 batteryView->show();
87 } 91 }
88} 92}
89 93
90void BatteryMeter::timerEvent( QTimerEvent * ) 94
91{ 95void BatteryMeter::timerEvent( QTimerEvent * ) {
92 PowerStatus prev = *ps; 96 PowerStatus prev = *ps;
93 97
94 *ps = PowerStatusManager::readStatus(); 98 *ps = PowerStatusManager::readStatus();
95 99
96 if ( prev != *ps ) { 100 if ( prev != *ps ) {
97 percent = ps->batteryPercentRemaining(); 101 percent = ps->batteryPercentRemaining();
98 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) { 102 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) {
99 percent = 0; 103 percent = 0;
100 charging = true; 104 charging = true;
101 chargeTimer->start( 500 ); 105 chargeTimer->start( 500 );
102 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { 106 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) {
103 charging = false; 107 charging = false;
104 chargeTimer->stop(); 108 chargeTimer->stop();
109 if ( batteryView )
110 batteryView->updatePercent( percent );
111 }
112 repaint( style != 0 );
105 if ( batteryView ) 113 if ( batteryView )
106 batteryView->updatePercent( percent ); 114 batteryView->repaint();
107 }
108 repaint( style != 0 );
109 if ( batteryView )
110 batteryView->repaint();
111 } 115 }
112} 116}
113 117
114void BatteryMeter::chargeTimeout() 118void BatteryMeter::chargeTimeout() {
115{
116 percent += 20; 119 percent += 20;
117 if ( percent > 100 ) 120 if ( percent > 100 )
118 percent = 0; 121 percent = 0;
119 122
120 repaint(FALSE); 123 repaint(FALSE);
121 if ( batteryView ) 124 if ( batteryView )
122 batteryView->updatePercent( percent ); 125 batteryView->updatePercent( percent );
123} 126}
124 127
125void BatteryMeter::paintEvent( QPaintEvent* ) 128void BatteryMeter::paintEvent( QPaintEvent* ) {
126{
127 129
128 if ( style == 1 ) 130 if ( style == 1 ) {
129 {
130 QPainter p(this); 131 QPainter p(this);
131 QFont f( "Fixed", AppLnk::smallIconSize()/2 ); 132 QFont f( "Fixed", AppLnk::smallIconSize()/2 );
132 QFontMetrics fm( f ); 133 QFontMetrics fm( f );
@@ -139,15 +140,20 @@ void BatteryMeter::paintEvent( QPaintEvent* )
139 QPainter p(this); 140 QPainter p(this);
140 QColor color; 141 QColor color;
141 QColor g = gray.light( 160 ); 142 QColor g = gray.light( 160 );
142 switch ( ps->acStatus() ) 143 switch ( ps->acStatus() ) {
143 { 144 case PowerStatus::Offline:
144 case PowerStatus::Offline: color = blue.light( 150 ); break; 145 color = blue.light( 150 );
145 case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break; 146 break;
146 default: color = red.light( 160 ); 147 case PowerStatus::Online:
148 color = green.dark( 130 ).light( 180 );
149 break;
150 default:
151 color = red.light( 160 );
147 } 152 }
148 153
149 int w = height() / 2; 154 int w = height() / 2;
150 if ( !(w%2) ) w--; // should have an odd value to get a real middle line 155 if ( !(w%2) )
156 w--; // should have an odd value to get a real middle line
151 int h = height() - 4; 157 int h = height() - 4;
152 int pix = (percent * h) / 100; 158 int pix = (percent * h) / 100;
153 int y2 = height() -2; 159 int y2 = height() -2;
@@ -162,8 +168,7 @@ void BatteryMeter::paintEvent( QPaintEvent* )
162 //int extra = ((percent * h) % 100)/(100/4); 168 //int extra = ((percent * h) % 100)/(100/4);
163 169
164 int middle = w/2; 170 int middle = w/2;
165 for ( int i = 0; i < middle; i++ ) 171 for ( int i = 0; i < middle; i++ ) {
166 {
167 p.setPen( gray.dark( 100+i*20 ) ); 172 p.setPen( gray.dark( 100+i*20 ) );
168 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); 173 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 );
169 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); 174 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 );
@@ -173,8 +178,7 @@ void BatteryMeter::paintEvent( QPaintEvent* )
173 } 178 }
174} 179}
175 180
176int BatteryMeter::position() 181int BatteryMeter::position() {
177{
178 return 8; 182 return 8;
179} 183}
180 184
diff --git a/core/applets/batteryapplet/battery.h b/core/applets/batteryapplet/battery.h
index 622c083..970c857 100644
--- a/core/applets/batteryapplet/battery.h
+++ b/core/applets/batteryapplet/battery.h
@@ -37,12 +37,13 @@ class BatteryMeter : public QWidget
37 QSize sizeHint() const; 37 QSize sizeHint() const;
38 static int position(); 38 static int position();
39 39
40
41
40 protected: 42 protected:
41 void timerEvent( QTimerEvent* ); 43 void timerEvent( QTimerEvent* );
42 void paintEvent( QPaintEvent* ); 44 void paintEvent( QPaintEvent* );
43 void mousePressEvent( QMouseEvent* ); 45 void mousePressEvent( QMouseEvent* );
44 void mouseReleaseEvent( QMouseEvent* ); 46 void mouseReleaseEvent( QMouseEvent* );
45
46 protected slots: 47 protected slots:
47 void chargeTimeout(); 48 void chargeTimeout();
48 49
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp
index ab8f36d..655fdc4 100644
--- a/core/applets/batteryapplet/batterystatus.cpp
+++ b/core/applets/batteryapplet/batterystatus.cpp
@@ -9,243 +9,248 @@
9#include <qpushbutton.h> 9#include <qpushbutton.h>
10#include <qdrawutil.h> 10#include <qdrawutil.h>
11#include <qfile.h> 11#include <qfile.h>
12#include <qlayout.h>
13#include <qtextstream.h> 12#include <qtextstream.h>
14#include <qmessagebox.h> 13#include <qmessagebox.h>
15 14
16using namespace Opie::Core; 15using namespace Opie::Core;
17 16
18BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) 17BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent, WFlags f )
19 : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) { 18: QFrame( parent, 0, f), ps(p), bat2(false) {
20 setCaption( tr("Battery status") );
21 setMinimumSize( 150, 200 );
22 19
23 QPushButton *pb = new QPushButton( tr("Close"), this ); 20 jackPercent = 0;
24 QVBoxLayout *layout = new QVBoxLayout ( this );
25 21
26 jackPercent = 0; 22 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
27 23 getProcApmStatusIpaq();
28 pb->setMaximumSize( 120, 40 ); 24 }
29 25 percent = ps->batteryPercentRemaining();
30 pb->show();
31
32 layout->addStretch();
33 layout->addWidget( pb );
34
35 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
36 getProcApmStatusIpaq();
37 }
38 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) );
39 percent = ps->batteryPercentRemaining();
40 show();
41} 26}
42 27
43BatteryStatus::~BatteryStatus() 28BatteryStatus::~BatteryStatus() {}
44{
45}
46 29
47/* 30/*
48 * Make use of the advanced apm interface of the ipaq 31 * Make use of the advanced apm interface of the ipaq
49 */ 32 */
50bool BatteryStatus::getProcApmStatusIpaq() { 33bool BatteryStatus::getProcApmStatusIpaq() {
51 34
52 bat2 = false; 35 bat2 = false;
53 36
54 QFile procApmIpaq("/proc/hal/battery"); 37 QFile procApmIpaq("/proc/hal/battery");
55 38
56 if (procApmIpaq.open(IO_ReadOnly) ) { 39 if (procApmIpaq.open(IO_ReadOnly) ) {
57 QStringList list; 40 QStringList list;
58 // since it is /proc we _must_ use QTextStream 41 // since it is /proc we _must_ use QTextStream
59 QTextStream stream ( &procApmIpaq); 42 QTextStream stream ( &procApmIpaq);
60 QString streamIn; 43 QString streamIn;
61 streamIn = stream.read(); 44 streamIn = stream.read();
62 list = QStringList::split("\n", streamIn); 45 list = QStringList::split("\n", streamIn);
63 46
64 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { 47 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
65 // not nice, need a rewrite later 48 // not nice, need a rewrite later
66 if( (*line).startsWith(" Percentage") ){ 49 if( (*line).startsWith(" Percentage") ) {
67 if (bat2 == true) { 50 if (bat2 == true) {
68 perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 51 perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2);
52 } else {
53 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
54 }
55 } else if( (*line).startsWith(" Life") ) {
56 if (bat2 == true) {
57 sec2 = (*line).mid(((*line).find(':')+2), 5 );
58 } else {
59 sec1 = (*line).mid(((*line).find(':')+2), 5 );
60 }
61 } else if( (*line).startsWith("Battery #1") ) {
62 bat2 = true;
63 } else if( (*line).startsWith(" Status") ) {
64 if (bat2 == true) {
65 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
66 } else {
67 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
68 }
69 } else if( (*line).startsWith(" Chemistry") ) {
70 if (bat2 == true) {
71 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
72 } else {
73 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
74 }
75 }
76 }
69 } else { 77 } else {
70 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 78 QMessageBox::warning(this, tr("Failure"),tr("could not open file"));
71 } 79 }
72 }else if( (*line).startsWith(" Life") ){ 80
73 if (bat2 == true) { 81 procApmIpaq.close();
74 sec2 = (*line).mid(((*line).find(':')+2), 5 ); 82 jackPercent = perc2.toInt();
83 ipaqPercent = perc1.toInt();
84
85 if (perc2.isEmpty()) {
86 perc2 = tr("no data");
75 } else { 87 } else {
76 sec1 = (*line).mid(((*line).find(':')+2), 5 ); 88 perc2 += " %";
77 } 89 }
78 }else if( (*line).startsWith("Battery #1") ){ 90
79 bat2 = true; 91 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
80 }else if( (*line).startsWith(" Status") ){ 92 sec2 = tr("no data");
81 if (bat2 == true) {
82 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
83 } else {
84 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
85 }
86 }else if( (*line).startsWith(" Chemistry") ) {
87 if (bat2 == true) {
88 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
89 } else { 93 } else {
90 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 94 sec2 += " min";
91 } 95 }
92 }
93 }
94 } else {
95 QMessageBox::warning(this, tr("Failure"),tr("could not open file"));
96 }
97
98 procApmIpaq.close();
99
100 jackPercent = perc2.toInt();
101 ipaqPercent = perc1.toInt();
102
103 if (perc2.isEmpty()) {
104 perc2 = tr("no data");
105 } else {
106 perc2 += " %";
107 }
108
109
110 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
111 sec2 = tr("no data");
112 } else {
113 sec2 += " min";
114 }
115
116 jackStatus == (" ( " + jackStatus + " )");
117 96
118 return true; 97 jackStatus == (" ( " + jackStatus + " )");
98 return true;
119} 99}
120 100
121 101
122void BatteryStatus::updatePercent( int pc ) { 102void BatteryStatus::updatePercent( int pc ) {
123 percent = pc; 103 percent = pc;
124 repaint(FALSE); 104 repaint(FALSE);
125} 105}
126 106
127void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { 107void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) {
128 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; 108 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height;
129 topgrad.hsv( &h1, &s1, &v1 ); 109 topgrad.hsv( &h1, &s1, &v1 );
130 botgrad.hsv( &h2, &s2, &v2 ); 110 botgrad.hsv( &h2, &s2, &v2 );
131 for ( int j = 0; j < hy-2; j++ ) { 111 for ( int j = 0; j < hy-2; j++ ) {
132 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 112 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
133 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 113 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
134 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); 114 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j );
135 } 115 }
136 for ( int j = 0; j < hh; j++ ) { 116 for ( int j = 0; j < hh; j++ ) {
137 p->setPen( highlight ); 117 p->setPen( highlight );
138 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); 118 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j );
119 }
120 for ( int j = 0; j < ng-hy-hh; j++ ) {
121 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
122 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
123 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j );
139 } 124 }
140 for ( int j = 0; j < ng-hy-hh; j++ ) {
141 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
142 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
143 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j );
144 }
145} 125}
146 126
147void BatteryStatus::paintEvent( QPaintEvent * ) { 127QString BatteryStatus::statusText() const {
128 QString text;
148 129
149 QPainter p(this); 130 if ( ps->batteryStatus() == PowerStatus::Charging ) {
150 QString text;
151 if ( ps->batteryStatus() == PowerStatus::Charging ) {
152 if (bat2) { 131 if (bat2) {
153 text = tr("Charging both devices"); 132 text = tr("Charging both devices");
154 } else { 133 } else {
155 text = tr("Charging"); 134 text = tr("Charging");
156 } 135 }
157 } else if ( ps->batteryPercentAccurate() ) { 136 } else if ( ps->batteryPercentAccurate() ) {
158 text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent ); 137 text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent );
159 } else { 138 } else {
160 text = tr("Battery status: "); 139 text = tr("Battery status: ");
161 switch ( ps->batteryStatus() ) { 140 switch ( ps->batteryStatus() ) {
162 case PowerStatus::High: 141 case PowerStatus::High:
163 text += tr("Good"); 142 text += tr("Good");
164 break; 143 break;
165 case PowerStatus::Low: 144 case PowerStatus::Low:
166 text += tr("Low"); 145 text += tr("Low");
167 break; 146 break;
168 case PowerStatus::VeryLow: 147 case PowerStatus::VeryLow:
169 text += tr("Very Low"); 148 text += tr("Very Low");
170 break; 149 break;
171 case PowerStatus::Critical: 150 case PowerStatus::Critical:
172 text += tr("Critical"); 151 text += tr("Critical");
173 break; 152 break;
174 default: // NotPresent, etc. 153 default: // NotPresent, etc.
175 text += tr("Unknown"); 154 text += tr("Unknown");
155 }
176 } 156 }
177 }
178 p.drawText( 10, 90, text );
179
180 if ( ps->acStatus() == PowerStatus::Backup )
181 p.drawText( 10, 110, tr("On backup power") );
182 else if ( ps->acStatus() == PowerStatus::Online )
183 p.drawText( 10, 110, tr("Power on-line") );
184 else if ( ps->acStatus() == PowerStatus::Offline )
185 p.drawText( 10, 110, tr("External power disconnected") );
186
187 if ( ps->batteryTimeRemaining() >= 0 ) {
188 text.sprintf( tr("Battery time remaining") + ": %im %02is",
189 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 );
190 p.drawText( 10, 130, text );
191 }
192
193 QColor c;
194 QColor darkc;
195 QColor lightc;
196 if ( ps->acStatus() == PowerStatus::Offline ) {
197 c = blue.light(120);
198 darkc = c.dark(280);
199 lightc = c.light(145);
200 } else if ( ps->acStatus() == PowerStatus::Online ) {
201 c = green.dark(130);
202 darkc = c.dark(200);
203 lightc = c.light(220);
204 } else {
205 c = red;
206 darkc = c.dark(280);
207 lightc = c.light(140);
208 }
209 if ( percent < 0 )
210 return;
211
212 int rightEnd1 = width() - 47;
213 int rightEnd2 = width() - 35;
214 int percent2 = (percent * rightEnd1) / 100;
215 p.setPen( black );
216 qDrawShadePanel( &p, 9, 30, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL);
217 qDrawShadePanel( &p, rightEnd2, 37, 12, 24, colorGroup(), TRUE, 1, NULL);
218 drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 );
219 drawSegment( &p, QRect( 11 + percent2, 30, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 );
220 drawSegment( &p, QRect( rightEnd2, 37, 10, 25 ), white.light(80), black, white.light(90), 2 );
221 p.setPen( black);
222
223
224 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
225
226 p.drawText(15, 50, tr ("Ipaq ") + ipaqChem);
227
228 QString jacketMsg;
229 if (bat2) {
230 p.setPen(black);
231 p.drawText(10,220, tr("Percentage battery remaining: ") + perc2 + " " + jackStatus);
232 p.drawText(10,240, tr("Battery time remaining: ") + sec2);
233 jacketMsg = tr("Jacket ") + jackChem;
234 } else {
235 jackPercent = 0;
236 jacketMsg = tr("No jacket with battery inserted");
237 }
238
239 int jackPerc = ( jackPercent * ( width() - 47 ) ) / 100;
240
241 qDrawShadePanel( &p, 9, 160, rightEnd1, 39, colorGroup(), TRUE, 1, NULL);
242 qDrawShadePanel( &p, rightEnd2, 167, 12, 24, colorGroup(), TRUE, 1, NULL);
243 drawSegment( &p, QRect( 10, 160, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 );
244 drawSegment( &p, QRect( 11 + jackPerc, 160, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 );
245 drawSegment( &p, QRect( rightEnd2, 167, 10, 25 ), white.light(80), black, white.light(90), 2 );
246 p.setPen( black );
247 p.drawText(15, 180, jacketMsg);
248 }
249 157
158 if ( ps->acStatus() == PowerStatus::Backup )
159 text += "\n" + tr("On backup power");
160 else if ( ps->acStatus() == PowerStatus::Online )
161 text += "\n" + tr("Power on-line");
162 else if ( ps->acStatus() == PowerStatus::Offline )
163 text += "\n" + tr("External power disconnected");
164
165 if ( ps->batteryTimeRemaining() >= 0 ) {
166 text += "\n" + QString().sprintf( tr("Battery time remaining") + ": %im %02is",
167 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 );
168 }
169 return text;
170}
171
172QString BatteryStatus::statusTextIpaq() const {
173 QString text;
174 text += tr("Percentage battery remaining: ") + perc2 + " " + jackStatus;
175 text += "\n" + tr("Battery time remaining: ") + sec2;
176 return text;
177}
178
179void BatteryStatus::paintEvent( QPaintEvent * ) {
180
181 QPainter p( this );
182
183 QString text = statusText();
184 p.drawText( 10, 50, width() - 20, 40 , AlignVCenter, text );
185
186 QColor c;
187 QColor darkc;
188 QColor lightc;
189 if ( ps->acStatus() == PowerStatus::Offline ) {
190 c = blue.light(120);
191 darkc = c.dark(280);
192 lightc = c.light(145);
193 } else if ( ps->acStatus() == PowerStatus::Online ) {
194 c = green.dark(130);
195 darkc = c.dark(200);
196 lightc = c.light(220);
197 } else {
198 c = red;
199 darkc = c.dark(280);
200 lightc = c.light(140);
201 }
202 if ( percent < 0 )
203 return;
204
205 int rightEnd1 = width() - 47;
206 int rightEnd2 = width() - 35;
207 int percent2 = (percent * rightEnd1) / 100;
208 p.setPen( black );
209 qDrawShadePanel( &p, 9, 10, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL);
210 qDrawShadePanel( &p, rightEnd2, 17, 12, 24, colorGroup(), TRUE, 1, NULL);
211 drawSegment( &p, QRect( 10, 10, percent2, 40 ), lightc, darkc, lightc.light(115), 6 );
212 drawSegment( &p, QRect( 11 + percent2, 10, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 );
213 drawSegment( &p, QRect( rightEnd2, 17, 10, 25 ), white.light(80), black, white.light(90), 2 );
214 p.setPen( black);
215
216 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ && bat2 ) {
217
218 p.drawText( 15, 30, tr ("Ipaq ") + ipaqChem );
219
220 QString jacketMsg;
221 if (bat2) {
222 p.setPen(black);
223 QString text = statusTextIpaq();
224 p.drawText( 10, 150, text );
225 jacketMsg = tr("Jacket ") + jackChem;
226 } else {
227 jackPercent = 0;
228 jacketMsg = tr("No jacket with battery inserted");
229 }
230
231 int jackPerc = ( jackPercent * ( width() - 47 ) ) / 100;
232
233 qDrawShadePanel( &p, 9, 90, rightEnd1, 39, colorGroup(), TRUE, 1, NULL);
234 qDrawShadePanel( &p, rightEnd2, 97, 12, 24, colorGroup(), TRUE, 1, NULL);
235 drawSegment( &p, QRect( 10, 90, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 );
236 drawSegment( &p, QRect( 11 + jackPerc, 90, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 );
237 drawSegment( &p, QRect( rightEnd2, 97, 10, 25 ), white.light(80), black, white.light(90), 2 );
238 p.setPen( black );
239 p.drawText(15, 100, width() - 20, 20 , AlignVCenter, jacketMsg);
240 }
250} 241}
251 242
243QSize BatteryStatus::sizeHint() const {
244 QString text = statusText();
245 QString text2 = statusTextIpaq();
246 QFontMetrics fm = fontMetrics();
247 QRect r=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text );
248 QRect r2=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text2 );
249
250 if ( bat2 ) {
251 return QSize( QMAX( QMIN( 200, qApp->desktop()->width() ),
252 r.width() ), 2 * 10 + 80 + r.height() + r2.height() );
253 }
254 return QSize( QMAX( QMIN( 200, qApp->desktop()->width() ),
255 r.width() ), 2 * 10 + 40 + r.height() );
256}
diff --git a/core/applets/batteryapplet/batterystatus.h b/core/applets/batteryapplet/batterystatus.h
index a5ab804..bb95ece 100644
--- a/core/applets/batteryapplet/batterystatus.h
+++ b/core/applets/batteryapplet/batterystatus.h
@@ -20,24 +20,27 @@
20#ifndef BATTERY_STATUS_H 20#ifndef BATTERY_STATUS_H
21#define BATTERY_STATUS_H 21#define BATTERY_STATUS_H
22 22
23#include <qwidget.h> 23#include <qframe.h>
24 24
25class PowerStatus; 25class PowerStatus;
26 26
27class BatteryStatus : public QWidget 27class BatteryStatus : public QFrame
28{ 28{
29 Q_OBJECT 29 Q_OBJECT
30public: 30public:
31 BatteryStatus( const PowerStatus *s, QWidget *parent=0 ); 31 BatteryStatus( const PowerStatus *s, QWidget *parent=0, WFlags f = 0 );
32 ~BatteryStatus(); 32 ~BatteryStatus();
33 33
34 void updatePercent( int ); 34 void updatePercent( int );
35 35 QSize sizeHint() const;
36protected: 36protected:
37 void drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ); 37 void drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height );
38 void paintEvent( QPaintEvent *pe ); 38 void paintEvent( QPaintEvent *pe );
39 bool BatteryStatus::getProcApmStatusIpaq(); 39 bool BatteryStatus::getProcApmStatusIpaq();
40
40private: 41private:
42 QString statusText() const;
43 QString statusTextIpaq() const;
41 const PowerStatus *ps; 44 const PowerStatus *ps;
42 int percent; 45 int percent;
43 int ipaqPercent; 46 int ipaqPercent;
@@ -52,6 +55,7 @@ private:
52 QString ipaqChem; 55 QString ipaqChem;
53 QString jackChem; 56 QString jackChem;
54 bool bat2; 57 bool bat2;
58 bool bat2inserted;
55 int screenWidth; 59 int screenWidth;
56 int screenHeight; 60 int screenHeight;
57}; 61};