Show customized context menu in applet and appletscript

Aaron J. Seigo aseigo at kde.org
Fri Oct 10 19:56:46 CEST 2008


On Thursday 09 October 2008, Dong Tiger wrote:
> Hi,
>
> For example, the context menu shown by folderview when right clicking on a
> file icon doesn't have menu items like "Remove this folder view" and
> "Desktop options". Folderview achieves this by reimplementing
> mousePressEvent.
>
> But in an AppletScript subclass, there is no mousePressEvent to
> reimplement.

it doesn't need one.

> Also I feel reimplementing mousePressEvent to handle
> customized context menu is a little overkill. I am thinking modifying
> contextualActions in Applet and AppletScript from QList<QAction*>
> contextualActions() to QList<QAction*> contextualActions(bool *appendable).
> If contexualActions set "appendable" flag to false, then the caller should
> not append more actions.

passing in booleans like that is API rape.

no, what should be done is this:

* if your applets are like any other widget in plasma, then return actions 
that represent their menu items and plasma will figure out what to do with 
them. the reason why applets don't get to choose is exactly to avoid people 
doing what you suggest in your email here ;) in this case, yes, Plasma knows 
better than the developer.

* if your applets can not participate with Plasma when it comes to context 
menus (for whatever reason), then catch the mouse events in a QGraphicsWidget 
that you add as the only child of the Plasma::Applet you are given. you can 
intercept all the events you wish that way, in fact. because this is possible, 
we provide the applet handle which is not under the Applet's control, so that 
the user will always, no matter what the Applet or ScriptApplet itself does, 
can still access the basics like "remove this widget"

now, doing the "intercept events" thing is not the best thing to do from a 
user's POV, becuse it diminishes the consistency between applets. that's why 
it isn't made super-easy to do and requires you to write a bit more code. it 
is possible to do, however, because i realized that in some cases it will be 
required.

in those few cases, the developer can put in that little bit of extra effort to 
circumvent Plasma. because it takes extra effort, i'm hoping it will make 
developers think twice before doing so.

-- 
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

KDE core developer sponsored by Qt Software

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/plasma-devel/attachments/20081010/a6a4e3be/attachment-0001.sig 


More information about the Plasma-devel mailing list