User:Chani/DevTips
this is just a collection of various little tips that haven't been put into a proper tutorial or anything
don’t sync the config; that’s plasma’s responsibility. you can, however, emit configNeedsSaving().
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?
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.