<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://techbase.kde.org/skins/common/feed.css?0.2"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;feed=atom&amp;action=history</id>
		<title>Development/Tutorials/Plasma/WallpaperDoubleBuffer - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;action=history"/>
		<updated>2013-05-24T20:07:07Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.2</generator>

	<entry>
		<id>http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;diff=70008&amp;oldid=prev</id>
		<title>Icwiener: moved Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer to Development/Tutorials/Plasma/WallpaperDoubleBuffer: Next try to move this page to its correct location.</title>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;diff=70008&amp;oldid=prev"/>
				<updated>2012-04-06T18:48:31Z</updated>
		
		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/index.php?title=Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer (page does not exist)&quot;&gt;Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer&lt;/a&gt; to &lt;a href=&quot;/Development/Tutorials/Plasma/WallpaperDoubleBuffer&quot; title=&quot;Development/Tutorials/Plasma/WallpaperDoubleBuffer&quot;&gt;Development/Tutorials/Plasma/WallpaperDoubleBuffer&lt;/a&gt;: Next try to move this page to its correct location.&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 18:48, 6 April 2012&lt;/td&gt;
			&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Icwiener</name></author>	</entry>

	<entry>
		<id>http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;diff=70007&amp;oldid=prev</id>
		<title>Icwiener: moved /Development/Tutorials/Plasma/WallpaperDoubleBuffer to Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer: revert
Man, it's easy to blow things up. :/</title>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;diff=70007&amp;oldid=prev"/>
				<updated>2012-04-06T18:47:51Z</updated>
		
		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/index.php?title=/Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;/Development/Tutorials/Plasma/WallpaperDoubleBuffer (page does not exist)&quot;&gt;/Development/Tutorials/Plasma/WallpaperDoubleBuffer&lt;/a&gt; to &lt;a href=&quot;/index.php?title=Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer (page does not exist)&quot;&gt;Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer&lt;/a&gt;: revert Man, it&amp;#039;s easy to blow things up. :/&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 18:47, 6 April 2012&lt;/td&gt;
			&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Icwiener</name></author>	</entry>

	<entry>
		<id>http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;diff=70006&amp;oldid=prev</id>
		<title>Icwiener: moved Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer to /Development/Tutorials/Plasma/WallpaperDoubleBuffer: Oops?</title>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;diff=70006&amp;oldid=prev"/>
				<updated>2012-04-06T18:46:26Z</updated>
		
		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/index.php?title=Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer (page does not exist)&quot;&gt;Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer&lt;/a&gt; to &lt;a href=&quot;/index.php?title=/Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;/Development/Tutorials/Plasma/WallpaperDoubleBuffer (page does not exist)&quot;&gt;/Development/Tutorials/Plasma/WallpaperDoubleBuffer&lt;/a&gt;: Oops?&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 18:46, 6 April 2012&lt;/td&gt;
			&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Icwiener</name></author>	</entry>

	<entry>
		<id>http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;diff=70003&amp;oldid=prev</id>
		<title>Icwiener: moved User:StijnRuts to Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer: User request.
