diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-06-29 01:23:22 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-06-29 01:23:22 (GMT) |
commit | 16a8e075e09323b3e77f8faa58bfc9e9a3bf310f (patch) | |
tree | d51df8e75b1d81fbecd15553744a768956a7992a /src/declarative/extra | |
parent | 13086523d7181d5628872c74030b460e5f7388a5 (diff) | |
download | Qt-16a8e075e09323b3e77f8faa58bfc9e9a3bf310f.zip Qt-16a8e075e09323b3e77f8faa58bfc9e9a3bf310f.tar.gz Qt-16a8e075e09323b3e77f8faa58bfc9e9a3bf310f.tar.bz2 |
Move some non-essential classes to extra.
Diffstat (limited to 'src/declarative/extra')
-rw-r--r-- | src/declarative/extra/extra.pri | 17 | ||||
-rw-r--r-- | src/declarative/extra/qbindablemap.cpp | 182 | ||||
-rw-r--r-- | src/declarative/extra/qbindablemap.h | 87 | ||||
-rw-r--r-- | src/declarative/extra/qfxanimatedimageitem.cpp | 212 | ||||
-rw-r--r-- | src/declarative/extra/qfxanimatedimageitem.h | 100 | ||||
-rw-r--r-- | src/declarative/extra/qfxanimatedimageitem_p.h | 77 | ||||
-rw-r--r-- | src/declarative/extra/qfxblendedimage.cpp | 308 | ||||
-rw-r--r-- | src/declarative/extra/qfxblendedimage.h | 110 | ||||
-rw-r--r-- | src/declarative/extra/qfxflowview.cpp | 381 | ||||
-rw-r--r-- | src/declarative/extra/qfxflowview.h | 106 | ||||
-rw-r--r-- | src/declarative/extra/qmlbehaviour.cpp | 259 | ||||
-rw-r--r-- | src/declarative/extra/qmlbehaviour.h | 95 | ||||
-rw-r--r-- | src/declarative/extra/qmldatetimeformatter.cpp | 368 | ||||
-rw-r--r-- | src/declarative/extra/qmldatetimeformatter.h | 115 |
14 files changed, 2415 insertions, 2 deletions
diff --git a/src/declarative/extra/extra.pri b/src/declarative/extra/extra.pri index 2590fbc..a0bbdf4 100644 --- a/src/declarative/extra/extra.pri +++ b/src/declarative/extra/extra.pri @@ -1,14 +1,27 @@ SOURCES += \ extra/qnumberformat.cpp \ extra/qmlnumberformatter.cpp \ + extra/qmldatetimeformatter.cpp \ extra/qfxintegermodel.cpp \ - extra/qmltimer.cpp + extra/qmltimer.cpp \ + extra/qfxanimatedimageitem.cpp \ + extra/qfxblendedimage.cpp \ + extra/qfxflowview.cpp \ + extra/qmlbehaviour.cpp \ + extra/qbindablemap.cpp HEADERS += \ extra/qnumberformat.h \ extra/qmlnumberformatter.h \ + extra/qmldatetimeformatter.h \ extra/qfxintegermodel.h \ - extra/qmltimer.h + extra/qmltimer.h \ + extra/qfxanimatedimageitem.h \ + extra/qfxanimatedimageitem_p.h \ + extra/qfxblendedimage.h \ + extra/qfxflowview.h \ + extra/qmlbehaviour.h \ + extra/qbindablemap.h contains(QT_CONFIG, xmlpatterns) { QT+=xmlpatterns diff --git a/src/declarative/extra/qbindablemap.cpp b/src/declarative/extra/qbindablemap.cpp new file mode 100644 index 0000000..c8c8ced --- /dev/null +++ b/src/declarative/extra/qbindablemap.cpp @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** 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 "qbindablemap.h" +#include <qmlopenmetaobject.h> +#include <QDebug> + +QT_BEGIN_NAMESPACE + +//QBindableMapMetaObject lets us listen for changes coming from QML +//so we can emit the changed signal. +class QBindableMapMetaObject : public QmlOpenMetaObject +{ +public: + QBindableMapMetaObject(QBindableMap *obj) : QmlOpenMetaObject(obj) + { + map = obj; + } + +protected: + virtual void propertyWrite(int index) + { + map->emitChanged(QLatin1String(name(index))); + } + +private: + QBindableMap *map; +}; + +/*! + \class QBindableMap + \brief The QBindableMap class allows you to set key-value pairs that can be used in bindings. + + QBindableMap provides a convenient way to expose domain data to the UI layer. + The following example shows how you might declare data in C++ and then + access it in QML. + + Setup in C++: + \code + //create our data + QBindableMap ownerData; + ownerData.setValue("name", QVariant(QString("John Smith"))); + ownerData.setValue("phone", QVariant(QString("555-5555"))); + + //expose it to the UI layer + QmlContext *ctxt = view->bindContext(); + ctxt->setProperty("owner", &data); + \endcode + + Then, in QML: + \code + Text { text: owner.name } + Text { text: owner.phone } + \endcode + + The binding is dynamic - whenever a key's value is updated, anything bound to that + key will be updated as well. + + To detect value changes made in the UI layer you can connect to the changed() signal. + However, note that changed() is \b NOT emitted when changes are made by calling setValue() + or clearValue() - it is only emitted when a value is updated from QML. +*/ + +// is there a more efficient way to store/return keys? +// (or should we just provide an iterator or something else instead?) +// can we provide a way to clear keys? +// do we want to make any claims regarding key ordering? +// should we have signals for insertion and and deletion -- becoming more model like +// should we emit change for our own changes as well? +// Bug or Feature?: values can be created in QML (owner.somethingElse = "Hello") will create somethingElse property. (need to verify if this is actually the case) +// Bug or Feature?: all values are read-write (there are no read-only values) + +/*! + Constructs a bindable map with parent object \a parent. +*/ +QBindableMap::QBindableMap(QObject *parent) +: QObject(parent) +{ + m_mo = new QBindableMapMetaObject(this); +} + +/*! + Destroys the bindable map. +*/ +QBindableMap::~QBindableMap() +{ +} + +/*! + Clears the value (if any) associated with \a key. +*/ +void QBindableMap::clearValue(const QString &key) +{ + //m_keys.remove(); //### + m_mo->setValue(key.toLatin1(), QVariant()); + //emit changed(key); +} + +/*! + Returns the value associated with \a key. + + If no value has been set for this key (or if the value has been cleared), + an invalid QVariant is returned. +*/ +QVariant QBindableMap::value(const QString &key) const +{ + return m_mo->value(key.toLatin1()); +} + +/*! + Sets the value associated with \a key to \a value. + + If the key doesn't exist, it is automatically created. +*/ +void QBindableMap::setValue(const QString &key, QVariant value) +{ + if (!m_keys.contains(key)) + m_keys.append(key); + m_mo->setValue(key.toLatin1(), value); + //emit changed(key); +} + +/*! + Returns the list of keys. + + Keys that have been cleared will still appear in this list, even though their + associated values are invalid QVariants. +*/ +QStringList QBindableMap::keys() const +{ + return m_keys; +} + +/*! + \fn void QBindableMap::changed(const QString &key) + This signal is emitted whenever one of the values in the map is changed. \a key + is the key corresponding to the value that was changed. + */ + +void QBindableMap::emitChanged(const QString &key) +{ + emit changed(key); +} +QT_END_NAMESPACE diff --git a/src/declarative/extra/qbindablemap.h b/src/declarative/extra/qbindablemap.h new file mode 100644 index 0000000..c76928d --- /dev/null +++ b/src/declarative/extra/qbindablemap.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** 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 QBINDABLEMAP_H +#define QBINDABLEMAP_H + +#include <QtDeclarative/qfxglobal.h> +#include <QtCore/QObject> +#include <QtCore/QHash> +#include <QtCore/QStringList> +#include <QtCore/QVariant> + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QBindableMapMetaObject; +class Q_DECLARATIVE_EXPORT QBindableMap : public QObject +{ + Q_OBJECT +public: + QBindableMap(QObject *parent = 0); + virtual ~QBindableMap(); + + QVariant value(const QString &key) const; + void setValue(const QString &key, QVariant value); + void clearValue(const QString &key); + + Q_INVOKABLE QStringList keys() const; + +Q_SIGNALS: + void changed(const QString &key); + +private: + Q_DISABLE_COPY(QBindableMap) + void emitChanged(const QString &key); + QBindableMapMetaObject *m_mo; + QStringList m_keys; + friend class QBindableMapMetaObject; +}; + + +QT_END_NAMESPACE + +QT_END_HEADER +#endif diff --git a/src/declarative/extra/qfxanimatedimageitem.cpp b/src/declarative/extra/qfxanimatedimageitem.cpp new file mode 100644 index 0000000..d22959a --- /dev/null +++ b/src/declarative/extra/qfxanimatedimageitem.cpp @@ -0,0 +1,212 @@ +/**************************************************************************** +** +** 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 <QMovie> +#include <QtDeclarative/qmlcontext.h> +#include <QtDeclarative/qmlengine.h> +#include "qfxanimatedimageitem.h" +#include "qfxanimatedimageitem_p.h" +#include <QNetworkRequest> +#include <QNetworkReply> + +QT_BEGIN_NAMESPACE + +/*! + \class QFxAnimatedImageItem + \internal +*/ + +/*! + \qmlclass AnimatedImage + \inherits Image + + This item provides for playing animations stored as images containing a series of frames, + such as GIF files. The full list of supported formats can be determined with + QMovie::supportedFormats(). + + \table + \row + \o \image animatedimageitem.gif + \o + \qml +Item { + width: anim.width; height: anim.height+8 + AnimatedImage { id: anim; source: "pics/games-anim.gif" } + Rect { color: "red"; width: 4; height: 8; y: anim.height + x: (anim.width-width)*anim.currentFrame/(anim.frameCount-1) + } +} + \endqml + \endtable +*/ +QML_DEFINE_TYPE(QFxAnimatedImageItem, AnimatedImage) + +QFxAnimatedImageItem::QFxAnimatedImageItem(QFxItem *parent) + : QFxImage(*(new QFxAnimatedImageItemPrivate), parent) +{ +} + +QFxAnimatedImageItem::QFxAnimatedImageItem(QFxAnimatedImageItemPrivate &dd, QFxItem *parent) + : QFxImage(dd, parent) +{ +} + +QFxAnimatedImageItem::~QFxAnimatedImageItem() +{ + Q_D(QFxAnimatedImageItem); + delete d->_movie; +} + +/*! + \qmlproperty bool AnimatedImage::playing + This property holds whether the animated image is playing or not + + Defaults to true, so as to start playing immediately. +*/ +bool QFxAnimatedImageItem::isPlaying() const +{ + Q_D(const QFxAnimatedImageItem); + if (!d->_movie) + return false; + return d->_movie->state()==QMovie::Running; +} + +void QFxAnimatedImageItem::setPlaying(bool play) +{ + Q_D(QFxAnimatedImageItem); + if (!d->_movie) + return; + if (play) + d->_movie->start(); + else + d->_movie->stop(); +} + +/*! + \qmlproperty int AnimatedImage::currentFrame + \qmlproperty int AnimatedImage::frameCount + + currentFrame is the frame that is currently visible. Watching when this changes can + allow other things to animate at the same time as the image. frameCount is the number + of frames in the animation. For some animation formats, frameCount is unknown and set to zero. +*/ +int QFxAnimatedImageItem::currentFrame() const +{ + Q_D(const QFxAnimatedImageItem); + if (!d->_movie) + return -1; + return d->_movie->currentFrameNumber(); +} + +void QFxAnimatedImageItem::setCurrentFrame(int frame) +{ + Q_D(QFxAnimatedImageItem); + if (!d->_movie) + return; + d->_movie->jumpToFrame(frame); +} + +int QFxAnimatedImageItem::frameCount() const +{ + Q_D(const QFxAnimatedImageItem); + if (!d->_movie) + return 0; + return d->_movie->frameCount(); +} + +void QFxAnimatedImageItem::setSource(const QUrl &url) +{ + Q_D(QFxAnimatedImageItem); + if (url == d->url) + return; + + delete d->_movie; + d->_movie = 0; + + if (d->reply) { + d->reply->deleteLater(); + d->reply = 0; + } + + d->url = url; + + if (url.isEmpty()) { + delete d->_movie; + d->status = Idle; + } else { + d->status = Loading; + QNetworkRequest req(d->url); + req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); + d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req); + QObject::connect(d->reply, SIGNAL(finished()), + this, SLOT(movieRequestFinished())); + } + + emit statusChanged(d->status); +} + +void QFxAnimatedImageItem::movieRequestFinished() +{ + Q_D(QFxAnimatedImageItem); + d->_movie = new QMovie(d->reply); + if (!d->_movie->isValid()){ + qWarning() << "Error Reading File " << d->url; + delete d->_movie; + d->_movie = 0; + return; + } + connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)), + this, SIGNAL(playingChanged())); + connect(d->_movie, SIGNAL(frameChanged(int)), + this, SLOT(movieUpdate())); + d->_movie->setCacheMode(QMovie::CacheAll); + d->_movie->start(); + setPixmap(d->_movie->currentPixmap()); +} + +void QFxAnimatedImageItem::movieUpdate() +{ + Q_D(QFxAnimatedImageItem); + setPixmap(d->_movie->currentPixmap()); + emit frameChanged(); +} + +QT_END_NAMESPACE diff --git a/src/declarative/extra/qfxanimatedimageitem.h b/src/declarative/extra/qfxanimatedimageitem.h new file mode 100644 index 0000000..5d115d7 --- /dev/null +++ b/src/declarative/extra/qfxanimatedimageitem.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** 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 QFXANIMATEDIMAGEITEM_H +#define QFXANIMATEDIMAGEITEM_H + +#include <QtDeclarative/qfximage.h> + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QMovie; +class QFxAnimatedImageItemPrivate; + +class Q_DECLARATIVE_EXPORT QFxAnimatedImageItem : public QFxImage +{ + Q_OBJECT + + Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) + Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY frameChanged) + Q_PROPERTY(int frameCount READ frameCount) +public: + QFxAnimatedImageItem(QFxItem *parent=0); + ~QFxAnimatedImageItem(); + + bool isPlaying() const; + void setPlaying(bool play); + + int currentFrame() const; + void setCurrentFrame(int frame); + + int frameCount() const; + + // Extends QFxImage's src property*/ + virtual void setSource(const QUrl&); + +Q_SIGNALS: + void playingChanged(); + void frameChanged(); + +private Q_SLOTS: + void movieUpdate(); + void movieRequestFinished(); + +protected: + QFxAnimatedImageItem(QFxAnimatedImageItemPrivate &dd, QFxItem *parent); + +private: + Q_DISABLE_COPY(QFxAnimatedImageItem) + Q_DECLARE_PRIVATE(QFxAnimatedImageItem) +}; + +QML_DECLARE_TYPE(QFxAnimatedImageItem) + + +QT_END_NAMESPACE + +QT_END_HEADER +#endif diff --git a/src/declarative/extra/qfxanimatedimageitem_p.h b/src/declarative/extra/qfxanimatedimageitem_p.h new file mode 100644 index 0000000..e7d8fb8 --- /dev/null +++ b/src/declarative/extra/qfxanimatedimageitem_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 QFXANIMATEDIMAGE_P_H +#define QFXANIMATEDIMAGE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <private/qfximage_p.h> + +QT_BEGIN_NAMESPACE + +class QMovie; + +class QFxAnimatedImageItemPrivate : public QFxImagePrivate +{ + Q_DECLARE_PUBLIC(QFxAnimatedImageItem) + +public: + QFxAnimatedImageItemPrivate() + : _movie(0) + { + } + + QMovie *_movie; +}; + +QT_END_NAMESPACE + +#endif // QFXANIMATEDIMAGE_P_H diff --git a/src/declarative/extra/qfxblendedimage.cpp b/src/declarative/extra/qfxblendedimage.cpp new file mode 100644 index 0000000..0c93fef --- /dev/null +++ b/src/declarative/extra/qfxblendedimage.cpp @@ -0,0 +1,308 @@ +/**************************************************************************** +** +** 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 "qfxblendedimage.h" +#include <QtDeclarative/qmlcontext.h> + +#if defined(QFX_RENDER_OPENGL2) +#include <glbasicshaders.h> +#endif + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass BlendedImage + \brief The BlendedImage elements blends two different images depending on a blend ratio. + + This element can be used to simulate blur on slow devices by setting secondaryUrl with + a pre-rendered blurred version of primaryUrl. + + Note that this class will only work under OpenGL. On the software canvas it will display + only the primary image unless the blend is > 0.75, in which case it will display only the + secondary image. +*/ + +/*! + \internal + \class QFxBlendedImage + \brief The QFxBlendedImage blends two different images depending on a blend ratio. + + This class can be used to simulate blur on slow devices by setting secondaryUrl with + a pre-rendered blurred version of primaryUrl. + + Note that this class will only work under OpenGL. On the software canvas it will display + only the primary image unless the blend is > 0.75, in which case it will display only the + secondary image. +*/ +QFxBlendedImage::QFxBlendedImage(QFxItem *parent) +: QFxItem(parent), _blend(0), _smooth(false), dirty(false) +{ +#if defined(QFX_RENDER_OPENGL2) + setOptions(HasContents); +#endif +} + +/*! + Cancels any pending image loads and destroys the image. +*/ +QFxBlendedImage::~QFxBlendedImage() +{ + if (!primUrl.isEmpty()) + QFxPixmap::cancelGet(primUrl,this); + if (!secUrl.isEmpty()) + QFxPixmap::cancelGet(secUrl,this); +} + +/*! + \qmlproperty string BlendedImage::primaryUrl + The URL of the first image to be displayed in this item. +*/ +QUrl QFxBlendedImage::primaryUrl() const +{ + return primUrl; +} + +void QFxBlendedImage::primaryLoaded() +{ + primPix = QFxPixmap(primUrl); + dirty = true; + update(); +} + +void QFxBlendedImage::setPrimaryUrl(const QUrl &url) +{ + if (primUrl == url) + return; + if (!primUrl.isEmpty()) + QFxPixmap::cancelGet(primUrl,this); + Q_ASSERT(!url.isRelative()); + primUrl = url; + if (!primUrl.isEmpty()) + QFxPixmap::get(qmlEngine(this), primUrl,this,SLOT(primaryLoaded())); +} + +/*! + \qmlproperty string BlendedImage::secondaryUrl + The URL of the second image to be displayed in this item. +*/ +QUrl QFxBlendedImage::secondaryUrl() const +{ + return secUrl; +} + +void QFxBlendedImage::secondaryLoaded() +{ + secPix = QFxPixmap(secUrl); + dirty = true; + update(); +} + +void QFxBlendedImage::setSecondaryUrl(const QUrl &url) +{ + if (secUrl == url) + return; + if (!secUrl.isEmpty()) + QFxPixmap::cancelGet(secUrl,this); + Q_ASSERT(!url.isRelative()); + secUrl = url; + if (!secUrl.isEmpty()) + QFxPixmap::get(qmlEngine(this), secUrl,this,SLOT(secondaryLoaded())); +} + +/*! + \qmlproperty real BlendedImage::blend + The ratio used to blend the two images. + + If blend has a value of 0, only the first image will be displayed. + If blend has a value of 1, only the second image will be displayed. +*/ +qreal QFxBlendedImage::blend() const +{ + return _blend; +} + +void QFxBlendedImage::setBlend(qreal b) +{ + _blend = b; + update(); +} + +/*! + \qmlproperty bool BlendedImage::smooth + + Set this property if you want the image to be smoothly filtered when scaled or + transformed. Smooth filtering gives better visual quality, but is slower. If + the BlendedImage is displayed at its natural size, this property has no visual or + performance effect. + + \note Generally scaling artifacts are only visible if the image is stationary on + the screen. A common pattern when animating an image is to disable smooth + filtering at the beginning of the animation and reenable it at the conclusion. + */ +bool QFxBlendedImage::smoothTransform() const +{ + return _smooth; +} + +void QFxBlendedImage::setSmoothTransform(bool s) +{ + if (_smooth == s) + return; + _smooth = s; + update(); +} + +#if defined(QFX_RENDER_QPAINTER) + +void QFxBlendedImage::paintContents(QPainter &p) +{ + if (primUrl.isEmpty() && secUrl.isEmpty()) + return; + + if (_smooth) { + p.save(); + p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, _smooth); + } + + if (_blend < 0.75) + p.drawPixmap(0, 0, primPix); + else + p.drawPixmap(0, 0, secPix); + + if (_smooth) { + p.restore(); + } +} + +#elif defined(QFX_RENDER_OPENGL2) + +void QFxBlendedImage::paintGLContents(GLPainter &p) +{ + static DualTextureBlendShader *shader = 0; + if (!shader) + shader = new DualTextureBlendShader(); + + if (dirty) { + prim.clear(); + sec.clear(); + prim.setImage(primPix.toImage()); + sec.setImage(secPix.toImage()); + + dirty = false; + } + + if (prim.isNull() || sec.isNull()) { + + return; + } + + GLfloat vertices[8]; + GLfloat texVertices[8]; + + float widthV = width(); + float heightV = height(); + if (!widthV) + widthV = qMax(primPix.width(), secPix.width()); + if (!heightV) + heightV = qMax(primPix.height(), secPix.height()); + + vertices[0] = 0; vertices[1] = heightV; + vertices[2] = widthV; vertices[3] = heightV; + vertices[4] = 0; vertices[5] = 0; + vertices[6] = widthV; vertices[7] = 0; + + texVertices[0] = 0; texVertices[1] = 0; + texVertices[2] = 1; texVertices[3] = 0; + texVertices[4] = 0; texVertices[5] = 1; + texVertices[6] = 1; texVertices[7] = 1; + + if (_blend == 0 || _blend == 1) { + QGLShaderProgram *tshader = p.useTextureShader(); + + GLTexture *tex = 0; + + if (_blend == 0) + tex = &prim; + else + tex = &sec; + + tshader->setAttributeArray(SingleTextureShader::Vertices, vertices, 2); + tshader->setAttributeArray(SingleTextureShader::TextureCoords, texVertices, 2); + + glBindTexture(GL_TEXTURE_2D, tex->texture()); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + tshader->disableAttributeArray(SingleTextureShader::Vertices); + tshader->disableAttributeArray(SingleTextureShader::TextureCoords); + } else { + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, prim.texture()); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, sec.texture()); + + shader->enable(); + shader->setOpacity(1); + qreal b = _blend; + if (b > 1) b = 1; + else if (b < 0) b = 0; + shader->setBlend(b); + shader->setTransform(p.activeTransform); + + shader->setAttributeArray(DualTextureBlendShader::Vertices, vertices, 2); + shader->setAttributeArray(DualTextureBlendShader::TextureCoords, texVertices, 2); + shader->setAttributeArray(DualTextureBlendShader::BlendTextureCoords, texVertices, 2); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + shader->disableAttributeArray(DualTextureBlendShader::Vertices); + shader->disableAttributeArray(DualTextureBlendShader::TextureCoords); + shader->disableAttributeArray(DualTextureBlendShader::BlendTextureCoords); + + glBindTexture(GL_TEXTURE_2D, 0); + glActiveTexture(GL_TEXTURE0); + } +} +#endif + +QML_DEFINE_TYPE(QFxBlendedImage,BlendedImage) + +QT_END_NAMESPACE diff --git a/src/declarative/extra/qfxblendedimage.h b/src/declarative/extra/qfxblendedimage.h new file mode 100644 index 0000000..248cc9d --- /dev/null +++ b/src/declarative/extra/qfxblendedimage.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** 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 QFXBLENDEDIMAGE_H +#define QFXBLENDEDIMAGE_H + +#include <QtDeclarative/qfxitem.h> +#if defined(QFX_RENDER_OPENGL2) +#include <gltexture.h> +#endif + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class Q_DECLARATIVE_EXPORT QFxBlendedImage : public QFxItem +{ + Q_OBJECT + + Q_PROPERTY(QUrl primaryUrl READ primaryUrl WRITE setPrimaryUrl) + Q_PROPERTY(QUrl secondaryUrl READ secondaryUrl WRITE setSecondaryUrl) + Q_PROPERTY(qreal blend READ blend WRITE setBlend) + Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform) +public: + QFxBlendedImage(QFxItem *parent=0); + ~QFxBlendedImage(); + + QUrl primaryUrl() const; + void setPrimaryUrl(const QUrl &); + + QUrl secondaryUrl() const; + void setSecondaryUrl(const QUrl &); + + qreal blend() const; + void setBlend(qreal); + + bool smoothTransform() const; + void setSmoothTransform(bool); + +#if defined(QFX_RENDER_QPAINTER) + void paintContents(QPainter &painter); +#elif defined(QFX_RENDER_OPENGL2) + void paintGLContents(GLPainter &); +#endif + +private Q_SLOTS: + void primaryLoaded(); + void secondaryLoaded(); + +private: + QUrl primUrl; + QUrl secUrl; + + qreal _blend; + bool _smooth; + bool dirty; +#if defined(QFX_RENDER_OPENGL2) + GLTexture prim; + GLTexture sec; +#endif + QPixmap primPix; + QPixmap secPix; +}; +QML_DECLARE_TYPE(QFxBlendedImage) + + +QT_END_NAMESPACE + +QT_END_HEADER +#endif // QFXBLENDEDIMAGE_H diff --git a/src/declarative/extra/qfxflowview.cpp b/src/declarative/extra/qfxflowview.cpp new file mode 100644 index 0000000..77cd6df --- /dev/null +++ b/src/declarative/extra/qfxflowview.cpp @@ -0,0 +1,381 @@ +/**************************************************************************** +** +** 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 "qfxvisualitemmodel.h" +#include "qfxflowview.h" + +QT_BEGIN_NAMESPACE + +class QFxFlowViewAttached : public QObject +{ +Q_OBJECT +Q_PROPERTY(int row READ row NOTIFY posChanged); +Q_PROPERTY(int column READ column NOTIFY posChanged); +public: + QFxFlowViewAttached(QObject *parent); + + int row() const; + int column() const; + +signals: + void posChanged(); + +private: + friend class QFxFlowView; + int m_row; + int m_column; +}; + + +QFxFlowView::QFxFlowView() +: m_columns(0), m_model(0), m_vertical(false), m_dragItem(0), m_dragIdx(-1) +{ + setAcceptedMouseButtons(Qt::LeftButton); + setOptions(MouseEvents); +} + +QFxVisualItemModel *QFxFlowView::model() const +{ + return m_model; +} + +void QFxFlowView::setModel(QFxVisualItemModel *m) +{ + m_model = m; + refresh(); +} + +int QFxFlowView::columns() const +{ + return m_columns; +} + +void QFxFlowView::setColumns(int c) +{ + m_columns = c; + refresh(); +} + +bool QFxFlowView::vertical() const +{ + return m_vertical; +} + +void QFxFlowView::setVertical(bool v) +{ + m_vertical = v; +} + +class QFxFlowViewValue : public QmlTimeLineValue +{ +public: + enum Property { xProperty, yProperty }; + + QFxFlowViewValue(QFxItem *item, Property p) + : m_item(item), m_property(p) {} + + qreal value() const { + return (m_property == xProperty)?m_item->x():m_item->y(); + } + void setValue(qreal v) { + if (m_property == xProperty) m_item->setX(v); + else m_item->setY(v); + } +private: + QFxItem *m_item; + Property m_property; +}; + +void QFxFlowView::refresh() +{ + if (m_model && m_columns >= 1) { + for (int ii = 0; ii < m_model->count(); ++ii) { + if (QFxItem *item = m_model->item(ii)) { + item->setParent(this); + item->setZ(0); + m_items << item; + } + } + + reflow(); + } +} + +void QFxFlowView::reflow(bool animate) +{ + qreal y = 0; + qreal maxY = 0; + qreal x = 0; + int row = 0; + int column = -1; + if (animate) + clearTimeLine(); + + for (int ii = 0; ii < m_items.count(); ++ii) { + if (0 == (ii % m_columns)) { + y += maxY; + maxY = 0; + x = 0; + row = 0; + column++; + } + + QFxItem *item = m_items.at(ii); + QFxFlowViewAttached *att = + (QFxFlowViewAttached *)qmlAttachedPropertiesObject<QFxFlowView>(item); + att->m_row = row; + att->m_column = column; + emit att->posChanged(); + + + if (animate) { + if (vertical()) + moveItem(item, QPointF(y, x)); + else + moveItem(item, QPointF(x, y)); + } else { + if (vertical()) { + item->setX(y); + item->setY(x); + } else { + item->setX(x); + item->setY(y); + } + } + if (vertical()) { + x += item->height(); + maxY = qMax(maxY, item->width()); + } else { + x += item->width(); + maxY = qMax(maxY, item->height()); + } + ++row; + } +} + +void QFxFlowView::reflowDrag(const QPointF &dp) +{ + qreal y = 0; + qreal maxY = 0; + qreal x = 0; + + int flowedItems = 0; + + clearTimeLine(); + + QList<QFxItem *> items; + + bool dragUsed = false; + bool dragSeen = false; + for (int ii = 0; ii < m_items.count(); ++ii) { + if (0 == (ii % m_columns)) { + y += maxY; + maxY = 0; + x = 0; + } + + QFxItem *item = m_items.at(ii); + if (item == m_dragItem) + dragSeen = true; + if (item == m_dragItem && dragUsed) + continue; + QRectF r; + if (vertical()) + r = QRectF(y, x, item->width(), item->height()); + else + r = QRectF(x, y, item->width(), item->height()); + if (r.contains(dp)) { + dragUsed = true; + if (dragSeen) + m_dragIdx = items.count() + 1; + else + m_dragIdx = items.count(); + + items.append(m_dragItem); + if (m_dragItem != item) { + if (dragSeen) + items.insert(items.count() - 1, item); + else + items.append(item); + } + } else { + if (m_dragItem != item) + items.append(item); + } + + if (vertical()) { + x += item->height(); + maxY = qMax(maxY, item->width()); + } else { + x += item->width(); + maxY = qMax(maxY, item->height()); + } + } + + y = 0; + maxY = 0; + x = 0; + clearTimeLine(); + for (int ii = 0; ii < items.count(); ++ii) { + if (0 == (ii % m_columns)) { + y += maxY; + maxY = 0; + x = 0; + } + + QFxItem *item = items.at(ii); + if (item != m_dragItem) { + if (vertical()) + moveItem(item, QPointF(y, x)); + else + moveItem(item, QPointF(x, y)); + } + if (vertical()) { + x += item->height(); + maxY = qMax(maxY, item->width()); + } else { + x += item->width(); + maxY = qMax(maxY, item->height()); + } + } + +} + +void QFxFlowView::moveItem(QFxItem *item, const QPointF &p) +{ + QFxFlowViewValue *xv = new QFxFlowViewValue(item, QFxFlowViewValue::xProperty); + QFxFlowViewValue *yv = new QFxFlowViewValue(item, QFxFlowViewValue::yProperty); + m_values << xv << yv; + m_timeline.move(*xv, p.x(), 100); + m_timeline.move(*yv, p.y(), 100); +} + +#include <QGraphicsSceneMouseEvent> + +void QFxFlowView::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + for (int ii = 0; ii < m_items.count(); ++ii) { + QFxItem *item = m_items.at(ii); + QRectF r = rectForItem(ii); + + if (r.contains(event->pos())) { + m_dragItem = item; + m_dragItem->setZ(1); + m_dragOffset = r.topLeft() - event->pos(); + event->accept(); + return; + } + } + event->ignore(); +} + +QRectF QFxFlowView::rectForItem(int idx) const +{ + QFxItem *item = m_items.at(idx); + QRectF r(item->x(), item->y(), item->width(), item->height()); + return r; +} + +void QFxFlowView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_dragItem) { + m_dragItem->setZ(0); + + clearTimeLine(); + + if (m_dragIdx != -1) { + m_items.removeAll(m_dragItem); + m_items.insert(m_dragIdx, m_dragItem); + } + + reflow(true); + m_dragItem = 0; + m_dragIdx = -1; + } +} + +QFxFlowViewAttached::QFxFlowViewAttached(QObject *parent) +: QObject(parent), m_row(0), m_column(0) +{ +} + +int QFxFlowViewAttached::row() const +{ + return m_row; +} + +int QFxFlowViewAttached::column() const +{ + return m_column; +} + +QFxFlowViewAttached *QFxFlowView::qmlAttachedProperties(QObject *obj) +{ + return new QFxFlowViewAttached(obj); +} + +void QFxFlowView::clearTimeLine() +{ + m_timeline.clear(); + qDeleteAll(m_values); + m_values.clear(); +} + +void QFxFlowView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_dragItem) { + QPointF p = event->pos() + m_dragOffset; + m_dragItem->setX(p.x()); + m_dragItem->setY(p.y()); + + for (int ii = 0; ii < m_items.count(); ++ii) { + if (m_items.at(ii) != m_dragItem && rectForItem(ii).contains(event->pos())) { + reflowDrag(event->pos()); + } + } + } +} + +QML_DEFINE_TYPE(QFxFlowView,FlowView); + +#include "qfxflowview.moc" + +QT_END_NAMESPACE diff --git a/src/declarative/extra/qfxflowview.h b/src/declarative/extra/qfxflowview.h new file mode 100644 index 0000000..0e7c2d3 --- /dev/null +++ b/src/declarative/extra/qfxflowview.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** 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 QFXFLOWVIEW_H +#define QFXFLOWVIEW_H + +#include <QtDeclarative/QmlTimeLine> +#include <QtDeclarative/qfxitem.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QFxVisualItemModel; +class QFxFlowViewValue; +class QFxFlowViewAttached; +class Q_DECLARATIVE_EXPORT QFxFlowView : public QFxItem +{ + Q_OBJECT + Q_PROPERTY(QFxVisualItemModel *model READ model WRITE setModel) + Q_PROPERTY(int column READ columns WRITE setColumns); + Q_PROPERTY(bool vertical READ vertical WRITE setVertical); + +public: + QFxFlowView(); + + QFxVisualItemModel *model() const; + void setModel(QFxVisualItemModel *); + + int columns() const; + void setColumns(int); + + bool vertical() const; + void setVertical(bool); + + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + + static QFxFlowViewAttached *qmlAttachedProperties(QObject *); + +private: + QRectF rectForItem(int idx) const; + void refresh(); + void reflow(bool animate = false); + void reflowDrag(const QPointF &); + void clearTimeLine(); + int m_columns; + QFxVisualItemModel *m_model; + QList<QFxItem *> m_items; + bool m_vertical; + void moveItem(QFxItem *item, const QPointF &); + + QPointF m_dragOffset; + QFxItem *m_dragItem; + + QmlTimeLine m_timeline; + QList<QFxFlowViewValue *> m_values; + int m_dragIdx; +}; +QML_DECLARE_TYPE(QFxFlowView); + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QFXFLOWVIEW_H diff --git a/src/declarative/extra/qmlbehaviour.cpp b/src/declarative/extra/qmlbehaviour.cpp new file mode 100644 index 0000000..4beca5e --- /dev/null +++ b/src/declarative/extra/qmlbehaviour.cpp @@ -0,0 +1,259 @@ +/**************************************************************************** +** +** 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 "qmlanimation.h" +#include "qmltransition.h" +#include "qmlbehaviour.h" +#include <QtDeclarative/qmlcontext.h> +#include <QtCore/qparallelanimationgroup.h> + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(QmlBehaviour,Behavior) + +class QmlBehaviourData : public QObject +{ +Q_OBJECT +public: + QmlBehaviourData(QObject *parent) + : QObject(parent) {} + + Q_PROPERTY(QVariant endValue READ endValue NOTIFY valuesChanged); + Q_PROPERTY(QVariant startValue READ startValue NOTIFY valuesChanged); + QVariant endValue() const { return e; } + QVariant startValue() const { return s; } + + QVariant e; + QVariant s; + +Q_SIGNALS: + void valuesChanged(); + +private: + friend class QmlBehaviour; +}; + +class QmlBehaviourPrivate : public QObjectPrivate +{ +public: + QmlBehaviourPrivate() + : context(0), valueData(0), operations(this) {} + QmlMetaProperty property; + QVariant currentValue; + + QVariant fromValue; + QVariant toValue; + QmlContext *context; + QmlBehaviourData *valueData; + class AnimationList : public QmlConcreteList<QmlAbstractAnimation *> + { + public: + AnimationList(QmlBehaviourPrivate *parent) : _parent(parent) {} + virtual void append(QmlAbstractAnimation *a) + { + QmlConcreteList<QmlAbstractAnimation *>::append(a); + _parent->group->addAnimation(a->qtAnimation()); + if (_parent->property.isValid()) { + a->setTarget(_parent->property); + } + } + virtual void clear() { QmlConcreteList<QmlAbstractAnimation *>::clear(); } //### + private: + QmlBehaviourPrivate *_parent; + }; + AnimationList operations; + QParallelAnimationGroup *group; +}; + +/*! + \qmlclass Behavior QmlBehaviour + \brief The Behavior element allows you to specify a default animation for a property change. + + In example below, the rect will use a bounce easing curve over 200 millisecond for any changes to its y property: + \code + Rect { + width: 20; height: 20 + color: "#00ff00" + y: 200 //initial value + y: Behavior { + NumberAnimation { + easing: "easeOutBounce(amplitude:100)" + duration: 200 + } + } + } + \endcode +*/ + +QmlBehaviour::QmlBehaviour(QObject *parent) +: QmlPropertyValueSource(*(new QmlBehaviourPrivate), parent) +{ + Q_D(QmlBehaviour); + d->valueData = new QmlBehaviourData(this); + d->group = new QParallelAnimationGroup(this); +} + +/*! + \qmlproperty QVariant Behavior::fromValue + This property holds a selector specifying a starting value for the behavior + + If you only want the behavior to apply when the change starts at a + specific value you can specify fromValue. This selector is used in conjunction + with the toValue selector. +*/ + +QVariant QmlBehaviour::fromValue() const +{ + Q_D(const QmlBehaviour); + return d->fromValue; +} + +void QmlBehaviour::setFromValue(const QVariant &v) +{ + Q_D(QmlBehaviour); + d->fromValue = v; +} + +/*! + \qmlproperty QVariant Behavior::toValue + This property holds a selector specifying a ending value for the behavior + + If you only want the behavior to apply when the change ends at a + specific value you can specify toValue. This selector is used in conjunction + with the fromValue selector. +*/ + +QVariant QmlBehaviour::toValue() const +{ + Q_D(const QmlBehaviour); + return d->toValue; +} + +void QmlBehaviour::setToValue(const QVariant &v) +{ + Q_D(QmlBehaviour); + d->toValue = v; +} + +QmlList<QmlAbstractAnimation *>* QmlBehaviour::operations() +{ + Q_D(QmlBehaviour); + return &d->operations; +} + +QmlBehaviour::~QmlBehaviour() +{ + //### do we need any other cleanup here? +} + +bool QmlBehaviour::_ignore = false; +void QmlBehaviour::propertyValueChanged() +{ + Q_D(QmlBehaviour); + if (_ignore) + return; + + QVariant newValue = d->property.read(); + + if ((!fromValue().isValid() || fromValue() == d->currentValue) && + (!toValue().isValid() || toValue() == newValue)) { + + //### does this clean up everything needed? + d->group->stop(); + + d->valueData->e = newValue; + d->valueData->s = d->currentValue; + emit d->valueData->valuesChanged(); + + QmlStateOperation::ActionList actions; + Action action; + action.property = d->property; + action.fromValue = d->currentValue; + action.toValue = newValue; + actions << action; + + _ignore = true; + d->property.write(d->currentValue); + + QList<QmlMetaProperty> after; + for (int ii = 0; ii < d->operations.count(); ++ii) { + d->operations.at(ii)->transition(actions, after, QmlAbstractAnimation::Forward); + } + d->group->start(); + if (!after.contains(d->property)) + d->property.write(newValue); + _ignore = false; + } + + d->currentValue = newValue; +} + +void QmlBehaviour::setTarget(const QmlMetaProperty &property) +{ + Q_D(QmlBehaviour); + d->property = property; + d->currentValue = property.read(); + d->property.connectNotifier(this, SLOT(propertyValueChanged())); + for (int ii = 0; ii < d->operations.count(); ++ii) { + d->operations.at(ii)->setTarget(property); + } +} + +void QmlBehaviour::classBegin() +{ + Q_D(QmlBehaviour); + if (!d->context) { + d->context = new QmlContext(qmlContext(this), this); + d->context->addDefaultObject(d->valueData); + } + d->context->activate(); +} + +void QmlBehaviour::classComplete() +{ + Q_D(QmlBehaviour); + d->context->deactivate(); +} + +#include "qmlbehaviour.moc" + +QT_END_NAMESPACE diff --git a/src/declarative/extra/qmlbehaviour.h b/src/declarative/extra/qmlbehaviour.h new file mode 100644 index 0000000..7cc83b2 --- /dev/null +++ b/src/declarative/extra/qmlbehaviour.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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 QMLBEHAVIOUR_H +#define QMLBEHAVIOUR_H + +#include <QtDeclarative/qmlpropertyvaluesource.h> +#include <QtDeclarative/qml.h> +#include <QtDeclarative/qmlstate.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlAbstractAnimation; +class QmlBehaviourPrivate; +class Q_DECLARATIVE_EXPORT QmlBehaviour : public QmlPropertyValueSource, + public QmlParserStatus +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlBehaviour) + Q_INTERFACES(QmlParserStatus) + + Q_PROPERTY(QVariant from READ fromValue WRITE setFromValue) + Q_PROPERTY(QVariant to READ toValue WRITE setToValue) + Q_CLASSINFO("DefaultProperty", "operations") + Q_PROPERTY(QmlList<QmlAbstractAnimation *>* operations READ operations) + +public: + QmlBehaviour(QObject *parent=0); + ~QmlBehaviour(); + + QVariant fromValue() const; + void setFromValue(const QVariant &); + QVariant toValue() const; + void setToValue(const QVariant &); + virtual void setTarget(const QmlMetaProperty &); + + QmlList<QmlAbstractAnimation *>* operations(); + + static bool _ignore; + +protected: + virtual void classBegin(); + virtual void classComplete(); + +private Q_SLOTS: + void propertyValueChanged(); +}; +QML_DECLARE_TYPE(QmlBehaviour) + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLBEHAVIOUR_H diff --git a/src/declarative/extra/qmldatetimeformatter.cpp b/src/declarative/extra/qmldatetimeformatter.cpp new file mode 100644 index 0000000..ad0e473 --- /dev/null +++ b/src/declarative/extra/qmldatetimeformatter.cpp @@ -0,0 +1,368 @@ +/**************************************************************************** +** +** 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 "qmldatetimeformatter.h" +#include "private/qobject_p.h" +#include <QtCore/qlocale.h> + +QT_BEGIN_NAMESPACE +//TODO: may need optimisation as the QDateTime member may not be needed? +// be able to set a locale? + +class QmlDateTimeFormatterPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlDateTimeFormatter) +public: + QmlDateTimeFormatterPrivate() : locale(QLocale::system()), longStyle(false), classComplete(true) {} + + void updateText(); + + QDateTime dateTime; + QDate date; + QTime time; + QLocale locale; + QString dateTimeText; + QString dateText; + QString timeText; + QString dateTimeFormat; //set for convienience? + QString dateFormat; + QString timeFormat; + bool longStyle; + bool classComplete; +}; + +/*! + \qmlclass DateTimeFormatter QmlDateTimeFormatter + \brief The DateTimeFormatter allows you to control the format of a date string. + + \code + DateTimeFormatter { id: Formatter; date: System.date } + Text { text: Formatter.dateText } + \endcode + + By default, the text properties (dateText, timeText, and dateTimeText) will return the + date and time using the current system locale's format. +*/ + +/*! + \internal + \class QmlDateTimeFormatter + \ingroup group_utility + \brief The QmlDateTimeFormatter class allows you to format a date string. +*/ + +QmlDateTimeFormatter::QmlDateTimeFormatter(QObject *parent) +: QObject(*(new QmlDateTimeFormatterPrivate), parent) +{ +} + +QmlDateTimeFormatter::~QmlDateTimeFormatter() +{ +} + +/*! + \qmlproperty string DateTimeFormatter::dateText + \qmlproperty string DateTimeFormatter::timeText + \qmlproperty string DateTimeFormatter::dateTimeText + + Formatted text representations of the \c date, \c time, + and \c {date and time}, respectively. + + If there is no explictly specified format the DateTimeFormatter + will use the system locale's default 'short' setting. + + \code + // specify source date (assuming today is February 19, 2009) + DateTimeFormatter { id: formatter; dateTime: Today.date } + + // display the full date and time + Text { text: formatter.dateText } + \endcode + + Would be equivalent to the following for a US English locale: + + \code + // display the date + Text { text: "2/19/09" } + \endcode +*/ +QString QmlDateTimeFormatter::dateTimeText() const +{ + Q_D(const QmlDateTimeFormatter); + return d->dateTimeText; +} + +QString QmlDateTimeFormatter::dateText() const +{ + Q_D(const QmlDateTimeFormatter); + return d->dateText; +} + +QString QmlDateTimeFormatter::timeText() const +{ + Q_D(const QmlDateTimeFormatter); + return d->timeText; +} + +/*! + \qmlproperty date DateTimeFormatter::date + \qmlproperty time DateTimeFormatter::time + \qmlproperty datetime DateTimeFormatter::dateTime + + The source date and time to be used by the formatter. + + \code + // setting the date and time + DateTimeFormatter { date: System.date; time: System.time } + \endcode + + For convienience it is possible to set the datetime property to set both the date and the time. + \code + // setting the datetime + DateTimeFormatter { dateTime: System.dateTime } + \endcode + + There can only be one instance of date and time per formatter; if date, time, and dateTime are all + set the actual date and time used is not guaranteed. + + \note If no date is set, dateTimeText will be just the date; + If no time is set, the dateTimeText will be just the time. + +*/ +QDate QmlDateTimeFormatter::date() const +{ + Q_D(const QmlDateTimeFormatter); + return d->date; +} + +QTime QmlDateTimeFormatter::time() const +{ + Q_D(const QmlDateTimeFormatter); + return d->time; +} + +QDateTime QmlDateTimeFormatter::dateTime() const +{ + Q_D(const QmlDateTimeFormatter); + return d->dateTime; +} + +/*! + \qmlproperty string DateTimeFormatter::dateFormat + \qmlproperty string DateTimeFormatter::timeFormat + \qmlproperty string DateTimeFormatter::dateTimeFormat + + Specifies a custom format which the DateTime Formatter can use. + + If there is no explictly specified format the DateTimeFormatter + will use the system locale's default 'short' setting. + + The text's format may be modified by setting: + \list + \i \c dateFormat + \i \c timeFormat + \i \c dateTimeFormat + \endlist + + If only the format for date is defined, the time and dateTime formats will be defined + as the system locale default and likewise for the others. + + Syntax for the format is based on the QDateTime::toString() formatting options. + + \code + // Format the date such that the dateText is: '1997-12-12' + DateTimeFormatter { id: formatter; dateTime: Today.dateTime; formatDate: "yyyy-MM-d" } + \endcode + + Assigning an empty string to a particular format will reset it. +*/ +QString QmlDateTimeFormatter::dateTimeFormat() const +{ + Q_D(const QmlDateTimeFormatter); + return d->dateTimeFormat; +} + +QString QmlDateTimeFormatter::dateFormat() const +{ + Q_D(const QmlDateTimeFormatter); + return d->dateFormat; +} + +QString QmlDateTimeFormatter::timeFormat() const +{ + Q_D(const QmlDateTimeFormatter); + return d->timeFormat; +} + +/*! + \qmlproperty bool DateTimeFormatter::longStyle + + This property causes the formatter to use the system locale's long format rather than short format + by default. + + This setting is off by default. +*/ +bool QmlDateTimeFormatter::longStyle() const +{ + Q_D(const QmlDateTimeFormatter); + return d->longStyle; +} + +void QmlDateTimeFormatter::setDateTime(const QDateTime &dateTime) +{ + Q_D(QmlDateTimeFormatter); + if (d->dateTime == dateTime) + return; + d->dateTime = dateTime; + d->date = d->dateTime.date(); + d->time = d->dateTime.time(); + d->updateText(); +} + +void QmlDateTimeFormatter::setTime(const QTime &time) +{ + Q_D(QmlDateTimeFormatter); + if (d->dateTime.time() == time) + return; + d->time = time; + d->dateTime.setTime(time); + d->updateText(); +} + +void QmlDateTimeFormatter::setDate(const QDate &date) +{ + Q_D(QmlDateTimeFormatter); + if (d->dateTime.date() == date) + return; + d->date = date; + bool clearTime = d->dateTime.time().isValid() ? false : true; //because setting date generates default time + d->dateTime.setDate(date); + if (clearTime) + d->dateTime.setTime(QTime()); + d->updateText(); +} + +//DateTime formatting may be a combination of date and time? +void QmlDateTimeFormatter::setDateTimeFormat(const QString &format) +{ + Q_D(QmlDateTimeFormatter); + //no format checking + d->dateTimeFormat = format; + d->updateText(); +} + +void QmlDateTimeFormatter::setDateFormat(const QString &format) +{ + Q_D(QmlDateTimeFormatter); + //no format checking + d->dateFormat = format; + d->updateText(); +} + +void QmlDateTimeFormatter::setTimeFormat(const QString &format) +{ + Q_D(QmlDateTimeFormatter); + //no format checking + d->timeFormat = format; + d->updateText(); +} + +void QmlDateTimeFormatter::setLongStyle(bool longStyle) +{ + Q_D(QmlDateTimeFormatter); + d->longStyle = longStyle; + d->updateText(); +} + +void QmlDateTimeFormatterPrivate::updateText() +{ + Q_Q(QmlDateTimeFormatter); + if (!classComplete) + return; + + QString str; + QString str1; + QString str2; + + Qt::DateFormat defaultFormat = longStyle ? Qt::SystemLocaleLongDate : Qt::SystemLocaleShortDate; + + if (dateFormat.isEmpty()) + str1 = date.toString(defaultFormat); + else + str1 = date.toString(dateFormat); + + if (timeFormat.isEmpty()) + str2 = time.toString(defaultFormat); + else + str2 = time.toString(timeFormat); + + if (dateTimeFormat.isEmpty()) + str = dateTime.toString(defaultFormat); + //else if (!formatTime.isEmpty() && !formatDate.isEmpty()) + // str = str1 + QLatin1Char(' ') + str2; + else + str = dateTime.toString(dateTimeFormat); + + if (dateTimeText == str && dateText == str1 && timeText == str2) + return; + + dateTimeText = str; + dateText = str1; + timeText = str2; + + emit q->textChanged(); +} + +void QmlDateTimeFormatter::classBegin() +{ + Q_D(QmlDateTimeFormatter); + d->classComplete = false; +} + +void QmlDateTimeFormatter::classComplete() +{ + Q_D(QmlDateTimeFormatter); + d->classComplete = true; + d->updateText(); +} + +QML_DEFINE_TYPE(QmlDateTimeFormatter, DateTimeFormatter) +QT_END_NAMESPACE diff --git a/src/declarative/extra/qmldatetimeformatter.h b/src/declarative/extra/qmldatetimeformatter.h new file mode 100644 index 0000000..84b27e3 --- /dev/null +++ b/src/declarative/extra/qmldatetimeformatter.h @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** 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 QMLDATETIMEFORMATTER_H +#define QMLDATETIMEFORMATTER_H + +#include <QtCore/qdatetime.h> +#include <QtDeclarative/qml.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlDateTimeFormatterPrivate; +class Q_DECLARATIVE_EXPORT QmlDateTimeFormatter : public QObject, public QmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QmlParserStatus) + + Q_PROPERTY(QString dateText READ dateText NOTIFY textChanged) + Q_PROPERTY(QString timeText READ timeText NOTIFY textChanged) + Q_PROPERTY(QString dateTimeText READ dateTimeText NOTIFY textChanged) + Q_PROPERTY(QDate date READ date WRITE setDate) + Q_PROPERTY(QTime time READ time WRITE setTime) + Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime) + Q_PROPERTY(QString dateFormat READ dateFormat WRITE setDateFormat) + Q_PROPERTY(QString timeFormat READ timeFormat WRITE setTimeFormat) + Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat) + Q_PROPERTY(bool longStyle READ longStyle WRITE setLongStyle) +public: + QmlDateTimeFormatter(QObject *parent=0); + ~QmlDateTimeFormatter(); + + QString dateTimeText() const; + QString dateText() const; + QString timeText() const; + + QDate date() const; + void setDate(const QDate &); + + QTime time() const; + void setTime(const QTime &); + + QDateTime dateTime() const; + void setDateTime(const QDateTime &); + + QString dateTimeFormat() const; + void setDateTimeFormat(const QString &); + + QString dateFormat() const; + void setDateFormat(const QString &); + + QString timeFormat() const; + void setTimeFormat(const QString &); + + bool longStyle() const; + void setLongStyle(bool); + + virtual void classBegin(); + virtual void classComplete(); + +Q_SIGNALS: + void textChanged(); + +private: + Q_DISABLE_COPY(QmlDateTimeFormatter) + Q_DECLARE_PRIVATE(QmlDateTimeFormatter) +}; + +QML_DECLARE_TYPE(QmlDateTimeFormatter) + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif |