diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-08-12 04:32:42 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-08-12 04:32:42 (GMT) |
commit | 185c052e994a2a224c73829fefa10ea7d1c58e52 (patch) | |
tree | 031bcc398fdbcf79e89749f8988d121935ac8f2e /src/declarative/qml | |
parent | 2d4db45fabb68d380b34eb5b2922357ebd26b94c (diff) | |
download | Qt-185c052e994a2a224c73829fefa10ea7d1c58e52.zip Qt-185c052e994a2a224c73829fefa10ea7d1c58e52.tar.gz Qt-185c052e994a2a224c73829fefa10ea7d1c58e52.tar.bz2 |
Add a basic QFont value type.
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/qmlvaluetype.cpp | 85 | ||||
-rw-r--r-- | src/declarative/qml/qmlvaluetype_p.h | 39 |
2 files changed, 124 insertions, 0 deletions
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 <QtCore/qdebug.h> 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 <QtCore/qrect.h> #include <QtCore/qvariant.h> #include <QtGui/qvector3d.h> +#include <QtGui/qfont.h> 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 |