00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00309 static QStringList listCategories(const QString &parentApp = QString(),
00310 bool visibleOnly = true);
00311
00318 void setCustomCategories(const QStringList &categories);
00319
00324 QStringList customCategories();
00325
00340 static Applet *loadPlasmoid(const QString &path, uint appletId = 0,
00341 const QVariantList &args = QVariantList());
00342
00356 static Applet *load(const QString &name, uint appletId = 0,
00357 const QVariantList &args = QVariantList());
00358
00372 static Applet *load(const KPluginInfo &info, uint appletId = 0,
00373 const QVariantList &args = QVariantList());
00374
00380 static QString category(const KPluginInfo &applet);
00381
00387 static QString category(const QString &appletName);
00388
00397 virtual void paintInterface(QPainter *painter,
00398 const QStyleOptionGraphicsItem *option,
00399 const QRect &contentsRect);
00400
00407 QString name() const;
00408
00412 QFont font() const;
00413
00417 QString pluginName() const;
00418
00425 bool shouldConserveResources() const;
00426
00430 QString icon() const;
00431
00436 QString category() const;
00437
00441 ImmutabilityType immutability() const;
00442
00443 void paintWindowFrame(QPainter *painter,
00444 const QStyleOptionGraphicsItem *option, QWidget *widget);
00445
00451 bool hasFailedToLaunch() const;
00452
00456 bool isBusy() const;
00457
00462 bool configurationRequired() const;
00463
00467 bool hasConfigurationInterface() const;
00468
00478 virtual QList<QAction*> contextualActions();
00479
00483 QAction *action(QString name) const;
00484
00488 void addAction(QString name, QAction *action);
00489
00495 void setBackgroundHints(const BackgroundHints hints);
00496
00501 BackgroundHints backgroundHints() const;
00502
00506 bool isContainment() const;
00507
00517 QRect screenRect() const;
00518
00522 int type() const;
00523 enum {
00524 Type = Plasma::AppletType
00525 };
00526
00530 Containment *containment() const;
00531
00535 void setGlobalShortcut(const KShortcut &shortcut);
00536
00541 KShortcut globalShortcut() const;
00542
00548 virtual bool isPopupShowing() const;
00549
00554 virtual void addAssociatedWidget(QWidget *widget);
00555
00560 virtual void removeAssociatedWidget(QWidget *widget);
00561
00579 virtual void initExtenderItem(ExtenderItem *item);
00580
00588 explicit Applet(QGraphicsItem *parent = 0,
00589 const QString &serviceId = QString(),
00590 uint appletId = 0);
00591
00602 explicit Applet(QGraphicsItem *parent,
00603 const QString &serviceId,
00604 uint appletId,
00605 const QVariantList &args);
00606
00607
00612 bool destroyed() const;
00613
00622 virtual void createConfigurationInterface(KConfigDialog *parent);
00623
00629 bool hasAuthorization(const QString &constraint) const;
00630
00631 Q_SIGNALS:
00638 void releaseVisualFocus();
00639
00644 void geometryChanged();
00645
00649 void appletTransformedByUser();
00650
00654 void appletTransformedItself();
00655
00659 void sizeHintChanged(Qt::SizeHint which);
00660
00669 void configNeedsSaving();
00670
00675 void activate();
00676
00683 void messageButtonPressed(const MessageButton button);
00684
00688 void appletDestroyed(Plasma::Applet *applet);
00689
00690
00694 void extenderItemRestored(Plasma::ExtenderItem *item);
00695
00696 public Q_SLOTS:
00702 void setImmutability(const ImmutabilityType immutable);
00703
00708 virtual void destroy();
00709
00721 virtual void showConfigurationInterface();
00722
00726 void raise();
00727
00731 void lower();
00732
00737 void flushPendingConstraintsEvents();
00738
00749 virtual void init();
00750
00754 virtual void configChanged();
00755
00760 void setBusy(bool busy);
00761
00766 QVariantList startupArguments() const;
00767
00768 protected:
00779 Applet(QObject *parent, const QVariantList &args);
00780
00793 void setFailedToLaunch(bool failed, const QString &reason = QString());
00794
00804 virtual void saveState(KConfigGroup &config) const;
00805
00815 void setHasConfigurationInterface(bool hasInterface);
00816
00828 void setConfigurationRequired(bool needsConfiguring, const QString &reason = QString());
00829
00844 void showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons);
00845
00858 virtual void constraintsEvent(Plasma::Constraints constraints);
00859
00869 void registerAsDragHandle(QGraphicsItem *item);
00870
00876 void unregisterAsDragHandle(QGraphicsItem *item);
00877
00882 bool isRegisteredAsDragHandle(QGraphicsItem *item);
00883
00887 Extender *extender() const;
00888
00892 bool eventFilter(QObject *o, QEvent *e);
00893
00897 bool sceneEventFilter (QGraphicsItem *watched, QEvent *event);
00898
00902 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
00903
00907 void focusInEvent(QFocusEvent *event);
00908
00912 void resizeEvent(QGraphicsSceneResizeEvent *event);
00913
00917 QVariant itemChange(GraphicsItemChange change, const QVariant &value);
00918
00922 QPainterPath shape() const;
00923
00927 QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
00928
00932 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
00933
00937 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
00938
00942 void timerEvent (QTimerEvent *event);
00943
00944 private:
00953 Applet(const QString &packagePath, uint appletId, const QVariantList &args);
00954
00955 Q_PRIVATE_SLOT(d, void setFocus())
00956 Q_PRIVATE_SLOT(d, void checkImmutability())
00957 Q_PRIVATE_SLOT(d, void themeChanged())
00958 Q_PRIVATE_SLOT(d, void appletAnimationComplete(QGraphicsItem *item,
00959 Plasma::Animator::Animation anim))
00960 Q_PRIVATE_SLOT(d, void selectItemToDestroy())
00961 Q_PRIVATE_SLOT(d, void updateRect(const QRectF& rect))
00962 Q_PRIVATE_SLOT(d, void destroyMessageOverlay())
00963 Q_PRIVATE_SLOT(d, void clearShortcutEditorPtr())
00964 Q_PRIVATE_SLOT(d, void configDialogFinished())
00965 Q_PRIVATE_SLOT(d, void updateShortcuts())
00966
00970 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00971
00972 AppletPrivate *const d;
00973
00974
00975 friend class Corona;
00976 friend class CoronaPrivate;
00977 friend class Containment;
00978 friend class ContainmentPrivate;
00979 friend class AppletScript;
00980 friend class AppletHandle;
00981 friend class AppletPrivate;
00982 friend class PopupApplet;
00983 friend class PopupAppletPrivate;
00984
00985 friend class Extender;
00986 friend class ExtenderGroup;
00987 friend class ExtenderGroupPrivate;
00988 friend class ExtenderPrivate;
00989 friend class ExtenderItem;
00990 };
00991
00992 }
00993
00994 Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Applet::BackgroundHints)
00995
00999 #define K_EXPORT_PLASMA_APPLET(libname, classname) \
01000 K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
01001 K_EXPORT_PLUGIN(factory("plasma_applet_" #libname)) \
01002 K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
01003
01004 #endif // multiple inclusion guard