author | harlekin <harlekin> | 2004-05-11 22:41:22 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2004-05-11 22:41:22 (UTC) |
commit | 7a9cabb330284777113bb544139843dcf0593628 (patch) (unidiff) | |
tree | ec706423d2abc2b7d2dcbbab8f3d846bcff45ee0 /core/applets/batteryapplet/batterystatus.cpp | |
parent | 81104f00cb87962333a024d3fa5ff6cf3d8d7d83 (diff) | |
download | opie-7a9cabb330284777113bb544139843dcf0593628.zip opie-7a9cabb330284777113bb544139843dcf0593628.tar.gz opie-7a9cabb330284777113bb544139843dcf0593628.tar.bz2 |
the "bett ery" commit, batteryapplet is now a popup, only shows second battery on ipaq if a second battery is present
Diffstat (limited to 'core/applets/batteryapplet/batterystatus.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/applets/batteryapplet/batterystatus.cpp | 103 |
1 files changed, 54 insertions, 49 deletions
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp index ab8f36d..655fdc4 100644 --- a/core/applets/batteryapplet/batterystatus.cpp +++ b/core/applets/batteryapplet/batterystatus.cpp | |||
@@ -9,40 +9,23 @@ | |||
9 | #include <qpushbutton.h> | 9 | #include <qpushbutton.h> |
10 | #include <qdrawutil.h> | 10 | #include <qdrawutil.h> |
11 | #include <qfile.h> | 11 | #include <qfile.h> |
12 | #include <qlayout.h> | ||
13 | #include <qtextstream.h> | 12 | #include <qtextstream.h> |
14 | #include <qmessagebox.h> | 13 | #include <qmessagebox.h> |
15 | 14 | ||
16 | using namespace Opie::Core; | 15 | using namespace Opie::Core; |
17 | 16 | ||
18 | BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) | 17 | BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent, WFlags f ) |
19 | : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) { | 18 | : QFrame( parent, 0, f), ps(p), bat2(false) { |
20 | setCaption( tr("Battery status") ); | ||
21 | setMinimumSize( 150, 200 ); | ||
22 | |||
23 | QPushButton *pb = new QPushButton( tr("Close"), this ); | ||
24 | QVBoxLayout *layout = new QVBoxLayout ( this ); | ||
25 | 19 | ||
26 | jackPercent = 0; | 20 | jackPercent = 0; |
27 | 21 | ||
28 | pb->setMaximumSize( 120, 40 ); | ||
29 | |||
30 | pb->show(); | ||
31 | |||
32 | layout->addStretch(); | ||
33 | layout->addWidget( pb ); | ||
34 | |||
35 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { | 22 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { |
36 | getProcApmStatusIpaq(); | 23 | getProcApmStatusIpaq(); |
37 | } | 24 | } |
38 | connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) ); | ||
39 | percent = ps->batteryPercentRemaining(); | 25 | percent = ps->batteryPercentRemaining(); |
40 | show(); | ||
41 | } | 26 | } |
42 | 27 | ||
43 | BatteryStatus::~BatteryStatus() | 28 | BatteryStatus::~BatteryStatus() {} |
44 | { | ||
45 | } | ||
46 | 29 | ||
47 | /* | 30 | /* |
48 | * Make use of the advanced apm interface of the ipaq | 31 | * Make use of the advanced apm interface of the ipaq |
@@ -96,7 +79,6 @@ bool BatteryStatus::getProcApmStatusIpaq() { | |||
96 | } | 79 | } |
97 | 80 | ||
98 | procApmIpaq.close(); | 81 | procApmIpaq.close(); |
99 | |||
100 | jackPercent = perc2.toInt(); | 82 | jackPercent = perc2.toInt(); |
101 | ipaqPercent = perc1.toInt(); | 83 | ipaqPercent = perc1.toInt(); |
102 | 84 | ||
@@ -106,7 +88,6 @@ bool BatteryStatus::getProcApmStatusIpaq() { | |||
106 | perc2 += " %"; | 88 | perc2 += " %"; |
107 | } | 89 | } |
108 | 90 | ||
109 | |||
110 | if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { | 91 | if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { |
111 | sec2 = tr("no data"); | 92 | sec2 = tr("no data"); |
112 | } else { | 93 | } else { |
@@ -114,7 +95,6 @@ bool BatteryStatus::getProcApmStatusIpaq() { | |||
114 | } | 95 | } |
115 | 96 | ||
116 | jackStatus == (" ( " + jackStatus + " )"); | 97 | jackStatus == (" ( " + jackStatus + " )"); |
117 | |||
118 | return true; | 98 | return true; |
119 | } | 99 | } |
120 | 100 | ||
@@ -144,10 +124,9 @@ void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topg | |||
144 | } | 124 | } |
145 | } | 125 | } |
146 | 126 | ||
147 | void BatteryStatus::paintEvent( QPaintEvent * ) { | 127 | QString BatteryStatus::statusText() const { |
148 | |||
149 | QPainter p(this); | ||
150 | QString text; | 128 | QString text; |
129 | |||
151 | if ( ps->batteryStatus() == PowerStatus::Charging ) { | 130 | if ( ps->batteryStatus() == PowerStatus::Charging ) { |
152 | if (bat2) { | 131 | if (bat2) { |
153 | text = tr("Charging both devices"); | 132 | text = tr("Charging both devices"); |
@@ -175,20 +154,34 @@ void BatteryStatus::paintEvent( QPaintEvent * ) { | |||
175 | text += tr("Unknown"); | 154 | text += tr("Unknown"); |
176 | } | 155 | } |
177 | } | 156 | } |
178 | p.drawText( 10, 90, text ); | ||
179 | 157 | ||
180 | if ( ps->acStatus() == PowerStatus::Backup ) | 158 | if ( ps->acStatus() == PowerStatus::Backup ) |
181 | p.drawText( 10, 110, tr("On backup power") ); | 159 | text += "\n" + tr("On backup power"); |
182 | else if ( ps->acStatus() == PowerStatus::Online ) | 160 | else if ( ps->acStatus() == PowerStatus::Online ) |
183 | p.drawText( 10, 110, tr("Power on-line") ); | 161 | text += "\n" + tr("Power on-line"); |
184 | else if ( ps->acStatus() == PowerStatus::Offline ) | 162 | else if ( ps->acStatus() == PowerStatus::Offline ) |
185 | p.drawText( 10, 110, tr("External power disconnected") ); | 163 | text += "\n" + tr("External power disconnected"); |
186 | 164 | ||
187 | if ( ps->batteryTimeRemaining() >= 0 ) { | 165 | if ( ps->batteryTimeRemaining() >= 0 ) { |
188 | text.sprintf( tr("Battery time remaining") + ": %im %02is", | 166 | text += "\n" + QString().sprintf( tr("Battery time remaining") + ": %im %02is", |
189 | ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); | 167 | ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); |
190 | p.drawText( 10, 130, text ); | ||
191 | } | 168 | } |
169 | return text; | ||
170 | } | ||
171 | |||
172 | QString BatteryStatus::statusTextIpaq() const { | ||
173 | QString text; | ||
174 | text += tr("Percentage battery remaining: ") + perc2 + " " + jackStatus; | ||
175 | text += "\n" + tr("Battery time remaining: ") + sec2; | ||
176 | return text; | ||
177 | } | ||
178 | |||
179 | void BatteryStatus::paintEvent( QPaintEvent * ) { | ||
180 | |||
181 | QPainter p( this ); | ||
182 | |||
183 | QString text = statusText(); | ||
184 | p.drawText( 10, 50, width() - 20, 40 , AlignVCenter, text ); | ||
192 | 185 | ||
193 | QColor c; | 186 | QColor c; |
194 | QColor darkc; | 187 | QColor darkc; |
@@ -213,23 +206,22 @@ void BatteryStatus::paintEvent( QPaintEvent * ) { | |||
213 | int rightEnd2 = width() - 35; | 206 | int rightEnd2 = width() - 35; |
214 | int percent2 = (percent * rightEnd1) / 100; | 207 | int percent2 = (percent * rightEnd1) / 100; |
215 | p.setPen( black ); | 208 | p.setPen( black ); |
216 | qDrawShadePanel( &p, 9, 30, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL); | 209 | qDrawShadePanel( &p, 9, 10, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL); |
217 | qDrawShadePanel( &p, rightEnd2, 37, 12, 24, colorGroup(), TRUE, 1, NULL); | 210 | qDrawShadePanel( &p, rightEnd2, 17, 12, 24, colorGroup(), TRUE, 1, NULL); |
218 | drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 ); | 211 | drawSegment( &p, QRect( 10, 10, percent2, 40 ), lightc, darkc, lightc.light(115), 6 ); |
219 | drawSegment( &p, QRect( 11 + percent2, 30, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 ); | 212 | drawSegment( &p, QRect( 11 + percent2, 10, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 ); |
220 | drawSegment( &p, QRect( rightEnd2, 37, 10, 25 ), white.light(80), black, white.light(90), 2 ); | 213 | drawSegment( &p, QRect( rightEnd2, 17, 10, 25 ), white.light(80), black, white.light(90), 2 ); |
221 | p.setPen( black); | 214 | p.setPen( black); |
222 | 215 | ||
216 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ && bat2 ) { | ||
223 | 217 | ||
224 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { | 218 | p.drawText( 15, 30, tr ("Ipaq ") + ipaqChem ); |
225 | |||
226 | p.drawText(15, 50, tr ("Ipaq ") + ipaqChem); | ||
227 | 219 | ||
228 | QString jacketMsg; | 220 | QString jacketMsg; |
229 | if (bat2) { | 221 | if (bat2) { |
230 | p.setPen(black); | 222 | p.setPen(black); |
231 | p.drawText(10,220, tr("Percentage battery remaining: ") + perc2 + " " + jackStatus); | 223 | QString text = statusTextIpaq(); |
232 | p.drawText(10,240, tr("Battery time remaining: ") + sec2); | 224 | p.drawText( 10, 150, text ); |
233 | jacketMsg = tr("Jacket ") + jackChem; | 225 | jacketMsg = tr("Jacket ") + jackChem; |
234 | } else { | 226 | } else { |
235 | jackPercent = 0; | 227 | jackPercent = 0; |
@@ -238,14 +230,27 @@ void BatteryStatus::paintEvent( QPaintEvent * ) { | |||
238 | 230 | ||
239 | int jackPerc = ( jackPercent * ( width() - 47 ) ) / 100; | 231 | int jackPerc = ( jackPercent * ( width() - 47 ) ) / 100; |
240 | 232 | ||
241 | qDrawShadePanel( &p, 9, 160, rightEnd1, 39, colorGroup(), TRUE, 1, NULL); | 233 | qDrawShadePanel( &p, 9, 90, rightEnd1, 39, colorGroup(), TRUE, 1, NULL); |
242 | qDrawShadePanel( &p, rightEnd2, 167, 12, 24, colorGroup(), TRUE, 1, NULL); | 234 | qDrawShadePanel( &p, rightEnd2, 97, 12, 24, colorGroup(), TRUE, 1, NULL); |
243 | drawSegment( &p, QRect( 10, 160, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 ); | 235 | drawSegment( &p, QRect( 10, 90, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 ); |
244 | drawSegment( &p, QRect( 11 + jackPerc, 160, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 ); | 236 | drawSegment( &p, QRect( 11 + jackPerc, 90, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 ); |
245 | drawSegment( &p, QRect( rightEnd2, 167, 10, 25 ), white.light(80), black, white.light(90), 2 ); | 237 | drawSegment( &p, QRect( rightEnd2, 97, 10, 25 ), white.light(80), black, white.light(90), 2 ); |
246 | p.setPen( black ); | 238 | p.setPen( black ); |
247 | p.drawText(15, 180, jacketMsg); | 239 | p.drawText(15, 100, width() - 20, 20 , AlignVCenter, jacketMsg); |
248 | } | 240 | } |
249 | |||
250 | } | 241 | } |
251 | 242 | ||
243 | QSize BatteryStatus::sizeHint() const { | ||
244 | QString text = statusText(); | ||
245 | QString text2 = statusTextIpaq(); | ||
246 | QFontMetrics fm = fontMetrics(); | ||
247 | QRect r=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text ); | ||
248 | QRect r2=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text2 ); | ||
249 | |||
250 | if ( bat2 ) { | ||
251 | return QSize( QMAX( QMIN( 200, qApp->desktop()->width() ), | ||
252 | r.width() ), 2 * 10 + 80 + r.height() + r2.height() ); | ||
253 | } | ||
254 | return QSize( QMAX( QMIN( 200, qApp->desktop()->width() ), | ||
255 | r.width() ), 2 * 10 + 40 + r.height() ); | ||
256 | } | ||