From 7950ccd27ea1353c699dc77242a03bd347daa5e5 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 5 Aug 2009 08:41:15 +1000 Subject: Move QmlFontFamily to extra. --- src/declarative/extra/extra.pri | 6 +- src/declarative/extra/qmlfontfamily.cpp | 206 ++++++++++++++++++++++++++++++++ src/declarative/extra/qmlfontfamily.h | 94 +++++++++++++++ src/declarative/util/qmlfontfamily.cpp | 206 -------------------------------- src/declarative/util/qmlfontfamily.h | 94 --------------- src/declarative/util/util.pri | 2 - 6 files changed, 304 insertions(+), 304 deletions(-) create mode 100644 src/declarative/extra/qmlfontfamily.cpp create mode 100644 src/declarative/extra/qmlfontfamily.h delete mode 100644 src/declarative/util/qmlfontfamily.cpp delete mode 100644 src/declarative/util/qmlfontfamily.h diff --git a/src/declarative/extra/extra.pri b/src/declarative/extra/extra.pri index d3ce7eb..c731afa 100644 --- a/src/declarative/extra/extra.pri +++ b/src/declarative/extra/extra.pri @@ -8,7 +8,8 @@ SOURCES += \ extra/qfxflowview.cpp \ extra/qfxparticles.cpp \ extra/qmlbehaviour.cpp \ - extra/qbindablemap.cpp + extra/qbindablemap.cpp \ + extra/qmlfontfamily.cpp HEADERS += \ extra/qnumberformat.h \ @@ -21,7 +22,8 @@ HEADERS += \ extra/qfxflowview.h \ extra/qfxparticles.h \ extra/qmlbehaviour.h \ - extra/qbindablemap.h + extra/qbindablemap.h \ + extra/qmlfontfamily.h contains(QT_CONFIG, xmlpatterns) { QT+=xmlpatterns diff --git a/src/declarative/extra/qmlfontfamily.cpp b/src/declarative/extra/qmlfontfamily.cpp new file mode 100644 index 0000000..73688c1 --- /dev/null +++ b/src/declarative/extra/qmlfontfamily.cpp @@ -0,0 +1,206 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "private/qobject_p.h" +#include "qmlfontfamily.h" +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlFontFamilyPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlFontFamily); + +public: + QmlFontFamilyPrivate() : reply(0), status(QmlFontFamily::Null) {} + + void addFontToDatabase(const QByteArray &); + + QUrl url; + QString name; + QNetworkReply *reply; + QmlFontFamily::Status status; +}; + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FontFamily,QmlFontFamily) + +/*! + \qmlclass FontFamily QmlFontFamily + \ingroup group_utility + \brief This item allows using fonts by name or url. + + Example: + \code + FontFamily { id: FixedFont; name: "Courier" } + FontFamily { id: WebFont; source: "http://www.mysite.com/myfont.ttf" } + + Text { text: "Fixed-size font"; font.family: FixedFont.name } + Text { text: "Fancy font"; font.family: WebFont.name } + \endcode +*/ +QmlFontFamily::QmlFontFamily(QObject *parent) + : QObject(*(new QmlFontFamilyPrivate), parent) +{ +} + +QmlFontFamily::~QmlFontFamily() +{ +} + +/*! + \qmlproperty url FontFamily::source + The url of the font to load. +*/ +QUrl QmlFontFamily::source() const +{ + Q_D(const QmlFontFamily); + return d->url; +} + +void QmlFontFamily::setSource(const QUrl &url) +{ + Q_D(QmlFontFamily); + if (url == d->url) + return; + d->url = qmlContext(this)->resolvedUrl(url); + + d->status = Loading; + emit statusChanged(); +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + if (d->url.scheme() == QLatin1String("file")) { + QFile file(d->url.toLocalFile()); + file.open(QIODevice::ReadOnly); + QByteArray ba = file.readAll(); + d->addFontToDatabase(ba); + } else +#endif + { + QNetworkRequest req(d->url); + req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); + d->reply = qmlEngine(this)->networkAccessManager()->get(req); + QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(replyFinished())); + } +} + +/*! + \qmlproperty string FontFamily::name + + This property holds the name of the font family. + It is set automatically when a font is loaded using the \c url property. + + Use this to set the \c font.family property of a \c Text item. + + Example: + \qml + FontFamily { id: WebFont; source: "http://www.mysite.com/myfont.ttf" } + Text { text: "Fancy font"; font.family: WebFont.name } + \endqml +*/ +QString QmlFontFamily::name() const +{ + Q_D(const QmlFontFamily); + return d->name; +} + +void QmlFontFamily::setName(const QString &name) +{ + Q_D(QmlFontFamily); + if (d->name == name ) + return; + d->name = name; + emit nameChanged(); +} + +/*! + \qmlproperty enum FontFamily::status + + This property holds the status of font loading. It can be one of: + \list + \o Null - no font has been set + \o Ready - the font has been loaded + \o Loading - the font is currently being loaded + \o Error - an error occurred while loading the font + \endlist +*/ +QmlFontFamily::Status QmlFontFamily::status() const +{ + Q_D(const QmlFontFamily); + return d->status; +} + +void QmlFontFamily::replyFinished() +{ + Q_D(QmlFontFamily); + if (!d->reply->error()) { + QByteArray ba = d->reply->readAll(); + d->addFontToDatabase(ba); + } else { + d->status = Error; + emit statusChanged(); + } + d->reply->deleteLater(); + d->reply = 0; +} + +void QmlFontFamilyPrivate::addFontToDatabase(const QByteArray &ba) +{ + Q_Q(QmlFontFamily); + + int id = QFontDatabase::addApplicationFontFromData(ba); + if (id != -1) { + name = QFontDatabase::applicationFontFamilies(id).at(0); + emit q->nameChanged(); + status = QmlFontFamily::Ready; + } else { + status = QmlFontFamily::Error; + qWarning() << "Cannot load font: " << name << url; + } + emit q->statusChanged(); +} + +QT_END_NAMESPACE diff --git a/src/declarative/extra/qmlfontfamily.h b/src/declarative/extra/qmlfontfamily.h new file mode 100644 index 0000000..17b6635 --- /dev/null +++ b/src/declarative/extra/qmlfontfamily.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLFONTFAMILY_H +#define QMLFONTFAMILY_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlFontFamilyPrivate; +class Q_DECLARATIVE_EXPORT QmlFontFamily : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlFontFamily) + Q_ENUMS(Status) + + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + +public: + enum Status { Null = 0, Ready, Loading, Error }; + + QmlFontFamily(QObject *parent = 0); + ~QmlFontFamily(); + + QUrl source() const; + void setSource(const QUrl &url); + + QString name() const; + void setName(const QString &name); + + Status status() const; + +private Q_SLOTS: + void replyFinished(); + +Q_SIGNALS: + void nameChanged(); + void statusChanged(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlFontFamily) + +QT_END_HEADER + +#endif // QMLFONTFAMILY_H + diff --git a/src/declarative/util/qmlfontfamily.cpp b/src/declarative/util/qmlfontfamily.cpp deleted file mode 100644 index 73688c1..0000000 --- a/src/declarative/util/qmlfontfamily.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "private/qobject_p.h" -#include "qmlfontfamily.h" -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QmlFontFamilyPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlFontFamily); - -public: - QmlFontFamilyPrivate() : reply(0), status(QmlFontFamily::Null) {} - - void addFontToDatabase(const QByteArray &); - - QUrl url; - QString name; - QNetworkReply *reply; - QmlFontFamily::Status status; -}; - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FontFamily,QmlFontFamily) - -/*! - \qmlclass FontFamily QmlFontFamily - \ingroup group_utility - \brief This item allows using fonts by name or url. - - Example: - \code - FontFamily { id: FixedFont; name: "Courier" } - FontFamily { id: WebFont; source: "http://www.mysite.com/myfont.ttf" } - - Text { text: "Fixed-size font"; font.family: FixedFont.name } - Text { text: "Fancy font"; font.family: WebFont.name } - \endcode -*/ -QmlFontFamily::QmlFontFamily(QObject *parent) - : QObject(*(new QmlFontFamilyPrivate), parent) -{ -} - -QmlFontFamily::~QmlFontFamily() -{ -} - -/*! - \qmlproperty url FontFamily::source - The url of the font to load. -*/ -QUrl QmlFontFamily::source() const -{ - Q_D(const QmlFontFamily); - return d->url; -} - -void QmlFontFamily::setSource(const QUrl &url) -{ - Q_D(QmlFontFamily); - if (url == d->url) - return; - d->url = qmlContext(this)->resolvedUrl(url); - - d->status = Loading; - emit statusChanged(); -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - if (d->url.scheme() == QLatin1String("file")) { - QFile file(d->url.toLocalFile()); - file.open(QIODevice::ReadOnly); - QByteArray ba = file.readAll(); - d->addFontToDatabase(ba); - } else -#endif - { - QNetworkRequest req(d->url); - req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - d->reply = qmlEngine(this)->networkAccessManager()->get(req); - QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(replyFinished())); - } -} - -/*! - \qmlproperty string FontFamily::name - - This property holds the name of the font family. - It is set automatically when a font is loaded using the \c url property. - - Use this to set the \c font.family property of a \c Text item. - - Example: - \qml - FontFamily { id: WebFont; source: "http://www.mysite.com/myfont.ttf" } - Text { text: "Fancy font"; font.family: WebFont.name } - \endqml -*/ -QString QmlFontFamily::name() const -{ - Q_D(const QmlFontFamily); - return d->name; -} - -void QmlFontFamily::setName(const QString &name) -{ - Q_D(QmlFontFamily); - if (d->name == name ) - return; - d->name = name; - emit nameChanged(); -} - -/*! - \qmlproperty enum FontFamily::status - - This property holds the status of font loading. It can be one of: - \list - \o Null - no font has been set - \o Ready - the font has been loaded - \o Loading - the font is currently being loaded - \o Error - an error occurred while loading the font - \endlist -*/ -QmlFontFamily::Status QmlFontFamily::status() const -{ - Q_D(const QmlFontFamily); - return d->status; -} - -void QmlFontFamily::replyFinished() -{ - Q_D(QmlFontFamily); - if (!d->reply->error()) { - QByteArray ba = d->reply->readAll(); - d->addFontToDatabase(ba); - } else { - d->status = Error; - emit statusChanged(); - } - d->reply->deleteLater(); - d->reply = 0; -} - -void QmlFontFamilyPrivate::addFontToDatabase(const QByteArray &ba) -{ - Q_Q(QmlFontFamily); - - int id = QFontDatabase::addApplicationFontFromData(ba); - if (id != -1) { - name = QFontDatabase::applicationFontFamilies(id).at(0); - emit q->nameChanged(); - status = QmlFontFamily::Ready; - } else { - status = QmlFontFamily::Error; - qWarning() << "Cannot load font: " << name << url; - } - emit q->statusChanged(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/util/qmlfontfamily.h b/src/declarative/util/qmlfontfamily.h deleted file mode 100644 index 17b6635..0000000 --- a/src/declarative/util/qmlfontfamily.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLFONTFAMILY_H -#define QMLFONTFAMILY_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlFontFamilyPrivate; -class Q_DECLARATIVE_EXPORT QmlFontFamily : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlFontFamily) - Q_ENUMS(Status) - - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - -public: - enum Status { Null = 0, Ready, Loading, Error }; - - QmlFontFamily(QObject *parent = 0); - ~QmlFontFamily(); - - QUrl source() const; - void setSource(const QUrl &url); - - QString name() const; - void setName(const QString &name); - - Status status() const; - -private Q_SLOTS: - void replyFinished(); - -Q_SIGNALS: - void nameChanged(); - void statusChanged(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlFontFamily) - -QT_END_HEADER - -#endif // QMLFONTFAMILY_H - diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index dfb79ac..59e3695 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -7,7 +7,6 @@ SOURCES += \ util/qmlscript.cpp \ util/qmlanimation.cpp \ util/qmlfont.cpp \ - util/qmlfontfamily.cpp \ util/qmlpalette.cpp \ util/qmlfollow.cpp \ util/qmlstate.cpp\ @@ -34,7 +33,6 @@ HEADERS += \ util/qmlanimation.h \ util/qmlanimation_p.h \ util/qmlfont.h \ - util/qmlfontfamily.h \ util/qmlpalette.h \ util/qmlfollow.h \ util/qmlstate.h\ -- cgit v0.12 From 28a76d03cd4f74d2619c8ab402fa97e71ce41310 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 5 Aug 2009 08:52:32 +1000 Subject: Get qmldebugger running, and add basic object/property view. --- src/declarative/debugger/qmldebug.cpp | 1 + src/declarative/qml/qmlenginedebug.cpp | 9 +- src/declarative/qml/qmlenginedebug_p.h | 1 + tools/qmldebugger/canvasscene.cpp | 248 --------------------------------- tools/qmldebugger/canvasscene.h | 43 ------ tools/qmldebugger/engine.cpp | 77 +++++++++- tools/qmldebugger/engine.h | 9 ++ tools/qmldebugger/engines.qml | 2 +- tools/qmldebugger/main.cpp | 4 - tools/qmldebugger/qmldebugger.pro | 4 +- tools/tools.pro | 2 +- 11 files changed, 93 insertions(+), 307 deletions(-) delete mode 100644 tools/qmldebugger/canvasscene.cpp delete mode 100644 tools/qmldebugger/canvasscene.h diff --git a/src/declarative/debugger/qmldebug.cpp b/src/declarative/debugger/qmldebug.cpp index 8309ec6..9397bb9 100644 --- a/src/declarative/debugger/qmldebug.cpp +++ b/src/declarative/debugger/qmldebug.cpp @@ -103,6 +103,7 @@ void QmlEngineDebugPrivate::decode(QDataStream &ds, QmlDebugObjectReference &o, ds >> data; QmlDebugPropertyReference prop; prop.m_name = data.name; + prop.m_binding = data.binding; if (data.type == QmlEngineDebugServer::QmlObjectProperty::Basic) prop.m_value = data.value; else if (data.type == QmlEngineDebugServer::QmlObjectProperty::Object) { diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp index 2b8aac3..c26f3b7 100644 --- a/src/declarative/qml/qmlenginedebug.cpp +++ b/src/declarative/qml/qmlenginedebug.cpp @@ -44,6 +44,8 @@ #include #include #include +#include +#include #include "qmlcontext_p.h" QT_BEGIN_NAMESPACE @@ -73,7 +75,7 @@ QDataStream &operator>>(QDataStream &ds, QDataStream &operator<<(QDataStream &ds, const QmlEngineDebugServer::QmlObjectProperty &data) { - ds << (int)data.type << data.name << data.value; + ds << (int)data.type << data.name << data.value << data.binding; return ds; } @@ -81,7 +83,7 @@ QDataStream &operator>>(QDataStream &ds, QmlEngineDebugServer::QmlObjectProperty &data) { int type; - ds >> type >> data.name >> data.value; + ds >> type >> data.name >> data.value >> data.binding; data.type = (QmlEngineDebugServer::QmlObjectProperty::Type)type; return ds; } @@ -95,6 +97,9 @@ QmlEngineDebugServer::propertyData(QObject *obj, int propIdx) rv.type = QmlObjectProperty::Unknown; rv.name = prop.name(); + QmlBinding *binding = QmlMetaProperty(obj, rv.name).binding(); + if (binding) + rv.binding = binding->expression(); if (prop.type() < QVariant::UserType) { rv.type = QmlObjectProperty::Basic; diff --git a/src/declarative/qml/qmlenginedebug_p.h b/src/declarative/qml/qmlenginedebug_p.h index e85ab6f..87b2ffd 100644 --- a/src/declarative/qml/qmlenginedebug_p.h +++ b/src/declarative/qml/qmlenginedebug_p.h @@ -81,6 +81,7 @@ public: Type type; QString name; QVariant value; + QString binding; }; static void addEngine(QmlEngine *); diff --git a/tools/qmldebugger/canvasscene.cpp b/tools/qmldebugger/canvasscene.cpp deleted file mode 100644 index 65db9da..0000000 --- a/tools/qmldebugger/canvasscene.cpp +++ /dev/null @@ -1,248 +0,0 @@ -#include "canvasscene.h" -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class CanvasSceneClientPlugin : public QmlDebugClient -{ -public: - CanvasSceneClientPlugin(QmlDebugConnection *, CanvasScene *s); - -protected: - void messageReceived(const QByteArray &); - -private: - void dump(QDataStream &, int indent); - CanvasScene *scene; -}; - -class QmlCanvasDebuggerItem : public QTreeWidgetItem -{ -public: - QmlCanvasDebuggerItem(QTreeWidget *tree) - : QTreeWidgetItem(tree), me(0), img(0) - { - } - - QmlCanvasDebuggerItem(QTreeWidgetItem *item) - : QTreeWidgetItem(item), me(0), img(0) - { - } - - QFxRect *me; - QFxImage *img; -}; - -CanvasSceneClientPlugin::CanvasSceneClientPlugin(QmlDebugConnection *c, - CanvasScene *s) -: QmlDebugClient(QLatin1String("CanvasScene"), c), scene(s) -{ -} - -void CanvasSceneClientPlugin::messageReceived(const QByteArray &data) -{ - QByteArray d = data; - QDataStream ds(&d, QIODevice::ReadOnly); - - scene->message(ds); -} - -void CanvasScene::message(QDataStream &ds) -{ - QList children = m_canvasRoot->children(); - qDeleteAll(children); - m_tree->clear(); - m_selected = 0; - - QTreeWidgetItem *root = new QmlCanvasDebuggerItem(m_tree); - root->setText(0, tr("Root")); - root->setExpanded(true); - clone(root, m_canvasRoot, ds); -} - -void CanvasScene::clone(QTreeWidgetItem *item, QSimpleCanvasItem *me, - QDataStream &ds) -{ - int children; - ds >> children; - - for (int ii = 0; ii < children; ++ii) { - QString name; - qreal x, y, z, width, height, scale; - QTransform transform; - bool activeFocus; - int transformOrigin, flip, options; - QPixmap pix; - - ds >> name >> x >> y >> z >> width >> height >> transformOrigin >> scale - >> flip >> transform >> activeFocus >> options >> pix; - - QmlCanvasDebuggerItem *childItem = new QmlCanvasDebuggerItem(item); - childItem->setText(0, name); - childItem->setExpanded(true); - - QFxRect *rect = new QFxRect; - rect->setParent(me); - rect->setX(x); - rect->setY(y); - rect->setZ(z); - rect->setWidth(width); - rect->setHeight(height); - rect->setTransformOrigin((QSimpleCanvasItem::TransformOrigin)transformOrigin); - rect->setScale(scale); - rect->setFlip((QSimpleCanvasItem::Flip)flip); - rect->setTransform(transform); - - if (activeFocus) - rect->setColor(QColor(0, 0, 0, 10)); - else if(options & QSimpleCanvasItem::IsFocusPanel) - rect->setColor(QColor(0, 255, 0, 10)); - else if(options & QSimpleCanvasItem::IsFocusRealm) - rect->setColor(QColor(0, 0, 255, 10)); - else - rect->setColor(QColor(255, 0, 0, 10)); - - if (pix.width() > 0 || pix.height() > 0) { - QFxImage *img = new QFxImage; - img->setParent(rect); - img->setWidth(width); - img->setHeight(height); - img->setPixmap(pix); - img->setOpacity(0); - childItem->img = img; - } - - childItem->me = rect; - - clone(childItem, rect, ds); - } -} - -void CanvasSceneClientPlugin::dump(QDataStream &ds, int indent) -{ - QString name; - qreal x, y, z, width, height, scale; - QTransform transform; - bool activeFocus; - int transformOrigin, flip, options, count; - QPixmap pix; - - ds >> name >> x >> y >> z >> width >> height >> transformOrigin >> scale - >> flip >> transform >> activeFocus >> options >> pix >> count; - - QByteArray ba(indent * 4, ' '); - qWarning() << ba.constData() << name << x << y; - - for(int ii = 0; ii < count; ++ii) - dump(ds, indent + 1); -} - -CanvasScene::CanvasScene(QmlDebugConnection *c, QWidget *parent) -: QWidget(parent) -{ - client = new CanvasSceneClientPlugin(c, this); - - QVBoxLayout *layout = new QVBoxLayout; - layout->setContentsMargins(0,0,0,0); - layout->setSpacing(0); - setLayout(layout); - QSplitter *splitter = new QSplitter(this); - - m_tree = new QTreeWidget(this); - m_tree->setHeaderHidden(true); - QObject::connect(m_tree, SIGNAL(itemExpanded(QTreeWidgetItem*)), - this, SLOT(itemExpanded(QTreeWidgetItem*))); - QObject::connect(m_tree, SIGNAL(itemCollapsed(QTreeWidgetItem*)), - this, SLOT(itemCollapsed(QTreeWidgetItem*))); - QObject::connect(m_tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), - this, SLOT(itemClicked(QTreeWidgetItem*))); - m_canvas = new QSimpleCanvas(QSimpleCanvas::SimpleCanvas, this); - m_canvasRoot = new QSimpleCanvasItem; - m_canvasRoot->setParent(m_canvas->root()); - splitter->addWidget(m_tree); - splitter->addWidget(m_canvas); - splitter->setStretchFactor(1, 2); - layout->addWidget(splitter); - - QHBoxLayout *hlayout = new QHBoxLayout; - hlayout->setContentsMargins(0,0,0,0); - hlayout->addStretch(2); - hlayout->setSpacing(0); - layout->addLayout(hlayout); - QSpinBox *x = new QSpinBox(this); - x->setSingleStep(50); - x->setMaximum(10000); - x->setMinimum(-10000); - QObject::connect(x, SIGNAL(valueChanged(int)), this, SLOT(setX(int))); - QSpinBox *y = new QSpinBox(this); - y->setSingleStep(50); - y->setMaximum(10000); - y->setMinimum(-10000); - QObject::connect(y, SIGNAL(valueChanged(int)), this, SLOT(setY(int))); - hlayout->addWidget(x); - hlayout->addWidget(y); - QPushButton *pb = new QPushButton(tr("Refresh"), this); - QObject::connect(pb, SIGNAL(clicked()), this, SLOT(refresh())); - hlayout->addWidget(pb); -} - -void CanvasScene::refresh() -{ - client->sendMessage(QByteArray()); -} - -void CanvasScene::itemExpanded(QTreeWidgetItem *i) -{ - QmlCanvasDebuggerItem *item = static_cast(i); - if(item->me) - item->me->setOpacity(1); -} - -void CanvasScene::setOpacityRecur(QTreeWidgetItem *i, qreal op) -{ - QmlCanvasDebuggerItem *item = static_cast(i); - if(item->img) - item->img->setOpacity(op); - - for(int ii = 0; ii < item->childCount(); ++ii) - setOpacityRecur(item->child(ii), op); -} - -void CanvasScene::itemClicked(QTreeWidgetItem *i) -{ - QmlCanvasDebuggerItem *item = static_cast(i); - - if(m_selected) { - setOpacityRecur(m_selected, 0); - m_selected = 0; - } - - m_selected = item; - setOpacityRecur(m_selected, 1); -} - -void CanvasScene::itemCollapsed(QTreeWidgetItem *i) -{ - QmlCanvasDebuggerItem *item = static_cast(i); - if(item->me) - item->me->setOpacity(0); -} - -void CanvasScene::setX(int x) -{ - m_canvasRoot->setX(x); -} - -void CanvasScene::setY(int y) -{ - m_canvasRoot->setY(y); -} - -QT_END_NAMESPACE diff --git a/tools/qmldebugger/canvasscene.h b/tools/qmldebugger/canvasscene.h deleted file mode 100644 index 8c6b8d5..0000000 --- a/tools/qmldebugger/canvasscene.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef CANVASSCENE_H -#define CANVASSCENE_H - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QmlDebugConnection; -class CanvasSceneClient; -class QmlDebugClient; -class CanvasScene : public QWidget -{ -Q_OBJECT -public: - CanvasScene(QmlDebugConnection *, QWidget *parent = 0); - - void message(QDataStream &); -private slots: - void refresh(); - void itemClicked(QTreeWidgetItem *); - void itemExpanded(QTreeWidgetItem *); - void itemCollapsed(QTreeWidgetItem *); - void setX(int); - void setY(int); - -private: - void setOpacityRecur(QTreeWidgetItem *, qreal); - void clone(QTreeWidgetItem *item, QSimpleCanvasItem *me, QDataStream &); - QmlDebugClient *client; - - QTreeWidget *m_tree; - QSimpleCanvas *m_canvas; - QSimpleCanvasItem *m_canvasRoot; - QTreeWidgetItem *m_selected; -}; - -QT_END_NAMESPACE - -#endif // CANVASSCENE_H - diff --git a/tools/qmldebugger/engine.cpp b/tools/qmldebugger/engine.cpp index 3b8c8b1..229cd3f 100644 --- a/tools/qmldebugger/engine.cpp +++ b/tools/qmldebugger/engine.cpp @@ -2,7 +2,10 @@ #include #include #include +#include #include +#include +#include #include #include #include @@ -11,9 +14,9 @@ QT_BEGIN_NAMESPACE class DebuggerEngineItem : public QObject { -Q_OBJECT -Q_PROPERTY(QString name READ name CONSTANT); -Q_PROPERTY(QString engineId READ engineId CONSTANT); + Q_OBJECT + Q_PROPERTY(QString name READ name CONSTANT); + Q_PROPERTY(int engineId READ engineId CONSTANT); public: DebuggerEngineItem(const QString &name, int id) @@ -56,7 +59,23 @@ EnginePane::EnginePane(QmlDebugConnection *client, QWidget *parent) QObject::connect(query, SIGNAL(clicked()), this, SLOT(fetchClicked())); layout->addWidget(query); - layout->addStretch(10); + QHBoxLayout *hbox = new QHBoxLayout; + hbox->setContentsMargins(0, 0, 0, 0); + + m_objTree = new QTreeWidget(this); + m_objTree->setHeaderHidden(true); + connect(m_objTree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(itemClicked(QTreeWidgetItem *))); + hbox->addWidget(m_objTree); + + m_propTable = new QTableWidget(this); + m_propTable->setColumnCount(2); + m_propTable->setColumnWidth(0, 150); + m_propTable->setColumnWidth(1, 400); + m_propTable->setHorizontalHeaderLabels(QStringList() << "name" << "value"); + hbox->addWidget(m_propTable); + hbox->setStretchFactor(m_propTable, 2); + + layout->addLayout(hbox); } void EnginePane::engineSelected(int id) @@ -65,6 +84,40 @@ void EnginePane::engineSelected(int id) queryContext(id); } +void EnginePane::itemClicked(QTreeWidgetItem *item) +{ + m_propTable->clearContents(); + + if (m_object) { + delete m_object; + m_object = 0; + } + + m_object = m_client.queryObjectRecursive(QmlDebugObjectReference(item->data(0, Qt::UserRole).toInt()), this); + if (!m_object->isWaiting()) + showProperties(); + else + QObject::connect(m_object, SIGNAL(stateChanged(State)), + this, SLOT(showProperties())); +} + +void EnginePane::showProperties() +{ + QmlDebugObjectReference obj = m_object->object(); + m_propTable->setRowCount(obj.properties().count()); + for (int ii = 0; ii < obj.properties().count(); ++ii) { + QTableWidgetItem *name = new QTableWidgetItem(obj.properties().at(ii).name()); + m_propTable->setItem(ii, 0, name); + QTableWidgetItem *value; + if (!obj.properties().at(ii).binding().isEmpty()) + value = new QTableWidgetItem(obj.properties().at(ii).binding()); + else + value = new QTableWidgetItem(obj.properties().at(ii).value().toString()); + m_propTable->setItem(ii, 1, value); + } + delete m_object; m_object = 0; +} + void EnginePane::queryContext(int id) { if (m_context) { @@ -110,6 +163,17 @@ void EnginePane::dump(const QmlDebugObjectReference &obj, int ind) dump(obj.children().at(ii), ind + 1); } + +void EnginePane::buildTree(const QmlDebugObjectReference &obj, QTreeWidgetItem *parent) +{ + QTreeWidgetItem *item = parent ? new QTreeWidgetItem(parent) : new QTreeWidgetItem(m_objTree); + item->setText(0, obj.className()); + item->setData(0, Qt::UserRole, obj.debugId()); + + for (int ii = 0; ii < obj.children().count(); ++ii) + buildTree(obj.children().at(ii), item); +} + void EnginePane::queryEngines() { if (m_engines) @@ -131,8 +195,8 @@ void EnginePane::enginesChanged() QList engines = m_engines->engines(); delete m_engines; m_engines = 0; - for (int ii = 0; ii < engines.count(); ++ii) - m_engineItems << new DebuggerEngineItem(engines.at(ii).name(), + for (int ii = 0; ii < engines.count(); ++ii) + m_engineItems << new DebuggerEngineItem(engines.at(ii).name(), engines.at(ii).debugId()); m_engineView->rootContext()->setContextProperty("engines", qVariantFromValue(&m_engineItems)); @@ -162,6 +226,7 @@ void EnginePane::fetchObject(int id) void EnginePane::objectFetched() { dump(m_object->object(), 0); + buildTree(m_object->object(), 0); delete m_object; m_object = 0; } diff --git a/tools/qmldebugger/engine.h b/tools/qmldebugger/engine.h index a713f25..52f0608 100644 --- a/tools/qmldebugger/engine.h +++ b/tools/qmldebugger/engine.h @@ -12,6 +12,9 @@ QT_BEGIN_NAMESPACE class QmlDebugConnection; class EngineClientPlugin; class QLineEdit; +class QTreeWidget; +class QTreeWidgetItem; +class QTableWidget; class EnginePane : public QWidget { Q_OBJECT @@ -31,9 +34,13 @@ private slots: void engineSelected(int); + void itemClicked(QTreeWidgetItem *); + void showProperties(); + private: void dump(const QmlDebugContextReference &, int); void dump(const QmlDebugObjectReference &, int); + void buildTree(const QmlDebugObjectReference &, QTreeWidgetItem *parent); QmlEngineDebug m_client; QmlDebugEnginesQuery *m_engines; @@ -41,6 +48,8 @@ private: QmlDebugObjectQuery *m_object; QLineEdit *m_text; + QTreeWidget *m_objTree; + QTableWidget *m_propTable; QFxView *m_engineView; QList m_engineItems; diff --git a/tools/qmldebugger/engines.qml b/tools/qmldebugger/engines.qml index fc364e2..eedba08 100644 --- a/tools/qmldebugger/engines.qml +++ b/tools/qmldebugger/engines.qml @@ -19,7 +19,7 @@ Item { } Text { anchors.top: Image.bottom; - text: modelData.name + "(" + modelData.engineId + ")" + text: modelData.name + "(" + modelData.engineId + ")" anchors.horizontalCenter: parent.horizontalCenter } MouseRegion { diff --git a/tools/qmldebugger/main.cpp b/tools/qmldebugger/main.cpp index 500836f..a37a437 100644 --- a/tools/qmldebugger/main.cpp +++ b/tools/qmldebugger/main.cpp @@ -8,7 +8,6 @@ #include #include #include "canvasframerate.h" -#include "canvasscene.h" #include "engine.h" #include #include @@ -75,9 +74,6 @@ Shell::Shell(QWidget *parent) CanvasFrameRate *cfr = new CanvasFrameRate(&client, this); tabs->addTab(cfr, tr("Frame Rate")); - CanvasScene *cs = new CanvasScene(&client, this); - tabs->addTab(cs, tr("Scene")); - EnginePane *ep = new EnginePane(&client, this); tabs->addTab(ep, tr("QML Engine")); diff --git a/tools/qmldebugger/qmldebugger.pro b/tools/qmldebugger/qmldebugger.pro index 1068858..532fd2a 100644 --- a/tools/qmldebugger/qmldebugger.pro +++ b/tools/qmldebugger/qmldebugger.pro @@ -3,8 +3,8 @@ QT += network declarative contains(QT_CONFIG, opengles2)|contains(QT_CONFIG, opengles1): QT += opengl # Input -HEADERS += canvasframerate.h canvasscene.h engine.h -SOURCES += main.cpp canvasframerate.cpp canvasscene.cpp engine.cpp +HEADERS += canvasframerate.h engine.h +SOURCES += main.cpp canvasframerate.cpp engine.cpp target.path=$$[QT_INSTALL_BINS] INSTALLS += target diff --git a/tools/tools.pro b/tools/tools.pro index ecdbcd1..68b4801 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -24,7 +24,7 @@ mac { embedded:SUBDIRS += kmap2qmap -contains(QT_CONFIG, declarative):SUBDIRS += qmlviewer +contains(QT_CONFIG, declarative):SUBDIRS += qmlviewer qmldebugger contains(QT_CONFIG, dbus):SUBDIRS += qdbus !wince*:contains(QT_CONFIG, xmlpatterns): SUBDIRS += xmlpatterns xmlpatternsvalidator embedded: SUBDIRS += makeqpf -- cgit v0.12 From 29b184cf0bdebafe6d667994543f7af6e44b709b Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 5 Aug 2009 09:12:57 +1000 Subject: Renaming: FontFamily -> FontLoader --- examples/declarative/fonts/fonts.qml | 8 +- src/declarative/extra/extra.pri | 4 +- src/declarative/extra/qmlfontfamily.cpp | 206 -------------------------------- src/declarative/extra/qmlfontfamily.h | 94 --------------- src/declarative/extra/qmlfontloader.cpp | 206 ++++++++++++++++++++++++++++++++ src/declarative/extra/qmlfontloader.h | 94 +++++++++++++++ 6 files changed, 306 insertions(+), 306 deletions(-) delete mode 100644 src/declarative/extra/qmlfontfamily.cpp delete mode 100644 src/declarative/extra/qmlfontfamily.h create mode 100644 src/declarative/extra/qmlfontloader.cpp create mode 100644 src/declarative/extra/qmlfontloader.h diff --git a/examples/declarative/fonts/fonts.qml b/examples/declarative/fonts/fonts.qml index eb8cfef..c981e51 100644 --- a/examples/declarative/fonts/fonts.qml +++ b/examples/declarative/fonts/fonts.qml @@ -8,13 +8,13 @@ Rect { Palette { id: Palette; colorGroup: "Active" } - FontFamily { id: FixedFont; name: "Courier" } + FontLoader { id: FixedFont; name: "Courier" } - FontFamily { id: LocalFont; source: "fonts/Fontin-Bold.ttf" } + FontLoader { id: LocalFont; source: "fonts/Fontin-Bold.ttf" } /* A font by Jos Buivenga (exljbris) -> www.exljbris.nl */ - FontFamily { id: WebFont; source: "http://www.princexml.com/fonts/steffmann/Starburst.ttf" } - FontFamily { id: WebFont2; source: "http://wrong.address.org" } + FontLoader { id: WebFont; source: "http://www.princexml.com/fonts/steffmann/Starburst.ttf" } + FontLoader { id: WebFont2; source: "http://wrong.address.org" } VerticalLayout { anchors.fill: parent diff --git a/src/declarative/extra/extra.pri b/src/declarative/extra/extra.pri index c731afa..1f84406 100644 --- a/src/declarative/extra/extra.pri +++ b/src/declarative/extra/extra.pri @@ -9,7 +9,7 @@ SOURCES += \ extra/qfxparticles.cpp \ extra/qmlbehaviour.cpp \ extra/qbindablemap.cpp \ - extra/qmlfontfamily.cpp + extra/qmlfontloader.cpp HEADERS += \ extra/qnumberformat.h \ @@ -23,7 +23,7 @@ HEADERS += \ extra/qfxparticles.h \ extra/qmlbehaviour.h \ extra/qbindablemap.h \ - extra/qmlfontfamily.h + extra/qmlfontloader.h contains(QT_CONFIG, xmlpatterns) { QT+=xmlpatterns diff --git a/src/declarative/extra/qmlfontfamily.cpp b/src/declarative/extra/qmlfontfamily.cpp deleted file mode 100644 index 73688c1..0000000 --- a/src/declarative/extra/qmlfontfamily.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "private/qobject_p.h" -#include "qmlfontfamily.h" -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QmlFontFamilyPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlFontFamily); - -public: - QmlFontFamilyPrivate() : reply(0), status(QmlFontFamily::Null) {} - - void addFontToDatabase(const QByteArray &); - - QUrl url; - QString name; - QNetworkReply *reply; - QmlFontFamily::Status status; -}; - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FontFamily,QmlFontFamily) - -/*! - \qmlclass FontFamily QmlFontFamily - \ingroup group_utility - \brief This item allows using fonts by name or url. - - Example: - \code - FontFamily { id: FixedFont; name: "Courier" } - FontFamily { id: WebFont; source: "http://www.mysite.com/myfont.ttf" } - - Text { text: "Fixed-size font"; font.family: FixedFont.name } - Text { text: "Fancy font"; font.family: WebFont.name } - \endcode -*/ -QmlFontFamily::QmlFontFamily(QObject *parent) - : QObject(*(new QmlFontFamilyPrivate), parent) -{ -} - -QmlFontFamily::~QmlFontFamily() -{ -} - -/*! - \qmlproperty url FontFamily::source - The url of the font to load. -*/ -QUrl QmlFontFamily::source() const -{ - Q_D(const QmlFontFamily); - return d->url; -} - -void QmlFontFamily::setSource(const QUrl &url) -{ - Q_D(QmlFontFamily); - if (url == d->url) - return; - d->url = qmlContext(this)->resolvedUrl(url); - - d->status = Loading; - emit statusChanged(); -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - if (d->url.scheme() == QLatin1String("file")) { - QFile file(d->url.toLocalFile()); - file.open(QIODevice::ReadOnly); - QByteArray ba = file.readAll(); - d->addFontToDatabase(ba); - } else -#endif - { - QNetworkRequest req(d->url); - req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - d->reply = qmlEngine(this)->networkAccessManager()->get(req); - QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(replyFinished())); - } -} - -/*! - \qmlproperty string FontFamily::name - - This property holds the name of the font family. - It is set automatically when a font is loaded using the \c url property. - - Use this to set the \c font.family property of a \c Text item. - - Example: - \qml - FontFamily { id: WebFont; source: "http://www.mysite.com/myfont.ttf" } - Text { text: "Fancy font"; font.family: WebFont.name } - \endqml -*/ -QString QmlFontFamily::name() const -{ - Q_D(const QmlFontFamily); - return d->name; -} - -void QmlFontFamily::setName(const QString &name) -{ - Q_D(QmlFontFamily); - if (d->name == name ) - return; - d->name = name; - emit nameChanged(); -} - -/*! - \qmlproperty enum FontFamily::status - - This property holds the status of font loading. It can be one of: - \list - \o Null - no font has been set - \o Ready - the font has been loaded - \o Loading - the font is currently being loaded - \o Error - an error occurred while loading the font - \endlist -*/ -QmlFontFamily::Status QmlFontFamily::status() const -{ - Q_D(const QmlFontFamily); - return d->status; -} - -void QmlFontFamily::replyFinished() -{ - Q_D(QmlFontFamily); - if (!d->reply->error()) { - QByteArray ba = d->reply->readAll(); - d->addFontToDatabase(ba); - } else { - d->status = Error; - emit statusChanged(); - } - d->reply->deleteLater(); - d->reply = 0; -} - -void QmlFontFamilyPrivate::addFontToDatabase(const QByteArray &ba) -{ - Q_Q(QmlFontFamily); - - int id = QFontDatabase::addApplicationFontFromData(ba); - if (id != -1) { - name = QFontDatabase::applicationFontFamilies(id).at(0); - emit q->nameChanged(); - status = QmlFontFamily::Ready; - } else { - status = QmlFontFamily::Error; - qWarning() << "Cannot load font: " << name << url; - } - emit q->statusChanged(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/extra/qmlfontfamily.h b/src/declarative/extra/qmlfontfamily.h deleted file mode 100644 index 17b6635..0000000 --- a/src/declarative/extra/qmlfontfamily.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLFONTFAMILY_H -#define QMLFONTFAMILY_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlFontFamilyPrivate; -class Q_DECLARATIVE_EXPORT QmlFontFamily : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlFontFamily) - Q_ENUMS(Status) - - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - -public: - enum Status { Null = 0, Ready, Loading, Error }; - - QmlFontFamily(QObject *parent = 0); - ~QmlFontFamily(); - - QUrl source() const; - void setSource(const QUrl &url); - - QString name() const; - void setName(const QString &name); - - Status status() const; - -private Q_SLOTS: - void replyFinished(); - -Q_SIGNALS: - void nameChanged(); - void statusChanged(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlFontFamily) - -QT_END_HEADER - -#endif // QMLFONTFAMILY_H - diff --git a/src/declarative/extra/qmlfontloader.cpp b/src/declarative/extra/qmlfontloader.cpp new file mode 100644 index 0000000..2f54f24 --- /dev/null +++ b/src/declarative/extra/qmlfontloader.cpp @@ -0,0 +1,206 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "private/qobject_p.h" +#include "qmlfontloader.h" +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlFontLoaderPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlFontLoader); + +public: + QmlFontLoaderPrivate() : reply(0), status(QmlFontLoader::Null) {} + + void addFontToDatabase(const QByteArray &); + + QUrl url; + QString name; + QNetworkReply *reply; + QmlFontLoader::Status status; +}; + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FontLoader,QmlFontLoader) + +/*! + \qmlclass FontLoader QmlFontLoader + \ingroup group_utility + \brief This item allows using fonts by name or url. + + Example: + \code + FontLoader { id: FixedFont; name: "Courier" } + FontLoader { id: WebFont; source: "http://www.mysite.com/myfont.ttf" } + + Text { text: "Fixed-size font"; font.family: FixedFont.name } + Text { text: "Fancy font"; font.family: WebFont.name } + \endcode +*/ +QmlFontLoader::QmlFontLoader(QObject *parent) + : QObject(*(new QmlFontLoaderPrivate), parent) +{ +} + +QmlFontLoader::~QmlFontLoader() +{ +} + +/*! + \qmlproperty url FontLoader::source + The url of the font to load. +*/ +QUrl QmlFontLoader::source() const +{ + Q_D(const QmlFontLoader); + return d->url; +} + +void QmlFontLoader::setSource(const QUrl &url) +{ + Q_D(QmlFontLoader); + if (url == d->url) + return; + d->url = qmlContext(this)->resolvedUrl(url); + + d->status = Loading; + emit statusChanged(); +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + if (d->url.scheme() == QLatin1String("file")) { + QFile file(d->url.toLocalFile()); + file.open(QIODevice::ReadOnly); + QByteArray ba = file.readAll(); + d->addFontToDatabase(ba); + } else +#endif + { + QNetworkRequest req(d->url); + req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); + d->reply = qmlEngine(this)->networkAccessManager()->get(req); + QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(replyFinished())); + } +} + +/*! + \qmlproperty string FontLoader::name + + This property holds the name of the font family. + It is set automatically when a font is loaded using the \c url property. + + Use this to set the \c font.family property of a \c Text item. + + Example: + \qml + FontLoader { id: WebFont; source: "http://www.mysite.com/myfont.ttf" } + Text { text: "Fancy font"; font.family: WebFont.name } + \endqml +*/ +QString QmlFontLoader::name() const +{ + Q_D(const QmlFontLoader); + return d->name; +} + +void QmlFontLoader::setName(const QString &name) +{ + Q_D(QmlFontLoader); + if (d->name == name ) + return; + d->name = name; + emit nameChanged(); +} + +/*! + \qmlproperty enum FontLoader::status + + This property holds the status of font loading. It can be one of: + \list + \o Null - no font has been set + \o Ready - the font has been loaded + \o Loading - the font is currently being loaded + \o Error - an error occurred while loading the font + \endlist +*/ +QmlFontLoader::Status QmlFontLoader::status() const +{ + Q_D(const QmlFontLoader); + return d->status; +} + +void QmlFontLoader::replyFinished() +{ + Q_D(QmlFontLoader); + if (!d->reply->error()) { + QByteArray ba = d->reply->readAll(); + d->addFontToDatabase(ba); + } else { + d->status = Error; + emit statusChanged(); + } + d->reply->deleteLater(); + d->reply = 0; +} + +void QmlFontLoaderPrivate::addFontToDatabase(const QByteArray &ba) +{ + Q_Q(QmlFontLoader); + + int id = QFontDatabase::addApplicationFontFromData(ba); + if (id != -1) { + name = QFontDatabase::applicationFontFamilies(id).at(0); + emit q->nameChanged(); + status = QmlFontLoader::Ready; + } else { + status = QmlFontLoader::Error; + qWarning() << "Cannot load font: " << name << url; + } + emit q->statusChanged(); +} + +QT_END_NAMESPACE diff --git a/src/declarative/extra/qmlfontloader.h b/src/declarative/extra/qmlfontloader.h new file mode 100644 index 0000000..c2c7a16 --- /dev/null +++ b/src/declarative/extra/qmlfontloader.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLFONTLOADER_H +#define QMLFONTLOADER_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlFontLoaderPrivate; +class Q_DECLARATIVE_EXPORT QmlFontLoader : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlFontLoader) + Q_ENUMS(Status) + + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + +public: + enum Status { Null = 0, Ready, Loading, Error }; + + QmlFontLoader(QObject *parent = 0); + ~QmlFontLoader(); + + QUrl source() const; + void setSource(const QUrl &url); + + QString name() const; + void setName(const QString &name); + + Status status() const; + +private Q_SLOTS: + void replyFinished(); + +Q_SIGNALS: + void nameChanged(); + void statusChanged(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlFontLoader) + +QT_END_HEADER + +#endif // QMLFONTLOADER_H + -- cgit v0.12