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