Diffstat (limited to 'core/applets/batteryapplet/battery.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/batteryapplet/battery.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp index b2cef55..18e368e 100644 --- a/core/applets/batteryapplet/battery.cpp +++ b/core/applets/batteryapplet/battery.cpp | |||
@@ -1,81 +1,84 @@ | |||
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 | |||
26 | #include <qpe/qpeapplication.h> | ||
25 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
26 | #include <qpe/config.h> | 28 | #include <qpe/config.h> |
27 | #include <qpe/power.h> | 29 | #include <qpe/power.h> |
28 | 30 | ||
29 | /* QT */ | 31 | /* QT */ |
30 | #include <qpainter.h> | 32 | #include <qpainter.h> |
31 | #include <qtimer.h> | 33 | #include <qtimer.h> |
32 | 34 | ||
33 | 35 | ||
36 | using namespace Opie::Ui; | ||
34 | BatteryMeter::BatteryMeter( QWidget *parent ) | 37 | BatteryMeter::BatteryMeter( QWidget *parent ) |
35 | : QWidget( parent ), charging(false) | 38 | : QWidget( parent ), charging(false) |
36 | { | 39 | { |
37 | ps = new PowerStatus; | 40 | ps = new PowerStatus; |
38 | startTimer( 10000 ); | 41 | startTimer( 10000 ); |
39 | 42 | ||
40 | setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); | 43 | setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); |
41 | setFixedHeight( AppLnk::smallIconSize() ); | 44 | setFixedHeight( AppLnk::smallIconSize() ); |
42 | 45 | ||
43 | chargeTimer = new QTimer( this ); | 46 | chargeTimer = new QTimer( this ); |
44 | connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); | 47 | connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); |
45 | timerEvent(0); | 48 | timerEvent(0); |
46 | QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); | 49 | QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); |
47 | Config c( "qpe" ); | 50 | Config c( "qpe" ); |
48 | c.setGroup( "Battery" ); | 51 | c.setGroup( "Battery" ); |
49 | style = c.readNumEntry( "Style", 0 ); | 52 | style = c.readNumEntry( "Style", 0 ); |
50 | } | 53 | } |
51 | 54 | ||
52 | BatteryMeter::~BatteryMeter() | 55 | BatteryMeter::~BatteryMeter() |
53 | { | 56 | { |
54 | delete ps; | 57 | delete ps; |
55 | } | 58 | } |
56 | 59 | ||
57 | QSize BatteryMeter::sizeHint() const | 60 | QSize BatteryMeter::sizeHint() const |
58 | { | 61 | { |
59 | return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); | 62 | return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); |
60 | } | 63 | } |
61 | 64 | ||
62 | void BatteryMeter::mousePressEvent( QMouseEvent* e ) | 65 | void BatteryMeter::mousePressEvent( QMouseEvent* e ) |
63 | { | 66 | { |
64 | if ( e->button() == RightButton ) | 67 | if ( e->button() == RightButton ) |
65 | { | 68 | { |
66 | style = 1-style; | 69 | style = 1-style; |
67 | Config c( "qpe" ); | 70 | Config c( "qpe" ); |
68 | c.setGroup( "Battery" ); | 71 | c.setGroup( "Battery" ); |
69 | c.writeEntry( "Style", style ); | 72 | c.writeEntry( "Style", style ); |
70 | repaint( true ); | 73 | repaint( true ); |
71 | } | 74 | } |
72 | QWidget::mousePressEvent( e ); | 75 | QWidget::mousePressEvent( e ); |
73 | } | 76 | } |
74 | 77 | ||
75 | void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) | 78 | void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) |
76 | { | 79 | { |
77 | if ( batteryView && batteryView->isVisible() ) { | 80 | if ( batteryView && batteryView->isVisible() ) { |
78 | delete (QWidget *) batteryView; | 81 | delete (QWidget *) batteryView; |
79 | } else { | 82 | } else { |
80 | if ( !batteryView ) batteryView = new BatteryStatus( ps ); | 83 | if ( !batteryView ) batteryView = new BatteryStatus( ps ); |
81 | QPEApplication::showWidget( batteryView ); | 84 | QPEApplication::showWidget( batteryView ); |
@@ -130,53 +133,50 @@ void BatteryMeter::paintEvent( QPaintEvent* ) | |||
130 | p.setFont( f ); | 133 | p.setFont( f ); |
131 | p.drawText( 0, height()/2, QString::number( percent ) ); | 134 | p.drawText( 0, height()/2, QString::number( percent ) ); |
132 | p.drawText( width()/4, height(), "%" ); | 135 | p.drawText( width()/4, height(), "%" ); |
133 | return; | 136 | return; |
134 | } | 137 | } |
135 | 138 | ||
136 | QPainter p(this); | 139 | QPainter p(this); |
137 | QColor color; | 140 | QColor color; |
138 | QColor g = gray.light( 160 ); | 141 | QColor g = gray.light( 160 ); |
139 | switch ( ps->acStatus() ) | 142 | switch ( ps->acStatus() ) |
140 | { | 143 | { |
141 | case PowerStatus::Offline: color = blue.light( 150 ); break; | 144 | case PowerStatus::Offline: color = blue.light( 150 ); break; |
142 | case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break; | 145 | case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break; |
143 | default: color = red.light( 160 ); | 146 | default: color = red.light( 160 ); |
144 | } | 147 | } |
145 | 148 | ||
146 | int w = height() / 2; | 149 | int w = height() / 2; |
147 | if ( !(w%2) ) w--; // should have an odd value to get a real middle line | 150 | if ( !(w%2) ) w--; // should have an odd value to get a real middle line |
148 | int h = height() - 4; | 151 | int h = height() - 4; |
149 | int pix = (percent * h) / 100; | 152 | int pix = (percent * h) / 100; |
150 | int y2 = height() -2; | 153 | int y2 = height() -2; |
151 | int y = y2 - pix; | 154 | int y = y2 - pix; |
152 | int x1 = (width() - w ) / 2; | 155 | int x1 = (width() - w ) / 2; |
153 | 156 | ||
154 | p.setPen(QColor(80,80,80)); | 157 | p.setPen(QColor(80,80,80)); |
155 | p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header | 158 | p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header |
156 | p.drawRect(x1,1,w,height()-1); // corpus | 159 | p.drawRect(x1,1,w,height()-1); // corpus |
157 | p.setBrush(color); | 160 | p.setBrush(color); |
158 | 161 | ||
159 | //int extra = ((percent * h) % 100)/(100/4); | 162 | //int extra = ((percent * h) % 100)/(100/4); |
160 | 163 | ||
161 | int middle = w/2; | 164 | int middle = w/2; |
162 | for ( int i = 0; i < middle; i++ ) | 165 | for ( int i = 0; i < middle; i++ ) |
163 | { | 166 | { |
164 | p.setPen( gray.dark( 100+i*20 ) ); | 167 | p.setPen( gray.dark( 100+i*20 ) ); |
165 | p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); | 168 | p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); |
166 | p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); | 169 | p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); |
167 | p.setPen( color.dark( 100+i*20 ) ); | 170 | p.setPen( color.dark( 100+i*20 ) ); |
168 | p.drawLine( x1+middle-i, y, x1+middle-i, y2 ); | 171 | p.drawLine( x1+middle-i, y, x1+middle-i, y2 ); |
169 | p.drawLine( x1+middle+i, y, x1+middle+i, y2 ); | 172 | p.drawLine( x1+middle+i, y, x1+middle+i, y2 ); |
170 | } | 173 | } |
171 | } | 174 | } |
172 | 175 | ||
173 | int BatteryMeter::position() | 176 | int BatteryMeter::position() |
174 | { | 177 | { |
175 | return 8; | 178 | return 8; |
176 | } | 179 | } |
177 | 180 | ||
178 | Q_EXPORT_INTERFACE() | 181 | EXPORT_OPIE_APPLET_v1( BatteryMeter ) |
179 | { | ||
180 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<BatteryMeter> ); | ||
181 | } | ||
182 | 182 | ||