Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / libs / plasma / scripting / appletscript.h
blobdefdc8816c1e2a3f3b58b3cfc442ebc6c2efe8b1
1 /*
2 * Copyright 2007 by Aaron Seigo <aseigo@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #ifndef PLASMA_APPLETSCRIPT_H
21 #define PLASMA_APPLETSCRIPT_H
24 #include <QtCore/QObject>
25 #include <QtCore/QRect>
26 #include <QtCore/QSizeF>
28 #include <KGenericFactory>
30 #include <plasma/plasma_export.h>
31 #include <plasma/scripting/scriptengine.h>
33 class QPainter;
34 class QStyleOptionGraphicsItem;
36 namespace Plasma
39 class PLASMA_EXPORT AppletScript : public ScriptEngine
41 Q_OBJECT
43 public:
44 /**
45 * Default constructor for an AppletScript.
46 * Subclasses should not attempt to access the Plasma::Applet
47 * associated with this AppletScript in the constructor. All
48 * such set up that requires the Applet itself should be done
49 * in the init() method.
51 explicit AppletScript(QObject *parent = 0);
52 ~AppletScript();
54 /**
55 * Sets the applet associated with this AppletScript
57 void setApplet(Plasma::Applet *applet);
59 /**
60 * Returns the Plasma::Applet associated with this script component
62 Plasma::Applet* applet() const;
64 /**
65 * Called when the script should paint the applet
67 * @param painter the QPainter to use
68 * @param option the style option containing such flags as selection, level of detail, etc
69 **/
70 virtual void paintInterface(QPainter* painter,
71 const QStyleOptionGraphicsItem* option,
72 const QRect &contentsRect);
74 /**
75 * Called to discover the content size hint for the item.
76 * The default implementation simply returns the Applet's contentSizeHint
78 virtual QSizeF contentSizeHint() const;
80 Q_INVOKABLE QSizeF size() const;
82 protected:
83 /**
84 * @arg engine name of the engine
85 * @return a data engine associated with this plasmoid
87 Q_INVOKABLE DataEngine* dataEngine(const QString &engine) const;
89 /**
90 * @return absolute path to the main script file for this plasmoid
91 **/
92 QString mainScript() const;
94 /**
95 * @return the Package associated with this plasmoid which can
96 * be used to request resources, such as images and
97 * interface files.
99 const Package* package() const;
101 private:
102 class Private;
103 Private * const d;
106 #define K_EXPORT_PLASMA_APPLETSCRIPTENGINE(libname, classname) \
107 K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
108 K_EXPORT_PLUGIN(factory("plasma_appletscriptengine_" #libname))
110 } //Plasma namespace
112 #endif