textsprite.cpp

Go to the documentation of this file.
00001 /*
00002    This file is part of the KDE games lskat program
00003    Copyright (c) 2006 Martin Heni <kde@heni-online.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 // Qt includes
00022 
00023 // KDE includes
00024 #include <kdebug.h>
00025 
00026 // Local includes
00027 #include "textsprite.h"
00028 
00029 
00030 // Constructor for the sprite
00031 TextSprite::TextSprite(QString text, QString id, ThemeManager* theme, QGraphicsScene* scene)
00032           : Themable(id, theme), QGraphicsTextItem(0, scene)
00033 {
00034   setPlainText(text);
00035   hide();
00036  
00037   if (theme) theme->updateTheme(this);
00038 }
00039 
00040 
00041 // Constructor for the sprite
00042 TextSprite::TextSprite(QString id, ThemeManager* theme, QGraphicsScene* scene)
00043           : Themable(id, theme), QGraphicsTextItem(0, scene)
00044 {
00045   hide();
00046  
00047   if (theme) theme->updateTheme(this);
00048 }
00049 
00050 
00051 void TextSprite::setText(QString text)
00052 {
00053   setPlainText(text);
00054   thememanager()->updateTheme(this);
00055 }
00056 
00057 
00058 // Main themable function. Called for any theme change. The sprites needs to
00059 // resize and redraw here.
00060 void TextSprite::changeTheme()
00061 {
00062 
00063   // Get scaling change
00064   double scale    = thememanager()->getScale();
00065   setScale(scale);
00066 
00067   // Retrieve theme data from configuration
00068   KConfigGroup config = thememanager()->config(id());
00069 
00070   // Size
00071   double width  = config.readEntry("width", 1.0);
00072   double height = config.readEntry("height", 0.0);
00073   width *= scale;
00074   height *= scale;
00075 
00076   // Position
00077   QPointF pos = config.readEntry("pos", QPointF(1.0,1.0));
00078   pos *= scale;
00079   setPos(pos.x(), pos.y());
00080 
00081   // z-Value
00082   double zValue = config.readEntry("zValue", 0.0);
00083   setZValue(zValue);
00084 
00085   // Text font
00086   bool bold = config.readEntry("bold", false);
00087   QFont font;
00088   font.setPixelSize(int(height));
00089   font.setBold(bold);
00090   setFont(font);
00091   if (width < boundingRect().width())
00092   {
00093     setTextWidth(width);   
00094   }
00095 
00096   // Retrieve font color
00097   QColor fontColor;
00098   fontColor = config.readEntry("fontColor", QColor(Qt::white));
00099   setDefaultTextColor(fontColor);
00100 
00101   // Centering
00102   bool center = config.readEntry("center", false);
00103   resetMatrix();
00104   if (center)
00105   {
00106     translate(-boundingRect().width()/2.0, 0.0);
00107   }
00108 
00109   update();
00110 }
00111 

Generated on Tue May 1 09:34:40 2007 for LSkat by  doxygen 1.4.6