• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

libkdegames

  • sources
  • kde-4.14
  • kdegames
  • libkdegames
kgimageprovider.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright 2012 Viranch Mehta <viranch.mehta@gmail.com> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU Library General Public License *
6  * version 2 as published by the Free Software Foundation *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU Library General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU Library General Public *
14  * License along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
17  ***************************************************************************/
18 
19 #include "kgimageprovider_p.h"
20 
21 #include <QPainter>
22 #include <KgThemeProvider>
23 
24 KgImageProvider::KgImageProvider(KgThemeProvider* prov) :
25  QDeclarativeImageProvider(QDeclarativeImageProvider::Image),
26  m_provider(prov)
27 {
28  reloadRenderer();
29 }
30 
31 void KgImageProvider::reloadRenderer()
32 {
33  m_renderer.load(m_provider->currentTheme()->graphicsPath());
34  m_themeName = m_provider->currentThemeName();
35 }
36 
37 QImage KgImageProvider::requestImage(const QString& source, QSize *size, const QSize& requestedSize)
38 {
39  Q_UNUSED(requestedSize); // this is always QSize(-1,-1) for some reason
40 
41  QImage image;
42 
43  const QStringList tokens = source.split("/");
44  if (tokens.size() > 2) {
45  const QString theme = tokens[0];
46  const QString spriteKey = tokens[1];
47  const QStringList size = tokens[2].split("x");
48  uint width = qRound(size[0].toDouble());
49  uint height = qRound(size[1].toDouble());
50 
51  if (theme != m_themeName) {
52  reloadRenderer();
53  }
54 
55  if (m_renderer.isValid()) {
56  if (width == 0 || height == 0) {
57  image = QImage(m_renderer.boundsOnElement(spriteKey).size().toSize(), QImage::Format_ARGB32_Premultiplied);
58  } else {
59  image = QImage(width, height, QImage::Format_ARGB32_Premultiplied);
60  }
61  image.fill(Qt::transparent);
62  QPainter* painter = new QPainter(&image);
63  m_renderer.render(painter, spriteKey);
64  delete painter;
65  }
66  }
67 
68  if (size) *size = image.size();
69 
70  return image;
71 }
72 
73 #include "kgimageprovider_p.moc"
QSvgRenderer::render
void render(QPainter *painter)
KgImageProvider::KgImageProvider
KgImageProvider(KgThemeProvider *provider)
Construcs a new KgImageProvider with the supplied KgThemeProvider.
Definition: kgimageprovider.cpp:24
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
KgThemeProvider
A theme provider manages KgTheme instances, and maintains a selection of the currentTheme().
Definition: kgthemeprovider.h:39
QRectF::size
QSizeF size() const
QSvgRenderer::isValid
bool isValid() const
QList::size
int size() const
kgimageprovider_p.h
QSvgRenderer::load
bool load(const QString &filename)
QImage::fill
void fill(uint pixelValue)
QSizeF::toSize
QSize toSize() const
KgThemeProvider::currentThemeName
QString currentThemeName
Definition: kgthemeprovider.h:44
QPainter
KgImageProvider::requestImage
QImage requestImage(const QString &source, QSize *size, const QSize &requestedSize)
Reimplemented method that is called when a sprite pixmap is requested.
Definition: kgimageprovider.cpp:37
QString
KgTheme::graphicsPath
QString graphicsPath
Definition: kgtheme.h:79
QStringList
QSize
QImage
QSvgRenderer::boundsOnElement
QRectF boundsOnElement(const QString &id) const
KgThemeProvider::currentTheme
const KgTheme currentTheme
Definition: kgthemeprovider.h:42
QStringList::split
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
QImage::size
QSize size() const
QDeclarativeImageProvider
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdegames

Skip menu "libkdegames"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal