Using PopupApplets with script engines without subclassing them
Richard Dale
richard.j.dale at gmail.com
Fri May 1 17:00:20 CEST 2009
I recently added a PopupApplet service that allows applet scripting
engines to use Plasma::PopupApplets. However, the C++ api assumes that
the applet can be sub-classed, and that isn't possible with the
scripting engine api.
To use an ExtenderItem with an Applet you need to be able to override
Applet::initExtenderItem() method. In addition the PopApplet class has
two virtual methods that need to be overridden, widget() and
graphicsWidget(), if you want to associate a QWidget or
QGraphicsWidget with the applet:
/**
* Implement either this function or graphicsWidget().
* @return the widget that will get shown in either a layout, in
the applet or in a Dialog,
* depending on the form factor of the applet.
*/
virtual QWidget *widget();
/**
* Implement either this function or widget().
* @return the widget that will get shown in either a layout, in
the applet or in a Dialog,
* depending on the form factor of the applet.
*/
virtual QGraphicsWidget *graphicsWidget();
The default implementation of graphicsWidget() returns any Extender
that is associated with the popup:
QGraphicsWidget *PopupApplet::graphicsWidget()
{
return static_cast<Applet*>(this)->d->extender;
}
So if you create an Extender in a scripting language with your applet
as the parent, you can customize the behaviour of graphicsWidget()
because it will return your Extender.
So I've been thinking about what is the minimum change to allow
scripting applets to use Extenders and avoid any BIC problems. The
attached patch adds a setWidget() method to Plasma::PopupApplet, along
with an instance variable in the d pointer to hold the value. Existing
implementations of PopupApplet::widget() should carry on working find.
To handle initExtenderItem() I've added a initScriptExtenderItem()
signal to Plasma::Applet which is emitted by
Applet::initExtenderItem() when the applet has an associated script.
It is up to the script engine to connect to the signal and do
something appropriate. It wasn't posssible to add an
initExtenderItem() virtual method to appletscripting.h as I assume
that would be BIC.
The case where is QGraphicsItem which isn't an ExtenderItem, is
returned by PopupApplet::graphicsWidget() isn't handled. Should it be,
and if so could it be added to the PopupApplet d pointer, with a
setGraphicsWidget() method to set it. Or is it a rare use case that
isn't really needed for scripting applets? In fact are Extenders a
rare use case not needed for scripting, and the patch is a bit
redundant?
-- Richard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: popupapplet_scripting.patch
Type: text/x-diff
Size: 3061 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/plasma-devel/attachments/20090501/e4452335/attachment.bin
More information about the Plasma-devel
mailing list