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
@@ -35,8 +35,7 @@
35 35
36using namespace Opie::Ui; 36using 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;
41 startTimer( 10000 ); 40 startTimer( 10000 );
42 41
@@ -52,20 +51,16 @@ BatteryMeter::BatteryMeter( QWidget *parent )
52 style = c.readNumEntry( "Style", 0 ); 51 style = c.readNumEntry( "Style", 0 );
53} 52}
54 53
55BatteryMeter::~BatteryMeter() 54BatteryMeter::~BatteryMeter() {
56{
57 delete ps; 55 delete ps;
58} 56}
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() );
63} 60}
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;
70 Config c( "qpe" ); 65 Config c( "qpe" );
71 c.setGroup( "Battery" ); 66 c.setGroup( "Battery" );
@@ -75,20 +70,29 @@ void BatteryMeter::mousePressEvent( QMouseEvent* e )
75 QWidget::mousePressEvent( e ); 70 QWidget::mousePressEvent( e );
76} 71}
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 }
88} 92}
89 93
90void BatteryMeter::timerEvent( QTimerEvent * ) 94
91{ 95void BatteryMeter::timerEvent( QTimerEvent * ) {
92 PowerStatus prev = *ps; 96 PowerStatus prev = *ps;
93 97
94 *ps = PowerStatusManager::readStatus(); 98 *ps = PowerStatusManager::readStatus();
@@ -111,8 +115,7 @@ void BatteryMeter::timerEvent( QTimerEvent * )
111 } 115 }
112} 116}
113 117
114void BatteryMeter::chargeTimeout() 118void BatteryMeter::chargeTimeout() {
115{
116 percent += 20; 119 percent += 20;
117 if ( percent > 100 ) 120 if ( percent > 100 )
118 percent = 0; 121 percent = 0;
@@ -122,11 +125,9 @@ void BatteryMeter::chargeTimeout()
122 batteryView->updatePercent( percent ); 125 batteryView->updatePercent( percent );
123} 126}
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);
131 QFont f( "Fixed", AppLnk::smallIconSize()/2 ); 132 QFont f( "Fixed", AppLnk::smallIconSize()/2 );
132 QFontMetrics fm( f ); 133 QFontMetrics fm( f );
@@ -139,15 +140,20 @@ void BatteryMeter::paintEvent( QPaintEvent* )
139 QPainter p(this); 140 QPainter p(this);
140 QColor color; 141 QColor color;
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 }
148 153
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;
152 int pix = (percent * h) / 100; 158 int pix = (percent * h) / 100;
153 int y2 = height() -2; 159 int y2 = height() -2;
@@ -162,8 +168,7 @@ void BatteryMeter::paintEvent( QPaintEvent* )
162 //int extra = ((percent * h) % 100)/(100/4); 168 //int extra = ((percent * h) % 100)/(100/4);
163 169
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 ) );
168 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); 173 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 );
169 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); 174 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 );
@@ -173,8 +178,7 @@ void BatteryMeter::paintEvent( QPaintEvent* )
173 } 178 }
174} 179}
175 180
176int BatteryMeter::position() 181int BatteryMeter::position() {
177{
178 return 8; 182 return 8;
179} 183}
180 184
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
@@ -37,12 +37,13 @@ class BatteryMeter : public QWidget
37 QSize sizeHint() const; 37 QSize sizeHint() const;
38 static int position(); 38 static int position();
39 39
40
41
40 protected: 42 protected:
41 void timerEvent( QTimerEvent* ); 43 void timerEvent( QTimerEvent* );
42 void paintEvent( QPaintEvent* ); 44 void paintEvent( QPaintEvent* );
43 void mousePressEvent( QMouseEvent* ); 45 void mousePressEvent( QMouseEvent* );
44 void mouseReleaseEvent( QMouseEvent* ); 46 void mouseReleaseEvent( QMouseEvent* );
45
46 protected slots: 47 protected slots:
47 void chargeTimeout(); 48 void chargeTimeout();
48 49
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
16using namespace Opie::Core; 15using 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
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
43BatteryStatus::~BatteryStatus() 28BatteryStatus::~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
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 ) {
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
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
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
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
@@ -20,24 +20,27 @@
20#ifndef BATTERY_STATUS_H 20#ifndef BATTERY_STATUS_H
21#define BATTERY_STATUS_H 21#define BATTERY_STATUS_H
22 22
23#include <qwidget.h> 23#include <qframe.h>
24 24
25class PowerStatus; 25class PowerStatus;
26 26
27class BatteryStatus : public QWidget 27class BatteryStatus : public QFrame
28{ 28{
29 Q_OBJECT 29 Q_OBJECT
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();
33 33
34 void updatePercent( int ); 34 void updatePercent( int );
35 35 QSize sizeHint() const;
36protected: 36protected:
37 void drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ); 37 void drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height );
38 void paintEvent( QPaintEvent *pe ); 38 void paintEvent( QPaintEvent *pe );
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;
42 int percent; 45 int percent;
43 int ipaqPercent; 46 int ipaqPercent;
@@ -52,6 +55,7 @@ private:
52 QString ipaqChem; 55 QString ipaqChem;
53 QString jackChem; 56 QString jackChem;
54 bool bat2; 57 bool bat2;
58 bool bat2inserted;
55 int screenWidth; 59 int screenWidth;
56 int screenHeight; 60 int screenHeight;
57}; 61};