File indexing completed on 2024-05-05 08:08:38
0001 /*************************************************************************** 0002 onu.h - description 0003 ------------------- 0004 begin : Wed Jul 18 2001 0005 copyright : (C) 2001 by Gael de Chalendar 0006 email : Gael.de.Chalendar@free.fr 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either either version 2 0014 of the License, or (at your option) any later version.of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * You should have received a copy of the GNU General Public License 0018 * along with this program; if not, write to the Free Software 0019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0020 * 02110-1301, USA 0021 ***************************************************************************/ 0022 0023 #ifndef KSIRKSKINEDITORONU_H 0024 #define KSIRKSKINEDITORONU_H 0025 0026 #include "country.h" 0027 #include "continent.h" 0028 #include "nationality.h" 0029 #include "spritetype.h" 0030 0031 #include <QPixmap> 0032 #include <QFont> 0033 #include <QSvgRenderer> 0034 #include <QObject> 0035 #include <QMap> 0036 0037 #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API 0038 #include <libkdegamesprivate/kgamesvgdocument.h> 0039 0040 class QGraphicsItem; 0041 0042 namespace KsirkSkinEditor 0043 { 0044 0045 class Country; 0046 class Goal; 0047 /** 0048 * Class ONU (Organisation des Nations Unies = UNO : United Nations 0049 * Organization) is simply the list of the countries. The data definining 0050 * each country is loaded from an XML configuration file located in the 0051 * current skin data directory 0052 */ 0053 class ONU: public QObject 0054 { 0055 Q_OBJECT 0056 0057 public: 0058 0059 /** 0060 * Constructor 0061 * @param configFileName The name of the XML file defining this world. Built 0062 * from the current skin dir and a default file name. 0063 */ 0064 explicit ONU(const QString& configFileName, QObject *parent); 0065 0066 /** Default destructor */ 0067 ~ONU() override; 0068 0069 //{@ 0070 /** 0071 * Accessors 0072 */ 0073 inline const QString& skin() const {return m_skin;} 0074 inline const QString& name() const {return m_name;} 0075 inline void setName(const QString& n) { if (m_name != n) {m_name = n; m_dirty = true;} } 0076 inline const QString& description() const {return m_description;} 0077 inline void setDescription(const QString& d) { if (m_description != d) {m_description = d; m_dirty=true;} } 0078 inline const QString& configFileName() const {return m_configFileName;} 0079 inline const QPixmap& map() const {return m_map;} 0080 inline const QPixmap& snapshot() const {return m_snapshot;} 0081 inline unsigned int width() const {return m_width;} 0082 inline void setWidth(unsigned int w) { if (m_width != w) {m_width = w; m_dirty = true;} } 0083 inline unsigned int height() const {return m_height;} 0084 inline void setHeight(unsigned int h) { if (m_height != h) {m_height = h; m_dirty = true;} } 0085 inline const QStringList& poolIds() const {return m_poolIds;} 0086 inline bool dirty() const {return m_dirty;} 0087 inline void setDirty() {m_dirty = true;} 0088 //@} 0089 0090 /** 0091 * This method returns a pointer to the country that contains the given 0092 * point. If there is no country there, the functions returns 0. 0093 * @param point The point where to search for a country in the map mask 0094 * @return The country at the given point or 0 if there is no country there. 0095 */ 0096 Country* countryAt(const QPointF& point); 0097 0098 /** 0099 * Calls its reset method for each country 0100 */ 0101 void reset(); 0102 0103 /** 0104 * Return the countries list 0105 */ 0106 inline QList<Country*>& countries() {return m_countries;} 0107 0108 /** 0109 * Returns the nationalities list 0110 */ 0111 inline QList<Nationality*>& nationalities() {return m_nationalities;} 0112 0113 //@{ 0114 /** Read property of QList<Continent*> continents. */ 0115 inline QList<Continent*>& continents() {return m_continents;} 0116 inline const QList<Continent*>& continents() const {return m_continents;} 0117 //@} 0118 0119 inline QList<Goal*>& goals() {return m_goals;} 0120 0121 /** 0122 * Retrieves the continent with the given id 0123 * @param id The id of the continent to retrieve 0124 * @return A pointer to the retrieved continent or 0 if there is no 0125 * continent with the given id. 0126 */ 0127 const Continent* continentWithId(const unsigned int id) const; 0128 0129 /** 0130 * Returns the country named "name" ; 0 in case there is no such country. 0131 * @param name The name of the country to retrieve. 0132 * @return The country named name or 0 if there is no such country. 0133 */ 0134 Country* countryNamed(const QString& name); 0135 0136 /** 0137 * Gets the number of countries in the world 0138 * @return The number of countries in the world 0139 */ 0140 unsigned int getNbCountries() const; 0141 0142 /** 0143 * Saves a XML representation of the world for game saving purpose 0144 * @param xmlStream The stream to write on 0145 */ 0146 void saveXml(std::ostream& xmlStream); 0147 0148 /** 0149 * Returns the nation named "name" ; 0 in case there is no such nation 0150 * @param name The name of the nation to retrieve. 0151 * @return The nation named name or 0 if there is no such nation. 0152 */ 0153 Nationality* nationNamed(const QString& name); 0154 0155 /** 0156 * Returns the continent named "name" ; 0 in case there is no such continent 0157 * @param name The name of the continent to retrieve. 0158 * @return The continent named name or 0 if there is no such continent. 0159 */ 0160 Continent* continentNamed(const QString& name); 0161 0162 Nationality* nationalityNamed(const QString& name); 0163 0164 QSvgRenderer* renderer(); 0165 0166 inline const QImage& mask() const {return m_countriesMask;} 0167 0168 KGameSvgDocument* svgDom(); 0169 0170 inline QMap<QGraphicsItem*, QPair<Country*, SpriteType> >& itemsMap() {return m_itemsMap;} 0171 0172 QGraphicsItem* itemFor(const Country* country, SpriteType spriteType); 0173 0174 QPixmap pixmapForId(const QString& id, int width, int height); 0175 0176 inline const QPixmap& flagIcon() const {return m_flagIcon;} 0177 inline const QPixmap& infantryIcon() const {return m_infantryIcon;} 0178 inline const QPixmap& cavalryIcon() const {return m_cavalryIcon;} 0179 inline const QPixmap& cannonIcon() const {return m_cannonIcon;} 0180 0181 void saveConfig(const QString& configFileName = QString()); 0182 0183 QFont foregroundFont(); 0184 QFont backgroundFont(); 0185 0186 QColor foregroundColor() {return QColor(m_font.foregroundColor);} 0187 QColor backgroundColor() {return QColor(m_font.backgroundColor);} 0188 0189 void setFont(const QFont& font); 0190 void setFontFgColor(const QColor& color); 0191 void setFontBgColor(const QColor& color); 0192 0193 void createCountry(const QString& newCountryName); 0194 void deleteCountry(Country* country); 0195 0196 void createContinent(const QString& newCountryName); 0197 void deleteContinent(Continent* country); 0198 0199 void updateIcon(SpriteType type); 0200 0201 void createGoal(); 0202 void deleteGoal(int g); 0203 0204 void createNationality(const QString& newNationalityName); 0205 void deleteNationality(Nationality* nationality); 0206 0207 private: 0208 /** 0209 * All data that have to be stored about the font to display countries names 0210 * in this world's skin 0211 */ 0212 struct FontDesc 0213 { 0214 QString family; 0215 int size; 0216 QFont::Weight weight; 0217 bool italic; 0218 QString foregroundColor; 0219 QString backgroundColor; 0220 }; 0221 0222 /** 0223 * Build the map from it's stored image and the countries names 0224 */ 0225 void buildMap(); 0226 0227 void loadPoolIds(const QString& fileName); 0228 0229 QString m_configDir; 0230 0231 /** 0232 * The name of the .desktop file containing the world's definition 0233 */ 0234 QString m_configFileName; 0235 0236 /** 0237 * The displayable name of the skin 0238 */ 0239 QString m_name; 0240 0241 /** 0242 * The displayable long description of the skin 0243 */ 0244 QString m_description; 0245 0246 /** 0247 * The map used by this skin, built at the proper size from its SVG source 0248 * and decorated with countries names 0249 */ 0250 QPixmap m_map; 0251 0252 /** 0253 * A snaphsot of a running game with this skin. Used at skin choice time. 0254 */ 0255 QPixmap m_snapshot; 0256 0257 //@{ 0258 /** 0259 * The width and height of the map file (will be used as canvas size). These 0260 * measures do not take into account the zoom factor. 0261 */ 0262 unsigned int m_width; 0263 unsigned int m_height; 0264 //@} 0265 0266 /** 0267 * The list of countries 0268 */ 0269 QList<Country*> m_countries; 0270 0271 /** 0272 * The list of nationalities 0273 */ 0274 QList<Nationality*> m_nationalities; 0275 0276 /** 0277 * The continents of the world 0278 */ 0279 QList<Continent*> m_continents; 0280 0281 /** 0282 * This image stores the mask that defines the countries of the world. 0283 * The blue RGB component value of each pixel gives the index of the 0284 * country in the countries list. 0285 */ 0286 QImage m_countriesMask; 0287 0288 /** 0289 * The path to the skin ; relative to the ksirk data dir ; loaded from the 0290 * XML file 0291 */ 0292 QString m_skin; 0293 0294 /** 0295 * The description of the font used to draw countries names onto the map. 0296 */ 0297 FontDesc m_font; 0298 0299 /** 0300 * This SVG renderer stores the SVG file of the map, renders it at the 0301 * desired zoom factor and the result is used to build the map image. 0302 */ 0303 QSvgRenderer m_renderer; 0304 0305 KGameSvgDocument m_svgDom; 0306 0307 QMap<QGraphicsItem*, QPair<Country*, SpriteType> > m_itemsMap; 0308 0309 QPixmap m_flagIcon; 0310 QPixmap m_infantryIcon; 0311 QPixmap m_cavalryIcon; 0312 QPixmap m_cannonIcon; 0313 0314 QString m_poolString; 0315 0316 QList<Goal*> m_goals; 0317 0318 QStringList m_poolIds; 0319 0320 bool m_dirty; 0321 }; 0322 0323 } 0324 #endif // ONU_H 0325