-rw-r--r-- | core/applets/batteryapplet/.cvsignore | 3 | ||||
-rw-r--r-- | core/applets/batteryapplet/Makefile.in | 122 | ||||
-rw-r--r-- | core/applets/batteryapplet/battery.cpp | 152 | ||||
-rw-r--r-- | core/applets/batteryapplet/battery.h | 55 | ||||
-rw-r--r-- | core/applets/batteryapplet/batteryapplet.pro | 12 | ||||
-rw-r--r-- | core/applets/batteryapplet/batteryappletimpl.cpp | 63 | ||||
-rw-r--r-- | core/applets/batteryapplet/batteryappletimpl.h | 44 | ||||
-rw-r--r-- | core/applets/batteryapplet/batterystatus.cpp | 140 | ||||
-rw-r--r-- | core/applets/batteryapplet/batterystatus.h | 45 | ||||
-rw-r--r-- | core/applets/batteryapplet/qpe-batteryapplet.control | 9 | ||||
-rwxr-xr-x | core/applets/batteryapplet/qpe-batteryapplet.postinst | 2 | ||||
-rwxr-xr-x | core/applets/batteryapplet/qpe-batteryapplet.postrm | 2 |
12 files changed, 649 insertions, 0 deletions
diff --git a/core/applets/batteryapplet/.cvsignore b/core/applets/batteryapplet/.cvsignore new file mode 100644 index 0000000..edfa921 --- a/dev/null +++ b/core/applets/batteryapplet/.cvsignore | |||
@@ -0,0 +1,3 @@ | |||
1 | moc_* | ||
2 | *.moc | ||
3 | Makefile | ||
diff --git a/core/applets/batteryapplet/Makefile.in b/core/applets/batteryapplet/Makefile.in new file mode 100644 index 0000000..0493fd6 --- a/dev/null +++ b/core/applets/batteryapplet/Makefile.in | |||
@@ -0,0 +1,122 @@ | |||
1 | ############################################################################# | ||
2 | |||
3 | ####### Compiler, tools and options | ||
4 | |||
5 | CXX =$(SYSCONF_CXX) $(QT_CXX_MT) | ||
6 | CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) $(SYSCONF_CXXFLAGS_LIB) | ||
7 | CC =$(SYSCONF_CC) $(QT_C_MT) | ||
8 | CFLAGS =$(SYSCONF_CFLAGS) $(SYSCONF_CFLAGS_LIB) | ||
9 | INCPATH =-I$(QPEDIR)/include | ||
10 | LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT) | ||
11 | LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS_QTAPP) | ||
12 | MOC =$(SYSCONF_MOC) | ||
13 | UIC =$(SYSCONF_UIC) | ||
14 | |||
15 | ####### Target | ||
16 | |||
17 | DESTDIR = ../../plugins/applets/ | ||
18 | VER_MAJ = 1 | ||
19 | VER_MIN = 0 | ||
20 | VER_PATCH = 0 | ||
21 | TARGET= batteryapplet | ||
22 | TARGET1 = lib$(TARGET).so.$(VER_MAJ) | ||
23 | |||
24 | ####### Files | ||
25 | |||
26 | HEADERS =battery.h \ | ||
27 | batterystatus.h \ | ||
28 | batteryappletimpl.h | ||
29 | SOURCES =battery.cpp \ | ||
30 | batterystatus.cpp \ | ||
31 | batteryappletimpl.cpp | ||
32 | OBJECTS =battery.o \ | ||
33 | batterystatus.o \ | ||
34 | batteryappletimpl.o | ||
35 | INTERFACES = | ||
36 | UICDECLS = | ||
37 | UICIMPLS = | ||
38 | SRCMOC =moc_battery.cpp | ||
39 | OBJMOC =moc_battery.o | ||
40 | |||
41 | |||
42 | ####### Implicit rules | ||
43 | |||
44 | .SUFFIXES: .cpp .cxx .cc .C .c | ||
45 | |||
46 | .cpp.o: | ||
47 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
48 | |||
49 | .cxx.o: | ||
50 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
51 | |||
52 | .cc.o: | ||
53 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
54 | |||
55 | .C.o: | ||
56 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
57 | |||
58 | .c.o: | ||
59 | $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< | ||
60 | |||
61 | ####### Build rules | ||
62 | |||
63 | |||
64 | all: $(DESTDIR)$(SYSCONF_LINK_TARGET) | ||
65 | |||
66 | $(DESTDIR)$(SYSCONF_LINK_TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS) | ||
67 | $(SYSCONF_LINK_LIB) | ||
68 | |||
69 | moc: $(SRCMOC) | ||
70 | |||
71 | tmake: | ||
72 | tmake batteryapplet.pro | ||
73 | |||
74 | clean: | ||
75 | -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) | ||
76 | -rm -f *~ core | ||
77 | -rm -f allmoc.cpp | ||
78 | |||
79 | ####### Extension Modules | ||
80 | |||
81 | listpromodules: | ||
82 | @echo | ||
83 | |||
84 | listallmodules: | ||
85 | @echo | ||
86 | |||
87 | listaddonpromodules: | ||
88 | @echo | ||
89 | |||
90 | listaddonentmodules: | ||
91 | @echo | ||
92 | |||
93 | |||
94 | REQUIRES= | ||
95 | |||
96 | ####### Sub-libraries | ||
97 | |||
98 | |||
99 | ###### Combined headers | ||
100 | |||
101 | |||
102 | |||
103 | ####### Compile | ||
104 | |||
105 | battery.o: battery.cpp \ | ||
106 | battery.h \ | ||
107 | batterystatus.h | ||
108 | |||
109 | batterystatus.o: batterystatus.cpp \ | ||
110 | batterystatus.h | ||
111 | |||
112 | batteryappletimpl.o: batteryappletimpl.cpp \ | ||
113 | battery.h \ | ||
114 | batteryappletimpl.h | ||
115 | |||
116 | moc_battery.o: moc_battery.cpp \ | ||
117 | battery.h | ||
118 | |||
119 | moc_battery.cpp: battery.h | ||
120 | $(MOC) battery.h -o moc_battery.cpp | ||
121 | |||
122 | |||
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp new file mode 100644 index 0000000..3d254fc --- a/dev/null +++ b/core/applets/batteryapplet/battery.cpp | |||
@@ -0,0 +1,152 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include "battery.h" | ||
21 | #include "batterystatus.h" | ||
22 | |||
23 | #include <qpe/power.h> | ||
24 | |||
25 | #include <qpainter.h> | ||
26 | #include <qtimer.h> | ||
27 | |||
28 | |||
29 | BatteryMeter::BatteryMeter( QWidget *parent = 0 ) | ||
30 | : QWidget( parent ), charging(false) | ||
31 | { | ||
32 | ps = new PowerStatus; | ||
33 | startTimer( 10000 ); | ||
34 | setFixedHeight(12); | ||
35 | chargeTimer = new QTimer( this ); | ||
36 | connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); | ||
37 | timerEvent(0); | ||
38 | } | ||
39 | |||
40 | BatteryMeter::~BatteryMeter() | ||
41 | { | ||
42 | delete ps; | ||
43 | } | ||
44 | |||
45 | QSize BatteryMeter::sizeHint() const | ||
46 | { | ||
47 | return QSize(10,12); | ||
48 | } | ||
49 | |||
50 | void BatteryMeter::mouseReleaseEvent( QMouseEvent *) | ||
51 | { | ||
52 | if ( batteryView && batteryView->isVisible() ) { | ||
53 | delete (QWidget *) batteryView; | ||
54 | } else { | ||
55 | if ( !batteryView ) | ||
56 | batteryView = new BatteryStatus( ps ); | ||
57 | batteryView->showMaximized(); | ||
58 | batteryView->raise(); | ||
59 | batteryView->show(); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | void BatteryMeter::timerEvent( QTimerEvent * ) | ||
64 | { | ||
65 | PowerStatus prev = *ps; | ||
66 | |||
67 | *ps = PowerStatusManager::readStatus(); | ||
68 | |||
69 | if ( prev != *ps ) { | ||
70 | percent = ps->batteryPercentRemaining(); | ||
71 | if ( !charging && ps->batteryStatus() == PowerStatus::Charging && percent < 0 ) { | ||
72 | percent = 0; | ||
73 | charging = true; | ||
74 | chargeTimer->start( 500 ); | ||
75 | } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { | ||
76 | charging = false; | ||
77 | chargeTimer->stop(); | ||
78 | if ( batteryView ) | ||
79 | batteryView->updatePercent( percent ); | ||
80 | } | ||
81 | repaint(FALSE); | ||
82 | if ( batteryView ) | ||
83 | batteryView->repaint(); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | void BatteryMeter::chargeTimeout() | ||
88 | { | ||
89 | percent += 20; | ||
90 | if ( percent > 100 ) | ||
91 | percent = 0; | ||
92 | |||
93 | repaint(FALSE); | ||
94 | if ( batteryView ) | ||
95 | batteryView->updatePercent( percent ); | ||
96 | } | ||
97 | |||
98 | void BatteryMeter::paintEvent( QPaintEvent* ) | ||
99 | { | ||
100 | QPainter p(this); | ||
101 | |||
102 | QColor c; | ||
103 | QColor darkc; | ||
104 | QColor lightc; | ||
105 | if ( ps->acStatus() == PowerStatus::Offline ) { | ||
106 | c = blue.light(120); | ||
107 | darkc = c.dark(120); | ||
108 | lightc = c.light(140); | ||
109 | } else if ( ps->acStatus() == PowerStatus::Online ) { | ||
110 | c = green.dark(130); | ||
111 | darkc = c.dark(120); | ||
112 | lightc = c.light(180); | ||
113 | } else { | ||
114 | c = red; | ||
115 | darkc = c.dark(120); | ||
116 | lightc = c.light(160); | ||
117 | } | ||
118 | |||
119 | int w = 6; | ||
120 | int h = height()-3; | ||
121 | int pix = (percent * h) / 100; | ||
122 | int y2 = height() - 2; | ||
123 | int y = y2 - pix; | ||
124 | int x1 = (width() - w) / 2; | ||
125 | |||
126 | p.setPen(QColor(80,80,80)); | ||
127 | p.drawLine(x1+w/4,0,x1+w/4+w/2,0); | ||
128 | p.drawRect(x1,1,w,height()-1); | ||
129 | p.setBrush(c); | ||
130 | |||
131 | int extra = ((percent * h) % 100)/(100/4); | ||
132 | |||
133 | #define Y(i) ((i<=extra)?y-1:y) | ||
134 | #define DRAWUPPER(i) if ( Y(i) >= 2 ) p.drawLine(i+x1,2,i+x1,Y(i)); | ||
135 | p.setPen( gray ); | ||
136 | DRAWUPPER(1); | ||
137 | DRAWUPPER(3); | ||
138 | p.setPen( gray.light(130) ); | ||
139 | DRAWUPPER(2); | ||
140 | p.setPen( gray.dark(120) ); | ||
141 | DRAWUPPER(4); | ||
142 | |||
143 | #define DRAW(i) { if ( Y(i) < y2 ) p.drawLine(i+x1,Y(i)+1,i+x1,y2); } | ||
144 | p.setPen( c ); | ||
145 | DRAW(1); | ||
146 | DRAW(3); | ||
147 | p.setPen( lightc ); | ||
148 | DRAW(2); | ||
149 | p.setPen(darkc); | ||
150 | DRAW(4); | ||
151 | } | ||
152 | |||
diff --git a/core/applets/batteryapplet/battery.h b/core/applets/batteryapplet/battery.h new file mode 100644 index 0000000..d4807b0 --- a/dev/null +++ b/core/applets/batteryapplet/battery.h | |||
@@ -0,0 +1,55 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef BATTERY_H | ||
21 | #define BATTERY_H | ||
22 | |||
23 | #include <qwidget.h> | ||
24 | #include <qguardedptr.h> | ||
25 | |||
26 | class PowerStatus; | ||
27 | class BatteryStatus; | ||
28 | class QTimer; | ||
29 | |||
30 | class BatteryMeter : public QWidget | ||
31 | { | ||
32 | Q_OBJECT | ||
33 | public: | ||
34 | BatteryMeter( QWidget *parent = 0 ); | ||
35 | ~BatteryMeter(); | ||
36 | |||
37 | QSize sizeHint() const; | ||
38 | |||
39 | protected: | ||
40 | void timerEvent( QTimerEvent * ); | ||
41 | void paintEvent( QPaintEvent* ); | ||
42 | void mouseReleaseEvent( QMouseEvent * ); | ||
43 | |||
44 | protected slots: | ||
45 | void chargeTimeout(); | ||
46 | |||
47 | protected: | ||
48 | QGuardedPtr<BatteryStatus> batteryView; | ||
49 | PowerStatus *ps; | ||
50 | QTimer *chargeTimer; | ||
51 | int percent; | ||
52 | bool charging; | ||
53 | }; | ||
54 | |||
55 | #endif | ||
diff --git a/core/applets/batteryapplet/batteryapplet.pro b/core/applets/batteryapplet/batteryapplet.pro new file mode 100644 index 0000000..fa0fca8 --- a/dev/null +++ b/core/applets/batteryapplet/batteryapplet.pro | |||
@@ -0,0 +1,12 @@ | |||
1 | TEMPLATE= lib | ||
2 | CONFIG += qt warn_on release | ||
3 | HEADERS= battery.h batterystatus.h batteryappletimpl.h | ||
4 | SOURCES= battery.cpp batterystatus.cpp batteryappletimpl.cpp | ||
5 | TARGET = batteryapplet | ||
6 | DESTDIR = ../../plugins/applets | ||
7 | INCLUDEPATH += $(QPEDIR)/include | ||
8 | DEPENDPATH += ../$(QPEDIR)/include .. | ||
9 | LIBS += -lqpe | ||
10 | VERSION = 1.0.0 | ||
11 | |||
12 | TRANSLATIONS += ../../i18n/de/libbatteryapplet.ts | ||
diff --git a/core/applets/batteryapplet/batteryappletimpl.cpp b/core/applets/batteryapplet/batteryappletimpl.cpp new file mode 100644 index 0000000..3f3079a --- a/dev/null +++ b/core/applets/batteryapplet/batteryappletimpl.cpp | |||
@@ -0,0 +1,63 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include "battery.h" | ||
21 | #include "batteryappletimpl.h" | ||
22 | |||
23 | |||
24 | BatteryAppletImpl::BatteryAppletImpl() | ||
25 | : battery(0), ref(0) | ||
26 | { | ||
27 | } | ||
28 | |||
29 | BatteryAppletImpl::~BatteryAppletImpl() | ||
30 | { | ||
31 | delete battery; | ||
32 | } | ||
33 | |||
34 | QWidget *BatteryAppletImpl::applet( QWidget *parent ) | ||
35 | { | ||
36 | if ( !battery ) | ||
37 | battery = new BatteryMeter( parent ); | ||
38 | return battery; | ||
39 | } | ||
40 | |||
41 | int BatteryAppletImpl::position() const | ||
42 | { | ||
43 | return 8; | ||
44 | } | ||
45 | |||
46 | QRESULT BatteryAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) | ||
47 | { | ||
48 | *iface = 0; | ||
49 | if ( uuid == IID_QUnknown ) | ||
50 | *iface = this; | ||
51 | else if ( uuid == IID_TaskbarApplet ) | ||
52 | *iface = this; | ||
53 | |||
54 | if ( *iface ) | ||
55 | (*iface)->addRef(); | ||
56 | return QS_OK; | ||
57 | } | ||
58 | |||
59 | Q_EXPORT_INTERFACE() | ||
60 | { | ||
61 | Q_CREATE_INSTANCE( BatteryAppletImpl ) | ||
62 | } | ||
63 | |||
diff --git a/core/applets/batteryapplet/batteryappletimpl.h b/core/applets/batteryapplet/batteryappletimpl.h new file mode 100644 index 0000000..94f49db --- a/dev/null +++ b/core/applets/batteryapplet/batteryappletimpl.h | |||
@@ -0,0 +1,44 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef BATTERYAPPLETIMPL_H | ||
21 | #define BATTERYAPPLETIMPL_H | ||
22 | |||
23 | #include <qpe/taskbarappletinterface.h> | ||
24 | |||
25 | class BatteryMeter; | ||
26 | |||
27 | class BatteryAppletImpl : public TaskbarAppletInterface | ||
28 | { | ||
29 | public: | ||
30 | BatteryAppletImpl(); | ||
31 | virtual ~BatteryAppletImpl(); | ||
32 | |||
33 | QRESULT queryInterface( const QUuid&, QUnknownInterface** ); | ||
34 | Q_REFCOUNT | ||
35 | |||
36 | virtual QWidget *applet( QWidget *parent ); | ||
37 | virtual int position() const; | ||
38 | |||
39 | private: | ||
40 | BatteryMeter *battery; | ||
41 | ulong ref; | ||
42 | }; | ||
43 | |||
44 | #endif | ||
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp new file mode 100644 index 0000000..d18b6c9 --- a/dev/null +++ b/core/applets/batteryapplet/batterystatus.cpp | |||
@@ -0,0 +1,140 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include "batterystatus.h" | ||
21 | |||
22 | #include <qpe/power.h> | ||
23 | |||
24 | #include <qpainter.h> | ||
25 | #include <qpushbutton.h> | ||
26 | #include <qdrawutil.h> | ||
27 | |||
28 | |||
29 | BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) | ||
30 | : QWidget( parent, 0, WDestructiveClose), ps(p) | ||
31 | { | ||
32 | setCaption( tr("Battery Status") ); | ||
33 | QPushButton *pb = new QPushButton( tr("Close"), this ); | ||
34 | pb->move( 70, 220 ); | ||
35 | pb->show(); | ||
36 | connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) ); | ||
37 | percent = ps->batteryPercentRemaining(); | ||
38 | show(); | ||
39 | } | ||
40 | |||
41 | BatteryStatus::~BatteryStatus() | ||
42 | { | ||
43 | } | ||
44 | |||
45 | void BatteryStatus::updatePercent( int pc ) | ||
46 | { | ||
47 | percent = pc; | ||
48 | repaint(FALSE); | ||
49 | } | ||
50 | |||
51 | void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) | ||
52 | { | ||
53 | int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; | ||
54 | topgrad.hsv( &h1, &s1, &v1 ); | ||
55 | botgrad.hsv( &h2, &s2, &v2 ); | ||
56 | for ( int j = 0; j < hy-2; j++ ) { | ||
57 | p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), | ||
58 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); | ||
59 | p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); | ||
60 | } | ||
61 | for ( int j = 0; j < hh; j++ ) { | ||
62 | p->setPen( highlight ); | ||
63 | p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); | ||
64 | } | ||
65 | for ( int j = 0; j < ng-hy-hh; j++ ) { | ||
66 | p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), | ||
67 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); | ||
68 | p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | void BatteryStatus::paintEvent( QPaintEvent * ) | ||
73 | { | ||
74 | QPainter p(this); | ||
75 | QString text; | ||
76 | if ( ps->batteryStatus() == PowerStatus::Charging ) { | ||
77 | text = tr("Charging"); | ||
78 | } else if ( ps->batteryPercentAccurate() ) { | ||
79 | text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent ); | ||
80 | } else { | ||
81 | text = tr("Battery status: "); | ||
82 | switch ( ps->batteryStatus() ) { | ||
83 | case PowerStatus::High: | ||
84 | text += tr("Good"); | ||
85 | break; | ||
86 | case PowerStatus::Low: | ||
87 | text += tr("Low"); | ||
88 | break; | ||
89 | case PowerStatus::VeryLow: | ||
90 | text += tr("Very Low"); | ||
91 | break; | ||
92 | case PowerStatus::Critical: | ||
93 | text += tr("Critical"); | ||
94 | break; | ||
95 | default: // NotPresent, etc. | ||
96 | text += tr("Unknown"); | ||
97 | } | ||
98 | } | ||
99 | p.drawText( 10, 120, text ); | ||
100 | if ( ps->acStatus() == PowerStatus::Backup ) | ||
101 | p.drawText( 10, 150, tr("On backup power") ); | ||
102 | else if ( ps->acStatus() == PowerStatus::Online ) | ||
103 | p.drawText( 10, 150, tr("Power on-line") ); | ||
104 | else if ( ps->acStatus() == PowerStatus::Offline ) | ||
105 | p.drawText( 10, 150, tr("External power disconnected") ); | ||
106 | |||
107 | if ( ps->batteryTimeRemaining() >= 0 ) { | ||
108 | text.sprintf( tr("Battery time remaining") + ": %im %02is", | ||
109 | ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); | ||
110 | p.drawText( 10, 180, text ); | ||
111 | } | ||
112 | |||
113 | QColor c; | ||
114 | QColor darkc; | ||
115 | QColor lightc; | ||
116 | if ( ps->acStatus() == PowerStatus::Offline ) { | ||
117 | c = blue.light(120); | ||
118 | darkc = c.dark(280); | ||
119 | lightc = c.light(145); | ||
120 | } else if ( ps->acStatus() == PowerStatus::Online ) { | ||
121 | c = green.dark(130); | ||
122 | darkc = c.dark(200); | ||
123 | lightc = c.light(220); | ||
124 | } else { | ||
125 | c = red; | ||
126 | darkc = c.dark(280); | ||
127 | lightc = c.light(140); | ||
128 | } | ||
129 | if ( percent < 0 ) | ||
130 | return; | ||
131 | |||
132 | int percent2 = percent * 2; | ||
133 | p.setPen( black ); | ||
134 | qDrawShadePanel( &p, 9, 30, 204, 39, colorGroup(), TRUE, 1, NULL); | ||
135 | qDrawShadePanel( &p, 212, 37, 12, 24, colorGroup(), TRUE, 1, NULL); | ||
136 | drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 ); | ||
137 | drawSegment( &p, QRect( 11 + percent2, 30, 200 - percent2, 40 ), white.light(80), black, white.light(90), 6 ); | ||
138 | drawSegment( &p, QRect( 212, 37, 10, 25 ), white.light(80), black, white.light(90), 2 ); | ||
139 | } | ||
140 | |||
diff --git a/core/applets/batteryapplet/batterystatus.h b/core/applets/batteryapplet/batterystatus.h new file mode 100644 index 0000000..85b2c4d --- a/dev/null +++ b/core/applets/batteryapplet/batterystatus.h | |||
@@ -0,0 +1,45 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef BATTERY_STATUS_H | ||
21 | #define BATTERY_STATUS_H | ||
22 | |||
23 | #include <qwidget.h> | ||
24 | |||
25 | class PowerStatus; | ||
26 | |||
27 | class BatteryStatus : public QWidget | ||
28 | { | ||
29 | public: | ||
30 | BatteryStatus( const PowerStatus *s, QWidget *parent=0 ); | ||
31 | ~BatteryStatus(); | ||
32 | |||
33 | void updatePercent( int ); | ||
34 | |||
35 | protected: | ||
36 | void drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ); | ||
37 | void paintEvent( QPaintEvent *pe ); | ||
38 | |||
39 | private: | ||
40 | const PowerStatus *ps; | ||
41 | int percent; | ||
42 | }; | ||
43 | |||
44 | #endif | ||
45 | |||
diff --git a/core/applets/batteryapplet/qpe-batteryapplet.control b/core/applets/batteryapplet/qpe-batteryapplet.control new file mode 100644 index 0000000..83d0b8b --- a/dev/null +++ b/core/applets/batteryapplet/qpe-batteryapplet.control | |||
@@ -0,0 +1,9 @@ | |||
1 | Files: plugins/applets/libbatteryapplet.so* | ||
2 | Priority: optional | ||
3 | Section: qpe/taskbar | ||
4 | Maintainer: Warwick Allison <warwick@trolltech.com> | ||
5 | Architecture: arm | ||
6 | Version: $QPE_VERSION-3 | ||
7 | Depends: qpe-base ($QPE_VERSION) | ||
8 | Description: Battery Monitor applet | ||
9 | Battery Monitor applet for the Qtopia environment taskbar. | ||
diff --git a/core/applets/batteryapplet/qpe-batteryapplet.postinst b/core/applets/batteryapplet/qpe-batteryapplet.postinst new file mode 100755 index 0000000..ba76ffa --- a/dev/null +++ b/core/applets/batteryapplet/qpe-batteryapplet.postinst | |||
@@ -0,0 +1,2 @@ | |||
1 | #!/bin/sh | ||
2 | /opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()" | ||
diff --git a/core/applets/batteryapplet/qpe-batteryapplet.postrm b/core/applets/batteryapplet/qpe-batteryapplet.postrm new file mode 100755 index 0000000..ba76ffa --- a/dev/null +++ b/core/applets/batteryapplet/qpe-batteryapplet.postrm | |||
@@ -0,0 +1,2 @@ | |||
1 | #!/bin/sh | ||
2 | /opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()" | ||