~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/applets/battery/battery.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2007-2009 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
 ***************************************************************************/
 
19
 
 
20
#ifndef BATTERY_H
 
21
#define BATTERY_H
 
22
 
 
23
#include <QGraphicsSceneHoverEvent>
 
24
#include <QGraphicsGridLayout>
 
25
#include <QPropertyAnimation>
 
26
 
 
27
#include <Plasma/Applet>
 
28
#include <Plasma/Animator>
 
29
#include <Plasma/DataEngine>
 
30
#include <Plasma/PopupApplet>
 
31
#include "ui_batteryConfig.h"
 
32
 
 
33
typedef QMap< QString, QString > StringStringMap;
 
34
 
 
35
namespace Plasma
 
36
{
 
37
    class Svg;
 
38
    class Label;
 
39
    class ExtenderItem;
 
40
    class ComboBox;
 
41
    class Slider;
 
42
}
 
43
 
 
44
class BrightnessOSDWidget;
 
45
 
 
46
class Battery : public Plasma::PopupApplet
 
47
{
 
48
    Q_OBJECT
 
49
    Q_PROPERTY(qreal labelAlpha READ labelAlpha WRITE setLabelAlpha )
 
50
    Q_PROPERTY(qreal acAlpha READ acAlpha WRITE setAcAlpha)
 
51
 
 
52
    public:
 
53
        Battery(QObject *parent, const QVariantList &args);
 
54
        ~Battery();
 
55
 
 
56
        void init();
 
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);
 
64
 
 
65
        qreal labelAlpha() const;
 
66
        void setLabelAlpha(qreal alpha);
 
67
        qreal acAlpha() const;
 
68
        void setAcAlpha(qreal alpha);
 
69
 
 
70
        QList<QAction*> contextualActions();
 
71
 
 
72
    public Q_SLOTS:
 
73
        void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data);
 
74
        void configChanged();
 
75
        void toolTipAboutToShow();
 
76
        void toolTipHidden();
 
77
 
 
78
    protected Q_SLOTS:
 
79
        virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
 
80
        virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
 
81
        void configAccepted();
 
82
        void readColors();
 
83
 
 
84
    protected:
 
85
        void createConfigurationInterface(KConfigDialog *parent);
 
86
        void setEmbedded(const bool embedded);
 
87
 
 
88
    private Q_SLOTS:
 
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);
 
96
        void updateSlider();
 
97
        void openConfig();
 
98
        void setProfile(const QString &profile);
 
99
        void suspend();
 
100
        void hibernate();
 
101
        void updateBattery();
 
102
        void setupFonts();
 
103
        void showBrightnessOSD(int brightness);
 
104
 
 
105
    private:
 
106
        void connectSources();
 
107
        void initPopupWidget();
 
108
        void updateStatus();
 
109
        bool isConstrained();
 
110
        QString stringForState(const QHash<QString, QVariant> &batteryData, bool *chargeChanging = 0);
 
111
        QFont setupLabelPainting(const QRect &contentsRect, const QString &batterLabel);
 
112
 
 
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);
 
125
 
 
126
        /* Prevent creating infinite loops by embedding applets inside applets */
 
127
        bool m_isEmbedded;
 
128
        bool m_extenderVisible;
 
129
 
 
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;
 
141
        int m_inhibitCookie;
 
142
 
 
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;
 
149
        int m_minutes;
 
150
        int m_hours;
 
151
        QSizeF m_size;
 
152
        int m_pixelSize;
 
153
        Plasma::Svg* m_theme;
 
154
 
 
155
        StringStringMap m_availableProfiles;
 
156
        QString m_currentProfile;
 
157
        QStringList m_suspendMethods;
 
158
 
 
159
        // Configuration dialog
 
160
        Ui::batteryConfig ui;
 
161
 
 
162
        int m_batteryAnimId;
 
163
 
 
164
        // Internal data
 
165
        QList<QVariant> batterylist;
 
166
        QList<QVariant> acadapterlist;
 
167
        QHash<QString, QHash<QString, QVariant> > m_batteriesData;
 
168
        QFont m_font;
 
169
        bool m_firstRun;
 
170
        QColor m_boxColor;
 
171
        QColor m_textColor;
 
172
        QRectF m_textRect;
 
173
        int m_boxAlpha;
 
174
        int m_boxHoverAlpha;
 
175
        int m_numOfBattery;
 
176
        bool m_acAdapterPlugged;
 
177
        qulonglong m_remainingMSecs;
 
178
 
 
179
        qreal m_labelAlpha;
 
180
        QPropertyAnimation *m_labelAnimation;
 
181
        qreal m_acAlpha;
 
182
        QPropertyAnimation *m_acAnimation;
 
183
 
 
184
        bool m_ignoreBrightnessChange;
 
185
        BrightnessOSDWidget* m_brightnessOSD;
 
186
};
 
187
 
 
188
Q_DECLARE_METATYPE(StringStringMap)
 
189
K_EXPORT_PLASMA_APPLET(battery, Battery)
 
190
 
 
191
#endif