summaryrefslogtreecommitdiff
path: root/core/applets/batteryapplet/battery.cpp
Unidiff
Diffstat (limited to 'core/applets/batteryapplet/battery.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/battery.cpp104
1 files changed, 54 insertions, 50 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
@@ -37,4 +37,3 @@ using 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;
@@ -42,3 +41,3 @@ BatteryMeter::BatteryMeter( QWidget *parent )
42 41
43 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); 42 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) );
44 setFixedHeight( AppLnk::smallIconSize() ); 43 setFixedHeight( AppLnk::smallIconSize() );
@@ -54,4 +53,3 @@ BatteryMeter::BatteryMeter( QWidget *parent )
54 53
55BatteryMeter::~BatteryMeter() 54BatteryMeter::~BatteryMeter() {
56{
57 delete ps; 55 delete ps;
@@ -59,4 +57,3 @@ BatteryMeter::~BatteryMeter()
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() );
@@ -64,6 +61,4 @@ QSize BatteryMeter::sizeHint() const
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;
@@ -77,11 +72,20 @@ void BatteryMeter::mousePressEvent( QMouseEvent* e )
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 }
@@ -89,4 +93,4 @@ void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ )
89 93
90void BatteryMeter::timerEvent( QTimerEvent * ) 94
91{ 95void BatteryMeter::timerEvent( QTimerEvent * ) {
92 PowerStatus prev = *ps; 96 PowerStatus prev = *ps;
@@ -96,16 +100,16 @@ void BatteryMeter::timerEvent( QTimerEvent * )
96 if ( prev != *ps ) { 100 if ( prev != *ps ) {
97 percent = ps->batteryPercentRemaining(); 101 percent = ps->batteryPercentRemaining();
98 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) { 102 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) {
99 percent = 0; 103 percent = 0;
100 charging = true; 104 charging = true;
101 chargeTimer->start( 500 ); 105 chargeTimer->start( 500 );
102 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { 106 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) {
103 charging = false; 107 charging = false;
104 chargeTimer->stop(); 108 chargeTimer->stop();
109 if ( batteryView )
110 batteryView->updatePercent( percent );
111 }
112 repaint( style != 0 );
105 if ( batteryView ) 113 if ( batteryView )
106 batteryView->updatePercent( percent ); 114 batteryView->repaint();
107 }
108 repaint( style != 0 );
109 if ( batteryView )
110 batteryView->repaint();
111 } 115 }
@@ -113,7 +117,6 @@ void BatteryMeter::timerEvent( QTimerEvent * )
113 117
114void BatteryMeter::chargeTimeout() 118void BatteryMeter::chargeTimeout() {
115{
116 percent += 20; 119 percent += 20;
117 if ( percent > 100 ) 120 if ( percent > 100 )
118 percent = 0; 121 percent = 0;
119 122
@@ -121,10 +124,8 @@ void BatteryMeter::chargeTimeout()
121 if ( batteryView ) 124 if ( batteryView )
122 batteryView->updatePercent( percent ); 125 batteryView->updatePercent( percent );
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);
@@ -141,7 +142,11 @@ void BatteryMeter::paintEvent( QPaintEvent* )
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 }
@@ -149,3 +154,4 @@ void BatteryMeter::paintEvent( QPaintEvent* )
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;
@@ -164,4 +170,3 @@ void BatteryMeter::paintEvent( QPaintEvent* )
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 ) );
@@ -175,4 +180,3 @@ void BatteryMeter::paintEvent( QPaintEvent* )
175 180
176int BatteryMeter::position() 181int BatteryMeter::position() {
177{
178 return 8; 182 return 8;