summaryrefslogtreecommitdiff
path: root/core/applets
Unidiff
Diffstat (limited to 'core/applets') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/battery.cpp135
-rw-r--r--core/applets/batteryapplet/battery.h14
2 files changed, 82 insertions, 67 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp
index f3a95ed..eee3ed3 100644
--- a/core/applets/batteryapplet/battery.cpp
+++ b/core/applets/batteryapplet/battery.cpp
@@ -21,6 +21,8 @@
21#include "batterystatus.h" 21#include "batterystatus.h"
22 22
23#include <qpe/power.h>
24#include <qpe/applnk.h> 23#include <qpe/applnk.h>
24#include <qpe/config.h>
25#include <qpe/power.h>
26#include <qpe/qpeapplication.h>
25 27
26#include <qpainter.h> 28#include <qpainter.h>
@@ -33,8 +35,12 @@ BatteryMeter::BatteryMeter( QWidget *parent )
33 ps = new PowerStatus; 35 ps = new PowerStatus;
34 startTimer( 10000 ); 36 startTimer( 10000 );
35 setFixedHeight( AppLnk::smallIconSize() ); 37 setFixedHeight( AppLnk::smallIconSize() );
36 chargeTimer = new QTimer( this ); 38 chargeTimer = new QTimer( this );
37 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); 39 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) );
38 timerEvent(0); 40 timerEvent(0);
41 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
42 Config c( "qpe" );
43 c.setGroup( "Battery" );
44 style = c.readNumEntry( "Style", 0 );
39} 45}
40 46
@@ -49,14 +55,26 @@ QSize BatteryMeter::sizeHint() const
49} 55}
50 56
51void BatteryMeter::mouseReleaseEvent( QMouseEvent *) 57void BatteryMeter::mousePressEvent( QMouseEvent* e )
58{
59 if ( e->button() == RightButton )
60 {
61 style = 1-style;
62 Config c( "qpe" );
63 c.setGroup( "Battery" );
64 c.writeEntry( "Style", style );
65 repaint();
66 }
67 QWidget::mousePressEvent( e );
68}
69
70void BatteryMeter::mouseReleaseEvent( QMouseEvent* e)
52{ 71{
53 if ( batteryView && batteryView->isVisible() ) { 72 if ( batteryView && batteryView->isVisible() ) {
54 delete (QWidget *) batteryView; 73 delete (QWidget *) batteryView;
55 } else { 74 } else {
56 if ( !batteryView ) 75 if ( !batteryView ) batteryView = new BatteryStatus( ps );
57 batteryView = new BatteryStatus( ps ); 76 batteryView->showMaximized();
58 batteryView->showMaximized(); 77 batteryView->raise();
59 batteryView->raise(); 78 batteryView->show();
60 batteryView->show();
61 } 79 }
62} 80}
@@ -69,18 +87,18 @@ void BatteryMeter::timerEvent( QTimerEvent * )
69 87
70 if ( prev != *ps ) { 88 if ( prev != *ps ) {
71 percent = ps->batteryPercentRemaining(); 89 percent = ps->batteryPercentRemaining();
72 if ( !charging && ps->batteryStatus() == PowerStatus::Charging && percent < 0 ) { 90 if ( !charging && ps->batteryStatus() == PowerStatus::Charging && percent < 0 ) {
73 percent = 0; 91 percent = 0;
74 charging = true; 92 charging = true;
75 chargeTimer->start( 500 ); 93 chargeTimer->start( 500 );
76 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { 94 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) {
77 charging = false; 95 charging = false;
78 chargeTimer->stop(); 96 chargeTimer->stop();
79 if ( batteryView ) 97 if ( batteryView )
80 batteryView->updatePercent( percent ); 98 batteryView->updatePercent( percent );
81 } 99 }
82 repaint(FALSE); 100 repaint(FALSE);
83 if ( batteryView ) 101 if ( batteryView )
84 batteryView->repaint(); 102 batteryView->repaint();
85 } 103 }
86} 104}
@@ -99,24 +117,27 @@ void BatteryMeter::chargeTimeout()
99void BatteryMeter::paintEvent( QPaintEvent* ) 117void BatteryMeter::paintEvent( QPaintEvent* )
100{ 118{
101 QPainter p(this); 119 if ( style == 1 )
120 {
121 QPainter p(this);
122 QFont f( "Fixed", AppLnk::smallIconSize()/2 );
123 QFontMetrics fm( f );
124 p.setFont( f );
125 p.drawText( 0, AppLnk::smallIconSize()/2, QString::number( percent ) );
126 p.drawText( AppLnk::smallIconSize()/4, AppLnk::smallIconSize(), "%" );
127 return;
128 }
102 129
103 QColor c; 130 QPainter p(this);
104 QColor darkc; 131 QColor color;
105 QColor lightc; 132 QColor g = gray.light( 160 );
106 if ( ps->acStatus() == PowerStatus::Offline ) { 133 switch ( ps->acStatus() )
107 c = blue.light(120); 134 {
108 darkc = c.dark(120); 135 case PowerStatus::Offline: color = blue.light( 150 ); break;
109 lightc = c.light(140); 136 case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break;
110 } else if ( ps->acStatus() == PowerStatus::Online ) { 137 default: color = red.light( 160 );
111 c = green.dark(130);
112 darkc = c.dark(120);
113 lightc = c.light(180);
114 } else {
115 c = red;
116 darkc = c.dark(120);
117 lightc = c.light(160);
118 } 138 }
119 139
120 int w = height() / 2 ; 140 int w = height() / 2;
141 if ( !(w%2) ) w--; // should have an odd value to get a real middle line
121 int h = height() - 4; 142 int h = height() - 4;
122 int pix = (percent * h) / 100; 143 int pix = (percent * h) / 100;
@@ -126,28 +147,20 @@ void BatteryMeter::paintEvent( QPaintEvent* )
126 147
127 p.setPen(QColor(80,80,80)); 148 p.setPen(QColor(80,80,80));
128 p.drawLine(x1+w/4,0,x1+w/4+w/2,0); 149 p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header
129 p.drawRect(x1,1,w,height()-1); 150 p.drawRect(x1,1,w,height()-1); // corpus
130 p.setBrush(c); 151 p.setBrush(color);
131 152
132 int extra = ((percent * h) % 100)/(100/4); 153 int extra = ((percent * h) % 100)/(100/4);
133 154
134#define Y(i) ((i<=extra)?y-1:y) 155 int middle = w/2;
135#define DRAWUPPER(i) if ( Y(i) >= 2 ) p.drawLine(i+x1,2,i+x1,Y(i)); 156 for ( int i = 0; i < middle; i++ )
136 p.setPen( gray ); 157 {
137 DRAWUPPER(1); 158 p.setPen( gray.dark( 100+i*20 ) );
138 DRAWUPPER(3); 159 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 );
139 p.setPen( gray.light(130) ); 160 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 );
140 DRAWUPPER(2); 161 p.setPen( color.dark( 100+i*20 ) );
141 p.setPen( gray.dark(120) ); 162 p.drawLine( x1+middle-i, y, x1+middle-i, y2 );
142 DRAWUPPER(4); 163 p.drawLine( x1+middle+i, y, x1+middle+i, y2 );
143 164 }
144#define DRAW(i) { if ( Y(i) < y2 ) p.drawLine(i+x1,Y(i)+1, i+x1,y2); }
145 p.setPen( c );
146 DRAW(1);
147 DRAW(3);
148 p.setPen( lightc );
149 DRAW(2);
150 p.setPen(darkc);
151 DRAW(4);
152} 165}
153 166
diff --git a/core/applets/batteryapplet/battery.h b/core/applets/batteryapplet/battery.h
index d4807b0..c2d1216 100644
--- a/core/applets/batteryapplet/battery.h
+++ b/core/applets/batteryapplet/battery.h
@@ -31,5 +31,5 @@ class BatteryMeter : public QWidget
31{ 31{
32 Q_OBJECT 32 Q_OBJECT
33public: 33 public:
34 BatteryMeter( QWidget *parent = 0 ); 34 BatteryMeter( QWidget *parent = 0 );
35 ~BatteryMeter(); 35 ~BatteryMeter();
@@ -37,13 +37,14 @@ public:
37 QSize sizeHint() const; 37 QSize sizeHint() const;
38 38
39protected: 39 protected:
40 void timerEvent( QTimerEvent * ); 40 void timerEvent( QTimerEvent* );
41 void paintEvent( QPaintEvent* ); 41 void paintEvent( QPaintEvent* );
42 void mouseReleaseEvent( QMouseEvent * ); 42 void mousePressEvent( QMouseEvent* );
43 void mouseReleaseEvent( QMouseEvent* );
43 44
44protected slots: 45 protected slots:
45 void chargeTimeout(); 46 void chargeTimeout();
46 47
47protected: 48 protected:
48 QGuardedPtr<BatteryStatus> batteryView; 49 QGuardedPtr<BatteryStatus> batteryView;
49 PowerStatus *ps; 50 PowerStatus *ps;
@@ -51,4 +52,5 @@ protected:
51 int percent; 52 int percent;
52 bool charging; 53 bool charging;
54 int style;
53}; 55};
54 56