-rw-r--r-- | core/applets/batteryapplet/batterystatus.cpp | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp index addb517..7f8de2c 100644 --- a/core/applets/batteryapplet/batterystatus.cpp +++ b/core/applets/batteryapplet/batterystatus.cpp | |||
@@ -78,177 +78,194 @@ bool BatteryStatus::getProcApmStatusIpaq() { | |||
78 | ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); | 78 | ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); |
79 | } | 79 | } |
80 | } | 80 | } |
81 | } | 81 | } |
82 | } else { | 82 | } else { |
83 | QMessageBox::warning(this, tr("Failure"),tr("could not open file")); | 83 | QMessageBox::warning(this, tr("Failure"),tr("could not open file")); |
84 | } | 84 | } |
85 | 85 | ||
86 | procApmIpaq.close(); | 86 | procApmIpaq.close(); |
87 | jackPercent = perc2.toInt(); | 87 | jackPercent = perc2.toInt(); |
88 | ipaqPercent = perc1.toInt(); | 88 | ipaqPercent = perc1.toInt(); |
89 | 89 | ||
90 | if (perc2.isEmpty()) { | 90 | if (perc2.isEmpty()) { |
91 | perc2 = tr("no data"); | 91 | perc2 = tr("no data"); |
92 | } else { | 92 | } else { |
93 | perc2 += " %"; | 93 | perc2 += " %"; |
94 | } | 94 | } |
95 | 95 | ||
96 | if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { | 96 | if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { |
97 | sec2 = tr("no data"); | 97 | sec2 = tr("no data"); |
98 | } else { | 98 | } else { |
99 | sec2 += " min"; | 99 | sec2 += " min"; |
100 | } | 100 | } |
101 | 101 | ||
102 | jackStatus == (" ( " + jackStatus + " )"); | 102 | jackStatus.prepend( " ( " ); |
103 | jackStatus.append( " )" ); | ||
103 | return true; | 104 | return true; |
104 | } | 105 | } |
105 | 106 | ||
106 | 107 | ||
107 | void BatteryStatus::updatePercent( int pc ) { | 108 | void BatteryStatus::updatePercent( int pc ) { |
108 | percent = pc; | 109 | percent = pc; |
109 | repaint(FALSE); | 110 | repaint(FALSE); |
110 | } | 111 | } |
111 | 112 | ||
112 | void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { | 113 | void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { |
113 | int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; | 114 | int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; |
114 | topgrad.hsv( &h1, &s1, &v1 ); | 115 | topgrad.hsv( &h1, &s1, &v1 ); |
115 | botgrad.hsv( &h2, &s2, &v2 ); | 116 | botgrad.hsv( &h2, &s2, &v2 ); |
116 | for ( int j = 0; j < hy-2; j++ ) { | 117 | for ( int j = 0; j < hy-2; j++ ) { |
117 | p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), | 118 | p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), |
118 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); | 119 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); |
119 | p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); | 120 | p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); |
120 | } | 121 | } |
121 | for ( int j = 0; j < hh; j++ ) { | 122 | for ( int j = 0; j < hh; j++ ) { |
122 | p->setPen( highlight ); | 123 | p->setPen( highlight ); |
123 | p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); | 124 | p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); |
124 | } | 125 | } |
125 | for ( int j = 0; j < ng-hy-hh; j++ ) { | 126 | for ( int j = 0; j < ng-hy-hh; j++ ) { |
126 | p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), | 127 | p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), |
127 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); | 128 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); |
128 | p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); | 129 | p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); |
129 | } | 130 | } |
130 | } | 131 | } |
131 | 132 | ||
132 | QString BatteryStatus::statusText() const { | 133 | QString BatteryStatus::statusText() const { |
133 | QString text; | 134 | QString text; |
134 | 135 | ||
135 | if ( ps->batteryStatus() == PowerStatus::Charging ) { | 136 | if ( ps->batteryStatus() == PowerStatus::Charging ) { |
136 | if (bat2) { | 137 | if (bat2) { |
137 | text = tr("Charging both devices"); | 138 | text = tr("Charging both devices"); |
138 | } else { | 139 | } else { |
139 | text = tr("Charging"); | 140 | text = tr("Charging"); |
140 | } | 141 | } |
141 | } else if ( ps->batteryPercentAccurate() ) { | 142 | } else if ( ps->batteryPercentAccurate() ) { |
142 | text.sprintf( tr("Remaining Power") + ": %i%%", percent ); | 143 | text = tr( "Remaining Power: %1%" ).arg( percent ); |
144 | //text.sprintf( tr("Remaining Power") + ": %i%%", percent ); | ||
143 | } else { | 145 | } else { |
144 | text = tr("Battery status: "); | 146 | text = tr( "Battery status: " ); |
145 | switch ( ps->batteryStatus() ) { | 147 | switch ( ps->batteryStatus() ) { |
146 | case PowerStatus::High: | 148 | case PowerStatus::High: |
147 | text += tr("Good"); | 149 | text.append( tr( "Good" ) ); |
148 | break; | 150 | break; |
149 | case PowerStatus::Low: | 151 | case PowerStatus::Low: |
150 | text += tr("Low"); | 152 | text.append( tr( "Low" ) ); |
151 | break; | 153 | break; |
152 | case PowerStatus::VeryLow: | 154 | case PowerStatus::VeryLow: |
153 | text += tr("Very Low"); | 155 | text.append( tr( "Very Low" ) ); |
154 | break; | 156 | break; |
155 | case PowerStatus::Critical: | 157 | case PowerStatus::Critical: |
156 | text += tr("Critical"); | 158 | text.append( tr( "Critical" ) ); |
157 | break; | 159 | break; |
158 | default: // NotPresent, etc. | 160 | default: // NotPresent, etc. |
159 | text += tr("Unknown"); | 161 | text.append( tr( "Unknown" ) ); |
160 | } | 162 | } |
161 | } | 163 | } |
162 | 164 | ||
163 | if ( ps->acStatus() == PowerStatus::Backup ) | 165 | if ( ps->acStatus() == PowerStatus::Backup ) |
164 | text += "\n" + tr("On backup power"); | 166 | { |
167 | text.append( '\n' ); | ||
168 | text.append( tr( "On backup power" ) ); | ||
169 | } | ||
165 | else if ( ps->acStatus() == PowerStatus::Online ) | 170 | else if ( ps->acStatus() == PowerStatus::Online ) |
166 | text += "\n" + tr("Power on-line"); | 171 | { |
172 | text.append( '\n' ); | ||
173 | text.append( tr( "Power on-line" ) ); | ||
174 | } | ||
167 | else if ( ps->acStatus() == PowerStatus::Offline ) | 175 | else if ( ps->acStatus() == PowerStatus::Offline ) |
168 | text += "\n" + tr("External power disconnected"); | 176 | { |
177 | text.append( '\n' ); | ||
178 | text.append( tr( "External power disconnected" ) ); | ||
179 | } | ||
169 | 180 | ||
170 | if ( ps->batteryTimeRemaining() >= 0 ) { | 181 | if ( ps->batteryTimeRemaining() >= 0 ) |
171 | text += "\n" + QString().sprintf( tr("Remaining Time") + ": %im %02is", | 182 | { |
172 | ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); | 183 | text.append( '\n' ); |
184 | text.append( tr("Remaining Time: %1m %2s" ).arg( ps->batteryTimeRemaining() / 60 ) | ||
185 | .arg( ps->batteryTimeRemaining() % 60, 2 ) ); | ||
186 | /* text += "\n" + QString().sprintf( tr("Remaining Time") + ": %im %02is", | ||
187 | ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 );*/ | ||
173 | } | 188 | } |
174 | return text; | 189 | return text; |
175 | } | 190 | } |
176 | 191 | ||
177 | QString BatteryStatus::statusTextIpaq() const { | 192 | QString BatteryStatus::statusTextIpaq() const { |
178 | QString text; | 193 | QString text = tr( "Remaing Power: %1 %2\nRemaining Time: %3" ).arg( perc2 ) |
179 | text += tr("Remaining Power: ") + perc2 + " " + jackStatus; | 194 | .arg( jackStatus ) |
180 | text += "\n" + tr("Remaining Time: ") + sec2; | 195 | .arg( sec2 ); |
196 | /* QString text = tr("Remaining Power: ") + perc2 + " " + jackStatus; | ||
197 | text += "\n" + tr("Remaining Time: ") + sec2;*/ | ||
181 | return text; | 198 | return text; |
182 | } | 199 | } |
183 | 200 | ||
184 | void BatteryStatus::paintEvent( QPaintEvent * ev ) { | 201 | void BatteryStatus::paintEvent( QPaintEvent * ev ) { |
185 | 202 | ||
186 | QPainter p( this ); | 203 | QPainter p( this ); |
187 | 204 | ||
188 | QString text = statusText(); | 205 | QString text = statusText(); |
189 | p.drawText( 10, 50, width() - 20, 40 , AlignVCenter, text ); | 206 | p.drawText( 10, 50, width() - 20, 40 , AlignVCenter, text ); |
190 | 207 | ||
191 | QColor c; | 208 | QColor c; |
192 | QColor darkc; | 209 | QColor darkc; |
193 | QColor lightc; | 210 | QColor lightc; |
194 | if ( ps->acStatus() == PowerStatus::Offline ) { | 211 | if ( ps->acStatus() == PowerStatus::Offline ) { |
195 | c = blue.light(120); | 212 | c = blue.light(120); |
196 | darkc = c.dark(280); | 213 | darkc = c.dark(280); |
197 | lightc = c.light(145); | 214 | lightc = c.light(145); |
198 | } else if ( ps->acStatus() == PowerStatus::Online ) { | 215 | } else if ( ps->acStatus() == PowerStatus::Online ) { |
199 | c = green.dark(130); | 216 | c = green.dark(130); |
200 | darkc = c.dark(200); | 217 | darkc = c.dark(200); |
201 | lightc = c.light(220); | 218 | lightc = c.light(220); |
202 | } else { | 219 | } else { |
203 | c = red; | 220 | c = red; |
204 | darkc = c.dark(280); | 221 | darkc = c.dark(280); |
205 | lightc = c.light(140); | 222 | lightc = c.light(140); |
206 | } | 223 | } |
207 | if ( percent < 0 ) | 224 | if ( percent < 0 ) |
208 | return; | 225 | return; |
209 | 226 | ||
210 | int rightEnd1 = width() - 47; | 227 | int rightEnd1 = width() - 47; |
211 | int rightEnd2 = width() - 35; | 228 | int rightEnd2 = width() - 35; |
212 | int percent2 = (percent * rightEnd1) / 100; | 229 | int percent2 = (percent * rightEnd1) / 100; |
213 | p.setPen( black ); | 230 | p.setPen( black ); |
214 | qDrawShadePanel( &p, 9, 10, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL); | 231 | qDrawShadePanel( &p, 9, 10, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL); |
215 | qDrawShadePanel( &p, rightEnd2, 17, 12, 24, colorGroup(), TRUE, 1, NULL); | 232 | qDrawShadePanel( &p, rightEnd2, 17, 12, 24, colorGroup(), TRUE, 1, NULL); |
216 | drawSegment( &p, QRect( 10, 10, percent2, 40 ), lightc, darkc, lightc.light(115), 6 ); | 233 | drawSegment( &p, QRect( 10, 10, percent2, 40 ), lightc, darkc, lightc.light(115), 6 ); |
217 | drawSegment( &p, QRect( 11 + percent2, 10, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 ); | 234 | drawSegment( &p, QRect( 11 + percent2, 10, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 ); |
218 | drawSegment( &p, QRect( rightEnd2, 17, 10, 25 ), white.light(80), black, white.light(90), 2 ); | 235 | drawSegment( &p, QRect( rightEnd2, 17, 10, 25 ), white.light(80), black, white.light(90), 2 ); |
219 | p.setPen( black); | 236 | p.setPen( black); |
220 | 237 | ||
221 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ && bat2 ) { | 238 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ && bat2 ) { |
222 | 239 | ||
223 | p.drawText( 15, 30, tr ("Ipaq ") + ipaqChem ); | 240 | p.drawText( 15, 30, tr("Ipaq %1").arg( ipaqChem ) ); |
224 | 241 | ||
225 | QString jacketMsg; | 242 | QString jacketMsg; |
226 | if (bat2) { | 243 | if (bat2) { |
227 | p.setPen(black); | 244 | p.setPen(black); |
228 | QString text = statusTextIpaq(); | 245 | QString text = statusTextIpaq(); |
229 | p.drawText( 10, 150, text ); | 246 | p.drawText( 10, 150, text ); |
230 | jacketMsg = tr("Jacket ") + jackChem; | 247 | jacketMsg = tr("Jacket ").arg( jackChem ); |
231 | } else { | 248 | } else { |
232 | jackPercent = 0; | 249 | jackPercent = 0; |
233 | jacketMsg = tr("No jacket with battery inserted"); | 250 | jacketMsg = tr("No jacket with battery inserted"); |
234 | } | 251 | } |
235 | 252 | ||
236 | int jackPerc = ( jackPercent * ( width() - 47 ) ) / 100; | 253 | int jackPerc = ( jackPercent * ( width() - 47 ) ) / 100; |
237 | 254 | ||
238 | qDrawShadePanel( &p, 9, 90, rightEnd1, 39, colorGroup(), TRUE, 1, NULL); | 255 | qDrawShadePanel( &p, 9, 90, rightEnd1, 39, colorGroup(), TRUE, 1, NULL); |
239 | qDrawShadePanel( &p, rightEnd2, 97, 12, 24, colorGroup(), TRUE, 1, NULL); | 256 | qDrawShadePanel( &p, rightEnd2, 97, 12, 24, colorGroup(), TRUE, 1, NULL); |
240 | drawSegment( &p, QRect( 10, 90, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 ); | 257 | drawSegment( &p, QRect( 10, 90, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 ); |
241 | drawSegment( &p, QRect( 11 + jackPerc, 90, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 ); | 258 | drawSegment( &p, QRect( 11 + jackPerc, 90, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 ); |
242 | drawSegment( &p, QRect( rightEnd2, 97, 10, 25 ), white.light(80), black, white.light(90), 2 ); | 259 | drawSegment( &p, QRect( rightEnd2, 97, 10, 25 ), white.light(80), black, white.light(90), 2 ); |
243 | p.setPen( black ); | 260 | p.setPen( black ); |
244 | p.drawText(15, 100, width() - 20, 20 , AlignVCenter, jacketMsg); | 261 | p.drawText(15, 100, width() - 20, 20 , AlignVCenter, jacketMsg); |
245 | } | 262 | } |
246 | QFrame::paintEvent(ev); | 263 | QFrame::paintEvent(ev); |
247 | } | 264 | } |
248 | 265 | ||
249 | QSize BatteryStatus::sizeHint() const { | 266 | QSize BatteryStatus::sizeHint() const { |
250 | QString text = statusText(); | 267 | QString text = statusText(); |
251 | QString text2 = statusTextIpaq(); | 268 | QString text2 = statusTextIpaq(); |
252 | QFontMetrics fm = fontMetrics(); | 269 | QFontMetrics fm = fontMetrics(); |
253 | QRect r=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text ); | 270 | QRect r=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text ); |
254 | QRect r2=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text2 ); | 271 | QRect r2=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text2 ); |