summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/battery.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp
index 078ce8d..480d261 100644
--- a/core/applets/batteryapplet/battery.cpp
+++ b/core/applets/batteryapplet/battery.cpp
@@ -1,166 +1,176 @@
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#include <qpe/applnk.h> 23#include <qpe/applnk.h>
24#include <qpe/config.h> 24#include <qpe/config.h>
25#include <qpe/power.h> 25#include <qpe/power.h>
26#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
27 27
28#include <qpainter.h> 28#include <qpainter.h>
29#include <qtimer.h> 29#include <qtimer.h>
30 30
31 31
32BatteryMeter::BatteryMeter( QWidget *parent ) 32BatteryMeter::BatteryMeter( QWidget *parent )
33 : QWidget( parent ), charging(false) 33 : QWidget( parent ), charging(false)
34{ 34{
35 ps = new PowerStatus; 35 ps = new PowerStatus;
36 startTimer( 10000 ); 36 startTimer( 10000 );
37 setFixedHeight( AppLnk::smallIconSize() ); 37 setFixedHeight( AppLnk::smallIconSize() );
38 chargeTimer = new QTimer( this ); 38 chargeTimer = new QTimer( this );
39 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); 39 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) );
40 timerEvent(0); 40 timerEvent(0);
41 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 41 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
42 Config c( "qpe" ); 42 Config c( "qpe" );
43 c.setGroup( "Battery" ); 43 c.setGroup( "Battery" );
44 style = c.readNumEntry( "Style", 0 ); 44 style = c.readNumEntry( "Style", 0 );
45} 45}
46 46
47BatteryMeter::~BatteryMeter() 47BatteryMeter::~BatteryMeter()
48{ 48{
49 delete ps; 49 delete ps;
50} 50}
51 51
52QSize BatteryMeter::sizeHint() const 52QSize BatteryMeter::sizeHint() const
53{ 53{
54 return QSize(10, height() ); 54 return QSize(10, height() );
55} 55}
56 56
57void BatteryMeter::mousePressEvent( QMouseEvent* e ) 57void BatteryMeter::mousePressEvent( QMouseEvent* e )
58{ 58{
59 if ( e->button() == RightButton ) 59 if ( e->button() == RightButton )
60 { 60 {
61 style = 1-style; 61 style = 1-style;
62 Config c( "qpe" ); 62 Config c( "qpe" );
63 c.setGroup( "Battery" ); 63 c.setGroup( "Battery" );
64 c.writeEntry( "Style", style ); 64 c.writeEntry( "Style", style );
65 repaint( true ); 65 repaint( true );
66 } 66 }
67 QWidget::mousePressEvent( e ); 67 QWidget::mousePressEvent( e );
68} 68}
69 69
70void BatteryMeter::mouseReleaseEvent( QMouseEvent* e) 70void BatteryMeter::mouseReleaseEvent( QMouseEvent* e)
71{ 71{
72 if ( batteryView && batteryView->isVisible() ) { 72 if ( batteryView && batteryView->isVisible() ) {
73 delete (QWidget *) batteryView; 73 delete (QWidget *) batteryView;
74 } else { 74 } else {
75 if ( !batteryView ) batteryView = new BatteryStatus( ps ); 75 if ( !batteryView ) batteryView = new BatteryStatus( ps );
76 batteryView->showMaximized(); 76 batteryView->showMaximized();
77 batteryView->raise(); 77 batteryView->raise();
78 batteryView->show(); 78 batteryView->show();
79 } 79 }
80} 80}
81 81
82void BatteryMeter::timerEvent( QTimerEvent * ) 82void BatteryMeter::timerEvent( QTimerEvent * )
83{ 83{
84 PowerStatus prev = *ps; 84 PowerStatus prev = *ps;
85 85
86 *ps = PowerStatusManager::readStatus(); 86 *ps = PowerStatusManager::readStatus();
87 87
88 if ( prev != *ps ) { 88 if ( prev != *ps ) {
89 percent = ps->batteryPercentRemaining(); 89 percent = ps->batteryPercentRemaining();
90 if ( !charging && ps->batteryStatus() == PowerStatus::Charging && percent < 0 ) { 90 if ( !charging && ps->batteryStatus() == PowerStatus::Charging && percent < 0 ) {
91 percent = 0; 91 percent = 0;
92 charging = true; 92 charging = true;
93 chargeTimer->start( 500 ); 93 chargeTimer->start( 500 );
94 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { 94 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) {
95 charging = false; 95 charging = false;
96 chargeTimer->stop(); 96 chargeTimer->stop();
97 if ( batteryView ) 97 if ( batteryView )
98 batteryView->updatePercent( percent ); 98 batteryView->updatePercent( percent );
99 } 99 }
100 repaint( style != 0 ); 100 repaint( style != 0 );
101 if ( batteryView ) 101 if ( batteryView )
102 batteryView->repaint(); 102 batteryView->repaint();
103 } 103 }
104} 104}
105 105
106void BatteryMeter::chargeTimeout() 106void BatteryMeter::chargeTimeout()
107{ 107{
108 percent += 20; 108 percent += 20;
109 if ( percent > 100 ) 109 if ( percent > 100 )
110 percent = 0; 110 percent = 0;
111 111
112 repaint(FALSE); 112 repaint(FALSE);
113 if ( batteryView ) 113 if ( batteryView )
114 batteryView->updatePercent( percent ); 114 batteryView->updatePercent( percent );
115} 115}
116 116
117void BatteryMeter::paintEvent( QPaintEvent* ) 117void BatteryMeter::paintEvent( QPaintEvent* )
118{ 118{
119 if ( style == 1 ) 119 if ( style == 1 )
120 { 120 {
121 QPainter p(this); 121 QPainter p(this);
122 QFont f( "Fixed", AppLnk::smallIconSize()/2 ); 122 QFont f( "Fixed", AppLnk::smallIconSize()/2 );
123 QFontMetrics fm( f ); 123 QFontMetrics fm( f );
124 p.setFont( f ); 124 p.setFont( f );
125 p.drawText( 0, AppLnk::smallIconSize()/2, QString::number( percent ) ); 125 if ( percent > 98 ) {
126 p.drawText( AppLnk::smallIconSize()/4, AppLnk::smallIconSize(), "%" ); 126 p.drawText( 0, 0, width(), height(), Qt::AlignCenter, tr( "F" ) );
127 }
128 else if ( percent < 5 )
129 {
130 p.drawText( 0, 0, width(), height(), Qt::AlignCenter, tr( "E" ) );
131 }
132 else
133 {
134 p.drawText( 0, AppLnk::smallIconSize()/2, QString::number( percent ) );
135 p.drawText( AppLnk::smallIconSize()/4, AppLnk::smallIconSize(), "%" );
136 }
127 return; 137 return;
128 } 138 }
129 139
130 QPainter p(this); 140 QPainter p(this);
131 QColor color; 141 QColor color;
132 QColor g = gray.light( 160 ); 142 QColor g = gray.light( 160 );
133 switch ( ps->acStatus() ) 143 switch ( ps->acStatus() )
134 { 144 {
135 case PowerStatus::Offline: color = blue.light( 150 ); break; 145 case PowerStatus::Offline: color = blue.light( 150 ); break;
136 case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break; 146 case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break;
137 default: color = red.light( 160 ); 147 default: color = red.light( 160 );
138 } 148 }
139 149
140 int w = height() / 2; 150 int w = height() / 2;
141 if ( !(w%2) ) w--; // should have an odd value to get a real middle line 151 if ( !(w%2) ) w--; // should have an odd value to get a real middle line
142 int h = height() - 4; 152 int h = height() - 4;
143 int pix = (percent * h) / 100; 153 int pix = (percent * h) / 100;
144 int y2 = height() -2; 154 int y2 = height() -2;
145 int y = y2 - pix; 155 int y = y2 - pix;
146 int x1 = (width() - w ) / 2; 156 int x1 = (width() - w ) / 2;
147 157
148 p.setPen(QColor(80,80,80)); 158 p.setPen(QColor(80,80,80));
149 p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header 159 p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header
150 p.drawRect(x1,1,w,height()-1); // corpus 160 p.drawRect(x1,1,w,height()-1); // corpus
151 p.setBrush(color); 161 p.setBrush(color);
152 162
153 int extra = ((percent * h) % 100)/(100/4); 163 int extra = ((percent * h) % 100)/(100/4);
154 164
155 int middle = w/2; 165 int middle = w/2;
156 for ( int i = 0; i < middle; i++ ) 166 for ( int i = 0; i < middle; i++ )
157 { 167 {
158 p.setPen( gray.dark( 100+i*20 ) ); 168 p.setPen( gray.dark( 100+i*20 ) );
159 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); 169 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 );
160 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); 170 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 );
161 p.setPen( color.dark( 100+i*20 ) ); 171 p.setPen( color.dark( 100+i*20 ) );
162 p.drawLine( x1+middle-i, y, x1+middle-i, y2 ); 172 p.drawLine( x1+middle-i, y, x1+middle-i, y2 );
163 p.drawLine( x1+middle+i, y, x1+middle+i, y2 ); 173 p.drawLine( x1+middle+i, y, x1+middle+i, y2 );
164 } 174 }
165} 175}
166 176