Part of a series.</title>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;diff=70003&amp;oldid=prev"/>
				<updated>2012-04-06T18:43:49Z</updated>
		
		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/index.php?title=User:StijnRuts&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;User:StijnRuts (page does not exist)&quot;&gt;User:StijnRuts&lt;/a&gt; to &lt;a href=&quot;/index.php?title=Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer (page does not exist)&quot;&gt;Http://techbase.kde.org/Development/Tutorials/Plasma/WallpaperDoubleBuffer&lt;/a&gt;: User request. Part of a series.&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 18:43, 6 April 2012&lt;/td&gt;
			&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Icwiener</name></author>	</entry>

	<entry>
		<id>http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;diff=69916&amp;oldid=prev</id>
		<title>Icwiener: Typo</title>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;diff=69916&amp;oldid=prev"/>
				<updated>2012-04-05T22:42:37Z</updated>
		
		<summary type="html">&lt;p&gt;Typo&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 22:42, 5 April 2012&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;= &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Plama &lt;/del&gt;Wallpaper Tutorial 3 - Double Buffer =&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;= &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Plasma &lt;/ins&gt;Wallpaper Tutorial 3 - Double Buffer =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==Introduction==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==Introduction==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Icwiener</name></author>	</entry>

	<entry>
		<id>http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;diff=69788&amp;oldid=prev</id>
		<title>StijnRuts: Created page with &quot;= Plama Wallpaper Tutorial 3 - Double Buffer =  ==Introduction==  So far we have ignored the exposedRect argument of our paint function. Whenever the paint function was called we...&quot;</title>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Development/Tutorials/Plasma/WallpaperDoubleBuffer&amp;diff=69788&amp;oldid=prev"/>
				<updated>2012-04-03T18:34:00Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Plama Wallpaper Tutorial 3 - Double Buffer =  ==Introduction==  So far we have ignored the exposedRect argument of our paint function. Whenever the paint function was called we...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Plama Wallpaper Tutorial 3 - Double Buffer =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
So far we have ignored the exposedRect argument of our paint function. Whenever the paint function was called we redrew the entire wallpaper even when only a small region needed repainting. As you can imagine this is not very efficient so let's improve our wallpaper by using a so-called 'double buffer' technique.&lt;br /&gt;
&lt;br /&gt;
==Adding the Buffer== &lt;br /&gt;
&lt;br /&gt;
The way this double buffer technique works is by rendering our wallpaper to a pixmap in memory, the buffer, instead of rendering it directly to the screen. Whenever a region on the screen needs repainting we can just copy the corresponding region from the buffer to the screen.&lt;br /&gt;
&lt;br /&gt;
First we'll need to add the buffer to our private variables and write a new function for rendering the buffer. Add the following lines to our tutorial.h:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
#ifndef PLASMA_WALLPAPER_TUTORIAL&lt;br /&gt;
#define PLASMA_WALLPAPER_TUTORIAL&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Plasma/Wallpaper&amp;gt;&lt;br /&gt;
#include &amp;quot;ui_config.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class Tutorial : public Plasma::Wallpaper&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
    public:&lt;br /&gt;
        Tutorial(QObject* parent, const QVariantList&amp;amp; args);&lt;br /&gt;
&lt;br /&gt;
        virtual void save(KConfigGroup &amp;amp;config);&lt;br /&gt;
        void paint(QPainter* painter, const QRectF&amp;amp; exposedRect);&lt;br /&gt;
        virtual QWidget* createConfigurationInterface(QWidget* parent);&lt;br /&gt;
&lt;br /&gt;
    Q_SIGNALS:&lt;br /&gt;
        void settingsChanged(bool modified);&lt;br /&gt;
&lt;br /&gt;
    protected:&lt;br /&gt;
        virtual void init(const KConfigGroup &amp;amp;config);&lt;br /&gt;
&lt;br /&gt;
    protected slots:&lt;br /&gt;
        void settingsModified();&lt;br /&gt;
&lt;br /&gt;
    private:&lt;br /&gt;
        Ui::Config configWidget;&lt;br /&gt;
        QColor backgroundColor;&lt;br /&gt;
        QColor textColor;&lt;br /&gt;
        QFont textFont;&lt;br /&gt;
        QString textString;&lt;br /&gt;
        QPixmap buffer;                         // New&lt;br /&gt;
        void render();                          // New&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
