{"id":724,"date":"2009-02-07T12:00:20","date_gmt":"2009-02-07T12:00:20","guid":{"rendered":"http:\/\/www.notmart.org\/index.php\/BlaBla\/TokaTalks"},"modified":"2009-02-07T12:00:20","modified_gmt":"2009-02-07T12:00:20","slug":"tokatalks","status":"publish","type":"post","link":"https:\/\/notmart.org\/blog\/2009\/02\/tokatalks\/","title":{"rendered":"TokaTalks"},"content":{"rendered":"<p>Yesterday talks were wicked interesting, especially the Alexis talk about the new animation framework was really breathtaking.<br \/>\nAaanyways, this is kinda a synopsis of what i talked about in my part during<br \/>\nthe talk session yesterday at Tokamak, slides<br \/>\n<a href=\"http:\/\/www.notmart.org\/files\/tokamak2slides.pdf\">here<\/a>,<br \/>\nit&#8217;s quickly written in few minutes, so the english it&#8217;s a total horror,<br \/>\nbut i feel it could be kinda interesting anyways \ud83d\ude42<\/p>\n<h2>Themes<\/h2>\n<p>Pretty much everything you see in Plasma is based on SVG graphics,<br \/>\nthis means that you have a really high degree of customizability<br \/>\ncontrolled by the Plasma theme. This also means that compared to<br \/>\nclassical Qt themes the entry barrier is significantly lower, because<br \/>\nof course you have to be a good designer to make one, but not a<br \/>\nprogrammer, while to do a Qt theme you have to be both and this is a<br \/>\nreally really rare thing.<\/p>\n<p>Also, since themes are pure graphics without binary code they are<br \/>\ncompletely platform independent so they can be distributed trough the<br \/>\nGHNS framework.<\/p>\n<p>Being vector graphics, we can display them without problem from<br \/>\nvery little screen to huge monsters when we will have 600dpi screens<br \/>\nthat won&#8217;t be a problem, specially for the theme elements based on<br \/>\nthe FrameSvg concept.<\/p>\n<p>From a programmer point of view using the theme graphics is quite<br \/>\neasy too, because the two main classes that manages Svg themes (Svg<br \/>\nand FrameSvg) are very abstracted, so you won&#8217;t have to bother that<br \/>\nthe graphics is actually a Svg.<\/p>\n<p>Plasma themes will be installed under your KDE installation prefix<br \/>\n under share\/apps\/desktopthemes. The filesystem structure inside the<br \/>\ntheme has got two main subfolders: <em>widgets<\/em>, meant for element<br \/>\ndrawn on canvas and <em>dialogs<\/em>, meant for elements that are<br \/>\nactually a top level window. There are two particular and optional<br \/>\nsubfolders: the first is <em>locolor<\/em>, that will have the same two<br \/>\nwidgets and dialogs subfolders meant to be used when the theme is<br \/>\ndisplayed on screens with less than 16 bit color depth.<\/p>\n<p>The other folder is called <em>opaque<\/em> and has replacements for<br \/>\nthe elements that are a top level widget when the desktop effects are<br \/>\nturned off, that&#8217;s because in this case we won&#8217;t be able to have a<br \/>\nsemitransparent window, so we won&#8217;t be able to have luxuries like<br \/>\nantialiased borders or drop shadows, if you have a rounded border<br \/>\nthere you should use the good old pixelart tecnique from the 80&#8217;s.<\/p>\n<p>In order to load an Svg from the current theme is sufficient to<br \/>\nuse the setImagePath() function of Plasma::Svg, where you don&#8217;t have<br \/>\nto worry neither of the path of the theme or the svg or svgz<br \/>\nextension, so something like &#8220;widgets\/background&#8221; will suffice.<\/p>\n<p>If you are writing a scripted applet you can also include the<br \/>\ngraphics alongside the applet code and distribute everything in a<br \/>\nsingle package, from a javascript applet for instance it will be<br \/>\nsufficient to call the function plasmoid.findSvg(&#8220;foo&#8221;) and the<br \/>\nproper foo.svg file will be located for you.<\/p>\n<p>That said however now i have to get a bit annoying with some<br \/>\nadvices: you should be really really careful when you add custom<br \/>\ngraphics in your applet, both when you install it alongside your c++<br \/>\napplet and also when you embed it in the package of your scripted<br \/>\napplet, because your additional graphics must work with as much<br \/>\nthemes as possible, and this is an hell lot difficult. You should at<br \/>\nleast try it with both a dark and a light theme, but in the end&#8230; if<br \/>\nyou want to do that, think again \ud83d\ude42<\/p>\n<h3>Boring implementation details<\/h3>\n<p>Usually in your applet won&#8217;t have to directly paint Svgs, because<br \/>\nif you just use the default plasma widgets you&#8217;ll have the svg<br \/>\npainting done for you, but if you have to draw some svg elements you<br \/>\nhave to know two classes: Plasma::Svg and Plasma::FrameSvg.<\/p>\n<p>The mighty machine that manages all the svg painting in Plasma is<br \/>\nthe Plasma::svg class, that internally uses the QSvgRenderer class,<br \/>\nbut optimizes it as much as possible: in the context of the whole<br \/>\nPlasma application for each svg file we get an unique shared svg<br \/>\nrenderer and the rendering result is saved to disk thanks to a<br \/>\nKPixmapCache, that can avoid the creation of renderer to a satisfatry<br \/>\ndegree: in the second plasma start won&#8217;t be created a single renderer<br \/>\nuntil you resize something, saving a bit of startup time and some<br \/>\nmegs of ram.<\/p>\n<p>The most important functions you are interested if you want to use<br \/>\na Svg are its several paint functions (overloaded with QPoints or<br \/>\nQRects as parameters) the already mentioned setImagePath() resize()<br \/>\nand various functions to access the svg sub elements like<br \/>\nhasElement(), elementSize() and elementRect().<\/p>\n<p>The other class used in plasma to render Svgs works at a slightly<br \/>\nhigher level of abstraction and is Plasma::FrameSvg. Usually widgets<br \/>\nare mostly rectangular things, but even if Svg is scalable that<br \/>\ndoesn&#8217;t mean the result will look pretty, take a look at the slides<br \/>\nexample for instance, where a<br \/>\ndefault applet background is heavily vertically stretched, so the<br \/>\nhorizontal borders become thicker that the vertical ones, and to make<br \/>\nthings worse they usually aren&#8217;t even an integer number of pixels<br \/>\nmaking the result to look really blurred.<\/p>\n<p>So, what is there in the default applet background? We can see<br \/>\nthere are actually 9 pieces: the corners, the edges and the central<br \/>\npart (called with a great stretch of fantasy center, top, topleft,<br \/>\ntopright, left,right,bottom, bottomright and bottomleft). When the<br \/>\nthing will get painted not all elements will be scaled, it&#8217;s<br \/>\nimportant that the corners won&#8217;t be never ever scaled, while the<br \/>\nhorizontal edges will be scaled only horizontally and similarly the<br \/>\nvertical edges will be scaled only vertically, while the center<br \/>\nelement will scale freely.<\/p>\n<p>From a boring code standpoint FrameSvg inherit the Svg class, so<br \/>\nall the stuff that is available in Svg is available in FrameSvg too,<br \/>\nbut with the difference that you want to resize the image with<br \/>\nresizeFrame() that uses the method i talked before and you&#8217;ll paint<br \/>\nthe correctly resize Svg with paintFrame(), while paint() is still<br \/>\nuseful to paint single elements in the Svg. Also a single Svg can<br \/>\ncontain multiple series of 9 elements, with the names differentiated<br \/>\nby a proper prefix, that can be chosen with the setElementPrefix()<br \/>\nfunction.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday talks were wicked interesting, especially the Alexis talk about the new animation framework was really breathtaking. Aaanyways, this is kinda a synopsis of what i talked about in my part during the talk session yesterday at Tokamak, slides here, it&#8217;s quickly written in few minutes, so the english it&#8217;s a total horror, but i [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[2,10,21,40,64],"class_list":["post-724","post","type-post","status-publish","format-standard","hentry","category-blabla","tag-kde","tag-kde4","tag-linux","tag-real-life","tag-tokamak"],"_links":{"self":[{"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/posts\/724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/comments?post=724"}],"version-history":[{"count":0,"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/posts\/724\/revisions"}],"wp:attachment":[{"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/media?parent=724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/categories?post=724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/tags?post=724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}