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