• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Applets

battery.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007-2008 by Sebastian Kuegler <sebas@kde.org>          *
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU General Public License     *
00015  *   along with this program; if not, write to the                         *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
00018  ***************************************************************************/
00019 
00020 #ifndef BATTERY_H
00021 #define BATTERY_H
00022 
00023 #include <QLabel>
00024 #include <QGraphicsSceneHoverEvent>
00025 #include <QGraphicsGridLayout>
00026 #include <QPair>
00027 #include <QMap>
00028 
00029 #include <Plasma/Applet>
00030 #include <Plasma/Animator>
00031 #include <Plasma/DataEngine>
00032 #include <Plasma/PopupApplet>
00033 #include "ui_batteryConfig.h"
00034 
00035 namespace Plasma
00036 {
00037     class Svg;
00038     class Label;
00039     class ExtenderItem;
00040     class ComboBox;
00041     class Slider;
00042 }
00043 
00044 class Battery : public Plasma::PopupApplet
00045 {
00046     Q_OBJECT
00047     public:
00048         Battery(QObject *parent, const QVariantList &args);
00049         ~Battery();
00050 
00051         void init();
00052         void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option,
00053                             const QRect &contents);
00054         void setPath(const QString&);
00055         Qt::Orientations expandingDirections() const;
00056         void constraintsEvent(Plasma::Constraints constraints);
00057         void popupEvent(bool show);
00058         void showBatteryLabel(bool show);
00059 
00060     public slots:
00061         void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data);
00062 
00063     protected Q_SLOTS:
00064         virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
00065         virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
00066         void configAccepted();
00067         void readColors();
00068 
00069     protected:
00070         void createConfigurationInterface(KConfigDialog *parent);
00071         void setEmbedded(const bool embedded);
00072 
00073     private slots:
00074         void animationUpdate(qreal progress);
00075         void acAnimationUpdate(qreal progress);
00076         void batteryAnimationUpdate(qreal progress);
00077         void sourceAdded(const QString &source);
00078         void sourceRemoved(const QString &source);
00079         void brightnessChanged(const int brightness);
00080         void updateSlider(const float brightness);
00081         void setFullBrightness();
00082         void openConfig();
00083         void setProfile(const QString &profile);
00084         void suspend();
00085         void hibernate();
00086 
00087     private:
00088         void connectSources();
00089         void disconnectSources();
00090         void initBatteryExtender(Plasma::ExtenderItem *item);
00091         void updateStatus();
00092 
00093         /* Prevent creating infinite loops by embedding applets inside applets */
00094         bool m_isEmbedded;
00095         Battery *m_extenderApplet;
00096         bool m_extenderVisible;
00097 
00098         QGraphicsGridLayout *m_controlsLayout;
00099         QGraphicsGridLayout *m_batteryLayout;
00100         Plasma::Label *m_statusLabel;
00101         Plasma::Label *m_batteryLabel;
00102         Plasma::Label *m_profileLabel;
00103         Plasma::ComboBox *m_profileCombo;
00104         Plasma::Slider *m_brightnessSlider;
00105         int m_inhibitCookie;
00106 
00107         /* Paint battery with proper charge level */
00108         void paintBattery(QPainter *p, const QRect &contentsRect, const int batteryPercent, const bool plugState);
00109         /* Paint a label on top of the battery */
00110         void paintLabel(QPainter *p, const QRect &contentsRect, const QString& labelText);
00111         /* Scale in/out Battery. */
00112         void showBattery(bool show);
00113         /* Scale in/out Ac Adapter. */
00114         void showAcAdapter(bool show);
00115         /* Fade in/out the label above the battery. */
00116         void showLabel(bool show);
00117         /* Scale in a QRectF */
00118         QRectF scaleRectF(qreal progress, QRectF rect);
00119         /* Show multiple batteries with individual icons and charge info? */
00120         bool m_showMultipleBatteries;
00121         /* Should the battery charge information be shown on top? */
00122         bool m_showBatteryString;
00123         QSizeF m_size;
00124         int m_pixelSize;
00125         Plasma::Svg* m_theme;
00126 
00127         QStringList m_availableProfiles;
00128         QString m_currentProfile;
00129         QStringList m_suspendMethods;
00130 
00131         // Configuration dialog
00132         Ui::batteryConfig ui;
00133 
00134         int m_animId;
00135         qreal m_alpha;
00136         bool m_fadeIn;
00137 
00138         int m_acAnimId;
00139         qreal m_acAlpha;
00140         bool m_acFadeIn;
00141 
00142         int m_batteryAnimId;
00143         qreal m_batteryAlpha;
00144         bool m_batteryFadeIn;
00145 
00146         // Internal data
00147         QList<QVariant> batterylist, acadapterlist;
00148         QHash<QString, QHash<QString, QVariant> > m_batteries_data;
00149         QFont m_font;
00150         bool m_isHovered;
00151         bool m_firstRun;
00152         QColor m_boxColor;
00153         QColor m_textColor;
00154         QRectF m_textRect;
00155         int m_boxAlpha;
00156         int m_boxHoverAlpha;
00157         int m_numOfBattery;
00158         bool m_acadapter_plugged;
00159         int m_remainingMSecs;
00160 };
00161 
00162 K_EXPORT_PLASMA_APPLET(battery, Battery)
00163 
00164 #endif

Applets

Skip menu "Applets"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal