1 /***************************************************************************
2 * Copyright (C) 2007-2008 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 ***************************************************************************/
24 #include <QGraphicsSceneHoverEvent>
25 #include <QGraphicsGridLayout>
29 #include <Plasma/Applet>
30 #include <Plasma/Animator>
31 #include <Plasma/DataEngine>
32 #include <Plasma/PopupApplet>
33 #include "ui_batteryConfig.h"
44 class Battery
: public Plasma::PopupApplet
48 Battery(QObject
*parent
, const QVariantList
&args
);
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
);
61 void dataUpdated(const QString
&name
, const Plasma::DataEngine::Data
&data
);
64 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent
*event
);
65 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent
*event
);
66 void configAccepted();
70 void createConfigurationInterface(KConfigDialog
*parent
);
71 void setEmbedded(const bool embedded
);
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();
83 void setProfile(const QString
&profile
);
88 void connectSources();
89 void disconnectSources();
90 void initBatteryExtender(Plasma::ExtenderItem
*item
);
93 /* Prevent creating infinite loops by embedding applets inside applets */
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
;
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
;
125 Plasma::Svg
* m_theme
;
127 QStringList m_availableProfiles
;
128 QString m_currentProfile
;
129 QStringList m_suspendMethods
;
131 // Configuration dialog
132 Ui::batteryConfig ui
;
143 qreal m_batteryAlpha
;
144 bool m_batteryFadeIn
;
147 QList
<QVariant
> batterylist
, acadapterlist
;
148 QHash
<QString
, QHash
<QString
, QVariant
> > m_batteries_data
;
158 bool m_acadapter_plugged
;
159 int m_remainingMSecs
;
162 K_EXPORT_PLASMA_APPLET(battery
, Battery
)