File indexing completed on 2024-12-15 03:48:05
0001 /* 0002 SPDX-FileCopyrightText: 2008 Sascha Peilicke <sasch.pe@gmx.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #ifndef KIGO_THEMERENDERER_H 0008 #define KIGO_THEMERENDERER_H 0009 0010 #include <QObject> 0011 #include <QString> 0012 0013 class KGameThemeProvider; 0014 class KGameTheme; 0015 0016 class QSvgRenderer; 0017 class QPixmap; 0018 class QPainter; 0019 class QSize; 0020 class QRectF; 0021 0022 namespace Kigo { 0023 0024 /** 0025 * The class ThemeRenderer loads shapes from a SVG theme file and converts them into 0026 * pixmaps which can be used by QGraphicsView classes to display the game scene. 0027 * The class is implemented as a singleton because it is needed only once per 0028 * application and uses a pixamp cache to efficiently store the pixmaps. 0029 * 0030 * ThemeRenderer is implemented as a singleton. 0031 * 0032 * @author Sascha Peilicke <sasch.pe@gmx.de> 0033 * @since 0.1 0034 */ 0035 class ThemeRenderer : public QObject 0036 { 0037 Q_OBJECT 0038 0039 private: 0040 ThemeRenderer(); 0041 ~ThemeRenderer() override; 0042 0043 public: 0044 /** 0045 * Enumeration of all possible renderable scene element types. 0046 */ 0047 enum class Element { 0048 Background = 1, 0049 Board, 0050 HandicapMark, 0051 WhiteStone, 0052 WhiteStoneLast, 0053 WhiteStoneTransparent, 0054 WhiteTerritory, 0055 BlackStone, 0056 BlackStoneLast, 0057 BlackStoneTransparent, 0058 BlackTerritory, 0059 PlacementMarker 0060 }; 0061 0062 /** 0063 * Only one ThemeRenderer is needed per application, this method returns 0064 * the singleton self. 0065 * 0066 * @return ThemeRenderer self 0067 */ 0068 inline static ThemeRenderer* self() 0069 { 0070 static ThemeRenderer self; 0071 return &self; 0072 } 0073 0074 /** 0075 * Load the game theme specified by 'name'. See the correspondig KConfigXT 0076 * settings file and available themes for details. 0077 * 0078 * @param theme the theme to load 0079 */ 0080 void loadTheme(const KGameTheme *theme); 0081 0082 /** 0083 * Renders a specific element of the current SVG theme. 0084 * 0085 * @param element Determines which part of the theme to render 0086 * @param painter The QPainter to paint the element with 0087 * @param rect The desired size of the element to render 0088 */ 0089 void renderElement(Element element, QPainter *painter, const QRectF &rect) const; 0090 /** 0091 * Renders and returns a specific element of the current SVG theme. 0092 * 0093 * @param element Determines which part of the theme to render 0094 * @param size The desired size of the element to render 0095 */ 0096 QPixmap renderElement(Element element, const QSize &size) const; 0097 0098 /** 0099 * Retrieves the default size of a given theme element from the current SVG theme. 0100 * 0101 * @param element The theme element to return the size of 0102 * @return The rounded size of the elements rectangle 0103 */ 0104 QSize elementSize(Element element) const; 0105 0106 KGameThemeProvider *themeProvider() const; 0107 0108 Q_SIGNALS: 0109 void themeChanged(); 0110 0111 private: 0112 KGameThemeProvider *m_themeProvider; 0113 QSvgRenderer *m_renderer; ///< Converts SVG parts into pixmaps 0114 }; 0115 0116 } // End of namespace Kigo 0117 0118 #endif