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

kblackbox

  • sources
  • kde-4.14
  • kdegames
  • kblackbox
kbbthememanager.cpp
Go to the documentation of this file.
1 //
2 // KBlackBox
3 //
4 // A simple game inspired by an emacs module
5 //
6 /***************************************************************************
7  * Copyright (c) 2007, Nicolas Roffet *
8  * nicolas-kde@roffet.com *
9  * *
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  * This program is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19  * GNU General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU General Public License *
22  * along with this program; if not, write to the *
23  * Free Software Foundation, Inc., *
24  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA *
25  ***************************************************************************/
26 
27 
28 #include "kbbthememanager.h"
29 
30 #include <QColor>
31 #include <QDomDocument>
32 #include <QFile>
33 
34 #include <QStringList>
35 
36 
37 #include <kfilterdev.h>
38 #include <qsvgrenderer.h>
39 
40 
41 #include "kbbscalablegraphicwidget.h"
42 
43 
44 
45 //
46 // Constructor / Destructor
47 //
48 
49 KBBThemeManager::KBBThemeManager(const QString &svgzFileName)
50 {
51  // 1. for SVG items
52  m_svgRenderer.load(svgzFileName);
53 
54 
55  // 2. for non SVG items
56  QFile svgzFile(svgzFileName);
57  QIODevice *f = KFilterDev::device(&svgzFile, QString::fromLatin1("application/x-gzip"), false);
58 
59  if (f) {
60  QDomDocument doc;
61  if (doc.setContent(f,true)) {
62  m_root = doc.documentElement();
63  }
64 
65  delete f;
66  }
67 }
68 
69 
70 
71 //
72 // Public
73 //
74 
75 QColor KBBThemeManager::color(const KBBScalableGraphicWidget::itemType itemType)
76 {
77  return QColor(value(itemType, "stroke"));
78 }
79 
80 
81 QString KBBThemeManager::elementId(const KBBScalableGraphicWidget::itemType itemType)
82 {
83  QString eId;
84 
85  switch (itemType) {
86  case KBBScalableGraphicWidget::background:
87  eId = "background";
88  break;
89  case KBBScalableGraphicWidget::blackbox:
90  eId = "blackbox";
91  break;
92  case KBBScalableGraphicWidget::blackboxGrid:
93  eId = "blackbox_grid";
94  break;
95  case KBBScalableGraphicWidget::cursor:
96  eId = "cursor";
97  break;
98  case KBBScalableGraphicWidget::informationBackground:
99  eId = "information_background";
100  break;
101  case KBBScalableGraphicWidget::interactionInfoDeflection:
102  eId = "interaction_info_deflection";
103  break;
104  case KBBScalableGraphicWidget::interactionInfoHit:
105  eId = "interaction_info_hit";
106  break;
107  case KBBScalableGraphicWidget::interactionInfoNothing:
108  eId = "interaction_info_nothing";
109  break;
110  case KBBScalableGraphicWidget::interactionInfoReflection:
111  eId = "interaction_info_reflection";
112  break;
113  case KBBScalableGraphicWidget::interactionInfoReflectionSym:
114  eId = "interaction_info_reflection_sym";
115  break;
116  case KBBScalableGraphicWidget::laser0:
117  eId = "laser_0";
118  break;
119  case KBBScalableGraphicWidget::laser90:
120  eId = "laser_90";
121  break;
122  case KBBScalableGraphicWidget::laser180:
123  eId = "laser_180";
124  break;
125  case KBBScalableGraphicWidget::laser270:
126  eId = "laser_270";
127  break;
128  case KBBScalableGraphicWidget::markerNothing:
129  eId = "marker_nothing";
130  break;
131  case KBBScalableGraphicWidget::playerBall:
132  eId = "player_ball";
133  break;
134  case KBBScalableGraphicWidget::playerRay:
135  eId = "player_ray";
136  break;
137  case KBBScalableGraphicWidget::resultBackground:
138  eId = "result_background";
139  break;
140  case KBBScalableGraphicWidget::resultBackgroundHighlight:
141  eId = "result_background_highlight";
142  break;
143  case KBBScalableGraphicWidget::resultHit:
144  eId = "result_hit";
145  break;
146  case KBBScalableGraphicWidget::resultReflection:
147  eId = "result_reflection";
148  break;
149  case KBBScalableGraphicWidget::rightPlayerBall:
150  eId = "right_player_ball";
151  break;
152  case KBBScalableGraphicWidget::solutionBall:
153  eId = "solution_ball";
154  break;
155  case KBBScalableGraphicWidget::solutionRay:
156  eId = "solution_ray";
157  break;
158  case KBBScalableGraphicWidget::tutorialMarker:
159  eId = "tutorial_marker";
160  break;
161  case KBBScalableGraphicWidget::unsureBall:
162  eId = "unsure_ball";
163  break;
164  case KBBScalableGraphicWidget::wrongPlayerBall:
165  eId = "wrong_player_ball";
166  break;
167  default:
168  eId = "none";
169  break;
170  }
171 
172  return eId;
173 }
174 
175 
176 Qt::PenStyle KBBThemeManager::style(const KBBScalableGraphicWidget::itemType itemType)
177 {
178  if (value(itemType, "stroke-dasharray")=="none") {
179  return Qt::SolidLine;
180  } else
181  return Qt::DotLine;
182 }
183 
184 
185 QSvgRenderer* KBBThemeManager::svgRenderer()
186 {
187  return &m_svgRenderer;
188 }
189 
190 
191 qreal KBBThemeManager::width(const KBBScalableGraphicWidget::itemType itemType)
192 {
193  return value(itemType, "stroke-width").toFloat();
194 }
195 
196 
197 int KBBThemeManager::zValue(const KBBScalableGraphicWidget::itemType itemType)
198 {
199  return itemType;
200 }
201 
202 
203 
204 //
205 // Private
206 //
207 
208 QString KBBThemeManager::value(const KBBScalableGraphicWidget::itemType itemType, const QString &styleElement)
209 {
210  const QString id = elementId(itemType);
211  QString style("");
212  QString v("");
213 
214  QDomNode node = m_root.firstChild();
215  while(!node.isNull()) {
216  if (node.toElement().attribute("id") == id)
217  style = node.toElement().attribute("style");
218  node = node.nextSibling();
219  }
220 
221  QStringList styleList = style.split(';');
222  for (int i = 0; i < styleList.size(); i++) {
223  styleList.replace(i, styleList.at(i).trimmed());
224  if (styleList.at(i).startsWith(styleElement + ':')) {
225  QString s = styleList.at(i);
226  v = s.right(s.length()-styleElement.length()-1);
227  }
228  }
229 
230  return v;
231 }
QIODevice
KBBScalableGraphicWidget::solutionBall
Definition: kbbscalablegraphicwidget.h:103
KBBThemeManager::width
qreal width(const KBBScalableGraphicWidget::itemType itemType)
Get the width of the item.
Definition: kbbthememanager.cpp:191
KBBScalableGraphicWidget::laser180
Definition: kbbscalablegraphicwidget.h:115
QWidget::cursor
QCursor cursor() const
QDomElement::attribute
QString attribute(const QString &name, const QString &defValue) const
QList::at
const T & at(int i) const
KBBScalableGraphicWidget::interactionInfoReflection
Definition: kbbscalablegraphicwidget.h:111
QSvgRenderer
KBBThemeManager::zValue
int zValue(const KBBScalableGraphicWidget::itemType itemType)
Get the relative height of the item.
Definition: kbbthememanager.cpp:197
QDomDocument::documentElement
QDomElement documentElement() const
QDomNode
KBBScalableGraphicWidget::markerNothing
Definition: kbbscalablegraphicwidget.h:95
QFile
KBBScalableGraphicWidget::playerBall
Definition: kbbscalablegraphicwidget.h:104
KBBScalableGraphicWidget::resultBackground
Definition: kbbscalablegraphicwidget.h:98
QList::size
int size() const
QDomNode::nextSibling
QDomNode nextSibling() const
QDomNode::toElement
QDomElement toElement() const
KBBScalableGraphicWidget::solutionRay
Definition: kbbscalablegraphicwidget.h:96
KBBScalableGraphicWidget::informationBackground
Definition: kbbscalablegraphicwidget.h:91
QSvgRenderer::load
bool load(const QString &filename)
KBBScalableGraphicWidget::interactionInfoHit
Definition: kbbscalablegraphicwidget.h:109
KBBScalableGraphicWidget::unsureBall
Definition: kbbscalablegraphicwidget.h:105
KBBScalableGraphicWidget::tutorialMarker
Definition: kbbscalablegraphicwidget.h:94
KBBThemeManager::svgRenderer
QSvgRenderer * svgRenderer()
Get the shared SVG renderer.
Definition: kbbthememanager.cpp:185
KBBScalableGraphicWidget::rightPlayerBall
Definition: kbbscalablegraphicwidget.h:107
kbbscalablegraphicwidget.h
KBBScalableGraphicWidget::playerRay
Definition: kbbscalablegraphicwidget.h:97
QString
QColor
KBBThemeManager::color
QColor color(const KBBScalableGraphicWidget::itemType itemType)
Get the color of the item.
Definition: kbbthememanager.cpp:75
QStringList
QString::right
QString right(int n) const
KBBScalableGraphicWidget::blackbox
Definition: kbbscalablegraphicwidget.h:92
KBBScalableGraphicWidget::blackboxGrid
Definition: kbbscalablegraphicwidget.h:93
QDomDocument
QDomNode::isNull
bool isNull() const
KBBScalableGraphicWidget::interactionInfoNothing
Definition: kbbscalablegraphicwidget.h:110
KBBScalableGraphicWidget::resultHit
Definition: kbbscalablegraphicwidget.h:101
KBBScalableGraphicWidget::laser90
Definition: kbbscalablegraphicwidget.h:114
KBBScalableGraphicWidget::interactionInfoDeflection
Definition: kbbscalablegraphicwidget.h:108
KBBScalableGraphicWidget::interactionInfoReflectionSym
Definition: kbbscalablegraphicwidget.h:112
QDomNode::firstChild
QDomNode firstChild() const
KBBThemeManager::elementId
QString elementId(const KBBScalableGraphicWidget::itemType itemType)
Get the XML "id" value of the item.
Definition: kbbthememanager.cpp:81
QString::toFloat
float toFloat(bool *ok) const
QString::length
int length() const
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KBBScalableGraphicWidget::laser270
Definition: kbbscalablegraphicwidget.h:116
KBBScalableGraphicWidget::background
Definition: kbbscalablegraphicwidget.h:90
KBBThemeManager::style
Qt::PenStyle style(const KBBScalableGraphicWidget::itemType itemType)
Get the pen style of the item.
Definition: kbbthememanager.cpp:176
KBBScalableGraphicWidget::resultBackgroundHighlight
Definition: kbbscalablegraphicwidget.h:99
KBBScalableGraphicWidget::laser0
Definition: kbbscalablegraphicwidget.h:113
KBBScalableGraphicWidget::resultReflection
Definition: kbbscalablegraphicwidget.h:100
KBBScalableGraphicWidget::itemType
itemType
Every graphic items.
Definition: kbbscalablegraphicwidget.h:89
kbbthememanager.h
KBBScalableGraphicWidget::wrongPlayerBall
Definition: kbbscalablegraphicwidget.h:106
QDomDocument::setContent
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
KBBThemeManager::KBBThemeManager
KBBThemeManager(const QString &svgzFileName)
Constructor.
Definition: kbbthememanager.cpp:49
QList::replace
void replace(int i, const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kblackbox

Skip menu "kblackbox"
  • Main Page
  • 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