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

Plasma

applet.h

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2006-2007 by Aaron Seigo <aseigo@kde.org>
00003  *   Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org>
00004  *   Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
00005 
00006  *   This program is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU Library General Public License as
00008  *   published by the Free Software Foundation; either version 2, or
00009  *   (at your option) any later version.
00010  *
00011  *   This program is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details
00015  *
00016  *   You should have received a copy of the GNU Library General Public
00017  *   License along with this program; if not, write to the
00018  *   Free Software Foundation, Inc.,
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  */
00021 
00022 #ifndef PLASMA_APPLET_H
00023 #define PLASMA_APPLET_H
00024 
00025 #include <QtGui/QGraphicsItem>
00026 #include <QtGui/QGraphicsWidget>
00027 #include <QtGui/QIcon>
00028 
00029 #include <kconfiggroup.h>
00030 #include <kgenericfactory.h>
00031 #include <kplugininfo.h>
00032 #include <kshortcut.h>
00033 
00034 #include <plasma/configloader.h>
00035 #include <plasma/packagestructure.h>
00036 #include <plasma/plasma.h>
00037 #include <plasma/animator.h>
00038 #include <plasma/version.h>
00039 #include <plasma/framesvg.h>
00040 
00041 class QWidget;
00042 
00043 class KConfigDialog;
00044 class QGraphicsView;
00045 class KActionCollection;
00046 
00047 namespace Plasma
00048 {
00049 
00050 class AppletPrivate;
00051 class Containment;
00052 class Context;
00053 class DataEngine;
00054 class Extender;
00055 class ExtenderItem;
00056 class Package;
00057 
00058 
00077 class PLASMA_EXPORT Applet : public QGraphicsWidget
00078 {
00079     Q_OBJECT
00080     Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface)
00081     Q_PROPERTY(QString name READ name)
00082     Q_PROPERTY(QString category READ category)
00083     Q_PROPERTY(ImmutabilityType immutability READ immutability WRITE setImmutability)
00084     Q_PROPERTY(bool hasFailedToLaunch READ hasFailedToLaunch WRITE setFailedToLaunch)
00085     Q_PROPERTY(bool isBusy READ isBusy WRITE setBusy)
00086     Q_PROPERTY(bool configurationRequired READ configurationRequired WRITE setConfigurationRequired)
00087     Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
00088     Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
00089 
00090     public:
00091         typedef QList<Applet*> List;
00092         typedef QHash<QString, Applet*> Dict;
00093 
00097         enum BackgroundHint {
00098             NoBackground = 0,         
00100             StandardBackground = 1,   
00101             TranslucentBackground = 2, 
00103             DefaultBackground = StandardBackground 
00105         };
00106         Q_DECLARE_FLAGS(BackgroundHints, BackgroundHint)
00107 
00108         ~Applet();
00109 
00113         static PackageStructure::Ptr packageStructure();
00114 
00118         uint id() const;
00119 
00127         KConfigGroup config() const;
00128 
00136         KConfigGroup config(const QString &group) const;
00137 
00148         virtual void save(KConfigGroup &group) const;
00149 
00158         virtual void restore(KConfigGroup &group);
00159 
00167         KConfigGroup globalConfig() const;
00168 
00175         ConfigLoader *configScheme() const;
00176 
00194         Q_INVOKABLE DataEngine *dataEngine(const QString &name) const;
00195 
00202         const Package *package() const;
00203 
00210         QGraphicsView *view() const;
00211 
00217         QRectF mapFromView(const QGraphicsView *view, const QRect &rect) const;
00218 
00224         QRect mapToView(const QGraphicsView *view, const QRectF &rect) const;
00225 
00232         QPoint popupPosition(const QSize &s) const;
00233 
00241         void updateConstraints(Plasma::Constraints constraints = Plasma::AllConstraints);
00242 
00248         virtual FormFactor formFactor() const;
00249 
00255         virtual Location location() const;
00256 
00260         Context *context() const;
00261 
00265         Plasma::AspectRatioMode aspectRatioMode() const;
00266 
00270         void setAspectRatioMode(Plasma::AspectRatioMode);
00271 
00288         static KPluginInfo::List listAppletInfo(const QString &category = QString(),
00289                                               const QString &parentApp = QString());
00290 
00296         static KPluginInfo::List listAppletInfoForMimetype(const QString &mimetype);
00297 
00310         static QStringList listCategories(const QString &parentApp = QString(),
00311                                           bool visibleOnly = true);
00312 
00326         static Applet *load(const QString &name, uint appletId = 0,
00327                             const QVariantList &args = QVariantList());
00328 
00342         static Applet *load(const KPluginInfo &info, uint appletId = 0,
00343                             const QVariantList &args = QVariantList());
00344 
00350         static QString category(const KPluginInfo &applet);
00351 
00357         static QString category(const QString &appletName);
00358 
00367         virtual void paintInterface(QPainter *painter,
00368                                     const QStyleOptionGraphicsItem *option,
00369                                     const QRect &contentsRect);
00370 
00377         QString name() const;
00378 
00382         QFont font() const;
00383 
00387         QString pluginName() const;
00388 
00395         bool shouldConserveResources() const;
00396 
00400         QString icon() const;
00401 
00406         QString category() const;
00407 
00411         ImmutabilityType immutability() const;
00412 
00413         void paintWindowFrame(QPainter *painter,
00414                               const QStyleOptionGraphicsItem *option, QWidget *widget);
00415 
00421         bool hasFailedToLaunch() const;
00422 
00426         bool isBusy() const;
00427 
00432         bool configurationRequired() const;
00433 
00437         bool hasConfigurationInterface() const;
00438 
00448         virtual QList<QAction*> contextualActions();
00449 
00453         QAction *action(QString name) const;
00454 
00458         void addAction(QString name, QAction *action);
00459 
00465         void setBackgroundHints(const BackgroundHints hints);
00466 
00471         BackgroundHints backgroundHints() const;
00472 
00476         bool isContainment() const;
00477 
00487         QRect screenRect() const;
00488 
00492         int type() const;
00493         enum {
00494             Type = Plasma::AppletType
00495         };
00496 
00500         Containment *containment() const;
00501 
00505         void setGlobalShortcut(const KShortcut &shortcut);
00506 
00511         KShortcut globalShortcut() const;
00512 
00518         virtual bool isPopupShowing() const;
00519 
00524         virtual void addAssociatedWidget(QWidget *widget);
00525 
00530         virtual void removeAssociatedWidget(QWidget *widget);
00531 
00549         virtual void initExtenderItem(ExtenderItem *item);
00550 
00558         explicit Applet(QGraphicsItem *parent = 0,
00559                         const QString &serviceId = QString(),
00560                         uint appletId = 0);
00561 
00566         bool destroyed() const;
00567 
00568     Q_SIGNALS:
00575         void releaseVisualFocus();
00576 
00581         void geometryChanged();
00582 
00586         void sizeHintChanged(Qt::SizeHint which);
00587 
00596         void configNeedsSaving();
00597 
00602         void activate();
00603 
00604     public Q_SLOTS:
00610         void setImmutability(const ImmutabilityType immutable);
00611 
00616         virtual void destroy();
00617 
00629         virtual void showConfigurationInterface();
00630 
00634         void raise();
00635 
00639         void lower();
00640 
00645         void flushPendingConstraintsEvents();
00646 
00657         virtual void init();
00658 
00662         virtual void configChanged();
00663 
00668         void setBusy(bool busy);
00669 
00670     protected:
00681         Applet(QObject *parent, const QVariantList &args);
00682 
00695         void setFailedToLaunch(bool failed, const QString &reason = QString());
00696 
00706         virtual void saveState(KConfigGroup &config) const;
00707 
00717         void setHasConfigurationInterface(bool hasInterface);
00718 
00730         void setConfigurationRequired(bool needsConfiguring, const QString &reason = QString());
00731 
00740         virtual void createConfigurationInterface(KConfigDialog *parent);
00741 
00754         virtual void constraintsEvent(Plasma::Constraints constraints);
00755 
00765         void registerAsDragHandle(QGraphicsItem *item);
00766 
00772         void unregisterAsDragHandle(QGraphicsItem *item);
00773 
00778         bool isRegisteredAsDragHandle(QGraphicsItem *item);
00779 
00780 
00784         Extender *extender() const;
00785 
00789         bool eventFilter(QObject *o, QEvent *e);
00790 
00794         bool sceneEventFilter (QGraphicsItem *watched, QEvent *event);
00795 
00799         void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
00800 
00804         void focusInEvent(QFocusEvent *event);
00805 
00809         void resizeEvent(QGraphicsSceneResizeEvent *event);
00810 
00814         QVariant itemChange(GraphicsItemChange change, const QVariant &value);
00815 
00819         QPainterPath shape() const;
00820 
00824         QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
00825 
00829         void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
00830 
00834         void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
00835 
00839         void timerEvent (QTimerEvent *event);
00840 
00841     private:
00842         Q_PRIVATE_SLOT(d, void setFocus())
00843         Q_PRIVATE_SLOT(d, void checkImmutability())
00844         Q_PRIVATE_SLOT(d, void themeChanged())
00845         Q_PRIVATE_SLOT(d, void appletAnimationComplete(QGraphicsItem *item,
00846                                                        Plasma::Animator::Animation anim))
00847         Q_PRIVATE_SLOT(d, void selectItemToDestroy())
00848         Q_PRIVATE_SLOT(d, void updateRect(const QRectF& rect))
00849         Q_PRIVATE_SLOT(d, void destroyMessageOverlay())
00850         Q_PRIVATE_SLOT(d, void clearShortcutEditorPtr())
00851         Q_PRIVATE_SLOT(d, void configDialogFinished())
00852 
00856         void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00857 
00858         AppletPrivate *const d;
00859 
00860         //Corona needs to access setFailedToLaunch and init
00861         friend class Corona;
00862         friend class CoronaPrivate;
00863         friend class Containment;
00864         friend class ContainmentPrivate;
00865         friend class AppletScript;
00866         friend class AppletHandle;
00867         friend class AppletPrivate;
00868         friend class PopupApplet;
00869         friend class PopupAppletPrivate;
00870 
00871         friend class Extender;
00872         friend class ExtenderItem;
00873 };
00874 
00875 } // Plasma namespace
00876 
00877 Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Applet::BackgroundHints)
00878 
00882 #define K_EXPORT_PLASMA_APPLET(libname, classname) \
00883 K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
00884 K_EXPORT_PLUGIN(factory("plasma_applet_" #libname)) \
00885 K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
00886 
00887 #endif // multiple inclusion guard

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs 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