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/battery.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/battery.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/batteryapplet/battery.cpp | 104 |
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 | |||
@@ -36,10 +36,9 @@ | |||
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 | { | ||
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 | ||
@@ -53,18 +52,14 @@ BatteryMeter::BatteryMeter( QWidget *parent ) | |||
53 | } | 52 | } |
54 | 53 | ||
55 | BatteryMeter::~BatteryMeter() | 54 | BatteryMeter::~BatteryMeter() { |
56 | { | ||
57 | delete ps; | 55 | delete ps; |
58 | } | 56 | } |
59 | 57 | ||
60 | QSize BatteryMeter::sizeHint() const | 58 | QSize 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 | ||
65 | void BatteryMeter::mousePressEvent( QMouseEvent* e ) | 62 | void 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" ); |
@@ -76,18 +71,27 @@ void BatteryMeter::mousePressEvent( QMouseEvent* e ) | |||
76 | } | 71 | } |
77 | 72 | ||
78 | void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) | 73 | void 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 | ||
90 | void BatteryMeter::timerEvent( QTimerEvent * ) | 94 | |
91 | { | 95 | void BatteryMeter::timerEvent( QTimerEvent * ) { |
92 | PowerStatus prev = *ps; | 96 | PowerStatus prev = *ps; |
93 | 97 | ||
@@ -95,37 +99,34 @@ void BatteryMeter::timerEvent( QTimerEvent * ) | |||
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 | ||
114 | void BatteryMeter::chargeTimeout() | 118 | void 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 | ||
125 | void BatteryMeter::paintEvent( QPaintEvent* ) | 128 | void 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 ); |
@@ -140,13 +141,18 @@ void BatteryMeter::paintEvent( QPaintEvent* ) | |||
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; |
@@ -163,6 +169,5 @@ void BatteryMeter::paintEvent( QPaintEvent* ) | |||
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 ); |
@@ -174,6 +179,5 @@ void BatteryMeter::paintEvent( QPaintEvent* ) | |||
174 | } | 179 | } |
175 | 180 | ||
176 | int BatteryMeter::position() | 181 | int BatteryMeter::position() { |
177 | { | ||
178 | return 8; | 182 | return 8; |
179 | } | 183 | } |