diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-30 06:28:37 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-30 06:28:37 (GMT) |
commit | 980e3f143505639ec8f1a8cc4d0ca2bbe59e69c7 (patch) | |
tree | 59232e6c61e7e01101b0f349b14c52c7fbd52713 | |
parent | deb92c796c727c6ad0eaf28929cda6d000c1b3c1 (diff) | |
download | Qt-980e3f143505639ec8f1a8cc4d0ca2bbe59e69c7.zip Qt-980e3f143505639ec8f1a8cc4d0ca2bbe59e69c7.tar.gz Qt-980e3f143505639ec8f1a8cc4d0ca2bbe59e69c7.tar.bz2 |
Add Qt.fontFamilies() method
QTBUG-10239
-rw-r--r-- | doc/src/declarative/globalobject.qdoc | 3 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeengine.cpp | 12 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeengine_p.h | 1 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativeqt/data/fontFamilies.qml | 6 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp | 18 |
5 files changed, 40 insertions, 0 deletions
diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 47460cf..7c27ae4 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -226,6 +226,9 @@ This function causes the QML engine to emit the quit signal, which in This function returns \c url resolved relative to the URL of the caller. +\section3 Qt.fontFamilies() +This function returns a list of the font families available to the application. + \section3 Qt.isQtObject(object) Returns true if \c object is a valid reference to a Qt or QML object, otherwise false. diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 4d23e8f..dee5ec6 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -82,6 +82,7 @@ #include <QStack> #include <QMap> #include <QPluginLoader> +#include <QtGui/qfontdatabase.h> #include <QtCore/qlibraryinfo.h> #include <QtCore/qthreadstorage.h> #include <QtCore/qthread.h> @@ -225,6 +226,7 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr //misc methods qtObject.setProperty(QLatin1String("openUrlExternally"),newFunction(QDeclarativeEnginePrivate::desktopOpenUrl, 1)); + qtObject.setProperty(QLatin1String("fontFamilies"),newFunction(QDeclarativeEnginePrivate::fontFamilies, 0)); qtObject.setProperty(QLatin1String("md5"),newFunction(QDeclarativeEnginePrivate::md5, 1)); qtObject.setProperty(QLatin1String("btoa"),newFunction(QDeclarativeEnginePrivate::btoa, 1)); qtObject.setProperty(QLatin1String("atob"),newFunction(QDeclarativeEnginePrivate::atob, 1)); @@ -1274,6 +1276,16 @@ QScriptValue QDeclarativeEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QSc return QScriptValue(e, ret); } +QScriptValue QDeclarativeEnginePrivate::fontFamilies(QScriptContext *ctxt, QScriptEngine *e) +{ + if(ctxt->argumentCount() != 0) + return ctxt->throwError("Qt.fontFamilies(): Invalid arguments"); + + QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(e); + QFontDatabase database; + return p->scriptValueFromVariant(database.families()); +} + QScriptValue QDeclarativeEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *) { if (ctxt->argumentCount() != 1) diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 45656e8..531ac97 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -294,6 +294,7 @@ public: static QScriptValue tint(QScriptContext*, QScriptEngine*); static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*); + static QScriptValue fontFamilies(QScriptContext*, QScriptEngine*); static QScriptValue md5(QScriptContext*, QScriptEngine*); static QScriptValue btoa(QScriptContext*, QScriptEngine*); static QScriptValue atob(QScriptContext*, QScriptEngine*); diff --git a/tests/auto/declarative/qdeclarativeqt/data/fontFamilies.qml b/tests/auto/declarative/qdeclarativeqt/data/fontFamilies.qml new file mode 100644 index 0000000..e66c7be --- /dev/null +++ b/tests/auto/declarative/qdeclarativeqt/data/fontFamilies.qml @@ -0,0 +1,6 @@ +import Qt 4.7 + +QtObject { + property variant test1: Qt.fontFamilies(10) + property variant test2: Qt.fontFamilies(); +} diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp index 17b7925..5095be8 100644 --- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp +++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp @@ -42,6 +42,7 @@ #include <qtest.h> #include <QDebug> #include <QDeclarativeEngine> +#include <QFontDatabase> #include <QFileInfo> #include <QDeclarativeComponent> #include <QDesktopServices> @@ -76,6 +77,7 @@ private slots: void isQtObject(); void btoa(); void atob(); + void fontFamilies(); private: QDeclarativeEngine engine; @@ -483,6 +485,22 @@ void tst_qdeclarativeqt::atob() delete object; } +void tst_qdeclarativeqt::fontFamilies() +{ + QDeclarativeComponent component(&engine, TEST_FILE("fontFamilies.qml")); + + QString warning1 = component.url().toString() + ":4: Error: Qt.fontFamilies(): Invalid arguments"; + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); + + QObject *object = component.create(); + QVERIFY(object != 0); + + QFontDatabase database; + QCOMPARE(object->property("test2"), QVariant::fromValue(database.families())); + + delete object; +} + QTEST_MAIN(tst_qdeclarativeqt) #include "tst_qdeclarativeqt.moc" |