summaryrefslogtreecommitdiff
path: root/core/applets/batteryapplet/battery.cpp
Unidiff
Diffstat (limited to 'core/applets/batteryapplet/battery.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/applets/batteryapplet/battery.cpp72
1 files changed, 38 insertions, 34 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp
index 98b61b5..0d3d190 100644
--- a/core/applets/batteryapplet/battery.cpp
+++ b/core/applets/batteryapplet/battery.cpp
@@ -36,6 +36,5 @@
36using namespace Opie::Ui; 36using namespace Opie::Ui;
37BatteryMeter::BatteryMeter( QWidget *parent ) 37BatteryMeter::BatteryMeter( QWidget *parent )
38 : QWidget( parent ), charging(false) 38: QWidget( parent ), charging(false) {
39{
40 ps = new PowerStatus; 39 ps = new PowerStatus;
41 startTimer( 10000 ); 40 startTimer( 10000 );
@@ -53,18 +52,14 @@ BatteryMeter::BatteryMeter( QWidget *parent )
53} 52}
54 53
55BatteryMeter::~BatteryMeter() 54BatteryMeter::~BatteryMeter() {
56{
57 delete ps; 55 delete ps;
58} 56}
59 57
60QSize BatteryMeter::sizeHint() const 58QSize BatteryMeter::sizeHint() const {
61{
62 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); 59 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() );
63} 60}
64 61
65void BatteryMeter::mousePressEvent( QMouseEvent* e ) 62void BatteryMeter::mousePressEvent( QMouseEvent* e ) {
66{ 63 if ( e->button() == RightButton ) {
67 if ( e->button() == RightButton )
68 {
69 style = 1-style; 64 style = 1-style;
70 Config c( "qpe" ); 65 Config c( "qpe" );
@@ -76,18 +71,27 @@ void BatteryMeter::mousePressEvent( QMouseEvent* e )
76} 71}
77 72
78void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) 73void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) {
79{
80 if ( batteryView && batteryView->isVisible() ) { 74 if ( batteryView && batteryView->isVisible() ) {
81 delete (QWidget *) batteryView; 75 batteryView->hide();
82 } else { 76 } else {
83 if ( !batteryView ) batteryView = new BatteryStatus( ps ); 77 if ( !batteryView ) {
84 QPEApplication::showWidget( batteryView ); 78 batteryView = new BatteryStatus( ps, 0, WStyle_StaysOnTop | WType_Popup );
79 batteryView->setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
80 }
81
82 QRect r(batteryView->pos(),batteryView->sizeHint());
83 QPoint curPos = this->mapToGlobal ( rect().topLeft() );
84
85 int lp = qApp->desktop()->width() - batteryView->sizeHint().width();
86 r.moveTopLeft( QPoint(lp, curPos.y()-batteryView->sizeHint().height()-1) );
87 batteryView->setGeometry(r);
88
85 batteryView->raise(); 89 batteryView->raise();
86 batteryView->showMaximized(); 90 batteryView->show();
87 } 91 }
88} 92}
89 93
90void BatteryMeter::timerEvent( QTimerEvent * ) 94
91{ 95void BatteryMeter::timerEvent( QTimerEvent * ) {
92 PowerStatus prev = *ps; 96 PowerStatus prev = *ps;
93 97
@@ -112,6 +116,5 @@ void BatteryMeter::timerEvent( QTimerEvent * )
112} 116}
113 117
114void BatteryMeter::chargeTimeout() 118void BatteryMeter::chargeTimeout() {
115{
116 percent += 20; 119 percent += 20;
117 if ( percent > 100 ) 120 if ( percent > 100 )
@@ -123,9 +126,7 @@ void BatteryMeter::chargeTimeout()
123} 126}
124 127
125void BatteryMeter::paintEvent( QPaintEvent* ) 128void BatteryMeter::paintEvent( QPaintEvent* ) {
126{
127 129
128 if ( style == 1 ) 130 if ( style == 1 ) {
129 {
130 QPainter p(this); 131 QPainter p(this);
131 QFont f( "Fixed", AppLnk::smallIconSize()/2 ); 132 QFont f( "Fixed", AppLnk::smallIconSize()/2 );
@@ -140,13 +141,18 @@ void BatteryMeter::paintEvent( QPaintEvent* )
140 QColor color; 141 QColor color;
141 QColor g = gray.light( 160 ); 142 QColor g = gray.light( 160 );
142 switch ( ps->acStatus() ) 143 switch ( ps->acStatus() ) {
143 { 144 case PowerStatus::Offline:
144 case PowerStatus::Offline: color = blue.light( 150 ); break; 145 color = blue.light( 150 );
145 case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break; 146 break;
146 default: color = red.light( 160 ); 147 case PowerStatus::Online:
148 color = green.dark( 130 ).light( 180 );
149 break;
150 default:
151 color = red.light( 160 );
147 } 152 }
148 153
149 int w = height() / 2; 154 int w = height() / 2;
150 if ( !(w%2) ) w--; // should have an odd value to get a real middle line 155 if ( !(w%2) )
156 w--; // should have an odd value to get a real middle line
151 int h = height() - 4; 157 int h = height() - 4;
152 int pix = (percent * h) / 100; 158 int pix = (percent * h) / 100;
@@ -163,6 +169,5 @@ void BatteryMeter::paintEvent( QPaintEvent* )
163 169
164 int middle = w/2; 170 int middle = w/2;
165 for ( int i = 0; i < middle; i++ ) 171 for ( int i = 0; i < middle; i++ ) {
166 {
167 p.setPen( gray.dark( 100+i*20 ) ); 172 p.setPen( gray.dark( 100+i*20 ) );
168 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); 173 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 );
@@ -174,6 +179,5 @@ void BatteryMeter::paintEvent( QPaintEvent* )
174} 179}
175 180
176int BatteryMeter::position() 181int BatteryMeter::position() {
177{
178 return 8; 182 return 8;
179} 183}