[kde-doc-english] branches/KDE/4.4/kdeedu/khangman/src
Adam Rakowski
foo-script at o2.pl
Wed Jun 23 05:45:16 CEST 2010
SVN commit 1141622 by adamrakowski:
GUI:XML themes added CC:annma at kde.org
M +1 -0 CMakeLists.txt
M +9 -3 khangman.cpp
M +4 -0 khangman.h
M +1 -1 khangmanview.cpp
M +52 -153 khmtheme.cpp
M +29 -28 khmtheme.h
AM khmthemefactory.cpp [License: GPL (v2+)]
AM khmthemefactory.h [License: GPL (v2+)]
A standardthemes.xml
--- branches/KDE/4.4/kdeedu/khangman/src/CMakeLists.txt #1141621:1141622
@@ -8,6 +8,7 @@
main.cpp
khangmanview.cpp
khmtheme.cpp
+ khmthemefactory.cpp
langutils.cpp
timer.cpp)
--- branches/KDE/4.4/kdeedu/khangman/src/khangman.cpp #1141621:1141622
@@ -22,7 +22,7 @@
#include "khangman.h"
#include "prefs.h"
#include "timer.h"
-#include "khmtheme.h"
+
#include "langutils.h"
#include "khangmanview.h"
#include "sharedkvtmlfiles.h"
@@ -61,6 +61,10 @@
setCentralWidget(m_view);
setLanguages();
setupStatusbar();
+
+ //load the standard set of themes
+ khm_factory.addTheme(KStandardDirs::locate("data", "khangman/pics/standardthemes.xml")); //TODO move it to better place
+
setupActions();
// Toolbar for special characters
@@ -132,7 +136,8 @@
m_modeAction = new KSelectAction(i18n("L&ook"), this);
actionCollection()->addAction("combo_mode", m_modeAction );
connect(m_modeAction, SIGNAL(triggered(int)), this, SLOT(slotChangeMode(int)));
- m_modeAction->setItems(KHMThemeFactory::instance()->themeList());
+ //m_modeAction->setItems(KHMThemeFactory::instance()->themeList());
+ m_modeAction->setItems(khm_factory.themeList());
m_modeAction->setCurrentItem(Prefs::mode());
m_modeAction->setToolTip(i18n( "Choose the look and feel" ));
m_modeAction->setWhatsThis(i18n( "Choose the look and feel" ));
@@ -196,7 +201,8 @@
{
Prefs::setMode(index);
Prefs::self()->writeConfig();
- m_view->setTheme(KHMThemeFactory::instance()->buildTheme(index));
+ //m_view->setTheme(KHMThemeFactory::instance()->buildTheme(index));
+ m_view->setTheme(khm_factory.buildTheme(index));
}
--- branches/KDE/4.4/kdeedu/khangman/src/khangman.h #1141621:1141622
@@ -26,6 +26,7 @@
#include "khangmanview.h"
#include "ui_generalui.h"
#include "ui_languageui.h"
+#include "khmthemefactory.h"
class KSelectAction;
class KToggleAction;
@@ -154,6 +155,9 @@
// Settings.
Ui::generalui ui_general;
Ui::languageui ui_language;
+
+ //Theme manager
+ KHMThemeFactory khm_factory;
};
#endif // _KHANGMAN_H_
--- branches/KDE/4.4/kdeedu/khangman/src/khangmanview.cpp #1141621:1141622
@@ -87,7 +87,7 @@
m_renderer = new QSvgRenderer();
// not the best thing to do, but at least avoid no theme set
- setTheme(KHMThemeFactory::instance()->buildTheme(0));
+ //setTheme(KHMThemeFactory::instance()->buildTheme(0));
}
--- branches/KDE/4.4/kdeedu/khangman/src/khmtheme.cpp #1141621:1141622
@@ -1,5 +1,6 @@
/***************************************************************************
- * Copyright (C) 2007 Pino Toscano <pino at kde.org> *
+ * Copyright (C) 2007-2010 Pino Toscano <pino at kde.org> *
+ * Updated by Adam Rakowski <foo-script at o2.pl> (GSoC 2010) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -22,202 +23,100 @@
#include <KLocale>
-KHMTheme::KHMTheme()
+KHMTheme::KHMTheme( QString name, QString uiName, QString svgFileName, QString author, QString themeVersion,
+ QRect wordRect, QRect hintRect, QRect kRect,
+ QColor letterColor, QColor guessButtonTextColor, QColor guessButtonColor, QColor guessButtonHoverColor, QColor letterInputTextColor,
+ QPoint goodWordPos)
{
+ KHMname=name;
+ KHMuiName=uiName;
+ KHMsvgFileName=svgFileName;
+ KHMauthor=author;
+ KHMthemeVersion=themeVersion;
+ KHMwordRect=wordRect;
+ KHMhintRect=hintRect;
+ KHMkRect=kRect;
+ KHMletterColor=letterColor;
+ KHMguessButtonTextColor=guessButtonTextColor;
+ KHMguessButtonColor=guessButtonColor;
+ KHMguessButtonHoverColor=guessButtonHoverColor;
+ KHMletterInputTextColor=letterInputTextColor;
+ KHMgoodWordPos=goodWordPos;
}
-KHMTheme::~KHMTheme()
+QString KHMTheme::name()
{
+ return KHMname;
}
-
-/// The 'sea' theme
-class KHMThemeSea : public KHMTheme
+QString KHMTheme::uiName()
{
-public:
- KHMThemeSea()
- : KHMTheme()
- {
+ return i18n(KHMuiName.toAscii());
}
- virtual QString name() const
+QString KHMTheme::svgFileName()
{
- return "sea";
+ return KHMsvgFileName;
}
- virtual QString uiName() const
+QColor KHMTheme::letterInputTextColor()
{
- return i18n("Sea Theme");
+ return KHMsvgFileName;
}
- virtual QString svgFileName() const
+QString KHMTheme::getAuthor()
{
- return "khangman_sea.svg";
+ return KHMauthor;
}
- virtual QRect wordRect(const QSize& windowsize) const
+QString KHMTheme::getThemeVersion()
{
- return QRect(0, windowsize.height()-windowsize.height()*15/100,
- windowsize.width()*417/700, windowsize.height()*15/100);
+ return KHMthemeVersion;
}
- virtual QRect hintRect(const QSize& windowsize) const
+QRect KHMTheme::wordRect(const QSize& windowsize)
{
- return QRect(0, windowsize.height()-windowsize.height()*210/700,
- windowsize.width()*410/700, windowsize.height()*130/700);
+ return QRect(windowsize.width()*KHMwordRect.x()/10000, windowsize.height()*KHMwordRect.y()/10000,
+ windowsize.width()*KHMwordRect.width()/10000, windowsize.height()*KHMwordRect.height()/10000);
}
- virtual QRect kRect(const QSize& windowsize) const
+QRect KHMTheme::hintRect(const QSize& windowsize)
{
- return QRect(0, 0, windowsize.width()*630/700, windowsize.height()*285/535);
+ return QRect(windowsize.width()*KHMhintRect.x()/10000, windowsize.height()*KHMhintRect.y()/10000,
+ windowsize.width()*KHMhintRect.width()/10000, windowsize.height()*KHMhintRect.height()/10000);
}
- virtual QPoint goodWordPos(const QSize& windowsize, const QPoint& popupPos) const
+QRect KHMTheme::kRect(const QSize& windowsize)
{
- return QPoint(popupPos.x() + windowsize.width()*250/700,
- popupPos.y() + windowsize.height()*485/535);
+ return QRect(windowsize.width()*KHMkRect.x()/10000, windowsize.height()*KHMkRect.y()/10000,
+ windowsize.width()*KHMkRect.width()/10000, windowsize.height()*KHMkRect.height()/10000);
}
- virtual QColor letterColor() const
+QColor KHMTheme::letterColor()
{
- return QColor(148, 156, 167);
+ return KHMletterColor;
}
- virtual QColor guessButtonColor() const
+QColor KHMTheme::guessButtonTextColor()
{
- return QColor( 115, 64, 49);
+ return KHMguessButtonTextColor;
}
- virtual QColor guessButtonTextColor() const
+QColor KHMTheme::guessButtonColor()
{
- return QColor( 165, 165, 165);
+ return KHMguessButtonColor;
}
- virtual QColor guessButtonHoverColor() const
+QColor KHMTheme::guessButtonHoverColor()
{
- return QColor( 115, 55, 55);
+ return KHMguessButtonHoverColor;
}
- virtual QColor letterInputTextColor() const
+QPoint KHMTheme::goodWordPos(const QSize& windowsize, const QPoint& popupPos) //works good
{
- return QColor( 83, 40, 14);
+ return QPoint(popupPos.x() + windowsize.width()*KHMgoodWordPos.x()/10000,
+ popupPos.y() + windowsize.height()*KHMgoodWordPos.y()/10000);
}
-};
-
-/// The 'desert' theme
-class KHMThemeDesert : public KHMTheme
-{
-public:
- KHMThemeDesert()
- : KHMTheme()
- {
- }
-
- virtual QString name() const
- {
- return "desert";
- }
-
- virtual QString uiName() const
- {
- return i18n("Desert Theme");
- }
-
- virtual QString svgFileName() const
- {
- return "khangman_desert.svg";
- }
-
- virtual QRect wordRect(const QSize& windowsize) const
- {
- return QRect(0, windowsize.height()-windowsize.height()*15/100,
- windowsize.width()*327/700, windowsize.height()*15/100);
- }
-
- virtual QRect hintRect(const QSize& windowsize) const
- {
- return QRect(0, windowsize.height()-windowsize.height()*210/700,
- windowsize.width()*320/700, windowsize.height()*130/700);
- }
-
- virtual QRect kRect(const QSize& windowsize) const
- {
- return QRect(windowsize.width()*68/700, windowsize.height()*170/535,
- windowsize.width()*200/700, windowsize.height()*220/535);
- }
-
- virtual QColor letterColor() const
- {
- return QColor(87, 0, 0);
- }
-
- virtual QColor guessButtonColor() const
- {
- return QColor( 205, 214, 90);
- }
-
- virtual QColor guessButtonTextColor() const
- {
- return QColor( 82, 119, 70);
- }
-
- virtual QColor guessButtonHoverColor() const
- {
- return QColor( 205, 220, 100);
- }
-
- virtual QColor letterInputTextColor() const
- {
- return QColor( 82, 119, 70);
- }
-
- virtual QPoint goodWordPos(const QSize& windowsize, const QPoint& popupPos) const
- {
- return QPoint(popupPos.x() + windowsize.width()*200/700,
- popupPos.y() + windowsize.height()*485/535);
- }
-};
-
-
-KHMThemeFactory* KHMThemeFactory::instance()
-{
- static KHMThemeFactory factory;
- return &factory;
-}
-
-KHMThemeFactory::KHMThemeFactory()
-{
-}
-
-KHMThemeFactory::~KHMThemeFactory()
-{
-}
-
-KHMTheme* KHMThemeFactory::buildTheme(int id) const
-{
- switch (id)
- {
- case 0:
- return new KHMThemeSea();
- case 1:
- return new KHMThemeDesert();
- }
- return 0;
-}
-
-#define ADD_THEME_NAME( themeclass, list ) \
-{ \
- themeclass x; \
- list.append( x.uiName() ); \
-}
-QStringList KHMThemeFactory::themeList() const
-{
- QStringList ret;
- ADD_THEME_NAME( KHMThemeSea, ret )
- ADD_THEME_NAME( KHMThemeDesert, ret )
- return ret;
-}
-
// kate: space-indent on; tab-width 4; indent-width 4; mixed-indent off; replace-tabs on;
// vim: set et sw=4 ts=4 cino=l1,cs,U1:
--- branches/KDE/4.4/kdeedu/khangman/src/khmtheme.h #1141621:1141622
@@ -1,5 +1,6 @@
/***************************************************************************
- * Copyright (C) Copyright (C) 2007 Pino Toscano <pino at kde.org> *
+ * Copyright (C) 2007-2010 Pino Toscano <pino at kde.org> *
+ * Updated by Adam Rakowski <foo-script at o2.pl> (GSoC 2010) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -24,48 +25,48 @@
class KHMTheme
{
+ private:
+ QString KHMname, KHMuiName, KHMsvgFileName, KHMauthor, KHMthemeVersion;
+ QRect KHMwordRect, KHMhintRect, KHMkRect;
+ QColor KHMletterColor, KHMguessButtonTextColor, KHMguessButtonColor, KHMguessButtonHoverColor, KHMletterInputTextColor;
+ QPoint KHMgoodWordPos;
+
public:
- KHMTheme();
- virtual ~KHMTheme();
+ KHMTheme( QString name, QString uiName, QString svgFileName, QString author, QString themeVersion,
+ QRect wordRect, QRect hintRect, QRect kRect,
+ QColor letterColor, QColor guessButtonTextColor, QColor guessButtonColor, QColor guessButtonHoverColor, QColor letterInputTextColor,
+ QPoint goodWordPos);
///The name of theme as in the folder
- virtual QString name() const = 0;
+ QString name();
///The name of the theme in the menu
- virtual QString uiName() const = 0;
- ///Get the svg name of the theme
- virtual QString svgFileName() const = 0;
+ QString uiName();
+ ///Get the svg n22 the theme
+ QString svgFileName();
///Set the position and size for drawing the word to guess
- virtual QRect wordRect(const QSize& windowsize) const = 0;
+ QRect wordRect(const QSize& windowsize);
- virtual QRect hintRect(const QSize& windowsize) const = 0;
+ QRect hintRect(const QSize& windowsize);
///Set the position and size for drawing the hanged K
- virtual QRect kRect(const QSize& windowsize) const = 0;
+ QRect kRect(const QSize& windowsize);
///Set the color for the word and the missed letters
- virtual QColor letterColor() const = 0;
+ QColor letterColor();
///Set the color of the Guess word
- virtual QColor guessButtonTextColor() const = 0;
+ QColor guessButtonTextColor();
///Set the color of the Guess button background
- virtual QColor guessButtonColor() const = 0;
+ QColor guessButtonColor();
///Set the color of the Guess button background when the mouse is over it
- virtual QColor guessButtonHoverColor() const = 0;
+ QColor guessButtonHoverColor();
///Set the color of the input text in the input widget
- virtual QColor letterInputTextColor() const = 0;
+ QColor letterInputTextColor();
///Set the already guessed popup position
- virtual QPoint goodWordPos(const QSize& windowsize, const QPoint& popupPos) const = 0;
-};
+ QPoint goodWordPos(const QSize& windowsize, const QPoint& popupPos);
+ //Find out who's the author
+ QString getAuthor();
+ //Version is equal to a KHMTheme format version declared in XML file
+ QString getThemeVersion();
-class KHMThemeFactory
-{
-public:
- static KHMThemeFactory* instance();
- ~KHMThemeFactory();
-
- KHMTheme* buildTheme(int id) const;
- QStringList themeList() const;
-
-private:
- KHMThemeFactory();
};
#endif
More information about the kde-doc-english
mailing list