User:Chani/DevTips: Difference between revisions

From KDE TechBase
(dump of data from blog)
 
No edit summary
Line 11: Line 11:
when creating an applet, do as little as possible in the constructor. set a default size, and preferably no more. your ui creation, config reading, etc. should all go in init() instead. don’t read your size from the config, it’s done for you.
when creating an applet, do as little as possible in the constructor. set a default size, and preferably no more. your ui creation, config reading, etc. should all go in init() instead. don’t read your size from the config, it’s done for you.


if your applet is useless without some configuration, then there’s a special thing you should set, but I forget what it is; I should do this for twitter at some point.
if your applet is useless without some configuration, then setNeedsConfiguring(true) - but judging by the documentation this could have some annoying side-effects. I should try it in twitter at some point and see what breaks.


however… layouts may not like not being in the constructor. can someone explain how these two bits of information fit together?
however… layouts may not like not being in the constructor. can someone explain how these two bits of information fit together?

Revision as of 13:56, 18 January 2008

this is just a collection of various little tips that haven't been put into a proper tutorial or anything

sizing: when you’re an applet doing your own stuff, you want to use functions with Content in them, so that you don’t have the borders added in. when you’re acting on another applet, you use the ones without, so that the border is taken into account. other than that, I’m really quite confused. I feel like we really shouldn’t need two functions for every type of sizing. but I don’t have time to investigate that right now.

If you need to be notified when your plasmoid is resized, then implement constraintsUpdated() and check for a sizeconstraint. your new size is given by contentSize().

avoid reimplementing functions that return a size. only override contentSizeHint if you really need to (eg. controlling the aspect ratio).

if you know you’ll always need a certain amount of space, then setMinimumContentSize

when creating an applet, do as little as possible in the constructor. set a default size, and preferably no more. your ui creation, config reading, etc. should all go in init() instead. don’t read your size from the config, it’s done for you.

if your applet is useless without some configuration, then setNeedsConfiguring(true) - but judging by the documentation this could have some annoying side-effects. I should try it in twitter at some point and see what breaks.

however… layouts may not like not being in the constructor. can someone explain how these two bits of information fit together?

don’t sync the config; that’s plasma’s responsibility. you can, however, emit configNeedsSaving().

there’s stuff to be done when accepting mouseclicks so that the event doesn’t get completely swallowed all the time - but I’ve forgotten the details and just can’t find the information any more.

setVisibility() does the same thing as show() and hide() - so don’t use both at once :P

if your function name starts with “got”, or you’re having trouble commenting the function in the header, chances are your design is suboptimal.