summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/battery.cpp2
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp12
2 files changed, 10 insertions, 4 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp
index e85a9da..fa95b2b 100644
--- a/core/applets/batteryapplet/battery.cpp
+++ b/core/applets/batteryapplet/battery.cpp
@@ -1,187 +1,189 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "battery.h" 20#include "battery.h"
21#include "batterystatus.h" 21#include "batterystatus.h"
22 22
23/* OPIE */ 23/* OPIE */
24#include <opie2/otaskbarapplet.h> 24#include <opie2/otaskbarapplet.h>
25 25
26#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
27#include <qpe/applnk.h> 27#include <qpe/applnk.h>
28#include <qpe/config.h> 28#include <qpe/config.h>
29#include <qpe/power.h> 29#include <qpe/power.h>
30 30
31/* QT */ 31/* QT */
32#include <qpainter.h> 32#include <qpainter.h>
33#include <qtimer.h> 33#include <qtimer.h>
34 34
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 ps = new PowerStatus; 39 ps = new PowerStatus;
40 startTimer( 10000 ); 40 startTimer( 10000 );
41 41
42 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); 42 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) );
43 setFixedHeight( AppLnk::smallIconSize() ); 43 setFixedHeight( AppLnk::smallIconSize() );
44 44
45 chargeTimer = new QTimer( this ); 45 chargeTimer = new QTimer( this );
46 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); 46 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) );
47 timerEvent(0); 47 timerEvent(0);
48 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 48 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
49 Config c( "qpe" ); 49 Config c( "qpe" );
50 c.setGroup( "Battery" ); 50 c.setGroup( "Battery" );
51 style = c.readNumEntry( "Style", 0 ); 51 style = c.readNumEntry( "Style", 0 );
52} 52}
53 53
54BatteryMeter::~BatteryMeter() { 54BatteryMeter::~BatteryMeter() {
55 delete ps; 55 delete ps;
56} 56}
57 57
58QSize BatteryMeter::sizeHint() const { 58QSize BatteryMeter::sizeHint() const {
59 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); 59 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() );
60} 60}
61 61
62void BatteryMeter::mousePressEvent( QMouseEvent* e ) { 62void BatteryMeter::mousePressEvent( QMouseEvent* e ) {
63 if ( e->button() == RightButton ) { 63 if ( e->button() == RightButton ) {
64 style = 1-style; 64 style = 1-style;
65 Config c( "qpe" ); 65 Config c( "qpe" );
66 c.setGroup( "Battery" ); 66 c.setGroup( "Battery" );
67 c.writeEntry( "Style", style ); 67 c.writeEntry( "Style", style );
68 repaint( true ); 68 repaint( true );
69 } 69 }
70 QWidget::mousePressEvent( e ); 70 QWidget::mousePressEvent( e );
71} 71}
72 72
73void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) { 73void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) {
74 if ( batteryView && batteryView->isVisible() ) { 74 if ( batteryView && batteryView->isVisible() ) {
75 batteryView->hide(); 75 batteryView->hide();
76 } else { 76 } else {
77 if ( !batteryView ) { 77 if ( !batteryView ) {
78 batteryView = new BatteryStatus( ps, 0, WStyle_StaysOnTop | WType_Popup ); 78 batteryView = new BatteryStatus( ps, 0, WStyle_StaysOnTop | WType_Popup );
79 batteryView->setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 79 batteryView->setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
80 } 80 }
81 81
82 batteryView->UpdateBatteryStatus(); 82 batteryView->UpdateBatteryStatus();
83 QRect r(batteryView->pos(),batteryView->sizeHint()); 83 QRect r(batteryView->pos(),batteryView->sizeHint());
84 QPoint curPos = this->mapToGlobal ( rect().topLeft() ); 84 QPoint curPos = this->mapToGlobal ( rect().topLeft() );
85 85
86 int lp = qApp->desktop()->width() - batteryView->sizeHint().width(); 86 int lp = qApp->desktop()->width() - batteryView->sizeHint().width();
87 r.moveTopLeft( QPoint(lp, curPos.y()-batteryView->sizeHint().height()-1) ); 87 r.moveTopLeft( QPoint(lp, curPos.y()-batteryView->sizeHint().height()-1) );
88 batteryView->setGeometry(r); 88 batteryView->setGeometry(r);
89 89
90 batteryView->raise(); 90 batteryView->raise();
91 batteryView->show(); 91 batteryView->show();
92 } 92 }
93} 93}
94 94
95 95
96void BatteryMeter::timerEvent( QTimerEvent * ) { 96void BatteryMeter::timerEvent( QTimerEvent * ) {
97 PowerStatus prev = *ps; 97 PowerStatus prev = *ps;
98 98
99 *ps = PowerStatusManager::readStatus(); 99 *ps = PowerStatusManager::readStatus();
100 100
101 if ( prev != *ps ) { 101 if ( prev != *ps ) {
102 percent = ps->batteryPercentRemaining(); 102 percent = ps->batteryPercentRemaining();
103 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) { 103 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) {
104 percent = 0; 104 percent = 0;
105 charging = true; 105 charging = true;
106 chargeTimer->start( 500 ); 106 chargeTimer->start( 500 );
107 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { 107 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) {
108 charging = false; 108 charging = false;
109 chargeTimer->stop(); 109 chargeTimer->stop();
110 if ( batteryView ) 110 if ( batteryView )
111 batteryView->updatePercent( percent ); 111 batteryView->updatePercent( percent );
112 } 112 }
113 repaint( style != 0 ); 113 repaint( style != 0 );
114 if ( batteryView ) 114 if ( batteryView )
115 batteryView->repaint(); 115 batteryView->repaint();
116 } 116 }
117} 117}
118 118
119void BatteryMeter::chargeTimeout() { 119void BatteryMeter::chargeTimeout() {
120 percent += 20; 120 percent += 20;
121 if ( percent > 100 ) 121 if ( percent > 100 )
122 percent = 0; 122 percent = 0;
123 123
124 repaint(FALSE); 124 repaint(FALSE);
125 if ( batteryView ) 125 if ( batteryView )
126 batteryView->updatePercent( percent ); 126 batteryView->updatePercent( percent );
127} 127}
128 128
129void BatteryMeter::paintEvent( QPaintEvent* ) { 129void BatteryMeter::paintEvent( QPaintEvent* ) {
130 130
131 if ( style == 1 ) { 131 if ( style == 1 ) {
132 QPainter p(this); 132 QPainter p(this);
133 QFont f( "Fixed", AppLnk::smallIconSize()/2 ); 133 QFont f( "Fixed", AppLnk::smallIconSize()/2 );
134 QFontMetrics fm( f ); 134 QFontMetrics fm( f );
135 //Avoid text overlapping
136 p.eraseRect( 0, 0, 20, 20 );
135 p.setFont( f ); 137 p.setFont( f );
136 p.drawText( 0, height()/2, QString::number( percent ) ); 138 p.drawText( 0, height()/2, QString::number( percent ) );
137 p.drawText( width()/4, height(), "%" ); 139 p.drawText( width()/4, height(), "%" );
138 return; 140 return;
139 } 141 }
140 142
141 QPainter p(this); 143 QPainter p(this);
142 QColor color; 144 QColor color;
143 QColor g = gray.light( 160 ); 145 QColor g = gray.light( 160 );
144 switch ( ps->acStatus() ) { 146 switch ( ps->acStatus() ) {
145 case PowerStatus::Offline: 147 case PowerStatus::Offline:
146 color = blue.light( 150 ); 148 color = blue.light( 150 );
147 break; 149 break;
148 case PowerStatus::Online: 150 case PowerStatus::Online:
149 color = green.dark( 130 ).light( 180 ); 151 color = green.dark( 130 ).light( 180 );
150 break; 152 break;
151 default: 153 default:
152 color = red.light( 160 ); 154 color = red.light( 160 );
153 } 155 }
154 156
155 int w = height() / 2; 157 int w = height() / 2;
156 if ( !(w%2) ) 158 if ( !(w%2) )
157 w--; // should have an odd value to get a real middle line 159 w--; // should have an odd value to get a real middle line
158 int h = height() - 4; 160 int h = height() - 4;
159 int pix = (percent * h) / 100; 161 int pix = (percent * h) / 100;
160 int y2 = height() -2; 162 int y2 = height() -2;
161 int y = y2 - pix; 163 int y = y2 - pix;
162 int x1 = (width() - w ) / 2; 164 int x1 = (width() - w ) / 2;
163 165
164 p.setPen(QColor(80,80,80)); 166 p.setPen(QColor(80,80,80));
165 p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header 167 p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header
166 p.drawRect(x1,1,w,height()-1); // corpus 168 p.drawRect(x1,1,w,height()-1); // corpus
167 p.setBrush(color); 169 p.setBrush(color);
168 170
169 //int extra = ((percent * h) % 100)/(100/4); 171 //int extra = ((percent * h) % 100)/(100/4);
170 172
171 int middle = w/2; 173 int middle = w/2;
172 for ( int i = 0; i < middle; i++ ) { 174 for ( int i = 0; i < middle; i++ ) {
173 p.setPen( gray.dark( 100+i*20 ) ); 175 p.setPen( gray.dark( 100+i*20 ) );
174 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); 176 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 );
175 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); 177 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 );
176 p.setPen( color.dark( 100+i*20 ) ); 178 p.setPen( color.dark( 100+i*20 ) );
177 p.drawLine( x1+middle-i, y, x1+middle-i, y2 ); 179 p.drawLine( x1+middle-i, y, x1+middle-i, y2 );
178 p.drawLine( x1+middle+i, y, x1+middle+i, y2 ); 180 p.drawLine( x1+middle+i, y, x1+middle+i, y2 );
179 } 181 }
180} 182}
181 183
182int BatteryMeter::position() { 184int BatteryMeter::position() {
183 return 8; 185 return 8;
184} 186}
185 187
186EXPORT_OPIE_APPLET_v1( BatteryMeter ) 188EXPORT_OPIE_APPLET_v1( BatteryMeter )
187 189
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp
index 7f8de2c..34043f4 100644
--- a/core/applets/batteryapplet/batterystatus.cpp
+++ b/core/applets/batteryapplet/batterystatus.cpp
@@ -1,279 +1,283 @@
1 1
2#include "batterystatus.h" 2#include "batterystatus.h"
3 3
4/* OPIE */ 4/* OPIE */
5#include <opie2/odevice.h> 5#include <opie2/odevice.h>
6#include <qpe/power.h> 6#include <qpe/power.h>
7 7
8/* QT */ 8/* QT */
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 <qtextstream.h> 12#include <qtextstream.h>
13#include <qmessagebox.h> 13#include <qmessagebox.h>
14 14
15using namespace Opie::Core; 15using namespace Opie::Core;
16 16
17BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent, WFlags f ) 17BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent, WFlags f )
18: QFrame( parent, 0, f), ps(p), bat2(false) { 18: QFrame( parent, 0, f), ps(p), bat2(false) {
19 19
20 UpdateBatteryStatus(); 20 UpdateBatteryStatus();
21} 21}
22 22
23BatteryStatus::~BatteryStatus() {} 23BatteryStatus::~BatteryStatus() {}
24 24
25void BatteryStatus::UpdateBatteryStatus() { 25void BatteryStatus::UpdateBatteryStatus() {
26 26
27 jackPercent = 0; 27 jackPercent = 0;
28 28
29 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { 29 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
30 getProcApmStatusIpaq(); 30 getProcApmStatusIpaq();
31 } 31 }
32 percent = ps->batteryPercentRemaining(); 32 percent = ps->batteryPercentRemaining();
33} 33}
34 34
35/* 35/*
36 * Make use of the advanced apm interface of the ipaq 36 * Make use of the advanced apm interface of the ipaq
37 */ 37 */
38bool BatteryStatus::getProcApmStatusIpaq() { 38bool BatteryStatus::getProcApmStatusIpaq() {
39 39
40 bat2 = false; 40 bat2 = false;
41 41
42 QFile procApmIpaq("/proc/hal/battery"); 42 QFile procApmIpaq("/proc/hal/battery");
43 43
44 if (procApmIpaq.open(IO_ReadOnly) ) { 44 if (procApmIpaq.open(IO_ReadOnly) ) {
45 QStringList list; 45 QStringList list;
46 // since it is /proc we _must_ use QTextStream 46 // since it is /proc we _must_ use QTextStream
47 QTextStream stream ( &procApmIpaq); 47 QTextStream stream ( &procApmIpaq);
48 QString streamIn; 48 QString streamIn;
49 streamIn = stream.read(); 49 streamIn = stream.read();
50 list = QStringList::split("\n", streamIn); 50 list = QStringList::split("\n", streamIn);
51
52 sec2 = sec1 = "";
51 53
52 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { 54 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
53 // not nice, need a rewrite later 55 // not nice, need a rewrite later
54 if( (*line).startsWith(" Percentage") ) { 56 if( (*line).startsWith(" Percentage") ) {
55 if (bat2 == true) { 57 if (bat2 == true) {
56 perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2); 58 perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2);
57 } else { 59 } else {
58 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 60 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
59 } 61 }
60 } else if( (*line).startsWith(" Life") ) { 62 } else if( (*line).startsWith(" Life") ) {
61 if (bat2 == true) { 63 if (bat2 == true) {
62 sec2 = (*line).mid(((*line).find(':')+2), 5 ); 64 sec2 = (*line).mid(((*line).find(':')+2), 5 );
63 } else { 65 } else {
64 sec1 = (*line).mid(((*line).find(':')+2), 5 ); 66 sec1 = (*line).mid(((*line).find(':')+2), 5 );
65 } 67 }
66 } else if( (*line).startsWith("Battery #1") ) { 68 } else if( (*line).startsWith("Battery #1") ) {
67 bat2 = true; 69 bat2 = true;
68 } else if( (*line).startsWith(" Status") ) { 70 } else if( (*line).startsWith(" Status") ) {
69 if (bat2 == true) { 71 if (bat2 == true) {
70 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); 72 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
71 } else { 73 } else {
72 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); 74 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
73 } 75 }
74 } else if( (*line).startsWith(" Chemistry") ) { 76 } else if( (*line).startsWith(" Chemistry") ) {
75 if (bat2 == true) { 77 if (bat2 == true) {
76 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 78 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
77 } else { 79 } else {
78 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 80 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
79 } 81 }
80 } 82 }
81 } 83 }
82 } else { 84 } else {
83 QMessageBox::warning(this, tr("Failure"),tr("could not open file")); 85 QMessageBox::warning(this, tr("Failure"),tr("could not open file"));
84 } 86 }
85 87
86 procApmIpaq.close(); 88 procApmIpaq.close();
87 jackPercent = perc2.toInt(); 89 jackPercent = perc2.toInt();
88 ipaqPercent = perc1.toInt(); 90 ipaqPercent = perc1.toInt();
89 91
90 if (perc2.isEmpty()) { 92 if (perc2.isEmpty() || perc2 == "unknow" ) {
91 perc2 = tr("no data"); 93 perc2 = tr("no data");
92 } else { 94 } else {
93 perc2 += " %"; 95 perc2 += " %";
94 } 96 }
95 97
96 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { 98 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
97 sec2 = tr("no data"); 99 sec2 = tr("no data");
98 } else { 100 } else {
99 sec2 += " min"; 101 sec2 += " min";
100 } 102 }
101 103
102 jackStatus.prepend( " ( " ); 104 jackStatus.prepend( " ( " );
103 jackStatus.append( " )" ); 105 jackStatus.append( " )" );
104 return true; 106 return true;
105} 107}
106 108
107 109
108void BatteryStatus::updatePercent( int pc ) { 110void BatteryStatus::updatePercent( int pc ) {
109 percent = pc; 111 percent = pc;
110 repaint(FALSE); 112 repaint(FALSE);
111} 113}
112 114
113void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { 115void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) {
114 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; 116 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height;
115 topgrad.hsv( &h1, &s1, &v1 ); 117 topgrad.hsv( &h1, &s1, &v1 );
116 botgrad.hsv( &h2, &s2, &v2 ); 118 botgrad.hsv( &h2, &s2, &v2 );
117 for ( int j = 0; j < hy-2; j++ ) { 119 for ( int j = 0; j < hy-2; j++ ) {
118 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 120 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
119 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 121 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
120 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); 122 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j );
121 } 123 }
122 for ( int j = 0; j < hh; j++ ) { 124 for ( int j = 0; j < hh; j++ ) {
123 p->setPen( highlight ); 125 p->setPen( highlight );
124 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); 126 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j );
125 } 127 }
126 for ( int j = 0; j < ng-hy-hh; j++ ) { 128 for ( int j = 0; j < ng-hy-hh; j++ ) {
127 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 129 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
128 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 130 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
129 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); 131 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j );
130 } 132 }
131} 133}
132 134
133QString BatteryStatus::statusText() const { 135QString BatteryStatus::statusText() const {
134 QString text; 136 QString text;
135 137
136 if ( ps->batteryStatus() == PowerStatus::Charging ) { 138 if ( ps->batteryStatus() == PowerStatus::Charging ) {
137 if (bat2) { 139 if (bat2) {
138 text = tr("Charging both devices"); 140 text = tr("Charging both devices");
139 } else { 141 } else {
140 text = tr("Charging"); 142 text = tr("Charging");
141 } 143 }
142 } else if ( ps->batteryPercentAccurate() ) { 144 } else if ( ps->batteryPercentAccurate() ) {
143 text = tr( "Remaining Power: %1%" ).arg( percent ); 145 text = tr( "Remaining Power: %1%" ).arg( percent );
144 //text.sprintf( tr("Remaining Power") + ": %i%%", percent ); 146 //text.sprintf( tr("Remaining Power") + ": %i%%", percent );
145 } else { 147 } else {
146 text = tr( "Battery status: " ); 148 text = tr( "Battery status: " );
147 switch ( ps->batteryStatus() ) { 149 switch ( ps->batteryStatus() ) {
148 case PowerStatus::High: 150 case PowerStatus::High:
149 text.append( tr( "Good" ) ); 151 text.append( tr( "Good" ) );
150 break; 152 break;
151 case PowerStatus::Low: 153 case PowerStatus::Low:
152 text.append( tr( "Low" ) ); 154 text.append( tr( "Low" ) );
153 break; 155 break;
154 case PowerStatus::VeryLow: 156 case PowerStatus::VeryLow:
155 text.append( tr( "Very Low" ) ); 157 text.append( tr( "Very Low" ) );
156 break; 158 break;
157 case PowerStatus::Critical: 159 case PowerStatus::Critical:
158 text.append( tr( "Critical" ) ); 160 text.append( tr( "Critical" ) );
159 break; 161 break;
160 default: // NotPresent, etc. 162 default: // NotPresent, etc.
161 text.append( tr( "Unknown" ) ); 163 text.append( tr( "Unknown" ) );
162 } 164 }
163 } 165 }
164 166
165 if ( ps->acStatus() == PowerStatus::Backup ) 167 if ( ps->acStatus() == PowerStatus::Backup )
166 { 168 {
167 text.append( '\n' ); 169 text.append( '\n' );
168 text.append( tr( "On backup power" ) ); 170 text.append( tr( "On backup power" ) );
169 } 171 }
170 else if ( ps->acStatus() == PowerStatus::Online ) 172 else if ( ps->acStatus() == PowerStatus::Online )
171 { 173 {
172 text.append( '\n' ); 174 text.append( '\n' );
173 text.append( tr( "Power on-line" ) ); 175 text.append( tr( "Power on-line" ) );
174 } 176 }
175 else if ( ps->acStatus() == PowerStatus::Offline ) 177 else if ( ps->acStatus() == PowerStatus::Offline )
176 { 178 {
177 text.append( '\n' ); 179 text.append( '\n' );
178 text.append( tr( "External power disconnected" ) ); 180 text.append( tr( "External power disconnected" ) );
179 } 181 }
180 182
181 if ( ps->batteryTimeRemaining() >= 0 ) 183 if ( ps->batteryTimeRemaining() >= 0 )
182 { 184 {
183 text.append( '\n' ); 185 text.append( '\n' );
184 text.append( tr("Remaining Time: %1m %2s" ).arg( ps->batteryTimeRemaining() / 60 ) 186 text.append( tr("Remaining Time: %1m %2s" ).arg( ps->batteryTimeRemaining() / 60 )
185 .arg( ps->batteryTimeRemaining() % 60, 2 ) ); 187 .arg( ps->batteryTimeRemaining() % 60, 2 ) );
186/* text += "\n" + QString().sprintf( tr("Remaining Time") + ": %im %02is", 188/* text += "\n" + QString().sprintf( tr("Remaining Time") + ": %im %02is",
187 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 );*/ 189 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 );*/
188 } 190 }
189 return text; 191 return text;
190} 192}
191 193
192QString BatteryStatus::statusTextIpaq() const { 194QString BatteryStatus::statusTextIpaq() const {
193 QString text = tr( "Remaing Power: %1 %2\nRemaining Time: %3" ).arg( perc2 ) 195 QString text = tr( "Remaining Power: %1 \n%2\nRemaining Time: %3" ).arg( perc2 )
194 .arg( jackStatus ) 196 .arg( jackStatus )
195 .arg( sec2 ); 197 .arg( sec2 );
196/* QString text = tr("Remaining Power: ") + perc2 + " " + jackStatus; 198/* QString text = tr("Remaining Power: ") + perc2 + " " + jackStatus;
197 text += "\n" + tr("Remaining Time: ") + sec2;*/ 199 text += "\n" + tr("Remaining Time: ") + sec2;*/
198 return text; 200 return text;
199} 201}
200 202
201void BatteryStatus::paintEvent( QPaintEvent * ev ) { 203void BatteryStatus::paintEvent( QPaintEvent * ev ) {
202 204
203 QPainter p( this ); 205 QPainter p( this );
204 206
205 QString text = statusText(); 207 QString text = statusText();
208 p.eraseRect( p.boundingRect( 10, 50, width() - 20, 40 , AlignVCenter, text ) );
206 p.drawText( 10, 50, width() - 20, 40 , AlignVCenter, text ); 209 p.drawText( 10, 50, width() - 20, 40 , AlignVCenter, text );
207 210
208 QColor c; 211 QColor c;
209 QColor darkc; 212 QColor darkc;
210 QColor lightc; 213 QColor lightc;
211 if ( ps->acStatus() == PowerStatus::Offline ) { 214 if ( ps->acStatus() == PowerStatus::Offline ) {
212 c = blue.light(120); 215 c = blue.light(120);
213 darkc = c.dark(280); 216 darkc = c.dark(280);
214 lightc = c.light(145); 217 lightc = c.light(145);
215 } else if ( ps->acStatus() == PowerStatus::Online ) { 218 } else if ( ps->acStatus() == PowerStatus::Online ) {
216 c = green.dark(130); 219 c = green.dark(130);
217 darkc = c.dark(200); 220 darkc = c.dark(200);
218 lightc = c.light(220); 221 lightc = c.light(220);
219 } else { 222 } else {
220 c = red; 223 c = red;
221 darkc = c.dark(280); 224 darkc = c.dark(280);
222 lightc = c.light(140); 225 lightc = c.light(140);
223 } 226 }
224 if ( percent < 0 ) 227 if ( percent < 0 )
225 return; 228 return;
226 229
227 int rightEnd1 = width() - 47; 230 int rightEnd1 = width() - 47;
228 int rightEnd2 = width() - 35; 231 int rightEnd2 = width() - 35;
229 int percent2 = (percent * rightEnd1) / 100; 232 int percent2 = (percent * rightEnd1) / 100;
230 p.setPen( black ); 233 p.setPen( black );
231 qDrawShadePanel( &p, 9, 10, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL); 234 qDrawShadePanel( &p, 9, 10, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL);
232 qDrawShadePanel( &p, rightEnd2, 17, 12, 24, colorGroup(), TRUE, 1, NULL); 235 qDrawShadePanel( &p, rightEnd2, 17, 12, 24, colorGroup(), TRUE, 1, NULL);
233 drawSegment( &p, QRect( 10, 10, percent2, 40 ), lightc, darkc, lightc.light(115), 6 ); 236 drawSegment( &p, QRect( 10, 10, percent2, 40 ), lightc, darkc, lightc.light(115), 6 );
234 drawSegment( &p, QRect( 11 + percent2, 10, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 ); 237 drawSegment( &p, QRect( 11 + percent2, 10, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 );
235 drawSegment( &p, QRect( rightEnd2, 17, 10, 25 ), white.light(80), black, white.light(90), 2 ); 238 drawSegment( &p, QRect( rightEnd2, 17, 10, 25 ), white.light(80), black, white.light(90), 2 );
236 p.setPen( black); 239 p.setPen( black);
237 240
238 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ && bat2 ) { 241 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ && bat2 ) {
239 242
240 p.drawText( 15, 30, tr("Ipaq %1").arg( ipaqChem ) ); 243 p.drawText( 15, 30, tr("Ipaq %1").arg( ipaqChem ) );
241 244
242 QString jacketMsg; 245 QString jacketMsg;
243 if (bat2) { 246 if (bat2) {
244 p.setPen(black); 247 p.setPen(black);
245 QString text = statusTextIpaq(); 248 QString text = statusTextIpaq();
246 p.drawText( 10, 150, text ); 249 p.eraseRect( p.boundingRect( 10, 130, width() - 20, 40 , AlignVCenter, text ) );
250 p.drawText( 10, 130, width() - 20, 40 , AlignVCenter, text );
247 jacketMsg = tr("Jacket ").arg( jackChem ); 251 jacketMsg = tr("Jacket ").arg( jackChem );
248 } else { 252 } else {
249 jackPercent = 0; 253 jackPercent = 0;
250 jacketMsg = tr("No jacket with battery inserted"); 254 jacketMsg = tr("No jacket with battery inserted");
251 } 255 }
252 256
253 int jackPerc = ( jackPercent * ( width() - 47 ) ) / 100; 257 int jackPerc = ( jackPercent * ( width() - 47 ) ) / 100;
254 258
255 qDrawShadePanel( &p, 9, 90, rightEnd1, 39, colorGroup(), TRUE, 1, NULL); 259 qDrawShadePanel( &p, 9, 90, rightEnd1, 39, colorGroup(), TRUE, 1, NULL);
256 qDrawShadePanel( &p, rightEnd2, 97, 12, 24, colorGroup(), TRUE, 1, NULL); 260 qDrawShadePanel( &p, rightEnd2, 97, 12, 24, colorGroup(), TRUE, 1, NULL);
257 drawSegment( &p, QRect( 10, 90, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 ); 261 drawSegment( &p, QRect( 10, 90, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 );
258 drawSegment( &p, QRect( 11 + jackPerc, 90, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 ); 262 drawSegment( &p, QRect( 11 + jackPerc, 90, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 );
259 drawSegment( &p, QRect( rightEnd2, 97, 10, 25 ), white.light(80), black, white.light(90), 2 ); 263 drawSegment( &p, QRect( rightEnd2, 97, 10, 25 ), white.light(80), black, white.light(90), 2 );
260 p.setPen( black ); 264 p.setPen( black );
261 p.drawText(15, 100, width() - 20, 20 , AlignVCenter, jacketMsg); 265 p.drawText(15, 100, width() - 20, 20 , AlignVCenter, jacketMsg);
262 } 266 }
263 QFrame::paintEvent(ev); 267 QFrame::paintEvent(ev);
264} 268}
265 269
266QSize BatteryStatus::sizeHint() const { 270QSize BatteryStatus::sizeHint() const {
267 QString text = statusText(); 271 QString text = statusText();
268 QString text2 = statusTextIpaq(); 272 QString text2 = statusTextIpaq();
269 QFontMetrics fm = fontMetrics(); 273 QFontMetrics fm = fontMetrics();
270 QRect r=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text ); 274 QRect r=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text );
271 QRect r2=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text2 ); 275 QRect r2=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text2 );
272 276
273 if ( bat2 ) { 277 if ( bat2 ) {
274 return QSize( QMAX( QMIN( 200, qApp->desktop()->width() ), 278 return QSize( QMAX( QMIN( 200, qApp->desktop()->width() ),
275 r.width()+2*10 ), 2 * 10 + 80 + r.height() + r2.height() ); 279 r.width()+2*10 ), 2 * 10 + 100 + r.height() + r2.height() );
276 } 280 }
277 return QSize( QMAX( QMIN( 200, qApp->desktop()->width() ), 281 return QSize( QMAX( QMIN( 200, qApp->desktop()->width() ),
278 r.width()+2*10 ), 2 * 10 + 40 + r.height() ); 282 r.width()+2*10 ), 2 * 10 + 40 + r.height() );
279} 283}