not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / applets / battery / battery.h
bloba853082489f0d36a0162de71c47c83c1dcffdad0
1 /***************************************************************************
2 * Copyright (C) 2007-2008 by Sebastian Kuegler <sebas@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
20 #ifndef BATTERY_H
21 #define BATTERY_H
23 #include <QLabel>
24 #include <QGraphicsSceneHoverEvent>
25 #include <QGraphicsGridLayout>
26 #include <QPair>
27 #include <QMap>
29 #include <Plasma/Applet>
30 #include <Plasma/Animator>
31 #include <Plasma/DataEngine>
32 #include <Plasma/PopupApplet>
33 #include "ui_batteryConfig.h"
35 namespace Plasma
37 class Svg;
38 class Label;
39 class ExtenderItem;
40 class ComboBox;
41 class Slider;
44 class Battery : public Plasma::PopupApplet
46 Q_OBJECT
47 public:
48 Battery(QObject *parent, const QVariantList &args);
49 ~Battery();
51 void init();
52 void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option,
53 const QRect &contents);
54 void setPath(const QString&);
55 Qt::Orientations expandingDirections() const;
56 void constraintsEvent(Plasma::Constraints constraints);
57 void popupEvent(bool show);
58 void showBatteryLabel(bool show);
60 public slots:
61 void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data);
63 protected Q_SLOTS:
64 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
65 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
66 void configAccepted();
67 void readColors();
69 protected:
70 void createConfigurationInterface(KConfigDialog *parent);
71 void setEmbedded(const bool embedded);
73 private slots:
74 void animationUpdate(qreal progress);
75 void acAnimationUpdate(qreal progress);
76 void batteryAnimationUpdate(qreal progress);
77 void sourceAdded(const QString &source);
78 void sourceRemoved(const QString &source);
79 void brightnessChanged(const int brightness);
80 void updateSlider(const float brightness);
81 void setFullBrightness();
82 void openConfig();
83 void setProfile(const QString &profile);
84 void suspend();
85 void hibernate();
87 private:
88 void connectSources();
89 void disconnectSources();
90 void initBatteryExtender(Plasma::ExtenderItem *item);
91 void updateStatus();
93 /* Prevent creating infinite loops by embedding applets inside applets */
94 bool m_isEmbedded;
95 Battery *m_extenderApplet;
96 bool m_extenderVisible;
98 QGraphicsGridLayout *m_controlsLayout;
99 QGraphicsGridLayout *m_batteryLayout;
100 Plasma::Label *m_statusLabel;
101 Plasma::Label *m_batteryLabel;
102 Plasma::Label *m_profileLabel;
103 Plasma::ComboBox *m_profileCombo;
104 Plasma::Slider *m_brightnessSlider;
105 int m_inhibitCookie;
107 /* Paint battery with proper charge level */
108 void paintBattery(QPainter *p, const QRect &contentsRect, const int batteryPercent, const bool plugState);
109 /* Paint a label on top of the battery */
110 void paintLabel(QPainter *p, const QRect &contentsRect, const QString& labelText);
111 /* Scale in/out Battery. */
112 void showBattery(bool show);
113 /* Scale in/out Ac Adapter. */
114 void showAcAdapter(bool show);
115 /* Fade in/out the label above the battery. */
116 void showLabel(bool show);
117 /* Scale in a QRectF */
118 QRectF scaleRectF(qreal progress, QRectF rect);
119 /* Show multiple batteries with individual icons and charge info? */
120 bool m_showMultipleBatteries;
121 /* Should the battery charge information be shown on top? */
122 bool m_showBatteryString;
123 QSizeF m_size;
124 int m_pixelSize;
125 Plasma::Svg* m_theme;
127 QStringList m_availableProfiles;
128 QString m_currentProfile;
129 QStringList m_suspendMethods;
131 // Configuration dialog
132 Ui::batteryConfig ui;
134 int m_animId;
135 qreal m_alpha;
136 bool m_fadeIn;
138 int m_acAnimId;
139 qreal m_acAlpha;
140 bool m_acFadeIn;
142 int m_batteryAnimId;
143 qreal m_batteryAlpha;
144 bool m_batteryFadeIn;
146 // Internal data
147 QList<QVariant> batterylist, acadapterlist;
148 QHash<QString, QHash<QString, QVariant> > m_batteries_data;
149 QFont m_font;
150 bool m_isHovered;
151 bool m_firstRun;
152 QColor m_boxColor;
153 QColor m_textColor;
154 QRectF m_textRect;
155 int m_boxAlpha;
156 int m_boxHoverAlpha;
157 int m_numOfBattery;
158 bool m_acadapter_plugged;
159 int m_remainingMSecs;
162 K_EXPORT_PLASMA_APPLET(battery, Battery)
164 #endif