-rw-r--r-- | core/applets/batteryapplet/battery.cpp | 8 | ||||
-rw-r--r-- | core/applets/batteryapplet/batterystatus.cpp | 75 |
2 files changed, 40 insertions, 43 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp index 3b64fb5..9a9ddf6 100644 --- a/core/applets/batteryapplet/battery.cpp +++ b/core/applets/batteryapplet/battery.cpp | |||
@@ -1,170 +1,170 @@ | |||
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 | #include <qpe/applnk.h> | 23 | #include <qpe/applnk.h> |
24 | #include <qpe/config.h> | 24 | #include <qpe/config.h> |
25 | #include <qpe/power.h> | 25 | #include <qpe/power.h> |
26 | #include <qpe/qpeapplication.h> | 26 | #include <qpe/qpeapplication.h> |
27 | 27 | ||
28 | #include <qpainter.h> | 28 | #include <qpainter.h> |
29 | #include <qtimer.h> | 29 | #include <qtimer.h> |
30 | 30 | ||
31 | 31 | ||
32 | BatteryMeter::BatteryMeter( QWidget *parent ) | 32 | BatteryMeter::BatteryMeter( QWidget *parent ) |
33 | : QWidget( parent ), charging(false) | 33 | : QWidget( parent ), charging(false) |
34 | { | 34 | { |
35 | ps = new PowerStatus; | 35 | ps = new PowerStatus; |
36 | startTimer( 10000 ); | 36 | startTimer( 10000 ); |
37 | 37 | ||
38 | setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); | 38 | setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); |
39 | setFixedHeight( AppLnk::smallIconSize() ); | 39 | setFixedHeight( AppLnk::smallIconSize() ); |
40 | 40 | ||
41 | chargeTimer = new QTimer( this ); | 41 | chargeTimer = new QTimer( this ); |
42 | connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); | 42 | connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); |
43 | timerEvent(0); | 43 | timerEvent(0); |
44 | QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); | 44 | QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); |
45 | Config c( "qpe" ); | 45 | Config c( "qpe" ); |
46 | c.setGroup( "Battery" ); | 46 | c.setGroup( "Battery" ); |
47 | style = c.readNumEntry( "Style", 0 ); | 47 | style = c.readNumEntry( "Style", 0 ); |
48 | } | 48 | } |
49 | 49 | ||
50 | BatteryMeter::~BatteryMeter() | 50 | BatteryMeter::~BatteryMeter() |
51 | { | 51 | { |
52 | delete ps; | 52 | delete ps; |
53 | } | 53 | } |
54 | 54 | ||
55 | QSize BatteryMeter::sizeHint() const | 55 | QSize BatteryMeter::sizeHint() const |
56 | { | 56 | { |
57 | return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); | 57 | return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); |
58 | } | 58 | } |
59 | 59 | ||
60 | void BatteryMeter::mousePressEvent( QMouseEvent* e ) | 60 | void BatteryMeter::mousePressEvent( QMouseEvent* e ) |
61 | { | 61 | { |
62 | if ( e->button() == RightButton ) | 62 | if ( e->button() == RightButton ) |
63 | { | 63 | { |
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 | { | 74 | { |
75 | if ( batteryView && batteryView->isVisible() ) { | 75 | if ( batteryView && batteryView->isVisible() ) { |
76 | delete (QWidget *) batteryView; | 76 | delete (QWidget *) batteryView; |
77 | } else { | 77 | } else { |
78 | if ( !batteryView ) batteryView = new BatteryStatus( ps ); | 78 | if ( !batteryView ) batteryView = new BatteryStatus( ps ); |
79 | QPEApplication::showWidget( batteryView ); | 79 | QPEApplication::showWidget( batteryView ); |
80 | batteryView->raise(); | 80 | batteryView->raise(); |
81 | batteryView->show(); | 81 | batteryView->show(); |
82 | } | 82 | } |
83 | } | 83 | } |
84 | 84 | ||
85 | void BatteryMeter::timerEvent( QTimerEvent * ) | 85 | void BatteryMeter::timerEvent( QTimerEvent * ) |
86 | { | 86 | { |
87 | PowerStatus prev = *ps; | 87 | PowerStatus prev = *ps; |
88 | 88 | ||
89 | *ps = PowerStatusManager::readStatus(); | 89 | *ps = PowerStatusManager::readStatus(); |
90 | 90 | ||
91 | if ( prev != *ps ) { | 91 | if ( prev != *ps ) { |
92 | percent = ps->batteryPercentRemaining(); | 92 | percent = ps->batteryPercentRemaining(); |
93 | if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) { | 93 | if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) { |
94 | percent = 0; | 94 | percent = 0; |
95 | charging = true; | 95 | charging = true; |
96 | chargeTimer->start( 500 ); | 96 | chargeTimer->start( 500 ); |
97 | } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { | 97 | } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { |
98 | charging = false; | 98 | charging = false; |
99 | chargeTimer->stop(); | 99 | chargeTimer->stop(); |
100 | if ( batteryView ) | 100 | if ( batteryView ) |
101 | batteryView->updatePercent( percent ); | 101 | batteryView->updatePercent( percent ); |
102 | } | 102 | } |
103 | repaint( style != 0 ); | 103 | repaint( style != 0 ); |
104 | if ( batteryView ) | 104 | if ( batteryView ) |
105 | batteryView->repaint(); | 105 | batteryView->repaint(); |
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | void BatteryMeter::chargeTimeout() | 109 | void BatteryMeter::chargeTimeout() |
110 | { | 110 | { |
111 | percent += 20; | 111 | percent += 20; |
112 | if ( percent > 100 ) | 112 | if ( percent > 100 ) |
113 | percent = 0; | 113 | percent = 0; |
114 | 114 | ||
115 | repaint(FALSE); | 115 | repaint(FALSE); |
116 | if ( batteryView ) | 116 | if ( batteryView ) |
117 | batteryView->updatePercent( percent ); | 117 | batteryView->updatePercent( percent ); |
118 | } | 118 | } |
119 | 119 | ||
120 | void BatteryMeter::paintEvent( QPaintEvent* ) | 120 | void BatteryMeter::paintEvent( QPaintEvent* ) |
121 | { | 121 | { |
122 | 122 | ||
123 | if ( style == 1 ) | 123 | if ( style == 1 ) |
124 | { | 124 | { |
125 | QPainter p(this); | 125 | QPainter p(this); |
126 | QFont f( "Fixed", AppLnk::smallIconSize()/2 ); | 126 | QFont f( "Fixed", AppLnk::smallIconSize()/2 ); |
127 | QFontMetrics fm( f ); | 127 | QFontMetrics fm( f ); |
128 | p.setFont( f ); | 128 | p.setFont( f ); |
129 | p.drawText( 0, height()/2, QString::number( percent ) ); | 129 | p.drawText( 0, height()/2, QString::number( percent ) ); |
130 | p.drawText( width()/4, height(), "%" ); | 130 | p.drawText( width()/4, height(), "%" ); |
131 | return; | 131 | return; |
132 | } | 132 | } |
133 | 133 | ||
134 | QPainter p(this); | 134 | QPainter p(this); |
135 | QColor color; | 135 | QColor color; |
136 | QColor g = gray.light( 160 ); | 136 | QColor g = gray.light( 160 ); |
137 | switch ( ps->acStatus() ) | 137 | switch ( ps->acStatus() ) |
138 | { | 138 | { |
139 | case PowerStatus::Offline: color = blue.light( 150 ); break; | 139 | case PowerStatus::Offline: color = blue.light( 150 ); break; |
140 | case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break; | 140 | case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break; |
141 | default: color = red.light( 160 ); | 141 | default: color = red.light( 160 ); |
142 | } | 142 | } |
143 | 143 | ||
144 | int w = height() / 2; | 144 | int w = height() / 2; |
145 | if ( !(w%2) ) w--; // should have an odd value to get a real middle line | 145 | if ( !(w%2) ) w--; // should have an odd value to get a real middle line |
146 | int h = height() - 4; | 146 | int h = height() - 4; |
147 | int pix = (percent * h) / 100; | 147 | int pix = (percent * h) / 100; |
148 | int y2 = height() -2; | 148 | int y2 = height() -2; |
149 | int y = y2 - pix; | 149 | int y = y2 - pix; |
150 | int x1 = (width() - w ) / 2; | 150 | int x1 = (width() - w ) / 2; |
151 | 151 | ||
152 | p.setPen(QColor(80,80,80)); | 152 | p.setPen(QColor(80,80,80)); |
153 | p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header | 153 | p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header |
154 | p.drawRect(x1,1,w,height()-1); // corpus | 154 | p.drawRect(x1,1,w,height()-1); // corpus |
155 | p.setBrush(color); | 155 | p.setBrush(color); |
156 | 156 | ||
157 | int extra = ((percent * h) % 100)/(100/4); | 157 | //int extra = ((percent * h) % 100)/(100/4); |
158 | 158 | ||
159 | int middle = w/2; | 159 | int middle = w/2; |
160 | for ( int i = 0; i < middle; i++ ) | 160 | for ( int i = 0; i < middle; i++ ) |
161 | { | 161 | { |
162 | p.setPen( gray.dark( 100+i*20 ) ); | 162 | p.setPen( gray.dark( 100+i*20 ) ); |
163 | p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); | 163 | p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); |
164 | p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); | 164 | p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); |
165 | p.setPen( color.dark( 100+i*20 ) ); | 165 | p.setPen( color.dark( 100+i*20 ) ); |
166 | p.drawLine( x1+middle-i, y, x1+middle-i, y2 ); | 166 | p.drawLine( x1+middle-i, y, x1+middle-i, y2 ); |
167 | p.drawLine( x1+middle+i, y, x1+middle+i, y2 ); | 167 | p.drawLine( x1+middle+i, y, x1+middle+i, y2 ); |
168 | } | 168 | } |
169 | } | 169 | } |
170 | 170 | ||
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp index 64e0499..86b20e8 100644 --- a/core/applets/batteryapplet/batterystatus.cpp +++ b/core/applets/batteryapplet/batterystatus.cpp | |||
@@ -1,255 +1,252 @@ | |||
1 | 1 | ||
2 | #include "batterystatus.h" | 2 | #include "batterystatus.h" |
3 | 3 | ||
4 | #include <qpe/power.h> | 4 | #include <qpe/power.h> |
5 | 5 | ||
6 | #include <opie/odevice.h> | 6 | #include <opie/odevice.h> |
7 | 7 | ||
8 | #include <qpainter.h> | 8 | #include <qpainter.h> |
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 <qlayout.h> | 12 | #include <qlayout.h> |
13 | #include <qtextstream.h> | 13 | #include <qtextstream.h> |
14 | #include <qapplication.h> | 14 | #include <qapplication.h> |
15 | #include <qmessagebox.h> | 15 | #include <qmessagebox.h> |
16 | 16 | ||
17 | using namespace Opie; | 17 | using namespace Opie; |
18 | 18 | ||
19 | BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) | 19 | BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) |
20 | : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) { | 20 | : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) { |
21 | setCaption( tr("Battery status") ); | 21 | setCaption( tr("Battery status") ); |
22 | setMinimumSize( 150, 200 ); | ||
23 | |||
22 | QPushButton *pb = new QPushButton( tr("Close"), this ); | 24 | QPushButton *pb = new QPushButton( tr("Close"), this ); |
23 | QVBoxLayout *layout = new QVBoxLayout ( this ); | 25 | QVBoxLayout *layout = new QVBoxLayout ( this ); |
24 | 26 | ||
25 | jackPercent = 0; | 27 | jackPercent = 0; |
26 | 28 | ||
27 | pb->setMaximumHeight(40); | 29 | pb->setMaximumSize( 120, 40 ); |
28 | pb->setMaximumWidth( 120 ); | ||
29 | 30 | ||
30 | pb->show(); | 31 | pb->show(); |
31 | 32 | ||
32 | layout->addStretch( 0 ); | 33 | layout->addStretch(); |
33 | layout->addWidget( pb ); | 34 | layout->addWidget( pb ); |
34 | 35 | ||
35 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { | 36 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { |
36 | getProcApmStatusIpaq(); | 37 | getProcApmStatusIpaq(); |
37 | } | 38 | } |
38 | connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) ); | 39 | connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) ); |
39 | percent = ps->batteryPercentRemaining(); | 40 | percent = ps->batteryPercentRemaining(); |
40 | show(); | 41 | show(); |
41 | } | 42 | } |
42 | 43 | ||
43 | BatteryStatus::~BatteryStatus() | 44 | BatteryStatus::~BatteryStatus() |
44 | { | 45 | { |
45 | } | 46 | } |
46 | 47 | ||
47 | /* | 48 | /* |
48 | * Make use of the advanced apm interface of the ipaq | 49 | * Make use of the advanced apm interface of the ipaq |
49 | */ | 50 | */ |
50 | bool BatteryStatus::getProcApmStatusIpaq() { | 51 | bool BatteryStatus::getProcApmStatusIpaq() { |
51 | 52 | ||
52 | bat2 = false; | 53 | bat2 = false; |
53 | 54 | ||
54 | QFile procApmIpaq("/proc/hal/battery"); | 55 | QFile procApmIpaq("/proc/hal/battery"); |
55 | 56 | ||
56 | if (procApmIpaq.open(IO_ReadOnly) ) { | 57 | if (procApmIpaq.open(IO_ReadOnly) ) { |
57 | QStringList list; | 58 | QStringList list; |
58 | // since it is /proc we _must_ use QTextStream | 59 | // since it is /proc we _must_ use QTextStream |
59 | QTextStream stream ( &procApmIpaq); | 60 | QTextStream stream ( &procApmIpaq); |
60 | QString streamIn; | 61 | QString streamIn; |
61 | streamIn = stream.read(); | 62 | streamIn = stream.read(); |
62 | list = QStringList::split("\n", streamIn); | 63 | list = QStringList::split("\n", streamIn); |
63 | 64 | ||
64 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { | 65 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { |
65 | // not nice, need a rewrite later | 66 | // not nice, need a rewrite later |
66 | if( (*line).startsWith(" Percentage") ){ | 67 | if( (*line).startsWith(" Percentage") ){ |
67 | if (bat2 == true) { | 68 | if (bat2 == true) { |
68 | perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); | 69 | perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); |
69 | } else { | 70 | } else { |
70 | perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); | 71 | perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); |
71 | } | 72 | } |
72 | }else if( (*line).startsWith(" Life") ){ | 73 | }else if( (*line).startsWith(" Life") ){ |
73 | if (bat2 == true) { | 74 | if (bat2 == true) { |
74 | sec2 = (*line).mid(((*line).find(':')+2), 5 ); | 75 | sec2 = (*line).mid(((*line).find(':')+2), 5 ); |
75 | } else { | 76 | } else { |
76 | sec1 = (*line).mid(((*line).find(':')+2), 5 ); | 77 | sec1 = (*line).mid(((*line).find(':')+2), 5 ); |
77 | } | 78 | } |
78 | }else if( (*line).startsWith("Battery #1") ){ | 79 | }else if( (*line).startsWith("Battery #1") ){ |
79 | bat2 = true; | 80 | bat2 = true; |
80 | }else if( (*line).startsWith(" Status") ){ | 81 | }else if( (*line).startsWith(" Status") ){ |
81 | if (bat2 == true) { | 82 | if (bat2 == true) { |
82 | jackStatus = (*line).mid((*line).find('(')+1., (*line).find(')')-(*line).find('(')-1); | 83 | jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); |
83 | } else { | 84 | } else { |
84 | ipaqStatus = (*line).mid((*line).find('(')+1., (*line).find(')')-(*line).find('(')-1); | 85 | ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); |
85 | } | 86 | } |
86 | }else if( (*line).startsWith(" Chemistry") ) { | 87 | }else if( (*line).startsWith(" Chemistry") ) { |
87 | if (bat2 == true) { | 88 | if (bat2 == true) { |
88 | jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); | 89 | jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); |
89 | } else { | 90 | } else { |
90 | ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); | 91 | ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); |
91 | } | 92 | } |
92 | } | 93 | } |
93 | } | 94 | } |
94 | } else { | 95 | } else { |
95 | QMessageBox::warning(this, tr("Failure"),tr("could not open file")); | 96 | QMessageBox::warning(this, tr("Failure"),tr("could not open file")); |
96 | } | 97 | } |
97 | 98 | ||
98 | procApmIpaq.close(); | 99 | procApmIpaq.close(); |
99 | 100 | ||
100 | jackPercent = perc2.toInt(); | 101 | jackPercent = perc2.toInt(); |
101 | ipaqPercent = perc1.toInt(); | 102 | ipaqPercent = perc1.toInt(); |
102 | 103 | ||
103 | if (perc2.isEmpty()) { | 104 | if (perc2.isEmpty()) { |
104 | perc2 = tr("no data"); | 105 | perc2 = tr("no data"); |
105 | } else { | 106 | } else { |
106 | perc2 += " %"; | 107 | perc2 += " %"; |
107 | } | 108 | } |
108 | 109 | ||
109 | 110 | ||
110 | if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { | 111 | if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { |
111 | sec2 = tr("no data"); | 112 | sec2 = tr("no data"); |
112 | } else { | 113 | } else { |
113 | sec2 += " min"; | 114 | sec2 += " min"; |
114 | } | 115 | } |
115 | 116 | ||
116 | jackStatus == (" ( " + jackStatus + " )"); | 117 | jackStatus == (" ( " + jackStatus + " )"); |
117 | 118 | ||
118 | return true; | 119 | return true; |
119 | } | 120 | } |
120 | 121 | ||
121 | 122 | ||
122 | void BatteryStatus::updatePercent( int pc ) { | 123 | void BatteryStatus::updatePercent( int pc ) { |
123 | percent = pc; | 124 | percent = pc; |
124 | repaint(FALSE); | 125 | repaint(FALSE); |
125 | } | 126 | } |
126 | 127 | ||
127 | void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { | 128 | void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { |
128 | int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; | 129 | int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; |
129 | topgrad.hsv( &h1, &s1, &v1 ); | 130 | topgrad.hsv( &h1, &s1, &v1 ); |
130 | botgrad.hsv( &h2, &s2, &v2 ); | 131 | botgrad.hsv( &h2, &s2, &v2 ); |
131 | for ( int j = 0; j < hy-2; j++ ) { | 132 | for ( int j = 0; j < hy-2; j++ ) { |
132 | p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), | 133 | p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), |
133 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); | 134 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); |
134 | p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); | 135 | p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); |
135 | } | 136 | } |
136 | for ( int j = 0; j < hh; j++ ) { | 137 | for ( int j = 0; j < hh; j++ ) { |
137 | p->setPen( highlight ); | 138 | p->setPen( highlight ); |
138 | p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); | 139 | p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); |
139 | } | 140 | } |
140 | for ( int j = 0; j < ng-hy-hh; j++ ) { | 141 | for ( int j = 0; j < ng-hy-hh; j++ ) { |
141 | p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), | 142 | p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), |
142 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); | 143 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); |
143 | p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); | 144 | p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); |
144 | } | 145 | } |
145 | } | 146 | } |
146 | 147 | ||
147 | void BatteryStatus::paintEvent( QPaintEvent * ) { | 148 | void BatteryStatus::paintEvent( QPaintEvent * ) { |
148 | 149 | ||
149 | |||
150 | int screenWidth = qApp->desktop()->width(); | ||
151 | int screenHeight = qApp->desktop()->height(); | ||
152 | |||
153 | QPainter p(this); | 150 | QPainter p(this); |
154 | QString text; | 151 | QString text; |
155 | if ( ps->batteryStatus() == PowerStatus::Charging ) { | 152 | if ( ps->batteryStatus() == PowerStatus::Charging ) { |
156 | if (bat2) { | 153 | if (bat2) { |
157 | text = tr("Charging both devices"); | 154 | text = tr("Charging both devices"); |
158 | } else { | 155 | } else { |
159 | text = tr("Charging"); | 156 | text = tr("Charging"); |
160 | } | 157 | } |
161 | } else if ( ps->batteryPercentAccurate() ) { | 158 | } else if ( ps->batteryPercentAccurate() ) { |
162 | text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent ); | 159 | text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent ); |
163 | } else { | 160 | } else { |
164 | text = tr("Battery status: "); | 161 | text = tr("Battery status: "); |
165 | switch ( ps->batteryStatus() ) { | 162 | switch ( ps->batteryStatus() ) { |
166 | case PowerStatus::High: | 163 | case PowerStatus::High: |
167 | text += tr("Good"); | 164 | text += tr("Good"); |
168 | break; | 165 | break; |
169 | case PowerStatus::Low: | 166 | case PowerStatus::Low: |
170 | text += tr("Low"); | 167 | text += tr("Low"); |
171 | break; | 168 | break; |
172 | case PowerStatus::VeryLow: | 169 | case PowerStatus::VeryLow: |
173 | text += tr("Very Low"); | 170 | text += tr("Very Low"); |
174 | break; | 171 | break; |
175 | case PowerStatus::Critical: | 172 | case PowerStatus::Critical: |
176 | text += tr("Critical"); | 173 | text += tr("Critical"); |
177 | break; | 174 | break; |
178 | default: // NotPresent, etc. | 175 | default: // NotPresent, etc. |
179 | text += tr("Unknown"); | 176 | text += tr("Unknown"); |
180 | } | 177 | } |
181 | } | 178 | } |
182 | p.drawText( 10, 90, text ); | 179 | p.drawText( 10, 90, text ); |
183 | 180 | ||
184 | if ( ps->acStatus() == PowerStatus::Backup ) | 181 | if ( ps->acStatus() == PowerStatus::Backup ) |
185 | p.drawText( 10, 110, tr("On backup power") ); | 182 | p.drawText( 10, 110, tr("On backup power") ); |
186 | else if ( ps->acStatus() == PowerStatus::Online ) | 183 | else if ( ps->acStatus() == PowerStatus::Online ) |
187 | p.drawText( 10, 110, tr("Power on-line") ); | 184 | p.drawText( 10, 110, tr("Power on-line") ); |
188 | else if ( ps->acStatus() == PowerStatus::Offline ) | 185 | else if ( ps->acStatus() == PowerStatus::Offline ) |
189 | p.drawText( 10, 110, tr("External power disconnected") ); | 186 | p.drawText( 10, 110, tr("External power disconnected") ); |
190 | 187 | ||
191 | if ( ps->batteryTimeRemaining() >= 0 ) { | 188 | if ( ps->batteryTimeRemaining() >= 0 ) { |
192 | text.sprintf( tr("Battery time remaining") + ": %im %02is", | 189 | text.sprintf( tr("Battery time remaining") + ": %im %02is", |
193 | ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); | 190 | ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); |
194 | p.drawText( 10, 130, text ); | 191 | p.drawText( 10, 130, text ); |
195 | } | 192 | } |
196 | 193 | ||
197 | QColor c; | 194 | QColor c; |
198 | QColor darkc; | 195 | QColor darkc; |
199 | QColor lightc; | 196 | QColor lightc; |
200 | if ( ps->acStatus() == PowerStatus::Offline ) { | 197 | if ( ps->acStatus() == PowerStatus::Offline ) { |
201 | c = blue.light(120); | 198 | c = blue.light(120); |
202 | darkc = c.dark(280); | 199 | darkc = c.dark(280); |
203 | lightc = c.light(145); | 200 | lightc = c.light(145); |
204 | } else if ( ps->acStatus() == PowerStatus::Online ) { | 201 | } else if ( ps->acStatus() == PowerStatus::Online ) { |
205 | c = green.dark(130); | 202 | c = green.dark(130); |
206 | darkc = c.dark(200); | 203 | darkc = c.dark(200); |
207 | lightc = c.light(220); | 204 | lightc = c.light(220); |
208 | } else { | 205 | } else { |
209 | c = red; | 206 | c = red; |
210 | darkc = c.dark(280); | 207 | darkc = c.dark(280); |
211 | lightc = c.light(140); | 208 | lightc = c.light(140); |
212 | } | 209 | } |
213 | if ( percent < 0 ) | 210 | if ( percent < 0 ) |
214 | return; | 211 | return; |
215 | 212 | ||
216 | int rightEnd1 = screenWidth - 47; | 213 | int rightEnd1 = width() - 47; |
217 | int rightEnd2 = screenWidth - 35; | 214 | int rightEnd2 = width() - 35; |
218 | int percent2 = ( percent / 100.0 ) * rightEnd1 ; | 215 | int percent2 = ( percent / 100 ) * rightEnd1 ; |
219 | p.setPen( black ); | 216 | p.setPen( black ); |
220 | qDrawShadePanel( &p, 9, 30, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL); | 217 | qDrawShadePanel( &p, 9, 30, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL); |
221 | qDrawShadePanel( &p, rightEnd2, 37, 12, 24, colorGroup(), TRUE, 1, NULL); | 218 | qDrawShadePanel( &p, rightEnd2, 37, 12, 24, colorGroup(), TRUE, 1, NULL); |
222 | drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 ); | 219 | drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 ); |
223 | drawSegment( &p, QRect( 11 + percent2, 30, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 ); | 220 | drawSegment( &p, QRect( 11 + percent2, 30, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 ); |
224 | drawSegment( &p, QRect( rightEnd2, 37, 10, 25 ), white.light(80), black, white.light(90), 2 ); | 221 | drawSegment( &p, QRect( rightEnd2, 37, 10, 25 ), white.light(80), black, white.light(90), 2 ); |
225 | p.setPen( black); | 222 | p.setPen( black); |
226 | 223 | ||
227 | 224 | ||
228 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { | 225 | if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { |
229 | 226 | ||
230 | p.drawText(15, 50, tr ("Ipaq ") + ipaqChem); | 227 | p.drawText(15, 50, tr ("Ipaq ") + ipaqChem); |
231 | 228 | ||
232 | QString jacketMsg; | 229 | QString jacketMsg; |
233 | if (bat2) { | 230 | if (bat2) { |
234 | p.setPen(black); | 231 | p.setPen(black); |
235 | p.drawText(10,220, tr("Percentage battery remaining: ") + perc2 + " " + jackStatus); | 232 | p.drawText(10,220, tr("Percentage battery remaining: ") + perc2 + " " + jackStatus); |
236 | p.drawText(10,240, tr("Battery time remaining: ") + sec2); | 233 | p.drawText(10,240, tr("Battery time remaining: ") + sec2); |
237 | jacketMsg = tr("Jacket ") + jackChem; | 234 | jacketMsg = tr("Jacket ") + jackChem; |
238 | } else { | 235 | } else { |
239 | jackPercent = 0; | 236 | jackPercent = 0; |
240 | jacketMsg = tr("No jacket with battery inserted"); | 237 | jacketMsg = tr("No jacket with battery inserted"); |
241 | } | 238 | } |
242 | 239 | ||
243 | int jackPerc = ( jackPercent / 100.0 ) * ( screenWidth - 47 ) ; | 240 | int jackPerc = ( jackPercent / 100 ) * ( width() - 47 ) ; |
244 | 241 | ||
245 | qDrawShadePanel( &p, 9, 160, rightEnd1, 39, colorGroup(), TRUE, 1, NULL); | 242 | qDrawShadePanel( &p, 9, 160, rightEnd1, 39, colorGroup(), TRUE, 1, NULL); |
246 | qDrawShadePanel( &p, rightEnd2, 167, 12, 24, colorGroup(), TRUE, 1, NULL); | 243 | qDrawShadePanel( &p, rightEnd2, 167, 12, 24, colorGroup(), TRUE, 1, NULL); |
247 | drawSegment( &p, QRect( 10, 160, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 ); | 244 | drawSegment( &p, QRect( 10, 160, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 ); |
248 | drawSegment( &p, QRect( 11 + jackPerc, 160, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 ); | 245 | drawSegment( &p, QRect( 11 + jackPerc, 160, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 ); |
249 | drawSegment( &p, QRect( rightEnd2, 167, 10, 25 ), white.light(80), black, white.light(90), 2 ); | 246 | drawSegment( &p, QRect( rightEnd2, 167, 10, 25 ), white.light(80), black, white.light(90), 2 ); |
250 | p.setPen( black ); | 247 | p.setPen( black ); |
251 | p.drawText(15, 180, jacketMsg); | 248 | p.drawText(15, 180, jacketMsg); |
252 | } | 249 | } |
253 | 250 | ||
254 | } | 251 | } |
255 | 252 | ||