-rw-r--r-- | core/applets/batteryapplet/battery.cpp | 1 | ||||
-rw-r--r-- | core/applets/batteryapplet/batterystatus.cpp | 17 | ||||
-rw-r--r-- | core/applets/batteryapplet/batterystatus.h | 2 |
3 files changed, 13 insertions, 7 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp index 0d3d190..e85a9da 100644 --- a/core/applets/batteryapplet/battery.cpp +++ b/core/applets/batteryapplet/battery.cpp | |||
@@ -1,186 +1,187 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "battery.h" | 20 | #include "battery.h" |
21 | #include "batterystatus.h" | 21 | #include "batterystatus.h" |
22 | 22 | ||
23 | /* OPIE */ | 23 | /* OPIE */ |
24 | #include <opie2/otaskbarapplet.h> | 24 | #include <opie2/otaskbarapplet.h> |
25 | 25 | ||
26 | #include <qpe/qpeapplication.h> | 26 | #include <qpe/qpeapplication.h> |
27 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
28 | #include <qpe/config.h> | 28 | #include <qpe/config.h> |
29 | #include <qpe/power.h> | 29 | #include <qpe/power.h> |
30 | 30 | ||
31 | /* QT */ | 31 | /* QT */ |
32 | #include <qpainter.h> | 32 | #include <qpainter.h> |
33 | #include <qtimer.h> | 33 | #include <qtimer.h> |
34 | 34 | ||
35 | 35 | ||
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 | ps = new PowerStatus; | 39 | ps = new PowerStatus; |
40 | startTimer( 10000 ); | 40 | startTimer( 10000 ); |
41 | 41 | ||
42 | setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); | 42 | setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); |
43 | setFixedHeight( AppLnk::smallIconSize() ); | 43 | setFixedHeight( AppLnk::smallIconSize() ); |
44 | 44 | ||
45 | chargeTimer = new QTimer( this ); | 45 | chargeTimer = new QTimer( this ); |
46 | connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); | 46 | connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); |
47 | timerEvent(0); | 47 | timerEvent(0); |
48 | QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); | 48 | QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); |
49 | Config c( "qpe" ); | 49 | Config c( "qpe" ); |
50 | c.setGroup( "Battery" ); | 50 | c.setGroup( "Battery" ); |
51 | style = c.readNumEntry( "Style", 0 ); | 51 | style = c.readNumEntry( "Style", 0 ); |
52 | } | 52 | } |
53 | 53 | ||
54 | BatteryMeter::~BatteryMeter() { | 54 | BatteryMeter::~BatteryMeter() { |
55 | delete ps; | 55 | delete ps; |
56 | } | 56 | } |
57 | 57 | ||
58 | QSize BatteryMeter::sizeHint() const { | 58 | QSize BatteryMeter::sizeHint() const { |
59 | return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); | 59 | return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); |
60 | } | 60 | } |
61 | 61 | ||
62 | void BatteryMeter::mousePressEvent( QMouseEvent* e ) { | 62 | void BatteryMeter::mousePressEvent( QMouseEvent* e ) { |
63 | if ( e->button() == RightButton ) { | 63 | if ( e->button() == RightButton ) { |
64 | style = 1-style; | 64 | style = 1-style; |
65 | Config c( "qpe" ); | 65 | Config c( "qpe" ); |
66 | c.setGroup( "Battery" ); | 66 | c.setGroup( "Battery" ); |
67 | c.writeEntry( "Style", style ); | 67 | c.writeEntry( "Style", style ); |
68 | repaint( true ); | 68 | repaint( true ); |
69 | } | 69 | } |
70 | QWidget::mousePressEvent( e ); | 70 | QWidget::mousePressEvent( e ); |
71 | } | 71 | } |
72 | 72 | ||
73 | void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) { | 73 | void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) { |
74 | if ( batteryView && batteryView->isVisible() ) { | 74 | if ( batteryView && batteryView->isVisible() ) { |
75 | batteryView->hide(); | 75 | batteryView->hide(); |
76 | } else { | 76 | } else { |
77 | if ( !batteryView ) { | 77 | if ( !batteryView ) { |
78 | batteryView = new BatteryStatus( ps, 0, WStyle_StaysOnTop | WType_Popup ); | 78 | batteryView = new BatteryStatus( ps, 0, WStyle_StaysOnTop | WType_Popup ); |
79 | batteryView->setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 79 | batteryView->setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
80 | } | 80 | } |
81 | 81 | ||
82 | batteryView->UpdateBatteryStatus(); | ||
82 | QRect r(batteryView->pos(),batteryView->sizeHint()); | 83 | QRect r(batteryView->pos(),batteryView->sizeHint()); |
83 | QPoint curPos = this->mapToGlobal ( rect().topLeft() ); | 84 | QPoint curPos = this->mapToGlobal ( rect().topLeft() ); |
84 | 85 | ||
85 | int lp = qApp->desktop()->width() - batteryView->sizeHint().width(); | 86 | int lp = qApp->desktop()->width() - batteryView->sizeHint().width(); |
86 | r.moveTopLeft( QPoint(lp, curPos.y()-batteryView->sizeHint().height()-1) ); | 87 | r.moveTopLeft( QPoint(lp, curPos.y()-batteryView->sizeHint().height()-1) ); |
87 | batteryView->setGeometry(r); | 88 | batteryView->setGeometry(r); |
88 | 89 | ||
89 | batteryView->raise(); | 90 | batteryView->raise(); |
90 | batteryView->show(); | 91 | batteryView->show(); |
91 | } | 92 | } |
92 | } | 93 | } |
93 | 94 | ||
94 | 95 | ||
95 | void BatteryMeter::timerEvent( QTimerEvent * ) { | 96 | void BatteryMeter::timerEvent( QTimerEvent * ) { |
96 | PowerStatus prev = *ps; | 97 | PowerStatus prev = *ps; |
97 | 98 | ||
98 | *ps = PowerStatusManager::readStatus(); | 99 | *ps = PowerStatusManager::readStatus(); |
99 | 100 | ||
100 | if ( prev != *ps ) { | 101 | if ( prev != *ps ) { |
101 | percent = ps->batteryPercentRemaining(); | 102 | percent = ps->batteryPercentRemaining(); |
102 | if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) { | 103 | if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) { |
103 | percent = 0; | 104 | percent = 0; |
104 | charging = true; | 105 | charging = true; |
105 | chargeTimer->start( 500 ); | 106 | chargeTimer->start( 500 ); |
106 | } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { | 107 | } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { |
107 | charging = false; | 108 | charging = false; |
108 | chargeTimer->stop(); | 109 | chargeTimer->stop(); |
109 | if ( batteryView ) | 110 | if ( batteryView ) |
110 | batteryView->updatePercent( percent ); | 111 | batteryView->updatePercent( percent ); |
111 | } | 112 | } |
112 | repaint( style != 0 ); | 113 | repaint( style != 0 ); |
113 | if ( batteryView ) | 114 | if ( batteryView ) |
114 | batteryView->repaint(); | 115 | batteryView->repaint(); |
115 | } | 116 | } |
116 | } | 117 | } |
117 | 118 | ||
118 | void BatteryMeter::chargeTimeout() { | 119 | void BatteryMeter::chargeTimeout() { |
119 | percent += 20; | 120 | percent += 20; |
120 | if ( percent > 100 ) | 121 | if ( percent > 100 ) |
121 | percent = 0; | 122 | percent = 0; |
122 | 123 | ||
123 | repaint(FALSE); | 124 | repaint(FALSE); |
124 | if ( batteryView ) | 125 | if ( batteryView ) |
125 | batteryView->updatePercent( percent ); | 126 | batteryView->updatePercent( percent ); |
126 | } | 127 | } |
127 | 128 | ||
128 | void BatteryMeter::paintEvent( QPaintEvent* ) { | 129 | void BatteryMeter::paintEvent( QPaintEvent* ) { |
129 | 130 | ||
130 | if ( style == 1 ) { | 131 | if ( style == 1 ) { |
131 | QPainter p(this); | 132 | QPainter p(this); |
132 | QFont f( "Fixed", AppLnk::smallIconSize()/2 ); | 133 | QFont f( "Fixed", AppLnk::smallIconSize()/2 ); |
133 | QFontMetrics fm( f ); | 134 | QFontMetrics fm( f ); |
134 | p.setFont( f ); | 135 | p.setFont( f ); |
135 | p.drawText( 0, height()/2, QString::number( percent ) ); | 136 | p.drawText( 0, height()/2, QString::number( percent ) ); |
136 | p.drawText( width()/4, height(), "%" ); | 137 | p.drawText( width()/4, height(), "%" ); |
137 | return; | 138 | return; |
138 | } | 139 | } |
139 | 140 | ||
140 | QPainter p(this); | 141 | QPainter p(this); |
141 | QColor color; | 142 | QColor color; |
142 | QColor g = gray.light( 160 ); | 143 | QColor g = gray.light( 160 ); |
143 | switch ( ps->acStatus() ) { | 144 | switch ( ps->acStatus() ) { |
144 | case PowerStatus::Offline: | 145 | case PowerStatus::Offline: |
145 | color = blue.light( 150 ); | 146 | color = blue.light( 150 ); |
146 | break; | 147 | break; |
147 | case PowerStatus::Online: | 148 | case PowerStatus::Online: |
148 | color = green.dark( 130 ).light( 180 ); | 149 | color = green.dark( 130 ).light( 180 ); |
149 | break; | 150 | break; |
150 | default: | 151 | default: |
151 | color = red.light( 160 ); | 152 | color = red.light( 160 ); |
152 | } | 153 | } |
153 | 154 | ||
154 | int w = height() / 2; | 155 | int w = height() / 2; |
155 | if ( !(w%2) ) | 156 | if ( !(w%2) ) |
156 | w--; // should have an odd value to get a real middle line | 157 | w--; // should have an odd value to get a real middle line |
157 | int h = height() - 4; | 158 | int h = height() - 4; |
158 | int pix = (percent * h) / 100; | 159 | int pix = (percent * h) / 100; |
159 | int y2 = height() -2; | 160 | int y2 = height() -2; |
160 | int y = y2 - pix; | 161 | int y = y2 - pix; |
161 | int x1 = (width() - w ) / 2; | 162 | int x1 = (width() - w ) / 2; |
162 | 163 | ||
163 | p.setPen(QColor(80,80,80)); | 164 | p.setPen(QColor(80,80,80)); |
164 | p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header | 165 | p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header |
165 | p.drawRect(x1,1,w,height()-1); // corpus | 166 | p.drawRect(x1,1,w,height()-1); // corpus |
166 | p.setBrush(color); | 167 | p.setBrush(color); |
167 | 168 | ||
168 | //int extra = ((percent * h) % 100)/(100/4); | 169 | //int extra = ((percent * h) % 100)/(100/4); |
169 | 170 | ||
170 | int middle = w/2; | 171 | int middle = w/2; |
171 | for ( int i = 0; i < middle; i++ ) { | 172 | for ( int i = 0; i < middle; i++ ) { |
172 | p.setPen( gray.dark( 100+i*20 ) ); | 173 | p.setPen( gray.dark( 100+i*20 ) ); |
173 | p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); | 174 | p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); |
174 | p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); | 175 | p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); |
175 | p.setPen( color.dark( 100+i*20 ) ); | 176 | p.setPen( color.dark( 100+i*20 ) ); |
176 | p.drawLine( x1+middle-i, y, x1+middle-i, y2 ); | 177 | p.drawLine( x1+middle-i, y, x1+middle-i, y2 ); |
177 | p.drawLine( x1+middle+i, y, x1+middle+i, y2 ); | 178 | p.drawLine( x1+middle+i, y, x1+middle+i, y2 ); |
178 | } | 179 | } |
179 | } | 180 | } |
180 | 181 | ||
181 | int BatteryMeter::position() { | 182 | int BatteryMeter::position() { |
182 | return 8; | 183 | return 8; |
183 | } | 184 | } |
184 | 185 | ||
185 | EXPORT_OPIE_APPLET_v1( BatteryMeter ) | 186 | EXPORT_OPIE_APPLET_v1( BatteryMeter ) |
186 | 187 | ||
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp index 5a24b94..860db64 100644 --- a/core/applets/batteryapplet/batterystatus.cpp +++ b/core/applets/batteryapplet/batterystatus.cpp | |||
@@ -1,257 +1,262 @@ | |||
1 | 1 | ||
2 | #include "batterystatus.h" | 2 | #include "batterystatus.h" |
3 | 3 | ||
4 | /* OPIE */ | 4 | /* OPIE */ |
5 | #include <opie2/odevice.h> | 5 | #include <opie2/odevice.h> |
6 | #include <qpe/power.h> | 6 | #include <qpe/power.h> |
7 | 7 | ||
8 | /* QT */ | 8 | /* QT */ |
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 <qtextstream.h> | 12 | #include <qtextstream.h> |
13 | #include <qmessagebox.h> | 13 | #include <qmessagebox.h> |
14 | 14 | ||
15 | using namespace Opie::Core; | 15 | using namespace Opie::Core; |
16 | 16 | ||
17 | BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent, WFlags f ) | 17 | BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent, WFlags f ) |
18 | : QFrame( parent, 0, f), ps(p), bat2(false) { | 18 | : QFrame( parent, 0, f), ps(p), bat2(false) { |
19 | 19 | ||
20 | jackPercent = 0; | 20 | UpdateBatteryStatus(); |
21 | |||
22 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { | ||
23 | getProcApmStatusIpaq(); | ||
24 | } | ||
25 | percent = ps->batteryPercentRemaining(); | ||
26 | } | 21 | } |
27 | 22 | ||
28 | BatteryStatus::~BatteryStatus() {} | 23 | BatteryStatus::~BatteryStatus() {} |
29 | 24 | ||
25 | void BatteryStatus::UpdateBatteryStatus() { | ||
26 | |||
27 | jackPercent = 0; | ||
28 | |||
29 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { | ||
30 | getProcApmStatusIpaq(); | ||
31 | } | ||
32 | percent = ps->batteryPercentRemaining(); | ||
33 | } | ||
34 | |||
30 | /* | 35 | /* |
31 | * Make use of the advanced apm interface of the ipaq | 36 | * Make use of the advanced apm interface of the ipaq |
32 | */ | 37 | */ |
33 | bool BatteryStatus::getProcApmStatusIpaq() { | 38 | bool BatteryStatus::getProcApmStatusIpaq() { |
34 | 39 | ||
35 | bat2 = false; | 40 | bat2 = false; |
36 | 41 | ||
37 | QFile procApmIpaq("/proc/hal/battery"); | 42 | QFile procApmIpaq("/proc/hal/battery"); |
38 | 43 | ||
39 | if (procApmIpaq.open(IO_ReadOnly) ) { | 44 | if (procApmIpaq.open(IO_ReadOnly) ) { |
40 | QStringList list; | 45 | QStringList list; |
41 | // since it is /proc we _must_ use QTextStream | 46 | // since it is /proc we _must_ use QTextStream |
42 | QTextStream stream ( &procApmIpaq); | 47 | QTextStream stream ( &procApmIpaq); |
43 | QString streamIn; | 48 | QString streamIn; |
44 | streamIn = stream.read(); | 49 | streamIn = stream.read(); |
45 | list = QStringList::split("\n", streamIn); | 50 | list = QStringList::split("\n", streamIn); |
46 | 51 | ||
47 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { | 52 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { |
48 | // not nice, need a rewrite later | 53 | // not nice, need a rewrite later |
49 | if( (*line).startsWith(" Percentage") ) { | 54 | if( (*line).startsWith(" Percentage") ) { |
50 | if (bat2 == true) { | 55 | if (bat2 == true) { |
51 | perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2); | 56 | perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2); |
52 | } else { | 57 | } else { |
53 | perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); | 58 | perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); |
54 | } | 59 | } |
55 | } else if( (*line).startsWith(" Life") ) { | 60 | } else if( (*line).startsWith(" Life") ) { |
56 | if (bat2 == true) { | 61 | if (bat2 == true) { |
57 | sec2 = (*line).mid(((*line).find(':')+2), 5 ); | 62 | sec2 = (*line).mid(((*line).find(':')+2), 5 ); |
58 | } else { | 63 | } else { |
59 | sec1 = (*line).mid(((*line).find(':')+2), 5 ); | 64 | sec1 = (*line).mid(((*line).find(':')+2), 5 ); |
60 | } | 65 | } |
61 | } else if( (*line).startsWith("Battery #1") ) { | 66 | } else if( (*line).startsWith("Battery #1") ) { |
62 | bat2 = true; | 67 | bat2 = true; |
63 | } else if( (*line).startsWith(" Status") ) { | 68 | } else if( (*line).startsWith(" Status") ) { |
64 | if (bat2 == true) { | 69 | if (bat2 == true) { |
65 | jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); | 70 | jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); |
66 | } else { | 71 | } else { |
67 | ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); | 72 | ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); |
68 | } | 73 | } |
69 | } else if( (*line).startsWith(" Chemistry") ) { | 74 | } else if( (*line).startsWith(" Chemistry") ) { |
70 | if (bat2 == true) { | 75 | if (bat2 == true) { |
71 | jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); | 76 | jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); |
72 | } else { | 77 | } else { |
73 | ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); | 78 | ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); |
74 | } | 79 | } |
75 | } | 80 | } |
76 | } | 81 | } |
77 | } else { | 82 | } else { |
78 | QMessageBox::warning(this, tr("Failure"),tr("could not open file")); | 83 | QMessageBox::warning(this, tr("Failure"),tr("could not open file")); |
79 | } | 84 | } |
80 | 85 | ||
81 | procApmIpaq.close(); | 86 | procApmIpaq.close(); |
82 | jackPercent = perc2.toInt(); | 87 | jackPercent = perc2.toInt(); |
83 | ipaqPercent = perc1.toInt(); | 88 | ipaqPercent = perc1.toInt(); |
84 | 89 | ||
85 | if (perc2.isEmpty()) { | 90 | if (perc2.isEmpty()) { |
86 | perc2 = tr("no data"); | 91 | perc2 = tr("no data"); |
87 | } else { | 92 | } else { |
88 | perc2 += " %"; | 93 | perc2 += " %"; |
89 | } | 94 | } |
90 | 95 | ||
91 | if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { | 96 | if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { |
92 | sec2 = tr("no data"); | 97 | sec2 = tr("no data"); |
93 | } else { | 98 | } else { |
94 | sec2 += " min"; | 99 | sec2 += " min"; |
95 | } | 100 | } |
96 | 101 | ||
97 | jackStatus == (" ( " + jackStatus + " )"); | 102 | jackStatus == (" ( " + jackStatus + " )"); |
98 | return true; | 103 | return true; |
99 | } | 104 | } |
100 | 105 | ||
101 | 106 | ||
102 | void BatteryStatus::updatePercent( int pc ) { | 107 | void BatteryStatus::updatePercent( int pc ) { |
103 | percent = pc; | 108 | percent = pc; |
104 | repaint(FALSE); | 109 | repaint(FALSE); |
105 | } | 110 | } |
106 | 111 | ||
107 | 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 ) { |
108 | 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; |
109 | topgrad.hsv( &h1, &s1, &v1 ); | 114 | topgrad.hsv( &h1, &s1, &v1 ); |
110 | botgrad.hsv( &h2, &s2, &v2 ); | 115 | botgrad.hsv( &h2, &s2, &v2 ); |
111 | for ( int j = 0; j < hy-2; j++ ) { | 116 | for ( int j = 0; j < hy-2; j++ ) { |
112 | 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), |
113 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); | 118 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); |
114 | 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 ); |
115 | } | 120 | } |
116 | for ( int j = 0; j < hh; j++ ) { | 121 | for ( int j = 0; j < hh; j++ ) { |
117 | p->setPen( highlight ); | 122 | p->setPen( highlight ); |
118 | 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 ); |
119 | } | 124 | } |
120 | for ( int j = 0; j < ng-hy-hh; j++ ) { | 125 | for ( int j = 0; j < ng-hy-hh; j++ ) { |
121 | 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), |
122 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); | 127 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); |
123 | 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 ); |
124 | } | 129 | } |
125 | } | 130 | } |
126 | 131 | ||
127 | QString BatteryStatus::statusText() const { | 132 | QString BatteryStatus::statusText() const { |
128 | QString text; | 133 | QString text; |
129 | 134 | ||
130 | if ( ps->batteryStatus() == PowerStatus::Charging ) { | 135 | if ( ps->batteryStatus() == PowerStatus::Charging ) { |
131 | if (bat2) { | 136 | if (bat2) { |
132 | text = tr("Charging both devices"); | 137 | text = tr("Charging both devices"); |
133 | } else { | 138 | } else { |
134 | text = tr("Charging"); | 139 | text = tr("Charging"); |
135 | } | 140 | } |
136 | } else if ( ps->batteryPercentAccurate() ) { | 141 | } else if ( ps->batteryPercentAccurate() ) { |
137 | text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent ); | 142 | text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent ); |
138 | } else { | 143 | } else { |
139 | text = tr("Battery status: "); | 144 | text = tr("Battery status: "); |
140 | switch ( ps->batteryStatus() ) { | 145 | switch ( ps->batteryStatus() ) { |
141 | case PowerStatus::High: | 146 | case PowerStatus::High: |
142 | text += tr("Good"); | 147 | text += tr("Good"); |
143 | break; | 148 | break; |
144 | case PowerStatus::Low: | 149 | case PowerStatus::Low: |
145 | text += tr("Low"); | 150 | text += tr("Low"); |
146 | break; | 151 | break; |
147 | case PowerStatus::VeryLow: | 152 | case PowerStatus::VeryLow: |
148 | text += tr("Very Low"); | 153 | text += tr("Very Low"); |
149 | break; | 154 | break; |
150 | case PowerStatus::Critical: | 155 | case PowerStatus::Critical: |
151 | text += tr("Critical"); | 156 | text += tr("Critical"); |
152 | break; | 157 | break; |
153 | default: // NotPresent, etc. | 158 | default: // NotPresent, etc. |
154 | text += tr("Unknown"); | 159 | text += tr("Unknown"); |
155 | } | 160 | } |
156 | } | 161 | } |
157 | 162 | ||
158 | if ( ps->acStatus() == PowerStatus::Backup ) | 163 | if ( ps->acStatus() == PowerStatus::Backup ) |
159 | text += "\n" + tr("On backup power"); | 164 | text += "\n" + tr("On backup power"); |
160 | else if ( ps->acStatus() == PowerStatus::Online ) | 165 | else if ( ps->acStatus() == PowerStatus::Online ) |
161 | text += "\n" + tr("Power on-line"); | 166 | text += "\n" + tr("Power on-line"); |
162 | else if ( ps->acStatus() == PowerStatus::Offline ) | 167 | else if ( ps->acStatus() == PowerStatus::Offline ) |
163 | text += "\n" + tr("External power disconnected"); | 168 | text += "\n" + tr("External power disconnected"); |
164 | 169 | ||
165 | if ( ps->batteryTimeRemaining() >= 0 ) { | 170 | if ( ps->batteryTimeRemaining() >= 0 ) { |
166 | text += "\n" + QString().sprintf( tr("Battery time remaining") + ": %im %02is", | 171 | text += "\n" + QString().sprintf( tr("Battery time remaining") + ": %im %02is", |
167 | ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); | 172 | ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); |
168 | } | 173 | } |
169 | return text; | 174 | return text; |
170 | } | 175 | } |
171 | 176 | ||
172 | QString BatteryStatus::statusTextIpaq() const { | 177 | QString BatteryStatus::statusTextIpaq() const { |
173 | QString text; | 178 | QString text; |
174 | text += tr("Percentage battery remaining: ") + perc2 + " " + jackStatus; | 179 | text += tr("Percentage battery remaining: ") + perc2 + " " + jackStatus; |
175 | text += "\n" + tr("Battery time remaining: ") + sec2; | 180 | text += "\n" + tr("Battery time remaining: ") + sec2; |
176 | return text; | 181 | return text; |
177 | } | 182 | } |
178 | 183 | ||
179 | void BatteryStatus::paintEvent( QPaintEvent * ev ) { | 184 | void BatteryStatus::paintEvent( QPaintEvent * ev ) { |
180 | 185 | ||
181 | QPainter p( this ); | 186 | QPainter p( this ); |
182 | 187 | ||
183 | QString text = statusText(); | 188 | QString text = statusText(); |
184 | p.drawText( 10, 50, width() - 20, 40 , AlignVCenter, text ); | 189 | p.drawText( 10, 50, width() - 20, 40 , AlignVCenter, text ); |
185 | 190 | ||
186 | QColor c; | 191 | QColor c; |
187 | QColor darkc; | 192 | QColor darkc; |
188 | QColor lightc; | 193 | QColor lightc; |
189 | if ( ps->acStatus() == PowerStatus::Offline ) { | 194 | if ( ps->acStatus() == PowerStatus::Offline ) { |
190 | c = blue.light(120); | 195 | c = blue.light(120); |
191 | darkc = c.dark(280); | 196 | darkc = c.dark(280); |
192 | lightc = c.light(145); | 197 | lightc = c.light(145); |
193 | } else if ( ps->acStatus() == PowerStatus::Online ) { | 198 | } else if ( ps->acStatus() == PowerStatus::Online ) { |
194 | c = green.dark(130); | 199 | c = green.dark(130); |
195 | darkc = c.dark(200); | 200 | darkc = c.dark(200); |
196 | lightc = c.light(220); | 201 | lightc = c.light(220); |
197 | } else { | 202 | } else { |
198 | c = red; | 203 | c = red; |
199 | darkc = c.dark(280); | 204 | darkc = c.dark(280); |
200 | lightc = c.light(140); | 205 | lightc = c.light(140); |
201 | } | 206 | } |
202 | if ( percent < 0 ) | 207 | if ( percent < 0 ) |
203 | return; | 208 | return; |
204 | 209 | ||
205 | int rightEnd1 = width() - 47; | 210 | int rightEnd1 = width() - 47; |
206 | int rightEnd2 = width() - 35; | 211 | int rightEnd2 = width() - 35; |
207 | int percent2 = (percent * rightEnd1) / 100; | 212 | int percent2 = (percent * rightEnd1) / 100; |
208 | p.setPen( black ); | 213 | p.setPen( black ); |
209 | qDrawShadePanel( &p, 9, 10, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL); | 214 | qDrawShadePanel( &p, 9, 10, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL); |
210 | qDrawShadePanel( &p, rightEnd2, 17, 12, 24, colorGroup(), TRUE, 1, NULL); | 215 | qDrawShadePanel( &p, rightEnd2, 17, 12, 24, colorGroup(), TRUE, 1, NULL); |
211 | 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 ); |
212 | 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 ); |
213 | 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 ); |
214 | p.setPen( black); | 219 | p.setPen( black); |
215 | 220 | ||
216 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ && bat2 ) { | 221 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ && bat2 ) { |
217 | 222 | ||
218 | p.drawText( 15, 30, tr ("Ipaq ") + ipaqChem ); | 223 | p.drawText( 15, 30, tr ("Ipaq ") + ipaqChem ); |
219 | 224 | ||
220 | QString jacketMsg; | 225 | QString jacketMsg; |
221 | if (bat2) { | 226 | if (bat2) { |
222 | p.setPen(black); | 227 | p.setPen(black); |
223 | QString text = statusTextIpaq(); | 228 | QString text = statusTextIpaq(); |
224 | p.drawText( 10, 150, text ); | 229 | p.drawText( 10, 150, text ); |
225 | jacketMsg = tr("Jacket ") + jackChem; | 230 | jacketMsg = tr("Jacket ") + jackChem; |
226 | } else { | 231 | } else { |
227 | jackPercent = 0; | 232 | jackPercent = 0; |
228 | jacketMsg = tr("No jacket with battery inserted"); | 233 | jacketMsg = tr("No jacket with battery inserted"); |
229 | } | 234 | } |
230 | 235 | ||
231 | int jackPerc = ( jackPercent * ( width() - 47 ) ) / 100; | 236 | int jackPerc = ( jackPercent * ( width() - 47 ) ) / 100; |
232 | 237 | ||
233 | qDrawShadePanel( &p, 9, 90, rightEnd1, 39, colorGroup(), TRUE, 1, NULL); | 238 | qDrawShadePanel( &p, 9, 90, rightEnd1, 39, colorGroup(), TRUE, 1, NULL); |
234 | qDrawShadePanel( &p, rightEnd2, 97, 12, 24, colorGroup(), TRUE, 1, NULL); | 239 | qDrawShadePanel( &p, rightEnd2, 97, 12, 24, colorGroup(), TRUE, 1, NULL); |
235 | 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 ); |
236 | 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 ); |
237 | 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 ); |
238 | p.setPen( black ); | 243 | p.setPen( black ); |
239 | p.drawText(15, 100, width() - 20, 20 , AlignVCenter, jacketMsg); | 244 | p.drawText(15, 100, width() - 20, 20 , AlignVCenter, jacketMsg); |
240 | } | 245 | } |
241 | QFrame::paintEvent(ev); | 246 | QFrame::paintEvent(ev); |
242 | } | 247 | } |
243 | 248 | ||
244 | QSize BatteryStatus::sizeHint() const { | 249 | QSize BatteryStatus::sizeHint() const { |
245 | QString text = statusText(); | 250 | QString text = statusText(); |
246 | QString text2 = statusTextIpaq(); | 251 | QString text2 = statusTextIpaq(); |
247 | QFontMetrics fm = fontMetrics(); | 252 | QFontMetrics fm = fontMetrics(); |
248 | QRect r=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text ); | 253 | QRect r=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text ); |
249 | QRect r2=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text2 ); | 254 | QRect r2=fm.boundingRect( 10, 0, width(), height(), AlignVCenter, text2 ); |
250 | 255 | ||
251 | if ( bat2 ) { | 256 | if ( bat2 ) { |
252 | return QSize( QMAX( QMIN( 200, qApp->desktop()->width() ), | 257 | return QSize( QMAX( QMIN( 200, qApp->desktop()->width() ), |
253 | r.width() ), 2 * 10 + 80 + r.height() + r2.height() ); | 258 | r.width() ), 2 * 10 + 80 + r.height() + r2.height() ); |
254 | } | 259 | } |
255 | return QSize( QMAX( QMIN( 200, qApp->desktop()->width() ), | 260 | return QSize( QMAX( QMIN( 200, qApp->desktop()->width() ), |
256 | r.width() ), 2 * 10 + 40 + r.height() ); | 261 | r.width() ), 2 * 10 + 40 + r.height() ); |
257 | } | 262 | } |
diff --git a/core/applets/batteryapplet/batterystatus.h b/core/applets/batteryapplet/batterystatus.h index bb95ece..4da446d 100644 --- a/core/applets/batteryapplet/batterystatus.h +++ b/core/applets/batteryapplet/batterystatus.h | |||
@@ -1,64 +1,64 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef BATTERY_STATUS_H | 20 | #ifndef BATTERY_STATUS_H |
21 | #define BATTERY_STATUS_H | 21 | #define BATTERY_STATUS_H |
22 | 22 | ||
23 | #include <qframe.h> | 23 | #include <qframe.h> |
24 | 24 | ||
25 | class PowerStatus; | 25 | class PowerStatus; |
26 | 26 | ||
27 | class BatteryStatus : public QFrame | 27 | class BatteryStatus : public QFrame |
28 | { | 28 | { |
29 | Q_OBJECT | 29 | Q_OBJECT |
30 | public: | 30 | public: |
31 | BatteryStatus( const PowerStatus *s, QWidget *parent=0, WFlags f = 0 ); | 31 | BatteryStatus( const PowerStatus *s, QWidget *parent=0, WFlags f = 0 ); |
32 | ~BatteryStatus(); | 32 | ~BatteryStatus(); |
33 | 33 | void BatteryStatus::UpdateBatteryStatus(); | |
34 | void updatePercent( int ); | 34 | void updatePercent( int ); |
35 | QSize sizeHint() const; | 35 | QSize sizeHint() const; |
36 | protected: | 36 | protected: |
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 | 40 | ||
41 | private: | 41 | private: |
42 | QString statusText() const; | 42 | QString statusText() const; |
43 | QString statusTextIpaq() const; | 43 | QString statusTextIpaq() const; |
44 | const PowerStatus *ps; | 44 | const PowerStatus *ps; |
45 | int percent; | 45 | int percent; |
46 | int ipaqPercent; | 46 | int ipaqPercent; |
47 | int jackPercent; | 47 | int jackPercent; |
48 | int jackMinutes; | 48 | int jackMinutes; |
49 | QString perc1; | 49 | QString perc1; |
50 | QString sec1; | 50 | QString sec1; |
51 | QString perc2; | 51 | QString perc2; |
52 | QString sec2; | 52 | QString sec2; |
53 | QString ipaqStatus; | 53 | QString ipaqStatus; |
54 | QString jackStatus; | 54 | QString jackStatus; |
55 | QString ipaqChem; | 55 | QString ipaqChem; |
56 | QString jackChem; | 56 | QString jackChem; |
57 | bool bat2; | 57 | bool bat2; |
58 | bool bat2inserted; | 58 | bool bat2inserted; |
59 | int screenWidth; | 59 | int screenWidth; |
60 | int screenHeight; | 60 | int screenHeight; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | #endif | 63 | #endif |
64 | 64 | ||