4 // A simple game inspired by an emacs module
6 /***************************************************************************
7 * Copyright (c) 2007, Nicolas Roffet *
8 * nicolas-kde@roffet.com *
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. *
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. *
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 ***************************************************************************/
29 #ifndef KBBTHEMEMANAGER_H
30 #define KBBTHEMEMANAGER_H
33 #include <QDomElement>
37 #include <ksvgrenderer.h>
40 #include "kbbscalablegraphicwidget.h"
45 * @brief Theme manager of the scalable graphic widget
47 * This class manages the graphic theme of the central widget.
48 * Graphics elements of the game are mainly SVG items. Some dynamic elements (like laser rays) are not SVG items but their theme attributes are nonetheless saved in the SVG file.
57 * The constructor opens the SVGZ file, creates the SVG renderer and gets the DOM root node.
58 * @param &svgzFileName Path to the SVGZ file
60 KBBThemeManager(const QString
&svgzFileName
);
64 * @brief Get the color of the item
66 * @param &itemType Type of the considered item
69 QColor
color(const KBBScalableGraphicWidget::itemType itemType
);
72 * @brief Get the XML "id" value of the item
74 * In the SVG file, each graphic element has an ID that is saved in the attribute "id" of every XML node.
75 * This methode maps the item type with its XML "id" value.
77 * @param &itemType Type of the considered item
78 * @return The XML attribute "id" of the item
80 QString
elementId(const KBBScalableGraphicWidget::itemType itemType
);
83 * @brief Get the pen style of the item
85 * @param &itemType Type of the considered item
86 * @return Qt::DotLine except if the style value "stroke-dasharray" is "none". In that case: Qt::SolidLine
88 Qt::PenStyle
style(const KBBScalableGraphicWidget::itemType itemType
);
91 * @brief Get the shared SVG renderer
93 * @return The SVG renderer
95 KSvgRenderer
* svgRenderer();
98 * @brief Get the width of the item
100 * @param &itemType Type of the considered item
101 * @return The stroke width
103 qreal
width(const KBBScalableGraphicWidget::itemType itemType
);
106 * @brief Get the relative height of the item
108 * Items are stacked horizontally. It's important to know what item is over or unter what other item.
110 * @param &itemType Type of the considered item
111 * @return item relative height
113 int zValue(const KBBScalableGraphicWidget::itemType itemType
);
118 * @brief Get the value of the style attribute in the SVG file for a non SVG item
120 * This methode is useful for laser rays or for the grid of the black box.
121 * Laser rays (for instance) inherit QGraphicsPathItem and not KBBGraphicsItem (i.e. not QGraphicsSvgItem). But we want to be able to configure their attributes (color, width and style) to suit the graphic theme. All other items are saved as SVG items in a single theme file. To make it easy to manage themes, the laser ray attributes are also saved in the same SVG file. And as SVG is a XML format, <b>this methode of this class parses the XML of the SVG file</b>.
123 * Prerequisites: The SVG file must follow a strict structure.
124 * - Laser ray elements must be defined in a XML node that is a direct child of the root SVG node. It won't work for instance if there is a "layer" node between the XML node of the laser ray and the root node.
125 * - Just the attribute "style" of the laser ray node is used. The color is the value of "stroke:", the width is the value of "stroke-width:", and the style is the value of "stroke-dasharray:". All other values are ignored.
126 * - The id attribute of the node is important, but the node tag is not. ("g" or "path" or whatever is OK).
128 * @param &itemType Type of the considered item
129 * @param &styleElement Element of the attribute "style" to consider
130 * @return Value of the given element in the attribute "style" of the give XML node
131 * @see KBBGraphicsItemRay
133 QString
value(const KBBScalableGraphicWidget::itemType itemType
, const QString
&styleElement
);
136 * @brief Root element of the DOM tree of the XML theme file
141 * @brief SVG Renderer
143 * The SVG renderer is shared by all SVG graphic items.
145 KSvgRenderer m_svgRenderer
;
148 #endif // KBBTHEMEMANAGER_H