From 185c052e994a2a224c73829fefa10ea7d1c58e52 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 12 Aug 2009 14:32:42 +1000 Subject: Add a basic QFont value type. --- src/declarative/qml/qmlvaluetype.cpp | 85 ++++++++++++++++++++++++++++++++++++ src/declarative/qml/qmlvaluetype_p.h | 39 +++++++++++++++++ 2 files changed, 124 insertions(+) diff --git a/src/declarative/qml/qmlvaluetype.cpp b/src/declarative/qml/qmlvaluetype.cpp index dada8ff..7af3c56 100644 --- a/src/declarative/qml/qmlvaluetype.cpp +++ b/src/declarative/qml/qmlvaluetype.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qmlvaluetype_p.h" +#include QT_BEGIN_NAMESPACE @@ -73,6 +74,8 @@ QmlValueType *QmlValueTypeFactory::valueType(int t) return new QmlRectFValueType; case QVariant::Vector3D: return new QmlVector3DValueType; + case QVariant::Font: + return new QmlFontValueType; default: return 0; } @@ -392,4 +395,86 @@ void QmlVector3DValueType::setZ(qreal z) vector.setZ(z); } +QmlFontValueType::QmlFontValueType(QObject *parent) +: QmlValueType(parent), hasPixelSize(false) +{ +} + +void QmlFontValueType::read(QObject *obj, int idx) +{ + void *a[] = { &font, 0 }; + QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); +} + +void QmlFontValueType::write(QObject *obj, int idx) +{ + void *a[] = { &font, 0 }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); +} + +QString QmlFontValueType::family() const +{ + return font.family(); +} + +void QmlFontValueType::setFamily(const QString &family) +{ + font.setFamily(family); +} + +bool QmlFontValueType::bold() const +{ + return font.bold(); +} + +void QmlFontValueType::setBold(bool b) +{ + font.setBold(b); +} + +bool QmlFontValueType::italic() const +{ + return font.italic(); +} + +void QmlFontValueType::setItalic(bool b) +{ + font.setItalic(b); +} + +bool QmlFontValueType::underline() const +{ + return font.underline(); +} + +void QmlFontValueType::setUnderline(bool b) +{ + font.setUnderline(b); +} + +qreal QmlFontValueType::pointSize() const +{ + return font.pointSizeF(); +} + +void QmlFontValueType::setPointSize(qreal size) +{ + if (hasPixelSize) { + qWarning() << "Both point size and pixel size set. Using pixel size."; + return; + } + font.setPointSizeF(size); +} + +int QmlFontValueType::pixelSize() const +{ + return font.pixelSize(); +} + +void QmlFontValueType::setPixelSize(int size) +{ + font.setPixelSize(size); + hasPixelSize = true; +} + QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlvaluetype_p.h b/src/declarative/qml/qmlvaluetype_p.h index 8f6700b..7a3620c 100644 --- a/src/declarative/qml/qmlvaluetype_p.h +++ b/src/declarative/qml/qmlvaluetype_p.h @@ -57,6 +57,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -237,6 +238,44 @@ private: QVector3D vector; }; +class QmlFontValueType : public QmlValueType +{ + Q_OBJECT + Q_PROPERTY(QString family READ family WRITE setFamily) + Q_PROPERTY(bool bold READ bold WRITE setBold) + Q_PROPERTY(bool italic READ italic WRITE setItalic) + Q_PROPERTY(bool underline READ underline WRITE setUnderline) + Q_PROPERTY(qreal pointSize READ pointSize WRITE setPointSize) + Q_PROPERTY(int pixelSize READ pixelSize WRITE setPixelSize) +public: + QmlFontValueType(QObject *parent = 0); + + virtual void read(QObject *, int); + virtual void write(QObject *, int); + + QString family() const; + void setFamily(const QString &); + + bool bold() const; + void setBold(bool b); + + bool italic() const; + void setItalic(bool b); + + bool underline() const; + void setUnderline(bool b); + + qreal pointSize() const; + void setPointSize(qreal size); + + int pixelSize() const; + void setPixelSize(int size); + +private: + QFont font; + bool hasPixelSize; +}; + QT_END_NAMESPACE #endif // QMLVALUETYPE_P_H -- cgit v0.12