summaryrefslogtreecommitdiff
path: root/core/applets/batteryapplet/battery.cpp
authorharlekin <harlekin>2004-05-11 22:41:22 (UTC)
committer harlekin <harlekin>2004-05-11 22:41:22 (UTC)
commit7a9cabb330284777113bb544139843dcf0593628 (patch) (unidiff)
treeec706423d2abc2b7d2dcbbab8f3d846bcff45ee0 /core/applets/batteryapplet/battery.cpp
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 (limited to 'core/applets/batteryapplet/battery.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/battery.cpp104
1 files changed, 54 insertions, 50 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,12 +35,11 @@
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
43 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); 42 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) );
44 setFixedHeight( AppLnk::smallIconSize() ); 43 setFixedHeight( AppLnk::smallIconSize() );
45 44
46 chargeTimer = new QTimer( this ); 45 chargeTimer = new QTimer( this );
@@ -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,58 +70,64 @@ 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();
95 99
96 if ( prev != *ps ) { 100 if ( prev != *ps ) {
97 percent = ps->batteryPercentRemaining(); 101 percent = ps->batteryPercentRemaining();
98 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) { 102 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) {
99 percent = 0; 103 percent = 0;
100 charging = true; 104 charging = true;
101 chargeTimer->start( 500 ); 105 chargeTimer->start( 500 );
102 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { 106 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) {
103 charging = false; 107 charging = false;
104 chargeTimer->stop(); 108 chargeTimer->stop();
109 if ( batteryView )
110 batteryView->updatePercent( percent );
111 }
112 repaint( style != 0 );
105 if ( batteryView ) 113 if ( batteryView )
106 batteryView->updatePercent( percent ); 114 batteryView->repaint();
107 }
108 repaint( style != 0 );
109 if ( batteryView )
110 batteryView->repaint();
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;
119 122
120 repaint(FALSE); 123 repaint(FALSE);
121 if ( batteryView ) 124 if ( batteryView )
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