• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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 pluginName READ pluginName)
00083     Q_PROPERTY(QString category READ category)
00084     Q_PROPERTY(ImmutabilityType immutability READ immutability WRITE setImmutability)
00085     Q_PROPERTY(bool hasFailedToLaunch READ hasFailedToLaunch WRITE setFailedToLaunch)
00086     Q_PROPERTY(bool isBusy READ isBusy WRITE setBusy) //KDE5: remove
00087     Q_PROPERTY(bool busy READ isBusy WRITE setBusy)
00088     Q_PROPERTY(bool configurationRequired READ configurationRequired WRITE setConfigurationRequired)
00089     Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
00090     Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
00091     Q_PROPERTY(uint id READ id)
00092     Q_PROPERTY(bool userConfiguring READ isUserConfiguring)
00093     Q_PROPERTY(BackgroundHints backgroundHints READ backgroundHints WRITE setBackgroundHints)
00094     Q_ENUMS(BackgroundHints)
00095 
00096     public:
00097         typedef QList<Applet*> List;
00098         typedef QHash<QString, Applet*> Dict;
00099 
00103         enum BackgroundHint {
00104             NoBackground = 0,         
00106             StandardBackground = 1,   
00107             TranslucentBackground = 2, 
00109             DefaultBackground = StandardBackground 
00111         };
00112         Q_DECLARE_FLAGS(BackgroundHints, BackgroundHint)
00113 
00114         ~Applet();
00115 
00119         static PackageStructure::Ptr packageStructure();
00120 
00124         uint id() const;
00125 
00133         KConfigGroup config() const;
00134 
00142         KConfigGroup config(const QString &group) const;
00143 
00154         virtual void save(KConfigGroup &group) const;
00155 
00164         virtual void restore(KConfigGroup &group);
00165 
00173         KConfigGroup globalConfig() const;
00174 
00181         ConfigLoader *configScheme() const;
00182 
00200         Q_INVOKABLE DataEngine *dataEngine(const QString &name) const;
00201 
00208         const Package *package() const;
00209 
00216         QGraphicsView *view() const;
00217 
00223         QRectF mapFromView(const QGraphicsView *view, const QRect &rect) const;
00224 
00230         QRect mapToView(const QGraphicsView *view, const QRectF &rect) const;
00231 
00238         QPoint popupPosition(const QSize &s) const;
00239 
00248         QPoint popupPosition(const QSize &s, Qt::AlignmentFlag alignment) const;
00249 
00257         void updateConstraints(Plasma::Constraints constraints = Plasma::AllConstraints);
00258 
00264         virtual FormFactor formFactor() const;
00265 
00271         virtual Location location() const;
00272 
00276         Context *context() const;
00277 
00281         Plasma::AspectRatioMode aspectRatioMode() const;
00282 
00286         void setAspectRatioMode(Plasma::AspectRatioMode);
00287 
00305         static KPluginInfo::List listAppletInfo(const QString &category = QString(),
00306                                                 const QString &parentApp = QString());
00307 
00313         static KPluginInfo::List listAppletInfoForMimetype(const QString &mimetype);
00314 
00321         static KPluginInfo::List listAppletInfoForUrl(const QUrl &url);
00322 
00334         static QStringList listCategories(const QString &parentApp = QString(),
00335                                           bool visibleOnly = true);
00336 
00343         void setCustomCategories(const QStringList &categories);
00344 
00349         QStringList customCategories();
00350 
00365         static Applet *loadPlasmoid(const QString &path, uint appletId = 0,
00366                                     const QVariantList &args = QVariantList());
00367 
00381         static Applet *load(const QString &name, uint appletId = 0,
00382                             const QVariantList &args = QVariantList());
00383 
00397         static Applet *load(const KPluginInfo &info, uint appletId = 0,
00398                             const QVariantList &args = QVariantList());
00399 
00405         static QString category(const KPluginInfo &applet);
00406 
00412         static QString category(const QString &appletName);
00413 
00422         virtual void paintInterface(QPainter *painter,
00423                                     const QStyleOptionGraphicsItem *option,
00424                                     const QRect &contentsRect);
00425 
00432         QString name() const;
00433 
00437         QFont font() const;
00438 
00442         QString pluginName() const;
00443 
00450         bool shouldConserveResources() const;
00451 
00455         QString icon() const;
00456 
00461         QString category() const;
00462 
00466         ImmutabilityType immutability() const;
00467 
00468         void paintWindowFrame(QPainter *painter,
00469                               const QStyleOptionGraphicsItem *option, QWidget *widget);
00470 
00476         bool hasFailedToLaunch() const;
00477 
00481         bool isBusy() const;
00482 
00487         bool configurationRequired() const;
00488 
00492         bool hasConfigurationInterface() const;
00493 
00503         virtual QList<QAction*> contextualActions();
00504 
00508         Q_INVOKABLE QAction *action(QString name) const;
00509 
00513         void addAction(QString name, QAction *action);
00514 
00520         void setBackgroundHints(const BackgroundHints hints);
00521 
00526         BackgroundHints backgroundHints() const;
00527 
00531         bool isContainment() const;
00532 
00542         QRect screenRect() const;
00543 
00547         int type() const;
00548         enum {
00549             Type = Plasma::AppletType
00550         };
00551 
00555         Containment *containment() const;
00556 
00560         void setGlobalShortcut(const KShortcut &shortcut);
00561 
00566         KShortcut globalShortcut() const;
00567 
00573         virtual bool isPopupShowing() const;
00574 
00579         virtual void addAssociatedWidget(QWidget *widget);
00580 
00585         virtual void removeAssociatedWidget(QWidget *widget);
00586 
00604         virtual void initExtenderItem(ExtenderItem *item);
00605 
00613         explicit Applet(QGraphicsItem *parent = 0,
00614                         const QString &serviceId = QString(),
00615                         uint appletId = 0);
00616 
00624         explicit Applet(const KPluginInfo &info, QGraphicsItem *parent = 0, uint appletId = 0);
00625 
00636         explicit Applet(QGraphicsItem *parent,
00637                         const QString &serviceId,
00638                         uint appletId,
00639                         const QVariantList &args);
00640 
00641 
00646         bool destroyed() const;
00647 
00671         virtual void createConfigurationInterface(KConfigDialog *parent);
00672 
00678         bool hasAuthorization(const QString &constraint) const;
00679 
00691         void setAssociatedApplication(const QString &string);
00692 
00700         void setAssociatedApplicationUrls(const KUrl::List &urls);
00701 
00706         QString associatedApplication() const;
00707 
00712         KUrl::List associatedApplicationUrls() const;
00713 
00718         bool hasValidAssociatedApplication() const;
00719 
00720     Q_SIGNALS:
00727         void releaseVisualFocus();
00728 
00729 #if QT_VERSION >= 0x040700
00730     protected:
00731         void geometryChanged(); // in QGraphicsWidget now; preserve BC
00732 #else
00733 
00737         void geometryChanged();
00738 #endif
00739 
00740     Q_SIGNALS:
00744         void appletTransformedByUser();
00745 
00749         void appletTransformedItself();
00750 
00754         void sizeHintChanged(Qt::SizeHint which);
00755 
00764         void configNeedsSaving();
00765 
00770         void activate();
00771 
00779         void messageButtonPressed(const Plasma::MessageButton button);
00780 
00784         void appletDestroyed(Plasma::Applet *applet);
00785 
00790         void newStatus(Plasma::ItemStatus status);
00791 
00795         void extenderItemRestored(Plasma::ExtenderItem *item);
00796 
00801         void immutabilityChanged(Plasma::ImmutabilityType immutable);
00802 
00803     public Q_SLOTS:
00809         void setImmutability(const ImmutabilityType immutable);
00810 
00815         virtual void destroy();
00816 
00830         virtual void showConfigurationInterface();
00831 
00840         void showConfigurationInterface(QWidget *widget);
00841 
00846         bool isUserConfiguring() const;
00847 
00851         void raise();
00852 
00856         void lower();
00857 
00862         void flushPendingConstraintsEvents();
00863 
00874         virtual void init();
00875 
00879         virtual void configChanged();
00880 
00885         void setBusy(bool busy);
00886 
00891         QVariantList startupArguments() const;
00892 
00897         ItemStatus status() const;
00898 
00903         void setStatus(const ItemStatus stat);
00904 
00911         void publish(Plasma::AnnouncementMethods methods, const QString &resourceName);
00912 
00913         void unpublish();
00914 
00915         bool isPublished() const;
00916 
00925         void runAssociatedApplication();
00926 
00927     protected:
00938         Applet(QObject *parent, const QVariantList &args);
00939 
00952         void setFailedToLaunch(bool failed, const QString &reason = QString());
00953 
00963         virtual void saveState(KConfigGroup &config) const;
00964 
00974         void setHasConfigurationInterface(bool hasInterface);
00975 
00987         void setConfigurationRequired(bool needsConfiguring, const QString &reason = QString());
00988 
01003         void showMessage(const QIcon &icon, const QString &message, const Plasma::MessageButtons buttons);
01004 
01017         virtual void constraintsEvent(Plasma::Constraints constraints);
01018 
01028         void registerAsDragHandle(QGraphicsItem *item);
01029 
01035         void unregisterAsDragHandle(QGraphicsItem *item);
01036 
01041         bool isRegisteredAsDragHandle(QGraphicsItem *item);
01042 
01046         Extender *extender() const;
01047 
01051         bool eventFilter(QObject *o, QEvent *e);
01052 
01056         bool sceneEventFilter (QGraphicsItem *watched, QEvent *event);
01057 
01061         void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
01062 
01066         void focusInEvent(QFocusEvent *event);
01067 
01071         void resizeEvent(QGraphicsSceneResizeEvent *event);
01072 
01076         QVariant itemChange(GraphicsItemChange change, const QVariant &value);
01077 
01081         QPainterPath shape() const;
01082 
01086         QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
01087 
01091         void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
01092 
01096         void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
01097 
01101         void timerEvent (QTimerEvent *event);
01102 
01103 
01104     private:
01113         Applet(const QString &packagePath, uint appletId, const QVariantList &args);
01114 
01115         Q_PRIVATE_SLOT(d, void setFocus())
01116         Q_PRIVATE_SLOT(d, void themeChanged())
01117         Q_PRIVATE_SLOT(d, void cleanUpAndDelete())
01118         Q_PRIVATE_SLOT(d, void selectItemToDestroy())
01119         Q_PRIVATE_SLOT(d, void updateRect(const QRectF& rect))
01120         Q_PRIVATE_SLOT(d, void destroyMessageOverlay())
01121         Q_PRIVATE_SLOT(d, void clearShortcutEditorPtr())
01122         Q_PRIVATE_SLOT(d, void configDialogFinished())
01123         Q_PRIVATE_SLOT(d, void updateShortcuts())
01124         Q_PRIVATE_SLOT(d, void publishCheckboxStateChanged(int state))
01125         Q_PRIVATE_SLOT(d, void globalShortcutChanged())
01126         Q_PRIVATE_SLOT(d, void propagateConfigChanged())
01127         Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle))
01128 
01132         void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
01133 
01134         AppletPrivate *const d;
01135 
01136         //Corona needs to access setFailedToLaunch and init
01137         friend class Corona;
01138         friend class CoronaPrivate;
01139         friend class Containment;
01140         friend class ContainmentPrivate;
01141         friend class AppletScript;
01142         friend class AppletHandle;
01143         friend class AppletPrivate;
01144         friend class AccessAppletJobPrivate;
01145         friend class PluginLoader;
01146         friend class PopupApplet;
01147         friend class PopupAppletPrivate;
01148         friend class AssociatedApplicationManager;
01149 
01150         friend class Extender;
01151         friend class ExtenderGroup;
01152         friend class ExtenderGroupPrivate;
01153         friend class ExtenderPrivate;
01154         friend class ExtenderItem;
01155 };
01156 
01157 } // Plasma namespace
01158 
01159 Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Applet::BackgroundHints)
01160 
01164 #define K_EXPORT_PLASMA_APPLET(libname, classname) \
01165 K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
01166 K_EXPORT_PLUGIN(factory("plasma_applet_" #libname)) \
01167 K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
01168 
01169 #endif // multiple inclusion guard

Plasma

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

kdelibs

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