Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed to a common, template based SimpleSetter for handling all bas…
…ic properties of the words
- Loading branch information
1 parent
b5dcd97
commit 5e99d01
Showing
9 changed files
with
145 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Common header files to include in all modules | ||
#include <typeinfo> | ||
#include <QtCore> | ||
#include <QtGui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#ifndef __simplesetter_hpp_included__ | ||
#define __simplesetter_hpp_included__ | ||
|
||
#include <QBrush> | ||
#include <QColor> | ||
#include <QFont> | ||
#include <QGraphicsSimpleTextItem> | ||
#include <QString> | ||
#include "../include/clouddef.hpp" | ||
#include "../include/propset.hpp" | ||
#include "../include/setter.hpp" | ||
|
||
// Default property handlers | ||
template <class T> | ||
const char* getPropName() | ||
{ | ||
throw "Not implemented"; | ||
} | ||
|
||
template <class T> | ||
void applyPropValue(QGraphicsSimpleTextItem&, const T&) | ||
{ | ||
throw "Not implemented"; | ||
} | ||
|
||
// QString = text | ||
template <> | ||
const char* getPropName<QString>() | ||
{ | ||
return "text"; | ||
} | ||
|
||
template <> | ||
void applyPropValue<QString>(QGraphicsSimpleTextItem& item, | ||
const QString& value) | ||
{ | ||
item.setText(value); | ||
} | ||
|
||
// QFont = font | ||
template <> | ||
const char* getPropName<QFont>() | ||
{ | ||
return "font"; | ||
} | ||
|
||
template <> | ||
void applyPropValue<QFont>(QGraphicsSimpleTextItem& item, | ||
const QFont& value) | ||
{ | ||
QFont f(value); | ||
f.setPointSizeF(item.font().pointSizeF()); | ||
item.setFont(f); | ||
} | ||
|
||
// QColor = color | ||
template <> | ||
const char* getPropName<QColor>() | ||
{ | ||
return "color"; | ||
} | ||
|
||
template <> | ||
void applyPropValue<QColor>(QGraphicsSimpleTextItem& item, | ||
const QColor& value) | ||
{ | ||
item.setBrush(QBrush(value)); | ||
} | ||
|
||
// qreal = size | ||
template <> | ||
const char* getPropName<qreal>() | ||
{ | ||
return "size"; | ||
} | ||
|
||
template <> | ||
void applyPropValue<qreal>(QGraphicsSimpleTextItem& item, | ||
const qreal& value) | ||
{ | ||
QFont f(item.font()); | ||
f.setPointSizeF(value); | ||
item.setFont(f); | ||
} | ||
|
||
// The generic setter implementation | ||
template <class T> | ||
class SimpleSetter : public Setter | ||
{ | ||
public: | ||
virtual void init(const CloudDef& cloud) | ||
{ | ||
_default = cloud.get<T>(getPropName<T>(), _default); | ||
} | ||
|
||
virtual void apply(const PropSet& word, | ||
QGraphicsSimpleTextItem& item, | ||
QTransform&, | ||
const QRegion&) | ||
{ | ||
applyPropValue<T>(item, word.get<T>(getPropName<T>(), _default)); | ||
} | ||
|
||
private: | ||
T _default; | ||
}; | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
text_mode=normal | ||
text_setter=text | ||
color=#00c000 | ||
|
||
[1] | ||
text=This is word 0! | ||
size=10 | ||
|
||
[2] | ||
text=This is word 1! | ||
size=20 | ||
|
||
[3] | ||
text=This is word 2! | ||
size=30 | ||
|
||
[something] | ||
text=This is word 3! | ||
size=40 | ||
|
||
[hello] | ||
text=This is word 4! | ||
size=50 | ||
color=#ff0000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.