1
/***************************************************************************
2
* Copyright (C) 2007-2009 by Sebastian Kuegler <sebas@kde.org> *
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. *
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. *
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
***************************************************************************/
23
#include <QGraphicsSceneHoverEvent>
24
#include <QGraphicsGridLayout>
25
#include <QPropertyAnimation>
27
#include <Plasma/Applet>
28
#include <Plasma/Animator>
29
#include <Plasma/DataEngine>
30
#include <Plasma/PopupApplet>
31
#include "ui_batteryConfig.h"
33
typedef QMap< QString, QString > StringStringMap;
44
class BrightnessOSDWidget;
46
class Battery : public Plasma::PopupApplet
49
Q_PROPERTY(qreal labelAlpha READ labelAlpha WRITE setLabelAlpha )
50
Q_PROPERTY(qreal acAlpha READ acAlpha WRITE setAcAlpha)
53
Battery(QObject *parent, const QVariantList &args);
57
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option,
58
const QRect &contents);
59
void setPath(const QString&);
60
Qt::Orientations expandingDirections() const;
61
void constraintsEvent(Plasma::Constraints constraints);
62
void popupEvent(bool show);
63
void setShowBatteryLabel(bool show);
65
qreal labelAlpha() const;
66
void setLabelAlpha(qreal alpha);
67
qreal acAlpha() const;
68
void setAcAlpha(qreal alpha);
70
QList<QAction*> contextualActions();
73
void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data);
75
void toolTipAboutToShow();
79
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
80
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
81
void configAccepted();
85
void createConfigurationInterface(KConfigDialog *parent);
86
void setEmbedded(const bool embedded);
89
//void animationUpdate(qreal progress);
90
//void acAnimationUpdate(qreal progress);
91
//void batteryAnimationUpdate(qreal progress);
92
void sourceAdded(const QString &source);
93
void sourceRemoved(const QString &source);
94
void brightnessChanged(const int brightness);
95
void updateSlider(const float brightness);
98
void setProfile(const QString &profile);
101
void updateBattery();
103
void showBrightnessOSD(int brightness);
106
void connectSources();
107
void initPopupWidget();
109
bool isConstrained();
110
QString stringForState(const QHash<QString, QVariant> &batteryData, bool *chargeChanging = 0);
111
QFont setupLabelPainting(const QRect &contentsRect, const QString &batterLabel);
113
/* Paint battery with proper charge level */
114
void paintBattery(QPainter *p, const QRect &contentsRect, const int batteryPercent, const bool plugState);
115
/* Paint a label on top of the battery */
116
void paintLabel(QPainter *p, const QRect &contentsRect, const QString& labelText);
117
/* Scale in/out Battery. */
118
//void showBattery(bool show);
119
/* Scale in/out Ac Adapter. */
120
void showAcAdapter(bool show);
121
/* Fade in/out the label above the battery. */
122
void showLabel(bool show);
123
/* Scale in a QRectF */
124
QRectF scaleRectF(qreal progress, QRectF rect);
126
/* Prevent creating infinite loops by embedding applets inside applets */
128
bool m_extenderVisible;
130
Plasma::Label *m_batteryLabelLabel;
131
Plasma::Label *m_batteryInfoLabel;
132
Plasma::Label *m_acLabelLabel;
133
Plasma::Label *m_acInfoLabel;
134
Plasma::Label *m_remainingTimeLabel;
135
Plasma::Label *m_remainingInfoLabel;
136
Plasma::Label *m_statusLabel;
137
Plasma::Label *m_brightnessLabel;
138
Plasma::Label *m_profileLabel;
139
Plasma::ComboBox *m_profileCombo;
140
Plasma::Slider *m_brightnessSlider;
143
/* Show multiple batteries with individual icons and charge info? */
144
bool m_showMultipleBatteries;
145
/* Should the battery charge information be shown on top? */
146
bool m_showBatteryLabel;
147
/* Should that info be percentage (false) or time (true)? */
148
bool m_showRemainingTime;
153
Plasma::Svg* m_theme;
155
StringStringMap m_availableProfiles;
156
QString m_currentProfile;
157
QStringList m_suspendMethods;
159
// Configuration dialog
160
Ui::batteryConfig ui;
165
QList<QVariant> batterylist;
166
QList<QVariant> acadapterlist;
167
QHash<QString, QHash<QString, QVariant> > m_batteriesData;
176
bool m_acAdapterPlugged;
177
qulonglong m_remainingMSecs;
180
QPropertyAnimation *m_labelAnimation;
182
QPropertyAnimation *m_acAnimation;
184
bool m_ignoreBrightnessChange;
185
BrightnessOSDWidget* m_brightnessOSD;
188
Q_DECLARE_METATYPE(StringStringMap)
189
K_EXPORT_PLASMA_APPLET(battery, Battery)