K_EXPORT_PLASMA_WALLPAPER(tutorial, Tutorial)&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we will implement render() in our tutorial.cpp. This function is largely identical to the old paint function, except it will draw to our newly created buffer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
void Tutorial::render()&lt;br /&gt;
{&lt;br /&gt;
    if(buffer.size() != boundingRect().size())&lt;br /&gt;
    {&lt;br /&gt;
        buffer = QPixmap(boundingRect().size().toSize());&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    QPainter painter;&lt;br /&gt;
    painter.begin(&amp;amp;buffer);&lt;br /&gt;
	&lt;br /&gt;
    painter.setPen(backgroundColor);&lt;br /&gt;
    painter.setBrush(backgroundColor);&lt;br /&gt;
    painter.drawRect(boundingRect());&lt;br /&gt;
 &lt;br /&gt;
    painter.setPen(textColor);&lt;br /&gt;
    painter.setFont(textFont);&lt;br /&gt;
    painter.drawText(boundingRect(), Qt::AlignCenter, textString);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the buffer has the wrong size or if the buffer doesn't exist yet (size = 0px*0px) we create a new QPixmap with the same size as our wallpaper. We then associate a QPainter object with this buffer and draw with the QPainter as before.&lt;br /&gt;
&lt;br /&gt;
==Using the Buffer== &lt;br /&gt;
&lt;br /&gt;
We will now need to change the paint function to make use of our buffer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
void Tutorial::paint(QPainter *painter, const QRectF&amp;amp; exposedRect)&lt;br /&gt;
{&lt;br /&gt;
    if(buffer.size() != boundingRect().size())&lt;br /&gt;
    {&lt;br /&gt;
        render();&lt;br /&gt;
    }&lt;br /&gt;
	&lt;br /&gt;
    painter-&amp;gt;drawPixmap(exposedRect, buffer, exposedRect);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the buffer has the wrong size or if the buffer doesn't exist yet (size = 0px*0px) we call our render function to fill the buffer with the correct content. When our buffer is up-to-date we copy the exposedRect region from the buffer to the painter.&lt;br /&gt;
&lt;br /&gt;
We'll also need to update the buffer, by calling our render function, whenever the content of the wallpaper changes. Add the following lines to the init and settingsModified functions in our tutorial.cpp:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
void Tutorial::init(const KConfigGroup &amp;amp;config)&lt;br /&gt;
{&lt;br /&gt;
    backgroundColor = config.readEntry(&amp;quot;backgroundColor&amp;quot;, QColor(Qt::white));&lt;br /&gt;
    textColor = config.readEntry(&amp;quot;textColor&amp;quot;, QColor(Qt::black));&lt;br /&gt;
    textFont = config.readEntry(&amp;quot;textFont&amp;quot;, QFont(&amp;quot;Arial&amp;quot;, 50));&lt;br /&gt;
    textString = config.readEntry(&amp;quot;textString&amp;quot;, QString(&amp;quot;Hello World!&amp;quot;));&lt;br /&gt;
 &lt;br /&gt;
    render();                                             // New&lt;br /&gt;
    emit update(boundingRect());&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void Tutorial::settingsModified()&lt;br /&gt;
{&lt;br /&gt;
    textString = configWidget.textString-&amp;gt;text();&lt;br /&gt;
    textFont = configWidget.textFont-&amp;gt;font();&lt;br /&gt;
    textColor = configWidget.textColor-&amp;gt;color();&lt;br /&gt;
    backgroundColor = configWidget.backgroundColor-&amp;gt;color();&lt;br /&gt;
 &lt;br /&gt;
    render();                                             // New&lt;br /&gt;
    emit settingsChanged(true);&lt;br /&gt;
    emit update(boundingRect());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
&lt;br /&gt;
To compile we follow the same steps as before:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir -p build&lt;br /&gt;
cd build&lt;br /&gt;
cmake .. -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix`&lt;br /&gt;
make&lt;br /&gt;
sudo make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
Again we can test using the Plasma wallpaper viewer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
plasmawallpaperviewer -p tutorial&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or we can test it directly on our desktop. Restart plasma using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kquitapp plasma-desktop; sleep 1; plasma-desktop&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then right click on your desktop, go to Desktop Settings&amp;gt;Wallpaper&amp;gt;Type and select 'Tutorial'.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
By adding a buffer to our wallpaper plugin we can make it redraw only the parts that need to be redrawn.&lt;/div&gt;</summary>
		<author><name>StijnRuts</name></author>	</entry>

	</feed>