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