• Skip to content
  • Skip to link menu
KDE 4.6 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 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) //KDE5: remove
00086     Q_PROPERTY(bool busy READ isBusy WRITE setBusy)
00087     Q_PROPERTY(bool configurationRequired READ configurationRequired WRITE setConfigurationRequired)
00088     Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
00089     Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
00090     Q_PROPERTY(uint id READ id)
00091     Q_PROPERTY(bool userConfiguring READ isUserConfiguring)
00092 
00093     public:
00094         typedef QList<Applet*> List;
00095         typedef QHash<QString, Applet*> Dict;
00096 
00100         enum BackgroundHint {
00101             NoBackground = 0,         
00103             StandardBackground = 1,   
00104             TranslucentBackground = 2, 
00106             DefaultBackground = StandardBackground 
00108         };
00109         Q_DECLARE_FLAGS(BackgroundHints, BackgroundHint)
00110 
00111         ~Applet();
00112 
00116         static PackageStructure::Ptr packageStructure();
00117 
00121         uint id() const;
00122 
00130         KConfigGroup config() const;
00131 
00139         KConfigGroup config(const QString &group) const;
00140 
00151         virtual void save(KConfigGroup &group) const;
00152 
00161         virtual void restore(KConfigGroup &group);
00162 
00170         KConfigGroup globalConfig() const;
00171 
00178         ConfigLoader *configScheme() const;
00179 
00197         Q_INVOKABLE DataEngine *dataEngine(const QString &name) const;
00198 
00205         const Package *package() const;
00206 
00213         QGraphicsView *view() const;
00214 
00220         QRectF mapFromView(const QGraphicsView *view, const QRect &rect) const;
00221 
00227         QRect mapToView(const QGraphicsView *view, const QRectF &rect) const;
00228 
00235         QPoint popupPosition(const QSize &s) const;
00236 
00245         QPoint popupPosition(const QSize &s, Qt::AlignmentFlag alignment) const;
00246 
00254         void updateConstraints(Plasma::Constraints constraints = Plasma::AllConstraints);
00255 
00261         virtual FormFactor formFactor() const;
00262 
00268         virtual Location location() const;
00269 
00273         Context *context() const;
00274 
00278         Plasma::AspectRatioMode aspectRatioMode() const;
00279 
00283         void setAspectRatioMode(Plasma::AspectRatioMode);
00284 
00302         static KPluginInfo::List listAppletInfo(const QString &category = QString(),
00303                                                 const QString &parentApp = QString());
00304 
00310         static KPluginInfo::List listAppletInfoForMimetype(const QString &mimetype);
00311 
00318         static KPluginInfo::List listAppletInfoForUrl(const QUrl &url);
00319 
00331         static QStringList listCategories(const QString &parentApp = QString(),
00332                                           bool visibleOnly = true);
00333 
00340         void setCustomCategories(const QStringList &categories);
00341 
00346         QStringList customCategories();
00347 
00362         static Applet *loadPlasmoid(const QString &path, uint appletId = 0,
00363                                     const QVariantList &args = QVariantList());
00364 
00378         static Applet *load(const QString &name, uint appletId = 0,
00379                             const QVariantList &args = QVariantList());
00380 
00394         static Applet *load(const KPluginInfo &info, uint appletId = 0,
00395                             const QVariantList &args = QVariantList());
00396 
00402         static QString category(const KPluginInfo &applet);
00403 
00409         static QString category(const QString &appletName);
00410 
00419         virtual void paintInterface(QPainter *painter,
00420                                     const QStyleOptionGraphicsItem *option,
00421                                     const QRect &contentsRect);
00422 
00429         QString name() const;
00430 
00434         QFont font() const;
00435 
00439         QString pluginName() const;
00440 
00447         bool shouldConserveResources() const;
00448 
00452         QString icon() const;
00453 
00458         QString category() const;
00459 
00463         ImmutabilityType immutability() const;
00464 
00465         void paintWindowFrame(QPainter *painter,
00466                               const QStyleOptionGraphicsItem *option, QWidget *widget);
00467 
00473         bool hasFailedToLaunch() const;
00474 
00478         bool isBusy() const;
00479 
00484         bool configurationRequired() const;
00485 
00489         bool hasConfigurationInterface() const;
00490 
00500         virtual QList<QAction*> contextualActions();
00501 
00505         QAction *action(QString name) const;
00506 
00510         void addAction(QString name, QAction *action);
00511 
00517         void setBackgroundHints(const BackgroundHints hints);
00518 
00523         BackgroundHints backgroundHints() const;
00524 
00528         bool isContainment() const;
00529 
00539         QRect screenRect() const;
00540 
00544         int type() const;
00545         enum {
00546             Type = Plasma::AppletType
00547         };
00548 
00552         Containment *containment() const;
00553 
00557         void setGlobalShortcut(const KShortcut &shortcut);
00558 
00563         KShortcut globalShortcut() const;
00564 
00570         virtual bool isPopupShowing() const;
00571 
00576         virtual void addAssociatedWidget(QWidget *widget);
00577 
00582         virtual void removeAssociatedWidget(QWidget *widget);
00583 
00601         virtual void initExtenderItem(ExtenderItem *item);
00602 
00610         explicit Applet(QGraphicsItem *parent = 0,
00611                         const QString &serviceId = QString(),
00612                         uint appletId = 0);
00613 
00621         explicit Applet(const KPluginInfo &info, QGraphicsItem *parent = 0, uint appletId = 0);
00622 
00633         explicit Applet(QGraphicsItem *parent,
00634                         const QString &serviceId,
00635                         uint appletId,
00636                         const QVariantList &args);
00637 
00638 
00643         bool destroyed() const;
00644 
00668         virtual void createConfigurationInterface(KConfigDialog *parent);
00669 
00675         bool hasAuthorization(const QString &constraint) const;
00676 
00688         void setAssociatedApplication(const QString &string);
00689 
00697         void setAssociatedApplicationUrls(const KUrl::List &urls);
00698 
00703         QString associatedApplication() const;
00704 
00709         KUrl::List associatedApplicationUrls() const;
00710 
00715         bool hasValidAssociatedApplication() const;
00716 
00717     Q_SIGNALS:
00724         void releaseVisualFocus();
00725 
00726 #if QT_VERSION >= 0x040700
00727     protected:
00728         void geometryChanged(); // in QGraphicsWidget now; preserve BC
00729 #else
00730 
00734         void geometryChanged();
00735 #endif
00736 
00737     Q_SIGNALS:
00741         void appletTransformedByUser();
00742 
00746         void appletTransformedItself();
00747 
00751         void sizeHintChanged(Qt::SizeHint which);
00752 
00761         void configNeedsSaving();
00762 
00767         void activate();
00768 
00776         void messageButtonPressed(const Plasma::MessageButton button);
00777 
00781         void appletDestroyed(Plasma::Applet *applet);
00782 
00787         void newStatus(Plasma::ItemStatus status);
00788 
00792         void extenderItemRestored(Plasma::ExtenderItem *item);
00793 
00798         void immutabilityChanged(Plasma::ImmutabilityType immutable);
00799 
00800     public Q_SLOTS:
00806         void setImmutability(const ImmutabilityType immutable);
00807 
00812         virtual void destroy();
00813 
00827         virtual void showConfigurationInterface();
00828 
00837         void showConfigurationInterface(QWidget *widget);
00838 
00843         bool isUserConfiguring() const;
00844 
00848         void raise();
00849 
00853         void lower();
00854 
00859         void flushPendingConstraintsEvents();
00860 
00871         virtual void init();
00872 
00876         virtual void configChanged();
00877 
00882         void setBusy(bool busy);
00883 
00888         QVariantList startupArguments() const;
00889 
00894         ItemStatus status() const;
00895 
00900         void setStatus(const ItemStatus stat);
00901 
00908         void publish(Plasma::AnnouncementMethods methods, const QString &resourceName);
00909 
00910         void unpublish();
00911 
00912         bool isPublished() const;
00913 
00922         void runAssociatedApplication();
00923 
00924     protected:
00935         Applet(QObject *parent, const QVariantList &args);
00936 
00949         void setFailedToLaunch(bool failed, const QString &reason = QString());
00950 
00960         virtual void saveState(KConfigGroup &config) const;
00961 
00971         void setHasConfigurationInterface(bool hasInterface);
00972 
00984         void setConfigurationRequired(bool needsConfiguring, const QString &reason = QString());
00985 
01000         void showMessage(const QIcon &icon, const QString &message, const Plasma::MessageButtons buttons);
01001 
01014         virtual void constraintsEvent(Plasma::Constraints constraints);
01015 
01025         void registerAsDragHandle(QGraphicsItem *item);
01026 
01032         void unregisterAsDragHandle(QGraphicsItem *item);
01033 
01038         bool isRegisteredAsDragHandle(QGraphicsItem *item);
01039 
01043         Extender *extender() const;
01044 
01048         bool eventFilter(QObject *o, QEvent *e);
01049 
01053         bool sceneEventFilter (QGraphicsItem *watched, QEvent *event);
01054 
01058         void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
01059 
01063         void focusInEvent(QFocusEvent *event);
01064 
01068         void resizeEvent(QGraphicsSceneResizeEvent *event);
01069 
01073         QVariant itemChange(GraphicsItemChange change, const QVariant &value);
01074 
01078         QPainterPath shape() const;
01079 
01083         QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
01084 
01088         void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
01089 
01093         void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
01094 
01098         void timerEvent (QTimerEvent *event);
01099 
01100 
01101     private:
01110         Applet(const QString &packagePath, uint appletId, const QVariantList &args);
01111 
01112         Q_PRIVATE_SLOT(d, void setFocus())
01113         Q_PRIVATE_SLOT(d, void themeChanged())
01114         Q_PRIVATE_SLOT(d, void cleanUpAndDelete())
01115         Q_PRIVATE_SLOT(d, void selectItemToDestroy())
01116         Q_PRIVATE_SLOT(d, void updateRect(const QRectF& rect))
01117         Q_PRIVATE_SLOT(d, void destroyMessageOverlay())
01118         Q_PRIVATE_SLOT(d, void clearShortcutEditorPtr())
01119         Q_PRIVATE_SLOT(d, void configDialogFinished())
01120         Q_PRIVATE_SLOT(d, void updateShortcuts())
01121         Q_PRIVATE_SLOT(d, void publishCheckboxStateChanged(int state))
01122         Q_PRIVATE_SLOT(d, void globalShortcutChanged())
01123 
01127         void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
01128 
01129         AppletPrivate *const d;
01130 
01131         //Corona needs to access setFailedToLaunch and init
01132         friend class Corona;
01133         friend class CoronaPrivate;
01134         friend class Containment;
01135         friend class ContainmentPrivate;
01136         friend class AppletScript;
01137         friend class AppletHandle;
01138         friend class AppletPrivate;
01139         friend class AccessAppletJobPrivate;
01140         friend class PluginLoader;
01141         friend class PopupApplet;
01142         friend class PopupAppletPrivate;
01143         friend class AssociatedApplicationManager;
01144 
01145         friend class Extender;
01146         friend class ExtenderGroup;
01147         friend class ExtenderGroupPrivate;
01148         friend class ExtenderPrivate;
01149         friend class ExtenderItem;
01150 };
01151 
01152 } // Plasma namespace
01153 
01154 Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Applet::BackgroundHints)
01155 
01159 #define K_EXPORT_PLASMA_APPLET(libname, classname) \
01160 K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
01161 K_EXPORT_PLUGIN(factory("plasma_applet_" #libname)) \
01162 K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
01163 
01164 #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
  • 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.3
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