~ubuntu-branches/ubuntu/precise/kdegames/precise

« back to all changes in this revision

Viewing changes to kollision/renderer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sune Vuorela
  • Date: 2009-04-06 01:33:00 UTC
  • mfrom: (1.1.3 upstream)
  • mto: (2.2.2 squeeze)
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: james.westby@ubuntu.com-20090406013300-5d62yspscjsv5zd6
Tags: 4:4.2.2-1
* New upstream release:
  - Bugfixes in kpat. (Closes: #376420, #444050, #291007, #422437, #448641)
  - kmines, it is not longer possible cheat the timer. (Closes: #409310)
  - knetwalk, game type is shown after restart. (Closes: #417837)
* Bump build-deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
 
3
            
 
4
  This program is free software; you can redistribute it and/or modify
 
5
  it under the terms of the GNU General Public License as published by
 
6
  the Free Software Foundation; either version 2 of the License, or
 
7
  (at your option) any later version.
 
8
*/
 
9
 
 
10
#include "renderer.h"
 
11
#include <QImage>
 
12
#include <QPainter>
 
13
#include <ksvgrenderer.h>
 
14
#include <kstandarddirs.h>
 
15
#include <KDebug>
 
16
 
 
17
Renderer::Renderer()
 
18
{
 
19
    m_renderer = new KSvgRenderer(
 
20
        KStandardDirs::locate("appdata", "pictures/theme.svgz"), 0);
 
21
}
 
22
 
 
23
Renderer::~Renderer()
 
24
{
 
25
    delete m_renderer;
 
26
}
 
27
 
 
28
 
 
29
QPixmap Renderer::render(const QString& id)
 
30
{
 
31
    if (!m_cache.contains(id)) {
 
32
        QImage tmp(m_size, QImage::Format_ARGB32_Premultiplied);
 
33
        tmp.fill(0);
 
34
        
 
35
        QPainter p(&tmp);
 
36
        m_renderer->render(&p, id, QRectF(QPointF(0, 0), m_size));
 
37
        p.end();
 
38
 
 
39
        m_cache[id] = QPixmap::fromImage(tmp);
 
40
    }
 
41
    
 
42
    return m_cache.value(id);
 
43
}
 
44
 
 
45
 
 
46
void Renderer::resize(const QSize& size)
 
47
{
 
48
    m_size = size;
 
49
    m_cache.clear();
 
50
}
 
51