2007-07-23 09:42:29 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-08-06 13:20:02 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
2007-07-23 09:42:29 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2008-01-25 01:04:03 +01:00
|
|
|
#ifndef PLASMA_APPLETSCRIPT_H
|
|
|
|
#define PLASMA_APPLETSCRIPT_H
|
2007-07-23 09:42:29 +02:00
|
|
|
|
2007-11-29 05:30:48 +01:00
|
|
|
|
2007-07-23 09:42:29 +02:00
|
|
|
#include <QtCore/QObject>
|
2007-11-29 05:30:48 +01:00
|
|
|
#include <QtCore/QRect>
|
2007-07-23 11:21:45 +02:00
|
|
|
#include <QtCore/QSizeF>
|
|
|
|
|
2008-03-14 00:35:06 +01:00
|
|
|
#include <KDE/KGenericFactory>
|
2008-02-26 06:07:15 +01:00
|
|
|
|
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
#include <plasma/scripting/scriptengine.h>
|
|
|
|
|
2008-03-02 22:36:59 +01:00
|
|
|
class QAction;
|
2007-07-23 11:21:45 +02:00
|
|
|
class QPainter;
|
|
|
|
class QStyleOptionGraphicsItem;
|
2007-07-23 09:42:29 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-01-25 01:04:03 +01:00
|
|
|
class PLASMA_EXPORT AppletScript : public ScriptEngine
|
2007-07-23 09:42:29 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
2008-01-25 01:04:03 +01:00
|
|
|
* Default constructor for an AppletScript.
|
|
|
|
* Subclasses should not attempt to access the Plasma::Applet
|
|
|
|
* associated with this AppletScript in the constructor. All
|
|
|
|
* such set up that requires the Applet itself should be done
|
|
|
|
* in the init() method.
|
|
|
|
*/
|
|
|
|
explicit AppletScript(QObject *parent = 0);
|
|
|
|
~AppletScript();
|
2007-07-23 09:42:29 +02:00
|
|
|
|
|
|
|
/**
|
2008-01-25 01:04:03 +01:00
|
|
|
* Sets the applet associated with this AppletScript
|
|
|
|
*/
|
|
|
|
void setApplet(Plasma::Applet *applet);
|
2007-07-23 09:42:29 +02:00
|
|
|
|
|
|
|
/**
|
2008-01-25 01:04:03 +01:00
|
|
|
* Returns the Plasma::Applet associated with this script component
|
|
|
|
*/
|
|
|
|
Plasma::Applet* applet() const;
|
2007-07-23 09:42:29 +02:00
|
|
|
|
2007-07-23 11:21:45 +02:00
|
|
|
/**
|
|
|
|
* Called when the script should paint the applet
|
|
|
|
*
|
|
|
|
* @param painter the QPainter to use
|
|
|
|
* @param option the style option containing such flags as selection, level of detail, etc
|
2008-03-02 22:36:59 +01:00
|
|
|
*/
|
2008-01-25 01:04:03 +01:00
|
|
|
virtual void paintInterface(QPainter* painter,
|
|
|
|
const QStyleOptionGraphicsItem* option,
|
|
|
|
const QRect &contentsRect);
|
2007-07-23 11:21:45 +02:00
|
|
|
|
2008-03-02 22:36:59 +01:00
|
|
|
/**
|
|
|
|
* Returns the area within which contents can be painted.
|
|
|
|
**/
|
2007-11-29 21:39:42 +01:00
|
|
|
Q_INVOKABLE QSizeF size() const;
|
2007-07-23 11:21:45 +02:00
|
|
|
|
2008-03-02 22:36:59 +01:00
|
|
|
/**
|
|
|
|
* Called when any of the geometry constraints have been updated.
|
|
|
|
*
|
|
|
|
* This is always called prior to painting and should be used as an
|
|
|
|
* opportunity to layout the widget, calculate sizings, etc.
|
|
|
|
*
|
|
|
|
* Do not call update() from this method; an update() will be triggered
|
|
|
|
* at the appropriate time for the applet.
|
|
|
|
*
|
|
|
|
* @param constraints the type of constraints that were updated
|
|
|
|
*/
|
2008-04-27 13:23:09 +02:00
|
|
|
virtual void constraintsEvent(Plasma::Constraints constraints);
|
2008-03-02 22:36:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of context-related QAction instances.
|
|
|
|
*
|
|
|
|
* @return A list of actions. The default implementation returns an
|
|
|
|
* empty list.
|
|
|
|
*/
|
2008-04-25 21:55:24 +02:00
|
|
|
virtual QList<QAction*> contextualActions();
|
2008-03-02 22:36:59 +01:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a configuration dialog.
|
|
|
|
*/
|
|
|
|
virtual void showConfigurationInterface();
|
|
|
|
|
2007-07-23 09:42:29 +02:00
|
|
|
protected:
|
|
|
|
/**
|
2008-01-25 01:04:03 +01:00
|
|
|
* @arg engine name of the engine
|
|
|
|
* @return a data engine associated with this plasmoid
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE DataEngine* dataEngine(const QString &engine) const;
|
2007-07-23 09:42:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return absolute path to the main script file for this plasmoid
|
2008-03-02 22:36:59 +01:00
|
|
|
*/
|
2007-07-23 09:42:29 +02:00
|
|
|
QString mainScript() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the Package associated with this plasmoid which can
|
|
|
|
* be used to request resources, such as images and
|
|
|
|
* interface files.
|
|
|
|
*/
|
|
|
|
const Package* package() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class Private;
|
|
|
|
Private * const d;
|
|
|
|
};
|
|
|
|
|
2008-01-25 01:04:03 +01:00
|
|
|
#define K_EXPORT_PLASMA_APPLETSCRIPTENGINE(libname, classname) \
|
2007-08-29 05:00:00 +02:00
|
|
|
K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
|
2008-01-25 01:04:03 +01:00
|
|
|
K_EXPORT_PLUGIN(factory("plasma_appletscriptengine_" #libname))
|
2007-07-23 09:42:29 +02:00
|
|
|
|
2008-01-25 01:04:03 +01:00
|
|
|
} //Plasma namespace
|
2007-07-23 09:42:29 +02:00
|
|
|
|
|
|
|
#endif
|