summaryrefslogtreecommitdiff
path: root/core/applets/batteryapplet/batterystatus.cpp
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /core/applets/batteryapplet/batterystatus.cpp
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'core/applets/batteryapplet/batterystatus.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp
new file mode 100644
index 0000000..d18b6c9
--- a/dev/null
+++ b/core/applets/batteryapplet/batterystatus.cpp
@@ -0,0 +1,140 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "batterystatus.h"
21
22#include <qpe/power.h>
23
24#include <qpainter.h>
25#include <qpushbutton.h>
26#include <qdrawutil.h>
27
28
29BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent )
30 : QWidget( parent, 0, WDestructiveClose), ps(p)
31{
32 setCaption( tr("Battery Status") );
33 QPushButton *pb = new QPushButton( tr("Close"), this );
34 pb->move( 70, 220 );
35 pb->show();
36 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) );
37 percent = ps->batteryPercentRemaining();
38 show();
39}
40
41BatteryStatus::~BatteryStatus()
42{
43}
44
45void BatteryStatus::updatePercent( int pc )
46{
47 percent = pc;
48 repaint(FALSE);
49}
50
51void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height )
52{
53 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height;
54 topgrad.hsv( &h1, &s1, &v1 );
55 botgrad.hsv( &h2, &s2, &v2 );
56 for ( int j = 0; j < hy-2; j++ ) {
57 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
58 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
59 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j );
60 }
61 for ( int j = 0; j < hh; j++ ) {
62 p->setPen( highlight );
63 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j );
64 }
65 for ( int j = 0; j < ng-hy-hh; j++ ) {
66 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
67 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
68 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j );
69 }
70}
71
72void BatteryStatus::paintEvent( QPaintEvent * )
73{
74 QPainter p(this);
75 QString text;
76 if ( ps->batteryStatus() == PowerStatus::Charging ) {
77 text = tr("Charging");
78 } else if ( ps->batteryPercentAccurate() ) {
79 text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent );
80 } else {
81 text = tr("Battery status: ");
82 switch ( ps->batteryStatus() ) {
83 case PowerStatus::High:
84 text += tr("Good");
85 break;
86 case PowerStatus::Low:
87 text += tr("Low");
88 break;
89 case PowerStatus::VeryLow:
90 text += tr("Very Low");
91 break;
92 case PowerStatus::Critical:
93 text += tr("Critical");
94 break;
95 default: // NotPresent, etc.
96 text += tr("Unknown");
97 }
98 }
99 p.drawText( 10, 120, text );
100 if ( ps->acStatus() == PowerStatus::Backup )
101 p.drawText( 10, 150, tr("On backup power") );
102 else if ( ps->acStatus() == PowerStatus::Online )
103 p.drawText( 10, 150, tr("Power on-line") );
104 else if ( ps->acStatus() == PowerStatus::Offline )
105 p.drawText( 10, 150, tr("External power disconnected") );
106
107 if ( ps->batteryTimeRemaining() >= 0 ) {
108 text.sprintf( tr("Battery time remaining") + ": %im %02is",
109 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 );
110 p.drawText( 10, 180, text );
111 }
112
113 QColor c;
114 QColor darkc;
115 QColor lightc;
116 if ( ps->acStatus() == PowerStatus::Offline ) {
117 c = blue.light(120);
118 darkc = c.dark(280);
119 lightc = c.light(145);
120 } else if ( ps->acStatus() == PowerStatus::Online ) {
121 c = green.dark(130);
122 darkc = c.dark(200);
123 lightc = c.light(220);
124 } else {
125 c = red;
126 darkc = c.dark(280);
127 lightc = c.light(140);
128 }
129 if ( percent < 0 )
130 return;
131
132 int percent2 = percent * 2;
133 p.setPen( black );
134 qDrawShadePanel( &p, 9, 30, 204, 39, colorGroup(), TRUE, 1, NULL);
135 qDrawShadePanel( &p, 212, 37, 12, 24, colorGroup(), TRUE, 1, NULL);
136 drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 );
137 drawSegment( &p, QRect( 11 + percent2, 30, 200 - percent2, 40 ), white.light(80), black, white.light(90), 6 );
138 drawSegment( &p, QRect( 212, 37, 10, 25 ), white.light(80), black, white.light(90), 2 );
139}
140