-rw-r--r-- | core/applets/batteryapplet/battery.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp index 3d254fc..3b329c6 100644 --- a/core/applets/batteryapplet/battery.cpp +++ b/core/applets/batteryapplet/battery.cpp | |||
@@ -1,125 +1,125 @@ | |||
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/power.h> | 23 | #include <qpe/power.h> |
24 | 24 | ||
25 | #include <qpainter.h> | 25 | #include <qpainter.h> |
26 | #include <qtimer.h> | 26 | #include <qtimer.h> |
27 | 27 | ||
28 | 28 | ||
29 | BatteryMeter::BatteryMeter( QWidget *parent = 0 ) | 29 | BatteryMeter::BatteryMeter( QWidget *parent ) |
30 | : QWidget( parent ), charging(false) | 30 | : QWidget( parent ), charging(false) |
31 | { | 31 | { |
32 | ps = new PowerStatus; | 32 | ps = new PowerStatus; |
33 | startTimer( 10000 ); | 33 | startTimer( 10000 ); |
34 | setFixedHeight(12); | 34 | setFixedHeight(12); |
35 | chargeTimer = new QTimer( this ); | 35 | chargeTimer = new QTimer( this ); |
36 | connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); | 36 | connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); |
37 | timerEvent(0); | 37 | timerEvent(0); |
38 | } | 38 | } |
39 | 39 | ||
40 | BatteryMeter::~BatteryMeter() | 40 | BatteryMeter::~BatteryMeter() |
41 | { | 41 | { |
42 | delete ps; | 42 | delete ps; |
43 | } | 43 | } |
44 | 44 | ||
45 | QSize BatteryMeter::sizeHint() const | 45 | QSize BatteryMeter::sizeHint() const |
46 | { | 46 | { |
47 | return QSize(10,12); | 47 | return QSize(10,12); |
48 | } | 48 | } |
49 | 49 | ||
50 | void BatteryMeter::mouseReleaseEvent( QMouseEvent *) | 50 | void BatteryMeter::mouseReleaseEvent( QMouseEvent *) |
51 | { | 51 | { |
52 | if ( batteryView && batteryView->isVisible() ) { | 52 | if ( batteryView && batteryView->isVisible() ) { |
53 | delete (QWidget *) batteryView; | 53 | delete (QWidget *) batteryView; |
54 | } else { | 54 | } else { |
55 | if ( !batteryView ) | 55 | if ( !batteryView ) |
56 | batteryView = new BatteryStatus( ps ); | 56 | batteryView = new BatteryStatus( ps ); |
57 | batteryView->showMaximized(); | 57 | batteryView->showMaximized(); |
58 | batteryView->raise(); | 58 | batteryView->raise(); |
59 | batteryView->show(); | 59 | batteryView->show(); |
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
63 | void BatteryMeter::timerEvent( QTimerEvent * ) | 63 | void BatteryMeter::timerEvent( QTimerEvent * ) |
64 | { | 64 | { |
65 | PowerStatus prev = *ps; | 65 | PowerStatus prev = *ps; |
66 | 66 | ||
67 | *ps = PowerStatusManager::readStatus(); | 67 | *ps = PowerStatusManager::readStatus(); |
68 | 68 | ||
69 | if ( prev != *ps ) { | 69 | if ( prev != *ps ) { |
70 | percent = ps->batteryPercentRemaining(); | 70 | percent = ps->batteryPercentRemaining(); |
71 | if ( !charging && ps->batteryStatus() == PowerStatus::Charging && percent < 0 ) { | 71 | if ( !charging && ps->batteryStatus() == PowerStatus::Charging && percent < 0 ) { |
72 | percent = 0; | 72 | percent = 0; |
73 | charging = true; | 73 | charging = true; |
74 | chargeTimer->start( 500 ); | 74 | chargeTimer->start( 500 ); |
75 | } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { | 75 | } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { |
76 | charging = false; | 76 | charging = false; |
77 | chargeTimer->stop(); | 77 | chargeTimer->stop(); |
78 | if ( batteryView ) | 78 | if ( batteryView ) |
79 | batteryView->updatePercent( percent ); | 79 | batteryView->updatePercent( percent ); |
80 | } | 80 | } |
81 | repaint(FALSE); | 81 | repaint(FALSE); |
82 | if ( batteryView ) | 82 | if ( batteryView ) |
83 | batteryView->repaint(); | 83 | batteryView->repaint(); |
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | void BatteryMeter::chargeTimeout() | 87 | void BatteryMeter::chargeTimeout() |
88 | { | 88 | { |
89 | percent += 20; | 89 | percent += 20; |
90 | if ( percent > 100 ) | 90 | if ( percent > 100 ) |
91 | percent = 0; | 91 | percent = 0; |
92 | 92 | ||
93 | repaint(FALSE); | 93 | repaint(FALSE); |
94 | if ( batteryView ) | 94 | if ( batteryView ) |
95 | batteryView->updatePercent( percent ); | 95 | batteryView->updatePercent( percent ); |
96 | } | 96 | } |
97 | 97 | ||
98 | void BatteryMeter::paintEvent( QPaintEvent* ) | 98 | void BatteryMeter::paintEvent( QPaintEvent* ) |
99 | { | 99 | { |
100 | QPainter p(this); | 100 | QPainter p(this); |
101 | 101 | ||
102 | QColor c; | 102 | QColor c; |
103 | QColor darkc; | 103 | QColor darkc; |
104 | QColor lightc; | 104 | QColor lightc; |
105 | if ( ps->acStatus() == PowerStatus::Offline ) { | 105 | if ( ps->acStatus() == PowerStatus::Offline ) { |
106 | c = blue.light(120); | 106 | c = blue.light(120); |
107 | darkc = c.dark(120); | 107 | darkc = c.dark(120); |
108 | lightc = c.light(140); | 108 | lightc = c.light(140); |
109 | } else if ( ps->acStatus() == PowerStatus::Online ) { | 109 | } else if ( ps->acStatus() == PowerStatus::Online ) { |
110 | c = green.dark(130); | 110 | c = green.dark(130); |
111 | darkc = c.dark(120); | 111 | darkc = c.dark(120); |
112 | lightc = c.light(180); | 112 | lightc = c.light(180); |
113 | } else { | 113 | } else { |
114 | c = red; | 114 | c = red; |
115 | darkc = c.dark(120); | 115 | darkc = c.dark(120); |
116 | lightc = c.light(160); | 116 | lightc = c.light(160); |
117 | } | 117 | } |
118 | 118 | ||
119 | int w = 6; | 119 | int w = 6; |
120 | int h = height()-3; | 120 | int h = height()-3; |
121 | int pix = (percent * h) / 100; | 121 | int pix = (percent * h) / 100; |
122 | int y2 = height() - 2; | 122 | int y2 = height() - 2; |
123 | int y = y2 - pix; | 123 | int y = y2 - pix; |
124 | int x1 = (width() - w) / 2; | 124 | int x1 = (width() - w) / 2; |
125 | 125 | ||