• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kblackbox

kbbthememanager.cpp

Go to the documentation of this file.
00001 //
00002 // KBlackBox
00003 //
00004 // A simple game inspired by an emacs module
00005 //
00006 /***************************************************************************
00007  *   Copyright (c) 2007, Nicolas Roffet                                    *
00008  *   nicolas-kde@roffet.com                                                *
00009  *                                                                         *
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   This program is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019  *   GNU General Public License for more details.                          *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU General Public License     *
00022  *   along with this program; if not, write to the                         *
00023  *   Free Software Foundation, Inc.,                                       *
00024  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA               *
00025  ***************************************************************************/
00026 
00027 
00028 #include "kbbthememanager.h"
00029 
00030 #include <QColor>
00031 #include <QDomDocument>
00032 #include <QFile>
00033 
00034 #include <QStringList>
00035 
00036 
00037 #include <kfilterdev.h>
00038 #include <ksvgrenderer.h>
00039 
00040 
00041 #include "kbbscalablegraphicwidget.h"
00042 
00043 
00044 
00045 //
00046 // Constructor / Destructor
00047 //
00048 
00049 KBBThemeManager::KBBThemeManager(const QString &svgzFileName)
00050 {
00051     // 1. for SVG items
00052     m_svgRenderer.load(svgzFileName);
00053     
00054     
00055     // 2. for non SVG items
00056     QFile svgzFile(svgzFileName);
00057     QIODevice *f = KFilterDev::device(&svgzFile, QString::fromLatin1("application/x-gzip"), false);
00058     
00059     if (f) {
00060         QDomDocument doc;
00061         if (doc.setContent(f,true)) {
00062             m_root = doc.documentElement();
00063         }
00064         
00065         delete f;
00066     }
00067 }
00068 
00069 
00070 
00071 //
00072 // Public
00073 //
00074 
00075 QColor KBBThemeManager::color(const KBBScalableGraphicWidget::itemType itemType)
00076 {
00077     return QColor(value(itemType, "stroke"));
00078 }
00079 
00080 
00081 QString KBBThemeManager::elementId(const KBBScalableGraphicWidget::itemType itemType)
00082 {
00083     QString eId;
00084     
00085     switch (itemType) {
00086         case KBBScalableGraphicWidget::background:
00087             eId = "background";
00088             break;
00089         case KBBScalableGraphicWidget::blackbox:
00090             eId = "blackbox";
00091             break;
00092         case KBBScalableGraphicWidget::blackboxGrid:
00093             eId = "blackbox_grid";
00094             break;
00095         case KBBScalableGraphicWidget::cursor:
00096             eId = "cursor";
00097             break;
00098         case KBBScalableGraphicWidget::informationBackground:
00099             eId = "information_background";
00100             break;
00101         case KBBScalableGraphicWidget::interactionInfoDeflection:
00102             eId = "interaction_info_deflection";
00103             break;
00104         case KBBScalableGraphicWidget::interactionInfoHit:
00105             eId = "interaction_info_hit";
00106             break;
00107         case KBBScalableGraphicWidget::interactionInfoNothing:
00108             eId = "interaction_info_nothing";
00109             break;
00110         case KBBScalableGraphicWidget::interactionInfoReflection:
00111             eId = "interaction_info_reflection";
00112             break;
00113         case KBBScalableGraphicWidget::interactionInfoReflectionSym:
00114             eId = "interaction_info_reflection_sym";
00115             break;
00116         case KBBScalableGraphicWidget::laser0:
00117             eId = "laser_0";
00118             break;
00119         case KBBScalableGraphicWidget::laser90:
00120             eId = "laser_90";
00121             break;
00122         case KBBScalableGraphicWidget::laser180:
00123             eId = "laser_180";
00124             break;
00125         case KBBScalableGraphicWidget::laser270:
00126             eId = "laser_270";
00127             break;
00128         case KBBScalableGraphicWidget::markerNothing:
00129             eId = "marker_nothing";
00130             break;
00131         case KBBScalableGraphicWidget::playerBall:
00132             eId = "player_ball";
00133             break;
00134         case KBBScalableGraphicWidget::playerRay:
00135             eId = "player_ray";
00136             break;
00137         case KBBScalableGraphicWidget::resultBackground:
00138             eId = "result_background";
00139             break;
00140         case KBBScalableGraphicWidget::resultBackgroundHighlight:
00141             eId = "result_background_highlight";
00142             break;
00143         case KBBScalableGraphicWidget::resultHit:
00144             eId = "result_hit";
00145             break;
00146         case KBBScalableGraphicWidget::resultReflection:
00147             eId = "result_reflection";
00148             break;
00149         case KBBScalableGraphicWidget::rightPlayerBall:
00150             eId = "right_player_ball";
00151             break;
00152         case KBBScalableGraphicWidget::solutionBall:
00153             eId = "solution_ball";
00154             break;
00155         case KBBScalableGraphicWidget::solutionRay:
00156             eId = "solution_ray";
00157             break;
00158         case KBBScalableGraphicWidget::tutorialMarker:
00159             eId = "tutorial_marker";
00160             break;
00161         case KBBScalableGraphicWidget::unsureBall:
00162             eId = "unsure_ball";
00163             break;
00164         case KBBScalableGraphicWidget::wrongPlayerBall:
00165             eId = "wrong_player_ball";
00166             break;
00167         default:
00168             eId = "none";
00169             break;
00170     }
00171     
00172     return eId;
00173 }
00174 
00175 
00176 Qt::PenStyle KBBThemeManager::style(const KBBScalableGraphicWidget::itemType itemType)
00177 {
00178     if (value(itemType, "stroke-dasharray")=="none") {
00179         return Qt::SolidLine;
00180     } else
00181         return Qt::DotLine;
00182 }
00183 
00184 
00185 KSvgRenderer* KBBThemeManager::svgRenderer()
00186 {
00187     return &m_svgRenderer;
00188 }
00189 
00190 
00191 qreal KBBThemeManager::width(const KBBScalableGraphicWidget::itemType itemType)
00192 {
00193     return value(itemType, "stroke-width").toFloat();
00194 }
00195 
00196 
00197 int KBBThemeManager::zValue(const KBBScalableGraphicWidget::itemType itemType)
00198 {
00199     return itemType;
00200 }
00201 
00202 
00203 
00204 //
00205 // Private
00206 //
00207 
00208 QString KBBThemeManager::value(const KBBScalableGraphicWidget::itemType itemType, const QString &styleElement)
00209 {
00210     const QString id = elementId(itemType);
00211     QString style("");
00212     QString v("");
00213     
00214     QDomNode node = m_root.firstChild();
00215     while(!node.isNull()) {
00216         if (node.toElement().attribute("id") == id)
00217             style = node.toElement().attribute("style");
00218         node = node.nextSibling();
00219     }
00220     
00221     QStringList styleList = style.split(";");
00222     for (int i = 0; i < styleList.size(); i++) {
00223         styleList.replace(i, styleList.at(i).trimmed());
00224         if (styleList.at(i).startsWith(styleElement + ':')) {
00225             QString s = styleList.at(i);
00226             v = s.right(s.length()-styleElement.length()-1);
00227         }
00228     }
00229     
00230     return v;
00231 }

kblackbox

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

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal