1 /***************************************************************************
2 * Copyright (C) 2005,2006,2007 by Siraj Razick <siraj@kdemail.net> *
3 * Copyright (C) 2007 by Sebastian Kuegler <sebas@kde.org> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
19 ***************************************************************************/
25 #include <QGraphicsSceneHoverEvent>
29 #include <plasma/applet.h>
30 #include <plasma/phase.h>
31 #include <plasma/dataengine.h>
32 #include "ui_batteryConfig.h"
41 class Battery
: public Plasma::Applet
45 Battery(QObject
*parent
, const QVariantList
&args
);
49 void paintInterface(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
,
50 const QRect
&contents
);
51 void setPath(const QString
&);
52 QSizeF
contentSizeHint() const;
53 Qt::Orientations
expandingDirections() const;
55 void constraintsUpdated(Plasma::Constraints constraints
);
58 void dataUpdated(const QString
&name
, const Plasma::DataEngine::Data
&data
);
59 void showConfigurationInterface();
62 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent
*event
);
63 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent
*event
);
66 void configAccepted();
70 void animationUpdate(qreal progress
);
71 void acAnimationUpdate(qreal progress
);
72 void batteryAnimationUpdate(qreal progress
);
75 Q_ENUMS( m_batteryStyle
)
77 // Keep the order of styles the same order as the items in the configdialog!
78 OxygenBattery
, ClassicBattery
80 void connectSources();
81 void disconnectSources();
83 /* Paint battery with proper charge level */
84 void paintBattery(QPainter
*p
, const QRect
&contentsRect
, const int batteryPercent
, const bool plugState
);
85 /* Paint a label on top of the battery */
86 void paintLabel(QPainter
*p
, const QRect
&contentsRect
, const QString
& labelText
);
87 /* Fade in/out the label above the battery. */
88 void showLabel(bool show
);
89 /* Scale in/out Battery. */
90 void showBattery(bool show
);
91 /* Scale in/out Ac Adapter. */
92 void showAcAdapter(bool show
);
93 /* Scale in a QRectF */
94 QRectF
scaleRectF(qreal progress
, QRectF rect
);
95 /* Show multiple batteries with individual icons and charge info? */
96 bool m_showMultipleBatteries
;
97 /* Should the battery charge information be shown on top? */
98 bool m_showBatteryString
;
101 int m_smallPixelSize
;
102 Plasma::Svg
* m_theme
;
103 bool m_acadapter_plugged
;
105 // Configuration dialog
107 Ui::batteryConfig ui
;
109 Plasma::Phase::AnimId m_animId
;
113 Plasma::Phase::AnimId m_acAnimId
;
117 Plasma::Phase::AnimId m_batteryAnimId
;
118 qreal m_batteryAlpha
;
119 bool m_batteryFadeIn
;
122 QList
<QVariant
> batterylist
, acadapterlist
;
123 QHash
<QString
, QHash
<QString
, QVariant
> > m_batteries_data
;
126 bool m_drawBackground
;
134 K_EXPORT_PLASMA_APPLET(battery
, Battery
)