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

libplasma

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/QWidget>
00027 #include <QtGui/QGraphicsWidget>
00028 
00029 #include <KDE/KConfigGroup>
00030 #include <KDE/KGenericFactory>
00031 #include <KDE/KPluginInfo>
00032 #include <KDE/KShortcut>
00033 
00034 #include <plasma/configxml.h>
00035 #include <plasma/packagestructure.h>
00036 #include <plasma/plasma.h>
00037 #include <plasma/animator.h>
00038 #include <plasma/version.h>
00039 
00040 class KConfigDialog;
00041 class QGraphicsView;
00042 class KActionCollection;
00043 
00044 namespace Plasma
00045 {
00046 
00047 class Containment;
00048 class DataEngine;
00049 class Package;
00050 class AppletPrivate;
00051 
00068 class PLASMA_EXPORT Applet : public QGraphicsWidget
00069 {
00070     Q_OBJECT
00071     Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface)
00072     Q_PROPERTY(QString name READ name)
00073     Q_PROPERTY(QString category READ category)
00074     Q_PROPERTY(ImmutabilityType immutability READ immutability WRITE setImmutability)
00075     Q_PROPERTY(bool hasFailedToLaunch READ hasFailedToLaunch WRITE setFailedToLaunch)
00076     Q_PROPERTY(bool configurationRequired READ configurationRequired WRITE setConfigurationRequired)
00077     Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
00078     Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
00079 
00080     public:
00081         typedef QList<Applet*> List;
00082         typedef QHash<QString, Applet*> Dict;
00083 
00087         enum BackgroundHint { NoBackground = 0 ,
00088                               StandardBackground = 1 ,
00089                               TranslucentBackground = 2 ,
00090                               ShadowedBackground = 4 ,
00091                               DefaultBackground = StandardBackground | ShadowedBackground 
00092                             };
00093         Q_DECLARE_FLAGS(BackgroundHints, BackgroundHint)
00094 
00095         ~Applet();
00096 
00100         static PackageStructure::Ptr packageStructure();
00101 
00105         uint id() const;
00106 
00114         KConfigGroup config() const;
00115 
00123         KConfigGroup config(const QString &group) const;
00124 
00135         virtual void save(KConfigGroup &group) const;
00136 
00145         virtual void restore(KConfigGroup &group);
00146 
00154         KConfigGroup globalConfig() const;
00155 
00162         ConfigXml* configScheme() const;
00163 
00181         Q_INVOKABLE DataEngine* dataEngine(const QString& name) const;
00182 
00189         const Package* package() const;
00190 
00194         QGraphicsView *view() const;
00195 
00201         QRectF mapFromView(const QGraphicsView *view, const QRect &rect) const;
00202 
00208         QRect mapToView(const QGraphicsView *view, const QRectF &rect) const;
00209 
00216         QPoint popupPosition(const QSize &s) const;
00217 
00225         void updateConstraints(Plasma::Constraints constraints = Plasma::AllConstraints);
00226 
00232         virtual FormFactor formFactor() const;
00233 
00239         virtual Location location() const;
00240 
00244         Plasma::AspectRatioMode aspectRatioMode() const;
00245 
00249         void setAspectRatioMode(Plasma::AspectRatioMode);
00250 
00267         static KPluginInfo::List listAppletInfo(const QString &category = QString(),
00268                                               const QString &parentApp = QString());
00269 
00275         static KPluginInfo::List listAppletInfoForMimetype(const QString &mimetype);
00276 
00289         static QStringList listCategories(const QString &parentApp = QString(), bool visibleOnly = true);
00290 
00304         static Applet* load(const QString &name, uint appletId = 0,
00305                             const QVariantList& args = QVariantList());
00306 
00320         static Applet* load(const KPluginInfo& info, uint appletId = 0,
00321                                   const QVariantList& args = QVariantList());
00322 
00328         static QString category(const KPluginInfo& applet);
00329 
00335         static QString category(const QString& appletName);
00336 
00345         virtual void paintInterface(QPainter *painter,
00346                                     const QStyleOptionGraphicsItem *option,
00347                                     const QRect& contentsRect);
00348 
00355         QString name() const;
00356 
00360         QFont font() const;
00361 
00365         QString pluginName() const;
00366 
00373         bool shouldConserveResources() const;
00374 
00378         QString icon() const;
00379 
00384         QString category() const;
00385 
00389         ImmutabilityType immutability() const;
00390 
00391         void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
00392 
00398         bool hasFailedToLaunch() const;
00399 
00404         bool configurationRequired() const;
00405 
00409         bool hasConfigurationInterface() const;
00410 
00420         virtual QList<QAction*> contextualActions();
00421 
00425         QAction* action(QString name) const;
00426 
00430         void addAction(QString name, QAction *action);
00431 
00437         void setBackgroundHints(const BackgroundHints hints);
00438 
00443         BackgroundHints backgroundHints() const;
00444 
00448         bool isContainment() const;
00449 
00453         QRect screenRect() const;
00454 
00458         int type() const;
00459         enum { Type = Plasma::AppletType };
00460 
00464         Containment* containment() const;
00465 
00469         void setGlobalShortcut(const KShortcut &shortcut);
00470 
00475         KShortcut globalShortcut() const;
00476 
00481         virtual void addAssociatedWidget(QWidget *widget);
00482 
00487         virtual void removeAssociatedWidget(QWidget *widget);
00488 
00496         explicit Applet(QGraphicsItem* parent = 0,
00497                         const QString& serviceId = QString(),
00498                         uint appletId = 0);
00499 
00500     Q_SIGNALS:
00507         void releaseVisualFocus();
00508 
00513         void geometryChanged();
00514 
00523         void configNeedsSaving();
00524 
00529         void activate();
00530 
00531     public Q_SLOTS:
00536         void setImmutability(const ImmutabilityType immutable);
00537 
00542         virtual void destroy();
00543 
00555         virtual void showConfigurationInterface();
00556 
00560         void raise();
00561 
00565         void lower();
00566 
00571         void flushPendingConstraintsEvents();
00572 
00579         virtual void init();
00580 
00581     protected:
00592         Applet(QObject* parent, const QVariantList& args);
00593 
00606         void setFailedToLaunch(bool failed, const QString& reason = QString());
00607 
00617         virtual void saveState(KConfigGroup &config) const;
00618 
00628         void setHasConfigurationInterface(bool hasInterface);
00629 
00642         void setConfigurationRequired(bool needsConfiguring, const QString& reason = QString());
00643 
00652         virtual void createConfigurationInterface(KConfigDialog *parent);
00653 
00657         void setIsContainment(bool isContainment);
00658 
00671         virtual void constraintsEvent(Plasma::Constraints constraints);
00672 
00682         void registerAsDragHandle(QGraphicsItem *item);
00683 
00689         void unregisterAsDragHandle(QGraphicsItem *item);
00690 
00695         bool isRegisteredAsDragHandle(QGraphicsItem *item);
00696 
00700         bool eventFilter( QObject *o, QEvent *e );
00701 
00705         bool sceneEventFilter ( QGraphicsItem * watched, QEvent * event );
00706 
00710         void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
00711 
00715         void mousePressEvent(QGraphicsSceneMouseEvent *event);
00716 
00720         void focusInEvent(QFocusEvent *event);
00721 
00725         void resizeEvent(QGraphicsSceneResizeEvent *event);
00726 
00730         QVariant itemChange(GraphicsItemChange change, const QVariant &value);
00731 
00735         QPainterPath shape() const;
00736 
00740          QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
00741 
00745         void timerEvent (QTimerEvent *event);
00746 
00747     private:
00748         Q_PRIVATE_SLOT(d, void setFocus())
00749         Q_PRIVATE_SLOT(d, void checkImmutability())
00750         Q_PRIVATE_SLOT(d, void themeChanged())
00751         Q_PRIVATE_SLOT(d, void appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim))
00752         Q_PRIVATE_SLOT(d, void selectItemToDestroy())
00753 
00757         void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00758 
00759         AppletPrivate* const d;
00760 
00761         //Corona needs to access setFailedToLaunch and init
00762         friend class Corona;
00763         friend class CoronaPrivate;
00764         friend class Containment;
00765         friend class ContainmentPrivate;
00766         friend class AppletScript;
00767         friend class AppletHandle;
00768         friend class AppletPrivate;
00769 };
00770 
00771 } // Plasma namespace
00772 
00773 Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Applet::BackgroundHints)
00774 
00778 #define K_EXPORT_PLASMA_APPLET(libname, classname) \
00779 K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
00780 K_EXPORT_PLUGIN(factory("plasma_applet_" #libname)) \
00781 K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
00782 
00783 #endif // multiple inclusion guard

libplasma

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

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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