summaryrefslogtreecommitdiff
authorharlekin <harlekin>2004-05-11 22:41:22 (UTC)
committer harlekin <harlekin>2004-05-11 22:41:22 (UTC)
commit7a9cabb330284777113bb544139843dcf0593628 (patch) (unidiff)
treeec706423d2abc2b7d2dcbbab8f3d846bcff45ee0
parent81104f00cb87962333a024d3fa5ff6cf3d8d7d83 (diff)
downloadopie-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 (more/less context) (show whitespace changes)
-rw-r--r--core/applets/batteryapplet/battery.cpp72
-rw-r--r--core/applets/batteryapplet/battery.h3
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp103
-rw-r--r--core/applets/batteryapplet/batterystatus.h12
4 files changed, 102 insertions, 88 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp
index 98b61b5..0d3d190 100644
--- a/core/applets/batteryapplet/battery.cpp
+++ b/core/applets/batteryapplet/battery.cpp
@@ -37,4 +37,3 @@ using namespace Opie::Ui;
37BatteryMeter::BatteryMeter( QWidget *parent ) 37BatteryMeter::BatteryMeter( QWidget *parent )
38 : QWidget( parent ), charging(false) 38: QWidget( parent ), charging(false) {
39{
40 ps = new PowerStatus; 39 ps = new PowerStatus;
@@ -54,4 +53,3 @@ BatteryMeter::BatteryMeter( QWidget *parent )
54 53
55BatteryMeter::~BatteryMeter() 54BatteryMeter::~BatteryMeter() {
56{
57 delete ps; 55 delete ps;
@@ -59,4 +57,3 @@ BatteryMeter::~BatteryMeter()
59 57
60QSize BatteryMeter::sizeHint() const 58QSize BatteryMeter::sizeHint() const {
61{
62 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); 59 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() );
@@ -64,6 +61,4 @@ QSize BatteryMeter::sizeHint() const
64 61
65void BatteryMeter::mousePressEvent( QMouseEvent* e ) 62void BatteryMeter::mousePressEvent( QMouseEvent* e ) {
66{ 63 if ( e->button() == RightButton ) {
67 if ( e->button() == RightButton )
68 {
69 style = 1-style; 64 style = 1-style;
@@ -77,11 +72,20 @@ void BatteryMeter::mousePressEvent( QMouseEvent* e )
77 72
78void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) 73void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) {
79{
80 if ( batteryView && batteryView->isVisible() ) { 74 if ( batteryView && batteryView->isVisible() ) {
81 delete (QWidget *) batteryView; 75 batteryView->hide();
82 } else { 76 } else {
83 if ( !batteryView ) batteryView = new BatteryStatus( ps ); 77 if ( !batteryView ) {
84 QPEApplication::showWidget( batteryView ); 78 batteryView = new BatteryStatus( ps, 0, WStyle_StaysOnTop | WType_Popup );
79 batteryView->setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
80 }
81
82 QRect r(batteryView->pos(),batteryView->sizeHint());
83 QPoint curPos = this->mapToGlobal ( rect().topLeft() );
84
85 int lp = qApp->desktop()->width() - batteryView->sizeHint().width();
86 r.moveTopLeft( QPoint(lp, curPos.y()-batteryView->sizeHint().height()-1) );
87 batteryView->setGeometry(r);
88
85 batteryView->raise(); 89 batteryView->raise();
86 batteryView->showMaximized(); 90 batteryView->show();
87 } 91 }
@@ -89,4 +93,4 @@ void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ )
89 93
90void BatteryMeter::timerEvent( QTimerEvent * ) 94
91{ 95void BatteryMeter::timerEvent( QTimerEvent * ) {
92 PowerStatus prev = *ps; 96 PowerStatus prev = *ps;
@@ -113,4 +117,3 @@ void BatteryMeter::timerEvent( QTimerEvent * )
113 117
114void BatteryMeter::chargeTimeout() 118void BatteryMeter::chargeTimeout() {
115{
116 percent += 20; 119 percent += 20;
@@ -124,7 +127,5 @@ void BatteryMeter::chargeTimeout()
124 127
125void BatteryMeter::paintEvent( QPaintEvent* ) 128void BatteryMeter::paintEvent( QPaintEvent* ) {
126{
127 129
128 if ( style == 1 ) 130 if ( style == 1 ) {
129 {
130 QPainter p(this); 131 QPainter p(this);
@@ -141,7 +142,11 @@ void BatteryMeter::paintEvent( QPaintEvent* )
141 QColor g = gray.light( 160 ); 142 QColor g = gray.light( 160 );
142 switch ( ps->acStatus() ) 143 switch ( ps->acStatus() ) {
143 { 144 case PowerStatus::Offline:
144 case PowerStatus::Offline: color = blue.light( 150 ); break; 145 color = blue.light( 150 );
145 case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break; 146 break;
146 default: color = red.light( 160 ); 147 case PowerStatus::Online:
148 color = green.dark( 130 ).light( 180 );
149 break;
150 default:
151 color = red.light( 160 );
147 } 152 }
@@ -149,3 +154,4 @@ void BatteryMeter::paintEvent( QPaintEvent* )
149 int w = height() / 2; 154 int w = height() / 2;
150 if ( !(w%2) ) w--; // should have an odd value to get a real middle line 155 if ( !(w%2) )
156 w--; // should have an odd value to get a real middle line
151 int h = height() - 4; 157 int h = height() - 4;
@@ -164,4 +170,3 @@ void BatteryMeter::paintEvent( QPaintEvent* )
164 int middle = w/2; 170 int middle = w/2;
165 for ( int i = 0; i < middle; i++ ) 171 for ( int i = 0; i < middle; i++ ) {
166 {
167 p.setPen( gray.dark( 100+i*20 ) ); 172 p.setPen( gray.dark( 100+i*20 ) );
@@ -175,4 +180,3 @@ void BatteryMeter::paintEvent( QPaintEvent* )
175 180
176int BatteryMeter::position() 181int BatteryMeter::position() {
177{
178 return 8; 182 return 8;
diff --git a/core/applets/batteryapplet/battery.h b/core/applets/batteryapplet/battery.h
index 622c083..970c857 100644
--- a/core/applets/batteryapplet/battery.h
+++ b/core/applets/batteryapplet/battery.h
@@ -39,2 +39,4 @@ class BatteryMeter : public QWidget
39 39
40
41
40 protected: 42 protected:
@@ -44,3 +46,2 @@ class BatteryMeter : public QWidget
44 void mouseReleaseEvent( QMouseEvent* ); 46 void mouseReleaseEvent( QMouseEvent* );
45
46 protected slots: 47 protected slots:
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
@@ -11,3 +11,2 @@
11#include <qfile.h> 11#include <qfile.h>
12#include <qlayout.h>
13#include <qtextstream.h> 12#include <qtextstream.h>
@@ -17,9 +16,4 @@ using namespace Opie::Core;
17 16
18BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) 17BatteryStatus::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
@@ -27,9 +21,2 @@ BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent )
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 ) {
@@ -37,10 +24,6 @@ BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent )
37 } 24 }
38 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) );
39 percent = ps->batteryPercentRemaining(); 25 percent = ps->batteryPercentRemaining();
40 show();
41} 26}
42 27
43BatteryStatus::~BatteryStatus() 28BatteryStatus::~BatteryStatus() {}
44{
45}
46 29
@@ -98,3 +81,2 @@ bool BatteryStatus::getProcApmStatusIpaq() {
98 procApmIpaq.close(); 81 procApmIpaq.close();
99
100 jackPercent = perc2.toInt(); 82 jackPercent = perc2.toInt();
@@ -108,3 +90,2 @@ bool BatteryStatus::getProcApmStatusIpaq() {
108 90
109
110 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { 91 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
@@ -116,3 +97,2 @@ bool BatteryStatus::getProcApmStatusIpaq() {
116 jackStatus == (" ( " + jackStatus + " )"); 97 jackStatus == (" ( " + jackStatus + " )");
117
118 return true; 98 return true;
@@ -146,6 +126,5 @@ void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topg
146 126
147void BatteryStatus::paintEvent( QPaintEvent * ) { 127QString 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 ) {
@@ -177,16 +156,30 @@ void BatteryStatus::paintEvent( QPaintEvent * ) {
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
172QString 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
179void 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
@@ -215,13 +208,12 @@ void BatteryStatus::paintEvent( QPaintEvent * ) {
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
@@ -230,4 +222,4 @@ void BatteryStatus::paintEvent( QPaintEvent * ) {
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;
@@ -240,12 +232,25 @@ void BatteryStatus::paintEvent( QPaintEvent * ) {
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
243QSize 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}
diff --git a/core/applets/batteryapplet/batterystatus.h b/core/applets/batteryapplet/batterystatus.h
index a5ab804..bb95ece 100644
--- a/core/applets/batteryapplet/batterystatus.h
+++ b/core/applets/batteryapplet/batterystatus.h
@@ -22,3 +22,3 @@
22 22
23#include <qwidget.h> 23#include <qframe.h>
24 24
@@ -26,3 +26,3 @@ class PowerStatus;
26 26
27class BatteryStatus : public QWidget 27class BatteryStatus : public QFrame
28{ 28{
@@ -30,3 +30,3 @@ class BatteryStatus : public QWidget
30public: 30public:
31 BatteryStatus( const PowerStatus *s, QWidget *parent=0 ); 31 BatteryStatus( const PowerStatus *s, QWidget *parent=0, WFlags f = 0 );
32 ~BatteryStatus(); 32 ~BatteryStatus();
@@ -34,3 +34,3 @@ public:
34 void updatePercent( int ); 34 void updatePercent( int );
35 35 QSize sizeHint() const;
36protected: 36protected:
@@ -39,3 +39,6 @@ protected:
39 bool BatteryStatus::getProcApmStatusIpaq(); 39 bool BatteryStatus::getProcApmStatusIpaq();
40
40private: 41private:
42 QString statusText() const;
43 QString statusTextIpaq() const;
41 const PowerStatus *ps; 44 const PowerStatus *ps;
@@ -54,2 +57,3 @@ private:
54 bool bat2; 57 bool bat2;
58 bool bat2inserted;
55 int screenWidth; 59 int screenWidth;