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