From 45cc1ea534640cb492bd00405bf8fcd5dbfbcf5c Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 30 Oct 2009 14:15:22 +1000 Subject: Rename QFx classes to QmlGraphics --- doc/src/declarative/measuring-performance.qdoc | 6 +- doc/src/declarative/qtprogrammers.qdoc | 10 +- src/declarative/3rdparty/qlistmodelinterface.cpp | 4 +- src/declarative/extra/qfxanimatedimageitem.cpp | 60 +- src/declarative/extra/qfxanimatedimageitem.h | 18 +- src/declarative/extra/qfxanimatedimageitem_p.h | 6 +- src/declarative/extra/qfxintegermodel.cpp | 28 +- src/declarative/extra/qfxintegermodel.h | 12 +- src/declarative/extra/qfxparticles.cpp | 318 ++++----- src/declarative/extra/qfxparticles.h | 74 +- src/declarative/fx/qfxanchors.cpp | 392 +++++----- src/declarative/fx/qfxanchors.h | 76 +- src/declarative/fx/qfxanchors_p.h | 50 +- src/declarative/fx/qfxborderimage.cpp | 80 +-- src/declarative/fx/qfxborderimage.h | 26 +- src/declarative/fx/qfxborderimage_p.h | 24 +- src/declarative/fx/qfxevents.cpp | 12 +- src/declarative/fx/qfxevents_p.h | 14 +- src/declarative/fx/qfxflickable.cpp | 352 ++++----- src/declarative/fx/qfxflickable.h | 30 +- src/declarative/fx/qfxflickable_p.h | 24 +- src/declarative/fx/qfxflipable.cpp | 68 +- src/declarative/fx/qfxflipable.h | 26 +- src/declarative/fx/qfxfocuspanel.cpp | 14 +- src/declarative/fx/qfxfocuspanel.h | 10 +- src/declarative/fx/qfxfocusscope.cpp | 10 +- src/declarative/fx/qfxfocusscope.h | 8 +- src/declarative/fx/qfxgraphicsobjectcontainer.cpp | 52 +- src/declarative/fx/qfxgraphicsobjectcontainer.h | 12 +- src/declarative/fx/qfxgridview.cpp | 376 +++++----- src/declarative/fx/qfxgridview.h | 28 +- src/declarative/fx/qfximage.cpp | 40 +- src/declarative/fx/qfximage.h | 16 +- src/declarative/fx/qfximage_p.h | 10 +- src/declarative/fx/qfximagebase.cpp | 44 +- src/declarative/fx/qfximagebase.h | 14 +- src/declarative/fx/qfximagebase_p.h | 10 +- src/declarative/fx/qfxitem.cpp | 792 ++++++++++----------- src/declarative/fx/qfxitem.h | 70 +- src/declarative/fx/qfxitem_p.h | 76 +- src/declarative/fx/qfxlayoutitem.cpp | 16 +- src/declarative/fx/qfxlayoutitem.h | 8 +- src/declarative/fx/qfxlistview.cpp | 488 ++++++------- src/declarative/fx/qfxlistview.h | 28 +- src/declarative/fx/qfxloader.cpp | 80 +-- src/declarative/fx/qfxloader.h | 18 +- src/declarative/fx/qfxloader_p.h | 12 +- src/declarative/fx/qfxmouseregion.cpp | 168 ++--- src/declarative/fx/qfxmouseregion.h | 52 +- src/declarative/fx/qfxmouseregion_p.h | 12 +- src/declarative/fx/qfxpainteditem.cpp | 78 +- src/declarative/fx/qfxpainteditem.h | 16 +- src/declarative/fx/qfxpainteditem_p.h | 6 +- src/declarative/fx/qfxpath.cpp | 194 ++--- src/declarative/fx/qfxpath.h | 62 +- src/declarative/fx/qfxpath_p.h | 10 +- src/declarative/fx/qfxpathview.cpp | 232 +++--- src/declarative/fx/qfxpathview.h | 30 +- src/declarative/fx/qfxpathview_p.h | 34 +- src/declarative/fx/qfxpixmapcache.cpp | 28 +- src/declarative/fx/qfxpixmapcache.h | 4 +- src/declarative/fx/qfxpositioners.cpp | 168 ++--- src/declarative/fx/qfxpositioners.h | 52 +- src/declarative/fx/qfxpositioners_p.h | 24 +- src/declarative/fx/qfxrect.cpp | 100 +-- src/declarative/fx/qfxrect.h | 52 +- src/declarative/fx/qfxrect_p.h | 24 +- src/declarative/fx/qfxrepeater.cpp | 88 +-- src/declarative/fx/qfxrepeater.h | 16 +- src/declarative/fx/qfxrepeater_p.h | 14 +- src/declarative/fx/qfxscalegrid.cpp | 54 +- src/declarative/fx/qfxscalegrid_p.h | 28 +- src/declarative/fx/qfxtext.cpp | 178 ++--- src/declarative/fx/qfxtext.h | 16 +- src/declarative/fx/qfxtext_p.h | 22 +- src/declarative/fx/qfxtextedit.cpp | 314 ++++---- src/declarative/fx/qfxtextedit.h | 14 +- src/declarative/fx/qfxtextedit_p.h | 18 +- src/declarative/fx/qfxtextinput.cpp | 246 +++---- src/declarative/fx/qfxtextinput.h | 14 +- src/declarative/fx/qfxtextinput_p.h | 18 +- src/declarative/fx/qfxvisualitemmodel.cpp | 338 ++++----- src/declarative/fx/qfxvisualitemmodel.h | 78 +- src/declarative/fx/qfxwebview.cpp | 328 ++++----- src/declarative/fx/qfxwebview.h | 48 +- src/declarative/qml/qmlbinding.cpp | 2 +- src/declarative/qml/qmlboundsignal.cpp | 4 +- src/declarative/qml/qmlcompiler.cpp | 2 +- src/declarative/qml/qmlcomponent.cpp | 4 +- src/declarative/qml/qmldom.cpp | 2 +- src/declarative/qml/qmlengine.cpp | 4 +- src/declarative/qml/qmlexpression.cpp | 6 +- src/declarative/qml/qmlscriptparser.cpp | 2 +- src/declarative/util/qfxglobal.h | 6 +- src/declarative/util/qfxperf.cpp | 16 +- src/declarative/util/qfxperf_p.h | 6 +- src/declarative/util/qmlanimation.cpp | 18 +- src/declarative/util/qmlanimation.h | 14 +- src/declarative/util/qmlanimation_p.h | 4 +- src/declarative/util/qmlstategroup.cpp | 2 +- src/declarative/util/qmlstateoperations.cpp | 164 ++--- src/declarative/util/qmlstateoperations.h | 60 +- src/declarative/util/qmltimer.cpp | 2 +- src/declarative/util/qmlview.cpp | 22 +- src/declarative/util/qmlview.h | 6 +- src/gui/graphicsview/qgraphicsitem_p.h | 2 +- tests/auto/declarative/anchors/tst_anchors.cpp | 84 +-- .../animatedimage/tst_animatedimage.cpp | 8 +- .../auto/declarative/animations/tst_animations.cpp | 22 +- tests/auto/declarative/behaviors/tst_behaviors.cpp | 30 +- tests/auto/declarative/layouts/tst_layouts.cpp | 66 +- tests/auto/declarative/listview/tst_listview.cpp | 108 +-- tests/auto/declarative/pathview/tst_pathview.cpp | 52 +- tests/auto/declarative/qfxloader/tst_qfxloader.cpp | 16 +- .../qfxpixmapcache/tst_qfxpixmapcache.cpp | 22 +- tests/auto/declarative/qfxtext/tst_qfxtext.cpp | 62 +- .../declarative/qfxtextedit/tst_qfxtextedit.cpp | 52 +- .../declarative/qfxtextinput/tst_qfxtextinput.cpp | 42 +- .../auto/declarative/qfxwebview/tst_qfxwebview.cpp | 4 +- .../declarative/qmllanguage/tst_qmllanguage.cpp | 28 +- .../qmlpropertymap/tst_qmlpropertymap.cpp | 2 +- tests/auto/declarative/repeater/tst_repeater.cpp | 28 +- tests/auto/declarative/sql/tst_sql.cpp | 2 +- tests/auto/declarative/states/tst_states.cpp | 22 +- tests/benchmarks/qmlpainting/tst_qmlpainting.cpp | 6 +- tools/qdoc3/htmlgenerator.cpp | 4 +- tools/qmlviewer/qfxtester.cpp | 48 +- tools/qmlviewer/qfxtester.h | 32 +- tools/qmlviewer/qmlviewer.cpp | 2 +- tools/qmlviewer/qmlviewer.h | 6 +- 130 files changed, 4108 insertions(+), 4108 deletions(-) diff --git a/doc/src/declarative/measuring-performance.qdoc b/doc/src/declarative/measuring-performance.qdoc index 01e7b03..bd1b0eb 100644 --- a/doc/src/declarative/measuring-performance.qdoc +++ b/doc/src/declarative/measuring-performance.qdoc @@ -71,14 +71,14 @@ Q_DEFINE_PERFORMANCE_METRIC(TextSize, "Text Size Calculation"); You could then use this category in the code: \code -void QFxText::updateSize() +void QmlGraphicsText::updateSize() { - QFxPerfTimer perf; + QmlPerfTimer perf; ... } \endcode -Because there is no cost for a QFxPerfTimer when Q_ENABLE_PERFORMANCE_LOG is not defined, this line can persist in the code and be used to help detect performance bottlenecks and regressions. See the QPerformanceLog documentation for more information on this performance framework. +Because there is no cost for a QmlPerfTimer when Q_ENABLE_PERFORMANCE_LOG is not defined, this line can persist in the code and be used to help detect performance bottlenecks and regressions. See the QPerformanceLog documentation for more information on this performance framework. \section1 FPS Measurements diff --git a/doc/src/declarative/qtprogrammers.qdoc b/doc/src/declarative/qtprogrammers.qdoc index 4c28255..6892005 100644 --- a/doc/src/declarative/qtprogrammers.qdoc +++ b/doc/src/declarative/qtprogrammers.qdoc @@ -84,14 +84,14 @@ QML Items also serve these purposes. Each is considered separately below. \section2 Simple Widgets -The most important rule to remember while implementing a new QFxItem in C++ +The most important rule to remember while implementing a new QmlGraphicsItem in C++ is that it should not contain any look and feel policies - leave that to the QML usage of the item. As an example, imagine you wanted a reusable Button item. If you therefore -decided to write a QFxItem subclass to implement a button, +decided to write a QmlGraphicsItem subclass to implement a button, just as QToolButton subclasses QWidget for this purpose, following the rule above, your -\c QFxButton would not have any appearance - just the notions of enabled, triggering, etc. +\c QmlGraphicsButton would not have any appearance - just the notions of enabled, triggering, etc. But there is already an object in Qt that does this: QAction. @@ -103,8 +103,8 @@ The look and feel of an action - the appearance of the button, the transition be and exactly how it respond to mouse, key, or touch input, should all be left for definition in QML. -It is illustrative to note that QFxTextEdit is built upon QTextControl, -QFxWebView is built upon QWebPage, and ListView uses QListModelInterface, +It is illustrative to note that QmlGraphicsTextEdit is built upon QTextControl, +QmlGraphicsWebView is built upon QWebPage, and ListView uses QListModelInterface, just as QTextEdit, QWebView, and QListView are built upon those same UI-agnostic components. diff --git a/src/declarative/3rdparty/qlistmodelinterface.cpp b/src/declarative/3rdparty/qlistmodelinterface.cpp index 4213ff2..b47ed8b 100644 --- a/src/declarative/3rdparty/qlistmodelinterface.cpp +++ b/src/declarative/3rdparty/qlistmodelinterface.cpp @@ -46,11 +46,11 @@ QT_BEGIN_NAMESPACE /*! \internal \class QListModelInterface - \brief The QListModelInterface class can be subclassed to provide C++ models to QFx Views + \brief The QListModelInterface class can be subclassed to provide C++ models to QmlGraphics Views This class is comprised primarily of pure virtual functions which you must implement in a subclass. You can then use the subclass - as a model for a QFx view, such as a QFxListView. + as a model for a QmlGraphics view, such as a QmlGraphicsListView. */ /*! \fn QListModelInterface::QListModelInterface(QObject *parent) diff --git a/src/declarative/extra/qfxanimatedimageitem.cpp b/src/declarative/extra/qfxanimatedimageitem.cpp index 5a491e0..8a6046e 100644 --- a/src/declarative/extra/qfxanimatedimageitem.cpp +++ b/src/declarative/extra/qfxanimatedimageitem.cpp @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE /*! - \class QFxAnimatedImageItem + \class QmlGraphicsAnimatedImageItem \internal */ @@ -77,21 +77,21 @@ Item { \endqml \endtable */ -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,AnimatedImage,QFxAnimatedImageItem) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,AnimatedImage,QmlGraphicsAnimatedImageItem) -QFxAnimatedImageItem::QFxAnimatedImageItem(QFxItem *parent) - : QFxImage(*(new QFxAnimatedImageItemPrivate), parent) +QmlGraphicsAnimatedImageItem::QmlGraphicsAnimatedImageItem(QmlGraphicsItem *parent) + : QmlGraphicsImage(*(new QmlGraphicsAnimatedImageItemPrivate), parent) { } -QFxAnimatedImageItem::QFxAnimatedImageItem(QFxAnimatedImageItemPrivate &dd, QFxItem *parent) - : QFxImage(dd, parent) +QmlGraphicsAnimatedImageItem::QmlGraphicsAnimatedImageItem(QmlGraphicsAnimatedImageItemPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsImage(dd, parent) { } -QFxAnimatedImageItem::~QFxAnimatedImageItem() +QmlGraphicsAnimatedImageItem::~QmlGraphicsAnimatedImageItem() { - Q_D(QFxAnimatedImageItem); + Q_D(QmlGraphicsAnimatedImageItem); delete d->_movie; } @@ -101,17 +101,17 @@ QFxAnimatedImageItem::~QFxAnimatedImageItem() Defaults to false, and can be set to true when you want to pause. */ -bool QFxAnimatedImageItem::isPaused() const +bool QmlGraphicsAnimatedImageItem::isPaused() const { - Q_D(const QFxAnimatedImageItem); + Q_D(const QmlGraphicsAnimatedImageItem); if(!d->_movie) return false; return d->_movie->state()==QMovie::Paused; } -void QFxAnimatedImageItem::setPaused(bool pause) +void QmlGraphicsAnimatedImageItem::setPaused(bool pause) { - Q_D(QFxAnimatedImageItem); + Q_D(QmlGraphicsAnimatedImageItem); if(pause == d->paused) return; d->paused = pause; @@ -125,17 +125,17 @@ void QFxAnimatedImageItem::setPaused(bool pause) Defaults to true, so as to start playing immediately. */ -bool QFxAnimatedImageItem::isPlaying() const +bool QmlGraphicsAnimatedImageItem::isPlaying() const { - Q_D(const QFxAnimatedImageItem); + Q_D(const QmlGraphicsAnimatedImageItem); if (!d->_movie) return false; return d->_movie->state()!=QMovie::NotRunning; } -void QFxAnimatedImageItem::setPlaying(bool play) +void QmlGraphicsAnimatedImageItem::setPlaying(bool play) { - Q_D(QFxAnimatedImageItem); + Q_D(QmlGraphicsAnimatedImageItem); if(play == d->playing) return; d->playing = play; @@ -155,33 +155,33 @@ void QFxAnimatedImageItem::setPlaying(bool play) 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 +int QmlGraphicsAnimatedImageItem::currentFrame() const { - Q_D(const QFxAnimatedImageItem); + Q_D(const QmlGraphicsAnimatedImageItem); if (!d->_movie) return -1; return d->_movie->currentFrameNumber(); } -void QFxAnimatedImageItem::setCurrentFrame(int frame) +void QmlGraphicsAnimatedImageItem::setCurrentFrame(int frame) { - Q_D(QFxAnimatedImageItem); + Q_D(QmlGraphicsAnimatedImageItem); if (!d->_movie) return; d->_movie->jumpToFrame(frame); } -int QFxAnimatedImageItem::frameCount() const +int QmlGraphicsAnimatedImageItem::frameCount() const { - Q_D(const QFxAnimatedImageItem); + Q_D(const QmlGraphicsAnimatedImageItem); if (!d->_movie) return 0; return d->_movie->frameCount(); } -void QFxAnimatedImageItem::setSource(const QUrl &url) +void QmlGraphicsAnimatedImageItem::setSource(const QUrl &url) { - Q_D(QFxAnimatedImageItem); + Q_D(QmlGraphicsAnimatedImageItem); if (url == d->url) return; @@ -209,9 +209,9 @@ void QFxAnimatedImageItem::setSource(const QUrl &url) emit statusChanged(d->status); } -void QFxAnimatedImageItem::movieRequestFinished() +void QmlGraphicsAnimatedImageItem::movieRequestFinished() { - Q_D(QFxAnimatedImageItem); + Q_D(QmlGraphicsAnimatedImageItem); d->_movie = new QMovie(d->reply); if (!d->_movie->isValid()){ qWarning() << "Error Reading Animated Image File " << d->url; @@ -233,16 +233,16 @@ void QFxAnimatedImageItem::movieRequestFinished() setPixmap(d->_movie->currentPixmap()); } -void QFxAnimatedImageItem::movieUpdate() +void QmlGraphicsAnimatedImageItem::movieUpdate() { - Q_D(QFxAnimatedImageItem); + Q_D(QmlGraphicsAnimatedImageItem); setPixmap(d->_movie->currentPixmap()); emit frameChanged(); } -void QFxAnimatedImageItem::playingStatusChanged() +void QmlGraphicsAnimatedImageItem::playingStatusChanged() { - Q_D(QFxAnimatedImageItem); + Q_D(QmlGraphicsAnimatedImageItem); if((d->_movie->state() != QMovie::NotRunning) != d->playing){ d->playing = (d->_movie->state() != QMovie::NotRunning); emit playingChanged(); diff --git a/src/declarative/extra/qfxanimatedimageitem.h b/src/declarative/extra/qfxanimatedimageitem.h index 4002a3f..782f920 100644 --- a/src/declarative/extra/qfxanimatedimageitem.h +++ b/src/declarative/extra/qfxanimatedimageitem.h @@ -51,9 +51,9 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QMovie; -class QFxAnimatedImageItemPrivate; +class QmlGraphicsAnimatedImageItemPrivate; -class Q_DECLARATIVE_EXPORT QFxAnimatedImageItem : public QFxImage +class Q_DECLARATIVE_EXPORT QmlGraphicsAnimatedImageItem : public QmlGraphicsImage { Q_OBJECT @@ -62,8 +62,8 @@ class Q_DECLARATIVE_EXPORT QFxAnimatedImageItem : public QFxImage Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY frameChanged) Q_PROPERTY(int frameCount READ frameCount) public: - QFxAnimatedImageItem(QFxItem *parent=0); - ~QFxAnimatedImageItem(); + QmlGraphicsAnimatedImageItem(QmlGraphicsItem *parent=0); + ~QmlGraphicsAnimatedImageItem(); bool isPlaying() const; void setPlaying(bool play); @@ -76,7 +76,7 @@ public: int frameCount() const; - // Extends QFxImage's src property*/ + // Extends QmlGraphicsImage's src property*/ virtual void setSource(const QUrl&); Q_SIGNALS: @@ -90,16 +90,16 @@ private Q_SLOTS: void playingStatusChanged(); protected: - QFxAnimatedImageItem(QFxAnimatedImageItemPrivate &dd, QFxItem *parent); + QmlGraphicsAnimatedImageItem(QmlGraphicsAnimatedImageItemPrivate &dd, QmlGraphicsItem *parent); private: - Q_DISABLE_COPY(QFxAnimatedImageItem) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxAnimatedImageItem) + Q_DISABLE_COPY(QmlGraphicsAnimatedImageItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsAnimatedImageItem) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxAnimatedImageItem) +QML_DECLARE_TYPE(QmlGraphicsAnimatedImageItem) QT_END_HEADER diff --git a/src/declarative/extra/qfxanimatedimageitem_p.h b/src/declarative/extra/qfxanimatedimageitem_p.h index 56252ca..e61c488 100644 --- a/src/declarative/extra/qfxanimatedimageitem_p.h +++ b/src/declarative/extra/qfxanimatedimageitem_p.h @@ -60,12 +60,12 @@ QT_BEGIN_NAMESPACE class QMovie; class QNetworkReply; -class QFxAnimatedImageItemPrivate : public QFxImagePrivate +class QmlGraphicsAnimatedImageItemPrivate : public QmlGraphicsImagePrivate { - Q_DECLARE_PUBLIC(QFxAnimatedImageItem) + Q_DECLARE_PUBLIC(QmlGraphicsAnimatedImageItem) public: - QFxAnimatedImageItemPrivate() + QmlGraphicsAnimatedImageItemPrivate() : playing(true), paused(false), _movie(0), reply(0) { } diff --git a/src/declarative/extra/qfxintegermodel.cpp b/src/declarative/extra/qfxintegermodel.cpp index 3cd46d7..496cd3e 100644 --- a/src/declarative/extra/qfxintegermodel.cpp +++ b/src/declarative/extra/qfxintegermodel.cpp @@ -43,53 +43,53 @@ QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,IntegerModel,QFxIntegerModel) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,IntegerModel,QmlGraphicsIntegerModel) -class QFxIntegerModelPrivate +class QmlGraphicsIntegerModelPrivate { public: - QFxIntegerModelPrivate() : minimum(0), maximum(0) {} + QmlGraphicsIntegerModelPrivate() : minimum(0), maximum(0) {} int minimum; int maximum; }; -QFxIntegerModel::QFxIntegerModel(QObject *parent) +QmlGraphicsIntegerModel::QmlGraphicsIntegerModel(QObject *parent) : QListModelInterface(parent) { - d = new QFxIntegerModelPrivate; + d = new QmlGraphicsIntegerModelPrivate; } -QFxIntegerModel::~QFxIntegerModel() +QmlGraphicsIntegerModel::~QmlGraphicsIntegerModel() { delete d; } -int QFxIntegerModel::minimum() const +int QmlGraphicsIntegerModel::minimum() const { return d->minimum; } -void QFxIntegerModel::setMinimum(int minimum) +void QmlGraphicsIntegerModel::setMinimum(int minimum) { d->minimum = minimum; } -int QFxIntegerModel::maximum() const +int QmlGraphicsIntegerModel::maximum() const { return d->maximum; } -void QFxIntegerModel::setMaximum(int maximum) +void QmlGraphicsIntegerModel::setMaximum(int maximum) { d->maximum = maximum; } -int QFxIntegerModel::count() const +int QmlGraphicsIntegerModel::count() const { return qMax(0, d->maximum - d->minimum + 1); } -QHash QFxIntegerModel::data(int index, const QList &roles) const +QHash QmlGraphicsIntegerModel::data(int index, const QList &roles) const { QHash returnHash; @@ -108,7 +108,7 @@ QHash QFxIntegerModel::data(int index, const QList &roles) co return returnHash; } -QString QFxIntegerModel::toString(int role) const +QString QmlGraphicsIntegerModel::toString(int role) const { switch(role) { case Qt::DisplayRole: @@ -118,7 +118,7 @@ QString QFxIntegerModel::toString(int role) const } } -QList QFxIntegerModel::roles() const +QList QmlGraphicsIntegerModel::roles() const { return QList() << Qt::DisplayRole; } diff --git a/src/declarative/extra/qfxintegermodel.h b/src/declarative/extra/qfxintegermodel.h index 7fced2c..cf69bdc 100644 --- a/src/declarative/extra/qfxintegermodel.h +++ b/src/declarative/extra/qfxintegermodel.h @@ -52,13 +52,13 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxIntegerModelPrivate; -class Q_DECLARATIVE_EXPORT QFxIntegerModel : public QListModelInterface +class QmlGraphicsIntegerModelPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsIntegerModel : public QListModelInterface { Q_OBJECT public: - QFxIntegerModel(QObject *parent=0); - ~QFxIntegerModel(); + QmlGraphicsIntegerModel(QObject *parent=0); + ~QmlGraphicsIntegerModel(); Q_PROPERTY(int minimum READ minimum WRITE setMinimum) int minimum() const; @@ -74,12 +74,12 @@ public: QString toString(int role) const; private: - QFxIntegerModelPrivate *d; + QmlGraphicsIntegerModelPrivate *d; }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxIntegerModel) +QML_DECLARE_TYPE(QmlGraphicsIntegerModel) QT_END_HEADER diff --git a/src/declarative/extra/qfxparticles.cpp b/src/declarative/extra/qfxparticles.cpp index 80255b9..0bb4826 100644 --- a/src/declarative/extra/qfxparticles.cpp +++ b/src/declarative/extra/qfxparticles.cpp @@ -81,10 +81,10 @@ inline qreal fastCos(qreal theta) return fastSin(theta); } -class QFxParticle +class QmlGraphicsParticle { public: - QFxParticle(int time) : lifeSpan(1000), fadeOutAge(800) + QmlGraphicsParticle(int time) : lifeSpan(1000), fadeOutAge(800) , opacity(0), birthTime(time), x_velocity(0), y_velocity(0) , state(FadeIn), data(0) { @@ -105,21 +105,21 @@ public: //--------------------------------------------------------------------------- -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotion,QFxParticleMotion) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotion,QmlGraphicsParticleMotion) /*! - \class QFxParticleMotion + \class QmlGraphicsParticleMotion \ingroup group_effects - \brief The QFxParticleMotion class is the base class for particle motion. + \brief The QmlGraphicsParticleMotion class is the base class for particle motion. \internal This class causes the particles to remain static. */ /*! - Constructs a QFxParticleMotion with parent object \a parent. + Constructs a QmlGraphicsParticleMotion with parent object \a parent. */ -QFxParticleMotion::QFxParticleMotion(QObject *parent) : +QmlGraphicsParticleMotion::QmlGraphicsParticleMotion(QObject *parent) : QObject(parent) { } @@ -128,7 +128,7 @@ QFxParticleMotion::QFxParticleMotion(QObject *parent) : Move the \a particle to its new position. \a interval is the number of milliseconds elapsed since it was last moved. */ -void QFxParticleMotion::advance(QFxParticle &particle, int interval) +void QmlGraphicsParticleMotion::advance(QmlGraphicsParticle &particle, int interval) { Q_UNUSED(particle); Q_UNUSED(interval); @@ -138,7 +138,7 @@ void QFxParticleMotion::advance(QFxParticle &particle, int interval) The \a particle has just been created. Some motion strategies require additional state information. This can be allocated by this function. */ -void QFxParticleMotion::created(QFxParticle &particle) +void QmlGraphicsParticleMotion::created(QmlGraphicsParticle &particle) { Q_UNUSED(particle); } @@ -147,7 +147,7 @@ void QFxParticleMotion::created(QFxParticle &particle) The \a particle is about to be destroyed. Any additional memory that has been allocated for the particle should be freed. */ -void QFxParticleMotion::destroy(QFxParticle &particle) +void QmlGraphicsParticleMotion::destroy(QmlGraphicsParticle &particle) { Q_UNUSED(particle); } @@ -161,14 +161,14 @@ void QFxParticleMotion::destroy(QFxParticle &particle) /*! \internal - \class QFxParticleMotionLinear + \class QmlGraphicsParticleMotionLinear \ingroup group_effects - \brief The QFxParticleMotionLinear class moves the particles linearly. + \brief The QmlGraphicsParticleMotionLinear class moves the particles linearly. */ -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionLinear,QFxParticleMotionLinear) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionLinear,QmlGraphicsParticleMotionLinear) -void QFxParticleMotionLinear::advance(QFxParticle &p, int interval) +void QmlGraphicsParticleMotionLinear::advance(QmlGraphicsParticle &p, int interval) { p.x += interval * p.x_velocity; p.y += interval * p.y_velocity; @@ -183,12 +183,12 @@ void QFxParticleMotionLinear::advance(QFxParticle &p, int interval) /*! \internal - \class QFxParticleMotionGravity + \class QmlGraphicsParticleMotionGravity \ingroup group_effects - \brief The QFxParticleMotionGravity class moves the particles towards a point. + \brief The QmlGraphicsParticleMotionGravity class moves the particles towards a point. */ -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionGravity,QFxParticleMotionGravity) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionGravity,QmlGraphicsParticleMotionGravity) /*! \qmlproperty int ParticleMotionGravity::xattractor @@ -202,21 +202,21 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionGravity,QFxParticl */ /*! - \property QFxParticleMotionGravity::xattractor + \property QmlGraphicsParticleMotionGravity::xattractor \brief the x coordinate of the point attracting the particles. */ /*! - \property QFxParticleMotionGravity::yattractor + \property QmlGraphicsParticleMotionGravity::yattractor \brief the y coordinate of the point attracting the particles. */ /*! - \property QFxParticleMotionGravity::acceleration + \property QmlGraphicsParticleMotionGravity::acceleration \brief the acceleration to apply to the particles. */ -void QFxParticleMotionGravity::advance(QFxParticle &p, int interval) +void QmlGraphicsParticleMotionGravity::advance(QmlGraphicsParticle &p, int interval) { qreal xdiff = p.x - _xAttr; qreal ydiff = p.y - _yAttr; @@ -270,32 +270,32 @@ Rectangle { /*! \internal - \class QFxParticleMotionWander + \class QmlGraphicsParticleMotionWander \ingroup group_effects - \brief The QFxParticleMotionWander class moves particles in a somewhat random fashion. + \brief The QmlGraphicsParticleMotionWander class moves particles in a somewhat random fashion. The particles will continue roughly in the original direction, however will randomly drift to each side. */ /*! - \qmlproperty int QFxParticleMotionWander::xvariance - \qmlproperty int QFxParticleMotionWander::yvariance + \qmlproperty int QmlGraphicsParticleMotionWander::xvariance + \qmlproperty int QmlGraphicsParticleMotionWander::yvariance These properties set the amount to wander in the x and y directions. */ /*! - \qmlproperty int QFxParticleMotionWander::pace + \qmlproperty int QmlGraphicsParticleMotionWander::pace This property holds how quickly the paricles will move from side to side. */ -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionWander,QFxParticleMotionWander) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionWander,QmlGraphicsParticleMotionWander) -void QFxParticleMotionWander::advance(QFxParticle &p, int interval) +void QmlGraphicsParticleMotionWander::advance(QmlGraphicsParticle &p, int interval) { if (!particles) - particles = qobject_cast(parent()); + particles = qobject_cast(parent()); if (particles) { Data *d = (Data*)p.data; if (_xvariance != 0.) { @@ -320,7 +320,7 @@ void QFxParticleMotionWander::advance(QFxParticle &p, int interval) } } -void QFxParticleMotionWander::created(QFxParticle &p) +void QmlGraphicsParticleMotionWander::created(QmlGraphicsParticle &p) { if (!p.data) { Data *d = new Data; @@ -334,18 +334,18 @@ void QFxParticleMotionWander::created(QFxParticle &p) } } -void QFxParticleMotionWander::destroy(QFxParticle &p) +void QmlGraphicsParticleMotionWander::destroy(QmlGraphicsParticle &p) { if (p.data) delete (Data*)p.data; } //--------------------------------------------------------------------------- -class QFxParticlesPainter : public QFxItem +class QmlGraphicsParticlesPainter : public QmlGraphicsItem { public: - QFxParticlesPainter(QFxParticlesPrivate *p, QFxItem* parent) - : QFxItem(parent), d(p) + QmlGraphicsParticlesPainter(QmlGraphicsParticlesPrivate *p, QmlGraphicsItem* parent) + : QmlGraphicsItem(parent), d(p) { setFlag(QGraphicsItem::ItemHasNoContents, false); maxX = minX = maxY = minY = 0; @@ -359,15 +359,15 @@ public: qreal minX; qreal maxY; qreal minY; - QFxParticlesPrivate* d; + QmlGraphicsParticlesPrivate* d; }; //--------------------------------------------------------------------------- -class QFxParticlesPrivate : public QFxItemPrivate +class QmlGraphicsParticlesPrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxParticles) + Q_DECLARE_PUBLIC(QmlGraphicsParticles) public: - QFxParticlesPrivate() + QmlGraphicsParticlesPrivate() : count(1), lifeSpan(1000), lifeSpanDev(1000), fadeInDur(200), fadeOutDur(300) , angle(0), angleDev(0), velocity(0), velocityDev(0) , addParticleTime(0), addParticleCount(0), lastAdvTime(0), stream(false), streamDelay(0) @@ -375,19 +375,19 @@ public: { } - ~QFxParticlesPrivate() + ~QmlGraphicsParticlesPrivate() { } void init() { - Q_Q(QFxParticles); - paintItem = new QFxParticlesPainter(this, q); + Q_Q(QmlGraphicsParticles); + paintItem = new QmlGraphicsParticlesPainter(this, q); } void tick(int time); void createParticle(int time); - void updateOpacity(QFxParticle &p, int age); + void updateOpacity(QmlGraphicsParticle &p, int age); QUrl url; QPixmap image; @@ -406,30 +406,30 @@ public: bool stream; int streamDelay; bool emitting; - QFxParticleMotion *motion; - QFxParticlesPainter *paintItem; + QmlGraphicsParticleMotion *motion; + QmlGraphicsParticlesPainter *paintItem; bool pendingPixmapCache; - QList particles; - QTickAnimationProxy clock; + QList particles; + QTickAnimationProxy clock; }; -void QFxParticlesPrivate::tick(int time) +void QmlGraphicsParticlesPrivate::tick(int time) { - Q_Q(QFxParticles); + Q_Q(QmlGraphicsParticles); if (!motion) - motion = new QFxParticleMotionLinear(q); + motion = new QmlGraphicsParticleMotionLinear(q); int oldCount = particles.count(); int removed = 0; int interval = time - lastAdvTime; for (int i = 0; i < particles.count(); ) { - QFxParticle &particle = particles[i]; + QmlGraphicsParticle &particle = particles[i]; int age = time - particle.birthTime; if (age >= particle.lifeSpan) { - QFxParticle part = particles.takeAt(i); + QmlGraphicsParticle part = particles.takeAt(i); motion->destroy(part); ++removed; } else { @@ -478,13 +478,13 @@ void QFxParticlesPrivate::tick(int time) } } -void QFxParticlesPrivate::createParticle(int time) +void QmlGraphicsParticlesPrivate::createParticle(int time) { #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer x; + QmlPerfTimer x; #endif - Q_Q(QFxParticles); - QFxParticle p(time); + Q_Q(QmlGraphicsParticles); + QmlGraphicsParticle p(time); p.x = q->x() + q->width() * qreal(rand()) / RAND_MAX - image.width()/2.0; p.y = q->y() + q->height() * qreal(rand()) / RAND_MAX - image.height()/2.0; p.lifeSpan = lifeSpan; @@ -492,7 +492,7 @@ void QFxParticlesPrivate::createParticle(int time) p.lifeSpan += int(lifeSpanDev/2 - lifeSpanDev * qreal(rand()) / RAND_MAX); p.fadeOutAge = p.lifeSpan - fadeOutDur; if (fadeInDur == 0.) { - p.state= QFxParticle::Solid; + p.state= QmlGraphicsParticle::Solid; p.opacity = 1.0; } qreal a = angle; @@ -509,32 +509,32 @@ void QFxParticlesPrivate::createParticle(int time) motion->created(particles.last()); } -void QFxParticlesPrivate::updateOpacity(QFxParticle &p, int age) +void QmlGraphicsParticlesPrivate::updateOpacity(QmlGraphicsParticle &p, int age) { switch (p.state) { - case QFxParticle::FadeIn: + case QmlGraphicsParticle::FadeIn: if (age <= fadeInDur) { p.opacity = qreal(age) / fadeInDur; break; } else { p.opacity = 1.0; - p.state = QFxParticle::Solid; + p.state = QmlGraphicsParticle::Solid; // Fall through } - case QFxParticle::Solid: + case QmlGraphicsParticle::Solid: if (age <= p.fadeOutAge) { break; } else { - p.state = QFxParticle::FadeOut; + p.state = QmlGraphicsParticle::FadeOut; // Fall through } - case QFxParticle::FadeOut: + case QmlGraphicsParticle::FadeOut: p.opacity = qreal(p.lifeSpan - age) / fadeOutDur; break; } } -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Particles,QFxParticles) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Particles,QmlGraphicsParticles) /*! \qmlclass Particles @@ -596,30 +596,30 @@ Rectangle { /*! \internal - \class QFxParticles + \class QmlGraphicsParticles \ingroup group_effects - \brief The QFxParticles class generates and moves particles. + \brief The QmlGraphicsParticles class generates and moves particles. */ -QFxParticles::QFxParticles(QFxItem *parent) - : QFxItem(*(new QFxParticlesPrivate), parent) +QmlGraphicsParticles::QmlGraphicsParticles(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsParticlesPrivate), parent) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); d->init(); } -QFxParticles::QFxParticles(QFxParticlesPrivate &dd, QFxItem *parent) - : QFxItem(dd, parent) +QmlGraphicsParticles::QmlGraphicsParticles(QmlGraphicsParticlesPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); d->init(); } -QFxParticles::~QFxParticles() +QmlGraphicsParticles::~QmlGraphicsParticles() { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); if (d->pendingPixmapCache) - QFxPixmapCache::cancelGet(d->url, this); + QmlGraphicsPixmapCache::cancelGet(d->url, this); } /*! @@ -628,33 +628,33 @@ QFxParticles::~QFxParticles() */ /*! - \property QFxParticles::source + \property QmlGraphicsParticles::source \brief the URL of the particle image. */ -QUrl QFxParticles::source() const +QUrl QmlGraphicsParticles::source() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->url; } -void QFxParticles::imageLoaded() +void QmlGraphicsParticles::imageLoaded() { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); d->pendingPixmapCache = false; - QFxPixmapCache::find(d->url, &d->image); + QmlGraphicsPixmapCache::find(d->url, &d->image); d->paintItem->updateSize(); d->paintItem->update(); } -void QFxParticles::setSource(const QUrl &name) +void QmlGraphicsParticles::setSource(const QUrl &name) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); if ((d->url.isEmpty() == name.isEmpty()) && name == d->url) return; if (d->pendingPixmapCache) { - QFxPixmapCache::cancelGet(d->url, this); + QmlGraphicsPixmapCache::cancelGet(d->url, this); d->pendingPixmapCache = false; } if (name.isEmpty()) { @@ -665,7 +665,7 @@ void QFxParticles::setSource(const QUrl &name) } else { d->url = name; Q_ASSERT(!name.isRelative()); - QNetworkReply *reply = QFxPixmapCache::get(qmlEngine(this), d->url, &d->image); + QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->image); if (reply) { connect(reply, SIGNAL(finished()), this, SLOT(imageLoaded())); d->pendingPixmapCache = true; @@ -683,18 +683,18 @@ void QFxParticles::setSource(const QUrl &name) */ /*! - \property QFxParticles::count + \property QmlGraphicsParticles::count \brief the target number of particles */ -int QFxParticles::count() const +int QmlGraphicsParticles::count() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->count; } -void QFxParticles::setCount(int cnt) +void QmlGraphicsParticles::setCount(int cnt) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); if (cnt == d->count) return; @@ -731,27 +731,27 @@ Particles { */ /*! - \property QFxParticles::lifeSpan + \property QmlGraphicsParticles::lifeSpan \brief the life span of each particle. Default value is 1000ms. - \sa QFxParticles::lifeSpanDeviation + \sa QmlGraphicsParticles::lifeSpanDeviation */ -int QFxParticles::lifeSpan() const +int QmlGraphicsParticles::lifeSpan() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->lifeSpan; } -void QFxParticles::setLifeSpan(int ls) +void QmlGraphicsParticles::setLifeSpan(int ls) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); d->lifeSpan = ls; } /*! - \property QFxParticles::lifeSpanDeviation + \property QmlGraphicsParticles::lifeSpanDeviation \brief the maximum possible deviation from the set lifeSpan. Randomly varies the lifeSpan up to the specified variation. For @@ -766,17 +766,17 @@ Particles { } \endqml - \sa QFxParticles::lifeSpan + \sa QmlGraphicsParticles::lifeSpan */ -int QFxParticles::lifeSpanDeviation() const +int QmlGraphicsParticles::lifeSpanDeviation() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->lifeSpanDev; } -void QFxParticles::setLifeSpanDeviation(int dev) +void QmlGraphicsParticles::setLifeSpanDeviation(int dev) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); d->lifeSpanDev = dev; } @@ -789,39 +789,39 @@ void QFxParticles::setLifeSpanDeviation(int dev) */ /*! - \property QFxParticles::fadeInDuration + \property QmlGraphicsParticles::fadeInDuration \brief the time taken to fade in the particles. Default value is 200ms. */ -int QFxParticles::fadeInDuration() const +int QmlGraphicsParticles::fadeInDuration() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->fadeInDur; } -void QFxParticles::setFadeInDuration(int dur) +void QmlGraphicsParticles::setFadeInDuration(int dur) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); if (dur >= 0.0) d->fadeInDur = dur; } /*! - \property QFxParticles::fadeOutDuration + \property QmlGraphicsParticles::fadeOutDuration \brief the time taken to fade out the particles. Default value is 300ms. */ -int QFxParticles::fadeOutDuration() const +int QmlGraphicsParticles::fadeOutDuration() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->fadeOutDur; } -void QFxParticles::setFadeOutDuration(int dur) +void QmlGraphicsParticles::setFadeOutDuration(int dur) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); if (dur >= 0.0) d->fadeOutDur = dur; } @@ -846,25 +846,25 @@ Particles { */ /*! - \property QFxParticles::angle + \property QmlGraphicsParticles::angle \brief the initial angle of direction. - \sa QFxParticles::angleDeviation + \sa QmlGraphicsParticles::angleDeviation */ -qreal QFxParticles::angle() const +qreal QmlGraphicsParticles::angle() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->angle * 180.0 / M_PI; } -void QFxParticles::setAngle(qreal angle) +void QmlGraphicsParticles::setAngle(qreal angle) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); d->angle = angle * M_PI / 180.0; } /*! - \property QFxParticles::angleDeviation + \property QmlGraphicsParticles::angleDeviation \brief the maximum possible deviation from the set angle. Randomly varies the direction up to the specified variation. For @@ -879,17 +879,17 @@ Particles { } \endqml - \sa QFxParticles::angle + \sa QmlGraphicsParticles::angle */ -qreal QFxParticles::angleDeviation() const +qreal QmlGraphicsParticles::angleDeviation() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->angleDev * 180.0 / M_PI; } -void QFxParticles::setAngleDeviation(qreal dev) +void QmlGraphicsParticles::setAngleDeviation(qreal dev) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); d->angleDev = dev * M_PI / 180.0;; } @@ -913,25 +913,25 @@ Particles { */ /*! - \property QFxParticles::velocity + \property QmlGraphicsParticles::velocity \brief the initial velocity of the particles. - \sa QFxParticles::velocityDeviation + \sa QmlGraphicsParticles::velocityDeviation */ -qreal QFxParticles::velocity() const +qreal QmlGraphicsParticles::velocity() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->velocity * 1000.0; } -void QFxParticles::setVelocity(qreal velocity) +void QmlGraphicsParticles::setVelocity(qreal velocity) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); d->velocity = velocity / 1000.0; } /*! - \property QFxParticles::velocityDeviation + \property QmlGraphicsParticles::velocityDeviation \brief the maximum possible deviation from the set velocity. Randomly varies the velocity up to the specified variation. For @@ -946,17 +946,17 @@ Particles { } \endqml - \sa QFxParticles::velocity + \sa QmlGraphicsParticles::velocity */ -qreal QFxParticles::velocityDeviation() const +qreal QmlGraphicsParticles::velocityDeviation() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->velocityDev * 1000.0; } -void QFxParticles::setVelocityDeviation(qreal velocity) +void QmlGraphicsParticles::setVelocityDeviation(qreal velocity) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); d->velocityDev = velocity / 1000.0; } @@ -970,7 +970,7 @@ void QFxParticles::setVelocityDeviation(qreal velocity) particles to unclump over time. */ /*! - \property QFxParticles::streamIn + \property QmlGraphicsParticles::streamIn \brief determines whether the particles stream in at a constant rate When stream is set to true the particles will stream in at a constant rate. @@ -979,15 +979,15 @@ void QFxParticles::setVelocityDeviation(qreal velocity) */ //The name may need a rethink -bool QFxParticles::streamIn() const +bool QmlGraphicsParticles::streamIn() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->stream; } -void QFxParticles::setStreamIn(bool b) +void QmlGraphicsParticles::setStreamIn(bool b) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); d->stream = b; } @@ -1003,7 +1003,7 @@ void QFxParticles::setStreamIn(bool b) will be produced until it is set to true. */ /*! - \property QFxParticles::emitting + \property QmlGraphicsParticles::emitting If emitting is set to false no new particles will be created. This means that when a particle reaches the end of its lifespan it is not replaced. This property can be used to turn particles on and off with a more natural look. @@ -1011,15 +1011,15 @@ void QFxParticles::setStreamIn(bool b) The default setting is true. Note that if it initialized to false no particles will be produced until it is set to true. */ -bool QFxParticles::emitting() const +bool QmlGraphicsParticles::emitting() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->emitting; } -void QFxParticles::setEmitting(bool r) +void QmlGraphicsParticles::setEmitting(bool r) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); d->emitting = r; if (d->count && r) d->clock.start(); @@ -1036,28 +1036,28 @@ void QFxParticles::setEmitting(bool r) */ /*! - \property QFxParticles::motion + \property QmlGraphicsParticles::motion \brief sets the type of motion to apply to the particles. When a particle is created it will have an initial direction and velocity. The motion of the particle during its lifeSpan is then influenced by the motion property. - Default motion is QFxParticleMotionLinear. + Default motion is QmlGraphicsParticleMotionLinear. */ -QFxParticleMotion *QFxParticles::motion() const +QmlGraphicsParticleMotion *QmlGraphicsParticles::motion() const { - Q_D(const QFxParticles); + Q_D(const QmlGraphicsParticles); return d->motion; } -void QFxParticles::setMotion(QFxParticleMotion *motion) +void QmlGraphicsParticles::setMotion(QmlGraphicsParticleMotion *motion) { - Q_D(QFxParticles); + Q_D(QmlGraphicsParticles); d->motion = motion; } -void QFxParticlesPainter::updateSize() +void QmlGraphicsParticlesPainter::updateSize() { if (!isComponentComplete()) return; @@ -1065,7 +1065,7 @@ void QFxParticlesPainter::updateSize() const int parentX = parentItem()->x(); const int parentY = parentItem()->y(); for (int i = 0; i < d->particles.count(); ++i) { - const QFxParticle &particle = d->particles.at(i); + const QmlGraphicsParticle &particle = d->particles.at(i); if(particle.x > maxX) maxX = particle.x; if(particle.x < minX) @@ -1086,13 +1086,13 @@ void QFxParticlesPainter::updateSize() setY(myY); } -void QFxParticles::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +void QmlGraphicsParticles::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_UNUSED(p); //painting is done by the ParticlesPainter, so it can have the right size } -void QFxParticlesPainter::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +void QmlGraphicsParticlesPainter::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { if (d->image.isNull() || d->particles.isEmpty()) return; @@ -1106,7 +1106,7 @@ void QFxParticlesPainter::paint(QPainter *p, const QStyleOptionGraphicsItem *, Q const QRectF sourceRect = d->image.rect(); for (int i = 0; i < d->particles.count(); ++i) { - const QFxParticle &particle = d->particles.at(i); + const QmlGraphicsParticle &particle = d->particles.at(i); pixmapData[i].point = QPointF(particle.x - myX, particle.y - myY); pixmapData[i].opacity = particle.opacity; @@ -1119,10 +1119,10 @@ void QFxParticlesPainter::paint(QPainter *p, const QStyleOptionGraphicsItem *, Q qDrawPixmaps(p, pixmapData.data(), d->particles.count(), d->image); } -void QFxParticles::componentComplete() +void QmlGraphicsParticles::componentComplete() { - Q_D(QFxParticles); - QFxItem::componentComplete(); + Q_D(QmlGraphicsParticles); + QmlGraphicsItem::componentComplete(); if (d->count) { d->paintItem->updateSize(); d->clock.start(); diff --git a/src/declarative/extra/qfxparticles.h b/src/declarative/extra/qfxparticles.h index 959c518..5e5a581 100644 --- a/src/declarative/extra/qfxparticles.h +++ b/src/declarative/extra/qfxparticles.h @@ -50,30 +50,30 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxParticle; -class QFxParticles; -class Q_DECLARATIVE_EXPORT QFxParticleMotion : public QObject +class QmlGraphicsParticle; +class QmlGraphicsParticles; +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotion : public QObject { Q_OBJECT public: - QFxParticleMotion(QObject *parent=0); + QmlGraphicsParticleMotion(QObject *parent=0); - virtual void advance(QFxParticle &, int interval); - virtual void created(QFxParticle &); - virtual void destroy(QFxParticle &); + virtual void advance(QmlGraphicsParticle &, int interval); + virtual void created(QmlGraphicsParticle &); + virtual void destroy(QmlGraphicsParticle &); }; -class Q_DECLARATIVE_EXPORT QFxParticleMotionLinear : public QFxParticleMotion +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionLinear : public QmlGraphicsParticleMotion { Q_OBJECT public: - QFxParticleMotionLinear(QObject *parent=0) - : QFxParticleMotion(parent) {} + QmlGraphicsParticleMotionLinear(QObject *parent=0) + : QmlGraphicsParticleMotion(parent) {} - virtual void advance(QFxParticle &, int interval); + virtual void advance(QmlGraphicsParticle &, int interval); }; -class Q_DECLARATIVE_EXPORT QFxParticleMotionGravity : public QFxParticleMotion +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionGravity : public QmlGraphicsParticleMotion { Q_OBJECT @@ -81,8 +81,8 @@ class Q_DECLARATIVE_EXPORT QFxParticleMotionGravity : public QFxParticleMotion Q_PROPERTY(int yattractor READ yAttractor WRITE setYAttractor) Q_PROPERTY(int acceleration READ acceleration WRITE setAcceleration) public: - QFxParticleMotionGravity(QObject *parent=0) - : QFxParticleMotion(parent), _xAttr(0), _yAttr(0), _accel(0.00005) {} + QmlGraphicsParticleMotionGravity(QObject *parent=0) + : QmlGraphicsParticleMotion(parent), _xAttr(0), _yAttr(0), _accel(0.00005) {} int xAttractor() const { return _xAttr; } void setXAttractor(int x) { _xAttr = x; } @@ -93,7 +93,7 @@ public: int acceleration() const { return int(_accel * 1000000); } void setAcceleration(int accel) { _accel = qreal(accel)/1000000.0; } - virtual void advance(QFxParticle &, int interval); + virtual void advance(QmlGraphicsParticle &, int interval); private: int _xAttr; @@ -101,16 +101,16 @@ private: qreal _accel; }; -class Q_DECLARATIVE_EXPORT QFxParticleMotionWander : public QFxParticleMotion +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionWander : public QmlGraphicsParticleMotion { Q_OBJECT public: - QFxParticleMotionWander() - : QFxParticleMotion(), particles(0), _xvariance(0), _yvariance(0) {} + QmlGraphicsParticleMotionWander() + : QmlGraphicsParticleMotion(), particles(0), _xvariance(0), _yvariance(0) {} - virtual void advance(QFxParticle &, int interval); - virtual void created(QFxParticle &); - virtual void destroy(QFxParticle &); + virtual void advance(QmlGraphicsParticle &, int interval); + virtual void created(QmlGraphicsParticle &); + virtual void destroy(QmlGraphicsParticle &); struct Data { qreal x_targetV; @@ -134,14 +134,14 @@ public: void setPace(int pace) { _pace = pace / 1000.0; } private: - QFxParticles *particles; + QmlGraphicsParticles *particles; qreal _xvariance; qreal _yvariance; qreal _pace; }; -class QFxParticlesPrivate; -class Q_DECLARATIVE_EXPORT QFxParticles : public QFxItem +class QmlGraphicsParticlesPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsParticles : public QmlGraphicsItem { Q_OBJECT @@ -157,12 +157,12 @@ class Q_DECLARATIVE_EXPORT QFxParticles : public QFxItem Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation) Q_PROPERTY(bool streamIn READ streamIn WRITE setStreamIn) Q_PROPERTY(bool emitting READ emitting WRITE setEmitting) - Q_PROPERTY(QFxParticleMotion *motion READ motion WRITE setMotion) + Q_PROPERTY(QmlGraphicsParticleMotion *motion READ motion WRITE setMotion) Q_CLASSINFO("DefaultProperty", "motion") public: - QFxParticles(QFxItem *parent=0); - ~QFxParticles(); + QmlGraphicsParticles(QmlGraphicsItem *parent=0); + ~QmlGraphicsParticles(); QUrl source() const; void setSource(const QUrl &); @@ -200,30 +200,30 @@ public: bool emitting() const; void setEmitting(bool); - QFxParticleMotion *motion() const; - void setMotion(QFxParticleMotion *); + QmlGraphicsParticleMotion *motion() const; + void setMotion(QmlGraphicsParticleMotion *); void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); protected: virtual void componentComplete(); - QFxParticles(QFxParticlesPrivate &dd, QFxItem *parent); + QmlGraphicsParticles(QmlGraphicsParticlesPrivate &dd, QmlGraphicsItem *parent); private Q_SLOTS: void imageLoaded(); private: - Q_DISABLE_COPY(QFxParticles) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxParticles) + Q_DISABLE_COPY(QmlGraphicsParticles) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsParticles) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxParticleMotion) -QML_DECLARE_TYPE(QFxParticleMotionLinear) -QML_DECLARE_TYPE(QFxParticleMotionGravity) -QML_DECLARE_TYPE(QFxParticleMotionWander) -QML_DECLARE_TYPE(QFxParticles) +QML_DECLARE_TYPE(QmlGraphicsParticleMotion) +QML_DECLARE_TYPE(QmlGraphicsParticleMotionLinear) +QML_DECLARE_TYPE(QmlGraphicsParticleMotionGravity) +QML_DECLARE_TYPE(QmlGraphicsParticleMotionWander) +QML_DECLARE_TYPE(QmlGraphicsParticles) QT_END_HEADER diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp index 8d4a8b8..3908520 100644 --- a/src/declarative/fx/qfxanchors.cpp +++ b/src/declarative/fx/qfxanchors.cpp @@ -47,36 +47,36 @@ QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Anchors,QFxAnchors) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Anchors,QmlGraphicsAnchors) //TODO: should we cache relationships, so we don't have to check each time (parent-child or sibling)? //TODO: support non-parent, non-sibling (need to find lowest common ancestor) //### const item? //local position -static qreal position(QFxItem *item, QFxAnchorLine::AnchorLine anchorLine) +static qreal position(QmlGraphicsItem *item, QmlGraphicsAnchorLine::AnchorLine anchorLine) { qreal ret = 0.0; switch(anchorLine) { - case QFxAnchorLine::Left: + case QmlGraphicsAnchorLine::Left: ret = item->x(); break; - case QFxAnchorLine::Right: + case QmlGraphicsAnchorLine::Right: ret = item->x() + item->width(); break; - case QFxAnchorLine::Top: + case QmlGraphicsAnchorLine::Top: ret = item->y(); break; - case QFxAnchorLine::Bottom: + case QmlGraphicsAnchorLine::Bottom: ret = item->y() + item->height(); break; - case QFxAnchorLine::HCenter: + case QmlGraphicsAnchorLine::HCenter: ret = item->x() + item->width()/2; break; - case QFxAnchorLine::VCenter: + case QmlGraphicsAnchorLine::VCenter: ret = item->y() + item->height()/2; break; - case QFxAnchorLine::Baseline: + case QmlGraphicsAnchorLine::Baseline: ret = item->y() + item->baselineOffset(); break; default: @@ -87,29 +87,29 @@ static qreal position(QFxItem *item, QFxAnchorLine::AnchorLine anchorLine) } //position when origin is 0,0 -static qreal adjustedPosition(QFxItem *item, QFxAnchorLine::AnchorLine anchorLine) +static qreal adjustedPosition(QmlGraphicsItem *item, QmlGraphicsAnchorLine::AnchorLine anchorLine) { int ret = 0; switch(anchorLine) { - case QFxAnchorLine::Left: + case QmlGraphicsAnchorLine::Left: ret = 0; break; - case QFxAnchorLine::Right: + case QmlGraphicsAnchorLine::Right: ret = item->width(); break; - case QFxAnchorLine::Top: + case QmlGraphicsAnchorLine::Top: ret = 0; break; - case QFxAnchorLine::Bottom: + case QmlGraphicsAnchorLine::Bottom: ret = item->height(); break; - case QFxAnchorLine::HCenter: + case QmlGraphicsAnchorLine::HCenter: ret = item->width()/2; break; - case QFxAnchorLine::VCenter: + case QmlGraphicsAnchorLine::VCenter: ret = item->height()/2; break; - case QFxAnchorLine::Baseline: + case QmlGraphicsAnchorLine::Baseline: ret = item->baselineOffset(); break; default: @@ -121,21 +121,21 @@ static qreal adjustedPosition(QFxItem *item, QFxAnchorLine::AnchorLine anchorLin /*! \internal - \class QFxAnchors + \class QmlGraphicsAnchors \ingroup group_layouts - \brief The QFxAnchors class provides a way to lay out items relative to other items. + \brief The QmlGraphicsAnchors class provides a way to lay out items relative to other items. \warning Currently, only anchoring to siblings or parent is supported. */ -QFxAnchors::QFxAnchors(QObject *parent) - : QObject(*new QFxAnchorsPrivate(), parent) +QmlGraphicsAnchors::QmlGraphicsAnchors(QObject *parent) + : QObject(*new QmlGraphicsAnchorsPrivate(), parent) { } -QFxAnchors::~QFxAnchors() +QmlGraphicsAnchors::~QmlGraphicsAnchors() { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); d->remDepend(d->fill); d->remDepend(d->centerIn); d->remDepend(d->left.item); @@ -147,7 +147,7 @@ QFxAnchors::~QFxAnchors() d->remDepend(d->baseline.item); } -void QFxAnchorsPrivate::fillChanged() +void QmlGraphicsAnchorsPrivate::fillChanged() { if (!fill || !isItemComplete()) return; @@ -161,7 +161,7 @@ void QFxAnchorsPrivate::fillChanged() setItemHeight(fill->height()-topMargin-bottomMargin); } -void QFxAnchorsPrivate::centerInChanged() +void QmlGraphicsAnchorsPrivate::centerInChanged() { if (!centerIn || fill || !isItemComplete()) return; @@ -179,7 +179,7 @@ void QFxAnchorsPrivate::centerInChanged() } } -void QFxAnchorsPrivate::clearItem(QFxItem *item) +void QmlGraphicsAnchorsPrivate::clearItem(QmlGraphicsItem *item) { if (!item) return; @@ -189,107 +189,107 @@ void QFxAnchorsPrivate::clearItem(QFxItem *item) centerIn = 0; if (left.item == item) { left.item = 0; - usedAnchors &= ~QFxAnchors::HasLeftAnchor; + usedAnchors &= ~QmlGraphicsAnchors::HasLeftAnchor; } if (right.item == item) { right.item = 0; - usedAnchors &= ~QFxAnchors::HasRightAnchor; + usedAnchors &= ~QmlGraphicsAnchors::HasRightAnchor; } if (top.item == item) { top.item = 0; - usedAnchors &= ~QFxAnchors::HasTopAnchor; + usedAnchors &= ~QmlGraphicsAnchors::HasTopAnchor; } if (bottom.item == item) { bottom.item = 0; - usedAnchors &= ~QFxAnchors::HasBottomAnchor; + usedAnchors &= ~QmlGraphicsAnchors::HasBottomAnchor; } if (vCenter.item == item) { vCenter.item = 0; - usedAnchors &= ~QFxAnchors::HasVCenterAnchor; + usedAnchors &= ~QmlGraphicsAnchors::HasVCenterAnchor; } if (hCenter.item == item) { hCenter.item = 0; - usedAnchors &= ~QFxAnchors::HasHCenterAnchor; + usedAnchors &= ~QmlGraphicsAnchors::HasHCenterAnchor; } if (baseline.item == item) { baseline.item = 0; - usedAnchors &= ~QFxAnchors::HasBaselineAnchor; + usedAnchors &= ~QmlGraphicsAnchors::HasBaselineAnchor; } } -void QFxAnchorsPrivate::addDepend(QFxItem *item) +void QmlGraphicsAnchorsPrivate::addDepend(QmlGraphicsItem *item) { - Q_Q(QFxAnchors); + Q_Q(QmlGraphicsAnchors); if (!item) return; - QFxItemPrivate *p = - static_cast(QGraphicsItemPrivate::get(item)); + QmlGraphicsItemPrivate *p = + static_cast(QGraphicsItemPrivate::get(item)); p->dependantAnchors.append(q); } -void QFxAnchorsPrivate::remDepend(QFxItem *item) +void QmlGraphicsAnchorsPrivate::remDepend(QmlGraphicsItem *item) { - Q_Q(QFxAnchors); + Q_Q(QmlGraphicsAnchors); if (!item) return; - QFxItemPrivate *p = - static_cast(QGraphicsItemPrivate::get(item)); + QmlGraphicsItemPrivate *p = + static_cast(QGraphicsItemPrivate::get(item)); p->dependantAnchors.removeOne(q); } -bool QFxAnchorsPrivate::isItemComplete() const +bool QmlGraphicsAnchorsPrivate::isItemComplete() const { return componentComplete; } -void QFxAnchors::classBegin() +void QmlGraphicsAnchors::classBegin() { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); d->componentComplete = false; } -void QFxAnchors::componentComplete() +void QmlGraphicsAnchors::componentComplete() { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); d->componentComplete = true; } -void QFxAnchorsPrivate::setItemHeight(qreal v) +void QmlGraphicsAnchorsPrivate::setItemHeight(qreal v) { updatingMe = true; item->setHeight(v); updatingMe = false; } -void QFxAnchorsPrivate::setItemWidth(qreal v) +void QmlGraphicsAnchorsPrivate::setItemWidth(qreal v) { updatingMe = true; item->setWidth(v); updatingMe = false; } -void QFxAnchorsPrivate::setItemX(qreal v) +void QmlGraphicsAnchorsPrivate::setItemX(qreal v) { updatingMe = true; item->setX(v); updatingMe = false; } -void QFxAnchorsPrivate::setItemY(qreal v) +void QmlGraphicsAnchorsPrivate::setItemY(qreal v) { updatingMe = true; item->setY(v); updatingMe = false; } -void QFxAnchorsPrivate::setItemPos(const QPointF &v) +void QmlGraphicsAnchorsPrivate::setItemPos(const QPointF &v) { updatingMe = true; item->setPos(v); updatingMe = false; } -void QFxAnchorsPrivate::updateMe() +void QmlGraphicsAnchorsPrivate::updateMe() { if (updatingMe) { updatingMe = false; @@ -302,7 +302,7 @@ void QFxAnchorsPrivate::updateMe() updateVerticalAnchors(); } -void QFxAnchorsPrivate::updateOnComplete() +void QmlGraphicsAnchorsPrivate::updateOnComplete() { fillChanged(); centerInChanged(); @@ -310,7 +310,7 @@ void QFxAnchorsPrivate::updateOnComplete() updateVerticalAnchors(); } -void QFxAnchorsPrivate::update(QFxItem *, const QRectF &newG, const QRectF &oldG) +void QmlGraphicsAnchorsPrivate::update(QmlGraphicsItem *, const QRectF &newG, const QRectF &oldG) { fillChanged(); centerInChanged(); @@ -321,15 +321,15 @@ void QFxAnchorsPrivate::update(QFxItem *, const QRectF &newG, const QRectF &oldG updateVerticalAnchors(); } -QFxItem *QFxAnchors::fill() const +QmlGraphicsItem *QmlGraphicsAnchors::fill() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->fill; } -void QFxAnchors::setFill(QFxItem *f) +void QmlGraphicsAnchors::setFill(QmlGraphicsItem *f) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (!f) { d->remDepend(d->fill); d->fill = f; @@ -346,15 +346,15 @@ void QFxAnchors::setFill(QFxItem *f) d->fillChanged(); } -QFxItem *QFxAnchors::centerIn() const +QmlGraphicsItem *QmlGraphicsAnchors::centerIn() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->centerIn; } -void QFxAnchors::setCenterIn(QFxItem* c) +void QmlGraphicsAnchors::setCenterIn(QmlGraphicsItem* c) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (!c) { d->remDepend(d->centerIn); d->centerIn = c; @@ -372,11 +372,11 @@ void QFxAnchors::setCenterIn(QFxItem* c) d->centerInChanged(); } -bool QFxAnchorsPrivate::calcStretch(const QFxAnchorLine &edge1, - const QFxAnchorLine &edge2, +bool QmlGraphicsAnchorsPrivate::calcStretch(const QmlGraphicsAnchorLine &edge1, + const QmlGraphicsAnchorLine &edge2, int offset1, int offset2, - QFxAnchorLine::AnchorLine line, + QmlGraphicsAnchorLine::AnchorLine line, int &stretch) { bool edge1IsParent = (edge1.item == item->parentItem()); @@ -401,21 +401,21 @@ bool QFxAnchorsPrivate::calcStretch(const QFxAnchorLine &edge1, return invalid; } -void QFxAnchorsPrivate::updateVerticalAnchors() +void QmlGraphicsAnchorsPrivate::updateVerticalAnchors() { if (fill || centerIn || !isItemComplete()) return; if (updatingVerticalAnchor < 2) { ++updatingVerticalAnchor; - if (usedAnchors & QFxAnchors::HasTopAnchor) { + if (usedAnchors & QmlGraphicsAnchors::HasTopAnchor) { //Handle stretching bool invalid = true; int height = 0; - if (usedAnchors & QFxAnchors::HasBottomAnchor) { - invalid = calcStretch(top, bottom, topMargin, -bottomMargin, QFxAnchorLine::Top, height); - } else if (usedAnchors & QFxAnchors::HasVCenterAnchor) { - invalid = calcStretch(top, vCenter, topMargin, vCenterOffset, QFxAnchorLine::Top, height); + if (usedAnchors & QmlGraphicsAnchors::HasBottomAnchor) { + invalid = calcStretch(top, bottom, topMargin, -bottomMargin, QmlGraphicsAnchorLine::Top, height); + } else if (usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor) { + invalid = calcStretch(top, vCenter, topMargin, vCenterOffset, QmlGraphicsAnchorLine::Top, height); height *= 2; } if (!invalid) @@ -427,12 +427,12 @@ void QFxAnchorsPrivate::updateVerticalAnchors() } else if (top.item->parentItem() == item->parentItem()) { setItemY(position(top.item, top.anchorLine) + topMargin); } - } else if (usedAnchors & QFxAnchors::HasBottomAnchor) { + } else if (usedAnchors & QmlGraphicsAnchors::HasBottomAnchor) { //Handle stretching (top + bottom case is handled above) - if (usedAnchors & QFxAnchors::HasVCenterAnchor) { + if (usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor) { int height = 0; bool invalid = calcStretch(vCenter, bottom, vCenterOffset, -bottomMargin, - QFxAnchorLine::Top, height); + QmlGraphicsAnchorLine::Top, height); if (!invalid) setItemHeight(height*2); } @@ -443,7 +443,7 @@ void QFxAnchorsPrivate::updateVerticalAnchors() } else if (bottom.item->parentItem() == item->parentItem()) { setItemY(position(bottom.item, bottom.anchorLine) - item->height() - bottomMargin); } - } else if (usedAnchors & QFxAnchors::HasVCenterAnchor) { + } else if (usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor) { //(stetching handled above) //Handle vCenter @@ -453,7 +453,7 @@ void QFxAnchorsPrivate::updateVerticalAnchors() } else if (vCenter.item->parentItem() == item->parentItem()) { setItemY(position(vCenter.item, vCenter.anchorLine) - item->height()/2 + vCenterOffset); } - } else if (usedAnchors & QFxAnchors::HasBaselineAnchor) { + } else if (usedAnchors & QmlGraphicsAnchors::HasBaselineAnchor) { //Handle baseline if (baseline.item->parentItem() == item->parentItem()) { setItemY(position(baseline.item, baseline.anchorLine) - item->baselineOffset() + baselineOffset); @@ -462,11 +462,11 @@ void QFxAnchorsPrivate::updateVerticalAnchors() --updatingVerticalAnchor; } else { // ### Make this certain :) - qmlInfo(QFxAnchors::tr("Possible anchor loop detected on vertical anchor."), item); + qmlInfo(QmlGraphicsAnchors::tr("Possible anchor loop detected on vertical anchor."), item); } } -void QFxAnchorsPrivate::updateHorizontalAnchors() +void QmlGraphicsAnchorsPrivate::updateHorizontalAnchors() { if (fill || centerIn || !isItemComplete()) return; @@ -474,14 +474,14 @@ void QFxAnchorsPrivate::updateHorizontalAnchors() if (updatingHorizontalAnchor < 2) { ++updatingHorizontalAnchor; - if (usedAnchors & QFxAnchors::HasLeftAnchor) { + if (usedAnchors & QmlGraphicsAnchors::HasLeftAnchor) { //Handle stretching bool invalid = true; int width = 0; - if (usedAnchors & QFxAnchors::HasRightAnchor) { - invalid = calcStretch(left, right, leftMargin, -rightMargin, QFxAnchorLine::Left, width); - } else if (usedAnchors & QFxAnchors::HasHCenterAnchor) { - invalid = calcStretch(left, hCenter, leftMargin, hCenterOffset, QFxAnchorLine::Left, width); + if (usedAnchors & QmlGraphicsAnchors::HasRightAnchor) { + invalid = calcStretch(left, right, leftMargin, -rightMargin, QmlGraphicsAnchorLine::Left, width); + } else if (usedAnchors & QmlGraphicsAnchors::HasHCenterAnchor) { + invalid = calcStretch(left, hCenter, leftMargin, hCenterOffset, QmlGraphicsAnchorLine::Left, width); width *= 2; } if (!invalid) @@ -493,12 +493,12 @@ void QFxAnchorsPrivate::updateHorizontalAnchors() } else if (left.item->parentItem() == item->parentItem()) { setItemX(position(left.item, left.anchorLine) + leftMargin); } - } else if (usedAnchors & QFxAnchors::HasRightAnchor) { + } else if (usedAnchors & QmlGraphicsAnchors::HasRightAnchor) { //Handle stretching (left + right case is handled in updateLeftAnchor) - if (usedAnchors & QFxAnchors::HasHCenterAnchor) { + if (usedAnchors & QmlGraphicsAnchors::HasHCenterAnchor) { int width = 0; bool invalid = calcStretch(hCenter, right, hCenterOffset, -rightMargin, - QFxAnchorLine::Left, width); + QmlGraphicsAnchorLine::Left, width); if (!invalid) setItemWidth(width*2); } @@ -509,7 +509,7 @@ void QFxAnchorsPrivate::updateHorizontalAnchors() } else if (right.item->parentItem() == item->parentItem()) { setItemX(position(right.item, right.anchorLine) - item->width() - rightMargin); } - } else if (usedAnchors & QFxAnchors::HasHCenterAnchor) { + } else if (usedAnchors & QmlGraphicsAnchors::HasHCenterAnchor) { //Handle hCenter if (hCenter.item == item->parentItem()) { setItemX(adjustedPosition(hCenter.item, hCenter.anchorLine) - item->width()/2 + hCenterOffset); @@ -521,19 +521,19 @@ void QFxAnchorsPrivate::updateHorizontalAnchors() --updatingHorizontalAnchor; } else { // ### Make this certain :) - qmlInfo(QFxAnchors::tr("Possible anchor loop detected on horizontal anchor."), item); + qmlInfo(QmlGraphicsAnchors::tr("Possible anchor loop detected on horizontal anchor."), item); } } -QFxAnchorLine QFxAnchors::top() const +QmlGraphicsAnchorLine QmlGraphicsAnchors::top() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->top; } -void QFxAnchors::setTop(const QFxAnchorLine &edge) +void QmlGraphicsAnchors::setTop(const QmlGraphicsAnchorLine &edge) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (!d->checkVAnchorValid(edge)) return; @@ -550,24 +550,24 @@ void QFxAnchors::setTop(const QFxAnchorLine &edge) d->updateVerticalAnchors(); } -void QFxAnchors::resetTop() +void QmlGraphicsAnchors::resetTop() { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); d->usedAnchors &= ~HasTopAnchor; d->remDepend(d->top.item); - d->top = QFxAnchorLine(); + d->top = QmlGraphicsAnchorLine(); d->updateVerticalAnchors(); } -QFxAnchorLine QFxAnchors::bottom() const +QmlGraphicsAnchorLine QmlGraphicsAnchors::bottom() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->bottom; } -void QFxAnchors::setBottom(const QFxAnchorLine &edge) +void QmlGraphicsAnchors::setBottom(const QmlGraphicsAnchorLine &edge) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (!d->checkVAnchorValid(edge)) return; @@ -584,24 +584,24 @@ void QFxAnchors::setBottom(const QFxAnchorLine &edge) d->updateVerticalAnchors(); } -void QFxAnchors::resetBottom() +void QmlGraphicsAnchors::resetBottom() { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); d->usedAnchors &= ~HasBottomAnchor; d->remDepend(d->bottom.item); - d->bottom = QFxAnchorLine(); + d->bottom = QmlGraphicsAnchorLine(); d->updateVerticalAnchors(); } -QFxAnchorLine QFxAnchors::verticalCenter() const +QmlGraphicsAnchorLine QmlGraphicsAnchors::verticalCenter() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->vCenter; } -void QFxAnchors::setVerticalCenter(const QFxAnchorLine &edge) +void QmlGraphicsAnchors::setVerticalCenter(const QmlGraphicsAnchorLine &edge) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (!d->checkVAnchorValid(edge)) return; @@ -618,24 +618,24 @@ void QFxAnchors::setVerticalCenter(const QFxAnchorLine &edge) d->updateVerticalAnchors(); } -void QFxAnchors::resetVerticalCenter() +void QmlGraphicsAnchors::resetVerticalCenter() { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); d->usedAnchors &= ~HasVCenterAnchor; d->remDepend(d->vCenter.item); - d->vCenter = QFxAnchorLine(); + d->vCenter = QmlGraphicsAnchorLine(); d->updateVerticalAnchors(); } -QFxAnchorLine QFxAnchors::baseline() const +QmlGraphicsAnchorLine QmlGraphicsAnchors::baseline() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->baseline; } -void QFxAnchors::setBaseline(const QFxAnchorLine &edge) +void QmlGraphicsAnchors::setBaseline(const QmlGraphicsAnchorLine &edge) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (!d->checkVAnchorValid(edge)) return; @@ -652,24 +652,24 @@ void QFxAnchors::setBaseline(const QFxAnchorLine &edge) d->updateVerticalAnchors(); } -void QFxAnchors::resetBaseline() +void QmlGraphicsAnchors::resetBaseline() { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); d->usedAnchors &= ~HasBaselineAnchor; d->remDepend(d->baseline.item); - d->baseline = QFxAnchorLine(); + d->baseline = QmlGraphicsAnchorLine(); d->updateVerticalAnchors(); } -QFxAnchorLine QFxAnchors::left() const +QmlGraphicsAnchorLine QmlGraphicsAnchors::left() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->left; } -void QFxAnchors::setLeft(const QFxAnchorLine &edge) +void QmlGraphicsAnchors::setLeft(const QmlGraphicsAnchorLine &edge) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (!d->checkHAnchorValid(edge)) return; @@ -686,24 +686,24 @@ void QFxAnchors::setLeft(const QFxAnchorLine &edge) d->updateHorizontalAnchors(); } -void QFxAnchors::resetLeft() +void QmlGraphicsAnchors::resetLeft() { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); d->usedAnchors &= ~HasLeftAnchor; d->remDepend(d->left.item); - d->left = QFxAnchorLine(); + d->left = QmlGraphicsAnchorLine(); d->updateHorizontalAnchors(); } -QFxAnchorLine QFxAnchors::right() const +QmlGraphicsAnchorLine QmlGraphicsAnchors::right() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->right; } -void QFxAnchors::setRight(const QFxAnchorLine &edge) +void QmlGraphicsAnchors::setRight(const QmlGraphicsAnchorLine &edge) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (!d->checkHAnchorValid(edge)) return; @@ -721,24 +721,24 @@ void QFxAnchors::setRight(const QFxAnchorLine &edge) d->updateHorizontalAnchors(); } -void QFxAnchors::resetRight() +void QmlGraphicsAnchors::resetRight() { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); d->usedAnchors &= ~HasRightAnchor; d->remDepend(d->right.item); - d->right = QFxAnchorLine(); + d->right = QmlGraphicsAnchorLine(); d->updateHorizontalAnchors(); } -QFxAnchorLine QFxAnchors::horizontalCenter() const +QmlGraphicsAnchorLine QmlGraphicsAnchors::horizontalCenter() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->hCenter; } -void QFxAnchors::setHorizontalCenter(const QFxAnchorLine &edge) +void QmlGraphicsAnchors::setHorizontalCenter(const QmlGraphicsAnchorLine &edge) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (!d->checkHAnchorValid(edge)) return; @@ -755,24 +755,24 @@ void QFxAnchors::setHorizontalCenter(const QFxAnchorLine &edge) d->updateHorizontalAnchors(); } -void QFxAnchors::resetHorizontalCenter() +void QmlGraphicsAnchors::resetHorizontalCenter() { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); d->usedAnchors &= ~HasHCenterAnchor; d->remDepend(d->hCenter.item); - d->hCenter = QFxAnchorLine(); + d->hCenter = QmlGraphicsAnchorLine(); d->updateHorizontalAnchors(); } -qreal QFxAnchors::leftMargin() const +qreal QmlGraphicsAnchors::leftMargin() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->leftMargin; } -void QFxAnchors::setLeftMargin(qreal offset) +void QmlGraphicsAnchors::setLeftMargin(qreal offset) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (d->leftMargin == offset) return; d->leftMargin = offset; @@ -780,15 +780,15 @@ void QFxAnchors::setLeftMargin(qreal offset) emit leftMarginChanged(); } -qreal QFxAnchors::rightMargin() const +qreal QmlGraphicsAnchors::rightMargin() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->rightMargin; } -void QFxAnchors::setRightMargin(qreal offset) +void QmlGraphicsAnchors::setRightMargin(qreal offset) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (d->rightMargin == offset) return; d->rightMargin = offset; @@ -796,15 +796,15 @@ void QFxAnchors::setRightMargin(qreal offset) emit rightMarginChanged(); } -qreal QFxAnchors::horizontalCenterOffset() const +qreal QmlGraphicsAnchors::horizontalCenterOffset() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->hCenterOffset; } -void QFxAnchors::setHorizontalCenterOffset(qreal offset) +void QmlGraphicsAnchors::setHorizontalCenterOffset(qreal offset) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (d->hCenterOffset == offset) return; d->hCenterOffset = offset; @@ -812,15 +812,15 @@ void QFxAnchors::setHorizontalCenterOffset(qreal offset) emit horizontalCenterOffsetChanged(); } -qreal QFxAnchors::topMargin() const +qreal QmlGraphicsAnchors::topMargin() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->topMargin; } -void QFxAnchors::setTopMargin(qreal offset) +void QmlGraphicsAnchors::setTopMargin(qreal offset) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (d->topMargin == offset) return; d->topMargin = offset; @@ -828,15 +828,15 @@ void QFxAnchors::setTopMargin(qreal offset) emit topMarginChanged(); } -qreal QFxAnchors::bottomMargin() const +qreal QmlGraphicsAnchors::bottomMargin() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->bottomMargin; } -void QFxAnchors::setBottomMargin(qreal offset) +void QmlGraphicsAnchors::setBottomMargin(qreal offset) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (d->bottomMargin == offset) return; d->bottomMargin = offset; @@ -844,15 +844,15 @@ void QFxAnchors::setBottomMargin(qreal offset) emit bottomMarginChanged(); } -qreal QFxAnchors::verticalCenterOffset() const +qreal QmlGraphicsAnchors::verticalCenterOffset() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->vCenterOffset; } -void QFxAnchors::setVerticalCenterOffset(qreal offset) +void QmlGraphicsAnchors::setVerticalCenterOffset(qreal offset) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (d->vCenterOffset == offset) return; d->vCenterOffset = offset; @@ -860,15 +860,15 @@ void QFxAnchors::setVerticalCenterOffset(qreal offset) emit verticalCenterOffsetChanged(); } -qreal QFxAnchors::baselineOffset() const +qreal QmlGraphicsAnchors::baselineOffset() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->baselineOffset; } -void QFxAnchors::setBaselineOffset(qreal offset) +void QmlGraphicsAnchors::setBaselineOffset(qreal offset) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); if (d->baselineOffset == offset) return; d->baselineOffset = offset; @@ -876,80 +876,80 @@ void QFxAnchors::setBaselineOffset(qreal offset) emit baselineOffsetChanged(); } -QFxAnchors::UsedAnchors QFxAnchors::usedAnchors() const +QmlGraphicsAnchors::UsedAnchors QmlGraphicsAnchors::usedAnchors() const { - Q_D(const QFxAnchors); + Q_D(const QmlGraphicsAnchors); return d->usedAnchors; } -void QFxAnchors::setItem(QFxItem *item) +void QmlGraphicsAnchors::setItem(QmlGraphicsItem *item) { - Q_D(QFxAnchors); + Q_D(QmlGraphicsAnchors); d->item = item; } -bool QFxAnchorsPrivate::checkHValid() const +bool QmlGraphicsAnchorsPrivate::checkHValid() const { - if (usedAnchors & QFxAnchors::HasLeftAnchor && - usedAnchors & QFxAnchors::HasRightAnchor && - usedAnchors & QFxAnchors::HasHCenterAnchor) { - qmlInfo(QFxAnchors::tr("Can't specify left, right, and hcenter anchors."), item); + if (usedAnchors & QmlGraphicsAnchors::HasLeftAnchor && + usedAnchors & QmlGraphicsAnchors::HasRightAnchor && + usedAnchors & QmlGraphicsAnchors::HasHCenterAnchor) { + qmlInfo(QmlGraphicsAnchors::tr("Can't specify left, right, and hcenter anchors."), item); return false; } return true; } -bool QFxAnchorsPrivate::checkHAnchorValid(QFxAnchorLine anchor) const +bool QmlGraphicsAnchorsPrivate::checkHAnchorValid(QmlGraphicsAnchorLine anchor) const { if (!anchor.item) { - qmlInfo(QFxAnchors::tr("Can't anchor to a null item."), item); + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor to a null item."), item); return false; - } else if (anchor.anchorLine & QFxAnchorLine::Vertical_Mask) { - qmlInfo(QFxAnchors::tr("Can't anchor a horizontal edge to a vertical edge."), item); + } else if (anchor.anchorLine & QmlGraphicsAnchorLine::Vertical_Mask) { + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor a horizontal edge to a vertical edge."), item); return false; } else if (anchor.item != item->parentItem() && anchor.item->parentItem() != item->parentItem()){ - qmlInfo(QFxAnchors::tr("Can't anchor to an item that isn't a parent or sibling."), item); + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor to an item that isn't a parent or sibling."), item); return false; } else if (anchor.item == item) { - qmlInfo(QFxAnchors::tr("Can't anchor item to self."), item); + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor item to self."), item); return false; } return true; } -bool QFxAnchorsPrivate::checkVValid() const +bool QmlGraphicsAnchorsPrivate::checkVValid() const { - if (usedAnchors & QFxAnchors::HasTopAnchor && - usedAnchors & QFxAnchors::HasBottomAnchor && - usedAnchors & QFxAnchors::HasVCenterAnchor) { - qmlInfo(QFxAnchors::tr("Can't specify top, bottom, and vcenter anchors."), item); + if (usedAnchors & QmlGraphicsAnchors::HasTopAnchor && + usedAnchors & QmlGraphicsAnchors::HasBottomAnchor && + usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor) { + qmlInfo(QmlGraphicsAnchors::tr("Can't specify top, bottom, and vcenter anchors."), item); return false; - } else if (usedAnchors & QFxAnchors::HasBaselineAnchor && - (usedAnchors & QFxAnchors::HasTopAnchor || - usedAnchors & QFxAnchors::HasBottomAnchor || - usedAnchors & QFxAnchors::HasVCenterAnchor)) { - qmlInfo(QFxAnchors::tr("Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors."), item); + } else if (usedAnchors & QmlGraphicsAnchors::HasBaselineAnchor && + (usedAnchors & QmlGraphicsAnchors::HasTopAnchor || + usedAnchors & QmlGraphicsAnchors::HasBottomAnchor || + usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor)) { + qmlInfo(QmlGraphicsAnchors::tr("Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors."), item); return false; } return true; } -bool QFxAnchorsPrivate::checkVAnchorValid(QFxAnchorLine anchor) const +bool QmlGraphicsAnchorsPrivate::checkVAnchorValid(QmlGraphicsAnchorLine anchor) const { if (!anchor.item) { - qmlInfo(QFxAnchors::tr("Can't anchor to a null item."), item); + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor to a null item."), item); return false; - } else if (anchor.anchorLine & QFxAnchorLine::Horizontal_Mask) { - qmlInfo(QFxAnchors::tr("Can't anchor a vertical edge to a horizontal edge."), item); + } else if (anchor.anchorLine & QmlGraphicsAnchorLine::Horizontal_Mask) { + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor a vertical edge to a horizontal edge."), item); return false; } else if (anchor.item != item->parentItem() && anchor.item->parentItem() != item->parentItem()){ - qmlInfo(QFxAnchors::tr("Can't anchor to an item that isn't a parent or sibling."), item); + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor to an item that isn't a parent or sibling."), item); return false; } else if (anchor.item == item){ - qmlInfo(QFxAnchors::tr("Can't anchor item to self."), item); + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor item to self."), item); return false; } diff --git a/src/declarative/fx/qfxanchors.h b/src/declarative/fx/qfxanchors.h index 3dd64c7..9e2bac6 100644 --- a/src/declarative/fx/qfxanchors.h +++ b/src/declarative/fx/qfxanchors.h @@ -53,19 +53,19 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxAnchorsPrivate; -class QFxAnchorLine; -class Q_DECLARATIVE_EXPORT QFxAnchors : public QObject +class QmlGraphicsAnchorsPrivate; +class QmlGraphicsAnchorLine; +class Q_DECLARATIVE_EXPORT QmlGraphicsAnchors : public QObject { Q_OBJECT - Q_PROPERTY(QFxAnchorLine left READ left WRITE setLeft RESET resetLeft) - Q_PROPERTY(QFxAnchorLine right READ right WRITE setRight RESET resetRight) - Q_PROPERTY(QFxAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter) - Q_PROPERTY(QFxAnchorLine top READ top WRITE setTop RESET resetTop) - Q_PROPERTY(QFxAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom) - Q_PROPERTY(QFxAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter) - Q_PROPERTY(QFxAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline) + Q_PROPERTY(QmlGraphicsAnchorLine left READ left WRITE setLeft RESET resetLeft) + Q_PROPERTY(QmlGraphicsAnchorLine right READ right WRITE setRight RESET resetRight) + Q_PROPERTY(QmlGraphicsAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter) + Q_PROPERTY(QmlGraphicsAnchorLine top READ top WRITE setTop RESET resetTop) + Q_PROPERTY(QmlGraphicsAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom) + Q_PROPERTY(QmlGraphicsAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter) + Q_PROPERTY(QmlGraphicsAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline) Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged) Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged()) @@ -73,12 +73,12 @@ class Q_DECLARATIVE_EXPORT QFxAnchors : public QObject Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged()) Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged()) - Q_PROPERTY(QFxItem *fill READ fill WRITE setFill) - Q_PROPERTY(QFxItem *centerIn READ centerIn WRITE setCenterIn) + Q_PROPERTY(QmlGraphicsItem *fill READ fill WRITE setFill) + Q_PROPERTY(QmlGraphicsItem *centerIn READ centerIn WRITE setCenterIn) public: - QFxAnchors(QObject *parent=0); - virtual ~QFxAnchors(); + QmlGraphicsAnchors(QObject *parent=0); + virtual ~QmlGraphicsAnchors(); enum UsedAnchor { HasLeftAnchor = 0x01, @@ -93,32 +93,32 @@ public: }; Q_DECLARE_FLAGS(UsedAnchors, UsedAnchor) - QFxAnchorLine left() const; - void setLeft(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine left() const; + void setLeft(const QmlGraphicsAnchorLine &edge); void resetLeft(); - QFxAnchorLine right() const; - void setRight(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine right() const; + void setRight(const QmlGraphicsAnchorLine &edge); void resetRight(); - QFxAnchorLine horizontalCenter() const; - void setHorizontalCenter(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine horizontalCenter() const; + void setHorizontalCenter(const QmlGraphicsAnchorLine &edge); void resetHorizontalCenter(); - QFxAnchorLine top() const; - void setTop(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine top() const; + void setTop(const QmlGraphicsAnchorLine &edge); void resetTop(); - QFxAnchorLine bottom() const; - void setBottom(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine bottom() const; + void setBottom(const QmlGraphicsAnchorLine &edge); void resetBottom(); - QFxAnchorLine verticalCenter() const; - void setVerticalCenter(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine verticalCenter() const; + void setVerticalCenter(const QmlGraphicsAnchorLine &edge); void resetVerticalCenter(); - QFxAnchorLine baseline() const; - void setBaseline(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine baseline() const; + void setBaseline(const QmlGraphicsAnchorLine &edge); void resetBaseline(); qreal leftMargin() const; @@ -142,15 +142,15 @@ public: qreal baselineOffset() const; void setBaselineOffset(qreal); - QFxItem *fill() const; - void setFill(QFxItem *); + QmlGraphicsItem *fill() const; + void setFill(QmlGraphicsItem *); - QFxItem *centerIn() const; - void setCenterIn(QFxItem *); + QmlGraphicsItem *centerIn() const; + void setCenterIn(QmlGraphicsItem *); UsedAnchors usedAnchors() const; - void setItem(QFxItem *item); + void setItem(QmlGraphicsItem *item); void classBegin(); void componentComplete(); @@ -165,15 +165,15 @@ Q_SIGNALS: void baselineOffsetChanged(); private: - friend class QFxItem; - Q_DISABLE_COPY(QFxAnchors) - Q_DECLARE_PRIVATE(QFxAnchors) + friend class QmlGraphicsItem; + Q_DISABLE_COPY(QmlGraphicsAnchors) + Q_DECLARE_PRIVATE(QmlGraphicsAnchors) }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QFxAnchors::UsedAnchors) +Q_DECLARE_OPERATORS_FOR_FLAGS(QmlGraphicsAnchors::UsedAnchors) QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxAnchors) +QML_DECLARE_TYPE(QmlGraphicsAnchors) QT_END_HEADER diff --git a/src/declarative/fx/qfxanchors_p.h b/src/declarative/fx/qfxanchors_p.h index 9b1bc18..50f1dc4 100644 --- a/src/declarative/fx/qfxanchors_p.h +++ b/src/declarative/fx/qfxanchors_p.h @@ -58,10 +58,10 @@ QT_BEGIN_NAMESPACE -class QFxAnchorLine +class QmlGraphicsAnchorLine { public: - QFxAnchorLine() : item(0), anchorLine(Invalid) + QmlGraphicsAnchorLine() : item(0), anchorLine(Invalid) { } @@ -78,16 +78,16 @@ public: Vertical_Mask = Top | Bottom | VCenter | Baseline }; - QFxItem *item; + QmlGraphicsItem *item; AnchorLine anchorLine; }; -Q_DECLARE_METATYPE(QFxAnchorLine) +Q_DECLARE_METATYPE(QmlGraphicsAnchorLine) -class QFxAnchorsPrivate : public QObjectPrivate +class QmlGraphicsAnchorsPrivate : public QObjectPrivate { - Q_DECLARE_PUBLIC(QFxAnchors) + Q_DECLARE_PUBLIC(QmlGraphicsAnchors) public: - QFxAnchorsPrivate() + QmlGraphicsAnchorsPrivate() : updatingMe(false), updatingHorizontalAnchor(0), updatingVerticalAnchor(0), item(0), usedAnchors(0), fill(0), centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), @@ -100,10 +100,10 @@ public: { } - void clearItem(QFxItem *); + void clearItem(QmlGraphicsItem *); - void addDepend(QFxItem *); - void remDepend(QFxItem *); + void addDepend(QmlGraphicsItem *); + void remDepend(QmlGraphicsItem *); bool isItemComplete() const; bool updatingMe; @@ -118,32 +118,32 @@ public: void updateOnComplete(); void updateMe(); - void update(QFxItem *, const QRectF &, const QRectF &); + void update(QmlGraphicsItem *, const QRectF &, const QRectF &); bool checkHValid() const; bool checkVValid() const; - bool checkHAnchorValid(QFxAnchorLine anchor) const; - bool checkVAnchorValid(QFxAnchorLine anchor) const; - bool calcStretch(const QFxAnchorLine &edge1, const QFxAnchorLine &edge2, int offset1, int offset2, QFxAnchorLine::AnchorLine line, int &stretch); + bool checkHAnchorValid(QmlGraphicsAnchorLine anchor) const; + bool checkVAnchorValid(QmlGraphicsAnchorLine anchor) const; + bool calcStretch(const QmlGraphicsAnchorLine &edge1, const QmlGraphicsAnchorLine &edge2, int offset1, int offset2, QmlGraphicsAnchorLine::AnchorLine line, int &stretch); void updateHorizontalAnchors(); void updateVerticalAnchors(); void fillChanged(); void centerInChanged(); - QFxItem *item; - QFxAnchors::UsedAnchors usedAnchors; + QmlGraphicsItem *item; + QmlGraphicsAnchors::UsedAnchors usedAnchors; - QFxItem *fill; - QFxItem *centerIn; + QmlGraphicsItem *fill; + QmlGraphicsItem *centerIn; - QFxAnchorLine left; - QFxAnchorLine right; - QFxAnchorLine top; - QFxAnchorLine bottom; - QFxAnchorLine vCenter; - QFxAnchorLine hCenter; - QFxAnchorLine baseline; + QmlGraphicsAnchorLine left; + QmlGraphicsAnchorLine right; + QmlGraphicsAnchorLine top; + QmlGraphicsAnchorLine bottom; + QmlGraphicsAnchorLine vCenter; + QmlGraphicsAnchorLine hCenter; + QmlGraphicsAnchorLine baseline; qreal leftMargin; qreal rightMargin; diff --git a/src/declarative/fx/qfxborderimage.cpp b/src/declarative/fx/qfxborderimage.cpp index f1574e5..1ee2f71 100644 --- a/src/declarative/fx/qfxborderimage.cpp +++ b/src/declarative/fx/qfxborderimage.cpp @@ -48,10 +48,10 @@ QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,BorderImage,QFxBorderImage) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,BorderImage,QmlGraphicsBorderImage) /*! - \qmlclass BorderImage QFxBorderImage + \qmlclass BorderImage QmlGraphicsBorderImage \brief The BorderImage element provides an image that can be used as a border. \inherits Item @@ -64,23 +64,23 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,BorderImage,QFxBorderImage) /*! \internal - \class QFxBorderImage BorderImage - \brief The QFxBorderImage class provides an image item that you can add to a QmlView. + \class QmlGraphicsBorderImage BorderImage + \brief The QmlGraphicsBorderImage class provides an image item that you can add to a QmlView. */ -QFxBorderImage::QFxBorderImage(QFxItem *parent) - : QFxImageBase(*(new QFxBorderImagePrivate), parent) +QmlGraphicsBorderImage::QmlGraphicsBorderImage(QmlGraphicsItem *parent) + : QmlGraphicsImageBase(*(new QmlGraphicsBorderImagePrivate), parent) { setFlag(QGraphicsItem::ItemHasNoContents, false); } -QFxBorderImage::~QFxBorderImage() +QmlGraphicsBorderImage::~QmlGraphicsBorderImage() { - Q_D(QFxBorderImage); + Q_D(QmlGraphicsBorderImage); if (d->sciReply) d->sciReply->deleteLater(); if (d->sciPendingPixmapCache) - QFxPixmapCache::cancelGet(d->sciurl, this); + QmlGraphicsPixmapCache::cancelGet(d->sciurl, this); } /*! \qmlproperty enum BorderImage::status @@ -147,9 +147,9 @@ static QString toLocalFileOrQrc(const QUrl& url) } -void QFxBorderImage::setSource(const QUrl &url) +void QmlGraphicsBorderImage::setSource(const QUrl &url) { - Q_D(QFxBorderImage); + Q_D(QmlGraphicsBorderImage); //equality is fairly expensive, so we bypass for simple, common case if ((d->url.isEmpty() == url.isEmpty()) && url == d->url) return; @@ -160,11 +160,11 @@ void QFxBorderImage::setSource(const QUrl &url) } if (d->pendingPixmapCache) { - QFxPixmapCache::cancelGet(d->url, this); + QmlGraphicsPixmapCache::cancelGet(d->url, this); d->pendingPixmapCache = false; } if (d->sciPendingPixmapCache) { - QFxPixmapCache::cancelGet(d->sciurl, this); + QmlGraphicsPixmapCache::cancelGet(d->sciurl, this); d->sciPendingPixmapCache = false; } @@ -193,7 +193,7 @@ void QFxBorderImage::setSource(const QUrl &url) if (!lf.isEmpty()) { QFile file(lf); file.open(QIODevice::ReadOnly); - setGridScaledImage(QFxGridScaledImage(&file)); + setGridScaledImage(QmlGraphicsGridScaledImage(&file)); } else #endif { @@ -203,7 +203,7 @@ void QFxBorderImage::setSource(const QUrl &url) this, SLOT(sciRequestFinished())); } } else { - QNetworkReply *reply = QFxPixmapCache::get(qmlEngine(this), d->url, &d->pix); + QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->pix); if (reply) { d->pendingPixmapCache = true; connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); @@ -254,9 +254,9 @@ void QFxBorderImage::setSource(const QUrl &url) \l {BorderImage::source}{.sci file}. */ -QFxScaleGrid *QFxBorderImage::border() +QmlGraphicsScaleGrid *QmlGraphicsBorderImage::border() { - Q_D(QFxBorderImage); + Q_D(QmlGraphicsBorderImage); return d->getScaleGrid(); } @@ -272,15 +272,15 @@ QFxScaleGrid *QFxBorderImage::border() \o Round - Like Repeat, but scales the images down to ensure that the last image is not cropped. \endlist */ -QFxBorderImage::TileMode QFxBorderImage::horizontalTileMode() const +QmlGraphicsBorderImage::TileMode QmlGraphicsBorderImage::horizontalTileMode() const { - Q_D(const QFxBorderImage); + Q_D(const QmlGraphicsBorderImage); return d->horizontalTileMode; } -void QFxBorderImage::setHorizontalTileMode(TileMode t) +void QmlGraphicsBorderImage::setHorizontalTileMode(TileMode t) { - Q_D(QFxBorderImage); + Q_D(QmlGraphicsBorderImage); if (t != d->horizontalTileMode) { d->horizontalTileMode = t; emit horizontalTileModeChanged(); @@ -288,15 +288,15 @@ void QFxBorderImage::setHorizontalTileMode(TileMode t) } } -QFxBorderImage::TileMode QFxBorderImage::verticalTileMode() const +QmlGraphicsBorderImage::TileMode QmlGraphicsBorderImage::verticalTileMode() const { - Q_D(const QFxBorderImage); + Q_D(const QmlGraphicsBorderImage); return d->verticalTileMode; } -void QFxBorderImage::setVerticalTileMode(TileMode t) +void QmlGraphicsBorderImage::setVerticalTileMode(TileMode t) { - Q_D(QFxBorderImage); + Q_D(QmlGraphicsBorderImage); if (t != d->verticalTileMode) { d->verticalTileMode = t; emit verticalTileModeChanged(); @@ -304,14 +304,14 @@ void QFxBorderImage::setVerticalTileMode(TileMode t) } } -void QFxBorderImage::setGridScaledImage(const QFxGridScaledImage& sci) +void QmlGraphicsBorderImage::setGridScaledImage(const QmlGraphicsGridScaledImage& sci) { - Q_D(QFxBorderImage); + Q_D(QmlGraphicsBorderImage); if (!sci.isValid()) { d->status = Error; emit statusChanged(d->status); } else { - QFxScaleGrid *sg = border(); + QmlGraphicsScaleGrid *sg = border(); sg->setTop(sci.gridTop()); sg->setBottom(sci.gridBottom()); sg->setLeft(sci.gridLeft()); @@ -320,7 +320,7 @@ void QFxBorderImage::setGridScaledImage(const QFxGridScaledImage& sci) d->verticalTileMode = sci.verticalTileRule(); d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); - QNetworkReply *reply = QFxPixmapCache::get(qmlEngine(this), d->sciurl, &d->pix); + QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->sciurl, &d->pix); if (reply) { d->sciPendingPixmapCache = true; connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); @@ -342,16 +342,16 @@ void QFxBorderImage::setGridScaledImage(const QFxGridScaledImage& sci) } } -void QFxBorderImage::requestFinished() +void QmlGraphicsBorderImage::requestFinished() { - Q_D(QFxBorderImage); + Q_D(QmlGraphicsBorderImage); if (d->url.path().endsWith(QLatin1String(".sci"))) { d->sciPendingPixmapCache = false; - QFxPixmapCache::find(d->sciurl, &d->pix); + QmlGraphicsPixmapCache::find(d->sciurl, &d->pix); } else { d->pendingPixmapCache = false; - if (!QFxPixmapCache::find(d->url, &d->pix)) + if (!QmlGraphicsPixmapCache::find(d->url, &d->pix)) d->status = Error; } setImplicitWidth(d->pix.width()); @@ -366,25 +366,25 @@ void QFxBorderImage::requestFinished() update(); } -void QFxBorderImage::sciRequestFinished() +void QmlGraphicsBorderImage::sciRequestFinished() { - Q_D(QFxBorderImage); + Q_D(QmlGraphicsBorderImage); if (d->sciReply->error() != QNetworkReply::NoError) { d->status = Error; d->sciReply->deleteLater(); d->sciReply = 0; emit statusChanged(d->status); } else { - QFxGridScaledImage sci(d->sciReply); + QmlGraphicsGridScaledImage sci(d->sciReply); d->sciReply->deleteLater(); d->sciReply = 0; setGridScaledImage(sci); } } -void QFxBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +void QmlGraphicsBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { - Q_D(QFxBorderImage); + Q_D(QmlGraphicsBorderImage); if (d->pix.isNull()) return; @@ -402,8 +402,8 @@ void QFxBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidge } } -QFxBorderImage::QFxBorderImage(QFxBorderImagePrivate &dd, QFxItem *parent) - : QFxImageBase(dd, parent) +QmlGraphicsBorderImage::QmlGraphicsBorderImage(QmlGraphicsBorderImagePrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsImageBase(dd, parent) { setFlag(QGraphicsItem::ItemHasNoContents, false); } diff --git a/src/declarative/fx/qfxborderimage.h b/src/declarative/fx/qfxborderimage.h index 5bc1067..b6f99a3 100644 --- a/src/declarative/fx/qfxborderimage.h +++ b/src/declarative/fx/qfxborderimage.h @@ -50,23 +50,23 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxScaleGrid; -class QFxGridScaledImage; -class QFxBorderImagePrivate; -class Q_DECLARATIVE_EXPORT QFxBorderImage : public QFxImageBase +class QmlGraphicsScaleGrid; +class QmlGraphicsGridScaledImage; +class QmlGraphicsBorderImagePrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsBorderImage : public QmlGraphicsImageBase { Q_OBJECT Q_ENUMS(TileMode) - Q_PROPERTY(QFxScaleGrid *border READ border CONSTANT) + Q_PROPERTY(QmlGraphicsScaleGrid *border READ border CONSTANT) Q_PROPERTY(TileMode horizontalTileMode READ horizontalTileMode WRITE setHorizontalTileMode NOTIFY horizontalTileModeChanged) Q_PROPERTY(TileMode verticalTileMode READ verticalTileMode WRITE setVerticalTileMode NOTIFY verticalTileModeChanged) public: - QFxBorderImage(QFxItem *parent=0); - ~QFxBorderImage(); + QmlGraphicsBorderImage(QmlGraphicsItem *parent=0); + ~QmlGraphicsBorderImage(); - QFxScaleGrid *border(); + QmlGraphicsScaleGrid *border(); enum TileMode { Stretch = Qt::StretchTile, Repeat = Qt::RepeatTile, Round = Qt::RoundTile }; @@ -84,22 +84,22 @@ Q_SIGNALS: void verticalTileModeChanged(); protected: - QFxBorderImage(QFxBorderImagePrivate &dd, QFxItem *parent); + QmlGraphicsBorderImage(QmlGraphicsBorderImagePrivate &dd, QmlGraphicsItem *parent); private: - void setGridScaledImage(const QFxGridScaledImage& sci); + void setGridScaledImage(const QmlGraphicsGridScaledImage& sci); private Q_SLOTS: void requestFinished(); void sciRequestFinished(); private: - Q_DISABLE_COPY(QFxBorderImage) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxBorderImage) + Q_DISABLE_COPY(QmlGraphicsBorderImage) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsBorderImage) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxBorderImage) +QML_DECLARE_TYPE(QmlGraphicsBorderImage) QT_END_HEADER #endif // QFXBORDERIMAGE_H diff --git a/src/declarative/fx/qfxborderimage_p.h b/src/declarative/fx/qfxborderimage_p.h index aebe13f..75a638c 100644 --- a/src/declarative/fx/qfxborderimage_p.h +++ b/src/declarative/fx/qfxborderimage_p.h @@ -59,37 +59,37 @@ QT_BEGIN_NAMESPACE class QNetworkReply; -class QFxBorderImagePrivate : public QFxImageBasePrivate +class QmlGraphicsBorderImagePrivate : public QmlGraphicsImageBasePrivate { - Q_DECLARE_PUBLIC(QFxBorderImage) + Q_DECLARE_PUBLIC(QmlGraphicsBorderImage) public: - QFxBorderImagePrivate() + QmlGraphicsBorderImagePrivate() : border(0), sciReply(0), sciPendingPixmapCache(false), - horizontalTileMode(QFxBorderImage::Stretch), - verticalTileMode(QFxBorderImage::Stretch) + horizontalTileMode(QmlGraphicsBorderImage::Stretch), + verticalTileMode(QmlGraphicsBorderImage::Stretch) { } - ~QFxBorderImagePrivate() + ~QmlGraphicsBorderImagePrivate() { } - QFxScaleGrid *getScaleGrid() + QmlGraphicsScaleGrid *getScaleGrid() { - Q_Q(QFxBorderImage); + Q_Q(QmlGraphicsBorderImage); if (!border) - border = new QFxScaleGrid(q); + border = new QmlGraphicsScaleGrid(q); return border; } - QFxScaleGrid *border; + QmlGraphicsScaleGrid *border; QUrl sciurl; QNetworkReply *sciReply; bool sciPendingPixmapCache; - QFxBorderImage::TileMode horizontalTileMode; - QFxBorderImage::TileMode verticalTileMode; + QmlGraphicsBorderImage::TileMode horizontalTileMode; + QmlGraphicsBorderImage::TileMode verticalTileMode; }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxevents.cpp b/src/declarative/fx/qfxevents.cpp index 43f0dd7..fe249f9 100644 --- a/src/declarative/fx/qfxevents.cpp +++ b/src/declarative/fx/qfxevents.cpp @@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE /*! - \qmlclass KeyEvent QFxKeyEvent + \qmlclass KeyEvent QmlGraphicsKeyEvent \brief The KeyEvent object provides information about a key event. For example, the following changes the Item's state property when the Enter @@ -58,7 +58,7 @@ Item { /*! \internal - \class QFxKeyEvent + \class QmlGraphicsKeyEvent */ /*! @@ -112,7 +112,7 @@ Item { /*! - \qmlclass MouseEvent QFxMouseEvent + \qmlclass MouseEvent QmlGraphicsMouseEvent \brief The MouseEvent object provides information about a mouse event. The position of the mouse can be found via the x and y properties. @@ -121,7 +121,7 @@ Item { /*! \internal - \class QFxMouseEvent + \class QmlGraphicsMouseEvent */ /*! @@ -189,7 +189,7 @@ MouseRegion { \endqml */ -QML_DEFINE_NOCREATE_TYPE(QFxKeyEvent) -QML_DEFINE_NOCREATE_TYPE(QFxMouseEvent) +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsKeyEvent) +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsMouseEvent) QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxevents_p.h b/src/declarative/fx/qfxevents_p.h index 7b0c24c..e558c42 100644 --- a/src/declarative/fx/qfxevents_p.h +++ b/src/declarative/fx/qfxevents_p.h @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE -class QFxKeyEvent : public QObject +class QmlGraphicsKeyEvent : public QObject { Q_OBJECT Q_PROPERTY(int key READ key) @@ -71,9 +71,9 @@ class QFxKeyEvent : public QObject Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) public: - QFxKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text=QString(), bool autorep=false, ushort count=1) + QmlGraphicsKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text=QString(), bool autorep=false, ushort count=1) : event(type, key, modifiers, text, autorep, count) { event.setAccepted(false); } - QFxKeyEvent(const QKeyEvent &ke) + QmlGraphicsKeyEvent(const QKeyEvent &ke) : event(ke) { event.setAccepted(false); } int key() const { return event.key(); } @@ -89,7 +89,7 @@ private: QKeyEvent event; }; -class QFxMouseEvent : public QObject +class QmlGraphicsMouseEvent : public QObject { Q_OBJECT Q_PROPERTY(int x READ x) @@ -102,7 +102,7 @@ class QFxMouseEvent : public QObject Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) public: - QFxMouseEvent(int x, int y, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers + QmlGraphicsMouseEvent(int x, int y, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers , bool isClick=false, bool wasHeld=false) : _x(x), _y(y), _button(button), _buttons(buttons), _modifiers(modifiers) , _wasHeld(wasHeld), _isClick(isClick), _accepted(true) {} @@ -131,7 +131,7 @@ private: QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxKeyEvent) -QML_DECLARE_TYPE(QFxMouseEvent) +QML_DECLARE_TYPE(QmlGraphicsKeyEvent) +QML_DECLARE_TYPE(QmlGraphicsMouseEvent) #endif // QFXEVENTS_P_H diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 0fb8474..34e3e75 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -60,7 +60,7 @@ static const int FlickThreshold = 20; // Really slow flicks can be annoying. static const int minimumFlickVelocity = 200; -class QFxFlickableVisibleArea : public QObject +class QmlGraphicsFlickableVisibleArea : public QObject { Q_OBJECT @@ -70,7 +70,7 @@ class QFxFlickableVisibleArea : public QObject Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY pageChanged) public: - QFxFlickableVisibleArea(QFxFlickable *parent=0); + QmlGraphicsFlickableVisibleArea(QmlGraphicsFlickable *parent=0); qreal xPosition() const; qreal widthRatio() const; @@ -83,42 +83,42 @@ signals: void pageChanged(); private: - QFxFlickable *flickable; + QmlGraphicsFlickable *flickable; qreal m_xPosition; qreal m_widthRatio; qreal m_yPosition; qreal m_heightRatio; }; -QFxFlickableVisibleArea::QFxFlickableVisibleArea(QFxFlickable *parent) +QmlGraphicsFlickableVisibleArea::QmlGraphicsFlickableVisibleArea(QmlGraphicsFlickable *parent) : QObject(parent), flickable(parent), m_xPosition(0.), m_widthRatio(0.) , m_yPosition(0.), m_heightRatio(0.) { } -qreal QFxFlickableVisibleArea::widthRatio() const +qreal QmlGraphicsFlickableVisibleArea::widthRatio() const { return m_widthRatio; } -qreal QFxFlickableVisibleArea::xPosition() const +qreal QmlGraphicsFlickableVisibleArea::xPosition() const { return m_xPosition; } -qreal QFxFlickableVisibleArea::heightRatio() const +qreal QmlGraphicsFlickableVisibleArea::heightRatio() const { return m_heightRatio; } -qreal QFxFlickableVisibleArea::yPosition() const +qreal QmlGraphicsFlickableVisibleArea::yPosition() const { return m_yPosition; } -void QFxFlickableVisibleArea::updateVisible() +void QmlGraphicsFlickableVisibleArea::updateVisible() { - QFxFlickablePrivate *p = static_cast(QGraphicsItemPrivate::get(flickable)); + QmlGraphicsFlickablePrivate *p = static_cast(QGraphicsItemPrivate::get(flickable)); bool pageChange = false; // Vertical @@ -155,21 +155,21 @@ void QFxFlickableVisibleArea::updateVisible() } -QFxFlickablePrivate::QFxFlickablePrivate() - : viewport(new QFxItem), _moveX(viewport, &QFxItem::setX), _moveY(viewport, &QFxItem::setY) +QmlGraphicsFlickablePrivate::QmlGraphicsFlickablePrivate() + : viewport(new QmlGraphicsItem), _moveX(viewport, &QmlGraphicsItem::setX), _moveY(viewport, &QmlGraphicsItem::setY) , vWidth(-1), vHeight(-1), overShoot(true), flicked(false), moving(false), stealMouse(false) , pressed(false), atXEnd(false), atXBeginning(true), atYEnd(false), atYBeginning(true) , interactive(true), deceleration(500), maxVelocity(5000), reportedVelocitySmoothing(100) , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0) , horizontalVelocity(this), verticalVelocity(this), vTime(0), visibleArea(0) { - fixupXEvent = QmlTimeLineEvent::timeLineEvent(&_moveX, this); - fixupYEvent = QmlTimeLineEvent::timeLineEvent(&_moveY, this); + fixupXEvent = QmlTimeLineEvent::timeLineEvent(&_moveX, this); + fixupYEvent = QmlTimeLineEvent::timeLineEvent(&_moveY, this); } -void QFxFlickablePrivate::init() +void QmlGraphicsFlickablePrivate::init() { - Q_Q(QFxFlickable); + Q_Q(QmlGraphicsFlickable); viewport->setParent(q); QObject::connect(&timeline, SIGNAL(updated()), q, SLOT(ticked())); QObject::connect(&timeline, SIGNAL(completed()), q, SLOT(movementEnding())); @@ -181,9 +181,9 @@ void QFxFlickablePrivate::init() QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(widthChange())); } -void QFxFlickablePrivate::flickX(qreal velocity) +void QmlGraphicsFlickablePrivate::flickX(qreal velocity) { - Q_Q(QFxFlickable); + Q_Q(QmlGraphicsFlickable); qreal maxDistance = -1; if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; @@ -219,9 +219,9 @@ void QFxFlickablePrivate::flickX(qreal velocity) } } -void QFxFlickablePrivate::flickY(qreal velocity) +void QmlGraphicsFlickablePrivate::flickY(qreal velocity) { - Q_Q(QFxFlickable); + Q_Q(QmlGraphicsFlickable); qreal maxDistance = -1; // -ve velocity means list is moving up if (velocity > 0) { @@ -255,9 +255,9 @@ void QFxFlickablePrivate::flickY(qreal velocity) } } -void QFxFlickablePrivate::fixupX() +void QmlGraphicsFlickablePrivate::fixupX() { - Q_Q(QFxFlickable); + Q_Q(QmlGraphicsFlickable); if (!q->xflick() || _moveX.timeLine()) return; @@ -277,9 +277,9 @@ void QFxFlickablePrivate::fixupX() } } -void QFxFlickablePrivate::fixupY() +void QmlGraphicsFlickablePrivate::fixupY() { - Q_Q(QFxFlickable); + Q_Q(QmlGraphicsFlickable); if (!q->yflick() || _moveY.timeLine()) return; @@ -299,9 +299,9 @@ void QFxFlickablePrivate::fixupY() } } -void QFxFlickablePrivate::updateBeginningEnd() +void QmlGraphicsFlickablePrivate::updateBeginningEnd() { - Q_Q(QFxFlickable); + Q_Q(QmlGraphicsFlickable); bool atBoundaryChange = false; // Vertical @@ -341,7 +341,7 @@ void QFxFlickablePrivate::updateBeginningEnd() visibleArea->updateVisible(); } -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flickable,QFxFlickable) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flickable,QmlGraphicsFlickable) /*! \qmlclass Flickable @@ -369,12 +369,12 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flickable,QFxFlickable) /*! \internal - \class QFxFlickable - \brief The QFxFlickable class provides a view that can be "flicked". + \class QmlGraphicsFlickable + \brief The QmlGraphicsFlickable class provides a view that can be "flicked". \ingroup group_widgets - QFxFlickable allows its children to be dragged and flicked. + QmlGraphicsFlickable allows its children to be dragged and flicked. \code Flickable { @@ -383,8 +383,8 @@ Flickable { } \endcode - Note that QFxFlickable does not automatically clip its contents. If - it is not full-screen it is likely that QFxItem::clip should be set + Note that QmlGraphicsFlickable does not automatically clip its contents. If + it is not full-screen it is likely that QmlGraphicsItem::clip should be set to true. */ @@ -410,21 +410,21 @@ Flickable { \endcode */ -QFxFlickable::QFxFlickable(QFxItem *parent) - : QFxItem(*(new QFxFlickablePrivate), parent) +QmlGraphicsFlickable::QmlGraphicsFlickable(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsFlickablePrivate), parent) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); d->init(); } -QFxFlickable::QFxFlickable(QFxFlickablePrivate &dd, QFxItem *parent) - : QFxItem(dd, parent) +QmlGraphicsFlickable::QmlGraphicsFlickable(QmlGraphicsFlickablePrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); d->init(); } -QFxFlickable::~QFxFlickable() +QmlGraphicsFlickable::~QmlGraphicsFlickable() { } @@ -436,15 +436,15 @@ QFxFlickable::~QFxFlickable() corner of the Flickable. For example, if you flick an image up 100 pixels, \c yPosition will be 100. */ -qreal QFxFlickable::viewportX() const +qreal QmlGraphicsFlickable::viewportX() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return -d->_moveX.value(); } -void QFxFlickable::setViewportX(qreal pos) +void QmlGraphicsFlickable::setViewportX(qreal pos) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); pos = qRound(pos); d->timeline.reset(d->_moveX); if (-pos != d->_moveX.value()) { @@ -453,15 +453,15 @@ void QFxFlickable::setViewportX(qreal pos) } } -qreal QFxFlickable::viewportY() const +qreal QmlGraphicsFlickable::viewportY() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return -d->_moveY.value(); } -void QFxFlickable::setViewportY(qreal pos) +void QmlGraphicsFlickable::setViewportY(qreal pos) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); pos = qRound(pos); d->timeline.reset(d->_moveY); if (-pos != d->_moveY.value()) { @@ -479,15 +479,15 @@ void QFxFlickable::setViewportY(qreal pos) special interaction with Flickable's children: for example, you might want to freeze a flickable map while viewing detailed information on a location popup that is a child of the Flickable. */ -bool QFxFlickable::isInteractive() const +bool QmlGraphicsFlickable::isInteractive() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->interactive; } -void QFxFlickable::setInteractive(bool interactive) +void QmlGraphicsFlickable::setInteractive(bool interactive) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); d->interactive = interactive; if (!interactive && d->flicked) { d->timeline.clear(); @@ -507,15 +507,15 @@ void QFxFlickable::setInteractive(bool interactive) The reported velocity is smoothed to avoid erratic output. reportedVelocitySmoothing determines how much smoothing is applied. */ -qreal QFxFlickable::horizontalVelocity() const +qreal QmlGraphicsFlickable::horizontalVelocity() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->horizontalVelocity.value(); } -qreal QFxFlickable::verticalVelocity() const +qreal QmlGraphicsFlickable::verticalVelocity() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->verticalVelocity.value(); } @@ -528,62 +528,62 @@ qreal QFxFlickable::verticalVelocity() const These properties are true if the flickable view is positioned at the beginning, or end respecively. */ -bool QFxFlickable::isAtXEnd() const +bool QmlGraphicsFlickable::isAtXEnd() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->atXEnd; } -bool QFxFlickable::isAtXBeginning() const +bool QmlGraphicsFlickable::isAtXBeginning() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->atXBeginning; } -bool QFxFlickable::isAtYEnd() const +bool QmlGraphicsFlickable::isAtYEnd() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->atYEnd; } -bool QFxFlickable::isAtYBeginning() const +bool QmlGraphicsFlickable::isAtYBeginning() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->atYBeginning; } -void QFxFlickable::ticked() +void QmlGraphicsFlickable::ticked() { viewportMoved(); } -QFxItem *QFxFlickable::viewport() +QmlGraphicsItem *QmlGraphicsFlickable::viewport() { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); return d->viewport; } -qreal QFxFlickable::visibleX() const +qreal QmlGraphicsFlickable::visibleX() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return -d->_moveX.value(); } -qreal QFxFlickable::visibleY() const +qreal QmlGraphicsFlickable::visibleY() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return -d->_moveY.value(); } -QFxFlickableVisibleArea *QFxFlickable::visibleArea() +QmlGraphicsFlickableVisibleArea *QmlGraphicsFlickable::visibleArea() { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); if (!d->visibleArea) - d->visibleArea = new QFxFlickableVisibleArea(this); + d->visibleArea = new QmlGraphicsFlickableVisibleArea(this); return d->visibleArea; } -void QFxFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event) { if (interactive && timeline.isActive() && (qAbs(velocityX) > 10 || qAbs(velocityY) > 10)) stealMouse = true; // If we've been flicked then steal the click. @@ -594,18 +594,18 @@ void QFxFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event) velocityX = 0; velocityY = 0; lastPos = QPoint(); - QFxItemPrivate::start(lastPosTime); + QmlGraphicsItemPrivate::start(lastPosTime); pressPos = event->pos(); pressX = _moveX.value(); pressY = _moveY.value(); flicked = false; - QFxItemPrivate::start(pressTime); - QFxItemPrivate::start(velocityTime); + QmlGraphicsItemPrivate::start(pressTime); + QmlGraphicsItemPrivate::start(velocityTime); } -void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) { - Q_Q(QFxFlickable); + Q_Q(QmlGraphicsFlickable); if (!interactive || lastPosTime.isNull()) return; bool rejectY = false; @@ -614,7 +614,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) if (q->yflick()) { int dy = int(event->pos().y() - pressPos.y()); - if (qAbs(dy) > DragThreshold || QFxItemPrivate::elapsed(pressTime) > 200) { + if (qAbs(dy) > DragThreshold || QmlGraphicsItemPrivate::elapsed(pressTime) > 200) { qreal newY = dy + pressY; const qreal minY = q->minYExtent(); const qreal maxY = q->maxYExtent(); @@ -641,7 +641,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) if (q->xflick()) { int dx = int(event->pos().x() - pressPos.x()); - if (qAbs(dx) > DragThreshold || QFxItemPrivate::elapsed(pressTime) > 200) { + if (qAbs(dx) > DragThreshold || QmlGraphicsItemPrivate::elapsed(pressTime) > 200) { qreal newX = dx + pressX; const qreal minX = q->minXExtent(); const qreal maxX = q->maxXExtent(); @@ -668,7 +668,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) } if (!lastPos.isNull()) { - qreal elapsed = qreal(QFxItemPrivate::restart(lastPosTime)) / 1000.; + qreal elapsed = qreal(QmlGraphicsItemPrivate::restart(lastPosTime)) / 1000.; if (elapsed <= 0) elapsed = 1; if (q->yflick()) { @@ -697,14 +697,14 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) lastPos = event->pos(); } -void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - Q_Q(QFxFlickable); + Q_Q(QmlGraphicsFlickable); pressed = false; if (lastPosTime.isNull()) return; - if (QFxItemPrivate::elapsed(lastPosTime) > 100) { + if (QmlGraphicsItemPrivate::elapsed(lastPosTime) > 100) { // if we drag then pause before release we should not cause a flick. velocityX = 0.0; velocityY = 0.0; @@ -736,32 +736,32 @@ void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *even q->movementEnding(); } -void QFxFlickable::mousePressEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsFlickable::mousePressEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); d->handleMousePressEvent(event); event->accept(); } -void QFxFlickable::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsFlickable::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); d->handleMouseMoveEvent(event); event->accept(); } -void QFxFlickable::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsFlickable::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); d->clearDelayedPress(); d->handleMouseReleaseEvent(event); event->accept(); ungrabMouse(); } -void QFxFlickablePrivate::captureDelayedPress(QGraphicsSceneMouseEvent *event) +void QmlGraphicsFlickablePrivate::captureDelayedPress(QGraphicsSceneMouseEvent *event) { - Q_Q(QFxFlickable); + Q_Q(QmlGraphicsFlickable); if (!q->scene() || pressDelay <= 0) return; delayedPressTarget = q->scene()->mouseGrabberItem(); @@ -787,7 +787,7 @@ void QFxFlickablePrivate::captureDelayedPress(QGraphicsSceneMouseEvent *event) delayedPressTimer.start(pressDelay, q); } -void QFxFlickablePrivate::clearDelayedPress() +void QmlGraphicsFlickablePrivate::clearDelayedPress() { if (delayedPressEvent) { delayedPressTimer.stop(); @@ -796,13 +796,13 @@ void QFxFlickablePrivate::clearDelayedPress() } } -void QFxFlickable::timerEvent(QTimerEvent *event) +void QmlGraphicsFlickable::timerEvent(QTimerEvent *event) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); if (event->timerId() == d->delayedPressTimer.timerId()) { d->delayedPressTimer.stop(); if (d->delayedPressEvent) { - QFxItem *grabber = scene() ? qobject_cast(scene()->mouseGrabberItem()) : 0; + QmlGraphicsItem *grabber = scene() ? qobject_cast(scene()->mouseGrabberItem()) : 0; if (!grabber || grabber != this) scene()->sendEvent(d->delayedPressTarget, d->delayedPressEvent); delete d->delayedPressEvent; @@ -811,32 +811,32 @@ void QFxFlickable::timerEvent(QTimerEvent *event) } } -qreal QFxFlickable::minYExtent() const +qreal QmlGraphicsFlickable::minYExtent() const { return 0.0; } -qreal QFxFlickable::minXExtent() const +qreal QmlGraphicsFlickable::minXExtent() const { return 0.0; } /* returns -ve */ -qreal QFxFlickable::maxXExtent() const +qreal QmlGraphicsFlickable::maxXExtent() const { return width() - vWidth(); } /* returns -ve */ -qreal QFxFlickable::maxYExtent() const +qreal QmlGraphicsFlickable::maxYExtent() const { return height() - vHeight(); } -void QFxFlickable::viewportMoved() +void QmlGraphicsFlickable::viewportMoved() { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); - int elapsed = QFxItemPrivate::elapsed(d->velocityTime); + int elapsed = QmlGraphicsItemPrivate::elapsed(d->velocityTime); if (elapsed) { qreal prevY = d->lastFlickablePosition.x(); @@ -861,7 +861,7 @@ void QFxFlickable::viewportMoved() } d->lastFlickablePosition = QPointF(d->_moveY.value(), d->_moveX.value()); - QFxItemPrivate::restart(d->velocityTime); + QmlGraphicsItemPrivate::restart(d->velocityTime); d->updateBeginningEnd(); if (d->flicked) { @@ -889,61 +889,61 @@ void QFxFlickable::viewportMoved() } } -void QFxFlickable::cancelFlick() +void QmlGraphicsFlickable::cancelFlick() { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); d->timeline.reset(d->_moveX); d->timeline.reset(d->_moveY); movementEnding(); } -void QFxFlickablePrivate::data_removeAt(int) +void QmlGraphicsFlickablePrivate::data_removeAt(int) { // ### } -int QFxFlickablePrivate::data_count() const +int QmlGraphicsFlickablePrivate::data_count() const { // ### return 0; } -void QFxFlickablePrivate::data_append(QObject *o) +void QmlGraphicsFlickablePrivate::data_append(QObject *o) { - Q_Q(QFxFlickable); - QFxItem *i = qobject_cast(o); + Q_Q(QmlGraphicsFlickable); + QmlGraphicsItem *i = qobject_cast(o); if (i) viewport->fxChildren()->append(i); else o->setParent(q); } -void QFxFlickablePrivate::data_insert(int, QObject *) +void QmlGraphicsFlickablePrivate::data_insert(int, QObject *) { // ### } -QObject *QFxFlickablePrivate::data_at(int) const +QObject *QmlGraphicsFlickablePrivate::data_at(int) const { // ### return 0; } -void QFxFlickablePrivate::data_clear() +void QmlGraphicsFlickablePrivate::data_clear() { // ### } -QmlList *QFxFlickable::flickableData() +QmlList *QmlGraphicsFlickable::flickableData() { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); return &d->data; } -QmlList *QFxFlickable::flickableChildren() +QmlList *QmlGraphicsFlickable::flickableChildren() { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); return d->viewport->fxChildren(); } @@ -957,15 +957,15 @@ QmlList *QFxFlickable::flickableChildren() the feeling that the edges of the view are soft, rather than a hard physical boundary. */ -bool QFxFlickable::overShoot() const +bool QmlGraphicsFlickable::overShoot() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->overShoot; } -void QFxFlickable::setOverShoot(bool o) +void QmlGraphicsFlickable::setOverShoot(bool o) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); d->overShoot = o; } @@ -983,15 +983,15 @@ void QFxFlickable::setOverShoot(bool o) } \endcode */ -qreal QFxFlickable::viewportWidth() const +qreal QmlGraphicsFlickable::viewportWidth() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->vWidth; } -void QFxFlickable::setViewportWidth(qreal w) +void QmlGraphicsFlickable::setViewportWidth(qreal w) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); if (d->vWidth == w) return; d->vWidth = w; @@ -1006,9 +1006,9 @@ void QFxFlickable::setViewportWidth(qreal w) d->updateBeginningEnd(); } -void QFxFlickable::widthChange() +void QmlGraphicsFlickable::widthChange() { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); if (d->vWidth < 0) { d->viewport->setWidth(width()); emit viewportWidthChanged(); @@ -1016,9 +1016,9 @@ void QFxFlickable::widthChange() d->updateBeginningEnd(); } -void QFxFlickable::heightChange() +void QmlGraphicsFlickable::heightChange() { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); if (d->vHeight < 0) { d->viewport->setHeight(height()); emit viewportHeightChanged(); @@ -1026,15 +1026,15 @@ void QFxFlickable::heightChange() d->updateBeginningEnd(); } -qreal QFxFlickable::viewportHeight() const +qreal QmlGraphicsFlickable::viewportHeight() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->vHeight; } -void QFxFlickable::setViewportHeight(qreal h) +void QmlGraphicsFlickable::setViewportHeight(qreal h) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); if (d->vHeight == h) return; d->vHeight = h; @@ -1049,42 +1049,42 @@ void QFxFlickable::setViewportHeight(qreal h) d->updateBeginningEnd(); } -qreal QFxFlickable::vWidth() const +qreal QmlGraphicsFlickable::vWidth() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); if (d->vWidth < 0) return width(); else return d->vWidth; } -qreal QFxFlickable::vHeight() const +qreal QmlGraphicsFlickable::vHeight() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); if (d->vHeight < 0) return height(); else return d->vHeight; } -bool QFxFlickable::xflick() const +bool QmlGraphicsFlickable::xflick() const { return vWidth() != width(); } -bool QFxFlickable::yflick() const +bool QmlGraphicsFlickable::yflick() const { return vHeight() != height(); } -bool QFxFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event) +bool QmlGraphicsFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); QGraphicsSceneMouseEvent mouseEvent(event->type()); QRectF myRect = mapToScene(QRectF(0, 0, width(), height())).boundingRect(); QGraphicsScene *s = scene(); - QFxItem *grabber = s ? qobject_cast(s->mouseGrabberItem()) : 0; + QmlGraphicsItem *grabber = s ? qobject_cast(s->mouseGrabberItem()) : 0; if ((d->stealMouse || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) { mouseEvent.setAccepted(false); for (int i = 0x1; i <= 0x10; i <<= 1) { @@ -1119,7 +1119,7 @@ bool QFxFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event) default: break; } - grabber = qobject_cast(s->mouseGrabberItem()); + grabber = qobject_cast(s->mouseGrabberItem()); if (grabber && d->stealMouse && !grabber->keepMouseGrab() && grabber != this) { d->clearDelayedPress(); grabMouse(); @@ -1134,10 +1134,10 @@ bool QFxFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event) return false; } -bool QFxFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e) +bool QmlGraphicsFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e) { if (!isVisible()) - return QFxItem::sceneEventFilter(i, e); + return QmlGraphicsItem::sceneEventFilter(i, e); switch (e->type()) { case QEvent::GraphicsSceneMousePress: case QEvent::GraphicsSceneMouseMove: @@ -1147,7 +1147,7 @@ bool QFxFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e) break; } - return QFxItem::sceneEventFilter(i, e); + return QmlGraphicsItem::sceneEventFilter(i, e); } /*! @@ -1156,15 +1156,15 @@ bool QFxFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e) The default is 5000 pixels/s */ -qreal QFxFlickable::maximumFlickVelocity() const +qreal QmlGraphicsFlickable::maximumFlickVelocity() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->maxVelocity; } -void QFxFlickable::setMaximumFlickVelocity(qreal v) +void QmlGraphicsFlickable::setMaximumFlickVelocity(qreal v) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); if (v == d->maxVelocity) return; d->maxVelocity = v; @@ -1176,21 +1176,21 @@ void QFxFlickable::setMaximumFlickVelocity(qreal v) The default is 500. */ -qreal QFxFlickable::flickDeceleration() const +qreal QmlGraphicsFlickable::flickDeceleration() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->deceleration; } -void QFxFlickable::setFlickDeceleration(qreal deceleration) +void QmlGraphicsFlickable::setFlickDeceleration(qreal deceleration) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); d->deceleration = deceleration; } -bool QFxFlickable::isFlicking() const +bool QmlGraphicsFlickable::isFlicking() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->flicked; } @@ -1205,29 +1205,29 @@ bool QFxFlickable::isFlicking() const the press event will not be delivered. If the button is released within the timeout, both the press and release will be delivered. */ -int QFxFlickable::pressDelay() const +int QmlGraphicsFlickable::pressDelay() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->pressDelay; } -void QFxFlickable::setPressDelay(int delay) +void QmlGraphicsFlickable::setPressDelay(int delay) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); if (d->pressDelay == delay) return; d->pressDelay = delay; } -qreal QFxFlickable::reportedVelocitySmoothing() const +qreal QmlGraphicsFlickable::reportedVelocitySmoothing() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->reportedVelocitySmoothing; } -void QFxFlickable::setReportedVelocitySmoothing(qreal reportedVelocitySmoothing) +void QmlGraphicsFlickable::setReportedVelocitySmoothing(qreal reportedVelocitySmoothing) { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); Q_ASSERT(reportedVelocitySmoothing >= 0); if (reportedVelocitySmoothing == d->reportedVelocitySmoothing) return; @@ -1235,15 +1235,15 @@ void QFxFlickable::setReportedVelocitySmoothing(qreal reportedVelocitySmoothing) emit reportedVelocitySmoothingChanged(reportedVelocitySmoothing); } -bool QFxFlickable::isMoving() const +bool QmlGraphicsFlickable::isMoving() const { - Q_D(const QFxFlickable); + Q_D(const QmlGraphicsFlickable); return d->moving; } -void QFxFlickable::movementStarting() +void QmlGraphicsFlickable::movementStarting() { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); if (!d->moving) { d->moving = true; emit movingChanged(); @@ -1251,9 +1251,9 @@ void QFxFlickable::movementStarting() } } -void QFxFlickable::movementEnding() +void QmlGraphicsFlickable::movementEnding() { - Q_D(QFxFlickable); + Q_D(QmlGraphicsFlickable); if (d->moving) { d->moving = false; emit movingChanged(); @@ -1268,16 +1268,16 @@ void QFxFlickable::movementEnding() d->verticalVelocity.setValue(0); } -void QFxFlickablePrivate::updateVelocity() +void QmlGraphicsFlickablePrivate::updateVelocity() { - Q_Q(QFxFlickable); + Q_Q(QmlGraphicsFlickable); emit q->horizontalVelocityChanged(); emit q->verticalVelocityChanged(); } QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxFlickableVisibleArea) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisibleArea,QFxFlickableVisibleArea) +QML_DECLARE_TYPE(QmlGraphicsFlickableVisibleArea) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisibleArea,QmlGraphicsFlickableVisibleArea) #include "qfxflickable.moc" diff --git a/src/declarative/fx/qfxflickable.h b/src/declarative/fx/qfxflickable.h index 3db4ca7..634fe88 100644 --- a/src/declarative/fx/qfxflickable.h +++ b/src/declarative/fx/qfxflickable.h @@ -50,9 +50,9 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxFlickablePrivate; -class QFxFlickableVisibleArea; -class Q_DECLARATIVE_EXPORT QFxFlickable : public QFxItem +class QmlGraphicsFlickablePrivate; +class QmlGraphicsFlickableVisibleArea; +class Q_DECLARATIVE_EXPORT QmlGraphicsFlickable : public QmlGraphicsItem { Q_OBJECT @@ -79,18 +79,18 @@ class Q_DECLARATIVE_EXPORT QFxFlickable : public QFxItem Q_PROPERTY(bool atXBeginning READ isAtXBeginning NOTIFY isAtBoundaryChanged) Q_PROPERTY(bool atYBeginning READ isAtYBeginning NOTIFY isAtBoundaryChanged) - Q_PROPERTY(QFxFlickableVisibleArea *visibleArea READ visibleArea CONSTANT) + Q_PROPERTY(QmlGraphicsFlickableVisibleArea *visibleArea READ visibleArea CONSTANT) Q_PROPERTY(QmlList* flickableData READ flickableData) - Q_PROPERTY(QmlList* flickableChildren READ flickableChildren) + Q_PROPERTY(QmlList* flickableChildren READ flickableChildren) Q_CLASSINFO("DefaultProperty", "flickableData") public: - QFxFlickable(QFxItem *parent=0); - ~QFxFlickable(); + QmlGraphicsFlickable(QmlGraphicsItem *parent=0); + ~QmlGraphicsFlickable(); QmlList *flickableData(); - QmlList *flickableChildren(); + QmlList *flickableChildren(); bool overShoot() const; void setOverShoot(bool); @@ -133,7 +133,7 @@ public: bool isAtYEnd() const; bool isAtYBeginning() const; - QFxItem *viewport(); + QmlGraphicsItem *viewport(); Q_SIGNALS: void viewportWidthChanged(); @@ -162,7 +162,7 @@ protected: qreal visibleX() const; qreal visibleY() const; - QFxFlickableVisibleArea *visibleArea(); + QmlGraphicsFlickableVisibleArea *visibleArea(); protected Q_SLOTS: virtual void ticked(); @@ -186,17 +186,17 @@ protected: void cancelFlick(); protected: - QFxFlickable(QFxFlickablePrivate &dd, QFxItem *parent); + QmlGraphicsFlickable(QmlGraphicsFlickablePrivate &dd, QmlGraphicsItem *parent); private: - Q_DISABLE_COPY(QFxFlickable) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxFlickable) - friend class QFxFlickableVisibleArea; + Q_DISABLE_COPY(QmlGraphicsFlickable) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsFlickable) + friend class QmlGraphicsFlickableVisibleArea; }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxFlickable) +QML_DECLARE_TYPE(QmlGraphicsFlickable) QT_END_HEADER diff --git a/src/declarative/fx/qfxflickable_p.h b/src/declarative/fx/qfxflickable_p.h index 07d66b8..5e9863f 100644 --- a/src/declarative/fx/qfxflickable_p.h +++ b/src/declarative/fx/qfxflickable_p.h @@ -62,13 +62,13 @@ QT_BEGIN_NAMESPACE -class QFxFlickableVisibleArea; -class QFxFlickablePrivate : public QFxItemPrivate +class QmlGraphicsFlickableVisibleArea; +class QmlGraphicsFlickablePrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxFlickable) + Q_DECLARE_PUBLIC(QmlGraphicsFlickable) public: - QFxFlickablePrivate(); + QmlGraphicsFlickablePrivate(); void init(); virtual void flickX(qreal velocity); virtual void flickY(qreal velocity); @@ -80,9 +80,9 @@ public: void clearDelayedPress(); public: - QFxItem *viewport; - QmlTimeLineValueProxy _moveX; - QmlTimeLineValueProxy _moveY; + QmlGraphicsItem *viewport; + QmlTimeLineValueProxy _moveX; + QmlTimeLineValueProxy _moveY; QmlTimeLine timeline; qreal vWidth; qreal vHeight; @@ -121,19 +121,19 @@ public: void updateVelocity(); struct Velocity : public QmlTimeLineValue { - Velocity(QFxFlickablePrivate *p) + Velocity(QmlGraphicsFlickablePrivate *p) : parent(p) {} virtual void setValue(qreal v) { QmlTimeLineValue::setValue(v); parent->updateVelocity(); } - QFxFlickablePrivate *parent; + QmlGraphicsFlickablePrivate *parent; }; Velocity horizontalVelocity; Velocity verticalVelocity; int vTime; QmlTimeLine velocityTimeline; - QFxFlickableVisibleArea *visibleArea; + QmlGraphicsFlickableVisibleArea *visibleArea; void handleMousePressEvent(QGraphicsSceneMouseEvent *); void handleMouseMoveEvent(QGraphicsSceneMouseEvent *); @@ -147,8 +147,8 @@ public: QObject *data_at(int) const; void data_clear(); - friend class QFxFlickableVisibleArea; - QML_DECLARE_LIST_PROXY(QFxFlickablePrivate, QObject *, data) + friend class QmlGraphicsFlickableVisibleArea; + QML_DECLARE_LIST_PROXY(QmlGraphicsFlickablePrivate, QObject *, data) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxflipable.cpp b/src/declarative/fx/qfxflipable.cpp index d381cfe..090f8a0 100644 --- a/src/declarative/fx/qfxflipable.cpp +++ b/src/declarative/fx/qfxflipable.cpp @@ -46,23 +46,23 @@ QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flipable,QFxFlipable) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flipable,QmlGraphicsFlipable) -class QFxFlipablePrivate : public QFxItemPrivate +class QmlGraphicsFlipablePrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxFlipable) + Q_DECLARE_PUBLIC(QmlGraphicsFlipable) public: - QFxFlipablePrivate() : current(QFxFlipable::Front), front(0), back(0) {} + QmlGraphicsFlipablePrivate() : current(QmlGraphicsFlipable::Front), front(0), back(0) {} void updateSceneTransformFromParent(); - QFxFlipable::Side current; - QFxItem *front; - QFxItem *back; + QmlGraphicsFlipable::Side current; + QmlGraphicsItem *front; + QmlGraphicsItem *back; }; /*! - \qmlclass Flipable QFxFlipable + \qmlclass Flipable QmlGraphicsFlipable \brief The Flipable item provides a surface that can be flipped. \inherits Item @@ -107,21 +107,21 @@ public: /*! \internal - \class QFxFlipable - \brief The QFxFlipable class provides a flipable surface. + \class QmlGraphicsFlipable + \brief The QmlGraphicsFlipable class provides a flipable surface. \ingroup group_widgets - QFxFlipable allows you to specify a front and a back, as well as an + QmlGraphicsFlipable allows you to specify a front and a back, as well as an axis for the flip. */ -QFxFlipable::QFxFlipable(QFxItem *parent) -: QFxItem(*(new QFxFlipablePrivate), parent) +QmlGraphicsFlipable::QmlGraphicsFlipable(QmlGraphicsItem *parent) +: QmlGraphicsItem(*(new QmlGraphicsFlipablePrivate), parent) { } -QFxFlipable::~QFxFlipable() +QmlGraphicsFlipable::~QmlGraphicsFlipable() { } @@ -132,15 +132,15 @@ QFxFlipable::~QFxFlipable() The front and back sides of the flipable. */ -QFxItem *QFxFlipable::front() +QmlGraphicsItem *QmlGraphicsFlipable::front() { - Q_D(const QFxFlipable); + Q_D(const QmlGraphicsFlipable); return d->front; } -void QFxFlipable::setFront(QFxItem *front) +void QmlGraphicsFlipable::setFront(QmlGraphicsItem *front) { - Q_D(QFxFlipable); + Q_D(QmlGraphicsFlipable); if (d->front) { qmlInfo(tr("front is a write-once property"),this); return; @@ -151,15 +151,15 @@ void QFxFlipable::setFront(QFxItem *front) d->front->setOpacity(0.); } -QFxItem *QFxFlipable::back() +QmlGraphicsItem *QmlGraphicsFlipable::back() { - Q_D(const QFxFlipable); + Q_D(const QmlGraphicsFlipable); return d->back; } -void QFxFlipable::setBack(QFxItem *back) +void QmlGraphicsFlipable::setBack(QmlGraphicsItem *back) { - Q_D(QFxFlipable); + Q_D(QmlGraphicsFlipable); if (d->back) { qmlInfo(tr("back is a write-once property"),this); return; @@ -176,11 +176,11 @@ void QFxFlipable::setBack(QFxItem *back) The side of the Flippable currently visible. Possible values are \c Front and \c Back. */ -QFxFlipable::Side QFxFlipable::side() const +QmlGraphicsFlipable::Side QmlGraphicsFlipable::side() const { - Q_D(const QFxFlipable); + Q_D(const QmlGraphicsFlipable); if (d->dirtySceneTransform) - const_cast(d)->updateSceneTransformFromParent(); + const_cast(d)->updateSceneTransformFromParent(); return d->current; } @@ -188,11 +188,11 @@ QFxFlipable::Side QFxFlipable::side() const // determination on the currently visible side of the flipable // has to be done on the complete scene transform to give // correct results. -void QFxFlipablePrivate::updateSceneTransformFromParent() +void QmlGraphicsFlipablePrivate::updateSceneTransformFromParent() { - Q_Q(QFxFlipable); + Q_Q(QmlGraphicsFlipable); - QFxItemPrivate::updateSceneTransformFromParent(); + QmlGraphicsItemPrivate::updateSceneTransformFromParent(); QPointF p1(0, 0); QPointF p2(1, 0); QPointF p3(1, 1); @@ -204,16 +204,16 @@ void QFxFlipablePrivate::updateSceneTransformFromParent() qreal cross = (p1.x() - p2.x()) * (p3.y() - p2.y()) - (p1.y() - p2.y()) * (p3.x() - p2.x()); - QFxFlipable::Side newSide; + QmlGraphicsFlipable::Side newSide; if (cross > 0) { - newSide = QFxFlipable::Back; + newSide = QmlGraphicsFlipable::Back; } else { - newSide = QFxFlipable::Front; + newSide = QmlGraphicsFlipable::Front; } if (newSide != current) { current = newSide; - if (current == QFxFlipable::Back) { + if (current == QmlGraphicsFlipable::Back) { QTransform mat; mat.translate(back->width()/2,back->height()/2); if (back->width() && p1.x() >= p2.x()) @@ -224,9 +224,9 @@ void QFxFlipablePrivate::updateSceneTransformFromParent() back->setTransform(mat); } if (front) - front->setOpacity((current==QFxFlipable::Front)?1.:0.); + front->setOpacity((current==QmlGraphicsFlipable::Front)?1.:0.); if (back) - back->setOpacity((current==QFxFlipable::Back)?1.:0.); + back->setOpacity((current==QmlGraphicsFlipable::Back)?1.:0.); emit q->sideChanged(); } } diff --git a/src/declarative/fx/qfxflipable.h b/src/declarative/fx/qfxflipable.h index e1bd9ea..1b10d48 100644 --- a/src/declarative/fx/qfxflipable.h +++ b/src/declarative/fx/qfxflipable.h @@ -53,26 +53,26 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxFlipablePrivate; -class Q_DECLARATIVE_EXPORT QFxFlipable : public QFxItem +class QmlGraphicsFlipablePrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsFlipable : public QmlGraphicsItem { Q_OBJECT Q_ENUMS(Side) - Q_PROPERTY(QFxItem *front READ front WRITE setFront) - Q_PROPERTY(QFxItem *back READ back WRITE setBack) + Q_PROPERTY(QmlGraphicsItem *front READ front WRITE setFront) + Q_PROPERTY(QmlGraphicsItem *back READ back WRITE setBack) Q_PROPERTY(Side side READ side NOTIFY sideChanged) //### flipAxis //### flipRotation public: - QFxFlipable(QFxItem *parent=0); - ~QFxFlipable(); + QmlGraphicsFlipable(QmlGraphicsItem *parent=0); + ~QmlGraphicsFlipable(); - QFxItem *front(); - void setFront(QFxItem *); + QmlGraphicsItem *front(); + void setFront(QmlGraphicsItem *); - QFxItem *back(); - void setBack(QFxItem *); + QmlGraphicsItem *back(); + void setBack(QmlGraphicsItem *); enum Side { Front, Back }; Side side() const; @@ -81,13 +81,13 @@ Q_SIGNALS: void sideChanged(); private: - Q_DISABLE_COPY(QFxFlipable) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxFlipable) + Q_DISABLE_COPY(QmlGraphicsFlipable) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsFlipable) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxFlipable) +QML_DECLARE_TYPE(QmlGraphicsFlipable) QT_END_HEADER diff --git a/src/declarative/fx/qfxfocuspanel.cpp b/src/declarative/fx/qfxfocuspanel.cpp index 3bb0b25..3d246a0 100644 --- a/src/declarative/fx/qfxfocuspanel.cpp +++ b/src/declarative/fx/qfxfocuspanel.cpp @@ -45,7 +45,7 @@ QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FocusPanel,QFxFocusPanel) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FocusPanel,QmlGraphicsFocusPanel) /*! \qmlclass FocusPanel @@ -59,16 +59,16 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FocusPanel,QFxFocusPanel) /*! \internal - \class QFxFocusPanel + \class QmlGraphicsFocusPanel */ -QFxFocusPanel::QFxFocusPanel(QFxItem *parent) : - QFxItem(parent) +QmlGraphicsFocusPanel::QmlGraphicsFocusPanel(QmlGraphicsItem *parent) : + QmlGraphicsItem(parent) { setFlag(ItemIsPanel); } -QFxFocusPanel::~QFxFocusPanel() +QmlGraphicsFocusPanel::~QmlGraphicsFocusPanel() { } @@ -78,12 +78,12 @@ QFxFocusPanel::~QFxFocusPanel() Sets whether the item is the active focus panel. */ -bool QFxFocusPanel::sceneEvent(QEvent *event) +bool QmlGraphicsFocusPanel::sceneEvent(QEvent *event) { if (event->type() == QEvent::WindowActivate || event->type() == QEvent::WindowDeactivate) emit activeChanged(); - return QFxItem::sceneEvent(event); + return QmlGraphicsItem::sceneEvent(event); } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxfocuspanel.h b/src/declarative/fx/qfxfocuspanel.h index 1fea011..43eb96e 100644 --- a/src/declarative/fx/qfxfocuspanel.h +++ b/src/declarative/fx/qfxfocuspanel.h @@ -50,13 +50,13 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class Q_DECLARATIVE_EXPORT QFxFocusPanel : public QFxItem +class Q_DECLARATIVE_EXPORT QmlGraphicsFocusPanel : public QmlGraphicsItem { Q_OBJECT Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) public: - QFxFocusPanel(QFxItem *parent=0); - virtual ~QFxFocusPanel(); + QmlGraphicsFocusPanel(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsFocusPanel(); Q_SIGNALS: void activeChanged(); @@ -65,12 +65,12 @@ protected: bool sceneEvent(QEvent *event); private: - Q_DISABLE_COPY(QFxFocusPanel) + Q_DISABLE_COPY(QmlGraphicsFocusPanel) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxFocusPanel) +QML_DECLARE_TYPE(QmlGraphicsFocusPanel) QT_END_HEADER diff --git a/src/declarative/fx/qfxfocusscope.cpp b/src/declarative/fx/qfxfocusscope.cpp index 9bcc17e..468d532 100644 --- a/src/declarative/fx/qfxfocusscope.cpp +++ b/src/declarative/fx/qfxfocusscope.cpp @@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FocusScope,QFxFocusScope) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FocusScope,QmlGraphicsFocusScope) /*! \qmlclass FocusScope @@ -57,16 +57,16 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FocusScope,QFxFocusScope) /*! \internal - \class QFxFocusScope + \class QmlGraphicsFocusScope */ -QFxFocusScope::QFxFocusScope(QFxItem *parent) : - QFxItem(parent) +QmlGraphicsFocusScope::QmlGraphicsFocusScope(QmlGraphicsItem *parent) : + QmlGraphicsItem(parent) { setFlag(QGraphicsItem::ItemIsFocusScope); } -QFxFocusScope::~QFxFocusScope() +QmlGraphicsFocusScope::~QmlGraphicsFocusScope() { } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxfocusscope.h b/src/declarative/fx/qfxfocusscope.h index e337fc6..126ccfc 100644 --- a/src/declarative/fx/qfxfocusscope.h +++ b/src/declarative/fx/qfxfocusscope.h @@ -51,17 +51,17 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) //### set component root as focusscope -class Q_DECLARATIVE_EXPORT QFxFocusScope : public QFxItem +class Q_DECLARATIVE_EXPORT QmlGraphicsFocusScope : public QmlGraphicsItem { Q_OBJECT public: - QFxFocusScope(QFxItem *parent=0); - virtual ~QFxFocusScope(); + QmlGraphicsFocusScope(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsFocusScope(); }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxFocusScope) +QML_DECLARE_TYPE(QmlGraphicsFocusScope) QT_END_HEADER diff --git a/src/declarative/fx/qfxgraphicsobjectcontainer.cpp b/src/declarative/fx/qfxgraphicsobjectcontainer.cpp index 5a61d12..0c9dc69 100644 --- a/src/declarative/fx/qfxgraphicsobjectcontainer.cpp +++ b/src/declarative/fx/qfxgraphicsobjectcontainer.cpp @@ -47,19 +47,19 @@ QT_BEGIN_NAMESPACE -class QFxGraphicsObjectContainerPrivate : public QFxItemPrivate +class QmlGraphicsGraphicsObjectContainerPrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxGraphicsObjectContainer) + Q_DECLARE_PUBLIC(QmlGraphicsGraphicsObjectContainer) public: - QFxGraphicsObjectContainerPrivate() : QFxItemPrivate(), graphicsObject(0), syncedResize(false) + QmlGraphicsGraphicsObjectContainerPrivate() : QmlGraphicsItemPrivate(), graphicsObject(0), syncedResize(false) { } void _q_updateSize(); void setFiltering(bool on) { - Q_Q(QFxGraphicsObjectContainer); + Q_Q(QmlGraphicsGraphicsObjectContainer); if (graphicsObject && graphicsObject->isWidget()) { if (!on) { graphicsObject->removeEventFilter(q); @@ -80,31 +80,31 @@ public: /*! - \qmlclass GraphicsObjectContainer QFxGraphicsObjectContainer + \qmlclass GraphicsObjectContainer QmlGraphicsGraphicsObjectContainer \brief The GraphicsObjectContainer element allows you to add QGraphicsObjects into Fluid UI elements. */ /*! \internal - \class QFxGraphicsObjectContainer - \brief The QFxGraphicsObjectContainer class allows you to add QGraphicsObjects into Fluid UI applications. + \class QmlGraphicsGraphicsObjectContainer + \brief The QmlGraphicsGraphicsObjectContainer class allows you to add QGraphicsObjects into Fluid UI applications. */ QML_DEFINE_NOCREATE_TYPE(QGraphicsObject) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GraphicsObjectContainer,QFxGraphicsObjectContainer) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GraphicsObjectContainer,QmlGraphicsGraphicsObjectContainer) -QFxGraphicsObjectContainer::QFxGraphicsObjectContainer(QFxItem *parent) -: QFxItem(*new QFxGraphicsObjectContainerPrivate, parent) +QmlGraphicsGraphicsObjectContainer::QmlGraphicsGraphicsObjectContainer(QmlGraphicsItem *parent) +: QmlGraphicsItem(*new QmlGraphicsGraphicsObjectContainerPrivate, parent) { } -QFxGraphicsObjectContainer::~QFxGraphicsObjectContainer() +QmlGraphicsGraphicsObjectContainer::~QmlGraphicsGraphicsObjectContainer() { } -QGraphicsObject *QFxGraphicsObjectContainer::graphicsObject() const +QGraphicsObject *QmlGraphicsGraphicsObjectContainer::graphicsObject() const { - Q_D(const QFxGraphicsObjectContainer); + Q_D(const QmlGraphicsGraphicsObjectContainer); return d->graphicsObject; } @@ -112,9 +112,9 @@ QGraphicsObject *QFxGraphicsObjectContainer::graphicsObject() const \qmlproperty QGraphicsObject GraphicsObjectContainer::graphicsObject The QGraphicsObject associated with this element. */ -void QFxGraphicsObjectContainer::setGraphicsObject(QGraphicsObject *object) +void QmlGraphicsGraphicsObjectContainer::setGraphicsObject(QGraphicsObject *object) { - Q_D(QFxGraphicsObjectContainer); + Q_D(QmlGraphicsGraphicsObjectContainer); if (object == d->graphicsObject) return; @@ -147,20 +147,20 @@ void QFxGraphicsObjectContainer::setGraphicsObject(QGraphicsObject *object) } } -QVariant QFxGraphicsObjectContainer::itemChange(GraphicsItemChange change, const QVariant &value) +QVariant QmlGraphicsGraphicsObjectContainer::itemChange(GraphicsItemChange change, const QVariant &value) { - Q_D(QFxGraphicsObjectContainer); + Q_D(QmlGraphicsGraphicsObjectContainer); if (change == ItemSceneHasChanged) { QGraphicsObject *o = d->graphicsObject; d->graphicsObject = 0; setGraphicsObject(o); } - return QFxItem::itemChange(change, value); + return QmlGraphicsItem::itemChange(change, value); } -bool QFxGraphicsObjectContainer::eventFilter(QObject *watched, QEvent *e) +bool QmlGraphicsGraphicsObjectContainer::eventFilter(QObject *watched, QEvent *e) { - Q_D(QFxGraphicsObjectContainer); + Q_D(QmlGraphicsGraphicsObjectContainer); if (watched == d->graphicsObject && e->type() == QEvent::GraphicsSceneResize) { if (d->graphicsObject && d->graphicsObject->isWidget() && d->syncedResize) { QSizeF newSize = static_cast(d->graphicsObject)->size(); @@ -168,7 +168,7 @@ bool QFxGraphicsObjectContainer::eventFilter(QObject *watched, QEvent *e) setImplicitHeight(newSize.height()); } } - return QFxItem::eventFilter(watched, e); + return QmlGraphicsItem::eventFilter(watched, e); } /*! @@ -190,15 +190,15 @@ bool QFxGraphicsObjectContainer::eventFilter(QObject *watched, QEvent *e) widget's size will be reflected in the container. \endlist */ -bool QFxGraphicsObjectContainer::synchronizedResizing() const +bool QmlGraphicsGraphicsObjectContainer::synchronizedResizing() const { - Q_D(const QFxGraphicsObjectContainer); + Q_D(const QmlGraphicsGraphicsObjectContainer); return d->syncedResize; } -void QFxGraphicsObjectContainer::setSynchronizedResizing(bool on) +void QmlGraphicsGraphicsObjectContainer::setSynchronizedResizing(bool on) { - Q_D(QFxGraphicsObjectContainer); + Q_D(QmlGraphicsGraphicsObjectContainer); if (on == d->syncedResize) return; @@ -206,7 +206,7 @@ void QFxGraphicsObjectContainer::setSynchronizedResizing(bool on) d->setFiltering(on); } -void QFxGraphicsObjectContainerPrivate::_q_updateSize() +void QmlGraphicsGraphicsObjectContainerPrivate::_q_updateSize() { if (!graphicsObject || !graphicsObject->isWidget() || !syncedResize) return; diff --git a/src/declarative/fx/qfxgraphicsobjectcontainer.h b/src/declarative/fx/qfxgraphicsobjectcontainer.h index 656a7f8..2ed5c1f 100644 --- a/src/declarative/fx/qfxgraphicsobjectcontainer.h +++ b/src/declarative/fx/qfxgraphicsobjectcontainer.h @@ -51,9 +51,9 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QGraphicsObject; -class QFxGraphicsObjectContainerPrivate; +class QmlGraphicsGraphicsObjectContainerPrivate; -class Q_DECLARATIVE_EXPORT QFxGraphicsObjectContainer : public QFxItem +class Q_DECLARATIVE_EXPORT QmlGraphicsGraphicsObjectContainer : public QmlGraphicsItem { Q_OBJECT @@ -62,8 +62,8 @@ class Q_DECLARATIVE_EXPORT QFxGraphicsObjectContainer : public QFxItem Q_PROPERTY(bool synchronizedResizing READ synchronizedResizing WRITE setSynchronizedResizing) public: - QFxGraphicsObjectContainer(QFxItem *parent = 0); - ~QFxGraphicsObjectContainer(); + QmlGraphicsGraphicsObjectContainer(QmlGraphicsItem *parent = 0); + ~QmlGraphicsGraphicsObjectContainer(); QGraphicsObject *graphicsObject() const; void setGraphicsObject(QGraphicsObject *); @@ -77,13 +77,13 @@ protected: private: Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxGraphicsObjectContainer) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsGraphicsObjectContainer) }; QT_END_NAMESPACE QML_DECLARE_TYPE(QGraphicsObject) -QML_DECLARE_TYPE(QFxGraphicsObjectContainer) +QML_DECLARE_TYPE(QmlGraphicsGraphicsObjectContainer) QT_END_HEADER diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index c07258d..5ed82d7 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -49,18 +49,18 @@ QT_BEGIN_NAMESPACE -class QFxGridViewAttached : public QObject +class QmlGraphicsGridViewAttached : public QObject { Q_OBJECT public: - QFxGridViewAttached(QObject *parent) + QmlGraphicsGridViewAttached(QObject *parent) : QObject(parent), m_isCurrent(false), m_delayRemove(false) {} - ~QFxGridViewAttached() { + ~QmlGraphicsGridViewAttached() { attachedProperties.remove(parent()); } - Q_PROPERTY(QFxGridView *view READ view CONSTANT) - QFxGridView *view() { return m_view; } + Q_PROPERTY(QmlGraphicsGridView *view READ view CONSTANT) + QmlGraphicsGridView *view() { return m_view; } Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) bool isCurrentItem() const { return m_isCurrent; } @@ -80,10 +80,10 @@ public: } } - static QFxGridViewAttached *properties(QObject *obj) { - QFxGridViewAttached *rv = attachedProperties.value(obj); + static QmlGraphicsGridViewAttached *properties(QObject *obj) { + QmlGraphicsGridViewAttached *rv = attachedProperties.value(obj); if (!rv) { - rv = new QFxGridViewAttached(obj); + rv = new QmlGraphicsGridViewAttached(obj); attachedProperties.insert(obj, rv); } return rv; @@ -99,14 +99,14 @@ Q_SIGNALS: void remove(); public: - QFxGridView *m_view; + QmlGraphicsGridView *m_view; bool m_isCurrent; bool m_delayRemove; - static QHash attachedProperties; + static QHash attachedProperties; }; -QHash QFxGridViewAttached::attachedProperties; +QHash QmlGraphicsGridViewAttached::attachedProperties; //---------------------------------------------------------------------------- @@ -114,42 +114,42 @@ QHash QFxGridViewAttached::attachedProperties; class FxGridItem { public: - FxGridItem(QFxItem *i, QFxGridView *v) : item(i), view(v) { - attached = QFxGridViewAttached::properties(item); + FxGridItem(QmlGraphicsItem *i, QmlGraphicsGridView *v) : item(i), view(v) { + attached = QmlGraphicsGridViewAttached::properties(item); attached->m_view = view; } ~FxGridItem() {} - qreal rowPos() const { return (view->flow() == QFxGridView::LeftToRight ? item->y() : item->x()); } - qreal colPos() const { return (view->flow() == QFxGridView::LeftToRight ? item->x() : item->y()); } + qreal rowPos() const { return (view->flow() == QmlGraphicsGridView::LeftToRight ? item->y() : item->x()); } + qreal colPos() const { return (view->flow() == QmlGraphicsGridView::LeftToRight ? item->x() : item->y()); } qreal endRowPos() const { - return view->flow() == QFxGridView::LeftToRight + return view->flow() == QmlGraphicsGridView::LeftToRight ? item->y() + view->cellHeight() - 1 : item->x() + view->cellWidth() - 1; } void setPosition(qreal col, qreal row) { - if (view->flow() == QFxGridView::LeftToRight) { + if (view->flow() == QmlGraphicsGridView::LeftToRight) { item->setPos(QPointF(col, row)); } else { item->setPos(QPointF(row, col)); } } - QFxItem *item; - QFxGridView *view; - QFxGridViewAttached *attached; + QmlGraphicsItem *item; + QmlGraphicsGridView *view; + QmlGraphicsGridViewAttached *attached; int index; }; //---------------------------------------------------------------------------- -class QFxGridViewPrivate : public QFxFlickablePrivate +class QmlGraphicsGridViewPrivate : public QmlGraphicsFlickablePrivate { - Q_DECLARE_PUBLIC(QFxGridView) + Q_DECLARE_PUBLIC(QmlGraphicsGridView) public: - QFxGridViewPrivate() - : model(0), currentItem(0), flow(QFxGridView::LeftToRight) + QmlGraphicsGridViewPrivate() + : model(0), currentItem(0), flow(QmlGraphicsGridView::LeftToRight) , visiblePos(0), visibleIndex(0) , currentIndex(-1) , cellWidth(100), cellHeight(100), columns(1), requestedIndex(-1) , highlightComponent(0), highlight(0), trackedItem(0) @@ -184,19 +184,19 @@ public: } qreal position() const { - Q_Q(const QFxGridView); - return flow == QFxGridView::LeftToRight ? q->viewportY() : q->viewportX(); + Q_Q(const QmlGraphicsGridView); + return flow == QmlGraphicsGridView::LeftToRight ? q->viewportY() : q->viewportX(); } void setPosition(qreal pos) { - Q_Q(QFxGridView); - if (flow == QFxGridView::LeftToRight) + Q_Q(QmlGraphicsGridView); + if (flow == QmlGraphicsGridView::LeftToRight) q->setViewportY(pos); else q->setViewportX(pos); } int size() const { - Q_Q(const QFxGridView); - return flow == QFxGridView::LeftToRight ? q->height() : q->width(); + Q_Q(const QmlGraphicsGridView); + return flow == QmlGraphicsGridView::LeftToRight ? q->height() : q->width(); } qreal startPosition() const { qreal pos = 0; @@ -217,10 +217,10 @@ public: } int rowSize() const { - return flow == QFxGridView::LeftToRight ? cellHeight : cellWidth; + return flow == QmlGraphicsGridView::LeftToRight ? cellHeight : cellWidth; } int colSize() const { - return flow == QFxGridView::LeftToRight ? cellWidth : cellHeight; + return flow == QmlGraphicsGridView::LeftToRight ? cellWidth : cellHeight; } qreal colPosAt(int modelIndex) const { @@ -293,12 +293,12 @@ public: } } - QFxVisualModel *model; + QmlGraphicsVisualModel *model; QVariant modelVariant; QList visibleItems; - QHash unrequestedItems; + QHash unrequestedItems; FxGridItem *currentItem; - QFxGridView::Flow flow; + QmlGraphicsGridView::Flow flow; int visiblePos; int visibleIndex; int currentIndex; @@ -321,15 +321,15 @@ public: int fixCurrentVisibility : 1; }; -void QFxGridViewPrivate::init() +void QmlGraphicsGridViewPrivate::init() { - Q_Q(QFxGridView); + Q_Q(QmlGraphicsGridView); q->setFlag(QGraphicsItem::ItemIsFocusScope); QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(sizeChange())); QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(sizeChange())); } -void QFxGridViewPrivate::clear() +void QmlGraphicsGridViewPrivate::clear() { for (int i = 0; i < visibleItems.count(); ++i) releaseItem(visibleItems.at(i)); @@ -343,13 +343,13 @@ void QFxGridViewPrivate::clear() trackedItem = 0; } -FxGridItem *QFxGridViewPrivate::createItem(int modelIndex) +FxGridItem *QmlGraphicsGridViewPrivate::createItem(int modelIndex) { - Q_Q(QFxGridView); + Q_Q(QmlGraphicsGridView); // create object requestedIndex = modelIndex; FxGridItem *listItem = 0; - if (QFxItem *item = model->item(modelIndex, false)) { + if (QmlGraphicsItem *item = model->item(modelIndex, false)) { listItem = new FxGridItem(item, q); listItem->index = modelIndex; // complete @@ -362,9 +362,9 @@ FxGridItem *QFxGridViewPrivate::createItem(int modelIndex) } -void QFxGridViewPrivate::releaseItem(FxGridItem *item) +void QmlGraphicsGridViewPrivate::releaseItem(FxGridItem *item) { - Q_Q(QFxGridView); + Q_Q(QmlGraphicsGridView); if (!item) return; if (trackedItem == item) { @@ -379,9 +379,9 @@ void QFxGridViewPrivate::releaseItem(FxGridItem *item) delete item; } -void QFxGridViewPrivate::refill(qreal from, qreal to) +void QmlGraphicsGridViewPrivate::refill(qreal from, qreal to) { - Q_Q(QFxGridView); + Q_Q(QmlGraphicsGridView); if (!isValid() || !q->isComponentComplete()) return; @@ -463,28 +463,28 @@ void QFxGridViewPrivate::refill(qreal from, qreal to) changed = true; } if (changed) { - if (flow == QFxGridView::LeftToRight) + if (flow == QmlGraphicsGridView::LeftToRight) q->setViewportHeight(endPosition() - startPosition()); else q->setViewportWidth(endPosition() - startPosition()); } } -void QFxGridViewPrivate::updateGrid() +void QmlGraphicsGridViewPrivate::updateGrid() { - Q_Q(QFxGridView); - columns = (int)qMax((flow == QFxGridView::LeftToRight ? q->width() : q->height()) / colSize(), qreal(1.)); + Q_Q(QmlGraphicsGridView); + columns = (int)qMax((flow == QmlGraphicsGridView::LeftToRight ? q->width() : q->height()) / colSize(), qreal(1.)); if (isValid()) { - if (flow == QFxGridView::LeftToRight) + if (flow == QmlGraphicsGridView::LeftToRight) q->setViewportHeight(endPosition() - startPosition()); else q->setViewportWidth(endPosition() - startPosition()); } } -void QFxGridViewPrivate::layout(bool removed) +void QmlGraphicsGridViewPrivate::layout(bool removed) { - Q_Q(QFxGridView); + Q_Q(QmlGraphicsGridView); if (visibleItems.count()) { qreal rowPos = visibleItems.first()->rowPos(); qreal colPos = visibleItems.first()->colPos(); @@ -510,7 +510,7 @@ void QFxGridViewPrivate::layout(bool removed) q->refill(); q->trackedPositionChanged(); updateHighlight(); - if (flow == QFxGridView::LeftToRight) { + if (flow == QmlGraphicsGridView::LeftToRight) { q->setViewportHeight(endPosition() - startPosition()); fixupY(); } else { @@ -520,19 +520,19 @@ void QFxGridViewPrivate::layout(bool removed) updateUnrequestedPositions(); } -void QFxGridViewPrivate::updateUnrequestedIndexes() +void QmlGraphicsGridViewPrivate::updateUnrequestedIndexes() { - Q_Q(QFxGridView); - QHash::iterator it; + Q_Q(QmlGraphicsGridView); + QHash::iterator it; for (it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) *it = model->indexOf(it.key(), q); } -void QFxGridViewPrivate::updateUnrequestedPositions() +void QmlGraphicsGridViewPrivate::updateUnrequestedPositions() { - QHash::const_iterator it; + QHash::const_iterator it; for (it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) { - if (flow == QFxGridView::LeftToRight) { + if (flow == QmlGraphicsGridView::LeftToRight) { it.key()->setPos(QPointF(colPosAt(*it), rowPosAt(*it))); } else { it.key()->setPos(QPointF(rowPosAt(*it), colPosAt(*it))); @@ -540,9 +540,9 @@ void QFxGridViewPrivate::updateUnrequestedPositions() } } -void QFxGridViewPrivate::updateTrackedItem() +void QmlGraphicsGridViewPrivate::updateTrackedItem() { - Q_Q(QFxGridView); + Q_Q(QmlGraphicsGridView); FxGridItem *item = currentItem; if (highlight) item = highlight; @@ -563,9 +563,9 @@ void QFxGridViewPrivate::updateTrackedItem() q->trackedPositionChanged(); } -void QFxGridViewPrivate::createHighlight() +void QmlGraphicsGridViewPrivate::createHighlight() { - Q_Q(QFxGridView); + Q_Q(QmlGraphicsGridView); if (highlight) { if (trackedItem == highlight) trackedItem = 0; @@ -586,7 +586,7 @@ void QFxGridViewPrivate::createHighlight() QObject *nobj = highlightComponent->create(highlightContext); if (nobj) { highlightContext->setParent(nobj); - QFxItem *item = qobject_cast(nobj); + QmlGraphicsItem *item = qobject_cast(nobj); if (item) { item->setParent(q->viewport()); highlight = new FxGridItem(item, q); @@ -605,7 +605,7 @@ void QFxGridViewPrivate::createHighlight() } } -void QFxGridViewPrivate::updateHighlight() +void QmlGraphicsGridViewPrivate::updateHighlight() { if ((!currentItem && highlight) || (currentItem && !highlight)) createHighlight(); @@ -619,9 +619,9 @@ void QFxGridViewPrivate::updateHighlight() } } -void QFxGridViewPrivate::updateCurrent(int modelIndex) +void QmlGraphicsGridViewPrivate::updateCurrent(int modelIndex) { - Q_Q(QFxGridView); + Q_Q(QmlGraphicsGridView); if (!isValid() || modelIndex < 0 || modelIndex >= model->count()) { if (currentItem) { currentItem->attached->setIsCurrentItem(false); @@ -680,16 +680,16 @@ void QFxGridViewPrivate::updateCurrent(int modelIndex) In this case ListModel is a handy way for us to test our UI. In practice the model would be implemented in C++, or perhaps via a SQL data source. */ -QFxGridView::QFxGridView(QFxItem *parent) - : QFxFlickable(*(new QFxGridViewPrivate), parent) +QmlGraphicsGridView::QmlGraphicsGridView(QmlGraphicsItem *parent) + : QmlGraphicsFlickable(*(new QmlGraphicsGridViewPrivate), parent) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); d->init(); } -QFxGridView::~QFxGridView() +QmlGraphicsGridView::~QmlGraphicsGridView() { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); d->clear(); if (d->ownModel) delete d->model; @@ -758,27 +758,27 @@ QFxGridView::~QFxGridView() \sa {qmlmodels}{Data Models} */ -QVariant QFxGridView::model() const +QVariant QmlGraphicsGridView::model() const { - Q_D(const QFxGridView); + Q_D(const QmlGraphicsGridView); return d->modelVariant; } -void QFxGridView::setModel(const QVariant &model) +void QmlGraphicsGridView::setModel(const QVariant &model) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); - disconnect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); - disconnect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); + disconnect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + disconnect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); } d->clear(); d->modelVariant = model; QObject *object = qvariant_cast(model); - QFxVisualModel *vim = 0; - if (object && (vim = qobject_cast(object))) { + QmlGraphicsVisualModel *vim = 0; + if (object && (vim = qobject_cast(object))) { if (d->ownModel) { delete d->model; d->ownModel = false; @@ -786,10 +786,10 @@ void QFxGridView::setModel(const QVariant &model) d->model = vim; } else { if (!d->ownModel) { - d->model = new QFxVisualDataModel(qmlContext(this)); + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); d->ownModel = true; } - if (QFxVisualDataModel *dataModel = qobject_cast(d->model)) + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) dataModel->setModel(model); } if (d->model) { @@ -800,8 +800,8 @@ void QFxGridView::setModel(const QVariant &model) connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); - connect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); - connect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); + connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + connect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); refill(); emit countChanged(); } @@ -815,25 +815,25 @@ void QFxGridView::setModel(const QVariant &model) Here is an example delegate: \snippet doc/src/snippets/declarative/gridview/gridview.qml 0 */ -QmlComponent *QFxGridView::delegate() const +QmlComponent *QmlGraphicsGridView::delegate() const { - Q_D(const QFxGridView); + Q_D(const QmlGraphicsGridView); if (d->model) { - if (QFxVisualDataModel *dataModel = qobject_cast(d->model)) + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) return dataModel->delegate(); } return 0; } -void QFxGridView::setDelegate(QmlComponent *delegate) +void QmlGraphicsGridView::setDelegate(QmlComponent *delegate) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); if (!d->ownModel) { - d->model = new QFxVisualDataModel(qmlContext(this)); + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); d->ownModel = true; } - if (QFxVisualDataModel *dataModel = qobject_cast(d->model)) { + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) { dataModel->setDelegate(delegate); d->updateCurrent(d->currentIndex); refill(); @@ -848,15 +848,15 @@ void QFxGridView::setDelegate(QmlComponent *delegate) \c currentItem is the current item. Note that the position of the current item may only be approximate until it becomes visible in the view. */ -int QFxGridView::currentIndex() const +int QmlGraphicsGridView::currentIndex() const { - Q_D(const QFxGridView); + Q_D(const QmlGraphicsGridView); return d->currentIndex; } -void QFxGridView::setCurrentIndex(int index) +void QmlGraphicsGridView::setCurrentIndex(int index) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); if (d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) { cancelFlick(); d->updateCurrent(index); @@ -865,9 +865,9 @@ void QFxGridView::setCurrentIndex(int index) } } -QFxItem *QFxGridView::currentItem() +QmlGraphicsItem *QmlGraphicsGridView::currentItem() { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); if (!d->currentItem) return 0; return d->currentItem->item; @@ -877,9 +877,9 @@ QFxItem *QFxGridView::currentItem() \qmlproperty int GridView::count This property holds the number of items in the view. */ -int QFxGridView::count() const +int QmlGraphicsGridView::count() const { - Q_D(const QFxGridView); + Q_D(const QmlGraphicsGridView); if (d->model) return d->model->count(); return 0; @@ -898,15 +898,15 @@ int QFxGridView::count() const \sa highlightFollowsCurrentItem */ -QmlComponent *QFxGridView::highlight() const +QmlComponent *QmlGraphicsGridView::highlight() const { - Q_D(const QFxGridView); + Q_D(const QmlGraphicsGridView); return d->highlightComponent; } -void QFxGridView::setHighlight(QmlComponent *highlight) +void QmlGraphicsGridView::setHighlight(QmlComponent *highlight) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); delete d->highlightComponent; d->highlightComponent = highlight; d->updateCurrent(d->currentIndex); @@ -932,15 +932,15 @@ void QFxGridView::setHighlight(QmlComponent *highlight) } \endcode */ -bool QFxGridView::highlightFollowsCurrentItem() const +bool QmlGraphicsGridView::highlightFollowsCurrentItem() const { - Q_D(const QFxGridView); + Q_D(const QmlGraphicsGridView); return d->autoHighlight; } -void QFxGridView::setHighlightFollowsCurrentItem(bool autoHighlight) +void QmlGraphicsGridView::setHighlightFollowsCurrentItem(bool autoHighlight) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); d->autoHighlight = autoHighlight; if (d->highlightXAnimator) { d->highlightXAnimator->setEnabled(d->autoHighlight); @@ -958,15 +958,15 @@ void QFxGridView::setHighlightFollowsCurrentItem(bool autoHighlight) If \a flow is \c LeftToRight, the view will scroll vertically. If \a flow is \c TopToBottom, the view will scroll horizontally. */ -QFxGridView::Flow QFxGridView::flow() const +QmlGraphicsGridView::Flow QmlGraphicsGridView::flow() const { - Q_D(const QFxGridView); + Q_D(const QmlGraphicsGridView); return d->flow; } -void QFxGridView::setFlow(Flow flow) +void QmlGraphicsGridView::setFlow(Flow flow) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); if (d->flow != flow) { d->flow = flow; if (d->flow == LeftToRight) @@ -987,15 +987,15 @@ void QFxGridView::setFlow(Flow flow) If this property is true then key presses to move off of one end of the grid will cause the selection to jump to the other side. */ -bool QFxGridView::isWrapEnabled() const +bool QmlGraphicsGridView::isWrapEnabled() const { - Q_D(const QFxGridView); + Q_D(const QmlGraphicsGridView); return d->wrap; } -void QFxGridView::setWrapEnabled(bool wrap) +void QmlGraphicsGridView::setWrapEnabled(bool wrap) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); d->wrap = wrap; } @@ -1007,15 +1007,15 @@ void QFxGridView::setWrapEnabled(bool wrap) and below the bottom of the view to cache. Setting this value can make scrolling the view smoother at the expense of additional memory usage. */ -int QFxGridView::cacheBuffer() const +int QmlGraphicsGridView::cacheBuffer() const { - Q_D(const QFxGridView); + Q_D(const QmlGraphicsGridView); return d->buffer; } -void QFxGridView::setCacheBuffer(int buffer) +void QmlGraphicsGridView::setCacheBuffer(int buffer) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); if (d->buffer != buffer) { d->buffer = buffer; if (isComponentComplete()) @@ -1031,15 +1031,15 @@ void QFxGridView::setCacheBuffer(int buffer) The default sell size is 100x100. */ -int QFxGridView::cellWidth() const +int QmlGraphicsGridView::cellWidth() const { - Q_D(const QFxGridView); + Q_D(const QmlGraphicsGridView); return d->cellWidth; } -void QFxGridView::setCellWidth(int cellWidth) +void QmlGraphicsGridView::setCellWidth(int cellWidth) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); if (cellWidth != d->cellWidth && cellWidth > 0) { d->cellWidth = qMax(1, cellWidth); d->updateGrid(); @@ -1048,15 +1048,15 @@ void QFxGridView::setCellWidth(int cellWidth) } } -int QFxGridView::cellHeight() const +int QmlGraphicsGridView::cellHeight() const { - Q_D(const QFxGridView); + Q_D(const QmlGraphicsGridView); return d->cellHeight; } -void QFxGridView::setCellHeight(int cellHeight) +void QmlGraphicsGridView::setCellHeight(int cellHeight) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); if (cellHeight != d->cellHeight && cellHeight > 0) { d->cellHeight = qMax(1, cellHeight); d->updateGrid(); @@ -1065,62 +1065,62 @@ void QFxGridView::setCellHeight(int cellHeight) } } -void QFxGridView::sizeChange() +void QmlGraphicsGridView::sizeChange() { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); if (isComponentComplete()) { d->updateGrid(); d->layout(); } } -void QFxGridView::viewportMoved() +void QmlGraphicsGridView::viewportMoved() { - QFxFlickable::viewportMoved(); + QmlGraphicsFlickable::viewportMoved(); refill(); } -qreal QFxGridView::minYExtent() const +qreal QmlGraphicsGridView::minYExtent() const { - Q_D(const QFxGridView); - if (d->flow == QFxGridView::TopToBottom) - return QFxFlickable::minYExtent(); + Q_D(const QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::TopToBottom) + return QmlGraphicsFlickable::minYExtent(); return -d->startPosition(); } -qreal QFxGridView::maxYExtent() const +qreal QmlGraphicsGridView::maxYExtent() const { - Q_D(const QFxGridView); - if (d->flow == QFxGridView::TopToBottom) - return QFxFlickable::maxYExtent(); + Q_D(const QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::TopToBottom) + return QmlGraphicsFlickable::maxYExtent(); return -(d->endPosition() - height()); } -qreal QFxGridView::minXExtent() const +qreal QmlGraphicsGridView::minXExtent() const { - Q_D(const QFxGridView); - if (d->flow == QFxGridView::LeftToRight) - return QFxFlickable::minXExtent(); + Q_D(const QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::LeftToRight) + return QmlGraphicsFlickable::minXExtent(); return -d->startPosition(); } -qreal QFxGridView::maxXExtent() const +qreal QmlGraphicsGridView::maxXExtent() const { - Q_D(const QFxGridView); - if (d->flow == QFxGridView::LeftToRight) - return QFxFlickable::maxXExtent(); + Q_D(const QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::LeftToRight) + return QmlGraphicsFlickable::maxXExtent(); return -(d->endPosition() - width()); } -void QFxGridView::keyPressEvent(QKeyEvent *event) +void QmlGraphicsGridView::keyPressEvent(QKeyEvent *event) { - Q_D(QFxGridView); - QFxFlickable::keyPressEvent(event); + Q_D(QmlGraphicsGridView); + QmlGraphicsFlickable::keyPressEvent(event); if (event->isAccepted()) return; if (d->model && d->model->count() && d->interactive) { - d->moveReason = QFxGridViewPrivate::Key; + d->moveReason = QmlGraphicsGridViewPrivate::Key; int oldCurrent = currentIndex(); switch (event->key()) { case Qt::Key_Up: @@ -1143,7 +1143,7 @@ void QFxGridView::keyPressEvent(QKeyEvent *event) return; } } - d->moveReason = QFxGridViewPrivate::Other; + d->moveReason = QmlGraphicsGridViewPrivate::Other; event->ignore(); } @@ -1154,10 +1154,10 @@ void QFxGridView::keyPressEvent(QKeyEvent *event) The current index will wrap if keyNavigationWraps is true and it is currently at the end. */ -void QFxGridView::moveCurrentIndexUp() +void QmlGraphicsGridView::moveCurrentIndexUp() { - Q_D(QFxGridView); - if (d->flow == QFxGridView::LeftToRight) { + Q_D(QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::LeftToRight) { if (currentIndex() >= d->columns || d->wrap) { int index = currentIndex() - d->columns; setCurrentIndex(index >= 0 ? index : d->model->count()-1); @@ -1177,10 +1177,10 @@ void QFxGridView::moveCurrentIndexUp() The current index will wrap if keyNavigationWraps is true and it is currently at the end. */ -void QFxGridView::moveCurrentIndexDown() +void QmlGraphicsGridView::moveCurrentIndexDown() { - Q_D(QFxGridView); - if (d->flow == QFxGridView::LeftToRight) { + Q_D(QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::LeftToRight) { if (currentIndex() < d->model->count() - d->columns || d->wrap) { int index = currentIndex()+d->columns; setCurrentIndex(index < d->model->count() ? index : 0); @@ -1200,10 +1200,10 @@ void QFxGridView::moveCurrentIndexDown() The current index will wrap if keyNavigationWraps is true and it is currently at the end. */ -void QFxGridView::moveCurrentIndexLeft() +void QmlGraphicsGridView::moveCurrentIndexLeft() { - Q_D(QFxGridView); - if (d->flow == QFxGridView::LeftToRight) { + Q_D(QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::LeftToRight) { if (currentIndex() > 0 || d->wrap) { int index = currentIndex() - 1; setCurrentIndex(index >= 0 ? index : d->model->count()-1); @@ -1223,10 +1223,10 @@ void QFxGridView::moveCurrentIndexLeft() The current index will wrap if keyNavigationWraps is true and it is currently at the end. */ -void QFxGridView::moveCurrentIndexRight() +void QmlGraphicsGridView::moveCurrentIndexRight() { - Q_D(QFxGridView); - if (d->flow == QFxGridView::LeftToRight) { + Q_D(QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::LeftToRight) { if (currentIndex() < d->model->count() - 1 || d->wrap) { int index = currentIndex() + 1; setCurrentIndex(index < d->model->count() ? index : 0); @@ -1239,22 +1239,22 @@ void QFxGridView::moveCurrentIndexRight() } } -void QFxGridView::componentComplete() +void QmlGraphicsGridView::componentComplete() { - Q_D(QFxGridView); - QFxFlickable::componentComplete(); + Q_D(QmlGraphicsGridView); + QmlGraphicsFlickable::componentComplete(); d->updateGrid(); if (d->currentIndex < 0) d->updateCurrent(0); refill(); } -void QFxGridView::trackedPositionChanged() +void QmlGraphicsGridView::trackedPositionChanged() { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); if (!d->trackedItem) return; - if (!isFlicking() && !d->pressed && d->moveReason == QFxGridViewPrivate::Key) { + if (!isFlicking() && !d->pressed && d->moveReason == QmlGraphicsGridViewPrivate::Key) { if (d->trackedItem->rowPos() < d->position()) { d->setPosition(d->trackedItem->rowPos()); } else if (d->trackedItem->endRowPos() > d->position() + d->size()) { @@ -1266,9 +1266,9 @@ void QFxGridView::trackedPositionChanged() } } -void QFxGridView::itemsInserted(int modelIndex, int count) +void QmlGraphicsGridView::itemsInserted(int modelIndex, int count) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); if (!d->visibleItems.count() || d->model->count() <= 1) { refill(); d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); @@ -1377,9 +1377,9 @@ void QFxGridView::itemsInserted(int modelIndex, int count) emit countChanged(); } -void QFxGridView::itemsRemoved(int modelIndex, int count) +void QmlGraphicsGridView::itemsRemoved(int modelIndex, int count) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; int index = d->mapFromModel(modelIndex); if (index == -1) { @@ -1465,9 +1465,9 @@ void QFxGridView::itemsRemoved(int modelIndex, int count) emit countChanged(); } -void QFxGridView::destroyRemoved() +void QmlGraphicsGridView::destroyRemoved() { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); for (QList::Iterator it = d->visibleItems.begin(); it != d->visibleItems.end();) { FxGridItem *listItem = *it; @@ -1483,9 +1483,9 @@ void QFxGridView::destroyRemoved() d->layout(); } -void QFxGridView::itemsMoved(int from, int to, int count) +void QmlGraphicsGridView::itemsMoved(int from, int to, int count) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); QHash moved; QList::Iterator it = d->visibleItems.begin(); @@ -1544,14 +1544,14 @@ void QFxGridView::itemsMoved(int from, int to, int count) d->layout(); } -void QFxGridView::createdItem(int index, QFxItem *item) +void QmlGraphicsGridView::createdItem(int index, QmlGraphicsItem *item) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); item->setParentItem(this); if (d->requestedIndex != index) { item->setParentItem(this); d->unrequestedItems.insert(item, index); - if (d->flow == QFxGridView::LeftToRight) { + if (d->flow == QmlGraphicsGridView::LeftToRight) { item->setPos(QPointF(d->colPosAt(index), d->rowPosAt(index))); } else { item->setPos(QPointF(d->rowPosAt(index), d->colPosAt(index))); @@ -1559,26 +1559,26 @@ void QFxGridView::createdItem(int index, QFxItem *item) } } -void QFxGridView::destroyingItem(QFxItem *item) +void QmlGraphicsGridView::destroyingItem(QmlGraphicsItem *item) { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); d->unrequestedItems.remove(item); } -void QFxGridView::refill() +void QmlGraphicsGridView::refill() { - Q_D(QFxGridView); + Q_D(QmlGraphicsGridView); d->refill(d->position(), d->position()+d->size()-1); } -QFxGridViewAttached *QFxGridView::qmlAttachedProperties(QObject *obj) +QmlGraphicsGridViewAttached *QmlGraphicsGridView::qmlAttachedProperties(QObject *obj) { - return QFxGridViewAttached::properties(obj); + return QmlGraphicsGridViewAttached::properties(obj); } -QML_DEFINE_TYPE(Qt, 4,6, (QT_VERSION&0x00ff00)>>8, GridView, QFxGridView) +QML_DEFINE_TYPE(Qt, 4,6, (QT_VERSION&0x00ff00)>>8, GridView, QmlGraphicsGridView) QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h index 1c0a700..fd0a459 100644 --- a/src/declarative/fx/qfxgridview.h +++ b/src/declarative/fx/qfxgridview.h @@ -49,18 +49,18 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxVisualModel; -class QFxGridViewAttached; -class QFxGridViewPrivate; -class Q_DECLARATIVE_EXPORT QFxGridView : public QFxFlickable +class QmlGraphicsVisualModel; +class QmlGraphicsGridViewAttached; +class QmlGraphicsGridViewPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsGridView : public QmlGraphicsFlickable { Q_OBJECT - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxGridView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsGridView) Q_PROPERTY(QVariant model READ model WRITE setModel) Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QFxItem *currentItem READ currentItem NOTIFY currentIndexChanged) + Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) @@ -72,8 +72,8 @@ class Q_DECLARATIVE_EXPORT QFxGridView : public QFxFlickable Q_CLASSINFO("DefaultProperty", "data") public: - QFxGridView(QFxItem *parent=0); - ~QFxGridView(); + QmlGraphicsGridView(QmlGraphicsItem *parent=0); + ~QmlGraphicsGridView(); QVariant model() const; void setModel(const QVariant &); @@ -84,7 +84,7 @@ public: int currentIndex() const; void setCurrentIndex(int idx); - QFxItem *currentItem(); + QmlGraphicsItem *currentItem(); int count() const; QmlComponent *highlight() const; @@ -110,7 +110,7 @@ public: int cellHeight() const; void setCellHeight(int); - static QFxGridViewAttached *qmlAttachedProperties(QObject *); + static QmlGraphicsGridViewAttached *qmlAttachedProperties(QObject *); public Q_SLOTS: void moveCurrentIndexUp(); @@ -139,8 +139,8 @@ private Q_SLOTS: void itemsRemoved(int index, int count); void itemsMoved(int from, int to, int count); void destroyRemoved(); - void createdItem(int index, QFxItem *item); - void destroyingItem(QFxItem *item); + void createdItem(int index, QmlGraphicsItem *item); + void destroyingItem(QmlGraphicsItem *item); void sizeChange(); private: @@ -149,8 +149,8 @@ private: QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxGridView) -QML_DECLARE_TYPEINFO(QFxGridView, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QmlGraphicsGridView) +QML_DECLARE_TYPEINFO(QmlGraphicsGridView, QML_HAS_ATTACHED_PROPERTIES) QT_END_HEADER diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index 45a481c..34b3399 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -48,10 +48,10 @@ QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Image,QFxImage) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Image,QmlGraphicsImage) /*! - \qmlclass Image QFxImage + \qmlclass Image QmlGraphicsImage \brief The Image element allows you to add bitmaps to a scene. \inherits Item @@ -112,8 +112,8 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Image,QFxImage) /*! \internal - \class QFxImage Image - \brief The QFxImage class provides an image item that you can add to a QmlView. + \class QmlGraphicsImage Image + \brief The QmlGraphicsImage class provides an image item that you can add to a QmlView. \ingroup group_coreitems @@ -122,34 +122,34 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Image,QFxImage) Image { source: "pics/star.png" } \endqml - A QFxImage object can be instantiated in Qml using the tag \l Image. + A QmlGraphicsImage object can be instantiated in Qml using the tag \l Image. */ -QFxImage::QFxImage(QFxItem *parent) - : QFxImageBase(*(new QFxImagePrivate), parent) +QmlGraphicsImage::QmlGraphicsImage(QmlGraphicsItem *parent) + : QmlGraphicsImageBase(*(new QmlGraphicsImagePrivate), parent) { setFlag(QGraphicsItem::ItemHasNoContents, false); } -QFxImage::QFxImage(QFxImagePrivate &dd, QFxItem *parent) - : QFxImageBase(dd, parent) +QmlGraphicsImage::QmlGraphicsImage(QmlGraphicsImagePrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsImageBase(dd, parent) { setFlag(QGraphicsItem::ItemHasNoContents, false); } -QFxImage::~QFxImage() +QmlGraphicsImage::~QmlGraphicsImage() { } -QPixmap QFxImage::pixmap() const +QPixmap QmlGraphicsImage::pixmap() const { - Q_D(const QFxImage); + Q_D(const QmlGraphicsImage); return d->pix; } -void QFxImage::setPixmap(const QPixmap &pix) +void QmlGraphicsImage::setPixmap(const QPixmap &pix) { - Q_D(QFxImage); + Q_D(QmlGraphicsImage); if (!d->url.isEmpty()) return; d->pix = pix; @@ -179,15 +179,15 @@ void QFxImage::setPixmap(const QPixmap &pix) \sa examples/declarative/fillmode \sa examples/declarative/aspectratio */ -QFxImage::FillMode QFxImage::fillMode() const +QmlGraphicsImage::FillMode QmlGraphicsImage::fillMode() const { - Q_D(const QFxImage); + Q_D(const QmlGraphicsImage); return d->fillMode; } -void QFxImage::setFillMode(FillMode mode) +void QmlGraphicsImage::setFillMode(FillMode mode) { - Q_D(QFxImage); + Q_D(QmlGraphicsImage); if (d->fillMode == mode) return; d->fillMode = mode; @@ -239,9 +239,9 @@ void QFxImage::setFillMode(FillMode mode) The URL may be absolute, or relative to the URL of the component. */ -void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +void QmlGraphicsImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { - Q_D(QFxImage); + Q_D(QmlGraphicsImage); if (d->pix.isNull()) return; diff --git a/src/declarative/fx/qfximage.h b/src/declarative/fx/qfximage.h index fc8079c..1f52b17 100644 --- a/src/declarative/fx/qfximage.h +++ b/src/declarative/fx/qfximage.h @@ -50,8 +50,8 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxImagePrivate; -class Q_DECLARATIVE_EXPORT QFxImage : public QFxImageBase +class QmlGraphicsImagePrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsImage : public QmlGraphicsImageBase { Q_OBJECT Q_ENUMS(FillMode) @@ -60,8 +60,8 @@ class Q_DECLARATIVE_EXPORT QFxImage : public QFxImageBase Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) public: - QFxImage(QFxItem *parent=0); - ~QFxImage(); + QmlGraphicsImage(QmlGraphicsItem *parent=0); + ~QmlGraphicsImage(); enum FillMode { Stretch, PreserveAspectFit, PreserveAspectCrop, Tile, TileVertically, TileHorizontally }; FillMode fillMode() const; @@ -76,15 +76,15 @@ Q_SIGNALS: void fillModeChanged(); protected: - QFxImage(QFxImagePrivate &dd, QFxItem *parent); + QmlGraphicsImage(QmlGraphicsImagePrivate &dd, QmlGraphicsItem *parent); private: - Q_DISABLE_COPY(QFxImage) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxImage) + Q_DISABLE_COPY(QmlGraphicsImage) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsImage) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxImage) +QML_DECLARE_TYPE(QmlGraphicsImage) QT_END_HEADER #endif // QFXIMAGE_H diff --git a/src/declarative/fx/qfximage_p.h b/src/declarative/fx/qfximage_p.h index 8bdcc14..30f7665 100644 --- a/src/declarative/fx/qfximage_p.h +++ b/src/declarative/fx/qfximage_p.h @@ -58,17 +58,17 @@ QT_BEGIN_NAMESPACE -class QFxImagePrivate : public QFxImageBasePrivate +class QmlGraphicsImagePrivate : public QmlGraphicsImageBasePrivate { - Q_DECLARE_PUBLIC(QFxImage) + Q_DECLARE_PUBLIC(QmlGraphicsImage) public: - QFxImagePrivate() - : fillMode(QFxImage::Stretch) + QmlGraphicsImagePrivate() + : fillMode(QmlGraphicsImage::Stretch) { } - QFxImage::FillMode fillMode; + QmlGraphicsImage::FillMode fillMode; }; diff --git a/src/declarative/fx/qfximagebase.cpp b/src/declarative/fx/qfximagebase.cpp index a68c1f9..5afb79a 100644 --- a/src/declarative/fx/qfximagebase.cpp +++ b/src/declarative/fx/qfximagebase.cpp @@ -49,53 +49,53 @@ QT_BEGIN_NAMESPACE -QFxImageBase::QFxImageBase(QFxItem *parent) - : QFxItem(*(new QFxImageBasePrivate), parent) +QmlGraphicsImageBase::QmlGraphicsImageBase(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsImageBasePrivate), parent) { setFlag(QGraphicsItem::ItemHasNoContents, true); } -QFxImageBase::QFxImageBase(QFxImageBasePrivate &dd, QFxItem *parent) - : QFxItem(dd, parent) +QmlGraphicsImageBase::QmlGraphicsImageBase(QmlGraphicsImageBasePrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) { setFlag(QGraphicsItem::ItemHasNoContents, true); } -QFxImageBase::~QFxImageBase() +QmlGraphicsImageBase::~QmlGraphicsImageBase() { - Q_D(QFxImageBase); + Q_D(QmlGraphicsImageBase); if (d->pendingPixmapCache) - QFxPixmapCache::cancelGet(d->url, this); + QmlGraphicsPixmapCache::cancelGet(d->url, this); } -QFxImageBase::Status QFxImageBase::status() const +QmlGraphicsImageBase::Status QmlGraphicsImageBase::status() const { - Q_D(const QFxImageBase); + Q_D(const QmlGraphicsImageBase); return d->status; } -qreal QFxImageBase::progress() const +qreal QmlGraphicsImageBase::progress() const { - Q_D(const QFxImageBase); + Q_D(const QmlGraphicsImageBase); return d->progress; } -QUrl QFxImageBase::source() const +QUrl QmlGraphicsImageBase::source() const { - Q_D(const QFxImageBase); + Q_D(const QmlGraphicsImageBase); return d->url; } -void QFxImageBase::setSource(const QUrl &url) +void QmlGraphicsImageBase::setSource(const QUrl &url) { - Q_D(QFxImageBase); + Q_D(QmlGraphicsImageBase); //equality is fairly expensive, so we bypass for simple, common case if ((d->url.isEmpty() == url.isEmpty()) && url == d->url) return; if (d->pendingPixmapCache) { - QFxPixmapCache::cancelGet(d->url, this); + QmlGraphicsPixmapCache::cancelGet(d->url, this); d->pendingPixmapCache = false; } @@ -117,7 +117,7 @@ void QFxImageBase::setSource(const QUrl &url) update(); } else { d->status = Loading; - QNetworkReply *reply = QFxPixmapCache::get(qmlEngine(this), d->url, &d->pix); + QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->pix); if (reply) { d->pendingPixmapCache = true; connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); @@ -141,13 +141,13 @@ void QFxImageBase::setSource(const QUrl &url) emit statusChanged(d->status); } -void QFxImageBase::requestFinished() +void QmlGraphicsImageBase::requestFinished() { - Q_D(QFxImageBase); + Q_D(QmlGraphicsImageBase); d->pendingPixmapCache = false; - if (!QFxPixmapCache::find(d->url, &d->pix)) + if (!QmlGraphicsPixmapCache::find(d->url, &d->pix)) d->status = Error; setImplicitWidth(d->pix.width()); setImplicitHeight(d->pix.height()); @@ -161,9 +161,9 @@ void QFxImageBase::requestFinished() update(); } -void QFxImageBase::requestProgress(qint64 received, qint64 total) +void QmlGraphicsImageBase::requestProgress(qint64 received, qint64 total) { - Q_D(QFxImageBase); + Q_D(QmlGraphicsImageBase); if (d->status == Loading && total > 0) { d->progress = qreal(received)/total; emit progressChanged(d->progress); diff --git a/src/declarative/fx/qfximagebase.h b/src/declarative/fx/qfximagebase.h index 226d3c3..b43e9a2 100644 --- a/src/declarative/fx/qfximagebase.h +++ b/src/declarative/fx/qfximagebase.h @@ -47,8 +47,8 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QFxImageBasePrivate; -class QFxImageBase : public QFxItem +class QmlGraphicsImageBasePrivate; +class QmlGraphicsImageBase : public QmlGraphicsItem { Q_OBJECT Q_ENUMS(Status) @@ -58,8 +58,8 @@ class QFxImageBase : public QFxItem Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) public: - QFxImageBase(QFxItem *parent = 0); - ~QFxImageBase(); + QmlGraphicsImageBase(QmlGraphicsItem *parent = 0); + ~QmlGraphicsImageBase(); enum Status { Null, Ready, Loading, Error }; Status status() const; qreal progress() const; @@ -73,15 +73,15 @@ Q_SIGNALS: void progressChanged(qreal progress); protected: - QFxImageBase(QFxImageBasePrivate &dd, QFxItem *parent); + QmlGraphicsImageBase(QmlGraphicsImageBasePrivate &dd, QmlGraphicsItem *parent); private Q_SLOTS: virtual void requestFinished(); void requestProgress(qint64,qint64); private: - Q_DISABLE_COPY(QFxImageBase) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxImageBase) + Q_DISABLE_COPY(QmlGraphicsImageBase) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsImageBase) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfximagebase_p.h b/src/declarative/fx/qfximagebase_p.h index a6fcc80..9025c51 100644 --- a/src/declarative/fx/qfximagebase_p.h +++ b/src/declarative/fx/qfximagebase_p.h @@ -59,20 +59,20 @@ QT_BEGIN_NAMESPACE class QNetworkReply; -class QFxImageBasePrivate : public QFxItemPrivate +class QmlGraphicsImageBasePrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxImageBase) + Q_DECLARE_PUBLIC(QmlGraphicsImageBase) public: - QFxImageBasePrivate() - : status(QFxImageBase::Null), + QmlGraphicsImageBasePrivate() + : status(QmlGraphicsImageBase::Null), progress(0.0), pendingPixmapCache(false) { } QPixmap pix; - QFxImageBase::Status status; + QmlGraphicsImageBase::Status status; QUrl url; qreal progress; bool pendingPixmapCache; diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 72833e1..7a3cded 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -70,7 +70,7 @@ QT_BEGIN_NAMESPACE #define FLT_MAX 1E+37 #endif -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Item,QFxItem) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Item,QmlGraphicsItem) QML_DEFINE_NOCREATE_TYPE(QGraphicsTransform); QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Scale,QGraphicsScale) @@ -224,13 +224,13 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) /*! \internal - \class QFxContents + \class QmlGraphicsContents \ingroup group_utility - \brief The QFxContents class gives access to the height and width of an item's contents. + \brief The QmlGraphicsContents class gives access to the height and width of an item's contents. */ -QFxContents::QFxContents() : m_x(0), m_y(0), m_width(0), m_height(0) +QmlGraphicsContents::QmlGraphicsContents() : m_x(0), m_y(0), m_width(0), m_height(0) { } @@ -245,13 +245,13 @@ QFxContents::QFxContents() : m_x(0), m_y(0), m_width(0), m_height(0) sized to fit its children. */ -QRectF QFxContents::rectF() const +QRectF QmlGraphicsContents::rectF() const { return QRectF(m_x, m_y, m_width, m_height); } //TODO: optimization: only check sender(), if there is one -void QFxContents::calcHeight() +void QmlGraphicsContents::calcHeight() { qreal oldy = m_y; qreal oldheight = m_height; @@ -261,8 +261,8 @@ void QFxContents::calcHeight() QList children = m_item->childItems(); for (int i = 0; i < children.count(); ++i) { - QFxItem *child = qobject_cast(children.at(i)); - if(!child)//### Should this be ignoring non-QFxItem graphicsobjects? + QmlGraphicsItem *child = qobject_cast(children.at(i)); + if(!child)//### Should this be ignoring non-QmlGraphicsItem graphicsobjects? continue; qreal y = child->y(); if (y + child->height() > bottom) @@ -279,7 +279,7 @@ void QFxContents::calcHeight() } //TODO: optimization: only check sender(), if there is one -void QFxContents::calcWidth() +void QmlGraphicsContents::calcWidth() { qreal oldx = m_x; qreal oldwidth = m_width; @@ -289,8 +289,8 @@ void QFxContents::calcWidth() QList children = m_item->childItems(); for (int i = 0; i < children.count(); ++i) { - QFxItem *child = qobject_cast(children.at(i)); - if(!child)//### Should this be ignoring non-QFxItem graphicsobjects? + QmlGraphicsItem *child = qobject_cast(children.at(i)); + if(!child)//### Should this be ignoring non-QmlGraphicsItem graphicsobjects? continue; qreal x = child->x(); if (x + child->width() > right) @@ -306,14 +306,14 @@ void QFxContents::calcWidth() emit rectChanged(); } -void QFxContents::setItem(QFxItem *item) +void QmlGraphicsContents::setItem(QmlGraphicsItem *item) { m_item = item; QList children = m_item->childItems(); for (int i = 0; i < children.count(); ++i) { - QFxItem *child = qobject_cast(children.at(i)); - if(!child)//### Should this be ignoring non-QFxItem graphicsobjects? + QmlGraphicsItem *child = qobject_cast(children.at(i)); + if(!child)//### Should this be ignoring non-QmlGraphicsItem graphicsobjects? continue; connect(child, SIGNAL(heightChanged()), this, SLOT(calcHeight())); connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight())); @@ -327,16 +327,16 @@ void QFxContents::setItem(QFxItem *item) } /* - Key filters can be installed on a QFxItem, but not removed. Currently they + Key filters can be installed on a QmlGraphicsItem, but not removed. Currently they are only used by attached objects (which are only destroyed on Item destruction), so this isn't a problem. If in future this becomes any form of public API, they will have to support removal too. */ -class QFxItemKeyFilter +class QmlGraphicsItemKeyFilter { public: - QFxItemKeyFilter(QFxItem * = 0); - virtual ~QFxItemKeyFilter(); + QmlGraphicsItemKeyFilter(QmlGraphicsItem * = 0); + virtual ~QmlGraphicsItemKeyFilter(); virtual void keyPressed(QKeyEvent *event); virtual void keyReleased(QKeyEvent *event); @@ -345,84 +345,84 @@ public: virtual void componentComplete(); private: - QFxItemKeyFilter *m_next; + QmlGraphicsItemKeyFilter *m_next; }; -QFxItemKeyFilter::QFxItemKeyFilter(QFxItem *item) +QmlGraphicsItemKeyFilter::QmlGraphicsItemKeyFilter(QmlGraphicsItem *item) : m_next(0) { - QFxItemPrivate *p = - item?static_cast(QGraphicsItemPrivate::get(item)):0; + QmlGraphicsItemPrivate *p = + item?static_cast(QGraphicsItemPrivate::get(item)):0; if (p) { m_next = p->keyHandler; p->keyHandler = this; } } -QFxItemKeyFilter::~QFxItemKeyFilter() +QmlGraphicsItemKeyFilter::~QmlGraphicsItemKeyFilter() { } -void QFxItemKeyFilter::keyPressed(QKeyEvent *event) +void QmlGraphicsItemKeyFilter::keyPressed(QKeyEvent *event) { if (m_next) m_next->keyPressed(event); } -void QFxItemKeyFilter::keyReleased(QKeyEvent *event) +void QmlGraphicsItemKeyFilter::keyReleased(QKeyEvent *event) { if (m_next) m_next->keyReleased(event); } -void QFxItemKeyFilter::inputMethodEvent(QInputMethodEvent *event) +void QmlGraphicsItemKeyFilter::inputMethodEvent(QInputMethodEvent *event) { if (m_next) m_next->inputMethodEvent(event); } -QVariant QFxItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query) const +QVariant QmlGraphicsItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query) const { if (m_next) return m_next->inputMethodQuery(query); return QVariant(); } -void QFxItemKeyFilter::componentComplete() +void QmlGraphicsItemKeyFilter::componentComplete() { if (m_next) m_next->componentComplete(); } -class QFxKeyNavigationAttachedPrivate : public QObjectPrivate +class QmlGraphicsKeyNavigationAttachedPrivate : public QObjectPrivate { public: - QFxKeyNavigationAttachedPrivate() + QmlGraphicsKeyNavigationAttachedPrivate() : QObjectPrivate(), left(0), right(0), up(0), down(0) {} - QFxItem *left; - QFxItem *right; - QFxItem *up; - QFxItem *down; + QmlGraphicsItem *left; + QmlGraphicsItem *right; + QmlGraphicsItem *up; + QmlGraphicsItem *down; }; -class QFxKeyNavigationAttached : public QObject, public QFxItemKeyFilter +class QmlGraphicsKeyNavigationAttached : public QObject, public QmlGraphicsItemKeyFilter { Q_OBJECT - Q_DECLARE_PRIVATE(QFxKeyNavigationAttached) + Q_DECLARE_PRIVATE(QmlGraphicsKeyNavigationAttached) - Q_PROPERTY(QFxItem *left READ left WRITE setLeft NOTIFY changed) - Q_PROPERTY(QFxItem *right READ right WRITE setRight NOTIFY changed) - Q_PROPERTY(QFxItem *up READ up WRITE setUp NOTIFY changed) - Q_PROPERTY(QFxItem *down READ down WRITE setDown NOTIFY changed) + Q_PROPERTY(QmlGraphicsItem *left READ left WRITE setLeft NOTIFY changed) + Q_PROPERTY(QmlGraphicsItem *right READ right WRITE setRight NOTIFY changed) + Q_PROPERTY(QmlGraphicsItem *up READ up WRITE setUp NOTIFY changed) + Q_PROPERTY(QmlGraphicsItem *down READ down WRITE setDown NOTIFY changed) public: - QFxKeyNavigationAttached(QObject * = 0); + QmlGraphicsKeyNavigationAttached(QObject * = 0); - QFxItem *left() const; - void setLeft(QFxItem *); - QFxItem *right() const; - void setRight(QFxItem *); - QFxItem *up() const; - void setUp(QFxItem *); - QFxItem *down() const; - void setDown(QFxItem *); + QmlGraphicsItem *left() const; + void setLeft(QmlGraphicsItem *); + QmlGraphicsItem *right() const; + void setRight(QmlGraphicsItem *); + QmlGraphicsItem *up() const; + void setUp(QmlGraphicsItem *); + QmlGraphicsItem *down() const; + void setDown(QmlGraphicsItem *); - static QFxKeyNavigationAttached *qmlAttachedProperties(QObject *); + static QmlGraphicsKeyNavigationAttached *qmlAttachedProperties(QObject *); Q_SIGNALS: void changed(); @@ -432,73 +432,73 @@ private: virtual void keyReleased(QKeyEvent *event); }; -QFxKeyNavigationAttached::QFxKeyNavigationAttached(QObject *parent) -: QObject(*(new QFxKeyNavigationAttachedPrivate), parent), - QFxItemKeyFilter(qobject_cast(parent)) +QmlGraphicsKeyNavigationAttached::QmlGraphicsKeyNavigationAttached(QObject *parent) +: QObject(*(new QmlGraphicsKeyNavigationAttachedPrivate), parent), + QmlGraphicsItemKeyFilter(qobject_cast(parent)) { } -QFxKeyNavigationAttached * -QFxKeyNavigationAttached::qmlAttachedProperties(QObject *obj) +QmlGraphicsKeyNavigationAttached * +QmlGraphicsKeyNavigationAttached::qmlAttachedProperties(QObject *obj) { - return new QFxKeyNavigationAttached(obj); + return new QmlGraphicsKeyNavigationAttached(obj); } -QFxItem *QFxKeyNavigationAttached::left() const +QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::left() const { - Q_D(const QFxKeyNavigationAttached); + Q_D(const QmlGraphicsKeyNavigationAttached); return d->left; } -void QFxKeyNavigationAttached::setLeft(QFxItem *i) +void QmlGraphicsKeyNavigationAttached::setLeft(QmlGraphicsItem *i) { - Q_D(QFxKeyNavigationAttached); + Q_D(QmlGraphicsKeyNavigationAttached); d->left = i; emit changed(); } -QFxItem *QFxKeyNavigationAttached::right() const +QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::right() const { - Q_D(const QFxKeyNavigationAttached); + Q_D(const QmlGraphicsKeyNavigationAttached); return d->right; } -void QFxKeyNavigationAttached::setRight(QFxItem *i) +void QmlGraphicsKeyNavigationAttached::setRight(QmlGraphicsItem *i) { - Q_D(QFxKeyNavigationAttached); + Q_D(QmlGraphicsKeyNavigationAttached); d->right = i; emit changed(); } -QFxItem *QFxKeyNavigationAttached::up() const +QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::up() const { - Q_D(const QFxKeyNavigationAttached); + Q_D(const QmlGraphicsKeyNavigationAttached); return d->up; } -void QFxKeyNavigationAttached::setUp(QFxItem *i) +void QmlGraphicsKeyNavigationAttached::setUp(QmlGraphicsItem *i) { - Q_D(QFxKeyNavigationAttached); + Q_D(QmlGraphicsKeyNavigationAttached); d->up = i; emit changed(); } -QFxItem *QFxKeyNavigationAttached::down() const +QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::down() const { - Q_D(const QFxKeyNavigationAttached); + Q_D(const QmlGraphicsKeyNavigationAttached); return d->down; } -void QFxKeyNavigationAttached::setDown(QFxItem *i) +void QmlGraphicsKeyNavigationAttached::setDown(QmlGraphicsItem *i) { - Q_D(QFxKeyNavigationAttached); + Q_D(QmlGraphicsKeyNavigationAttached); d->down = i; emit changed(); } -void QFxKeyNavigationAttached::keyPressed(QKeyEvent *event) +void QmlGraphicsKeyNavigationAttached::keyPressed(QKeyEvent *event) { - Q_D(QFxKeyNavigationAttached); + Q_D(QmlGraphicsKeyNavigationAttached); event->ignore(); @@ -531,12 +531,12 @@ void QFxKeyNavigationAttached::keyPressed(QKeyEvent *event) break; } - if (!event->isAccepted()) QFxItemKeyFilter::keyPressed(event); + if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyPressed(event); } -void QFxKeyNavigationAttached::keyReleased(QKeyEvent *event) +void QmlGraphicsKeyNavigationAttached::keyReleased(QKeyEvent *event) { - Q_D(QFxKeyNavigationAttached); + Q_D(QmlGraphicsKeyNavigationAttached); event->ignore(); @@ -565,7 +565,7 @@ void QFxKeyNavigationAttached::keyReleased(QKeyEvent *event) break; } - if (!event->isAccepted()) QFxItemKeyFilter::keyReleased(event); + if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyReleased(event); } /*! @@ -895,10 +895,10 @@ void QFxKeyNavigationAttached::keyReleased(QKeyEvent *event) */ -class QFxKeysAttachedPrivate : public QObjectPrivate +class QmlGraphicsKeysAttachedPrivate : public QObjectPrivate { public: - QFxKeysAttachedPrivate() + QmlGraphicsKeysAttachedPrivate() : QObjectPrivate(), inPress(false), inRelease(false) , inIM(false), enabled(true), imeItem(0), item(0) {} @@ -921,82 +921,82 @@ public: bool enabled : 1; QGraphicsItem *imeItem; - QList targets; - QFxItem *item; + QList targets; + QmlGraphicsItem *item; }; -class QFxKeysAttached : public QObject, public QFxItemKeyFilter +class QmlGraphicsKeysAttached : public QObject, public QmlGraphicsItemKeyFilter { Q_OBJECT - Q_DECLARE_PRIVATE(QFxKeysAttached) + Q_DECLARE_PRIVATE(QmlGraphicsKeysAttached) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(QList *forwardTo READ forwardTo) + Q_PROPERTY(QList *forwardTo READ forwardTo) public: - QFxKeysAttached(QObject *parent=0); - ~QFxKeysAttached(); + QmlGraphicsKeysAttached(QObject *parent=0); + ~QmlGraphicsKeysAttached(); - bool enabled() const { Q_D(const QFxKeysAttached); return d->enabled; } + bool enabled() const { Q_D(const QmlGraphicsKeysAttached); return d->enabled; } void setEnabled(bool enabled) { - Q_D(QFxKeysAttached); + Q_D(QmlGraphicsKeysAttached); if (enabled != d->enabled) { d->enabled = enabled; emit enabledChanged(); } } - QList *forwardTo() { - Q_D(QFxKeysAttached); + QList *forwardTo() { + Q_D(QmlGraphicsKeysAttached); return &d->targets; } virtual void componentComplete(); - static QFxKeysAttached *qmlAttachedProperties(QObject *); + static QmlGraphicsKeysAttached *qmlAttachedProperties(QObject *); Q_SIGNALS: void enabledChanged(); - void pressed(QFxKeyEvent *event); - void released(QFxKeyEvent *event); - void digit0Pressed(QFxKeyEvent *event); - void digit1Pressed(QFxKeyEvent *event); - void digit2Pressed(QFxKeyEvent *event); - void digit3Pressed(QFxKeyEvent *event); - void digit4Pressed(QFxKeyEvent *event); - void digit5Pressed(QFxKeyEvent *event); - void digit6Pressed(QFxKeyEvent *event); - void digit7Pressed(QFxKeyEvent *event); - void digit8Pressed(QFxKeyEvent *event); - void digit9Pressed(QFxKeyEvent *event); - - void leftPressed(QFxKeyEvent *event); - void rightPressed(QFxKeyEvent *event); - void upPressed(QFxKeyEvent *event); - void downPressed(QFxKeyEvent *event); - - void asteriskPressed(QFxKeyEvent *event); - void numberSignPressed(QFxKeyEvent *event); - void escapePressed(QFxKeyEvent *event); - void returnPressed(QFxKeyEvent *event); - void enterPressed(QFxKeyEvent *event); - void deletePressed(QFxKeyEvent *event); - void spacePressed(QFxKeyEvent *event); - void backPressed(QFxKeyEvent *event); - void cancelPressed(QFxKeyEvent *event); - void selectPressed(QFxKeyEvent *event); - void yesPressed(QFxKeyEvent *event); - void noPressed(QFxKeyEvent *event); - void context1Pressed(QFxKeyEvent *event); - void context2Pressed(QFxKeyEvent *event); - void context3Pressed(QFxKeyEvent *event); - void context4Pressed(QFxKeyEvent *event); - void callPressed(QFxKeyEvent *event); - void hangupPressed(QFxKeyEvent *event); - void flipPressed(QFxKeyEvent *event); - void menuPressed(QFxKeyEvent *event); - void volumeUpPressed(QFxKeyEvent *event); - void volumeDownPressed(QFxKeyEvent *event); + void pressed(QmlGraphicsKeyEvent *event); + void released(QmlGraphicsKeyEvent *event); + void digit0Pressed(QmlGraphicsKeyEvent *event); + void digit1Pressed(QmlGraphicsKeyEvent *event); + void digit2Pressed(QmlGraphicsKeyEvent *event); + void digit3Pressed(QmlGraphicsKeyEvent *event); + void digit4Pressed(QmlGraphicsKeyEvent *event); + void digit5Pressed(QmlGraphicsKeyEvent *event); + void digit6Pressed(QmlGraphicsKeyEvent *event); + void digit7Pressed(QmlGraphicsKeyEvent *event); + void digit8Pressed(QmlGraphicsKeyEvent *event); + void digit9Pressed(QmlGraphicsKeyEvent *event); + + void leftPressed(QmlGraphicsKeyEvent *event); + void rightPressed(QmlGraphicsKeyEvent *event); + void upPressed(QmlGraphicsKeyEvent *event); + void downPressed(QmlGraphicsKeyEvent *event); + + void asteriskPressed(QmlGraphicsKeyEvent *event); + void numberSignPressed(QmlGraphicsKeyEvent *event); + void escapePressed(QmlGraphicsKeyEvent *event); + void returnPressed(QmlGraphicsKeyEvent *event); + void enterPressed(QmlGraphicsKeyEvent *event); + void deletePressed(QmlGraphicsKeyEvent *event); + void spacePressed(QmlGraphicsKeyEvent *event); + void backPressed(QmlGraphicsKeyEvent *event); + void cancelPressed(QmlGraphicsKeyEvent *event); + void selectPressed(QmlGraphicsKeyEvent *event); + void yesPressed(QmlGraphicsKeyEvent *event); + void noPressed(QmlGraphicsKeyEvent *event); + void context1Pressed(QmlGraphicsKeyEvent *event); + void context2Pressed(QmlGraphicsKeyEvent *event); + void context3Pressed(QmlGraphicsKeyEvent *event); + void context4Pressed(QmlGraphicsKeyEvent *event); + void callPressed(QmlGraphicsKeyEvent *event); + void hangupPressed(QmlGraphicsKeyEvent *event); + void flipPressed(QmlGraphicsKeyEvent *event); + void menuPressed(QmlGraphicsKeyEvent *event); + void volumeUpPressed(QmlGraphicsKeyEvent *event); + void volumeDownPressed(QmlGraphicsKeyEvent *event); private: virtual void keyPressed(QKeyEvent *event); @@ -1026,7 +1026,7 @@ private: static const SigMap sigMap[]; }; -const QFxKeysAttached::SigMap QFxKeysAttached::sigMap[] = { +const QmlGraphicsKeysAttached::SigMap QmlGraphicsKeysAttached::sigMap[] = { { Qt::Key_Left, "leftPressed" }, { Qt::Key_Right, "rightPressed" }, { Qt::Key_Up, "upPressed" }, @@ -1056,26 +1056,26 @@ const QFxKeysAttached::SigMap QFxKeysAttached::sigMap[] = { { 0, 0 } }; -bool QFxKeysAttachedPrivate::isConnected(const char *signalName) +bool QmlGraphicsKeysAttachedPrivate::isConnected(const char *signalName) { return isSignalConnected(signalIndex(signalName)); } -QFxKeysAttached::QFxKeysAttached(QObject *parent) -: QObject(*(new QFxKeysAttachedPrivate), parent), - QFxItemKeyFilter(qobject_cast(parent)) +QmlGraphicsKeysAttached::QmlGraphicsKeysAttached(QObject *parent) +: QObject(*(new QmlGraphicsKeysAttachedPrivate), parent), + QmlGraphicsItemKeyFilter(qobject_cast(parent)) { - Q_D(QFxKeysAttached); - d->item = qobject_cast(parent); + Q_D(QmlGraphicsKeysAttached); + d->item = qobject_cast(parent); } -QFxKeysAttached::~QFxKeysAttached() +QmlGraphicsKeysAttached::~QmlGraphicsKeysAttached() { } -void QFxKeysAttached::componentComplete() +void QmlGraphicsKeysAttached::componentComplete() { - Q_D(QFxKeysAttached); + Q_D(QmlGraphicsKeysAttached); if (d->item) { for (int ii = 0; ii < d->targets.count(); ++ii) { QGraphicsItem *targetItem = d->finalFocusProxy(d->targets.at(ii)); @@ -1087,9 +1087,9 @@ void QFxKeysAttached::componentComplete() } } -void QFxKeysAttached::keyPressed(QKeyEvent *event) +void QmlGraphicsKeysAttached::keyPressed(QKeyEvent *event) { - Q_D(QFxKeysAttached); + Q_D(QmlGraphicsKeysAttached); if (!d->enabled || d->inPress) { event->ignore(); return; @@ -1111,27 +1111,27 @@ void QFxKeysAttached::keyPressed(QKeyEvent *event) d->inPress = false; } - QFxKeyEvent ke(*event); + QmlGraphicsKeyEvent ke(*event); QByteArray keySignal = keyToSignal(event->key()); if (!keySignal.isEmpty()) { - keySignal += "(QFxKeyEvent*)"; + keySignal += "(QmlGraphicsKeyEvent*)"; if (d->isConnected(keySignal)) { // If we specifically handle a key then default to accepted ke.setAccepted(true); - int idx = QFxKeysAttached::staticMetaObject.indexOfSignal(keySignal); - metaObject()->method(idx).invoke(this, Q_ARG(QFxKeysAttached, &ke)); + int idx = QmlGraphicsKeysAttached::staticMetaObject.indexOfSignal(keySignal); + metaObject()->method(idx).invoke(this, Q_ARG(QmlGraphicsKeysAttached, &ke)); } } if (!ke.isAccepted()) emit pressed(&ke); event->setAccepted(ke.isAccepted()); - if (!event->isAccepted()) QFxItemKeyFilter::keyPressed(event); + if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyPressed(event); } -void QFxKeysAttached::keyReleased(QKeyEvent *event) +void QmlGraphicsKeysAttached::keyReleased(QKeyEvent *event) { - Q_D(QFxKeysAttached); + Q_D(QmlGraphicsKeysAttached); if (!d->enabled || d->inRelease) { event->ignore(); return; @@ -1152,16 +1152,16 @@ void QFxKeysAttached::keyReleased(QKeyEvent *event) d->inRelease = false; } - QFxKeyEvent ke(*event); + QmlGraphicsKeyEvent ke(*event); emit released(&ke); event->setAccepted(ke.isAccepted()); - if (!event->isAccepted()) QFxItemKeyFilter::keyReleased(event); + if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyReleased(event); } -void QFxKeysAttached::inputMethodEvent(QInputMethodEvent *event) +void QmlGraphicsKeysAttached::inputMethodEvent(QInputMethodEvent *event) { - Q_D(QFxKeysAttached); + Q_D(QmlGraphicsKeysAttached); if (d->item && !d->inIM && d->item->scene()) { d->inIM = true; for (int ii = 0; ii < d->targets.count(); ++ii) { @@ -1177,10 +1177,10 @@ void QFxKeysAttached::inputMethodEvent(QInputMethodEvent *event) } d->inIM = false; } - if (!event->isAccepted()) QFxItemKeyFilter::inputMethodEvent(event); + if (!event->isAccepted()) QmlGraphicsItemKeyFilter::inputMethodEvent(event); } -class QFxItemAccessor : public QGraphicsItem +class QmlGraphicsItemAccessor : public QGraphicsItem { public: QVariant doInputMethodQuery(Qt::InputMethodQuery query) const { @@ -1188,43 +1188,43 @@ public: } }; -QVariant QFxKeysAttached::inputMethodQuery(Qt::InputMethodQuery query) const +QVariant QmlGraphicsKeysAttached::inputMethodQuery(Qt::InputMethodQuery query) const { - Q_D(const QFxKeysAttached); + Q_D(const QmlGraphicsKeysAttached); if (d->item) { for (int ii = 0; ii < d->targets.count(); ++ii) { QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); if (i && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod) && i == d->imeItem) { //### how robust is i == d->imeItem check? - QVariant v = static_cast(i)->doInputMethodQuery(query); + QVariant v = static_cast(i)->doInputMethodQuery(query); if (v.type() == QVariant::RectF) v = d->item->mapRectFromItem(i, v.toRectF()); //### cost? return v; } } } - return QFxItemKeyFilter::inputMethodQuery(query); + return QmlGraphicsItemKeyFilter::inputMethodQuery(query); } -QFxKeysAttached *QFxKeysAttached::qmlAttachedProperties(QObject *obj) +QmlGraphicsKeysAttached *QmlGraphicsKeysAttached::qmlAttachedProperties(QObject *obj) { - return new QFxKeysAttached(obj); + return new QmlGraphicsKeysAttached(obj); } /*! - \class QFxItem - \brief The QFxItem class provides the most basic of all visual items in QML. + \class QmlGraphicsItem + \brief The QmlGraphicsItem class provides the most basic of all visual items in QML. - All visual items in Qt Declarative inherit from QFxItem. Although QFxItem + All visual items in Qt Declarative inherit from QmlGraphicsItem. Although QmlGraphicsItem has no visual appearance, it defines all the properties that are common across visual items - such as the x and y position, the width and height, \l {anchor-layout}{anchoring} and key handling. - You can subclass QFxItem to provide your own custom visual item that inherits + You can subclass QmlGraphicsItem to provide your own custom visual item that inherits these features. */ /*! - \qmlclass Item QFxItem + \qmlclass Item QmlGraphicsItem \brief The Item is the most basic of all visual items in QML. All visual items in Qt Declarative inherit from Item. Although Item @@ -1285,114 +1285,114 @@ QFxKeysAttached *QFxKeysAttached::qmlAttachedProperties(QObject *obj) */ /*! - \property QFxItem::baseline + \property QmlGraphicsItem::baseline \internal */ /*! - \property QFxItem::effect + \property QmlGraphicsItem::effect \internal */ /*! - \property QFxItem::focus + \property QmlGraphicsItem::focus \internal */ /*! - \property QFxItem::wantsFocus + \property QmlGraphicsItem::wantsFocus \internal */ /*! - \property QFxItem::transformOrigin + \property QmlGraphicsItem::transformOrigin \internal */ /*! - \fn void QFxItem::childrenRectChanged() + \fn void QmlGraphicsItem::childrenRectChanged() \internal */ /*! - \fn void QFxItem::baselineOffsetChanged() + \fn void QmlGraphicsItem::baselineOffsetChanged() \internal */ /*! - \fn void QFxItem::widthChanged() + \fn void QmlGraphicsItem::widthChanged() \internal */ /*! - \fn void QFxItem::heightChanged() + \fn void QmlGraphicsItem::heightChanged() \internal */ /*! - \fn void QFxItem::stateChanged(const QString &state) + \fn void QmlGraphicsItem::stateChanged(const QString &state) \internal */ /*! - \fn void QFxItem::parentChanged() + \fn void QmlGraphicsItem::parentChanged() \internal */ /*! - \fn void QFxItem::focusChanged() + \fn void QmlGraphicsItem::focusChanged() \internal */ /*! - \fn void QFxItem::wantsFocusChanged() + \fn void QmlGraphicsItem::wantsFocusChanged() \internal */ static inline void qfxitem_registerAnchorLine() { static bool registered = false; if (!registered) { - qRegisterMetaType("QFxAnchorLine"); + qRegisterMetaType("QmlGraphicsAnchorLine"); registered = true; } } /*! - \fn QFxItem::QFxItem(QFxItem *parent) + \fn QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItem *parent) - Constructs a QFxItem with the given \a parent. + Constructs a QmlGraphicsItem with the given \a parent. */ -QFxItem::QFxItem(QFxItem* parent) - : QGraphicsObject(*(new QFxItemPrivate), parent, 0) +QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItem* parent) + : QGraphicsObject(*(new QmlGraphicsItemPrivate), parent, 0) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); qfxitem_registerAnchorLine(); d->init(parent); } /*! \internal */ -QFxItem::QFxItem(QFxItemPrivate &dd, QFxItem *parent) +QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItemPrivate &dd, QmlGraphicsItem *parent) : QGraphicsObject(dd, parent, 0) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); qfxitem_registerAnchorLine(); d->init(parent); } /*! - Destroys the QFxItem. + Destroys the QmlGraphicsItem. */ -QFxItem::~QFxItem() +QmlGraphicsItem::~QmlGraphicsItem() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); for (int ii = 0; ii < d->dependantAnchors.count(); ++ii) { - QFxAnchors *anchor = d->dependantAnchors.at(ii); + QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); anchor->d_func()->clearItem(this); } if (!d->parent || (parentItem() && !parentItem()->QGraphicsItem::d_ptr->inDestructor)) for (int ii = 0; ii < d->dependantAnchors.count(); ++ii) { - QFxAnchors *anchor = d->dependantAnchors.at(ii); + QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); if (anchor->d_func()->item && anchor->d_func()->item->parentItem() != this) //child will be deleted anyway anchor->d_func()->updateOnComplete(); } @@ -1427,12 +1427,12 @@ QFxItem::~QFxItem() */ /*! - \property QFxItem::parent + \property QmlGraphicsItem::parent This property holds the parent of the item. */ -void QFxItem::setParentItem(QFxItem *parent) +void QmlGraphicsItem::setParentItem(QmlGraphicsItem *parent) { - QFxItem *oldParent = parentItem(); + QmlGraphicsItem *oldParent = parentItem(); if (parent == oldParent || !parent) return; QObject::setParent(parent); @@ -1440,11 +1440,11 @@ void QFxItem::setParentItem(QFxItem *parent) } /*! - Returns the QFxItem parent of this item. + Returns the QmlGraphicsItem parent of this item. */ -QFxItem *QFxItem::parentItem() const +QmlGraphicsItem *QmlGraphicsItem::parentItem() const { - return qobject_cast(QGraphicsObject::parentItem()); + return qobject_cast(QGraphicsObject::parentItem()); } /*! @@ -1475,12 +1475,12 @@ QFxItem *QFxItem::parentItem() const */ /*! - \property QFxItem::children + \property QmlGraphicsItem::children \internal */ /*! - \property QFxItem::resources + \property QmlGraphicsItem::resources \internal */ @@ -1493,86 +1493,86 @@ QFxItem *QFxItem::parentItem() const \sa componentComplete() */ -bool QFxItem::isComponentComplete() const +bool QmlGraphicsItem::isComponentComplete() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->_componentComplete; } /*! - \property QFxItem::anchors + \property QmlGraphicsItem::anchors \internal */ /*! \internal */ -QFxAnchors *QFxItem::anchors() +QmlGraphicsAnchors *QmlGraphicsItem::anchors() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); return d->anchors(); } -void QFxItemPrivate::data_removeAt(int) +void QmlGraphicsItemPrivate::data_removeAt(int) { // ### } -int QFxItemPrivate::data_count() const +int QmlGraphicsItemPrivate::data_count() const { // ### return 0; } -void QFxItemPrivate::data_append(QObject *o) +void QmlGraphicsItemPrivate::data_append(QObject *o) { - Q_Q(QFxItem); - QFxItem *i = qobject_cast(o); + Q_Q(QmlGraphicsItem); + QmlGraphicsItem *i = qobject_cast(o); if (i) q->fxChildren()->append(i); else resources_append(o); } -void QFxItemPrivate::data_insert(int, QObject *) +void QmlGraphicsItemPrivate::data_insert(int, QObject *) { // ### } -QObject *QFxItemPrivate::data_at(int) const +QObject *QmlGraphicsItemPrivate::data_at(int) const { // ### return 0; } -void QFxItemPrivate::data_clear() +void QmlGraphicsItemPrivate::data_clear() { // ### } -void QFxItemPrivate::resources_removeAt(int) +void QmlGraphicsItemPrivate::resources_removeAt(int) { // ### } -int QFxItemPrivate::resources_count() const +int QmlGraphicsItemPrivate::resources_count() const { - Q_Q(const QFxItem); + Q_Q(const QmlGraphicsItem); return q->children().count(); } -void QFxItemPrivate::resources_append(QObject *o) +void QmlGraphicsItemPrivate::resources_append(QObject *o) { - Q_Q(QFxItem); + Q_Q(QmlGraphicsItem); o->setParent(q); } -void QFxItemPrivate::resources_insert(int, QObject *) +void QmlGraphicsItemPrivate::resources_insert(int, QObject *) { // ### } -QObject *QFxItemPrivate::resources_at(int idx) const +QObject *QmlGraphicsItemPrivate::resources_at(int idx) const { - Q_Q(const QFxItem); + Q_Q(const QmlGraphicsItem); QObjectList children = q->children(); if (idx < children.count()) return children.at(idx); @@ -1580,50 +1580,50 @@ QObject *QFxItemPrivate::resources_at(int idx) const return 0; } -void QFxItemPrivate::resources_clear() +void QmlGraphicsItemPrivate::resources_clear() { // ### } -void QFxItemPrivate::children_removeAt(int) +void QmlGraphicsItemPrivate::children_removeAt(int) { // ### } -int QFxItemPrivate::children_count() const +int QmlGraphicsItemPrivate::children_count() const { - Q_Q(const QFxItem); + Q_Q(const QmlGraphicsItem); return q->childItems().count(); } -void QFxItemPrivate::children_append(QFxItem *i) +void QmlGraphicsItemPrivate::children_append(QmlGraphicsItem *i) { - Q_Q(QFxItem); + Q_Q(QmlGraphicsItem); i->setParentItem(q); } -void QFxItemPrivate::children_insert(int, QFxItem *) +void QmlGraphicsItemPrivate::children_insert(int, QmlGraphicsItem *) { // ### } -QFxItem *QFxItemPrivate::children_at(int idx) const +QmlGraphicsItem *QmlGraphicsItemPrivate::children_at(int idx) const { - Q_Q(const QFxItem); + Q_Q(const QmlGraphicsItem); QList children = q->childItems(); if (idx < children.count()) - return qobject_cast(children.at(idx)); + return qobject_cast(children.at(idx)); else return 0; } -void QFxItemPrivate::children_clear() +void QmlGraphicsItemPrivate::children_clear() { // ### } -void QFxItemPrivate::transform_removeAt(int i) +void QmlGraphicsItemPrivate::transform_removeAt(int i) { if (!transformData) return; @@ -1631,33 +1631,33 @@ void QFxItemPrivate::transform_removeAt(int i) dirtySceneTransform = 1; } -int QFxItemPrivate::transform_count() const +int QmlGraphicsItemPrivate::transform_count() const { return transformData ? transformData->graphicsTransforms.size() : 0; } -void QFxItemPrivate::transform_append(QGraphicsTransform *item) +void QmlGraphicsItemPrivate::transform_append(QGraphicsTransform *item) { appendGraphicsTransform(item); } -void QFxItemPrivate::transform_insert(int, QGraphicsTransform *) +void QmlGraphicsItemPrivate::transform_insert(int, QGraphicsTransform *) { // ### } -QGraphicsTransform *QFxItemPrivate::transform_at(int idx) const +QGraphicsTransform *QmlGraphicsItemPrivate::transform_at(int idx) const { if (!transformData) return 0; return transformData->graphicsTransforms.at(idx); } -void QFxItemPrivate::transform_clear() +void QmlGraphicsItemPrivate::transform_clear() { if (!transformData) return; - Q_Q(QFxItem); + Q_Q(QmlGraphicsItem); q->setTransformations(QList()); } @@ -1696,40 +1696,40 @@ void QFxItemPrivate::transform_clear() */ /*! - \property QFxItem::data + \property QmlGraphicsItem::data \internal */ /*! \internal */ -QmlList *QFxItem::data() +QmlList *QmlGraphicsItem::data() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); return &d->data; } /*! - \property QFxItem::childrenRect + \property QmlGraphicsItem::childrenRect \brief The geometry of an item's children. childrenRect provides an easy way to access the (collective) position and size of the item's children. */ -QRectF QFxItem::childrenRect() +QRectF QmlGraphicsItem::childrenRect() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); if (!d->_contents) { - d->_contents = new QFxContents; + d->_contents = new QmlGraphicsContents; d->_contents->setParent(this); d->_contents->setItem(this); } return d->_contents->rectF(); } -bool QFxItem::clip() const +bool QmlGraphicsItem::clip() const { return flags() & ItemClipsChildrenToShape; } -void QFxItem::setClip(bool c) +void QmlGraphicsItem::setClip(bool c) { setFlag(ItemClipsChildrenToShape, c); } @@ -1748,13 +1748,13 @@ void QFxItem::setClip(bool c) */ /*! - \property QFxItem::width + \property QmlGraphicsItem::width Defines the item's width relative to its parent. */ /*! - \property QFxItem::height + \property QmlGraphicsItem::height Defines the item's height relative to its parent. */ @@ -1842,15 +1842,15 @@ void QFxItem::setClip(bool c) geometry from \a oldGeometry to \a newGeometry. If the two geometries are the same, it doesn't do anything. */ -void QFxItem::geometryChanged(const QRectF &newGeometry, +void QmlGraphicsItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); if (d->_anchors) d->_anchors->d_func()->updateMe(); - if (transformOrigin() != QFxItem::TopLeft) + if (transformOrigin() != QmlGraphicsItem::TopLeft) setTransformOriginPoint(d->computeTransformOrigin()); if (newGeometry.x() != oldGeometry.x()) @@ -1863,15 +1863,15 @@ void QFxItem::geometryChanged(const QRectF &newGeometry, emit heightChanged(); for(int ii = 0; ii < d->dependantAnchors.count(); ++ii) { - QFxAnchors *anchor = d->dependantAnchors.at(ii); + QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); anchor->d_func()->update(this, newGeometry, oldGeometry); } } /*! \internal */ -void QFxItem::keyPressEvent(QKeyEvent *event) +void QmlGraphicsItem::keyPressEvent(QKeyEvent *event) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); if (d->keyHandler) d->keyHandler->keyPressed(event); else @@ -1879,9 +1879,9 @@ void QFxItem::keyPressEvent(QKeyEvent *event) } /*! \internal */ -void QFxItem::keyReleaseEvent(QKeyEvent *event) +void QmlGraphicsItem::keyReleaseEvent(QKeyEvent *event) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); if (d->keyHandler) d->keyHandler->keyReleased(event); else @@ -1889,9 +1889,9 @@ void QFxItem::keyReleaseEvent(QKeyEvent *event) } /*! \internal */ -void QFxItem::inputMethodEvent(QInputMethodEvent *event) +void QmlGraphicsItem::inputMethodEvent(QInputMethodEvent *event) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); if (d->keyHandler) d->keyHandler->inputMethodEvent(event); else @@ -1899,9 +1899,9 @@ void QFxItem::inputMethodEvent(QInputMethodEvent *event) } /*! \internal */ -QVariant QFxItem::inputMethodQuery(Qt::InputMethodQuery query) const +QVariant QmlGraphicsItem::inputMethodQuery(Qt::InputMethodQuery query) const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); QVariant v; if (d->keyHandler) v = d->keyHandler->inputMethodQuery(query); @@ -1931,54 +1931,54 @@ QVariant QFxItem::inputMethodQuery(Qt::InputMethodQuery query) const /*! \internal */ -QFxAnchorLine QFxItem::left() const +QmlGraphicsAnchorLine QmlGraphicsItem::left() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->anchorLines()->left; } /*! \internal */ -QFxAnchorLine QFxItem::right() const +QmlGraphicsAnchorLine QmlGraphicsItem::right() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->anchorLines()->right; } /*! \internal */ -QFxAnchorLine QFxItem::horizontalCenter() const +QmlGraphicsAnchorLine QmlGraphicsItem::horizontalCenter() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->anchorLines()->hCenter; } /*! \internal */ -QFxAnchorLine QFxItem::top() const +QmlGraphicsAnchorLine QmlGraphicsItem::top() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->anchorLines()->top; } /*! \internal */ -QFxAnchorLine QFxItem::bottom() const +QmlGraphicsAnchorLine QmlGraphicsItem::bottom() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->anchorLines()->bottom; } /*! \internal */ -QFxAnchorLine QFxItem::verticalCenter() const +QmlGraphicsAnchorLine QmlGraphicsItem::verticalCenter() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->anchorLines()->vCenter; } @@ -1986,39 +1986,39 @@ QFxAnchorLine QFxItem::verticalCenter() const /*! \internal */ -QFxAnchorLine QFxItem::baseline() const +QmlGraphicsAnchorLine QmlGraphicsItem::baseline() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->anchorLines()->baseline; } /*! - \property QFxItem::top + \property QmlGraphicsItem::top \internal */ /*! - \property QFxItem::bottom + \property QmlGraphicsItem::bottom \internal */ /*! - \property QFxItem::left + \property QmlGraphicsItem::left \internal */ /*! - \property QFxItem::right + \property QmlGraphicsItem::right \internal */ /*! - \property QFxItem::horizontalCenter + \property QmlGraphicsItem::horizontalCenter \internal */ /*! - \property QFxItem::verticalCenter + \property QmlGraphicsItem::verticalCenter \internal */ @@ -2104,7 +2104,7 @@ QFxAnchorLine QFxItem::baseline() const */ /*! - \property QFxItem::baselineOffset + \property QmlGraphicsItem::baselineOffset \brief The position of the item's baseline in local coordinates. The baseline of a Text item is the imaginary line on which the text @@ -2113,18 +2113,18 @@ QFxAnchorLine QFxItem::baseline() const For non-text items, a default baseline offset of 0 is used. */ -qreal QFxItem::baselineOffset() const +qreal QmlGraphicsItem::baselineOffset() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); if (!d->_baselineOffset.isValid()) { return 0.0; } else return d->_baselineOffset; } -void QFxItem::setBaselineOffset(qreal offset) +void QmlGraphicsItem::setBaselineOffset(qreal offset) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); if (offset == d->_baselineOffset) return; @@ -2132,7 +2132,7 @@ void QFxItem::setBaselineOffset(qreal offset) emit baselineOffsetChanged(); for(int ii = 0; ii < d->dependantAnchors.count(); ++ii) { - QFxAnchors *anchor = d->dependantAnchors.at(ii); + QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); anchor->d_func()->updateVerticalAnchors(); } } @@ -2254,9 +2254,9 @@ void QFxItem::setBaselineOffset(qreal offset) \sa setKeepMouseGrab() */ -bool QFxItem::keepMouseGrab() const +bool QmlGraphicsItem::keepMouseGrab() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->_keepMouse; } @@ -2278,9 +2278,9 @@ bool QFxItem::keepMouseGrab() const \sa keepMouseGrab */ -void QFxItem::setKeepMouseGrab(bool keep) +void QmlGraphicsItem::setKeepMouseGrab(bool keep) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); d->_keepMouse = keep; } @@ -2292,23 +2292,23 @@ void QFxItem::setKeepMouseGrab(bool keep) Subclasses overriding this function should call up to their base class. */ -void QFxItem::focusChanged(bool flag) +void QmlGraphicsItem::focusChanged(bool flag) { Q_UNUSED(flag); emit focusChanged(); } /*! \internal */ -QmlList *QFxItem::fxChildren() +QmlList *QmlGraphicsItem::fxChildren() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); return &(d->children); } /*! \internal */ -QmlList *QFxItem::resources() +QmlList *QmlGraphicsItem::resources() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); return &(d->resources); } @@ -2330,13 +2330,13 @@ QmlList *QFxItem::resources() */ /*! - \property QFxItem::states + \property QmlGraphicsItem::states \internal */ /*! \internal */ -QmlList* QFxItem::states() +QmlList* QmlGraphicsItem::states() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); return d->states()->statesProperty(); } @@ -2358,14 +2358,14 @@ QmlList* QFxItem::states() */ /*! - \property QFxItem::transitions + \property QmlGraphicsItem::transitions \internal */ /*! \internal */ -QmlList* QFxItem::transitions() +QmlList* QmlGraphicsItem::transitions() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); return d->states()->transitionsProperty(); } @@ -2401,7 +2401,7 @@ QmlList* QFxItem::transitions() */ /*! - \property QFxItem::clip + \property QmlGraphicsItem::clip This property holds whether clipping is enabled. if clipping is enabled, an item will clip its own painting, as well @@ -2437,14 +2437,14 @@ QmlList* QFxItem::transitions() */ /*! - \property QFxItem::state + \property QmlGraphicsItem::state \internal */ /*! \internal */ -QString QFxItem::state() const +QString QmlGraphicsItem::state() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); if (!d->_stateGroup) return QString(); else @@ -2452,9 +2452,9 @@ QString QFxItem::state() const } /*! \internal */ -void QFxItem::setState(const QString &state) +void QmlGraphicsItem::setState(const QString &state) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); d->states()->setState(state); } @@ -2466,14 +2466,14 @@ void QFxItem::setState(const QString &state) */ /*! - \property QFxItem::transform + \property QmlGraphicsItem::transform \internal */ /*! \internal */ -QmlList* QFxItem::transform() +QmlList* QmlGraphicsItem::transform() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); return &(d->transform); } @@ -2485,9 +2485,9 @@ QmlList* QFxItem::transform() \sa componentComplete(), isComponentComplete() */ -void QFxItem::classBegin() +void QmlGraphicsItem::classBegin() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); d->_componentComplete = false; if (d->_stateGroup) d->_stateGroup->classBegin(); @@ -2503,13 +2503,13 @@ void QFxItem::classBegin() processing until the component is complete an all bindings in the component have been resolved. */ -void QFxItem::componentComplete() +void QmlGraphicsItem::componentComplete() { #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer cc; + QmlPerfTimer cc; #endif - Q_D(QFxItem); + Q_D(QmlGraphicsItem); d->_componentComplete = true; if (d->_stateGroup) d->_stateGroup->componentComplete(); @@ -2521,9 +2521,9 @@ void QFxItem::componentComplete() d->keyHandler->componentComplete(); } -QmlStateGroup *QFxItemPrivate::states() +QmlStateGroup *QmlGraphicsItemPrivate::states() { - Q_Q(QFxItem); + Q_Q(QmlGraphicsItem); if (!_stateGroup) { _stateGroup = new QmlStateGroup(q); if (!_componentComplete) @@ -2535,55 +2535,55 @@ QmlStateGroup *QFxItemPrivate::states() return _stateGroup; } -QFxItemPrivate::AnchorLines::AnchorLines(QFxItem *q) +QmlGraphicsItemPrivate::AnchorLines::AnchorLines(QmlGraphicsItem *q) { left.item = q; - left.anchorLine = QFxAnchorLine::Left; + left.anchorLine = QmlGraphicsAnchorLine::Left; right.item = q; - right.anchorLine = QFxAnchorLine::Right; + right.anchorLine = QmlGraphicsAnchorLine::Right; hCenter.item = q; - hCenter.anchorLine = QFxAnchorLine::HCenter; + hCenter.anchorLine = QmlGraphicsAnchorLine::HCenter; top.item = q; - top.anchorLine = QFxAnchorLine::Top; + top.anchorLine = QmlGraphicsAnchorLine::Top; bottom.item = q; - bottom.anchorLine = QFxAnchorLine::Bottom; + bottom.anchorLine = QmlGraphicsAnchorLine::Bottom; vCenter.item = q; - vCenter.anchorLine = QFxAnchorLine::VCenter; + vCenter.anchorLine = QmlGraphicsAnchorLine::VCenter; baseline.item = q; - baseline.anchorLine = QFxAnchorLine::Baseline; + baseline.anchorLine = QmlGraphicsAnchorLine::Baseline; } -QPointF QFxItemPrivate::computeTransformOrigin() const +QPointF QmlGraphicsItemPrivate::computeTransformOrigin() const { - Q_Q(const QFxItem); + Q_Q(const QmlGraphicsItem); QRectF br = q->boundingRect(); switch(origin) { default: - case QFxItem::TopLeft: + case QmlGraphicsItem::TopLeft: return QPointF(0, 0); - case QFxItem::Top: + case QmlGraphicsItem::Top: return QPointF(br.width() / 2., 0); - case QFxItem::TopRight: + case QmlGraphicsItem::TopRight: return QPointF(br.width(), 0); - case QFxItem::Left: + case QmlGraphicsItem::Left: return QPointF(0, br.height() / 2.); - case QFxItem::Center: + case QmlGraphicsItem::Center: return QPointF(br.width() / 2., br.height() / 2.); - case QFxItem::Right: + case QmlGraphicsItem::Right: return QPointF(br.width(), br.height() / 2.); - case QFxItem::BottomLeft: + case QmlGraphicsItem::BottomLeft: return QPointF(0, br.height()); - case QFxItem::Bottom: + case QmlGraphicsItem::Bottom: return QPointF(br.width() / 2., br.height()); - case QFxItem::BottomRight: + case QmlGraphicsItem::BottomRight: return QPointF(br.width(), br.height()); } } /*! \internal */ -bool QFxItem::sceneEvent(QEvent *event) +bool QmlGraphicsItem::sceneEvent(QEvent *event) { bool rv = QGraphicsItem::sceneEvent(event); @@ -2596,7 +2596,7 @@ bool QFxItem::sceneEvent(QEvent *event) } /*! \internal */ -QVariant QFxItem::itemChange(GraphicsItemChange change, +QVariant QmlGraphicsItem::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemParentHasChanged) { @@ -2607,14 +2607,14 @@ QVariant QFxItem::itemChange(GraphicsItemChange change, } /*! \internal */ -QRectF QFxItem::boundingRect() const +QRectF QmlGraphicsItem::boundingRect() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return QRectF(0, 0, d->width, d->height); } /*! - \enum QFxItem::TransformOrigin + \enum QmlGraphicsItem::TransformOrigin Controls the point about which simple transforms like scale apply. @@ -2632,18 +2632,18 @@ QRectF QFxItem::boundingRect() const /*! Returns the current transform origin. */ -QFxItem::TransformOrigin QFxItem::transformOrigin() const +QmlGraphicsItem::TransformOrigin QmlGraphicsItem::transformOrigin() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->origin; } /*! Set the transform \a origin. */ -void QFxItem::setTransformOrigin(TransformOrigin origin) +void QmlGraphicsItem::setTransformOrigin(TransformOrigin origin) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); if (origin != d->origin) { d->origin = origin; QGraphicsItem::setTransformOriginPoint(d->computeTransformOrigin()); @@ -2651,7 +2651,7 @@ void QFxItem::setTransformOrigin(TransformOrigin origin) } /*! - \property QFxItem::smooth + \property QmlGraphicsItem::smooth \brief whether the item is smoothly transformed. This property is provided purely for the purpose of optimization. Turning @@ -2669,9 +2669,9 @@ void QFxItem::setTransformOrigin(TransformOrigin origin) \sa setSmoothTransform() */ -bool QFxItem::smoothTransform() const +bool QmlGraphicsItem::smoothTransform() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->smooth; } @@ -2681,24 +2681,24 @@ bool QFxItem::smoothTransform() const \sa smoothTransform() */ -void QFxItem::setSmoothTransform(bool smooth) +void QmlGraphicsItem::setSmoothTransform(bool smooth) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); if (d->smooth == smooth) return; d->smooth = smooth; update(); } -qreal QFxItem::width() const +qreal QmlGraphicsItem::width() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->width; } -void QFxItem::setWidth(qreal w) +void QmlGraphicsItem::setWidth(qreal w) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); d->widthValid = true; if (d->width == w) return; @@ -2713,22 +2713,22 @@ void QFxItem::setWidth(qreal w) QRectF(x(), y(), oldWidth, height())); } -void QFxItem::resetWidth() +void QmlGraphicsItem::resetWidth() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); d->widthValid = false; setImplicitWidth(implicitWidth()); } -qreal QFxItem::implicitWidth() const +qreal QmlGraphicsItem::implicitWidth() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->implicitWidth; } -void QFxItem::setImplicitWidth(qreal w) +void QmlGraphicsItem::setImplicitWidth(qreal w) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); d->implicitWidth = w; if (d->width == w || widthValid()) return; @@ -2743,21 +2743,21 @@ void QFxItem::setImplicitWidth(qreal w) QRectF(x(), y(), oldWidth, height())); } -bool QFxItem::widthValid() const +bool QmlGraphicsItem::widthValid() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->widthValid; } -qreal QFxItem::height() const +qreal QmlGraphicsItem::height() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->height; } -void QFxItem::setHeight(qreal h) +void QmlGraphicsItem::setHeight(qreal h) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); d->heightValid = true; if (d->height == h) return; @@ -2772,22 +2772,22 @@ void QFxItem::setHeight(qreal h) QRectF(x(), y(), width(), oldHeight)); } -void QFxItem::resetHeight() +void QmlGraphicsItem::resetHeight() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); d->heightValid = false; setImplicitHeight(implicitHeight()); } -qreal QFxItem::implicitHeight() const +qreal QmlGraphicsItem::implicitHeight() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->implicitHeight; } -void QFxItem::setImplicitHeight(qreal h) +void QmlGraphicsItem::setImplicitHeight(qreal h) { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); d->implicitHeight = h; if (d->height == h || heightValid()) return; @@ -2802,9 +2802,9 @@ void QFxItem::setImplicitHeight(qreal h) QRectF(x(), y(), width(), oldHeight)); } -bool QFxItem::heightValid() const +bool QmlGraphicsItem::heightValid() const { - Q_D(const QFxItem); + Q_D(const QmlGraphicsItem); return d->heightValid; } @@ -2815,7 +2815,7 @@ bool QFxItem::heightValid() const */ /*! \internal */ -bool QFxItem::wantsFocus() const +bool QmlGraphicsItem::wantsFocus() const { return focusItem() != 0; } @@ -2827,13 +2827,13 @@ bool QFxItem::wantsFocus() const */ /*! \internal */ -bool QFxItem::hasFocus() const +bool QmlGraphicsItem::hasFocus() const { return QGraphicsItem::hasFocus(); } /*! \internal */ -void QFxItem::setFocus(bool focus) +void QmlGraphicsItem::setFocus(bool focus) { if (focus) QGraphicsItem::setFocus(Qt::OtherFocusReason); @@ -2845,7 +2845,7 @@ void QFxItem::setFocus(bool focus) \reimp \internal */ -void QFxItem::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) +void QmlGraphicsItem::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) { } @@ -2853,15 +2853,15 @@ void QFxItem::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) \reimp \internal */ -bool QFxItem::event(QEvent *ev) +bool QmlGraphicsItem::event(QEvent *ev) { return QGraphicsObject::event(ev); } -QDebug operator<<(QDebug debug, QFxItem *item) +QDebug operator<<(QDebug debug, QmlGraphicsItem *item) { if (!item) { - debug << "QFxItem(0)"; + debug << "QmlGraphicsItem(0)"; return debug; } @@ -2872,13 +2872,13 @@ QDebug operator<<(QDebug debug, QFxItem *item) return debug; } -int QFxItemPrivate::consistentTime = -1; -void QFxItemPrivate::setConsistentTime(int t) +int QmlGraphicsItemPrivate::consistentTime = -1; +void QmlGraphicsItemPrivate::setConsistentTime(int t) { consistentTime = t; } -QTime QFxItemPrivate::currentTime() +QTime QmlGraphicsItemPrivate::currentTime() { if (consistentTime == -1) return QTime::currentTime(); @@ -2886,12 +2886,12 @@ QTime QFxItemPrivate::currentTime() return QTime(0, 0).addMSecs(consistentTime); } -void QFxItemPrivate::start(QTime &t) +void QmlGraphicsItemPrivate::start(QTime &t) { t = currentTime(); } -int QFxItemPrivate::elapsed(QTime &t) +int QmlGraphicsItemPrivate::elapsed(QTime &t) { int n = t.msecsTo(currentTime()); if (n < 0) // passed midnight @@ -2899,7 +2899,7 @@ int QFxItemPrivate::elapsed(QTime &t) return n; } -int QFxItemPrivate::restart(QTime &t) +int QmlGraphicsItemPrivate::restart(QTime &t) { QTime time = currentTime(); int n = t.msecsTo(time); @@ -2911,11 +2911,11 @@ int QFxItemPrivate::restart(QTime &t) QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxKeysAttached) -QML_DECLARE_TYPEINFO(QFxKeysAttached, QML_HAS_ATTACHED_PROPERTIES) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Keys,QFxKeysAttached) -QML_DECLARE_TYPE(QFxKeyNavigationAttached) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,KeyNavigation,QFxKeyNavigationAttached) +QML_DECLARE_TYPE(QmlGraphicsKeysAttached) +QML_DECLARE_TYPEINFO(QmlGraphicsKeysAttached, QML_HAS_ATTACHED_PROPERTIES) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Keys,QmlGraphicsKeysAttached) +QML_DECLARE_TYPE(QmlGraphicsKeyNavigationAttached) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,KeyNavigation,QmlGraphicsKeyNavigationAttached) #include "moc_qfxitem.cpp" #include "qfxitem.moc" diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index b2aefe2..ac094ad 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -58,19 +58,19 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QmlState; -class QFxAnchorLine; +class QmlGraphicsAnchorLine; class QmlTransition; -class QFxKeyEvent; -class QFxAnchors; -class QFxItemPrivate; -class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserStatus +class QmlGraphicsKeyEvent; +class QmlGraphicsAnchors; +class QmlGraphicsItemPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsItem : public QGraphicsObject, public QmlParserStatus { Q_OBJECT Q_INTERFACES(QmlParserStatus) - Q_PROPERTY(QFxItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL) + Q_PROPERTY(QmlGraphicsItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL) Q_PROPERTY(QmlList *data READ data DESIGNABLE false) - Q_PROPERTY(QmlList* children READ fxChildren DESIGNABLE false) + Q_PROPERTY(QmlList* children READ fxChildren DESIGNABLE false) Q_PROPERTY(QmlList* resources READ resources DESIGNABLE false) Q_PROPERTY(QmlList* states READ states DESIGNABLE false) Q_PROPERTY(QmlList* transitions READ transitions DESIGNABLE false) @@ -78,14 +78,14 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserSta Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL) Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL) Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL) - Q_PROPERTY(QFxAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL) - Q_PROPERTY(QFxAnchorLine left READ left CONSTANT FINAL) - Q_PROPERTY(QFxAnchorLine right READ right CONSTANT FINAL) - Q_PROPERTY(QFxAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL) - Q_PROPERTY(QFxAnchorLine top READ top CONSTANT FINAL) - Q_PROPERTY(QFxAnchorLine bottom READ bottom CONSTANT FINAL) - Q_PROPERTY(QFxAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL) - Q_PROPERTY(QFxAnchorLine baseline READ baseline CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine left READ left CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine right READ right CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine top READ top CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine bottom READ bottom CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine baseline READ baseline CONSTANT FINAL) Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged) Q_PROPERTY(bool clip READ clip WRITE setClip) // ### move to QGI/QGO, NOTIFY Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL) @@ -104,18 +104,18 @@ public: BottomLeft, Bottom, BottomRight }; - QFxItem(QFxItem *parent = 0); - virtual ~QFxItem(); + QmlGraphicsItem(QmlGraphicsItem *parent = 0); + virtual ~QmlGraphicsItem(); - QFxItem *parentItem() const; - void setParentItem(QFxItem *parent); - void setParent(QFxItem *parent) { setParentItem(parent); } + QmlGraphicsItem *parentItem() const; + void setParentItem(QmlGraphicsItem *parent); + void setParent(QmlGraphicsItem *parent) { setParentItem(parent); } QmlList *data(); - QmlList *fxChildren(); + QmlList *fxChildren(); QmlList *resources(); - QFxAnchors *anchors(); + QmlGraphicsAnchors *anchors(); QRectF childrenRect(); bool clip() const; @@ -190,22 +190,22 @@ protected: const QRectF &oldGeometry); protected: - QFxItem(QFxItemPrivate &dd, QFxItem *parent = 0); + QmlGraphicsItem(QmlGraphicsItemPrivate &dd, QmlGraphicsItem *parent = 0); private: // ### public? - QFxAnchorLine left() const; - QFxAnchorLine right() const; - QFxAnchorLine horizontalCenter() const; - QFxAnchorLine top() const; - QFxAnchorLine bottom() const; - QFxAnchorLine verticalCenter() const; - QFxAnchorLine baseline() const; + QmlGraphicsAnchorLine left() const; + QmlGraphicsAnchorLine right() const; + QmlGraphicsAnchorLine horizontalCenter() const; + QmlGraphicsAnchorLine top() const; + QmlGraphicsAnchorLine bottom() const; + QmlGraphicsAnchorLine verticalCenter() const; + QmlGraphicsAnchorLine baseline() const; friend class QmlStatePrivate; - friend class QFxAnchors; - Q_DISABLE_COPY(QFxItem) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxItem) + friend class QmlGraphicsAnchors; + Q_DISABLE_COPY(QmlGraphicsItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsItem) }; template @@ -224,11 +224,11 @@ T qobject_cast(QGraphicsItem *item) return qobject_cast(o); } -QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QFxItem *item); +QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QmlGraphicsItem *item); QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxItem) +QML_DECLARE_TYPE(QmlGraphicsItem) QML_DECLARE_TYPE(QGraphicsTransform) QML_DECLARE_TYPE(QGraphicsScale) QML_DECLARE_TYPE(QGraphicsRotation) diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h index 2c7440f..87b33be 100644 --- a/src/declarative/fx/qfxitem_p.h +++ b/src/declarative/fx/qfxitem_p.h @@ -67,18 +67,18 @@ QT_BEGIN_NAMESPACE class QNetworkReply; -class QFxItemKeyFilter; +class QmlGraphicsItemKeyFilter; //### merge into private? -class QFxContents : public QObject +class QmlGraphicsContents : public QObject { Q_OBJECT public: - QFxContents(); + QmlGraphicsContents(); QRectF rectF() const; - void setItem(QFxItem *item); + void setItem(QmlGraphicsItem *item); public Q_SLOTS: void calcHeight(); @@ -88,34 +88,34 @@ Q_SIGNALS: void rectChanged(); private: - QFxItem *m_item; + QmlGraphicsItem *m_item; qreal m_x; qreal m_y; qreal m_width; qreal m_height; }; -class QFxItemPrivate : public QGraphicsItemPrivate +class QmlGraphicsItemPrivate : public QGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxItem) + Q_DECLARE_PUBLIC(QmlGraphicsItem) public: - QFxItemPrivate() + QmlGraphicsItemPrivate() : _anchors(0), _contents(0), _baselineOffset(0), _anchorLines(0), - _stateGroup(0), origin(QFxItem::TopLeft), + _stateGroup(0), origin(QmlGraphicsItem::TopLeft), widthValid(false), heightValid(false), _componentComplete(true), _keepMouse(false), smooth(false), keyHandler(0), width(0), height(0), implicitWidth(0), implicitHeight(0) {} - ~QFxItemPrivate() + ~QmlGraphicsItemPrivate() { delete _anchors; } - void init(QFxItem *parent) + void init(QmlGraphicsItem *parent) { - Q_Q(QFxItem); + Q_Q(QmlGraphicsItem); if (parent) q->setParentItem(parent); @@ -136,7 +136,7 @@ public: void data_insert(int, QObject *); QObject *data_at(int) const; void data_clear(); - QML_DECLARE_LIST_PROXY(QFxItemPrivate, QObject *, data) + QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QObject *, data) // resources property void resources_removeAt(int); @@ -145,16 +145,16 @@ public: void resources_insert(int, QObject *); QObject *resources_at(int) const; void resources_clear(); - QML_DECLARE_LIST_PROXY(QFxItemPrivate, QObject *, resources) + QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QObject *, resources) // children property void children_removeAt(int); int children_count() const; - void children_append(QFxItem *); - void children_insert(int, QFxItem *); - QFxItem *children_at(int) const; + void children_append(QmlGraphicsItem *); + void children_insert(int, QmlGraphicsItem *); + QmlGraphicsItem *children_at(int) const; void children_clear(); - QML_DECLARE_LIST_PROXY(QFxItemPrivate, QFxItem *, children) + QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QmlGraphicsItem *, children) // transform property void transform_removeAt(int); @@ -163,53 +163,53 @@ public: void transform_insert(int, QGraphicsTransform *); QGraphicsTransform *transform_at(int) const; void transform_clear(); - QML_DECLARE_LIST_PROXY(QFxItemPrivate, QGraphicsTransform *, transform) + QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QGraphicsTransform *, transform) - QFxAnchors *anchors() { + QmlGraphicsAnchors *anchors() { if (!_anchors) { - Q_Q(QFxItem); - _anchors = new QFxAnchors; + Q_Q(QmlGraphicsItem); + _anchors = new QmlGraphicsAnchors; _anchors->setItem(q); if (!_componentComplete) _anchors->classBegin(); } return _anchors; } - QList dependantAnchors; - QFxAnchors *_anchors; - QFxContents *_contents; + QList dependantAnchors; + QmlGraphicsAnchors *_anchors; + QmlGraphicsContents *_contents; QmlNullableValue _baselineOffset; struct AnchorLines { - AnchorLines(QFxItem *); - QFxAnchorLine left; - QFxAnchorLine right; - QFxAnchorLine hCenter; - QFxAnchorLine top; - QFxAnchorLine bottom; - QFxAnchorLine vCenter; - QFxAnchorLine baseline; + AnchorLines(QmlGraphicsItem *); + QmlGraphicsAnchorLine left; + QmlGraphicsAnchorLine right; + QmlGraphicsAnchorLine hCenter; + QmlGraphicsAnchorLine top; + QmlGraphicsAnchorLine bottom; + QmlGraphicsAnchorLine vCenter; + QmlGraphicsAnchorLine baseline; }; mutable AnchorLines *_anchorLines; AnchorLines *anchorLines() const { - Q_Q(const QFxItem); + Q_Q(const QmlGraphicsItem); if (!_anchorLines) _anchorLines = - new AnchorLines(const_cast(q)); + new AnchorLines(const_cast(q)); return _anchorLines; } QmlStateGroup *states(); QmlStateGroup *_stateGroup; - QFxItem::TransformOrigin origin:4; + QmlGraphicsItem::TransformOrigin origin:4; bool widthValid:1; bool heightValid:1; bool _componentComplete:1; bool _keepMouse:1; bool smooth:1; - QFxItemKeyFilter *keyHandler; + QmlGraphicsItemKeyFilter *keyHandler; qreal width; qreal height; @@ -220,7 +220,7 @@ public: virtual void setPosHelper(const QPointF &pos) { - Q_Q(QFxItem); + Q_Q(QmlGraphicsItem); QRectF oldGeometry(this->pos.x(), this->pos.y(), width, height); QGraphicsItemPrivate::setPosHelper(pos); q->geometryChanged(QRectF(this->pos.x(), this->pos.y(), width, height), oldGeometry); diff --git a/src/declarative/fx/qfxlayoutitem.cpp b/src/declarative/fx/qfxlayoutitem.cpp index 61998e7..201dea2 100644 --- a/src/declarative/fx/qfxlayoutitem.cpp +++ b/src/declarative/fx/qfxlayoutitem.cpp @@ -45,17 +45,17 @@ QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,LayoutItem,QFxLayoutItem) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,LayoutItem,QmlGraphicsLayoutItem) /*! - \qmlclass LayoutItem QFxLayoutItem + \qmlclass LayoutItem QmlGraphicsLayoutItem \brief The LayoutItem element allows you to place your Fluid UI elements inside a classical Qt layout. */ /*! \internal - \class QFxLayoutItem - \brief The QFxLayoutItem class allows you to place your Fluid UI elements inside a classical Qt layout. + \class QmlGraphicsLayoutItem + \brief The QmlGraphicsLayoutItem class allows you to place your Fluid UI elements inside a classical Qt layout. */ @@ -77,13 +77,13 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,LayoutItem,QFxLayoutItem) The preferredSize property can be set to specify the preferred size of this LayoutItem */ -QFxLayoutItem::QFxLayoutItem(QFxItem* parent) - : QFxItem(parent), m_maximumSize(INT_MAX,INT_MAX), m_minimumSize(0,0), m_preferredSize(0,0) +QmlGraphicsLayoutItem::QmlGraphicsLayoutItem(QmlGraphicsItem* parent) + : QmlGraphicsItem(parent), m_maximumSize(INT_MAX,INT_MAX), m_minimumSize(0,0), m_preferredSize(0,0) { setGraphicsItem(this); } -void QFxLayoutItem::setGeometry(const QRectF & rect) +void QmlGraphicsLayoutItem::setGeometry(const QRectF & rect) { setX(rect.x()); setY(rect.y()); @@ -91,7 +91,7 @@ void QFxLayoutItem::setGeometry(const QRectF & rect) setHeight(rect.height()); } -QSizeF QFxLayoutItem::sizeHint(Qt::SizeHint w, const QSizeF &constraint) const +QSizeF QmlGraphicsLayoutItem::sizeHint(Qt::SizeHint w, const QSizeF &constraint) const { Q_UNUSED(constraint); if(w == Qt::MinimumSize){ diff --git a/src/declarative/fx/qfxlayoutitem.h b/src/declarative/fx/qfxlayoutitem.h index 7150554..35e6e74 100644 --- a/src/declarative/fx/qfxlayoutitem.h +++ b/src/declarative/fx/qfxlayoutitem.h @@ -42,7 +42,7 @@ #ifndef QFXGRAPHICSLAYOUTITEM_H #define QFXGRAPHICSLAYOUTITEM_H #include -#include +#include #include QT_BEGIN_HEADER @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxLayoutItem : public QFxItem, public QGraphicsLayoutItem +class QmlGraphicsLayoutItem : public QmlGraphicsItem, public QGraphicsLayoutItem { Q_OBJECT Q_INTERFACES(QGraphicsLayoutItem) @@ -59,7 +59,7 @@ class QFxLayoutItem : public QFxItem, public QGraphicsLayoutItem Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize NOTIFY minimumSizeChanged) Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize NOTIFY preferredSizeChanged) public: - QFxLayoutItem(QFxItem* parent=0); + QmlGraphicsLayoutItem(QmlGraphicsItem* parent=0); QSizeF maximumSize() const { return m_maximumSize; } void setMaximumSize(const QSizeF &s) { if(s==m_maximumSize) return; m_maximumSize = s; emit maximumSizeChanged(); } @@ -87,7 +87,7 @@ private: QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxLayoutItem) +QML_DECLARE_TYPE(QmlGraphicsLayoutItem) QT_END_HEADER #endif diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 18c3062..f85380a 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -49,18 +49,18 @@ #include QT_BEGIN_NAMESPACE -class QFxListViewAttached : public QObject +class QmlGraphicsListViewAttached : public QObject { Q_OBJECT public: - QFxListViewAttached(QObject *parent) + QmlGraphicsListViewAttached(QObject *parent) : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {} - ~QFxListViewAttached() { + ~QmlGraphicsListViewAttached() { attachedProperties.remove(parent()); } - Q_PROPERTY(QFxListView *view READ view CONSTANT) - QFxListView *view() { return m_view; } + Q_PROPERTY(QmlGraphicsListView *view READ view CONSTANT) + QmlGraphicsListView *view() { return m_view; } Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) bool isCurrentItem() const { return m_isCurrent; } @@ -98,10 +98,10 @@ public: } } - static QFxListViewAttached *properties(QObject *obj) { - QFxListViewAttached *rv = attachedProperties.value(obj); + static QmlGraphicsListViewAttached *properties(QObject *obj) { + QmlGraphicsListViewAttached *rv = attachedProperties.value(obj); if (!rv) { - rv = new QFxListViewAttached(obj); + rv = new QmlGraphicsListViewAttached(obj); attachedProperties.insert(obj, rv); } return rv; @@ -119,64 +119,64 @@ Q_SIGNALS: void remove(); public: - QFxListView *m_view; + QmlGraphicsListView *m_view; bool m_isCurrent; mutable QString m_section; QString m_prevSection; bool m_delayRemove; - static QHash attachedProperties; + static QHash attachedProperties; }; -QHash QFxListViewAttached::attachedProperties; +QHash QmlGraphicsListViewAttached::attachedProperties; //---------------------------------------------------------------------------- class FxListItem { public: - FxListItem(QFxItem *i, QFxListView *v) : item(i), view(v) { - attached = QFxListViewAttached::properties(item); + FxListItem(QmlGraphicsItem *i, QmlGraphicsListView *v) : item(i), view(v) { + attached = QmlGraphicsListViewAttached::properties(item); attached->m_view = view; } ~FxListItem() {} - qreal position() const { return (view->orientation() == QFxListView::Vertical ? item->y() : item->x()); } - int size() const { return (view->orientation() == QFxListView::Vertical ? item->height() : item->width()); } + qreal position() const { return (view->orientation() == QmlGraphicsListView::Vertical ? item->y() : item->x()); } + int size() const { return (view->orientation() == QmlGraphicsListView::Vertical ? item->height() : item->width()); } qreal endPosition() const { - return (view->orientation() == QFxListView::Vertical + return (view->orientation() == QmlGraphicsListView::Vertical ? item->y() + (item->height() > 0 ? item->height() : 1) : item->x() + (item->width() > 0 ? item->width() : 1)) - 1; } void setPosition(qreal pos) { - if (view->orientation() == QFxListView::Vertical) { + if (view->orientation() == QmlGraphicsListView::Vertical) { item->setY(pos); } else { item->setX(pos); } } - QFxItem *item; - QFxListView *view; - QFxListViewAttached *attached; + QmlGraphicsItem *item; + QmlGraphicsListView *view; + QmlGraphicsListViewAttached *attached; int index; }; //---------------------------------------------------------------------------- -class QFxListViewPrivate : public QFxFlickablePrivate +class QmlGraphicsListViewPrivate : public QmlGraphicsFlickablePrivate { - Q_DECLARE_PUBLIC(QFxListView) + Q_DECLARE_PUBLIC(QmlGraphicsListView) public: - QFxListViewPrivate() - : model(0), currentItem(0), orient(QFxListView::Vertical) + QmlGraphicsListViewPrivate() + : model(0), currentItem(0), orient(QmlGraphicsListView::Vertical) , visiblePos(0), visibleIndex(0) , averageSize(100.0), currentIndex(-1), requestedIndex(-1) , highlightRangeStart(0), highlightRangeEnd(0) , highlightComponent(0), highlight(0), trackedItem(0) , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0.0) - , highlightMoveSpeed(400), highlightResizeSpeed(400), highlightRange(QFxListView::NoHighlightRange) + , highlightMoveSpeed(400), highlightResizeSpeed(400), highlightRange(QmlGraphicsListView::NoHighlightRange) , ownModel(false), wrap(false), autoHighlight(true) , haveHighlightRange(false) {} @@ -198,19 +198,19 @@ public: } qreal position() const { - Q_Q(const QFxListView); - return orient == QFxListView::Vertical ? q->viewportY() : q->viewportX(); + Q_Q(const QmlGraphicsListView); + return orient == QmlGraphicsListView::Vertical ? q->viewportY() : q->viewportX(); } void setPosition(qreal pos) { - Q_Q(QFxListView); - if (orient == QFxListView::Vertical) + Q_Q(QmlGraphicsListView); + if (orient == QmlGraphicsListView::Vertical) q->setViewportY(pos); else q->setViewportX(pos); } qreal size() const { - Q_Q(const QFxListView); - return orient == QFxListView::Vertical ? q->height() : q->width(); + Q_Q(const QmlGraphicsListView); + return orient == QmlGraphicsListView::Vertical ? q->height() : q->width(); } qreal startPosition() const { @@ -261,7 +261,7 @@ public: } QString sectionAt(int modelIndex) { - Q_Q(QFxListView); + Q_Q(QmlGraphicsListView); if (FxListItem *item = visibleItem(modelIndex)) return item->attached->section(); QString section; @@ -344,8 +344,8 @@ public: } void updateViewport() { - Q_Q(QFxListView); - if (orient == QFxListView::Vertical) + Q_Q(QmlGraphicsListView); + if (orient == QmlGraphicsListView::Vertical) q->setViewportHeight(endPosition() - startPosition()); else q->setViewportWidth(endPosition() - startPosition()); @@ -382,12 +382,12 @@ public: virtual void flickX(qreal velocity); virtual void flickY(qreal velocity); - QFxVisualModel *model; + QmlGraphicsVisualModel *model; QVariant modelVariant; QList visibleItems; - QHash unrequestedItems; + QHash unrequestedItems; FxListItem *currentItem; - QFxListView::Orientation orient; + QmlGraphicsListView::Orientation orient; int visiblePos; int visibleIndex; qreal averageSize; @@ -408,7 +408,7 @@ public: qreal spacing; qreal highlightMoveSpeed; qreal highlightResizeSpeed; - QFxListView::HighlightRangeMode highlightRange; + QmlGraphicsListView::HighlightRangeMode highlightRange; bool ownModel : 1; bool wrap : 1; @@ -416,15 +416,15 @@ public: bool haveHighlightRange : 1; }; -void QFxListViewPrivate::init() +void QmlGraphicsListViewPrivate::init() { - Q_Q(QFxListView); + Q_Q(QmlGraphicsListView); q->setFlag(QGraphicsItem::ItemIsFocusScope); QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(refill())); QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(refill())); } -void QFxListViewPrivate::clear() +void QmlGraphicsListViewPrivate::clear() { for (int i = 0; i < visibleItems.count(); ++i) releaseItem(visibleItems.at(i)); @@ -438,13 +438,13 @@ void QFxListViewPrivate::clear() trackedItem = 0; } -FxListItem *QFxListViewPrivate::createItem(int modelIndex) +FxListItem *QmlGraphicsListViewPrivate::createItem(int modelIndex) { - Q_Q(QFxListView); + Q_Q(QmlGraphicsListView); // create object requestedIndex = modelIndex; FxListItem *listItem = 0; - if (QFxItem *item = model->item(modelIndex, false)) { + if (QmlGraphicsItem *item = model->item(modelIndex, false)) { listItem = new FxListItem(item, q); listItem->index = modelIndex; // initialise attached properties @@ -463,7 +463,7 @@ FxListItem *QFxListViewPrivate::createItem(int modelIndex) model->completeItem(); listItem->item->setZValue(1); listItem->item->setParent(q->viewport()); - if (orient == QFxListView::Vertical) + if (orient == QmlGraphicsListView::Vertical) QObject::connect(listItem->item, SIGNAL(heightChanged()), q, SLOT(itemResized())); else QObject::connect(listItem->item, SIGNAL(widthChanged()), q, SLOT(itemResized())); @@ -473,14 +473,14 @@ FxListItem *QFxListViewPrivate::createItem(int modelIndex) return listItem; } -void QFxListViewPrivate::releaseItem(FxListItem *item) +void QmlGraphicsListViewPrivate::releaseItem(FxListItem *item) { - Q_Q(QFxListView); + Q_Q(QmlGraphicsListView); if (!item) return; if (trackedItem == item) { - const char *notifier1 = orient == QFxListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); - const char *notifier2 = orient == QFxListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); + const char *notifier1 = orient == QmlGraphicsListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); + const char *notifier2 = orient == QmlGraphicsListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged())); trackedItem = 0; @@ -488,7 +488,7 @@ void QFxListViewPrivate::releaseItem(FxListItem *item) if (model->release(item->item) == 0) { // item was not destroyed, and we no longer reference it. unrequestedItems.insert(item->item, model->indexOf(item->item, q)); - if (orient == QFxListView::Vertical) + if (orient == QmlGraphicsListView::Vertical) QObject::disconnect(item->item, SIGNAL(heightChanged()), q, SLOT(itemResized())); else QObject::disconnect(item->item, SIGNAL(widthChanged()), q, SLOT(itemResized())); @@ -496,9 +496,9 @@ void QFxListViewPrivate::releaseItem(FxListItem *item) delete item; } -void QFxListViewPrivate::refill(qreal from, qreal to) +void QmlGraphicsListViewPrivate::refill(qreal from, qreal to) { - Q_Q(QFxListView); + Q_Q(QmlGraphicsListView); if (!isValid() || !q->isComponentComplete()) return; from -= buffer; @@ -566,9 +566,9 @@ void QFxListViewPrivate::refill(qreal from, qreal to) } } -void QFxListViewPrivate::layout() +void QmlGraphicsListViewPrivate::layout() { - Q_Q(QFxListView); + Q_Q(QmlGraphicsListView); if (!visibleItems.isEmpty()) { int oldEnd = visibleItems.last()->endPosition(); int pos = visibleItems.first()->endPosition() + spacing + 1; @@ -590,38 +590,38 @@ void QFxListViewPrivate::layout() updateViewport(); } -void QFxListViewPrivate::updateUnrequestedIndexes() +void QmlGraphicsListViewPrivate::updateUnrequestedIndexes() { - Q_Q(QFxListView); - QHash::iterator it; + Q_Q(QmlGraphicsListView); + QHash::iterator it; for (it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) *it = model->indexOf(it.key(), q); } -void QFxListViewPrivate::updateUnrequestedPositions() +void QmlGraphicsListViewPrivate::updateUnrequestedPositions() { - QHash::const_iterator it; + QHash::const_iterator it; for (it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) { if (visibleItem(*it)) continue; - if (orient == QFxListView::Vertical) + if (orient == QmlGraphicsListView::Vertical) it.key()->setY(positionAt(*it)); else it.key()->setX(positionAt(*it)); } } -void QFxListViewPrivate::updateTrackedItem() +void QmlGraphicsListViewPrivate::updateTrackedItem() { - Q_Q(QFxListView); + Q_Q(QmlGraphicsListView); FxListItem *item = currentItem; if (highlight) item = highlight; FxListItem *oldTracked = trackedItem; - const char *notifier1 = orient == QFxListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); - const char *notifier2 = orient == QFxListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); + const char *notifier1 = orient == QmlGraphicsListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); + const char *notifier2 = orient == QmlGraphicsListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); if (trackedItem && item != trackedItem) { QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); @@ -638,9 +638,9 @@ void QFxListViewPrivate::updateTrackedItem() q->trackedPositionChanged(); } -void QFxListViewPrivate::createHighlight() +void QmlGraphicsListViewPrivate::createHighlight() { - Q_Q(QFxListView); + Q_Q(QmlGraphicsListView); if (highlight) { if (trackedItem == highlight) trackedItem = 0; @@ -654,13 +654,13 @@ void QFxListViewPrivate::createHighlight() } if (currentItem) { - QFxItem *item = 0; + QmlGraphicsItem *item = 0; if (highlightComponent) { QmlContext *highlightContext = new QmlContext(qmlContext(q)); QObject *nobj = highlightComponent->create(highlightContext); if (nobj) { highlightContext->setParent(nobj); - item = qobject_cast(nobj); + item = qobject_cast(nobj); if (!item) { delete nobj; } else { @@ -670,22 +670,22 @@ void QFxListViewPrivate::createHighlight() delete highlightContext; } } else { - item = new QFxItem; + item = new QmlGraphicsItem; item->setParent(q->viewport()); } if (item) { item->setZValue(0); highlight = new FxListItem(item, q); - if (orient == QFxListView::Vertical) + if (orient == QmlGraphicsListView::Vertical) highlight->item->setHeight(currentItem->item->height()); else highlight->item->setWidth(currentItem->item->width()); - const QLatin1String posProp(orient == QFxListView::Vertical ? "y" : "x"); + const QLatin1String posProp(orient == QmlGraphicsListView::Vertical ? "y" : "x"); highlightPosAnimator = new QmlEaseFollow(q); highlightPosAnimator->setTarget(QmlMetaProperty(highlight->item, posProp)); highlightPosAnimator->setVelocity(highlightMoveSpeed); highlightPosAnimator->setEnabled(autoHighlight); - const QLatin1String sizeProp(orient == QFxListView::Vertical ? "height" : "width"); + const QLatin1String sizeProp(orient == QmlGraphicsListView::Vertical ? "height" : "width"); highlightSizeAnimator = new QmlEaseFollow(q); highlightSizeAnimator->setVelocity(highlightResizeSpeed); highlightSizeAnimator->setTarget(QmlMetaProperty(highlight->item, sizeProp)); @@ -694,7 +694,7 @@ void QFxListViewPrivate::createHighlight() } } -void QFxListViewPrivate::updateHighlight() +void QmlGraphicsListViewPrivate::updateHighlight() { if ((!currentItem && highlight) || (currentItem && !highlight)) createHighlight(); @@ -702,7 +702,7 @@ void QFxListViewPrivate::updateHighlight() // auto-update highlight highlightPosAnimator->setSourceValue(currentItem->position()); highlightSizeAnimator->setSourceValue(currentItem->size()); - if (orient == QFxListView::Vertical) { + if (orient == QmlGraphicsListView::Vertical) { if (highlight->item->width() == 0) highlight->item->setWidth(currentItem->item->width()); } else { @@ -713,7 +713,7 @@ void QFxListViewPrivate::updateHighlight() updateTrackedItem(); } -void QFxListViewPrivate::updateSections() +void QmlGraphicsListViewPrivate::updateSections() { if (!sectionExpression.isEmpty()) { QString prevSection; @@ -721,7 +721,7 @@ void QFxListViewPrivate::updateSections() prevSection = sectionAt(visibleIndex-1); for (int i = 0; i < visibleItems.count(); ++i) { if (visibleItems.at(i)->index != -1) { - QFxListViewAttached *attached = visibleItems.at(i)->attached; + QmlGraphicsListViewAttached *attached = visibleItems.at(i)->attached; attached->setPrevSection(prevSection); prevSection = attached->section(); } @@ -729,7 +729,7 @@ void QFxListViewPrivate::updateSections() } } -void QFxListViewPrivate::updateCurrentSection() +void QmlGraphicsListViewPrivate::updateCurrentSection() { if (sectionExpression.isEmpty() || visibleItems.isEmpty()) { currentSection = QString(); @@ -745,9 +745,9 @@ void QFxListViewPrivate::updateCurrentSection() currentSection = visibleItems.first()->attached->section(); } -void QFxListViewPrivate::updateCurrent(int modelIndex) +void QmlGraphicsListViewPrivate::updateCurrent(int modelIndex) { - Q_Q(QFxListView); + Q_Q(QmlGraphicsListView); if (!isValid() || modelIndex < 0 || modelIndex >= model->count()) { if (currentItem) { currentItem->attached->setIsCurrentItem(false); @@ -787,7 +787,7 @@ void QFxListViewPrivate::updateCurrent(int modelIndex) releaseItem(oldCurrentItem); } -void QFxListViewPrivate::updateAverage() +void QmlGraphicsListViewPrivate::updateAverage() { if (!visibleItems.count()) return; @@ -797,21 +797,21 @@ void QFxListViewPrivate::updateAverage() averageSize = sum / visibleItems.count(); } -void QFxListViewPrivate::fixupPosition() +void QmlGraphicsListViewPrivate::fixupPosition() { - if (orient == QFxListView::Vertical) + if (orient == QmlGraphicsListView::Vertical) fixupY(); else fixupX(); } -void QFxListViewPrivate::fixupY() +void QmlGraphicsListViewPrivate::fixupY() { - QFxFlickablePrivate::fixupY(); - if (orient == QFxListView::Horizontal) + QmlGraphicsFlickablePrivate::fixupY(); + if (orient == QmlGraphicsListView::Horizontal) return; - if (haveHighlightRange && highlightRange == QFxListView::StrictlyEnforceRange) { + if (haveHighlightRange && highlightRange == QmlGraphicsListView::StrictlyEnforceRange) { if (currentItem && highlight && currentItem->position() != highlight->position()) { moveReason = Mouse; timeline.clear(); @@ -820,13 +820,13 @@ void QFxListViewPrivate::fixupY() } } -void QFxListViewPrivate::fixupX() +void QmlGraphicsListViewPrivate::fixupX() { - QFxFlickablePrivate::fixupX(); - if (orient == QFxListView::Vertical) + QmlGraphicsFlickablePrivate::fixupX(); + if (orient == QmlGraphicsListView::Vertical) return; - if (haveHighlightRange && highlightRange == QFxListView::StrictlyEnforceRange) { + if (haveHighlightRange && highlightRange == QmlGraphicsListView::StrictlyEnforceRange) { if (currentItem && highlight && currentItem->position() != highlight->position()) { moveReason = Mouse; timeline.clear(); @@ -835,12 +835,12 @@ void QFxListViewPrivate::fixupX() } } -void QFxListViewPrivate::flickX(qreal velocity) +void QmlGraphicsListViewPrivate::flickX(qreal velocity) { - Q_Q(QFxListView); + Q_Q(QmlGraphicsListView); - if (!haveHighlightRange || highlightRange != QFxListView::StrictlyEnforceRange) { - QFxFlickablePrivate::flickX(velocity); + if (!haveHighlightRange || highlightRange != QmlGraphicsListView::StrictlyEnforceRange) { + QmlGraphicsFlickablePrivate::flickX(velocity); return; } @@ -893,12 +893,12 @@ void QFxListViewPrivate::flickX(qreal velocity) } } -void QFxListViewPrivate::flickY(qreal velocity) +void QmlGraphicsListViewPrivate::flickY(qreal velocity) { - Q_Q(QFxListView); + Q_Q(QmlGraphicsListView); - if (!haveHighlightRange || highlightRange != QFxListView::StrictlyEnforceRange) { - QFxFlickablePrivate::flickY(velocity); + if (!haveHighlightRange || highlightRange != QmlGraphicsListView::StrictlyEnforceRange) { + QmlGraphicsFlickablePrivate::flickY(velocity); return; } @@ -977,16 +977,16 @@ void QFxListViewPrivate::flickY(qreal velocity) the model would be implemented in C++, or perhaps via a SQL data source. */ -QFxListView::QFxListView(QFxItem *parent) - : QFxFlickable(*(new QFxListViewPrivate), parent) +QmlGraphicsListView::QmlGraphicsListView(QmlGraphicsItem *parent) + : QmlGraphicsFlickable(*(new QmlGraphicsListViewPrivate), parent) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); d->init(); } -QFxListView::~QFxListView() +QmlGraphicsListView::~QmlGraphicsListView() { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); d->clear(); if (d->ownModel) delete d->model; @@ -1079,27 +1079,27 @@ QFxListView::~QFxListView() \sa {qmlmodels}{Data Models} */ -QVariant QFxListView::model() const +QVariant QmlGraphicsListView::model() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->modelVariant; } -void QFxListView::setModel(const QVariant &model) +void QmlGraphicsListView::setModel(const QVariant &model) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); - disconnect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); - disconnect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); + disconnect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + disconnect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); } d->clear(); d->modelVariant = model; QObject *object = qvariant_cast(model); - QFxVisualModel *vim = 0; - if (object && (vim = qobject_cast(object))) { + QmlGraphicsVisualModel *vim = 0; + if (object && (vim = qobject_cast(object))) { if (d->ownModel) { delete d->model; d->ownModel = false; @@ -1107,10 +1107,10 @@ void QFxListView::setModel(const QVariant &model) d->model = vim; } else { if (!d->ownModel) { - d->model = new QFxVisualDataModel(qmlContext(this)); + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); d->ownModel = true; } - if (QFxVisualDataModel *dataModel = qobject_cast(d->model)) + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) dataModel->setModel(model); } if (d->model) { @@ -1121,8 +1121,8 @@ void QFxListView::setModel(const QVariant &model) connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); - connect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); - connect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); + connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + connect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); refill(); emit countChanged(); } @@ -1136,25 +1136,25 @@ void QFxListView::setModel(const QVariant &model) Here is an example delegate: \snippet doc/src/snippets/declarative/listview/listview.qml 0 */ -QmlComponent *QFxListView::delegate() const +QmlComponent *QmlGraphicsListView::delegate() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); if (d->model) { - if (QFxVisualDataModel *dataModel = qobject_cast(d->model)) + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) return dataModel->delegate(); } return 0; } -void QFxListView::setDelegate(QmlComponent *delegate) +void QmlGraphicsListView::setDelegate(QmlComponent *delegate) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); if (!d->ownModel) { - d->model = new QFxVisualDataModel(qmlContext(this)); + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); d->ownModel = true; } - if (QFxVisualDataModel *dataModel = qobject_cast(d->model)) { + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) { dataModel->setDelegate(delegate); d->updateCurrent(d->currentIndex); refill(); @@ -1169,16 +1169,16 @@ void QFxListView::setDelegate(QmlComponent *delegate) \c currentItem is the current item. Note that the position of the current item may only be approximate until it becomes visible in the view. */ -int QFxListView::currentIndex() const +int QmlGraphicsListView::currentIndex() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->currentIndex; } -void QFxListView::setCurrentIndex(int index) +void QmlGraphicsListView::setCurrentIndex(int index) { - Q_D(QFxListView); - d->moveReason = QFxListViewPrivate::Other; + Q_D(QmlGraphicsListView); + d->moveReason = QmlGraphicsListViewPrivate::Other; if (d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) { cancelFlick(); d->updateCurrent(index); @@ -1187,9 +1187,9 @@ void QFxListView::setCurrentIndex(int index) } } -QFxItem *QFxListView::currentItem() +QmlGraphicsItem *QmlGraphicsListView::currentItem() { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); if (!d->currentItem) return 0; return d->currentItem->item; @@ -1199,9 +1199,9 @@ QFxItem *QFxListView::currentItem() \qmlproperty int ListView::count This property holds the number of items in the view. */ -int QFxListView::count() const +int QmlGraphicsListView::count() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); if (d->model) return d->model->count(); return 0; @@ -1224,15 +1224,15 @@ int QFxListView::count() const \sa highlightFollowsCurrentItem */ -QmlComponent *QFxListView::highlight() const +QmlComponent *QmlGraphicsListView::highlight() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->highlightComponent; } -void QFxListView::setHighlight(QmlComponent *highlight) +void QmlGraphicsListView::setHighlight(QmlComponent *highlight) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); delete d->highlightComponent; d->highlightComponent = highlight; d->updateCurrent(d->currentIndex); @@ -1256,15 +1256,15 @@ void QFxListView::setHighlight(QmlComponent *highlight) \sa highlight */ -bool QFxListView::highlightFollowsCurrentItem() const +bool QmlGraphicsListView::highlightFollowsCurrentItem() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->autoHighlight; } -void QFxListView::setHighlightFollowsCurrentItem(bool autoHighlight) +void QmlGraphicsListView::setHighlightFollowsCurrentItem(bool autoHighlight) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); d->autoHighlight = autoHighlight; if (d->highlightPosAnimator) { d->highlightPosAnimator->setEnabled(d->autoHighlight); @@ -1296,41 +1296,41 @@ void QFxListView::setHighlightFollowsCurrentItem(bool autoHighlight) Note that a valid range requires preferredHighlightEnd to be greater than or equal to preferredHighlightBegin. */ -qreal QFxListView::preferredHighlightBegin() const +qreal QmlGraphicsListView::preferredHighlightBegin() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->highlightRangeStart; } -void QFxListView::setPreferredHighlightBegin(qreal start) +void QmlGraphicsListView::setPreferredHighlightBegin(qreal start) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); d->highlightRangeStart = start; d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; } -qreal QFxListView::preferredHighlightEnd() const +qreal QmlGraphicsListView::preferredHighlightEnd() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->highlightRangeEnd; } -void QFxListView::setPreferredHighlightEnd(qreal end) +void QmlGraphicsListView::setPreferredHighlightEnd(qreal end) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); d->highlightRangeEnd = end; d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; } -QFxListView::HighlightRangeMode QFxListView::highlightRangeMode() const +QmlGraphicsListView::HighlightRangeMode QmlGraphicsListView::highlightRangeMode() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->highlightRange; } -void QFxListView::setHighlightRangeMode(HighlightRangeMode mode) +void QmlGraphicsListView::setHighlightRangeMode(HighlightRangeMode mode) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); d->highlightRange = mode; d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; } @@ -1340,15 +1340,15 @@ void QFxListView::setHighlightRangeMode(HighlightRangeMode mode) This property holds the spacing to leave between items. */ -qreal QFxListView::spacing() const +qreal QmlGraphicsListView::spacing() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->spacing; } -void QFxListView::setSpacing(qreal spacing) +void QmlGraphicsListView::setSpacing(qreal spacing) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); if (spacing != d->spacing) { d->spacing = spacing; d->layout(); @@ -1367,18 +1367,18 @@ void QFxListView::setSpacing(qreal spacing) Horizontal Example: \image ListViewHorizontal.png */ -QFxListView::Orientation QFxListView::orientation() const +QmlGraphicsListView::Orientation QmlGraphicsListView::orientation() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->orient; } -void QFxListView::setOrientation(QFxListView::Orientation orientation) +void QmlGraphicsListView::setOrientation(QmlGraphicsListView::Orientation orientation) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); if (d->orient != orientation) { d->orient = orientation; - if (d->orient == QFxListView::Vertical) + if (d->orient == QmlGraphicsListView::Vertical) setViewportWidth(-1); else setViewportHeight(-1); @@ -1396,15 +1396,15 @@ void QFxListView::setOrientation(QFxListView::Orientation orientation) If this property is true then key presses to move off of one end of the list will cause the current item to jump to the other end. */ -bool QFxListView::isWrapEnabled() const +bool QmlGraphicsListView::isWrapEnabled() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->wrap; } -void QFxListView::setWrapEnabled(bool wrap) +void QmlGraphicsListView::setWrapEnabled(bool wrap) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); d->wrap = wrap; } @@ -1416,15 +1416,15 @@ void QFxListView::setWrapEnabled(bool wrap) and below the bottom of the list to cache. Setting this value can make scrolling the list smoother at the expense of additional memory usage. */ -int QFxListView::cacheBuffer() const +int QmlGraphicsListView::cacheBuffer() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->buffer; } -void QFxListView::setCacheBuffer(int b) +void QmlGraphicsListView::setCacheBuffer(int b) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); if (d->buffer != b) { d->buffer = b; if (isComponentComplete()) @@ -1446,24 +1446,24 @@ void QFxListView::setCacheBuffer(int b) \image ListViewSections.png */ -QString QFxListView::sectionExpression() const +QString QmlGraphicsListView::sectionExpression() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->sectionExpression; } -void QFxListView::setSectionExpression(const QString &expression) +void QmlGraphicsListView::setSectionExpression(const QString &expression) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); if (d->sectionExpression != expression) { d->sectionExpression = expression; emit sectionExpressionChanged(); } } -QString QFxListView::currentSection() const +QString QmlGraphicsListView::currentSection() const { - Q_D(const QFxListView); + Q_D(const QmlGraphicsListView); return d->currentSection; } @@ -1472,15 +1472,15 @@ QString QFxListView::currentSection() const This property holds the moving animation speed of the highlight delegate. */ -qreal QFxListView::highlightMoveSpeed() const +qreal QmlGraphicsListView::highlightMoveSpeed() const { - Q_D(const QFxListView);\ + Q_D(const QmlGraphicsListView);\ return d->highlightMoveSpeed; } -void QFxListView::setHighlightMoveSpeed(qreal speed) +void QmlGraphicsListView::setHighlightMoveSpeed(qreal speed) { - Q_D(QFxListView);\ + Q_D(QmlGraphicsListView);\ if (d->highlightMoveSpeed != speed) { d->highlightMoveSpeed = speed; @@ -1493,15 +1493,15 @@ void QFxListView::setHighlightMoveSpeed(qreal speed) This property holds the resizing animation speed of the highlight delegate. */ -qreal QFxListView::highlightResizeSpeed() const +qreal QmlGraphicsListView::highlightResizeSpeed() const { - Q_D(const QFxListView);\ + Q_D(const QmlGraphicsListView);\ return d->highlightResizeSpeed; } -void QFxListView::setHighlightResizeSpeed(qreal speed) +void QmlGraphicsListView::setHighlightResizeSpeed(qreal speed) { - Q_D(QFxListView);\ + Q_D(QmlGraphicsListView);\ if (d->highlightResizeSpeed != speed) { d->highlightResizeSpeed = speed; @@ -1509,14 +1509,14 @@ void QFxListView::setHighlightResizeSpeed(qreal speed) } } -void QFxListView::viewportMoved() +void QmlGraphicsListView::viewportMoved() { - Q_D(QFxListView); - QFxFlickable::viewportMoved(); + Q_D(QmlGraphicsListView); + QmlGraphicsFlickable::viewportMoved(); refill(); if (isFlicking() || d->moving) - d->moveReason = QFxListViewPrivate::Mouse; - if (d->moveReason == QFxListViewPrivate::Mouse) { + d->moveReason = QmlGraphicsListViewPrivate::Mouse; + if (d->moveReason == QmlGraphicsListViewPrivate::Mouse) { if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) { int idx = d->snapIndex(); if (idx >= 0 && idx != d->currentIndex) @@ -1532,11 +1532,11 @@ void QFxListView::viewportMoved() } } -qreal QFxListView::minYExtent() const +qreal QmlGraphicsListView::minYExtent() const { - Q_D(const QFxListView); - if (d->orient == QFxListView::Horizontal) - return QFxFlickable::minYExtent(); + Q_D(const QmlGraphicsListView); + if (d->orient == QmlGraphicsListView::Horizontal) + return QmlGraphicsFlickable::minYExtent(); qreal extent = -d->startPosition(); if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) extent += d->highlightRangeStart; @@ -1544,11 +1544,11 @@ qreal QFxListView::minYExtent() const return extent; } -qreal QFxListView::maxYExtent() const +qreal QmlGraphicsListView::maxYExtent() const { - Q_D(const QFxListView); - if (d->orient == QFxListView::Horizontal) - return QFxFlickable::maxYExtent(); + Q_D(const QmlGraphicsListView); + if (d->orient == QmlGraphicsListView::Horizontal) + return QmlGraphicsFlickable::maxYExtent(); qreal extent; if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) extent = -(d->positionAt(count()-1) - d->highlightRangeEnd); @@ -1560,11 +1560,11 @@ qreal QFxListView::maxYExtent() const return extent; } -qreal QFxListView::minXExtent() const +qreal QmlGraphicsListView::minXExtent() const { - Q_D(const QFxListView); - if (d->orient == QFxListView::Vertical) - return QFxFlickable::minXExtent(); + Q_D(const QmlGraphicsListView); + if (d->orient == QmlGraphicsListView::Vertical) + return QmlGraphicsFlickable::minXExtent(); qreal extent = -d->startPosition(); if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) extent += d->highlightRangeStart; @@ -1572,11 +1572,11 @@ qreal QFxListView::minXExtent() const return extent; } -qreal QFxListView::maxXExtent() const +qreal QmlGraphicsListView::maxXExtent() const { - Q_D(const QFxListView); - if (d->orient == QFxListView::Vertical) - return QFxFlickable::maxXExtent(); + Q_D(const QmlGraphicsListView); + if (d->orient == QmlGraphicsListView::Vertical) + return QmlGraphicsFlickable::maxXExtent(); qreal extent; if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) extent = -(d->positionAt(count()-1) - d->highlightRangeEnd); @@ -1588,18 +1588,18 @@ qreal QFxListView::maxXExtent() const return extent; } -void QFxListView::keyPressEvent(QKeyEvent *event) +void QmlGraphicsListView::keyPressEvent(QKeyEvent *event) { - Q_D(QFxListView); - QFxFlickable::keyPressEvent(event); + Q_D(QmlGraphicsListView); + QmlGraphicsFlickable::keyPressEvent(event); if (event->isAccepted()) return; if (d->model && d->model->count() && d->interactive) { - if ((d->orient == QFxListView::Horizontal && event->key() == Qt::Key_Left) - || (d->orient == QFxListView::Vertical && event->key() == Qt::Key_Up)) { + if ((d->orient == QmlGraphicsListView::Horizontal && event->key() == Qt::Key_Left) + || (d->orient == QmlGraphicsListView::Vertical && event->key() == Qt::Key_Up)) { if (currentIndex() > 0 || (d->wrap && !event->isAutoRepeat())) { - d->moveReason = QFxListViewPrivate::Key; + d->moveReason = QmlGraphicsListViewPrivate::Key; decrementCurrentIndex(); event->accept(); return; @@ -1607,10 +1607,10 @@ void QFxListView::keyPressEvent(QKeyEvent *event) event->accept(); return; } - } else if ((d->orient == QFxListView::Horizontal && event->key() == Qt::Key_Right) - || (d->orient == QFxListView::Vertical && event->key() == Qt::Key_Down)) { + } else if ((d->orient == QmlGraphicsListView::Horizontal && event->key() == Qt::Key_Right) + || (d->orient == QmlGraphicsListView::Vertical && event->key() == Qt::Key_Down)) { if (currentIndex() < d->model->count() - 1 || (d->wrap && !event->isAutoRepeat())) { - d->moveReason = QFxListViewPrivate::Key; + d->moveReason = QmlGraphicsListViewPrivate::Key; incrementCurrentIndex(); event->accept(); return; @@ -1620,7 +1620,7 @@ void QFxListView::keyPressEvent(QKeyEvent *event) } } } - d->moveReason = QFxListViewPrivate::Other; + d->moveReason = QmlGraphicsListViewPrivate::Other; event->ignore(); } @@ -1630,9 +1630,9 @@ void QFxListView::keyPressEvent(QKeyEvent *event) Increments the current index. The current index will wrap if keyNavigationWraps is true and it is currently at the end. */ -void QFxListView::incrementCurrentIndex() +void QmlGraphicsListView::incrementCurrentIndex() { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); if (currentIndex() < d->model->count() - 1 || d->wrap) { int index = currentIndex()+1; cancelFlick(); @@ -1646,9 +1646,9 @@ void QFxListView::incrementCurrentIndex() Decrements the current index. The current index will wrap if keyNavigationWraps is true and it is currently at the beginning. */ -void QFxListView::decrementCurrentIndex() +void QmlGraphicsListView::decrementCurrentIndex() { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); if (currentIndex() > 0 || d->wrap) { int index = currentIndex()-1; cancelFlick(); @@ -1656,28 +1656,28 @@ void QFxListView::decrementCurrentIndex() } } -void QFxListView::componentComplete() +void QmlGraphicsListView::componentComplete() { - Q_D(QFxListView); - QFxFlickable::componentComplete(); + Q_D(QmlGraphicsListView); + QmlGraphicsFlickable::componentComplete(); if (d->currentIndex < 0) d->updateCurrent(0); refill(); d->fixupPosition(); } -void QFxListView::refill() +void QmlGraphicsListView::refill() { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); d->refill(d->position(), d->position()+d->size()-1); } -void QFxListView::trackedPositionChanged() +void QmlGraphicsListView::trackedPositionChanged() { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); if (!d->trackedItem) return; - if (!isFlicking() && !d->moving && d->moveReason != QFxListViewPrivate::Mouse) { + if (!isFlicking() && !d->moving && d->moveReason != QmlGraphicsListViewPrivate::Mouse) { const qreal trackedPos = d->trackedItem->position(); const qreal viewPos = d->position(); if (d->haveHighlightRange) { @@ -1726,19 +1726,19 @@ void QFxListView::trackedPositionChanged() } } -void QFxListView::itemResized() +void QmlGraphicsListView::itemResized() { - Q_D(QFxListView); - QFxItem *item = qobject_cast(sender()); + Q_D(QmlGraphicsListView); + QmlGraphicsItem *item = qobject_cast(sender()); if (item) { d->layout(); d->fixupPosition(); } } -void QFxListView::itemsInserted(int modelIndex, int count) +void QmlGraphicsListView::itemsInserted(int modelIndex, int count) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); d->updateUnrequestedIndexes(); if (!d->visibleItems.count() || d->model->count() <= 1) { d->layout(); @@ -1824,9 +1824,9 @@ void QFxListView::itemsInserted(int modelIndex, int count) emit countChanged(); } -void QFxListView::itemsRemoved(int modelIndex, int count) +void QmlGraphicsListView::itemsRemoved(int modelIndex, int count) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); d->updateUnrequestedIndexes(); bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; if (!d->mapRangeFromModel(modelIndex, count)) { @@ -1921,9 +1921,9 @@ void QFxListView::itemsRemoved(int modelIndex, int count) emit countChanged(); } -void QFxListView::destroyRemoved() +void QmlGraphicsListView::destroyRemoved() { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); for (QList::Iterator it = d->visibleItems.begin(); it != d->visibleItems.end();) { FxListItem *listItem = *it; @@ -1939,9 +1939,9 @@ void QFxListView::destroyRemoved() d->layout(); } -void QFxListView::itemsMoved(int from, int to, int count) +void QmlGraphicsListView::itemsMoved(int from, int to, int count) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); qreal firstItemPos = d->visibleItems.first()->position(); QHash moved; int moveBy = 0; @@ -2005,31 +2005,31 @@ void QFxListView::itemsMoved(int from, int to, int count) d->layout(); } -void QFxListView::createdItem(int index, QFxItem *item) +void QmlGraphicsListView::createdItem(int index, QmlGraphicsItem *item) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); if (d->requestedIndex != index) { item->setParentItem(viewport()); d->unrequestedItems.insert(item, index); - if (d->orient == QFxListView::Vertical) + if (d->orient == QmlGraphicsListView::Vertical) item->setY(d->positionAt(index)); else item->setX(d->positionAt(index)); } } -void QFxListView::destroyingItem(QFxItem *item) +void QmlGraphicsListView::destroyingItem(QmlGraphicsItem *item) { - Q_D(QFxListView); + Q_D(QmlGraphicsListView); d->unrequestedItems.remove(item); } -QFxListViewAttached *QFxListView::qmlAttachedProperties(QObject *obj) +QmlGraphicsListViewAttached *QmlGraphicsListView::qmlAttachedProperties(QObject *obj) { - return QFxListViewAttached::properties(obj); + return QmlGraphicsListViewAttached::properties(obj); } -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ListView,QFxListView) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ListView,QmlGraphicsListView) QT_END_NAMESPACE #include "qfxlistview.moc" diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index b31b951..19e88c7 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -51,18 +51,18 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxVisualModel; -class QFxListViewAttached; -class QFxListViewPrivate; -class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable +class QmlGraphicsVisualModel; +class QmlGraphicsListViewAttached; +class QmlGraphicsListViewPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable { Q_OBJECT - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxListView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsListView) Q_PROPERTY(QVariant model READ model WRITE setModel) Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QFxItem *currentItem READ currentItem NOTIFY currentIndexChanged) + Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) @@ -85,8 +85,8 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_CLASSINFO("DefaultProperty", "data") public: - QFxListView(QFxItem *parent=0); - ~QFxListView(); + QmlGraphicsListView(QmlGraphicsItem *parent=0); + ~QmlGraphicsListView(); QVariant model() const; void setModel(const QVariant &); @@ -97,7 +97,7 @@ public: int currentIndex() const; void setCurrentIndex(int idx); - QFxItem *currentItem(); + QmlGraphicsItem *currentItem(); int count() const; QmlComponent *highlight() const; @@ -139,7 +139,7 @@ public: qreal highlightResizeSpeed() const; void setHighlightResizeSpeed(qreal); - static QFxListViewAttached *qmlAttachedProperties(QObject *); + static QmlGraphicsListViewAttached *qmlAttachedProperties(QObject *); public Q_SLOTS: void incrementCurrentIndex(); @@ -172,14 +172,14 @@ private Q_SLOTS: void itemsRemoved(int index, int count); void itemsMoved(int from, int to, int count); void destroyRemoved(); - void createdItem(int index, QFxItem *item); - void destroyingItem(QFxItem *item); + void createdItem(int index, QmlGraphicsItem *item); + void destroyingItem(QmlGraphicsItem *item); }; QT_END_NAMESPACE -QML_DECLARE_TYPEINFO(QFxListView, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QFxListView) +QML_DECLARE_TYPEINFO(QmlGraphicsListView, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QmlGraphicsListView) QT_END_HEADER diff --git a/src/declarative/fx/qfxloader.cpp b/src/declarative/fx/qfxloader.cpp index da4a280..af51282 100644 --- a/src/declarative/fx/qfxloader.cpp +++ b/src/declarative/fx/qfxloader.cpp @@ -44,16 +44,16 @@ QT_BEGIN_NAMESPACE -QFxLoaderPrivate::QFxLoaderPrivate() -: item(0), component(0), ownComponent(false), resizeMode(QFxLoader::SizeLoaderToItem) +QmlGraphicsLoaderPrivate::QmlGraphicsLoaderPrivate() +: item(0), component(0), ownComponent(false), resizeMode(QmlGraphicsLoader::SizeLoaderToItem) { } -QFxLoaderPrivate::~QFxLoaderPrivate() +QmlGraphicsLoaderPrivate::~QmlGraphicsLoaderPrivate() { } -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QFxLoader) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QmlGraphicsLoader) /*! \qmlclass Loader @@ -78,22 +78,22 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QFxLoader) /*! \internal - \class QFxLoader + \class QmlGraphicsLoader \qmlclass Loader */ /*! - Create a new QFxLoader instance. + Create a new QmlGraphicsLoader instance. */ -QFxLoader::QFxLoader(QFxItem *parent) - : QFxItem(*(new QFxLoaderPrivate), parent) +QmlGraphicsLoader::QmlGraphicsLoader(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsLoaderPrivate), parent) { } /*! Destroy the loader instance. */ -QFxLoader::~QFxLoader() +QmlGraphicsLoader::~QmlGraphicsLoader() { } @@ -104,15 +104,15 @@ QFxLoader::~QFxLoader() \sa status, progress */ -QUrl QFxLoader::source() const +QUrl QmlGraphicsLoader::source() const { - Q_D(const QFxLoader); + Q_D(const QmlGraphicsLoader); return d->source; } -void QFxLoader::setSource(const QUrl &url) +void QmlGraphicsLoader::setSource(const QUrl &url) { - Q_D(QFxLoader); + Q_D(QmlGraphicsLoader); if (d->source == url) return; @@ -167,15 +167,15 @@ void QFxLoader::setSource(const QUrl &url) \sa source */ -QmlComponent *QFxLoader::sourceComponent() const +QmlComponent *QmlGraphicsLoader::sourceComponent() const { - Q_D(const QFxLoader); + Q_D(const QmlGraphicsLoader); return d->component; } -void QFxLoader::setSourceComponent(QmlComponent *comp) +void QmlGraphicsLoader::setSourceComponent(QmlComponent *comp) { - Q_D(QFxLoader); + Q_D(QmlGraphicsLoader); if (comp == d->component) return; @@ -211,9 +211,9 @@ void QFxLoader::setSourceComponent(QmlComponent *comp) } } -void QFxLoaderPrivate::_q_sourceLoaded() +void QmlGraphicsLoaderPrivate::_q_sourceLoaded() { - Q_Q(QFxLoader); + Q_Q(QmlGraphicsLoader); if (component) { QmlContext *ctxt = new QmlContext(qmlContext(q)); @@ -229,14 +229,14 @@ void QFxLoaderPrivate::_q_sourceLoaded() QObject *obj = component->create(ctxt); if (obj) { - item = qobject_cast(obj); + item = qobject_cast(obj); if (item) { item->setParentItem(q); // item->setFocus(true); - QFxItem *resizeItem = 0; - if (resizeMode == QFxLoader::SizeLoaderToItem) + QmlGraphicsItem *resizeItem = 0; + if (resizeMode == QmlGraphicsLoader::SizeLoaderToItem) resizeItem = item; - else if (resizeMode == QFxLoader::SizeItemToLoader) + else if (resizeMode == QmlGraphicsLoader::SizeItemToLoader) resizeItem = q; if (resizeItem) { QObject::connect(resizeItem, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); @@ -269,12 +269,12 @@ void QFxLoaderPrivate::_q_sourceLoaded() \sa progress */ -QFxLoader::Status QFxLoader::status() const +QmlGraphicsLoader::Status QmlGraphicsLoader::status() const { - Q_D(const QFxLoader); + Q_D(const QmlGraphicsLoader); if (d->component) - return static_cast(d->component->status()); + return static_cast(d->component->status()); if (d->item) return Ready; @@ -290,9 +290,9 @@ QFxLoader::Status QFxLoader::status() const \sa status */ -qreal QFxLoader::progress() const +qreal QmlGraphicsLoader::progress() const { - Q_D(const QFxLoader); + Q_D(const QmlGraphicsLoader); if (d->item) return 1.0; @@ -315,20 +315,20 @@ qreal QFxLoader::progress() const The default resizeMode is SizeLoaderToItem. */ -QFxLoader::ResizeMode QFxLoader::resizeMode() const +QmlGraphicsLoader::ResizeMode QmlGraphicsLoader::resizeMode() const { - Q_D(const QFxLoader); + Q_D(const QmlGraphicsLoader); return d->resizeMode; } -void QFxLoader::setResizeMode(ResizeMode mode) +void QmlGraphicsLoader::setResizeMode(ResizeMode mode) { - Q_D(QFxLoader); + Q_D(QmlGraphicsLoader); if (mode == d->resizeMode) return; if (d->item) { - QFxItem *resizeItem = 0; + QmlGraphicsItem *resizeItem = 0; if (d->resizeMode == SizeLoaderToItem) resizeItem = d->item; else if (d->resizeMode == SizeItemToLoader) @@ -342,7 +342,7 @@ void QFxLoader::setResizeMode(ResizeMode mode) d->resizeMode = mode; if (d->item) { - QFxItem *resizeItem = 0; + QmlGraphicsItem *resizeItem = 0; if (d->resizeMode == SizeLoaderToItem) resizeItem = d->item; else if (d->resizeMode == SizeItemToLoader) @@ -356,17 +356,17 @@ void QFxLoader::setResizeMode(ResizeMode mode) } } -void QFxLoaderPrivate::_q_updateSize() +void QmlGraphicsLoaderPrivate::_q_updateSize() { - Q_Q(QFxLoader); + Q_Q(QmlGraphicsLoader); if (!item) return; switch (resizeMode) { - case QFxLoader::SizeLoaderToItem: + case QmlGraphicsLoader::SizeLoaderToItem: q->setImplicitWidth(item->width()); q->setImplicitHeight(item->height()); break; - case QFxLoader::SizeItemToLoader: + case QmlGraphicsLoader::SizeItemToLoader: item->setWidth(q->width()); item->setHeight(q->height()); break; @@ -379,9 +379,9 @@ void QFxLoaderPrivate::_q_updateSize() \qmlproperty Item Loader::item This property holds the top-level item created from source. */ -QFxItem *QFxLoader::item() const +QmlGraphicsItem *QmlGraphicsLoader::item() const { - Q_D(const QFxLoader); + Q_D(const QmlGraphicsLoader); return d->item; } diff --git a/src/declarative/fx/qfxloader.h b/src/declarative/fx/qfxloader.h index b967465..b838ed0 100644 --- a/src/declarative/fx/qfxloader.h +++ b/src/declarative/fx/qfxloader.h @@ -50,8 +50,8 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxLoaderPrivate; -class Q_DECLARATIVE_EXPORT QFxLoader : public QFxItem +class QmlGraphicsLoaderPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsLoader : public QmlGraphicsItem { Q_OBJECT Q_ENUMS(Status) @@ -60,14 +60,14 @@ class Q_DECLARATIVE_EXPORT QFxLoader : public QFxItem Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(QmlComponent *sourceComponent READ sourceComponent WRITE setSourceComponent NOTIFY sourceChanged) Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) - Q_PROPERTY(QFxItem *item READ item NOTIFY itemChanged) + Q_PROPERTY(QmlGraphicsItem *item READ item NOTIFY itemChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) //### sourceItem public: - QFxLoader(QFxItem *parent=0); - virtual ~QFxLoader(); + QmlGraphicsLoader(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsLoader(); QUrl source() const; void setSource(const QUrl &); @@ -83,7 +83,7 @@ public: ResizeMode resizeMode() const; void setResizeMode(ResizeMode mode); - QFxItem *item() const; + QmlGraphicsItem *item() const; Q_SIGNALS: void itemChanged(); @@ -92,15 +92,15 @@ Q_SIGNALS: void progressChanged(); private: - Q_DISABLE_COPY(QFxLoader) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxLoader) + Q_DISABLE_COPY(QmlGraphicsLoader) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsLoader) Q_PRIVATE_SLOT(d_func(), void _q_sourceLoaded()) Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxLoader) +QML_DECLARE_TYPE(QmlGraphicsLoader) QT_END_HEADER diff --git a/src/declarative/fx/qfxloader_p.h b/src/declarative/fx/qfxloader_p.h index 0700fcd..336c884 100644 --- a/src/declarative/fx/qfxloader_p.h +++ b/src/declarative/fx/qfxloader_p.h @@ -59,19 +59,19 @@ QT_BEGIN_NAMESPACE class QmlContext; -class QFxLoaderPrivate : public QFxItemPrivate +class QmlGraphicsLoaderPrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxLoader) + Q_DECLARE_PUBLIC(QmlGraphicsLoader) public: - QFxLoaderPrivate(); - ~QFxLoaderPrivate(); + QmlGraphicsLoaderPrivate(); + ~QmlGraphicsLoaderPrivate(); QUrl source; - QFxItem *item; + QmlGraphicsItem *item; QmlComponent *component; bool ownComponent; - QFxLoader::ResizeMode resizeMode; + QmlGraphicsLoader::ResizeMode resizeMode; void _q_sourceLoaded(); void _q_updateSize(); diff --git a/src/declarative/fx/qfxmouseregion.cpp b/src/declarative/fx/qfxmouseregion.cpp index 315a273..8acf32c 100644 --- a/src/declarative/fx/qfxmouseregion.cpp +++ b/src/declarative/fx/qfxmouseregion.cpp @@ -49,72 +49,72 @@ QT_BEGIN_NAMESPACE static const qreal DragThreshold = 5; static const int PressAndHoldDelay = 800; -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Drag,QFxDrag) -QFxDrag::QFxDrag(QObject *parent) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Drag,QmlGraphicsDrag) +QmlGraphicsDrag::QmlGraphicsDrag(QObject *parent) : QObject(parent), _target(0), _axis(XandYAxis), _xmin(0), _xmax(0), _ymin(0), _ymax(0) { } -QFxDrag::~QFxDrag() +QmlGraphicsDrag::~QmlGraphicsDrag() { } -QFxItem *QFxDrag::target() const +QmlGraphicsItem *QmlGraphicsDrag::target() const { return _target; } -void QFxDrag::setTarget(QFxItem *t) +void QmlGraphicsDrag::setTarget(QmlGraphicsItem *t) { _target = t; } -QFxDrag::Axis QFxDrag::axis() const +QmlGraphicsDrag::Axis QmlGraphicsDrag::axis() const { return _axis; } -void QFxDrag::setAxis(QFxDrag::Axis a) +void QmlGraphicsDrag::setAxis(QmlGraphicsDrag::Axis a) { _axis = a; } -qreal QFxDrag::xmin() const +qreal QmlGraphicsDrag::xmin() const { return _xmin; } -void QFxDrag::setXmin(qreal m) +void QmlGraphicsDrag::setXmin(qreal m) { _xmin = m; } -qreal QFxDrag::xmax() const +qreal QmlGraphicsDrag::xmax() const { return _xmax; } -void QFxDrag::setXmax(qreal m) +void QmlGraphicsDrag::setXmax(qreal m) { _xmax = m; } -qreal QFxDrag::ymin() const +qreal QmlGraphicsDrag::ymin() const { return _ymin; } -void QFxDrag::setYmin(qreal m) +void QmlGraphicsDrag::setYmin(qreal m) { _ymin = m; } -qreal QFxDrag::ymax() const +qreal QmlGraphicsDrag::ymax() const { return _ymax; } -void QFxDrag::setYmax(qreal m) +void QmlGraphicsDrag::setYmax(qreal m) { _ymax = m; } @@ -225,35 +225,35 @@ void QFxDrag::setYmax(qreal m) The \e accepted property of the MouseEvent parameter is ignored in this handler. */ -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,MouseRegion,QFxMouseRegion) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,MouseRegion,QmlGraphicsMouseRegion) /*! \internal - \class QFxMouseRegion - \brief The QFxMouseRegion class provides a simple mouse handling abstraction for use within Qml. + \class QmlGraphicsMouseRegion + \brief The QmlGraphicsMouseRegion class provides a simple mouse handling abstraction for use within Qml. \ingroup group_coreitems - All QFxItem derived classes can do mouse handling but the QFxMouseRegion class exposes mouse + All QmlGraphicsItem derived classes can do mouse handling but the QmlGraphicsMouseRegion class exposes mouse handling data as properties and tracks flicking and dragging of the mouse. - A QFxMouseRegion object can be instantiated in Qml using the tag \l MouseRegion. + A QmlGraphicsMouseRegion object can be instantiated in Qml using the tag \l MouseRegion. */ -QFxMouseRegion::QFxMouseRegion(QFxItem *parent) - : QFxItem(*(new QFxMouseRegionPrivate), parent) +QmlGraphicsMouseRegion::QmlGraphicsMouseRegion(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsMouseRegionPrivate), parent) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); d->init(); } -QFxMouseRegion::QFxMouseRegion(QFxMouseRegionPrivate &dd, QFxItem *parent) - : QFxItem(dd, parent) +QmlGraphicsMouseRegion::QmlGraphicsMouseRegion(QmlGraphicsMouseRegionPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); d->init(); } -QFxMouseRegion::~QFxMouseRegion() +QmlGraphicsMouseRegion::~QmlGraphicsMouseRegion() { } @@ -274,15 +274,15 @@ QFxMouseRegion::~QFxMouseRegion() The coordinates are relative to the MouseRegion. */ -qreal QFxMouseRegion::mouseX() const +qreal QmlGraphicsMouseRegion::mouseX() const { - Q_D(const QFxMouseRegion); + Q_D(const QmlGraphicsMouseRegion); return d->lastPos.x(); } -qreal QFxMouseRegion::mouseY() const +qreal QmlGraphicsMouseRegion::mouseY() const { - Q_D(const QFxMouseRegion); + Q_D(const QmlGraphicsMouseRegion); return d->lastPos.y(); } @@ -290,15 +290,15 @@ qreal QFxMouseRegion::mouseY() const \qmlproperty bool MouseRegion::enabled This property holds whether the item accepts mouse events. */ -bool QFxMouseRegion::isEnabled() const +bool QmlGraphicsMouseRegion::isEnabled() const { - Q_D(const QFxMouseRegion); + Q_D(const QmlGraphicsMouseRegion); return d->absorb; } -void QFxMouseRegion::setEnabled(bool a) +void QmlGraphicsMouseRegion::setEnabled(bool a) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); if (a != d->absorb) { d->absorb = a; emit enabledChanged(); @@ -331,40 +331,40 @@ void QFxMouseRegion::setEnabled(bool a) \sa acceptedButtons */ -Qt::MouseButtons QFxMouseRegion::pressedButtons() const +Qt::MouseButtons QmlGraphicsMouseRegion::pressedButtons() const { - Q_D(const QFxMouseRegion); + Q_D(const QmlGraphicsMouseRegion); return d->lastButtons; } -void QFxMouseRegion::mousePressEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsMouseRegion::mousePressEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); d->moved = false; if (!d->absorb) - QFxItem::mousePressEvent(event); + QmlGraphicsItem::mousePressEvent(event); else { d->longPress = false; d->saveEvent(event); - d->dragX = drag()->axis() & QFxDrag::XAxis; - d->dragY = drag()->axis() & QFxDrag::YAxis; + d->dragX = drag()->axis() & QmlGraphicsDrag::XAxis; + d->dragY = drag()->axis() & QmlGraphicsDrag::YAxis; d->dragged = false; setHovered(true); d->start = event->pos(); d->startScene = event->scenePos(); // we should only start timer if pressAndHold is connected to. - if (d->isConnected("pressAndHold(QFxMouseEvent*)")) + if (d->isConnected("pressAndHold(QmlGraphicsMouseEvent*)")) d->pressAndHoldTimer.start(PressAndHoldDelay, this); setKeepMouseGrab(false); event->setAccepted(setPressed(true)); } } -void QFxMouseRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsMouseRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); if (!d->absorb) { - QFxItem::mouseMoveEvent(event); + QmlGraphicsItem::mouseMoveEvent(event); return; } @@ -424,16 +424,16 @@ void QFxMouseRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } } d->moved = true; - QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); emit positionChanged(&me); } -void QFxMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); if (!d->absorb) { - QFxItem::mouseReleaseEvent(event); + QmlGraphicsItem::mouseReleaseEvent(event); } else { d->saveEvent(event); setPressed(false); @@ -444,57 +444,57 @@ void QFxMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } } -void QFxMouseRegion::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsMouseRegion::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); if (!d->absorb) { - QFxItem::mouseDoubleClickEvent(event); + QmlGraphicsItem::mouseDoubleClickEvent(event); } else { - QFxItem::mouseDoubleClickEvent(event); + QmlGraphicsItem::mouseDoubleClickEvent(event); if (event->isAccepted()) { // Only deliver the event if we have accepted the press. d->saveEvent(event); - QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false); + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false); emit this->doubleClicked(&me); } } } -void QFxMouseRegion::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +void QmlGraphicsMouseRegion::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); if (!d->absorb) - QFxItem::hoverEnterEvent(event); + QmlGraphicsItem::hoverEnterEvent(event); else setHovered(true); } -void QFxMouseRegion::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +void QmlGraphicsMouseRegion::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); if (!d->absorb) { - QFxItem::hoverEnterEvent(event); + QmlGraphicsItem::hoverEnterEvent(event); } else { d->lastPos = event->pos(); - QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, d->lastButtons, d->lastModifiers, false, d->longPress); + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, d->lastButtons, d->lastModifiers, false, d->longPress); emit positionChanged(&me); } } -void QFxMouseRegion::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +void QmlGraphicsMouseRegion::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); if (!d->absorb) - QFxItem::hoverLeaveEvent(event); + QmlGraphicsItem::hoverLeaveEvent(event); else setHovered(false); } -bool QFxMouseRegion::sceneEvent(QEvent *event) +bool QmlGraphicsMouseRegion::sceneEvent(QEvent *event) { - bool rv = QFxItem::sceneEvent(event); + bool rv = QmlGraphicsItem::sceneEvent(event); if (event->type() == QEvent::UngrabMouse) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); if (d->pressed) { // if our mouse grab has been removed (probably by Flickable), fix our // state @@ -507,14 +507,14 @@ bool QFxMouseRegion::sceneEvent(QEvent *event) return rv; } -void QFxMouseRegion::timerEvent(QTimerEvent *event) +void QmlGraphicsMouseRegion::timerEvent(QTimerEvent *event) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); if (event->timerId() == d->pressAndHoldTimer.timerId()) { d->pressAndHoldTimer.stop(); if (d->pressed && d->dragged == false && d->hovered == true) { d->longPress = true; - QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); emit pressAndHold(&me); } } @@ -538,9 +538,9 @@ void QFxMouseRegion::timerEvent(QTimerEvent *event) \warning This property is not updated if the region moves under the mouse: \e containsMouse will not change. In addition, if hoverEnabled is false, containsMouse will only be valid when the mouse is pressed. */ -bool QFxMouseRegion::hovered() const +bool QmlGraphicsMouseRegion::hovered() const { - Q_D(const QFxMouseRegion); + Q_D(const QmlGraphicsMouseRegion); return d->hovered; } @@ -548,15 +548,15 @@ bool QFxMouseRegion::hovered() const \qmlproperty bool MouseRegion::pressed This property holds whether the mouse region is currently pressed. */ -bool QFxMouseRegion::pressed() const +bool QmlGraphicsMouseRegion::pressed() const { - Q_D(const QFxMouseRegion); + Q_D(const QmlGraphicsMouseRegion); return d->pressed; } -void QFxMouseRegion::setHovered(bool h) +void QmlGraphicsMouseRegion::setHovered(bool h) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); if (d->hovered != h) { d->hovered = h; emit hoveredChanged(); @@ -584,12 +584,12 @@ void QFxMouseRegion::setHovered(bool h) The default is to accept the Left button. */ -Qt::MouseButtons QFxMouseRegion::acceptedButtons() const +Qt::MouseButtons QmlGraphicsMouseRegion::acceptedButtons() const { return acceptedMouseButtons(); } -void QFxMouseRegion::setAcceptedButtons(Qt::MouseButtons buttons) +void QmlGraphicsMouseRegion::setAcceptedButtons(Qt::MouseButtons buttons) { if (buttons != acceptedMouseButtons()) { setAcceptedMouseButtons(buttons); @@ -597,14 +597,14 @@ void QFxMouseRegion::setAcceptedButtons(Qt::MouseButtons buttons) } } -bool QFxMouseRegion::setPressed(bool p) +bool QmlGraphicsMouseRegion::setPressed(bool p) { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); bool isclick = d->pressed == true && p == false && d->dragged == false && d->hovered == true; if (d->pressed != p) { d->pressed = p; - QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress); + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress); if (d->pressed) { emit positionChanged(&me); emit pressed(&me); @@ -620,9 +620,9 @@ bool QFxMouseRegion::setPressed(bool p) return false; } -QFxDrag *QFxMouseRegion::drag() +QmlGraphicsDrag *QmlGraphicsMouseRegion::drag() { - Q_D(QFxMouseRegion); + Q_D(QmlGraphicsMouseRegion); return &(d->drag); } diff --git a/src/declarative/fx/qfxmouseregion.h b/src/declarative/fx/qfxmouseregion.h index 114ea87..41c3d0e 100644 --- a/src/declarative/fx/qfxmouseregion.h +++ b/src/declarative/fx/qfxmouseregion.h @@ -50,12 +50,12 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class Q_DECLARATIVE_EXPORT QFxDrag : public QObject +class Q_DECLARATIVE_EXPORT QmlGraphicsDrag : public QObject { Q_OBJECT Q_ENUMS(Axis) - Q_PROPERTY(QFxItem *target READ target WRITE setTarget) + Q_PROPERTY(QmlGraphicsItem *target READ target WRITE setTarget) Q_PROPERTY(Axis axis READ axis WRITE setAxis) Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin) Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax) @@ -64,11 +64,11 @@ class Q_DECLARATIVE_EXPORT QFxDrag : public QObject //### consider drag and drop public: - QFxDrag(QObject *parent=0); - ~QFxDrag(); + QmlGraphicsDrag(QObject *parent=0); + ~QmlGraphicsDrag(); - QFxItem *target() const; - void setTarget(QFxItem *); + QmlGraphicsItem *target() const; + void setTarget(QmlGraphicsItem *); enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 }; Axis axis() const; @@ -84,18 +84,18 @@ public: void setYmax(qreal); private: - QFxItem *_target; + QmlGraphicsItem *_target; Axis _axis; qreal _xmin; qreal _xmax; qreal _ymin; qreal _ymax; - Q_DISABLE_COPY(QFxDrag) + Q_DISABLE_COPY(QmlGraphicsDrag) }; -class QFxMouseEvent; -class QFxMouseRegionPrivate; -class Q_DECLARATIVE_EXPORT QFxMouseRegion : public QFxItem +class QmlGraphicsMouseEvent; +class QmlGraphicsMouseRegionPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsMouseRegion : public QmlGraphicsItem { Q_OBJECT @@ -107,11 +107,11 @@ class Q_DECLARATIVE_EXPORT QFxMouseRegion : public QFxItem Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged) Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) Q_PROPERTY(bool hoverEnabled READ acceptHoverEvents WRITE setAcceptHoverEvents) - Q_PROPERTY(QFxDrag *drag READ drag) //### add flicking to QFxDrag or add a QFxFlick ??? + Q_PROPERTY(QmlGraphicsDrag *drag READ drag) //### add flicking to QmlGraphicsDrag or add a QmlGraphicsFlick ??? public: - QFxMouseRegion(QFxItem *parent=0); - ~QFxMouseRegion(); + QmlGraphicsMouseRegion(QmlGraphicsItem *parent=0); + ~QmlGraphicsMouseRegion(); qreal mouseX() const; qreal mouseY() const; @@ -127,20 +127,20 @@ public: Qt::MouseButtons acceptedButtons() const; void setAcceptedButtons(Qt::MouseButtons buttons); - QFxDrag *drag(); + QmlGraphicsDrag *drag(); Q_SIGNALS: void hoveredChanged(); void pressedChanged(); void enabledChanged(); void acceptedButtonsChanged(); - void positionChanged(QFxMouseEvent *mouse); + void positionChanged(QmlGraphicsMouseEvent *mouse); - void pressed(QFxMouseEvent *mouse); - void pressAndHold(QFxMouseEvent *mouse); - void released(QFxMouseEvent *mouse); - void clicked(QFxMouseEvent *mouse); - void doubleClicked(QFxMouseEvent *mouse); + void pressed(QmlGraphicsMouseEvent *mouse); + void pressAndHold(QmlGraphicsMouseEvent *mouse); + void released(QmlGraphicsMouseEvent *mouse); + void clicked(QmlGraphicsMouseEvent *mouse); + void doubleClicked(QmlGraphicsMouseEvent *mouse); void entered(); void exited(); @@ -163,17 +163,17 @@ private: void handleRelease(); protected: - QFxMouseRegion(QFxMouseRegionPrivate &dd, QFxItem *parent); + QmlGraphicsMouseRegion(QmlGraphicsMouseRegionPrivate &dd, QmlGraphicsItem *parent); private: - Q_DISABLE_COPY(QFxMouseRegion) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxMouseRegion) + Q_DISABLE_COPY(QmlGraphicsMouseRegion) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsMouseRegion) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxDrag) -QML_DECLARE_TYPE(QFxMouseRegion) +QML_DECLARE_TYPE(QmlGraphicsDrag) +QML_DECLARE_TYPE(QmlGraphicsMouseRegion) QT_END_HEADER diff --git a/src/declarative/fx/qfxmouseregion_p.h b/src/declarative/fx/qfxmouseregion_p.h index caed2ab..66efb6f 100644 --- a/src/declarative/fx/qfxmouseregion_p.h +++ b/src/declarative/fx/qfxmouseregion_p.h @@ -60,19 +60,19 @@ QT_BEGIN_NAMESPACE -class QFxMouseRegionPrivate : public QFxItemPrivate +class QmlGraphicsMouseRegionPrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxMouseRegion) + Q_DECLARE_PUBLIC(QmlGraphicsMouseRegion) public: - QFxMouseRegionPrivate() + QmlGraphicsMouseRegionPrivate() : absorb(true), hovered(false), pressed(false), longPress(false), drag(0) { } void init() { - Q_Q(QFxMouseRegion); + Q_Q(QmlGraphicsMouseRegion); q->setAcceptedMouseButtons(Qt::LeftButton); } @@ -84,7 +84,7 @@ public: } bool isConnected(const char *signal) { - Q_Q(QFxMouseRegion); + Q_Q(QmlGraphicsMouseRegion); int idx = QObjectPrivate::get(q)->signalIndex(signal); return QObjectPrivate::get(q)->isSignalConnected(idx); } @@ -97,7 +97,7 @@ public: bool dragX : 1; bool dragY : 1; bool dragged : 1; - QFxDrag drag; + QmlGraphicsDrag drag; QPointF start; QPointF startScene; qreal startX; diff --git a/src/declarative/fx/qfxpainteditem.cpp b/src/declarative/fx/qfxpainteditem.cpp index e0ef99f..24d9602 100644 --- a/src/declarative/fx/qfxpainteditem.cpp +++ b/src/declarative/fx/qfxpainteditem.cpp @@ -53,8 +53,8 @@ QT_BEGIN_NAMESPACE /*! - \class QFxPaintedItem - \brief The QFxPaintedItem class is an abstract base class for QmlView items that want cached painting. + \class QmlGraphicsPaintedItem + \brief The QmlGraphicsPaintedItem class is an abstract base class for QmlView items that want cached painting. \internal This is a convenience class for implementing items that paint their contents @@ -62,21 +62,21 @@ QT_BEGIN_NAMESPACE The dirtyCache() function should be called if the contents change to ensure the cache is refreshed the next time painting occurs. - To subclass QFxPaintedItem, you must reimplement drawContents() to draw + To subclass QmlGraphicsPaintedItem, you must reimplement drawContents() to draw the contents of the item. */ /*! - \fn void QFxPaintedItem::drawContents(QPainter *painter, const QRect &rect) + \fn void QmlGraphicsPaintedItem::drawContents(QPainter *painter, const QRect &rect) This function is called when the cache needs to be refreshed. When - sub-classing QFxPaintedItem this function should be implemented so as to + sub-classing QmlGraphicsPaintedItem this function should be implemented so as to paint the contents of the item using the given \a painter for the area of the contents specified by \a rect. */ /*! - \property QFxPaintedItem::contentsSize + \property QmlGraphicsPaintedItem::contentsSize \brief The size of the contents The contents size is the size of the item in regards to how it is painted @@ -94,11 +94,11 @@ static int inpaint_clearcache=0; \sa clearCache() */ -void QFxPaintedItem::dirtyCache(const QRect& rect) +void QmlGraphicsPaintedItem::dirtyCache(const QRect& rect) { - Q_D(QFxPaintedItem); + Q_D(QmlGraphicsPaintedItem); for (int i=0; i < d->imagecache.count(); ) { - QFxPaintedItemPrivate::ImageCacheItem *c = d->imagecache[i]; + QmlGraphicsPaintedItemPrivate::ImageCacheItem *c = d->imagecache[i]; QRect isect = (c->area & rect) | c->dirty; if (isect == c->area && !inpaint) { delete d->imagecache.takeAt(i); @@ -114,13 +114,13 @@ void QFxPaintedItem::dirtyCache(const QRect& rect) \sa dirtyCache() */ -void QFxPaintedItem::clearCache() +void QmlGraphicsPaintedItem::clearCache() { if (inpaint) { inpaint_clearcache=1; return; } - Q_D(QFxPaintedItem); + Q_D(QmlGraphicsPaintedItem); qDeleteAll(d->imagecache); d->imagecache.clear(); } @@ -130,9 +130,9 @@ void QFxPaintedItem::clearCache() \sa setContentsSize() */ -QSize QFxPaintedItem::contentsSize() const +QSize QmlGraphicsPaintedItem::contentsSize() const { - Q_D(const QFxPaintedItem); + Q_D(const QmlGraphicsPaintedItem); return d->contentsSize; } @@ -141,9 +141,9 @@ QSize QFxPaintedItem::contentsSize() const \sa contentsSize() */ -void QFxPaintedItem::setContentsSize(const QSize &size) +void QmlGraphicsPaintedItem::setContentsSize(const QSize &size) { - Q_D(QFxPaintedItem); + Q_D(QmlGraphicsPaintedItem); if (d->contentsSize == size) return; d->contentsSize = size; clearCache(); @@ -151,21 +151,21 @@ void QFxPaintedItem::setContentsSize(const QSize &size) } /*! - Constructs a new QFxPaintedItem with the given \a parent. + Constructs a new QmlGraphicsPaintedItem with the given \a parent. */ -QFxPaintedItem::QFxPaintedItem(QFxItem *parent) - : QFxItem(*(new QFxPaintedItemPrivate), parent) +QmlGraphicsPaintedItem::QmlGraphicsPaintedItem(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsPaintedItemPrivate), parent) { init(); } /*! \internal - Constructs a new QFxPaintedItem with the given \a parent and + Constructs a new QmlGraphicsPaintedItem with the given \a parent and initialized private data member \a dd. */ -QFxPaintedItem::QFxPaintedItem(QFxPaintedItemPrivate &dd, QFxItem *parent) - : QFxItem(dd, parent) +QmlGraphicsPaintedItem::QmlGraphicsPaintedItem(QmlGraphicsPaintedItemPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) { init(); } @@ -173,7 +173,7 @@ QFxPaintedItem::QFxPaintedItem(QFxPaintedItemPrivate &dd, QFxItem *parent) /*! Destroys the image item. */ -QFxPaintedItem::~QFxPaintedItem() +QmlGraphicsPaintedItem::~QmlGraphicsPaintedItem() { clearCache(); } @@ -181,16 +181,16 @@ QFxPaintedItem::~QFxPaintedItem() /*! \internal */ -void QFxPaintedItem::init() +void QmlGraphicsPaintedItem::init() { connect(this,SIGNAL(widthChanged()),this,SLOT(clearCache())); connect(this,SIGNAL(heightChanged()),this,SLOT(clearCache())); connect(this,SIGNAL(visibleChanged()),this,SLOT(clearCache())); } -void QFxPaintedItem::setCacheFrozen(bool frozen) +void QmlGraphicsPaintedItem::setCacheFrozen(bool frozen) { - Q_D(QFxPaintedItem); + Q_D(QmlGraphicsPaintedItem); if (d->cachefrozen == frozen) return; d->cachefrozen = frozen; @@ -200,9 +200,9 @@ void QFxPaintedItem::setCacheFrozen(bool frozen) /*! \reimp */ -void QFxPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +void QmlGraphicsPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { - Q_D(QFxPaintedItem); + Q_D(QmlGraphicsPaintedItem); const QRect content(QPoint(0,0),d->contentsSize); if (content.width() <= 0 || content.height() <= 0) return; @@ -290,7 +290,7 @@ void QFxPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidge qp.translate(-r.x(),-r.y()); drawContents(&qp, r); } - QFxPaintedItemPrivate::ImageCacheItem *newitem = new QFxPaintedItemPrivate::ImageCacheItem; + QmlGraphicsPaintedItemPrivate::ImageCacheItem *newitem = new QmlGraphicsPaintedItemPrivate::ImageCacheItem; newitem->area = r; newitem->image = img; d->imagecache.append(newitem); @@ -320,21 +320,21 @@ void QFxPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidge */ /*! - \property QFxPaintedItem::cacheSize + \property QmlGraphicsPaintedItem::cacheSize The maximum number of pixels of image cache to allow. The default is 0.1 megapixels. The cache will not be larger than the (unscaled) - size of the QFxPaintedItem. + size of the QmlGraphicsPaintedItem. */ -int QFxPaintedItem::cacheSize() const +int QmlGraphicsPaintedItem::cacheSize() const { - Q_D(const QFxPaintedItem); + Q_D(const QmlGraphicsPaintedItem); return d->max_imagecache_size; } -void QFxPaintedItem::setCacheSize(int pixels) +void QmlGraphicsPaintedItem::setCacheSize(int pixels) { - Q_D(QFxPaintedItem); + Q_D(QmlGraphicsPaintedItem); if (pixels < d->max_imagecache_size) { int cachesize=0; for (int i=0; iimagecache.count(); ++i) { @@ -359,7 +359,7 @@ void QFxPaintedItem::setCacheSize(int pixels) } /*! - \property QFxPaintedItem::fillColor + \property QmlGraphicsPaintedItem::fillColor The color to be used to fill the item prior to calling drawContents(). By default, this is Qt::transparent. @@ -367,9 +367,9 @@ void QFxPaintedItem::setCacheSize(int pixels) Performance improvements can be achieved if subclasses call this with either an invalid color (QColor()), or an appropriate solid color. */ -void QFxPaintedItem::setFillColor(const QColor& c) +void QmlGraphicsPaintedItem::setFillColor(const QColor& c) { - Q_D(QFxPaintedItem); + Q_D(QmlGraphicsPaintedItem); if (d->fillColor == c) return; d->fillColor = c; @@ -377,9 +377,9 @@ void QFxPaintedItem::setFillColor(const QColor& c) update(); } -QColor QFxPaintedItem::fillColor() const +QColor QmlGraphicsPaintedItem::fillColor() const { - Q_D(const QFxPaintedItem); + Q_D(const QmlGraphicsPaintedItem); return d->fillColor; } diff --git a/src/declarative/fx/qfxpainteditem.h b/src/declarative/fx/qfxpainteditem.h index 13c6b15..33f938c 100644 --- a/src/declarative/fx/qfxpainteditem.h +++ b/src/declarative/fx/qfxpainteditem.h @@ -52,8 +52,8 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxPaintedItemPrivate; -class Q_DECLARATIVE_EXPORT QFxPaintedItem : public QFxItem +class QmlGraphicsPaintedItemPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsPaintedItem : public QmlGraphicsItem { Q_OBJECT @@ -62,8 +62,8 @@ class Q_DECLARATIVE_EXPORT QFxPaintedItem : public QFxItem Q_PROPERTY(int cacheSize READ cacheSize WRITE setCacheSize) public: - QFxPaintedItem(QFxItem *parent=0); - ~QFxPaintedItem(); + QmlGraphicsPaintedItem(QmlGraphicsItem *parent=0); + ~QmlGraphicsPaintedItem(); QSize contentsSize() const; void setContentsSize(const QSize &); @@ -77,7 +77,7 @@ public: void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); protected: - QFxPaintedItem(QFxPaintedItemPrivate &dd, QFxItem *parent); + QmlGraphicsPaintedItem(QmlGraphicsPaintedItemPrivate &dd, QmlGraphicsItem *parent); virtual void drawContents(QPainter *p, const QRect &) = 0; @@ -92,13 +92,13 @@ protected Q_SLOTS: private: void init(); - Q_DISABLE_COPY(QFxPaintedItem) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxPaintedItem) + Q_DISABLE_COPY(QmlGraphicsPaintedItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsPaintedItem) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxPaintedItem) +QML_DECLARE_TYPE(QmlGraphicsPaintedItem) QT_END_HEADER diff --git a/src/declarative/fx/qfxpainteditem_p.h b/src/declarative/fx/qfxpainteditem_p.h index 179fd61..cc7f697 100644 --- a/src/declarative/fx/qfxpainteditem_p.h +++ b/src/declarative/fx/qfxpainteditem_p.h @@ -57,12 +57,12 @@ QT_BEGIN_NAMESPACE -class QFxPaintedItemPrivate : public QFxItemPrivate +class QmlGraphicsPaintedItemPrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxPaintedItem) + Q_DECLARE_PUBLIC(QmlGraphicsPaintedItem) public: - QFxPaintedItemPrivate() + QmlGraphicsPaintedItemPrivate() : max_imagecache_size(100000), fillColor(Qt::transparent), cachefrozen(false) { } diff --git a/src/declarative/fx/qfxpath.cpp b/src/declarative/fx/qfxpath.cpp index 26fafc5..a9bd233 100644 --- a/src/declarative/fx/qfxpath.cpp +++ b/src/declarative/fx/qfxpath.cpp @@ -47,14 +47,14 @@ QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Path,QFxPath) -QML_DEFINE_NOCREATE_TYPE(QFxPathElement) -QML_DEFINE_NOCREATE_TYPE(QFxCurve) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathAttribute,QFxPathAttribute) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathPercent,QFxPathPercent) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathLine,QFxPathLine) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathQuad,QFxPathQuad) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathCubic,QFxPathCubic) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Path,QmlGraphicsPath) +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsPathElement) +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsCurve) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathAttribute,QmlGraphicsPathAttribute) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathPercent,QmlGraphicsPathPercent) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathLine,QmlGraphicsPathLine) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathQuad,QmlGraphicsPathQuad) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathCubic,QmlGraphicsPathCubic) /*! \qmlclass PathElement @@ -68,12 +68,12 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathCubic,QFxPathCubic) /*! \internal - \class QFxPathElement + \class QmlGraphicsPathElement \ingroup group_utility */ /*! - \qmlclass Path QFxPath + \qmlclass Path QmlGraphicsPath \brief A Path object defines a path for use by \l PathView. A Path is composed of one or more path segments - PathLine, PathQuad, @@ -90,22 +90,22 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathCubic,QFxPathCubic) /*! \internal - \class QFxPath + \class QmlGraphicsPath \ingroup group_utility - \brief The QFxPath class defines a path. - \sa QFxPathView + \brief The QmlGraphicsPath class defines a path. + \sa QmlGraphicsPathView */ -QFxPath::QFxPath(QObject *parent) - : QObject(*(new QFxPathPrivate), parent) +QmlGraphicsPath::QmlGraphicsPath(QObject *parent) + : QObject(*(new QmlGraphicsPathPrivate), parent) { } -QFxPath::QFxPath(QFxPathPrivate &dd, QObject *parent) +QmlGraphicsPath::QmlGraphicsPath(QmlGraphicsPathPrivate &dd, QObject *parent) : QObject(dd, parent) { } -QFxPath::~QFxPath() +QmlGraphicsPath::~QmlGraphicsPath() { } @@ -114,27 +114,27 @@ QFxPath::~QFxPath() \qmlproperty real Path::startY This property holds the starting position of the path. */ -qreal QFxPath::startX() const +qreal QmlGraphicsPath::startX() const { - Q_D(const QFxPath); + Q_D(const QmlGraphicsPath); return d->startX; } -void QFxPath::setStartX(qreal x) +void QmlGraphicsPath::setStartX(qreal x) { - Q_D(QFxPath); + Q_D(QmlGraphicsPath); d->startX = x; } -qreal QFxPath::startY() const +qreal QmlGraphicsPath::startY() const { - Q_D(const QFxPath); + Q_D(const QmlGraphicsPath); return d->startY; } -void QFxPath::setStartY(qreal y) +void QmlGraphicsPath::setStartY(qreal y) { - Q_D(QFxPath); + Q_D(QmlGraphicsPath); d->startY = y; } @@ -156,15 +156,15 @@ void QFxPath::setStartY(qreal y) \snippet doc/src/snippets/declarative/pathview/pathattributes.qml 2 */ -QList* QFxPath::pathElements() +QList* QmlGraphicsPath::pathElements() { - Q_D(QFxPath); + Q_D(QmlGraphicsPath); return &(d->_pathElements); } -void QFxPath::interpolate(int idx, const QString &name, qreal value) +void QmlGraphicsPath::interpolate(int idx, const QString &name, qreal value) { - Q_D(QFxPath); + Q_D(QmlGraphicsPath); if (!idx) return; @@ -193,9 +193,9 @@ void QFxPath::interpolate(int idx, const QString &name, qreal value) } } -void QFxPath::endpoint(const QString &name) +void QmlGraphicsPath::endpoint(const QString &name) { - Q_D(QFxPath); + Q_D(QmlGraphicsPath); const AttributePoint &first = d->_attributePoints.first(); qreal val = first.values.value(name); for (int ii = d->_attributePoints.count() - 1; ii >= 0; ii--) { @@ -210,9 +210,9 @@ void QFxPath::endpoint(const QString &name) } } -void QFxPath::processPath() +void QmlGraphicsPath::processPath() { - Q_D(QFxPath); + Q_D(QmlGraphicsPath); d->_pointCache.clear(); d->_attributePoints.clear(); @@ -225,17 +225,17 @@ void QFxPath::processPath() d->_path.moveTo(d->startX, d->startY); - foreach (QFxPathElement *pathElement, d->_pathElements) { - if (QFxCurve *curve = qobject_cast(pathElement)) { + foreach (QmlGraphicsPathElement *pathElement, d->_pathElements) { + if (QmlGraphicsCurve *curve = qobject_cast(pathElement)) { curve->addToPath(d->_path); AttributePoint p; p.origpercent = d->_path.length(); d->_attributePoints << p; - } else if (QFxPathAttribute *attribute = qobject_cast(pathElement)) { + } else if (QmlGraphicsPathAttribute *attribute = qobject_cast(pathElement)) { AttributePoint &point = d->_attributePoints.last(); point.values[attribute->name()] = attribute->value(); interpolate(d->_attributePoints.count() - 1, attribute->name(), attribute->value()); - } else if (QFxPathPercent *percent = qobject_cast(pathElement)) { + } else if (QmlGraphicsPathPercent *percent = qobject_cast(pathElement)) { AttributePoint &point = d->_attributePoints.last(); point.values[QLatin1String("_qfx_percent")] = percent->value(); interpolate(d->_attributePoints.count() - 1, QLatin1String("_qfx_percent"), percent->value()); @@ -255,7 +255,7 @@ void QFxPath::processPath() qreal prevorigpercent = 0; for (int ii = 0; ii < d->_attributePoints.count(); ++ii) { const AttributePoint &point = d->_attributePoints.at(ii); - if (point.values.contains(QLatin1String("_qfx_percent"))) { //special string for QFxPathPercent + if (point.values.contains(QLatin1String("_qfx_percent"))) { //special string for QmlGraphicsPathPercent if ( ii > 0) { qreal scale = (d->_attributePoints[ii].origpercent/length - prevorigpercent) / (point.values.value(QLatin1String("_qfx_percent"))-prevpercent); @@ -274,33 +274,33 @@ void QFxPath::processPath() emit changed(); } -void QFxPath::componentComplete() +void QmlGraphicsPath::componentComplete() { - Q_D(QFxPath); + Q_D(QmlGraphicsPath); QSet attrs; // First gather up all the attributes - foreach (QFxPathElement *pathElement, d->_pathElements) { - if (QFxPathAttribute *attribute = - qobject_cast(pathElement)) + foreach (QmlGraphicsPathElement *pathElement, d->_pathElements) { + if (QmlGraphicsPathAttribute *attribute = + qobject_cast(pathElement)) attrs.insert(attribute->name()); } d->_attributes = attrs.toList(); processPath(); - foreach (QFxPathElement *pathElement, d->_pathElements) + foreach (QmlGraphicsPathElement *pathElement, d->_pathElements) connect(pathElement, SIGNAL(changed()), this, SLOT(processPath())); } -QPainterPath QFxPath::path() const +QPainterPath QmlGraphicsPath::path() const { - Q_D(const QFxPath); + Q_D(const QmlGraphicsPath); return d->_path; } -QStringList QFxPath::attributes() const +QStringList QmlGraphicsPath::attributes() const { - Q_D(const QFxPath); + Q_D(const QmlGraphicsPath); return d->_attributes; } #include @@ -342,11 +342,11 @@ static inline QBezier nextBezier(const QPainterPath &path, int *from, qreal *bez return QBezier(); } -void QFxPath::createPointCache() const +void QmlGraphicsPath::createPointCache() const { - Q_D(const QFxPath); + Q_D(const QmlGraphicsPath); #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer pc; + QmlPerfTimer pc; #endif qreal pathLength = d->_path.length(); const int points = int(pathLength*2); @@ -393,9 +393,9 @@ void QFxPath::createPointCache() const } } -QPointF QFxPath::pointAt(qreal p) const +QPointF QmlGraphicsPath::pointAt(qreal p) const { - Q_D(const QFxPath); + Q_D(const QmlGraphicsPath); if (d->_pointCache.isEmpty()) { createPointCache(); } @@ -407,9 +407,9 @@ QPointF QFxPath::pointAt(qreal p) const return d->_pointCache.at(idx); } -qreal QFxPath::attributeAt(const QString &name, qreal percent) const +qreal QmlGraphicsPath::attributeAt(const QString &name, qreal percent) const { - Q_D(const QFxPath); + Q_D(const QmlGraphicsPath); if (percent < 0 || percent > 1) return 0; @@ -435,12 +435,12 @@ qreal QFxPath::attributeAt(const QString &name, qreal percent) const /****************************************************************************/ -qreal QFxCurve::x() const +qreal QmlGraphicsCurve::x() const { return _x; } -void QFxCurve::setX(qreal x) +void QmlGraphicsCurve::setX(qreal x) { if (_x != x) { _x = x; @@ -448,12 +448,12 @@ void QFxCurve::setX(qreal x) } } -qreal QFxCurve::y() const +qreal QmlGraphicsCurve::y() const { return _y; } -void QFxCurve::setY(qreal y) +void QmlGraphicsCurve::setY(qreal y) { if (_y != y) { _y = y; @@ -492,11 +492,11 @@ void QFxCurve::setY(qreal y) /*! \internal - \class QFxPathAttribute + \class QmlGraphicsPathAttribute \ingroup group_utility - \brief The QFxPathAttribute class allows to set the value of an attribute at a given position in the path. + \brief The QmlGraphicsPathAttribute class allows to set the value of an attribute at a given position in the path. - \sa QFxPath + \sa QmlGraphicsPath */ @@ -509,12 +509,12 @@ void QFxCurve::setY(qreal y) the name of the attribute to change. */ -QString QFxPathAttribute::name() const +QString QmlGraphicsPathAttribute::name() const { return _name; } -void QFxPathAttribute::setName(const QString &name) +void QmlGraphicsPathAttribute::setName(const QString &name) { _name = name; } @@ -527,12 +527,12 @@ void QFxPathAttribute::setName(const QString &name) /*! the new value of the attribute. */ -qreal QFxPathAttribute::value() const +qreal QmlGraphicsPathAttribute::value() const { return _value; } -void QFxPathAttribute::setValue(qreal value) +void QmlGraphicsPathAttribute::setValue(qreal value) { if (_value != value) { _value = value; @@ -561,11 +561,11 @@ void QFxPathAttribute::setValue(qreal value) /*! \internal - \class QFxPathLine + \class QmlGraphicsPathLine \ingroup group_utility - \brief The QFxPathLine class defines a straight line. + \brief The QmlGraphicsPathLine class defines a straight line. - \sa QFxPath + \sa QmlGraphicsPath */ /*! @@ -575,7 +575,7 @@ void QFxPathAttribute::setValue(qreal value) Defines the end point of the line. */ -void QFxPathLine::addToPath(QPainterPath &path) +void QmlGraphicsPathLine::addToPath(QPainterPath &path) { path.lineTo(x(), y()); } @@ -604,11 +604,11 @@ void QFxPathLine::addToPath(QPainterPath &path) /*! \internal - \class QFxPathQuad + \class QmlGraphicsPathQuad \ingroup group_utility - \brief The QFxPathQuad class defines a quadratic Bezier curve with a control point. + \brief The QmlGraphicsPathQuad class defines a quadratic Bezier curve with a control point. - \sa QFxPath + \sa QmlGraphicsPath */ @@ -629,12 +629,12 @@ void QFxPathLine::addToPath(QPainterPath &path) /*! the x position of the control point. */ -qreal QFxPathQuad::controlX() const +qreal QmlGraphicsPathQuad::controlX() const { return _controlX; } -void QFxPathQuad::setControlX(qreal x) +void QmlGraphicsPathQuad::setControlX(qreal x) { if (_controlX != x) { _controlX = x; @@ -646,12 +646,12 @@ void QFxPathQuad::setControlX(qreal x) /*! the y position of the control point. */ -qreal QFxPathQuad::controlY() const +qreal QmlGraphicsPathQuad::controlY() const { return _controlY; } -void QFxPathQuad::setControlY(qreal y) +void QmlGraphicsPathQuad::setControlY(qreal y) { if (_controlY != y) { _controlY = y; @@ -659,7 +659,7 @@ void QFxPathQuad::setControlY(qreal y) } } -void QFxPathQuad::addToPath(QPainterPath &path) +void QmlGraphicsPathQuad::addToPath(QPainterPath &path) { path.quadTo(controlX(), controlY(), x(), y()); } @@ -691,11 +691,11 @@ void QFxPathQuad::addToPath(QPainterPath &path) /*! \internal - \class QFxPathCubic + \class QmlGraphicsPathCubic \ingroup group_utility - \brief The QFxPathCubic class defines a cubic Bezier curve with two control points. + \brief The QmlGraphicsPathCubic class defines a cubic Bezier curve with two control points. - \sa QFxPath + \sa QmlGraphicsPath */ /*! @@ -711,12 +711,12 @@ void QFxPathQuad::addToPath(QPainterPath &path) Defines the position of the first control point. */ -qreal QFxPathCubic::control1X() const +qreal QmlGraphicsPathCubic::control1X() const { return _control1X; } -void QFxPathCubic::setControl1X(qreal x) +void QmlGraphicsPathCubic::setControl1X(qreal x) { if (_control1X != x) { _control1X = x; @@ -724,12 +724,12 @@ void QFxPathCubic::setControl1X(qreal x) } } -qreal QFxPathCubic::control1Y() const +qreal QmlGraphicsPathCubic::control1Y() const { return _control1Y; } -void QFxPathCubic::setControl1Y(qreal y) +void QmlGraphicsPathCubic::setControl1Y(qreal y) { if (_control1Y != y) { _control1Y = y; @@ -743,12 +743,12 @@ void QFxPathCubic::setControl1Y(qreal y) Defines the position of the second control point. */ -qreal QFxPathCubic::control2X() const +qreal QmlGraphicsPathCubic::control2X() const { return _control2X; } -void QFxPathCubic::setControl2X(qreal x) +void QmlGraphicsPathCubic::setControl2X(qreal x) { if (_control2X != x) { _control2X = x; @@ -756,12 +756,12 @@ void QFxPathCubic::setControl2X(qreal x) } } -qreal QFxPathCubic::control2Y() const +qreal QmlGraphicsPathCubic::control2Y() const { return _control2Y; } -void QFxPathCubic::setControl2Y(qreal y) +void QmlGraphicsPathCubic::setControl2Y(qreal y) { if (_control2Y != y) { _control2Y = y; @@ -769,7 +769,7 @@ void QFxPathCubic::setControl2Y(qreal y) } } -void QFxPathCubic::addToPath(QPainterPath &path) +void QmlGraphicsPathCubic::addToPath(QPainterPath &path) { path.cubicTo(control1X(), control1Y(), control2X(), control2Y(), x(), y()); } @@ -816,23 +816,23 @@ void QFxPathCubic::addToPath(QPainterPath &path) /*! \internal - \class QFxPathPercent + \class QmlGraphicsPathPercent \ingroup group_utility - \brief The QFxPathPercent class manipulates the way a path is interpreted. + \brief The QmlGraphicsPathPercent class manipulates the way a path is interpreted. - QFxPathPercent allows you to bunch up items (or spread out items) along various - segments of a QFxPathView's path. + QmlGraphicsPathPercent allows you to bunch up items (or spread out items) along various + segments of a QmlGraphicsPathView's path. - \sa QFxPath + \sa QmlGraphicsPath */ -qreal QFxPathPercent::value() const +qreal QmlGraphicsPathPercent::value() const { return _value; } -void QFxPathPercent::setValue(qreal value) +void QmlGraphicsPathPercent::setValue(qreal value) { _value = value; } diff --git a/src/declarative/fx/qfxpath.h b/src/declarative/fx/qfxpath.h index 04d24c6..e724474 100644 --- a/src/declarative/fx/qfxpath.h +++ b/src/declarative/fx/qfxpath.h @@ -53,23 +53,23 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class Q_DECLARATIVE_EXPORT QFxPathElement : public QObject +class Q_DECLARATIVE_EXPORT QmlGraphicsPathElement : public QObject { Q_OBJECT public: - QFxPathElement(QObject *parent=0) : QObject(parent) {} + QmlGraphicsPathElement(QObject *parent=0) : QObject(parent) {} Q_SIGNALS: void changed(); }; -class Q_DECLARATIVE_EXPORT QFxPathAttribute : public QFxPathElement +class Q_DECLARATIVE_EXPORT QmlGraphicsPathAttribute : public QmlGraphicsPathElement { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) public: - QFxPathAttribute(QObject *parent=0) : QFxPathElement(parent), _value(0) {} + QmlGraphicsPathAttribute(QObject *parent=0) : QmlGraphicsPathElement(parent), _value(0) {} QString name() const; @@ -83,14 +83,14 @@ private: qreal _value; }; -class Q_DECLARATIVE_EXPORT QFxCurve : public QFxPathElement +class Q_DECLARATIVE_EXPORT QmlGraphicsCurve : public QmlGraphicsPathElement { Q_OBJECT Q_PROPERTY(qreal x READ x WRITE setX NOTIFY changed) Q_PROPERTY(qreal y READ y WRITE setY NOTIFY changed) public: - QFxCurve(QObject *parent=0) : QFxPathElement(parent), _x(0), _y(0) {} + QmlGraphicsCurve(QObject *parent=0) : QmlGraphicsPathElement(parent), _x(0), _y(0) {} qreal x() const; void setX(qreal x); @@ -105,23 +105,23 @@ private: qreal _y; }; -class Q_DECLARATIVE_EXPORT QFxPathLine : public QFxCurve +class Q_DECLARATIVE_EXPORT QmlGraphicsPathLine : public QmlGraphicsCurve { Q_OBJECT public: - QFxPathLine(QObject *parent=0) : QFxCurve(parent) {} + QmlGraphicsPathLine(QObject *parent=0) : QmlGraphicsCurve(parent) {} void addToPath(QPainterPath &path); }; -class Q_DECLARATIVE_EXPORT QFxPathQuad : public QFxCurve +class Q_DECLARATIVE_EXPORT QmlGraphicsPathQuad : public QmlGraphicsCurve { Q_OBJECT Q_PROPERTY(qreal controlX READ controlX WRITE setControlX NOTIFY changed) Q_PROPERTY(qreal controlY READ controlY WRITE setControlY NOTIFY changed) public: - QFxPathQuad(QObject *parent=0) : QFxCurve(parent), _controlX(0), _controlY(0) {} + QmlGraphicsPathQuad(QObject *parent=0) : QmlGraphicsCurve(parent), _controlX(0), _controlY(0) {} qreal controlX() const; void setControlX(qreal x); @@ -136,7 +136,7 @@ private: qreal _controlY; }; -class Q_DECLARATIVE_EXPORT QFxPathCubic : public QFxCurve +class Q_DECLARATIVE_EXPORT QmlGraphicsPathCubic : public QmlGraphicsCurve { Q_OBJECT @@ -145,7 +145,7 @@ class Q_DECLARATIVE_EXPORT QFxPathCubic : public QFxCurve Q_PROPERTY(qreal control2X READ control2X WRITE setControl2X NOTIFY changed) Q_PROPERTY(qreal control2Y READ control2Y WRITE setControl2Y NOTIFY changed) public: - QFxPathCubic(QObject *parent=0) : QFxCurve(parent), _control1X(0), _control1Y(0), _control2X(0), _control2Y(0) {} + QmlGraphicsPathCubic(QObject *parent=0) : QmlGraphicsCurve(parent), _control1X(0), _control1Y(0), _control2X(0), _control2Y(0) {} qreal control1X() const; void setControl1X(qreal x); @@ -168,12 +168,12 @@ private: int _control2Y; }; -class Q_DECLARATIVE_EXPORT QFxPathPercent : public QFxPathElement +class Q_DECLARATIVE_EXPORT QmlGraphicsPathPercent : public QmlGraphicsPathElement { Q_OBJECT Q_PROPERTY(qreal value READ value WRITE setValue) public: - QFxPathPercent(QObject *parent=0) : QFxPathElement(parent) {} + QmlGraphicsPathPercent(QObject *parent=0) : QmlGraphicsPathElement(parent) {} qreal value() const; void setValue(qreal value); @@ -182,22 +182,22 @@ private: qreal _value; }; -class QFxPathPrivate; -class Q_DECLARATIVE_EXPORT QFxPath : public QObject, public QmlParserStatus +class QmlGraphicsPathPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsPath : public QObject, public QmlParserStatus { Q_OBJECT Q_INTERFACES(QmlParserStatus) - Q_PROPERTY(QList* pathElements READ pathElements) + Q_PROPERTY(QList* pathElements READ pathElements) Q_PROPERTY(qreal startX READ startX WRITE setStartX) Q_PROPERTY(qreal startY READ startY WRITE setStartY) Q_CLASSINFO("DefaultProperty", "pathElements") Q_INTERFACES(QmlParserStatus) public: - QFxPath(QObject *parent=0); - ~QFxPath(); + QmlGraphicsPath(QObject *parent=0); + ~QmlGraphicsPath(); - QList* pathElements(); + QList* pathElements(); qreal startX() const; void setStartX(qreal x); @@ -215,7 +215,7 @@ Q_SIGNALS: protected: virtual void componentComplete(); - QFxPath(QFxPathPrivate &dd, QObject *parent); + QmlGraphicsPath(QmlGraphicsPathPrivate &dd, QObject *parent); private Q_SLOTS: void processPath(); @@ -239,20 +239,20 @@ private: void createPointCache() const; private: - Q_DISABLE_COPY(QFxPath) - Q_DECLARE_PRIVATE(QFxPath) + Q_DISABLE_COPY(QmlGraphicsPath) + Q_DECLARE_PRIVATE(QmlGraphicsPath) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxPathElement) -QML_DECLARE_TYPE(QFxPathAttribute) -QML_DECLARE_TYPE(QFxCurve) -QML_DECLARE_TYPE(QFxPathLine) -QML_DECLARE_TYPE(QFxPathQuad) -QML_DECLARE_TYPE(QFxPathCubic) -QML_DECLARE_TYPE(QFxPathPercent) -QML_DECLARE_TYPE(QFxPath) +QML_DECLARE_TYPE(QmlGraphicsPathElement) +QML_DECLARE_TYPE(QmlGraphicsPathAttribute) +QML_DECLARE_TYPE(QmlGraphicsCurve) +QML_DECLARE_TYPE(QmlGraphicsPathLine) +QML_DECLARE_TYPE(QmlGraphicsPathQuad) +QML_DECLARE_TYPE(QmlGraphicsPathCubic) +QML_DECLARE_TYPE(QmlGraphicsPathPercent) +QML_DECLARE_TYPE(QmlGraphicsPath) QT_END_HEADER diff --git a/src/declarative/fx/qfxpath_p.h b/src/declarative/fx/qfxpath_p.h index d4a419a..49bd0d8 100644 --- a/src/declarative/fx/qfxpath_p.h +++ b/src/declarative/fx/qfxpath_p.h @@ -59,17 +59,17 @@ QT_BEGIN_NAMESPACE -class QFxPathPrivate : public QObjectPrivate +class QmlGraphicsPathPrivate : public QObjectPrivate { - Q_DECLARE_PUBLIC(QFxPath) + Q_DECLARE_PUBLIC(QmlGraphicsPath) public: - QFxPathPrivate() : startX(0), startY(0) { } + QmlGraphicsPathPrivate() : startX(0), startY(0) { } QPainterPath _path; - QList _pathElements; + QList _pathElements; mutable QVector _pointCache; - QList _attributePoints; + QList _attributePoints; QStringList _attributes; int startX; int startY; diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp index c580e98..fd7d734 100644 --- a/src/declarative/fx/qfxpathview.cpp +++ b/src/declarative/fx/qfxpathview.cpp @@ -54,20 +54,20 @@ static const int FlickThreshold = 5; QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathView,QFxPathView) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathView,QmlGraphicsPathView) -class QFxPathViewAttached : public QObject +class QmlGraphicsPathViewAttached : public QObject { Q_OBJECT public: - QFxPathViewAttached(QObject *parent) + QmlGraphicsPathViewAttached(QObject *parent) : QObject(parent), mo(new QmlOpenMetaObject(this)) { } - ~QFxPathViewAttached() + ~QmlGraphicsPathViewAttached() { - QFxPathView::attachedProperties.remove(parent()); + QmlGraphicsPathView::attachedProperties.remove(parent()); } QVariant value(const QByteArray &name) const @@ -86,14 +86,14 @@ private: /*! \internal - \class QFxPathView - \brief The QFxPathView class lays out items provided by a model on a path. + \class QmlGraphicsPathView + \brief The QmlGraphicsPathView class lays out items provided by a model on a path. \ingroup group_views The model must be a \l QListModelInterface subclass. - \sa QFxPath + \sa QmlGraphicsPath */ /*! @@ -112,23 +112,23 @@ private: \sa Path */ -QFxPathView::QFxPathView(QFxItem *parent) - : QFxItem(*(new QFxPathViewPrivate), parent) +QmlGraphicsPathView::QmlGraphicsPathView(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsPathViewPrivate), parent) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); d->init(); } -QFxPathView::QFxPathView(QFxPathViewPrivate &dd, QFxItem *parent) - : QFxItem(dd, parent) +QmlGraphicsPathView::QmlGraphicsPathView(QmlGraphicsPathViewPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); d->init(); } -QFxPathView::~QFxPathView() +QmlGraphicsPathView::~QmlGraphicsPathView() { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); if (d->ownModel) delete d->model; } @@ -143,21 +143,21 @@ QFxPathView::~QFxPathView() \sa {qmlmodels}{Data Models} */ -QVariant QFxPathView::model() const +QVariant QmlGraphicsPathView::model() const { - Q_D(const QFxPathView); + Q_D(const QmlGraphicsPathView); return d->modelVariant; } -void QFxPathView::setModel(const QVariant &model) +void QmlGraphicsPathView::setModel(const QVariant &model) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); - disconnect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); + disconnect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); for (int i=0; iitems.count(); i++){ - QFxItem *p = d->items[i]; + QmlGraphicsItem *p = d->items[i]; d->model->release(p); } d->items.clear(); @@ -165,8 +165,8 @@ void QFxPathView::setModel(const QVariant &model) d->modelVariant = model; QObject *object = qvariant_cast(model); - QFxVisualModel *vim = 0; - if (object && (vim = qobject_cast(object))) { + QmlGraphicsVisualModel *vim = 0; + if (object && (vim = qobject_cast(object))) { if (d->ownModel) { delete d->model; d->ownModel = false; @@ -174,16 +174,16 @@ void QFxPathView::setModel(const QVariant &model) d->model = vim; } else { if (!d->ownModel) { - d->model = new QFxVisualDataModel(qmlContext(this)); + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); d->ownModel = true; } - if (QFxVisualDataModel *dataModel = qobject_cast(d->model)) + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) dataModel->setModel(model); } if (d->model) { connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); - connect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); + connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); } d->firstIndex = 0; d->pathOffset = 0; @@ -195,9 +195,9 @@ void QFxPathView::setModel(const QVariant &model) \qmlproperty int PathView::count This property holds the number of items in the model. */ -int QFxPathView::count() const +int QmlGraphicsPathView::count() const { - Q_D(const QFxPathView); + Q_D(const QmlGraphicsPathView); return d->model ? d->model->count() : 0; } @@ -207,15 +207,15 @@ int QFxPathView::count() const This property holds the path used to lay out the items. For more information see the \l Path documentation. */ -QFxPath *QFxPathView::path() const +QmlGraphicsPath *QmlGraphicsPathView::path() const { - Q_D(const QFxPathView); + Q_D(const QmlGraphicsPathView); return d->path; } -void QFxPathView::setPath(QFxPath *path) +void QmlGraphicsPathView::setPath(QmlGraphicsPath *path) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); d->path = path; connect(d->path, SIGNAL(changed()), this, SLOT(refill())); d->regenerate(); @@ -225,15 +225,15 @@ void QFxPathView::setPath(QFxPath *path) \qmlproperty int PathView::currentIndex This property holds the index of the current item. */ -int QFxPathView::currentIndex() const +int QmlGraphicsPathView::currentIndex() const { - Q_D(const QFxPathView); + Q_D(const QmlGraphicsPathView); return d->currentIndex; } -void QFxPathView::setCurrentIndex(int idx) +void QmlGraphicsPathView::setCurrentIndex(int idx) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); if (d->model && d->model->count()) idx = qAbs(idx % d->model->count()); if (d->model && idx != d->currentIndex) { @@ -253,22 +253,22 @@ void QFxPathView::setCurrentIndex(int idx) The offset specifies how far along the path the items are from their initial positions. */ -qreal QFxPathView::offset() const +qreal QmlGraphicsPathView::offset() const { - Q_D(const QFxPathView); + Q_D(const QmlGraphicsPathView); return d->_offset; } -void QFxPathView::setOffset(qreal offset) +void QmlGraphicsPathView::setOffset(qreal offset) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); d->setOffset(offset); d->updateCurrent(); } -void QFxPathViewPrivate::setOffset(qreal o) +void QmlGraphicsPathViewPrivate::setOffset(qreal o) { - Q_Q(QFxPathView); + Q_Q(QmlGraphicsPathView); if (_offset != o) { _offset = fmod(o, 100.0); if (_offset < 0) @@ -282,15 +282,15 @@ void QFxPathViewPrivate::setOffset(qreal o) This property determines the position (0-100) the nearest item will snap to. */ -qreal QFxPathView::snapPosition() const +qreal QmlGraphicsPathView::snapPosition() const { - Q_D(const QFxPathView); + Q_D(const QmlGraphicsPathView); return d->snapPos; } -void QFxPathView::setSnapPosition(qreal pos) +void QmlGraphicsPathView::setSnapPosition(qreal pos) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); d->snapPos = pos/100; d->fixOffset(); } @@ -303,15 +303,15 @@ void QFxPathView::setSnapPosition(qreal pos) dragMargin is greater than zero, a drag can be initiated by clicking within dragMargin pixels of the path. */ -qreal QFxPathView::dragMargin() const +qreal QmlGraphicsPathView::dragMargin() const { - Q_D(const QFxPathView); + Q_D(const QmlGraphicsPathView); return d->dragMargin; } -void QFxPathView::setDragMargin(qreal dragMargin) +void QmlGraphicsPathView::setDragMargin(qreal dragMargin) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); d->dragMargin = dragMargin; } @@ -323,25 +323,25 @@ void QFxPathView::setDragMargin(qreal dragMargin) Here is an example delegate: \snippet doc/src/snippets/declarative/pathview/pathview.qml 1 */ -QmlComponent *QFxPathView::delegate() const +QmlComponent *QmlGraphicsPathView::delegate() const { - Q_D(const QFxPathView); + Q_D(const QmlGraphicsPathView); if (d->model) { - if (QFxVisualDataModel *dataModel = qobject_cast(d->model)) + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) return dataModel->delegate(); } return 0; } -void QFxPathView::setDelegate(QmlComponent *c) +void QmlGraphicsPathView::setDelegate(QmlComponent *c) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); if (!d->ownModel) { - d->model = new QFxVisualDataModel(qmlContext(this)); + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); d->ownModel = true; } - if (QFxVisualDataModel *dataModel = qobject_cast(d->model)) { + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) { dataModel->setDelegate(c); d->regenerate(); } @@ -351,22 +351,22 @@ void QFxPathView::setDelegate(QmlComponent *c) \qmlproperty int PathView::pathItemCount This property holds the number of items visible on the path at any one time */ -int QFxPathView::pathItemCount() const +int QmlGraphicsPathView::pathItemCount() const { - Q_D(const QFxPathView); + Q_D(const QmlGraphicsPathView); return d->pathItems; } -void QFxPathView::setPathItemCount(int i) +void QmlGraphicsPathView::setPathItemCount(int i) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); if (i == d->pathItems) return; d->pathItems = i; d->regenerate(); } -QPointF QFxPathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const +QPointF QmlGraphicsPathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const { //XXX maybe do recursively at increasing resolution. qreal mindist = 1e10; // big number @@ -390,9 +390,9 @@ QPointF QFxPathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) } -void QFxPathView::mousePressEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsPathView::mousePressEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); if (!d->items.count()) return; QPointF scenePoint = mapToScene(event->pos()); @@ -416,13 +416,13 @@ void QFxPathView::mousePressEvent(QGraphicsSceneMouseEvent *event) d->stealMouse = false; d->lastElapsed = 0; d->lastDist = 0; - QFxItemPrivate::start(d->lastPosTime); + QmlGraphicsItemPrivate::start(d->lastPosTime); d->tl.clear(); } -void QFxPathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsPathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); if (d->lastPosTime.isNull()) return; @@ -433,7 +433,7 @@ void QFxPathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } if (d->stealMouse) { - d->moveReason = QFxPathViewPrivate::Mouse; + d->moveReason = QmlGraphicsPathViewPrivate::Mouse; qreal newPc; d->pointNear(event->pos(), &newPc); qreal diff = newPc - d->startPc; @@ -445,20 +445,20 @@ void QFxPathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) else if (diff < -50) diff += 100; - d->lastElapsed = QFxItemPrivate::restart(d->lastPosTime); + d->lastElapsed = QmlGraphicsItemPrivate::restart(d->lastPosTime); d->lastDist = diff; d->startPc = newPc; } } } -void QFxPathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) +void QmlGraphicsPathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); if (d->lastPosTime.isNull()) return; - qreal elapsed = qreal(d->lastElapsed + QFxItemPrivate::elapsed(d->lastPosTime)) / 1000.; + qreal elapsed = qreal(d->lastElapsed + QmlGraphicsItemPrivate::elapsed(d->lastPosTime)) / 1000.; qreal velocity = elapsed > 0. ? d->lastDist / elapsed : 0; if (d->model && d->model->count() && qAbs(velocity) > 5) { if (velocity > 100) @@ -479,13 +479,13 @@ void QFxPathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) ungrabMouse(); } -bool QFxPathView::sendMouseEvent(QGraphicsSceneMouseEvent *event) +bool QmlGraphicsPathView::sendMouseEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); QGraphicsSceneMouseEvent mouseEvent(event->type()); QRectF myRect = mapToScene(QRectF(0, 0, width(), height())).boundingRect(); QGraphicsScene *s = scene(); - QFxItem *grabber = s ? qobject_cast(s->mouseGrabberItem()) : 0; + QmlGraphicsItem *grabber = s ? qobject_cast(s->mouseGrabberItem()) : 0; if ((d->stealMouse || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) { mouseEvent.setAccepted(false); for (int i = 0x1; i <= 0x10; i <<= 1) { @@ -512,7 +512,7 @@ bool QFxPathView::sendMouseEvent(QGraphicsSceneMouseEvent *event) default: break; } - grabber = qobject_cast(s->mouseGrabberItem()); + grabber = qobject_cast(s->mouseGrabberItem()); if (grabber && d->stealMouse && !grabber->keepMouseGrab() && grabber != this) grabMouse(); @@ -523,10 +523,10 @@ bool QFxPathView::sendMouseEvent(QGraphicsSceneMouseEvent *event) return false; } -bool QFxPathView::sceneEventFilter(QGraphicsItem *i, QEvent *e) +bool QmlGraphicsPathView::sceneEventFilter(QGraphicsItem *i, QEvent *e) { if (!isVisible()) - return QFxItem::sceneEventFilter(i, e); + return QmlGraphicsItem::sceneEventFilter(i, e); switch (e->type()) { case QEvent::GraphicsSceneMousePress: @@ -542,13 +542,13 @@ bool QFxPathView::sceneEventFilter(QGraphicsItem *i, QEvent *e) break; } - return QFxItem::sceneEventFilter(i, e); + return QmlGraphicsItem::sceneEventFilter(i, e); } -void QFxPathView::componentComplete() +void QmlGraphicsPathView::componentComplete() { - Q_D(QFxPathView); - QFxItem::componentComplete(); + Q_D(QmlGraphicsPathView); + QmlGraphicsItem::componentComplete(); d->regenerate(); // move to correct offset @@ -567,14 +567,14 @@ void QFxPathView::componentComplete() } } -void QFxPathViewPrivate::regenerate() +void QmlGraphicsPathViewPrivate::regenerate() { - Q_Q(QFxPathView); + Q_Q(QmlGraphicsPathView); if (!q->isComponentComplete()) return; for (int i=0; i= 0 ? pathItems : model->count(); for (int i=0; i < numItems && i < model->count(); ++i){ int index = (i + firstIndex) % model->count(); - QFxItem *item = getItem(index); + QmlGraphicsItem *item = getItem(index); if (!item) { qWarning() << "PathView: Cannot create item, index" << (i + firstIndex) % model->count(); return; @@ -603,20 +603,20 @@ void QFxPathViewPrivate::regenerate() q->refill(); } -void QFxPathViewPrivate::updateItem(QFxItem *item, qreal percent) +void QmlGraphicsPathViewPrivate::updateItem(QmlGraphicsItem *item, qreal percent) { - if (QObject *obj = QFxPathView::qmlAttachedProperties(item)) { + if (QObject *obj = QmlGraphicsPathView::qmlAttachedProperties(item)) { foreach(const QString &attr, path->attributes()) - static_cast(obj)->setValue(attr.toUtf8(), path->attributeAt(attr, percent)); + static_cast(obj)->setValue(attr.toUtf8(), path->attributeAt(attr, percent)); } QPointF pf = path->pointAt(percent); item->setX(pf.x() - item->width()*item->scale()/2); item->setY(pf.y() - item->height()*item->scale()/2); } -void QFxPathView::refill() +void QmlGraphicsPathView::refill() { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); if (!d->isValid() || !isComponentComplete()) return; @@ -649,13 +649,13 @@ void QFxPathView::refill() //A wraparound has occured if (wrapIndex < d->items.count()/2){ while(wrapIndex-- >= 0){ - QFxItem* p = d->items.takeFirst(); + QmlGraphicsItem* p = d->items.takeFirst(); d->updateItem(p, 0.0); d->releaseItem(p); d->firstIndex++; d->firstIndex %= d->model->count(); int index = (d->firstIndex + d->items.count())%d->model->count(); - QFxItem *item = d->getItem(index); + QmlGraphicsItem *item = d->getItem(index); item->setZValue(wrapIndex); if (d->currentIndex == index) item->setFocus(true); @@ -665,13 +665,13 @@ void QFxPathView::refill() } } else { while(wrapIndex++ < d->items.count()-1){ - QFxItem* p = d->items.takeLast(); + QmlGraphicsItem* p = d->items.takeLast(); d->updateItem(p, 1.0); d->releaseItem(p); d->firstIndex--; if (d->firstIndex < 0) d->firstIndex = d->model->count() - 1; - QFxItem *item = d->getItem(d->firstIndex); + QmlGraphicsItem *item = d->getItem(d->firstIndex); item->setZValue(d->firstIndex); if (d->currentIndex == d->firstIndex) item->setFocus(true); @@ -689,15 +689,15 @@ void QFxPathView::refill() d->updateItem(d->items.at(i), rotatedPositions[i]); } -void QFxPathView::itemsInserted(int modelIndex, int count) +void QmlGraphicsPathView::itemsInserted(int modelIndex, int count) { //XXX support animated insertion - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); if (!d->isValid() || !isComponentComplete()) return; if (d->pathItems == -1) { for (int i = 0; i < count; ++i) { - QFxItem *item = d->getItem(modelIndex + i); + QmlGraphicsItem *item = d->getItem(modelIndex + i); item->setZValue(modelIndex + i); d->items.insert(modelIndex + i, item); } @@ -719,15 +719,15 @@ void QFxPathView::itemsInserted(int modelIndex, int count) d->moveOffset.setValue(targetOffset); } -void QFxPathView::itemsRemoved(int modelIndex, int count) +void QmlGraphicsPathView::itemsRemoved(int modelIndex, int count) { //XXX support animated removal - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); if (!d->isValid() || !isComponentComplete()) return; if (d->pathItems == -1) { for (int i = 0; i < count; ++i) { - QFxItem* p = d->items.takeAt(modelIndex); + QmlGraphicsItem* p = d->items.takeAt(modelIndex); d->model->release(p); } d->snapToCurrent(); @@ -756,28 +756,28 @@ void QFxPathView::itemsRemoved(int modelIndex, int count) d->moveOffset.setValue(targetOffset); } -void QFxPathView::createdItem(int index, QFxItem *item) +void QmlGraphicsPathView::createdItem(int index, QmlGraphicsItem *item) { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); if (d->requestedIndex != index) { item->setParentItem(this); d->updateItem(item, index < d->firstIndex ? 0.0 : 1.0); } } -void QFxPathView::destroyingItem(QFxItem *item) +void QmlGraphicsPathView::destroyingItem(QmlGraphicsItem *item) { Q_UNUSED(item); } -void QFxPathView::ticked() +void QmlGraphicsPathView::ticked() { - Q_D(QFxPathView); + Q_D(QmlGraphicsPathView); d->updateCurrent(); } // find the item closest to the snap position -int QFxPathViewPrivate::calcCurrentIndex() +int QmlGraphicsPathViewPrivate::calcCurrentIndex() { int current = -1; if (model && items.count()) { @@ -816,9 +816,9 @@ int QFxPathViewPrivate::calcCurrentIndex() return current; } -void QFxPathViewPrivate::updateCurrent() +void QmlGraphicsPathViewPrivate::updateCurrent() { - Q_Q(QFxPathView); + Q_Q(QmlGraphicsPathView); if (moveReason != Mouse) return; int idx = calcCurrentIndex(); @@ -831,9 +831,9 @@ void QFxPathViewPrivate::updateCurrent() } } -void QFxPathViewPrivate::fixOffset() +void QmlGraphicsPathViewPrivate::fixOffset() { - Q_Q(QFxPathView); + Q_Q(QmlGraphicsPathView); if (model && items.count()) { int curr = calcCurrentIndex(); if (curr != currentIndex) @@ -843,7 +843,7 @@ void QFxPathViewPrivate::fixOffset() } } -void QFxPathViewPrivate::snapToCurrent() +void QmlGraphicsPathViewPrivate::snapToCurrent() { if (!model || model->count() <= 0) return; @@ -897,12 +897,12 @@ void QFxPathViewPrivate::snapToCurrent() } } -QHash QFxPathView::attachedProperties; -QObject *QFxPathView::qmlAttachedProperties(QObject *obj) +QHash QmlGraphicsPathView::attachedProperties; +QObject *QmlGraphicsPathView::qmlAttachedProperties(QObject *obj) { QObject *rv = attachedProperties.value(obj); if (!rv) { - rv = new QFxPathViewAttached(obj); + rv = new QmlGraphicsPathViewAttached(obj); attachedProperties.insert(obj, rv); } return rv; diff --git a/src/declarative/fx/qfxpathview.h b/src/declarative/fx/qfxpathview.h index c8c0ac0..e961106 100644 --- a/src/declarative/fx/qfxpathview.h +++ b/src/declarative/fx/qfxpathview.h @@ -52,13 +52,13 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QListModelInterface; -class QFxPathViewPrivate; -class Q_DECLARATIVE_EXPORT QFxPathView : public QFxItem +class QmlGraphicsPathViewPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsPathView : public QmlGraphicsItem { Q_OBJECT Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QFxPath *path READ path WRITE setPath) + Q_PROPERTY(QmlGraphicsPath *path READ path WRITE setPath) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged) Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition) @@ -68,14 +68,14 @@ class Q_DECLARATIVE_EXPORT QFxPathView : public QFxItem Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount) public: - QFxPathView(QFxItem *parent=0); - virtual ~QFxPathView(); + QmlGraphicsPathView(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsPathView(); QVariant model() const; void setModel(const QVariant &); - QFxPath *path() const; - void setPath(QFxPath *); + QmlGraphicsPath *path() const; + void setPath(QmlGraphicsPath *); int currentIndex() const; void setCurrentIndex(int idx); @@ -116,23 +116,23 @@ private Q_SLOTS: void ticked(); void itemsInserted(int index, int count); void itemsRemoved(int index, int count); - void createdItem(int index, QFxItem *item); - void destroyingItem(QFxItem *item); + void createdItem(int index, QmlGraphicsItem *item); + void destroyingItem(QmlGraphicsItem *item); protected: - QFxPathView(QFxPathViewPrivate &dd, QFxItem *parent); + QmlGraphicsPathView(QmlGraphicsPathViewPrivate &dd, QmlGraphicsItem *parent); private: - friend class QFxPathViewAttached; + friend class QmlGraphicsPathViewAttached; static QHash attachedProperties; - Q_DISABLE_COPY(QFxPathView) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxPathView) + Q_DISABLE_COPY(QmlGraphicsPathView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsPathView) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxPathView) -QML_DECLARE_TYPEINFO(QFxPathView, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QmlGraphicsPathView) +QML_DECLARE_TYPEINFO(QmlGraphicsPathView, QML_HAS_ATTACHED_PROPERTIES) QT_END_HEADER #endif // QFXPATHVIEW_H diff --git a/src/declarative/fx/qfxpathview_p.h b/src/declarative/fx/qfxpathview_p.h index 60bfdb3..23b468c 100644 --- a/src/declarative/fx/qfxpathview_p.h +++ b/src/declarative/fx/qfxpathview_p.h @@ -64,27 +64,27 @@ QT_BEGIN_NAMESPACE typedef struct PathViewItem{ int index; - QFxItem* item; + QmlGraphicsItem* item; }PathViewItem; -class QFxPathViewPrivate : public QFxItemPrivate +class QmlGraphicsPathViewPrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxPathView) + Q_DECLARE_PUBLIC(QmlGraphicsPathView) public: - QFxPathViewPrivate() + QmlGraphicsPathViewPrivate() : path(0), currentIndex(0), startPc(0), lastDist(0) , lastElapsed(0), stealMouse(false), ownModel(false), activeItem(0) - , snapPos(0), dragMargin(0), moveOffset(this, &QFxPathViewPrivate::setOffset) + , snapPos(0), dragMargin(0), moveOffset(this, &QmlGraphicsPathViewPrivate::setOffset) , firstIndex(0), pathItems(-1), pathOffset(0), requestedIndex(-1), model(0) , moveReason(Other) { - fixupOffsetEvent = QmlTimeLineEvent::timeLineEvent(&moveOffset, this); + fixupOffsetEvent = QmlTimeLineEvent::timeLineEvent(&moveOffset, this); } void init() { - Q_Q(QFxPathView); + Q_Q(QmlGraphicsPathView); _offset = 0; q->setAcceptedMouseButtons(Qt::LeftButton); q->setFlag(QGraphicsItem::ItemIsFocusScope); @@ -92,16 +92,16 @@ public: q->connect(&tl, SIGNAL(updated()), q, SLOT(ticked())); } - QFxItem *getItem(int modelIndex) { - Q_Q(QFxPathView); + QmlGraphicsItem *getItem(int modelIndex) { + Q_Q(QmlGraphicsPathView); requestedIndex = modelIndex; - QFxItem *item = model->item(modelIndex); + QmlGraphicsItem *item = model->item(modelIndex); if (item) item->setParentItem(q); requestedIndex = -1; return item; } - void releaseItem(QFxItem *item) { + void releaseItem(QmlGraphicsItem *item) { model->release(item); } @@ -114,11 +114,11 @@ public: void fixOffset(); void setOffset(qreal offset); void regenerate(); - void updateItem(QFxItem *, qreal); + void updateItem(QmlGraphicsItem *, qreal); void snapToCurrent(); QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const; - QFxPath *path; + QmlGraphicsPath *path; int currentIndex; qreal startPc; QPointF startPoint; @@ -129,18 +129,18 @@ public: bool ownModel : 1; QTime lastPosTime; QPointF lastPos; - QFxItem *activeItem; + QmlGraphicsItem *activeItem; qreal snapPos; qreal dragMargin; QmlTimeLine tl; - QmlTimeLineValueProxy moveOffset; + QmlTimeLineValueProxy moveOffset; QmlTimeLineEvent fixupOffsetEvent; int firstIndex; int pathItems; int pathOffset; int requestedIndex; - QList items; - QFxVisualModel *model; + QList items; + QmlGraphicsVisualModel *model; QVariant modelVariant; enum MovementReason { Other, Key, Mouse }; MovementReason moveReason; diff --git a/src/declarative/fx/qfxpixmapcache.cpp b/src/declarative/fx/qfxpixmapcache.cpp index 13e1b16..4d6104c 100644 --- a/src/declarative/fx/qfxpixmapcache.cpp +++ b/src/declarative/fx/qfxpixmapcache.cpp @@ -51,8 +51,8 @@ QT_BEGIN_NAMESPACE class QSharedNetworkReply; -typedef QHash QFxSharedNetworkReplyHash; -static QFxSharedNetworkReplyHash qfxActiveNetworkReplies; +typedef QHash QmlGraphicsSharedNetworkReplyHash; +static QmlGraphicsSharedNetworkReplyHash qfxActiveNetworkReplies; class QSharedNetworkReply { @@ -118,8 +118,8 @@ static bool readImage(QIODevice *dev, QPixmap *pixmap) /*! \internal - \class QFxPixmapCache - \brief Enacapsultes a pixmap for QFx items. + \class QmlGraphicsPixmapCache + \brief Enacapsultes a pixmap for QmlGraphics items. This class is NOT reentrant. */ @@ -140,10 +140,10 @@ static QString toLocalFileOrQrc(const QUrl& url) Returns true if the image was loaded without error. */ -bool QFxPixmapCache::find(const QUrl& url, QPixmap *pixmap) +bool QmlGraphicsPixmapCache::find(const QUrl& url, QPixmap *pixmap) { #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer perf; + QmlPerfTimer perf; #endif QString key = url.toString(); @@ -166,10 +166,10 @@ bool QFxPixmapCache::find(const QUrl& url, QPixmap *pixmap) } else #endif { - QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); if (iter == qfxActiveNetworkReplies.end()) { // API usage error - qWarning() << "QFxPixmapCache: URL not loaded" << url; + qWarning() << "QmlGraphicsPixmapCache: URL not loaded" << url; ok = false; } else { if ((*iter)->reply->error()) { @@ -195,7 +195,7 @@ bool QFxPixmapCache::find(const QUrl& url, QPixmap *pixmap) #endif // We may be the second finder. Still need to check for active replies. { - QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); if (iter != qfxActiveNetworkReplies.end()) (*iter)->release(); } @@ -213,7 +213,7 @@ bool QFxPixmapCache::find(const QUrl& url, QPixmap *pixmap) The returned QNetworkReply will be deleted when all get() calls are matched by a corresponding find() call. */ -QNetworkReply *QFxPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap *pixmap) +QNetworkReply *QmlGraphicsPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap *pixmap) { #ifndef QT_NO_LOCALFILE_OPTIMIZED_QML QString lf = toLocalFileOrQrc(url); @@ -239,7 +239,7 @@ QNetworkReply *QFxPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap * return 0; } - QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); if (iter == qfxActiveNetworkReplies.end()) { QNetworkRequest req(url); QSharedNetworkReply *item = new QSharedNetworkReply(engine->networkAccessManager()->get(req)); @@ -259,10 +259,10 @@ QNetworkReply *QFxPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap * Any connections from the QNetworkReply returned by get() to \a obj will be disconnected. */ -void QFxPixmapCache::cancelGet(const QUrl& url, QObject* obj) +void QmlGraphicsPixmapCache::cancelGet(const QUrl& url, QObject* obj) { QString key = url.toString(); - QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); if (iter == qfxActiveNetworkReplies.end()) return; if (obj) @@ -274,7 +274,7 @@ void QFxPixmapCache::cancelGet(const QUrl& url, QObject* obj) This function is mainly for test verification. It returns the number of requests that are still unfinished. */ -int QFxPixmapCache::pendingRequests() +int QmlGraphicsPixmapCache::pendingRequests() { return qfxActiveNetworkReplies.count(); } diff --git a/src/declarative/fx/qfxpixmapcache.h b/src/declarative/fx/qfxpixmapcache.h index fb5b88a..2a5c4fa 100644 --- a/src/declarative/fx/qfxpixmapcache.h +++ b/src/declarative/fx/qfxpixmapcache.h @@ -54,13 +54,13 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QmlEngine; class QNetworkReply; -class Q_DECLARATIVE_EXPORT QFxPixmapCache +class Q_DECLARATIVE_EXPORT QmlGraphicsPixmapCache { public: static QNetworkReply *get(QmlEngine *, const QUrl& url, QPixmap *pixmap); static void cancelGet(const QUrl& url, QObject* obj); - static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QFxPixmapCache::get, and any returned reply finished. + static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QmlGraphicsPixmapCache::get, and any returned reply finished. static int pendingRequests(); // mainly for test verification }; diff --git a/src/declarative/fx/qfxpositioners.cpp b/src/declarative/fx/qfxpositioners.cpp index 86a069d..d7ae49d 100644 --- a/src/declarative/fx/qfxpositioners.cpp +++ b/src/declarative/fx/qfxpositioners.cpp @@ -54,11 +54,11 @@ QT_BEGIN_NAMESPACE /*! \internal - \class QFxBasePositioner + \class QmlGraphicsBasePositioner \ingroup group_layouts - \brief The QFxBasePositioner class provides a base for QFx layouts. + \brief The QmlGraphicsBasePositioner class provides a base for QmlGraphics layouts. - To create a QFx Positioner, simply subclass QFxBasePositioner and implement + To create a QmlGraphics Positioner, simply subclass QmlGraphicsBasePositioner and implement doLayout(), which is automatically called when the layout might need updating. @@ -70,29 +70,29 @@ QT_BEGIN_NAMESPACE Note also that the subclass is responsible for adding the spacing in between items. */ -QFxBasePositioner::QFxBasePositioner(AutoUpdateType at, QFxItem *parent) - : QFxItem(*(new QFxBasePositionerPrivate), parent) +QmlGraphicsBasePositioner::QmlGraphicsBasePositioner(AutoUpdateType at, QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsBasePositionerPrivate), parent) { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); d->init(at); } -QFxBasePositioner::QFxBasePositioner(QFxBasePositionerPrivate &dd, AutoUpdateType at, QFxItem *parent) - : QFxItem(dd, parent) +QmlGraphicsBasePositioner::QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, AutoUpdateType at, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); d->init(at); } -int QFxBasePositioner::spacing() const +int QmlGraphicsBasePositioner::spacing() const { - Q_D(const QFxBasePositioner); + Q_D(const QmlGraphicsBasePositioner); return d->_spacing; } -void QFxBasePositioner::setSpacing(int s) +void QmlGraphicsBasePositioner::setSpacing(int s) { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); if (s==d->_spacing) return; d->_spacing = s; @@ -100,52 +100,52 @@ void QFxBasePositioner::setSpacing(int s) emit spacingChanged(); } -QmlTransition *QFxBasePositioner::move() const +QmlTransition *QmlGraphicsBasePositioner::move() const { - Q_D(const QFxBasePositioner); + Q_D(const QmlGraphicsBasePositioner); return d->moveTransition; } -void QFxBasePositioner::setMove(QmlTransition *mt) +void QmlGraphicsBasePositioner::setMove(QmlTransition *mt) { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); d->moveTransition = mt; } -QmlTransition *QFxBasePositioner::add() const +QmlTransition *QmlGraphicsBasePositioner::add() const { - Q_D(const QFxBasePositioner); + Q_D(const QmlGraphicsBasePositioner); return d->addTransition; } -void QFxBasePositioner::setAdd(QmlTransition *add) +void QmlGraphicsBasePositioner::setAdd(QmlTransition *add) { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); d->addTransition = add; } -QmlTransition *QFxBasePositioner::remove() const +QmlTransition *QmlGraphicsBasePositioner::remove() const { - Q_D(const QFxBasePositioner); + Q_D(const QmlGraphicsBasePositioner); return d->removeTransition; } -void QFxBasePositioner::setRemove(QmlTransition *remove) +void QmlGraphicsBasePositioner::setRemove(QmlTransition *remove) { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); d->removeTransition = remove; } -void QFxBasePositioner::componentComplete() +void QmlGraphicsBasePositioner::componentComplete() { - QFxItem::componentComplete(); + QmlGraphicsItem::componentComplete(); #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer cc; + QmlPerfTimer cc; #endif prePositioning(); } -QVariant QFxBasePositioner::itemChange(GraphicsItemChange change, +QVariant QmlGraphicsBasePositioner::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemChildAddedChange || @@ -153,12 +153,12 @@ QVariant QFxBasePositioner::itemChange(GraphicsItemChange change, prePositioning(); } - return QFxItem::itemChange(change, value); + return QmlGraphicsItem::itemChange(change, value); } -bool QFxBasePositioner::event(QEvent *e) +bool QmlGraphicsBasePositioner::event(QEvent *e) { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); if (e->type() == QEvent::User) { d->_ep = false; d->_stableItems += d->_newItems; @@ -166,25 +166,25 @@ bool QFxBasePositioner::event(QEvent *e) d->_newItems.clear(); return true; } - return QFxItem::event(e); + return QmlGraphicsItem::event(e); } /*! Items that have just been added to the positioner. This includes invisible items that have turned visible. */ -QSet* QFxBasePositioner::newItems() +QSet* QmlGraphicsBasePositioner::newItems() { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); return &d->_newItems; } /*! Items that are visible in the positioner, not including ones that have just been added. */ -QSet* QFxBasePositioner::items() +QSet* QmlGraphicsBasePositioner::items() { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); return &d->_stableItems; } @@ -192,15 +192,15 @@ QSet* QFxBasePositioner::items() Items that have just left the positioner. This includes visible items that have turned invisible. */ -QSet* QFxBasePositioner::leavingItems() +QSet* QmlGraphicsBasePositioner::leavingItems() { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); return &d->_leavingItems; } -void QFxBasePositioner::prePositioning() +void QmlGraphicsBasePositioner::prePositioning() { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); if (!isComponentComplete() || d->_movingItem) return; @@ -208,10 +208,10 @@ void QFxBasePositioner::prePositioning() d->_ep = true; QCoreApplication::postEvent(this, new QEvent(QEvent::User)); } - QSet allItems; + QSet allItems; QList children = childItems(); for (int ii = 0; ii < children.count(); ++ii) { - QFxItem *child = qobject_cast(children.at(ii)); + QmlGraphicsItem *child = qobject_cast(children.at(ii)); if (!child) continue; if (!d->_items.contains(child)){ @@ -235,8 +235,8 @@ void QFxBasePositioner::prePositioning() } allItems += child; } - QSet deletedItems = d->_items - allItems; - foreach(QFxItem *child, d->_items){ + QSet deletedItems = d->_items - allItems; + foreach(QmlGraphicsItem *child, d->_items){ if (!allItems.contains(child)){ if (!deletedItems.contains(child)) { QObject::disconnect(child, SIGNAL(opacityChanged()), @@ -256,7 +256,7 @@ void QFxBasePositioner::prePositioning() //###To keep this valid, do we need to update on pos change as well? qreal h = 0.0f; qreal w = 0.0f; - foreach(QFxItem *child, d->_items){ + foreach(QmlGraphicsItem *child, d->_items){ if(!child->isVisible() || child->opacity() <= 0) continue; h = qMax(h, child->y() + child->height()); @@ -266,9 +266,9 @@ void QFxBasePositioner::prePositioning() setImplicitWidth(w); } -void QFxBasePositioner::applyTransition(const QList >& changes, QFxItem* target, QmlStateOperation::ActionList &actions) +void QmlGraphicsBasePositioner::applyTransition(const QList >& changes, QmlGraphicsItem* target, QmlStateOperation::ActionList &actions) { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); if (!target) return; @@ -282,9 +282,9 @@ void QFxBasePositioner::applyTransition(const QList >& d->_animated << target; } -void QFxBasePositioner::finishApplyTransitions() +void QmlGraphicsBasePositioner::finishApplyTransitions() { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); // Note that if a transition is not set the transition manager will // apply the changes directly, in the case someone uses applyAdd/Move/Remove // without testing add()/move()/remove(). @@ -295,9 +295,9 @@ void QFxBasePositioner::finishApplyTransitions() d->moveActions.clear(); d->removeActions.clear(); } -void QFxBasePositioner::setMovingItem(QFxItem *i) +void QmlGraphicsBasePositioner::setMovingItem(QmlGraphicsItem *i) { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); d->_movingItem = i; } @@ -305,9 +305,9 @@ void QFxBasePositioner::setMovingItem(QFxItem *i) Applies the positioner's add transition to the \a target item.\a changes is a list of property,value pairs which will be changed on the target using the add transition. */ -void QFxBasePositioner::applyAdd(const QList >& changes, QFxItem* target) +void QmlGraphicsBasePositioner::applyAdd(const QList >& changes, QmlGraphicsItem* target) { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); applyTransition(changes,target, d->addActions); } @@ -315,9 +315,9 @@ void QFxBasePositioner::applyAdd(const QList >& changes Applies the positioner's move transition to the \a target.\a changes is a list of property,value pairs which will be changed on the target using the move transition. */ -void QFxBasePositioner::applyMove(const QList >& changes, QFxItem* target) +void QmlGraphicsBasePositioner::applyMove(const QList >& changes, QmlGraphicsItem* target) { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); applyTransition(changes,target, d->moveActions); } @@ -325,13 +325,13 @@ void QFxBasePositioner::applyMove(const QList >& change Applies the positioner's remove transition to the \a target item.\a changes is a list of property,value pairs which will be changed on the target using the remove transition. */ -void QFxBasePositioner::applyRemove(const QList >& changes, QFxItem* target) +void QmlGraphicsBasePositioner::applyRemove(const QList >& changes, QmlGraphicsItem* target) { - Q_D(QFxBasePositioner); + Q_D(QmlGraphicsBasePositioner); applyTransition(changes,target, d->removeActions); } -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Column,QFxColumn) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Column,QmlGraphicsColumn) /*! \qmlclass Column \brief The Column item lines up its children vertically. @@ -472,20 +472,20 @@ Column { */ /*! \internal - \class QFxColumn - \brief The QFxColumn class lines up items vertically. + \class QmlGraphicsColumn + \brief The QmlGraphicsColumn class lines up items vertically. \ingroup group_positioners */ -QFxColumn::QFxColumn(QFxItem *parent) -: QFxBasePositioner(Vertical, parent) +QmlGraphicsColumn::QmlGraphicsColumn(QmlGraphicsItem *parent) +: QmlGraphicsBasePositioner(Vertical, parent) { } -void QFxColumn::doPositioning() +void QmlGraphicsColumn::doPositioning() { int voffset = 0; - foreach(QFxItem* item, *leavingItems()){ + foreach(QmlGraphicsItem* item, *leavingItems()){ if (remove()){ QList > changes; applyRemove(changes, item); @@ -494,7 +494,7 @@ void QFxColumn::doPositioning() QList children = childItems(); for (int ii = 0; ii < children.count(); ++ii) { - QFxItem *child = qobject_cast(children.at(ii)); + QmlGraphicsItem *child = qobject_cast(children.at(ii)); if (!child || child->opacity() == 0.0) continue; @@ -517,7 +517,7 @@ void QFxColumn::doPositioning() } } -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Row,QFxRow) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Row,QmlGraphicsRow) /*! \qmlclass Row \brief The Row item lines up its children horizontally. @@ -629,20 +629,20 @@ Row { */ /*! \internal - \class QFxRow - \brief The QFxRow class lines up items horizontally. + \class QmlGraphicsRow + \brief The QmlGraphicsRow class lines up items horizontally. \ingroup group_positioners */ -QFxRow::QFxRow(QFxItem *parent) -: QFxBasePositioner(Horizontal, parent) +QmlGraphicsRow::QmlGraphicsRow(QmlGraphicsItem *parent) +: QmlGraphicsBasePositioner(Horizontal, parent) { } -void QFxRow::doPositioning() +void QmlGraphicsRow::doPositioning() { int hoffset = 0; - foreach(QFxItem* item, *leavingItems()){ + foreach(QmlGraphicsItem* item, *leavingItems()){ if (remove()){ QList > changes; applyRemove(changes, item); @@ -650,7 +650,7 @@ void QFxRow::doPositioning() } QList children = childItems(); for (int ii = 0; ii < children.count(); ++ii) { - QFxItem *child = qobject_cast(children.at(ii)); + QmlGraphicsItem *child = qobject_cast(children.at(ii)); if (!child || child->opacity() == 0.0) continue; @@ -675,10 +675,10 @@ void QFxRow::doPositioning() } } -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Grid,QFxGrid) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Grid,QmlGraphicsGrid) /*! - \qmlclass Grid QFxGrid + \qmlclass Grid QmlGraphicsGrid \brief The Grid item positions its children in a grid. \inherits Item @@ -810,13 +810,13 @@ Grid { */ /*! \internal - \class QFxGrid - \brief The QFxGrid class lays out items in a grid. + \class QmlGraphicsGrid + \brief The QmlGraphicsGrid class lays out items in a grid. \ingroup group_layouts */ -QFxGrid::QFxGrid(QFxItem *parent) : - QFxBasePositioner(Both, parent) +QmlGraphicsGrid::QmlGraphicsGrid(QmlGraphicsItem *parent) : + QmlGraphicsBasePositioner(Both, parent) { _columns=-1; _rows=-1; @@ -840,7 +840,7 @@ QFxGrid::QFxGrid(QFxItem *parent) : many rows some rows will be of zero width. */ -void QFxGrid::doPositioning() +void QmlGraphicsGrid::doPositioning() { int c=_columns,r=_rows;//Actual number of rows/columns int numVisible = items()->size() + newItems()->size(); @@ -866,7 +866,7 @@ void QFxGrid::doPositioning() if (childIndex == children.count()) continue; - QFxItem *child = qobject_cast(children.at(childIndex++)); + QmlGraphicsItem *child = qobject_cast(children.at(childIndex++)); if (!child || child->opacity() == 0.0) continue; if (child->width() > maxColWidth[j]) @@ -880,14 +880,14 @@ void QFxGrid::doPositioning() int yoffset=0; int curRow =0; int curCol =0; - foreach(QFxItem* item, *leavingItems()){ + foreach(QmlGraphicsItem* item, *leavingItems()){ if (remove()){ QList > changes; applyRemove(changes, item); } } foreach(QGraphicsItem* schild, children){ - QFxItem *child = qobject_cast(schild); + QmlGraphicsItem *child = qobject_cast(schild); if (!child || child->opacity() == 0.0) continue; bool needMove = (child->x()!=xoffset)||(child->y()!=yoffset); diff --git a/src/declarative/fx/qfxpositioners.h b/src/declarative/fx/qfxpositioners.h index d62da08..29c121c 100644 --- a/src/declarative/fx/qfxpositioners.h +++ b/src/declarative/fx/qfxpositioners.h @@ -53,9 +53,9 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxBasePositionerPrivate; +class QmlGraphicsBasePositionerPrivate; -class Q_DECLARATIVE_EXPORT QFxBasePositioner : public QFxItem +class Q_DECLARATIVE_EXPORT QmlGraphicsBasePositioner : public QmlGraphicsItem { Q_OBJECT @@ -65,7 +65,7 @@ class Q_DECLARATIVE_EXPORT QFxBasePositioner : public QFxItem Q_PROPERTY(QmlTransition *remove READ remove WRITE setRemove) public: enum AutoUpdateType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 }; - QFxBasePositioner(AutoUpdateType, QFxItem *parent); + QmlGraphicsBasePositioner(AutoUpdateType, QmlGraphicsItem *parent); int spacing() const; void setSpacing(int); @@ -83,12 +83,12 @@ protected: virtual void componentComplete(); virtual QVariant itemChange(GraphicsItemChange, const QVariant &); virtual bool event(QEvent *); - QSet* newItems(); - QSet* leavingItems(); - QSet* items(); - void applyAdd(const QList >& changes, QFxItem* target); - void applyMove(const QList >& changes, QFxItem* target); - void applyRemove(const QList >& changes, QFxItem* target); + QSet* newItems(); + QSet* leavingItems(); + QSet* items(); + void applyAdd(const QList >& changes, QmlGraphicsItem* target); + void applyMove(const QList >& changes, QmlGraphicsItem* target); + void applyRemove(const QList >& changes, QmlGraphicsItem* target); void finishApplyTransitions(); Q_SIGNALS: @@ -102,45 +102,45 @@ private Q_SLOTS: void prePositioning(); protected: - QFxBasePositioner(QFxBasePositionerPrivate &dd, AutoUpdateType at, QFxItem *parent); - void setMovingItem(QFxItem *); + QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, AutoUpdateType at, QmlGraphicsItem *parent); + void setMovingItem(QmlGraphicsItem *); private: - void applyTransition(const QList >& changes, QFxItem* target, + void applyTransition(const QList >& changes, QmlGraphicsItem* target, QmlStateOperation::ActionList &actions); - Q_DISABLE_COPY(QFxBasePositioner) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxBasePositioner) + Q_DISABLE_COPY(QmlGraphicsBasePositioner) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsBasePositioner) }; -class Q_DECLARATIVE_EXPORT QFxColumn : public QFxBasePositioner +class Q_DECLARATIVE_EXPORT QmlGraphicsColumn : public QmlGraphicsBasePositioner { Q_OBJECT public: - QFxColumn(QFxItem *parent=0); + QmlGraphicsColumn(QmlGraphicsItem *parent=0); protected Q_SLOTS: virtual void doPositioning(); private: - Q_DISABLE_COPY(QFxColumn) + Q_DISABLE_COPY(QmlGraphicsColumn) }; -class Q_DECLARATIVE_EXPORT QFxRow: public QFxBasePositioner +class Q_DECLARATIVE_EXPORT QmlGraphicsRow: public QmlGraphicsBasePositioner { Q_OBJECT public: - QFxRow(QFxItem *parent=0); + QmlGraphicsRow(QmlGraphicsItem *parent=0); protected Q_SLOTS: virtual void doPositioning(); private: - Q_DISABLE_COPY(QFxRow) + Q_DISABLE_COPY(QmlGraphicsRow) }; -class Q_DECLARATIVE_EXPORT QFxGrid : public QFxBasePositioner +class Q_DECLARATIVE_EXPORT QmlGraphicsGrid : public QmlGraphicsBasePositioner { Q_OBJECT Q_PROPERTY(int rows READ rows WRITE setRows) Q_PROPERTY(int columns READ columns WRITE setcolumns) public: - QFxGrid(QFxItem *parent=0); + QmlGraphicsGrid(QmlGraphicsItem *parent=0); int rows() const {return _rows;} void setRows(const int rows){_rows = rows;} @@ -153,14 +153,14 @@ protected Q_SLOTS: private: int _rows; int _columns; - Q_DISABLE_COPY(QFxGrid) + Q_DISABLE_COPY(QmlGraphicsGrid) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxColumn) -QML_DECLARE_TYPE(QFxRow) -QML_DECLARE_TYPE(QFxGrid) +QML_DECLARE_TYPE(QmlGraphicsColumn) +QML_DECLARE_TYPE(QmlGraphicsRow) +QML_DECLARE_TYPE(QmlGraphicsGrid) QT_END_HEADER diff --git a/src/declarative/fx/qfxpositioners_p.h b/src/declarative/fx/qfxpositioners_p.h index 8960952..fdc11bb 100644 --- a/src/declarative/fx/qfxpositioners_p.h +++ b/src/declarative/fx/qfxpositioners_p.h @@ -62,19 +62,19 @@ #include QT_BEGIN_NAMESPACE -class QFxBasePositionerPrivate : public QFxItemPrivate +class QmlGraphicsBasePositionerPrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxBasePositioner) + Q_DECLARE_PUBLIC(QmlGraphicsBasePositioner) public: - QFxBasePositionerPrivate() + QmlGraphicsBasePositionerPrivate() : _ep(false), _componentComplete(false), _spacing(0), - aut(QFxBasePositioner::None), moveTransition(0), addTransition(0), + aut(QmlGraphicsBasePositioner::None), moveTransition(0), addTransition(0), removeTransition(0), _movingItem(0) { } - void init(QFxBasePositioner::AutoUpdateType at) + void init(QmlGraphicsBasePositioner::AutoUpdateType at) { aut = at; } @@ -82,15 +82,15 @@ public: bool _ep; bool _componentComplete; int _spacing; - QFxBasePositioner::AutoUpdateType aut; + QmlGraphicsBasePositioner::AutoUpdateType aut; QmlTransition *moveTransition; QmlTransition *addTransition; QmlTransition *removeTransition; - QSet _items; - QSet _leavingItems; - QSet _stableItems; - QSet _newItems; - QSet _animated; + QSet _items; + QSet _leavingItems; + QSet _stableItems; + QSet _newItems; + QSet _animated; QmlStateOperation::ActionList addActions; QmlStateOperation::ActionList moveActions; QmlStateOperation::ActionList removeActions; @@ -98,7 +98,7 @@ public: QmlTransitionManager moveTransitionManager; QmlTransitionManager removeTransitionManager; // QmlStateGroup *stateGroup; - QFxItem *_movingItem; + QmlGraphicsItem *_movingItem; }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp index d4207a6..7ebacf0 100644 --- a/src/declarative/fx/qfxrect.cpp +++ b/src/declarative/fx/qfxrect.cpp @@ -46,14 +46,14 @@ #include QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pen,QFxPen) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GradientStop,QFxGradientStop) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Gradient,QFxGradient) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pen,QmlGraphicsPen) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GradientStop,QmlGraphicsGradientStop) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Gradient,QmlGraphicsGradient) /*! \internal - \class QFxPen - \brief The QFxPen class provides a pen used for drawing rectangle borders on a QmlView. + \class QmlGraphicsPen + \brief The QmlGraphicsPen class provides a pen used for drawing rectangle borders on a QmlView. By default, the pen is invalid and nothing is drawn. You must either set a color (then the default width is 1) or a width (then the default color is black). @@ -66,14 +66,14 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Gradient,QFxGradient) \endqml */ -void QFxPen::setColor(const QColor &c) +void QmlGraphicsPen::setColor(const QColor &c) { _color = c; _valid = _color.alpha() ? true : false; emit penChanged(); } -void QFxPen::setWidth(int w) +void QmlGraphicsPen::setWidth(int w) { if (_width == w && _valid) return; @@ -85,7 +85,7 @@ void QFxPen::setWidth(int w) /*! - \qmlclass GradientStop QFxGradientStop + \qmlclass GradientStop QmlGraphicsGradientStop \brief The GradientStop item defines the color at a position in a Gradient \sa Gradient @@ -98,14 +98,14 @@ void QFxPen::setWidth(int w) Sets a \e color at a \e position in a gradient. */ -void QFxGradientStop::updateGradient() +void QmlGraphicsGradientStop::updateGradient() { - if (QFxGradient *grad = qobject_cast(parent())) + if (QmlGraphicsGradient *grad = qobject_cast(parent())) grad->doUpdate(); } /*! - \qmlclass Gradient QFxGradient + \qmlclass Gradient QmlGraphicsGradient \brief The Gradient item defines a gradient fill. A gradient is defined by two or more colors, which will be blended seemlessly. The @@ -128,12 +128,12 @@ void QFxGradientStop::updateGradient() This property holds the gradient stops describing the gradient. */ -const QGradient *QFxGradient::gradient() const +const QGradient *QmlGraphicsGradient::gradient() const { if (!m_gradient && !m_stops.isEmpty()) { m_gradient = new QLinearGradient(0,0,0,1.0); for (int i = 0; i < m_stops.count(); ++i) { - const QFxGradientStop *stop = m_stops.at(i); + const QmlGraphicsGradientStop *stop = m_stops.at(i); m_gradient->setCoordinateMode(QGradient::ObjectBoundingMode); m_gradient->setColorAt(stop->position(), stop->color()); } @@ -142,17 +142,17 @@ const QGradient *QFxGradient::gradient() const return m_gradient; } -void QFxGradient::doUpdate() +void QmlGraphicsGradient::doUpdate() { delete m_gradient; m_gradient = 0; emit updated(); } -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rectangle,QFxRect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rectangle,QmlGraphicsRect) /*! - \qmlclass Rectangle QFxRect + \qmlclass Rectangle QmlGraphicsRect \brief The Rectangle item allows you to add rectangles to a scene. \inherits Item @@ -175,28 +175,28 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rectangle,QFxRect) /*! \internal - \class QFxRect - \brief The QFxRect class provides a rectangle item that you can add to a QmlView. + \class QmlGraphicsRect + \brief The QmlGraphicsRect class provides a rectangle item that you can add to a QmlView. */ -QFxRect::QFxRect(QFxItem *parent) - : QFxItem(*(new QFxRectPrivate), parent) +QmlGraphicsRect::QmlGraphicsRect(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsRectPrivate), parent) { - Q_D(QFxRect); + Q_D(QmlGraphicsRect); d->init(); setFlag(QGraphicsItem::ItemHasNoContents, false); } -QFxRect::QFxRect(QFxRectPrivate &dd, QFxItem *parent) - : QFxItem(dd, parent) +QmlGraphicsRect::QmlGraphicsRect(QmlGraphicsRectPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) { - Q_D(QFxRect); + Q_D(QmlGraphicsRect); d->init(); setFlag(QGraphicsItem::ItemHasNoContents, false); } -void QFxRect::doUpdate() +void QmlGraphicsRect::doUpdate() { - Q_D(QFxRect); + Q_D(QmlGraphicsRect); d->rectImage = QPixmap(); const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; d->setPaintMargin((pw+1)/2); @@ -214,9 +214,9 @@ void QFxRect::doUpdate() To keep the border smooth (rather than blurry), odd widths cause the rectangle to be painted at a half-pixel offset; */ -QFxPen *QFxRect::border() +QmlGraphicsPen *QmlGraphicsRect::border() { - Q_D(QFxRect); + Q_D(QmlGraphicsRect); return d->getPen(); } @@ -254,15 +254,15 @@ QFxPen *QFxRect::border() \sa Gradient, color */ -QFxGradient *QFxRect::gradient() const +QmlGraphicsGradient *QmlGraphicsRect::gradient() const { - Q_D(const QFxRect); + Q_D(const QmlGraphicsRect); return d->gradient; } -void QFxRect::setGradient(QFxGradient *gradient) +void QmlGraphicsRect::setGradient(QmlGraphicsGradient *gradient) { - Q_D(QFxRect); + Q_D(QmlGraphicsRect); if (d->gradient == gradient) return; if (d->gradient) @@ -282,15 +282,15 @@ void QFxRect::setGradient(QFxGradient *gradient) painted as a normal rectangle. The same radius is used by all 4 corners; there is currently no way to specify different radii for different corners. */ -qreal QFxRect::radius() const +qreal QmlGraphicsRect::radius() const { - Q_D(const QFxRect); + Q_D(const QmlGraphicsRect); return d->radius; } -void QFxRect::setRadius(qreal radius) +void QmlGraphicsRect::setRadius(qreal radius) { - Q_D(QFxRect); + Q_D(QmlGraphicsRect); if (d->radius == radius) return; @@ -316,15 +316,15 @@ void QFxRect::setRadius(qreal radius) If both a gradient and a color are specified, the gradient will be used. */ -QColor QFxRect::color() const +QColor QmlGraphicsRect::color() const { - Q_D(const QFxRect); + Q_D(const QmlGraphicsRect); return d->color; } -void QFxRect::setColor(const QColor &c) +void QmlGraphicsRect::setColor(const QColor &c) { - Q_D(QFxRect); + Q_D(QmlGraphicsRect); if (d->color == c) return; @@ -334,9 +334,9 @@ void QFxRect::setColor(const QColor &c) emit colorChanged(); } -void QFxRect::generateRoundedRect() +void QmlGraphicsRect::generateRoundedRect() { - Q_D(QFxRect); + Q_D(QmlGraphicsRect); if (d->rectImage.isNull()) { const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; const int radius = qCeil(d->radius); //ensure odd numbered width/height so we get 1-pixel center @@ -358,9 +358,9 @@ void QFxRect::generateRoundedRect() } } -void QFxRect::generateBorderedRect() +void QmlGraphicsRect::generateBorderedRect() { - Q_D(QFxRect); + Q_D(QmlGraphicsRect); if (d->rectImage.isNull()) { const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; d->rectImage = QPixmap(pw*2 + 3, pw*2 + 3); @@ -382,9 +382,9 @@ void QFxRect::generateBorderedRect() } } -void QFxRect::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +void QmlGraphicsRect::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { - Q_D(QFxRect); + Q_D(QmlGraphicsRect); if (d->radius > 0 || (d->pen && d->pen->isValid()) || (d->gradient && d->gradient->gradient()) ) { drawRect(*p); @@ -399,9 +399,9 @@ void QFxRect::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) } } -void QFxRect::drawRect(QPainter &p) +void QmlGraphicsRect::drawRect(QPainter &p) { - Q_D(QFxRect); + Q_D(QmlGraphicsRect); if (d->gradient && d->gradient->gradient()) { // XXX This path is still slower than the image path // Image path won't work for gradients though @@ -466,9 +466,9 @@ void QFxRect::drawRect(QPainter &p) \image rect-smooth.png */ -QRectF QFxRect::boundingRect() const +QRectF QmlGraphicsRect::boundingRect() const { - Q_D(const QFxRect); + Q_D(const QmlGraphicsRect); return QRectF(-d->paintmargin, -d->paintmargin, d->width+d->paintmargin*2, d->height+d->paintmargin*2); } diff --git a/src/declarative/fx/qfxrect.h b/src/declarative/fx/qfxrect.h index e5bb8d3..5154a8a 100644 --- a/src/declarative/fx/qfxrect.h +++ b/src/declarative/fx/qfxrect.h @@ -51,14 +51,14 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class Q_DECLARATIVE_EXPORT QFxPen : public QObject +class Q_DECLARATIVE_EXPORT QmlGraphicsPen : public QObject { Q_OBJECT Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged) Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged) public: - QFxPen(QObject *parent=0) + QmlGraphicsPen(QObject *parent=0) : QObject(parent), _width(1), _color("#000000"), _valid(false) {} @@ -79,7 +79,7 @@ private: bool _valid; }; -class Q_DECLARATIVE_EXPORT QFxGradientStop : public QObject +class Q_DECLARATIVE_EXPORT QmlGraphicsGradientStop : public QObject { Q_OBJECT @@ -87,7 +87,7 @@ class Q_DECLARATIVE_EXPORT QFxGradientStop : public QObject Q_PROPERTY(QColor color READ color WRITE setColor) public: - QFxGradientStop(QObject *parent=0) : QObject(parent) {} + QmlGraphicsGradientStop(QObject *parent=0) : QObject(parent) {} qreal position() const { return m_position; } void setPosition(qreal position) { m_position = position; updateGradient(); } @@ -103,18 +103,18 @@ private: QColor m_color; }; -class Q_DECLARATIVE_EXPORT QFxGradient : public QObject +class Q_DECLARATIVE_EXPORT QmlGraphicsGradient : public QObject { Q_OBJECT - Q_PROPERTY(QList *stops READ stops) + Q_PROPERTY(QList *stops READ stops) Q_CLASSINFO("DefaultProperty", "stops") public: - QFxGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} - ~QFxGradient() { delete m_gradient; } + QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} + ~QmlGraphicsGradient() { delete m_gradient; } - QList *stops() { return &m_stops; } + QList *stops() { return &m_stops; } const QGradient *gradient() const; @@ -125,30 +125,30 @@ private: void doUpdate(); private: - QList m_stops; + QList m_stops; mutable QGradient *m_gradient; - friend class QFxGradientStop; + friend class QmlGraphicsGradientStop; }; -class QFxRectPrivate; -class Q_DECLARATIVE_EXPORT QFxRect : public QFxItem +class QmlGraphicsRectPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsRect : public QmlGraphicsItem { Q_OBJECT Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) - Q_PROPERTY(QFxGradient *gradient READ gradient WRITE setGradient) - Q_PROPERTY(QFxPen * border READ border CONSTANT) + Q_PROPERTY(QmlGraphicsGradient *gradient READ gradient WRITE setGradient) + Q_PROPERTY(QmlGraphicsPen * border READ border CONSTANT) Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) public: - QFxRect(QFxItem *parent=0); + QmlGraphicsRect(QmlGraphicsItem *parent=0); QColor color() const; void setColor(const QColor &); - QFxPen *border(); + QmlGraphicsPen *border(); - QFxGradient *gradient() const; - void setGradient(QFxGradient *gradient); + QmlGraphicsGradient *gradient() const; + void setGradient(QmlGraphicsGradient *gradient); qreal radius() const; void setRadius(qreal radius); @@ -170,19 +170,19 @@ private: void drawRect(QPainter &painter); protected: - QFxRect(QFxRectPrivate &dd, QFxItem *parent); + QmlGraphicsRect(QmlGraphicsRectPrivate &dd, QmlGraphicsItem *parent); private: - Q_DISABLE_COPY(QFxRect) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxRect) + Q_DISABLE_COPY(QmlGraphicsRect) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRect) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxPen) -QML_DECLARE_TYPE(QFxGradientStop) -QML_DECLARE_TYPE(QFxGradient) -QML_DECLARE_TYPE(QFxRect) +QML_DECLARE_TYPE(QmlGraphicsPen) +QML_DECLARE_TYPE(QmlGraphicsGradientStop) +QML_DECLARE_TYPE(QmlGraphicsGradient) +QML_DECLARE_TYPE(QmlGraphicsRect) QT_END_HEADER diff --git a/src/declarative/fx/qfxrect_p.h b/src/declarative/fx/qfxrect_p.h index c055b76..d67209e 100644 --- a/src/declarative/fx/qfxrect_p.h +++ b/src/declarative/fx/qfxrect_p.h @@ -57,19 +57,19 @@ QT_BEGIN_NAMESPACE -class QFxGradient; -class QFxRect; -class QFxRectPrivate : public QFxItemPrivate +class QmlGraphicsGradient; +class QmlGraphicsRect; +class QmlGraphicsRectPrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxRect) + Q_DECLARE_PUBLIC(QmlGraphicsRect) public: - QFxRectPrivate() : + QmlGraphicsRectPrivate() : color(Qt::white), gradient(0), pen(0), radius(0), paintmargin(0) { } - ~QFxRectPrivate() + ~QmlGraphicsRectPrivate() { delete pen; } @@ -80,23 +80,23 @@ public: QColor getColor(); QColor color; - QFxGradient *gradient; - QFxPen *getPen() { + QmlGraphicsGradient *gradient; + QmlGraphicsPen *getPen() { if (!pen) { - Q_Q(QFxRect); - pen = new QFxPen; + Q_Q(QmlGraphicsRect); + pen = new QmlGraphicsPen; QObject::connect(pen, SIGNAL(penChanged()), q, SLOT(doUpdate())); } return pen; } - QFxPen *pen; + QmlGraphicsPen *pen; qreal radius; qreal paintmargin; QPixmap rectImage; void setPaintMargin(qreal margin) { - Q_Q(QFxRect); + Q_Q(QmlGraphicsRect); if (margin == paintmargin) return; q->prepareGeometryChange(); diff --git a/src/declarative/fx/qfxrepeater.cpp b/src/declarative/fx/qfxrepeater.cpp index 94954e7..e8e44cc 100644 --- a/src/declarative/fx/qfxrepeater.cpp +++ b/src/declarative/fx/qfxrepeater.cpp @@ -47,16 +47,16 @@ QT_BEGIN_NAMESPACE -QFxRepeaterPrivate::QFxRepeaterPrivate() +QmlGraphicsRepeaterPrivate::QmlGraphicsRepeaterPrivate() : model(0), ownModel(false) { } -QFxRepeaterPrivate::~QFxRepeaterPrivate() +QmlGraphicsRepeaterPrivate::~QmlGraphicsRepeaterPrivate() { } -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Repeater,QFxRepeater) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Repeater,QmlGraphicsRepeater) /*! \qmlclass Repeater @@ -103,7 +103,7 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Repeater,QFxRepeater) /*! \internal - \class QFxRepeater + \class QmlGraphicsRepeater \qmlclass Repeater XXX Repeater is very conservative in how it instatiates/deletes items. Also @@ -111,18 +111,18 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Repeater,QFxRepeater) */ /*! - Create a new QFxRepeater instance. + Create a new QmlGraphicsRepeater instance. */ -QFxRepeater::QFxRepeater(QFxItem *parent) - : QFxItem(*(new QFxRepeaterPrivate), parent) +QmlGraphicsRepeater::QmlGraphicsRepeater(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsRepeaterPrivate), parent) { } /*! \internal */ -QFxRepeater::QFxRepeater(QFxRepeaterPrivate &dd, QFxItem *parent) - : QFxItem(dd, parent) +QmlGraphicsRepeater::QmlGraphicsRepeater(QmlGraphicsRepeaterPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) { } @@ -130,7 +130,7 @@ QFxRepeater::QFxRepeater(QFxRepeaterPrivate &dd, QFxItem *parent) Destroy the repeater instance. All items it instantiated are also destroyed. */ -QFxRepeater::~QFxRepeater() +QmlGraphicsRepeater::~QmlGraphicsRepeater() { } @@ -154,29 +154,29 @@ QFxRepeater::~QFxRepeater() \sa {qmlmodels}{Data Models} */ -QVariant QFxRepeater::model() const +QVariant QmlGraphicsRepeater::model() const { - Q_D(const QFxRepeater); + Q_D(const QmlGraphicsRepeater); return d->dataSource; } -void QFxRepeater::setModel(const QVariant &model) +void QmlGraphicsRepeater::setModel(const QVariant &model) { - Q_D(QFxRepeater); + Q_D(QmlGraphicsRepeater); clear(); if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); /* - disconnect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); - disconnect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); + disconnect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + disconnect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); */ } d->dataSource = model; QObject *object = qvariant_cast(model); - QFxVisualModel *vim = 0; - if (object && (vim = qobject_cast(object))) { + QmlGraphicsVisualModel *vim = 0; + if (object && (vim = qobject_cast(object))) { if (d->ownModel) { delete d->model; d->ownModel = false; @@ -184,10 +184,10 @@ void QFxRepeater::setModel(const QVariant &model) d->model = vim; } else { if (!d->ownModel) { - d->model = new QFxVisualDataModel(qmlContext(this)); + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); d->ownModel = true; } - if (QFxVisualDataModel *dataModel = qobject_cast(d->model)) + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) dataModel->setModel(model); } if (d->model) { @@ -195,8 +195,8 @@ void QFxRepeater::setModel(const QVariant &model) connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); /* - connect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); - connect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); + connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + connect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); */ regenerate(); emit countChanged(); @@ -209,25 +209,25 @@ void QFxRepeater::setModel(const QVariant &model) The delegate provides a template describing what each item instantiated by the repeater should look and act like. */ -QmlComponent *QFxRepeater::delegate() const +QmlComponent *QmlGraphicsRepeater::delegate() const { - Q_D(const QFxRepeater); + Q_D(const QmlGraphicsRepeater); if (d->model) { - if (QFxVisualDataModel *dataModel = qobject_cast(d->model)) + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) return dataModel->delegate(); } return 0; } -void QFxRepeater::setDelegate(QmlComponent *delegate) +void QmlGraphicsRepeater::setDelegate(QmlComponent *delegate) { - Q_D(QFxRepeater); + Q_D(QmlGraphicsRepeater); if (!d->ownModel) { - d->model = new QFxVisualDataModel(qmlContext(this)); + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); d->ownModel = true; } - if (QFxVisualDataModel *dataModel = qobject_cast(d->model)) { + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) { dataModel->setDelegate(delegate); regenerate(); } @@ -238,9 +238,9 @@ void QFxRepeater::setDelegate(QmlComponent *delegate) This property holds the number of items in the repeater. */ -int QFxRepeater::count() const +int QmlGraphicsRepeater::count() const { - Q_D(const QFxRepeater); + Q_D(const QmlGraphicsRepeater); if (d->model) return d->model->count(); return 0; @@ -250,19 +250,19 @@ int QFxRepeater::count() const /*! \internal */ -void QFxRepeater::componentComplete() +void QmlGraphicsRepeater::componentComplete() { - QFxItem::componentComplete(); + QmlGraphicsItem::componentComplete(); regenerate(); } /*! \internal */ -QVariant QFxRepeater::itemChange(GraphicsItemChange change, +QVariant QmlGraphicsRepeater::itemChange(GraphicsItemChange change, const QVariant &value) { - QVariant rv = QFxItem::itemChange(change, value); + QVariant rv = QmlGraphicsItem::itemChange(change, value); if (change == ItemParentHasChanged) { regenerate(); } @@ -270,11 +270,11 @@ QVariant QFxRepeater::itemChange(GraphicsItemChange change, return rv; } -void QFxRepeater::clear() +void QmlGraphicsRepeater::clear() { - Q_D(QFxRepeater); + Q_D(QmlGraphicsRepeater); if (d->model) { - foreach (QFxItem *item, d->deletables) + foreach (QmlGraphicsItem *item, d->deletables) d->model->release(item); } d->deletables.clear(); @@ -283,9 +283,9 @@ void QFxRepeater::clear() /*! \internal */ -void QFxRepeater::regenerate() +void QmlGraphicsRepeater::regenerate() { - Q_D(QFxRepeater); + Q_D(QmlGraphicsRepeater); clear(); @@ -293,7 +293,7 @@ void QFxRepeater::regenerate() return; for (int ii = 0; ii < count(); ++ii) { - QFxItem *item = d->model->item(ii); + QmlGraphicsItem *item = d->model->item(ii); if (item) { item->setParent(parentItem()); item->stackBefore(this); @@ -302,17 +302,17 @@ void QFxRepeater::regenerate() } } -void QFxRepeater::itemsInserted(int, int) +void QmlGraphicsRepeater::itemsInserted(int, int) { regenerate(); } -void QFxRepeater::itemsRemoved(int, int) +void QmlGraphicsRepeater::itemsRemoved(int, int) { regenerate(); } -void QFxRepeater::itemsMoved(int,int,int) +void QmlGraphicsRepeater::itemsMoved(int,int,int) { regenerate(); } diff --git a/src/declarative/fx/qfxrepeater.h b/src/declarative/fx/qfxrepeater.h index 7a0318b..f8a03cc 100644 --- a/src/declarative/fx/qfxrepeater.h +++ b/src/declarative/fx/qfxrepeater.h @@ -50,8 +50,8 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxRepeaterPrivate; -class Q_DECLARATIVE_EXPORT QFxRepeater : public QFxItem +class QmlGraphicsRepeaterPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsRepeater : public QmlGraphicsItem { Q_OBJECT @@ -61,8 +61,8 @@ class Q_DECLARATIVE_EXPORT QFxRepeater : public QFxItem Q_CLASSINFO("DefaultProperty", "delegate") public: - QFxRepeater(QFxItem *parent=0); - virtual ~QFxRepeater(); + QmlGraphicsRepeater(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsRepeater(); QVariant model() const; void setModel(const QVariant &); @@ -82,7 +82,7 @@ private: protected: virtual void componentComplete(); QVariant itemChange(GraphicsItemChange change, const QVariant &value); - QFxRepeater(QFxRepeaterPrivate &dd, QFxItem *parent); + QmlGraphicsRepeater(QmlGraphicsRepeaterPrivate &dd, QmlGraphicsItem *parent); private Q_SLOTS: void itemsInserted(int,int); @@ -90,13 +90,13 @@ private Q_SLOTS: void itemsMoved(int,int,int); private: - Q_DISABLE_COPY(QFxRepeater) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxRepeater) + Q_DISABLE_COPY(QmlGraphicsRepeater) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRepeater) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxRepeater) +QML_DECLARE_TYPE(QmlGraphicsRepeater) QT_END_HEADER diff --git a/src/declarative/fx/qfxrepeater_p.h b/src/declarative/fx/qfxrepeater_p.h index a4eb96d..eb35352 100644 --- a/src/declarative/fx/qfxrepeater_p.h +++ b/src/declarative/fx/qfxrepeater_p.h @@ -61,20 +61,20 @@ QT_BEGIN_NAMESPACE class QmlContext; -class QFxVisualModel; -class QFxRepeaterPrivate : public QFxItemPrivate +class QmlGraphicsVisualModel; +class QmlGraphicsRepeaterPrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxRepeater) + Q_DECLARE_PUBLIC(QmlGraphicsRepeater) public: - QFxRepeaterPrivate(); - ~QFxRepeaterPrivate(); + QmlGraphicsRepeaterPrivate(); + ~QmlGraphicsRepeaterPrivate(); - QFxVisualModel *model; + QmlGraphicsVisualModel *model; QVariant dataSource; bool ownModel; - QList > deletables; + QList > deletables; }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxscalegrid.cpp b/src/declarative/fx/qfxscalegrid.cpp index 4c6a522..2012616 100644 --- a/src/declarative/fx/qfxscalegrid.cpp +++ b/src/declarative/fx/qfxscalegrid.cpp @@ -48,25 +48,25 @@ QT_BEGIN_NAMESPACE /*! \internal - \class QFxScaleGrid - \brief The QFxScaleGrid class allows you to specify a 3x3 grid to use in scaling an image. + \class QmlGraphicsScaleGrid + \brief The QmlGraphicsScaleGrid class allows you to specify a 3x3 grid to use in scaling an image. */ -QML_DEFINE_NOCREATE_TYPE(QFxScaleGrid) +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsScaleGrid) -QFxScaleGrid::QFxScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0) +QmlGraphicsScaleGrid::QmlGraphicsScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0) { } -QFxScaleGrid::~QFxScaleGrid() +QmlGraphicsScaleGrid::~QmlGraphicsScaleGrid() { } -bool QFxScaleGrid::isNull() const +bool QmlGraphicsScaleGrid::isNull() const { return !_left && !_top && !_right && !_bottom; } -void QFxScaleGrid::setLeft(int pos) +void QmlGraphicsScaleGrid::setLeft(int pos) { if (_left != pos) { _left = pos; @@ -74,7 +74,7 @@ void QFxScaleGrid::setLeft(int pos) } } -void QFxScaleGrid::setTop(int pos) +void QmlGraphicsScaleGrid::setTop(int pos) { if (_top != pos) { _top = pos; @@ -82,7 +82,7 @@ void QFxScaleGrid::setTop(int pos) } } -void QFxScaleGrid::setRight(int pos) +void QmlGraphicsScaleGrid::setRight(int pos) { if (_right != pos) { _right = pos; @@ -90,7 +90,7 @@ void QFxScaleGrid::setRight(int pos) } } -void QFxScaleGrid::setBottom(int pos) +void QmlGraphicsScaleGrid::setBottom(int pos) { if (_bottom != pos) { _bottom = pos; @@ -98,18 +98,18 @@ void QFxScaleGrid::setBottom(int pos) } } -QFxGridScaledImage::QFxGridScaledImage() +QmlGraphicsGridScaledImage::QmlGraphicsGridScaledImage() : _l(-1), _r(-1), _t(-1), _b(-1), - _h(QFxBorderImage::Stretch), _v(QFxBorderImage::Stretch) + _h(QmlGraphicsBorderImage::Stretch), _v(QmlGraphicsBorderImage::Stretch) { } -QFxGridScaledImage::QFxGridScaledImage(const QFxGridScaledImage &o) +QmlGraphicsGridScaledImage::QmlGraphicsGridScaledImage(const QmlGraphicsGridScaledImage &o) : _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix) { } -QFxGridScaledImage &QFxGridScaledImage::operator=(const QFxGridScaledImage &o) +QmlGraphicsGridScaledImage &QmlGraphicsGridScaledImage::operator=(const QmlGraphicsGridScaledImage &o) { _l = o._l; _r = o._r; @@ -121,8 +121,8 @@ QFxGridScaledImage &QFxGridScaledImage::operator=(const QFxGridScaledImage &o) return *this; } -QFxGridScaledImage::QFxGridScaledImage(QIODevice *data) -: _l(-1), _r(-1), _t(-1), _b(-1), _h(QFxBorderImage::Stretch), _v(QFxBorderImage::Stretch) +QmlGraphicsGridScaledImage::QmlGraphicsGridScaledImage(QIODevice *data) +: _l(-1), _r(-1), _t(-1), _b(-1), _h(QmlGraphicsBorderImage::Stretch), _v(QmlGraphicsBorderImage::Stretch) { int l = -1; int r = -1; @@ -166,45 +166,45 @@ QFxGridScaledImage::QFxGridScaledImage(QIODevice *data) _pix = imgFile; } -QFxBorderImage::TileMode QFxGridScaledImage::stringToRule(const QString &s) +QmlGraphicsBorderImage::TileMode QmlGraphicsGridScaledImage::stringToRule(const QString &s) { if (s == QLatin1String("Stretch")) - return QFxBorderImage::Stretch; + return QmlGraphicsBorderImage::Stretch; if (s == QLatin1String("Repeat")) - return QFxBorderImage::Repeat; + return QmlGraphicsBorderImage::Repeat; if (s == QLatin1String("Round")) - return QFxBorderImage::Round; + return QmlGraphicsBorderImage::Round; qWarning() << "Unknown tile rule specified. Using Stretch"; - return QFxBorderImage::Stretch; + return QmlGraphicsBorderImage::Stretch; } -bool QFxGridScaledImage::isValid() const +bool QmlGraphicsGridScaledImage::isValid() const { return _l >= 0; } -int QFxGridScaledImage::gridLeft() const +int QmlGraphicsGridScaledImage::gridLeft() const { return _l; } -int QFxGridScaledImage::gridRight() const +int QmlGraphicsGridScaledImage::gridRight() const { return _r; } -int QFxGridScaledImage::gridTop() const +int QmlGraphicsGridScaledImage::gridTop() const { return _t; } -int QFxGridScaledImage::gridBottom() const +int QmlGraphicsGridScaledImage::gridBottom() const { return _b; } -QString QFxGridScaledImage::pixmapUrl() const +QString QmlGraphicsGridScaledImage::pixmapUrl() const { return _pix; } diff --git a/src/declarative/fx/qfxscalegrid_p.h b/src/declarative/fx/qfxscalegrid_p.h index bae1436..f065f9d 100644 --- a/src/declarative/fx/qfxscalegrid_p.h +++ b/src/declarative/fx/qfxscalegrid_p.h @@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class Q_DECLARATIVE_EXPORT QFxScaleGrid : public QObject +class Q_DECLARATIVE_EXPORT QmlGraphicsScaleGrid : public QObject { Q_OBJECT Q_ENUMS(TileRule) @@ -67,8 +67,8 @@ class Q_DECLARATIVE_EXPORT QFxScaleGrid : public QObject Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY borderChanged) public: - QFxScaleGrid(QObject *parent=0); - ~QFxScaleGrid(); + QmlGraphicsScaleGrid(QObject *parent=0); + ~QmlGraphicsScaleGrid(); bool isNull() const; @@ -94,39 +94,39 @@ private: int _bottom; }; -class Q_DECLARATIVE_EXPORT QFxGridScaledImage +class Q_DECLARATIVE_EXPORT QmlGraphicsGridScaledImage { public: - QFxGridScaledImage(); - QFxGridScaledImage(const QFxGridScaledImage &); - QFxGridScaledImage(QIODevice*); - QFxGridScaledImage &operator=(const QFxGridScaledImage &); + QmlGraphicsGridScaledImage(); + QmlGraphicsGridScaledImage(const QmlGraphicsGridScaledImage &); + QmlGraphicsGridScaledImage(QIODevice*); + QmlGraphicsGridScaledImage &operator=(const QmlGraphicsGridScaledImage &); bool isValid() const; int gridLeft() const; int gridRight() const; int gridTop() const; int gridBottom() const; - QFxBorderImage::TileMode horizontalTileRule() const { return _h; } - QFxBorderImage::TileMode verticalTileRule() const { return _v; } + QmlGraphicsBorderImage::TileMode horizontalTileRule() const { return _h; } + QmlGraphicsBorderImage::TileMode verticalTileRule() const { return _v; } QString pixmapUrl() const; private: - static QFxBorderImage::TileMode stringToRule(const QString &); + static QmlGraphicsBorderImage::TileMode stringToRule(const QString &); private: int _l; int _r; int _t; int _b; - QFxBorderImage::TileMode _h; - QFxBorderImage::TileMode _v; + QmlGraphicsBorderImage::TileMode _h; + QmlGraphicsBorderImage::TileMode _v; QString _pix; }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxScaleGrid) +QML_DECLARE_TYPE(QmlGraphicsScaleGrid) QT_END_HEADER diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index 4a01cbd..77b3ab4 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -52,10 +52,10 @@ #include QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Text,QFxText) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Text,QmlGraphicsText) /*! - \qmlclass Text QFxText + \qmlclass Text QmlGraphicsText \brief The Text item allows you to add formatted text to a scene. \inherits Item @@ -80,11 +80,11 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Text,QFxText) /*! \internal - \class QFxText + \class QmlGraphicsText \qmlclass Text \ingroup group_coreitems - \brief The QFxText class provides a formatted text item that you can add to a QmlView. + \brief The QmlGraphicsText class provides a formatted text item that you can add to a QmlView. Text was designed for read-only text; it does not allow for any text editing. It can display both plain and rich text. For example: @@ -102,23 +102,23 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Text,QFxText) The \c elide property can alternatively be used to fit a line of plain text to a set width. - A QFxText object can be instantiated in Qml using the tag \c Text. + A QmlGraphicsText object can be instantiated in Qml using the tag \c Text. */ -QFxText::QFxText(QFxItem *parent) - : QFxItem(*(new QFxTextPrivate), parent) +QmlGraphicsText::QmlGraphicsText(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsTextPrivate), parent) { setAcceptedMouseButtons(Qt::LeftButton); setFlag(QGraphicsItem::ItemHasNoContents, false); } -QFxText::QFxText(QFxTextPrivate &dd, QFxItem *parent) - : QFxItem(dd, parent) +QmlGraphicsText::QmlGraphicsText(QmlGraphicsTextPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) { setAcceptedMouseButtons(Qt::LeftButton); setFlag(QGraphicsItem::ItemHasNoContents, false); } -QFxText::~QFxText() +QmlGraphicsText::~QmlGraphicsText() { } @@ -132,15 +132,15 @@ QFxText::~QFxText() Set the Text's font attributes. */ -QFont QFxText::font() const +QFont QmlGraphicsText::font() const { - Q_D(const QFxText); + Q_D(const QmlGraphicsText); return d->font; } -void QFxText::setFont(const QFont &font) +void QmlGraphicsText::setFont(const QFont &font) { - Q_D(QFxText); + Q_D(QmlGraphicsText); d->font = font; d->imgDirty = true; @@ -148,12 +148,12 @@ void QFxText::setFont(const QFont &font) update(); } -void QFxText::setText(const QString &n) +void QmlGraphicsText::setText(const QString &n) { #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer st; + QmlPerfTimer st; #endif - Q_D(QFxText); + Q_D(QmlGraphicsText); if (d->text == n) return; @@ -184,15 +184,15 @@ void QFxText::setText(const QString &n) The item will try to automatically determine whether the text should be treated as rich text. This determination is made using Qt::mightBeRichText(). */ -QString QFxText::text() const +QString QmlGraphicsText::text() const { - Q_D(const QFxText); + Q_D(const QmlGraphicsText); return d->text; } -void QFxText::setColor(const QColor &color) +void QmlGraphicsText::setColor(const QColor &color) { - Q_D(QFxText); + Q_D(QmlGraphicsText); if (d->color == color) return; @@ -215,9 +215,9 @@ void QFxText::setColor(const QColor &color) \endqml */ -QColor QFxText::color() const +QColor QmlGraphicsText::color() const { - Q_D(const QFxText); + Q_D(const QmlGraphicsText); return d->color; } @@ -239,15 +239,15 @@ QColor QFxText::color() const \image declarative-textstyle.png */ -QFxText::TextStyle QFxText::style() const +QmlGraphicsText::TextStyle QmlGraphicsText::style() const { - Q_D(const QFxText); + Q_D(const QmlGraphicsText); return d->style; } -void QFxText::setStyle(QFxText::TextStyle style) +void QmlGraphicsText::setStyle(QmlGraphicsText::TextStyle style) { - Q_D(QFxText); + Q_D(QmlGraphicsText); if (d->style == style) return; @@ -256,9 +256,9 @@ void QFxText::setStyle(QFxText::TextStyle style) update(); } -void QFxText::setStyleColor(const QColor &color) +void QmlGraphicsText::setStyleColor(const QColor &color) { - Q_D(QFxText); + Q_D(QmlGraphicsText); if (d->styleColor == color) return; @@ -276,9 +276,9 @@ void QFxText::setStyleColor(const QColor &color) shadow color for raised or sunken text. If no style has been set, it is not used at all. */ -QColor QFxText::styleColor() const +QColor QmlGraphicsText::styleColor() const { - Q_D(const QFxText); + Q_D(const QmlGraphicsText); return d->styleColor; } @@ -293,27 +293,27 @@ QColor QFxText::styleColor() const \c AlignHCenter. The valid values for \c verticalAlignment are \c AlignTop, \c AlignBottom and \c AlignVCenter. */ -QFxText::HAlignment QFxText::hAlign() const +QmlGraphicsText::HAlignment QmlGraphicsText::hAlign() const { - Q_D(const QFxText); + Q_D(const QmlGraphicsText); return d->hAlign; } -void QFxText::setHAlign(HAlignment align) +void QmlGraphicsText::setHAlign(HAlignment align) { - Q_D(QFxText); + Q_D(QmlGraphicsText); d->hAlign = align; } -QFxText::VAlignment QFxText::vAlign() const +QmlGraphicsText::VAlignment QmlGraphicsText::vAlign() const { - Q_D(const QFxText); + Q_D(const QmlGraphicsText); return d->vAlign; } -void QFxText::setVAlign(VAlignment align) +void QmlGraphicsText::setVAlign(VAlignment align) { - Q_D(QFxText); + Q_D(QmlGraphicsText); d->vAlign = align; } @@ -330,15 +330,15 @@ void QFxText::setVAlign(VAlignment align) Wrapping is off by default. */ //### Future may provide choice of wrap modes, such as QTextOption::WrapAtWordBoundaryOrAnywhere -bool QFxText::wrap() const +bool QmlGraphicsText::wrap() const { - Q_D(const QFxText); + Q_D(const QmlGraphicsText); return d->wrap; } -void QFxText::setWrap(bool w) +void QmlGraphicsText::setWrap(bool w) { - Q_D(QFxText); + Q_D(QmlGraphicsText); if (w == d->wrap) return; @@ -384,15 +384,15 @@ Column { \endtable */ -QFxText::TextFormat QFxText::textFormat() const +QmlGraphicsText::TextFormat QmlGraphicsText::textFormat() const { - Q_D(const QFxText); + Q_D(const QmlGraphicsText); return d->format; } -void QFxText::setTextFormat(TextFormat format) +void QmlGraphicsText::setTextFormat(TextFormat format) { - Q_D(QFxText); + Q_D(QmlGraphicsText); if (format == d->format) return; bool wasRich = d->richText; @@ -435,15 +435,15 @@ void QFxText::setTextFormat(TextFormat format) Multi-length strings are ordered from longest to shortest, separated by the Unicode "String Terminator" character \c U009C (write this in QML with \c{"\\x9C"}). */ -QFxText::TextElideMode QFxText::elideMode() const +QmlGraphicsText::TextElideMode QmlGraphicsText::elideMode() const { - Q_D(const QFxText); + Q_D(const QmlGraphicsText); return d->elideMode; } -void QFxText::setElideMode(QFxText::TextElideMode mode) +void QmlGraphicsText::setElideMode(QmlGraphicsText::TextElideMode mode) { - Q_D(QFxText); + Q_D(QmlGraphicsText); if (mode == d->elideMode) return; @@ -453,22 +453,22 @@ void QFxText::setElideMode(QFxText::TextElideMode mode) d->updateSize(); } -void QFxText::geometryChanged(const QRectF &newGeometry, +void QmlGraphicsText::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { - Q_D(QFxText); + Q_D(QmlGraphicsText); if (newGeometry.width() != oldGeometry.width()) { - if (d->wrap || d->elideMode != QFxText::ElideNone) { + if (d->wrap || d->elideMode != QmlGraphicsText::ElideNone) { d->imgDirty = true; d->updateSize(); } } - QFxItem::geometryChanged(newGeometry, oldGeometry); + QmlGraphicsItem::geometryChanged(newGeometry, oldGeometry); } -void QFxTextPrivate::updateSize() +void QmlGraphicsTextPrivate::updateSize() { - Q_Q(QFxText); + Q_Q(QmlGraphicsText); if (q->isComponentComplete()) { QFontMetrics fm(font); if (text.isEmpty()) { @@ -486,7 +486,7 @@ void QFxTextPrivate::updateSize() tmp = text; tmp.replace(QLatin1Char('\n'), QChar::LineSeparator); singleline = !tmp.contains(QChar::LineSeparator); - if (singleline && elideMode != QFxText::ElideNone && q->widthValid()) + if (singleline && elideMode != QmlGraphicsText::ElideNone && q->widthValid()) tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); // XXX still worth layout...? layout.clearLayout(); layout.setFont(font); @@ -514,9 +514,9 @@ void QFxTextPrivate::updateSize() int yoff = 0; if (q->heightValid()) { - if (vAlign == QFxText::AlignBottom) + if (vAlign == QmlGraphicsText::AlignBottom) yoff = dy; - else if (vAlign == QFxText::AlignVCenter) + else if (vAlign == QmlGraphicsText::AlignVCenter) yoff = dy/2; } q->setBaselineOffset(fm.ascent() + yoff); @@ -532,7 +532,7 @@ void QFxTextPrivate::updateSize() // ### text layout handling should be profiled and optimized as needed // what about QStackTextEngine engine(tmp, d->font.font()); QTextLayout textLayout(&engine); -void QFxTextPrivate::drawOutline() +void QmlGraphicsTextPrivate::drawOutline() { QPixmap img = QPixmap(imgCache.size()); img.fill(Qt::transparent); @@ -556,7 +556,7 @@ void QFxTextPrivate::drawOutline() imgCache = img; } -void QFxTextPrivate::drawOutline(int yOffset) +void QmlGraphicsTextPrivate::drawOutline(int yOffset) { QPixmap img = QPixmap(imgCache.size()); img.fill(Qt::transparent); @@ -574,9 +574,9 @@ void QFxTextPrivate::drawOutline(int yOffset) imgCache = img; } -QSize QFxTextPrivate::setupTextLayout(QTextLayout *layout) +QSize QmlGraphicsTextPrivate::setupTextLayout(QTextLayout *layout) { - Q_Q(QFxText); + Q_Q(QmlGraphicsText); layout->setCacheEnabled(true); QFontMetrics fm = QFontMetrics(font); @@ -586,7 +586,7 @@ QSize QFxTextPrivate::setupTextLayout(QTextLayout *layout) qreal lineWidth = 0; //set manual width - if ((wrap || elideMode != QFxText::ElideNone) && q->widthValid()) + if ((wrap || elideMode != QmlGraphicsText::ElideNone) && q->widthValid()) lineWidth = q->width(); layout->beginLayout(); @@ -596,7 +596,7 @@ QSize QFxTextPrivate::setupTextLayout(QTextLayout *layout) if (!line.isValid()) break; - if ((wrap || elideMode != QFxText::ElideNone) && q->widthValid()) + if ((wrap || elideMode != QmlGraphicsText::ElideNone) && q->widthValid()) line.setLineWidth(lineWidth); } layout->endLayout(); @@ -610,7 +610,7 @@ QSize QFxTextPrivate::setupTextLayout(QTextLayout *layout) return QSize((int)widthUsed, height); } -QPixmap QFxTextPrivate::wrappedTextImage(bool drawStyle) +QPixmap QmlGraphicsTextPrivate::wrappedTextImage(bool drawStyle) { //do layout QSize size = cachedLayoutSize; @@ -618,11 +618,11 @@ QPixmap QFxTextPrivate::wrappedTextImage(bool drawStyle) int x = 0; for (int i = 0; i < layout.lineCount(); ++i) { QTextLine line = layout.lineAt(i); - if (hAlign == QFxText::AlignLeft) { + if (hAlign == QmlGraphicsText::AlignLeft) { x = 0; - } else if (hAlign == QFxText::AlignRight) { + } else if (hAlign == QmlGraphicsText::AlignRight) { x = size.width() - (int)line.naturalTextWidth(); - } else if (hAlign == QFxText::AlignHCenter) { + } else if (hAlign == QmlGraphicsText::AlignHCenter) { x = (size.width() - (int)line.naturalTextWidth()) / 2; } line.setPosition(QPoint(x, (int)line.y())); @@ -644,7 +644,7 @@ QPixmap QFxTextPrivate::wrappedTextImage(bool drawStyle) return img; } -QPixmap QFxTextPrivate::richTextImage(bool drawStyle) +QPixmap QmlGraphicsTextPrivate::richTextImage(bool drawStyle) { QSize size = doc->size().toSize(); @@ -671,7 +671,7 @@ QPixmap QFxTextPrivate::richTextImage(bool drawStyle) return img; } -void QFxTextPrivate::checkImgCache() +void QmlGraphicsTextPrivate::checkImgCache() { if (!imgDirty) return; @@ -682,22 +682,22 @@ void QFxTextPrivate::checkImgCache() imgStyleCache = QPixmap(); } else if (richText) { imgCache = richTextImage(false); - if (style != QFxText::Normal) + if (style != QmlGraphicsText::Normal) imgStyleCache = richTextImage(true); //### should use styleColor } else { imgCache = wrappedTextImage(false); - if (style != QFxText::Normal) + if (style != QmlGraphicsText::Normal) imgStyleCache = wrappedTextImage(true); //### should use styleColor } if (!empty) switch (style) { - case QFxText::Outline: + case QmlGraphicsText::Outline: drawOutline(); break; - case QFxText::Sunken: + case QmlGraphicsText::Sunken: drawOutline(-1); break; - case QFxText::Raised: + case QmlGraphicsText::Raised: drawOutline(1); break; default: @@ -707,9 +707,9 @@ void QFxTextPrivate::checkImgCache() imgDirty = false; } -void QFxText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +void QmlGraphicsText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { - Q_D(QFxText); + Q_D(QmlGraphicsText); d->checkImgCache(); if (d->imgCache.isNull()) return; @@ -779,13 +779,13 @@ void QFxText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) filtering at the beginning of the animation and reenable it at the conclusion. */ -void QFxText::componentComplete() +void QmlGraphicsText::componentComplete() { - Q_D(QFxText); + Q_D(QmlGraphicsText); #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer cc; + QmlPerfTimer cc; #endif - QFxItem::componentComplete(); + QmlGraphicsItem::componentComplete(); if (d->dirty) { d->updateSize(); d->dirty = false; @@ -796,9 +796,9 @@ void QFxText::componentComplete() \overload Handles the given mouse \a event. */ -void QFxText::mousePressEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsText::mousePressEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxText); + Q_D(QmlGraphicsText); if (!d->richText || !d->doc || d->control->anchorAt(event->pos()).isEmpty()) { event->setAccepted(false); @@ -810,7 +810,7 @@ void QFxText::mousePressEvent(QGraphicsSceneMouseEvent *event) // ### may malfunction if two of the same links are clicked & dragged onto each other) if (!event->isAccepted()) - QFxItem::mousePressEvent(event); + QmlGraphicsItem::mousePressEvent(event); } @@ -824,9 +824,9 @@ void QFxText::mousePressEvent(QGraphicsSceneMouseEvent *event) \overload Handles the given mouse \a event. */ -void QFxText::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsText::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxText); + Q_D(QmlGraphicsText); // ### confirm the link, and send a signal out if (d->richText && d->doc && d->activeLink == d->control->anchorAt(event->pos())) @@ -835,6 +835,6 @@ void QFxText::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) event->setAccepted(false); if (!event->isAccepted()) - QFxItem::mouseReleaseEvent(event); + QmlGraphicsItem::mouseReleaseEvent(event); } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxtext.h b/src/declarative/fx/qfxtext.h index cdb8025..bc2fb4f 100644 --- a/src/declarative/fx/qfxtext.h +++ b/src/declarative/fx/qfxtext.h @@ -49,8 +49,8 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxTextPrivate; -class Q_DECLARATIVE_EXPORT QFxText : public QFxItem +class QmlGraphicsTextPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsText : public QmlGraphicsItem { Q_OBJECT Q_ENUMS(HAlignment) @@ -71,8 +71,8 @@ class Q_DECLARATIVE_EXPORT QFxText : public QFxItem Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode) //### elideMode? public: - QFxText(QFxItem *parent=0); - ~QFxText(); + QmlGraphicsText(QmlGraphicsItem *parent=0); + ~QmlGraphicsText(); enum HAlignment { AlignLeft = Qt::AlignLeft, AlignRight = Qt::AlignRight, @@ -131,20 +131,20 @@ Q_SIGNALS: void linkActivated(const QString &link); protected: - QFxText(QFxTextPrivate &dd, QFxItem *parent); + QmlGraphicsText(QmlGraphicsTextPrivate &dd, QmlGraphicsItem *parent); void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); private: - Q_DISABLE_COPY(QFxText) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxText) + Q_DISABLE_COPY(QmlGraphicsText) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsText) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxText) +QML_DECLARE_TYPE(QmlGraphicsText) QT_END_HEADER diff --git a/src/declarative/fx/qfxtext_p.h b/src/declarative/fx/qfxtext_p.h index a10cdfa..436aa08 100644 --- a/src/declarative/fx/qfxtext_p.h +++ b/src/declarative/fx/qfxtext_p.h @@ -64,15 +64,15 @@ class QTextLayout; class QTextDocument; class QTextControl; -class QFxTextPrivate : public QFxItemPrivate +class QmlGraphicsTextPrivate : public QmlGraphicsItemPrivate { - Q_DECLARE_PUBLIC(QFxText) + Q_DECLARE_PUBLIC(QmlGraphicsText) public: - QFxTextPrivate() - : color((QRgb)0), style(QFxText::Normal), imgDirty(true), - hAlign(QFxText::AlignLeft), vAlign(QFxText::AlignTop), elideMode(QFxText::ElideNone), + QmlGraphicsTextPrivate() + : color((QRgb)0), style(QmlGraphicsText::Normal), imgDirty(true), + hAlign(QmlGraphicsText::AlignLeft), vAlign(QmlGraphicsText::AlignTop), elideMode(QmlGraphicsText::ElideNone), dirty(true), wrap(false), richText(false), singleline(false), control(0), doc(0), - format(QFxText::AutoText) + format(QmlGraphicsText::AutoText) { } @@ -89,15 +89,15 @@ public: QString text; QFont font; QColor color; - QFxText::TextStyle style; + QmlGraphicsText::TextStyle style; QColor styleColor; QString activeLink; bool imgDirty; QPixmap imgCache; QPixmap imgStyleCache; - QFxText::HAlignment hAlign; - QFxText::VAlignment vAlign; - QFxText::TextElideMode elideMode; + QmlGraphicsText::HAlignment hAlign; + QmlGraphicsText::VAlignment vAlign; + QmlGraphicsText::TextElideMode elideMode; bool dirty; bool wrap; bool richText; @@ -106,7 +106,7 @@ public: QTextDocument *doc; QTextLayout layout; QSize cachedLayoutSize; - QFxText::TextFormat format; + QmlGraphicsText::TextFormat format; }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index ccb8f7e..ddb9194 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -53,7 +53,7 @@ #include QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,TextEdit,QFxTextEdit) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,TextEdit,QmlGraphicsTextEdit) /*! \qmlclass TextEdit @@ -80,42 +80,42 @@ TextEdit { /*! \internal - \class QFxTextEdit + \class QmlGraphicsTextEdit \qmlclass TextEdit \ingroup group_coreitems - \brief The QFxTextEdit class provides an editable formatted text item that you can add to a QmlView. + \brief The QmlGraphicsTextEdit class provides an editable formatted text item that you can add to a QmlView. It can display both plain and rich text. \image declarative-textedit.png - A QFxTextEdit object can be instantiated in Qml using the tag \c <TextEdit>. + A QmlGraphicsTextEdit object can be instantiated in Qml using the tag \c <TextEdit>. */ /*! - Constructs a new QFxTextEdit. + Constructs a new QmlGraphicsTextEdit. */ -QFxTextEdit::QFxTextEdit(QFxItem *parent) -: QFxPaintedItem(*(new QFxTextEditPrivate), parent) +QmlGraphicsTextEdit::QmlGraphicsTextEdit(QmlGraphicsItem *parent) +: QmlGraphicsPaintedItem(*(new QmlGraphicsTextEditPrivate), parent) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); d->init(); } /*! \internal */ -QFxTextEdit::QFxTextEdit(QFxTextEditPrivate &dd, QFxItem *parent) - : QFxPaintedItem(dd, parent) +QmlGraphicsTextEdit::QmlGraphicsTextEdit(QmlGraphicsTextEditPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsPaintedItem(dd, parent) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); d->init(); } -QString QFxTextEdit::text() const +QString QmlGraphicsTextEdit::text() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); if (d->richText) return d->document->toHtml(); @@ -141,10 +141,10 @@ QString QFxTextEdit::text() const automatically determine whether the text should be treated as rich text. This determination is made using Qt::mightBeRichText(). */ -void QFxTextEdit::setText(const QString &text) +void QmlGraphicsTextEdit::setText(const QString &text) { - Q_D(QFxTextEdit); - if (QFxTextEdit::text() == text) + Q_D(QmlGraphicsTextEdit); + if (QmlGraphicsTextEdit::text() == text) return; d->text = text; d->richText = d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(text)); @@ -192,15 +192,15 @@ Column { \o \image declarative-textformat.png \endtable */ -QFxTextEdit::TextFormat QFxTextEdit::textFormat() const +QmlGraphicsTextEdit::TextFormat QmlGraphicsTextEdit::textFormat() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->format; } -void QFxTextEdit::setTextFormat(TextFormat format) +void QmlGraphicsTextEdit::setTextFormat(TextFormat format) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (format == d->format) return; bool wasRich = d->richText; @@ -216,15 +216,15 @@ void QFxTextEdit::setTextFormat(TextFormat format) d->format = format; } -QFont QFxTextEdit::font() const +QFont QmlGraphicsTextEdit::font() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->font; } -void QFxTextEdit::setFont(const QFont &font) +void QmlGraphicsTextEdit::setFont(const QFont &font) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); d->font = font; clearCache(); @@ -250,15 +250,15 @@ TextEdit { color: "#00FF00"; ... } TextEdit { color: "steelblue"; ... } \endqml */ -QColor QFxTextEdit::color() const +QColor QmlGraphicsTextEdit::color() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->color; } -void QFxTextEdit::setColor(const QColor &color) +void QmlGraphicsTextEdit::setColor(const QColor &color) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (d->color == color) return; @@ -275,15 +275,15 @@ void QFxTextEdit::setColor(const QColor &color) The text highlight color, used behind selections. */ -QColor QFxTextEdit::selectionColor() const +QColor QmlGraphicsTextEdit::selectionColor() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->selectionColor; } -void QFxTextEdit::setSelectionColor(const QColor &color) +void QmlGraphicsTextEdit::setSelectionColor(const QColor &color) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (d->selectionColor == color) return; @@ -300,15 +300,15 @@ void QFxTextEdit::setSelectionColor(const QColor &color) The selected text color, used in selections. */ -QColor QFxTextEdit::selectedTextColor() const +QColor QmlGraphicsTextEdit::selectedTextColor() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->selectedTextColor; } -void QFxTextEdit::setSelectedTextColor(const QColor &color) +void QmlGraphicsTextEdit::setSelectedTextColor(const QColor &color) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (d->selectedTextColor == color) return; @@ -331,15 +331,15 @@ void QFxTextEdit::setSelectedTextColor(const QColor &color) \c AlignHCenter. The valid values for \c verticalAlignment are \c AlignTop, \c AlignBottom and \c AlignVCenter. */ -QFxTextEdit::HAlignment QFxTextEdit::hAlign() const +QmlGraphicsTextEdit::HAlignment QmlGraphicsTextEdit::hAlign() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->hAlign; } -void QFxTextEdit::setHAlign(QFxTextEdit::HAlignment alignment) +void QmlGraphicsTextEdit::setHAlign(QmlGraphicsTextEdit::HAlignment alignment) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (alignment == d->hAlign) return; d->hAlign = alignment; @@ -347,15 +347,15 @@ void QFxTextEdit::setHAlign(QFxTextEdit::HAlignment alignment) updateSize(); } -QFxTextEdit::VAlignment QFxTextEdit::vAlign() const +QmlGraphicsTextEdit::VAlignment QmlGraphicsTextEdit::vAlign() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->vAlign; } -void QFxTextEdit::setVAlign(QFxTextEdit::VAlignment alignment) +void QmlGraphicsTextEdit::setVAlign(QmlGraphicsTextEdit::VAlignment alignment) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (alignment == d->vAlign) return; d->vAlign = alignment; @@ -363,9 +363,9 @@ void QFxTextEdit::setVAlign(QFxTextEdit::VAlignment alignment) updateSize(); } -bool QFxTextEdit::wrap() const +bool QmlGraphicsTextEdit::wrap() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->wrap; } @@ -377,9 +377,9 @@ bool QFxTextEdit::wrap() const Wrapping is done on word boundaries (i.e. it is a "word-wrap"). Wrapping is off by default. */ -void QFxTextEdit::setWrap(bool w) +void QmlGraphicsTextEdit::setWrap(bool w) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (w == d->wrap) return; d->wrap = w; @@ -394,15 +394,15 @@ void QFxTextEdit::setWrap(bool w) This property is set and unset when the text edit gets focus, but it can also be set directly (useful, for example, if a KeyProxy might forward keys to it). */ -bool QFxTextEdit::isCursorVisible() const +bool QmlGraphicsTextEdit::isCursorVisible() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->cursorVisible; } -void QFxTextEdit::setCursorVisible(bool on) +void QmlGraphicsTextEdit::setCursorVisible(bool on) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (d->cursorVisible == on) return; d->cursorVisible = on; @@ -416,15 +416,15 @@ void QFxTextEdit::setCursorVisible(bool on) \qmlproperty int TextEdit::cursorPosition The position of the cursor in the TextEdit. */ -int QFxTextEdit::cursorPosition() const +int QmlGraphicsTextEdit::cursorPosition() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->control->textCursor().position(); } -void QFxTextEdit::setCursorPosition(int pos) +void QmlGraphicsTextEdit::setCursorPosition(int pos) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); QTextCursor cursor = d->control->textCursor(); if (cursor.position() == pos) return; @@ -442,18 +442,18 @@ void QFxTextEdit::setCursorPosition(int pos) needed, and the x and y properties of delegate instance will be set so as to be one pixel before the top left of the current character. - Note that the root item of the delegate component must be a QFxItem or - QFxItem derived item. + Note that the root item of the delegate component must be a QmlGraphicsItem or + QmlGraphicsItem derived item. */ -QmlComponent* QFxTextEdit::cursorDelegate() const +QmlComponent* QmlGraphicsTextEdit::cursorDelegate() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->cursorComponent; } -void QFxTextEdit::setCursorDelegate(QmlComponent* c) +void QmlGraphicsTextEdit::setCursorDelegate(QmlComponent* c) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if(d->cursorComponent){ if(d->cursor){ disconnect(d->control, SIGNAL(cursorPositionChanged()), @@ -474,12 +474,12 @@ void QFxTextEdit::setCursorDelegate(QmlComponent* c) } } -void QFxTextEdit::loadCursorDelegate() +void QmlGraphicsTextEdit::loadCursorDelegate() { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if(d->cursorComponent->isLoading()) return; - d->cursor = qobject_cast(d->cursorComponent->create(qmlContext(this))); + d->cursor = qobject_cast(d->cursorComponent->create(qmlContext(this))); if(d->cursor){ connect(d->control, SIGNAL(cursorPositionChanged()), this, SLOT(moveCursorDelegate())); @@ -506,15 +506,15 @@ void QFxTextEdit::loadCursorDelegate() \sa selectionEnd, cursorPosition, selectedText */ -int QFxTextEdit::selectionStart() const +int QmlGraphicsTextEdit::selectionStart() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->control->textCursor().selectionStart(); } -void QFxTextEdit::setSelectionStart(int s) +void QmlGraphicsTextEdit::setSelectionStart(int s) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if(d->lastSelectionStart == s || s < 0 || s > text().length()) return; d->lastSelectionStart = s; @@ -534,15 +534,15 @@ void QFxTextEdit::setSelectionStart(int s) \sa selectionStart, cursorPosition, selectedText */ -int QFxTextEdit::selectionEnd() const +int QmlGraphicsTextEdit::selectionEnd() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->control->textCursor().selectionEnd(); } -void QFxTextEdit::setSelectionEnd(int s) +void QmlGraphicsTextEdit::setSelectionEnd(int s) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if(d->lastSelectionEnd == s || s < 0 || s > text().length()) return; d->lastSelectionEnd = s; @@ -563,9 +563,9 @@ void QFxTextEdit::setSelectionEnd(int s) myTextEdit.selectionEnd); \endcode */ -QString QFxTextEdit::selectedText() const +QString QmlGraphicsTextEdit::selectedText() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->control->textCursor().selectedText(); } @@ -575,15 +575,15 @@ QString QFxTextEdit::selectedText() const Whether the TextEdit should gain focus on a mouse press. By default this is set to false; */ -bool QFxTextEdit::focusOnPress() const +bool QmlGraphicsTextEdit::focusOnPress() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->focusOnPress; } -void QFxTextEdit::setFocusOnPress(bool on) +void QmlGraphicsTextEdit::setFocusOnPress(bool on) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (d->focusOnPress == on) return; d->focusOnPress = on; @@ -595,51 +595,51 @@ void QFxTextEdit::setFocusOnPress(bool on) Whether the TextEdit should keep the selection visible when it loses focus to another item in the scene. By default this is set to true; */ -bool QFxTextEdit::persistentSelection() const +bool QmlGraphicsTextEdit::persistentSelection() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->persistentSelection; } -void QFxTextEdit::setPersistentSelection(bool on) +void QmlGraphicsTextEdit::setPersistentSelection(bool on) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (d->persistentSelection == on) return; d->persistentSelection = on; } -qreal QFxTextEdit::textMargin() const +qreal QmlGraphicsTextEdit::textMargin() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->textMargin; } -void QFxTextEdit::setTextMargin(qreal margin) +void QmlGraphicsTextEdit::setTextMargin(qreal margin) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (d->textMargin == margin) return; d->textMargin = margin; d->document->setDocumentMargin(d->textMargin); } -void QFxTextEdit::geometryChanged(const QRectF &newGeometry, +void QmlGraphicsTextEdit::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { if (newGeometry.width() != oldGeometry.width()) updateSize(); - QFxPaintedItem::geometryChanged(newGeometry, oldGeometry); + QmlGraphicsPaintedItem::geometryChanged(newGeometry, oldGeometry); } /*! Ensures any delayed caching or data loading the class needs to performed is complete. */ -void QFxTextEdit::componentComplete() +void QmlGraphicsTextEdit::componentComplete() { - Q_D(QFxTextEdit); - QFxPaintedItem::componentComplete(); + Q_D(QmlGraphicsTextEdit); + QmlGraphicsPaintedItem::componentComplete(); if (d->dirty) { updateSize(); d->dirty = false; @@ -654,9 +654,9 @@ void QFxTextEdit::componentComplete() By default this property is false. */ -void QFxTextEdit::setReadOnly(bool r) +void QmlGraphicsTextEdit::setReadOnly(bool r) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); Qt::TextInteractionFlags flags = Qt::NoTextInteraction; if (r) { @@ -669,9 +669,9 @@ void QFxTextEdit::setReadOnly(bool r) d->control->moveCursor(QTextCursor::End); } -bool QFxTextEdit::isReadOnly() const +bool QmlGraphicsTextEdit::isReadOnly() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return !(d->control->textInteractionFlags() & Qt::TextEditable); } @@ -679,9 +679,9 @@ bool QFxTextEdit::isReadOnly() const Sets how the text edit should interact with user input to the given \a flags. */ -void QFxTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags) +void QmlGraphicsTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); d->control->setTextInteractionFlags(flags); } @@ -689,9 +689,9 @@ void QFxTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags) Returns the flags specifying how the text edit should interact with user input. */ -Qt::TextInteractionFlags QFxTextEdit::textInteractionFlags() const +Qt::TextInteractionFlags QmlGraphicsTextEdit::textInteractionFlags() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->control->textInteractionFlags(); } @@ -699,9 +699,9 @@ Qt::TextInteractionFlags QFxTextEdit::textInteractionFlags() const Returns the cursor for the point at the given \a pos on the text edit. */ -QTextCursor QFxTextEdit::cursorForPosition(const QPoint &pos) const +QTextCursor QmlGraphicsTextEdit::cursorForPosition(const QPoint &pos) const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->control->cursorForPosition(pos); } @@ -709,9 +709,9 @@ QTextCursor QFxTextEdit::cursorForPosition(const QPoint &pos) const Returns the rectangle where the given text \a cursor is rendered within the text edit. */ -QRect QFxTextEdit::cursorRect(const QTextCursor &cursor) const +QRect QmlGraphicsTextEdit::cursorRect(const QTextCursor &cursor) const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); if (cursor.isNull()) return QRect(); @@ -722,9 +722,9 @@ QRect QFxTextEdit::cursorRect(const QTextCursor &cursor) const Returns the rectangle where the text cursor is rendered within the text edit. */ -QRect QFxTextEdit::cursorRect() const +QRect QmlGraphicsTextEdit::cursorRect() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->control->cursorRect().toRect(); } @@ -732,18 +732,18 @@ QRect QFxTextEdit::cursorRect() const /*! Sets the text cursor for the text edit to the given \a cursor. */ -void QFxTextEdit::setTextCursor(const QTextCursor &cursor) +void QmlGraphicsTextEdit::setTextCursor(const QTextCursor &cursor) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); d->control->setTextCursor(cursor); } /*! Returns the text cursor for the text edit. */ -QTextCursor QFxTextEdit::textCursor() const +QTextCursor QmlGraphicsTextEdit::textCursor() const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->control->textCursor(); } @@ -752,9 +752,9 @@ Moves the cursor by performing the given \a operation. If \a mode is QTextCursor::KeepAnchor, the cursor selects the text it moves over. This is the same effect that the user achieves when they hold down the Shift key and move the cursor with the cursor keys. */ -void QFxTextEdit::moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode) +void QmlGraphicsTextEdit::moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); d->control->moveCursor(operation, mode); } @@ -762,23 +762,23 @@ void QFxTextEdit::moveCursor(QTextCursor::MoveOperation operation, QTextCursor:: \overload Handles the given \a event. */ -bool QFxTextEdit::event(QEvent *event) +bool QmlGraphicsTextEdit::event(QEvent *event) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (event->type() == QEvent::ShortcutOverride) { d->control->processEvent(event, QPointF(0, 0)); return event->isAccepted(); } - return QFxPaintedItem::event(event); + return QmlGraphicsPaintedItem::event(event); } /*! \overload Handles the given key \a event. */ -void QFxTextEdit::keyPressEvent(QKeyEvent *event) +void QmlGraphicsTextEdit::keyPressEvent(QKeyEvent *event) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); //### this causes non-standard cursor behavior in some cases. // is it still needed? /*QTextCursor c = textCursor(); @@ -803,19 +803,19 @@ void QFxTextEdit::keyPressEvent(QKeyEvent *event) d->control->processEvent(event, QPointF(0, 0)); if (!event->isAccepted()) - QFxPaintedItem::keyPressEvent(event); + QmlGraphicsPaintedItem::keyPressEvent(event); } /*! \overload Handles the given key \a event. */ -void QFxTextEdit::keyReleaseEvent(QKeyEvent *event) +void QmlGraphicsTextEdit::keyReleaseEvent(QKeyEvent *event) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); d->control->processEvent(event, QPointF(0, 0)); if (!event->isAccepted()) - QFxPaintedItem::keyReleaseEvent(event); + QmlGraphicsPaintedItem::keyReleaseEvent(event); } /*! @@ -825,18 +825,18 @@ void QFxTextEdit::keyReleaseEvent(QKeyEvent *event) like KeyProxy can give the behavior of focus even when hasFocus() isn't true. */ -void QFxTextEdit::focusChanged(bool hasFocus) +void QmlGraphicsTextEdit::focusChanged(bool hasFocus) { setCursorVisible(hasFocus); - QFxItem::focusChanged(hasFocus); + QmlGraphicsItem::focusChanged(hasFocus); } /*! Causes all text to be selected. */ -void QFxTextEdit::selectAll() +void QmlGraphicsTextEdit::selectAll() { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); d->control->selectAll(); } @@ -844,59 +844,59 @@ void QFxTextEdit::selectAll() \overload Handles the given mouse \a event. */ -void QFxTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (d->focusOnPress) setFocus(true); d->control->processEvent(event, QPointF(0, 0)); if (!event->isAccepted()) - QFxPaintedItem::mousePressEvent(event); + QmlGraphicsPaintedItem::mousePressEvent(event); } /*! \overload Handles the given mouse \a event. */ -void QFxTextEdit::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsTextEdit::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); d->control->processEvent(event, QPointF(0, 0)); if (!event->isAccepted()) - QFxPaintedItem::mousePressEvent(event); + QmlGraphicsPaintedItem::mousePressEvent(event); } /*! \overload Handles the given mouse \a event. */ -void QFxTextEdit::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsTextEdit::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); d->control->processEvent(event, QPointF(0, 0)); if (!event->isAccepted()) - QFxPaintedItem::mouseDoubleClickEvent(event); + QmlGraphicsPaintedItem::mouseDoubleClickEvent(event); } /*! \overload Handles the given mouse \a event. */ -void QFxTextEdit::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsTextEdit::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); d->control->processEvent(event, QPointF(0, 0)); if (!event->isAccepted()) - QFxPaintedItem::mousePressEvent(event); + QmlGraphicsPaintedItem::mousePressEvent(event); } /*! \overload Handles the given input method \a event. */ -void QFxTextEdit::inputMethodEvent(QInputMethodEvent *event) +void QmlGraphicsTextEdit::inputMethodEvent(QInputMethodEvent *event) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); d->control->processEvent(event, QPointF(0, 0)); } @@ -904,9 +904,9 @@ void QFxTextEdit::inputMethodEvent(QInputMethodEvent *event) \overload Returns the value of the given \a property. */ -QVariant QFxTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const +QVariant QmlGraphicsTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const { - Q_D(const QFxTextEdit); + Q_D(const QmlGraphicsTextEdit); return d->control->inputMethodQuery(property); } @@ -914,16 +914,16 @@ QVariant QFxTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const Draws the contents of the text edit using the given \a painter within the given \a bounds. */ -void QFxTextEdit::drawContents(QPainter *painter, const QRect &bounds) +void QmlGraphicsTextEdit::drawContents(QPainter *painter, const QRect &bounds) { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); painter->setRenderHint(QPainter::TextAntialiasing, true); d->control->drawContents(painter, bounds); } -void QFxTextEdit::updateImgCache(const QRectF &r) +void QmlGraphicsTextEdit::updateImgCache(const QRectF &r) { dirtyCache(r.toRect()); emit update(); @@ -942,9 +942,9 @@ void QFxTextEdit::updateImgCache(const QRectF &r) filtering at the beginning of the animation and reenable it at the conclusion. */ -void QFxTextEditPrivate::init() +void QmlGraphicsTextEditPrivate::init() { - Q_Q(QFxTextEdit); + Q_Q(QmlGraphicsTextEdit); q->setSmoothTransform(smooth); q->setAcceptedMouseButtons(Qt::LeftButton); @@ -969,16 +969,16 @@ void QFxTextEditPrivate::init() updateDefaultTextOption(); } -void QFxTextEdit::q_textChanged() +void QmlGraphicsTextEdit::q_textChanged() { if (!widthValid()) updateSize(); //### optimize: we get 3 calls to updateSize every time a letter is typed emit textChanged(text()); } -void QFxTextEdit::moveCursorDelegate() +void QmlGraphicsTextEdit::moveCursorDelegate() { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if(!d->cursor) return; QRectF cursorRect = d->control->cursorRect(); @@ -986,9 +986,9 @@ void QFxTextEdit::moveCursorDelegate() d->cursor->setY(cursorRect.y()); } -void QFxTextEditPrivate::updateSelection() +void QmlGraphicsTextEditPrivate::updateSelection() { - Q_Q(QFxTextEdit); + Q_Q(QmlGraphicsTextEdit); QTextCursor cursor = control->textCursor(); bool startChange = (lastSelectionStart != cursor.selectionStart()); bool endChange = (lastSelectionEnd != cursor.selectionEnd()); @@ -1005,12 +1005,12 @@ void QFxTextEditPrivate::updateSelection() startChange = (lastSelectionStart != control->textCursor().selectionStart()); endChange = (lastSelectionEnd != control->textCursor().selectionEnd()); if(startChange || endChange) - qWarning() << "QFxTextEditPrivate::updateSelection() has failed you."; + qWarning() << "QmlGraphicsTextEditPrivate::updateSelection() has failed you."; } -void QFxTextEdit::updateSelectionMarkers() +void QmlGraphicsTextEdit::updateSelectionMarkers() { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if(d->lastSelectionStart != d->control->textCursor().selectionStart()){ d->lastSelectionStart = d->control->textCursor().selectionStart(); emit selectionStartChanged(); @@ -1023,9 +1023,9 @@ void QFxTextEdit::updateSelectionMarkers() //### we should perhaps be a bit smarter here -- depending on what has changed, we shouldn't // need to do all the calculations each time -void QFxTextEdit::updateSize() +void QmlGraphicsTextEdit::updateSize() { - Q_D(QFxTextEdit); + Q_D(QmlGraphicsTextEdit); if (isComponentComplete()) { QFontMetrics fm = QFontMetrics(d->font); int dy = height(); @@ -1064,7 +1064,7 @@ void QFxTextEdit::updateSize() emit update(); } -void QFxTextEditPrivate::updateDefaultTextOption() +void QmlGraphicsTextEditPrivate::updateDefaultTextOption() { QTextOption opt = document->defaultTextOption(); int oldAlignment = opt.alignment(); diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h index f4f101a..28eb180 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -58,8 +58,8 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxTextEditPrivate; -class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem +class QmlGraphicsTextEditPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsTextEdit : public QmlGraphicsPaintedItem { Q_OBJECT Q_ENUMS(VAlignment) @@ -87,7 +87,7 @@ class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin) public: - QFxTextEdit(QFxItem *parent=0); + QmlGraphicsTextEdit(QmlGraphicsItem *parent=0); enum HAlignment { AlignLeft = Qt::AlignLeft, @@ -201,7 +201,7 @@ private: void updateSize(); protected: - QFxTextEdit(QFxTextEditPrivate &dd, QFxItem *parent); + QmlGraphicsTextEdit(QmlGraphicsTextEditPrivate &dd, QmlGraphicsItem *parent); virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); @@ -221,13 +221,13 @@ protected: void drawContents(QPainter *, const QRect &); private: - Q_DISABLE_COPY(QFxTextEdit) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxTextEdit) + Q_DISABLE_COPY(QmlGraphicsTextEdit) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsTextEdit) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxTextEdit) +QML_DECLARE_TYPE(QmlGraphicsTextEdit) QT_END_HEADER diff --git a/src/declarative/fx/qfxtextedit_p.h b/src/declarative/fx/qfxtextedit_p.h index 82481ff..ca65109 100644 --- a/src/declarative/fx/qfxtextedit_p.h +++ b/src/declarative/fx/qfxtextedit_p.h @@ -62,16 +62,16 @@ QT_BEGIN_NAMESPACE class QTextLayout; class QTextDocument; class QTextControl; -class QFxTextEditPrivate : public QFxPaintedItemPrivate +class QmlGraphicsTextEditPrivate : public QmlGraphicsPaintedItemPrivate { - Q_DECLARE_PUBLIC(QFxTextEdit) + Q_DECLARE_PUBLIC(QmlGraphicsTextEdit) public: - QFxTextEditPrivate() - : color("black"), imgDirty(true), hAlign(QFxTextEdit::AlignLeft), vAlign(QFxTextEdit::AlignTop), + QmlGraphicsTextEditPrivate() + : color("black"), imgDirty(true), hAlign(QmlGraphicsTextEdit::AlignLeft), vAlign(QmlGraphicsTextEdit::AlignTop), dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(false), persistentSelection(true), textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0), - cursorComponent(0), cursor(0), format(QFxTextEdit::AutoText), document(0) + cursorComponent(0), cursor(0), format(QmlGraphicsTextEdit::AutoText), document(0) { } @@ -91,8 +91,8 @@ public: bool imgDirty; QPixmap imgCache; QPixmap imgStyleCache; - QFxTextEdit::HAlignment hAlign; - QFxTextEdit::VAlignment vAlign; + QmlGraphicsTextEdit::HAlignment hAlign; + QmlGraphicsTextEdit::VAlignment vAlign; bool dirty; bool wrap; bool richText; @@ -103,8 +103,8 @@ public: int lastSelectionStart; int lastSelectionEnd; QmlComponent* cursorComponent; - QFxItem* cursor; - QFxTextEdit::TextFormat format; + QmlGraphicsItem* cursor; + QmlGraphicsTextEdit::TextFormat format; QTextDocument *document; QTextControl *control; }; diff --git a/src/declarative/fx/qfxtextinput.cpp b/src/declarative/fx/qfxtextinput.cpp index e9ddd3f..930768d 100644 --- a/src/declarative/fx/qfxtextinput.cpp +++ b/src/declarative/fx/qfxtextinput.cpp @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,TextInput,QFxTextInput); +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,TextInput,QmlGraphicsTextInput); QML_DEFINE_NOCREATE_TYPE(QValidator); QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,QIntValidator,QIntValidator); @@ -63,24 +63,24 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,QIntValidator,QIntValidator); Input constraints include setting a QValidator, an input mask, or a maximum input length. */ -QFxTextInput::QFxTextInput(QFxItem* parent) - : QFxPaintedItem(*(new QFxTextInputPrivate), parent) +QmlGraphicsTextInput::QmlGraphicsTextInput(QmlGraphicsItem* parent) + : QmlGraphicsPaintedItem(*(new QmlGraphicsTextInputPrivate), parent) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->init(); } /* \internal */ -QFxTextInput::QFxTextInput(QFxTextInputPrivate &dd, QFxItem* parent) - : QFxPaintedItem(dd, parent) +QmlGraphicsTextInput::QmlGraphicsTextInput(QmlGraphicsTextInputPrivate &dd, QmlGraphicsItem* parent) + : QmlGraphicsPaintedItem(dd, parent) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->init(); } -QFxTextInput::~QFxTextInput() +QmlGraphicsTextInput::~QmlGraphicsTextInput() { } @@ -90,15 +90,15 @@ QFxTextInput::~QFxTextInput() The text in the TextInput. */ -QString QFxTextInput::text() const +QString QmlGraphicsTextInput::text() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->control->text(); } -void QFxTextInput::setText(const QString &s) +void QmlGraphicsTextInput::setText(const QString &s) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); if(s == text()) return; d->control->setText(s); @@ -115,15 +115,15 @@ void QFxTextInput::setText(const QString &s) Set the TextInput's font attributes. */ -QFont QFxTextInput::font() const +QFont QmlGraphicsTextInput::font() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->font; } -void QFxTextInput::setFont(const QFont &font) +void QmlGraphicsTextInput::setFont(const QFont &font) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->font = font; d->control->setFont(d->font); @@ -139,15 +139,15 @@ void QFxTextInput::setFont(const QFont &font) The text color. */ -QColor QFxTextInput::color() const +QColor QmlGraphicsTextInput::color() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->color; } -void QFxTextInput::setColor(const QColor &c) +void QmlGraphicsTextInput::setColor(const QColor &c) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->color = c; } @@ -157,15 +157,15 @@ void QFxTextInput::setColor(const QColor &c) The text highlight color, used behind selections. */ -QColor QFxTextInput::selectionColor() const +QColor QmlGraphicsTextInput::selectionColor() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->selectionColor; } -void QFxTextInput::setSelectionColor(const QColor &color) +void QmlGraphicsTextInput::setSelectionColor(const QColor &color) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); if (d->selectionColor == color) return; @@ -180,15 +180,15 @@ void QFxTextInput::setSelectionColor(const QColor &color) The highlighted text color, used in selections. */ -QColor QFxTextInput::selectedTextColor() const +QColor QmlGraphicsTextInput::selectedTextColor() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->selectedTextColor; } -void QFxTextInput::setSelectedTextColor(const QColor &color) +void QmlGraphicsTextInput::setSelectedTextColor(const QColor &color) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); if (d->selectedTextColor == color) return; @@ -213,40 +213,40 @@ void QFxTextInput::setSelectedTextColor(const QColor &color) The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and \c AlignHCenter. */ -QFxTextInput::HAlignment QFxTextInput::hAlign() const +QmlGraphicsTextInput::HAlignment QmlGraphicsTextInput::hAlign() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->hAlign; } -void QFxTextInput::setHAlign(HAlignment align) +void QmlGraphicsTextInput::setHAlign(HAlignment align) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->hAlign = align; //TODO: implement } -bool QFxTextInput::isReadOnly() const +bool QmlGraphicsTextInput::isReadOnly() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->control->isReadOnly(); } -void QFxTextInput::setReadOnly(bool ro) +void QmlGraphicsTextInput::setReadOnly(bool ro) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->control->setReadOnly(ro); } -int QFxTextInput::maxLength() const +int QmlGraphicsTextInput::maxLength() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->control->maxLength(); } -void QFxTextInput::setMaxLength(int ml) +void QmlGraphicsTextInput::setMaxLength(int ml) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->control->setMaxLength(ml); } @@ -257,15 +257,15 @@ void QFxTextInput::setMaxLength(int ml) This property is set and unset when the line edit gets focus, but it can also be set directly (useful, for example, if a KeyProxy might forward keys to it). */ -bool QFxTextInput::isCursorVisible() const +bool QmlGraphicsTextInput::isCursorVisible() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->cursorVisible; } -void QFxTextInput::setCursorVisible(bool on) +void QmlGraphicsTextInput::setCursorVisible(bool on) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); if (d->cursorVisible == on) return; d->cursorVisible = on; @@ -277,14 +277,14 @@ void QFxTextInput::setCursorVisible(bool on) \qmlproperty int TextInput::cursorPosition The position of the cursor in the TextInput. */ -int QFxTextInput::cursorPosition() const +int QmlGraphicsTextInput::cursorPosition() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->control->cursor(); } -void QFxTextInput::setCursorPosition(int cp) +void QmlGraphicsTextInput::setCursorPosition(int cp) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->control->moveCursor(cp); } @@ -294,9 +294,9 @@ void QFxTextInput::setCursorPosition(int cp) Returns a Rect which encompasses the cursor, but which may be larger than is required. Ignores custom cursor delegates. */ -QRect QFxTextInput::cursorRect() const +QRect QmlGraphicsTextInput::cursorRect() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->control->cursorRect(); } @@ -313,15 +313,15 @@ QRect QFxTextInput::cursorRect() const \sa selectionEnd, cursorPosition, selectedText */ -int QFxTextInput::selectionStart() const +int QmlGraphicsTextInput::selectionStart() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->lastSelectionStart; } -void QFxTextInput::setSelectionStart(int s) +void QmlGraphicsTextInput::setSelectionStart(int s) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); if(d->lastSelectionStart == s || s < 0 || s > text().length()) return; d->lastSelectionStart = s; @@ -341,15 +341,15 @@ void QFxTextInput::setSelectionStart(int s) \sa selectionStart, cursorPosition, selectedText */ -int QFxTextInput::selectionEnd() const +int QmlGraphicsTextInput::selectionEnd() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->lastSelectionEnd; } -void QFxTextInput::setSelectionEnd(int s) +void QmlGraphicsTextInput::setSelectionEnd(int s) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); if(d->lastSelectionEnd == s || s < 0 || s > text().length()) return; d->lastSelectionEnd = s; @@ -370,9 +370,9 @@ void QFxTextInput::setSelectionEnd(int s) myTextInput.selectionEnd); \endqml */ -QString QFxTextInput::selectedText() const +QString QmlGraphicsTextInput::selectedText() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->control->selectedText(); } @@ -382,15 +382,15 @@ QString QFxTextInput::selectedText() const Whether the TextInput should gain focus on a mouse press. By default this is set to true. */ -bool QFxTextInput::focusOnPress() const +bool QmlGraphicsTextInput::focusOnPress() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->focusOnPress; } -void QFxTextInput::setFocusOnPress(bool b) +void QmlGraphicsTextInput::setFocusOnPress(bool b) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->focusOnPress = b; } @@ -404,16 +404,16 @@ void QFxTextInput::setFocusOnPress(bool b) \sa acceptableInput, inputMask */ -QValidator* QFxTextInput::validator() const +QValidator* QmlGraphicsTextInput::validator() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); //###const cast isn't good, but needed for property system? return const_cast(d->control->validator()); } -void QFxTextInput::setValidator(QValidator* v) +void QmlGraphicsTextInput::setValidator(QValidator* v) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->control->setValidator(v); if(!d->control->hasAcceptableInput()){ d->oldValidity = false; @@ -430,15 +430,15 @@ void QFxTextInput::setValidator(QValidator* v) \sa acceptableInput, validator */ -QString QFxTextInput::inputMask() const +QString QmlGraphicsTextInput::inputMask() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->control->inputMask(); } -void QFxTextInput::setInputMask(const QString &im) +void QmlGraphicsTextInput::setInputMask(const QString &im) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->control->setInputMask(im); } @@ -450,9 +450,9 @@ void QFxTextInput::setInputMask(const QString &im) if the current text is acceptable to the validator or input mask as a final string (not as an intermediate string). */ -bool QFxTextInput::hasAcceptableInput() const +bool QmlGraphicsTextInput::hasAcceptableInput() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->control->hasAcceptableInput(); } @@ -466,15 +466,15 @@ bool QFxTextInput::hasAcceptableInput() const current character as asterixes. */ -QFxTextInput::EchoMode QFxTextInput::echoMode() const +QmlGraphicsTextInput::EchoMode QmlGraphicsTextInput::echoMode() const { - Q_D(const QFxTextInput); - return (QFxTextInput::EchoMode)d->control->echoMode(); + Q_D(const QmlGraphicsTextInput); + return (QmlGraphicsTextInput::EchoMode)d->control->echoMode(); } -void QFxTextInput::setEchoMode(QFxTextInput::EchoMode echo) +void QmlGraphicsTextInput::setEchoMode(QmlGraphicsTextInput::EchoMode echo) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->control->setEchoMode((uint)echo); } @@ -488,18 +488,18 @@ void QFxTextInput::setEchoMode(QFxTextInput::EchoMode echo) needed, and the x property of delegate instance will be set so as to be one pixel before the top left of the current character. - Note that the root item of the delegate component must be a QFxItem or - QFxItem derived item. + Note that the root item of the delegate component must be a QmlGraphicsItem or + QmlGraphicsItem derived item. */ -QmlComponent* QFxTextInput::cursorDelegate() const +QmlComponent* QmlGraphicsTextInput::cursorDelegate() const { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->cursorComponent; } -void QFxTextInput::setCursorDelegate(QmlComponent* c) +void QmlGraphicsTextInput::setCursorDelegate(QmlComponent* c) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->cursorComponent = c; if(!c){ //note that the components are owned by something else @@ -511,9 +511,9 @@ void QFxTextInput::setCursorDelegate(QmlComponent* c) } } -void QFxTextInputPrivate::startCreatingCursor() +void QmlGraphicsTextInputPrivate::startCreatingCursor() { - Q_Q(QFxTextInput); + Q_Q(QmlGraphicsTextInput); q->connect(control, SIGNAL(cursorPositionChanged(int, int)), q, SLOT(moveCursor())); if(cursorComponent->isReady()){ @@ -522,14 +522,14 @@ void QFxTextInputPrivate::startCreatingCursor() q->connect(cursorComponent, SIGNAL(statusChanged(int)), q, SLOT(createCursor())); }else{//isError - qmlInfo(QFxTextInput::tr("Could not load cursor delegate"), q); + qmlInfo(QmlGraphicsTextInput::tr("Could not load cursor delegate"), q); qWarning() << cursorComponent->errors(); } } -void QFxTextInput::createCursor() +void QmlGraphicsTextInput::createCursor() { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); if(d->cursorComponent->isError()){ qmlInfo(tr("Could not load cursor delegate"),this); qWarning() << d->cursorComponent->errors(); @@ -541,7 +541,7 @@ void QFxTextInput::createCursor() if(d->cursorItem) delete d->cursorItem; - d->cursorItem = qobject_cast(d->cursorComponent->create()); + d->cursorItem = qobject_cast(d->cursorComponent->create()); if(!d->cursorItem){ qmlInfo(tr("Could not instantiate cursor delegate"),this); //The failed instantiation should print its own error messages @@ -553,31 +553,31 @@ void QFxTextInput::createCursor() d->cursorItem->setHeight(d->control->height()); } -void QFxTextInput::moveCursor() +void QmlGraphicsTextInput::moveCursor() { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); if(!d->cursorItem) return; d->cursorItem->setX(d->control->cursorToX() - d->hscroll); } -int QFxTextInput::xToPos(int x) +int QmlGraphicsTextInput::xToPos(int x) { - Q_D(const QFxTextInput); + Q_D(const QmlGraphicsTextInput); return d->control->xToPos(x - d->hscroll); } -void QFxTextInput::focusChanged(bool hasFocus) +void QmlGraphicsTextInput::focusChanged(bool hasFocus) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->focused = hasFocus; setCursorVisible(hasFocus); - QFxItem::focusChanged(hasFocus); + QmlGraphicsItem::focusChanged(hasFocus); } -void QFxTextInput::keyPressEvent(QKeyEvent* ev) +void QmlGraphicsTextInput::keyPressEvent(QKeyEvent* ev) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); if((d->control->cursor() == 0 && ev->key() == Qt::Key_Left) || (d->control->cursor() == d->control->text().length() && ev->key() == Qt::Key_Right)){ @@ -587,12 +587,12 @@ void QFxTextInput::keyPressEvent(QKeyEvent* ev) d->control->processKeyEvent(ev); } if (!ev->isAccepted()) - QFxPaintedItem::keyPressEvent(ev); + QmlGraphicsPaintedItem::keyPressEvent(ev); } -void QFxTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); if(d->focusOnPress){ setFocus(true); setCursorVisible(true); @@ -601,9 +601,9 @@ void QFxTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) d->control->processEvent(event); } -bool QFxTextInput::event(QEvent* ev) +bool QmlGraphicsTextInput::event(QEvent* ev) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); //Anything we don't deal with ourselves, pass to the control bool handled = false; switch(ev->type()){ @@ -615,21 +615,21 @@ bool QFxTextInput::event(QEvent* ev) handled = d->control->processEvent(ev); } if(!handled) - return QFxPaintedItem::event(ev); + return QmlGraphicsPaintedItem::event(ev); return true; } -void QFxTextInput::geometryChanged(const QRectF &newGeometry, +void QmlGraphicsTextInput::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { if (newGeometry.width() != oldGeometry.width()) updateSize(); - QFxPaintedItem::geometryChanged(newGeometry, oldGeometry); + QmlGraphicsPaintedItem::geometryChanged(newGeometry, oldGeometry); } -void QFxTextInput::drawContents(QPainter *p, const QRect &r) +void QmlGraphicsTextInput::drawContents(QPainter *p, const QRect &r) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); p->setRenderHint(QPainter::TextAntialiasing, true); p->save(); p->setPen(QPen(d->color)); @@ -647,9 +647,9 @@ void QFxTextInput::drawContents(QPainter *p, const QRect &r) p->restore(); } -void QFxTextInput::selectAll() +void QmlGraphicsTextInput::selectAll() { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); d->control->setSelection(0, d->control->text().length()); } @@ -667,9 +667,9 @@ void QFxTextInput::selectAll() filtering at the beginning of the animation and reenable it at the conclusion. */ -void QFxTextInputPrivate::init() +void QmlGraphicsTextInputPrivate::init() { - Q_Q(QFxTextInput); + Q_Q(QmlGraphicsTextInput); control->setCursorWidth(1); control->setPasswordCharacter(QLatin1Char('*')); control->setLayoutDirection(Qt::LeftToRight); @@ -698,9 +698,9 @@ void QFxTextInputPrivate::init() lastSelectionEnd = 0; } -void QFxTextInput::cursorPosChanged() +void QmlGraphicsTextInput::cursorPosChanged() { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); emit cursorPositionChanged(); if(!d->control->hasSelectedText()){ @@ -715,9 +715,9 @@ void QFxTextInput::cursorPosChanged() } } -void QFxTextInput::selectionChanged() +void QmlGraphicsTextInput::selectionChanged() { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); emit selectedTextChanged(); if(d->lastSelectionStart != d->control->selectionStart()){ @@ -734,9 +734,9 @@ void QFxTextInput::selectionChanged() } } -void QFxTextInput::q_textChanged() +void QmlGraphicsTextInput::q_textChanged() { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); updateSize(); emit textChanged(); if(hasAcceptableInput() != d->oldValidity){ @@ -745,7 +745,7 @@ void QFxTextInput::q_textChanged() } } -void QFxTextInput::updateRect(const QRect &r) +void QmlGraphicsTextInput::updateRect(const QRect &r) { if(r == QRect()) clearCache(); @@ -754,9 +754,9 @@ void QFxTextInput::updateRect(const QRect &r) update(); } -void QFxTextInput::updateSize(bool needsRedraw) +void QmlGraphicsTextInput::updateSize(bool needsRedraw) { - Q_D(QFxTextInput); + Q_D(QmlGraphicsTextInput); int w = width(); int h = height(); setImplicitHeight(d->control->height()); diff --git a/src/declarative/fx/qfxtextinput.h b/src/declarative/fx/qfxtextinput.h index 2540d41..ada32f9 100644 --- a/src/declarative/fx/qfxtextinput.h +++ b/src/declarative/fx/qfxtextinput.h @@ -53,9 +53,9 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxTextInputPrivate; +class QmlGraphicsTextInputPrivate; class QValidator; -class Q_DECLARATIVE_EXPORT QFxTextInput : public QFxPaintedItem +class Q_DECLARATIVE_EXPORT QmlGraphicsTextInput : public QmlGraphicsPaintedItem { Q_OBJECT Q_ENUMS(HAlignment) @@ -84,8 +84,8 @@ class Q_DECLARATIVE_EXPORT QFxTextInput : public QFxPaintedItem Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) public: - QFxTextInput(QFxItem* parent=0); - ~QFxTextInput(); + QmlGraphicsTextInput(QmlGraphicsItem* parent=0); + ~QmlGraphicsTextInput(); enum EchoMode {//To match QLineEdit::EchoMode Normal, @@ -172,7 +172,7 @@ Q_SIGNALS: void acceptableInputChanged(); protected: - QFxTextInput(QFxTextInputPrivate &dd, QFxItem *parent); + QmlGraphicsTextInput(QmlGraphicsTextInputPrivate &dd, QmlGraphicsItem *parent); virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); @@ -195,12 +195,12 @@ private Q_SLOTS: void updateRect(const QRect &r = QRect()); private: - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxTextInput) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsTextInput) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxTextInput) +QML_DECLARE_TYPE(QmlGraphicsTextInput) QML_DECLARE_TYPE(QValidator) QML_DECLARE_TYPE(QIntValidator) diff --git a/src/declarative/fx/qfxtextinput_p.h b/src/declarative/fx/qfxtextinput_p.h index 3978be4..be8c946 100644 --- a/src/declarative/fx/qfxtextinput_p.h +++ b/src/declarative/fx/qfxtextinput_p.h @@ -59,19 +59,19 @@ QT_BEGIN_NAMESPACE -class QFxTextInputPrivate : public QFxPaintedItemPrivate +class QmlGraphicsTextInputPrivate : public QmlGraphicsPaintedItemPrivate { - Q_DECLARE_PUBLIC(QFxTextInput) + Q_DECLARE_PUBLIC(QmlGraphicsTextInput) public: - QFxTextInputPrivate() : control(new QLineControl(QString())), - color((QRgb)0), style(QFxText::Normal), - styleColor((QRgb)0), hAlign(QFxTextInput::AlignLeft), + QmlGraphicsTextInputPrivate() : control(new QLineControl(QString())), + color((QRgb)0), style(QmlGraphicsText::Normal), + styleColor((QRgb)0), hAlign(QmlGraphicsTextInput::AlignLeft), hscroll(0), oldScroll(0), focused(false), focusOnPress(true), cursorVisible(false) { } - ~QFxTextInputPrivate() + ~QmlGraphicsTextInputPrivate() { delete control; } @@ -85,11 +85,11 @@ public: QColor color; QColor selectionColor; QColor selectedTextColor; - QFxText::TextStyle style; + QmlGraphicsText::TextStyle style; QColor styleColor; - QFxTextInput::HAlignment hAlign; + QmlGraphicsTextInput::HAlignment hAlign; QPointer cursorComponent; - QPointer cursorItem; + QPointer cursorItem; int lastSelectionStart; int lastSelectionEnd; diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp index 7ee6eea..681e360 100644 --- a/src/declarative/fx/qfxvisualitemmodel.cpp +++ b/src/declarative/fx/qfxvisualitemmodel.cpp @@ -59,14 +59,14 @@ QML_DECLARE_TYPE(QListModelInterface) QT_BEGIN_NAMESPACE -class QFxVisualItemModelAttached : public QObject +class QmlGraphicsVisualItemModelAttached : public QObject { Q_OBJECT public: - QFxVisualItemModelAttached(QObject *parent) + QmlGraphicsVisualItemModelAttached(QObject *parent) : QObject(parent), m_index(0) {} - ~QFxVisualItemModelAttached() { + ~QmlGraphicsVisualItemModelAttached() { attachedProperties.remove(parent()); } @@ -79,10 +79,10 @@ public: } } - static QFxVisualItemModelAttached *properties(QObject *obj) { - QFxVisualItemModelAttached *rv = attachedProperties.value(obj); + static QmlGraphicsVisualItemModelAttached *properties(QObject *obj) { + QmlGraphicsVisualItemModelAttached *rv = attachedProperties.value(obj); if (!rv) { - rv = new QFxVisualItemModelAttached(obj); + rv = new QmlGraphicsVisualItemModelAttached(obj); attachedProperties.insert(obj, rv); } return rv; @@ -94,37 +94,37 @@ Q_SIGNALS: public: int m_index; - static QHash attachedProperties; + static QHash attachedProperties; }; -QHash QFxVisualItemModelAttached::attachedProperties; +QHash QmlGraphicsVisualItemModelAttached::attachedProperties; -class QFxVisualItemModelPrivate : public QObjectPrivate +class QmlGraphicsVisualItemModelPrivate : public QObjectPrivate { - Q_DECLARE_PUBLIC(QFxVisualItemModel) + Q_DECLARE_PUBLIC(QmlGraphicsVisualItemModel) public: - QFxVisualItemModelPrivate() : QObjectPrivate(), children(this) {} + QmlGraphicsVisualItemModelPrivate() : QObjectPrivate(), children(this) {} - struct ItemList : public QmlConcreteList + struct ItemList : public QmlConcreteList { - ItemList(QFxVisualItemModelPrivate *m) : QmlConcreteList(), model(m) {} + ItemList(QmlGraphicsVisualItemModelPrivate *m) : QmlConcreteList(), model(m) {} - void append(QFxItem *item); + void append(QmlGraphicsItem *item); - QFxVisualItemModelPrivate *model; + QmlGraphicsVisualItemModelPrivate *model; }; void itemAppended() { - Q_Q(QFxVisualItemModel); - QFxVisualItemModelAttached *attached = QFxVisualItemModelAttached::properties(children.last()); + Q_Q(QmlGraphicsVisualItemModel); + QmlGraphicsVisualItemModelAttached *attached = QmlGraphicsVisualItemModelAttached::properties(children.last()); attached->setIndex(children.count()-1); emit q->itemsInserted(children.count()-1, 1); emit q->countChanged(); } void emitChildrenChanged() { - Q_Q(QFxVisualItemModel); + Q_Q(QmlGraphicsVisualItemModel); emit q->childrenChanged(); } ItemList children; @@ -132,7 +132,7 @@ public: /*! - \qmlclass VisualItemModel QFxVisualItemModel + \qmlclass VisualItemModel QmlGraphicsVisualItemModel \brief The VisualItemModel allows items to be provided to a view. The children of the VisualItemModel are provided in a model which @@ -160,14 +160,14 @@ public: } \endcode */ -QFxVisualItemModel::QFxVisualItemModel() - : QFxVisualModel(*(new QFxVisualItemModelPrivate)) +QmlGraphicsVisualItemModel::QmlGraphicsVisualItemModel() + : QmlGraphicsVisualModel(*(new QmlGraphicsVisualItemModelPrivate)) { } -QmlList *QFxVisualItemModel::children() +QmlList *QmlGraphicsVisualItemModel::children() { - Q_D(QFxVisualItemModel); + Q_D(QmlGraphicsVisualItemModel); return &(d->children); } @@ -176,37 +176,37 @@ QmlList *QFxVisualItemModel::children() The number of items in the model. This property is readonly. */ -int QFxVisualItemModel::count() const +int QmlGraphicsVisualItemModel::count() const { - Q_D(const QFxVisualItemModel); + Q_D(const QmlGraphicsVisualItemModel); return d->children.count(); } -bool QFxVisualItemModel::isValid() const +bool QmlGraphicsVisualItemModel::isValid() const { return true; } -QFxItem *QFxVisualItemModel::item(int index, bool) +QmlGraphicsItem *QmlGraphicsVisualItemModel::item(int index, bool) { - Q_D(QFxVisualItemModel); + Q_D(QmlGraphicsVisualItemModel); return d->children.at(index); } -QFxVisualModel::ReleaseFlags QFxVisualItemModel::release(QFxItem *) +QmlGraphicsVisualModel::ReleaseFlags QmlGraphicsVisualItemModel::release(QmlGraphicsItem *) { // Nothing to do return 0; } -void QFxVisualItemModel::completeItem() +void QmlGraphicsVisualItemModel::completeItem() { // Nothing to do } -QVariant QFxVisualItemModel::evaluate(int index, const QString &expression, QObject *objectContext) +QVariant QmlGraphicsVisualItemModel::evaluate(int index, const QString &expression, QObject *objectContext) { - Q_D(QFxVisualItemModel); + Q_D(QmlGraphicsVisualItemModel); QmlContext *ccontext = qmlContext(this); QmlContext *ctxt = new QmlContext(ccontext); ctxt->addDefaultObject(d->children.at(index)); @@ -217,41 +217,41 @@ QVariant QFxVisualItemModel::evaluate(int index, const QString &expression, QObj return value; } -int QFxVisualItemModel::indexOf(QFxItem *item, QObject *) const +int QmlGraphicsVisualItemModel::indexOf(QmlGraphicsItem *item, QObject *) const { - Q_D(const QFxVisualItemModel); + Q_D(const QmlGraphicsVisualItemModel); return d->children.indexOf(item); } -void QFxVisualItemModelPrivate::ItemList::append(QFxItem *item) +void QmlGraphicsVisualItemModelPrivate::ItemList::append(QmlGraphicsItem *item) { - QmlConcreteList::append(item); + QmlConcreteList::append(item); item->QObject::setParent(model->q_ptr); model->itemAppended(); model->emitChildrenChanged(); } -QFxVisualItemModelAttached *QFxVisualItemModel::qmlAttachedProperties(QObject *obj) +QmlGraphicsVisualItemModelAttached *QmlGraphicsVisualItemModel::qmlAttachedProperties(QObject *obj) { - return QFxVisualItemModelAttached::properties(obj); + return QmlGraphicsVisualItemModelAttached::properties(obj); } -class QFxVisualDataModelParts; -class QFxVisualDataModelData; -class QFxVisualDataModelPrivate : public QObjectPrivate +class QmlGraphicsVisualDataModelParts; +class QmlGraphicsVisualDataModelData; +class QmlGraphicsVisualDataModelPrivate : public QObjectPrivate { public: - QFxVisualDataModelPrivate(QmlContext *); + QmlGraphicsVisualDataModelPrivate(QmlContext *); - static QFxVisualDataModelPrivate *get(QFxVisualDataModel *m) { - return static_cast(QObjectPrivate::get(m)); + static QmlGraphicsVisualDataModelPrivate *get(QmlGraphicsVisualDataModel *m) { + return static_cast(QObjectPrivate::get(m)); } QGuard m_listModelInterface; QGuard m_abstractItemModel; - QGuard m_visualItemModel; + QGuard m_visualItemModel; QString m_part; QmlComponent *m_delegate; @@ -334,10 +334,10 @@ public: Cache m_cache; QHash m_packaged; - QFxVisualDataModelParts *m_parts; - friend class QFxVisualItemParts; + QmlGraphicsVisualDataModelParts *m_parts; + friend class QmlGraphicsVisualItemParts; - QFxVisualDataModelData *data(QObject *item); + QmlGraphicsVisualDataModelData *data(QObject *item); QVariant m_modelVariant; QmlListAccessor *m_listAccessor; @@ -355,26 +355,26 @@ public: } }; -class QFxVisualDataModelDataMetaObject : public QmlOpenMetaObject +class QmlGraphicsVisualDataModelDataMetaObject : public QmlOpenMetaObject { public: - QFxVisualDataModelDataMetaObject(QObject *parent) + QmlGraphicsVisualDataModelDataMetaObject(QObject *parent) : QmlOpenMetaObject(parent) {} virtual QVariant propertyCreated(int, QMetaPropertyBuilder &); virtual int createProperty(const char *, const char *); private: - friend class QFxVisualDataModelData; + friend class QmlGraphicsVisualDataModelData; QList roles; }; -class QFxVisualDataModelData : public QObject +class QmlGraphicsVisualDataModelData : public QObject { Q_OBJECT public: - QFxVisualDataModelData(int index, QFxVisualDataModel *model); - ~QFxVisualDataModelData(); + QmlGraphicsVisualDataModelData(int index, QmlGraphicsVisualDataModel *model); + ~QmlGraphicsVisualDataModelData(); Q_PROPERTY(int index READ index NOTIFY indexChanged) int index() const; @@ -388,37 +388,37 @@ Q_SIGNALS: void indexChanged(); private: - friend class QFxVisualDataModelDataMetaObject; + friend class QmlGraphicsVisualDataModelDataMetaObject; int m_index; - QGuard m_model; - QFxVisualDataModelDataMetaObject *m_meta; + QGuard m_model; + QmlGraphicsVisualDataModelDataMetaObject *m_meta; }; -int QFxVisualDataModelData::count() const +int QmlGraphicsVisualDataModelData::count() const { return m_meta->count(); } -int QFxVisualDataModelData::role(int id) const +int QmlGraphicsVisualDataModelData::role(int id) const { Q_ASSERT(id >= 0 && id < count()); return m_meta->roles.at(id); } -void QFxVisualDataModelData::setValue(int id, const QVariant &val) +void QmlGraphicsVisualDataModelData::setValue(int id, const QVariant &val) { m_meta->setValue(id, val); } -int QFxVisualDataModelDataMetaObject::createProperty(const char *name, const char *type) +int QmlGraphicsVisualDataModelDataMetaObject::createProperty(const char *name, const char *type) { - QFxVisualDataModelData *data = - static_cast(object()); + QmlGraphicsVisualDataModelData *data = + static_cast(object()); if (!data->m_model) return -1; - QFxVisualDataModelPrivate *model = QFxVisualDataModelPrivate::get(data->m_model); + QmlGraphicsVisualDataModelPrivate *model = QmlGraphicsVisualDataModelPrivate::get(data->m_model); if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) { model->ensureRoles(); @@ -439,15 +439,15 @@ int QFxVisualDataModelDataMetaObject::createProperty(const char *name, const cha } QVariant -QFxVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuilder &prop) +QmlGraphicsVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuilder &prop) { prop.setWritable(false); - QFxVisualDataModelData *data = - static_cast(object()); + QmlGraphicsVisualDataModelData *data = + static_cast(object()); Q_ASSERT(data->m_model); - QFxVisualDataModelPrivate *model = QFxVisualDataModelPrivate::get(data->m_model); + QmlGraphicsVisualDataModelPrivate *model = QmlGraphicsVisualDataModelPrivate::get(data->m_model); QString name = QString::fromUtf8(prop.name()); if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) { @@ -493,109 +493,109 @@ QFxVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuilder &pro return QVariant(); } -QFxVisualDataModelData::QFxVisualDataModelData(int index, - QFxVisualDataModel *model) +QmlGraphicsVisualDataModelData::QmlGraphicsVisualDataModelData(int index, + QmlGraphicsVisualDataModel *model) : m_index(index), m_model(model), - m_meta(new QFxVisualDataModelDataMetaObject(this)) + m_meta(new QmlGraphicsVisualDataModelDataMetaObject(this)) { } -QFxVisualDataModelData::~QFxVisualDataModelData() +QmlGraphicsVisualDataModelData::~QmlGraphicsVisualDataModelData() { } -int QFxVisualDataModelData::index() const +int QmlGraphicsVisualDataModelData::index() const { return m_index; } // This is internal only - it should not be set from qml -void QFxVisualDataModelData::setIndex(int index) +void QmlGraphicsVisualDataModelData::setIndex(int index) { m_index = index; emit indexChanged(); } -class QFxVisualDataModelPartsMetaObject : public QmlOpenMetaObject +class QmlGraphicsVisualDataModelPartsMetaObject : public QmlOpenMetaObject { public: - QFxVisualDataModelPartsMetaObject(QObject *parent) + QmlGraphicsVisualDataModelPartsMetaObject(QObject *parent) : QmlOpenMetaObject(parent) {} virtual QVariant propertyCreated(int, QMetaPropertyBuilder &); }; -class QFxVisualDataModelParts : public QObject +class QmlGraphicsVisualDataModelParts : public QObject { Q_OBJECT public: - QFxVisualDataModelParts(QFxVisualDataModel *parent); + QmlGraphicsVisualDataModelParts(QmlGraphicsVisualDataModel *parent); private: - friend class QFxVisualDataModelPartsMetaObject; - QFxVisualDataModel *model; + friend class QmlGraphicsVisualDataModelPartsMetaObject; + QmlGraphicsVisualDataModel *model; }; QVariant -QFxVisualDataModelPartsMetaObject::propertyCreated(int, QMetaPropertyBuilder &prop) +QmlGraphicsVisualDataModelPartsMetaObject::propertyCreated(int, QMetaPropertyBuilder &prop) { prop.setWritable(false); - QFxVisualDataModel *m = new QFxVisualDataModel; + QmlGraphicsVisualDataModel *m = new QmlGraphicsVisualDataModel; m->setParent(object()); m->setPart(QString::fromUtf8(prop.name())); - m->setModel(QVariant::fromValue(static_cast(object())->model)); + m->setModel(QVariant::fromValue(static_cast(object())->model)); QVariant var = QVariant::fromValue((QObject *)m); return var; } -QFxVisualDataModelParts::QFxVisualDataModelParts(QFxVisualDataModel *parent) +QmlGraphicsVisualDataModelParts::QmlGraphicsVisualDataModelParts(QmlGraphicsVisualDataModel *parent) : QObject(parent), model(parent) { - new QFxVisualDataModelPartsMetaObject(this); + new QmlGraphicsVisualDataModelPartsMetaObject(this); } -QFxVisualDataModelPrivate::QFxVisualDataModelPrivate(QmlContext *ctxt) +QmlGraphicsVisualDataModelPrivate::QmlGraphicsVisualDataModelPrivate(QmlContext *ctxt) : m_listModelInterface(0), m_abstractItemModel(0), m_visualItemModel(0), m_delegate(0) , m_context(ctxt), m_parts(0), m_listAccessor(0) { } -QFxVisualDataModelData *QFxVisualDataModelPrivate::data(QObject *item) +QmlGraphicsVisualDataModelData *QmlGraphicsVisualDataModelPrivate::data(QObject *item) { - QFxVisualDataModelData *dataItem = - item->findChild(); + QmlGraphicsVisualDataModelData *dataItem = + item->findChild(); Q_ASSERT(dataItem); return dataItem; } -QFxVisualDataModel::QFxVisualDataModel() -: QFxVisualModel(*(new QFxVisualDataModelPrivate(0))) +QmlGraphicsVisualDataModel::QmlGraphicsVisualDataModel() +: QmlGraphicsVisualModel(*(new QmlGraphicsVisualDataModelPrivate(0))) { } -QFxVisualDataModel::QFxVisualDataModel(QmlContext *ctxt) -: QFxVisualModel(*(new QFxVisualDataModelPrivate(ctxt))) +QmlGraphicsVisualDataModel::QmlGraphicsVisualDataModel(QmlContext *ctxt) +: QmlGraphicsVisualModel(*(new QmlGraphicsVisualDataModelPrivate(ctxt))) { } -QFxVisualDataModel::~QFxVisualDataModel() +QmlGraphicsVisualDataModel::~QmlGraphicsVisualDataModel() { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); if (d->m_listAccessor) delete d->m_listAccessor; } -QVariant QFxVisualDataModel::model() const +QVariant QmlGraphicsVisualDataModel::model() const { - Q_D(const QFxVisualDataModel); + Q_D(const QmlGraphicsVisualDataModel); return d->m_modelVariant; } -void QFxVisualDataModel::setModel(const QVariant &model) +void QmlGraphicsVisualDataModel::setModel(const QVariant &model) { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); delete d->m_listAccessor; d->m_listAccessor = 0; d->m_modelVariant = model; @@ -656,7 +656,7 @@ void QFxVisualDataModel::setModel(const QVariant &model) this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); return; } - if ((d->m_visualItemModel = qvariant_cast(model))) { + if ((d->m_visualItemModel = qvariant_cast(model))) { QObject::connect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), this, SIGNAL(itemsInserted(int,int))); QObject::connect(d->m_visualItemModel, SIGNAL(itemsRemoved(int,int)), @@ -677,17 +677,17 @@ void QFxVisualDataModel::setModel(const QVariant &model) } } -QmlComponent *QFxVisualDataModel::delegate() const +QmlComponent *QmlGraphicsVisualDataModel::delegate() const { - Q_D(const QFxVisualDataModel); + Q_D(const QmlGraphicsVisualDataModel); if (d->m_visualItemModel) return d->m_visualItemModel->delegate(); return d->m_delegate; } -void QFxVisualDataModel::setDelegate(QmlComponent *delegate) +void QmlGraphicsVisualDataModel::setDelegate(QmlComponent *delegate) { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); d->m_delegate = delegate; if (d->modelCount()) { emit itemsInserted(0, d->modelCount()); @@ -695,27 +695,27 @@ void QFxVisualDataModel::setDelegate(QmlComponent *delegate) } } -QString QFxVisualDataModel::part() const +QString QmlGraphicsVisualDataModel::part() const { - Q_D(const QFxVisualDataModel); + Q_D(const QmlGraphicsVisualDataModel); return d->m_part; } -void QFxVisualDataModel::setPart(const QString &part) +void QmlGraphicsVisualDataModel::setPart(const QString &part) { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); d->m_part = part; } -int QFxVisualDataModel::count() const +int QmlGraphicsVisualDataModel::count() const { - Q_D(const QFxVisualDataModel); + Q_D(const QmlGraphicsVisualDataModel); return d->modelCount(); } -QFxItem *QFxVisualDataModel::item(int index, bool complete) +QmlGraphicsItem *QmlGraphicsVisualDataModel::item(int index, bool complete) { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); if (d->m_visualItemModel) return d->m_visualItemModel->item(index, d->m_part.toUtf8(), complete); return item(index, QByteArray(), complete); @@ -724,9 +724,9 @@ QFxItem *QFxVisualDataModel::item(int index, bool complete) /* Returns ReleaseStatus flags. */ -QFxVisualDataModel::ReleaseFlags QFxVisualDataModel::release(QFxItem *item) +QmlGraphicsVisualDataModel::ReleaseFlags QmlGraphicsVisualDataModel::release(QmlGraphicsItem *item) { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); if (d->m_visualItemModel) return d->m_visualItemModel->release(item); @@ -757,17 +757,17 @@ QFxVisualDataModel::ReleaseFlags QFxVisualDataModel::release(QFxItem *item) return stat; } -QObject *QFxVisualDataModel::parts() +QObject *QmlGraphicsVisualDataModel::parts() { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); if (!d->m_parts) - d->m_parts = new QFxVisualDataModelParts(this); + d->m_parts = new QmlGraphicsVisualDataModelParts(this); return d->m_parts; } -QFxItem *QFxVisualDataModel::item(int index, const QByteArray &viewId, bool complete) +QmlGraphicsItem *QmlGraphicsVisualDataModel::item(int index, const QByteArray &viewId, bool complete) { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); if (d->m_visualItemModel) return d->m_visualItemModel->item(index, viewId, complete); @@ -779,7 +779,7 @@ QFxItem *QFxVisualDataModel::item(int index, const QByteArray &viewId, bool comp QmlContext *ccontext = d->m_context; if (!ccontext) ccontext = qmlContext(this); QmlContext *ctxt = new QmlContext(ccontext); - QFxVisualDataModelData *data = new QFxVisualDataModelData(index, this); + QmlGraphicsVisualDataModelData *data = new QmlGraphicsVisualDataModelData(index, this); ctxt->setContextProperty(QLatin1String("model"), data); ctxt->addDefaultObject(data); nobj = d->m_delegate->beginCreate(ctxt); @@ -797,27 +797,27 @@ QFxItem *QFxVisualDataModel::item(int index, const QByteArray &viewId, bool comp qWarning() << d->m_delegate->errors(); } } - QFxItem *item = qobject_cast(nobj); + QmlGraphicsItem *item = qobject_cast(nobj); if (!item) { QmlPackage *package = qobject_cast(nobj); if (package) { QObject *o = package->part(QString::fromUtf8(viewId)); - item = qobject_cast(o); + item = qobject_cast(o); if (item) d->m_packaged.insertMulti(item, package); } } if (!item) { d->m_cache.releaseItem(nobj); - qmlInfo(QFxVisualDataModel::tr("Delegate component must be Item type."), d->m_delegate); + qmlInfo(QmlGraphicsVisualDataModel::tr("Delegate component must be Item type."), d->m_delegate); } return item; } -void QFxVisualDataModel::completeItem() +void QmlGraphicsVisualDataModel::completeItem() { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); if (d->m_visualItemModel) { d->m_visualItemModel->completeItem(); return; @@ -826,9 +826,9 @@ void QFxVisualDataModel::completeItem() d->m_delegate->completeCreate(); } -QVariant QFxVisualDataModel::evaluate(int index, const QString &expression, QObject *objectContext) +QVariant QmlGraphicsVisualDataModel::evaluate(int index, const QString &expression, QObject *objectContext) { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); if (d->m_visualItemModel) return d->m_visualItemModel->evaluate(index, expression, objectContext); @@ -838,7 +838,7 @@ QVariant QFxVisualDataModel::evaluate(int index, const QString &expression, QObj QVariant value; QObject *nobj = d->m_cache.item(index); if (nobj) { - QFxItem *item = qobject_cast(nobj); + QmlGraphicsItem *item = qobject_cast(nobj); if (item) { QmlExpression e(qmlContext(item), expression, objectContext); e.setTrackChange(false); @@ -848,7 +848,7 @@ QVariant QFxVisualDataModel::evaluate(int index, const QString &expression, QObj QmlContext *ccontext = d->m_context; if (!ccontext) ccontext = qmlContext(this); QmlContext *ctxt = new QmlContext(ccontext); - QFxVisualDataModelData *data = new QFxVisualDataModelData(index, this); + QmlGraphicsVisualDataModelData *data = new QmlGraphicsVisualDataModelData(index, this); ctxt->addDefaultObject(data); QmlExpression e(ctxt, expression, objectContext); e.setTrackChange(false); @@ -860,7 +860,7 @@ QVariant QFxVisualDataModel::evaluate(int index, const QString &expression, QObj return value; } -int QFxVisualDataModel::indexOf(QFxItem *item, QObject *objectContext) const +int QmlGraphicsVisualDataModel::indexOf(QmlGraphicsItem *item, QObject *objectContext) const { QmlExpression e(qmlContext(item), QLatin1String("index"), objectContext); e.setTrackChange(false); @@ -870,15 +870,15 @@ int QFxVisualDataModel::indexOf(QFxItem *item, QObject *objectContext) const return -1; } -void QFxVisualDataModel::_q_itemsChanged(int index, int count, +void QmlGraphicsVisualDataModel::_q_itemsChanged(int index, int count, const QList &roles) { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); // XXX - highly inefficient for (int ii = index; ii < index + count; ++ii) { if (QObject *item = d->m_cache.item(ii)) { - QFxVisualDataModelData *data = d->data(item); + QmlGraphicsVisualDataModelData *data = d->data(item); for (int prop = 0; prop < data->count(); ++prop) { @@ -897,22 +897,22 @@ void QFxVisualDataModel::_q_itemsChanged(int index, int count, } } -void QFxVisualDataModel::_q_itemsInserted(int index, int count) +void QmlGraphicsVisualDataModel::_q_itemsInserted(int index, int count) { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); // XXX - highly inefficient - QHash items; - for (QHash::Iterator iter = d->m_cache.begin(); + QHash items; + for (QHash::Iterator iter = d->m_cache.begin(); iter != d->m_cache.end(); ) { if (iter.key() >= index) { - QFxVisualDataModelPrivate::ObjectRef objRef = *iter; + QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; int index = iter.key() + count; iter = d->m_cache.erase(iter); items.insert(index, objRef); - QFxVisualDataModelData *data = d->data(objRef.obj); + QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); data->setIndex(index); } else { ++iter; @@ -924,25 +924,25 @@ void QFxVisualDataModel::_q_itemsInserted(int index, int count) emit countChanged(); } -void QFxVisualDataModel::_q_itemsRemoved(int index, int count) +void QmlGraphicsVisualDataModel::_q_itemsRemoved(int index, int count) { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); // XXX - highly inefficient - QHash items; - for (QHash::Iterator iter = d->m_cache.begin(); + QHash items; + for (QHash::Iterator iter = d->m_cache.begin(); iter != d->m_cache.end(); ) { if (iter.key() >= index && iter.key() < index + count) { - QFxVisualDataModelPrivate::ObjectRef objRef = *iter; + QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; iter = d->m_cache.erase(iter); items.insertMulti(-1, objRef); //XXX perhaps better to maintain separately - QFxVisualDataModelData *data = d->data(objRef.obj); + QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); data->setIndex(-1); } else if (iter.key() >= index + count) { - QFxVisualDataModelPrivate::ObjectRef objRef = *iter; + QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; int index = iter.key() - count; iter = d->m_cache.erase(iter); items.insert(index, objRef); - QFxVisualDataModelData *data = d->data(objRef.obj); + QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); data->setIndex(index); } else { ++iter; @@ -954,38 +954,38 @@ void QFxVisualDataModel::_q_itemsRemoved(int index, int count) emit countChanged(); } -void QFxVisualDataModel::_q_itemsMoved(int from, int to, int count) +void QmlGraphicsVisualDataModel::_q_itemsMoved(int from, int to, int count) { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); // XXX - highly inefficient - QHash items; - for (QHash::Iterator iter = d->m_cache.begin(); + QHash items; + for (QHash::Iterator iter = d->m_cache.begin(); iter != d->m_cache.end(); ) { if (iter.key() >= from && iter.key() < from + count) { - QFxVisualDataModelPrivate::ObjectRef objRef = *iter; + QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; int index = iter.key() - from + to; iter = d->m_cache.erase(iter); items.insert(index, objRef); - QFxVisualDataModelData *data = d->data(objRef.obj); + QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); data->setIndex(index); } else { ++iter; } } - for (QHash::Iterator iter = d->m_cache.begin(); + for (QHash::Iterator iter = d->m_cache.begin(); iter != d->m_cache.end(); ) { if (iter.key() >= qMin(from,to) && iter.key() < qMax(from+count,to+count)) { - QFxVisualDataModelPrivate::ObjectRef objRef = *iter; + QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; int index = iter.key() + from - to; iter = d->m_cache.erase(iter); items.insert(index, objRef); - QFxVisualDataModelData *data = d->data(objRef.obj); + QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); data->setIndex(index); } else { ++iter; @@ -996,37 +996,37 @@ void QFxVisualDataModel::_q_itemsMoved(int from, int to, int count) emit itemsMoved(from, to, count); } -void QFxVisualDataModel::_q_rowsInserted(const QModelIndex &, int begin, int end) +void QmlGraphicsVisualDataModel::_q_rowsInserted(const QModelIndex &, int begin, int end) { _q_itemsInserted(begin, end - begin + 1); } -void QFxVisualDataModel::_q_rowsRemoved(const QModelIndex &, int begin, int end) +void QmlGraphicsVisualDataModel::_q_rowsRemoved(const QModelIndex &, int begin, int end) { _q_itemsRemoved(begin, end - begin + 1); } -void QFxVisualDataModel::_q_dataChanged(const QModelIndex &begin, const QModelIndex &end) +void QmlGraphicsVisualDataModel::_q_dataChanged(const QModelIndex &begin, const QModelIndex &end) { - Q_D(QFxVisualDataModel); + Q_D(QmlGraphicsVisualDataModel); _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); } -void QFxVisualDataModel::_q_createdPackage(int index, QmlPackage *package) +void QmlGraphicsVisualDataModel::_q_createdPackage(int index, QmlPackage *package) { - Q_D(QFxVisualDataModel); - emit createdItem(index, qobject_cast(package->part(d->m_part))); + Q_D(QmlGraphicsVisualDataModel); + emit createdItem(index, qobject_cast(package->part(d->m_part))); } -void QFxVisualDataModel::_q_destroyingPackage(QmlPackage *package) +void QmlGraphicsVisualDataModel::_q_destroyingPackage(QmlPackage *package) { - Q_D(QFxVisualDataModel); - emit destroyingItem(qobject_cast(package->part(d->m_part))); + Q_D(QmlGraphicsVisualDataModel); + emit destroyingItem(qobject_cast(package->part(d->m_part))); } -QML_DEFINE_NOCREATE_TYPE(QFxVisualModel); -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisualItemModel,QFxVisualItemModel) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisualDataModel,QFxVisualDataModel) +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsVisualModel); +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisualItemModel,QmlGraphicsVisualItemModel) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisualDataModel,QmlGraphicsVisualDataModel) QT_END_NAMESPACE #include "qfxvisualitemmodel.moc" diff --git a/src/declarative/fx/qfxvisualitemmodel.h b/src/declarative/fx/qfxvisualitemmodel.h index 8e33279..7f7a13f 100644 --- a/src/declarative/fx/qfxvisualitemmodel.h +++ b/src/declarative/fx/qfxvisualitemmodel.h @@ -58,88 +58,88 @@ QT_MODULE(Declarative) ***************************************************************************** *****************************************************************************/ -class QFxItem; +class QmlGraphicsItem; class QmlComponent; class QmlPackage; -class QFxVisualDataModelPrivate; +class QmlGraphicsVisualDataModelPrivate; -class Q_DECLARATIVE_EXPORT QFxVisualModel : public QObject +class Q_DECLARATIVE_EXPORT QmlGraphicsVisualModel : public QObject { Q_OBJECT Q_PROPERTY(int count READ count NOTIFY countChanged) public: - QFxVisualModel() {} - virtual ~QFxVisualModel() {} + QmlGraphicsVisualModel() {} + virtual ~QmlGraphicsVisualModel() {} enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 }; Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag) virtual int count() const = 0; virtual bool isValid() const = 0; - virtual QFxItem *item(int index, bool complete=true) = 0; - virtual ReleaseFlags release(QFxItem *item) = 0; + virtual QmlGraphicsItem *item(int index, bool complete=true) = 0; + virtual ReleaseFlags release(QmlGraphicsItem *item) = 0; virtual void completeItem() = 0; virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext) = 0; - virtual int indexOf(QFxItem *item, QObject *objectContext) const = 0; + virtual int indexOf(QmlGraphicsItem *item, QObject *objectContext) const = 0; Q_SIGNALS: void countChanged(); void itemsInserted(int index, int count); void itemsRemoved(int index, int count); void itemsMoved(int from, int to, int count); - void createdItem(int index, QFxItem *item); - void destroyingItem(QFxItem *item); + void createdItem(int index, QmlGraphicsItem *item); + void destroyingItem(QmlGraphicsItem *item); protected: - QFxVisualModel(QObjectPrivate &dd, QObject *parent = 0) + QmlGraphicsVisualModel(QObjectPrivate &dd, QObject *parent = 0) : QObject(dd, parent) {} private: - Q_DISABLE_COPY(QFxVisualModel) + Q_DISABLE_COPY(QmlGraphicsVisualModel) }; -class QFxVisualItemModelAttached; -class QFxVisualItemModelPrivate; -class Q_DECLARATIVE_EXPORT QFxVisualItemModel : public QFxVisualModel +class QmlGraphicsVisualItemModelAttached; +class QmlGraphicsVisualItemModelPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsVisualItemModel : public QmlGraphicsVisualModel { Q_OBJECT - Q_DECLARE_PRIVATE(QFxVisualItemModel) + Q_DECLARE_PRIVATE(QmlGraphicsVisualItemModel) - Q_PROPERTY(QmlList* children READ children NOTIFY childrenChanged DESIGNABLE false) + Q_PROPERTY(QmlList* children READ children NOTIFY childrenChanged DESIGNABLE false) Q_CLASSINFO("DefaultProperty", "children") public: - QFxVisualItemModel(); - virtual ~QFxVisualItemModel() {} + QmlGraphicsVisualItemModel(); + virtual ~QmlGraphicsVisualItemModel() {} virtual int count() const; virtual bool isValid() const; - virtual QFxItem *item(int index, bool complete=true); - virtual ReleaseFlags release(QFxItem *item); + virtual QmlGraphicsItem *item(int index, bool complete=true); + virtual ReleaseFlags release(QmlGraphicsItem *item); virtual void completeItem(); virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext); - virtual int indexOf(QFxItem *item, QObject *objectContext) const; + virtual int indexOf(QmlGraphicsItem *item, QObject *objectContext) const; - QmlList *children(); + QmlList *children(); - static QFxVisualItemModelAttached *qmlAttachedProperties(QObject *obj); + static QmlGraphicsVisualItemModelAttached *qmlAttachedProperties(QObject *obj); signals: void childrenChanged(); private: - Q_DISABLE_COPY(QFxVisualItemModel) + Q_DISABLE_COPY(QmlGraphicsVisualItemModel) }; -class Q_DECLARATIVE_EXPORT QFxVisualDataModel : public QFxVisualModel +class Q_DECLARATIVE_EXPORT QmlGraphicsVisualDataModel : public QmlGraphicsVisualModel { Q_OBJECT - Q_DECLARE_PRIVATE(QFxVisualDataModel) + Q_DECLARE_PRIVATE(QmlGraphicsVisualDataModel) Q_PROPERTY(QVariant model READ model WRITE setModel) Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) @@ -147,9 +147,9 @@ class Q_DECLARATIVE_EXPORT QFxVisualDataModel : public QFxVisualModel Q_PROPERTY(QObject *parts READ parts CONSTANT) Q_CLASSINFO("DefaultProperty", "delegate") public: - QFxVisualDataModel(); - QFxVisualDataModel(QmlContext *); - virtual ~QFxVisualDataModel(); + QmlGraphicsVisualDataModel(); + QmlGraphicsVisualDataModel(QmlContext *); + virtual ~QmlGraphicsVisualDataModel(); QVariant model() const; void setModel(const QVariant &); @@ -162,13 +162,13 @@ public: int count() const; bool isValid() const { return delegate() != 0; } - QFxItem *item(int index, bool complete=true); - QFxItem *item(int index, const QByteArray &, bool complete=true); - ReleaseFlags release(QFxItem *item); + QmlGraphicsItem *item(int index, bool complete=true); + QmlGraphicsItem *item(int index, const QByteArray &, bool complete=true); + ReleaseFlags release(QmlGraphicsItem *item); void completeItem(); QVariant evaluate(int index, const QString &expression, QObject *objectContext); - int indexOf(QFxItem *item, QObject *objectContext) const; + int indexOf(QmlGraphicsItem *item, QObject *objectContext) const; QObject *parts(); @@ -188,15 +188,15 @@ private Q_SLOTS: void _q_destroyingPackage(QmlPackage *package); private: - Q_DISABLE_COPY(QFxVisualDataModel) + Q_DISABLE_COPY(QmlGraphicsVisualDataModel) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxVisualModel) -QML_DECLARE_TYPE(QFxVisualItemModel) -QML_DECLARE_TYPEINFO(QFxVisualItemModel, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QFxVisualDataModel) +QML_DECLARE_TYPE(QmlGraphicsVisualModel) +QML_DECLARE_TYPE(QmlGraphicsVisualItemModel) +QML_DECLARE_TYPEINFO(QmlGraphicsVisualItemModel, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QmlGraphicsVisualDataModel) QT_END_HEADER diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp index f7030ca..e6f0a1d 100644 --- a/src/declarative/fx/qfxwebview.cpp +++ b/src/declarative/fx/qfxwebview.cpp @@ -62,12 +62,12 @@ #include QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,WebView,QFxWebView) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,WebView,QmlGraphicsWebView) QML_DEFINE_NOCREATE_TYPE(QAction) static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system -class QFxWebSettings : public QObject { +class QmlGraphicsWebSettings : public QObject { Q_OBJECT Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily) @@ -99,7 +99,7 @@ class QFxWebSettings : public QObject { Q_PROPERTY(bool localContentCanAccessRemoteUrls READ localContentCanAccessRemoteUrls WRITE setLocalContentCanAccessRemoteUrls) public: - QFxWebSettings() {} + QmlGraphicsWebSettings() {} QString standardFontFamily() const { return s->fontFamily(QWebSettings::StandardFont); } void setStandardFontFamily(const QString& f) { s->setFontFamily(QWebSettings::StandardFont,f); } @@ -157,17 +157,17 @@ public: QWebSettings *s; }; -QML_DECLARE_TYPE(QFxWebSettings) -QML_DEFINE_NOCREATE_TYPE(QFxWebSettings) +QML_DECLARE_TYPE(QmlGraphicsWebSettings) +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsWebSettings) -class QFxWebViewPrivate : public QFxPaintedItemPrivate +class QmlGraphicsWebViewPrivate : public QmlGraphicsPaintedItemPrivate { - Q_DECLARE_PUBLIC(QFxWebView) + Q_DECLARE_PUBLIC(QmlGraphicsWebView) public: - QFxWebViewPrivate() - : QFxPaintedItemPrivate(), page(0), preferredwidth(0), pagewidth(0), - progress(1.0), status(QFxWebView::Null), pending(PendingNone), + QmlGraphicsWebViewPrivate() + : QmlGraphicsPaintedItemPrivate(), page(0), preferredwidth(0), pagewidth(0), + progress(1.0), status(QmlGraphicsWebView::Null), pending(PendingNone), newWindowComponent(0), newWindowParent(0), windowObjects(this), rendering(true) @@ -180,28 +180,28 @@ public: int preferredwidth; int pagewidth; qreal progress; - QFxWebView::Status status; + QmlGraphicsWebView::Status status; QString statusText; enum { PendingNone, PendingUrl, PendingHtml, PendingContent } pending; QUrl pending_url; QString pending_string; QByteArray pending_data; - mutable QFxWebSettings settings; + mutable QmlGraphicsWebSettings settings; QmlComponent *newWindowComponent; - QFxItem *newWindowParent; + QmlGraphicsItem *newWindowParent; void updateWindowObjects(); class WindowObjectList : public QmlConcreteList { public: - WindowObjectList(QFxWebViewPrivate *p) + WindowObjectList(QmlGraphicsWebViewPrivate *p) : priv(p) {} virtual void append(QObject *v) { QmlConcreteList::append(v); priv->updateWindowObjects(); } private: - QFxWebViewPrivate *priv; + QmlGraphicsWebViewPrivate *priv; } windowObjects; bool rendering; @@ -240,8 +240,8 @@ public: /*! \internal - \class QFxWebView - \brief The QFxWebView class allows you to add web content to a QmlView. + \class QmlGraphicsWebView + \brief The QmlGraphicsWebView class allows you to add web content to a QmlView. A WebView renders web content base on a URL. @@ -251,30 +251,30 @@ public: toolbars, etc., those must be implemented around WebView. See the WebBrowser example for a demonstration of this. - A QFxWebView object can be instantiated in Qml using the tag \l WebView. + A QmlGraphicsWebView object can be instantiated in Qml using the tag \l WebView. */ -QFxWebView::QFxWebView(QFxItem *parent) - : QFxPaintedItem(*(new QFxWebViewPrivate), parent) +QmlGraphicsWebView::QmlGraphicsWebView(QmlGraphicsItem *parent) + : QmlGraphicsPaintedItem(*(new QmlGraphicsWebViewPrivate), parent) { init(); } -QFxWebView::QFxWebView(QFxWebViewPrivate &dd, QFxItem *parent) - : QFxPaintedItem(dd, parent) +QmlGraphicsWebView::QmlGraphicsWebView(QmlGraphicsWebViewPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsPaintedItem(dd, parent) { init(); } -QFxWebView::~QFxWebView() +QmlGraphicsWebView::~QmlGraphicsWebView() { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); delete d->page; } -void QFxWebView::init() +void QmlGraphicsWebView::init() { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); setAcceptHoverEvents(true); setAcceptedMouseButtons(Qt::LeftButton); @@ -283,30 +283,30 @@ void QFxWebView::init() d->page = 0; } -void QFxWebView::componentComplete() +void QmlGraphicsWebView::componentComplete() { - QFxPaintedItem::componentComplete(); - Q_D(QFxWebView); + QmlGraphicsPaintedItem::componentComplete(); + Q_D(QmlGraphicsWebView); switch (d->pending) { - case QFxWebViewPrivate::PendingUrl: + case QmlGraphicsWebViewPrivate::PendingUrl: setUrl(d->pending_url); break; - case QFxWebViewPrivate::PendingHtml: + case QmlGraphicsWebViewPrivate::PendingHtml: setHtml(d->pending_string, d->pending_url); break; - case QFxWebViewPrivate::PendingContent: + case QmlGraphicsWebViewPrivate::PendingContent: setContent(d->pending_data, d->pending_string, d->pending_url); break; default: break; } - d->pending = QFxWebViewPrivate::PendingNone; + d->pending = QmlGraphicsWebViewPrivate::PendingNone; d->updateWindowObjects(); } -QFxWebView::Status QFxWebView::status() const +QmlGraphicsWebView::Status QmlGraphicsWebView::status() const { - Q_D(const QFxWebView); + Q_D(const QmlGraphicsWebView); return d->status; } @@ -317,15 +317,15 @@ QFxWebView::Status QFxWebView::status() const \sa onLoadFinished() onLoadFailed() */ -qreal QFxWebView::progress() const +qreal QmlGraphicsWebView::progress() const { - Q_D(const QFxWebView); + Q_D(const QmlGraphicsWebView); return d->progress; } -void QFxWebView::doLoadStarted() +void QmlGraphicsWebView::doLoadStarted() { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); if (!d->url.isEmpty()) { d->status = Loading; @@ -334,18 +334,18 @@ void QFxWebView::doLoadStarted() emit loadStarted(); } -void QFxWebView::doLoadProgress(int p) +void QmlGraphicsWebView::doLoadProgress(int p) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); if (d->progress == p/100.0) return; d->progress = p/100.0; emit progressChanged(); } -void QFxWebView::pageUrlChanged() +void QmlGraphicsWebView::pageUrlChanged() { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); // Reset zooming to full qreal zf = 1.0; @@ -371,9 +371,9 @@ void QFxWebView::pageUrlChanged() } } -void QFxWebView::doLoadFinished(bool ok) +void QmlGraphicsWebView::doLoadFinished(bool ok) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); if (title().isEmpty()) pageUrlChanged(); // XXX bug 232556 - pages with no title never get urlChanged() @@ -398,15 +398,15 @@ void QFxWebView::doLoadFinished(bool ok) The url is always absolute (QML will resolve relative URL strings in the context of the containing QML document). */ -QUrl QFxWebView::url() const +QUrl QmlGraphicsWebView::url() const { - Q_D(const QFxWebView); + Q_D(const QmlGraphicsWebView); return d->url; } -void QFxWebView::setUrl(const QUrl &url) +void QmlGraphicsWebView::setUrl(const QUrl &url) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); if (url == d->url) return; @@ -440,15 +440,15 @@ void QFxWebView::setUrl(const QUrl &url) \qmlproperty int WebView::preferredWidth This property holds the ideal width for displaying the current URL. */ -int QFxWebView::preferredWidth() const +int QmlGraphicsWebView::preferredWidth() const { - Q_D(const QFxWebView); + Q_D(const QmlGraphicsWebView); return d->preferredwidth; } -void QFxWebView::setPreferredWidth(int iw) +void QmlGraphicsWebView::setPreferredWidth(int iw) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); if (d->preferredwidth == iw) return; if (d->pagewidth) { if (d->preferredwidth) { @@ -466,15 +466,15 @@ void QFxWebView::setPreferredWidth(int iw) \qmlproperty int WebView::webPageWidth This property holds the page width suggested to the web engine. */ -int QFxWebView::webPageWidth() const +int QmlGraphicsWebView::webPageWidth() const { - Q_D(const QFxWebView); + Q_D(const QmlGraphicsWebView); return d->pagewidth; } -void QFxWebView::setWebPageWidth(int pw) +void QmlGraphicsWebView::setWebPageWidth(int pw) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); if (d->pagewidth == pw) return; d->pagewidth = pw; expandToWebPage(); @@ -484,26 +484,26 @@ void QFxWebView::setWebPageWidth(int pw) Evaluates the \a scriptSource JavaScript inside the main frame context and returns the result of the last executed statement. */ -QVariant QFxWebView::evaluateJavaScript(const QString &scriptSource) +QVariant QmlGraphicsWebView::evaluateJavaScript(const QString &scriptSource) { return this->page()->mainFrame()->evaluateJavaScript(scriptSource); } -void QFxWebView::focusChanged(bool hasFocus) +void QmlGraphicsWebView::focusChanged(bool hasFocus) { QFocusEvent e(hasFocus ? QEvent::FocusIn : QEvent::FocusOut); page()->event(&e); - QFxItem::focusChanged(hasFocus); + QmlGraphicsItem::focusChanged(hasFocus); } -void QFxWebView::contentsSizeChanged(const QSize&) +void QmlGraphicsWebView::contentsSizeChanged(const QSize&) { expandToWebPage(); } -void QFxWebView::expandToWebPage() +void QmlGraphicsWebView::expandToWebPage() { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); QSize cs = page()->mainFrame()->contentsSize(); qreal zoom = zoomFactor(); if (cs.width() < d->preferredwidth*zoom) @@ -520,17 +520,17 @@ void QFxWebView::expandToWebPage() } } -void QFxWebView::geometryChanged(const QRectF &newGeometry, +void QmlGraphicsWebView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { if (newGeometry.size() != oldGeometry.size()) expandToWebPage(); - QFxPaintedItem::geometryChanged(newGeometry, oldGeometry); + QmlGraphicsPaintedItem::geometryChanged(newGeometry, oldGeometry); } -void QFxWebView::paintPage(const QRect& r) +void QmlGraphicsWebView::paintPage(const QRect& r) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); if (d->page->mainFrame()->contentsSize() != contentsSize()) setContentsSize(d->page->mainFrame()->contentsSize()); dirtyCache(r); @@ -544,15 +544,15 @@ void QFxWebView::paintPage(const QRect& r) allow. The default is 0.1 megapixels. The cache will not be larger than the (unscaled) size of the WebView. */ -int QFxWebView::pixelCacheSize() const +int QmlGraphicsWebView::pixelCacheSize() const { - Q_D(const QFxWebView); + Q_D(const QmlGraphicsWebView); return d->max_imagecache_size; } -void QFxWebView::setPixelCacheSize(int pixels) +void QmlGraphicsWebView::setPixelCacheSize(int pixels) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); if (pixels < d->max_imagecache_size) { int cachesize=0; for (int i=0; iimagecache.count(); ++i) { @@ -598,18 +598,18 @@ void QFxWebView::setPixelCacheSize(int pixels) If Javascript is not enabled for this page, then this property does nothing. */ -QmlList *QFxWebView::javaScriptWindowObjects() +QmlList *QmlGraphicsWebView::javaScriptWindowObjects() { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); return &d->windowObjects; } -class QFxWebViewAttached : public QObject +class QmlGraphicsWebViewAttached : public QObject { Q_OBJECT Q_PROPERTY(QString windowObjectName READ windowObjectName WRITE setWindowObjectName) public: - QFxWebViewAttached(QObject *parent) + QmlGraphicsWebViewAttached(QObject *parent) : QObject(parent) { } @@ -628,35 +628,35 @@ private: QString m_windowObjectName; }; -QFxWebViewAttached *QFxWebView::qmlAttachedProperties(QObject *o) +QmlGraphicsWebViewAttached *QmlGraphicsWebView::qmlAttachedProperties(QObject *o) { - return new QFxWebViewAttached(o); + return new QmlGraphicsWebViewAttached(o); } -void QFxWebViewPrivate::updateWindowObjects() +void QmlGraphicsWebViewPrivate::updateWindowObjects() { - Q_Q(QFxWebView); + Q_Q(QmlGraphicsWebView); if (!q->isComponentComplete() || !page) return; for (int ii = 0; ii < windowObjects.count(); ++ii) { QObject *object = windowObjects.at(ii); - QFxWebViewAttached *attached = static_cast(qmlAttachedPropertiesObject(object)); + QmlGraphicsWebViewAttached *attached = static_cast(qmlAttachedPropertiesObject(object)); if (attached && !attached->windowObjectName().isEmpty()) { page->mainFrame()->addToJavaScriptWindowObject(attached->windowObjectName(), object); } } } -bool QFxWebView::renderingEnabled() const +bool QmlGraphicsWebView::renderingEnabled() const { - Q_D(const QFxWebView); + Q_D(const QmlGraphicsWebView); return d->rendering; } -void QFxWebView::setRenderingEnabled(bool enabled) +void QmlGraphicsWebView::setRenderingEnabled(bool enabled) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); if (d->rendering == enabled) return; d->rendering = enabled; @@ -666,9 +666,9 @@ void QFxWebView::setRenderingEnabled(bool enabled) } -void QFxWebView::drawContents(QPainter *p, const QRect &r) +void QmlGraphicsWebView::drawContents(QPainter *p, const QRect &r) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); if (d->rendering) page()->mainFrame()->render(p,r); } @@ -713,16 +713,16 @@ static QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *e) emits this signals. */ -void QFxWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { QMouseEvent *me = sceneMouseEventToMouseEvent(event); emit doubleClick(me->x(),me->y()); delete me; } -void QFxWebView::heuristicZoom(int clickX, int clickY) +void QmlGraphicsWebView::heuristicZoom(int clickX, int clickY) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); qreal ozf = zoomFactor(); QRect showarea = elementAreaAt(clickX, clickY, 1, 1); qreal z = qreal(preferredWidth())*ozf/showarea.width()*.95; @@ -734,7 +734,7 @@ void QFxWebView::heuristicZoom(int clickX, int clickY) emit zooming(z,r.x()+r.width()/2, r.y()+r.height()/2); } -void QFxWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) { setFocus (true); QMouseEvent *me = sceneMouseEventToMouseEvent(event); @@ -753,11 +753,11 @@ void QFxWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) ); delete me; if (!event->isAccepted()) { - QFxPaintedItem::mousePressEvent(event); + QmlGraphicsPaintedItem::mousePressEvent(event); } } -void QFxWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { QMouseEvent *me = sceneMouseEventToMouseEvent(event); page()->event(me); @@ -774,11 +774,11 @@ void QFxWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) ); delete me; if (!event->isAccepted()) { - QFxPaintedItem::mouseReleaseEvent(event); + QmlGraphicsPaintedItem::mouseReleaseEvent(event); } } -void QFxWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void QmlGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { QMouseEvent *me = sceneMouseEventToMouseEvent(event); page()->event(me); @@ -796,10 +796,10 @@ void QFxWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) ); delete me; if (!event->isAccepted()) - QFxPaintedItem::mouseMoveEvent(event); + QmlGraphicsPaintedItem::mouseMoveEvent(event); } -void QFxWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) +void QmlGraphicsWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) { QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event); page()->event(me); @@ -812,24 +812,24 @@ void QFxWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) ); delete me; if (!event->isAccepted()) - QFxPaintedItem::hoverMoveEvent(event); + QmlGraphicsPaintedItem::hoverMoveEvent(event); } -void QFxWebView::keyPressEvent(QKeyEvent* event) +void QmlGraphicsWebView::keyPressEvent(QKeyEvent* event) { page()->event(event); if (!event->isAccepted()) - QFxPaintedItem::keyPressEvent(event); + QmlGraphicsPaintedItem::keyPressEvent(event); } -void QFxWebView::keyReleaseEvent(QKeyEvent* event) +void QmlGraphicsWebView::keyReleaseEvent(QKeyEvent* event) { page()->event(event); if (!event->isAccepted()) - QFxPaintedItem::keyReleaseEvent(event); + QmlGraphicsPaintedItem::keyReleaseEvent(event); } -bool QFxWebView::sceneEvent(QEvent *event) +bool QmlGraphicsWebView::sceneEvent(QEvent *event) { if (event->type() == QEvent::KeyPress) { QKeyEvent *k = static_cast(event); @@ -841,7 +841,7 @@ bool QFxWebView::sceneEvent(QEvent *event) } } } - return QFxPaintedItem::sceneEvent(event); + return QmlGraphicsPaintedItem::sceneEvent(event); } @@ -850,7 +850,7 @@ bool QFxWebView::sceneEvent(QEvent *event) \qmlproperty action WebView::back This property holds the action for causing the previous URL in the history to be displayed. */ -QAction *QFxWebView::backAction() const +QAction *QmlGraphicsWebView::backAction() const { return page()->action(QWebPage::Back); } @@ -859,7 +859,7 @@ QAction *QFxWebView::backAction() const \qmlproperty action WebView::forward This property holds the action for causing the next URL in the history to be displayed. */ -QAction *QFxWebView::forwardAction() const +QAction *QmlGraphicsWebView::forwardAction() const { return page()->action(QWebPage::Forward); } @@ -868,7 +868,7 @@ QAction *QFxWebView::forwardAction() const \qmlproperty action WebView::reload This property holds the action for reloading with the current URL */ -QAction *QFxWebView::reloadAction() const +QAction *QmlGraphicsWebView::reloadAction() const { return page()->action(QWebPage::Reload); } @@ -877,7 +877,7 @@ QAction *QFxWebView::reloadAction() const \qmlproperty action WebView::stop This property holds the action for stopping loading with the current URL */ -QAction *QFxWebView::stopAction() const +QAction *QmlGraphicsWebView::stopAction() const { return page()->action(QWebPage::Stop); } @@ -888,7 +888,7 @@ QAction *QFxWebView::stopAction() const By default, this property contains an empty string. */ -QString QFxWebView::title() const +QString QmlGraphicsWebView::title() const { return page()->mainFrame()->title(); } @@ -899,7 +899,7 @@ QString QFxWebView::title() const \qmlproperty pixmap WebView::icon This property holds the icon associated with the web page currently viewed */ -QPixmap QFxWebView::icon() const +QPixmap QmlGraphicsWebView::icon() const { return page()->mainFrame()->icon().pixmap(QSize(256,256)); } @@ -909,12 +909,12 @@ QPixmap QFxWebView::icon() const \qmlproperty real WebView::textSizeMultiplier This property holds the multiplier used to scale the text in a Web page */ -void QFxWebView::setTextSizeMultiplier(qreal factor) +void QmlGraphicsWebView::setTextSizeMultiplier(qreal factor) { page()->mainFrame()->setTextSizeMultiplier(factor); } -qreal QFxWebView::textSizeMultiplier() const +qreal QmlGraphicsWebView::textSizeMultiplier() const { return page()->mainFrame()->textSizeMultiplier(); } @@ -923,9 +923,9 @@ qreal QFxWebView::textSizeMultiplier() const \qmlproperty real WebView::zoomFactor This property holds the multiplier used to scale the contents of a Web page. */ -void QFxWebView::setZoomFactor(qreal factor) +void QmlGraphicsWebView::setZoomFactor(qreal factor) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); if (factor == page()->mainFrame()->zoomFactor()) return; @@ -936,7 +936,7 @@ void QFxWebView::setZoomFactor(qreal factor) emit zoomFactorChanged(); } -qreal QFxWebView::zoomFactor() const +qreal QmlGraphicsWebView::zoomFactor() const { return page()->mainFrame()->zoomFactor(); } @@ -947,32 +947,32 @@ qreal QFxWebView::zoomFactor() const This property is the current status suggested by the current web page. In a web browser, such status is often shown in some kind of status bar. */ -void QFxWebView::setStatusText(const QString& s) +void QmlGraphicsWebView::setStatusText(const QString& s) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); d->statusText = s; emit statusTextChanged(); } -void QFxWebView::windowObjectCleared() +void QmlGraphicsWebView::windowObjectCleared() { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); d->updateWindowObjects(); } -QString QFxWebView::statusText() const +QString QmlGraphicsWebView::statusText() const { - Q_D(const QFxWebView); + Q_D(const QmlGraphicsWebView); return d->statusText; } -QWebPage *QFxWebView::page() const +QWebPage *QmlGraphicsWebView::page() const { - Q_D(const QFxWebView); + Q_D(const QmlGraphicsWebView); if (!d->page) { - QFxWebView *self = const_cast(this); - QWebPage *wp = new QFxWebPage(self); + QmlGraphicsWebView *self = const_cast(this); + QWebPage *wp = new QmlGraphicsWebPage(self); // QML items don't default to having a background, // even though most we pages will set one anyway. @@ -1033,16 +1033,16 @@ QWebPage *QFxWebView::page() const } \endqml */ -QFxWebSettings *QFxWebView::settingsObject() const +QmlGraphicsWebSettings *QmlGraphicsWebView::settingsObject() const { - Q_D(const QFxWebView); + Q_D(const QmlGraphicsWebView); d->settings.s = page()->settings(); return &d->settings; } -void QFxWebView::setPage(QWebPage *page) +void QmlGraphicsWebView::setPage(QWebPage *page) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); if (d->page == page) return; if (d->page) { @@ -1098,14 +1098,14 @@ void QFxWebView::setPage(QWebPage *page) \sa progress onLoadFinished() */ -void QFxWebView::load(const QNetworkRequest &request, +void QmlGraphicsWebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operation operation, const QByteArray &body) { page()->mainFrame()->load(request, operation, body); } -QString QFxWebView::html() const +QString QmlGraphicsWebView::html() const { return page()->mainFrame()->toHtml(); } @@ -1122,9 +1122,9 @@ QString QFxWebView::html() const } \endqml */ -void QFxWebView::setHtml(const QString &html, const QUrl &baseUrl) +void QmlGraphicsWebView::setHtml(const QString &html, const QUrl &baseUrl) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); page()->setViewportSize(QSize( d->preferredwidth>0 ? d->preferredwidth : width(), height())); if (isComponentComplete()) @@ -1136,9 +1136,9 @@ void QFxWebView::setHtml(const QString &html, const QUrl &baseUrl) } } -void QFxWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) +void QmlGraphicsWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); page()->setViewportSize(QSize( d->preferredwidth>0 ? d->preferredwidth : width(), height())); @@ -1152,19 +1152,19 @@ void QFxWebView::setContent(const QByteArray &data, const QString &mimeType, con } } -QWebHistory *QFxWebView::history() const +QWebHistory *QmlGraphicsWebView::history() const { return page()->history(); } -QWebSettings *QFxWebView::settings() const +QWebSettings *QmlGraphicsWebView::settings() const { return page()->settings(); } -QFxWebView *QFxWebView::createWindow(QWebPage::WebWindowType type) +QmlGraphicsWebView *QmlGraphicsWebView::createWindow(QWebPage::WebWindowType type) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); switch (type) { case QWebPage::WebBrowserWindow: { if (!d->newWindowComponent && d->newWindowParent) @@ -1172,17 +1172,17 @@ QFxWebView *QFxWebView::createWindow(QWebPage::WebWindowType type) else if (d->newWindowComponent && !d->newWindowParent) qWarning("WebView::newWindowParent not set - WebView::newWindowComponent ignored"); else if (d->newWindowComponent && d->newWindowParent) { - QFxWebView *webview = 0; + QmlGraphicsWebView *webview = 0; QmlContext *windowContext = new QmlContext(qmlContext(this)); QObject *nobj = d->newWindowComponent->create(windowContext); if (nobj) { windowContext->setParent(nobj); - QFxItem *item = qobject_cast(nobj); + QmlGraphicsItem *item = qobject_cast(nobj); if (!item) { delete nobj; } else { - webview = item->findChild(); + webview = item->findChild(); if (!webview) { delete item; } else { @@ -1215,15 +1215,15 @@ QFxWebView *QFxWebView::createWindow(QWebPage::WebWindowType type) The parent of the new window is set by newWindowParent. It must be set. */ -QmlComponent *QFxWebView::newWindowComponent() const +QmlComponent *QmlGraphicsWebView::newWindowComponent() const { - Q_D(const QFxWebView); + Q_D(const QmlGraphicsWebView); return d->newWindowComponent; } -void QFxWebView::setNewWindowComponent(QmlComponent *newWindow) +void QmlGraphicsWebView::setNewWindowComponent(QmlComponent *newWindow) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); delete d->newWindowComponent; d->newWindowComponent = newWindow; } @@ -1236,15 +1236,15 @@ void QFxWebView::setNewWindowComponent(QmlComponent *newWindow) \sa newWindowComponent */ -QFxItem *QFxWebView::newWindowParent() const +QmlGraphicsItem *QmlGraphicsWebView::newWindowParent() const { - Q_D(const QFxWebView); + Q_D(const QmlGraphicsWebView); return d->newWindowParent; } -void QFxWebView::setNewWindowParent(QFxItem *parent) +void QmlGraphicsWebView::setNewWindowParent(QmlGraphicsItem *parent) { - Q_D(QFxWebView); + Q_D(QmlGraphicsWebView); delete d->newWindowParent; d->newWindowParent = parent; } @@ -1255,7 +1255,7 @@ void QFxWebView::setNewWindowParent(QFxItem *parent) May return an area larger in the case when no smaller element is at the position. */ -QRect QFxWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const +QRect QmlGraphicsWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const { QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x,y)); QWebElement element = hit.enclosingBlockElement(); @@ -1271,17 +1271,17 @@ QRect QFxWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const /*! \internal - \class QFxWebPage - \brief The QFxWebPage class is a QWebPage that can create QML plugins. + \class QmlGraphicsWebPage + \brief The QmlGraphicsWebPage class is a QWebPage that can create QML plugins. - \sa QFxWebView + \sa QmlGraphicsWebView */ -QFxWebPage::QFxWebPage(QFxWebView *parent) : +QmlGraphicsWebPage::QmlGraphicsWebPage(QmlGraphicsWebView *parent) : QWebPage(parent) { } -QFxWebPage::~QFxWebPage() +QmlGraphicsWebPage::~QmlGraphicsWebPage() { } @@ -1306,7 +1306,7 @@ public: } return dsp; } - QWidget_Dummy_Plugin(const QUrl& url, QFxWebView *view, const QStringList ¶mNames, const QStringList ¶mValues) : + QWidget_Dummy_Plugin(const QUrl& url, QmlGraphicsWebView *view, const QStringList ¶mNames, const QStringList ¶mValues) : QWidget(dummy_shared_parent()), propertyNames(paramNames), propertyValues(paramValues), @@ -1329,7 +1329,7 @@ public Q_SLOTS: qWarning() << component->errors(); return; } - item = qobject_cast(component->create(qmlContext(webview))); + item = qobject_cast(component->create(qmlContext(webview))); item->setParent(webview); QString jsObjName; for (int i=0; i(parent()); + return static_cast(parent()); } -QObject *QFxWebPage::createPlugin(const QString &, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) +QObject *QmlGraphicsWebPage::createPlugin(const QString &, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) { QUrl comp = qmlContext(viewItem())->resolvedUrl(url); return new QWidget_Dummy_Plugin(comp,viewItem(),paramNames,paramValues); } -QWebPage *QFxWebPage::createWindow(WebWindowType type) +QWebPage *QmlGraphicsWebPage::createWindow(WebWindowType type) { - QFxWebView *newView = viewItem()->createWindow(type); + QmlGraphicsWebView *newView = viewItem()->createWindow(type); if (newView) return newView->page(); return 0; diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h index a31b2b0..e567197 100644 --- a/src/declarative/fx/qfxwebview.h +++ b/src/declarative/fx/qfxwebview.h @@ -57,31 +57,31 @@ class QWebSettings; QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxWebViewPrivate; +class QmlGraphicsWebViewPrivate; class QNetworkRequest; -class QFxWebView; +class QmlGraphicsWebView; -class Q_DECLARATIVE_EXPORT QFxWebPage : public QWebPage +class Q_DECLARATIVE_EXPORT QmlGraphicsWebPage : public QWebPage { Q_OBJECT public: - explicit QFxWebPage(QFxWebView *parent); - ~QFxWebPage(); + explicit QmlGraphicsWebPage(QmlGraphicsWebView *parent); + ~QmlGraphicsWebPage(); protected: QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); QWebPage *createWindow(WebWindowType type); private: - QFxWebView *viewItem(); + QmlGraphicsWebView *viewItem(); }; -class QFxWebViewAttached; -class QFxWebSettings; +class QmlGraphicsWebViewAttached; +class QmlGraphicsWebSettings; //### TODO: browser plugins -class Q_DECLARATIVE_EXPORT QFxWebView : public QFxPaintedItem +class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem { Q_OBJECT @@ -107,18 +107,18 @@ class Q_DECLARATIVE_EXPORT QFxWebView : public QFxPaintedItem Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) Q_PROPERTY(QAction* stop READ stopAction CONSTANT) - Q_PROPERTY(QFxWebSettings* settings READ settingsObject CONSTANT) + Q_PROPERTY(QmlGraphicsWebSettings* settings READ settingsObject CONSTANT) Q_PROPERTY(QmlList* javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent) - Q_PROPERTY(QFxItem* newWindowParent READ newWindowParent WRITE setNewWindowParent) + Q_PROPERTY(QmlGraphicsItem* newWindowParent READ newWindowParent WRITE setNewWindowParent) Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled) public: - QFxWebView(QFxItem *parent=0); - ~QFxWebView(); + QmlGraphicsWebView(QmlGraphicsItem *parent=0); + ~QmlGraphicsWebView(); QUrl url() const; void setUrl(const QUrl &); @@ -162,7 +162,7 @@ public: QWebHistory *history() const; QWebSettings *settings() const; - QFxWebSettings *settingsObject() const; + QmlGraphicsWebSettings *settingsObject() const; int pixelCacheSize() const; void setPixelCacheSize(int pixels); @@ -172,12 +172,12 @@ public: QmlList *javaScriptWindowObjects(); - static QFxWebViewAttached *qmlAttachedProperties(QObject *); + static QmlGraphicsWebViewAttached *qmlAttachedProperties(QObject *); QmlComponent *newWindowComponent() const; void setNewWindowComponent(QmlComponent *newWindow); - QFxItem *newWindowParent() const; - void setNewWindowParent(QFxItem *newWindow); + QmlGraphicsItem *newWindowParent() const; + void setNewWindowParent(QmlGraphicsItem *newWindow); Q_SIGNALS: void preferredWidthChanged(); @@ -214,7 +214,7 @@ private Q_SLOTS: void contentsSizeChanged(const QSize&); protected: - QFxWebView(QFxWebViewPrivate &dd, QFxItem *parent); + QmlGraphicsWebView(QmlGraphicsWebViewPrivate &dd, QmlGraphicsItem *parent); void drawContents(QPainter *, const QRect &); @@ -229,21 +229,21 @@ protected: const QRectF &oldGeometry); virtual void focusChanged(bool); virtual bool sceneEvent(QEvent *event); - QFxWebView *createWindow(QWebPage::WebWindowType type); + QmlGraphicsWebView *createWindow(QWebPage::WebWindowType type); QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; private: void init(); virtual void componentComplete(); - Q_DISABLE_COPY(QFxWebView) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxWebView) - friend class QFxWebPage; + Q_DISABLE_COPY(QmlGraphicsWebView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsWebView) + friend class QmlGraphicsWebPage; }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxWebView) -QML_DECLARE_TYPEINFO(QFxWebView, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QmlGraphicsWebView) +QML_DECLARE_TYPEINFO(QmlGraphicsWebView, QML_HAS_ATTACHED_PROPERTIES) QML_DECLARE_TYPE(QAction) QT_END_HEADER diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index 83ca65b..fa971a3 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -138,7 +138,7 @@ void QmlBinding::update(QmlMetaProperty::WriteFlags flags) Q_D(QmlBinding); #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer bu; + QmlPerfTimer bu; #endif QmlBindingData *data = d->bindingData(); diff --git a/src/declarative/qml/qmlboundsignal.cpp b/src/declarative/qml/qmlboundsignal.cpp index d715309..f4cecec 100644 --- a/src/declarative/qml/qmlboundsignal.cpp +++ b/src/declarative/qml/qmlboundsignal.cpp @@ -102,7 +102,7 @@ QmlBoundSignal::QmlBoundSignal(QObject *scope, const QMetaMethod &signal, // is that they both do the work to figure it out. Boo hoo. if (evaluateIdx == -1) evaluateIdx = metaObject()->methodCount(); - QFx_setParent_noEvent(this, parent); + QmlGraphics_setParent_noEvent(this, parent); QMetaObject::connect(scope, m_idx, this, evaluateIdx); if (!signal.parameterTypes().isEmpty()) @@ -121,7 +121,7 @@ QmlBoundSignal::QmlBoundSignal(QmlContext *ctxt, const QString &val, // is that they both do the work to figure it out. Boo hoo. if (evaluateIdx == -1) evaluateIdx = metaObject()->methodCount(); - QFx_setParent_noEvent(this, parent); + QmlGraphics_setParent_noEvent(this, parent); QMetaObject::connect(scope, m_idx, this, evaluateIdx); m_expression = new QmlExpression(ctxt, val, scope); diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 8f3d6a2..5d2bd12 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -562,7 +562,7 @@ bool QmlCompiler::compile(QmlEngine *engine, QmlCompiledData *out) { #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer pc; + QmlPerfTimer pc; #endif exceptions.clear(); diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 72ead87..c856680 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -648,7 +648,7 @@ QmlComponentPrivate::beginCreate(QmlContext *context, const QBitField &bindings) if (rv) { - QFx_setParent_noEvent(ctxt, rv); + QmlGraphics_setParent_noEvent(ctxt, rv); } else { delete ctxt; } @@ -676,7 +676,7 @@ void QmlComponentPrivate::completeCreate() if (completePending) { { #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer bi; + QmlPerfTimer bi; #endif for (int ii = 0; ii < bindValues.count(); ++ii) { QmlEnginePrivate::SimpleList bv = diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp index 21eeb7c..efc8e98 100644 --- a/src/declarative/qml/qmldom.cpp +++ b/src/declarative/qml/qmldom.cpp @@ -218,7 +218,7 @@ QList QmlDomDocument::errors() const Returns the document's root object, or an invalid QmlDomObject if the document has no root. - In the sample QML below, the root object will be the QFxItem type. + In the sample QML below, the root object will be the QmlGraphicsItem type. \qml Item { Text { diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 2f7f3e5..463bd93 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -268,7 +268,7 @@ QmlEnginePrivate::CapturedProperty::CapturedProperty(const QmlMetaProperty &p) \code QmlEngine engine; QmlComponent component(&engine, "Text { text: \"Hello world!\" }"); - QFxItem *item = qobject_cast(component.create()); + QmlGraphicsItem *item = qobject_cast(component.create()); //add item to view, etc ... @@ -1233,7 +1233,7 @@ void QmlEngine::addImportPath(const QString& path) Returns the directory where SQL and other offline storage is placed. - QFxWebView and the SQL databases created with openDatabase() + QmlGraphicsWebView and the SQL databases created with openDatabase() are stored here. The default is QML/OfflineStorage/ in the platform-standard diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index 7c69c16..69cfc3a 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -252,7 +252,7 @@ void QmlExpression::setExpression(const QString &expression) QVariant QmlExpressionPrivate::evalSSE() { #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer perfsse; + QmlPerfTimer perfsse; #endif QVariant rv = data->sse.run(data->context(), data->me); @@ -290,7 +290,7 @@ void QmlExpressionPrivate::exceptionToError(QScriptEngine *scriptEngine, QVariant QmlExpressionPrivate::evalQtScript(QObject *secondaryScope, bool *isUndefined) { #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer perfqt; + QmlPerfTimer perfqt; #endif QmlExpressionData *data = this->data; @@ -382,7 +382,7 @@ QVariant QmlExpressionPrivate::value(QObject *secondaryScope, bool *isUndefined) return rv; #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer perf; + QmlPerfTimer perf; #endif QmlEnginePrivate *ep = QmlEnginePrivate::get(q->engine()); diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index fb84651..95dfe5b 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -824,7 +824,7 @@ public: bool QmlScriptParser::parse(const QByteArray &qmldata, const QUrl &url) { #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer pt; + QmlPerfTimer pt; #endif clear(); diff --git a/src/declarative/util/qfxglobal.h b/src/declarative/util/qfxglobal.h index 9b4aee1..67eff6c 100644 --- a/src/declarative/util/qfxglobal.h +++ b/src/declarative/util/qfxglobal.h @@ -67,7 +67,7 @@ QT_MODULE(Declarative) return status == Yes; \ } -struct QFx_DerivedObject : public QObject +struct QmlGraphics_DerivedObject : public QObject { void setParent_noEvent(QObject *parent) { bool sce = d_ptr->sendChildEvents; @@ -82,9 +82,9 @@ struct QFx_DerivedObject : public QObject neither \a parent nor the object's previous parent (if it had one) will receive ChildRemoved or ChildAdded events. */ -inline void QFx_setParent_noEvent(QObject *object, QObject *parent) +inline void QmlGraphics_setParent_noEvent(QObject *object, QObject *parent) { - static_cast(object)->setParent_noEvent(parent); + static_cast(object)->setParent_noEvent(parent); } QT_END_NAMESPACE diff --git a/src/declarative/util/qfxperf.cpp b/src/declarative/util/qfxperf.cpp index 739e480..97f195b 100644 --- a/src/declarative/util/qfxperf.cpp +++ b/src/declarative/util/qfxperf.cpp @@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE -Q_DEFINE_PERFORMANCE_LOG(QFxPerf, "QFx") { +Q_DEFINE_PERFORMANCE_LOG(QmlPerf, "QmlGraphics") { Q_DEFINE_PERFORMANCE_METRIC(QmlParsing, "Compilation: QML Parsing") Q_DEFINE_PERFORMANCE_METRIC(Compilation, " QML Compilation") Q_DEFINE_PERFORMANCE_METRIC(VMEExecution, "Execution: QML VME Execution") @@ -54,13 +54,13 @@ Q_DEFINE_PERFORMANCE_LOG(QFxPerf, "QFx") { Q_DEFINE_PERFORMANCE_METRIC(BindableValueUpdate, "QmlBinding::update") Q_DEFINE_PERFORMANCE_METRIC(PixmapLoad, "Pixmap loading") Q_DEFINE_PERFORMANCE_METRIC(FontDatabase, "Font database creation") - Q_DEFINE_PERFORMANCE_METRIC(QFxPathViewPathCache, "FX Items: QFxPathView: Path cache") - Q_DEFINE_PERFORMANCE_METRIC(CreateParticle, " QFxParticles: Particle creation") - Q_DEFINE_PERFORMANCE_METRIC(ItemComponentComplete, " QFxItem::componentComplete") - Q_DEFINE_PERFORMANCE_METRIC(ImageComponentComplete, " QFxImage::componentComplete") - Q_DEFINE_PERFORMANCE_METRIC(BaseLayoutComponentComplete, " QFxBasePositioner::componentComplete") - Q_DEFINE_PERFORMANCE_METRIC(TextComponentComplete, " QFxText::componentComplete") - Q_DEFINE_PERFORMANCE_METRIC(QFxText_setText, " QFxText::setText") + Q_DEFINE_PERFORMANCE_METRIC(QmlGraphicsPathViewPathCache, "FX Items: QmlGraphicsPathView: Path cache") + Q_DEFINE_PERFORMANCE_METRIC(CreateParticle, " QmlGraphicsParticles: Particle creation") + Q_DEFINE_PERFORMANCE_METRIC(ItemComponentComplete, " QmlGraphicsItem::componentComplete") + Q_DEFINE_PERFORMANCE_METRIC(ImageComponentComplete, " QmlGraphicsImage::componentComplete") + Q_DEFINE_PERFORMANCE_METRIC(BaseLayoutComponentComplete, " QmlGraphicsBasePositioner::componentComplete") + Q_DEFINE_PERFORMANCE_METRIC(TextComponentComplete, " QmlGraphicsText::componentComplete") + Q_DEFINE_PERFORMANCE_METRIC(QmlGraphicsText_setText, " QmlGraphicsText::setText") Q_DEFINE_PERFORMANCE_METRIC(AddScript, "QmlScript::addScriptToEngine") } diff --git a/src/declarative/util/qfxperf_p.h b/src/declarative/util/qfxperf_p.h index cea7e80..37bfc32 100644 --- a/src/declarative/util/qfxperf_p.h +++ b/src/declarative/util/qfxperf_p.h @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -Q_DECLARE_PERFORMANCE_LOG(QFxPerf) { +Q_DECLARE_PERFORMANCE_LOG(QmlPerf) { Q_DECLARE_PERFORMANCE_METRIC(QmlParsing) Q_DECLARE_PERFORMANCE_METRIC(Compilation) @@ -73,13 +73,13 @@ Q_DECLARE_PERFORMANCE_LOG(QFxPerf) { Q_DECLARE_PERFORMANCE_METRIC(BindableValueUpdate) Q_DECLARE_PERFORMANCE_METRIC(PixmapLoad) Q_DECLARE_PERFORMANCE_METRIC(FontDatabase) - Q_DECLARE_PERFORMANCE_METRIC(QFxPathViewPathCache) + Q_DECLARE_PERFORMANCE_METRIC(QmlGraphicsPathViewPathCache) Q_DECLARE_PERFORMANCE_METRIC(CreateParticle) Q_DECLARE_PERFORMANCE_METRIC(ItemComponentComplete) Q_DECLARE_PERFORMANCE_METRIC(ImageComponentComplete) Q_DECLARE_PERFORMANCE_METRIC(BaseLayoutComponentComplete) Q_DECLARE_PERFORMANCE_METRIC(TextComponentComplete) - Q_DECLARE_PERFORMANCE_METRIC(QFxText_setText) + Q_DECLARE_PERFORMANCE_METRIC(QmlGraphicsText_setText) Q_DECLARE_PERFORMANCE_METRIC(AddScript) } diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index f103a6b..e00a1c8 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -663,7 +663,7 @@ void QmlPauseAnimationPrivate::init() { Q_Q(QmlPauseAnimation); pa = new QPauseAnimation; - QFx_setParent_noEvent(pa, q); + QmlGraphics_setParent_noEvent(pa, q); } /*! @@ -786,7 +786,7 @@ void QmlScriptActionPrivate::init() { Q_Q(QmlScriptAction); rsa = new QActionAnimation(&proxy); - QFx_setParent_noEvent(rsa, q); + QmlGraphics_setParent_noEvent(rsa, q); } /*! @@ -904,7 +904,7 @@ void QmlPropertyActionPrivate::init() { Q_Q(QmlPropertyAction); spa = new QActionAnimation; - QFx_setParent_noEvent(spa, q); + QmlGraphics_setParent_noEvent(spa, q); } /*! @@ -1097,28 +1097,28 @@ void QmlParentActionPrivate::init() { Q_Q(QmlParentAction); cpa = new QActionAnimation; - QFx_setParent_noEvent(cpa, q); + QmlGraphics_setParent_noEvent(cpa, q); } -QFxItem *QmlParentAction::object() const +QmlGraphicsItem *QmlParentAction::object() const { Q_D(const QmlParentAction); return d->pcTarget; } -void QmlParentAction::setObject(QFxItem *target) +void QmlParentAction::setObject(QmlGraphicsItem *target) { Q_D(QmlParentAction); d->pcTarget = target; } -QFxItem *QmlParentAction::parent() const +QmlGraphicsItem *QmlParentAction::parent() const { Q_D(const QmlParentAction); return d->pcParent; } -void QmlParentAction::setParent(QFxItem *parent) +void QmlParentAction::setParent(QmlGraphicsItem *parent) { Q_D(QmlParentAction); d->pcParent = parent; @@ -1516,7 +1516,7 @@ void QmlPropertyAnimationPrivate::init() { Q_Q(QmlPropertyAnimation); va = new QmlTimeLineValueAnimator; - QFx_setParent_noEvent(va, q); + QmlGraphics_setParent_noEvent(va, q); va->setStartValue(QVariant(0.0f)); va->setEndValue(QVariant(1.0f)); diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h index f4f9f38..4e94aa0 100644 --- a/src/declarative/util/qmlanimation.h +++ b/src/declarative/util/qmlanimation.h @@ -221,25 +221,25 @@ protected: virtual void prepare(QmlMetaProperty &); }; -class QFxItem; +class QmlGraphicsItem; class QmlParentActionPrivate; class QmlParentAction : public QmlAbstractAnimation { Q_OBJECT Q_DECLARE_PRIVATE(QmlParentAction) - Q_PROPERTY(QFxItem *target READ object WRITE setObject) - Q_PROPERTY(QFxItem *parent READ parent WRITE setParent) + Q_PROPERTY(QmlGraphicsItem *target READ object WRITE setObject) + Q_PROPERTY(QmlGraphicsItem *parent READ parent WRITE setParent) public: QmlParentAction(QObject *parent=0); virtual ~QmlParentAction(); - QFxItem *object() const; - void setObject(QFxItem *); + QmlGraphicsItem *object() const; + void setObject(QmlGraphicsItem *); - QFxItem *parent() const; - void setParent(QFxItem *); + QmlGraphicsItem *parent() const; + void setParent(QmlGraphicsItem *); protected: virtual void transition(QmlStateActions &actions, diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index 1f52fcd..38b92ae 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -275,8 +275,8 @@ public: void init(); - QFxItem *pcTarget; - QFxItem *pcParent; + QmlGraphicsItem *pcTarget; + QmlGraphicsItem *pcParent; void doAction(); QActionAnimation *cpa; diff --git a/src/declarative/util/qmlstategroup.cpp b/src/declarative/util/qmlstategroup.cpp index bb40a8b..b07def1 100644 --- a/src/declarative/util/qmlstategroup.cpp +++ b/src/declarative/util/qmlstategroup.cpp @@ -274,7 +274,7 @@ void QmlStateGroupPrivate::setCurrentStateInternal(const QString &state, } if (oldState == 0 || newState == 0) { - if (!nullState) { nullState = new QmlState; QFx_setParent_noEvent(nullState, q); } + if (!nullState) { nullState = new QmlState; QmlGraphics_setParent_noEvent(nullState, q); } if (!oldState) oldState = nullState; if (!newState) newState = nullState; } diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 4d469f9..1bd9199 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -59,15 +59,15 @@ class QmlParentChangePrivate : public QObjectPrivate public: QmlParentChangePrivate() : target(0), parent(0), origParent(0), origStackBefore(0) {} - QFxItem *target; - QFxItem *parent; - QGuard origParent; - QGuard origStackBefore; + QmlGraphicsItem *target; + QmlGraphicsItem *parent; + QGuard origParent; + QGuard origStackBefore; - void doChange(QFxItem *targetParent, QFxItem *stackBefore = 0); + void doChange(QmlGraphicsItem *targetParent, QmlGraphicsItem *stackBefore = 0); }; -void QmlParentChangePrivate::doChange(QFxItem *targetParent, QFxItem *stackBefore) +void QmlParentChangePrivate::doChange(QmlGraphicsItem *targetParent, QmlGraphicsItem *stackBefore) { if (targetParent && target && target->parentItem()) { //### for backwards direction, can we just restore original x, y, scale, rotation @@ -105,7 +105,7 @@ void QmlParentChangePrivate::doChange(QFxItem *targetParent, QFxItem *stackBefor qreal xt = transform.dx(); qreal yt = transform.dy(); - if (target->transformOrigin() != QFxItem::TopLeft) { + if (target->transformOrigin() != QmlGraphicsItem::TopLeft) { qreal tempxt = target->transformOriginPoint().x(); qreal tempyt = target->transformOriginPoint().y(); QTransform t; @@ -166,13 +166,13 @@ QmlParentChange::~QmlParentChange() This property holds the item to be reparented */ -QFxItem *QmlParentChange::object() const +QmlGraphicsItem *QmlParentChange::object() const { Q_D(const QmlParentChange); return d->target; } -void QmlParentChange::setObject(QFxItem *target) +void QmlParentChange::setObject(QmlGraphicsItem *target) { Q_D(QmlParentChange); d->target = target; @@ -183,13 +183,13 @@ void QmlParentChange::setObject(QFxItem *target) This property holds the parent for the item in this state */ -QFxItem *QmlParentChange::parent() const +QmlGraphicsItem *QmlParentChange::parent() const { Q_D(const QmlParentChange); return d->parent; } -void QmlParentChange::setParent(QFxItem *parent) +void QmlParentChange::setParent(QmlGraphicsItem *parent) { Q_D(QmlParentChange); d->parent = parent; @@ -207,13 +207,13 @@ QmlStateOperation::ActionList QmlParentChange::actions() return ActionList() << a; } -class AccessibleFxItem : public QFxItem +class AccessibleFxItem : public QmlGraphicsItem { Q_OBJECT - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsItem) public: int siblingIndex() { - Q_D(QFxItem); + Q_D(QmlGraphicsItem); return d->siblingIndex; } }; @@ -238,7 +238,7 @@ void QmlParentChange::saveOriginals() int siblingIndex = ((AccessibleFxItem*)d->target)->siblingIndex() + 1; QList children = d->origParent->childItems(); for (int i = 0; i < children.count(); ++i) { - QFxItem *child = qobject_cast(children.at(i)); + QmlGraphicsItem *child = qobject_cast(children.at(i)); if (!child) continue; if (((AccessibleFxItem*)child)->siblingIndex() == siblingIndex) { @@ -368,24 +368,24 @@ public: QmlAnchorChangesPrivate() : target(0) {} QString name; - QFxItem *target; + QmlGraphicsItem *target; QString resetString; QStringList resetList; - QFxAnchorLine left; - QFxAnchorLine right; - QFxAnchorLine horizontalCenter; - QFxAnchorLine top; - QFxAnchorLine bottom; - QFxAnchorLine verticalCenter; - QFxAnchorLine baseline; - - QFxAnchorLine origLeft; - QFxAnchorLine origRight; - QFxAnchorLine origHCenter; - QFxAnchorLine origTop; - QFxAnchorLine origBottom; - QFxAnchorLine origVCenter; - QFxAnchorLine origBaseline; + QmlGraphicsAnchorLine left; + QmlGraphicsAnchorLine right; + QmlGraphicsAnchorLine horizontalCenter; + QmlGraphicsAnchorLine top; + QmlGraphicsAnchorLine bottom; + QmlGraphicsAnchorLine verticalCenter; + QmlGraphicsAnchorLine baseline; + + QmlGraphicsAnchorLine origLeft; + QmlGraphicsAnchorLine origRight; + QmlGraphicsAnchorLine origHCenter; + QmlGraphicsAnchorLine origTop; + QmlGraphicsAnchorLine origBottom; + QmlGraphicsAnchorLine origVCenter; + QmlGraphicsAnchorLine origBaseline; qreal origX; qreal origY; qreal origWidth; @@ -413,13 +413,13 @@ QmlAnchorChanges::ActionList QmlAnchorChanges::actions() return ActionList() << a; } -QFxItem *QmlAnchorChanges::object() const +QmlGraphicsItem *QmlAnchorChanges::object() const { Q_D(const QmlAnchorChanges); return d->target; } -void QmlAnchorChanges::setObject(QFxItem *target) +void QmlAnchorChanges::setObject(QmlGraphicsItem *target) { Q_D(QmlAnchorChanges); d->target = target; @@ -450,85 +450,85 @@ void QmlAnchorChanges::setReset(const QString &reset) These properties change the respective anchors of the item. */ -QFxAnchorLine QmlAnchorChanges::left() const +QmlGraphicsAnchorLine QmlAnchorChanges::left() const { Q_D(const QmlAnchorChanges); return d->left; } -void QmlAnchorChanges::setLeft(const QFxAnchorLine &edge) +void QmlAnchorChanges::setLeft(const QmlGraphicsAnchorLine &edge) { Q_D(QmlAnchorChanges); d->left = edge; } -QFxAnchorLine QmlAnchorChanges::right() const +QmlGraphicsAnchorLine QmlAnchorChanges::right() const { Q_D(const QmlAnchorChanges); return d->right; } -void QmlAnchorChanges::setRight(const QFxAnchorLine &edge) +void QmlAnchorChanges::setRight(const QmlGraphicsAnchorLine &edge) { Q_D(QmlAnchorChanges); d->right = edge; } -QFxAnchorLine QmlAnchorChanges::horizontalCenter() const +QmlGraphicsAnchorLine QmlAnchorChanges::horizontalCenter() const { Q_D(const QmlAnchorChanges); return d->horizontalCenter; } -void QmlAnchorChanges::setHorizontalCenter(const QFxAnchorLine &edge) +void QmlAnchorChanges::setHorizontalCenter(const QmlGraphicsAnchorLine &edge) { Q_D(QmlAnchorChanges); d->horizontalCenter = edge; } -QFxAnchorLine QmlAnchorChanges::top() const +QmlGraphicsAnchorLine QmlAnchorChanges::top() const { Q_D(const QmlAnchorChanges); return d->top; } -void QmlAnchorChanges::setTop(const QFxAnchorLine &edge) +void QmlAnchorChanges::setTop(const QmlGraphicsAnchorLine &edge) { Q_D(QmlAnchorChanges); d->top = edge; } -QFxAnchorLine QmlAnchorChanges::bottom() const +QmlGraphicsAnchorLine QmlAnchorChanges::bottom() const { Q_D(const QmlAnchorChanges); return d->bottom; } -void QmlAnchorChanges::setBottom(const QFxAnchorLine &edge) +void QmlAnchorChanges::setBottom(const QmlGraphicsAnchorLine &edge) { Q_D(QmlAnchorChanges); d->bottom = edge; } -QFxAnchorLine QmlAnchorChanges::verticalCenter() const +QmlGraphicsAnchorLine QmlAnchorChanges::verticalCenter() const { Q_D(const QmlAnchorChanges); return d->verticalCenter; } -void QmlAnchorChanges::setVerticalCenter(const QFxAnchorLine &edge) +void QmlAnchorChanges::setVerticalCenter(const QmlGraphicsAnchorLine &edge) { Q_D(QmlAnchorChanges); d->verticalCenter = edge; } -QFxAnchorLine QmlAnchorChanges::baseline() const +QmlGraphicsAnchorLine QmlAnchorChanges::baseline() const { Q_D(const QmlAnchorChanges); return d->baseline; } -void QmlAnchorChanges::setBaseline(const QFxAnchorLine &edge) +void QmlAnchorChanges::setBaseline(const QmlGraphicsAnchorLine &edge) { Q_D(QmlAnchorChanges); d->baseline = edge; @@ -541,19 +541,19 @@ void QmlAnchorChanges::execute() return; //set any anchors that have been specified - if (d->left.anchorLine != QFxAnchorLine::Invalid) + if (d->left.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setLeft(d->left); - if (d->right.anchorLine != QFxAnchorLine::Invalid) + if (d->right.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setRight(d->right); - if (d->horizontalCenter.anchorLine != QFxAnchorLine::Invalid) + if (d->horizontalCenter.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setHorizontalCenter(d->horizontalCenter); - if (d->top.anchorLine != QFxAnchorLine::Invalid) + if (d->top.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setTop(d->top); - if (d->bottom.anchorLine != QFxAnchorLine::Invalid) + if (d->bottom.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setBottom(d->bottom); - if (d->verticalCenter.anchorLine != QFxAnchorLine::Invalid) + if (d->verticalCenter.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setVerticalCenter(d->verticalCenter); - if (d->baseline.anchorLine != QFxAnchorLine::Invalid) + if (d->baseline.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setBaseline(d->baseline); } @@ -569,19 +569,19 @@ void QmlAnchorChanges::reverse() return; //restore previous anchors - if (d->origLeft.anchorLine != QFxAnchorLine::Invalid) + if (d->origLeft.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setLeft(d->origLeft); - if (d->origRight.anchorLine != QFxAnchorLine::Invalid) + if (d->origRight.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setRight(d->origRight); - if (d->origHCenter.anchorLine != QFxAnchorLine::Invalid) + if (d->origHCenter.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setHorizontalCenter(d->origHCenter); - if (d->origTop.anchorLine != QFxAnchorLine::Invalid) + if (d->origTop.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setTop(d->origTop); - if (d->origBottom.anchorLine != QFxAnchorLine::Invalid) + if (d->origBottom.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setBottom(d->origBottom); - if (d->origVCenter.anchorLine != QFxAnchorLine::Invalid) + if (d->origVCenter.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setVerticalCenter(d->origVCenter); - if (d->origBaseline.anchorLine != QFxAnchorLine::Invalid) + if (d->origBaseline.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->setBaseline(d->origBaseline); } @@ -662,19 +662,19 @@ void QmlAnchorChanges::clearForwardBindings() d->target->anchors()->resetBaseline(); //reset any anchors that we'll be setting in the state - if (d->left.anchorLine != QFxAnchorLine::Invalid) + if (d->left.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetLeft(); - if (d->right.anchorLine != QFxAnchorLine::Invalid) + if (d->right.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetRight(); - if (d->horizontalCenter.anchorLine != QFxAnchorLine::Invalid) + if (d->horizontalCenter.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetHorizontalCenter(); - if (d->top.anchorLine != QFxAnchorLine::Invalid) + if (d->top.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetTop(); - if (d->bottom.anchorLine != QFxAnchorLine::Invalid) + if (d->bottom.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetBottom(); - if (d->verticalCenter.anchorLine != QFxAnchorLine::Invalid) + if (d->verticalCenter.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetVerticalCenter(); - if (d->baseline.anchorLine != QFxAnchorLine::Invalid) + if (d->baseline.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetBaseline(); } @@ -687,35 +687,35 @@ void QmlAnchorChanges::clearReverseBindings() d->origHeight = d->target->height(); //reset any anchors that were set in the state - if (d->left.anchorLine != QFxAnchorLine::Invalid) + if (d->left.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetLeft(); - if (d->right.anchorLine != QFxAnchorLine::Invalid) + if (d->right.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetRight(); - if (d->horizontalCenter.anchorLine != QFxAnchorLine::Invalid) + if (d->horizontalCenter.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetHorizontalCenter(); - if (d->top.anchorLine != QFxAnchorLine::Invalid) + if (d->top.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetTop(); - if (d->bottom.anchorLine != QFxAnchorLine::Invalid) + if (d->bottom.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetBottom(); - if (d->verticalCenter.anchorLine != QFxAnchorLine::Invalid) + if (d->verticalCenter.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetVerticalCenter(); - if (d->baseline.anchorLine != QFxAnchorLine::Invalid) + if (d->baseline.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetBaseline(); //reset any anchors that were set in the original state - if (d->origLeft.anchorLine != QFxAnchorLine::Invalid) + if (d->origLeft.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetLeft(); - if (d->origRight.anchorLine != QFxAnchorLine::Invalid) + if (d->origRight.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetRight(); - if (d->origHCenter.anchorLine != QFxAnchorLine::Invalid) + if (d->origHCenter.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetHorizontalCenter(); - if (d->origTop.anchorLine != QFxAnchorLine::Invalid) + if (d->origTop.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetTop(); - if (d->origBottom.anchorLine != QFxAnchorLine::Invalid) + if (d->origBottom.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetBottom(); - if (d->origVCenter.anchorLine != QFxAnchorLine::Invalid) + if (d->origVCenter.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetVerticalCenter(); - if (d->origBaseline.anchorLine != QFxAnchorLine::Invalid) + if (d->origBaseline.anchorLine != QmlGraphicsAnchorLine::Invalid) d->target->anchors()->resetBaseline(); } diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h index 237e3e8..903998d 100644 --- a/src/declarative/util/qmlstateoperations.h +++ b/src/declarative/util/qmlstateoperations.h @@ -59,17 +59,17 @@ class Q_DECLARATIVE_EXPORT QmlParentChange : public QmlStateOperation, public Ac Q_OBJECT Q_DECLARE_PRIVATE(QmlParentChange) - Q_PROPERTY(QFxItem *target READ object WRITE setObject) - Q_PROPERTY(QFxItem *parent READ parent WRITE setParent) + Q_PROPERTY(QmlGraphicsItem *target READ object WRITE setObject) + Q_PROPERTY(QmlGraphicsItem *parent READ parent WRITE setParent) public: QmlParentChange(QObject *parent=0); ~QmlParentChange(); - QFxItem *object() const; - void setObject(QFxItem *); + QmlGraphicsItem *object() const; + void setObject(QmlGraphicsItem *); - QFxItem *parent() const; - void setParent(QFxItem *); + QmlGraphicsItem *parent() const; + void setParent(QmlGraphicsItem *); virtual ActionList actions(); @@ -111,15 +111,15 @@ class Q_DECLARATIVE_EXPORT QmlAnchorChanges : public QmlStateOperation, public A Q_OBJECT Q_DECLARE_PRIVATE(QmlAnchorChanges) - Q_PROPERTY(QFxItem *target READ object WRITE setObject) + Q_PROPERTY(QmlGraphicsItem *target READ object WRITE setObject) Q_PROPERTY(QString reset READ reset WRITE setReset) - Q_PROPERTY(QFxAnchorLine left READ left WRITE setLeft) - Q_PROPERTY(QFxAnchorLine right READ right WRITE setRight) - Q_PROPERTY(QFxAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter) - Q_PROPERTY(QFxAnchorLine top READ top WRITE setTop) - Q_PROPERTY(QFxAnchorLine bottom READ bottom WRITE setBottom) - Q_PROPERTY(QFxAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter) - Q_PROPERTY(QFxAnchorLine baseline READ baseline WRITE setBaseline) + Q_PROPERTY(QmlGraphicsAnchorLine left READ left WRITE setLeft) + Q_PROPERTY(QmlGraphicsAnchorLine right READ right WRITE setRight) + Q_PROPERTY(QmlGraphicsAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter) + Q_PROPERTY(QmlGraphicsAnchorLine top READ top WRITE setTop) + Q_PROPERTY(QmlGraphicsAnchorLine bottom READ bottom WRITE setBottom) + Q_PROPERTY(QmlGraphicsAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter) + Q_PROPERTY(QmlGraphicsAnchorLine baseline READ baseline WRITE setBaseline) public: QmlAnchorChanges(QObject *parent=0); @@ -127,32 +127,32 @@ public: virtual ActionList actions(); - QFxItem *object() const; - void setObject(QFxItem *); + QmlGraphicsItem *object() const; + void setObject(QmlGraphicsItem *); QString reset() const; void setReset(const QString &); - QFxAnchorLine left() const; - void setLeft(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine left() const; + void setLeft(const QmlGraphicsAnchorLine &edge); - QFxAnchorLine right() const; - void setRight(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine right() const; + void setRight(const QmlGraphicsAnchorLine &edge); - QFxAnchorLine horizontalCenter() const; - void setHorizontalCenter(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine horizontalCenter() const; + void setHorizontalCenter(const QmlGraphicsAnchorLine &edge); - QFxAnchorLine top() const; - void setTop(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine top() const; + void setTop(const QmlGraphicsAnchorLine &edge); - QFxAnchorLine bottom() const; - void setBottom(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine bottom() const; + void setBottom(const QmlGraphicsAnchorLine &edge); - QFxAnchorLine verticalCenter() const; - void setVerticalCenter(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine verticalCenter() const; + void setVerticalCenter(const QmlGraphicsAnchorLine &edge); - QFxAnchorLine baseline() const; - void setBaseline(const QFxAnchorLine &edge); + QmlGraphicsAnchorLine baseline() const; + void setBaseline(const QmlGraphicsAnchorLine &edge); virtual void execute(); virtual bool isReversable(); diff --git a/src/declarative/util/qmltimer.cpp b/src/declarative/util/qmltimer.cpp index f1991f5..1d90051 100644 --- a/src/declarative/util/qmltimer.cpp +++ b/src/declarative/util/qmltimer.cpp @@ -66,7 +66,7 @@ public: }; /*! - \qmlclass Timer QFxTimer + \qmlclass Timer QmlGraphicsTimer \brief The Timer item triggers a handler at a specified interval. A timer can be used to trigger an action either once, or repeatedly diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index 329a9b2..ac67cb8 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -136,7 +136,7 @@ public: : q(w), root(0), component(0), resizable(false) {} QmlView *q; - QFxItem *root; + QmlGraphicsItem *root; QUrl source; QString qml; @@ -193,7 +193,7 @@ void QmlViewPrivate::init() QmlMetaType::registerCustomStringConverter(QVariant::KeySequence, &stringToKeySequence); #ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer perf; + QmlPerfTimer perf; #endif QFontDatabase database; @@ -213,7 +213,7 @@ void QmlViewPrivate::init() } /*! - The destructor clears the view's \l {QFxItem} {items} and + The destructor clears the view's \l {QmlGraphicsItem} {items} and deletes the internal representation. \sa clearItems() @@ -337,7 +337,7 @@ void QmlView::continueExecute() } if (obj) { - if (QFxItem *item = qobject_cast(obj)) { + if (QmlGraphicsItem *item = qobject_cast(obj)) { d->scene.addItem(item); @@ -476,11 +476,11 @@ QSize QmlView::sizeHint() const /*! Creates a \l{QmlComponent} {component} from the \a qml - string, and returns it as an \l {QFxItem} {item}. If the + string, and returns it as an \l {QmlGraphicsItem} {item}. If the \a parent item is provided, it becomes the new item's parent. \a parent should be in this view's item hierarchy. */ -QFxItem* QmlView::addItem(const QString &qml, QFxItem* parent) +QmlGraphicsItem* QmlView::addItem(const QString &qml, QmlGraphicsItem* parent) { if (!d->root) return 0; @@ -508,7 +508,7 @@ QFxItem* QmlView::addItem(const QString &qml, QFxItem* parent) } if (obj){ - QFxItem *item = static_cast(obj); + QmlGraphicsItem *item = static_cast(obj); if (!parent) parent = d->root; @@ -519,7 +519,7 @@ QFxItem* QmlView::addItem(const QString &qml, QFxItem* parent) } /*! - Deletes the view's \l {QFxItem} {items} and the \l {QmlEngine} + Deletes the view's \l {QmlGraphicsItem} {items} and the \l {QmlEngine} {QML engine's} Component cache. */ void QmlView::reset() @@ -530,7 +530,7 @@ void QmlView::reset() } /*! - Deletes the view's \l {QFxItem} {items}. + Deletes the view's \l {QmlGraphicsItem} {items}. */ void QmlView::clearItems() { @@ -541,9 +541,9 @@ void QmlView::clearItems() } /*! - Returns the view's root \l {QFxItem} {item}. + Returns the view's root \l {QmlGraphicsItem} {item}. */ -QFxItem *QmlView::root() const +QmlGraphicsItem *QmlView::root() const { return d->root; } diff --git a/src/declarative/util/qmlview.h b/src/declarative/util/qmlview.h index 822827a..4b2dd1c 100644 --- a/src/declarative/util/qmlview.h +++ b/src/declarative/util/qmlview.h @@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QFxItem; +class QmlGraphicsItem; class QmlEngine; class QmlContext; class QmlError; @@ -78,10 +78,10 @@ public: virtual void execute(); virtual void reset(); - virtual QFxItem* addItem(const QString &qml, QFxItem* parent=0); + virtual QmlGraphicsItem* addItem(const QString &qml, QmlGraphicsItem* parent=0); virtual void clearItems(); - virtual QFxItem *root() const; + virtual QmlGraphicsItem *root() const; void setContentResizable(bool); bool contentResizable() const; diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 7c3c4f0..8fc9610 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -604,7 +604,7 @@ public: inline bool isPixmap() const { return (item->type() == QGraphicsPixmapItem::Type); - //|| (item->d_ptr->isObject && qobject_cast(q_func())); + //|| (item->d_ptr->isObject && qobject_cast(q_func())); } inline const QStyleOption *styleOption() const diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index ec977da..fea6ef3 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -13,7 +13,7 @@ public: tst_anchors() {} template - T *findItem(QFxItem *parent, const QString &id); + T *findItem(QmlGraphicsItem *parent, const QString &id); private slots: void basicAnchors(); @@ -27,12 +27,12 @@ private slots: Find an item with the specified id. */ template -T *tst_anchors::findItem(QFxItem *parent, const QString &objectName) +T *tst_anchors::findItem(QmlGraphicsItem *parent, const QString &objectName) { const QMetaObject &mo = T::staticMetaObject; QList children = parent->childItems(); for (int i = 0; i < children.count(); ++i) { - QFxItem *item = qobject_cast(children.at(i)->toGraphicsObject()); + QmlGraphicsItem *item = qobject_cast(children.at(i)->toGraphicsObject()); if (item) { if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { return static_cast(item); @@ -55,41 +55,41 @@ void tst_anchors::basicAnchors() qApp->processEvents(); //sibling horizontal - QCOMPARE(findItem(view->root(), QLatin1String("Rect1"))->x(), 26.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect2"))->x(), 122.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect3"))->x(), 74.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect4"))->x(), 16.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect5"))->x(), 112.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect6"))->x(), 64.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect1"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect2"))->x(), 122.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect3"))->x(), 74.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect4"))->x(), 16.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect5"))->x(), 112.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect6"))->x(), 64.0); //parent horizontal - QCOMPARE(findItem(view->root(), QLatin1String("Rect7"))->x(), 0.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect8"))->x(), 240.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect9"))->x(), 120.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect10"))->x(), -10.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect11"))->x(), 230.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect12"))->x(), 110.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect7"))->x(), 0.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect8"))->x(), 240.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect9"))->x(), 120.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect10"))->x(), -10.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect11"))->x(), 230.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect12"))->x(), 110.0); //vertical - QCOMPARE(findItem(view->root(), QLatin1String("Rect13"))->y(), 20.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect14"))->y(), 155.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect13"))->y(), 20.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect14"))->y(), 155.0); //stretch - QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->x(), 26.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->width(), 96.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->x(), 26.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->width(), 192.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->x(), -70.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->width(), 192.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect15"))->width(), 96.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->x(), 26.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect16"))->width(), 192.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->x(), -70.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect17"))->width(), 192.0); //vertical stretch - QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->y(), 20.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->height(), 40.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->y(), 20.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect18"))->height(), 40.0); //more parent horizontal - QCOMPARE(findItem(view->root(), QLatin1String("Rect19"))->x(), 115.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect20"))->x(), 235.0); - QCOMPARE(findItem(view->root(), QLatin1String("Rect21"))->x(), -5.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect19"))->x(), 115.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect20"))->x(), 235.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect21"))->x(), -5.0); delete view; } @@ -102,7 +102,7 @@ void tst_anchors::loops() view->setUrl(QUrl("file://" SRCDIR "/data/loop1.qml")); - QString expect = "QML QFxText (" + view->url().toString() + ":7:5" + ") Possible anchor loop detected on horizontal anchor."; + QString expect = "QML QmlGraphicsText (" + view->url().toString() + ":7:5" + ") Possible anchor loop detected on horizontal anchor."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); @@ -117,7 +117,7 @@ void tst_anchors::loops() view->setUrl(QUrl("file://" SRCDIR "/data/loop2.qml")); - QString expect = "QML QFxImage (" + view->url().toString() + ":14:3" + ") Possible anchor loop detected on horizontal anchor."; + QString expect = "QML QmlGraphicsImage (" + view->url().toString() + ":14:3" + ") Possible anchor loop detected on horizontal anchor."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); qApp->processEvents(); @@ -133,7 +133,7 @@ void tst_anchors::illegalSets() view->setUrl(QUrl("file://" SRCDIR "/data/illegal1.qml")); - QString expect = "QML QFxRect (" + view->url().toString() + ":7:5" + ") Can't specify left, right, and hcenter anchors."; + QString expect = "QML QmlGraphicsRect (" + view->url().toString() + ":7:5" + ") Can't specify left, right, and hcenter anchors."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); qApp->processEvents(); @@ -146,7 +146,7 @@ void tst_anchors::illegalSets() view->setUrl(QUrl("file://" SRCDIR "/data/illegal2.qml")); - QString expect = "QML QFxText (" + view->url().toString() + ":7:5" + ") Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors."; + QString expect = "QML QmlGraphicsText (" + view->url().toString() + ":7:5" + ") Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); //qApp->processEvents(); @@ -159,7 +159,7 @@ void tst_anchors::illegalSets() view->setUrl(QUrl("file://" SRCDIR "/data/illegal3.qml")); - QString expect = "QML QFxRect (" + view->url().toString() + ":9:5" + ") Can't anchor to an item that isn't a parent or sibling."; + QString expect = "QML QmlGraphicsRect (" + view->url().toString() + ":9:5" + ") Can't anchor to an item that isn't a parent or sibling."; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); view->execute(); //qApp->processEvents(); @@ -170,25 +170,25 @@ void tst_anchors::illegalSets() void tst_anchors::reset() { - QFxItem *aItem = new QFxItem; - QFxAnchorLine anchor; + QmlGraphicsItem *aItem = new QmlGraphicsItem; + QmlGraphicsAnchorLine anchor; anchor.item = aItem; - anchor.anchorLine = QFxAnchorLine::Top; + anchor.anchorLine = QmlGraphicsAnchorLine::Top; - QFxItem *item = new QFxItem; + QmlGraphicsItem *item = new QmlGraphicsItem; item->anchors()->setBottom(anchor); - QCOMPARE(item->anchors()->usedAnchors().testFlag(QFxAnchors::HasBottomAnchor), true); + QCOMPARE(item->anchors()->usedAnchors().testFlag(QmlGraphicsAnchors::HasBottomAnchor), true); item->anchors()->resetBottom(); - QCOMPARE(item->anchors()->usedAnchors().testFlag(QFxAnchors::HasBottomAnchor), false); + QCOMPARE(item->anchors()->usedAnchors().testFlag(QmlGraphicsAnchors::HasBottomAnchor), false); } void tst_anchors::nullItem() { - QFxAnchorLine anchor; + QmlGraphicsAnchorLine anchor; - QTest::ignoreMessage(QtWarningMsg, "QML QFxItem (unknown location) Can't anchor to a null item."); - QFxItem *item = new QFxItem; + QTest::ignoreMessage(QtWarningMsg, "QML QmlGraphicsItem (unknown location) Can't anchor to a null item."); + QmlGraphicsItem *item = new QmlGraphicsItem; item->anchors()->setBottom(anchor); } diff --git a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp index 5c71731..46c953d 100644 --- a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp +++ b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp @@ -21,14 +21,14 @@ private slots: void tst_animatedimage::play() { - QFxAnimatedImageItem anim; + QmlGraphicsAnimatedImageItem anim; anim.setSource(QUrl("file://" SRCDIR "/data/stickman.gif")); QVERIFY(anim.isPlaying()); } void tst_animatedimage::pause() { - QFxAnimatedImageItem anim; + QmlGraphicsAnimatedImageItem anim; anim.setSource(QUrl("file://" SRCDIR "/data/stickman.gif")); anim.setPaused(true); QVERIFY(!anim.isPlaying()); @@ -36,7 +36,7 @@ void tst_animatedimage::pause() void tst_animatedimage::setFrame() { - QFxAnimatedImageItem anim; + QmlGraphicsAnimatedImageItem anim; anim.setSource(QUrl("file://" SRCDIR "/data/stickman.gif")); anim.setPaused(true); QVERIFY(!anim.isPlaying()); @@ -46,7 +46,7 @@ void tst_animatedimage::setFrame() void tst_animatedimage::frameCount() { - QFxAnimatedImageItem anim; + QmlGraphicsAnimatedImageItem anim; anim.setSource(QUrl("file://" SRCDIR "/data/stickman.gif")); QCOMPARE(anim.frameCount(), 299); } diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index a6f67b8..b5cc9d4 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -32,7 +32,7 @@ private slots: void tst_animations::simpleNumber() { - QFxRect rect; + QmlGraphicsRect rect; QmlNumberAnimation animation; animation.setTarget(&rect); animation.setProperty("x"); @@ -50,7 +50,7 @@ void tst_animations::simpleNumber() void tst_animations::simpleColor() { - QFxRect rect; + QmlGraphicsRect rect; QmlColorAnimation animation; animation.setTarget(&rect); animation.setProperty("color"); @@ -68,7 +68,7 @@ void tst_animations::simpleColor() void tst_animations::alwaysRunToEnd() { - QFxRect rect; + QmlGraphicsRect rect; QmlPropertyAnimation animation; animation.setTarget(&rect); animation.setProperty("x"); @@ -86,7 +86,7 @@ void tst_animations::alwaysRunToEnd() void tst_animations::dotProperty() { - QFxRect rect; + QmlGraphicsRect rect; QmlNumberAnimation animation; animation.setTarget(&rect); animation.setProperty("border.width"); @@ -141,12 +141,12 @@ void tst_animations::badTypes() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/badtype4.qml")); - QFxRect *rect = qobject_cast(c.create()); + QmlGraphicsRect *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("state1"); QTest::qWait(1000 + 50); - QFxRect *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust + QmlGraphicsRect *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust QVERIFY(myRect); QCOMPARE(myRect->x(),qreal(200)); } @@ -158,7 +158,7 @@ void tst_animations::badProperties() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/badproperty1.qml")); - QFxRect *rect = qobject_cast(c.create()); + QmlGraphicsRect *rect = qobject_cast(c.create()); QVERIFY(rect); QTest::ignoreMessage(QtWarningMsg, "QML QmlColorAnimation (file://" SRCDIR "/data/badproperty1.qml:22:9) Cannot animate non-existant property \"pen.colr\""); @@ -174,12 +174,12 @@ void tst_animations::mixedTypes() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/mixedtype1.qml")); - QFxRect *rect = qobject_cast(c.create()); + QmlGraphicsRect *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("state1"); QTest::qWait(500); - QFxRect *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust + QmlGraphicsRect *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust QVERIFY(myRect); //rather inexact -- is there a better way? @@ -190,12 +190,12 @@ void tst_animations::mixedTypes() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/mixedtype2.qml")); - QFxRect *rect = qobject_cast(c.create()); + QmlGraphicsRect *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("state1"); QTest::qWait(500); - QFxRect *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust + QmlGraphicsRect *myRect = qobject_cast(rect->QGraphicsObject::children().at(3)); //### not robust QVERIFY(myRect); //rather inexact -- is there a better way? diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 7bfadf6..079e2e7 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -26,12 +26,12 @@ void tst_behaviors::simpleBehavior() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/simple.qml")); - QFxRect *rect = qobject_cast(c.create()); + QmlGraphicsRect *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("moved"); QTest::qWait(100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered } @@ -39,12 +39,12 @@ void tst_behaviors::scriptTriggered() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/scripttrigger.qml")); - QFxRect *rect = qobject_cast(c.create()); + QmlGraphicsRect *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setColor(QColor("red")); QTest::qWait(100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered } @@ -52,10 +52,10 @@ void tst_behaviors::cppTriggered() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/cpptrigger.qml")); - QFxRect *rect = qobject_cast(c.create()); + QmlGraphicsRect *rect = qobject_cast(c.create()); QVERIFY(rect); - QFxRect *innerRect = qobject_cast(rect->findChild("MyRect")); + QmlGraphicsRect *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect); innerRect->setProperty("x", 200); @@ -68,7 +68,7 @@ void tst_behaviors::loop() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/loop.qml")); - QFxRect *rect = qobject_cast(c.create()); + QmlGraphicsRect *rect = qobject_cast(c.create()); QVERIFY(rect); //don't crash @@ -79,12 +79,12 @@ void tst_behaviors::colorBehavior() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/color.qml")); - QFxRect *rect = qobject_cast(c.create()); + QmlGraphicsRect *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("red"); QTest::qWait(100); - QColor color = qobject_cast(rect->findChild("MyRect"))->color(); + QColor color = qobject_cast(rect->findChild("MyRect"))->color(); QVERIFY(color != QColor("red") && color != QColor("green")); //i.e. the behavior has been triggered } @@ -92,12 +92,12 @@ void tst_behaviors::replaceBinding() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/binding.qml")); - QFxRect *rect = qobject_cast(c.create()); + QmlGraphicsRect *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("moved"); QTest::qWait(100); - QFxRect *innerRect = qobject_cast(rect->findChild("MyRect")); + QmlGraphicsRect *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect); qreal x = innerRect->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered @@ -127,24 +127,24 @@ void tst_behaviors::group() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/groupProperty.qml")); - QFxRect *rect = qobject_cast(c.create()); + QmlGraphicsRect *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("moved"); QTest::qWait(100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered } { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/groupProperty2.qml")); - QFxRect *rect = qobject_cast(c.create()); + QmlGraphicsRect *rect = qobject_cast(c.create()); QVERIFY(rect); rect->setState("moved"); QTest::qWait(100); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered } } diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index d1e6aab..70755ff 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -4,11 +4,11 @@ #include #include -class tst_QFxLayouts : public QObject +class tst_QmlGraphicsLayouts : public QObject { Q_OBJECT public: - tst_QFxLayouts(); + tst_QmlGraphicsLayouts(); private slots: void test_horizontal(); @@ -22,24 +22,24 @@ private: QmlView *createView(const QString &filename); }; -tst_QFxLayouts::tst_QFxLayouts() +tst_QmlGraphicsLayouts::tst_QmlGraphicsLayouts() { } -void tst_QFxLayouts::test_horizontal() +void tst_QmlGraphicsLayouts::test_horizontal() { QmlView *canvas = createView(SRCDIR "/data/horizontal.qml"); canvas->execute(); qApp->processEvents(); - QFxRect *one = canvas->root()->findChild("one"); + QmlGraphicsRect *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QFxRect *two = canvas->root()->findChild("two"); + QmlGraphicsRect *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QFxRect *three = canvas->root()->findChild("three"); + QmlGraphicsRect *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -50,20 +50,20 @@ void tst_QFxLayouts::test_horizontal() QCOMPARE(three->y(), 0.0); } -void tst_QFxLayouts::test_horizontal_spacing() +void tst_QmlGraphicsLayouts::test_horizontal_spacing() { QmlView *canvas = createView(SRCDIR "/data/horizontal-spacing.qml"); canvas->execute(); qApp->processEvents(); - QFxRect *one = canvas->root()->findChild("one"); + QmlGraphicsRect *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QFxRect *two = canvas->root()->findChild("two"); + QmlGraphicsRect *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QFxRect *three = canvas->root()->findChild("three"); + QmlGraphicsRect *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -74,20 +74,20 @@ void tst_QFxLayouts::test_horizontal_spacing() QCOMPARE(three->y(), 0.0); } -void tst_QFxLayouts::test_vertical() +void tst_QmlGraphicsLayouts::test_vertical() { QmlView *canvas = createView(SRCDIR "/data/vertical.qml"); canvas->execute(); qApp->processEvents(); - QFxRect *one = canvas->root()->findChild("one"); + QmlGraphicsRect *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QFxRect *two = canvas->root()->findChild("two"); + QmlGraphicsRect *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QFxRect *three = canvas->root()->findChild("three"); + QmlGraphicsRect *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -98,20 +98,20 @@ void tst_QFxLayouts::test_vertical() QCOMPARE(three->y(), 60.0); } -void tst_QFxLayouts::test_vertical_spacing() +void tst_QmlGraphicsLayouts::test_vertical_spacing() { QmlView *canvas = createView(SRCDIR "/data/vertical-spacing.qml"); canvas->execute(); qApp->processEvents(); - QFxRect *one = canvas->root()->findChild("one"); + QmlGraphicsRect *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QFxRect *two = canvas->root()->findChild("two"); + QmlGraphicsRect *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QFxRect *three = canvas->root()->findChild("three"); + QmlGraphicsRect *three = canvas->root()->findChild("three"); QVERIFY(three != 0); QCOMPARE(one->x(), 0.0); @@ -122,22 +122,22 @@ void tst_QFxLayouts::test_vertical_spacing() QCOMPARE(three->y(), 80.0); } -void tst_QFxLayouts::test_grid() +void tst_QmlGraphicsLayouts::test_grid() { QmlView *canvas = createView("data/grid.qml"); canvas->execute(); qApp->processEvents(); - QFxRect *one = canvas->root()->findChild("one"); + QmlGraphicsRect *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QFxRect *two = canvas->root()->findChild("two"); + QmlGraphicsRect *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QFxRect *three = canvas->root()->findChild("three"); + QmlGraphicsRect *three = canvas->root()->findChild("three"); QVERIFY(three != 0); - QFxRect *four = canvas->root()->findChild("four"); + QmlGraphicsRect *four = canvas->root()->findChild("four"); QVERIFY(four != 0); - QFxRect *five = canvas->root()->findChild("five"); + QmlGraphicsRect *five = canvas->root()->findChild("five"); QVERIFY(five != 0); QCOMPARE(one->x(), 0.0); @@ -152,22 +152,22 @@ void tst_QFxLayouts::test_grid() QCOMPARE(five->y(), 50.0); } -void tst_QFxLayouts::test_grid_spacing() +void tst_QmlGraphicsLayouts::test_grid_spacing() { QmlView *canvas = createView("data/grid-spacing.qml"); canvas->execute(); qApp->processEvents(); - QFxRect *one = canvas->root()->findChild("one"); + QmlGraphicsRect *one = canvas->root()->findChild("one"); QVERIFY(one != 0); - QFxRect *two = canvas->root()->findChild("two"); + QmlGraphicsRect *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QFxRect *three = canvas->root()->findChild("three"); + QmlGraphicsRect *three = canvas->root()->findChild("three"); QVERIFY(three != 0); - QFxRect *four = canvas->root()->findChild("four"); + QmlGraphicsRect *four = canvas->root()->findChild("four"); QVERIFY(four != 0); - QFxRect *five = canvas->root()->findChild("five"); + QmlGraphicsRect *five = canvas->root()->findChild("five"); QVERIFY(five != 0); QCOMPARE(one->x(), 0.0); @@ -182,7 +182,7 @@ void tst_QFxLayouts::test_grid_spacing() QCOMPARE(five->y(), 54.0); } -QmlView *tst_QFxLayouts::createView(const QString &filename) +QmlView *tst_QmlGraphicsLayouts::createView(const QString &filename) { QmlView *canvas = new QmlView(0); @@ -195,6 +195,6 @@ QmlView *tst_QFxLayouts::createView(const QString &filename) } -QTEST_MAIN(tst_QFxLayouts) +QTEST_MAIN(tst_QmlGraphicsLayouts) #include "tst_layouts.moc" diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 1875836..be65338 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -6,11 +6,11 @@ #include #include -class tst_QFxListView : public QObject +class tst_QmlGraphicsListView : public QObject { Q_OBJECT public: - tst_QFxListView(); + tst_QmlGraphicsListView(); private slots: // Test both QListModelInterface and QAbstractItemModel model types @@ -33,9 +33,9 @@ private: template void removed(); QmlView *createView(const QString &filename); template - T *findItem(QFxItem *parent, const QString &id, int index=-1); + T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); template - QList findItems(QFxItem *parent, const QString &objectName); + QList findItems(QmlGraphicsItem *parent, const QString &objectName); }; class TestModel : public QListModelInterface @@ -164,12 +164,12 @@ private: QList > list; }; -tst_QFxListView::tst_QFxListView() +tst_QmlGraphicsListView::tst_QmlGraphicsListView() { } template -void tst_QFxListView::items() +void tst_QmlGraphicsListView::items() { QmlView *canvas = createView(SRCDIR "/data/listview.qml"); @@ -184,19 +184,19 @@ void tst_QFxListView::items() canvas->execute(); qApp->processEvents(); - QFxFlickable *listview = findItem(canvas->root(), "list"); + QmlGraphicsFlickable *listview = findItem(canvas->root(), "list"); QVERIFY(listview != 0); - QFxItem *viewport = listview->viewport(); + QmlGraphicsItem *viewport = listview->viewport(); QVERIFY(viewport != 0); QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item for (int i = 0; i < model.count(); ++i) { - QFxText *name = findItem(viewport, "textName", i); + QmlGraphicsText *name = findItem(viewport, "textName", i); QVERIFY(name != 0); QCOMPARE(name->text(), model.name(i)); - QFxText *number = findItem(viewport, "textNumber", i); + QmlGraphicsText *number = findItem(viewport, "textNumber", i); QVERIFY(number != 0); QCOMPARE(number->text(), model.number(i)); } @@ -205,7 +205,7 @@ void tst_QFxListView::items() } template -void tst_QFxListView::changed() +void tst_QmlGraphicsListView::changed() { QmlView *canvas = createView(SRCDIR "/data/listview.qml"); @@ -220,17 +220,17 @@ void tst_QFxListView::changed() canvas->execute(); qApp->processEvents(); - QFxFlickable *listview = findItem(canvas->root(), "list"); + QmlGraphicsFlickable *listview = findItem(canvas->root(), "list"); QVERIFY(listview != 0); - QFxItem *viewport = listview->viewport(); + QmlGraphicsItem *viewport = listview->viewport(); QVERIFY(viewport != 0); model.modifyItem(1, "Will", "9876"); - QFxText *name = findItem(viewport, "textName", 1); + QmlGraphicsText *name = findItem(viewport, "textName", 1); QVERIFY(name != 0); QCOMPARE(name->text(), model.name(1)); - QFxText *number = findItem(viewport, "textNumber", 1); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); QVERIFY(number != 0); QCOMPARE(number->text(), model.number(1)); @@ -238,7 +238,7 @@ void tst_QFxListView::changed() } template -void tst_QFxListView::inserted() +void tst_QmlGraphicsListView::inserted() { QmlView *canvas = createView(SRCDIR "/data/listview.qml"); @@ -253,10 +253,10 @@ void tst_QFxListView::inserted() canvas->execute(); qApp->processEvents(); - QFxListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); QVERIFY(listview != 0); - QFxItem *viewport = listview->viewport(); + QmlGraphicsItem *viewport = listview->viewport(); QVERIFY(viewport != 0); model.insertItem(1, "Will", "9876"); @@ -266,16 +266,16 @@ void tst_QFxListView::inserted() QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - QFxText *name = findItem(viewport, "textName", 1); + QmlGraphicsText *name = findItem(viewport, "textName", 1); QVERIFY(name != 0); QCOMPARE(name->text(), model.name(1)); - QFxText *number = findItem(viewport, "textNumber", 1); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); QVERIFY(number != 0); QCOMPARE(number->text(), model.number(1)); // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { - QFxItem *item = findItem(viewport, "wrapper", i); + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); QVERIFY(item->y() == i*20); } @@ -286,10 +286,10 @@ void tst_QFxListView::inserted() QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - name = findItem(viewport, "textName", 0); + name = findItem(viewport, "textName", 0); QVERIFY(name != 0); QCOMPARE(name->text(), model.name(0)); - number = findItem(viewport, "textNumber", 0); + number = findItem(viewport, "textNumber", 0); QVERIFY(number != 0); QCOMPARE(number->text(), model.number(0)); @@ -297,7 +297,7 @@ void tst_QFxListView::inserted() // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { - QFxItem *item = findItem(viewport, "wrapper", i); + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); QVERIFY(item->y() == i*20); } @@ -305,7 +305,7 @@ void tst_QFxListView::inserted() } template -void tst_QFxListView::removed() +void tst_QmlGraphicsListView::removed() { QmlView *canvas = createView(SRCDIR "/data/listview.qml"); @@ -319,10 +319,10 @@ void tst_QFxListView::removed() canvas->execute(); qApp->processEvents(); - QFxListView *listview = findItem(canvas->root(), "list"); + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); QVERIFY(listview != 0); - QFxItem *viewport = listview->viewport(); + QmlGraphicsItem *viewport = listview->viewport(); QVERIFY(viewport != 0); model.removeItem(1); @@ -330,17 +330,17 @@ void tst_QFxListView::removed() // let transitions settle. QTest::qWait(1000); - QFxText *name = findItem(viewport, "textName", 1); + QmlGraphicsText *name = findItem(viewport, "textName", 1); QVERIFY(name != 0); QCOMPARE(name->text(), model.name(1)); - QFxText *number = findItem(viewport, "textNumber", 1); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); QVERIFY(number != 0); QCOMPARE(number->text(), model.number(1)); // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); + int itemCount = findItems(viewport, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QFxItem *item = findItem(viewport, "wrapper", i); + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); QVERIFY(item->y() == i*20); @@ -352,17 +352,17 @@ void tst_QFxListView::removed() // let transitions settle. QTest::qWait(1000); - name = findItem(viewport, "textName", 0); + name = findItem(viewport, "textName", 0); QVERIFY(name != 0); QCOMPARE(name->text(), model.name(0)); - number = findItem(viewport, "textNumber", 0); + number = findItem(viewport, "textNumber", 0); QVERIFY(number != 0); QCOMPARE(number->text(), model.number(0)); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(viewport, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QFxItem *item = findItem(viewport, "wrapper", i); + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); QCOMPARE(item->y(),i*20.0 + 20.0); @@ -374,9 +374,9 @@ void tst_QFxListView::removed() QTest::qWait(1000); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(viewport, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QFxItem *item = findItem(viewport, "wrapper", i); + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); QCOMPARE(item->y(),i*20.0+20.0); @@ -392,7 +392,7 @@ void tst_QFxListView::removed() // Confirm items positioned correctly for (int i = 2; i < 18; ++i) { - QFxItem *item = findItem(viewport, "wrapper", i); + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); QCOMPARE(item->y(),40+i*20.0); @@ -403,9 +403,9 @@ void tst_QFxListView::removed() QTest::qWait(1000); // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); + itemCount = findItems(viewport, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QFxItem *item = findItem(viewport, "wrapper", i); + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); QCOMPARE(item->y(),40+i*20.0); @@ -414,47 +414,47 @@ void tst_QFxListView::removed() delete canvas; } -void tst_QFxListView::qListModelInterface_items() +void tst_QmlGraphicsListView::qListModelInterface_items() { items(); } -void tst_QFxListView::qAbstractItemModel_items() +void tst_QmlGraphicsListView::qAbstractItemModel_items() { items(); } -void tst_QFxListView::qListModelInterface_changed() +void tst_QmlGraphicsListView::qListModelInterface_changed() { changed(); } -void tst_QFxListView::qAbstractItemModel_changed() +void tst_QmlGraphicsListView::qAbstractItemModel_changed() { changed(); } -void tst_QFxListView::qListModelInterface_inserted() +void tst_QmlGraphicsListView::qListModelInterface_inserted() { inserted(); } -void tst_QFxListView::qAbstractItemModel_inserted() +void tst_QmlGraphicsListView::qAbstractItemModel_inserted() { inserted(); } -void tst_QFxListView::qListModelInterface_removed() +void tst_QmlGraphicsListView::qListModelInterface_removed() { removed(); } -void tst_QFxListView::qAbstractItemModel_removed() +void tst_QmlGraphicsListView::qAbstractItemModel_removed() { removed(); } -QmlView *tst_QFxListView::createView(const QString &filename) +QmlView *tst_QmlGraphicsListView::createView(const QString &filename) { QmlView *canvas = new QmlView(0); canvas->setFixedSize(240,320); @@ -472,12 +472,12 @@ QmlView *tst_QFxListView::createView(const QString &filename) item must also evaluate the {index} expression equal to index */ template -T *tst_QFxListView::findItem(QFxItem *parent, const QString &objectName, int index) +T *tst_QmlGraphicsListView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index) { const QMetaObject &mo = T::staticMetaObject; //qDebug() << parent->QGraphicsObject::children().count() << "children"; for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { - QFxItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); if(!item) continue; //qDebug() << "try" << item; @@ -500,13 +500,13 @@ T *tst_QFxListView::findItem(QFxItem *parent, const QString &objectName, int ind } template -QList tst_QFxListView::findItems(QFxItem *parent, const QString &objectName) +QList tst_QmlGraphicsListView::findItems(QmlGraphicsItem *parent, const QString &objectName) { QList items; const QMetaObject &mo = T::staticMetaObject; //qDebug() << parent->QGraphicsObject::children().count() << "children"; for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { - QFxItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); if(!item) continue; //qDebug() << "try" << item; @@ -519,6 +519,6 @@ QList tst_QFxListView::findItems(QFxItem *parent, const QString &objectName) } -QTEST_MAIN(tst_QFxListView) +QTEST_MAIN(tst_QmlGraphicsListView) #include "tst_listview.moc" diff --git a/tests/auto/declarative/pathview/tst_pathview.cpp b/tests/auto/declarative/pathview/tst_pathview.cpp index 6e670bf..d5b922a 100644 --- a/tests/auto/declarative/pathview/tst_pathview.cpp +++ b/tests/auto/declarative/pathview/tst_pathview.cpp @@ -7,11 +7,11 @@ #include #include -class tst_QFxPathView : public QObject +class tst_QmlGraphicsPathView : public QObject { Q_OBJECT public: - tst_QFxPathView(); + tst_QmlGraphicsPathView(); private slots: void items(); @@ -21,7 +21,7 @@ private slots: private: QmlView *createView(const QString &filename); template - T *findItem(QFxItem *parent, const QString &id, int index=-1); + T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); }; class TestModel : public QListModelInterface @@ -95,11 +95,11 @@ private: QList > list; }; -tst_QFxPathView::tst_QFxPathView() +tst_QmlGraphicsPathView::tst_QmlGraphicsPathView() { } -void tst_QFxPathView::items() +void tst_QmlGraphicsPathView::items() { QmlView *canvas = createView(SRCDIR "/data/pathview.qml"); @@ -114,16 +114,16 @@ void tst_QFxPathView::items() canvas->execute(); qApp->processEvents(); - QFxPathView *pathview = findItem(canvas->root(), "view"); + QmlGraphicsPathView *pathview = findItem(canvas->root(), "view"); QVERIFY(pathview != 0); QCOMPARE(pathview->childItems().count(), model.count()); // assumes all are visible for (int i = 0; i < model.count(); ++i) { - QFxText *name = findItem(pathview, "textName", i); + QmlGraphicsText *name = findItem(pathview, "textName", i); QVERIFY(name != 0); QCOMPARE(name->text(), model.name(i)); - QFxText *number = findItem(pathview, "textNumber", i); + QmlGraphicsText *number = findItem(pathview, "textNumber", i); QVERIFY(number != 0); QCOMPARE(number->text(), model.number(i)); } @@ -131,7 +131,7 @@ void tst_QFxPathView::items() delete canvas; } -void tst_QFxPathView::pathMoved() +void tst_QmlGraphicsPathView::pathMoved() { QmlView *canvas = createView(SRCDIR "/data/pathview.qml"); @@ -147,12 +147,12 @@ void tst_QFxPathView::pathMoved() canvas->execute(); qApp->processEvents(); - QFxPathView *pathview = findItem(canvas->root(), "view"); + QmlGraphicsPathView *pathview = findItem(canvas->root(), "view"); QVERIFY(pathview != 0); - QFxRect *firstItem = findItem(pathview, "wrapper", 0); + QmlGraphicsRect *firstItem = findItem(pathview, "wrapper", 0); QVERIFY(firstItem); - QFxPath *path = qobject_cast(pathview->path()); + QmlGraphicsPath *path = qobject_cast(pathview->path()); QVERIFY(path); QPointF start = path->pointAt(0.0); QPointF offset;//Center of item is at point, but pos is from corner @@ -163,7 +163,7 @@ void tst_QFxPathView::pathMoved() QTest::qWait(1000);//Moving is animated? for(int i=0; i(pathview, "wrapper", i); + QmlGraphicsRect *curItem = findItem(pathview, "wrapper", i); QCOMPARE(curItem->pos() + offset, path->pointAt(0.1 + i*0.25)); } @@ -174,7 +174,7 @@ void tst_QFxPathView::pathMoved() delete canvas; } -void tst_QFxPathView::limitedItems() +void tst_QmlGraphicsPathView::limitedItems() { QmlView *canvas = createView(SRCDIR "/data/pathview.qml"); @@ -188,32 +188,32 @@ void tst_QFxPathView::limitedItems() canvas->execute(); qApp->processEvents(); - QFxPathView *pathview = findItem(canvas->root(), "view"); + QmlGraphicsPathView *pathview = findItem(canvas->root(), "view"); QVERIFY(pathview != 0); pathview->setPathItemCount(10); QCOMPARE(pathview->pathItemCount(), 10); - QFxRect *testItem = findItem(pathview, "wrapper", 0); + QmlGraphicsRect *testItem = findItem(pathview, "wrapper", 0); QVERIFY(testItem != 0); - testItem = findItem(pathview, "wrapper", 9); + testItem = findItem(pathview, "wrapper", 9); QVERIFY(testItem != 0); - testItem = findItem(pathview, "wrapper", 10); + testItem = findItem(pathview, "wrapper", 10); QVERIFY(testItem == 0); pathview->setCurrentIndex(50); QTest::qWait(5100);//Moving is animated and it's travelling far - should be reconsidered. - testItem = findItem(pathview, "wrapper", 0); + testItem = findItem(pathview, "wrapper", 0); QVERIFY(testItem == 0); - testItem = findItem(pathview, "wrapper", 1); + testItem = findItem(pathview, "wrapper", 1); QVERIFY(testItem == 0); - testItem = findItem(pathview, "wrapper", 9); + testItem = findItem(pathview, "wrapper", 9); QVERIFY(testItem == 0); - testItem = findItem(pathview, "wrapper", 50); + testItem = findItem(pathview, "wrapper", 50); QVERIFY(testItem != 0); } -QmlView *tst_QFxPathView::createView(const QString &filename) +QmlView *tst_QmlGraphicsPathView::createView(const QString &filename) { QmlView *canvas = new QmlView(0); canvas->setFixedSize(240,320); @@ -231,11 +231,11 @@ QmlView *tst_QFxPathView::createView(const QString &filename) item must also evaluate the {index} expression equal to index */ template -T *tst_QFxPathView::findItem(QFxItem *parent, const QString &objectName, int index) +T *tst_QmlGraphicsPathView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index) { const QMetaObject &mo = T::staticMetaObject; for (int i = 0; i < parent->children().count(); ++i) { - QFxItem *item = qobject_cast(parent->children().at(i)); + QmlGraphicsItem *item = qobject_cast(parent->children().at(i)); if(!item) continue; if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { @@ -256,6 +256,6 @@ T *tst_QFxPathView::findItem(QFxItem *parent, const QString &objectName, int ind return 0; } -QTEST_MAIN(tst_QFxPathView) +QTEST_MAIN(tst_QmlGraphicsPathView) #include "tst_pathview.moc" diff --git a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp index 2109898..99fecc3 100644 --- a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp +++ b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp @@ -41,7 +41,7 @@ tst_qfxloader::tst_qfxloader() void tst_qfxloader::url() { QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"Rect120x60.qml\" }"), QUrl("file://" SRCDIR "/")); - QFxLoader *loader = qobject_cast(component.create()); + QmlGraphicsLoader *loader = qobject_cast(component.create()); QVERIFY(loader != 0); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); @@ -51,10 +51,10 @@ void tst_qfxloader::url() void tst_qfxloader::component() { QmlComponent component(&engine, QUrl("file://" SRCDIR "/SetSourceComponent.qml")); - QFxItem *item = qobject_cast(component.create()); + QmlGraphicsItem *item = qobject_cast(component.create()); QVERIFY(item); - QFxLoader *loader = qobject_cast(item->QGraphicsObject::children().at(1)); + QmlGraphicsLoader *loader = qobject_cast(item->QGraphicsObject::children().at(1)); QVERIFY(loader); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); @@ -64,7 +64,7 @@ void tst_qfxloader::component() void tst_qfxloader::sizeLoaderToItem() { QmlComponent component(&engine, QUrl("file://" SRCDIR "/SizeToItem.qml")); - QFxLoader *loader = qobject_cast(component.create()); + QmlGraphicsLoader *loader = qobject_cast(component.create()); QVERIFY(loader != 0); QCOMPARE(loader->width(), 120.0); QCOMPARE(loader->height(), 60.0); @@ -73,12 +73,12 @@ void tst_qfxloader::sizeLoaderToItem() void tst_qfxloader::sizeItemToLoader() { QmlComponent component(&engine, QUrl("file://" SRCDIR "/SizeToLoader.qml")); - QFxLoader *loader = qobject_cast(component.create()); + QmlGraphicsLoader *loader = qobject_cast(component.create()); QVERIFY(loader != 0); QCOMPARE(loader->width(), 200.0); QCOMPARE(loader->height(), 80.0); - QFxItem *rect = loader->item(); + QmlGraphicsItem *rect = loader->item(); QVERIFY(rect); QCOMPARE(rect->width(), 200.0); QCOMPARE(rect->height(), 80.0); @@ -87,12 +87,12 @@ void tst_qfxloader::sizeItemToLoader() void tst_qfxloader::noResize() { QmlComponent component(&engine, QUrl("file://" SRCDIR "/NoResize.qml")); - QFxLoader *loader = qobject_cast(component.create()); + QmlGraphicsLoader *loader = qobject_cast(component.create()); QVERIFY(loader != 0); QCOMPARE(loader->width(), 200.0); QCOMPARE(loader->height(), 80.0); - QFxItem *rect = loader->item(); + QmlGraphicsItem *rect = loader->item(); QVERIFY(rect); QCOMPARE(rect->width(), 120.0); QCOMPARE(rect->height(), 60.0); diff --git a/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp b/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp index 5e24831..e735066 100644 --- a/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp +++ b/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp @@ -59,7 +59,7 @@ static const bool localfile_optimized = false; void tst_qfxpixmapcache::single_data() { - // Note, since QFxPixmapCache is shared, tests affect each other! + // Note, since QmlGraphicsPixmapCache is shared, tests affect each other! // so use different files fore all test functions. QTest::addColumn("target"); @@ -90,7 +90,7 @@ void tst_qfxpixmapcache::single() QPixmap pixmap; QVERIFY(pixmap.width() <= 0); // Check Qt assumption - QNetworkReply *reply= QFxPixmapCache::get(&engine, target, &pixmap); + QNetworkReply *reply= QmlGraphicsPixmapCache::get(&engine, target, &pixmap); if (incache) { QVERIFY(!reply); @@ -108,20 +108,20 @@ void tst_qfxpixmapcache::single() QVERIFY(!QTestEventLoop::instance().timeout()); QVERIFY(getter.gotslot); if (exists) { - QVERIFY(QFxPixmapCache::find(target, &pixmap)); + QVERIFY(QmlGraphicsPixmapCache::find(target, &pixmap)); QVERIFY(pixmap.width() > 0); } else { - QVERIFY(!QFxPixmapCache::find(target, &pixmap)); + QVERIFY(!QmlGraphicsPixmapCache::find(target, &pixmap)); QVERIFY(pixmap.width() <= 0); } } - QCOMPARE(QFxPixmapCache::pendingRequests(), 0); + QCOMPARE(QmlGraphicsPixmapCache::pendingRequests(), 0); } void tst_qfxpixmapcache::parallel_data() { - // Note, since QFxPixmapCache is shared, tests affect each other! + // Note, since QmlGraphicsPixmapCache is shared, tests affect each other! // so use different files fore all test functions. QTest::addColumn("target1"); @@ -187,7 +187,7 @@ void tst_qfxpixmapcache::parallel() for (int i=0; i 0); @@ -200,10 +200,10 @@ void tst_qfxpixmapcache::parallel() } QCOMPARE(incache+slotters, targets.count()); - QCOMPARE(QFxPixmapCache::pendingRequests(), requests); + QCOMPARE(QmlGraphicsPixmapCache::pendingRequests(), requests); if (cancel >= 0) { - QFxPixmapCache::cancelGet(targets.at(cancel), getters[cancel]); + QmlGraphicsPixmapCache::cancelGet(targets.at(cancel), getters[cancel]); slotters--; } @@ -220,14 +220,14 @@ void tst_qfxpixmapcache::parallel() } else { QVERIFY(getters[i]->gotslot); QPixmap pixmap; - QVERIFY(QFxPixmapCache::find(targets[i], &pixmap)); + QVERIFY(QmlGraphicsPixmapCache::find(targets[i], &pixmap)); QVERIFY(pixmap.width() > 0); } delete getters[i]; } } - QCOMPARE(QFxPixmapCache::pendingRequests(), 0); + QCOMPARE(QmlGraphicsPixmapCache::pendingRequests(), 0); } QTEST_MAIN(tst_qfxpixmapcache) diff --git a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp index cae85a4..12cac68 100644 --- a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp +++ b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp @@ -36,7 +36,7 @@ private: QList horizontalAlignmentments; QStringList styleStrings; - QList styles; + QList styles; QStringList colorStrings; @@ -72,10 +72,10 @@ tst_qfxtext::tst_qfxtext() << "Raised" << "Sunken"; - styles << QFxText::Normal - << QFxText::Outline - << QFxText::Raised - << QFxText::Sunken; + styles << QmlGraphicsText::Normal + << QmlGraphicsText::Outline + << QmlGraphicsText::Raised + << QmlGraphicsText::Sunken; colorStrings << "aliceblue" << "antiquewhite" @@ -100,7 +100,7 @@ void tst_qfxtext::text() { { QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QVERIFY(textObject != 0); QCOMPARE(textObject->text(), QString("")); @@ -110,7 +110,7 @@ void tst_qfxtext::text() { QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QVERIFY(textObject != 0); QCOMPARE(textObject->text(), standard.at(i)); @@ -120,7 +120,7 @@ void tst_qfxtext::text() { QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QVERIFY(textObject != 0); QString expected = richText.at(i); @@ -133,7 +133,7 @@ void tst_qfxtext::width() // uses Font metrics to find the width for standard and document to find the width for rich { QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 0.); } @@ -146,7 +146,7 @@ void tst_qfxtext::width() QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), qreal(metricWidth)); } @@ -161,7 +161,7 @@ void tst_qfxtext::width() QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), qreal(documentWidth)); } @@ -174,7 +174,7 @@ void tst_qfxtext::wrap() // for specified width and wrap set true { QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\"; wrap: true; width: 300 }", QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 300.); } @@ -183,7 +183,7 @@ void tst_qfxtext::wrap() { QString componentStr = "import Qt 4.6\nText { wrap: true; width: 300; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 300.); } @@ -192,7 +192,7 @@ void tst_qfxtext::wrap() { QString componentStr = "import Qt 4.6\nText { wrap: true; width: 300; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 300.); } @@ -209,7 +209,7 @@ void tst_qfxtext::elide() { QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 300 }").toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 300.); } @@ -218,7 +218,7 @@ void tst_qfxtext::elide() { QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 300.); } @@ -228,7 +228,7 @@ void tst_qfxtext::elide() { QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->width(), 300.); } @@ -246,7 +246,7 @@ void tst_qfxtext::horizontalAlignment() { QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); } @@ -258,7 +258,7 @@ void tst_qfxtext::horizontalAlignment() { QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); } @@ -276,7 +276,7 @@ void tst_qfxtext::verticalAlignment() { QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); } @@ -288,7 +288,7 @@ void tst_qfxtext::verticalAlignment() { QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); } @@ -302,7 +302,7 @@ void tst_qfxtext::font() { QString componentStr = "import Qt 4.6\nText { font.pointSize: 40; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->font().pointSize(), 40); QCOMPARE(textObject->font().bold(), false); @@ -312,7 +312,7 @@ void tst_qfxtext::font() { QString componentStr = "import Qt 4.6\nText { font.bold: true; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->font().bold(), true); QCOMPARE(textObject->font().italic(), false); @@ -321,7 +321,7 @@ void tst_qfxtext::font() { QString componentStr = "import Qt 4.6\nText { font.italic: true; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->font().italic(), true); QCOMPARE(textObject->font().bold(), false); @@ -330,7 +330,7 @@ void tst_qfxtext::font() { QString componentStr = "import Qt 4.6\nText { font.family: \"Helvetica\"; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->font().family(), QString("Helvetica")); QCOMPARE(textObject->font().bold(), false); @@ -340,7 +340,7 @@ void tst_qfxtext::font() { QString componentStr = "import Qt 4.6\nText { font.family: \"\"; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->font().family(), QString("")); } @@ -353,7 +353,7 @@ void tst_qfxtext::style() { QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE((int)textObject->style(), (int)styles.at(i)); QCOMPARE(textObject->styleColor(), QColor()); @@ -367,7 +367,7 @@ void tst_qfxtext::color() { QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); QCOMPARE(textObject->styleColor(), QColor()); @@ -377,7 +377,7 @@ void tst_qfxtext::color() { QString componentStr = "import Qt 4.6\nText { styleColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(i))); // default color to black? @@ -390,7 +390,7 @@ void tst_qfxtext::color() { QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; styleColor: \"" + colorStrings.at(j) + "\"; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(j))); @@ -403,7 +403,7 @@ void tst_qfxtext::color() QString componentStr = "import Qt 4.6\nText { color: \"" + colorStr + "\"; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QFxText *textObject = qobject_cast(textComponent.create()); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE(textObject->color(), testColor); } diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp index f78e564..0565fd4 100644 --- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp +++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp @@ -97,7 +97,7 @@ void tst_qfxtextedit::text() { { QmlComponent texteditComponent(&engine, "import Qt 4.6\nTextEdit { text: \"\" }", QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->text(), QString("")); @@ -107,7 +107,7 @@ void tst_qfxtextedit::text() { QString componentStr = "import Qt 4.6\nTextEdit { text: \"" + standard.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->text(), standard.at(i)); @@ -117,7 +117,7 @@ void tst_qfxtextedit::text() { QString componentStr = "import Qt 4.6\nTextEdit { text: \"" + richText.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QString actual = textEditObject->text(); @@ -134,7 +134,7 @@ void tst_qfxtextedit::width() // uses Font metrics to find the width for standard and document to find the width for rich { QmlComponent texteditComponent(&engine, "import Qt 4.6\nTextEdit { text: \"\" }", QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->width(), 1.);//+1 for cursor @@ -148,7 +148,7 @@ void tst_qfxtextedit::width() QString componentStr = "import Qt 4.6\nTextEdit { text: \"" + standard.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->width(), qreal(metricWidth + 1 + 3));//+3 is the current way of accounting for space between cursor and last character. @@ -164,7 +164,7 @@ void tst_qfxtextedit::width() QString componentStr = "import Qt 4.6\nTextEdit { text: \"" + richText.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->width(), qreal(documentWidth + 1 + 3)); @@ -176,7 +176,7 @@ void tst_qfxtextedit::wrap() // for specified width and wrap set true { QmlComponent texteditComponent(&engine, "import Qt 4.6\nTextEdit { text: \"\"; wrap: true; width: 300 }", QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->width(), 300.); @@ -186,7 +186,7 @@ void tst_qfxtextedit::wrap() { QString componentStr = "import Qt 4.6\nTextEdit { wrap: true; width: 300; text: \"" + standard.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->width(), 300.); @@ -196,7 +196,7 @@ void tst_qfxtextedit::wrap() { QString componentStr = "import Qt 4.6\nTextEdit { wrap: true; width: 300; text: \"" + richText.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->width(), 300.); @@ -215,7 +215,7 @@ void tst_qfxtextedit::hAlign() { QString componentStr = "import Qt 4.6\nTextEdit { horizontalAlignment: \"" + hAlignmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE((int)textEditObject->hAlign(), (int)hAlignments.at(j)); @@ -228,7 +228,7 @@ void tst_qfxtextedit::hAlign() { QString componentStr = "import Qt 4.6\nTextEdit { horizontalAlignment: \"" + hAlignmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE((int)textEditObject->hAlign(), (int)hAlignments.at(j)); @@ -247,7 +247,7 @@ void tst_qfxtextedit::vAlign() { QString componentStr = "import Qt 4.6\nTextEdit { verticalAlignment: \"" + vAlignmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE((int)textEditObject->vAlign(), (int)vAlignments.at(j)); @@ -260,7 +260,7 @@ void tst_qfxtextedit::vAlign() { QString componentStr = "import Qt 4.6\nTextEdit { verticalAlignment: \"" + vAlignmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE((int)textEditObject->vAlign(), (int)vAlignments.at(j)); @@ -275,7 +275,7 @@ void tst_qfxtextedit::font() { QString componentStr = "import Qt 4.6\nTextEdit { font.pointSize: 40; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->font().pointSize(), 40); @@ -286,7 +286,7 @@ void tst_qfxtextedit::font() { QString componentStr = "import Qt 4.6\nTextEdit { font.bold: true; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->font().bold(), true); @@ -296,7 +296,7 @@ void tst_qfxtextedit::font() { QString componentStr = "import Qt 4.6\nTextEdit { font.italic: true; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->font().italic(), true); @@ -306,7 +306,7 @@ void tst_qfxtextedit::font() { QString componentStr = "import Qt 4.6\nTextEdit { font.family: \"Helvetica\"; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->font().family(), QString("Helvetica")); @@ -317,7 +317,7 @@ void tst_qfxtextedit::font() { QString componentStr = "import Qt 4.6\nTextEdit { font.family: \"\"; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->font().family(), QString("")); @@ -331,7 +331,7 @@ void tst_qfxtextedit::color() { QString componentStr = "import Qt 4.6\nTextEdit { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); //qDebug() << "textEditObject: " << textEditObject->color() << "vs. " << QColor(colorStrings.at(i)); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->color(), QColor(colorStrings.at(i))); @@ -344,7 +344,7 @@ void tst_qfxtextedit::color() QString componentStr = "import Qt 4.6\nTextEdit { color: \"" + colorStr + "\"; text: \"Hello World\" }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); QCOMPARE(textEditObject->color(), testColor); @@ -356,7 +356,7 @@ void tst_qfxtextedit::selection() QString testStr = standard[0];//TODO: What should happen for multiline/rich text? QString componentStr = "import Qt 4.6\nTextEdit { text: \""+ testStr +"\"; }"; QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextEdit *textEditObject = qobject_cast(texteditComponent.create()); + QmlGraphicsTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); @@ -437,12 +437,12 @@ void tst_qfxtextedit::cursorDelegate() view->execute(); view->show(); view->setFocus(); - QFxTextEdit *textEditObject = view->root()->findChild("textEditObject"); + QmlGraphicsTextEdit *textEditObject = view->root()->findChild("textEditObject"); QVERIFY(textEditObject != 0); - QVERIFY(textEditObject->findChild("cursorInstance")); + QVERIFY(textEditObject->findChild("cursorInstance")); //Test Delegate gets created textEditObject->setFocus(true); - QFxItem* delegateObject = textEditObject->findChild("cursorInstance"); + QmlGraphicsItem* delegateObject = textEditObject->findChild("cursorInstance"); QVERIFY(delegateObject); //Test Delegate gets moved for(int i=0; i<= textEditObject->text().length(); i++){ @@ -455,7 +455,7 @@ void tst_qfxtextedit::cursorDelegate() QCOMPARE(textEditObject->cursorRect().y(), qRound(delegateObject->y())); //Test Delegate gets deleted textEditObject->setCursorDelegate(0); - QVERIFY(!textEditObject->findChild("cursorInstance")); + QVERIFY(!textEditObject->findChild("cursorInstance")); } /* @@ -471,7 +471,7 @@ void tst_qfxtextedit::navigation() QVERIFY(canvas->root() != 0); - QFxItem *input = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); + QmlGraphicsItem *input = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); QVERIFY(input != 0); QTRY_VERIFY(input->hasFocus() == true); diff --git a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp index 069574c..e4930f6 100644 --- a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp +++ b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include class tst_qfxtextinput : public QObject @@ -60,7 +60,7 @@ void tst_qfxtextinput::text() { { QmlComponent textinputComponent(&engine, "import Qt 4.6\nTextInput { text: \"\" }", QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); QCOMPARE(textinputObject->text(), QString("")); @@ -70,7 +70,7 @@ void tst_qfxtextinput::text() { QString componentStr = "import Qt 4.6\nTextInput { text: \"" + standard.at(i) + "\" }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); QCOMPARE(textinputObject->text(), standard.at(i)); @@ -83,7 +83,7 @@ void tst_qfxtextinput::width() // uses Font metrics to find the width for standard { QmlComponent textinputComponent(&engine, "import Qt 4.6\nTextInput { text: \"\" }", QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); QCOMPARE(textinputObject->width(), 1.);//1 for the cursor @@ -97,7 +97,7 @@ void tst_qfxtextinput::width() QString componentStr = "import Qt 4.6\nTextInput { text: \"" + standard.at(i) + "\" }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); QCOMPARE(textinputObject->width(), qreal(metricWidth) + 1.);//1 for the cursor @@ -110,7 +110,7 @@ void tst_qfxtextinput::font() { QString componentStr = "import Qt 4.6\nTextInput { font.pointSize: 40; text: \"Hello World\" }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); QCOMPARE(textinputObject->font().pointSize(), 40); @@ -121,7 +121,7 @@ void tst_qfxtextinput::font() { QString componentStr = "import Qt 4.6\nTextInput { font.bold: true; text: \"Hello World\" }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); QCOMPARE(textinputObject->font().bold(), true); @@ -131,7 +131,7 @@ void tst_qfxtextinput::font() { QString componentStr = "import Qt 4.6\nTextInput { font.italic: true; text: \"Hello World\" }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); QCOMPARE(textinputObject->font().italic(), true); @@ -141,7 +141,7 @@ void tst_qfxtextinput::font() { QString componentStr = "import Qt 4.6\nTextInput { font.family: \"Helvetica\"; text: \"Hello World\" }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); QCOMPARE(textinputObject->font().family(), QString("Helvetica")); @@ -152,7 +152,7 @@ void tst_qfxtextinput::font() { QString componentStr = "import Qt 4.6\nTextInput { font.family: \"\"; text: \"Hello World\" }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); QCOMPARE(textinputObject->font().family(), QString("")); @@ -166,7 +166,7 @@ void tst_qfxtextinput::color() { QString componentStr = "import Qt 4.6\nTextInput { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); //qDebug() << "textinputObject: " << textinputObject->color() << "vs. " << QColor(colorStrings.at(i)); QVERIFY(textinputObject != 0); QCOMPARE(textinputObject->color(), QColor(colorStrings.at(i))); @@ -179,7 +179,7 @@ void tst_qfxtextinput::color() QString componentStr = "import Qt 4.6\nTextInput { color: \"" + colorStr + "\"; text: \"Hello World\" }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); QCOMPARE(textinputObject->color(), testColor); @@ -191,7 +191,7 @@ void tst_qfxtextinput::selection() QString testStr = standard[0]; QString componentStr = "import Qt 4.6\nTextInput { text: \""+ testStr +"\"; }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); @@ -270,7 +270,7 @@ void tst_qfxtextinput::maxLength() { QString componentStr = "import Qt 4.6\nTextInput { maximumLength: 10; }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); QVERIFY(textinputObject->text().isEmpty()); foreach(const QString &str, standard){ @@ -285,7 +285,7 @@ void tst_qfxtextinput::masks() { QString componentStr = "import Qt 4.6\nTextInput { maximumLength: 10; }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); //TODO: Me @@ -295,7 +295,7 @@ void tst_qfxtextinput::validators() { QString componentStr = "import Qt 4.6\nTextInput { maximumLength: 10; }"; QmlComponent textinputComponent(&engine, componentStr.toLatin1(), QUrl()); - QFxTextInput *textinputObject = qobject_cast(textinputComponent.create()); + QmlGraphicsTextInput *textinputObject = qobject_cast(textinputComponent.create()); QVERIFY(textinputObject != 0); //TODO: Me @@ -314,7 +314,7 @@ void tst_qfxtextinput::navigation() QVERIFY(canvas->root() != 0); - QFxItem *input = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); + QmlGraphicsItem *input = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); QVERIFY(input != 0); QTRY_VERIFY(input->hasFocus() == true); @@ -334,12 +334,12 @@ void tst_qfxtextinput::cursorDelegate() view->execute(); view->show(); view->setFocus(); - QFxTextInput *textInputObject = view->root()->findChild("textInputObject"); + QmlGraphicsTextInput *textInputObject = view->root()->findChild("textInputObject"); QVERIFY(textInputObject != 0); - QVERIFY(textInputObject->findChild("cursorInstance")); + QVERIFY(textInputObject->findChild("cursorInstance")); //Test Delegate gets created textInputObject->setFocus(true); - QFxItem* delegateObject = textInputObject->findChild("cursorInstance"); + QmlGraphicsItem* delegateObject = textInputObject->findChild("cursorInstance"); QVERIFY(delegateObject); //Test Delegate gets moved for(int i=0; i<= textInputObject->text().length(); i++){ @@ -353,7 +353,7 @@ void tst_qfxtextinput::cursorDelegate() QCOMPARE(textInputObject->cursorRect().y(), qRound(delegateObject->y())); //Test Delegate gets deleted textInputObject->setCursorDelegate(0); - QVERIFY(!textInputObject->findChild("cursorInstance")); + QVERIFY(!textInputObject->findChild("cursorInstance")); } void tst_qfxtextinput::simulateKey(QmlView *view, int key) diff --git a/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp index dc124ce..6e3336c 100644 --- a/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp +++ b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp @@ -68,7 +68,7 @@ void tst_qfxwebview::testBasicProperties() checkNoErrors(component); QWebSettings::enablePersistentStorage(tmpDir()); - QFxWebView *wv = qobject_cast(component.create()); + QmlGraphicsWebView *wv = qobject_cast(component.create()); QVERIFY(wv != 0); QTRY_COMPARE(wv->progress(), 1.0); QCOMPARE(wv->title(),QString("Basic")); @@ -87,7 +87,7 @@ void tst_qfxwebview::testBasicProperties() QCOMPARE(wv->preferredWidth(), 0); QCOMPARE(wv->zoomFactor(), 1.0); QCOMPARE(wv->url(), QUrl::fromLocalFile(SRCDIR "/data/basic.html")); - QCOMPARE(wv->status(), QFxWebView::Ready); + QCOMPARE(wv->status(), QmlGraphicsWebView::Ready); QVERIFY(wv->reloadAction()); QVERIFY(wv->reloadAction()->isEnabled()); QVERIFY(wv->backAction()); diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 6494c40..e2a4142 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -947,11 +947,11 @@ void tst_qmllanguage::importsLocal_data() QTest::newRow("local import") << "import \"subdir\"\n" // QT-613 "Test {}" - << "QFxRect"; + << "QmlGraphicsRect"; QTest::newRow("local import as") << "import \"subdir\" as T\n" "T.Test {}" - << "QFxRect"; + << "QmlGraphicsRect"; QTest::newRow("wrong local import as") << "import \"subdir\" as T\n" "Test {}" @@ -979,9 +979,9 @@ void tst_qmllanguage::importsRemote_data() + QtNetworkSettings::serverName() + "/qtest/declarative/qmllanguage"; - QTest::newRow("remote import") << "import \""+serverdir+"\"\nTest {}" << "QFxRect"; - QTest::newRow("remote import with subdir") << "import \""+serverdir+"\"\nTestSubDir {}" << "QFxText"; - QTest::newRow("remote import with local") << "import \""+serverdir+"\"\nTestLocal {}" << "QFxImage"; + QTest::newRow("remote import") << "import \""+serverdir+"\"\nTest {}" << "QmlGraphicsRect"; + QTest::newRow("remote import with subdir") << "import \""+serverdir+"\"\nTestSubDir {}" << "QmlGraphicsText"; + QTest::newRow("remote import with local") << "import \""+serverdir+"\"\nTestLocal {}" << "QmlGraphicsImage"; } void tst_qmllanguage::importsRemote() @@ -1002,11 +1002,11 @@ void tst_qmllanguage::importsInstalled_data() QTest::newRow("installed import 1") << "import com.nokia.installedtest 1.0\n" "InstalledTest {}" - << "QFxRect"; + << "QmlGraphicsRect"; QTest::newRow("installed import 2") << "import com.nokia.installedtest 1.4\n" "InstalledTest {}" - << "QFxText"; + << "QmlGraphicsText"; QTest::newRow("installed import visibility") // QT-614 << "import com.nokia.installedtest 1.4\n" "PrivateType {}" @@ -1030,36 +1030,36 @@ void tst_qmllanguage::importsOrder_data() "import com.nokia.installedtest 1.0\n" "import com.nokia.installedtest 1.4\n" "InstalledTest {}" - << "QFxText"; + << "QmlGraphicsText"; QTest::newRow("installed import overrides 2") << "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "InstalledTest {}" - << "QFxRect"; + << "QmlGraphicsRect"; QTest::newRow("installed import re-overrides 1") << "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "import com.nokia.installedtest 1.4\n" "InstalledTest {}" - << "QFxText"; + << "QmlGraphicsText"; QTest::newRow("installed import re-overrides 2") << "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "import com.nokia.installedtest 1.4\n" "import com.nokia.installedtest 1.0\n" "InstalledTest {}" - << "QFxRect"; + << "QmlGraphicsRect"; QTest::newRow("installed import versus builtin 1") << "import com.nokia.installedtest 1.5\n" "import Qt 4.6\n" "Rectangle {}" - << "QFxRect"; + << "QmlGraphicsRect"; QTest::newRow("installed import versus builtin 2") << "import Qt 4.6\n" "import com.nokia.installedtest 1.5\n" "Rectangle {}" - << "QFxText"; + << "QmlGraphicsText"; QTest::newRow("namespaces cannot be overridden by types 1") << "import Qt 4.6 as Rectangle\n" "import com.nokia.installedtest 1.5\n" @@ -1069,7 +1069,7 @@ void tst_qmllanguage::importsOrder_data() "import Qt 4.6 as Rectangle\n" "import com.nokia.installedtest 1.5\n" "Rectangle.Image {}" - << "QFxImage"; + << "QmlGraphicsImage"; } void tst_qmllanguage::importsOrder() diff --git a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp index 7d3cc43..d11771c 100644 --- a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp +++ b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp @@ -79,7 +79,7 @@ void tst_QmlPropertyMap::changed() QmlComponent component(&engine, "import Qt 4.6\nText { text: { testdata.key1 = 'Hello World'; 'X' } }", QUrl("file://")); QVERIFY(component.isReady()); - QFxText *txt = qobject_cast(component.create()); + QmlGraphicsText *txt = qobject_cast(component.create()); QVERIFY(txt); QCOMPARE(txt->text(), QString('X')); QCOMPARE(spy.count(), 1); diff --git a/tests/auto/declarative/repeater/tst_repeater.cpp b/tests/auto/declarative/repeater/tst_repeater.cpp index 68007a6..0622028 100644 --- a/tests/auto/declarative/repeater/tst_repeater.cpp +++ b/tests/auto/declarative/repeater/tst_repeater.cpp @@ -5,11 +5,11 @@ #include #include -class tst_QFxRepeater : public QObject +class tst_QmlGraphicsRepeater : public QObject { Q_OBJECT public: - tst_QFxRepeater(); + tst_QmlGraphicsRepeater(); private slots: void stringList(); @@ -20,7 +20,7 @@ private: T *findItem(QObject *parent, const QString &id); }; -tst_QFxRepeater::tst_QFxRepeater() +tst_QmlGraphicsRepeater::tst_QmlGraphicsRepeater() { } @@ -29,7 +29,7 @@ The Repeater element creates children at its own position in its parent's stacking order. In this test we insert a repeater between two other Text elements to test this. */ -void tst_QFxRepeater::stringList() +void tst_QmlGraphicsRepeater::stringList() { QmlView *canvas = createView(SRCDIR "/data/repeater.qml"); @@ -45,10 +45,10 @@ void tst_QFxRepeater::stringList() canvas->execute(); qApp->processEvents(); - QFxRepeater *repeater = findItem(canvas->root(), "repeater"); + QmlGraphicsRepeater *repeater = findItem(canvas->root(), "repeater"); QVERIFY(repeater != 0); - QFxItem *container = findItem(canvas->root(), "container"); + QmlGraphicsItem *container = findItem(canvas->root(), "container"); QVERIFY(container != 0); QCOMPARE(container->childItems().count(), data.count() + 3); @@ -57,21 +57,21 @@ void tst_QFxRepeater::stringList() for (int i = 0; i < container->childItems().count(); ++i) { if (i == 0) { - QFxText *name = qobject_cast(container->childItems().at(i)); + QmlGraphicsText *name = qobject_cast(container->childItems().at(i)); QVERIFY(name != 0); QCOMPARE(name->text(), QLatin1String("Zero")); } else if (i == container->childItems().count() - 2) { // The repeater itself - QFxRepeater *rep = qobject_cast(container->childItems().at(i)); + QmlGraphicsRepeater *rep = qobject_cast(container->childItems().at(i)); QCOMPARE(rep, repeater); saw_repeater = true; continue; } else if (i == container->childItems().count() - 1) { - QFxText *name = qobject_cast(container->childItems().at(i)); + QmlGraphicsText *name = qobject_cast(container->childItems().at(i)); QVERIFY(name != 0); QCOMPARE(name->text(), QLatin1String("Last")); } else { - QFxText *name = qobject_cast(container->childItems().at(i)); + QmlGraphicsText *name = qobject_cast(container->childItems().at(i)); QVERIFY(name != 0); QCOMPARE(name->text(), data.at(i-1)); } @@ -82,7 +82,7 @@ void tst_QFxRepeater::stringList() } -QmlView *tst_QFxRepeater::createView(const QString &filename) +QmlView *tst_QmlGraphicsRepeater::createView(const QString &filename) { QmlView *canvas = new QmlView(0); canvas->setFixedSize(240,320); @@ -96,13 +96,13 @@ QmlView *tst_QFxRepeater::createView(const QString &filename) } template -T *tst_QFxRepeater::findItem(QObject *parent, const QString &objectName) +T *tst_QmlGraphicsRepeater::findItem(QObject *parent, const QString &objectName) { const QMetaObject &mo = T::staticMetaObject; if (mo.cast(parent) && (objectName.isEmpty() || parent->objectName() == objectName)) return static_cast(parent); for (int i = 0; i < parent->children().count(); ++i) { - QFxItem *item = findItem(parent->children().at(i), objectName); + QmlGraphicsItem *item = findItem(parent->children().at(i), objectName); if (item) return static_cast(item); } @@ -110,6 +110,6 @@ T *tst_QFxRepeater::findItem(QObject *parent, const QString &objectName) return 0; } -QTEST_MAIN(tst_QFxRepeater) +QTEST_MAIN(tst_QmlGraphicsRepeater) #include "tst_repeater.moc" diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp index 0ebdccd..e938ee4 100644 --- a/tests/auto/declarative/sql/tst_sql.cpp +++ b/tests/auto/declarative/sql/tst_sql.cpp @@ -157,7 +157,7 @@ void tst_sql::testQml() engine->setOfflineStoragePath(dbDir()); QmlComponent component(engine, qml.toUtf8(), QUrl::fromLocalFile(SRCDIR "/empty.qml")); // just a file for relative local imports - QFxText *text = qobject_cast(component.create()); + QmlGraphicsText *text = qobject_cast(component.create()); QVERIFY(text != 0); QCOMPARE(text->text(),result); QCOMPARE(QDir(dbDir()+"/Databases").entryInfoList(QDir::Files|QDir::NoDotAndDotDot).count(), databases*2); // *2 = .ini file + .sqlite file diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index b2532a2..91b6d0b 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -22,7 +22,7 @@ void tst_states::basicChanges() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges.qml"); - QFxRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -36,7 +36,7 @@ void tst_states::basicChanges() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges2.qml"); - QFxRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -56,7 +56,7 @@ void tst_states::basicChanges() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicChanges3.qml"); - QFxRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -92,7 +92,7 @@ void tst_states::basicExtension() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicExtension.qml"); - QFxRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -125,7 +125,7 @@ void tst_states::basicExtension() { QmlComponent rectComponent(&engine, SRCDIR "/data/fakeExtension.qml"); - QFxRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -156,7 +156,7 @@ void tst_states::basicBinding() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding.qml"); - QFxRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -183,7 +183,7 @@ void tst_states::basicBinding() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding2.qml"); - QFxRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -213,7 +213,7 @@ void tst_states::basicBinding() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding3.qml"); - QFxRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -237,7 +237,7 @@ void tst_states::basicBinding() { QmlComponent rectComponent(&engine, SRCDIR "/data/basicBinding4.qml"); - QFxRect *rect = qobject_cast(rectComponent.create()); + QmlGraphicsRect *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); QCOMPARE(rect->color(),QColor("red")); @@ -263,7 +263,7 @@ void tst_states::basicBinding() } } -class MyRect : public QFxRect +class MyRect : public QmlGraphicsRect { Q_OBJECT public: @@ -303,7 +303,7 @@ void tst_states::signalOverride() rect->doSomething(); QCOMPARE(rect->color(),QColor("blue")); - QFxRect *innerRect = qobject_cast(rect->findChild("extendedRect")); + QmlGraphicsRect *innerRect = qobject_cast(rect->findChild("extendedRect")); innerRect->setState("green"); rect->doSomething(); diff --git a/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp b/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp index ae6f9a3..b115445 100644 --- a/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp +++ b/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp @@ -327,7 +327,7 @@ void tst_QmlPainting::drawTransformedImageRoundedRect() surface.save("ti.png"); } -//code from QFxRect for drawing rounded rects +//code from QmlGraphicsRect for drawing rounded rects void tst_QmlPainting::drawScaleGridRoundedRect() { //setup image @@ -422,7 +422,7 @@ void tst_QmlPainting::drawScaledScaleGridRoundedRect_data() // QTest::newRow(QString(QLatin1String("scale=%1; imagetype=ARGB8565_Pre")).arg(i).toLatin1()) << i << (int)QImage::Format_ARGB8565_Premultiplied; } -//code from QFxRect for drawing rounded rects +//code from QmlGraphicsRect for drawing rounded rects void tst_QmlPainting::drawScaledScaleGridRoundedRect() { QFETCH(float, scale); @@ -522,7 +522,7 @@ void tst_QmlPainting::drawTransformedScaleGridRoundedRect_data() } -//code from QFxRect for drawing rounded rects +//code from QmlGraphicsRect for drawing rounded rects void tst_QmlPainting::drawTransformedScaleGridRoundedRect() { QFETCH(QTransform, transform); diff --git a/tools/qdoc3/htmlgenerator.cpp b/tools/qdoc3/htmlgenerator.cpp index 18c7916..c5ea308 100644 --- a/tools/qdoc3/htmlgenerator.cpp +++ b/tools/qdoc3/htmlgenerator.cpp @@ -4276,7 +4276,7 @@ void HtmlGenerator::generateQmlInherits(const QmlClassNode* cn, } /*! - Output the "[Xxx instantiates the C++ class QFxXxx]" + Output the "[Xxx instantiates the C++ class QmlGraphicsXxx]" line for the QML element, if there should be one. If there is no class node, or if the class node status @@ -4306,7 +4306,7 @@ void HtmlGenerator::generateQmlInstantiates(const QmlClassNode* qcn, } /*! - Output the "[QFxXxx is instantiated by QML element Xxx]" + Output the "[QmlGraphicsXxx is instantiated by QML element Xxx]" line for the class, if there should be one. If there is no QML element, or if the class node status diff --git a/tools/qmlviewer/qfxtester.cpp b/tools/qmlviewer/qfxtester.cpp index 0ccc9c0..a105701 100644 --- a/tools/qmlviewer/qfxtester.cpp +++ b/tools/qmlviewer/qfxtester.cpp @@ -24,12 +24,12 @@ QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt.VisualTest, 4, 6, (QT_VERSION&0x00ff00)>>8, VisualTest, QFxVisualTest); -QML_DEFINE_TYPE(Qt.VisualTest, 4, 6, (QT_VERSION&0x00ff00)>>8, Frame, QFxVisualTestFrame); -QML_DEFINE_TYPE(Qt.VisualTest, 4, 6, (QT_VERSION&0x00ff00)>>8, Mouse, QFxVisualTestMouse); -QML_DEFINE_TYPE(Qt.VisualTest, 4, 6, (QT_VERSION&0x00ff00)>>8, Key, QFxVisualTestKey); +QML_DEFINE_TYPE(Qt.VisualTest, 4, 6, (QT_VERSION&0x00ff00)>>8, VisualTest, QmlGraphicsVisualTest); +QML_DEFINE_TYPE(Qt.VisualTest, 4, 6, (QT_VERSION&0x00ff00)>>8, Frame, QmlGraphicsVisualTestFrame); +QML_DEFINE_TYPE(Qt.VisualTest, 4, 6, (QT_VERSION&0x00ff00)>>8, Mouse, QmlGraphicsVisualTestMouse); +QML_DEFINE_TYPE(Qt.VisualTest, 4, 6, (QT_VERSION&0x00ff00)>>8, Key, QmlGraphicsVisualTestKey); -QFxTester::QFxTester(const QString &script, QmlViewer::ScriptOptions opts, +QmlGraphicsTester::QmlGraphicsTester(const QString &script, QmlViewer::ScriptOptions opts, QmlView *parent) : QAbstractAnimation(parent), m_script(script), m_view(parent), filterEvents(true), options(opts), testscript(0), hasCompleted(false), hasFailed(false) @@ -42,7 +42,7 @@ QFxTester::QFxTester(const QString &script, QmlViewer::ScriptOptions opts, start(); } -QFxTester::~QFxTester() +QmlGraphicsTester::~QmlGraphicsTester() { if (!hasFailed && options & QmlViewer::Record && @@ -50,26 +50,26 @@ QFxTester::~QFxTester() save(); } -int QFxTester::duration() const +int QmlGraphicsTester::duration() const { return -1; } -void QFxTester::addMouseEvent(Destination dest, QMouseEvent *me) +void QmlGraphicsTester::addMouseEvent(Destination dest, QMouseEvent *me) { MouseEvent e(me); e.destination = dest; m_mouseEvents << e; } -void QFxTester::addKeyEvent(Destination dest, QKeyEvent *ke) +void QmlGraphicsTester::addKeyEvent(Destination dest, QKeyEvent *ke) { KeyEvent e(ke); e.destination = dest; m_keyEvents << e; } -bool QFxTester::eventFilter(QObject *o, QEvent *e) +bool QmlGraphicsTester::eventFilter(QObject *o, QEvent *e) { if (!filterEvents) return false; @@ -100,7 +100,7 @@ bool QFxTester::eventFilter(QObject *o, QEvent *e) return false; } -void QFxTester::executefailure() +void QmlGraphicsTester::executefailure() { hasFailed = true; @@ -108,7 +108,7 @@ void QFxTester::executefailure() exit(-1); } -void QFxTester::imagefailure() +void QmlGraphicsTester::imagefailure() { hasFailed = true; @@ -116,7 +116,7 @@ void QFxTester::imagefailure() exit(-1); } -void QFxTester::complete() +void QmlGraphicsTester::complete() { if (options & QmlViewer::ExitOnComplete) QApplication::exit(hasFailed?-1:0); @@ -129,17 +129,17 @@ void QFxTester::complete() qWarning("Script playback complete"); } -void QFxTester::run() +void QmlGraphicsTester::run() { QmlComponent c(m_view->engine(), m_script + QLatin1String(".qml")); - testscript = qobject_cast(c.create()); + testscript = qobject_cast(c.create()); if (testscript) testscript->setParent(this); else executefailure(); testscriptidx = 0; } -void QFxTester::save() +void QmlGraphicsTester::save() { QString filename = m_script + QLatin1String(".qml"); QFileInfo filenameInfo(filename); @@ -206,9 +206,9 @@ void QFxTester::save() file.close(); } -void QFxTester::updateCurrentTime(int msec) +void QmlGraphicsTester::updateCurrentTime(int msec) { - QFxItemPrivate::setConsistentTime(msec); + QmlGraphicsItemPrivate::setConsistentTime(msec); QImage img(m_view->width(), m_view->height(), QImage::Format_RGB32); @@ -268,17 +268,17 @@ void QFxTester::updateCurrentTime(int msec) QObject *event = testscript->event(testscriptidx); - if (QFxVisualTestFrame *frame = qobject_cast(event)) { + if (QmlGraphicsVisualTestFrame *frame = qobject_cast(event)) { if (frame->msec() < msec) { if (options & QmlViewer::TestImages) { - qWarning() << "QFxTester: Extra frame. Seen:" + qWarning() << "QmlGraphicsTester: Extra frame. Seen:" << msec << "Expected:" << frame->msec(); imagefailure(); } } else if (frame->msec() == msec) { if (frame->hash().toUtf8() != fe.hash.toHex()) { if (options & QmlViewer::TestImages) { - qWarning() << "QFxTester: Mismatched frame hash. Seen:" + qWarning() << "QmlGraphicsTester: Mismatched frame hash. Seen:" << fe.hash.toHex() << "Expected:" << frame->hash().toUtf8(); imagefailure(); @@ -292,13 +292,13 @@ void QFxTester::updateCurrentTime(int msec) QImage goodImage(frame->image().toLocalFile()); if (goodImage != img) { QString reject(frame->image().toLocalFile() + ".reject.png"); - qWarning() << "QFxTester: Image mismatch. Reject saved to:" + qWarning() << "QmlGraphicsTester: Image mismatch. Reject saved to:" << reject; img.save(reject); imagefailure(); } } - } else if (QFxVisualTestMouse *mouse = qobject_cast(event)) { + } else if (QmlGraphicsVisualTestMouse *mouse = qobject_cast(event)) { QPoint pos(mouse->x(), mouse->y()); QPoint globalPos = m_view->mapToGlobal(QPoint(0, 0)) + pos; QMouseEvent event((QEvent::Type)mouse->type(), pos, globalPos, (Qt::MouseButton)mouse->button(), (Qt::MouseButtons)mouse->buttons(), (Qt::KeyboardModifiers)mouse->modifiers()); @@ -313,7 +313,7 @@ void QFxTester::updateCurrentTime(int msec) me.destination = ViewPort; } m_savedMouseEvents.append(me); - } else if (QFxVisualTestKey *key = qobject_cast(event)) { + } else if (QmlGraphicsVisualTestKey *key = qobject_cast(event)) { QKeyEvent event((QEvent::Type)key->type(), key->key(), (Qt::KeyboardModifiers)key->modifiers(), QString::fromUtf8(QByteArray::fromHex(key->text().toUtf8())), key->autorep(), key->count()); diff --git a/tools/qmlviewer/qfxtester.h b/tools/qmlviewer/qfxtester.h index 52987db..c3a6f01 100644 --- a/tools/qmlviewer/qfxtester.h +++ b/tools/qmlviewer/qfxtester.h @@ -21,13 +21,13 @@ QT_BEGIN_NAMESPACE -class QFxVisualTest : public QObject +class QmlGraphicsVisualTest : public QObject { Q_OBJECT Q_PROPERTY(QList* events READ events CONSTANT) Q_CLASSINFO("DefaultProperty", "events") public: - QFxVisualTest() {} + QmlGraphicsVisualTest() {} QList *events() { return &m_events; } @@ -37,16 +37,16 @@ public: private: QList m_events; }; -QML_DECLARE_TYPE(QFxVisualTest) +QML_DECLARE_TYPE(QmlGraphicsVisualTest) -class QFxVisualTestFrame : public QObject +class QmlGraphicsVisualTestFrame : public QObject { Q_OBJECT Q_PROPERTY(int msec READ msec WRITE setMsec) Q_PROPERTY(QString hash READ hash WRITE setHash) Q_PROPERTY(QUrl image READ image WRITE setImage) public: - QFxVisualTestFrame() : m_msec(-1) {} + QmlGraphicsVisualTestFrame() : m_msec(-1) {} int msec() const { return m_msec; } void setMsec(int m) { m_msec = m; } @@ -62,9 +62,9 @@ private: QString m_hash; QUrl m_image; }; -QML_DECLARE_TYPE(QFxVisualTestFrame) +QML_DECLARE_TYPE(QmlGraphicsVisualTestFrame) -class QFxVisualTestMouse : public QObject +class QmlGraphicsVisualTestMouse : public QObject { Q_OBJECT Q_PROPERTY(int type READ type WRITE setType) @@ -75,7 +75,7 @@ class QFxVisualTestMouse : public QObject Q_PROPERTY(int modifiers READ modifiers WRITE setModifiers) Q_PROPERTY(bool sendToViewport READ sendToViewport WRITE setSendToViewport) public: - QFxVisualTestMouse() : m_type(0), m_button(0), m_buttons(0), m_x(0), m_y(0), m_modifiers(0), m_viewport(false) {} + QmlGraphicsVisualTestMouse() : m_type(0), m_button(0), m_buttons(0), m_x(0), m_y(0), m_modifiers(0), m_viewport(false) {} int type() const { return m_type; } void setType(int t) { m_type = t; } @@ -106,9 +106,9 @@ private: int m_modifiers; bool m_viewport; }; -QML_DECLARE_TYPE(QFxVisualTestMouse) +QML_DECLARE_TYPE(QmlGraphicsVisualTestMouse) -class QFxVisualTestKey : public QObject +class QmlGraphicsVisualTestKey : public QObject { Q_OBJECT Q_PROPERTY(int type READ type WRITE setType) @@ -119,7 +119,7 @@ class QFxVisualTestKey : public QObject Q_PROPERTY(int count READ count WRITE setCount) Q_PROPERTY(bool sendToViewport READ sendToViewport WRITE setSendToViewport) public: - QFxVisualTestKey() : m_type(0), m_key(0), m_modifiers(0), m_autorep(false), m_count(0), m_viewport(false) {} + QmlGraphicsVisualTestKey() : m_type(0), m_key(0), m_modifiers(0), m_autorep(false), m_count(0), m_viewport(false) {} int type() const { return m_type; } void setType(int t) { m_type = t; } @@ -150,13 +150,13 @@ private: int m_count; bool m_viewport; }; -QML_DECLARE_TYPE(QFxVisualTestKey) +QML_DECLARE_TYPE(QmlGraphicsVisualTestKey) -class QFxTester : public QAbstractAnimation +class QmlGraphicsTester : public QAbstractAnimation { public: - QFxTester(const QString &script, QmlViewer::ScriptOptions options, QmlView *parent); - ~QFxTester(); + QmlGraphicsTester(const QString &script, QmlViewer::ScriptOptions options, QmlView *parent); + ~QmlGraphicsTester(); virtual int duration() const; @@ -222,7 +222,7 @@ private: QmlViewer::ScriptOptions options; int testscriptidx; - QFxVisualTest *testscript; + QmlGraphicsVisualTest *testscript; bool hasCompleted; bool hasFailed; diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 3aeb0da..93470eb 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -637,7 +637,7 @@ void QmlViewer::openQml(const QString& file_or_url) setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(file_or_url)); if (!m_script.isEmpty()) - tester = new QFxTester(m_script, m_scriptOptions, canvas); + tester = new QmlGraphicsTester(m_script, m_scriptOptions, canvas); canvas->reset(); diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index e1f53f9..bc8fe11 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -23,10 +23,10 @@ QT_BEGIN_NAMESPACE class QmlView; class PreviewDeviceSkin; -class QFxTestEngine; +class QmlGraphicsTestEngine; class QProcess; class RecordingDialog; -class QFxTester; +class QmlGraphicsTester; class QmlViewer : public QWidget { @@ -126,7 +126,7 @@ private: QString m_script; ScriptOptions m_scriptOptions; - QFxTester *tester; + QmlGraphicsTester *tester; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QmlViewer::ScriptOptions) -- cgit v0.12 From 44a0c19eae2099e6cdb44825123a4b8ee9a5bf20 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 30 Oct 2009 15:00:02 +1000 Subject: Rename qfx files to qmlgraphics files --- demos/declarative/minehunt/main.cpp | 2 +- src/declarative/extra/extra.pri | 14 +- src/declarative/extra/qfxanimatedimageitem.cpp | 256 -- src/declarative/extra/qfxanimatedimageitem.h | 106 - src/declarative/extra/qfxanimatedimageitem_p.h | 81 - src/declarative/extra/qfxintegermodel.cpp | 126 - src/declarative/extra/qfxintegermodel.h | 86 - src/declarative/extra/qfxparticles.cpp | 1134 -------- src/declarative/extra/qfxparticles.h | 230 -- .../extra/qmlgraphicsanimatedimageitem.cpp | 256 ++ .../extra/qmlgraphicsanimatedimageitem.h | 106 + .../extra/qmlgraphicsanimatedimageitem_p.h | 81 + src/declarative/extra/qmlgraphicsintegermodel.cpp | 126 + src/declarative/extra/qmlgraphicsintegermodel.h | 86 + src/declarative/extra/qmlgraphicsparticles.cpp | 1134 ++++++++ src/declarative/extra/qmlgraphicsparticles.h | 230 ++ src/declarative/fx/fx.pri | 152 +- src/declarative/fx/qfxanchors.cpp | 962 ------- src/declarative/fx/qfxanchors.h | 180 -- src/declarative/fx/qfxanchors_p.h | 160 -- src/declarative/fx/qfxborderimage.cpp | 411 --- src/declarative/fx/qfxborderimage.h | 105 - src/declarative/fx/qfxborderimage_p.h | 97 - src/declarative/fx/qfxeffects.cpp | 238 -- src/declarative/fx/qfxevents.cpp | 195 -- src/declarative/fx/qfxevents_p.h | 137 - src/declarative/fx/qfxflickable.cpp | 1283 --------- src/declarative/fx/qfxflickable.h | 203 -- src/declarative/fx/qfxflickable_p.h | 156 -- src/declarative/fx/qfxflipable.cpp | 236 -- src/declarative/fx/qfxflipable.h | 94 - src/declarative/fx/qfxfocuspanel.cpp | 89 - src/declarative/fx/qfxfocuspanel.h | 77 - src/declarative/fx/qfxfocusscope.cpp | 72 - src/declarative/fx/qfxfocusscope.h | 68 - src/declarative/fx/qfxgraphicsobjectcontainer.cpp | 230 -- src/declarative/fx/qfxgraphicsobjectcontainer.h | 90 - src/declarative/fx/qfxgridview.cpp | 1585 ----------- src/declarative/fx/qfxgridview.h | 157 -- src/declarative/fx/qfximage.cpp | 301 -- src/declarative/fx/qfximage.h | 90 - src/declarative/fx/qfximage_p.h | 77 - src/declarative/fx/qfximagebase.cpp | 174 -- src/declarative/fx/qfximagebase.h | 90 - src/declarative/fx/qfximagebase_p.h | 83 - src/declarative/fx/qfxitem.cpp | 2921 -------------------- src/declarative/fx/qfxitem.h | 238 -- src/declarative/fx/qfxitem_p.h | 245 -- src/declarative/fx/qfxlayoutitem.cpp | 106 - src/declarative/fx/qfxlayoutitem.h | 93 - src/declarative/fx/qfxlistview.cpp | 2035 -------------- src/declarative/fx/qfxlistview.h | 186 -- src/declarative/fx/qfxloader.cpp | 390 --- src/declarative/fx/qfxloader.h | 107 - src/declarative/fx/qfxloader_p.h | 82 - src/declarative/fx/qfxmouseregion.cpp | 649 ----- src/declarative/fx/qfxmouseregion.h | 180 -- src/declarative/fx/qfxmouseregion_p.h | 114 - src/declarative/fx/qfxpainteditem.cpp | 387 --- src/declarative/fx/qfxpainteditem.h | 105 - src/declarative/fx/qfxpainteditem_p.h | 88 - src/declarative/fx/qfxpath.cpp | 839 ------ src/declarative/fx/qfxpath.h | 259 -- src/declarative/fx/qfxpath_p.h | 79 - src/declarative/fx/qfxpathview.cpp | 913 ------ src/declarative/fx/qfxpathview.h | 138 - src/declarative/fx/qfxpathview_p.h | 151 - src/declarative/fx/qfxpixmapcache.cpp | 282 -- src/declarative/fx/qfxpixmapcache.h | 72 - src/declarative/fx/qfxpositioners.cpp | 921 ------ src/declarative/fx/qfxpositioners.h | 167 -- src/declarative/fx/qfxpositioners_p.h | 105 - src/declarative/fx/qfxrect.cpp | 475 ---- src/declarative/fx/qfxrect.h | 189 -- src/declarative/fx/qfxrect_p.h | 109 - src/declarative/fx/qfxrepeater.cpp | 320 --- src/declarative/fx/qfxrepeater.h | 103 - src/declarative/fx/qfxrepeater_p.h | 81 - src/declarative/fx/qfxscalegrid.cpp | 212 -- src/declarative/fx/qfxscalegrid_p.h | 133 - src/declarative/fx/qfxtext.cpp | 840 ------ src/declarative/fx/qfxtext.h | 151 - src/declarative/fx/qfxtext_p.h | 113 - src/declarative/fx/qfxtextedit.cpp | 1085 -------- src/declarative/fx/qfxtextedit.h | 234 -- src/declarative/fx/qfxtextedit_p.h | 113 - src/declarative/fx/qfxtextinput.cpp | 777 ------ src/declarative/fx/qfxtextinput.h | 209 -- src/declarative/fx/qfxtextinput_p.h | 109 - src/declarative/fx/qfxvisualitemmodel.cpp | 1032 ------- src/declarative/fx/qfxvisualitemmodel.h | 203 -- src/declarative/fx/qfxwebview.cpp | 1388 ---------- src/declarative/fx/qfxwebview.h | 251 -- src/declarative/fx/qmlgraphicsanchors.cpp | 962 +++++++ src/declarative/fx/qmlgraphicsanchors.h | 180 ++ src/declarative/fx/qmlgraphicsanchors_p.h | 160 ++ src/declarative/fx/qmlgraphicsborderimage.cpp | 411 +++ src/declarative/fx/qmlgraphicsborderimage.h | 105 + src/declarative/fx/qmlgraphicsborderimage_p.h | 97 + src/declarative/fx/qmlgraphicseffects.cpp | 238 ++ src/declarative/fx/qmlgraphicsevents.cpp | 195 ++ src/declarative/fx/qmlgraphicsevents_p.h | 137 + src/declarative/fx/qmlgraphicsflickable.cpp | 1283 +++++++++ src/declarative/fx/qmlgraphicsflickable.h | 203 ++ src/declarative/fx/qmlgraphicsflickable_p.h | 156 ++ src/declarative/fx/qmlgraphicsflipable.cpp | 236 ++ src/declarative/fx/qmlgraphicsflipable.h | 94 + src/declarative/fx/qmlgraphicsfocuspanel.cpp | 89 + src/declarative/fx/qmlgraphicsfocuspanel.h | 77 + src/declarative/fx/qmlgraphicsfocusscope.cpp | 72 + src/declarative/fx/qmlgraphicsfocusscope.h | 68 + .../fx/qmlgraphicsgraphicsobjectcontainer.cpp | 230 ++ .../fx/qmlgraphicsgraphicsobjectcontainer.h | 90 + src/declarative/fx/qmlgraphicsgridview.cpp | 1585 +++++++++++ src/declarative/fx/qmlgraphicsgridview.h | 157 ++ src/declarative/fx/qmlgraphicsimage.cpp | 301 ++ src/declarative/fx/qmlgraphicsimage.h | 90 + src/declarative/fx/qmlgraphicsimage_p.h | 77 + src/declarative/fx/qmlgraphicsimagebase.cpp | 174 ++ src/declarative/fx/qmlgraphicsimagebase.h | 90 + src/declarative/fx/qmlgraphicsimagebase_p.h | 83 + src/declarative/fx/qmlgraphicsitem.cpp | 2921 ++++++++++++++++++++ src/declarative/fx/qmlgraphicsitem.h | 238 ++ src/declarative/fx/qmlgraphicsitem_p.h | 245 ++ src/declarative/fx/qmlgraphicslayoutitem.cpp | 106 + src/declarative/fx/qmlgraphicslayoutitem.h | 93 + src/declarative/fx/qmlgraphicslistview.cpp | 2035 ++++++++++++++ src/declarative/fx/qmlgraphicslistview.h | 186 ++ src/declarative/fx/qmlgraphicsloader.cpp | 390 +++ src/declarative/fx/qmlgraphicsloader.h | 107 + src/declarative/fx/qmlgraphicsloader_p.h | 82 + src/declarative/fx/qmlgraphicsmouseregion.cpp | 649 +++++ src/declarative/fx/qmlgraphicsmouseregion.h | 180 ++ src/declarative/fx/qmlgraphicsmouseregion_p.h | 114 + src/declarative/fx/qmlgraphicspainteditem.cpp | 387 +++ src/declarative/fx/qmlgraphicspainteditem.h | 105 + src/declarative/fx/qmlgraphicspainteditem_p.h | 88 + src/declarative/fx/qmlgraphicspath.cpp | 839 ++++++ src/declarative/fx/qmlgraphicspath.h | 259 ++ src/declarative/fx/qmlgraphicspath_p.h | 79 + src/declarative/fx/qmlgraphicspathview.cpp | 913 ++++++ src/declarative/fx/qmlgraphicspathview.h | 138 + src/declarative/fx/qmlgraphicspathview_p.h | 151 + src/declarative/fx/qmlgraphicspixmapcache.cpp | 282 ++ src/declarative/fx/qmlgraphicspixmapcache.h | 72 + src/declarative/fx/qmlgraphicspositioners.cpp | 921 ++++++ src/declarative/fx/qmlgraphicspositioners.h | 167 ++ src/declarative/fx/qmlgraphicspositioners_p.h | 105 + src/declarative/fx/qmlgraphicsrect.cpp | 475 ++++ src/declarative/fx/qmlgraphicsrect.h | 189 ++ src/declarative/fx/qmlgraphicsrect_p.h | 109 + src/declarative/fx/qmlgraphicsrepeater.cpp | 320 +++ src/declarative/fx/qmlgraphicsrepeater.h | 103 + src/declarative/fx/qmlgraphicsrepeater_p.h | 81 + src/declarative/fx/qmlgraphicsscalegrid.cpp | 212 ++ src/declarative/fx/qmlgraphicsscalegrid_p.h | 133 + src/declarative/fx/qmlgraphicstext.cpp | 840 ++++++ src/declarative/fx/qmlgraphicstext.h | 151 + src/declarative/fx/qmlgraphicstext_p.h | 113 + src/declarative/fx/qmlgraphicstextedit.cpp | 1085 ++++++++ src/declarative/fx/qmlgraphicstextedit.h | 234 ++ src/declarative/fx/qmlgraphicstextedit_p.h | 113 + src/declarative/fx/qmlgraphicstextinput.cpp | 777 ++++++ src/declarative/fx/qmlgraphicstextinput.h | 209 ++ src/declarative/fx/qmlgraphicstextinput_p.h | 109 + src/declarative/fx/qmlgraphicsvisualitemmodel.cpp | 1032 +++++++ src/declarative/fx/qmlgraphicsvisualitemmodel.h | 203 ++ src/declarative/fx/qmlgraphicswebview.cpp | 1388 ++++++++++ src/declarative/fx/qmlgraphicswebview.h | 251 ++ src/declarative/util/qmlstateoperations.cpp | 4 +- src/declarative/util/qmlstateoperations.h | 4 +- src/declarative/util/qmlview.cpp | 2 +- tests/auto/declarative/anchors/tst_anchors.cpp | 4 +- .../animatedimage/tst_animatedimage.cpp | 6 +- .../auto/declarative/animations/tst_animations.cpp | 2 +- tests/auto/declarative/behaviors/tst_behaviors.cpp | 2 +- tests/auto/declarative/layouts/tst_layouts.cpp | 2 +- tests/auto/declarative/listview/tst_listview.cpp | 4 +- tests/auto/declarative/pathview/tst_pathview.cpp | 6 +- tests/auto/declarative/qfxloader/qfxloader.pro | 2 +- tests/auto/declarative/qfxloader/tst_qfxloader.cpp | 2 +- .../declarative/qfxpixmapcache/qfxpixmapcache.pro | 2 +- .../qfxpixmapcache/tst_qfxpixmapcache.cpp | 2 +- tests/auto/declarative/qfxtext/qfxtext.pro | 2 +- tests/auto/declarative/qfxtext/tst_qfxtext.cpp | 2 +- tests/auto/declarative/qfxtextedit/qfxtextedit.pro | 2 +- .../declarative/qfxtextedit/tst_qfxtextedit.cpp | 2 +- .../auto/declarative/qfxtextinput/qfxtextinput.pro | 2 +- tests/auto/declarative/qfxwebview/qfxwebview.pro | 2 +- .../auto/declarative/qfxwebview/tst_qfxwebview.cpp | 2 +- .../qmlpropertymap/tst_qmlpropertymap.cpp | 2 +- tests/auto/declarative/repeater/tst_repeater.cpp | 4 +- tests/auto/declarative/sql/tst_sql.cpp | 2 +- tests/auto/declarative/states/tst_states.cpp | 2 +- tools/qmldebugger/standalone/engine.cpp | 2 +- tools/qmlviewer/qfxtester.cpp | 2 +- 196 files changed, 29758 insertions(+), 29758 deletions(-) delete mode 100644 src/declarative/extra/qfxanimatedimageitem.cpp delete mode 100644 src/declarative/extra/qfxanimatedimageitem.h delete mode 100644 src/declarative/extra/qfxanimatedimageitem_p.h delete mode 100644 src/declarative/extra/qfxintegermodel.cpp delete mode 100644 src/declarative/extra/qfxintegermodel.h delete mode 100644 src/declarative/extra/qfxparticles.cpp delete mode 100644 src/declarative/extra/qfxparticles.h create mode 100644 src/declarative/extra/qmlgraphicsanimatedimageitem.cpp create mode 100644 src/declarative/extra/qmlgraphicsanimatedimageitem.h create mode 100644 src/declarative/extra/qmlgraphicsanimatedimageitem_p.h create mode 100644 src/declarative/extra/qmlgraphicsintegermodel.cpp create mode 100644 src/declarative/extra/qmlgraphicsintegermodel.h create mode 100644 src/declarative/extra/qmlgraphicsparticles.cpp create mode 100644 src/declarative/extra/qmlgraphicsparticles.h delete mode 100644 src/declarative/fx/qfxanchors.cpp delete mode 100644 src/declarative/fx/qfxanchors.h delete mode 100644 src/declarative/fx/qfxanchors_p.h delete mode 100644 src/declarative/fx/qfxborderimage.cpp delete mode 100644 src/declarative/fx/qfxborderimage.h delete mode 100644 src/declarative/fx/qfxborderimage_p.h delete mode 100644 src/declarative/fx/qfxeffects.cpp delete mode 100644 src/declarative/fx/qfxevents.cpp delete mode 100644 src/declarative/fx/qfxevents_p.h delete mode 100644 src/declarative/fx/qfxflickable.cpp delete mode 100644 src/declarative/fx/qfxflickable.h delete mode 100644 src/declarative/fx/qfxflickable_p.h delete mode 100644 src/declarative/fx/qfxflipable.cpp delete mode 100644 src/declarative/fx/qfxflipable.h delete mode 100644 src/declarative/fx/qfxfocuspanel.cpp delete mode 100644 src/declarative/fx/qfxfocuspanel.h delete mode 100644 src/declarative/fx/qfxfocusscope.cpp delete mode 100644 src/declarative/fx/qfxfocusscope.h delete mode 100644 src/declarative/fx/qfxgraphicsobjectcontainer.cpp delete mode 100644 src/declarative/fx/qfxgraphicsobjectcontainer.h delete mode 100644 src/declarative/fx/qfxgridview.cpp delete mode 100644 src/declarative/fx/qfxgridview.h delete mode 100644 src/declarative/fx/qfximage.cpp delete mode 100644 src/declarative/fx/qfximage.h delete mode 100644 src/declarative/fx/qfximage_p.h delete mode 100644 src/declarative/fx/qfximagebase.cpp delete mode 100644 src/declarative/fx/qfximagebase.h delete mode 100644 src/declarative/fx/qfximagebase_p.h delete mode 100644 src/declarative/fx/qfxitem.cpp delete mode 100644 src/declarative/fx/qfxitem.h delete mode 100644 src/declarative/fx/qfxitem_p.h delete mode 100644 src/declarative/fx/qfxlayoutitem.cpp delete mode 100644 src/declarative/fx/qfxlayoutitem.h delete mode 100644 src/declarative/fx/qfxlistview.cpp delete mode 100644 src/declarative/fx/qfxlistview.h delete mode 100644 src/declarative/fx/qfxloader.cpp delete mode 100644 src/declarative/fx/qfxloader.h delete mode 100644 src/declarative/fx/qfxloader_p.h delete mode 100644 src/declarative/fx/qfxmouseregion.cpp delete mode 100644 src/declarative/fx/qfxmouseregion.h delete mode 100644 src/declarative/fx/qfxmouseregion_p.h delete mode 100644 src/declarative/fx/qfxpainteditem.cpp delete mode 100644 src/declarative/fx/qfxpainteditem.h delete mode 100644 src/declarative/fx/qfxpainteditem_p.h delete mode 100644 src/declarative/fx/qfxpath.cpp delete mode 100644 src/declarative/fx/qfxpath.h delete mode 100644 src/declarative/fx/qfxpath_p.h delete mode 100644 src/declarative/fx/qfxpathview.cpp delete mode 100644 src/declarative/fx/qfxpathview.h delete mode 100644 src/declarative/fx/qfxpathview_p.h delete mode 100644 src/declarative/fx/qfxpixmapcache.cpp delete mode 100644 src/declarative/fx/qfxpixmapcache.h delete mode 100644 src/declarative/fx/qfxpositioners.cpp delete mode 100644 src/declarative/fx/qfxpositioners.h delete mode 100644 src/declarative/fx/qfxpositioners_p.h delete mode 100644 src/declarative/fx/qfxrect.cpp delete mode 100644 src/declarative/fx/qfxrect.h delete mode 100644 src/declarative/fx/qfxrect_p.h delete mode 100644 src/declarative/fx/qfxrepeater.cpp delete mode 100644 src/declarative/fx/qfxrepeater.h delete mode 100644 src/declarative/fx/qfxrepeater_p.h delete mode 100644 src/declarative/fx/qfxscalegrid.cpp delete mode 100644 src/declarative/fx/qfxscalegrid_p.h delete mode 100644 src/declarative/fx/qfxtext.cpp delete mode 100644 src/declarative/fx/qfxtext.h delete mode 100644 src/declarative/fx/qfxtext_p.h delete mode 100644 src/declarative/fx/qfxtextedit.cpp delete mode 100644 src/declarative/fx/qfxtextedit.h delete mode 100644 src/declarative/fx/qfxtextedit_p.h delete mode 100644 src/declarative/fx/qfxtextinput.cpp delete mode 100644 src/declarative/fx/qfxtextinput.h delete mode 100644 src/declarative/fx/qfxtextinput_p.h delete mode 100644 src/declarative/fx/qfxvisualitemmodel.cpp delete mode 100644 src/declarative/fx/qfxvisualitemmodel.h delete mode 100644 src/declarative/fx/qfxwebview.cpp delete mode 100644 src/declarative/fx/qfxwebview.h create mode 100644 src/declarative/fx/qmlgraphicsanchors.cpp create mode 100644 src/declarative/fx/qmlgraphicsanchors.h create mode 100644 src/declarative/fx/qmlgraphicsanchors_p.h create mode 100644 src/declarative/fx/qmlgraphicsborderimage.cpp create mode 100644 src/declarative/fx/qmlgraphicsborderimage.h create mode 100644 src/declarative/fx/qmlgraphicsborderimage_p.h create mode 100644 src/declarative/fx/qmlgraphicseffects.cpp create mode 100644 src/declarative/fx/qmlgraphicsevents.cpp create mode 100644 src/declarative/fx/qmlgraphicsevents_p.h create mode 100644 src/declarative/fx/qmlgraphicsflickable.cpp create mode 100644 src/declarative/fx/qmlgraphicsflickable.h create mode 100644 src/declarative/fx/qmlgraphicsflickable_p.h create mode 100644 src/declarative/fx/qmlgraphicsflipable.cpp create mode 100644 src/declarative/fx/qmlgraphicsflipable.h create mode 100644 src/declarative/fx/qmlgraphicsfocuspanel.cpp create mode 100644 src/declarative/fx/qmlgraphicsfocuspanel.h create mode 100644 src/declarative/fx/qmlgraphicsfocusscope.cpp create mode 100644 src/declarative/fx/qmlgraphicsfocusscope.h create mode 100644 src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.cpp create mode 100644 src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.h create mode 100644 src/declarative/fx/qmlgraphicsgridview.cpp create mode 100644 src/declarative/fx/qmlgraphicsgridview.h create mode 100644 src/declarative/fx/qmlgraphicsimage.cpp create mode 100644 src/declarative/fx/qmlgraphicsimage.h create mode 100644 src/declarative/fx/qmlgraphicsimage_p.h create mode 100644 src/declarative/fx/qmlgraphicsimagebase.cpp create mode 100644 src/declarative/fx/qmlgraphicsimagebase.h create mode 100644 src/declarative/fx/qmlgraphicsimagebase_p.h create mode 100644 src/declarative/fx/qmlgraphicsitem.cpp create mode 100644 src/declarative/fx/qmlgraphicsitem.h create mode 100644 src/declarative/fx/qmlgraphicsitem_p.h create mode 100644 src/declarative/fx/qmlgraphicslayoutitem.cpp create mode 100644 src/declarative/fx/qmlgraphicslayoutitem.h create mode 100644 src/declarative/fx/qmlgraphicslistview.cpp create mode 100644 src/declarative/fx/qmlgraphicslistview.h create mode 100644 src/declarative/fx/qmlgraphicsloader.cpp create mode 100644 src/declarative/fx/qmlgraphicsloader.h create mode 100644 src/declarative/fx/qmlgraphicsloader_p.h create mode 100644 src/declarative/fx/qmlgraphicsmouseregion.cpp create mode 100644 src/declarative/fx/qmlgraphicsmouseregion.h create mode 100644 src/declarative/fx/qmlgraphicsmouseregion_p.h create mode 100644 src/declarative/fx/qmlgraphicspainteditem.cpp create mode 100644 src/declarative/fx/qmlgraphicspainteditem.h create mode 100644 src/declarative/fx/qmlgraphicspainteditem_p.h create mode 100644 src/declarative/fx/qmlgraphicspath.cpp create mode 100644 src/declarative/fx/qmlgraphicspath.h create mode 100644 src/declarative/fx/qmlgraphicspath_p.h create mode 100644 src/declarative/fx/qmlgraphicspathview.cpp create mode 100644 src/declarative/fx/qmlgraphicspathview.h create mode 100644 src/declarative/fx/qmlgraphicspathview_p.h create mode 100644 src/declarative/fx/qmlgraphicspixmapcache.cpp create mode 100644 src/declarative/fx/qmlgraphicspixmapcache.h create mode 100644 src/declarative/fx/qmlgraphicspositioners.cpp create mode 100644 src/declarative/fx/qmlgraphicspositioners.h create mode 100644 src/declarative/fx/qmlgraphicspositioners_p.h create mode 100644 src/declarative/fx/qmlgraphicsrect.cpp create mode 100644 src/declarative/fx/qmlgraphicsrect.h create mode 100644 src/declarative/fx/qmlgraphicsrect_p.h create mode 100644 src/declarative/fx/qmlgraphicsrepeater.cpp create mode 100644 src/declarative/fx/qmlgraphicsrepeater.h create mode 100644 src/declarative/fx/qmlgraphicsrepeater_p.h create mode 100644 src/declarative/fx/qmlgraphicsscalegrid.cpp create mode 100644 src/declarative/fx/qmlgraphicsscalegrid_p.h create mode 100644 src/declarative/fx/qmlgraphicstext.cpp create mode 100644 src/declarative/fx/qmlgraphicstext.h create mode 100644 src/declarative/fx/qmlgraphicstext_p.h create mode 100644 src/declarative/fx/qmlgraphicstextedit.cpp create mode 100644 src/declarative/fx/qmlgraphicstextedit.h create mode 100644 src/declarative/fx/qmlgraphicstextedit_p.h create mode 100644 src/declarative/fx/qmlgraphicstextinput.cpp create mode 100644 src/declarative/fx/qmlgraphicstextinput.h create mode 100644 src/declarative/fx/qmlgraphicstextinput_p.h create mode 100644 src/declarative/fx/qmlgraphicsvisualitemmodel.cpp create mode 100644 src/declarative/fx/qmlgraphicsvisualitemmodel.h create mode 100644 src/declarative/fx/qmlgraphicswebview.cpp create mode 100644 src/declarative/fx/qmlgraphicswebview.h diff --git a/demos/declarative/minehunt/main.cpp b/demos/declarative/minehunt/main.cpp index a9b8828..a7c7111 100644 --- a/demos/declarative/minehunt/main.cpp +++ b/demos/declarative/minehunt/main.cpp @@ -1,7 +1,7 @@ #include "qmlengine.h" #include "qmlcontext.h" #include "qml.h" -#include +#include #include #include diff --git a/src/declarative/extra/extra.pri b/src/declarative/extra/extra.pri index 5e5e74e..47cc8f8 100644 --- a/src/declarative/extra/extra.pri +++ b/src/declarative/extra/extra.pri @@ -2,9 +2,9 @@ SOURCES += \ extra/qnumberformat.cpp \ extra/qmlnumberformatter.cpp \ extra/qmldatetimeformatter.cpp \ - extra/qfxintegermodel.cpp \ - extra/qfxanimatedimageitem.cpp \ - extra/qfxparticles.cpp \ + extra/qmlgraphicsintegermodel.cpp \ + extra/qmlgraphicsanimatedimageitem.cpp \ + extra/qmlgraphicsparticles.cpp \ extra/qmlbehavior.cpp \ extra/qmlfontloader.cpp @@ -12,10 +12,10 @@ HEADERS += \ extra/qnumberformat.h \ extra/qmlnumberformatter.h \ extra/qmldatetimeformatter.h \ - extra/qfxintegermodel.h \ - extra/qfxanimatedimageitem.h \ - extra/qfxanimatedimageitem_p.h \ - extra/qfxparticles.h \ + extra/qmlgraphicsintegermodel.h \ + extra/qmlgraphicsanimatedimageitem.h \ + extra/qmlgraphicsanimatedimageitem_p.h \ + extra/qmlgraphicsparticles.h \ extra/qmlbehavior.h \ extra/qmlfontloader.h diff --git a/src/declarative/extra/qfxanimatedimageitem.cpp b/src/declarative/extra/qfxanimatedimageitem.cpp deleted file mode 100644 index 8a6046e..0000000 --- a/src/declarative/extra/qfxanimatedimageitem.cpp +++ /dev/null @@ -1,256 +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 -#include -#include -#include "qfxanimatedimageitem.h" -#include "qfxanimatedimageitem_p.h" -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \class QmlGraphicsAnimatedImageItem - \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" } - Rectangle { color: "red"; width: 4; height: 8; y: anim.height - x: (anim.width-width)*anim.currentFrame/(anim.frameCount-1) - } -} - \endqml - \endtable -*/ -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,AnimatedImage,QmlGraphicsAnimatedImageItem) - -QmlGraphicsAnimatedImageItem::QmlGraphicsAnimatedImageItem(QmlGraphicsItem *parent) - : QmlGraphicsImage(*(new QmlGraphicsAnimatedImageItemPrivate), parent) -{ -} - -QmlGraphicsAnimatedImageItem::QmlGraphicsAnimatedImageItem(QmlGraphicsAnimatedImageItemPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsImage(dd, parent) -{ -} - -QmlGraphicsAnimatedImageItem::~QmlGraphicsAnimatedImageItem() -{ - Q_D(QmlGraphicsAnimatedImageItem); - delete d->_movie; -} - -/*! - \qmlproperty bool AnimatedImage::paused - This property holds whether the animated image is paused or not - - Defaults to false, and can be set to true when you want to pause. -*/ -bool QmlGraphicsAnimatedImageItem::isPaused() const -{ - Q_D(const QmlGraphicsAnimatedImageItem); - if(!d->_movie) - return false; - return d->_movie->state()==QMovie::Paused; -} - -void QmlGraphicsAnimatedImageItem::setPaused(bool pause) -{ - Q_D(QmlGraphicsAnimatedImageItem); - if(pause == d->paused) - return; - d->paused = pause; - if(!d->_movie) - return; - d->_movie->setPaused(pause); -} -/*! - \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 QmlGraphicsAnimatedImageItem::isPlaying() const -{ - Q_D(const QmlGraphicsAnimatedImageItem); - if (!d->_movie) - return false; - return d->_movie->state()!=QMovie::NotRunning; -} - -void QmlGraphicsAnimatedImageItem::setPlaying(bool play) -{ - Q_D(QmlGraphicsAnimatedImageItem); - if(play == d->playing) - return; - d->playing = play; - 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 QmlGraphicsAnimatedImageItem::currentFrame() const -{ - Q_D(const QmlGraphicsAnimatedImageItem); - if (!d->_movie) - return -1; - return d->_movie->currentFrameNumber(); -} - -void QmlGraphicsAnimatedImageItem::setCurrentFrame(int frame) -{ - Q_D(QmlGraphicsAnimatedImageItem); - if (!d->_movie) - return; - d->_movie->jumpToFrame(frame); -} - -int QmlGraphicsAnimatedImageItem::frameCount() const -{ - Q_D(const QmlGraphicsAnimatedImageItem); - if (!d->_movie) - return 0; - return d->_movie->frameCount(); -} - -void QmlGraphicsAnimatedImageItem::setSource(const QUrl &url) -{ - Q_D(QmlGraphicsAnimatedImageItem); - if (url == d->url) - return; - - delete d->_movie; - d->_movie = 0; - - if (d->reply) { - d->reply->deleteLater(); - d->reply = 0; - } - - d->url = qmlContext(this)->resolvedUrl(url); - - if (url.isEmpty()) { - delete d->_movie; - d->status = Null; - } else { - d->status = Loading; - QNetworkRequest req(d->url); - d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req); - QObject::connect(d->reply, SIGNAL(finished()), - this, SLOT(movieRequestFinished())); - } - - emit statusChanged(d->status); -} - -void QmlGraphicsAnimatedImageItem::movieRequestFinished() -{ - Q_D(QmlGraphicsAnimatedImageItem); - d->_movie = new QMovie(d->reply); - if (!d->_movie->isValid()){ - qWarning() << "Error Reading Animated Image File " << d->url; - delete d->_movie; - d->_movie = 0; - return; - } - connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)), - this, SLOT(playingStatusChanged())); - connect(d->_movie, SIGNAL(frameChanged(int)), - this, SLOT(movieUpdate())); - d->_movie->setCacheMode(QMovie::CacheAll); - if(d->playing) - d->_movie->start(); - else - d->_movie->jumpToFrame(0); - if(d->paused) - d->_movie->setPaused(true); - setPixmap(d->_movie->currentPixmap()); -} - -void QmlGraphicsAnimatedImageItem::movieUpdate() -{ - Q_D(QmlGraphicsAnimatedImageItem); - setPixmap(d->_movie->currentPixmap()); - emit frameChanged(); -} - -void QmlGraphicsAnimatedImageItem::playingStatusChanged() -{ - Q_D(QmlGraphicsAnimatedImageItem); - if((d->_movie->state() != QMovie::NotRunning) != d->playing){ - d->playing = (d->_movie->state() != QMovie::NotRunning); - emit playingChanged(); - } - if((d->_movie->state() == QMovie::Paused) != d->paused){ - d->playing = (d->_movie->state() == QMovie::Paused); - emit pausedChanged(); - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/extra/qfxanimatedimageitem.h b/src/declarative/extra/qfxanimatedimageitem.h deleted file mode 100644 index 782f920..0000000 --- a/src/declarative/extra/qfxanimatedimageitem.h +++ /dev/null @@ -1,106 +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 QFXANIMATEDIMAGEITEM_H -#define QFXANIMATEDIMAGEITEM_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QMovie; -class QmlGraphicsAnimatedImageItemPrivate; - -class Q_DECLARATIVE_EXPORT QmlGraphicsAnimatedImageItem : public QmlGraphicsImage -{ - Q_OBJECT - - Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) - Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) - Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY frameChanged) - Q_PROPERTY(int frameCount READ frameCount) -public: - QmlGraphicsAnimatedImageItem(QmlGraphicsItem *parent=0); - ~QmlGraphicsAnimatedImageItem(); - - bool isPlaying() const; - void setPlaying(bool play); - - bool isPaused() const; - void setPaused(bool pause); - - int currentFrame() const; - void setCurrentFrame(int frame); - - int frameCount() const; - - // Extends QmlGraphicsImage's src property*/ - virtual void setSource(const QUrl&); - -Q_SIGNALS: - void playingChanged(); - void pausedChanged(); - void frameChanged(); - -private Q_SLOTS: - void movieUpdate(); - void movieRequestFinished(); - void playingStatusChanged(); - -protected: - QmlGraphicsAnimatedImageItem(QmlGraphicsAnimatedImageItemPrivate &dd, QmlGraphicsItem *parent); - -private: - Q_DISABLE_COPY(QmlGraphicsAnimatedImageItem) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsAnimatedImageItem) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsAnimatedImageItem) - -QT_END_HEADER - -#endif diff --git a/src/declarative/extra/qfxanimatedimageitem_p.h b/src/declarative/extra/qfxanimatedimageitem_p.h deleted file mode 100644 index e61c488..0000000 --- a/src/declarative/extra/qfxanimatedimageitem_p.h +++ /dev/null @@ -1,81 +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 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 - -QT_BEGIN_NAMESPACE - -class QMovie; -class QNetworkReply; - -class QmlGraphicsAnimatedImageItemPrivate : public QmlGraphicsImagePrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsAnimatedImageItem) - -public: - QmlGraphicsAnimatedImageItemPrivate() - : playing(true), paused(false), _movie(0), reply(0) - { - } - - bool playing; - bool paused; - QMovie *_movie; - QNetworkReply *reply; -}; - -QT_END_NAMESPACE - -#endif // QFXANIMATEDIMAGE_P_H diff --git a/src/declarative/extra/qfxintegermodel.cpp b/src/declarative/extra/qfxintegermodel.cpp deleted file mode 100644 index 496cd3e..0000000 --- a/src/declarative/extra/qfxintegermodel.cpp +++ /dev/null @@ -1,126 +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 "qfxintegermodel.h" - -QT_BEGIN_NAMESPACE - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,IntegerModel,QmlGraphicsIntegerModel) - -class QmlGraphicsIntegerModelPrivate -{ -public: - QmlGraphicsIntegerModelPrivate() : minimum(0), maximum(0) {} - int minimum; - int maximum; -}; - -QmlGraphicsIntegerModel::QmlGraphicsIntegerModel(QObject *parent) - : QListModelInterface(parent) -{ - d = new QmlGraphicsIntegerModelPrivate; -} - -QmlGraphicsIntegerModel::~QmlGraphicsIntegerModel() -{ - delete d; -} - -int QmlGraphicsIntegerModel::minimum() const -{ - return d->minimum; -} - -void QmlGraphicsIntegerModel::setMinimum(int minimum) -{ - d->minimum = minimum; -} - -int QmlGraphicsIntegerModel::maximum() const -{ - return d->maximum; -} - -void QmlGraphicsIntegerModel::setMaximum(int maximum) -{ - d->maximum = maximum; -} - -int QmlGraphicsIntegerModel::count() const -{ - return qMax(0, d->maximum - d->minimum + 1); -} - -QHash QmlGraphicsIntegerModel::data(int index, const QList &roles) const -{ - QHash returnHash; - - for (int i = 0; i < roles.size(); ++i) { - int role = roles.at(i); - QVariant info; - switch(role) { - case Qt::DisplayRole: - info = QVariant(QString::number(d->minimum+index)); - break; - default: - break; - } - returnHash.insert(role, info); - } - return returnHash; -} - -QString QmlGraphicsIntegerModel::toString(int role) const -{ - switch(role) { - case Qt::DisplayRole: - return QLatin1String("display"); - default: - return QLatin1String(""); - } -} - -QList QmlGraphicsIntegerModel::roles() const -{ - return QList() << Qt::DisplayRole; -} - -QT_END_NAMESPACE diff --git a/src/declarative/extra/qfxintegermodel.h b/src/declarative/extra/qfxintegermodel.h deleted file mode 100644 index cf69bdc..0000000 --- a/src/declarative/extra/qfxintegermodel.h +++ /dev/null @@ -1,86 +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 QFXINTMODEL_H -#define QFXINTMODEL_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsIntegerModelPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsIntegerModel : public QListModelInterface -{ - Q_OBJECT -public: - QmlGraphicsIntegerModel(QObject *parent=0); - ~QmlGraphicsIntegerModel(); - - Q_PROPERTY(int minimum READ minimum WRITE setMinimum) - int minimum() const; - void setMinimum(int); - - Q_PROPERTY(int maximum READ maximum WRITE setMaximum) - int maximum() const; - void setMaximum(int); - - int count() const; - QHash data(int index, const QList &roles) const; - QList roles() const; - QString toString(int role) const; - -private: - QmlGraphicsIntegerModelPrivate *d; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsIntegerModel) - -QT_END_HEADER - -#endif diff --git a/src/declarative/extra/qfxparticles.cpp b/src/declarative/extra/qfxparticles.cpp deleted file mode 100644 index 0bb4826..0000000 --- a/src/declarative/extra/qfxparticles.cpp +++ /dev/null @@ -1,1134 +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/qfxitem_p.h" - -#include -#include -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#define M_PI_2 (M_PI / 2.) -#endif -#ifndef INT_MAX -#define INT_MAX 2147483647 -#endif -#include -#include -#include -#include - -#include "qfxparticles.h" -#include -#include -#include - -QT_BEGIN_NAMESPACE -#define PI_SQR 9.8696044 -// parabolic approximation -inline qreal fastSin(qreal theta) -{ - const qreal b = 4 / M_PI; - const qreal c = -4 / PI_SQR; - - qreal y = b * theta + c * theta * qAbs(theta); - return y; -} - -inline qreal fastCos(qreal theta) -{ - theta += M_PI_2; - if (theta > M_PI) - theta -= 2 * M_PI; - - return fastSin(theta); -} - -class QmlGraphicsParticle -{ -public: - QmlGraphicsParticle(int time) : lifeSpan(1000), fadeOutAge(800) - , opacity(0), birthTime(time), x_velocity(0), y_velocity(0) - , state(FadeIn), data(0) - { - } - - int lifeSpan; - int fadeOutAge; - qreal x; - qreal y; - qreal opacity; - int birthTime; - qreal x_velocity; - qreal y_velocity; - enum State { FadeIn, Solid, FadeOut }; - State state; - void *data; -}; - -//--------------------------------------------------------------------------- - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotion,QmlGraphicsParticleMotion) - -/*! - \class QmlGraphicsParticleMotion - \ingroup group_effects - \brief The QmlGraphicsParticleMotion class is the base class for particle motion. - \internal - - This class causes the particles to remain static. -*/ - -/*! - Constructs a QmlGraphicsParticleMotion with parent object \a parent. -*/ -QmlGraphicsParticleMotion::QmlGraphicsParticleMotion(QObject *parent) : - QObject(parent) -{ -} - -/*! - Move the \a particle to its new position. \a interval is the number of - milliseconds elapsed since it was last moved. -*/ -void QmlGraphicsParticleMotion::advance(QmlGraphicsParticle &particle, int interval) -{ - Q_UNUSED(particle); - Q_UNUSED(interval); -} - -/*! - The \a particle has just been created. Some motion strategies require - additional state information. This can be allocated by this function. -*/ -void QmlGraphicsParticleMotion::created(QmlGraphicsParticle &particle) -{ - Q_UNUSED(particle); -} - -/*! - The \a particle is about to be destroyed. Any additional memory - that has been allocated for the particle should be freed. -*/ -void QmlGraphicsParticleMotion::destroy(QmlGraphicsParticle &particle) -{ - Q_UNUSED(particle); -} - -/*! - \qmlclass ParticleMotionLinear - \brief The ParticleMotionLinear object moves particles linearly. - - \sa Particles -*/ - -/*! - \internal - \class QmlGraphicsParticleMotionLinear - \ingroup group_effects - \brief The QmlGraphicsParticleMotionLinear class moves the particles linearly. -*/ - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionLinear,QmlGraphicsParticleMotionLinear) - -void QmlGraphicsParticleMotionLinear::advance(QmlGraphicsParticle &p, int interval) -{ - p.x += interval * p.x_velocity; - p.y += interval * p.y_velocity; -} - -/*! - \qmlclass ParticleMotionGravity - \brief The ParticleMotionGravity object moves particles towards a point. - - \sa Particles -*/ - -/*! - \internal - \class QmlGraphicsParticleMotionGravity - \ingroup group_effects - \brief The QmlGraphicsParticleMotionGravity class moves the particles towards a point. -*/ - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionGravity,QmlGraphicsParticleMotionGravity) - -/*! - \qmlproperty int ParticleMotionGravity::xattractor - \qmlproperty int ParticleMotionGravity::yattractor - These properties hold the x and y coordinates of the point attracting the particles. -*/ - -/*! - \qmlproperty int ParticleMotionGravity::acceleration - This property holds the acceleration to apply to the particles. -*/ - -/*! - \property QmlGraphicsParticleMotionGravity::xattractor - \brief the x coordinate of the point attracting the particles. -*/ - -/*! - \property QmlGraphicsParticleMotionGravity::yattractor - \brief the y coordinate of the point attracting the particles. -*/ - -/*! - \property QmlGraphicsParticleMotionGravity::acceleration - \brief the acceleration to apply to the particles. -*/ - -void QmlGraphicsParticleMotionGravity::advance(QmlGraphicsParticle &p, int interval) -{ - qreal xdiff = p.x - _xAttr; - qreal ydiff = p.y - _yAttr; - - qreal xcomp = xdiff / (xdiff + ydiff); - qreal ycomp = ydiff / (xdiff + ydiff); - - p.x_velocity += xcomp * _accel * interval; - p.y_velocity += ycomp * _accel * interval; - - p.x += interval * p.x_velocity; - p.y += interval * p.y_velocity; -} - -/*! - \qmlclass ParticleMotionWander - \brief The ParticleMotionWander object moves particles in a somewhat random fashion. - - The particles will continue roughly in the original direction, however will randomly - drift to each side. - - The code below produces an effect similar to falling snow. - - \qml -Rectangle { - width: 240 - height: 320 - color: "black" - - Particles { - y: 0 - width: parent.width - height: 30 - source: "star.png" - lifeSpan: 5000 - count: 50 - angle: 70 - angleDeviation: 36 - velocity: 30 - velocityDeviation: 10 - ParticleMotionWander { - xvariance: 30 - pace: 100 - } - } -} - \endqml - - \sa Particles -*/ - -/*! - \internal - \class QmlGraphicsParticleMotionWander - \ingroup group_effects - \brief The QmlGraphicsParticleMotionWander class moves particles in a somewhat random fashion. - - The particles will continue roughly in the original direction, however will randomly - drift to each side. -*/ - -/*! - \qmlproperty int QmlGraphicsParticleMotionWander::xvariance - \qmlproperty int QmlGraphicsParticleMotionWander::yvariance - - These properties set the amount to wander in the x and y directions. -*/ - -/*! - \qmlproperty int QmlGraphicsParticleMotionWander::pace - This property holds how quickly the paricles will move from side to side. -*/ - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionWander,QmlGraphicsParticleMotionWander) - -void QmlGraphicsParticleMotionWander::advance(QmlGraphicsParticle &p, int interval) -{ - if (!particles) - particles = qobject_cast(parent()); - if (particles) { - Data *d = (Data*)p.data; - if (_xvariance != 0.) { - qreal xdiff = p.x_velocity - d->x_targetV; - if ((xdiff > d->x_peak && d->x_var > 0.0) || (xdiff < -d->x_peak && d->x_var < 0.0)) { - d->x_var = -d->x_var; - d->x_peak = _xvariance + _xvariance * qreal(rand()) / RAND_MAX; - } - p.x_velocity += d->x_var * interval; - } - p.x += interval * p.x_velocity; - - if (_yvariance != 0.) { - qreal ydiff = p.y_velocity - d->y_targetV; - if ((ydiff > d->y_peak && d->y_var > 0.0) || (ydiff < -d->y_peak && d->y_var < 0.0)) { - d->y_var = -d->y_var; - d->y_peak = _yvariance + _yvariance * qreal(rand()) / RAND_MAX; - } - p.y_velocity += d->y_var * interval; - } - p.y += interval * p.y_velocity; - } -} - -void QmlGraphicsParticleMotionWander::created(QmlGraphicsParticle &p) -{ - if (!p.data) { - Data *d = new Data; - p.data = (void*)d; - d->x_targetV = p.x_velocity; - d->y_targetV = p.y_velocity; - d->x_peak = _xvariance; - d->y_peak = _yvariance; - d->x_var = _pace * qreal(rand()) / RAND_MAX / 1000.0; - d->y_var = _pace * qreal(rand()) / RAND_MAX / 1000.0; - } -} - -void QmlGraphicsParticleMotionWander::destroy(QmlGraphicsParticle &p) -{ - if (p.data) - delete (Data*)p.data; -} - -//--------------------------------------------------------------------------- -class QmlGraphicsParticlesPainter : public QmlGraphicsItem -{ -public: - QmlGraphicsParticlesPainter(QmlGraphicsParticlesPrivate *p, QmlGraphicsItem* parent) - : QmlGraphicsItem(parent), d(p) - { - setFlag(QGraphicsItem::ItemHasNoContents, false); - maxX = minX = maxY = minY = 0; - } - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - - void updateSize(); - - qreal maxX; - qreal minX; - qreal maxY; - qreal minY; - QmlGraphicsParticlesPrivate* d; -}; - -//--------------------------------------------------------------------------- -class QmlGraphicsParticlesPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsParticles) -public: - QmlGraphicsParticlesPrivate() - : count(1), lifeSpan(1000), lifeSpanDev(1000), fadeInDur(200), fadeOutDur(300) - , angle(0), angleDev(0), velocity(0), velocityDev(0) - , addParticleTime(0), addParticleCount(0), lastAdvTime(0), stream(false), streamDelay(0) - , emitting(true), motion(0), pendingPixmapCache(false), clock(this) - { - } - - ~QmlGraphicsParticlesPrivate() - { - } - - void init() - { - Q_Q(QmlGraphicsParticles); - paintItem = new QmlGraphicsParticlesPainter(this, q); - } - - void tick(int time); - void createParticle(int time); - void updateOpacity(QmlGraphicsParticle &p, int age); - - QUrl url; - QPixmap image; - int count; - int lifeSpan; - int lifeSpanDev; - int fadeInDur; - int fadeOutDur; - qreal angle; - qreal angleDev; - qreal velocity; - qreal velocityDev; - int addParticleTime; - int addParticleCount; - int lastAdvTime; - bool stream; - int streamDelay; - bool emitting; - QmlGraphicsParticleMotion *motion; - QmlGraphicsParticlesPainter *paintItem; - - bool pendingPixmapCache; - - QList particles; - QTickAnimationProxy clock; - -}; - -void QmlGraphicsParticlesPrivate::tick(int time) -{ - Q_Q(QmlGraphicsParticles); - if (!motion) - motion = new QmlGraphicsParticleMotionLinear(q); - - int oldCount = particles.count(); - int removed = 0; - int interval = time - lastAdvTime; - for (int i = 0; i < particles.count(); ) { - QmlGraphicsParticle &particle = particles[i]; - int age = time - particle.birthTime; - if (age >= particle.lifeSpan) { - QmlGraphicsParticle part = particles.takeAt(i); - motion->destroy(part); - ++removed; - } else { - updateOpacity(particle, age); - motion->advance(particle, interval); - ++i; - } - } - - while(removed-- && particles.count() < count && emitting) - createParticle(time); - - if (!addParticleTime) - addParticleTime = time; - - if (particles.count() < count && emitting) { - qreal perc = (lifeSpanDev <= 0)?(1.):(qreal(time - addParticleTime) / qreal(lifeSpanDev)); - int percCount = addParticleCount + (int)perc * (count - addParticleCount); - int streamWidth = -1; - if (stream){ - if (streamDelay > time){ - streamWidth = 0; - }else{ - int missed = time - streamDelay; - qreal streamWidthReal = qreal(count)/qreal(lifeSpan); - if (streamWidthReal < 1){ - streamDelay = time + (int)(1.0/streamWidthReal); - streamWidth = 1; - streamWidth += missed/streamDelay; - }else{ - streamWidth = qRound(streamWidthReal * (time-lastAdvTime)); - } - } - } - while(particles.count() < count && - (!stream || (particles.count() < percCount && streamWidth--))) - createParticle(time); - } - - lastAdvTime = time; - paintItem->updateSize(); - paintItem->update(); - if (!(oldCount || particles.count()) && (!count || !emitting)) { - lastAdvTime = 0; - clock.stop(); - } -} - -void QmlGraphicsParticlesPrivate::createParticle(int time) -{ -#ifdef Q_ENABLE_PERFORMANCE_LOG - QmlPerfTimer x; -#endif - Q_Q(QmlGraphicsParticles); - QmlGraphicsParticle p(time); - p.x = q->x() + q->width() * qreal(rand()) / RAND_MAX - image.width()/2.0; - p.y = q->y() + q->height() * qreal(rand()) / RAND_MAX - image.height()/2.0; - p.lifeSpan = lifeSpan; - if (lifeSpanDev) - p.lifeSpan += int(lifeSpanDev/2 - lifeSpanDev * qreal(rand()) / RAND_MAX); - p.fadeOutAge = p.lifeSpan - fadeOutDur; - if (fadeInDur == 0.) { - p.state= QmlGraphicsParticle::Solid; - p.opacity = 1.0; - } - qreal a = angle; - if (angleDev) - a += angleDev/2 - angleDev * qreal(rand()) / RAND_MAX; - if (a > M_PI) - a = a - 2 * M_PI; - qreal v = velocity; - if (velocityDev) - v += velocityDev/2 - velocityDev * qreal(rand()) / RAND_MAX; - p.x_velocity = v * fastCos(a); - p.y_velocity = v * fastSin(a); - particles.append(p); - motion->created(particles.last()); -} - -void QmlGraphicsParticlesPrivate::updateOpacity(QmlGraphicsParticle &p, int age) -{ - switch (p.state) { - case QmlGraphicsParticle::FadeIn: - if (age <= fadeInDur) { - p.opacity = qreal(age) / fadeInDur; - break; - } else { - p.opacity = 1.0; - p.state = QmlGraphicsParticle::Solid; - // Fall through - } - case QmlGraphicsParticle::Solid: - if (age <= p.fadeOutAge) { - break; - } else { - p.state = QmlGraphicsParticle::FadeOut; - // Fall through - } - case QmlGraphicsParticle::FadeOut: - p.opacity = qreal(p.lifeSpan - age) / fadeOutDur; - break; - } -} - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Particles,QmlGraphicsParticles) - -/*! - \qmlclass Particles - \brief The Particles object generates and moves particles. - \inherits Item - - The particles created by this object cannot be dealt with directly, they can only be controlled through the parameters of the Particles object. The particles are all the same pixmap, specified by the user. - - The particles are painted relative to the parent of the Particles object. Moving the - Particles object will not move the particles already emitted. - - The below example creates two differently behaving particle sources. - The top one has particles falling from the top like snow, - the lower one has particles expelled up like a fountain. - - \qml -Rectangle { - width: 240 - height: 320 - color: "black" - Particles { - y: 0 - width: parent.width - height: 30 - source: "star.png" - lifeSpan: 5000 - count: 50 - angle: 70 - angleDeviation: 36 - velocity: 30 - velocityDeviation: 10 - ParticleMotionWander { - xvariance: 30 - pace: 100 - } - } - Particles { - y: 300 - x: 120 - width: 1 - height: 1 - source: "star.png" - lifeSpan: 5000 - count: 200 - angle: 270 - angleDeviation: 45 - velocity: 50 - velocityDeviation: 30 - ParticleMotionGravity { - yattractor: 1000 - xattractor: 0 - acceleration: 25 - } - } -} - \endqml - \image particles.gif -*/ - -/*! - \internal - \class QmlGraphicsParticles - \ingroup group_effects - \brief The QmlGraphicsParticles class generates and moves particles. -*/ - -QmlGraphicsParticles::QmlGraphicsParticles(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsParticlesPrivate), parent) -{ - Q_D(QmlGraphicsParticles); - d->init(); -} - -QmlGraphicsParticles::QmlGraphicsParticles(QmlGraphicsParticlesPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ - Q_D(QmlGraphicsParticles); - d->init(); -} - -QmlGraphicsParticles::~QmlGraphicsParticles() -{ - Q_D(QmlGraphicsParticles); - if (d->pendingPixmapCache) - QmlGraphicsPixmapCache::cancelGet(d->url, this); -} - -/*! - \qmlproperty string Particles::src - This property holds the URL of the particle image. -*/ - -/*! - \property QmlGraphicsParticles::source - \brief the URL of the particle image. -*/ -QUrl QmlGraphicsParticles::source() const -{ - Q_D(const QmlGraphicsParticles); - return d->url; -} - -void QmlGraphicsParticles::imageLoaded() -{ - Q_D(QmlGraphicsParticles); - d->pendingPixmapCache = false; - QmlGraphicsPixmapCache::find(d->url, &d->image); - d->paintItem->updateSize(); - d->paintItem->update(); -} - -void QmlGraphicsParticles::setSource(const QUrl &name) -{ - Q_D(QmlGraphicsParticles); - - if ((d->url.isEmpty() == name.isEmpty()) && name == d->url) - return; - - if (d->pendingPixmapCache) { - QmlGraphicsPixmapCache::cancelGet(d->url, this); - d->pendingPixmapCache = false; - } - if (name.isEmpty()) { - d->url = name; - d->image = QPixmap(); - d->paintItem->updateSize(); - d->paintItem->update(); - } else { - d->url = name; - Q_ASSERT(!name.isRelative()); - QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->image); - if (reply) { - connect(reply, SIGNAL(finished()), this, SLOT(imageLoaded())); - d->pendingPixmapCache = true; - } else { - //### unify with imageLoaded - d->paintItem->updateSize(); - d->paintItem->update(); - } - } -} - -/*! - \qmlproperty int Particles::count - This property holds the target number of particles -*/ - -/*! - \property QmlGraphicsParticles::count - \brief the target number of particles -*/ -int QmlGraphicsParticles::count() const -{ - Q_D(const QmlGraphicsParticles); - return d->count; -} - -void QmlGraphicsParticles::setCount(int cnt) -{ - Q_D(QmlGraphicsParticles); - if (cnt == d->count) - return; - - int oldCount = d->count; - d->count = cnt; - d->addParticleTime = 0; - d->addParticleCount = d->particles.count(); - if (!oldCount && d->clock.state() != QAbstractAnimation::Running && d->count) { - d->clock.start(); - } - d->paintItem->updateSize(); - d->paintItem->update(); -} - -/*! - \qmlproperty int Particles::lifeSpan - \qmlproperty int Particles::lifeSpanDeviation - - These properties describe the life span of each particle. - - The default lifespan for a particle is 1000ms. - - lifeSpanDeviation randomly varies the lifeSpan up to the specified variation. For - example, the following creates particles whose lifeSpan will vary - from 150ms to 250ms: - - \qml -Particles { - source: "star.png" - lifeSpan: 200 - lifeSpanDeviation: 100 -} - \endqml -*/ - -/*! - \property QmlGraphicsParticles::lifeSpan - \brief the life span of each particle. - - Default value is 1000ms. - - \sa QmlGraphicsParticles::lifeSpanDeviation -*/ -int QmlGraphicsParticles::lifeSpan() const -{ - Q_D(const QmlGraphicsParticles); - return d->lifeSpan; -} - -void QmlGraphicsParticles::setLifeSpan(int ls) -{ - Q_D(QmlGraphicsParticles); - d->lifeSpan = ls; -} - -/*! - \property QmlGraphicsParticles::lifeSpanDeviation - \brief the maximum possible deviation from the set lifeSpan. - - Randomly varies the lifeSpan up to the specified variation. For - example, the following creates particles whose lifeSpan will vary - from 150ms to 250ms: - -\qml -Particles { - source: "star.png" - lifeSpan: 200 - lifeSpanDeviation: 100 -} -\endqml - - \sa QmlGraphicsParticles::lifeSpan -*/ -int QmlGraphicsParticles::lifeSpanDeviation() const -{ - Q_D(const QmlGraphicsParticles); - return d->lifeSpanDev; -} - -void QmlGraphicsParticles::setLifeSpanDeviation(int dev) -{ - Q_D(QmlGraphicsParticles); - d->lifeSpanDev = dev; -} - -/*! - \qmlproperty int Particles::fadeInDuration - \qmlproperty int Particles::fadeOutDuration - These properties hold the time taken to fade the particles in and out. - - By default fade in is 200ms and fade out is 300ms. -*/ - -/*! - \property QmlGraphicsParticles::fadeInDuration - \brief the time taken to fade in the particles. - - Default value is 200ms. -*/ -int QmlGraphicsParticles::fadeInDuration() const -{ - Q_D(const QmlGraphicsParticles); - return d->fadeInDur; -} - -void QmlGraphicsParticles::setFadeInDuration(int dur) -{ - Q_D(QmlGraphicsParticles); - if (dur >= 0.0) - d->fadeInDur = dur; -} - -/*! - \property QmlGraphicsParticles::fadeOutDuration - \brief the time taken to fade out the particles. - - Default value is 300ms. -*/ -int QmlGraphicsParticles::fadeOutDuration() const -{ - Q_D(const QmlGraphicsParticles); - return d->fadeOutDur; -} - -void QmlGraphicsParticles::setFadeOutDuration(int dur) -{ - Q_D(QmlGraphicsParticles); - if (dur >= 0.0) - d->fadeOutDur = dur; -} - -/*! - \qmlproperty real Particles::angle - \qmlproperty real Particles::angleDeviation - - These properties control particle direction. - - angleDeviation randomly varies the direction up to the specified variation. For - example, the following creates particles whose initial direction will - vary from 15 degrees to 105 degrees: - - \qml -Particles { - source: "star.png" - angle: 60 - angleDeviation: 90 -} - \endqml -*/ - -/*! - \property QmlGraphicsParticles::angle - \brief the initial angle of direction. - - \sa QmlGraphicsParticles::angleDeviation -*/ -qreal QmlGraphicsParticles::angle() const -{ - Q_D(const QmlGraphicsParticles); - return d->angle * 180.0 / M_PI; -} - -void QmlGraphicsParticles::setAngle(qreal angle) -{ - Q_D(QmlGraphicsParticles); - d->angle = angle * M_PI / 180.0; -} - -/*! - \property QmlGraphicsParticles::angleDeviation - \brief the maximum possible deviation from the set angle. - - Randomly varies the direction up to the specified variation. For - example, the following creates particles whose initial direction will - vary from 15 degrees to 105 degrees: - -\qml -Particles { - source: "star.png" - angle: 60 - angleDeviation: 90 -} -\endqml - - \sa QmlGraphicsParticles::angle -*/ -qreal QmlGraphicsParticles::angleDeviation() const -{ - Q_D(const QmlGraphicsParticles); - return d->angleDev * 180.0 / M_PI; -} - -void QmlGraphicsParticles::setAngleDeviation(qreal dev) -{ - Q_D(QmlGraphicsParticles); - d->angleDev = dev * M_PI / 180.0;; -} - -/*! - \qmlproperty real Particles::velocity - \qmlproperty real Particles::velocityDeviation - - These properties control the velocity of the particles. - - velocityDeviation randomly varies the velocity up to the specified variation. For - example, the following creates particles whose initial velocity will - vary from 40 to 60. - - \qml -Particles { - source: "star.png" - velocity: 50 - velocityDeviation: 20 -} - \endqml -*/ - -/*! - \property QmlGraphicsParticles::velocity - \brief the initial velocity of the particles. - - \sa QmlGraphicsParticles::velocityDeviation -*/ -qreal QmlGraphicsParticles::velocity() const -{ - Q_D(const QmlGraphicsParticles); - return d->velocity * 1000.0; -} - -void QmlGraphicsParticles::setVelocity(qreal velocity) -{ - Q_D(QmlGraphicsParticles); - d->velocity = velocity / 1000.0; -} - -/*! - \property QmlGraphicsParticles::velocityDeviation - \brief the maximum possible deviation from the set velocity. - - Randomly varies the velocity up to the specified variation. For - example, the following creates particles whose initial velocity will - vary from 40 to 60. - -\qml -Particles { - source: "star.png" - velocity: 50 - velocityDeviation: 20 -} -\endqml - - \sa QmlGraphicsParticles::velocity -*/ -qreal QmlGraphicsParticles::velocityDeviation() const -{ - Q_D(const QmlGraphicsParticles); - return d->velocityDev * 1000.0; -} - -void QmlGraphicsParticles::setVelocityDeviation(qreal velocity) -{ - Q_D(QmlGraphicsParticles); - d->velocityDev = velocity / 1000.0; -} - -/*! - \qmlproperty bool Particles::streamIn - This property determines whether the particles stream in at a constant rate - - When stream is set to true the particles will stream in at a constant rate. - Otherwise the particles will appear as a clump. Note that this only affects the - start of the particle effect, variables such as lifespan deviation can cause the - particles to unclump over time. -*/ -/*! - \property QmlGraphicsParticles::streamIn - \brief determines whether the particles stream in at a constant rate - - When stream is set to true the particles will stream in at a constant rate. - Otherwise the particles will appear as a clump. Note that this only affects the - start of the particle effect, variables such as lifespan deviation can cause the - -*/ -//The name may need a rethink -bool QmlGraphicsParticles::streamIn() const -{ - Q_D(const QmlGraphicsParticles); - return d->stream; -} - -void QmlGraphicsParticles::setStreamIn(bool b) -{ - Q_D(QmlGraphicsParticles); - d->stream = b; -} - -/*! - \qmlproperty bool Particles::emitting - This property determines whether new particles are created - - If emitting is set to false no new particles will be created. This means that - when a particle reaches the end of its lifespan it is not replaced. This - property can be used to turn particles on and off with a more natural look. - - The default setting is true. Note that if it initialized to false no particles - will be produced until it is set to true. -*/ -/*! - \property QmlGraphicsParticles::emitting - If emitting is set to false no new particles will be created. This means that - when a particle reaches the end of its lifespan it is not replaced. This - property can be used to turn particles on and off with a more natural look. - - The default setting is true. Note that if it initialized to false no particles - will be produced until it is set to true. -*/ -bool QmlGraphicsParticles::emitting() const -{ - Q_D(const QmlGraphicsParticles); - return d->emitting; -} - -void QmlGraphicsParticles::setEmitting(bool r) -{ - Q_D(QmlGraphicsParticles); - d->emitting = r; - if (d->count && r) - d->clock.start(); -} -/*! - \qmlproperty ParticleMotion Particles::motion - This property sets the type of motion to apply to the particles. - - When a particle is created it will have an initial direction and velocity. - The motion of the particle during its lifeSpan is then influenced by the - motion property. - - Default motion is ParticleMotionLinear. -*/ - -/*! - \property QmlGraphicsParticles::motion - \brief sets the type of motion to apply to the particles. - - When a particle is created it will have an initial direction and velocity. - The motion of the particle during its lifeSpan is then influenced by the - motion property. - - Default motion is QmlGraphicsParticleMotionLinear. -*/ -QmlGraphicsParticleMotion *QmlGraphicsParticles::motion() const -{ - Q_D(const QmlGraphicsParticles); - return d->motion; -} - -void QmlGraphicsParticles::setMotion(QmlGraphicsParticleMotion *motion) -{ - Q_D(QmlGraphicsParticles); - d->motion = motion; -} - -void QmlGraphicsParticlesPainter::updateSize() -{ - if (!isComponentComplete()) - return; - - const int parentX = parentItem()->x(); - const int parentY = parentItem()->y(); - for (int i = 0; i < d->particles.count(); ++i) { - const QmlGraphicsParticle &particle = d->particles.at(i); - if(particle.x > maxX) - maxX = particle.x; - if(particle.x < minX) - minX = particle.x; - if(particle.y > maxY) - maxY = particle.y; - if(particle.y < minY) - minY = particle.y; - } - - int myWidth = (int)(maxX-minX+0.5)+d->image.width(); - int myX = (int)(minX - parentX); - int myHeight = (int)(maxY-minY+0.5)+d->image.height(); - int myY = (int)(minY - parentY); - setWidth(myWidth); - setHeight(myHeight); - setX(myX); - setY(myY); -} - -void QmlGraphicsParticles::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - Q_UNUSED(p); - //painting is done by the ParticlesPainter, so it can have the right size -} - -void QmlGraphicsParticlesPainter::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - if (d->image.isNull() || d->particles.isEmpty()) - return; - - const int myX = x() + parentItem()->x(); - const int myY = y() + parentItem()->y(); - - static QVarLengthArray pixmapData; - if (pixmapData.count() < d->particles.count()) - pixmapData.resize(d->particles.count()); - - const QRectF sourceRect = d->image.rect(); - for (int i = 0; i < d->particles.count(); ++i) { - const QmlGraphicsParticle &particle = d->particles.at(i); - pixmapData[i].point = QPointF(particle.x - myX, particle.y - myY); - pixmapData[i].opacity = particle.opacity; - - //these never change - pixmapData[i].rotation = 0; - pixmapData[i].scaleX = 1; - pixmapData[i].scaleY = 1; - pixmapData[i].source = sourceRect; - } - qDrawPixmaps(p, pixmapData.data(), d->particles.count(), d->image); -} - -void QmlGraphicsParticles::componentComplete() -{ - Q_D(QmlGraphicsParticles); - QmlGraphicsItem::componentComplete(); - if (d->count) { - d->paintItem->updateSize(); - d->clock.start(); - } - if (d->lifeSpanDev > d->lifeSpan) - d->lifeSpanDev = d->lifeSpan; -} - -QT_END_NAMESPACE diff --git a/src/declarative/extra/qfxparticles.h b/src/declarative/extra/qfxparticles.h deleted file mode 100644 index 5e5a581..0000000 --- a/src/declarative/extra/qfxparticles.h +++ /dev/null @@ -1,230 +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 QFXPARTICLES_H -#define QFXPARTICLES_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsParticle; -class QmlGraphicsParticles; -class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotion : public QObject -{ - Q_OBJECT -public: - QmlGraphicsParticleMotion(QObject *parent=0); - - virtual void advance(QmlGraphicsParticle &, int interval); - virtual void created(QmlGraphicsParticle &); - virtual void destroy(QmlGraphicsParticle &); -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionLinear : public QmlGraphicsParticleMotion -{ - Q_OBJECT -public: - QmlGraphicsParticleMotionLinear(QObject *parent=0) - : QmlGraphicsParticleMotion(parent) {} - - virtual void advance(QmlGraphicsParticle &, int interval); -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionGravity : public QmlGraphicsParticleMotion -{ - Q_OBJECT - - Q_PROPERTY(int xattractor READ xAttractor WRITE setXAttractor) - Q_PROPERTY(int yattractor READ yAttractor WRITE setYAttractor) - Q_PROPERTY(int acceleration READ acceleration WRITE setAcceleration) -public: - QmlGraphicsParticleMotionGravity(QObject *parent=0) - : QmlGraphicsParticleMotion(parent), _xAttr(0), _yAttr(0), _accel(0.00005) {} - - int xAttractor() const { return _xAttr; } - void setXAttractor(int x) { _xAttr = x; } - - int yAttractor() const { return _yAttr; } - void setYAttractor(int y) { _yAttr = y; } - - int acceleration() const { return int(_accel * 1000000); } - void setAcceleration(int accel) { _accel = qreal(accel)/1000000.0; } - - virtual void advance(QmlGraphicsParticle &, int interval); - -private: - int _xAttr; - int _yAttr; - qreal _accel; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionWander : public QmlGraphicsParticleMotion -{ - Q_OBJECT -public: - QmlGraphicsParticleMotionWander() - : QmlGraphicsParticleMotion(), particles(0), _xvariance(0), _yvariance(0) {} - - virtual void advance(QmlGraphicsParticle &, int interval); - virtual void created(QmlGraphicsParticle &); - virtual void destroy(QmlGraphicsParticle &); - - struct Data { - qreal x_targetV; - qreal y_targetV; - qreal x_peak; - qreal y_peak; - qreal x_var; - qreal y_var; - }; - - Q_PROPERTY(int xvariance READ xVariance WRITE setXVariance) - int xVariance() const { return int(_xvariance * 1000); } - void setXVariance(int var) { _xvariance = var / 1000.0; } - - Q_PROPERTY(int yvariance READ yVariance WRITE setYVariance) - int yVariance() const { return int(_yvariance * 1000); } - void setYVariance(int var) { _yvariance = var / 1000.0; } - - Q_PROPERTY(int pace READ pace WRITE setPace) - int pace() const { return int(_pace * 1000); } - void setPace(int pace) { _pace = pace / 1000.0; } - -private: - QmlGraphicsParticles *particles; - qreal _xvariance; - qreal _yvariance; - qreal _pace; -}; - -class QmlGraphicsParticlesPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsParticles : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QUrl source READ source WRITE setSource) - Q_PROPERTY(int count READ count WRITE setCount) - Q_PROPERTY(int lifeSpan READ lifeSpan WRITE setLifeSpan) - Q_PROPERTY(int lifeSpanDeviation READ lifeSpanDeviation WRITE setLifeSpanDeviation) - Q_PROPERTY(int fadeInDuration READ fadeInDuration WRITE setFadeInDuration) - Q_PROPERTY(int fadeOutDuration READ fadeOutDuration WRITE setFadeOutDuration) - Q_PROPERTY(qreal angle READ angle WRITE setAngle) - Q_PROPERTY(qreal angleDeviation READ angleDeviation WRITE setAngleDeviation) - Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) - Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation) - Q_PROPERTY(bool streamIn READ streamIn WRITE setStreamIn) - Q_PROPERTY(bool emitting READ emitting WRITE setEmitting) - Q_PROPERTY(QmlGraphicsParticleMotion *motion READ motion WRITE setMotion) - Q_CLASSINFO("DefaultProperty", "motion") - -public: - QmlGraphicsParticles(QmlGraphicsItem *parent=0); - ~QmlGraphicsParticles(); - - QUrl source() const; - void setSource(const QUrl &); - - int count() const; - void setCount(int cnt); - - int lifeSpan() const; - void setLifeSpan(int); - - int lifeSpanDeviation() const; - void setLifeSpanDeviation(int); - - int fadeInDuration() const; - void setFadeInDuration(int); - - int fadeOutDuration() const; - void setFadeOutDuration(int); - - qreal angle() const; - void setAngle(qreal); - - qreal angleDeviation() const; - void setAngleDeviation(qreal); - - qreal velocity() const; - void setVelocity(qreal); - - qreal velocityDeviation() const; - void setVelocityDeviation(qreal); - - bool streamIn() const; - void setStreamIn(bool); - - bool emitting() const; - void setEmitting(bool); - - QmlGraphicsParticleMotion *motion() const; - void setMotion(QmlGraphicsParticleMotion *); - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -protected: - virtual void componentComplete(); - QmlGraphicsParticles(QmlGraphicsParticlesPrivate &dd, QmlGraphicsItem *parent); - -private Q_SLOTS: - void imageLoaded(); - -private: - Q_DISABLE_COPY(QmlGraphicsParticles) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsParticles) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsParticleMotion) -QML_DECLARE_TYPE(QmlGraphicsParticleMotionLinear) -QML_DECLARE_TYPE(QmlGraphicsParticleMotionGravity) -QML_DECLARE_TYPE(QmlGraphicsParticleMotionWander) -QML_DECLARE_TYPE(QmlGraphicsParticles) - -QT_END_HEADER - -#endif diff --git a/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp b/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp new file mode 100644 index 0000000..c22e56d --- /dev/null +++ b/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp @@ -0,0 +1,256 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include "qmlgraphicsanimatedimageitem.h" +#include "qmlgraphicsanimatedimageitem_p.h" +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \class QmlGraphicsAnimatedImageItem + \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" } + Rectangle { color: "red"; width: 4; height: 8; y: anim.height + x: (anim.width-width)*anim.currentFrame/(anim.frameCount-1) + } +} + \endqml + \endtable +*/ +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,AnimatedImage,QmlGraphicsAnimatedImageItem) + +QmlGraphicsAnimatedImageItem::QmlGraphicsAnimatedImageItem(QmlGraphicsItem *parent) + : QmlGraphicsImage(*(new QmlGraphicsAnimatedImageItemPrivate), parent) +{ +} + +QmlGraphicsAnimatedImageItem::QmlGraphicsAnimatedImageItem(QmlGraphicsAnimatedImageItemPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsImage(dd, parent) +{ +} + +QmlGraphicsAnimatedImageItem::~QmlGraphicsAnimatedImageItem() +{ + Q_D(QmlGraphicsAnimatedImageItem); + delete d->_movie; +} + +/*! + \qmlproperty bool AnimatedImage::paused + This property holds whether the animated image is paused or not + + Defaults to false, and can be set to true when you want to pause. +*/ +bool QmlGraphicsAnimatedImageItem::isPaused() const +{ + Q_D(const QmlGraphicsAnimatedImageItem); + if(!d->_movie) + return false; + return d->_movie->state()==QMovie::Paused; +} + +void QmlGraphicsAnimatedImageItem::setPaused(bool pause) +{ + Q_D(QmlGraphicsAnimatedImageItem); + if(pause == d->paused) + return; + d->paused = pause; + if(!d->_movie) + return; + d->_movie->setPaused(pause); +} +/*! + \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 QmlGraphicsAnimatedImageItem::isPlaying() const +{ + Q_D(const QmlGraphicsAnimatedImageItem); + if (!d->_movie) + return false; + return d->_movie->state()!=QMovie::NotRunning; +} + +void QmlGraphicsAnimatedImageItem::setPlaying(bool play) +{ + Q_D(QmlGraphicsAnimatedImageItem); + if(play == d->playing) + return; + d->playing = play; + 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 QmlGraphicsAnimatedImageItem::currentFrame() const +{ + Q_D(const QmlGraphicsAnimatedImageItem); + if (!d->_movie) + return -1; + return d->_movie->currentFrameNumber(); +} + +void QmlGraphicsAnimatedImageItem::setCurrentFrame(int frame) +{ + Q_D(QmlGraphicsAnimatedImageItem); + if (!d->_movie) + return; + d->_movie->jumpToFrame(frame); +} + +int QmlGraphicsAnimatedImageItem::frameCount() const +{ + Q_D(const QmlGraphicsAnimatedImageItem); + if (!d->_movie) + return 0; + return d->_movie->frameCount(); +} + +void QmlGraphicsAnimatedImageItem::setSource(const QUrl &url) +{ + Q_D(QmlGraphicsAnimatedImageItem); + if (url == d->url) + return; + + delete d->_movie; + d->_movie = 0; + + if (d->reply) { + d->reply->deleteLater(); + d->reply = 0; + } + + d->url = qmlContext(this)->resolvedUrl(url); + + if (url.isEmpty()) { + delete d->_movie; + d->status = Null; + } else { + d->status = Loading; + QNetworkRequest req(d->url); + d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req); + QObject::connect(d->reply, SIGNAL(finished()), + this, SLOT(movieRequestFinished())); + } + + emit statusChanged(d->status); +} + +void QmlGraphicsAnimatedImageItem::movieRequestFinished() +{ + Q_D(QmlGraphicsAnimatedImageItem); + d->_movie = new QMovie(d->reply); + if (!d->_movie->isValid()){ + qWarning() << "Error Reading Animated Image File " << d->url; + delete d->_movie; + d->_movie = 0; + return; + } + connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)), + this, SLOT(playingStatusChanged())); + connect(d->_movie, SIGNAL(frameChanged(int)), + this, SLOT(movieUpdate())); + d->_movie->setCacheMode(QMovie::CacheAll); + if(d->playing) + d->_movie->start(); + else + d->_movie->jumpToFrame(0); + if(d->paused) + d->_movie->setPaused(true); + setPixmap(d->_movie->currentPixmap()); +} + +void QmlGraphicsAnimatedImageItem::movieUpdate() +{ + Q_D(QmlGraphicsAnimatedImageItem); + setPixmap(d->_movie->currentPixmap()); + emit frameChanged(); +} + +void QmlGraphicsAnimatedImageItem::playingStatusChanged() +{ + Q_D(QmlGraphicsAnimatedImageItem); + if((d->_movie->state() != QMovie::NotRunning) != d->playing){ + d->playing = (d->_movie->state() != QMovie::NotRunning); + emit playingChanged(); + } + if((d->_movie->state() == QMovie::Paused) != d->paused){ + d->playing = (d->_movie->state() == QMovie::Paused); + emit pausedChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/declarative/extra/qmlgraphicsanimatedimageitem.h b/src/declarative/extra/qmlgraphicsanimatedimageitem.h new file mode 100644 index 0000000..c62a98e --- /dev/null +++ b/src/declarative/extra/qmlgraphicsanimatedimageitem.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 QMLGRAPHICSANIMATEDIMAGEITEM_H +#define QMLGRAPHICSANIMATEDIMAGEITEM_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QMovie; +class QmlGraphicsAnimatedImageItemPrivate; + +class Q_DECLARATIVE_EXPORT QmlGraphicsAnimatedImageItem : public QmlGraphicsImage +{ + Q_OBJECT + + Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) + Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) + Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY frameChanged) + Q_PROPERTY(int frameCount READ frameCount) +public: + QmlGraphicsAnimatedImageItem(QmlGraphicsItem *parent=0); + ~QmlGraphicsAnimatedImageItem(); + + bool isPlaying() const; + void setPlaying(bool play); + + bool isPaused() const; + void setPaused(bool pause); + + int currentFrame() const; + void setCurrentFrame(int frame); + + int frameCount() const; + + // Extends QmlGraphicsImage's src property*/ + virtual void setSource(const QUrl&); + +Q_SIGNALS: + void playingChanged(); + void pausedChanged(); + void frameChanged(); + +private Q_SLOTS: + void movieUpdate(); + void movieRequestFinished(); + void playingStatusChanged(); + +protected: + QmlGraphicsAnimatedImageItem(QmlGraphicsAnimatedImageItemPrivate &dd, QmlGraphicsItem *parent); + +private: + Q_DISABLE_COPY(QmlGraphicsAnimatedImageItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsAnimatedImageItem) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsAnimatedImageItem) + +QT_END_HEADER + +#endif diff --git a/src/declarative/extra/qmlgraphicsanimatedimageitem_p.h b/src/declarative/extra/qmlgraphicsanimatedimageitem_p.h new file mode 100644 index 0000000..04f1b6e --- /dev/null +++ b/src/declarative/extra/qmlgraphicsanimatedimageitem_p.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSANIMATEDIMAGE_P_H +#define QMLGRAPHICSANIMATEDIMAGE_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 + +QT_BEGIN_NAMESPACE + +class QMovie; +class QNetworkReply; + +class QmlGraphicsAnimatedImageItemPrivate : public QmlGraphicsImagePrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsAnimatedImageItem) + +public: + QmlGraphicsAnimatedImageItemPrivate() + : playing(true), paused(false), _movie(0), reply(0) + { + } + + bool playing; + bool paused; + QMovie *_movie; + QNetworkReply *reply; +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSANIMATEDIMAGE_P_H diff --git a/src/declarative/extra/qmlgraphicsintegermodel.cpp b/src/declarative/extra/qmlgraphicsintegermodel.cpp new file mode 100644 index 0000000..e83b9c9 --- /dev/null +++ b/src/declarative/extra/qmlgraphicsintegermodel.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsintegermodel.h" + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,IntegerModel,QmlGraphicsIntegerModel) + +class QmlGraphicsIntegerModelPrivate +{ +public: + QmlGraphicsIntegerModelPrivate() : minimum(0), maximum(0) {} + int minimum; + int maximum; +}; + +QmlGraphicsIntegerModel::QmlGraphicsIntegerModel(QObject *parent) + : QListModelInterface(parent) +{ + d = new QmlGraphicsIntegerModelPrivate; +} + +QmlGraphicsIntegerModel::~QmlGraphicsIntegerModel() +{ + delete d; +} + +int QmlGraphicsIntegerModel::minimum() const +{ + return d->minimum; +} + +void QmlGraphicsIntegerModel::setMinimum(int minimum) +{ + d->minimum = minimum; +} + +int QmlGraphicsIntegerModel::maximum() const +{ + return d->maximum; +} + +void QmlGraphicsIntegerModel::setMaximum(int maximum) +{ + d->maximum = maximum; +} + +int QmlGraphicsIntegerModel::count() const +{ + return qMax(0, d->maximum - d->minimum + 1); +} + +QHash QmlGraphicsIntegerModel::data(int index, const QList &roles) const +{ + QHash returnHash; + + for (int i = 0; i < roles.size(); ++i) { + int role = roles.at(i); + QVariant info; + switch(role) { + case Qt::DisplayRole: + info = QVariant(QString::number(d->minimum+index)); + break; + default: + break; + } + returnHash.insert(role, info); + } + return returnHash; +} + +QString QmlGraphicsIntegerModel::toString(int role) const +{ + switch(role) { + case Qt::DisplayRole: + return QLatin1String("display"); + default: + return QLatin1String(""); + } +} + +QList QmlGraphicsIntegerModel::roles() const +{ + return QList() << Qt::DisplayRole; +} + +QT_END_NAMESPACE diff --git a/src/declarative/extra/qmlgraphicsintegermodel.h b/src/declarative/extra/qmlgraphicsintegermodel.h new file mode 100644 index 0000000..3cad05e --- /dev/null +++ b/src/declarative/extra/qmlgraphicsintegermodel.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSINTMODEL_H +#define QMLGRAPHICSINTMODEL_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsIntegerModelPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsIntegerModel : public QListModelInterface +{ + Q_OBJECT +public: + QmlGraphicsIntegerModel(QObject *parent=0); + ~QmlGraphicsIntegerModel(); + + Q_PROPERTY(int minimum READ minimum WRITE setMinimum) + int minimum() const; + void setMinimum(int); + + Q_PROPERTY(int maximum READ maximum WRITE setMaximum) + int maximum() const; + void setMaximum(int); + + int count() const; + QHash data(int index, const QList &roles) const; + QList roles() const; + QString toString(int role) const; + +private: + QmlGraphicsIntegerModelPrivate *d; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsIntegerModel) + +QT_END_HEADER + +#endif diff --git a/src/declarative/extra/qmlgraphicsparticles.cpp b/src/declarative/extra/qmlgraphicsparticles.cpp new file mode 100644 index 0000000..dba3ac4 --- /dev/null +++ b/src/declarative/extra/qmlgraphicsparticles.cpp @@ -0,0 +1,1134 @@ +/**************************************************************************** +** +** 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/qmlgraphicsitem_p.h" + +#include +#include +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#define M_PI_2 (M_PI / 2.) +#endif +#ifndef INT_MAX +#define INT_MAX 2147483647 +#endif +#include +#include +#include +#include + +#include "qmlgraphicsparticles.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE +#define PI_SQR 9.8696044 +// parabolic approximation +inline qreal fastSin(qreal theta) +{ + const qreal b = 4 / M_PI; + const qreal c = -4 / PI_SQR; + + qreal y = b * theta + c * theta * qAbs(theta); + return y; +} + +inline qreal fastCos(qreal theta) +{ + theta += M_PI_2; + if (theta > M_PI) + theta -= 2 * M_PI; + + return fastSin(theta); +} + +class QmlGraphicsParticle +{ +public: + QmlGraphicsParticle(int time) : lifeSpan(1000), fadeOutAge(800) + , opacity(0), birthTime(time), x_velocity(0), y_velocity(0) + , state(FadeIn), data(0) + { + } + + int lifeSpan; + int fadeOutAge; + qreal x; + qreal y; + qreal opacity; + int birthTime; + qreal x_velocity; + qreal y_velocity; + enum State { FadeIn, Solid, FadeOut }; + State state; + void *data; +}; + +//--------------------------------------------------------------------------- + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotion,QmlGraphicsParticleMotion) + +/*! + \class QmlGraphicsParticleMotion + \ingroup group_effects + \brief The QmlGraphicsParticleMotion class is the base class for particle motion. + \internal + + This class causes the particles to remain static. +*/ + +/*! + Constructs a QmlGraphicsParticleMotion with parent object \a parent. +*/ +QmlGraphicsParticleMotion::QmlGraphicsParticleMotion(QObject *parent) : + QObject(parent) +{ +} + +/*! + Move the \a particle to its new position. \a interval is the number of + milliseconds elapsed since it was last moved. +*/ +void QmlGraphicsParticleMotion::advance(QmlGraphicsParticle &particle, int interval) +{ + Q_UNUSED(particle); + Q_UNUSED(interval); +} + +/*! + The \a particle has just been created. Some motion strategies require + additional state information. This can be allocated by this function. +*/ +void QmlGraphicsParticleMotion::created(QmlGraphicsParticle &particle) +{ + Q_UNUSED(particle); +} + +/*! + The \a particle is about to be destroyed. Any additional memory + that has been allocated for the particle should be freed. +*/ +void QmlGraphicsParticleMotion::destroy(QmlGraphicsParticle &particle) +{ + Q_UNUSED(particle); +} + +/*! + \qmlclass ParticleMotionLinear + \brief The ParticleMotionLinear object moves particles linearly. + + \sa Particles +*/ + +/*! + \internal + \class QmlGraphicsParticleMotionLinear + \ingroup group_effects + \brief The QmlGraphicsParticleMotionLinear class moves the particles linearly. +*/ + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionLinear,QmlGraphicsParticleMotionLinear) + +void QmlGraphicsParticleMotionLinear::advance(QmlGraphicsParticle &p, int interval) +{ + p.x += interval * p.x_velocity; + p.y += interval * p.y_velocity; +} + +/*! + \qmlclass ParticleMotionGravity + \brief The ParticleMotionGravity object moves particles towards a point. + + \sa Particles +*/ + +/*! + \internal + \class QmlGraphicsParticleMotionGravity + \ingroup group_effects + \brief The QmlGraphicsParticleMotionGravity class moves the particles towards a point. +*/ + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionGravity,QmlGraphicsParticleMotionGravity) + +/*! + \qmlproperty int ParticleMotionGravity::xattractor + \qmlproperty int ParticleMotionGravity::yattractor + These properties hold the x and y coordinates of the point attracting the particles. +*/ + +/*! + \qmlproperty int ParticleMotionGravity::acceleration + This property holds the acceleration to apply to the particles. +*/ + +/*! + \property QmlGraphicsParticleMotionGravity::xattractor + \brief the x coordinate of the point attracting the particles. +*/ + +/*! + \property QmlGraphicsParticleMotionGravity::yattractor + \brief the y coordinate of the point attracting the particles. +*/ + +/*! + \property QmlGraphicsParticleMotionGravity::acceleration + \brief the acceleration to apply to the particles. +*/ + +void QmlGraphicsParticleMotionGravity::advance(QmlGraphicsParticle &p, int interval) +{ + qreal xdiff = p.x - _xAttr; + qreal ydiff = p.y - _yAttr; + + qreal xcomp = xdiff / (xdiff + ydiff); + qreal ycomp = ydiff / (xdiff + ydiff); + + p.x_velocity += xcomp * _accel * interval; + p.y_velocity += ycomp * _accel * interval; + + p.x += interval * p.x_velocity; + p.y += interval * p.y_velocity; +} + +/*! + \qmlclass ParticleMotionWander + \brief The ParticleMotionWander object moves particles in a somewhat random fashion. + + The particles will continue roughly in the original direction, however will randomly + drift to each side. + + The code below produces an effect similar to falling snow. + + \qml +Rectangle { + width: 240 + height: 320 + color: "black" + + Particles { + y: 0 + width: parent.width + height: 30 + source: "star.png" + lifeSpan: 5000 + count: 50 + angle: 70 + angleDeviation: 36 + velocity: 30 + velocityDeviation: 10 + ParticleMotionWander { + xvariance: 30 + pace: 100 + } + } +} + \endqml + + \sa Particles +*/ + +/*! + \internal + \class QmlGraphicsParticleMotionWander + \ingroup group_effects + \brief The QmlGraphicsParticleMotionWander class moves particles in a somewhat random fashion. + + The particles will continue roughly in the original direction, however will randomly + drift to each side. +*/ + +/*! + \qmlproperty int QmlGraphicsParticleMotionWander::xvariance + \qmlproperty int QmlGraphicsParticleMotionWander::yvariance + + These properties set the amount to wander in the x and y directions. +*/ + +/*! + \qmlproperty int QmlGraphicsParticleMotionWander::pace + This property holds how quickly the paricles will move from side to side. +*/ + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ParticleMotionWander,QmlGraphicsParticleMotionWander) + +void QmlGraphicsParticleMotionWander::advance(QmlGraphicsParticle &p, int interval) +{ + if (!particles) + particles = qobject_cast(parent()); + if (particles) { + Data *d = (Data*)p.data; + if (_xvariance != 0.) { + qreal xdiff = p.x_velocity - d->x_targetV; + if ((xdiff > d->x_peak && d->x_var > 0.0) || (xdiff < -d->x_peak && d->x_var < 0.0)) { + d->x_var = -d->x_var; + d->x_peak = _xvariance + _xvariance * qreal(rand()) / RAND_MAX; + } + p.x_velocity += d->x_var * interval; + } + p.x += interval * p.x_velocity; + + if (_yvariance != 0.) { + qreal ydiff = p.y_velocity - d->y_targetV; + if ((ydiff > d->y_peak && d->y_var > 0.0) || (ydiff < -d->y_peak && d->y_var < 0.0)) { + d->y_var = -d->y_var; + d->y_peak = _yvariance + _yvariance * qreal(rand()) / RAND_MAX; + } + p.y_velocity += d->y_var * interval; + } + p.y += interval * p.y_velocity; + } +} + +void QmlGraphicsParticleMotionWander::created(QmlGraphicsParticle &p) +{ + if (!p.data) { + Data *d = new Data; + p.data = (void*)d; + d->x_targetV = p.x_velocity; + d->y_targetV = p.y_velocity; + d->x_peak = _xvariance; + d->y_peak = _yvariance; + d->x_var = _pace * qreal(rand()) / RAND_MAX / 1000.0; + d->y_var = _pace * qreal(rand()) / RAND_MAX / 1000.0; + } +} + +void QmlGraphicsParticleMotionWander::destroy(QmlGraphicsParticle &p) +{ + if (p.data) + delete (Data*)p.data; +} + +//--------------------------------------------------------------------------- +class QmlGraphicsParticlesPainter : public QmlGraphicsItem +{ +public: + QmlGraphicsParticlesPainter(QmlGraphicsParticlesPrivate *p, QmlGraphicsItem* parent) + : QmlGraphicsItem(parent), d(p) + { + setFlag(QGraphicsItem::ItemHasNoContents, false); + maxX = minX = maxY = minY = 0; + } + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + + void updateSize(); + + qreal maxX; + qreal minX; + qreal maxY; + qreal minY; + QmlGraphicsParticlesPrivate* d; +}; + +//--------------------------------------------------------------------------- +class QmlGraphicsParticlesPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsParticles) +public: + QmlGraphicsParticlesPrivate() + : count(1), lifeSpan(1000), lifeSpanDev(1000), fadeInDur(200), fadeOutDur(300) + , angle(0), angleDev(0), velocity(0), velocityDev(0) + , addParticleTime(0), addParticleCount(0), lastAdvTime(0), stream(false), streamDelay(0) + , emitting(true), motion(0), pendingPixmapCache(false), clock(this) + { + } + + ~QmlGraphicsParticlesPrivate() + { + } + + void init() + { + Q_Q(QmlGraphicsParticles); + paintItem = new QmlGraphicsParticlesPainter(this, q); + } + + void tick(int time); + void createParticle(int time); + void updateOpacity(QmlGraphicsParticle &p, int age); + + QUrl url; + QPixmap image; + int count; + int lifeSpan; + int lifeSpanDev; + int fadeInDur; + int fadeOutDur; + qreal angle; + qreal angleDev; + qreal velocity; + qreal velocityDev; + int addParticleTime; + int addParticleCount; + int lastAdvTime; + bool stream; + int streamDelay; + bool emitting; + QmlGraphicsParticleMotion *motion; + QmlGraphicsParticlesPainter *paintItem; + + bool pendingPixmapCache; + + QList particles; + QTickAnimationProxy clock; + +}; + +void QmlGraphicsParticlesPrivate::tick(int time) +{ + Q_Q(QmlGraphicsParticles); + if (!motion) + motion = new QmlGraphicsParticleMotionLinear(q); + + int oldCount = particles.count(); + int removed = 0; + int interval = time - lastAdvTime; + for (int i = 0; i < particles.count(); ) { + QmlGraphicsParticle &particle = particles[i]; + int age = time - particle.birthTime; + if (age >= particle.lifeSpan) { + QmlGraphicsParticle part = particles.takeAt(i); + motion->destroy(part); + ++removed; + } else { + updateOpacity(particle, age); + motion->advance(particle, interval); + ++i; + } + } + + while(removed-- && particles.count() < count && emitting) + createParticle(time); + + if (!addParticleTime) + addParticleTime = time; + + if (particles.count() < count && emitting) { + qreal perc = (lifeSpanDev <= 0)?(1.):(qreal(time - addParticleTime) / qreal(lifeSpanDev)); + int percCount = addParticleCount + (int)perc * (count - addParticleCount); + int streamWidth = -1; + if (stream){ + if (streamDelay > time){ + streamWidth = 0; + }else{ + int missed = time - streamDelay; + qreal streamWidthReal = qreal(count)/qreal(lifeSpan); + if (streamWidthReal < 1){ + streamDelay = time + (int)(1.0/streamWidthReal); + streamWidth = 1; + streamWidth += missed/streamDelay; + }else{ + streamWidth = qRound(streamWidthReal * (time-lastAdvTime)); + } + } + } + while(particles.count() < count && + (!stream || (particles.count() < percCount && streamWidth--))) + createParticle(time); + } + + lastAdvTime = time; + paintItem->updateSize(); + paintItem->update(); + if (!(oldCount || particles.count()) && (!count || !emitting)) { + lastAdvTime = 0; + clock.stop(); + } +} + +void QmlGraphicsParticlesPrivate::createParticle(int time) +{ +#ifdef Q_ENABLE_PERFORMANCE_LOG + QmlPerfTimer x; +#endif + Q_Q(QmlGraphicsParticles); + QmlGraphicsParticle p(time); + p.x = q->x() + q->width() * qreal(rand()) / RAND_MAX - image.width()/2.0; + p.y = q->y() + q->height() * qreal(rand()) / RAND_MAX - image.height()/2.0; + p.lifeSpan = lifeSpan; + if (lifeSpanDev) + p.lifeSpan += int(lifeSpanDev/2 - lifeSpanDev * qreal(rand()) / RAND_MAX); + p.fadeOutAge = p.lifeSpan - fadeOutDur; + if (fadeInDur == 0.) { + p.state= QmlGraphicsParticle::Solid; + p.opacity = 1.0; + } + qreal a = angle; + if (angleDev) + a += angleDev/2 - angleDev * qreal(rand()) / RAND_MAX; + if (a > M_PI) + a = a - 2 * M_PI; + qreal v = velocity; + if (velocityDev) + v += velocityDev/2 - velocityDev * qreal(rand()) / RAND_MAX; + p.x_velocity = v * fastCos(a); + p.y_velocity = v * fastSin(a); + particles.append(p); + motion->created(particles.last()); +} + +void QmlGraphicsParticlesPrivate::updateOpacity(QmlGraphicsParticle &p, int age) +{ + switch (p.state) { + case QmlGraphicsParticle::FadeIn: + if (age <= fadeInDur) { + p.opacity = qreal(age) / fadeInDur; + break; + } else { + p.opacity = 1.0; + p.state = QmlGraphicsParticle::Solid; + // Fall through + } + case QmlGraphicsParticle::Solid: + if (age <= p.fadeOutAge) { + break; + } else { + p.state = QmlGraphicsParticle::FadeOut; + // Fall through + } + case QmlGraphicsParticle::FadeOut: + p.opacity = qreal(p.lifeSpan - age) / fadeOutDur; + break; + } +} + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Particles,QmlGraphicsParticles) + +/*! + \qmlclass Particles + \brief The Particles object generates and moves particles. + \inherits Item + + The particles created by this object cannot be dealt with directly, they can only be controlled through the parameters of the Particles object. The particles are all the same pixmap, specified by the user. + + The particles are painted relative to the parent of the Particles object. Moving the + Particles object will not move the particles already emitted. + + The below example creates two differently behaving particle sources. + The top one has particles falling from the top like snow, + the lower one has particles expelled up like a fountain. + + \qml +Rectangle { + width: 240 + height: 320 + color: "black" + Particles { + y: 0 + width: parent.width + height: 30 + source: "star.png" + lifeSpan: 5000 + count: 50 + angle: 70 + angleDeviation: 36 + velocity: 30 + velocityDeviation: 10 + ParticleMotionWander { + xvariance: 30 + pace: 100 + } + } + Particles { + y: 300 + x: 120 + width: 1 + height: 1 + source: "star.png" + lifeSpan: 5000 + count: 200 + angle: 270 + angleDeviation: 45 + velocity: 50 + velocityDeviation: 30 + ParticleMotionGravity { + yattractor: 1000 + xattractor: 0 + acceleration: 25 + } + } +} + \endqml + \image particles.gif +*/ + +/*! + \internal + \class QmlGraphicsParticles + \ingroup group_effects + \brief The QmlGraphicsParticles class generates and moves particles. +*/ + +QmlGraphicsParticles::QmlGraphicsParticles(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsParticlesPrivate), parent) +{ + Q_D(QmlGraphicsParticles); + d->init(); +} + +QmlGraphicsParticles::QmlGraphicsParticles(QmlGraphicsParticlesPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ + Q_D(QmlGraphicsParticles); + d->init(); +} + +QmlGraphicsParticles::~QmlGraphicsParticles() +{ + Q_D(QmlGraphicsParticles); + if (d->pendingPixmapCache) + QmlGraphicsPixmapCache::cancelGet(d->url, this); +} + +/*! + \qmlproperty string Particles::src + This property holds the URL of the particle image. +*/ + +/*! + \property QmlGraphicsParticles::source + \brief the URL of the particle image. +*/ +QUrl QmlGraphicsParticles::source() const +{ + Q_D(const QmlGraphicsParticles); + return d->url; +} + +void QmlGraphicsParticles::imageLoaded() +{ + Q_D(QmlGraphicsParticles); + d->pendingPixmapCache = false; + QmlGraphicsPixmapCache::find(d->url, &d->image); + d->paintItem->updateSize(); + d->paintItem->update(); +} + +void QmlGraphicsParticles::setSource(const QUrl &name) +{ + Q_D(QmlGraphicsParticles); + + if ((d->url.isEmpty() == name.isEmpty()) && name == d->url) + return; + + if (d->pendingPixmapCache) { + QmlGraphicsPixmapCache::cancelGet(d->url, this); + d->pendingPixmapCache = false; + } + if (name.isEmpty()) { + d->url = name; + d->image = QPixmap(); + d->paintItem->updateSize(); + d->paintItem->update(); + } else { + d->url = name; + Q_ASSERT(!name.isRelative()); + QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->image); + if (reply) { + connect(reply, SIGNAL(finished()), this, SLOT(imageLoaded())); + d->pendingPixmapCache = true; + } else { + //### unify with imageLoaded + d->paintItem->updateSize(); + d->paintItem->update(); + } + } +} + +/*! + \qmlproperty int Particles::count + This property holds the target number of particles +*/ + +/*! + \property QmlGraphicsParticles::count + \brief the target number of particles +*/ +int QmlGraphicsParticles::count() const +{ + Q_D(const QmlGraphicsParticles); + return d->count; +} + +void QmlGraphicsParticles::setCount(int cnt) +{ + Q_D(QmlGraphicsParticles); + if (cnt == d->count) + return; + + int oldCount = d->count; + d->count = cnt; + d->addParticleTime = 0; + d->addParticleCount = d->particles.count(); + if (!oldCount && d->clock.state() != QAbstractAnimation::Running && d->count) { + d->clock.start(); + } + d->paintItem->updateSize(); + d->paintItem->update(); +} + +/*! + \qmlproperty int Particles::lifeSpan + \qmlproperty int Particles::lifeSpanDeviation + + These properties describe the life span of each particle. + + The default lifespan for a particle is 1000ms. + + lifeSpanDeviation randomly varies the lifeSpan up to the specified variation. For + example, the following creates particles whose lifeSpan will vary + from 150ms to 250ms: + + \qml +Particles { + source: "star.png" + lifeSpan: 200 + lifeSpanDeviation: 100 +} + \endqml +*/ + +/*! + \property QmlGraphicsParticles::lifeSpan + \brief the life span of each particle. + + Default value is 1000ms. + + \sa QmlGraphicsParticles::lifeSpanDeviation +*/ +int QmlGraphicsParticles::lifeSpan() const +{ + Q_D(const QmlGraphicsParticles); + return d->lifeSpan; +} + +void QmlGraphicsParticles::setLifeSpan(int ls) +{ + Q_D(QmlGraphicsParticles); + d->lifeSpan = ls; +} + +/*! + \property QmlGraphicsParticles::lifeSpanDeviation + \brief the maximum possible deviation from the set lifeSpan. + + Randomly varies the lifeSpan up to the specified variation. For + example, the following creates particles whose lifeSpan will vary + from 150ms to 250ms: + +\qml +Particles { + source: "star.png" + lifeSpan: 200 + lifeSpanDeviation: 100 +} +\endqml + + \sa QmlGraphicsParticles::lifeSpan +*/ +int QmlGraphicsParticles::lifeSpanDeviation() const +{ + Q_D(const QmlGraphicsParticles); + return d->lifeSpanDev; +} + +void QmlGraphicsParticles::setLifeSpanDeviation(int dev) +{ + Q_D(QmlGraphicsParticles); + d->lifeSpanDev = dev; +} + +/*! + \qmlproperty int Particles::fadeInDuration + \qmlproperty int Particles::fadeOutDuration + These properties hold the time taken to fade the particles in and out. + + By default fade in is 200ms and fade out is 300ms. +*/ + +/*! + \property QmlGraphicsParticles::fadeInDuration + \brief the time taken to fade in the particles. + + Default value is 200ms. +*/ +int QmlGraphicsParticles::fadeInDuration() const +{ + Q_D(const QmlGraphicsParticles); + return d->fadeInDur; +} + +void QmlGraphicsParticles::setFadeInDuration(int dur) +{ + Q_D(QmlGraphicsParticles); + if (dur >= 0.0) + d->fadeInDur = dur; +} + +/*! + \property QmlGraphicsParticles::fadeOutDuration + \brief the time taken to fade out the particles. + + Default value is 300ms. +*/ +int QmlGraphicsParticles::fadeOutDuration() const +{ + Q_D(const QmlGraphicsParticles); + return d->fadeOutDur; +} + +void QmlGraphicsParticles::setFadeOutDuration(int dur) +{ + Q_D(QmlGraphicsParticles); + if (dur >= 0.0) + d->fadeOutDur = dur; +} + +/*! + \qmlproperty real Particles::angle + \qmlproperty real Particles::angleDeviation + + These properties control particle direction. + + angleDeviation randomly varies the direction up to the specified variation. For + example, the following creates particles whose initial direction will + vary from 15 degrees to 105 degrees: + + \qml +Particles { + source: "star.png" + angle: 60 + angleDeviation: 90 +} + \endqml +*/ + +/*! + \property QmlGraphicsParticles::angle + \brief the initial angle of direction. + + \sa QmlGraphicsParticles::angleDeviation +*/ +qreal QmlGraphicsParticles::angle() const +{ + Q_D(const QmlGraphicsParticles); + return d->angle * 180.0 / M_PI; +} + +void QmlGraphicsParticles::setAngle(qreal angle) +{ + Q_D(QmlGraphicsParticles); + d->angle = angle * M_PI / 180.0; +} + +/*! + \property QmlGraphicsParticles::angleDeviation + \brief the maximum possible deviation from the set angle. + + Randomly varies the direction up to the specified variation. For + example, the following creates particles whose initial direction will + vary from 15 degrees to 105 degrees: + +\qml +Particles { + source: "star.png" + angle: 60 + angleDeviation: 90 +} +\endqml + + \sa QmlGraphicsParticles::angle +*/ +qreal QmlGraphicsParticles::angleDeviation() const +{ + Q_D(const QmlGraphicsParticles); + return d->angleDev * 180.0 / M_PI; +} + +void QmlGraphicsParticles::setAngleDeviation(qreal dev) +{ + Q_D(QmlGraphicsParticles); + d->angleDev = dev * M_PI / 180.0;; +} + +/*! + \qmlproperty real Particles::velocity + \qmlproperty real Particles::velocityDeviation + + These properties control the velocity of the particles. + + velocityDeviation randomly varies the velocity up to the specified variation. For + example, the following creates particles whose initial velocity will + vary from 40 to 60. + + \qml +Particles { + source: "star.png" + velocity: 50 + velocityDeviation: 20 +} + \endqml +*/ + +/*! + \property QmlGraphicsParticles::velocity + \brief the initial velocity of the particles. + + \sa QmlGraphicsParticles::velocityDeviation +*/ +qreal QmlGraphicsParticles::velocity() const +{ + Q_D(const QmlGraphicsParticles); + return d->velocity * 1000.0; +} + +void QmlGraphicsParticles::setVelocity(qreal velocity) +{ + Q_D(QmlGraphicsParticles); + d->velocity = velocity / 1000.0; +} + +/*! + \property QmlGraphicsParticles::velocityDeviation + \brief the maximum possible deviation from the set velocity. + + Randomly varies the velocity up to the specified variation. For + example, the following creates particles whose initial velocity will + vary from 40 to 60. + +\qml +Particles { + source: "star.png" + velocity: 50 + velocityDeviation: 20 +} +\endqml + + \sa QmlGraphicsParticles::velocity +*/ +qreal QmlGraphicsParticles::velocityDeviation() const +{ + Q_D(const QmlGraphicsParticles); + return d->velocityDev * 1000.0; +} + +void QmlGraphicsParticles::setVelocityDeviation(qreal velocity) +{ + Q_D(QmlGraphicsParticles); + d->velocityDev = velocity / 1000.0; +} + +/*! + \qmlproperty bool Particles::streamIn + This property determines whether the particles stream in at a constant rate + + When stream is set to true the particles will stream in at a constant rate. + Otherwise the particles will appear as a clump. Note that this only affects the + start of the particle effect, variables such as lifespan deviation can cause the + particles to unclump over time. +*/ +/*! + \property QmlGraphicsParticles::streamIn + \brief determines whether the particles stream in at a constant rate + + When stream is set to true the particles will stream in at a constant rate. + Otherwise the particles will appear as a clump. Note that this only affects the + start of the particle effect, variables such as lifespan deviation can cause the + +*/ +//The name may need a rethink +bool QmlGraphicsParticles::streamIn() const +{ + Q_D(const QmlGraphicsParticles); + return d->stream; +} + +void QmlGraphicsParticles::setStreamIn(bool b) +{ + Q_D(QmlGraphicsParticles); + d->stream = b; +} + +/*! + \qmlproperty bool Particles::emitting + This property determines whether new particles are created + + If emitting is set to false no new particles will be created. This means that + when a particle reaches the end of its lifespan it is not replaced. This + property can be used to turn particles on and off with a more natural look. + + The default setting is true. Note that if it initialized to false no particles + will be produced until it is set to true. +*/ +/*! + \property QmlGraphicsParticles::emitting + If emitting is set to false no new particles will be created. This means that + when a particle reaches the end of its lifespan it is not replaced. This + property can be used to turn particles on and off with a more natural look. + + The default setting is true. Note that if it initialized to false no particles + will be produced until it is set to true. +*/ +bool QmlGraphicsParticles::emitting() const +{ + Q_D(const QmlGraphicsParticles); + return d->emitting; +} + +void QmlGraphicsParticles::setEmitting(bool r) +{ + Q_D(QmlGraphicsParticles); + d->emitting = r; + if (d->count && r) + d->clock.start(); +} +/*! + \qmlproperty ParticleMotion Particles::motion + This property sets the type of motion to apply to the particles. + + When a particle is created it will have an initial direction and velocity. + The motion of the particle during its lifeSpan is then influenced by the + motion property. + + Default motion is ParticleMotionLinear. +*/ + +/*! + \property QmlGraphicsParticles::motion + \brief sets the type of motion to apply to the particles. + + When a particle is created it will have an initial direction and velocity. + The motion of the particle during its lifeSpan is then influenced by the + motion property. + + Default motion is QmlGraphicsParticleMotionLinear. +*/ +QmlGraphicsParticleMotion *QmlGraphicsParticles::motion() const +{ + Q_D(const QmlGraphicsParticles); + return d->motion; +} + +void QmlGraphicsParticles::setMotion(QmlGraphicsParticleMotion *motion) +{ + Q_D(QmlGraphicsParticles); + d->motion = motion; +} + +void QmlGraphicsParticlesPainter::updateSize() +{ + if (!isComponentComplete()) + return; + + const int parentX = parentItem()->x(); + const int parentY = parentItem()->y(); + for (int i = 0; i < d->particles.count(); ++i) { + const QmlGraphicsParticle &particle = d->particles.at(i); + if(particle.x > maxX) + maxX = particle.x; + if(particle.x < minX) + minX = particle.x; + if(particle.y > maxY) + maxY = particle.y; + if(particle.y < minY) + minY = particle.y; + } + + int myWidth = (int)(maxX-minX+0.5)+d->image.width(); + int myX = (int)(minX - parentX); + int myHeight = (int)(maxY-minY+0.5)+d->image.height(); + int myY = (int)(minY - parentY); + setWidth(myWidth); + setHeight(myHeight); + setX(myX); + setY(myY); +} + +void QmlGraphicsParticles::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + Q_UNUSED(p); + //painting is done by the ParticlesPainter, so it can have the right size +} + +void QmlGraphicsParticlesPainter::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + if (d->image.isNull() || d->particles.isEmpty()) + return; + + const int myX = x() + parentItem()->x(); + const int myY = y() + parentItem()->y(); + + static QVarLengthArray pixmapData; + if (pixmapData.count() < d->particles.count()) + pixmapData.resize(d->particles.count()); + + const QRectF sourceRect = d->image.rect(); + for (int i = 0; i < d->particles.count(); ++i) { + const QmlGraphicsParticle &particle = d->particles.at(i); + pixmapData[i].point = QPointF(particle.x - myX, particle.y - myY); + pixmapData[i].opacity = particle.opacity; + + //these never change + pixmapData[i].rotation = 0; + pixmapData[i].scaleX = 1; + pixmapData[i].scaleY = 1; + pixmapData[i].source = sourceRect; + } + qDrawPixmaps(p, pixmapData.data(), d->particles.count(), d->image); +} + +void QmlGraphicsParticles::componentComplete() +{ + Q_D(QmlGraphicsParticles); + QmlGraphicsItem::componentComplete(); + if (d->count) { + d->paintItem->updateSize(); + d->clock.start(); + } + if (d->lifeSpanDev > d->lifeSpan) + d->lifeSpanDev = d->lifeSpan; +} + +QT_END_NAMESPACE diff --git a/src/declarative/extra/qmlgraphicsparticles.h b/src/declarative/extra/qmlgraphicsparticles.h new file mode 100644 index 0000000..eed0d62 --- /dev/null +++ b/src/declarative/extra/qmlgraphicsparticles.h @@ -0,0 +1,230 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSPARTICLES_H +#define QMLGRAPHICSPARTICLES_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsParticle; +class QmlGraphicsParticles; +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotion : public QObject +{ + Q_OBJECT +public: + QmlGraphicsParticleMotion(QObject *parent=0); + + virtual void advance(QmlGraphicsParticle &, int interval); + virtual void created(QmlGraphicsParticle &); + virtual void destroy(QmlGraphicsParticle &); +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionLinear : public QmlGraphicsParticleMotion +{ + Q_OBJECT +public: + QmlGraphicsParticleMotionLinear(QObject *parent=0) + : QmlGraphicsParticleMotion(parent) {} + + virtual void advance(QmlGraphicsParticle &, int interval); +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionGravity : public QmlGraphicsParticleMotion +{ + Q_OBJECT + + Q_PROPERTY(int xattractor READ xAttractor WRITE setXAttractor) + Q_PROPERTY(int yattractor READ yAttractor WRITE setYAttractor) + Q_PROPERTY(int acceleration READ acceleration WRITE setAcceleration) +public: + QmlGraphicsParticleMotionGravity(QObject *parent=0) + : QmlGraphicsParticleMotion(parent), _xAttr(0), _yAttr(0), _accel(0.00005) {} + + int xAttractor() const { return _xAttr; } + void setXAttractor(int x) { _xAttr = x; } + + int yAttractor() const { return _yAttr; } + void setYAttractor(int y) { _yAttr = y; } + + int acceleration() const { return int(_accel * 1000000); } + void setAcceleration(int accel) { _accel = qreal(accel)/1000000.0; } + + virtual void advance(QmlGraphicsParticle &, int interval); + +private: + int _xAttr; + int _yAttr; + qreal _accel; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionWander : public QmlGraphicsParticleMotion +{ + Q_OBJECT +public: + QmlGraphicsParticleMotionWander() + : QmlGraphicsParticleMotion(), particles(0), _xvariance(0), _yvariance(0) {} + + virtual void advance(QmlGraphicsParticle &, int interval); + virtual void created(QmlGraphicsParticle &); + virtual void destroy(QmlGraphicsParticle &); + + struct Data { + qreal x_targetV; + qreal y_targetV; + qreal x_peak; + qreal y_peak; + qreal x_var; + qreal y_var; + }; + + Q_PROPERTY(int xvariance READ xVariance WRITE setXVariance) + int xVariance() const { return int(_xvariance * 1000); } + void setXVariance(int var) { _xvariance = var / 1000.0; } + + Q_PROPERTY(int yvariance READ yVariance WRITE setYVariance) + int yVariance() const { return int(_yvariance * 1000); } + void setYVariance(int var) { _yvariance = var / 1000.0; } + + Q_PROPERTY(int pace READ pace WRITE setPace) + int pace() const { return int(_pace * 1000); } + void setPace(int pace) { _pace = pace / 1000.0; } + +private: + QmlGraphicsParticles *particles; + qreal _xvariance; + qreal _yvariance; + qreal _pace; +}; + +class QmlGraphicsParticlesPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsParticles : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(QUrl source READ source WRITE setSource) + Q_PROPERTY(int count READ count WRITE setCount) + Q_PROPERTY(int lifeSpan READ lifeSpan WRITE setLifeSpan) + Q_PROPERTY(int lifeSpanDeviation READ lifeSpanDeviation WRITE setLifeSpanDeviation) + Q_PROPERTY(int fadeInDuration READ fadeInDuration WRITE setFadeInDuration) + Q_PROPERTY(int fadeOutDuration READ fadeOutDuration WRITE setFadeOutDuration) + Q_PROPERTY(qreal angle READ angle WRITE setAngle) + Q_PROPERTY(qreal angleDeviation READ angleDeviation WRITE setAngleDeviation) + Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) + Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation) + Q_PROPERTY(bool streamIn READ streamIn WRITE setStreamIn) + Q_PROPERTY(bool emitting READ emitting WRITE setEmitting) + Q_PROPERTY(QmlGraphicsParticleMotion *motion READ motion WRITE setMotion) + Q_CLASSINFO("DefaultProperty", "motion") + +public: + QmlGraphicsParticles(QmlGraphicsItem *parent=0); + ~QmlGraphicsParticles(); + + QUrl source() const; + void setSource(const QUrl &); + + int count() const; + void setCount(int cnt); + + int lifeSpan() const; + void setLifeSpan(int); + + int lifeSpanDeviation() const; + void setLifeSpanDeviation(int); + + int fadeInDuration() const; + void setFadeInDuration(int); + + int fadeOutDuration() const; + void setFadeOutDuration(int); + + qreal angle() const; + void setAngle(qreal); + + qreal angleDeviation() const; + void setAngleDeviation(qreal); + + qreal velocity() const; + void setVelocity(qreal); + + qreal velocityDeviation() const; + void setVelocityDeviation(qreal); + + bool streamIn() const; + void setStreamIn(bool); + + bool emitting() const; + void setEmitting(bool); + + QmlGraphicsParticleMotion *motion() const; + void setMotion(QmlGraphicsParticleMotion *); + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +protected: + virtual void componentComplete(); + QmlGraphicsParticles(QmlGraphicsParticlesPrivate &dd, QmlGraphicsItem *parent); + +private Q_SLOTS: + void imageLoaded(); + +private: + Q_DISABLE_COPY(QmlGraphicsParticles) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsParticles) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsParticleMotion) +QML_DECLARE_TYPE(QmlGraphicsParticleMotionLinear) +QML_DECLARE_TYPE(QmlGraphicsParticleMotionGravity) +QML_DECLARE_TYPE(QmlGraphicsParticleMotionWander) +QML_DECLARE_TYPE(QmlGraphicsParticles) + +QT_END_HEADER + +#endif diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index fc4e640..7759ab1 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -1,84 +1,84 @@ HEADERS += \ - fx/qfxanchors.h \ - fx/qfxanchors_p.h \ - fx/qfxevents_p.h \ - fx/qfxflickable.h \ - fx/qfxflickable_p.h \ - fx/qfxflipable.h \ - fx/qfxgridview.h \ - fx/qfximage.h \ - fx/qfximagebase.h \ - fx/qfxborderimage.h \ - fx/qfxpainteditem.h \ - fx/qfxpainteditem_p.h \ - fx/qfximage_p.h \ - fx/qfxborderimage_p.h \ - fx/qfximagebase_p.h \ - fx/qfxitem.h \ - fx/qfxitem_p.h \ - fx/qfxfocuspanel.h \ - fx/qfxfocusscope.h \ - fx/qfxpositioners.h \ - fx/qfxpositioners_p.h \ - fx/qfxloader.h \ - fx/qfxloader_p.h \ - fx/qfxmouseregion.h \ - fx/qfxmouseregion_p.h \ - fx/qfxpath.h \ - fx/qfxpath_p.h \ - fx/qfxpathview.h \ - fx/qfxpathview_p.h \ - fx/qfxrect.h \ - fx/qfxrect_p.h \ - fx/qfxrepeater.h \ - fx/qfxrepeater_p.h \ - fx/qfxscalegrid_p.h \ - fx/qfxtextinput.h \ - fx/qfxtextinput_p.h \ - fx/qfxtextedit.h \ - fx/qfxtextedit_p.h \ - fx/qfxtext.h \ - fx/qfxtext_p.h \ - fx/qfxpixmapcache.h \ - fx/qfxvisualitemmodel.h \ - fx/qfxlistview.h \ - fx/qfxgraphicsobjectcontainer.h \ - fx/qfxlayoutitem.h \ - fx/qfxeffects.cpp + fx/qmlgraphicsanchors.h \ + fx/qmlgraphicsanchors_p.h \ + fx/qmlgraphicsevents_p.h \ + fx/qmlgraphicsflickable.h \ + fx/qmlgraphicsflickable_p.h \ + fx/qmlgraphicsflipable.h \ + fx/qmlgraphicsgridview.h \ + fx/qmlgraphicsimage.h \ + fx/qmlgraphicsimagebase.h \ + fx/qmlgraphicsborderimage.h \ + fx/qmlgraphicspainteditem.h \ + fx/qmlgraphicspainteditem_p.h \ + fx/qmlgraphicsimage_p.h \ + fx/qmlgraphicsborderimage_p.h \ + fx/qmlgraphicsimagebase_p.h \ + fx/qmlgraphicsitem.h \ + fx/qmlgraphicsitem_p.h \ + fx/qmlgraphicsfocuspanel.h \ + fx/qmlgraphicsfocusscope.h \ + fx/qmlgraphicspositioners.h \ + fx/qmlgraphicspositioners_p.h \ + fx/qmlgraphicsloader.h \ + fx/qmlgraphicsloader_p.h \ + fx/qmlgraphicsmouseregion.h \ + fx/qmlgraphicsmouseregion_p.h \ + fx/qmlgraphicspath.h \ + fx/qmlgraphicspath_p.h \ + fx/qmlgraphicspathview.h \ + fx/qmlgraphicspathview_p.h \ + fx/qmlgraphicsrect.h \ + fx/qmlgraphicsrect_p.h \ + fx/qmlgraphicsrepeater.h \ + fx/qmlgraphicsrepeater_p.h \ + fx/qmlgraphicsscalegrid_p.h \ + fx/qmlgraphicstextinput.h \ + fx/qmlgraphicstextinput_p.h \ + fx/qmlgraphicstextedit.h \ + fx/qmlgraphicstextedit_p.h \ + fx/qmlgraphicstext.h \ + fx/qmlgraphicstext_p.h \ + fx/qmlgraphicspixmapcache.h \ + fx/qmlgraphicsvisualitemmodel.h \ + fx/qmlgraphicslistview.h \ + fx/qmlgraphicsgraphicsobjectcontainer.h \ + fx/qmlgraphicslayoutitem.h \ + fx/qmlgraphicseffects.cpp SOURCES += \ - fx/qfxanchors.cpp \ - fx/qfxevents.cpp \ - fx/qfxflickable.cpp \ - fx/qfxflipable.cpp \ - fx/qfxgridview.cpp \ - fx/qfximage.cpp \ - fx/qfxborderimage.cpp \ - fx/qfximagebase.cpp \ - fx/qfxpainteditem.cpp \ - fx/qfxitem.cpp \ - fx/qfxfocuspanel.cpp \ - fx/qfxfocusscope.cpp \ - fx/qfxpositioners.cpp \ - fx/qfxloader.cpp \ - fx/qfxmouseregion.cpp \ - fx/qfxpath.cpp \ - fx/qfxpathview.cpp \ - fx/qfxrect.cpp \ - fx/qfxrepeater.cpp \ - fx/qfxscalegrid.cpp \ - fx/qfxtextinput.cpp \ - fx/qfxtext.cpp \ - fx/qfxtextedit.cpp \ - fx/qfxpixmapcache.cpp \ - fx/qfxvisualitemmodel.cpp \ - fx/qfxlistview.cpp \ - fx/qfxgraphicsobjectcontainer.cpp \ - fx/qfxlayoutitem.cpp \ + fx/qmlgraphicsanchors.cpp \ + fx/qmlgraphicsevents.cpp \ + fx/qmlgraphicsflickable.cpp \ + fx/qmlgraphicsflipable.cpp \ + fx/qmlgraphicsgridview.cpp \ + fx/qmlgraphicsimage.cpp \ + fx/qmlgraphicsborderimage.cpp \ + fx/qmlgraphicsimagebase.cpp \ + fx/qmlgraphicspainteditem.cpp \ + fx/qmlgraphicsitem.cpp \ + fx/qmlgraphicsfocuspanel.cpp \ + fx/qmlgraphicsfocusscope.cpp \ + fx/qmlgraphicspositioners.cpp \ + fx/qmlgraphicsloader.cpp \ + fx/qmlgraphicsmouseregion.cpp \ + fx/qmlgraphicspath.cpp \ + fx/qmlgraphicspathview.cpp \ + fx/qmlgraphicsrect.cpp \ + fx/qmlgraphicsrepeater.cpp \ + fx/qmlgraphicsscalegrid.cpp \ + fx/qmlgraphicstextinput.cpp \ + fx/qmlgraphicstext.cpp \ + fx/qmlgraphicstextedit.cpp \ + fx/qmlgraphicspixmapcache.cpp \ + fx/qmlgraphicsvisualitemmodel.cpp \ + fx/qmlgraphicslistview.cpp \ + fx/qmlgraphicsgraphicsobjectcontainer.cpp \ + fx/qmlgraphicslayoutitem.cpp \ contains(QT_CONFIG, webkit) { QT+=webkit - SOURCES += fx/qfxwebview.cpp - HEADERS += fx/qfxwebview.h + SOURCES += fx/qmlgraphicswebview.cpp + HEADERS += fx/qmlgraphicswebview.h } diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp deleted file mode 100644 index 3908520..0000000 --- a/src/declarative/fx/qfxanchors.cpp +++ /dev/null @@ -1,962 +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 "qfxanchors_p.h" -#include "qfxitem.h" -#include "qfxitem_p.h" -#include -#include - -QT_BEGIN_NAMESPACE - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Anchors,QmlGraphicsAnchors) - -//TODO: should we cache relationships, so we don't have to check each time (parent-child or sibling)? -//TODO: support non-parent, non-sibling (need to find lowest common ancestor) - -//### const item? -//local position -static qreal position(QmlGraphicsItem *item, QmlGraphicsAnchorLine::AnchorLine anchorLine) -{ - qreal ret = 0.0; - switch(anchorLine) { - case QmlGraphicsAnchorLine::Left: - ret = item->x(); - break; - case QmlGraphicsAnchorLine::Right: - ret = item->x() + item->width(); - break; - case QmlGraphicsAnchorLine::Top: - ret = item->y(); - break; - case QmlGraphicsAnchorLine::Bottom: - ret = item->y() + item->height(); - break; - case QmlGraphicsAnchorLine::HCenter: - ret = item->x() + item->width()/2; - break; - case QmlGraphicsAnchorLine::VCenter: - ret = item->y() + item->height()/2; - break; - case QmlGraphicsAnchorLine::Baseline: - ret = item->y() + item->baselineOffset(); - break; - default: - break; - } - - return ret; -} - -//position when origin is 0,0 -static qreal adjustedPosition(QmlGraphicsItem *item, QmlGraphicsAnchorLine::AnchorLine anchorLine) -{ - int ret = 0; - switch(anchorLine) { - case QmlGraphicsAnchorLine::Left: - ret = 0; - break; - case QmlGraphicsAnchorLine::Right: - ret = item->width(); - break; - case QmlGraphicsAnchorLine::Top: - ret = 0; - break; - case QmlGraphicsAnchorLine::Bottom: - ret = item->height(); - break; - case QmlGraphicsAnchorLine::HCenter: - ret = item->width()/2; - break; - case QmlGraphicsAnchorLine::VCenter: - ret = item->height()/2; - break; - case QmlGraphicsAnchorLine::Baseline: - ret = item->baselineOffset(); - break; - default: - break; - } - - return ret; -} - -/*! - \internal - \class QmlGraphicsAnchors - \ingroup group_layouts - \brief The QmlGraphicsAnchors class provides a way to lay out items relative to other items. - - \warning Currently, only anchoring to siblings or parent is supported. -*/ - -QmlGraphicsAnchors::QmlGraphicsAnchors(QObject *parent) - : QObject(*new QmlGraphicsAnchorsPrivate(), parent) -{ -} - -QmlGraphicsAnchors::~QmlGraphicsAnchors() -{ - Q_D(QmlGraphicsAnchors); - d->remDepend(d->fill); - d->remDepend(d->centerIn); - d->remDepend(d->left.item); - d->remDepend(d->right.item); - d->remDepend(d->top.item); - d->remDepend(d->bottom.item); - d->remDepend(d->vCenter.item); - d->remDepend(d->hCenter.item); - d->remDepend(d->baseline.item); -} - -void QmlGraphicsAnchorsPrivate::fillChanged() -{ - if (!fill || !isItemComplete()) - return; - - if (fill == item->parentItem()) { //child-parent - setItemPos(QPointF(leftMargin, topMargin)); - } else if (fill->parentItem() == item->parentItem()) { //siblings - setItemPos(QPointF(fill->x()+leftMargin, fill->y()+topMargin)); - } - setItemWidth(fill->width()-leftMargin-rightMargin); - setItemHeight(fill->height()-topMargin-bottomMargin); -} - -void QmlGraphicsAnchorsPrivate::centerInChanged() -{ - if (!centerIn || fill || !isItemComplete()) - return; - - if (centerIn == item->parentItem()) { - QPointF p((item->parentItem()->width() - item->width()) / 2., - (item->parentItem()->height() - item->height()) / 2.); - setItemPos(p); - - } else if (centerIn->parentItem() == item->parentItem()) { - - QPointF p(centerIn->x() + (centerIn->width() - item->width()) / 2., - centerIn->y() + (centerIn->height() - item->height()) / 2.); - setItemPos(p); - } -} - -void QmlGraphicsAnchorsPrivate::clearItem(QmlGraphicsItem *item) -{ - if (!item) - return; - if (fill == item) - fill = 0; - if (centerIn == item) - centerIn = 0; - if (left.item == item) { - left.item = 0; - usedAnchors &= ~QmlGraphicsAnchors::HasLeftAnchor; - } - if (right.item == item) { - right.item = 0; - usedAnchors &= ~QmlGraphicsAnchors::HasRightAnchor; - } - if (top.item == item) { - top.item = 0; - usedAnchors &= ~QmlGraphicsAnchors::HasTopAnchor; - } - if (bottom.item == item) { - bottom.item = 0; - usedAnchors &= ~QmlGraphicsAnchors::HasBottomAnchor; - } - if (vCenter.item == item) { - vCenter.item = 0; - usedAnchors &= ~QmlGraphicsAnchors::HasVCenterAnchor; - } - if (hCenter.item == item) { - hCenter.item = 0; - usedAnchors &= ~QmlGraphicsAnchors::HasHCenterAnchor; - } - if (baseline.item == item) { - baseline.item = 0; - usedAnchors &= ~QmlGraphicsAnchors::HasBaselineAnchor; - } -} - -void QmlGraphicsAnchorsPrivate::addDepend(QmlGraphicsItem *item) -{ - Q_Q(QmlGraphicsAnchors); - if (!item) - return; - QmlGraphicsItemPrivate *p = - static_cast(QGraphicsItemPrivate::get(item)); - p->dependantAnchors.append(q); -} - -void QmlGraphicsAnchorsPrivate::remDepend(QmlGraphicsItem *item) -{ - Q_Q(QmlGraphicsAnchors); - if (!item) - return; - QmlGraphicsItemPrivate *p = - static_cast(QGraphicsItemPrivate::get(item)); - p->dependantAnchors.removeOne(q); -} - -bool QmlGraphicsAnchorsPrivate::isItemComplete() const -{ - return componentComplete; -} - -void QmlGraphicsAnchors::classBegin() -{ - Q_D(QmlGraphicsAnchors); - d->componentComplete = false; -} - -void QmlGraphicsAnchors::componentComplete() -{ - Q_D(QmlGraphicsAnchors); - d->componentComplete = true; -} - -void QmlGraphicsAnchorsPrivate::setItemHeight(qreal v) -{ - updatingMe = true; - item->setHeight(v); - updatingMe = false; -} - -void QmlGraphicsAnchorsPrivate::setItemWidth(qreal v) -{ - updatingMe = true; - item->setWidth(v); - updatingMe = false; -} - -void QmlGraphicsAnchorsPrivate::setItemX(qreal v) -{ - updatingMe = true; - item->setX(v); - updatingMe = false; -} - -void QmlGraphicsAnchorsPrivate::setItemY(qreal v) -{ - updatingMe = true; - item->setY(v); - updatingMe = false; -} - -void QmlGraphicsAnchorsPrivate::setItemPos(const QPointF &v) -{ - updatingMe = true; - item->setPos(v); - updatingMe = false; -} - -void QmlGraphicsAnchorsPrivate::updateMe() -{ - if (updatingMe) { - updatingMe = false; - return; - } - - fillChanged(); - centerInChanged(); - updateHorizontalAnchors(); - updateVerticalAnchors(); -} - -void QmlGraphicsAnchorsPrivate::updateOnComplete() -{ - fillChanged(); - centerInChanged(); - updateHorizontalAnchors(); - updateVerticalAnchors(); -} - -void QmlGraphicsAnchorsPrivate::update(QmlGraphicsItem *, const QRectF &newG, const QRectF &oldG) -{ - fillChanged(); - centerInChanged(); - - if (newG.x() != oldG.x() || newG.width() != oldG.width()) - updateHorizontalAnchors(); - if (newG.y() != oldG.y() || newG.height() != oldG.height()) - updateVerticalAnchors(); -} - -QmlGraphicsItem *QmlGraphicsAnchors::fill() const -{ - Q_D(const QmlGraphicsAnchors); - return d->fill; -} - -void QmlGraphicsAnchors::setFill(QmlGraphicsItem *f) -{ - Q_D(QmlGraphicsAnchors); - if (!f) { - d->remDepend(d->fill); - d->fill = f; - return; - } - if (f != d->item->parentItem() && f->parentItem() != d->item->parentItem()){ - qmlInfo(tr("Can't anchor to an item that isn't a parent or sibling."), d->item); - return; - } - d->remDepend(d->fill); - d->fill = f; - d->addDepend(d->fill); - - d->fillChanged(); -} - -QmlGraphicsItem *QmlGraphicsAnchors::centerIn() const -{ - Q_D(const QmlGraphicsAnchors); - return d->centerIn; -} - -void QmlGraphicsAnchors::setCenterIn(QmlGraphicsItem* c) -{ - Q_D(QmlGraphicsAnchors); - if (!c) { - d->remDepend(d->centerIn); - d->centerIn = c; - return; - } - if (c != d->item->parentItem() && c->parentItem() != d->item->parentItem()){ - qmlInfo(tr("Can't anchor to an item that isn't a parent or sibling."), d->item); - return; - } - - d->remDepend(d->centerIn); - d->centerIn = c; - d->addDepend(d->centerIn); - - d->centerInChanged(); -} - -bool QmlGraphicsAnchorsPrivate::calcStretch(const QmlGraphicsAnchorLine &edge1, - const QmlGraphicsAnchorLine &edge2, - int offset1, - int offset2, - QmlGraphicsAnchorLine::AnchorLine line, - int &stretch) -{ - bool edge1IsParent = (edge1.item == item->parentItem()); - bool edge2IsParent = (edge2.item == item->parentItem()); - bool edge1IsSibling = (edge1.item->parentItem() == item->parentItem()); - bool edge2IsSibling = (edge2.item->parentItem() == item->parentItem()); - - bool invalid = false; - if ((edge2IsParent && edge1IsParent) || (edge2IsSibling && edge1IsSibling)) { - stretch = ((int)position(edge2.item, edge2.anchorLine) + offset2) - - ((int)position(edge1.item, edge1.anchorLine) + offset1); - } else if (edge2IsParent && edge1IsSibling) { - stretch = ((int)position(edge2.item, edge2.anchorLine) + offset2) - - ((int)position(item->parentItem(), line) - + (int)position(edge1.item, edge1.anchorLine) + offset1); - } else if (edge2IsSibling && edge1IsParent) { - stretch = ((int)position(item->parentItem(), line) + (int)position(edge2.item, edge2.anchorLine) + offset2) - - ((int)position(edge1.item, edge1.anchorLine) + offset1); - } else - invalid = true; - - return invalid; -} - -void QmlGraphicsAnchorsPrivate::updateVerticalAnchors() -{ - if (fill || centerIn || !isItemComplete()) - return; - - if (updatingVerticalAnchor < 2) { - ++updatingVerticalAnchor; - if (usedAnchors & QmlGraphicsAnchors::HasTopAnchor) { - //Handle stretching - bool invalid = true; - int height = 0; - if (usedAnchors & QmlGraphicsAnchors::HasBottomAnchor) { - invalid = calcStretch(top, bottom, topMargin, -bottomMargin, QmlGraphicsAnchorLine::Top, height); - } else if (usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor) { - invalid = calcStretch(top, vCenter, topMargin, vCenterOffset, QmlGraphicsAnchorLine::Top, height); - height *= 2; - } - if (!invalid) - setItemHeight(height); - - //Handle top - if (top.item == item->parentItem()) { - setItemY(adjustedPosition(top.item, top.anchorLine) + topMargin); - } else if (top.item->parentItem() == item->parentItem()) { - setItemY(position(top.item, top.anchorLine) + topMargin); - } - } else if (usedAnchors & QmlGraphicsAnchors::HasBottomAnchor) { - //Handle stretching (top + bottom case is handled above) - if (usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor) { - int height = 0; - bool invalid = calcStretch(vCenter, bottom, vCenterOffset, -bottomMargin, - QmlGraphicsAnchorLine::Top, height); - if (!invalid) - setItemHeight(height*2); - } - - //Handle bottom - if (bottom.item == item->parentItem()) { - setItemY(adjustedPosition(bottom.item, bottom.anchorLine) - item->height() - bottomMargin); - } else if (bottom.item->parentItem() == item->parentItem()) { - setItemY(position(bottom.item, bottom.anchorLine) - item->height() - bottomMargin); - } - } else if (usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor) { - //(stetching handled above) - - //Handle vCenter - if (vCenter.item == item->parentItem()) { - setItemY(adjustedPosition(vCenter.item, vCenter.anchorLine) - - item->height()/2 + vCenterOffset); - } else if (vCenter.item->parentItem() == item->parentItem()) { - setItemY(position(vCenter.item, vCenter.anchorLine) - item->height()/2 + vCenterOffset); - } - } else if (usedAnchors & QmlGraphicsAnchors::HasBaselineAnchor) { - //Handle baseline - if (baseline.item->parentItem() == item->parentItem()) { - setItemY(position(baseline.item, baseline.anchorLine) - item->baselineOffset() + baselineOffset); - } - } - --updatingVerticalAnchor; - } else { - // ### Make this certain :) - qmlInfo(QmlGraphicsAnchors::tr("Possible anchor loop detected on vertical anchor."), item); - } -} - -void QmlGraphicsAnchorsPrivate::updateHorizontalAnchors() -{ - if (fill || centerIn || !isItemComplete()) - return; - - if (updatingHorizontalAnchor < 2) { - ++updatingHorizontalAnchor; - - if (usedAnchors & QmlGraphicsAnchors::HasLeftAnchor) { - //Handle stretching - bool invalid = true; - int width = 0; - if (usedAnchors & QmlGraphicsAnchors::HasRightAnchor) { - invalid = calcStretch(left, right, leftMargin, -rightMargin, QmlGraphicsAnchorLine::Left, width); - } else if (usedAnchors & QmlGraphicsAnchors::HasHCenterAnchor) { - invalid = calcStretch(left, hCenter, leftMargin, hCenterOffset, QmlGraphicsAnchorLine::Left, width); - width *= 2; - } - if (!invalid) - setItemWidth(width); - - //Handle left - if (left.item == item->parentItem()) { - setItemX(adjustedPosition(left.item, left.anchorLine) + leftMargin); - } else if (left.item->parentItem() == item->parentItem()) { - setItemX(position(left.item, left.anchorLine) + leftMargin); - } - } else if (usedAnchors & QmlGraphicsAnchors::HasRightAnchor) { - //Handle stretching (left + right case is handled in updateLeftAnchor) - if (usedAnchors & QmlGraphicsAnchors::HasHCenterAnchor) { - int width = 0; - bool invalid = calcStretch(hCenter, right, hCenterOffset, -rightMargin, - QmlGraphicsAnchorLine::Left, width); - if (!invalid) - setItemWidth(width*2); - } - - //Handle right - if (right.item == item->parentItem()) { - setItemX(adjustedPosition(right.item, right.anchorLine) - item->width() - rightMargin); - } else if (right.item->parentItem() == item->parentItem()) { - setItemX(position(right.item, right.anchorLine) - item->width() - rightMargin); - } - } else if (usedAnchors & QmlGraphicsAnchors::HasHCenterAnchor) { - //Handle hCenter - if (hCenter.item == item->parentItem()) { - setItemX(adjustedPosition(hCenter.item, hCenter.anchorLine) - item->width()/2 + hCenterOffset); - } else if (hCenter.item->parentItem() == item->parentItem()) { - setItemX(position(hCenter.item, hCenter.anchorLine) - item->width()/2 + hCenterOffset); - } - } - - --updatingHorizontalAnchor; - } else { - // ### Make this certain :) - qmlInfo(QmlGraphicsAnchors::tr("Possible anchor loop detected on horizontal anchor."), item); - } -} - -QmlGraphicsAnchorLine QmlGraphicsAnchors::top() const -{ - Q_D(const QmlGraphicsAnchors); - return d->top; -} - -void QmlGraphicsAnchors::setTop(const QmlGraphicsAnchorLine &edge) -{ - Q_D(QmlGraphicsAnchors); - if (!d->checkVAnchorValid(edge)) - return; - - d->usedAnchors |= HasTopAnchor; - - if (!d->checkVValid()) { - d->usedAnchors &= ~HasTopAnchor; - return; - } - - d->remDepend(d->top.item); - d->top = edge; - d->addDepend(d->top.item); - d->updateVerticalAnchors(); -} - -void QmlGraphicsAnchors::resetTop() -{ - Q_D(QmlGraphicsAnchors); - d->usedAnchors &= ~HasTopAnchor; - d->remDepend(d->top.item); - d->top = QmlGraphicsAnchorLine(); - d->updateVerticalAnchors(); -} - -QmlGraphicsAnchorLine QmlGraphicsAnchors::bottom() const -{ - Q_D(const QmlGraphicsAnchors); - return d->bottom; -} - -void QmlGraphicsAnchors::setBottom(const QmlGraphicsAnchorLine &edge) -{ - Q_D(QmlGraphicsAnchors); - if (!d->checkVAnchorValid(edge)) - return; - - d->usedAnchors |= HasBottomAnchor; - - if (!d->checkVValid()) { - d->usedAnchors &= ~HasBottomAnchor; - return; - } - - d->remDepend(d->bottom.item); - d->bottom = edge; - d->addDepend(d->bottom.item); - d->updateVerticalAnchors(); -} - -void QmlGraphicsAnchors::resetBottom() -{ - Q_D(QmlGraphicsAnchors); - d->usedAnchors &= ~HasBottomAnchor; - d->remDepend(d->bottom.item); - d->bottom = QmlGraphicsAnchorLine(); - d->updateVerticalAnchors(); -} - -QmlGraphicsAnchorLine QmlGraphicsAnchors::verticalCenter() const -{ - Q_D(const QmlGraphicsAnchors); - return d->vCenter; -} - -void QmlGraphicsAnchors::setVerticalCenter(const QmlGraphicsAnchorLine &edge) -{ - Q_D(QmlGraphicsAnchors); - if (!d->checkVAnchorValid(edge)) - return; - - d->usedAnchors |= HasVCenterAnchor; - - if (!d->checkVValid()) { - d->usedAnchors &= ~HasVCenterAnchor; - return; - } - - d->remDepend(d->vCenter.item); - d->vCenter = edge; - d->addDepend(d->vCenter.item); - d->updateVerticalAnchors(); -} - -void QmlGraphicsAnchors::resetVerticalCenter() -{ - Q_D(QmlGraphicsAnchors); - d->usedAnchors &= ~HasVCenterAnchor; - d->remDepend(d->vCenter.item); - d->vCenter = QmlGraphicsAnchorLine(); - d->updateVerticalAnchors(); -} - -QmlGraphicsAnchorLine QmlGraphicsAnchors::baseline() const -{ - Q_D(const QmlGraphicsAnchors); - return d->baseline; -} - -void QmlGraphicsAnchors::setBaseline(const QmlGraphicsAnchorLine &edge) -{ - Q_D(QmlGraphicsAnchors); - if (!d->checkVAnchorValid(edge)) - return; - - d->usedAnchors |= HasBaselineAnchor; - - if (!d->checkVValid()) { - d->usedAnchors &= ~HasBaselineAnchor; - return; - } - - d->remDepend(d->baseline.item); - d->baseline = edge; - d->addDepend(d->baseline.item); - d->updateVerticalAnchors(); -} - -void QmlGraphicsAnchors::resetBaseline() -{ - Q_D(QmlGraphicsAnchors); - d->usedAnchors &= ~HasBaselineAnchor; - d->remDepend(d->baseline.item); - d->baseline = QmlGraphicsAnchorLine(); - d->updateVerticalAnchors(); -} - -QmlGraphicsAnchorLine QmlGraphicsAnchors::left() const -{ - Q_D(const QmlGraphicsAnchors); - return d->left; -} - -void QmlGraphicsAnchors::setLeft(const QmlGraphicsAnchorLine &edge) -{ - Q_D(QmlGraphicsAnchors); - if (!d->checkHAnchorValid(edge)) - return; - - d->usedAnchors |= HasLeftAnchor; - - if (!d->checkHValid()) { - d->usedAnchors &= ~HasLeftAnchor; - return; - } - - d->remDepend(d->left.item); - d->left = edge; - d->addDepend(d->left.item); - d->updateHorizontalAnchors(); -} - -void QmlGraphicsAnchors::resetLeft() -{ - Q_D(QmlGraphicsAnchors); - d->usedAnchors &= ~HasLeftAnchor; - d->remDepend(d->left.item); - d->left = QmlGraphicsAnchorLine(); - d->updateHorizontalAnchors(); -} - -QmlGraphicsAnchorLine QmlGraphicsAnchors::right() const -{ - Q_D(const QmlGraphicsAnchors); - return d->right; -} - -void QmlGraphicsAnchors::setRight(const QmlGraphicsAnchorLine &edge) -{ - Q_D(QmlGraphicsAnchors); - if (!d->checkHAnchorValid(edge)) - return; - - d->usedAnchors |= HasRightAnchor; - - if (!d->checkHValid()) { - d->usedAnchors &= ~HasRightAnchor; - return; - } - - d->remDepend(d->right.item); - d->right = edge; - d->addDepend(d->right.item); - - d->updateHorizontalAnchors(); -} - -void QmlGraphicsAnchors::resetRight() -{ - Q_D(QmlGraphicsAnchors); - d->usedAnchors &= ~HasRightAnchor; - d->remDepend(d->right.item); - d->right = QmlGraphicsAnchorLine(); - d->updateHorizontalAnchors(); -} - -QmlGraphicsAnchorLine QmlGraphicsAnchors::horizontalCenter() const -{ - Q_D(const QmlGraphicsAnchors); - return d->hCenter; -} - -void QmlGraphicsAnchors::setHorizontalCenter(const QmlGraphicsAnchorLine &edge) -{ - Q_D(QmlGraphicsAnchors); - if (!d->checkHAnchorValid(edge)) - return; - - d->usedAnchors |= HasHCenterAnchor; - - if (!d->checkHValid()) { - d->usedAnchors &= ~HasHCenterAnchor; - return; - } - - d->remDepend(d->hCenter.item); - d->hCenter = edge; - d->addDepend(d->hCenter.item); - d->updateHorizontalAnchors(); -} - -void QmlGraphicsAnchors::resetHorizontalCenter() -{ - Q_D(QmlGraphicsAnchors); - d->usedAnchors &= ~HasHCenterAnchor; - d->remDepend(d->hCenter.item); - d->hCenter = QmlGraphicsAnchorLine(); - d->updateHorizontalAnchors(); -} - -qreal QmlGraphicsAnchors::leftMargin() const -{ - Q_D(const QmlGraphicsAnchors); - return d->leftMargin; -} - -void QmlGraphicsAnchors::setLeftMargin(qreal offset) -{ - Q_D(QmlGraphicsAnchors); - if (d->leftMargin == offset) - return; - d->leftMargin = offset; - d->updateHorizontalAnchors(); - emit leftMarginChanged(); -} - -qreal QmlGraphicsAnchors::rightMargin() const -{ - Q_D(const QmlGraphicsAnchors); - return d->rightMargin; -} - -void QmlGraphicsAnchors::setRightMargin(qreal offset) -{ - Q_D(QmlGraphicsAnchors); - if (d->rightMargin == offset) - return; - d->rightMargin = offset; - d->updateHorizontalAnchors(); - emit rightMarginChanged(); -} - -qreal QmlGraphicsAnchors::horizontalCenterOffset() const -{ - Q_D(const QmlGraphicsAnchors); - return d->hCenterOffset; -} - -void QmlGraphicsAnchors::setHorizontalCenterOffset(qreal offset) -{ - Q_D(QmlGraphicsAnchors); - if (d->hCenterOffset == offset) - return; - d->hCenterOffset = offset; - d->updateHorizontalAnchors(); - emit horizontalCenterOffsetChanged(); -} - -qreal QmlGraphicsAnchors::topMargin() const -{ - Q_D(const QmlGraphicsAnchors); - return d->topMargin; -} - -void QmlGraphicsAnchors::setTopMargin(qreal offset) -{ - Q_D(QmlGraphicsAnchors); - if (d->topMargin == offset) - return; - d->topMargin = offset; - d->updateVerticalAnchors(); - emit topMarginChanged(); -} - -qreal QmlGraphicsAnchors::bottomMargin() const -{ - Q_D(const QmlGraphicsAnchors); - return d->bottomMargin; -} - -void QmlGraphicsAnchors::setBottomMargin(qreal offset) -{ - Q_D(QmlGraphicsAnchors); - if (d->bottomMargin == offset) - return; - d->bottomMargin = offset; - d->updateVerticalAnchors(); - emit bottomMarginChanged(); -} - -qreal QmlGraphicsAnchors::verticalCenterOffset() const -{ - Q_D(const QmlGraphicsAnchors); - return d->vCenterOffset; -} - -void QmlGraphicsAnchors::setVerticalCenterOffset(qreal offset) -{ - Q_D(QmlGraphicsAnchors); - if (d->vCenterOffset == offset) - return; - d->vCenterOffset = offset; - d->updateVerticalAnchors(); - emit verticalCenterOffsetChanged(); -} - -qreal QmlGraphicsAnchors::baselineOffset() const -{ - Q_D(const QmlGraphicsAnchors); - return d->baselineOffset; -} - -void QmlGraphicsAnchors::setBaselineOffset(qreal offset) -{ - Q_D(QmlGraphicsAnchors); - if (d->baselineOffset == offset) - return; - d->baselineOffset = offset; - d->updateVerticalAnchors(); - emit baselineOffsetChanged(); -} - -QmlGraphicsAnchors::UsedAnchors QmlGraphicsAnchors::usedAnchors() const -{ - Q_D(const QmlGraphicsAnchors); - return d->usedAnchors; -} - -void QmlGraphicsAnchors::setItem(QmlGraphicsItem *item) -{ - Q_D(QmlGraphicsAnchors); - d->item = item; -} - -bool QmlGraphicsAnchorsPrivate::checkHValid() const -{ - if (usedAnchors & QmlGraphicsAnchors::HasLeftAnchor && - usedAnchors & QmlGraphicsAnchors::HasRightAnchor && - usedAnchors & QmlGraphicsAnchors::HasHCenterAnchor) { - qmlInfo(QmlGraphicsAnchors::tr("Can't specify left, right, and hcenter anchors."), item); - return false; - } - - return true; -} - -bool QmlGraphicsAnchorsPrivate::checkHAnchorValid(QmlGraphicsAnchorLine anchor) const -{ - if (!anchor.item) { - qmlInfo(QmlGraphicsAnchors::tr("Can't anchor to a null item."), item); - return false; - } else if (anchor.anchorLine & QmlGraphicsAnchorLine::Vertical_Mask) { - qmlInfo(QmlGraphicsAnchors::tr("Can't anchor a horizontal edge to a vertical edge."), item); - return false; - } else if (anchor.item != item->parentItem() && anchor.item->parentItem() != item->parentItem()){ - qmlInfo(QmlGraphicsAnchors::tr("Can't anchor to an item that isn't a parent or sibling."), item); - return false; - } else if (anchor.item == item) { - qmlInfo(QmlGraphicsAnchors::tr("Can't anchor item to self."), item); - return false; - } - - return true; -} - -bool QmlGraphicsAnchorsPrivate::checkVValid() const -{ - if (usedAnchors & QmlGraphicsAnchors::HasTopAnchor && - usedAnchors & QmlGraphicsAnchors::HasBottomAnchor && - usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor) { - qmlInfo(QmlGraphicsAnchors::tr("Can't specify top, bottom, and vcenter anchors."), item); - return false; - } else if (usedAnchors & QmlGraphicsAnchors::HasBaselineAnchor && - (usedAnchors & QmlGraphicsAnchors::HasTopAnchor || - usedAnchors & QmlGraphicsAnchors::HasBottomAnchor || - usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor)) { - qmlInfo(QmlGraphicsAnchors::tr("Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors."), item); - return false; - } - - return true; -} - -bool QmlGraphicsAnchorsPrivate::checkVAnchorValid(QmlGraphicsAnchorLine anchor) const -{ - if (!anchor.item) { - qmlInfo(QmlGraphicsAnchors::tr("Can't anchor to a null item."), item); - return false; - } else if (anchor.anchorLine & QmlGraphicsAnchorLine::Horizontal_Mask) { - qmlInfo(QmlGraphicsAnchors::tr("Can't anchor a vertical edge to a horizontal edge."), item); - return false; - } else if (anchor.item != item->parentItem() && anchor.item->parentItem() != item->parentItem()){ - qmlInfo(QmlGraphicsAnchors::tr("Can't anchor to an item that isn't a parent or sibling."), item); - return false; - } else if (anchor.item == item){ - qmlInfo(QmlGraphicsAnchors::tr("Can't anchor item to self."), item); - return false; - } - - return true; -} - -QT_END_NAMESPACE - -#include "moc_qfxanchors.cpp" - diff --git a/src/declarative/fx/qfxanchors.h b/src/declarative/fx/qfxanchors.h deleted file mode 100644 index 9e2bac6..0000000 --- a/src/declarative/fx/qfxanchors.h +++ /dev/null @@ -1,180 +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 QFXANCHORS_H -#define QFXANCHORS_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsAnchorsPrivate; -class QmlGraphicsAnchorLine; -class Q_DECLARATIVE_EXPORT QmlGraphicsAnchors : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QmlGraphicsAnchorLine left READ left WRITE setLeft RESET resetLeft) - Q_PROPERTY(QmlGraphicsAnchorLine right READ right WRITE setRight RESET resetRight) - Q_PROPERTY(QmlGraphicsAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter) - Q_PROPERTY(QmlGraphicsAnchorLine top READ top WRITE setTop RESET resetTop) - Q_PROPERTY(QmlGraphicsAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom) - Q_PROPERTY(QmlGraphicsAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter) - Q_PROPERTY(QmlGraphicsAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline) - Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged) - Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) - Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged()) - Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) - Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) - Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged()) - Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged()) - Q_PROPERTY(QmlGraphicsItem *fill READ fill WRITE setFill) - Q_PROPERTY(QmlGraphicsItem *centerIn READ centerIn WRITE setCenterIn) - -public: - QmlGraphicsAnchors(QObject *parent=0); - virtual ~QmlGraphicsAnchors(); - - enum UsedAnchor { - HasLeftAnchor = 0x01, - HasRightAnchor = 0x02, - HasTopAnchor = 0x04, - HasBottomAnchor = 0x08, - HasHCenterAnchor = 0x10, - HasVCenterAnchor = 0x20, - HasBaselineAnchor = 0x40, - Horizontal_Mask = HasLeftAnchor | HasRightAnchor | HasHCenterAnchor, - Vertical_Mask = HasTopAnchor | HasBottomAnchor | HasVCenterAnchor | HasBaselineAnchor - }; - Q_DECLARE_FLAGS(UsedAnchors, UsedAnchor) - - QmlGraphicsAnchorLine left() const; - void setLeft(const QmlGraphicsAnchorLine &edge); - void resetLeft(); - - QmlGraphicsAnchorLine right() const; - void setRight(const QmlGraphicsAnchorLine &edge); - void resetRight(); - - QmlGraphicsAnchorLine horizontalCenter() const; - void setHorizontalCenter(const QmlGraphicsAnchorLine &edge); - void resetHorizontalCenter(); - - QmlGraphicsAnchorLine top() const; - void setTop(const QmlGraphicsAnchorLine &edge); - void resetTop(); - - QmlGraphicsAnchorLine bottom() const; - void setBottom(const QmlGraphicsAnchorLine &edge); - void resetBottom(); - - QmlGraphicsAnchorLine verticalCenter() const; - void setVerticalCenter(const QmlGraphicsAnchorLine &edge); - void resetVerticalCenter(); - - QmlGraphicsAnchorLine baseline() const; - void setBaseline(const QmlGraphicsAnchorLine &edge); - void resetBaseline(); - - qreal leftMargin() const; - void setLeftMargin(qreal); - - qreal rightMargin() const; - void setRightMargin(qreal); - - qreal horizontalCenterOffset() const; - void setHorizontalCenterOffset(qreal); - - qreal topMargin() const; - void setTopMargin(qreal); - - qreal bottomMargin() const; - void setBottomMargin(qreal); - - qreal verticalCenterOffset() const; - void setVerticalCenterOffset(qreal); - - qreal baselineOffset() const; - void setBaselineOffset(qreal); - - QmlGraphicsItem *fill() const; - void setFill(QmlGraphicsItem *); - - QmlGraphicsItem *centerIn() const; - void setCenterIn(QmlGraphicsItem *); - - UsedAnchors usedAnchors() const; - - void setItem(QmlGraphicsItem *item); - - void classBegin(); - void componentComplete(); - -Q_SIGNALS: - void leftMarginChanged(); - void rightMarginChanged(); - void topMarginChanged(); - void bottomMarginChanged(); - void verticalCenterOffsetChanged(); - void horizontalCenterOffsetChanged(); - void baselineOffsetChanged(); - -private: - friend class QmlGraphicsItem; - Q_DISABLE_COPY(QmlGraphicsAnchors) - Q_DECLARE_PRIVATE(QmlGraphicsAnchors) -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(QmlGraphicsAnchors::UsedAnchors) - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsAnchors) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qfxanchors_p.h b/src/declarative/fx/qfxanchors_p.h deleted file mode 100644 index 50f1dc4..0000000 --- a/src/declarative/fx/qfxanchors_p.h +++ /dev/null @@ -1,160 +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 QFXANCHORS_P_H -#define QFXANCHORS_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 "qfxanchors.h" -#include "private/qobject_p.h" - -QT_BEGIN_NAMESPACE - -class QmlGraphicsAnchorLine -{ -public: - QmlGraphicsAnchorLine() : item(0), anchorLine(Invalid) - { - } - - enum AnchorLine { - Invalid = 0x0, - Left = 0x01, - Right = 0x02, - Top = 0x04, - Bottom = 0x08, - HCenter = 0x10, - VCenter = 0x20, - Baseline = 0x40, - Horizontal_Mask = Left | Right | HCenter, - Vertical_Mask = Top | Bottom | VCenter | Baseline - }; - - QmlGraphicsItem *item; - AnchorLine anchorLine; -}; -Q_DECLARE_METATYPE(QmlGraphicsAnchorLine) - -class QmlGraphicsAnchorsPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsAnchors) -public: - QmlGraphicsAnchorsPrivate() - : updatingMe(false), updatingHorizontalAnchor(0), - updatingVerticalAnchor(0), item(0), usedAnchors(0), fill(0), - centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), - bottomMargin(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0), - componentComplete(true) - { - } - - void init() - { - } - - void clearItem(QmlGraphicsItem *); - - void addDepend(QmlGraphicsItem *); - void remDepend(QmlGraphicsItem *); - bool isItemComplete() const; - - bool updatingMe; - int updatingHorizontalAnchor; - int updatingVerticalAnchor; - - void setItemHeight(qreal); - void setItemWidth(qreal); - void setItemX(qreal); - void setItemY(qreal); - void setItemPos(const QPointF &); - - void updateOnComplete(); - void updateMe(); - void update(QmlGraphicsItem *, const QRectF &, const QRectF &); - - bool checkHValid() const; - bool checkVValid() const; - bool checkHAnchorValid(QmlGraphicsAnchorLine anchor) const; - bool checkVAnchorValid(QmlGraphicsAnchorLine anchor) const; - bool calcStretch(const QmlGraphicsAnchorLine &edge1, const QmlGraphicsAnchorLine &edge2, int offset1, int offset2, QmlGraphicsAnchorLine::AnchorLine line, int &stretch); - - void updateHorizontalAnchors(); - void updateVerticalAnchors(); - void fillChanged(); - void centerInChanged(); - - QmlGraphicsItem *item; - QmlGraphicsAnchors::UsedAnchors usedAnchors; - - QmlGraphicsItem *fill; - QmlGraphicsItem *centerIn; - - QmlGraphicsAnchorLine left; - QmlGraphicsAnchorLine right; - QmlGraphicsAnchorLine top; - QmlGraphicsAnchorLine bottom; - QmlGraphicsAnchorLine vCenter; - QmlGraphicsAnchorLine hCenter; - QmlGraphicsAnchorLine baseline; - - qreal leftMargin; - qreal rightMargin; - qreal topMargin; - qreal bottomMargin; - qreal vCenterOffset; - qreal hCenterOffset; - qreal baselineOffset; - - bool componentComplete; -}; - -QT_END_NAMESPACE -#endif diff --git a/src/declarative/fx/qfxborderimage.cpp b/src/declarative/fx/qfxborderimage.cpp deleted file mode 100644 index 1ee2f71..0000000 --- a/src/declarative/fx/qfxborderimage.cpp +++ /dev/null @@ -1,411 +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 "qfxborderimage.h" -#include "qfxborderimage_p.h" -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,BorderImage,QmlGraphicsBorderImage) - -/*! - \qmlclass BorderImage QmlGraphicsBorderImage - \brief The BorderImage element provides an image that can be used as a border. - \inherits Item - - \snippet examples/declarative/border-image/example.qml 0 - - \image BorderImage.png - - \sa examples/declarative/border-image - */ - -/*! - \internal - \class QmlGraphicsBorderImage BorderImage - \brief The QmlGraphicsBorderImage class provides an image item that you can add to a QmlView. -*/ - -QmlGraphicsBorderImage::QmlGraphicsBorderImage(QmlGraphicsItem *parent) - : QmlGraphicsImageBase(*(new QmlGraphicsBorderImagePrivate), parent) -{ - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -QmlGraphicsBorderImage::~QmlGraphicsBorderImage() -{ - Q_D(QmlGraphicsBorderImage); - if (d->sciReply) - d->sciReply->deleteLater(); - if (d->sciPendingPixmapCache) - QmlGraphicsPixmapCache::cancelGet(d->sciurl, this); -} -/*! - \qmlproperty enum BorderImage::status - - This property holds the status of image loading. It can be one of: - \list - \o Null - no image has been set - \o Ready - the image has been loaded - \o Loading - the image is currently being loaded - \o Error - an error occurred while loading the image - \endlist - - \sa progress -*/ - -/*! - \qmlproperty real BorderImage::progress - - This property holds the progress of image loading, from 0.0 (nothing loaded) - to 1.0 (finished). - - \sa status -*/ - -/*! - \qmlproperty bool BorderImage::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 image 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. -*/ - -/*! - \qmlproperty url BorderImage::source - - BorderImage can handle any image format supported by Qt, loaded from any URL scheme supported by Qt. - - It can also handle .sci files, which are a Qml-specific format. A .sci file uses a simple text-based format that specifies - the borders, the image file and the tile rules. - - The following .sci file sets the borders to 10 on each side for the image \c picture.png: - \qml - border.left: 10 - border.top: 10 - border.bottom: 10 - border.right: 10 - source: picture.png - \endqml - - The URL may be absolute, or relative to the URL of the component. -*/ - -static QString toLocalFileOrQrc(const QUrl& url) -{ - QString r = url.toLocalFile(); - if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) - r = QLatin1Char(':') + url.path(); - return r; -} - - -void QmlGraphicsBorderImage::setSource(const QUrl &url) -{ - Q_D(QmlGraphicsBorderImage); - //equality is fairly expensive, so we bypass for simple, common case - if ((d->url.isEmpty() == url.isEmpty()) && url == d->url) - return; - - if (d->sciReply) { - d->sciReply->deleteLater(); - d->sciReply = 0; - } - - if (d->pendingPixmapCache) { - QmlGraphicsPixmapCache::cancelGet(d->url, this); - d->pendingPixmapCache = false; - } - if (d->sciPendingPixmapCache) { - QmlGraphicsPixmapCache::cancelGet(d->sciurl, this); - d->sciPendingPixmapCache = false; - } - - d->url = url; - d->sciurl = QUrl(); - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } - - if (url.isEmpty()) { - d->pix = QPixmap(); - d->status = Null; - d->progress = 1.0; - setImplicitWidth(0); - setImplicitHeight(0); - emit statusChanged(d->status); - emit sourceChanged(d->url); - emit progressChanged(1.0); - update(); - } else { - d->status = Loading; - if (d->url.path().endsWith(QLatin1String(".sci"))) { -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - QString lf = toLocalFileOrQrc(d->url); - if (!lf.isEmpty()) { - QFile file(lf); - file.open(QIODevice::ReadOnly); - setGridScaledImage(QmlGraphicsGridScaledImage(&file)); - } else -#endif - { - QNetworkRequest req(d->url); - d->sciReply = qmlEngine(this)->networkAccessManager()->get(req); - QObject::connect(d->sciReply, SIGNAL(finished()), - this, SLOT(sciRequestFinished())); - } - } else { - QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->pix); - if (reply) { - d->pendingPixmapCache = true; - connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); - connect(reply, SIGNAL(downloadProgress(qint64,qint64)), - this, SLOT(requestProgress(qint64,qint64))); - } else { - //### should be unified with requestFinished - setImplicitWidth(d->pix.width()); - setImplicitHeight(d->pix.height()); - - if (d->status == Loading) - d->status = Ready; - d->progress = 1.0; - emit statusChanged(d->status); - emit sourceChanged(d->url); - emit progressChanged(1.0); - update(); - } - } - } - - emit statusChanged(d->status); -} - -/*! - \qmlproperty int BorderImage::border.left - \qmlproperty int BorderImage::border.right - \qmlproperty int BorderImage::border.top - \qmlproperty int BorderImage::border.bottom - - \target ImagexmlpropertiesscaleGrid - - The 4 border lines (2 horizontal and 2 vertical) break an image into 9 sections, as shown below: - - \image declarative-scalegrid.png - - When the image is scaled: - \list - \i the corners (sections 1, 3, 7, and 9) are not scaled at all - \i the middle (section 5) is scaled according to BorderImage::horizontalTileMode and BorderImage::verticalTileMode - \i sections 2 and 8 are scaled according to BorderImage::horizontalTileMode - \i sections 4 and 6 are scaled according to BorderImage::verticalTileMode - \endlist - - Each border line (left, right, top, and bottom) specifies an offset from the respective side. For example, \c{border.bottom: 10} sets the bottom line 10 pixels up from the bottom of the image. - - The border lines can also be specified using a - \l {BorderImage::source}{.sci file}. -*/ - -QmlGraphicsScaleGrid *QmlGraphicsBorderImage::border() -{ - Q_D(QmlGraphicsBorderImage); - return d->getScaleGrid(); -} - -/*! - \qmlproperty TileMode BorderImage::horizontalTileMode - \qmlproperty TileMode BorderImage::verticalTileMode - - This property describes how to repeat or stretch the middle parts of the border image. - - \list - \o Stretch - Scale the image to fit to the available area. - \o Repeat - Tile the image until there is no more space. May crop the last image. - \o Round - Like Repeat, but scales the images down to ensure that the last image is not cropped. - \endlist -*/ -QmlGraphicsBorderImage::TileMode QmlGraphicsBorderImage::horizontalTileMode() const -{ - Q_D(const QmlGraphicsBorderImage); - return d->horizontalTileMode; -} - -void QmlGraphicsBorderImage::setHorizontalTileMode(TileMode t) -{ - Q_D(QmlGraphicsBorderImage); - if (t != d->horizontalTileMode) { - d->horizontalTileMode = t; - emit horizontalTileModeChanged(); - update(); - } -} - -QmlGraphicsBorderImage::TileMode QmlGraphicsBorderImage::verticalTileMode() const -{ - Q_D(const QmlGraphicsBorderImage); - return d->verticalTileMode; -} - -void QmlGraphicsBorderImage::setVerticalTileMode(TileMode t) -{ - Q_D(QmlGraphicsBorderImage); - if (t != d->verticalTileMode) { - d->verticalTileMode = t; - emit verticalTileModeChanged(); - update(); - } -} - -void QmlGraphicsBorderImage::setGridScaledImage(const QmlGraphicsGridScaledImage& sci) -{ - Q_D(QmlGraphicsBorderImage); - if (!sci.isValid()) { - d->status = Error; - emit statusChanged(d->status); - } else { - QmlGraphicsScaleGrid *sg = border(); - sg->setTop(sci.gridTop()); - sg->setBottom(sci.gridBottom()); - sg->setLeft(sci.gridLeft()); - sg->setRight(sci.gridRight()); - d->horizontalTileMode = sci.horizontalTileRule(); - d->verticalTileMode = sci.verticalTileRule(); - - d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); - QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->sciurl, &d->pix); - if (reply) { - d->sciPendingPixmapCache = true; - connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); - connect(reply, SIGNAL(downloadProgress(qint64,qint64)), - this, SLOT(requestProgress(qint64,qint64))); - } else { - //### should be unified with requestFinished - setImplicitWidth(d->pix.width()); - setImplicitHeight(d->pix.height()); - - if (d->status == Loading) - d->status = Ready; - d->progress = 1.0; - emit statusChanged(d->status); - emit sourceChanged(d->url); - emit progressChanged(1.0); - update(); - } - } -} - -void QmlGraphicsBorderImage::requestFinished() -{ - Q_D(QmlGraphicsBorderImage); - - if (d->url.path().endsWith(QLatin1String(".sci"))) { - d->sciPendingPixmapCache = false; - QmlGraphicsPixmapCache::find(d->sciurl, &d->pix); - } else { - d->pendingPixmapCache = false; - if (!QmlGraphicsPixmapCache::find(d->url, &d->pix)) - d->status = Error; - } - setImplicitWidth(d->pix.width()); - setImplicitHeight(d->pix.height()); - - if (d->status == Loading) - d->status = Ready; - d->progress = 1.0; - emit statusChanged(d->status); - emit sourceChanged(d->url); - emit progressChanged(1.0); - update(); -} - -void QmlGraphicsBorderImage::sciRequestFinished() -{ - Q_D(QmlGraphicsBorderImage); - if (d->sciReply->error() != QNetworkReply::NoError) { - d->status = Error; - d->sciReply->deleteLater(); - d->sciReply = 0; - emit statusChanged(d->status); - } else { - QmlGraphicsGridScaledImage sci(d->sciReply); - d->sciReply->deleteLater(); - d->sciReply = 0; - setGridScaledImage(sci); - } -} - -void QmlGraphicsBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - Q_D(QmlGraphicsBorderImage); - if (d->pix.isNull()) - return; - - bool oldAA = p->testRenderHint(QPainter::Antialiasing); - bool oldSmooth = p->testRenderHint(QPainter::SmoothPixmapTransform); - if (d->smooth) - p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); - - QMargins margins(border()->top(), border()->left(), border()->bottom(), border()->right()); - QTileRules rules((Qt::TileRule)d->horizontalTileMode, (Qt::TileRule)d->verticalTileMode); - qDrawBorderPixmap(p, QRect(0, 0, (int)d->width, (int)d->height), margins, d->pix, d->pix.rect(), margins, rules); - if (d->smooth) { - p->setRenderHint(QPainter::Antialiasing, oldAA); - p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); - } -} - -QmlGraphicsBorderImage::QmlGraphicsBorderImage(QmlGraphicsBorderImagePrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsImageBase(dd, parent) -{ - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxborderimage.h b/src/declarative/fx/qfxborderimage.h deleted file mode 100644 index b6f99a3..0000000 --- a/src/declarative/fx/qfxborderimage.h +++ /dev/null @@ -1,105 +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 QFXBORDERIMAGE_H -#define QFXBORDERIMAGE_H - -#include -#include "qfximagebase.h" - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsScaleGrid; -class QmlGraphicsGridScaledImage; -class QmlGraphicsBorderImagePrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsBorderImage : public QmlGraphicsImageBase -{ - Q_OBJECT - Q_ENUMS(TileMode) - - Q_PROPERTY(QmlGraphicsScaleGrid *border READ border CONSTANT) - Q_PROPERTY(TileMode horizontalTileMode READ horizontalTileMode WRITE setHorizontalTileMode NOTIFY horizontalTileModeChanged) - Q_PROPERTY(TileMode verticalTileMode READ verticalTileMode WRITE setVerticalTileMode NOTIFY verticalTileModeChanged) - -public: - QmlGraphicsBorderImage(QmlGraphicsItem *parent=0); - ~QmlGraphicsBorderImage(); - - QmlGraphicsScaleGrid *border(); - - enum TileMode { Stretch = Qt::StretchTile, Repeat = Qt::RepeatTile, Round = Qt::RoundTile }; - - TileMode horizontalTileMode() const; - void setHorizontalTileMode(TileMode); - - TileMode verticalTileMode() const; - void setVerticalTileMode(TileMode); - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - void setSource(const QUrl &url); - -Q_SIGNALS: - void horizontalTileModeChanged(); - void verticalTileModeChanged(); - -protected: - QmlGraphicsBorderImage(QmlGraphicsBorderImagePrivate &dd, QmlGraphicsItem *parent); - -private: - void setGridScaledImage(const QmlGraphicsGridScaledImage& sci); - -private Q_SLOTS: - void requestFinished(); - void sciRequestFinished(); - -private: - Q_DISABLE_COPY(QmlGraphicsBorderImage) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsBorderImage) -}; - -QT_END_NAMESPACE -QML_DECLARE_TYPE(QmlGraphicsBorderImage) -QT_END_HEADER - -#endif // QFXBORDERIMAGE_H diff --git a/src/declarative/fx/qfxborderimage_p.h b/src/declarative/fx/qfxborderimage_p.h deleted file mode 100644 index 75a638c..0000000 --- a/src/declarative/fx/qfxborderimage_p.h +++ /dev/null @@ -1,97 +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 QFXBORDERIMAGE_P_H -#define QFXBORDERIMAGE_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 "qfximagebase_p.h" -#include "qfxscalegrid_p.h" - -QT_BEGIN_NAMESPACE - -class QNetworkReply; -class QmlGraphicsBorderImagePrivate : public QmlGraphicsImageBasePrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsBorderImage) - -public: - QmlGraphicsBorderImagePrivate() - : border(0), sciReply(0), - sciPendingPixmapCache(false), - horizontalTileMode(QmlGraphicsBorderImage::Stretch), - verticalTileMode(QmlGraphicsBorderImage::Stretch) - { - } - - ~QmlGraphicsBorderImagePrivate() - { - } - - QmlGraphicsScaleGrid *getScaleGrid() - { - Q_Q(QmlGraphicsBorderImage); - if (!border) - border = new QmlGraphicsScaleGrid(q); - return border; - } - - QmlGraphicsScaleGrid *border; - QUrl sciurl; - QNetworkReply *sciReply; - bool sciPendingPixmapCache; - QmlGraphicsBorderImage::TileMode horizontalTileMode; - QmlGraphicsBorderImage::TileMode verticalTileMode; -}; - -QT_END_NAMESPACE - -#endif // QFXBORDERIMAGE_P_H diff --git a/src/declarative/fx/qfxeffects.cpp b/src/declarative/fx/qfxeffects.cpp deleted file mode 100644 index ebdd880..0000000 --- a/src/declarative/fx/qfxeffects.cpp +++ /dev/null @@ -1,238 +0,0 @@ -#include -#include -#include - -QML_DECLARE_TYPE(QGraphicsEffect) -QML_DEFINE_NOCREATE_TYPE(QGraphicsEffect) - -QML_DECLARE_TYPE(QGraphicsBlurEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Blur,QGraphicsBlurEffect) - -/*! - \qmlclass Blur - \brief The Blur object provides a blur effect. - - A blur effect blurs the source item. This effect is useful for reducing details, - such as when the source loses focus and you want to draw attention to other - elements. The level of detail can be modified using the blurRadius property. - Use blurHint to choose the quality or performance blur hints. - - By default, the blur radius is 5 pixels. - - \img graphicseffect-blur.png -*/ - -/*! - \qmlproperty real Blur::blurRadius - - blurRadius controls how blurry an item will appear. - Using a smaller radius results in a sharper appearance, whereas a bigger - radius results in a more blurred appearance. - - By default, the blur radius is 5 pixels. -*/ -/*! - \qmlproperty enumeration Blur::blurHint - - Use the Qt.PerformanceHint hint to say that you want a faster blur, - and the Qt.QualityHint hint to say that you prefer a higher quality blur. - - When animating the blur radius it's recommended to use Qt.PerformanceHint. - - By default, the blur hint is Qt.PerformanceHint. -*/ - -QML_DECLARE_TYPE(QGraphicsGrayscaleEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Grayscale,QGraphicsGrayscaleEffect) - -/*! - \qmlclass Grayscale - \brief The Grayscale object provides a grayscale effect. - - A grayscale effect renders the source item in shades of gray. - - \img graphicseffect-grayscale.png -*/ - -/*! - \qmlproperty real Grayscale::strength - - To what extent the source item is "grayed". A strength of 0.0 is equal to no effect, - while 1.0 means full grayscale. By default, the strength is 1.0. -*/ - -QML_DECLARE_TYPE(QGraphicsColorizeEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Colorize,QGraphicsColorizeEffect) - -/*! - \qmlclass Colorize - \brief The Colorize object provides a colorize effect. - - A colorize effect renders the source item with a tint of its color. - - By default, the color is light blue. - - \img graphicseffect-colorize.png -*/ - -/*! - \qmlproperty color Colorize::color - The color of the effect. - - By default, the color is light blue. -*/ - -/*! - \qmlproperty real Colorize::strength - - To what extent the source item is "colored". A strength of 0.0 is equal to no effect, - while 1.0 means full colorization. By default, the strength is 1.0. -*/ - -QML_DECLARE_TYPE(QGraphicsPixelizeEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pixelize,QGraphicsPixelizeEffect) - -/*! - \qmlclass Pixelize - \brief The Pixelize object provides a pixelize effect. - - A pixelize effect renders the source item in lower resolution. The resolution - can be modified using the pixelSize property. - - By default, the pixel size is 3. - - \img graphicseffect-pixelize.png -*/ - -/*! - \qmlproperty int Pixelize::pixelSize - The size of a pixel in the effect. - - Setting the pixel size to 2 means two pixels in the source item will be used to - represent one pixel in the output. Using a bigger size results in lower resolution. - - By default, the pixel size is 3. -*/ - - -QML_DECLARE_TYPE(QGraphicsDropShadowEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,DropShadow,QGraphicsDropShadowEffect) - -/*! - \qmlclass DropShadow - \brief The DropShadow object provides a drop shadow effect. - - A drop shadow effect renders the source item with a drop shadow. The color of - the drop shadow can be modified using the color property. The drop - shadow offset can be modified using the xOffset and yOffset properties and the blur - radius of the drop shadow can be changed with the blurRadius property. - - By default, the drop shadow is a semi-transparent dark gray shadow, - blurred with a radius of 1 at an offset of 8 pixels towards the lower right. - - \img graphicseffect-drop-shadow.png -*/ - -/*! - \qmlproperty real DropShadow::xOffset - \qmlproperty real DropShadow::yOffset - The shadow offset in pixels. - - By default, xOffset and yOffset are 8 pixels. -*/ - -/*! - \qmlproperty real DropShadow::blurRadius - The blur radius in pixels of the drop shadow. - - Using a smaller radius results in a sharper shadow, whereas using a bigger - radius results in a more blurred shadow. - - By default, the blur radius is 1 pixel. -*/ - -/*! - \qmlproperty color DropShadow::color - The color of the drop shadow. - - By default, the drop color is a semi-transparent dark gray. -*/ - -QML_DECLARE_TYPE(QGraphicsOpacityEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Opacity,QGraphicsOpacityEffect) - -/*! - \qmlclass Opacity - \brief The Opacity object provides an opacity effect. - - An opacity effect renders the source with an opacity. This effect is useful - for making the source semi-transparent, similar to a fade-in/fade-out - sequence. The opacity can be modified using the opacity property. - - By default, the opacity is 0.7. - - \img graphicseffect-opacity.png -*/ - -/*! - \qmlproperty real Opacity::opacity - This property specifies how opaque an item should appear. - - The value should be in the range of 0.0 to 1.0, where 0.0 is - fully transparent and 1.0 is fully opaque. - - By default, the opacity is 0.7. -*/ - -QML_DECLARE_TYPE(QGraphicsBloomEffect) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Bloom,QGraphicsBloomEffect) - -/*! - \qmlclass Bloom - \brief The Bloom object provides a bloom/glow effect. - - A bloom/glow effect adds fringes of light around bright areas in the source item. - - \img graphicseffect-bloom.png -*/ - -/*! - \qmlproperty real Bloom::blurRadius - The blur radius in pixels of the effect. - - Using a smaller radius results in a sharper appearance, whereas a bigger - radius results in a more blurred appearance. - - By default, the blur radius is 5 pixels. -*/ - -/*! - \qmlproperty enumeration Bloom::blurHint - - Use the Qt.PerformanceHint hint to say that you want a faster blur, - and the Qt.QualityHint hint to say that you prefer a higher quality blur. - - When animating the blur radius it's recommended to use Qt.PerformanceHint. - - By default, the blur hint is Qt.PerformanceHint. -*/ - -/*! - \qmlproperty int Bloom::brightness - This property specifies how bright the glow should appear. - - The value should be in the range of 0 to 255, where 0 is dark - and 255 is bright. - - By default, the brightness is 70. -*/ - -/*! - \qmlproperty real Bloom::strength - The strength of the glow. - - A strength of 0.0 is equal to no effect, while 1.0 means maximum glow. - - By default, the strength is 0.7. -*/ - diff --git a/src/declarative/fx/qfxevents.cpp b/src/declarative/fx/qfxevents.cpp deleted file mode 100644 index fe249f9..0000000 --- a/src/declarative/fx/qfxevents.cpp +++ /dev/null @@ -1,195 +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 "qfxevents_p.h" - -QT_BEGIN_NAMESPACE -/*! - \qmlclass KeyEvent QmlGraphicsKeyEvent - \brief The KeyEvent object provides information about a key event. - - For example, the following changes the Item's state property when the Enter - key is pressed: - \qml -Item { - focus: true - Keys.onPressed: { if (event.key == Qt.Key_Enter) state = 'ShowDetails'; } -} - \endqml -*/ - -/*! - \internal - \class QmlGraphicsKeyEvent -*/ - -/*! - \qmlproperty int KeyEvent::key - - This property holds the code of the key that was pressed or released. - - See \l {Qt::Key}{Qt.Key} for the list of keyboard codes. These codes are - independent of the underlying window system. Note that this - function does not distinguish between capital and non-capital - letters, use the text() function (returning the Unicode text the - key generated) for this purpose. - - A value of either 0 or \l {Qt::Key_unknown}{Qt.Key_Unknown} means that the event is not - the result of a known key; for example, it may be the result of - a compose sequence, a keyboard macro, or due to key event - compression. -*/ - -/*! - \qmlproperty string KeyEvent::text - - This property holds the Unicode text that the key generated. - The text returned can be an empty string in cases where modifier keys, - such as Shift, Control, Alt, and Meta, are being pressed or released. - In such cases \c key will contain a valid value -*/ - -/*! - \qmlproperty bool KeyEvent::isAutoRepeat - - This property holds whether this event comes from an auto-repeating key. -*/ - -/*! - \qmlproperty int KeyEvent::count - - This property holds the number of keys involved in this event. If \l KeyEvent::text - is not empty, this is simply the length of the string. -*/ - -/*! - \qmlproperty bool KeyEvent::accepted - - Setting \a accepted to true prevents the key event from being - propagated to the item's parent. - - Generally, if the item acts on the key event then it should be accepted - so that ancestor items do not also respond to the same event. -*/ - - -/*! - \qmlclass MouseEvent QmlGraphicsMouseEvent - \brief The MouseEvent object provides information about a mouse event. - - The position of the mouse can be found via the x and y properties. - The button that caused the event is available via the button property. -*/ - -/*! - \internal - \class QmlGraphicsMouseEvent -*/ - -/*! - \qmlproperty int MouseEvent::x - \qmlproperty int MouseEvent::y - - These properties hold the position of the mouse event. -*/ - -/*! - \qmlproperty enum MouseEvent::button - - This property holds the button that caused the event. It can be one of: - \list - \o Qt.LeftButton - \o Qt.RightButton - \o Qt.MidButton - \endlist -*/ - -/*! - \qmlproperty bool MouseEvent::wasHeld - - This property is true if the mouse button has been held pressed longer the - threshold (800ms). -*/ - -/*! - \qmlproperty int MouseEvent::buttons - - This property holds the mouse buttons pressed when the event was generated. - For mouse move events, this is all buttons that are pressed down. For mouse - press and double click events this includes the button that caused the event. - For mouse release events this excludes the button that caused the event. - - It contains a bitwise combination of: - \list - \o Qt.LeftButton - \o Qt.RightButton - \o Qt.MidButton - \endlist -*/ - -/*! - \qmlproperty int MouseEvent::modifiers - - This property holds the keyboard modifier flags that existed immediately - before the event occurred. - - It contains a bitwise combination of: - \list - \o Qt.NoModifier - No modifier key is pressed. - \o Qt.ShiftModifier - A Shift key on the keyboard is pressed. - \o Qt.ControlModifier - A Ctrl key on the keyboard is pressed. - \o Qt.AltModifier - An Alt key on the keyboard is pressed. - \o Qt.MetaModifier - A Meta key on the keyboard is pressed. - \o Qt.KeypadModifier - A keypad button is pressed. - \endlist - - For example, to react to a Shift key + Left mouse button click: - \qml -MouseRegion { - onClicked: { if (mouse.button == Qt.LeftButton && mouse.modifiers & Qt.ShiftModifier) doSomething(); } -} - \endqml -*/ - -QML_DEFINE_NOCREATE_TYPE(QmlGraphicsKeyEvent) -QML_DEFINE_NOCREATE_TYPE(QmlGraphicsMouseEvent) - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxevents_p.h b/src/declarative/fx/qfxevents_p.h deleted file mode 100644 index e558c42..0000000 --- a/src/declarative/fx/qfxevents_p.h +++ /dev/null @@ -1,137 +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 QFXEVENTS_P_H -#define QFXEVENTS_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 -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QmlGraphicsKeyEvent : public QObject -{ - Q_OBJECT - Q_PROPERTY(int key READ key) - Q_PROPERTY(QString text READ text) - Q_PROPERTY(int modifiers READ modifiers) - Q_PROPERTY(bool isAutoRepeat READ isAutoRepeat) - Q_PROPERTY(int count READ count) - Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) - -public: - QmlGraphicsKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text=QString(), bool autorep=false, ushort count=1) - : event(type, key, modifiers, text, autorep, count) { event.setAccepted(false); } - QmlGraphicsKeyEvent(const QKeyEvent &ke) - : event(ke) { event.setAccepted(false); } - - int key() const { return event.key(); } - QString text() const { return event.text(); } - int modifiers() const { return event.modifiers(); } - bool isAutoRepeat() const { return event.isAutoRepeat(); } - int count() const { return event.count(); } - - bool isAccepted() { return event.isAccepted(); } - void setAccepted(bool accepted) { event.setAccepted(accepted); } - -private: - QKeyEvent event; -}; - -class QmlGraphicsMouseEvent : public QObject -{ - Q_OBJECT - Q_PROPERTY(int x READ x) - Q_PROPERTY(int y READ y) - Q_PROPERTY(int button READ button) - Q_PROPERTY(int buttons READ buttons) - Q_PROPERTY(int modifiers READ modifiers) - Q_PROPERTY(bool wasHeld READ wasHeld) - Q_PROPERTY(bool isClick READ isClick) - Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) - -public: - QmlGraphicsMouseEvent(int x, int y, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers - , bool isClick=false, bool wasHeld=false) - : _x(x), _y(y), _button(button), _buttons(buttons), _modifiers(modifiers) - , _wasHeld(wasHeld), _isClick(isClick), _accepted(true) {} - - int x() const { return _x; } - int y() const { return _y; } - int button() const { return _button; } - int buttons() const { return _buttons; } - int modifiers() const { return _modifiers; } - bool wasHeld() const { return _wasHeld; } - bool isClick() const { return _isClick; } - - bool isAccepted() { return _accepted; } - void setAccepted(bool accepted) { _accepted = accepted; } - -private: - int _x; - int _y; - Qt::MouseButton _button; - Qt::MouseButtons _buttons; - Qt::KeyboardModifiers _modifiers; - bool _wasHeld; - bool _isClick; - bool _accepted; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsKeyEvent) -QML_DECLARE_TYPE(QmlGraphicsMouseEvent) - -#endif // QFXEVENTS_P_H diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp deleted file mode 100644 index 34e3e75..0000000 --- a/src/declarative/fx/qfxflickable.cpp +++ /dev/null @@ -1,1283 +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 "qfxflickable.h" -#include "qfxflickable_p.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - - -// These are highly device dependant. -// DragThreshold determines how far the "mouse" must move before -// we begin a drag. -// FlickThreshold determines how far the "mouse" must have moved -// before we perform a flick. -static const int DragThreshold = 8; -static const int FlickThreshold = 20; - -// Really slow flicks can be annoying. -static const int minimumFlickVelocity = 200; - -class QmlGraphicsFlickableVisibleArea : public QObject -{ - Q_OBJECT - - Q_PROPERTY(qreal xPosition READ xPosition NOTIFY pageChanged) - Q_PROPERTY(qreal yPosition READ yPosition NOTIFY pageChanged) - Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY pageChanged) - Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY pageChanged) - -public: - QmlGraphicsFlickableVisibleArea(QmlGraphicsFlickable *parent=0); - - qreal xPosition() const; - qreal widthRatio() const; - qreal yPosition() const; - qreal heightRatio() const; - - void updateVisible(); - -signals: - void pageChanged(); - -private: - QmlGraphicsFlickable *flickable; - qreal m_xPosition; - qreal m_widthRatio; - qreal m_yPosition; - qreal m_heightRatio; -}; - -QmlGraphicsFlickableVisibleArea::QmlGraphicsFlickableVisibleArea(QmlGraphicsFlickable *parent) - : QObject(parent), flickable(parent), m_xPosition(0.), m_widthRatio(0.) - , m_yPosition(0.), m_heightRatio(0.) -{ -} - -qreal QmlGraphicsFlickableVisibleArea::widthRatio() const -{ - return m_widthRatio; -} - -qreal QmlGraphicsFlickableVisibleArea::xPosition() const -{ - return m_xPosition; -} - -qreal QmlGraphicsFlickableVisibleArea::heightRatio() const -{ - return m_heightRatio; -} - -qreal QmlGraphicsFlickableVisibleArea::yPosition() const -{ - return m_yPosition; -} - -void QmlGraphicsFlickableVisibleArea::updateVisible() -{ - QmlGraphicsFlickablePrivate *p = static_cast(QGraphicsItemPrivate::get(flickable)); - bool pageChange = false; - - // Vertical - const qreal viewheight = flickable->height(); - const qreal maxyextent = -flickable->maxYExtent(); - qreal pagePos = -p->_moveY.value() / (maxyextent + viewheight); - qreal pageSize = viewheight / (maxyextent + viewheight); - - if (pageSize != m_heightRatio) { - m_heightRatio = pageSize; - pageChange = true; - } - if (pagePos != m_yPosition) { - m_yPosition = pagePos; - pageChange = true; - } - - // Horizontal - const qreal viewwidth = flickable->width(); - const qreal maxxextent = -flickable->maxXExtent(); - pagePos = -p->_moveX.value() / (maxxextent + viewwidth); - pageSize = viewwidth / (maxxextent + viewwidth); - - if (pageSize != m_widthRatio) { - m_widthRatio = pageSize; - pageChange = true; - } - if (pagePos != m_xPosition) { - m_xPosition = pagePos; - pageChange = true; - } - if (pageChange) - emit pageChanged(); -} - - -QmlGraphicsFlickablePrivate::QmlGraphicsFlickablePrivate() - : viewport(new QmlGraphicsItem), _moveX(viewport, &QmlGraphicsItem::setX), _moveY(viewport, &QmlGraphicsItem::setY) - , vWidth(-1), vHeight(-1), overShoot(true), flicked(false), moving(false), stealMouse(false) - , pressed(false), atXEnd(false), atXBeginning(true), atYEnd(false), atYBeginning(true) - , interactive(true), deceleration(500), maxVelocity(5000), reportedVelocitySmoothing(100) - , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0) - , horizontalVelocity(this), verticalVelocity(this), vTime(0), visibleArea(0) -{ - fixupXEvent = QmlTimeLineEvent::timeLineEvent(&_moveX, this); - fixupYEvent = QmlTimeLineEvent::timeLineEvent(&_moveY, this); -} - -void QmlGraphicsFlickablePrivate::init() -{ - Q_Q(QmlGraphicsFlickable); - viewport->setParent(q); - QObject::connect(&timeline, SIGNAL(updated()), q, SLOT(ticked())); - QObject::connect(&timeline, SIGNAL(completed()), q, SLOT(movementEnding())); - q->setAcceptedMouseButtons(Qt::LeftButton); - q->setFiltersChildEvents(true); - QObject::connect(viewport, SIGNAL(xChanged()), q, SIGNAL(positionXChanged())); - QObject::connect(viewport, SIGNAL(yChanged()), q, SIGNAL(positionYChanged())); - QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(heightChange())); - QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(widthChange())); -} - -void QmlGraphicsFlickablePrivate::flickX(qreal velocity) -{ - Q_Q(QmlGraphicsFlickable); - qreal maxDistance = -1; - if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. - velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; - // -ve velocity means list is moving up - if (velocity > 0) { - if (_moveX.value() < q->minXExtent()) - maxDistance = qAbs(q->minXExtent() -_moveX.value() + (overShoot?30:0)); - flickTargetX = q->minXExtent(); - } else { - if (_moveX.value() > q->maxXExtent()) - maxDistance = qAbs(q->maxXExtent() - _moveX.value()) + (overShoot?30:0); - flickTargetX = q->maxXExtent(); - } - if (maxDistance > 0) { - qreal v = velocity; - if (maxVelocity != -1 && maxVelocity < qAbs(v)) { - if (v < 0) - v = -maxVelocity; - else - v = maxVelocity; - } - timeline.reset(_moveX); - timeline.accel(_moveX, v, deceleration, maxDistance); - timeline.execute(fixupXEvent); - if (!flicked) { - flicked = true; - emit q->flickingChanged(); - emit q->flickStarted(); - } - } else { - timeline.reset(_moveX); - fixupX(); - } -} - -void QmlGraphicsFlickablePrivate::flickY(qreal velocity) -{ - Q_Q(QmlGraphicsFlickable); - qreal maxDistance = -1; - // -ve velocity means list is moving up - if (velocity > 0) { - if (_moveY.value() < q->minYExtent()) - maxDistance = qAbs(q->minYExtent() -_moveY.value() + (overShoot?30:0)); - flickTargetY = q->minYExtent(); - } else { - if (_moveY.value() > q->maxYExtent()) - maxDistance = qAbs(q->maxYExtent() - _moveY.value()) + (overShoot?30:0); - flickTargetY = q->maxYExtent(); - } - if (maxDistance > 0) { - qreal v = velocity; - if (maxVelocity != -1 && maxVelocity < qAbs(v)) { - if (v < 0) - v = -maxVelocity; - else - v = maxVelocity; - } - timeline.reset(_moveY); - timeline.accel(_moveY, v, deceleration, maxDistance); - timeline.execute(fixupYEvent); - if (!flicked) { - flicked = true; - emit q->flickingChanged(); - emit q->flickStarted(); - } - } else { - timeline.reset(_moveY); - fixupY(); - } -} - -void QmlGraphicsFlickablePrivate::fixupX() -{ - Q_Q(QmlGraphicsFlickable); - if (!q->xflick() || _moveX.timeLine()) - return; - - vTime = timeline.time(); - - if (_moveX.value() > q->minXExtent() || (q->maxXExtent() > q->minXExtent())) { - timeline.reset(_moveX); - if (_moveX.value() != q->minXExtent()) - timeline.move(_moveX, q->minXExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); - //emit flickingChanged(); - } else if (_moveX.value() < q->maxXExtent()) { - timeline.reset(_moveX); - timeline.move(_moveX, q->maxXExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); - //emit flickingChanged(); - } else { - flicked = false; - } -} - -void QmlGraphicsFlickablePrivate::fixupY() -{ - Q_Q(QmlGraphicsFlickable); - if (!q->yflick() || _moveY.timeLine()) - return; - - vTime = timeline.time(); - - if (_moveY.value() > q->minYExtent() || (q->maxYExtent() > q->minYExtent())) { - timeline.reset(_moveY); - if (_moveY.value() != q->minYExtent()) - timeline.move(_moveY, q->minYExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); - //emit flickingChanged(); - } else if (_moveY.value() < q->maxYExtent()) { - timeline.reset(_moveY); - timeline.move(_moveY, q->maxYExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); - //emit flickingChanged(); - } else { - flicked = false; - } -} - -void QmlGraphicsFlickablePrivate::updateBeginningEnd() -{ - Q_Q(QmlGraphicsFlickable); - bool atBoundaryChange = false; - - // Vertical - const int maxyextent = int(-q->maxYExtent()); - const qreal ypos = -_moveY.value(); - bool atBeginning = (ypos <= 0.0); - bool atEnd = (maxyextent <= ypos); - - if (atBeginning != atYBeginning) { - atYBeginning = atBeginning; - atBoundaryChange = true; - } - if (atEnd != atYEnd) { - atYEnd = atEnd; - atBoundaryChange = true; - } - - // Horizontal - const int maxxextent = int(-q->maxXExtent()); - const qreal xpos = -_moveX.value(); - atBeginning = (xpos <= 0.0); - atEnd = (maxxextent <= xpos); - - if (atBeginning != atXBeginning) { - atXBeginning = atBeginning; - atBoundaryChange = true; - } - if (atEnd != atXEnd) { - atXEnd = atEnd; - atBoundaryChange = true; - } - - if (atBoundaryChange) - emit q->isAtBoundaryChanged(); - - if (visibleArea) - visibleArea->updateVisible(); -} - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flickable,QmlGraphicsFlickable) - -/*! - \qmlclass Flickable - \brief The Flickable item provides a surface that can be "flicked". - \inherits Item - - Flickable places its children on a surface that can be dragged and flicked. - - \code - Flickable { - width: 200; height: 200; viewportWidth: image.width; viewportHeight: image.height - Image { id: image; source: "bigimage.png" } - } - \endcode - - \image flickable.gif - - \note Flickable does not automatically clip its contents. If - it is not full-screen it is likely that \c clip should be set - to true. - - \note Due to an implementation detail items placed inside a flickable cannot anchor to it by - id, use 'parent' instead. -*/ - -/*! - \internal - \class QmlGraphicsFlickable - \brief The QmlGraphicsFlickable class provides a view that can be "flicked". - - \ingroup group_widgets - - QmlGraphicsFlickable allows its children to be dragged and flicked. - -\code -Flickable { - width: 320; height: 480; viewportWidth: image.width; viewportHeight: image.height - Image { id: image; source: "bigimage.png" } -} -\endcode - - Note that QmlGraphicsFlickable does not automatically clip its contents. If - it is not full-screen it is likely that QmlGraphicsItem::clip should be set - to true. - -*/ - -/*! - \qmlproperty real Flickable::visibleArea.xPosition - \qmlproperty real Flickable::visibleArea.widthRatio - \qmlproperty real Flickable::visibleArea.yPosition - \qmlproperty real Flickable::visibleArea.heightRatio - - These properties describe the position and size of the currently viewed area. - The size is defined as the percentage of the full view currently visible, - scaled to 0.0 - 1.0. The page position is in the range 0.0 (beginning) to - size ratio (end), i.e. yPosition is in the range 0.0 - heightRatio. - - These properties are typically used to draw a scrollbar, for example: - \code - Rectangle { - opacity: 0.5; anchors.right: MyListView.right-2; width: 6 - y: MyListView.visibleArea.yPosition * MyListView.height - height: MyListView.visibleArea.heightRatio * MyListView.height - } - \endcode -*/ - -QmlGraphicsFlickable::QmlGraphicsFlickable(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsFlickablePrivate), parent) -{ - Q_D(QmlGraphicsFlickable); - d->init(); -} - -QmlGraphicsFlickable::QmlGraphicsFlickable(QmlGraphicsFlickablePrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ - Q_D(QmlGraphicsFlickable); - d->init(); -} - -QmlGraphicsFlickable::~QmlGraphicsFlickable() -{ -} - -/*! - \qmlproperty int Flickable::viewportX - \qmlproperty int Flickable::viewportY - - These properties hold the surface coordinate currently at the top-left - corner of the Flickable. For example, if you flick an image up 100 pixels, - \c yPosition will be 100. -*/ -qreal QmlGraphicsFlickable::viewportX() const -{ - Q_D(const QmlGraphicsFlickable); - return -d->_moveX.value(); -} - -void QmlGraphicsFlickable::setViewportX(qreal pos) -{ - Q_D(QmlGraphicsFlickable); - pos = qRound(pos); - d->timeline.reset(d->_moveX); - if (-pos != d->_moveX.value()) { - d->_moveX.setValue(-pos); - viewportMoved(); - } -} - -qreal QmlGraphicsFlickable::viewportY() const -{ - Q_D(const QmlGraphicsFlickable); - return -d->_moveY.value(); -} - -void QmlGraphicsFlickable::setViewportY(qreal pos) -{ - Q_D(QmlGraphicsFlickable); - pos = qRound(pos); - d->timeline.reset(d->_moveY); - if (-pos != d->_moveY.value()) { - d->_moveY.setValue(-pos); - viewportMoved(); - } -} - -/*! - \qmlproperty bool Flickable::interactive - - A user cannot drag or flick a Flickable that is not interactive. - - This property is useful for temporarily disabling flicking. This allows - special interaction with Flickable's children: for example, you might want to - freeze a flickable map while viewing detailed information on a location popup that is a child of the Flickable. -*/ -bool QmlGraphicsFlickable::isInteractive() const -{ - Q_D(const QmlGraphicsFlickable); - return d->interactive; -} - -void QmlGraphicsFlickable::setInteractive(bool interactive) -{ - Q_D(QmlGraphicsFlickable); - d->interactive = interactive; - if (!interactive && d->flicked) { - d->timeline.clear(); - d->flicked = false; - emit flickingChanged(); - emit flickEnded(); - } -} - -/*! - \qmlproperty real Flickable::horizontalVelocity - \qmlproperty real Flickable::verticalVelocity - \qmlproperty real Flickable::reportedVelocitySmoothing - - The instantaneous velocity of movement along the x and y axes, in pixels/sec. - - The reported velocity is smoothed to avoid erratic output. - reportedVelocitySmoothing determines how much smoothing is applied. -*/ -qreal QmlGraphicsFlickable::horizontalVelocity() const -{ - Q_D(const QmlGraphicsFlickable); - return d->horizontalVelocity.value(); -} - -qreal QmlGraphicsFlickable::verticalVelocity() const -{ - Q_D(const QmlGraphicsFlickable); - return d->verticalVelocity.value(); -} - -/*! - \qmlproperty bool Flickable::atXBeginning - \qmlproperty bool Flickable::atXEnd - \qmlproperty bool Flickable::atYBeginning - \qmlproperty bool Flickable::atYEnd - - These properties are true if the flickable view is positioned at the beginning, - or end respecively. -*/ -bool QmlGraphicsFlickable::isAtXEnd() const -{ - Q_D(const QmlGraphicsFlickable); - return d->atXEnd; -} - -bool QmlGraphicsFlickable::isAtXBeginning() const -{ - Q_D(const QmlGraphicsFlickable); - return d->atXBeginning; -} - -bool QmlGraphicsFlickable::isAtYEnd() const -{ - Q_D(const QmlGraphicsFlickable); - return d->atYEnd; -} - -bool QmlGraphicsFlickable::isAtYBeginning() const -{ - Q_D(const QmlGraphicsFlickable); - return d->atYBeginning; -} - -void QmlGraphicsFlickable::ticked() -{ - viewportMoved(); -} - -QmlGraphicsItem *QmlGraphicsFlickable::viewport() -{ - Q_D(QmlGraphicsFlickable); - return d->viewport; -} - -qreal QmlGraphicsFlickable::visibleX() const -{ - Q_D(const QmlGraphicsFlickable); - return -d->_moveX.value(); -} - -qreal QmlGraphicsFlickable::visibleY() const -{ - Q_D(const QmlGraphicsFlickable); - return -d->_moveY.value(); -} - -QmlGraphicsFlickableVisibleArea *QmlGraphicsFlickable::visibleArea() -{ - Q_D(QmlGraphicsFlickable); - if (!d->visibleArea) - d->visibleArea = new QmlGraphicsFlickableVisibleArea(this); - return d->visibleArea; -} - -void QmlGraphicsFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event) -{ - if (interactive && timeline.isActive() && (qAbs(velocityX) > 10 || qAbs(velocityY) > 10)) - stealMouse = true; // If we've been flicked then steal the click. - else - stealMouse = false; - pressed = true; - timeline.clear(); - velocityX = 0; - velocityY = 0; - lastPos = QPoint(); - QmlGraphicsItemPrivate::start(lastPosTime); - pressPos = event->pos(); - pressX = _moveX.value(); - pressY = _moveY.value(); - flicked = false; - QmlGraphicsItemPrivate::start(pressTime); - QmlGraphicsItemPrivate::start(velocityTime); -} - -void QmlGraphicsFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - Q_Q(QmlGraphicsFlickable); - if (!interactive || lastPosTime.isNull()) - return; - bool rejectY = false; - bool rejectX = false; - bool moved = false; - - if (q->yflick()) { - int dy = int(event->pos().y() - pressPos.y()); - if (qAbs(dy) > DragThreshold || QmlGraphicsItemPrivate::elapsed(pressTime) > 200) { - qreal newY = dy + pressY; - const qreal minY = q->minYExtent(); - const qreal maxY = q->maxYExtent(); - if (newY > minY) - newY = minY + (newY - minY) / 2; - if (newY < maxY && maxY - minY < 0) - newY = maxY + (newY - maxY) / 2; - if (!q->overShoot() && (newY > minY || newY < maxY)) { - if (newY > minY) - newY = minY; - else if (newY < maxY) - newY = maxY; - else - rejectY = true; - } - if (!rejectY) { - _moveY.setValue(newY); - moved = true; - } - if (qAbs(dy) > DragThreshold) - stealMouse = true; - } - } - - if (q->xflick()) { - int dx = int(event->pos().x() - pressPos.x()); - if (qAbs(dx) > DragThreshold || QmlGraphicsItemPrivate::elapsed(pressTime) > 200) { - qreal newX = dx + pressX; - const qreal minX = q->minXExtent(); - const qreal maxX = q->maxXExtent(); - if (newX > minX) - newX = minX + (newX - minX) / 2; - if (newX < maxX && maxX - minX < 0) - newX = maxX + (newX - maxX) / 2; - if (!q->overShoot() && (newX > minX || newX < maxX)) { - if (newX > minX) - newX = minX; - else if (newX < maxX) - newX = maxX; - else - rejectX = true; - } - if (!rejectX) { - _moveX.setValue(newX); - moved = true; - } - - if (qAbs(dx) > DragThreshold) - stealMouse = true; - } - } - - if (!lastPos.isNull()) { - qreal elapsed = qreal(QmlGraphicsItemPrivate::restart(lastPosTime)) / 1000.; - if (elapsed <= 0) - elapsed = 1; - if (q->yflick()) { - qreal diff = event->pos().y() - lastPos.y(); - // average to reduce the effect of spurious moves - velocityY += diff / elapsed; - velocityY /= 2; - } - - if (q->xflick()) { - qreal diff = event->pos().x() - lastPos.x(); - // average to reduce the effect of spurious moves - velocityX += diff / elapsed; - velocityX /= 2; - } - } - - if (rejectY) velocityY = 0; - if (rejectX) velocityX = 0; - - if (moved) { - q->movementStarting(); - q->viewportMoved(); - } - - lastPos = event->pos(); -} - -void QmlGraphicsFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_Q(QmlGraphicsFlickable); - pressed = false; - if (lastPosTime.isNull()) - return; - - if (QmlGraphicsItemPrivate::elapsed(lastPosTime) > 100) { - // if we drag then pause before release we should not cause a flick. - velocityX = 0.0; - velocityY = 0.0; - } - - vTime = timeline.time(); - if (qAbs(velocityY) > 10 && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) { - qreal velocity = velocityY; - if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. - velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; - flickY(velocity); - } else { - fixupY(); - } - - if (qAbs(velocityX) > 10 && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) { - qreal velocity = velocityX; - if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. - velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; - flickX(velocity); - } else { - fixupX(); - } - - stealMouse = false; - lastPosTime = QTime(); - - if (!timeline.isActive()) - q->movementEnding(); -} - -void QmlGraphicsFlickable::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsFlickable); - d->handleMousePressEvent(event); - event->accept(); -} - -void QmlGraphicsFlickable::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsFlickable); - d->handleMouseMoveEvent(event); - event->accept(); -} - -void QmlGraphicsFlickable::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsFlickable); - d->clearDelayedPress(); - d->handleMouseReleaseEvent(event); - event->accept(); - ungrabMouse(); -} - -void QmlGraphicsFlickablePrivate::captureDelayedPress(QGraphicsSceneMouseEvent *event) -{ - Q_Q(QmlGraphicsFlickable); - if (!q->scene() || pressDelay <= 0) - return; - delayedPressTarget = q->scene()->mouseGrabberItem(); - delayedPressEvent = new QGraphicsSceneMouseEvent(event->type()); - delayedPressEvent->setAccepted(false); - for (int i = 0x1; i <= 0x10; i <<= 1) { - if (event->buttons() & i) { - Qt::MouseButton button = Qt::MouseButton(i); - delayedPressEvent->setButtonDownPos(button, event->buttonDownPos(button)); - delayedPressEvent->setButtonDownScenePos(button, event->buttonDownScenePos(button)); - delayedPressEvent->setButtonDownScreenPos(button, event->buttonDownScreenPos(button)); - } - } - delayedPressEvent->setButtons(event->buttons()); - delayedPressEvent->setButton(event->button()); - delayedPressEvent->setPos(event->pos()); - delayedPressEvent->setScenePos(event->scenePos()); - delayedPressEvent->setScreenPos(event->screenPos()); - delayedPressEvent->setLastPos(event->lastPos()); - delayedPressEvent->setLastScenePos(event->lastScenePos()); - delayedPressEvent->setLastScreenPos(event->lastScreenPos()); - delayedPressEvent->setModifiers(event->modifiers()); - delayedPressTimer.start(pressDelay, q); -} - -void QmlGraphicsFlickablePrivate::clearDelayedPress() -{ - if (delayedPressEvent) { - delayedPressTimer.stop(); - delete delayedPressEvent; - delayedPressEvent = 0; - } -} - -void QmlGraphicsFlickable::timerEvent(QTimerEvent *event) -{ - Q_D(QmlGraphicsFlickable); - if (event->timerId() == d->delayedPressTimer.timerId()) { - d->delayedPressTimer.stop(); - if (d->delayedPressEvent) { - QmlGraphicsItem *grabber = scene() ? qobject_cast(scene()->mouseGrabberItem()) : 0; - if (!grabber || grabber != this) - scene()->sendEvent(d->delayedPressTarget, d->delayedPressEvent); - delete d->delayedPressEvent; - d->delayedPressEvent = 0; - } - } -} - -qreal QmlGraphicsFlickable::minYExtent() const -{ - return 0.0; -} - -qreal QmlGraphicsFlickable::minXExtent() const -{ - return 0.0; -} - -/* returns -ve */ -qreal QmlGraphicsFlickable::maxXExtent() const -{ - return width() - vWidth(); -} -/* returns -ve */ -qreal QmlGraphicsFlickable::maxYExtent() const -{ - return height() - vHeight(); -} - -void QmlGraphicsFlickable::viewportMoved() -{ - Q_D(QmlGraphicsFlickable); - - int elapsed = QmlGraphicsItemPrivate::elapsed(d->velocityTime); - - if (elapsed) { - qreal prevY = d->lastFlickablePosition.x(); - qreal prevX = d->lastFlickablePosition.y(); - d->velocityTimeline.clear(); - if (d->pressed) { - qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / elapsed; - qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / elapsed; - d->velocityTimeline.move(d->horizontalVelocity, horizontalVelocity, d->reportedVelocitySmoothing); - d->velocityTimeline.move(d->horizontalVelocity, 0, d->reportedVelocitySmoothing); - d->velocityTimeline.move(d->verticalVelocity, verticalVelocity, d->reportedVelocitySmoothing); - d->velocityTimeline.move(d->verticalVelocity, 0, d->reportedVelocitySmoothing); - } else { - if (d->timeline.time() != d->vTime) { - qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / (d->timeline.time() - d->vTime); - qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / (d->timeline.time() - d->vTime); - d->horizontalVelocity.setValue(horizontalVelocity); - d->verticalVelocity.setValue(verticalVelocity); - } - d->vTime = d->timeline.time(); - } - } - - d->lastFlickablePosition = QPointF(d->_moveY.value(), d->_moveX.value()); - QmlGraphicsItemPrivate::restart(d->velocityTime); - d->updateBeginningEnd(); - - if (d->flicked) { - // Near an end and it seems that the extent has changed? - // Recalculate the flick so that we don't end up in an odd position. - if (d->velocityY > 0) { - const qreal minY = minYExtent(); - if (minY - d->_moveY.value() < height()/3 && minY != d->flickTargetY) - d->flickY(-d->verticalVelocity.value()); - } else { - const qreal maxY = maxYExtent(); - if (d->_moveY.value() - maxY < height()/3 && maxY != d->flickTargetY) - d->flickY(-d->verticalVelocity.value()); - } - - if (d->velocityX > 0) { - const qreal minX = minXExtent(); - if (minX - d->_moveX.value() < height()/3 && minX != d->flickTargetX) - d->flickX(-d->horizontalVelocity.value()); - } else { - const qreal maxX = maxXExtent(); - if (d->_moveX.value() - maxX < height()/3 && maxX != d->flickTargetX) - d->flickX(-d->horizontalVelocity.value()); - } - } -} - -void QmlGraphicsFlickable::cancelFlick() -{ - Q_D(QmlGraphicsFlickable); - d->timeline.reset(d->_moveX); - d->timeline.reset(d->_moveY); - movementEnding(); -} - -void QmlGraphicsFlickablePrivate::data_removeAt(int) -{ - // ### -} - -int QmlGraphicsFlickablePrivate::data_count() const -{ - // ### - return 0; -} - -void QmlGraphicsFlickablePrivate::data_append(QObject *o) -{ - Q_Q(QmlGraphicsFlickable); - QmlGraphicsItem *i = qobject_cast(o); - if (i) - viewport->fxChildren()->append(i); - else - o->setParent(q); -} - -void QmlGraphicsFlickablePrivate::data_insert(int, QObject *) -{ - // ### -} - -QObject *QmlGraphicsFlickablePrivate::data_at(int) const -{ - // ### - return 0; -} - -void QmlGraphicsFlickablePrivate::data_clear() -{ - // ### -} - - -QmlList *QmlGraphicsFlickable::flickableData() -{ - Q_D(QmlGraphicsFlickable); - return &d->data; -} - -QmlList *QmlGraphicsFlickable::flickableChildren() -{ - Q_D(QmlGraphicsFlickable); - return d->viewport->fxChildren(); -} - -/*! - \qmlproperty bool Flickable::overShoot - This property holds the number of pixels the surface may overshoot the - Flickable's boundaries when flicked. - - If overShoot is non-zero the contents can be flicked beyond the boundary - of the Flickable before being moved back to the boundary. This provides - the feeling that the edges of the view are soft, rather than a hard - physical boundary. -*/ -bool QmlGraphicsFlickable::overShoot() const -{ - Q_D(const QmlGraphicsFlickable); - return d->overShoot; -} - -void QmlGraphicsFlickable::setOverShoot(bool o) -{ - Q_D(QmlGraphicsFlickable); - d->overShoot = o; -} - -/*! - \qmlproperty int Flickable::viewportWidth - \qmlproperty int Flickable::viewportHeight - - The dimensions of the viewport (the surface controlled by Flickable). Typically this - should be set to the combined size of the items placed in the Flickable. - - \code - Flickable { - width: 320; height: 480; viewportWidth: image.width; viewportHeight: image.height - Image { id: image; source: "bigimage.png" } - } - \endcode -*/ -qreal QmlGraphicsFlickable::viewportWidth() const -{ - Q_D(const QmlGraphicsFlickable); - return d->vWidth; -} - -void QmlGraphicsFlickable::setViewportWidth(qreal w) -{ - Q_D(QmlGraphicsFlickable); - if (d->vWidth == w) - return; - d->vWidth = w; - if (w < 0) - d->viewport->setWidth(width()); - else - d->viewport->setWidth(w); - // Make sure that we're entirely in view. - if (!d->pressed) - d->fixupX(); - emit viewportWidthChanged(); - d->updateBeginningEnd(); -} - -void QmlGraphicsFlickable::widthChange() -{ - Q_D(QmlGraphicsFlickable); - if (d->vWidth < 0) { - d->viewport->setWidth(width()); - emit viewportWidthChanged(); - } - d->updateBeginningEnd(); -} - -void QmlGraphicsFlickable::heightChange() -{ - Q_D(QmlGraphicsFlickable); - if (d->vHeight < 0) { - d->viewport->setHeight(height()); - emit viewportHeightChanged(); - } - d->updateBeginningEnd(); -} - -qreal QmlGraphicsFlickable::viewportHeight() const -{ - Q_D(const QmlGraphicsFlickable); - return d->vHeight; -} - -void QmlGraphicsFlickable::setViewportHeight(qreal h) -{ - Q_D(QmlGraphicsFlickable); - if (d->vHeight == h) - return; - d->vHeight = h; - if (h < 0) - d->viewport->setHeight(height()); - else - d->viewport->setHeight(h); - // Make sure that we're entirely in view. - if (!d->pressed) - d->fixupY(); - emit viewportHeightChanged(); - d->updateBeginningEnd(); -} - -qreal QmlGraphicsFlickable::vWidth() const -{ - Q_D(const QmlGraphicsFlickable); - if (d->vWidth < 0) - return width(); - else - return d->vWidth; -} - -qreal QmlGraphicsFlickable::vHeight() const -{ - Q_D(const QmlGraphicsFlickable); - if (d->vHeight < 0) - return height(); - else - return d->vHeight; -} - -bool QmlGraphicsFlickable::xflick() const -{ - return vWidth() != width(); -} - -bool QmlGraphicsFlickable::yflick() const -{ - return vHeight() != height(); -} - -bool QmlGraphicsFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsFlickable); - QGraphicsSceneMouseEvent mouseEvent(event->type()); - QRectF myRect = mapToScene(QRectF(0, 0, width(), height())).boundingRect(); - - QGraphicsScene *s = scene(); - QmlGraphicsItem *grabber = s ? qobject_cast(s->mouseGrabberItem()) : 0; - if ((d->stealMouse || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) { - mouseEvent.setAccepted(false); - for (int i = 0x1; i <= 0x10; i <<= 1) { - if (event->buttons() & i) { - Qt::MouseButton button = Qt::MouseButton(i); - mouseEvent.setButtonDownPos(button, mapFromScene(event->buttonDownPos(button))); - } - } - mouseEvent.setScenePos(event->scenePos()); - mouseEvent.setLastScenePos(event->lastScenePos()); - mouseEvent.setPos(mapFromScene(event->scenePos())); - mouseEvent.setLastPos(mapFromScene(event->lastScenePos())); - - switch(mouseEvent.type()) { - case QEvent::GraphicsSceneMouseMove: - d->handleMouseMoveEvent(&mouseEvent); - break; - case QEvent::GraphicsSceneMousePress: - if (d->delayedPressEvent) - return false; - - d->handleMousePressEvent(&mouseEvent); - d->captureDelayedPress(event); - break; - case QEvent::GraphicsSceneMouseRelease: - if (d->delayedPressEvent) { - scene()->sendEvent(d->delayedPressTarget, d->delayedPressEvent); - d->clearDelayedPress(); - } - d->handleMouseReleaseEvent(&mouseEvent); - break; - default: - break; - } - grabber = qobject_cast(s->mouseGrabberItem()); - if (grabber && d->stealMouse && !grabber->keepMouseGrab() && grabber != this) { - d->clearDelayedPress(); - grabMouse(); - } - - return d->stealMouse || d->delayedPressEvent; - } else if (!d->lastPosTime.isNull()) { - d->lastPosTime = QTime(); - } - if (mouseEvent.type() == QEvent::GraphicsSceneMouseRelease) - d->clearDelayedPress(); - return false; -} - -bool QmlGraphicsFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e) -{ - if (!isVisible()) - return QmlGraphicsItem::sceneEventFilter(i, e); - switch (e->type()) { - case QEvent::GraphicsSceneMousePress: - case QEvent::GraphicsSceneMouseMove: - case QEvent::GraphicsSceneMouseRelease: - return sendMouseEvent(static_cast(e)); - default: - break; - } - - return QmlGraphicsItem::sceneEventFilter(i, e); -} - -/*! - \qmlproperty real Flickable::maximumFlickVelocity - This property holds the maximum velocity that the user can flick the view in pixels/second. - - The default is 5000 pixels/s -*/ -qreal QmlGraphicsFlickable::maximumFlickVelocity() const -{ - Q_D(const QmlGraphicsFlickable); - return d->maxVelocity; -} - -void QmlGraphicsFlickable::setMaximumFlickVelocity(qreal v) -{ - Q_D(QmlGraphicsFlickable); - if (v == d->maxVelocity) - return; - d->maxVelocity = v; -} - -/*! - \qmlproperty real Flickable::maximumFlickVelocity - This property holds the rate at which a flick will decelerate. - - The default is 500. -*/ -qreal QmlGraphicsFlickable::flickDeceleration() const -{ - Q_D(const QmlGraphicsFlickable); - return d->deceleration; -} - -void QmlGraphicsFlickable::setFlickDeceleration(qreal deceleration) -{ - Q_D(QmlGraphicsFlickable); - d->deceleration = deceleration; -} - -bool QmlGraphicsFlickable::isFlicking() const -{ - Q_D(const QmlGraphicsFlickable); - return d->flicked; -} - -/*! - \qmlproperty int Flickable::pressDelay - - This property holds the time to delay (ms) delivering a press to - children of the Flickable. This can be useful where reacting - to a press before a flicking action has undesireable effects. - - If the flickable is dragged/flicked before the delay times out - the press event will not be delivered. If the button is released - within the timeout, both the press and release will be delivered. -*/ -int QmlGraphicsFlickable::pressDelay() const -{ - Q_D(const QmlGraphicsFlickable); - return d->pressDelay; -} - -void QmlGraphicsFlickable::setPressDelay(int delay) -{ - Q_D(QmlGraphicsFlickable); - if (d->pressDelay == delay) - return; - d->pressDelay = delay; -} - -qreal QmlGraphicsFlickable::reportedVelocitySmoothing() const -{ - Q_D(const QmlGraphicsFlickable); - return d->reportedVelocitySmoothing; -} - -void QmlGraphicsFlickable::setReportedVelocitySmoothing(qreal reportedVelocitySmoothing) -{ - Q_D(QmlGraphicsFlickable); - Q_ASSERT(reportedVelocitySmoothing >= 0); - if (reportedVelocitySmoothing == d->reportedVelocitySmoothing) - return; - d->reportedVelocitySmoothing = reportedVelocitySmoothing; - emit reportedVelocitySmoothingChanged(reportedVelocitySmoothing); -} - -bool QmlGraphicsFlickable::isMoving() const -{ - Q_D(const QmlGraphicsFlickable); - return d->moving; -} - -void QmlGraphicsFlickable::movementStarting() -{ - Q_D(QmlGraphicsFlickable); - if (!d->moving) { - d->moving = true; - emit movingChanged(); - emit movementStarted(); - } -} - -void QmlGraphicsFlickable::movementEnding() -{ - Q_D(QmlGraphicsFlickable); - if (d->moving) { - d->moving = false; - emit movingChanged(); - emit movementEnded(); - } - if (d->flicked) { - d->flicked = false; - emit flickingChanged(); - emit flickEnded(); - } - d->horizontalVelocity.setValue(0); - d->verticalVelocity.setValue(0); -} - -void QmlGraphicsFlickablePrivate::updateVelocity() -{ - Q_Q(QmlGraphicsFlickable); - emit q->horizontalVelocityChanged(); - emit q->verticalVelocityChanged(); -} - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsFlickableVisibleArea) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisibleArea,QmlGraphicsFlickableVisibleArea) - -#include "qfxflickable.moc" diff --git a/src/declarative/fx/qfxflickable.h b/src/declarative/fx/qfxflickable.h deleted file mode 100644 index 634fe88..0000000 --- a/src/declarative/fx/qfxflickable.h +++ /dev/null @@ -1,203 +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 QFXFLICKABLE_H -#define QFXFLICKABLE_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsFlickablePrivate; -class QmlGraphicsFlickableVisibleArea; -class Q_DECLARATIVE_EXPORT QmlGraphicsFlickable : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(qreal viewportWidth READ viewportWidth WRITE setViewportWidth NOTIFY viewportWidthChanged) - Q_PROPERTY(qreal viewportHeight READ viewportHeight WRITE setViewportHeight NOTIFY viewportHeightChanged) - Q_PROPERTY(qreal viewportX READ viewportX WRITE setViewportX NOTIFY positionXChanged) - Q_PROPERTY(qreal viewportY READ viewportY WRITE setViewportY NOTIFY positionYChanged) - - Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged) - Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged) - Q_PROPERTY(qreal reportedVelocitySmoothing READ reportedVelocitySmoothing WRITE setReportedVelocitySmoothing NOTIFY reportedVelocitySmoothingChanged) - - Q_PROPERTY(bool overShoot READ overShoot WRITE setOverShoot) - Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity) - Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration) - Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) - Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) - - Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive) - Q_PROPERTY(int pressDelay READ pressDelay WRITE setPressDelay) - - Q_PROPERTY(bool atXEnd READ isAtXEnd NOTIFY isAtBoundaryChanged) - Q_PROPERTY(bool atYEnd READ isAtYEnd NOTIFY isAtBoundaryChanged) - Q_PROPERTY(bool atXBeginning READ isAtXBeginning NOTIFY isAtBoundaryChanged) - Q_PROPERTY(bool atYBeginning READ isAtYBeginning NOTIFY isAtBoundaryChanged) - - Q_PROPERTY(QmlGraphicsFlickableVisibleArea *visibleArea READ visibleArea CONSTANT) - - Q_PROPERTY(QmlList* flickableData READ flickableData) - Q_PROPERTY(QmlList* flickableChildren READ flickableChildren) - Q_CLASSINFO("DefaultProperty", "flickableData") - -public: - QmlGraphicsFlickable(QmlGraphicsItem *parent=0); - ~QmlGraphicsFlickable(); - - QmlList *flickableData(); - QmlList *flickableChildren(); - - bool overShoot() const; - void setOverShoot(bool); - - qreal viewportWidth() const; - void setViewportWidth(qreal); - - qreal viewportHeight() const; - void setViewportHeight(qreal); - - qreal viewportX() const; - void setViewportX(qreal pos); - - qreal viewportY() const; - void setViewportY(qreal pos); - - bool isMoving() const; - bool isFlicking() const; - - int pressDelay() const; - void setPressDelay(int delay); - - qreal reportedVelocitySmoothing() const; - void setReportedVelocitySmoothing(qreal); - - qreal maximumFlickVelocity() const; - void setMaximumFlickVelocity(qreal); - - qreal flickDeceleration() const; - void setFlickDeceleration(qreal); - - bool isInteractive() const; - void setInteractive(bool); - - qreal horizontalVelocity() const; - qreal verticalVelocity() const; - - bool isAtXEnd() const; - bool isAtXBeginning() const; - bool isAtYEnd() const; - bool isAtYBeginning() const; - - QmlGraphicsItem *viewport(); - -Q_SIGNALS: - void viewportWidthChanged(); - void viewportHeightChanged(); - void positionXChanged(); - void positionYChanged(); - void movingChanged(); - void flickingChanged(); - void movementStarted(); - void movementEnded(); - void flickStarted(); - void flickEnded(); - void reportedVelocitySmoothingChanged(int); - void horizontalVelocityChanged(); - void verticalVelocityChanged(); - void isAtBoundaryChanged(); - void pageChanged(); - -protected: - virtual bool sceneEventFilter(QGraphicsItem *, QEvent *); - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void timerEvent(QTimerEvent *event); - - qreal visibleX() const; - qreal visibleY() const; - - QmlGraphicsFlickableVisibleArea *visibleArea(); - -protected Q_SLOTS: - virtual void ticked(); - void movementStarting(); - void movementEnding(); - void heightChange(); - void widthChange(); - -protected: - virtual qreal minXExtent() const; - virtual qreal minYExtent() const; - virtual qreal maxXExtent() const; - virtual qreal maxYExtent() const; - qreal vWidth() const; - qreal vHeight() const; - virtual void viewportMoved(); - bool sendMouseEvent(QGraphicsSceneMouseEvent *event); - - bool xflick() const; - bool yflick() const; - void cancelFlick(); - -protected: - QmlGraphicsFlickable(QmlGraphicsFlickablePrivate &dd, QmlGraphicsItem *parent); - -private: - Q_DISABLE_COPY(QmlGraphicsFlickable) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsFlickable) - friend class QmlGraphicsFlickableVisibleArea; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsFlickable) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qfxflickable_p.h b/src/declarative/fx/qfxflickable_p.h deleted file mode 100644 index 5e9863f..0000000 --- a/src/declarative/fx/qfxflickable_p.h +++ /dev/null @@ -1,156 +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 QFXFLICKABLE_P_H -#define QFXFLICKABLE_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 "qdatetime.h" -#include "qfxflickable.h" -#include "qfxitem_p.h" -#include "qml.h" -#include "private/qmltimeline_p.h" -#include "private/qmlanimation_p.h" - -QT_BEGIN_NAMESPACE - -class QmlGraphicsFlickableVisibleArea; -class QmlGraphicsFlickablePrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsFlickable) - -public: - QmlGraphicsFlickablePrivate(); - void init(); - virtual void flickX(qreal velocity); - virtual void flickY(qreal velocity); - virtual void fixupX(); - virtual void fixupY(); - void updateBeginningEnd(); - - void captureDelayedPress(QGraphicsSceneMouseEvent *event); - void clearDelayedPress(); - -public: - QmlGraphicsItem *viewport; - QmlTimeLineValueProxy _moveX; - QmlTimeLineValueProxy _moveY; - QmlTimeLine timeline; - qreal vWidth; - qreal vHeight; - bool overShoot : 1; - bool flicked : 1; - bool moving : 1; - bool stealMouse : 1; - bool pressed : 1; - bool atXEnd : 1; - bool atXBeginning : 1; - bool atYEnd : 1; - bool atYBeginning : 1; - bool interactive : 1; - QTime lastPosTime; - QPointF lastPos; - QPointF pressPos; - qreal pressX; - qreal pressY; - qreal velocityX; - qreal velocityY; - QTime pressTime; - QmlTimeLineEvent fixupXEvent; - QmlTimeLineEvent fixupYEvent; - qreal deceleration; - qreal maxVelocity; - QTime velocityTime; - QPointF lastFlickablePosition; - qreal reportedVelocitySmoothing; - int flickTargetX; - int flickTargetY; - QGraphicsSceneMouseEvent *delayedPressEvent; - QGraphicsItem *delayedPressTarget; - QBasicTimer delayedPressTimer; - int pressDelay; - - void updateVelocity(); - struct Velocity : public QmlTimeLineValue - { - Velocity(QmlGraphicsFlickablePrivate *p) - : parent(p) {} - virtual void setValue(qreal v) { - QmlTimeLineValue::setValue(v); - parent->updateVelocity(); - } - QmlGraphicsFlickablePrivate *parent; - }; - Velocity horizontalVelocity; - Velocity verticalVelocity; - int vTime; - QmlTimeLine velocityTimeline; - QmlGraphicsFlickableVisibleArea *visibleArea; - - void handleMousePressEvent(QGraphicsSceneMouseEvent *); - void handleMouseMoveEvent(QGraphicsSceneMouseEvent *); - void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *); - - // flickableData property - void data_removeAt(int); - int data_count() const; - void data_append(QObject *); - void data_insert(int, QObject *); - QObject *data_at(int) const; - void data_clear(); - - friend class QmlGraphicsFlickableVisibleArea; - QML_DECLARE_LIST_PROXY(QmlGraphicsFlickablePrivate, QObject *, data) -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/declarative/fx/qfxflipable.cpp b/src/declarative/fx/qfxflipable.cpp deleted file mode 100644 index 090f8a0..0000000 --- a/src/declarative/fx/qfxflipable.cpp +++ /dev/null @@ -1,236 +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 "qfxflipable.h" -#include "private/qfxitem_p.h" -#include "QtGui/qgraphicstransform.h" -#include - -QT_BEGIN_NAMESPACE - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flipable,QmlGraphicsFlipable) - -class QmlGraphicsFlipablePrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsFlipable) -public: - QmlGraphicsFlipablePrivate() : current(QmlGraphicsFlipable::Front), front(0), back(0) {} - - void updateSceneTransformFromParent(); - - QmlGraphicsFlipable::Side current; - QmlGraphicsItem *front; - QmlGraphicsItem *back; -}; - -/*! - \qmlclass Flipable QmlGraphicsFlipable - \brief The Flipable item provides a surface that can be flipped. - \inherits Item - - Flipable allows you to specify a front and a back and then flip between those sides. - - \qml - Flipable { - id: flipable - width: 40 - height: 40 - axis: Axis { - startX: 20 - startY: 0 - endX: 20 - endY: 40 - } - front: Image { source: "front.png" } - back: Image { source: "back.png" } - states: [ - State { - name: "back" - SetProperty { - target: flipable - property: "rotation" - value: 180 - } - } - ] - transitions: [ - Transition { - NumberAnimation { - easing: "easeInOutQuad" - properties: "rotation" - } - } - ] -} - \endqml - - \image flipable.gif -*/ - -/*! - \internal - \class QmlGraphicsFlipable - \brief The QmlGraphicsFlipable class provides a flipable surface. - - \ingroup group_widgets - - QmlGraphicsFlipable allows you to specify a front and a back, as well as an - axis for the flip. -*/ - -QmlGraphicsFlipable::QmlGraphicsFlipable(QmlGraphicsItem *parent) -: QmlGraphicsItem(*(new QmlGraphicsFlipablePrivate), parent) -{ -} - -QmlGraphicsFlipable::~QmlGraphicsFlipable() -{ -} - -/*! - \qmlproperty Item Flipable::front - \qmlproperty Item Flipable::back - - The front and back sides of the flipable. -*/ - -QmlGraphicsItem *QmlGraphicsFlipable::front() -{ - Q_D(const QmlGraphicsFlipable); - return d->front; -} - -void QmlGraphicsFlipable::setFront(QmlGraphicsItem *front) -{ - Q_D(QmlGraphicsFlipable); - if (d->front) { - qmlInfo(tr("front is a write-once property"),this); - return; - } - d->front = front; - fxChildren()->append(d->front); - if (Back == d->current) - d->front->setOpacity(0.); -} - -QmlGraphicsItem *QmlGraphicsFlipable::back() -{ - Q_D(const QmlGraphicsFlipable); - return d->back; -} - -void QmlGraphicsFlipable::setBack(QmlGraphicsItem *back) -{ - Q_D(QmlGraphicsFlipable); - if (d->back) { - qmlInfo(tr("back is a write-once property"),this); - return; - } - d->back = back; - fxChildren()->append(d->back); - if (Front == d->current) - d->back->setOpacity(0.); -} - -/*! - \qmlproperty enumeration Flipable::side - - The side of the Flippable currently visible. Possible values are \c - Front and \c Back. -*/ -QmlGraphicsFlipable::Side QmlGraphicsFlipable::side() const -{ - Q_D(const QmlGraphicsFlipable); - if (d->dirtySceneTransform) - const_cast(d)->updateSceneTransformFromParent(); - - return d->current; -} - -// determination on the currently visible side of the flipable -// has to be done on the complete scene transform to give -// correct results. -void QmlGraphicsFlipablePrivate::updateSceneTransformFromParent() -{ - Q_Q(QmlGraphicsFlipable); - - QmlGraphicsItemPrivate::updateSceneTransformFromParent(); - QPointF p1(0, 0); - QPointF p2(1, 0); - QPointF p3(1, 1); - - p1 = sceneTransform.map(p1); - p2 = sceneTransform.map(p2); - p3 = sceneTransform.map(p3); - - qreal cross = (p1.x() - p2.x()) * (p3.y() - p2.y()) - - (p1.y() - p2.y()) * (p3.x() - p2.x()); - - QmlGraphicsFlipable::Side newSide; - if (cross > 0) { - newSide = QmlGraphicsFlipable::Back; - } else { - newSide = QmlGraphicsFlipable::Front; - } - - if (newSide != current) { - current = newSide; - if (current == QmlGraphicsFlipable::Back) { - QTransform mat; - mat.translate(back->width()/2,back->height()/2); - if (back->width() && p1.x() >= p2.x()) - mat.rotate(180, Qt::YAxis); - if (back->height() && p2.y() >= p3.y()) - mat.rotate(180, Qt::XAxis); - mat.translate(-back->width()/2,-back->height()/2); - back->setTransform(mat); - } - if (front) - front->setOpacity((current==QmlGraphicsFlipable::Front)?1.:0.); - if (back) - back->setOpacity((current==QmlGraphicsFlipable::Back)?1.:0.); - emit q->sideChanged(); - } -} - -QT_END_NAMESPACE - -#include "moc_qfxflipable.cpp" diff --git a/src/declarative/fx/qfxflipable.h b/src/declarative/fx/qfxflipable.h deleted file mode 100644 index 1b10d48..0000000 --- a/src/declarative/fx/qfxflipable.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 QFXFLIPABLE_H -#define QFXFLIPABLE_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsFlipablePrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsFlipable : public QmlGraphicsItem -{ - Q_OBJECT - - Q_ENUMS(Side) - Q_PROPERTY(QmlGraphicsItem *front READ front WRITE setFront) - Q_PROPERTY(QmlGraphicsItem *back READ back WRITE setBack) - Q_PROPERTY(Side side READ side NOTIFY sideChanged) - //### flipAxis - //### flipRotation -public: - QmlGraphicsFlipable(QmlGraphicsItem *parent=0); - ~QmlGraphicsFlipable(); - - QmlGraphicsItem *front(); - void setFront(QmlGraphicsItem *); - - QmlGraphicsItem *back(); - void setBack(QmlGraphicsItem *); - - enum Side { Front, Back }; - Side side() const; - -Q_SIGNALS: - void sideChanged(); - -private: - Q_DISABLE_COPY(QmlGraphicsFlipable) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsFlipable) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsFlipable) - -QT_END_HEADER - -#endif // QFXFLIPABLE_H diff --git a/src/declarative/fx/qfxfocuspanel.cpp b/src/declarative/fx/qfxfocuspanel.cpp deleted file mode 100644 index 3d246a0..0000000 --- a/src/declarative/fx/qfxfocuspanel.cpp +++ /dev/null @@ -1,89 +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 "qfxfocuspanel.h" -#include -#include - -QT_BEGIN_NAMESPACE - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FocusPanel,QmlGraphicsFocusPanel) - -/*! - \qmlclass FocusPanel - \brief The FocusPanel item explicitly creates a focus panel. - \inherits Item - - Focus panels assist in keyboard focus handling when building QML - applications. All the details are covered in the - \l {qmlfocus}{keyboard focus documentation}. -*/ - -/*! - \internal - \class QmlGraphicsFocusPanel -*/ - -QmlGraphicsFocusPanel::QmlGraphicsFocusPanel(QmlGraphicsItem *parent) : - QmlGraphicsItem(parent) -{ - setFlag(ItemIsPanel); -} - -QmlGraphicsFocusPanel::~QmlGraphicsFocusPanel() -{ -} - -/*! - \qmlproperty bool FocusPanel::active - - Sets whether the item is the active focus panel. -*/ - -bool QmlGraphicsFocusPanel::sceneEvent(QEvent *event) -{ - if (event->type() == QEvent::WindowActivate || - event->type() == QEvent::WindowDeactivate) - emit activeChanged(); - return QmlGraphicsItem::sceneEvent(event); -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxfocuspanel.h b/src/declarative/fx/qfxfocuspanel.h deleted file mode 100644 index 43eb96e..0000000 --- a/src/declarative/fx/qfxfocuspanel.h +++ /dev/null @@ -1,77 +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 QFXFOCUSPANEL_H -#define QFXFOCUSPANEL_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QmlGraphicsFocusPanel : public QmlGraphicsItem -{ - Q_OBJECT - Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) -public: - QmlGraphicsFocusPanel(QmlGraphicsItem *parent=0); - virtual ~QmlGraphicsFocusPanel(); - -Q_SIGNALS: - void activeChanged(); - -protected: - bool sceneEvent(QEvent *event); - -private: - Q_DISABLE_COPY(QmlGraphicsFocusPanel) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsFocusPanel) - -QT_END_HEADER - -#endif // QFXFOCUSPANEL_H diff --git a/src/declarative/fx/qfxfocusscope.cpp b/src/declarative/fx/qfxfocusscope.cpp deleted file mode 100644 index 468d532..0000000 --- a/src/declarative/fx/qfxfocusscope.cpp +++ /dev/null @@ -1,72 +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 "qfxfocusscope.h" - - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FocusScope,QmlGraphicsFocusScope) - -/*! - \qmlclass FocusScope - \brief The FocusScope object explicitly creates a focus scope. - \inherits Item - - Focus scopes assist in keyboard focus handling when building reusable QML - components. All the details are covered in the - \l {qmlfocus}{keyboard focus documentation}. -*/ - -/*! - \internal - \class QmlGraphicsFocusScope -*/ - -QmlGraphicsFocusScope::QmlGraphicsFocusScope(QmlGraphicsItem *parent) : - QmlGraphicsItem(parent) -{ - setFlag(QGraphicsItem::ItemIsFocusScope); -} - -QmlGraphicsFocusScope::~QmlGraphicsFocusScope() -{ -} -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxfocusscope.h b/src/declarative/fx/qfxfocusscope.h deleted file mode 100644 index 126ccfc..0000000 --- a/src/declarative/fx/qfxfocusscope.h +++ /dev/null @@ -1,68 +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 QFXFOCUSSCOPE_H -#define QFXFOCUSSCOPE_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -//### set component root as focusscope -class Q_DECLARATIVE_EXPORT QmlGraphicsFocusScope : public QmlGraphicsItem -{ - Q_OBJECT -public: - QmlGraphicsFocusScope(QmlGraphicsItem *parent=0); - virtual ~QmlGraphicsFocusScope(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsFocusScope) - -QT_END_HEADER - -#endif // QFXFOCUSSCOPE_H diff --git a/src/declarative/fx/qfxgraphicsobjectcontainer.cpp b/src/declarative/fx/qfxgraphicsobjectcontainer.cpp deleted file mode 100644 index 0c9dc69..0000000 --- a/src/declarative/fx/qfxgraphicsobjectcontainer.cpp +++ /dev/null @@ -1,230 +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 "qfxgraphicsobjectcontainer.h" -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QmlGraphicsGraphicsObjectContainerPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsGraphicsObjectContainer) - -public: - QmlGraphicsGraphicsObjectContainerPrivate() : QmlGraphicsItemPrivate(), graphicsObject(0), syncedResize(false) - { } - - void _q_updateSize(); - - void setFiltering(bool on) - { - Q_Q(QmlGraphicsGraphicsObjectContainer); - if (graphicsObject && graphicsObject->isWidget()) { - if (!on) { - graphicsObject->removeEventFilter(q); - QObject::disconnect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); - QObject::disconnect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); - } else { - graphicsObject->installEventFilter(q); - QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); - QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); - } - } - } - - - QGraphicsObject *graphicsObject; - bool syncedResize; -}; - - -/*! - \qmlclass GraphicsObjectContainer QmlGraphicsGraphicsObjectContainer - \brief The GraphicsObjectContainer element allows you to add QGraphicsObjects into Fluid UI elements. -*/ - -/*! - \internal - \class QmlGraphicsGraphicsObjectContainer - \brief The QmlGraphicsGraphicsObjectContainer class allows you to add QGraphicsObjects into Fluid UI applications. -*/ - -QML_DEFINE_NOCREATE_TYPE(QGraphicsObject) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GraphicsObjectContainer,QmlGraphicsGraphicsObjectContainer) - -QmlGraphicsGraphicsObjectContainer::QmlGraphicsGraphicsObjectContainer(QmlGraphicsItem *parent) -: QmlGraphicsItem(*new QmlGraphicsGraphicsObjectContainerPrivate, parent) -{ -} - -QmlGraphicsGraphicsObjectContainer::~QmlGraphicsGraphicsObjectContainer() -{ -} - -QGraphicsObject *QmlGraphicsGraphicsObjectContainer::graphicsObject() const -{ - Q_D(const QmlGraphicsGraphicsObjectContainer); - return d->graphicsObject; -} - -/*! - \qmlproperty QGraphicsObject GraphicsObjectContainer::graphicsObject - The QGraphicsObject associated with this element. -*/ -void QmlGraphicsGraphicsObjectContainer::setGraphicsObject(QGraphicsObject *object) -{ - Q_D(QmlGraphicsGraphicsObjectContainer); - if (object == d->graphicsObject) - return; - - //### remove previously set item? - - d->setFiltering(false); - - d->graphicsObject = object; - - if (d->graphicsObject) { - d->graphicsObject->setParentItem(this); - - if (d->syncedResize && d->graphicsObject->isWidget()) { - QGraphicsWidget *gw = static_cast(d->graphicsObject); - QSizeF gwSize = gw->size(); //### should we use sizeHint? - QSizeF newSize = gwSize; - if (heightValid()) - newSize.setHeight(height()); - if (widthValid()) - newSize.setWidth(width()); - if (gwSize != newSize) - gw->resize(newSize); - - gwSize = gw->size(); - setImplicitWidth(gwSize.width()); - setImplicitHeight(gwSize.height()); - - d->setFiltering(true); - } - } -} - -QVariant QmlGraphicsGraphicsObjectContainer::itemChange(GraphicsItemChange change, const QVariant &value) -{ - Q_D(QmlGraphicsGraphicsObjectContainer); - if (change == ItemSceneHasChanged) { - QGraphicsObject *o = d->graphicsObject; - d->graphicsObject = 0; - setGraphicsObject(o); - } - return QmlGraphicsItem::itemChange(change, value); -} - -bool QmlGraphicsGraphicsObjectContainer::eventFilter(QObject *watched, QEvent *e) -{ - Q_D(QmlGraphicsGraphicsObjectContainer); - if (watched == d->graphicsObject && e->type() == QEvent::GraphicsSceneResize) { - if (d->graphicsObject && d->graphicsObject->isWidget() && d->syncedResize) { - QSizeF newSize = static_cast(d->graphicsObject)->size(); - setImplicitWidth(newSize.width()); - setImplicitHeight(newSize.height()); - } - } - return QmlGraphicsItem::eventFilter(watched, e); -} - -/*! - \qmlproperty bool GraphicsObjectContainer::synchronizedResizing - - This property determines whether or not the container and graphics object will synchronize their - sizes. - - \note This property only applies when wrapping a QGraphicsWidget. - - If synchronizedResizing is enabled, the container and widget will - synchronize their sizes as follows. - \list - \o If a size has been set on the container, the widget will be resized to the container. - Any changes in the container's size will be reflected in the widget. - - \o \e Otherwise, the container will initially be sized to the preferred size of the widget. - Any changes to the container's size will be reflected in the widget, and any changes to the - widget's size will be reflected in the container. - \endlist -*/ -bool QmlGraphicsGraphicsObjectContainer::synchronizedResizing() const -{ - Q_D(const QmlGraphicsGraphicsObjectContainer); - return d->syncedResize; -} - -void QmlGraphicsGraphicsObjectContainer::setSynchronizedResizing(bool on) -{ - Q_D(QmlGraphicsGraphicsObjectContainer); - if (on == d->syncedResize) - return; - - d->syncedResize = on; - d->setFiltering(on); -} - -void QmlGraphicsGraphicsObjectContainerPrivate::_q_updateSize() -{ - if (!graphicsObject || !graphicsObject->isWidget() || !syncedResize) - return; - - QGraphicsWidget *gw = static_cast(graphicsObject); - const QSizeF newSize(width, height); - gw->resize(newSize); - - //### will respecting the widgets min/max ever get us in trouble? (all other items always - // size to exactly what you tell them) - /*QSizeF constrainedSize = newSize.expandedTo(gw->minimumSize()).boundedTo(gw->maximumSize()); - gw->resize(constrainedSize); - if (constrainedSize != newSize) { - setImplicitWidth(constrainedSize.width()); - setImplicitHeight(constrainedSize.height()); - }*/ -} - -QT_END_NAMESPACE - -#include "moc_qfxgraphicsobjectcontainer.cpp" diff --git a/src/declarative/fx/qfxgraphicsobjectcontainer.h b/src/declarative/fx/qfxgraphicsobjectcontainer.h deleted file mode 100644 index 2ed5c1f..0000000 --- a/src/declarative/fx/qfxgraphicsobjectcontainer.h +++ /dev/null @@ -1,90 +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 QFXGRAPHICSOBJECTCONTAINER_H -#define QFXGRAPHICSOBJECTCONTAINER_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QGraphicsObject; -class QmlGraphicsGraphicsObjectContainerPrivate; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGraphicsObjectContainer : public QmlGraphicsItem -{ - Q_OBJECT - - Q_CLASSINFO("DefaultProperty", "graphicsObject") - Q_PROPERTY(QGraphicsObject *graphicsObject READ graphicsObject WRITE setGraphicsObject) - Q_PROPERTY(bool synchronizedResizing READ synchronizedResizing WRITE setSynchronizedResizing) - -public: - QmlGraphicsGraphicsObjectContainer(QmlGraphicsItem *parent = 0); - ~QmlGraphicsGraphicsObjectContainer(); - - QGraphicsObject *graphicsObject() const; - void setGraphicsObject(QGraphicsObject *); - - bool synchronizedResizing() const; - void setSynchronizedResizing(bool on); - -protected: - QVariant itemChange(GraphicsItemChange change, const QVariant &value); - bool eventFilter(QObject *watched, QEvent *e); - -private: - Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsGraphicsObjectContainer) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QGraphicsObject) -QML_DECLARE_TYPE(QmlGraphicsGraphicsObjectContainer) - -QT_END_HEADER - -#endif // QFXGRAPHICSOBJECTCONTAINER_H diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp deleted file mode 100644 index 5ed82d7..0000000 --- a/src/declarative/fx/qfxgridview.cpp +++ /dev/null @@ -1,1585 +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 "qfxvisualitemmodel.h" -#include "qlistmodelinterface.h" -#include "qmleasefollow.h" -#include "private/qfxflickable_p.h" -#include "qfxgridview.h" - -#include - -QT_BEGIN_NAMESPACE - -class QmlGraphicsGridViewAttached : public QObject -{ - Q_OBJECT -public: - QmlGraphicsGridViewAttached(QObject *parent) - : QObject(parent), m_isCurrent(false), m_delayRemove(false) {} - ~QmlGraphicsGridViewAttached() { - attachedProperties.remove(parent()); - } - - Q_PROPERTY(QmlGraphicsGridView *view READ view CONSTANT) - QmlGraphicsGridView *view() { return m_view; } - - Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) - bool isCurrentItem() const { return m_isCurrent; } - void setIsCurrentItem(bool c) { - if (m_isCurrent != c) { - m_isCurrent = c; - emit currentItemChanged(); - } - } - - Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged) - bool delayRemove() const { return m_delayRemove; } - void setDelayRemove(bool delay) { - if (m_delayRemove != delay) { - m_delayRemove = delay; - emit delayRemoveChanged(); - } - } - - static QmlGraphicsGridViewAttached *properties(QObject *obj) { - QmlGraphicsGridViewAttached *rv = attachedProperties.value(obj); - if (!rv) { - rv = new QmlGraphicsGridViewAttached(obj); - attachedProperties.insert(obj, rv); - } - return rv; - } - - void emitAdd() { emit add(); } - void emitRemove() { emit remove(); } - -Q_SIGNALS: - void currentItemChanged(); - void delayRemoveChanged(); - void add(); - void remove(); - -public: - QmlGraphicsGridView *m_view; - bool m_isCurrent; - bool m_delayRemove; - - static QHash attachedProperties; -}; - -QHash QmlGraphicsGridViewAttached::attachedProperties; - - -//---------------------------------------------------------------------------- - -class FxGridItem -{ -public: - FxGridItem(QmlGraphicsItem *i, QmlGraphicsGridView *v) : item(i), view(v) { - attached = QmlGraphicsGridViewAttached::properties(item); - attached->m_view = view; - } - ~FxGridItem() {} - - qreal rowPos() const { return (view->flow() == QmlGraphicsGridView::LeftToRight ? item->y() : item->x()); } - qreal colPos() const { return (view->flow() == QmlGraphicsGridView::LeftToRight ? item->x() : item->y()); } - qreal endRowPos() const { - return view->flow() == QmlGraphicsGridView::LeftToRight - ? item->y() + view->cellHeight() - 1 - : item->x() + view->cellWidth() - 1; - } - void setPosition(qreal col, qreal row) { - if (view->flow() == QmlGraphicsGridView::LeftToRight) { - item->setPos(QPointF(col, row)); - } else { - item->setPos(QPointF(row, col)); - } - } - - QmlGraphicsItem *item; - QmlGraphicsGridView *view; - QmlGraphicsGridViewAttached *attached; - int index; -}; - -//---------------------------------------------------------------------------- - -class QmlGraphicsGridViewPrivate : public QmlGraphicsFlickablePrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsGridView) - -public: - QmlGraphicsGridViewPrivate() - : model(0), currentItem(0), flow(QmlGraphicsGridView::LeftToRight) - , visiblePos(0), visibleIndex(0) , currentIndex(-1) - , cellWidth(100), cellHeight(100), columns(1), requestedIndex(-1) - , highlightComponent(0), highlight(0), trackedItem(0) - , moveReason(Other), buffer(0), highlightXAnimator(0), highlightYAnimator(0) - , ownModel(false), wrap(false), autoHighlight(true) - , fixCurrentVisibility(false) {} - - void init(); - void clear(); - FxGridItem *createItem(int modelIndex); - void releaseItem(FxGridItem *item); - void refill(qreal from, qreal to); - - void updateGrid(); - void layout(bool removed=false); - void updateUnrequestedIndexes(); - void updateUnrequestedPositions(); - void updateTrackedItem(); - void createHighlight(); - void updateHighlight(); - void updateCurrent(int modelIndex); - - FxGridItem *visibleItem(int modelIndex) const { - if (modelIndex >= visibleIndex && modelIndex < visibleIndex + visibleItems.count()) { - for (int i = modelIndex - visibleIndex; i < visibleItems.count(); ++i) { - FxGridItem *item = visibleItems.at(i); - if (item->index == modelIndex) - return item; - } - } - return 0; - } - - qreal position() const { - Q_Q(const QmlGraphicsGridView); - return flow == QmlGraphicsGridView::LeftToRight ? q->viewportY() : q->viewportX(); - } - void setPosition(qreal pos) { - Q_Q(QmlGraphicsGridView); - if (flow == QmlGraphicsGridView::LeftToRight) - q->setViewportY(pos); - else - q->setViewportX(pos); - } - int size() const { - Q_Q(const QmlGraphicsGridView); - return flow == QmlGraphicsGridView::LeftToRight ? q->height() : q->width(); - } - qreal startPosition() const { - qreal pos = 0; - if (!visibleItems.isEmpty()) - pos = visibleItems.first()->rowPos() - visibleIndex / columns * rowSize(); - return pos; - } - - qreal endPosition() const { - qreal pos = 0; - if (model && model->count()) - pos = rowPosAt(model->count() - 1) + rowSize(); - return pos; - } - - bool isValid() const { - return model && model->count() && model->isValid(); - } - - int rowSize() const { - return flow == QmlGraphicsGridView::LeftToRight ? cellHeight : cellWidth; - } - int colSize() const { - return flow == QmlGraphicsGridView::LeftToRight ? cellWidth : cellHeight; - } - - qreal colPosAt(int modelIndex) const { - if (FxGridItem *item = visibleItem(modelIndex)) - return item->colPos(); - if (!visibleItems.isEmpty()) { - if (modelIndex < visibleIndex) { - int count = (visibleIndex - modelIndex) % columns; - int col = visibleItems.first()->colPos() / colSize(); - col = (columns - count + col) % columns; - return col * colSize(); - } else { - int count = columns - 1 - (modelIndex - visibleItems.last()->index - 1) % columns; - return visibleItems.last()->colPos() - count * colSize(); - } - } else { - return (modelIndex % columns) * colSize(); - } - return 0; - } - qreal rowPosAt(int modelIndex) const { - if (FxGridItem *item = visibleItem(modelIndex)) - return item->rowPos(); - if (!visibleItems.isEmpty()) { - if (modelIndex < visibleIndex) { - int firstCol = visibleItems.first()->colPos() / colSize(); - int col = visibleIndex - modelIndex + (columns - firstCol - 1); - int rows = col / columns; - return visibleItems.first()->rowPos() - rows * rowSize(); - } else { - int count = modelIndex - visibleItems.last()->index; - int col = visibleItems.last()->colPos() + count * colSize(); - int rows = col / (columns * colSize()); - return visibleItems.last()->rowPos() + rows * rowSize(); - } - } else { - return (modelIndex / columns) * rowSize(); - } - return 0; - } - - // Map a model index to visibleItems list index. - // These may differ if removed items are still present in the visible list, - // e.g. doing a removal animation - int mapFromModel(int modelIndex) const { - if (modelIndex < visibleIndex || modelIndex >= visibleIndex + visibleItems.count()) - return -1; - for (int i = 0; i < visibleItems.count(); ++i) { - FxGridItem *listItem = visibleItems.at(i); - if (listItem->index == modelIndex) - return i + visibleIndex; - if (listItem->index > modelIndex) - return -1; - } - return -1; // Not in visibleList - } - - // for debugging only - void checkVisible() const { - int skip = 0; - for (int i = 0; i < visibleItems.count(); ++i) { - FxGridItem *listItem = visibleItems.at(i); - if (listItem->index == -1) { - ++skip; - } else if (listItem->index != visibleIndex + i - skip) { - for (int j = 0; j < visibleItems.count(); j++) - qDebug() << " index" << j << "item index" << visibleItems.at(j)->index; - qFatal("index %d %d %d", visibleIndex, i, listItem->index); - } - } - } - - QmlGraphicsVisualModel *model; - QVariant modelVariant; - QList visibleItems; - QHash unrequestedItems; - FxGridItem *currentItem; - QmlGraphicsGridView::Flow flow; - int visiblePos; - int visibleIndex; - int currentIndex; - int cellWidth; - int cellHeight; - int columns; - int requestedIndex; - QmlComponent *highlightComponent; - FxGridItem *highlight; - FxGridItem *trackedItem; - enum MovementReason { Other, Key, Mouse }; - MovementReason moveReason; - int buffer; - QmlEaseFollow *highlightXAnimator; - QmlEaseFollow *highlightYAnimator; - - int ownModel : 1; - int wrap : 1; - int autoHighlight : 1; - int fixCurrentVisibility : 1; -}; - -void QmlGraphicsGridViewPrivate::init() -{ - Q_Q(QmlGraphicsGridView); - q->setFlag(QGraphicsItem::ItemIsFocusScope); - QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(sizeChange())); - QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(sizeChange())); -} - -void QmlGraphicsGridViewPrivate::clear() -{ - for (int i = 0; i < visibleItems.count(); ++i) - releaseItem(visibleItems.at(i)); - visibleItems.clear(); - visiblePos = 0; - visibleIndex = 0; - releaseItem(currentItem); - currentItem = 0; - currentIndex = -1; - createHighlight(); - trackedItem = 0; -} - -FxGridItem *QmlGraphicsGridViewPrivate::createItem(int modelIndex) -{ - Q_Q(QmlGraphicsGridView); - // create object - requestedIndex = modelIndex; - FxGridItem *listItem = 0; - if (QmlGraphicsItem *item = model->item(modelIndex, false)) { - listItem = new FxGridItem(item, q); - listItem->index = modelIndex; - // complete - model->completeItem(); - listItem->item->setZValue(modelIndex + 1); - listItem->item->setParent(q->viewport()); - } - requestedIndex = 0; - return listItem; -} - - -void QmlGraphicsGridViewPrivate::releaseItem(FxGridItem *item) -{ - Q_Q(QmlGraphicsGridView); - if (!item) - return; - if (trackedItem == item) { - QObject::disconnect(trackedItem->item, SIGNAL(yChanged()), q, SLOT(trackedPositionChanged())); - QObject::disconnect(trackedItem->item, SIGNAL(xChanged()), q, SLOT(trackedPositionChanged())); - trackedItem = 0; - } - if (model->release(item->item) == 0) { - // item was not destroyed, and we no longer reference it. - unrequestedItems.insert(item->item, model->indexOf(item->item, q)); - } - delete item; -} - -void QmlGraphicsGridViewPrivate::refill(qreal from, qreal to) -{ - Q_Q(QmlGraphicsGridView); - if (!isValid() || !q->isComponentComplete()) - return; - - from -= buffer; - to += buffer; - bool changed = false; - - int colPos = 0; - int rowPos = 0; - int modelIndex = 0; - if (visibleItems.count()) { - rowPos = visibleItems.last()->rowPos(); - colPos = visibleItems.last()->colPos() + colSize(); - if (colPos > colSize() * (columns-1)) { - colPos = 0; - rowPos += rowSize(); - } - int i = visibleItems.count() - 1; - while (i > 0 && visibleItems.at(i)->index == -1) - --i; - modelIndex = visibleItems.at(i)->index + 1; - } - - FxGridItem *item = 0; - while (modelIndex < model->count() && rowPos <= to) { - //qDebug() << "refill: append item" << modelIndex; - if (!(item = createItem(modelIndex))) - break; - item->setPosition(colPos, rowPos); - visibleItems.append(item); - colPos += colSize(); - if (colPos > colSize() * (columns-1)) { - colPos = 0; - rowPos += rowSize(); - } - ++modelIndex; - changed = true; - } - - if (visibleItems.count()) { - rowPos = visibleItems.first()->rowPos(); - colPos = visibleItems.first()->colPos() - colSize(); - if (colPos < 0) { - colPos = colSize() * (columns - 1); - rowPos -= rowSize(); - } - } - while (visibleIndex > 0 && rowPos + rowSize() - 1 >= from){ - //qDebug() << "refill: prepend item" << visibleIndex-1 << "top pos" << rowPos << colPos; - if (!(item = createItem(visibleIndex-1))) - break; - --visibleIndex; - item->setPosition(colPos, rowPos); - visibleItems.prepend(item); - colPos -= colSize(); - if (colPos < 0) { - colPos = colSize() * (columns - 1); - rowPos -= rowSize(); - } - changed = true; - } - - while (visibleItems.count() > 1 && (item = visibleItems.first()) && item->endRowPos() < from) { - if (item->attached->delayRemove()) - break; - //qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endRowPos(); - if (item->index != -1) - visibleIndex++; - visibleItems.removeFirst(); - releaseItem(item); - changed = true; - } - while (visibleItems.count() > 1 && (item = visibleItems.last()) && item->rowPos() > to) { - if (item->attached->delayRemove()) - break; - //qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1; - visibleItems.removeLast(); - releaseItem(item); - changed = true; - } - if (changed) { - if (flow == QmlGraphicsGridView::LeftToRight) - q->setViewportHeight(endPosition() - startPosition()); - else - q->setViewportWidth(endPosition() - startPosition()); - } -} - -void QmlGraphicsGridViewPrivate::updateGrid() -{ - Q_Q(QmlGraphicsGridView); - columns = (int)qMax((flow == QmlGraphicsGridView::LeftToRight ? q->width() : q->height()) / colSize(), qreal(1.)); - if (isValid()) { - if (flow == QmlGraphicsGridView::LeftToRight) - q->setViewportHeight(endPosition() - startPosition()); - else - q->setViewportWidth(endPosition() - startPosition()); - } -} - -void QmlGraphicsGridViewPrivate::layout(bool removed) -{ - Q_Q(QmlGraphicsGridView); - if (visibleItems.count()) { - qreal rowPos = visibleItems.first()->rowPos(); - qreal colPos = visibleItems.first()->colPos(); - if (visibleIndex % columns != 0) { - if (removed) - rowPos -= rowSize(); - colPos = (visibleIndex % columns) * colSize(); - visibleItems.first()->setPosition(colPos, rowPos); - } else if (colPos != 0) { - colPos = 0; - visibleItems.first()->setPosition(colPos, rowPos); - } - for (int i = 1; i < visibleItems.count(); ++i) { - FxGridItem *item = visibleItems.at(i); - colPos += colSize(); - if (colPos > colSize() * (columns-1)) { - colPos = 0; - rowPos += rowSize(); - } - item->setPosition(colPos, rowPos); - } - } - q->refill(); - q->trackedPositionChanged(); - updateHighlight(); - if (flow == QmlGraphicsGridView::LeftToRight) { - q->setViewportHeight(endPosition() - startPosition()); - fixupY(); - } else { - q->setViewportWidth(endPosition() - startPosition()); - fixupX(); - } - updateUnrequestedPositions(); -} - -void QmlGraphicsGridViewPrivate::updateUnrequestedIndexes() -{ - Q_Q(QmlGraphicsGridView); - QHash::iterator it; - for (it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) - *it = model->indexOf(it.key(), q); -} - -void QmlGraphicsGridViewPrivate::updateUnrequestedPositions() -{ - QHash::const_iterator it; - for (it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) { - if (flow == QmlGraphicsGridView::LeftToRight) { - it.key()->setPos(QPointF(colPosAt(*it), rowPosAt(*it))); - } else { - it.key()->setPos(QPointF(rowPosAt(*it), colPosAt(*it))); - } - } -} - -void QmlGraphicsGridViewPrivate::updateTrackedItem() -{ - Q_Q(QmlGraphicsGridView); - FxGridItem *item = currentItem; - if (highlight) - item = highlight; - - if (trackedItem && item != trackedItem) { - QObject::disconnect(trackedItem->item, SIGNAL(yChanged()), q, SLOT(trackedPositionChanged())); - QObject::disconnect(trackedItem->item, SIGNAL(xChanged()), q, SLOT(trackedPositionChanged())); - trackedItem = 0; - } - - if (!trackedItem && item) { - trackedItem = item; - QObject::connect(trackedItem->item, SIGNAL(yChanged()), q, SLOT(trackedPositionChanged())); - QObject::connect(trackedItem->item, SIGNAL(xChanged()), q, SLOT(trackedPositionChanged())); - q->trackedPositionChanged(); - } - if (trackedItem) - q->trackedPositionChanged(); -} - -void QmlGraphicsGridViewPrivate::createHighlight() -{ - Q_Q(QmlGraphicsGridView); - if (highlight) { - if (trackedItem == highlight) - trackedItem = 0; - delete highlight->item; - delete highlight; - highlight = 0; - delete highlightXAnimator; - delete highlightYAnimator; - highlightXAnimator = 0; - highlightYAnimator = 0; - } - - if (!highlightComponent) - return; - - if (currentItem) { - QmlContext *highlightContext = new QmlContext(qmlContext(q)); - QObject *nobj = highlightComponent->create(highlightContext); - if (nobj) { - highlightContext->setParent(nobj); - QmlGraphicsItem *item = qobject_cast(nobj); - if (item) { - item->setParent(q->viewport()); - highlight = new FxGridItem(item, q); - highlightXAnimator = new QmlEaseFollow(q); - highlightXAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("x"))); - highlightXAnimator->setDuration(150); - highlightXAnimator->setEnabled(autoHighlight); - highlightYAnimator = new QmlEaseFollow(q); - highlightYAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("y"))); - highlightYAnimator->setDuration(150); - highlightYAnimator->setEnabled(autoHighlight); - } else { - delete highlightContext; - } - } - } -} - -void QmlGraphicsGridViewPrivate::updateHighlight() -{ - if ((!currentItem && highlight) || (currentItem && !highlight)) - createHighlight(); - updateTrackedItem(); - if (currentItem && autoHighlight && highlight) { - // auto-update highlight - highlightXAnimator->setSourceValue(currentItem->item->x()); - highlightYAnimator->setSourceValue(currentItem->item->y()); - highlight->item->setWidth(currentItem->item->width()); - highlight->item->setHeight(currentItem->item->height()); - } -} - -void QmlGraphicsGridViewPrivate::updateCurrent(int modelIndex) -{ - Q_Q(QmlGraphicsGridView); - if (!isValid() || modelIndex < 0 || modelIndex >= model->count()) { - if (currentItem) { - currentItem->attached->setIsCurrentItem(false); - releaseItem(currentItem); - currentItem = 0; - currentIndex = -1; - updateHighlight(); - emit q->currentIndexChanged(); - } - return; - } - - if (currentItem && currentIndex == modelIndex) { - updateHighlight(); - return; - } - - FxGridItem *oldCurrentItem = currentItem; - currentIndex = modelIndex; - currentItem = createItem(modelIndex); - fixCurrentVisibility = true; - if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item)) - oldCurrentItem->attached->setIsCurrentItem(false); - if (currentItem) { - currentItem->setPosition(colPosAt(modelIndex), rowPosAt(modelIndex)); - currentItem->item->setFocus(true); - currentItem->attached->setIsCurrentItem(true); - } - updateHighlight(); - emit q->currentIndexChanged(); - releaseItem(oldCurrentItem); -} - -//---------------------------------------------------------------------------- - -/*! - \qmlclass GridView - \inherits Flickable - \brief The GridView item provides a grid view of items provided by a model. - - The model is typically provided by a QAbstractListModel "C++ model object", - but can also be created directly in QML. - - The items are laid out top to bottom (vertically) or left to right (horizontally) - and may be flicked to scroll. - - The below example creates a very simple grid, using a QML model. - - \image gridview.png - - \snippet doc/src/snippets/declarative/gridview/gridview.qml 3 - - The model is defined as a ListModel using QML: - \quotefile doc/src/snippets/declarative/gridview/dummydata/ContactModel.qml - - In this case ListModel is a handy way for us to test our UI. In practice - the model would be implemented in C++, or perhaps via a SQL data source. -*/ -QmlGraphicsGridView::QmlGraphicsGridView(QmlGraphicsItem *parent) - : QmlGraphicsFlickable(*(new QmlGraphicsGridViewPrivate), parent) -{ - Q_D(QmlGraphicsGridView); - d->init(); -} - -QmlGraphicsGridView::~QmlGraphicsGridView() -{ - Q_D(QmlGraphicsGridView); - d->clear(); - if (d->ownModel) - delete d->model; -} - -/*! - \qmlattachedproperty bool GridView::isCurrentItem - This attched property is true if this delegate is the current item; otherwise false. - - It is attached to each instance of the delegate. -*/ - -/*! - \qmlattachedproperty GridView GridView::view - This attached property holds the view that manages this delegate instance. - - It is attached to each instance of the delegate. -*/ - -/*! - \qmlattachedproperty bool GridView::delayRemove - This attached property holds whether the delegate may be destroyed. - - It is attached to each instance of the delegate. - - It is sometimes necessary to delay the destruction of an item - until an animation completes. - - The example below ensures that the animation completes before - the item is removed from the grid. - - \code - Component { - id: myDelegate - Item { - id: wrapper - GridView.onRemove: SequentialAnimation { - PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: true } - NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" } - PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: false } - } - } - } - \endcode -*/ - -/*! - \qmlattachedsignal GridView::onAdd() - This attached handler is called immediately after an item is added to the view. -*/ - -/*! - \qmlattachedsignal GridView::onRemove() - This attached handler is called immediately before an item is removed from the view. -*/ - - -/*! - \qmlproperty model GridView::model - This property holds the model providing data for the grid. - - The model provides a set of data that is used to create the items - for the view. For large or dynamic datasets the model is usually - provided by a C++ model object. The C++ model object must be a \l - {QAbstractItemModel} subclass, a VisualModel, or a simple list. - - \sa {qmlmodels}{Data Models} -*/ -QVariant QmlGraphicsGridView::model() const -{ - Q_D(const QmlGraphicsGridView); - return d->modelVariant; -} - -void QmlGraphicsGridView::setModel(const QVariant &model) -{ - Q_D(QmlGraphicsGridView); - if (d->model) { - disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); - disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); - disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); - disconnect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); - disconnect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); - } - d->clear(); - d->modelVariant = model; - QObject *object = qvariant_cast(model); - QmlGraphicsVisualModel *vim = 0; - if (object && (vim = qobject_cast(object))) { - if (d->ownModel) { - delete d->model; - d->ownModel = false; - } - d->model = vim; - } else { - if (!d->ownModel) { - d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); - d->ownModel = true; - } - if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) - dataModel->setModel(model); - } - if (d->model) { - if (d->currentIndex >= d->model->count() || d->currentIndex < 0) - setCurrentIndex(0); - else - d->updateCurrent(d->currentIndex); - connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); - connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); - connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); - connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); - connect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); - refill(); - emit countChanged(); - } -} - -/*! - \qmlproperty component GridView::delegate - - The delegate provides a template describing what each item in the view should look and act like. - - Here is an example delegate: - \snippet doc/src/snippets/declarative/gridview/gridview.qml 0 -*/ -QmlComponent *QmlGraphicsGridView::delegate() const -{ - Q_D(const QmlGraphicsGridView); - if (d->model) { - if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) - return dataModel->delegate(); - } - - return 0; -} - -void QmlGraphicsGridView::setDelegate(QmlComponent *delegate) -{ - Q_D(QmlGraphicsGridView); - if (!d->ownModel) { - d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); - d->ownModel = true; - } - if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) { - dataModel->setDelegate(delegate); - d->updateCurrent(d->currentIndex); - refill(); - } -} - -/*! - \qmlproperty int GridView::currentIndex - \qmlproperty Item GridView::currentItem - - \c currentIndex holds the index of the current item. - \c currentItem is the current item. Note that the position of the current item - may only be approximate until it becomes visible in the view. -*/ -int QmlGraphicsGridView::currentIndex() const -{ - Q_D(const QmlGraphicsGridView); - return d->currentIndex; -} - -void QmlGraphicsGridView::setCurrentIndex(int index) -{ - Q_D(QmlGraphicsGridView); - if (d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) { - cancelFlick(); - d->updateCurrent(index); - } else { - d->currentIndex = index; - } -} - -QmlGraphicsItem *QmlGraphicsGridView::currentItem() -{ - Q_D(QmlGraphicsGridView); - if (!d->currentItem) - return 0; - return d->currentItem->item; -} - -/*! - \qmlproperty int GridView::count - This property holds the number of items in the view. -*/ -int QmlGraphicsGridView::count() const -{ - Q_D(const QmlGraphicsGridView); - if (d->model) - return d->model->count(); - return 0; -} - -/*! - \qmlproperty component GridView::highlight - This property holds the component to use as the highlight. - - An instance of the highlight component will be created for each view. - The geometry of the resultant component instance will be managed by the view - so as to stay with the current item, unless the highlightFollowsCurrentItem property is false. - - The below example demonstrates how to make a simple highlight: - \snippet doc/src/snippets/declarative/gridview/gridview.qml 1 - - \sa highlightFollowsCurrentItem -*/ -QmlComponent *QmlGraphicsGridView::highlight() const -{ - Q_D(const QmlGraphicsGridView); - return d->highlightComponent; -} - -void QmlGraphicsGridView::setHighlight(QmlComponent *highlight) -{ - Q_D(QmlGraphicsGridView); - delete d->highlightComponent; - d->highlightComponent = highlight; - d->updateCurrent(d->currentIndex); -} - -/*! - \qmlproperty bool GridView::highlightFollowsCurrentItem - This property sets whether the highlight is managed by the view. - - If highlightFollowsCurrentItem is true, the highlight will be moved smoothly - to follow the current item. If highlightFollowsCurrentItem is false, the - highlight will not be moved by the view, and must be implemented - by the highlight component, for example: - - \code - Component { - id: myHighlight - Rectangle { - id: wrapper; color: "lightsteelblue"; radius: 4; width: 320; height: 60 > - y: SpringFollow { source: Wrapper.GridView.view.currentItem.y; spring: 3; damping: 0.2 } - x: SpringFollow { source: Wrapper.GridView.view.currentItem.x; spring: 3; damping: 0.2 } - } - } - \endcode -*/ -bool QmlGraphicsGridView::highlightFollowsCurrentItem() const -{ - Q_D(const QmlGraphicsGridView); - return d->autoHighlight; -} - -void QmlGraphicsGridView::setHighlightFollowsCurrentItem(bool autoHighlight) -{ - Q_D(QmlGraphicsGridView); - d->autoHighlight = autoHighlight; - if (d->highlightXAnimator) { - d->highlightXAnimator->setEnabled(d->autoHighlight); - d->highlightYAnimator->setEnabled(d->autoHighlight); - } - d->updateHighlight(); -} - -/*! - \qmlproperty enumeration GridView::flow - This property holds the flow of the grid. - - Possible values are \c LeftToRight (default) and \c TopToBottom. - - If \a flow is \c LeftToRight, the view will scroll vertically. - If \a flow is \c TopToBottom, the view will scroll horizontally. -*/ -QmlGraphicsGridView::Flow QmlGraphicsGridView::flow() const -{ - Q_D(const QmlGraphicsGridView); - return d->flow; -} - -void QmlGraphicsGridView::setFlow(Flow flow) -{ - Q_D(QmlGraphicsGridView); - if (d->flow != flow) { - d->flow = flow; - if (d->flow == LeftToRight) - setViewportWidth(-1); - else - setViewportHeight(-1); - d->clear(); - d->updateGrid(); - refill(); - d->updateCurrent(d->currentIndex); - } -} - -/*! - \qmlproperty bool GridView::keyNavigationWraps - This property holds whether the grid wraps key navigation - - If this property is true then key presses to move off of one end of the grid will cause the - selection to jump to the other side. -*/ -bool QmlGraphicsGridView::isWrapEnabled() const -{ - Q_D(const QmlGraphicsGridView); - return d->wrap; -} - -void QmlGraphicsGridView::setWrapEnabled(bool wrap) -{ - Q_D(QmlGraphicsGridView); - d->wrap = wrap; -} - -/*! - \qmlproperty int GridView::cacheBuffer - This property holds the number of off-screen pixels to cache. - - This property determines the number of pixels above the top of the view - and below the bottom of the view to cache. Setting this value can make - scrolling the view smoother at the expense of additional memory usage. -*/ -int QmlGraphicsGridView::cacheBuffer() const -{ - Q_D(const QmlGraphicsGridView); - return d->buffer; -} - -void QmlGraphicsGridView::setCacheBuffer(int buffer) -{ - Q_D(QmlGraphicsGridView); - if (d->buffer != buffer) { - d->buffer = buffer; - if (isComponentComplete()) - refill(); - } -} - -/*! - \qmlproperty int GridView::cellWidth - \qmlproperty int GridView::cellHeight - - These properties holds the width and height of each cell in the grid - - The default sell size is 100x100. -*/ -int QmlGraphicsGridView::cellWidth() const -{ - Q_D(const QmlGraphicsGridView); - return d->cellWidth; -} - -void QmlGraphicsGridView::setCellWidth(int cellWidth) -{ - Q_D(QmlGraphicsGridView); - if (cellWidth != d->cellWidth && cellWidth > 0) { - d->cellWidth = qMax(1, cellWidth); - d->updateGrid(); - emit cellWidthChanged(); - d->layout(); - } -} - -int QmlGraphicsGridView::cellHeight() const -{ - Q_D(const QmlGraphicsGridView); - return d->cellHeight; -} - -void QmlGraphicsGridView::setCellHeight(int cellHeight) -{ - Q_D(QmlGraphicsGridView); - if (cellHeight != d->cellHeight && cellHeight > 0) { - d->cellHeight = qMax(1, cellHeight); - d->updateGrid(); - emit cellHeightChanged(); - d->layout(); - } -} - -void QmlGraphicsGridView::sizeChange() -{ - Q_D(QmlGraphicsGridView); - if (isComponentComplete()) { - d->updateGrid(); - d->layout(); - } -} - -void QmlGraphicsGridView::viewportMoved() -{ - QmlGraphicsFlickable::viewportMoved(); - refill(); -} - -qreal QmlGraphicsGridView::minYExtent() const -{ - Q_D(const QmlGraphicsGridView); - if (d->flow == QmlGraphicsGridView::TopToBottom) - return QmlGraphicsFlickable::minYExtent(); - return -d->startPosition(); -} - -qreal QmlGraphicsGridView::maxYExtent() const -{ - Q_D(const QmlGraphicsGridView); - if (d->flow == QmlGraphicsGridView::TopToBottom) - return QmlGraphicsFlickable::maxYExtent(); - return -(d->endPosition() - height()); -} - -qreal QmlGraphicsGridView::minXExtent() const -{ - Q_D(const QmlGraphicsGridView); - if (d->flow == QmlGraphicsGridView::LeftToRight) - return QmlGraphicsFlickable::minXExtent(); - return -d->startPosition(); -} - -qreal QmlGraphicsGridView::maxXExtent() const -{ - Q_D(const QmlGraphicsGridView); - if (d->flow == QmlGraphicsGridView::LeftToRight) - return QmlGraphicsFlickable::maxXExtent(); - return -(d->endPosition() - width()); -} - -void QmlGraphicsGridView::keyPressEvent(QKeyEvent *event) -{ - Q_D(QmlGraphicsGridView); - QmlGraphicsFlickable::keyPressEvent(event); - if (event->isAccepted()) - return; - - if (d->model && d->model->count() && d->interactive) { - d->moveReason = QmlGraphicsGridViewPrivate::Key; - int oldCurrent = currentIndex(); - switch (event->key()) { - case Qt::Key_Up: - moveCurrentIndexUp(); - break; - case Qt::Key_Down: - moveCurrentIndexDown(); - break; - case Qt::Key_Left: - moveCurrentIndexLeft(); - break; - case Qt::Key_Right: - moveCurrentIndexRight(); - break; - default: - break; - } - if (oldCurrent != currentIndex()) { - event->accept(); - return; - } - } - d->moveReason = QmlGraphicsGridViewPrivate::Other; - event->ignore(); -} - -/*! - \qmlmethod GridView::moveCurrentIndexUp - - Move the currentIndex up one item in the view. - The current index will wrap if keyNavigationWraps is true and it - is currently at the end. -*/ -void QmlGraphicsGridView::moveCurrentIndexUp() -{ - Q_D(QmlGraphicsGridView); - if (d->flow == QmlGraphicsGridView::LeftToRight) { - if (currentIndex() >= d->columns || d->wrap) { - int index = currentIndex() - d->columns; - setCurrentIndex(index >= 0 ? index : d->model->count()-1); - } - } else { - if (currentIndex() > 0 || d->wrap) { - int index = currentIndex() - 1; - setCurrentIndex(index >= 0 ? index : d->model->count()-1); - } - } -} - -/*! - \qmlmethod GridView::moveCurrentIndexDown - - Move the currentIndex down one item in the view. - The current index will wrap if keyNavigationWraps is true and it - is currently at the end. -*/ -void QmlGraphicsGridView::moveCurrentIndexDown() -{ - Q_D(QmlGraphicsGridView); - if (d->flow == QmlGraphicsGridView::LeftToRight) { - if (currentIndex() < d->model->count() - d->columns || d->wrap) { - int index = currentIndex()+d->columns; - setCurrentIndex(index < d->model->count() ? index : 0); - } - } else { - if (currentIndex() < d->model->count() - 1 || d->wrap) { - int index = currentIndex() + 1; - setCurrentIndex(index < d->model->count() ? index : 0); - } - } -} - -/*! - \qmlmethod GridView::moveCurrentIndexLeft - - Move the currentIndex left one item in the view. - The current index will wrap if keyNavigationWraps is true and it - is currently at the end. -*/ -void QmlGraphicsGridView::moveCurrentIndexLeft() -{ - Q_D(QmlGraphicsGridView); - if (d->flow == QmlGraphicsGridView::LeftToRight) { - if (currentIndex() > 0 || d->wrap) { - int index = currentIndex() - 1; - setCurrentIndex(index >= 0 ? index : d->model->count()-1); - } - } else { - if (currentIndex() >= d->columns || d->wrap) { - int index = currentIndex() - d->columns; - setCurrentIndex(index >= 0 ? index : d->model->count()-1); - } - } -} - -/*! - \qmlmethod GridView::moveCurrentIndexRight - - Move the currentIndex right one item in the view. - The current index will wrap if keyNavigationWraps is true and it - is currently at the end. -*/ -void QmlGraphicsGridView::moveCurrentIndexRight() -{ - Q_D(QmlGraphicsGridView); - if (d->flow == QmlGraphicsGridView::LeftToRight) { - if (currentIndex() < d->model->count() - 1 || d->wrap) { - int index = currentIndex() + 1; - setCurrentIndex(index < d->model->count() ? index : 0); - } - } else { - if (currentIndex() < d->model->count() - d->columns || d->wrap) { - int index = currentIndex()+d->columns; - setCurrentIndex(index < d->model->count() ? index : 0); - } - } -} - -void QmlGraphicsGridView::componentComplete() -{ - Q_D(QmlGraphicsGridView); - QmlGraphicsFlickable::componentComplete(); - d->updateGrid(); - if (d->currentIndex < 0) - d->updateCurrent(0); - refill(); -} - -void QmlGraphicsGridView::trackedPositionChanged() -{ - Q_D(QmlGraphicsGridView); - if (!d->trackedItem) - return; - if (!isFlicking() && !d->pressed && d->moveReason == QmlGraphicsGridViewPrivate::Key) { - if (d->trackedItem->rowPos() < d->position()) { - d->setPosition(d->trackedItem->rowPos()); - } else if (d->trackedItem->endRowPos() > d->position() + d->size()) { - qreal pos = d->trackedItem->endRowPos() - d->size(); - if (d->rowSize() > d->size()) - pos = d->trackedItem->rowPos(); - d->setPosition(pos); - } - } -} - -void QmlGraphicsGridView::itemsInserted(int modelIndex, int count) -{ - Q_D(QmlGraphicsGridView); - if (!d->visibleItems.count() || d->model->count() <= 1) { - refill(); - d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); - emit countChanged(); - return; - } - - int index = d->mapFromModel(modelIndex); - if (index == -1) { - int i = d->visibleItems.count() - 1; - while (i > 0 && d->visibleItems.at(i)->index == -1) - --i; - if (d->visibleItems.at(i)->index + 1 == modelIndex) { - // Special case of appending an item to the model. - index = d->visibleIndex + d->visibleItems.count(); - } else { - if (modelIndex + count - 1 < d->visibleIndex) { - // Insert before visible items - d->visibleIndex += count; - for (int i = 0; i < d->visibleItems.count(); ++i) { - FxGridItem *listItem = d->visibleItems.at(i); - if (listItem->index != -1) - listItem->index += count; - } - } - if (d->currentIndex >= modelIndex) { - // adjust current item index - d->currentIndex += count; - if (d->currentItem) - d->currentItem->index = d->currentIndex; - } - d->layout(); - emit countChanged(); - return; - } - } - - // At least some of the added items will be visible - int insertCount = count; - if (index < d->visibleIndex) { - insertCount -= d->visibleIndex - index; - index = d->visibleIndex; - modelIndex = d->visibleIndex; - } - - index -= d->visibleIndex; - int to = d->buffer+d->position()+d->size()-1; - int colPos, rowPos; - if (index < d->visibleItems.count()) { - colPos = d->visibleItems.at(index)->colPos(); - rowPos = d->visibleItems.at(index)->rowPos(); - } else { - // appending items to visible list - colPos = d->visibleItems.at(index-1)->colPos() + d->colSize(); - rowPos = d->visibleItems.at(index-1)->rowPos(); - if (colPos > d->colSize() * (d->columns-1)) { - colPos = 0; - rowPos += d->rowSize(); - } - } - - QList added; - int i = 0; - for (; i < insertCount && rowPos + d->rowSize() - 1 <= to; ++i) { - int mod = (modelIndex+i) % d->columns; - while (mod++ < d->columns && modelIndex + i < d->model->count() && i < insertCount) { - FxGridItem *item = d->createItem(modelIndex + i); - d->visibleItems.insert(index, item); - item->setPosition(colPos, rowPos); - added.append(item); - colPos += d->colSize(); - if (colPos > d->colSize() * (d->columns-1)) { - colPos = 0; - rowPos += d->rowSize(); - } - ++index; - ++i; - } - } - - if (d->currentIndex >= modelIndex) { - // adjust current item index - d->currentIndex += count; - if (d->currentItem) { - d->currentItem->index = d->currentIndex; - d->currentItem->setPosition(d->colPosAt(d->currentIndex), d->rowPosAt(d->currentIndex)); - } - } - if (i < insertCount) { - // We didn't insert all our new items, which means anything - // beyond the current index is not visible - remove it. - while (d->visibleItems.count() > index) - d->releaseItem(d->visibleItems.takeLast()); - } else { - // Update the indexes of the following visible items. - for (; index < d->visibleItems.count(); ++index) { - FxGridItem *listItem = d->visibleItems.at(index); - if (listItem->index != -1) - listItem->index += count; - } - } - // everything is in order now - emit add() signal - for (int j = 0; j < added.count(); ++j) - added.at(j)->attached->emitAdd(); - d->layout(); - emit countChanged(); -} - -void QmlGraphicsGridView::itemsRemoved(int modelIndex, int count) -{ - Q_D(QmlGraphicsGridView); - bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; - int index = d->mapFromModel(modelIndex); - if (index == -1) { - if (modelIndex + count - 1 < d->visibleIndex) { - // Items removed before our visible items. - d->visibleIndex -= count; - for (int i = 0; i < d->visibleItems.count(); ++i) { - FxGridItem *listItem = d->visibleItems.at(i); - if (listItem->index != -1) - listItem->index -= count; - } - } - if (d->currentIndex >= modelIndex + count) { - d->currentIndex -= count; - if (d->currentItem) - d->currentItem->index -= count; - } else if (currentRemoved) { - // current item has been removed. - d->releaseItem(d->currentItem); - d->currentItem = 0; - d->currentIndex = -1; - d->updateCurrent(qMin(modelIndex, d->model->count()-1)); - } - d->layout(true); - emit countChanged(); - return; - } - - // Remove the items from the visible list, skipping anything already marked for removal - QList::Iterator it = d->visibleItems.begin(); - while (it != d->visibleItems.end()) { - FxGridItem *item = *it; - if (item->index == -1 || item->index < modelIndex) { - // already removed, or before removed items - ++it; - } else if (item->index >= modelIndex + count) { - // after removed items - item->index -= count; - ++it; - } else { - // removed item - item->attached->emitRemove(); - if (item->attached->delayRemove()) { - item->index = -1; - connect(item->attached, SIGNAL(delayRemoveChanged()), this, SLOT(destroyRemoved()), Qt::QueuedConnection); - ++it; - } else { - it = d->visibleItems.erase(it); - d->releaseItem(item); - } - } - } - - // fix current - if (d->currentIndex >= modelIndex + count) { - d->currentIndex -= count; - if (d->currentItem) - d->currentItem->index -= count; - } else if (currentRemoved) { - // current item has been removed. - d->releaseItem(d->currentItem); - d->currentItem = 0; - d->currentIndex = -1; - d->updateCurrent(qMin(modelIndex, d->model->count()-1)); - } - - // update visibleIndex - for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { - if ((*it)->index != -1) { - d->visibleIndex = (*it)->index; - break; - } - } - - if (d->visibleItems.isEmpty()) { - d->visibleIndex = 0; - d->setPosition(0); - refill(); - } else { - // Correct the positioning of the items - d->layout(); - } - emit countChanged(); -} - -void QmlGraphicsGridView::destroyRemoved() -{ - Q_D(QmlGraphicsGridView); - for (QList::Iterator it = d->visibleItems.begin(); - it != d->visibleItems.end();) { - FxGridItem *listItem = *it; - if (listItem->index == -1 && listItem->attached->delayRemove() == false) { - d->releaseItem(listItem); - it = d->visibleItems.erase(it); - } else { - ++it; - } - } - - // Correct the positioning of the items - d->layout(); -} - -void QmlGraphicsGridView::itemsMoved(int from, int to, int count) -{ - Q_D(QmlGraphicsGridView); - QHash moved; - - QList::Iterator it = d->visibleItems.begin(); - while (it != d->visibleItems.end()) { - FxGridItem *item = *it; - if (item->index >= from && item->index < from + count) { - // take the items that are moving - item->index += (to-from); - moved.insert(item->index, item); - it = d->visibleItems.erase(it); - } else { - if (item->index > from && item->index != -1) { - // move everything after the moved items. - item->index -= count; - } - ++it; - } - } - - int remaining = count; - int endIndex = d->visibleIndex; - it = d->visibleItems.begin(); - while (it != d->visibleItems.end()) { - FxGridItem *item = *it; - if (remaining && item->index >= to && item->index < to + count) { - // place items in the target position, reusing any existing items - FxGridItem *movedItem = moved.take(item->index); - if (!movedItem) - movedItem = d->createItem(item->index); - it = d->visibleItems.insert(it, movedItem); - ++it; - --remaining; - } else { - if (item->index != -1) { - if (item->index >= to) { - // update everything after the moved items. - item->index += count; - } - endIndex = item->index; - } - ++it; - } - } - - // If we have moved items to the end of the visible items - // then add any existing moved items that we have - while (FxGridItem *item = moved.take(endIndex+1)) { - d->visibleItems.append(item); - ++endIndex; - } - - // Whatever moved items remain are no longer visible items. - while (moved.count()) - d->releaseItem(moved.take(moved.begin().key())); - - d->layout(); -} - -void QmlGraphicsGridView::createdItem(int index, QmlGraphicsItem *item) -{ - Q_D(QmlGraphicsGridView); - item->setParentItem(this); - if (d->requestedIndex != index) { - item->setParentItem(this); - d->unrequestedItems.insert(item, index); - if (d->flow == QmlGraphicsGridView::LeftToRight) { - item->setPos(QPointF(d->colPosAt(index), d->rowPosAt(index))); - } else { - item->setPos(QPointF(d->rowPosAt(index), d->colPosAt(index))); - } - } -} - -void QmlGraphicsGridView::destroyingItem(QmlGraphicsItem *item) -{ - Q_D(QmlGraphicsGridView); - d->unrequestedItems.remove(item); -} - - -void QmlGraphicsGridView::refill() -{ - Q_D(QmlGraphicsGridView); - d->refill(d->position(), d->position()+d->size()-1); -} - - -QmlGraphicsGridViewAttached *QmlGraphicsGridView::qmlAttachedProperties(QObject *obj) -{ - return QmlGraphicsGridViewAttached::properties(obj); -} - -QML_DEFINE_TYPE(Qt, 4,6, (QT_VERSION&0x00ff00)>>8, GridView, QmlGraphicsGridView) - -QT_END_NAMESPACE - -#include "qfxgridview.moc" diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h deleted file mode 100644 index fd0a459..0000000 --- a/src/declarative/fx/qfxgridview.h +++ /dev/null @@ -1,157 +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 QFXGRIDVIEW_H -#define QFXGRIDVIEW_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlGraphicsVisualModel; -class QmlGraphicsGridViewAttached; -class QmlGraphicsGridViewPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsGridView : public QmlGraphicsFlickable -{ - Q_OBJECT - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsGridView) - - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) - Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) - Q_PROPERTY(Flow flow READ flow WRITE setFlow) - Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) - Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) - Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged) - Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged) - Q_CLASSINFO("DefaultProperty", "data") - -public: - QmlGraphicsGridView(QmlGraphicsItem *parent=0); - ~QmlGraphicsGridView(); - - QVariant model() const; - void setModel(const QVariant &); - - QmlComponent *delegate() const; - void setDelegate(QmlComponent *); - - int currentIndex() const; - void setCurrentIndex(int idx); - - QmlGraphicsItem *currentItem(); - int count() const; - - QmlComponent *highlight() const; - void setHighlight(QmlComponent *highlight); - - bool highlightFollowsCurrentItem() const; - void setHighlightFollowsCurrentItem(bool); - - Q_ENUMS(Flow) - enum Flow { LeftToRight, TopToBottom }; - Flow flow() const; - void setFlow(Flow); - - bool isWrapEnabled() const; - void setWrapEnabled(bool); - - int cacheBuffer() const; - void setCacheBuffer(int); - - int cellWidth() const; - void setCellWidth(int); - - int cellHeight() const; - void setCellHeight(int); - - static QmlGraphicsGridViewAttached *qmlAttachedProperties(QObject *); - -public Q_SLOTS: - void moveCurrentIndexUp(); - void moveCurrentIndexDown(); - void moveCurrentIndexLeft(); - void moveCurrentIndexRight(); - -Q_SIGNALS: - void countChanged(); - void currentIndexChanged(); - void cellWidthChanged(); - void cellHeightChanged(); - -protected: - virtual void viewportMoved(); - virtual qreal minYExtent() const; - virtual qreal maxYExtent() const; - virtual qreal minXExtent() const; - virtual qreal maxXExtent() const; - virtual void keyPressEvent(QKeyEvent *); - virtual void componentComplete(); - -private Q_SLOTS: - void trackedPositionChanged(); - void itemsInserted(int index, int count); - void itemsRemoved(int index, int count); - void itemsMoved(int from, int to, int count); - void destroyRemoved(); - void createdItem(int index, QmlGraphicsItem *item); - void destroyingItem(QmlGraphicsItem *item); - void sizeChange(); - -private: - void refill(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsGridView) -QML_DECLARE_TYPEINFO(QmlGraphicsGridView, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp deleted file mode 100644 index 34b3399..0000000 --- a/src/declarative/fx/qfximage.cpp +++ /dev/null @@ -1,301 +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 "qfximage.h" -#include "qfximage_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Image,QmlGraphicsImage) - -/*! - \qmlclass Image QmlGraphicsImage - \brief The Image element allows you to add bitmaps to a scene. - \inherits Item - - The Image element supports untransformed, stretched and tiled. - - For an explanation of stretching and tiling, see the fillMode property description. - - Examples: - \table - \row - \o \image declarative-qtlogo1.png - \o Untransformed - \qml - Image { source: "pics/qtlogo.png" } - \endqml - \row - \o \image declarative-qtlogo2.png - \o fillMode: Stretch (default) - \qml - Image { - width: 160 - height: 160 - source: "pics/qtlogo.png" - } - \endqml - \row - \o \image declarative-qtlogo3.png - \o fillMode: Tile - \qml - Image { - fillMode: Image.Tile - width: 160; height: 160 - source: "pics/qtlogo.png" - } - \endqml - \row - \o \image declarative-qtlogo6.png - \o fillMode: TileVertically - \qml - Image { - fillMode: Image.TileVertically - width: 160; height: 160 - source: "pics/qtlogo.png" - } - \endqml - \row - \o \image declarative-qtlogo5.png - \o fillMode: TileHorizontally - \qml - Image { - fillMode: Image.TileHorizontally - width: 160; height: 160 - source: "pics/qtlogo.png" - } - \endqml - \endtable - */ - -/*! - \internal - \class QmlGraphicsImage Image - \brief The QmlGraphicsImage class provides an image item that you can add to a QmlView. - - \ingroup group_coreitems - - Example: - \qml - Image { source: "pics/star.png" } - \endqml - - A QmlGraphicsImage object can be instantiated in Qml using the tag \l Image. -*/ - -QmlGraphicsImage::QmlGraphicsImage(QmlGraphicsItem *parent) - : QmlGraphicsImageBase(*(new QmlGraphicsImagePrivate), parent) -{ - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -QmlGraphicsImage::QmlGraphicsImage(QmlGraphicsImagePrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsImageBase(dd, parent) -{ - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -QmlGraphicsImage::~QmlGraphicsImage() -{ -} - -QPixmap QmlGraphicsImage::pixmap() const -{ - Q_D(const QmlGraphicsImage); - return d->pix; -} - -void QmlGraphicsImage::setPixmap(const QPixmap &pix) -{ - Q_D(QmlGraphicsImage); - if (!d->url.isEmpty()) - return; - d->pix = pix; - - setImplicitWidth(d->pix.width()); - setImplicitHeight(d->pix.height()); - - update(); -} - -/*! - \qmlproperty enumeration Image::fillMode - - Set this property to define what happens when the image set for the item is smaller - than the size of the item. - - \list - \o Stretch - the image is scaled to fit - \o PreserveAspectFit - the image is scaled uniformly to fit without cropping - \o PreserveAspectCrop - the image is scaled uniformly to fill, cropping if necessary - \o Tile - the image is duplicated horizontally and vertically - \o TileVertically - the image is stretched horizontally and tiled vertically - \o TileHorizontally - the image is stretched vertically and tiled horizontally - \endlist - - \image declarative-image_fillMode.gif - \sa examples/declarative/fillmode - \sa examples/declarative/aspectratio -*/ -QmlGraphicsImage::FillMode QmlGraphicsImage::fillMode() const -{ - Q_D(const QmlGraphicsImage); - return d->fillMode; -} - -void QmlGraphicsImage::setFillMode(FillMode mode) -{ - Q_D(QmlGraphicsImage); - if (d->fillMode == mode) - return; - d->fillMode = mode; - update(); - emit fillModeChanged(); -} - -/*! - \qmlproperty enum Image::status - - This property holds the status of image loading. It can be one of: - \list - \o Null - no image has been set - \o Ready - the image has been loaded - \o Loading - the image is currently being loaded - \o Error - an error occurred while loading the image - \endlist - - \sa progress -*/ - -/*! - \qmlproperty real Image::progress - - This property holds the progress of image loading, from 0.0 (nothing loaded) - to 1.0 (finished). - - \sa status -*/ - -/*! - \qmlproperty bool Image::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 image 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. -*/ - -/*! - \qmlproperty url Image::source - - Image can handle any image format supported by Qt, loaded from any URL scheme supported by Qt. - - The URL may be absolute, or relative to the URL of the component. -*/ - -void QmlGraphicsImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - Q_D(QmlGraphicsImage); - if (d->pix.isNull()) - return; - - bool oldAA = p->testRenderHint(QPainter::Antialiasing); - bool oldSmooth = p->testRenderHint(QPainter::SmoothPixmapTransform); - if (d->smooth) - p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); - - if (width() != d->pix.width() || height() != d->pix.height()) { - if (d->fillMode >= Tile) { - if (d->fillMode == Tile) - p->drawTiledPixmap(QRectF(0,0,width(),height()), d->pix); - else if (d->fillMode == TileVertically) - p->drawTiledPixmap(QRectF(0,0,d->pix.width(),height()), d->pix); - else - p->drawTiledPixmap(QRectF(0,0,width(),d->pix.height()), d->pix); - } else { - qreal widthScale = width() / qreal(d->pix.width()); - qreal heightScale = height() / qreal(d->pix.height()); - - QTransform scale; - - if (d->fillMode == PreserveAspectFit) { - if (widthScale < heightScale) { - heightScale = widthScale; - scale.translate(0, (height() - heightScale * d->pix.height()) / 2); - } else if(heightScale < widthScale) { - widthScale = heightScale; - scale.translate((width() - widthScale * d->pix.width()) / 2, 0); - } - } else if (d->fillMode == PreserveAspectCrop) { - if (widthScale < heightScale) { - widthScale = heightScale; - scale.translate((width() - widthScale * d->pix.width()) / 2, 0); - } else if(heightScale < widthScale) { - heightScale = widthScale; - scale.translate(0, (height() - heightScale * d->pix.height()) / 2); - } - } - - scale.scale(widthScale, heightScale); - QTransform old = p->transform(); - p->setWorldTransform(scale * old); - p->drawPixmap(0, 0, d->pix); - p->setWorldTransform(old); - } - } else { - p->drawPixmap(0, 0, d->pix); - } - - if (d->smooth) { - p->setRenderHint(QPainter::Antialiasing, oldAA); - p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfximage.h b/src/declarative/fx/qfximage.h deleted file mode 100644 index 1f52b17..0000000 --- a/src/declarative/fx/qfximage.h +++ /dev/null @@ -1,90 +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 QFXIMAGE_H -#define QFXIMAGE_H - -#include -#include "qfximagebase.h" - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsImagePrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsImage : public QmlGraphicsImageBase -{ - Q_OBJECT - Q_ENUMS(FillMode) - - Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap DESIGNABLE false) - Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) - -public: - QmlGraphicsImage(QmlGraphicsItem *parent=0); - ~QmlGraphicsImage(); - - enum FillMode { Stretch, PreserveAspectFit, PreserveAspectCrop, Tile, TileVertically, TileHorizontally }; - FillMode fillMode() const; - void setFillMode(FillMode); - - QPixmap pixmap() const; - void setPixmap(const QPixmap &); - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -Q_SIGNALS: - void fillModeChanged(); - -protected: - QmlGraphicsImage(QmlGraphicsImagePrivate &dd, QmlGraphicsItem *parent); - -private: - Q_DISABLE_COPY(QmlGraphicsImage) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsImage) -}; - -QT_END_NAMESPACE -QML_DECLARE_TYPE(QmlGraphicsImage) -QT_END_HEADER - -#endif // QFXIMAGE_H diff --git a/src/declarative/fx/qfximage_p.h b/src/declarative/fx/qfximage_p.h deleted file mode 100644 index 30f7665..0000000 --- a/src/declarative/fx/qfximage_p.h +++ /dev/null @@ -1,77 +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 QFXIMAGE_P_H -#define QFXIMAGE_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 "qfxitem_p.h" -#include "qfximagebase_p.h" - -QT_BEGIN_NAMESPACE - -class QmlGraphicsImagePrivate : public QmlGraphicsImageBasePrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsImage) - -public: - QmlGraphicsImagePrivate() - : fillMode(QmlGraphicsImage::Stretch) - { - } - - QmlGraphicsImage::FillMode fillMode; - -}; - -QT_END_NAMESPACE - -#endif // QFXIMAGE_P_H diff --git a/src/declarative/fx/qfximagebase.cpp b/src/declarative/fx/qfximagebase.cpp deleted file mode 100644 index 5afb79a..0000000 --- a/src/declarative/fx/qfximagebase.cpp +++ /dev/null @@ -1,174 +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 "qfximagebase.h" -#include "qfximagebase_p.h" -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QmlGraphicsImageBase::QmlGraphicsImageBase(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsImageBasePrivate), parent) -{ - setFlag(QGraphicsItem::ItemHasNoContents, true); -} - -QmlGraphicsImageBase::QmlGraphicsImageBase(QmlGraphicsImageBasePrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ - setFlag(QGraphicsItem::ItemHasNoContents, true); -} - -QmlGraphicsImageBase::~QmlGraphicsImageBase() -{ - Q_D(QmlGraphicsImageBase); - if (d->pendingPixmapCache) - QmlGraphicsPixmapCache::cancelGet(d->url, this); -} - -QmlGraphicsImageBase::Status QmlGraphicsImageBase::status() const -{ - Q_D(const QmlGraphicsImageBase); - return d->status; -} - - -qreal QmlGraphicsImageBase::progress() const -{ - Q_D(const QmlGraphicsImageBase); - return d->progress; -} - -QUrl QmlGraphicsImageBase::source() const -{ - Q_D(const QmlGraphicsImageBase); - return d->url; -} - -void QmlGraphicsImageBase::setSource(const QUrl &url) -{ - Q_D(QmlGraphicsImageBase); - //equality is fairly expensive, so we bypass for simple, common case - if ((d->url.isEmpty() == url.isEmpty()) && url == d->url) - return; - - if (d->pendingPixmapCache) { - QmlGraphicsPixmapCache::cancelGet(d->url, this); - d->pendingPixmapCache = false; - } - - d->url = url; - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } - - if (url.isEmpty()) { - d->pix = QPixmap(); - d->status = Null; - d->progress = 1.0; - setImplicitWidth(0); - setImplicitHeight(0); - emit statusChanged(d->status); - emit sourceChanged(d->url); - emit progressChanged(1.0); - update(); - } else { - d->status = Loading; - QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->pix); - if (reply) { - d->pendingPixmapCache = true; - connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); - connect(reply, SIGNAL(downloadProgress(qint64,qint64)), - this, SLOT(requestProgress(qint64,qint64))); - } else { - //### should be unified with requestFinished - setImplicitWidth(d->pix.width()); - setImplicitHeight(d->pix.height()); - - if (d->status == Loading) - d->status = Ready; - d->progress = 1.0; - emit statusChanged(d->status); - emit sourceChanged(d->url); - emit progressChanged(1.0); - update(); - } - } - - emit statusChanged(d->status); -} - -void QmlGraphicsImageBase::requestFinished() -{ - Q_D(QmlGraphicsImageBase); - - d->pendingPixmapCache = false; - - if (!QmlGraphicsPixmapCache::find(d->url, &d->pix)) - d->status = Error; - setImplicitWidth(d->pix.width()); - setImplicitHeight(d->pix.height()); - - if (d->status == Loading) - d->status = Ready; - d->progress = 1.0; - emit statusChanged(d->status); - emit sourceChanged(d->url); - emit progressChanged(1.0); - update(); -} - -void QmlGraphicsImageBase::requestProgress(qint64 received, qint64 total) -{ - Q_D(QmlGraphicsImageBase); - if (d->status == Loading && total > 0) { - d->progress = qreal(received)/total; - emit progressChanged(d->progress); - } -} - - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfximagebase.h b/src/declarative/fx/qfximagebase.h deleted file mode 100644 index b43e9a2..0000000 --- a/src/declarative/fx/qfximagebase.h +++ /dev/null @@ -1,90 +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 QFXIMAGEBASE_H -#define QFXIMAGEBASE_H - -#include - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - -class QmlGraphicsImageBasePrivate; -class QmlGraphicsImageBase : public QmlGraphicsItem -{ - Q_OBJECT - Q_ENUMS(Status) - - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - -public: - QmlGraphicsImageBase(QmlGraphicsItem *parent = 0); - ~QmlGraphicsImageBase(); - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - - QUrl source() const; - virtual void setSource(const QUrl &url); - -Q_SIGNALS: - void sourceChanged(const QUrl &); - void statusChanged(Status); - void progressChanged(qreal progress); - -protected: - QmlGraphicsImageBase(QmlGraphicsImageBasePrivate &dd, QmlGraphicsItem *parent); - -private Q_SLOTS: - virtual void requestFinished(); - void requestProgress(qint64,qint64); - -private: - Q_DISABLE_COPY(QmlGraphicsImageBase) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsImageBase) -}; - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QFXIMAGEBASE_H diff --git a/src/declarative/fx/qfximagebase_p.h b/src/declarative/fx/qfximagebase_p.h deleted file mode 100644 index 9025c51..0000000 --- a/src/declarative/fx/qfximagebase_p.h +++ /dev/null @@ -1,83 +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 QFXIMAGEBASE_P_H -#define QFXIMAGEBASE_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 "qfxitem_p.h" -#include - -QT_BEGIN_NAMESPACE - -class QNetworkReply; -class QmlGraphicsImageBasePrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsImageBase) - -public: - QmlGraphicsImageBasePrivate() - : status(QmlGraphicsImageBase::Null), - progress(0.0), - pendingPixmapCache(false) - { - } - - QPixmap pix; - QmlGraphicsImageBase::Status status; - QUrl url; - qreal progress; - bool pendingPixmapCache; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp deleted file mode 100644 index 7a3cded..0000000 --- a/src/declarative/fx/qfxitem.cpp +++ /dev/null @@ -1,2921 +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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "qmlstate.h" -#include "qlistmodelinterface.h" - -#include "qmlview.h" -#include "qmlstategroup.h" - -#include "qfxitem_p.h" -#include "qfxitem.h" -#include "qfxevents_p.h" -#include - -QT_BEGIN_NAMESPACE - -#ifndef FLT_MAX -#define FLT_MAX 1E+37 -#endif - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Item,QmlGraphicsItem) - -QML_DEFINE_NOCREATE_TYPE(QGraphicsTransform); -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Scale,QGraphicsScale) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) - -#include "qfxeffects.cpp" - -/*! - \qmlclass Transform - \brief The Transform elements provide a way of building advanced transformations on Items. - - The Transform elements let you create and control advanced transformations that can be configured - independently using specialized properties. - - You can assign any number of Transform elements to an Item. Each Transform is applied in order, - one at a time, to the Item it's assigned to. - - \sa Rotation, Scale -*/ - -/*! - \qmlclass Scale - \brief The Scale object provides a way to scale an Item. - - The Scale object gives more control over scaling than using Item's scale property. Specifically, - it allows a different scale for the x and y axes, and allows the scale to be relative to an - arbitrary point. - - The following example scales the X axis of the Rectangle, relative to its interior point 25, 25: - \qml - Rectangle { - width: 100; height: 100 - color: "blue" - transform: Scale { origin.x: 25; origin.y: 25; xScale: 3} - } - \endqml -*/ - -/*! - \qmlproperty real Scale::origin.x - \qmlproperty real Scale::origin.y - - The point that the item is scaled from (i.e., the point that stays fixed relative to the parent as - the rest of the item grows). By default the origin is 0, 0. -*/ - -/*! - \qmlproperty real Scale::xScale - - The scaling factor for the X axis. -*/ - -/*! - \qmlproperty real Scale::yScale - - The scaling factor for the Y axis. -*/ - -/*! - \qmlclass Rotation - \brief The Rotation object provides a way to rotate an Item. - - The Rotation object gives more control over rotation than using Item's rotation property. - Specifically, it allows (z axis) rotation to be relative to an arbitrary point. - - The following example rotates a Rectangle around its interior point 25, 25: - \qml - Rectangle { - width: 100; height: 100 - color: "blue" - transform: Rotation { origin.x: 25; origin.y: 25; angle: 45} - } - \endqml - - Rotation also provides a way to specify 3D-like rotations for Items. For these types of - rotations you must specify the axis to rotate around in addition to the origin point. - - The following example shows various 3D-like rotations applied to an \l Image. - \snippet doc/src/snippets/declarative/rotation.qml 0 - - \image axisrotation.png -*/ - -/*! - \qmlproperty real Rotation::origin.x - \qmlproperty real Rotation::origin.y - - The origin point of the rotation (i.e., the point that stays fixed relative to the parent as - the rest of the item rotates). By default the origin is 0, 0. -*/ - -/*! - \qmlproperty real Rotation::axis.x - \qmlproperty real Rotation::axis.y - \qmlproperty real Rotation::axis.z - - The axis to rotate around. For simple (2D) rotation around a point, you do not need to specify an axis, - as the default axis is the z axis (\c{ axis { x: 0; y: 0; z: 0 } }). - - For a typical 3D-like rotation you will usually specify both the origin and the axis. - - \image 3d-rotation-axis.png -*/ - -/*! - \qmlproperty real Rotation::angle - - The angle to rotate, in degrees clockwise. -*/ - - -/*! - \group group_animation - \title Animation -*/ - -/*! - \group group_coreitems - \title Basic Items -*/ - -/*! - \group group_effects - \title Effects -*/ - -/*! - \group group_layouts - \title Layouts -*/ - -/*! - \group group_states - \title States and Transitions -*/ - -/*! - \group group_utility - \title Utility -*/ - -/*! - \group group_views - \title Views -*/ - -/*! - \group group_widgets - \title Widgets -*/ - -/*! - \internal - \class QmlGraphicsContents - \ingroup group_utility - \brief The QmlGraphicsContents class gives access to the height and width of an item's contents. - -*/ - -QmlGraphicsContents::QmlGraphicsContents() : m_x(0), m_y(0), m_width(0), m_height(0) -{ -} - -/*! - \qmlproperty real Item::childrenRect.x - \qmlproperty real Item::childrenRect.y - \qmlproperty real Item::childrenRect.width - \qmlproperty real Item::childrenRect.height - - The childrenRect properties allow an item access to the geometry of its - children. This property is useful if you have an item that needs to be - sized to fit its children. -*/ - -QRectF QmlGraphicsContents::rectF() const -{ - return QRectF(m_x, m_y, m_width, m_height); -} - -//TODO: optimization: only check sender(), if there is one -void QmlGraphicsContents::calcHeight() -{ - qreal oldy = m_y; - qreal oldheight = m_height; - - qreal top = FLT_MAX; - qreal bottom = 0; - - QList children = m_item->childItems(); - for (int i = 0; i < children.count(); ++i) { - QmlGraphicsItem *child = qobject_cast(children.at(i)); - if(!child)//### Should this be ignoring non-QmlGraphicsItem graphicsobjects? - continue; - qreal y = child->y(); - if (y + child->height() > bottom) - bottom = y + child->height(); - if (y < top) - top = y; - } - if (!children.isEmpty()) - m_y = top; - m_height = qMax(bottom - top, qreal(0.0)); - - if (m_height != oldheight || m_y != oldy) - emit rectChanged(); -} - -//TODO: optimization: only check sender(), if there is one -void QmlGraphicsContents::calcWidth() -{ - qreal oldx = m_x; - qreal oldwidth = m_width; - - qreal left = FLT_MAX; - qreal right = 0; - - QList children = m_item->childItems(); - for (int i = 0; i < children.count(); ++i) { - QmlGraphicsItem *child = qobject_cast(children.at(i)); - if(!child)//### Should this be ignoring non-QmlGraphicsItem graphicsobjects? - continue; - qreal x = child->x(); - if (x + child->width() > right) - right = x + child->width(); - if (x < left) - left = x; - } - if (!children.isEmpty()) - m_x = left; - m_width = qMax(right - left, qreal(0.0)); - - if (m_width != oldwidth || m_x != oldx) - emit rectChanged(); -} - -void QmlGraphicsContents::setItem(QmlGraphicsItem *item) -{ - m_item = item; - - QList children = m_item->childItems(); - for (int i = 0; i < children.count(); ++i) { - QmlGraphicsItem *child = qobject_cast(children.at(i)); - if(!child)//### Should this be ignoring non-QmlGraphicsItem graphicsobjects? - continue; - connect(child, SIGNAL(heightChanged()), this, SLOT(calcHeight())); - connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight())); - connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth())); - connect(child, SIGNAL(xChanged()), this, SLOT(calcWidth())); - connect(this, SIGNAL(rectChanged()), m_item, SIGNAL(childrenRectChanged())); - } - - calcHeight(); - calcWidth(); -} - -/* - Key filters can be installed on a QmlGraphicsItem, but not removed. Currently they - are only used by attached objects (which are only destroyed on Item - destruction), so this isn't a problem. If in future this becomes any form - of public API, they will have to support removal too. -*/ -class QmlGraphicsItemKeyFilter -{ -public: - QmlGraphicsItemKeyFilter(QmlGraphicsItem * = 0); - virtual ~QmlGraphicsItemKeyFilter(); - - virtual void keyPressed(QKeyEvent *event); - virtual void keyReleased(QKeyEvent *event); - virtual void inputMethodEvent(QInputMethodEvent *event); - virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; - virtual void componentComplete(); - -private: - QmlGraphicsItemKeyFilter *m_next; -}; - -QmlGraphicsItemKeyFilter::QmlGraphicsItemKeyFilter(QmlGraphicsItem *item) -: m_next(0) -{ - QmlGraphicsItemPrivate *p = - item?static_cast(QGraphicsItemPrivate::get(item)):0; - if (p) { - m_next = p->keyHandler; - p->keyHandler = this; - } -} - -QmlGraphicsItemKeyFilter::~QmlGraphicsItemKeyFilter() -{ -} - -void QmlGraphicsItemKeyFilter::keyPressed(QKeyEvent *event) -{ - if (m_next) m_next->keyPressed(event); -} - -void QmlGraphicsItemKeyFilter::keyReleased(QKeyEvent *event) -{ - if (m_next) m_next->keyReleased(event); -} - -void QmlGraphicsItemKeyFilter::inputMethodEvent(QInputMethodEvent *event) -{ - if (m_next) m_next->inputMethodEvent(event); -} - -QVariant QmlGraphicsItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query) const -{ - if (m_next) return m_next->inputMethodQuery(query); - return QVariant(); -} - -void QmlGraphicsItemKeyFilter::componentComplete() -{ - if (m_next) m_next->componentComplete(); -} - -class QmlGraphicsKeyNavigationAttachedPrivate : public QObjectPrivate -{ -public: - QmlGraphicsKeyNavigationAttachedPrivate() - : QObjectPrivate(), left(0), right(0), up(0), down(0) {} - - QmlGraphicsItem *left; - QmlGraphicsItem *right; - QmlGraphicsItem *up; - QmlGraphicsItem *down; -}; - -class QmlGraphicsKeyNavigationAttached : public QObject, public QmlGraphicsItemKeyFilter -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlGraphicsKeyNavigationAttached) - - Q_PROPERTY(QmlGraphicsItem *left READ left WRITE setLeft NOTIFY changed) - Q_PROPERTY(QmlGraphicsItem *right READ right WRITE setRight NOTIFY changed) - Q_PROPERTY(QmlGraphicsItem *up READ up WRITE setUp NOTIFY changed) - Q_PROPERTY(QmlGraphicsItem *down READ down WRITE setDown NOTIFY changed) -public: - QmlGraphicsKeyNavigationAttached(QObject * = 0); - - QmlGraphicsItem *left() const; - void setLeft(QmlGraphicsItem *); - QmlGraphicsItem *right() const; - void setRight(QmlGraphicsItem *); - QmlGraphicsItem *up() const; - void setUp(QmlGraphicsItem *); - QmlGraphicsItem *down() const; - void setDown(QmlGraphicsItem *); - - static QmlGraphicsKeyNavigationAttached *qmlAttachedProperties(QObject *); - -Q_SIGNALS: - void changed(); - -private: - virtual void keyPressed(QKeyEvent *event); - virtual void keyReleased(QKeyEvent *event); -}; - -QmlGraphicsKeyNavigationAttached::QmlGraphicsKeyNavigationAttached(QObject *parent) -: QObject(*(new QmlGraphicsKeyNavigationAttachedPrivate), parent), - QmlGraphicsItemKeyFilter(qobject_cast(parent)) -{ -} - -QmlGraphicsKeyNavigationAttached * -QmlGraphicsKeyNavigationAttached::qmlAttachedProperties(QObject *obj) -{ - return new QmlGraphicsKeyNavigationAttached(obj); -} - -QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::left() const -{ - Q_D(const QmlGraphicsKeyNavigationAttached); - return d->left; -} - -void QmlGraphicsKeyNavigationAttached::setLeft(QmlGraphicsItem *i) -{ - Q_D(QmlGraphicsKeyNavigationAttached); - d->left = i; - emit changed(); -} - -QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::right() const -{ - Q_D(const QmlGraphicsKeyNavigationAttached); - return d->right; -} - -void QmlGraphicsKeyNavigationAttached::setRight(QmlGraphicsItem *i) -{ - Q_D(QmlGraphicsKeyNavigationAttached); - d->right = i; - emit changed(); -} - -QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::up() const -{ - Q_D(const QmlGraphicsKeyNavigationAttached); - return d->up; -} - -void QmlGraphicsKeyNavigationAttached::setUp(QmlGraphicsItem *i) -{ - Q_D(QmlGraphicsKeyNavigationAttached); - d->up = i; - emit changed(); -} - -QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::down() const -{ - Q_D(const QmlGraphicsKeyNavigationAttached); - return d->down; -} - -void QmlGraphicsKeyNavigationAttached::setDown(QmlGraphicsItem *i) -{ - Q_D(QmlGraphicsKeyNavigationAttached); - d->down = i; - emit changed(); -} - -void QmlGraphicsKeyNavigationAttached::keyPressed(QKeyEvent *event) -{ - Q_D(QmlGraphicsKeyNavigationAttached); - - event->ignore(); - - switch(event->key()) { - case Qt::Key_Left: - if (d->left) { - d->left->setFocus(true); - event->accept(); - } - break; - case Qt::Key_Right: - if (d->right) { - d->right->setFocus(true); - event->accept(); - } - break; - case Qt::Key_Up: - if (d->up) { - d->up->setFocus(true); - event->accept(); - } - break; - case Qt::Key_Down: - if (d->down) { - d->down->setFocus(true); - event->accept(); - } - break; - default: - break; - } - - if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyPressed(event); -} - -void QmlGraphicsKeyNavigationAttached::keyReleased(QKeyEvent *event) -{ - Q_D(QmlGraphicsKeyNavigationAttached); - - event->ignore(); - - switch(event->key()) { - case Qt::Key_Left: - if (d->left) { - event->accept(); - } - break; - case Qt::Key_Right: - if (d->right) { - event->accept(); - } - break; - case Qt::Key_Up: - if (d->up) { - event->accept(); - } - break; - case Qt::Key_Down: - if (d->down) { - event->accept(); - } - break; - default: - break; - } - - if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyReleased(event); -} - -/*! - \qmlclass Keys - \brief The Keys attached property provides key handling to Items. - - All visual primitives support key handling via the \e Keys - attached property. Keys can be handled via the \e onPressed - and \e onReleased signal properties. - - The signal properties have a \l KeyEvent parameter, named - \e event which contains details of the event. If a key is - handled \e event.accepted should be set to true to prevent the - event from propagating up the item heirarchy. - - \code - Item { - focus: true - Keys.onPressed: { - if (event.key == Qt.Key_Left) { - print("move left"); - event.accepted = true; - } - } - } - \endcode - - Some keys may alternatively be handled via specific signal properties, - for example \e onSelectPressed. These handlers automatically set - \e event.accepted to true. - - \code - Item { - focus: true - Keys.onLeftPressed: print("move left") - } - \endcode - - See \l {Qt::Key}{Qt.Key} for the list of keyboard codes. - - \sa KeyEvent -*/ - -/*! - \qmlproperty bool Keys::enabled - - This flags enables key handling if true (default); otherwise - no key handlers will be called. -*/ - -/*! - \qmlproperty List Keys::forwardTo - - This property provides a way to forward key presses, key releases, and keyboard input - coming from input methods to other items. This can be useful when you want - one item to handle some keys (e.g. the up and down arrow keys), and another item to - handle other keys (e.g. the left and right arrow keys). Once an item that has been - forwarded keys accepts the event it is no longer forwarded to items later in the - list. - - This example forwards key events to two lists: - \qml - ListView { id: list1 ... } - ListView { id: list2 ... } - Keys.forwardTo: [list1, list2] - focus: true - \endqml -*/ - -/*! - \qmlsignal Keys::onPressed(event) - - This handler is called when a key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onReleased(event) - - This handler is called when a key has been released. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onDigit0Pressed(event) - - This handler is called when the digit '0' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onDigit1Pressed(event) - - This handler is called when the digit '1' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onDigit2Pressed(event) - - This handler is called when the digit '2' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onDigit3Pressed(event) - - This handler is called when the digit '3' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onDigit4Pressed(event) - - This handler is called when the digit '4' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onDigit5Pressed(event) - - This handler is called when the digit '5' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onDigit6Pressed(event) - - This handler is called when the digit '6' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onDigit7Pressed(event) - - This handler is called when the digit '7' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onDigit8Pressed(event) - - This handler is called when the digit '8' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onDigit9Pressed(event) - - This handler is called when the digit '9' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onLeftPressed(event) - - This handler is called when the Left arrow has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onRightPressed(event) - - This handler is called when the Right arrow has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onUpPressed(event) - - This handler is called when the Up arrow has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onDownPressed(event) - - This handler is called when the Down arrow has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onAsteriskPressed(event) - - This handler is called when the Asterisk '*' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onEscapePressed(event) - - This handler is called when the Escape key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onReturnPressed(event) - - This handler is called when the Return key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onEnterPressed(event) - - This handler is called when the Enter key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onDeletePressed(event) - - This handler is called when the Delete key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onSpacePressed(event) - - This handler is called when the Space key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onBackPressed(event) - - This handler is called when the Back key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onCancelPressed(event) - - This handler is called when the Cancel key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onSelectPressed(event) - - This handler is called when the Select key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onYesPressed(event) - - This handler is called when the Yes key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onNoPressed(event) - - This handler is called when the No key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onContext1Pressed(event) - - This handler is called when the Context1 key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onContext2Pressed(event) - - This handler is called when the Context2 key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onContext3Pressed(event) - - This handler is called when the Context3 key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onContext4Pressed(event) - - This handler is called when the Context4 key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onCallPressed(event) - - This handler is called when the Call key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onHangupPressed(event) - - This handler is called when the Hangup key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onFlipPressed(event) - - This handler is called when the Flip key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onMenuPressed(event) - - This handler is called when the Menu key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onVolumeUpPressed(event) - - This handler is called when the VolumeUp key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal Keys::onVolumeDownPressed(event) - - This handler is called when the VolumeDown key has been pressed. The \a event - parameter provides information about the event. -*/ - - -class QmlGraphicsKeysAttachedPrivate : public QObjectPrivate -{ -public: - QmlGraphicsKeysAttachedPrivate() - : QObjectPrivate(), inPress(false), inRelease(false) - , inIM(false), enabled(true), imeItem(0), item(0) - {} - - bool isConnected(const char *signalName); - - QGraphicsItem *finalFocusProxy(QGraphicsItem *item) const - { - QGraphicsItem *fp; - while ((fp = item->focusProxy())) - item = fp; - return item; - } - - //loop detection - bool inPress:1; - bool inRelease:1; - bool inIM:1; - - bool enabled : 1; - - QGraphicsItem *imeItem; - QList targets; - QmlGraphicsItem *item; -}; - -class QmlGraphicsKeysAttached : public QObject, public QmlGraphicsItemKeyFilter -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlGraphicsKeysAttached) - - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(QList *forwardTo READ forwardTo) - -public: - QmlGraphicsKeysAttached(QObject *parent=0); - ~QmlGraphicsKeysAttached(); - - bool enabled() const { Q_D(const QmlGraphicsKeysAttached); return d->enabled; } - void setEnabled(bool enabled) { - Q_D(QmlGraphicsKeysAttached); - if (enabled != d->enabled) { - d->enabled = enabled; - emit enabledChanged(); - } - } - - QList *forwardTo() { - Q_D(QmlGraphicsKeysAttached); - return &d->targets; - } - - virtual void componentComplete(); - - static QmlGraphicsKeysAttached *qmlAttachedProperties(QObject *); - -Q_SIGNALS: - void enabledChanged(); - void pressed(QmlGraphicsKeyEvent *event); - void released(QmlGraphicsKeyEvent *event); - void digit0Pressed(QmlGraphicsKeyEvent *event); - void digit1Pressed(QmlGraphicsKeyEvent *event); - void digit2Pressed(QmlGraphicsKeyEvent *event); - void digit3Pressed(QmlGraphicsKeyEvent *event); - void digit4Pressed(QmlGraphicsKeyEvent *event); - void digit5Pressed(QmlGraphicsKeyEvent *event); - void digit6Pressed(QmlGraphicsKeyEvent *event); - void digit7Pressed(QmlGraphicsKeyEvent *event); - void digit8Pressed(QmlGraphicsKeyEvent *event); - void digit9Pressed(QmlGraphicsKeyEvent *event); - - void leftPressed(QmlGraphicsKeyEvent *event); - void rightPressed(QmlGraphicsKeyEvent *event); - void upPressed(QmlGraphicsKeyEvent *event); - void downPressed(QmlGraphicsKeyEvent *event); - - void asteriskPressed(QmlGraphicsKeyEvent *event); - void numberSignPressed(QmlGraphicsKeyEvent *event); - void escapePressed(QmlGraphicsKeyEvent *event); - void returnPressed(QmlGraphicsKeyEvent *event); - void enterPressed(QmlGraphicsKeyEvent *event); - void deletePressed(QmlGraphicsKeyEvent *event); - void spacePressed(QmlGraphicsKeyEvent *event); - void backPressed(QmlGraphicsKeyEvent *event); - void cancelPressed(QmlGraphicsKeyEvent *event); - void selectPressed(QmlGraphicsKeyEvent *event); - void yesPressed(QmlGraphicsKeyEvent *event); - void noPressed(QmlGraphicsKeyEvent *event); - void context1Pressed(QmlGraphicsKeyEvent *event); - void context2Pressed(QmlGraphicsKeyEvent *event); - void context3Pressed(QmlGraphicsKeyEvent *event); - void context4Pressed(QmlGraphicsKeyEvent *event); - void callPressed(QmlGraphicsKeyEvent *event); - void hangupPressed(QmlGraphicsKeyEvent *event); - void flipPressed(QmlGraphicsKeyEvent *event); - void menuPressed(QmlGraphicsKeyEvent *event); - void volumeUpPressed(QmlGraphicsKeyEvent *event); - void volumeDownPressed(QmlGraphicsKeyEvent *event); - -private: - virtual void keyPressed(QKeyEvent *event); - virtual void keyReleased(QKeyEvent *event); - virtual void inputMethodEvent(QInputMethodEvent *); - virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; - - const QByteArray keyToSignal(int key) { - QByteArray keySignal; - if (key >= Qt::Key_0 && key <= Qt::Key_9) { - keySignal = "digit0Pressed"; - keySignal[5] = '0' + (key - Qt::Key_0); - } else { - int i = 0; - while (sigMap[i].key && sigMap[i].key != key) - ++i; - keySignal = sigMap[i].sig; - } - return keySignal; - } - - struct SigMap { - int key; - const char *sig; - }; - - static const SigMap sigMap[]; -}; - -const QmlGraphicsKeysAttached::SigMap QmlGraphicsKeysAttached::sigMap[] = { - { Qt::Key_Left, "leftPressed" }, - { Qt::Key_Right, "rightPressed" }, - { Qt::Key_Up, "upPressed" }, - { Qt::Key_Down, "downPressed" }, - { Qt::Key_Asterisk, "asteriskPressed" }, - { Qt::Key_NumberSign, "numberSignPressed" }, - { Qt::Key_Escape, "escapePressed" }, - { Qt::Key_Return, "returnPressed" }, - { Qt::Key_Enter, "enterPressed" }, - { Qt::Key_Delete, "deletePressed" }, - { Qt::Key_Space, "spacePressed" }, - { Qt::Key_Back, "backPressed" }, - { Qt::Key_Cancel, "cancelPressed" }, - { Qt::Key_Select, "selectPressed" }, - { Qt::Key_Yes, "yesPressed" }, - { Qt::Key_No, "noPressed" }, - { Qt::Key_Context1, "context1Pressed" }, - { Qt::Key_Context2, "context2Pressed" }, - { Qt::Key_Context3, "context3Pressed" }, - { Qt::Key_Context4, "context4Pressed" }, - { Qt::Key_Call, "callPressed" }, - { Qt::Key_Hangup, "hangupPressed" }, - { Qt::Key_Flip, "flipPressed" }, - { Qt::Key_Menu, "menuPressed" }, - { Qt::Key_VolumeUp, "volumeUpPressed" }, - { Qt::Key_VolumeDown, "volumeDownPressed" }, - { 0, 0 } -}; - -bool QmlGraphicsKeysAttachedPrivate::isConnected(const char *signalName) -{ - return isSignalConnected(signalIndex(signalName)); -} - -QmlGraphicsKeysAttached::QmlGraphicsKeysAttached(QObject *parent) -: QObject(*(new QmlGraphicsKeysAttachedPrivate), parent), - QmlGraphicsItemKeyFilter(qobject_cast(parent)) -{ - Q_D(QmlGraphicsKeysAttached); - d->item = qobject_cast(parent); -} - -QmlGraphicsKeysAttached::~QmlGraphicsKeysAttached() -{ -} - -void QmlGraphicsKeysAttached::componentComplete() -{ - Q_D(QmlGraphicsKeysAttached); - if (d->item) { - for (int ii = 0; ii < d->targets.count(); ++ii) { - QGraphicsItem *targetItem = d->finalFocusProxy(d->targets.at(ii)); - if (targetItem && (targetItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) { - d->item->setFlag(QGraphicsItem::ItemAcceptsInputMethod); - break; - } - } - } -} - -void QmlGraphicsKeysAttached::keyPressed(QKeyEvent *event) -{ - Q_D(QmlGraphicsKeysAttached); - if (!d->enabled || d->inPress) { - event->ignore(); - return; - } - - // first process forwards - if (d->item && d->item->scene()) { - d->inPress = true; - for (int ii = 0; ii < d->targets.count(); ++ii) { - QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); - if (i) { - d->item->scene()->sendEvent(i, event); - if (event->isAccepted()) { - d->inPress = false; - return; - } - } - } - d->inPress = false; - } - - QmlGraphicsKeyEvent ke(*event); - QByteArray keySignal = keyToSignal(event->key()); - if (!keySignal.isEmpty()) { - keySignal += "(QmlGraphicsKeyEvent*)"; - if (d->isConnected(keySignal)) { - // If we specifically handle a key then default to accepted - ke.setAccepted(true); - int idx = QmlGraphicsKeysAttached::staticMetaObject.indexOfSignal(keySignal); - metaObject()->method(idx).invoke(this, Q_ARG(QmlGraphicsKeysAttached, &ke)); - } - } - if (!ke.isAccepted()) - emit pressed(&ke); - event->setAccepted(ke.isAccepted()); - - if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyPressed(event); -} - -void QmlGraphicsKeysAttached::keyReleased(QKeyEvent *event) -{ - Q_D(QmlGraphicsKeysAttached); - if (!d->enabled || d->inRelease) { - event->ignore(); - return; - } - - if (d->item && d->item->scene()) { - d->inRelease = true; - for (int ii = 0; ii < d->targets.count(); ++ii) { - QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); - if (i) { - d->item->scene()->sendEvent(i, event); - if (event->isAccepted()) { - d->inRelease = false; - return; - } - } - } - d->inRelease = false; - } - - QmlGraphicsKeyEvent ke(*event); - emit released(&ke); - event->setAccepted(ke.isAccepted()); - - if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyReleased(event); -} - -void QmlGraphicsKeysAttached::inputMethodEvent(QInputMethodEvent *event) -{ - Q_D(QmlGraphicsKeysAttached); - if (d->item && !d->inIM && d->item->scene()) { - d->inIM = true; - for (int ii = 0; ii < d->targets.count(); ++ii) { - QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); - if (i && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod)) { - d->item->scene()->sendEvent(i, event); - if (event->isAccepted()) { - d->imeItem = i; - d->inIM = false; - return; - } - } - } - d->inIM = false; - } - if (!event->isAccepted()) QmlGraphicsItemKeyFilter::inputMethodEvent(event); -} - -class QmlGraphicsItemAccessor : public QGraphicsItem -{ -public: - QVariant doInputMethodQuery(Qt::InputMethodQuery query) const { - return QGraphicsItem::inputMethodQuery(query); - } -}; - -QVariant QmlGraphicsKeysAttached::inputMethodQuery(Qt::InputMethodQuery query) const -{ - Q_D(const QmlGraphicsKeysAttached); - if (d->item) { - for (int ii = 0; ii < d->targets.count(); ++ii) { - QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); - if (i && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod) && i == d->imeItem) { //### how robust is i == d->imeItem check? - QVariant v = static_cast(i)->doInputMethodQuery(query); - if (v.type() == QVariant::RectF) - v = d->item->mapRectFromItem(i, v.toRectF()); //### cost? - return v; - } - } - } - return QmlGraphicsItemKeyFilter::inputMethodQuery(query); -} - -QmlGraphicsKeysAttached *QmlGraphicsKeysAttached::qmlAttachedProperties(QObject *obj) -{ - return new QmlGraphicsKeysAttached(obj); -} - -/*! - \class QmlGraphicsItem - \brief The QmlGraphicsItem class provides the most basic of all visual items in QML. - - All visual items in Qt Declarative inherit from QmlGraphicsItem. Although QmlGraphicsItem - has no visual appearance, it defines all the properties that are - common across visual items - such as the x and y position, the - width and height, \l {anchor-layout}{anchoring} and key handling. - - You can subclass QmlGraphicsItem to provide your own custom visual item that inherits - these features. -*/ - -/*! - \qmlclass Item QmlGraphicsItem - \brief The Item is the most basic of all visual items in QML. - - All visual items in Qt Declarative inherit from Item. Although Item - has no visual appearance, it defines all the properties that are - common across visual items - such as the x and y position, the - width and height, \l {anchor-layout}{anchoring} and key handling. - - Item is also useful for grouping items together. - - \qml - Item { - Image { - file: "tile.png" - } - Image { - x: 80 - width: 100 - height: 100 - file: "tile.png" - } - Image { - x: 190 - width: 100 - height: 100 - tile: true - file: "tile.png" - } - } - \endqml - - \section1 Key Handling - - Key handling is available to all Item-based visual elements via the \l {Keys}{Keys} - attached property. The \e Keys attached property provides basic handlers such - as \l {Keys::onPressed(event)}{onPressed} and \l {Keys::onReleased(event)}{onReleased}, - as well as handlers for specific keys, such as - \l {Keys::onCancelPressed(event)}{onCancelPressed}. The example below - assigns \l {qmlfocus}{focus} to the item and handles - the Left key via the general \e onPressed handler and the Select key via the - onSelectPressed handler: - - \qml - Item { - focus: true - Keys.onPressed: { - if (event.key == Qt.Key_Left) { - print("move left"); - event.accepted = true; - } - } - Keys.onSelectPressed: print("Selected"); - } - \endqml - - See the \l {Keys}{Keys} attached property for detailed documentation. - - \ingroup group_coreitems -*/ - -/*! - \property QmlGraphicsItem::baseline - \internal -*/ - -/*! - \property QmlGraphicsItem::effect - \internal -*/ - -/*! - \property QmlGraphicsItem::focus - \internal -*/ - -/*! - \property QmlGraphicsItem::wantsFocus - \internal -*/ - -/*! - \property QmlGraphicsItem::transformOrigin - \internal -*/ - -/*! - \fn void QmlGraphicsItem::childrenRectChanged() - \internal -*/ - -/*! - \fn void QmlGraphicsItem::baselineOffsetChanged() - \internal -*/ - -/*! - \fn void QmlGraphicsItem::widthChanged() - \internal -*/ - -/*! - \fn void QmlGraphicsItem::heightChanged() - \internal -*/ - -/*! - \fn void QmlGraphicsItem::stateChanged(const QString &state) - \internal -*/ - -/*! - \fn void QmlGraphicsItem::parentChanged() - \internal -*/ - -/*! - \fn void QmlGraphicsItem::focusChanged() - \internal -*/ - -/*! - \fn void QmlGraphicsItem::wantsFocusChanged() - \internal -*/ - -static inline void qfxitem_registerAnchorLine() { - static bool registered = false; - if (!registered) { - qRegisterMetaType("QmlGraphicsAnchorLine"); - registered = true; - } -} - -/*! - \fn QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItem *parent) - - Constructs a QmlGraphicsItem with the given \a parent. -*/ -QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItem* parent) - : QGraphicsObject(*(new QmlGraphicsItemPrivate), parent, 0) -{ - Q_D(QmlGraphicsItem); - qfxitem_registerAnchorLine(); - d->init(parent); -} - -/*! \internal -*/ -QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItemPrivate &dd, QmlGraphicsItem *parent) - : QGraphicsObject(dd, parent, 0) -{ - Q_D(QmlGraphicsItem); - qfxitem_registerAnchorLine(); - d->init(parent); -} - -/*! - Destroys the QmlGraphicsItem. -*/ -QmlGraphicsItem::~QmlGraphicsItem() -{ - Q_D(QmlGraphicsItem); - for (int ii = 0; ii < d->dependantAnchors.count(); ++ii) { - QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); - anchor->d_func()->clearItem(this); - } - if (!d->parent || (parentItem() && !parentItem()->QGraphicsItem::d_ptr->inDestructor)) - for (int ii = 0; ii < d->dependantAnchors.count(); ++ii) { - QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); - if (anchor->d_func()->item && anchor->d_func()->item->parentItem() != this) //child will be deleted anyway - anchor->d_func()->updateOnComplete(); - } - d->dependantAnchors.clear(); - delete d->_anchorLines; d->_anchorLines = 0; - delete d->_anchors; d->_anchors = 0; -} - -/*! - \qmlproperty enum Item::transformOrigin - This property holds the origin point around which scale and rotation transform. - - Nine transform origins are available, as shown in the image below. - - \image declarative-transformorigin.png - - This example scales an image about its center. - \qml - Image { - source: "myimage.png" - transformOrigin: Item.Center - scale: 4 - } - \endqml - - The default transform origin is \c TopLeft. -*/ - -/*! - \qmlproperty Item Item::parent - This property holds the parent of the item. -*/ - -/*! - \property QmlGraphicsItem::parent - This property holds the parent of the item. -*/ -void QmlGraphicsItem::setParentItem(QmlGraphicsItem *parent) -{ - QmlGraphicsItem *oldParent = parentItem(); - if (parent == oldParent || !parent) return; - - QObject::setParent(parent); - QGraphicsObject::setParentItem(parent); -} - -/*! - Returns the QmlGraphicsItem parent of this item. -*/ -QmlGraphicsItem *QmlGraphicsItem::parentItem() const -{ - return qobject_cast(QGraphicsObject::parentItem()); -} - -/*! - \qmlproperty list Item::children - \qmlproperty list Item::resources - - The children property contains the list of visual children of this item. - The resources property contains non-visual resources that you want to - reference by name. - - Generally you can rely on Item's default property to handle all this for - you, but it can come in handy in some cases. - - \qml - Item { - children: [ - Text {}, - Rectangle {} - ] - resources: [ - Component { - id: myComponent - Text {} - } - ] - } - \endqml -*/ - -/*! - \property QmlGraphicsItem::children - \internal -*/ - -/*! - \property QmlGraphicsItem::resources - \internal -*/ - -/*! - Returns true if construction of the QML component is complete; otherwise - returns false. - - It is often desireable to delay some processing until the component is - completed. - - \sa componentComplete() -*/ -bool QmlGraphicsItem::isComponentComplete() const -{ - Q_D(const QmlGraphicsItem); - return d->_componentComplete; -} - -/*! - \property QmlGraphicsItem::anchors - \internal -*/ - -/*! \internal */ -QmlGraphicsAnchors *QmlGraphicsItem::anchors() -{ - Q_D(QmlGraphicsItem); - return d->anchors(); -} - -void QmlGraphicsItemPrivate::data_removeAt(int) -{ - // ### -} - -int QmlGraphicsItemPrivate::data_count() const -{ - // ### - return 0; -} - -void QmlGraphicsItemPrivate::data_append(QObject *o) -{ - Q_Q(QmlGraphicsItem); - QmlGraphicsItem *i = qobject_cast(o); - if (i) - q->fxChildren()->append(i); - else - resources_append(o); -} - -void QmlGraphicsItemPrivate::data_insert(int, QObject *) -{ - // ### -} - -QObject *QmlGraphicsItemPrivate::data_at(int) const -{ - // ### - return 0; -} - -void QmlGraphicsItemPrivate::data_clear() -{ - // ### -} - -void QmlGraphicsItemPrivate::resources_removeAt(int) -{ - // ### -} - -int QmlGraphicsItemPrivate::resources_count() const -{ - Q_Q(const QmlGraphicsItem); - return q->children().count(); -} - -void QmlGraphicsItemPrivate::resources_append(QObject *o) -{ - Q_Q(QmlGraphicsItem); - o->setParent(q); -} - -void QmlGraphicsItemPrivate::resources_insert(int, QObject *) -{ - // ### -} - -QObject *QmlGraphicsItemPrivate::resources_at(int idx) const -{ - Q_Q(const QmlGraphicsItem); - QObjectList children = q->children(); - if (idx < children.count()) - return children.at(idx); - else - return 0; -} - -void QmlGraphicsItemPrivate::resources_clear() -{ - // ### -} - -void QmlGraphicsItemPrivate::children_removeAt(int) -{ - // ### -} - -int QmlGraphicsItemPrivate::children_count() const -{ - Q_Q(const QmlGraphicsItem); - return q->childItems().count(); -} - -void QmlGraphicsItemPrivate::children_append(QmlGraphicsItem *i) -{ - Q_Q(QmlGraphicsItem); - i->setParentItem(q); -} - -void QmlGraphicsItemPrivate::children_insert(int, QmlGraphicsItem *) -{ - // ### -} - -QmlGraphicsItem *QmlGraphicsItemPrivate::children_at(int idx) const -{ - Q_Q(const QmlGraphicsItem); - QList children = q->childItems(); - if (idx < children.count()) - return qobject_cast(children.at(idx)); - else - return 0; -} - -void QmlGraphicsItemPrivate::children_clear() -{ - // ### -} - - -void QmlGraphicsItemPrivate::transform_removeAt(int i) -{ - if (!transformData) - return; - transformData->graphicsTransforms.removeAt(i); - dirtySceneTransform = 1; -} - -int QmlGraphicsItemPrivate::transform_count() const -{ - return transformData ? transformData->graphicsTransforms.size() : 0; -} - -void QmlGraphicsItemPrivate::transform_append(QGraphicsTransform *item) -{ - appendGraphicsTransform(item); -} - -void QmlGraphicsItemPrivate::transform_insert(int, QGraphicsTransform *) -{ - // ### -} - -QGraphicsTransform *QmlGraphicsItemPrivate::transform_at(int idx) const -{ - if (!transformData) - return 0; - return transformData->graphicsTransforms.at(idx); -} - -void QmlGraphicsItemPrivate::transform_clear() -{ - if (!transformData) - return; - Q_Q(QmlGraphicsItem); - q->setTransformations(QList()); -} - -/*! - \qmlproperty list Item::data - \default - - The data property is allows you to freely mix visual children and resources - of an item. If you assign a visual item to the data list it becomes - a child and if you assign any other object type, it is added as a resource. - - So you can write: - \qml - Item { - Text {} - Rectangle {} - Script {} - } - \endqml - - instead of: - \qml - Item { - children: [ - Text {}, - Rectangle {} - ] - resources: [ - Script {} - ] - } - \endqml - - data is a behind-the-scenes property: you should never need to explicitly - specify it. - */ - -/*! - \property QmlGraphicsItem::data - \internal -*/ - -/*! \internal */ -QmlList *QmlGraphicsItem::data() -{ - Q_D(QmlGraphicsItem); - return &d->data; -} - -/*! - \property QmlGraphicsItem::childrenRect - \brief The geometry of an item's children. - - childrenRect provides an easy way to access the (collective) position and size of the item's children. -*/ -QRectF QmlGraphicsItem::childrenRect() -{ - Q_D(QmlGraphicsItem); - if (!d->_contents) { - d->_contents = new QmlGraphicsContents; - d->_contents->setParent(this); - d->_contents->setItem(this); - } - return d->_contents->rectF(); -} - -bool QmlGraphicsItem::clip() const -{ - return flags() & ItemClipsChildrenToShape; -} - -void QmlGraphicsItem::setClip(bool c) -{ - setFlag(ItemClipsChildrenToShape, c); -} - -/*! - \qmlproperty real Item::x - \qmlproperty real Item::y - \qmlproperty real Item::width - \qmlproperty real Item::height - - Defines the item's position and size relative to its parent. - - \qml - Item { x: 100; y: 100; width: 100; height: 100 } - \endqml - */ - -/*! - \property QmlGraphicsItem::width - - Defines the item's width relative to its parent. - */ - -/*! - \property QmlGraphicsItem::height - - Defines the item's height relative to its parent. - */ - -/*! - \qmlproperty real Item::z - - Sets the stacking order of the item. By default the stacking order is 0. - - Items with a higher stacking value are drawn on top of items with a - lower stacking order. Items with the same stacking value are drawn - bottom up in the order they appear. Items with a negative stacking - value are drawn under their parent's content. - - The following example shows the various effects of stacking order. - - \table - \row - \o \image declarative-item_stacking1.png - \o Same \c z - later children above earlier children: - \qml - Item { - Rectangle { - color: "red" - width: 100; height: 100 - } - Rectangle { - color: "blue" - x: 50; y: 50; width: 100; height: 100 - } - } - \endqml - \row - \o \image declarative-item_stacking2.png - \o Higher \c z on top: - \qml - Item { - Rectangle { - z: 1 - color: "red" - width: 100; height: 100 - } - Rectangle { - color: "blue" - x: 50; y: 50; width: 100; height: 100 - } - } - \endqml - \row - \o \image declarative-item_stacking3.png - \o Same \c z - children above parents: - \qml - Item { - Rectangle { - color: "red" - width: 100; height: 100 - Rectangle { - color: "blue" - x: 50; y: 50; width: 100; height: 100 - } - } - } - \endqml - \row - \o \image declarative-item_stacking4.png - \o Lower \c z below: - \qml - Item { - Rectangle { - color: "red" - width: 100; height: 100 - Rectangle { - z: -1 - color: "blue" - x: 50; y: 50; width: 100; height: 100 - } - } - } - \endqml - \endtable - */ - -/*! - This function is called to handle this item's changes in - geometry from \a oldGeometry to \a newGeometry. If the two - geometries are the same, it doesn't do anything. - */ -void QmlGraphicsItem::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - Q_D(QmlGraphicsItem); - - if (d->_anchors) - d->_anchors->d_func()->updateMe(); - - if (transformOrigin() != QmlGraphicsItem::TopLeft) - setTransformOriginPoint(d->computeTransformOrigin()); - - if (newGeometry.x() != oldGeometry.x()) - emit xChanged(); - if (newGeometry.width() != oldGeometry.width()) - emit widthChanged(); - if (newGeometry.y() != oldGeometry.y()) - emit yChanged(); - if (newGeometry.height() != oldGeometry.height()) - emit heightChanged(); - - for(int ii = 0; ii < d->dependantAnchors.count(); ++ii) { - QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); - anchor->d_func()->update(this, newGeometry, oldGeometry); - } -} - -/*! \internal */ -void QmlGraphicsItem::keyPressEvent(QKeyEvent *event) -{ - Q_D(QmlGraphicsItem); - if (d->keyHandler) - d->keyHandler->keyPressed(event); - else - event->ignore(); -} - -/*! \internal */ -void QmlGraphicsItem::keyReleaseEvent(QKeyEvent *event) -{ - Q_D(QmlGraphicsItem); - if (d->keyHandler) - d->keyHandler->keyReleased(event); - else - event->ignore(); -} - -/*! \internal */ -void QmlGraphicsItem::inputMethodEvent(QInputMethodEvent *event) -{ - Q_D(QmlGraphicsItem); - if (d->keyHandler) - d->keyHandler->inputMethodEvent(event); - else - event->ignore(); -} - -/*! \internal */ -QVariant QmlGraphicsItem::inputMethodQuery(Qt::InputMethodQuery query) const -{ - Q_D(const QmlGraphicsItem); - QVariant v; - if (d->keyHandler) - v = d->keyHandler->inputMethodQuery(query); - - if (!v.isValid()) - v = QGraphicsObject::inputMethodQuery(query); - - return v; -} - -/*! - \qmlproperty string Item::id - This property holds the identifier for the item. - - The identifier can be used in bindings and other expressions to - refer to the item. For example: - - \qml - Text { id: myText; ... } - Text { text: myText.text } - \endqml - - The identifier is available throughout to the \l {components}{component} - where it is declared. The identifier must be unique in thecomponent. -*/ - -/*! - \internal -*/ -QmlGraphicsAnchorLine QmlGraphicsItem::left() const -{ - Q_D(const QmlGraphicsItem); - return d->anchorLines()->left; -} - -/*! - \internal -*/ -QmlGraphicsAnchorLine QmlGraphicsItem::right() const -{ - Q_D(const QmlGraphicsItem); - return d->anchorLines()->right; -} - -/*! - \internal -*/ -QmlGraphicsAnchorLine QmlGraphicsItem::horizontalCenter() const -{ - Q_D(const QmlGraphicsItem); - return d->anchorLines()->hCenter; -} - -/*! - \internal -*/ -QmlGraphicsAnchorLine QmlGraphicsItem::top() const -{ - Q_D(const QmlGraphicsItem); - return d->anchorLines()->top; -} - -/*! - \internal -*/ -QmlGraphicsAnchorLine QmlGraphicsItem::bottom() const -{ - Q_D(const QmlGraphicsItem); - return d->anchorLines()->bottom; -} - -/*! - \internal -*/ -QmlGraphicsAnchorLine QmlGraphicsItem::verticalCenter() const -{ - Q_D(const QmlGraphicsItem); - return d->anchorLines()->vCenter; -} - - -/*! - \internal -*/ -QmlGraphicsAnchorLine QmlGraphicsItem::baseline() const -{ - Q_D(const QmlGraphicsItem); - return d->anchorLines()->baseline; -} - -/*! - \property QmlGraphicsItem::top - \internal -*/ - -/*! - \property QmlGraphicsItem::bottom - \internal -*/ - -/*! - \property QmlGraphicsItem::left - \internal -*/ - -/*! - \property QmlGraphicsItem::right - \internal -*/ - -/*! - \property QmlGraphicsItem::horizontalCenter - \internal -*/ - -/*! - \property QmlGraphicsItem::verticalCenter - \internal -*/ - -/*! - \qmlproperty AnchorLine Item::top - \qmlproperty AnchorLine Item::bottom - \qmlproperty AnchorLine Item::left - \qmlproperty AnchorLine Item::right - \qmlproperty AnchorLine Item::horizontalCenter - \qmlproperty AnchorLine Item::verticalCenter - \qmlproperty AnchorLine Item::baseline - - The anchor lines of the item. - - For more information see \l {anchor-layout}{Anchor Layouts}. -*/ - -/*! - \qmlproperty AnchorLine Item::anchors.top - \qmlproperty AnchorLine Item::anchors.bottom - \qmlproperty AnchorLine Item::anchors.left - \qmlproperty AnchorLine Item::anchors.right - \qmlproperty AnchorLine Item::anchors.horizontalCenter - \qmlproperty AnchorLine Item::anchors.verticalCenter - \qmlproperty AnchorLine Item::anchors.baseline - - \qmlproperty Item Item::anchors.fill - \qmlproperty Item Item::anchors.centerIn - - \qmlproperty real Item::anchors.topMargin - \qmlproperty real Item::anchors.bottomMargin - \qmlproperty real Item::anchors.leftMargin - \qmlproperty real Item::anchors.rightMargin - \qmlproperty real Item::anchors.horizontalCenterOffset - \qmlproperty real Item::anchors.verticalCenterOffset - \qmlproperty real Item::anchors.baselineOffset - - Anchors provide a way to position an item by specifying its - relationship with other items. - - Margins apply to top, bottom, left, right, and fill anchors. - - Offsets apply for horizontal center, vertical center, and baseline anchors. - - \table - \row - \o \image declarative-anchors_example.png - \o Text anchored to Image, horizontally centered and vertically below, with a margin. - \qml - Image { id: pic; ... } - Text { - id: label - anchors.horizontalCenter: pic.horizontalCenter - anchors.top: pic.bottom - anchors.topMargin: 5 - ... - } - \endqml - \row - \o \image declarative-anchors_example2.png - \o - Left of Text anchored to right of Image, with a margin. The y - property of both defaults to 0. - - \qml - Image { id: pic; ... } - Text { - id: label - anchors.left: pic.right - anchors.leftMargin: 5 - ... - } - \endqml - \endtable - - anchors.fill provides a convenient way for one item to have the - same geometry as another item, and is equivalent to connecting all - four directional anchors. - - \note You can only anchor an item to siblings or a parent. - - For more information see \l {anchor-layout}{Anchor Layouts}. -*/ - -/*! - \property QmlGraphicsItem::baselineOffset - \brief The position of the item's baseline in local coordinates. - - The baseline of a Text item is the imaginary line on which the text - sits. Controls containing text usually set their baseline to the - baseline of their text. - - For non-text items, a default baseline offset of 0 is used. -*/ -qreal QmlGraphicsItem::baselineOffset() const -{ - Q_D(const QmlGraphicsItem); - if (!d->_baselineOffset.isValid()) { - return 0.0; - } else - return d->_baselineOffset; -} - -void QmlGraphicsItem::setBaselineOffset(qreal offset) -{ - Q_D(QmlGraphicsItem); - if (offset == d->_baselineOffset) - return; - - d->_baselineOffset = offset; - emit baselineOffsetChanged(); - - for(int ii = 0; ii < d->dependantAnchors.count(); ++ii) { - QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); - anchor->d_func()->updateVerticalAnchors(); - } -} - -/*! - \qmlproperty real Item::rotation - This property holds the rotation of the item in degrees clockwise. - - This specifies how many degrees to rotate the item around its transformOrigin. - The default rotation is 0 degrees (i.e. not rotated at all). - - \table - \row - \o \image declarative-rotation.png - \o - \qml - Rectangle { - color: "blue" - width: 100; height: 100 - Rectangle { - color: "green" - width: 25; height: 25 - } - Rectangle { - color: "red" - x: 25; y: 25; width: 50; height: 50 - rotation: 30 - } - } - \endqml - \endtable -*/ - -/*! - \qmlproperty real Item::scale - This property holds the scale of the item. - - A scale of less than 1 means the item will be displayed smaller than - normal, and a scale of greater than 1 means the item will be - displayed larger than normal. A negative scale means the item will - be mirrored. - - By default, items are displayed at a scale of 1 (i.e. at their - normal size). - - Scaling is from the item's transformOrigin. - - \table - \row - \o \image declarative-scale.png - \o - \qml - Rectangle { - color: "blue" - width: 100; height: 100 - Rectangle { - color: "green" - width: 25; height: 25 - } - Rectangle { - color: "red" - x: 25; y: 25; width: 50; height: 50 - scale: 1.4 - } - } - \endqml - \endtable -*/ - -/*! - \qmlproperty real Item::opacity - - The opacity of the item. Opacity is specified as a number between 0 - (fully transparent) and 1 (fully opaque). The default is 1. - - Opacity is an \e inherited attribute. That is, the opacity is - also applied individually to child items. In almost all cases this - is what you want. If you can spot the issue in the following - example, you might need to use an opacity filter (not yet available) instead. - - \table - \row - \o \image declarative-item_opacity1.png - \o - \qml - Item { - Rectangle { - color: "red" - width: 100; height: 100 - Rectangle { - color: "blue" - x: 50; y: 50; width: 100; height: 100 - } - } - } - \endqml - \row - \o \image declarative-item_opacity2.png - \o - \qml - Item { - Rectangle { - opacity: 0.5 - color: "red" - width: 100; height: 100 - Rectangle { - color: "blue" - x: 50; y: 50; width: 100; height: 100 - } - } - } - \endqml - \endtable -*/ - -/*! - Returns a value indicating whether mouse input should - remain with this item exclusively. - - \sa setKeepMouseGrab() - */ -bool QmlGraphicsItem::keepMouseGrab() const -{ - Q_D(const QmlGraphicsItem); - return d->_keepMouse; -} - -/*! - The flag indicating whether the mouse should remain - with this item is set to \a keep. - - This is useful for items that wish to grab and keep mouse - interaction following a predefined gesture. For example, - an item that is interested in horizontal mouse movement - may set keepMouseGrab to true once a threshold has been - exceeded. Once keepMouseGrab has been set to true, filtering - items will not react to mouse events. - - If the item does not indicate that it wishes to retain mouse grab, - a filtering item may steal the grab. For example, Flickable may attempt - to steal a mouse grab if it detects that the user has begun to - move the viewport. - - \sa keepMouseGrab - */ -void QmlGraphicsItem::setKeepMouseGrab(bool keep) -{ - Q_D(QmlGraphicsItem); - d->_keepMouse = keep; -} - -/*! - \internal - - This function emits the \e focusChanged signal. - - Subclasses overriding this function should call up - to their base class. -*/ -void QmlGraphicsItem::focusChanged(bool flag) -{ - Q_UNUSED(flag); - emit focusChanged(); -} - -/*! \internal */ -QmlList *QmlGraphicsItem::fxChildren() -{ - Q_D(QmlGraphicsItem); - return &(d->children); -} - -/*! \internal */ -QmlList *QmlGraphicsItem::resources() -{ - Q_D(QmlGraphicsItem); - return &(d->resources); -} - -/*! - \qmlproperty list Item::states - This property holds a list of states defined by the item. - - \qml - Item { - states: [ - State { ... }, - State { ... } - ... - ] - } - \endqml - - \sa {qmlstate}{States} -*/ - -/*! - \property QmlGraphicsItem::states - \internal -*/ -/*! \internal */ -QmlList* QmlGraphicsItem::states() -{ - Q_D(QmlGraphicsItem); - return d->states()->statesProperty(); -} - -/*! - \qmlproperty list Item::transitions - This property holds a list of transitions defined by the item. - - \qml - Item { - transitions: [ - Transition { ... }, - Transition { ... } - ... - ] - } - \endqml - - \sa {state-transitions}{Transitions} -*/ - -/*! - \property QmlGraphicsItem::transitions - \internal -*/ - -/*! \internal */ -QmlList* QmlGraphicsItem::transitions() -{ - Q_D(QmlGraphicsItem); - return d->states()->transitionsProperty(); -} - -/* - \qmlproperty list Item::filter - This property holds a list of graphical filters to be applied to the item. - - \l {Filter}{Filters} include things like \l {Blur}{blurring} - the item, or giving it a \l Reflection. Some - filters may not be available on all canvases; if a filter is not - available on a certain canvas, it will simply not be applied for - that canvas (but the QML will still be considered valid). - - \qml - Item { - filter: [ - Blur { ... }, - Relection { ... } - ... - ] - } - \endqml -*/ - -/*! - \qmlproperty bool Item::clip - This property holds whether clipping is enabled. - - if clipping is enabled, an item will clip its own painting, as well - as the painting of its children, to its bounding rectangle. - - Non-rectangular clipping regions are not supported for performance reasons. -*/ - -/*! - \property QmlGraphicsItem::clip - This property holds whether clipping is enabled. - - if clipping is enabled, an item will clip its own painting, as well - as the painting of its children, to its bounding rectangle. - - Non-rectangular clipping regions are not supported for performance reasons. -*/ - -/*! - \qmlproperty string Item::state - - This property holds the name of the current state of the item. - - This property is often used in scripts to change between states. For - example: - - \qml - Script { - function toggle() { - if (button.state == 'On') - button.state = 'Off'; - else - button.state = 'On'; - } - } - \endqml - - If the item is in its base state (i.e. no explicit state has been - set), \c state will be a blank string. Likewise, you can return an - item to its base state by setting its current state to \c ''. - - \sa {qmlstates}{States} -*/ - -/*! - \property QmlGraphicsItem::state - \internal -*/ - -/*! \internal */ -QString QmlGraphicsItem::state() const -{ - Q_D(const QmlGraphicsItem); - if (!d->_stateGroup) - return QString(); - else - return d->_stateGroup->state(); -} - -/*! \internal */ -void QmlGraphicsItem::setState(const QString &state) -{ - Q_D(QmlGraphicsItem); - d->states()->setState(state); -} - -/*! - \qmlproperty list Item::transform - This property holds the list of transformations to apply. - - For more information see \l Transform. -*/ - -/*! - \property QmlGraphicsItem::transform - \internal -*/ - -/*! \internal */ -QmlList* QmlGraphicsItem::transform() -{ - Q_D(QmlGraphicsItem); - return &(d->transform); -} - -/*! - \internal - - classBegin() is called when the item is constructed, but its - properties have not yet been set. - - \sa componentComplete(), isComponentComplete() -*/ -void QmlGraphicsItem::classBegin() -{ - Q_D(QmlGraphicsItem); - d->_componentComplete = false; - if (d->_stateGroup) - d->_stateGroup->classBegin(); - if (d->_anchors) - d->_anchors->classBegin(); -} - -/*! - \internal - - componentComplete() is called when all items in the component - have been constructed. It is often desireable to delay some - processing until the component is complete an all bindings in the - component have been resolved. -*/ -void QmlGraphicsItem::componentComplete() -{ -#ifdef Q_ENABLE_PERFORMANCE_LOG - QmlPerfTimer cc; -#endif - - Q_D(QmlGraphicsItem); - d->_componentComplete = true; - if (d->_stateGroup) - d->_stateGroup->componentComplete(); - if (d->_anchors) { - d->_anchors->componentComplete(); - d->_anchors->d_func()->updateOnComplete(); - } - if (d->keyHandler) - d->keyHandler->componentComplete(); -} - -QmlStateGroup *QmlGraphicsItemPrivate::states() -{ - Q_Q(QmlGraphicsItem); - if (!_stateGroup) { - _stateGroup = new QmlStateGroup(q); - if (!_componentComplete) - _stateGroup->classBegin(); - QObject::connect(_stateGroup, SIGNAL(stateChanged(QString)), - q, SIGNAL(stateChanged(QString))); - } - - return _stateGroup; -} - -QmlGraphicsItemPrivate::AnchorLines::AnchorLines(QmlGraphicsItem *q) -{ - left.item = q; - left.anchorLine = QmlGraphicsAnchorLine::Left; - right.item = q; - right.anchorLine = QmlGraphicsAnchorLine::Right; - hCenter.item = q; - hCenter.anchorLine = QmlGraphicsAnchorLine::HCenter; - top.item = q; - top.anchorLine = QmlGraphicsAnchorLine::Top; - bottom.item = q; - bottom.anchorLine = QmlGraphicsAnchorLine::Bottom; - vCenter.item = q; - vCenter.anchorLine = QmlGraphicsAnchorLine::VCenter; - baseline.item = q; - baseline.anchorLine = QmlGraphicsAnchorLine::Baseline; -} - -QPointF QmlGraphicsItemPrivate::computeTransformOrigin() const -{ - Q_Q(const QmlGraphicsItem); - - QRectF br = q->boundingRect(); - - switch(origin) { - default: - case QmlGraphicsItem::TopLeft: - return QPointF(0, 0); - case QmlGraphicsItem::Top: - return QPointF(br.width() / 2., 0); - case QmlGraphicsItem::TopRight: - return QPointF(br.width(), 0); - case QmlGraphicsItem::Left: - return QPointF(0, br.height() / 2.); - case QmlGraphicsItem::Center: - return QPointF(br.width() / 2., br.height() / 2.); - case QmlGraphicsItem::Right: - return QPointF(br.width(), br.height() / 2.); - case QmlGraphicsItem::BottomLeft: - return QPointF(0, br.height()); - case QmlGraphicsItem::Bottom: - return QPointF(br.width() / 2., br.height()); - case QmlGraphicsItem::BottomRight: - return QPointF(br.width(), br.height()); - } -} - -/*! \internal */ -bool QmlGraphicsItem::sceneEvent(QEvent *event) -{ - bool rv = QGraphicsItem::sceneEvent(event); - - if (event->type() == QEvent::FocusIn || - event->type() == QEvent::FocusOut) { - focusChanged(hasFocus()); - } - - return rv; -} - -/*! \internal */ -QVariant QmlGraphicsItem::itemChange(GraphicsItemChange change, - const QVariant &value) -{ - if (change == ItemParentHasChanged) { - emit parentChanged(); - } - - return QGraphicsItem::itemChange(change, value); -} - -/*! \internal */ -QRectF QmlGraphicsItem::boundingRect() const -{ - Q_D(const QmlGraphicsItem); - return QRectF(0, 0, d->width, d->height); -} - -/*! - \enum QmlGraphicsItem::TransformOrigin - - Controls the point about which simple transforms like scale apply. - - \value TopLeft The top-left corner of the item. - \value Top The center point of the top of the item. - \value TopRight The top-right corner of the item. - \value Left The left most point of the vertical middle. - \value Center The center of the item. - \value Right The right most point of the vertical middle. - \value BottomLeft The bottom-left corner of the item. - \value Bottom The center point of the bottom of the item. - \value BottomRight The bottom-right corner of the item. -*/ - -/*! - Returns the current transform origin. -*/ -QmlGraphicsItem::TransformOrigin QmlGraphicsItem::transformOrigin() const -{ - Q_D(const QmlGraphicsItem); - return d->origin; -} - -/*! - Set the transform \a origin. -*/ -void QmlGraphicsItem::setTransformOrigin(TransformOrigin origin) -{ - Q_D(QmlGraphicsItem); - if (origin != d->origin) { - d->origin = origin; - QGraphicsItem::setTransformOriginPoint(d->computeTransformOrigin()); - } -} - -/*! - \property QmlGraphicsItem::smooth - \brief whether the item is smoothly transformed. - - This property is provided purely for the purpose of optimization. Turning - smooth transforms off is faster, but looks worse; turning smooth - transformations on is slower, but looks better. - - By default smooth transformations are off. -*/ - -/*! - Returns true if the item should be drawn with antialiasing and - smooth pixmap filtering, false otherwise. - - The default is false. - - \sa setSmoothTransform() -*/ -bool QmlGraphicsItem::smoothTransform() const -{ - Q_D(const QmlGraphicsItem); - return d->smooth; -} - -/*! - Sets whether the item should be drawn with antialiasing and - smooth pixmap filtering to \a smooth. - - \sa smoothTransform() -*/ -void QmlGraphicsItem::setSmoothTransform(bool smooth) -{ - Q_D(QmlGraphicsItem); - if (d->smooth == smooth) - return; - d->smooth = smooth; - update(); -} - -qreal QmlGraphicsItem::width() const -{ - Q_D(const QmlGraphicsItem); - return d->width; -} - -void QmlGraphicsItem::setWidth(qreal w) -{ - Q_D(QmlGraphicsItem); - d->widthValid = true; - if (d->width == w) - return; - - qreal oldWidth = d->width; - - prepareGeometryChange(); - d->width = w; - update(); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), oldWidth, height())); -} - -void QmlGraphicsItem::resetWidth() -{ - Q_D(QmlGraphicsItem); - d->widthValid = false; - setImplicitWidth(implicitWidth()); -} - -qreal QmlGraphicsItem::implicitWidth() const -{ - Q_D(const QmlGraphicsItem); - return d->implicitWidth; -} - -void QmlGraphicsItem::setImplicitWidth(qreal w) -{ - Q_D(QmlGraphicsItem); - d->implicitWidth = w; - if (d->width == w || widthValid()) - return; - - qreal oldWidth = d->width; - - prepareGeometryChange(); - d->width = w; - update(); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), oldWidth, height())); -} - -bool QmlGraphicsItem::widthValid() const -{ - Q_D(const QmlGraphicsItem); - return d->widthValid; -} - -qreal QmlGraphicsItem::height() const -{ - Q_D(const QmlGraphicsItem); - return d->height; -} - -void QmlGraphicsItem::setHeight(qreal h) -{ - Q_D(QmlGraphicsItem); - d->heightValid = true; - if (d->height == h) - return; - - qreal oldHeight = d->height; - - prepareGeometryChange(); - d->height = h; - update(); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), width(), oldHeight)); -} - -void QmlGraphicsItem::resetHeight() -{ - Q_D(QmlGraphicsItem); - d->heightValid = false; - setImplicitHeight(implicitHeight()); -} - -qreal QmlGraphicsItem::implicitHeight() const -{ - Q_D(const QmlGraphicsItem); - return d->implicitHeight; -} - -void QmlGraphicsItem::setImplicitHeight(qreal h) -{ - Q_D(QmlGraphicsItem); - d->implicitHeight = h; - if (d->height == h || heightValid()) - return; - - qreal oldHeight = d->height; - - prepareGeometryChange(); - d->height = h; - update(); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), width(), oldHeight)); -} - -bool QmlGraphicsItem::heightValid() const -{ - Q_D(const QmlGraphicsItem); - return d->heightValid; -} - -/*! - \qmlproperty bool Item::wantsFocus - - This property indicates whether the item has has an active focus request. -*/ - -/*! \internal */ -bool QmlGraphicsItem::wantsFocus() const -{ - return focusItem() != 0; -} - -/*! - \qmlproperty bool Item::focus - This property indicates whether the item has keyboard input focus. Set this - property to true to request focus. -*/ - -/*! \internal */ -bool QmlGraphicsItem::hasFocus() const -{ - return QGraphicsItem::hasFocus(); -} - -/*! \internal */ -void QmlGraphicsItem::setFocus(bool focus) -{ - if (focus) - QGraphicsItem::setFocus(Qt::OtherFocusReason); - else - QGraphicsItem::clearFocus(); -} - -/*! - \reimp - \internal -*/ -void QmlGraphicsItem::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) -{ -} - -/*! - \reimp - \internal -*/ -bool QmlGraphicsItem::event(QEvent *ev) -{ - return QGraphicsObject::event(ev); -} - -QDebug operator<<(QDebug debug, QmlGraphicsItem *item) -{ - if (!item) { - debug << "QmlGraphicsItem(0)"; - return debug; - } - - debug << item->metaObject()->className() << "(this =" << ((void*)item) - << ", parent =" << ((void*)item->parentItem()) - << ", geometry =" << QRectF(item->pos(), QSizeF(item->width(), item->height())) - << ", z =" << item->zValue() << ")"; - return debug; -} - -int QmlGraphicsItemPrivate::consistentTime = -1; -void QmlGraphicsItemPrivate::setConsistentTime(int t) -{ - consistentTime = t; -} - -QTime QmlGraphicsItemPrivate::currentTime() -{ - if (consistentTime == -1) - return QTime::currentTime(); - else - return QTime(0, 0).addMSecs(consistentTime); -} - -void QmlGraphicsItemPrivate::start(QTime &t) -{ - t = currentTime(); -} - -int QmlGraphicsItemPrivate::elapsed(QTime &t) -{ - int n = t.msecsTo(currentTime()); - if (n < 0) // passed midnight - n += 86400 * 1000; - return n; -} - -int QmlGraphicsItemPrivate::restart(QTime &t) -{ - QTime time = currentTime(); - int n = t.msecsTo(time); - if (n < 0) // passed midnight - n += 86400*1000; - t = time; - return n; -} - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsKeysAttached) -QML_DECLARE_TYPEINFO(QmlGraphicsKeysAttached, QML_HAS_ATTACHED_PROPERTIES) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Keys,QmlGraphicsKeysAttached) -QML_DECLARE_TYPE(QmlGraphicsKeyNavigationAttached) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,KeyNavigation,QmlGraphicsKeyNavigationAttached) - -#include "moc_qfxitem.cpp" -#include "qfxitem.moc" diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h deleted file mode 100644 index ac094ad..0000000 --- a/src/declarative/fx/qfxitem.h +++ /dev/null @@ -1,238 +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 QFXITEM_H -#define QFXITEM_H - -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlState; -class QmlGraphicsAnchorLine; -class QmlTransition; -class QmlGraphicsKeyEvent; -class QmlGraphicsAnchors; -class QmlGraphicsItemPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsItem : public QGraphicsObject, public QmlParserStatus -{ - Q_OBJECT - Q_INTERFACES(QmlParserStatus) - - Q_PROPERTY(QmlGraphicsItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL) - Q_PROPERTY(QmlList *data READ data DESIGNABLE false) - Q_PROPERTY(QmlList* children READ fxChildren DESIGNABLE false) - Q_PROPERTY(QmlList* resources READ resources DESIGNABLE false) - Q_PROPERTY(QmlList* states READ states DESIGNABLE false) - Q_PROPERTY(QmlList* transitions READ transitions DESIGNABLE false) - Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) - Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL) - Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL) - Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL) - Q_PROPERTY(QmlGraphicsAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL) - Q_PROPERTY(QmlGraphicsAnchorLine left READ left CONSTANT FINAL) - Q_PROPERTY(QmlGraphicsAnchorLine right READ right CONSTANT FINAL) - Q_PROPERTY(QmlGraphicsAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL) - Q_PROPERTY(QmlGraphicsAnchorLine top READ top CONSTANT FINAL) - Q_PROPERTY(QmlGraphicsAnchorLine bottom READ bottom CONSTANT FINAL) - Q_PROPERTY(QmlGraphicsAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL) - Q_PROPERTY(QmlGraphicsAnchorLine baseline READ baseline CONSTANT FINAL) - Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged) - Q_PROPERTY(bool clip READ clip WRITE setClip) // ### move to QGI/QGO, NOTIFY - Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL) - Q_PROPERTY(bool wantsFocus READ wantsFocus NOTIFY wantsFocusChanged) - Q_PROPERTY(QmlList* transform READ transform DESIGNABLE false FINAL) - Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin) - Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform) - Q_PROPERTY(QGraphicsEffect *effect READ graphicsEffect WRITE setGraphicsEffect) - Q_ENUMS(TransformOrigin) - Q_CLASSINFO("DefaultProperty", "data") - -public: - enum TransformOrigin { - TopLeft, Top, TopRight, - Left, Center, Right, - BottomLeft, Bottom, BottomRight - }; - - QmlGraphicsItem(QmlGraphicsItem *parent = 0); - virtual ~QmlGraphicsItem(); - - QmlGraphicsItem *parentItem() const; - void setParentItem(QmlGraphicsItem *parent); - void setParent(QmlGraphicsItem *parent) { setParentItem(parent); } - - QmlList *data(); - QmlList *fxChildren(); - QmlList *resources(); - - QmlGraphicsAnchors *anchors(); - QRectF childrenRect(); - - bool clip() const; - void setClip(bool); - - QmlList* states(); - QmlList* transitions(); - - QString state() const; - void setState(const QString &); - - qreal baselineOffset() const; - void setBaselineOffset(qreal); - - QmlList *transform(); - - qreal width() const; - void setWidth(qreal); - void resetWidth(); - qreal implicitWidth() const; - - qreal height() const; - void setHeight(qreal); - void resetHeight(); - qreal implicitHeight() const; - - TransformOrigin transformOrigin() const; - void setTransformOrigin(TransformOrigin); - - bool smoothTransform() const; - void setSmoothTransform(bool); - - QRectF boundingRect() const; - virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - - bool wantsFocus() const; - bool hasFocus() const; - void setFocus(bool); - - bool keepMouseGrab() const; - void setKeepMouseGrab(bool); - -Q_SIGNALS: - void widthChanged(); - void heightChanged(); - void childrenRectChanged(); - void baselineOffsetChanged(); - void stateChanged(const QString &); - void focusChanged(); - void wantsFocusChanged(); - void parentChanged(); - -protected: - bool isComponentComplete() const; - virtual bool sceneEvent(QEvent *); - virtual bool event(QEvent *); - virtual QVariant itemChange(GraphicsItemChange, const QVariant &); - - void setImplicitWidth(qreal); - bool widthValid() const; // ### better name? - void setImplicitHeight(qreal); - bool heightValid() const; // ### better name? - - virtual void classBegin(); - virtual void componentComplete(); - virtual void focusChanged(bool); - virtual void keyPressEvent(QKeyEvent *event); - virtual void keyReleaseEvent(QKeyEvent *event); - virtual void inputMethodEvent(QInputMethodEvent *); - virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - -protected: - QmlGraphicsItem(QmlGraphicsItemPrivate &dd, QmlGraphicsItem *parent = 0); - -private: - // ### public? - QmlGraphicsAnchorLine left() const; - QmlGraphicsAnchorLine right() const; - QmlGraphicsAnchorLine horizontalCenter() const; - QmlGraphicsAnchorLine top() const; - QmlGraphicsAnchorLine bottom() const; - QmlGraphicsAnchorLine verticalCenter() const; - QmlGraphicsAnchorLine baseline() const; - - friend class QmlStatePrivate; - friend class QmlGraphicsAnchors; - Q_DISABLE_COPY(QmlGraphicsItem) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsItem) -}; - -template - T qobject_cast(QGraphicsObject *o) -{ - QObject *obj = o; - return qobject_cast(obj); -} - -// ### move to QGO -template -T qobject_cast(QGraphicsItem *item) -{ - if (!item) return 0; - QObject *o = item->toGraphicsObject(); - return qobject_cast(o); -} - -QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QmlGraphicsItem *item); - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsItem) -QML_DECLARE_TYPE(QGraphicsTransform) -QML_DECLARE_TYPE(QGraphicsScale) -QML_DECLARE_TYPE(QGraphicsRotation) - -QT_END_HEADER - -#endif // QFXITEM_H diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h deleted file mode 100644 index 87b33be..0000000 --- a/src/declarative/fx/qfxitem_p.h +++ /dev/null @@ -1,245 +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 QFXITEM_P_H -#define QFXITEM_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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QNetworkReply; -class QmlGraphicsItemKeyFilter; - -//### merge into private? -class QmlGraphicsContents : public QObject -{ - Q_OBJECT -public: - QmlGraphicsContents(); - - QRectF rectF() const; - - void setItem(QmlGraphicsItem *item); - -public Q_SLOTS: - void calcHeight(); - void calcWidth(); - -Q_SIGNALS: - void rectChanged(); - -private: - QmlGraphicsItem *m_item; - qreal m_x; - qreal m_y; - qreal m_width; - qreal m_height; -}; - -class QmlGraphicsItemPrivate : public QGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsItem) - -public: - QmlGraphicsItemPrivate() - : _anchors(0), _contents(0), - _baselineOffset(0), - _anchorLines(0), - _stateGroup(0), origin(QmlGraphicsItem::TopLeft), - widthValid(false), heightValid(false), - _componentComplete(true), _keepMouse(false), - smooth(false), keyHandler(0), - width(0), height(0), implicitWidth(0), implicitHeight(0) - {} - ~QmlGraphicsItemPrivate() - { delete _anchors; } - - void init(QmlGraphicsItem *parent) - { - Q_Q(QmlGraphicsItem); - - if (parent) - q->setParentItem(parent); - _baselineOffset.invalidate(); - q->setAcceptedMouseButtons(Qt::NoButton); - q->setFlags(QGraphicsItem::ItemHasNoContents | - QGraphicsItem::ItemIsFocusable | - QGraphicsItem::ItemNegativeZStacksBehindParent); - mouseSetsFocus = false; - } - - QString _id; - - // data property - void data_removeAt(int); - int data_count() const; - void data_append(QObject *); - void data_insert(int, QObject *); - QObject *data_at(int) const; - void data_clear(); - QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QObject *, data) - - // resources property - void resources_removeAt(int); - int resources_count() const; - void resources_append(QObject *); - void resources_insert(int, QObject *); - QObject *resources_at(int) const; - void resources_clear(); - QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QObject *, resources) - - // children property - void children_removeAt(int); - int children_count() const; - void children_append(QmlGraphicsItem *); - void children_insert(int, QmlGraphicsItem *); - QmlGraphicsItem *children_at(int) const; - void children_clear(); - QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QmlGraphicsItem *, children) - - // transform property - void transform_removeAt(int); - int transform_count() const; - void transform_append(QGraphicsTransform *); - void transform_insert(int, QGraphicsTransform *); - QGraphicsTransform *transform_at(int) const; - void transform_clear(); - QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QGraphicsTransform *, transform) - - QmlGraphicsAnchors *anchors() { - if (!_anchors) { - Q_Q(QmlGraphicsItem); - _anchors = new QmlGraphicsAnchors; - _anchors->setItem(q); - if (!_componentComplete) - _anchors->classBegin(); - } - return _anchors; - } - QList dependantAnchors; - QmlGraphicsAnchors *_anchors; - QmlGraphicsContents *_contents; - - QmlNullableValue _baselineOffset; - - struct AnchorLines { - AnchorLines(QmlGraphicsItem *); - QmlGraphicsAnchorLine left; - QmlGraphicsAnchorLine right; - QmlGraphicsAnchorLine hCenter; - QmlGraphicsAnchorLine top; - QmlGraphicsAnchorLine bottom; - QmlGraphicsAnchorLine vCenter; - QmlGraphicsAnchorLine baseline; - }; - mutable AnchorLines *_anchorLines; - AnchorLines *anchorLines() const { - Q_Q(const QmlGraphicsItem); - if (!_anchorLines) _anchorLines = - new AnchorLines(const_cast(q)); - return _anchorLines; - } - - QmlStateGroup *states(); - QmlStateGroup *_stateGroup; - - QmlGraphicsItem::TransformOrigin origin:4; - bool widthValid:1; - bool heightValid:1; - bool _componentComplete:1; - bool _keepMouse:1; - bool smooth:1; - - QmlGraphicsItemKeyFilter *keyHandler; - - qreal width; - qreal height; - qreal implicitWidth; - qreal implicitHeight; - - QPointF computeTransformOrigin() const; - - virtual void setPosHelper(const QPointF &pos) - { - Q_Q(QmlGraphicsItem); - QRectF oldGeometry(this->pos.x(), this->pos.y(), width, height); - QGraphicsItemPrivate::setPosHelper(pos); - q->geometryChanged(QRectF(this->pos.x(), this->pos.y(), width, height), oldGeometry); - } - - // Reimplemented from QGraphicsItemPrivate - virtual void subFocusItemChange() - { - emit q_func()->wantsFocusChanged(); - } - - static int consistentTime; - static QTime currentTime(); - static void Q_DECLARATIVE_EXPORT setConsistentTime(int t); - static void start(QTime &); - static int elapsed(QTime &); - static int restart(QTime &); -}; - -QT_END_NAMESPACE - -#endif // QFXITEM_P_H diff --git a/src/declarative/fx/qfxlayoutitem.cpp b/src/declarative/fx/qfxlayoutitem.cpp deleted file mode 100644 index 201dea2..0000000 --- a/src/declarative/fx/qfxlayoutitem.cpp +++ /dev/null @@ -1,106 +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 "qfxlayoutitem.h" -#include -#include - -QT_BEGIN_NAMESPACE - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,LayoutItem,QmlGraphicsLayoutItem) - -/*! - \qmlclass LayoutItem QmlGraphicsLayoutItem - \brief The LayoutItem element allows you to place your Fluid UI elements inside a classical Qt layout. -*/ - -/*! - \internal - \class QmlGraphicsLayoutItem - \brief The QmlGraphicsLayoutItem class allows you to place your Fluid UI elements inside a classical Qt layout. -*/ - - -/*! - \qmlproperty QSizeF LayoutItem::maximumSize - - The maximumSize property can be set to specify the maximum desired size of this LayoutItem -*/ - -/*! - \qmlproperty QSizeF LayoutItem::minimumSize - - The minimumSize property can be set to specify the minimum desired size of this LayoutItem -*/ - -/*! - \qmlproperty QSizeF LayoutItem::preferredSize - - The preferredSize property can be set to specify the preferred size of this LayoutItem -*/ - -QmlGraphicsLayoutItem::QmlGraphicsLayoutItem(QmlGraphicsItem* parent) - : QmlGraphicsItem(parent), m_maximumSize(INT_MAX,INT_MAX), m_minimumSize(0,0), m_preferredSize(0,0) -{ - setGraphicsItem(this); -} - -void QmlGraphicsLayoutItem::setGeometry(const QRectF & rect) -{ - setX(rect.x()); - setY(rect.y()); - setWidth(rect.width()); - setHeight(rect.height()); -} - -QSizeF QmlGraphicsLayoutItem::sizeHint(Qt::SizeHint w, const QSizeF &constraint) const -{ - Q_UNUSED(constraint); - if(w == Qt::MinimumSize){ - return m_minimumSize; - }else if(w == Qt::MaximumSize){ - return m_maximumSize; - }else{ - return m_preferredSize; - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxlayoutitem.h b/src/declarative/fx/qfxlayoutitem.h deleted file mode 100644 index 35e6e74..0000000 --- a/src/declarative/fx/qfxlayoutitem.h +++ /dev/null @@ -1,93 +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 QFXGRAPHICSLAYOUTITEM_H -#define QFXGRAPHICSLAYOUTITEM_H -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsLayoutItem : public QmlGraphicsItem, public QGraphicsLayoutItem -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayoutItem) - Q_PROPERTY(QSizeF maximumSize READ maximumSize WRITE setMaximumSize NOTIFY maximumSizeChanged) - Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize NOTIFY minimumSizeChanged) - Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize NOTIFY preferredSizeChanged) -public: - QmlGraphicsLayoutItem(QmlGraphicsItem* parent=0); - - QSizeF maximumSize() const { return m_maximumSize; } - void setMaximumSize(const QSizeF &s) { if(s==m_maximumSize) return; m_maximumSize = s; emit maximumSizeChanged(); } - - QSizeF minimumSize() const { return m_minimumSize; } - void setMinimumSize(const QSizeF &s) { if(s==m_minimumSize) return; m_minimumSize = s; emit minimumSizeChanged(); } - - QSizeF preferredSize() const { return m_preferredSize; } - void setPreferredSize(const QSizeF &s) { if(s==m_preferredSize) return; m_preferredSize = s; emit preferredSizeChanged(); } - - virtual void setGeometry(const QRectF & rect); -protected: - virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; - -Q_SIGNALS: - void maximumSizeChanged(); - void minimumSizeChanged(); - void preferredSizeChanged(); - -private: - QSizeF m_maximumSize; - QSizeF m_minimumSize; - QSizeF m_preferredSize; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsLayoutItem) - -QT_END_HEADER -#endif diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp deleted file mode 100644 index f85380a..0000000 --- a/src/declarative/fx/qfxlistview.cpp +++ /dev/null @@ -1,2035 +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/qfxflickable_p.h" -#include "qmleasefollow.h" -#include "qlistmodelinterface.h" -#include "qfxvisualitemmodel.h" -#include "qfxlistview.h" -#include - -#include - -QT_BEGIN_NAMESPACE -class QmlGraphicsListViewAttached : public QObject -{ - Q_OBJECT -public: - QmlGraphicsListViewAttached(QObject *parent) - : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {} - ~QmlGraphicsListViewAttached() { - attachedProperties.remove(parent()); - } - - Q_PROPERTY(QmlGraphicsListView *view READ view CONSTANT) - QmlGraphicsListView *view() { return m_view; } - - Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) - bool isCurrentItem() const { return m_isCurrent; } - void setIsCurrentItem(bool c) { - if (m_isCurrent != c) { - m_isCurrent = c; - emit currentItemChanged(); - } - } - - Q_PROPERTY(QString prevSection READ prevSection NOTIFY prevSectionChanged) - QString prevSection() const { return m_prevSection; } - void setPrevSection(const QString §) { - if (m_prevSection != sect) { - m_prevSection = sect; - emit prevSectionChanged(); - } - } - - Q_PROPERTY(QString section READ section NOTIFY sectionChanged) - QString section() const { return m_section; } - void setSection(const QString §) { - if (m_section != sect) { - m_section = sect; - emit sectionChanged(); - } - } - - Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged) - bool delayRemove() const { return m_delayRemove; } - void setDelayRemove(bool delay) { - if (m_delayRemove != delay) { - m_delayRemove = delay; - emit delayRemoveChanged(); - } - } - - static QmlGraphicsListViewAttached *properties(QObject *obj) { - QmlGraphicsListViewAttached *rv = attachedProperties.value(obj); - if (!rv) { - rv = new QmlGraphicsListViewAttached(obj); - attachedProperties.insert(obj, rv); - } - return rv; - } - - void emitAdd() { emit add(); } - void emitRemove() { emit remove(); } - -Q_SIGNALS: - void currentItemChanged(); - void sectionChanged(); - void prevSectionChanged(); - void delayRemoveChanged(); - void add(); - void remove(); - -public: - QmlGraphicsListView *m_view; - bool m_isCurrent; - mutable QString m_section; - QString m_prevSection; - bool m_delayRemove; - - static QHash attachedProperties; -}; - -QHash QmlGraphicsListViewAttached::attachedProperties; - -//---------------------------------------------------------------------------- - -class FxListItem -{ -public: - FxListItem(QmlGraphicsItem *i, QmlGraphicsListView *v) : item(i), view(v) { - attached = QmlGraphicsListViewAttached::properties(item); - attached->m_view = view; - } - ~FxListItem() {} - - qreal position() const { return (view->orientation() == QmlGraphicsListView::Vertical ? item->y() : item->x()); } - int size() const { return (view->orientation() == QmlGraphicsListView::Vertical ? item->height() : item->width()); } - qreal endPosition() const { - return (view->orientation() == QmlGraphicsListView::Vertical - ? item->y() + (item->height() > 0 ? item->height() : 1) - : item->x() + (item->width() > 0 ? item->width() : 1)) - 1; - } - void setPosition(qreal pos) { - if (view->orientation() == QmlGraphicsListView::Vertical) { - item->setY(pos); - } else { - item->setX(pos); - } - } - - QmlGraphicsItem *item; - QmlGraphicsListView *view; - QmlGraphicsListViewAttached *attached; - int index; -}; - -//---------------------------------------------------------------------------- - -class QmlGraphicsListViewPrivate : public QmlGraphicsFlickablePrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsListView) - -public: - QmlGraphicsListViewPrivate() - : model(0), currentItem(0), orient(QmlGraphicsListView::Vertical) - , visiblePos(0), visibleIndex(0) - , averageSize(100.0), currentIndex(-1), requestedIndex(-1) - , highlightRangeStart(0), highlightRangeEnd(0) - , highlightComponent(0), highlight(0), trackedItem(0) - , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0.0) - , highlightMoveSpeed(400), highlightResizeSpeed(400), highlightRange(QmlGraphicsListView::NoHighlightRange) - , ownModel(false), wrap(false), autoHighlight(true) - , haveHighlightRange(false) - {} - - void init(); - void clear(); - FxListItem *createItem(int modelIndex); - void releaseItem(FxListItem *item); - - FxListItem *visibleItem(int modelIndex) const { - if (modelIndex >= visibleIndex && modelIndex < visibleIndex + visibleItems.count()) { - for (int i = modelIndex - visibleIndex; i < visibleItems.count(); ++i) { - FxListItem *item = visibleItems.at(i); - if (item->index == modelIndex) - return item; - } - } - return 0; - } - - qreal position() const { - Q_Q(const QmlGraphicsListView); - return orient == QmlGraphicsListView::Vertical ? q->viewportY() : q->viewportX(); - } - void setPosition(qreal pos) { - Q_Q(QmlGraphicsListView); - if (orient == QmlGraphicsListView::Vertical) - q->setViewportY(pos); - else - q->setViewportX(pos); - } - qreal size() const { - Q_Q(const QmlGraphicsListView); - return orient == QmlGraphicsListView::Vertical ? q->height() : q->width(); - } - - qreal startPosition() const { - qreal pos = 0; - if (!visibleItems.isEmpty()) { - pos = visibleItems.first()->position(); - if (visibleIndex > 0) - pos -= visibleIndex * (averageSize + spacing) - spacing; - } - return pos; - } - - qreal endPosition() const { - qreal pos = 0; - if (!visibleItems.isEmpty()) { - int invisibleCount = visibleItems.count() - visibleIndex; - for (int i = visibleItems.count()-1; i >= 0; --i) { - if (visibleItems.at(i)->index != -1) { - invisibleCount = model->count() - visibleItems.at(i)->index - 1; - break; - } - } - pos = visibleItems.last()->endPosition() + invisibleCount * (averageSize + spacing); - } - return pos; - } - - qreal positionAt(int modelIndex) const { - if (FxListItem *item = visibleItem(modelIndex)) - return item->position(); - if (!visibleItems.isEmpty()) { - if (modelIndex < visibleIndex) { - int count = visibleIndex - modelIndex; - return visibleItems.first()->position() - count * (averageSize + spacing); - } else { - int idx = visibleItems.count() - 1; - while (idx >= 0 && visibleItems.at(idx)->index == -1) - --idx; - if (idx < 0) - idx = visibleIndex; - else - idx = visibleItems.at(idx)->index; - int count = modelIndex - idx - 1; - return visibleItems.last()->endPosition() + spacing + count * (averageSize + spacing) + 1; - } - } - return 0; - } - - QString sectionAt(int modelIndex) { - Q_Q(QmlGraphicsListView); - if (FxListItem *item = visibleItem(modelIndex)) - return item->attached->section(); - QString section; - if (!sectionExpression.isEmpty()) - section = model->evaluate(modelIndex, sectionExpression, q).toString(); - return section; - } - - bool isValid() const { - return model && model->count() && model->isValid(); - } - - int snapIndex() { - int index = currentIndex; - for (int i = 0; i < visibleItems.count(); ++i) { - FxListItem *item = visibleItems[i]; - if (item->index == -1) - continue; - qreal itemTop = item->position(); - if (itemTop >= highlight->position()-item->size()/2 && itemTop < highlight->position()+item->size()/2) - return item->index; - } - return index; - } - - //XXX Rough. Only works for fixed size items. - qreal snapPosAt(qreal pos) { - return qRound((pos - startPosition()) / averageSize) * averageSize + startPosition(); - } - - int lastVisibleIndex() const { - int lastIndex = -1; - for (int i = visibleItems.count()-1; i >= 0; --i) { - FxListItem *listItem = visibleItems.at(i); - if (listItem->index != -1) { - lastIndex = listItem->index; - break; - } - } - return lastIndex; - } - - // map a model index to visibleItems index. - // These may differ if removed items are still present in the visible list, - // e.g. doing a removal animation - int mapFromModel(int modelIndex) const { - if (modelIndex < visibleIndex || modelIndex >= visibleIndex + visibleItems.count()) - return -1; - for (int i = 0; i < visibleItems.count(); ++i) { - FxListItem *listItem = visibleItems.at(i); - if (listItem->index == modelIndex) - return i + visibleIndex; - if (listItem->index > modelIndex) - return -1; - } - return -1; // Not in visibleList - } - - bool mapRangeFromModel(int &index, int &count) const { - if (index + count < visibleIndex) - return false; - - int lastIndex = -1; - for (int i = visibleItems.count()-1; i >= 0; --i) { - FxListItem *listItem = visibleItems.at(i); - if (listItem->index != -1) { - lastIndex = listItem->index; - break; - } - } - - if (index > lastIndex) - return false; - - int last = qMin(index + count - 1, lastIndex); - index = qMax(index, visibleIndex); - count = last - index + 1; - - return true; - } - - void updateViewport() { - Q_Q(QmlGraphicsListView); - if (orient == QmlGraphicsListView::Vertical) - q->setViewportHeight(endPosition() - startPosition()); - else - q->setViewportWidth(endPosition() - startPosition()); - } - - - // for debugging only - void checkVisible() const { - int skip = 0; - for (int i = 0; i < visibleItems.count(); ++i) { - FxListItem *listItem = visibleItems.at(i); - if (listItem->index == -1) { - ++skip; - } else if (listItem->index != visibleIndex + i - skip) { - qFatal("index %d %d %d", visibleIndex, i, listItem->index); - } - } - } - - void refill(qreal from, qreal to); - void layout(); - void updateUnrequestedIndexes(); - void updateUnrequestedPositions(); - void updateTrackedItem(); - void createHighlight(); - void updateHighlight(); - void updateSections(); - void updateCurrentSection(); - void updateCurrent(int); - void updateAverage(); - void fixupPosition(); - virtual void fixupY(); - virtual void fixupX(); - virtual void flickX(qreal velocity); - virtual void flickY(qreal velocity); - - QmlGraphicsVisualModel *model; - QVariant modelVariant; - QList visibleItems; - QHash unrequestedItems; - FxListItem *currentItem; - QmlGraphicsListView::Orientation orient; - int visiblePos; - int visibleIndex; - qreal averageSize; - int currentIndex; - int requestedIndex; - qreal highlightRangeStart; - qreal highlightRangeEnd; - QmlComponent *highlightComponent; - FxListItem *highlight; - FxListItem *trackedItem; - enum MovementReason { Other, Key, Mouse }; - MovementReason moveReason; - int buffer; - QmlEaseFollow *highlightPosAnimator; - QmlEaseFollow *highlightSizeAnimator; - QString sectionExpression; - QString currentSection; - qreal spacing; - qreal highlightMoveSpeed; - qreal highlightResizeSpeed; - QmlGraphicsListView::HighlightRangeMode highlightRange; - - bool ownModel : 1; - bool wrap : 1; - bool autoHighlight : 1; - bool haveHighlightRange : 1; -}; - -void QmlGraphicsListViewPrivate::init() -{ - Q_Q(QmlGraphicsListView); - q->setFlag(QGraphicsItem::ItemIsFocusScope); - QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(refill())); - QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(refill())); -} - -void QmlGraphicsListViewPrivate::clear() -{ - for (int i = 0; i < visibleItems.count(); ++i) - releaseItem(visibleItems.at(i)); - visibleItems.clear(); - visiblePos = 0; - visibleIndex = 0; - releaseItem(currentItem); - currentItem = 0; - currentIndex = -1; - createHighlight(); - trackedItem = 0; -} - -FxListItem *QmlGraphicsListViewPrivate::createItem(int modelIndex) -{ - Q_Q(QmlGraphicsListView); - // create object - requestedIndex = modelIndex; - FxListItem *listItem = 0; - if (QmlGraphicsItem *item = model->item(modelIndex, false)) { - listItem = new FxListItem(item, q); - listItem->index = modelIndex; - // initialise attached properties - if (!sectionExpression.isEmpty()) { - QmlExpression e(qmlContext(listItem->item), sectionExpression, q); - e.setTrackChange(false); - listItem->attached->m_section = e.value().toString(); - if (modelIndex > 0) { - if (FxListItem *item = visibleItem(modelIndex-1)) - listItem->attached->m_prevSection = item->attached->section(); - else - listItem->attached->m_prevSection = sectionAt(modelIndex-1); - } - } - // complete - model->completeItem(); - listItem->item->setZValue(1); - listItem->item->setParent(q->viewport()); - if (orient == QmlGraphicsListView::Vertical) - QObject::connect(listItem->item, SIGNAL(heightChanged()), q, SLOT(itemResized())); - else - QObject::connect(listItem->item, SIGNAL(widthChanged()), q, SLOT(itemResized())); - } - requestedIndex = -1; - - return listItem; -} - -void QmlGraphicsListViewPrivate::releaseItem(FxListItem *item) -{ - Q_Q(QmlGraphicsListView); - if (!item) - return; - if (trackedItem == item) { - const char *notifier1 = orient == QmlGraphicsListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); - const char *notifier2 = orient == QmlGraphicsListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); - QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); - QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged())); - trackedItem = 0; - } - if (model->release(item->item) == 0) { - // item was not destroyed, and we no longer reference it. - unrequestedItems.insert(item->item, model->indexOf(item->item, q)); - if (orient == QmlGraphicsListView::Vertical) - QObject::disconnect(item->item, SIGNAL(heightChanged()), q, SLOT(itemResized())); - else - QObject::disconnect(item->item, SIGNAL(widthChanged()), q, SLOT(itemResized())); - } - delete item; -} - -void QmlGraphicsListViewPrivate::refill(qreal from, qreal to) -{ - Q_Q(QmlGraphicsListView); - if (!isValid() || !q->isComponentComplete()) - return; - from -= buffer; - to += buffer; - int modelIndex = 0; - qreal itemEnd = visiblePos-1; - if (!visibleItems.isEmpty()) { - visiblePos = visibleItems.first()->position(); - itemEnd = visibleItems.last()->endPosition() + spacing; - int i = visibleItems.count() - 1; - while (i > 0 && visibleItems.at(i)->index == -1) - --i; - modelIndex = visibleItems.at(i)->index + 1; - } - - bool changed = false; - FxListItem *item = 0; - int pos = itemEnd + 1; - while (modelIndex < model->count() && pos <= to) { - //qDebug() << "refill: append item" << modelIndex; - if (!(item = createItem(modelIndex))) - break; - item->setPosition(pos); - pos += item->size() + spacing; - visibleItems.append(item); - ++modelIndex; - changed = true; - } - while (visibleIndex > 0 && visibleIndex <= model->count() && visiblePos > from) { - //qDebug() << "refill: prepend item" << visibleIndex-1 << "current top pos" << visiblePos; - if (!(item = createItem(visibleIndex-1))) - break; - --visibleIndex; - visiblePos -= item->size() + spacing; - item->setPosition(visiblePos); - visibleItems.prepend(item); - changed = true; - } - - while (visibleItems.count() > 1 && (item = visibleItems.first()) && item->endPosition() < from) { - if (item->attached->delayRemove()) - break; - //qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endPosition(); - if (item->index != -1) - visibleIndex++; - visibleItems.removeFirst(); - releaseItem(item); - changed = true; - } - while (visibleItems.count() > 1 && (item = visibleItems.last()) && item->position() > to) { - if (item->attached->delayRemove()) - break; - //qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1; - visibleItems.removeLast(); - releaseItem(item); - changed = true; - } - if (changed) { - if (visibleItems.count()) - visiblePos = visibleItems.first()->position(); - updateAverage(); - if (!sectionExpression.isEmpty()) - updateCurrentSection(); - updateViewport(); - } -} - -void QmlGraphicsListViewPrivate::layout() -{ - Q_Q(QmlGraphicsListView); - if (!visibleItems.isEmpty()) { - int oldEnd = visibleItems.last()->endPosition(); - int pos = visibleItems.first()->endPosition() + spacing + 1; - for (int i=1; i < visibleItems.count(); ++i) { - FxListItem *item = visibleItems.at(i); - item->setPosition(pos); - pos += item->size() + spacing; - } - // move current item if it is after the visible items. - if (currentItem && currentIndex > lastVisibleIndex()) - currentItem->setPosition(currentItem->position() + (visibleItems.last()->endPosition() - oldEnd)); - } - if (!isValid()) - return; - q->refill(); - updateHighlight(); - fixupPosition(); - updateUnrequestedPositions(); - updateViewport(); -} - -void QmlGraphicsListViewPrivate::updateUnrequestedIndexes() -{ - Q_Q(QmlGraphicsListView); - QHash::iterator it; - for (it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) - *it = model->indexOf(it.key(), q); -} - -void QmlGraphicsListViewPrivate::updateUnrequestedPositions() -{ - QHash::const_iterator it; - for (it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) { - if (visibleItem(*it)) - continue; - if (orient == QmlGraphicsListView::Vertical) - it.key()->setY(positionAt(*it)); - else - it.key()->setX(positionAt(*it)); - } -} - -void QmlGraphicsListViewPrivate::updateTrackedItem() -{ - Q_Q(QmlGraphicsListView); - FxListItem *item = currentItem; - if (highlight) - item = highlight; - - FxListItem *oldTracked = trackedItem; - - const char *notifier1 = orient == QmlGraphicsListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); - const char *notifier2 = orient == QmlGraphicsListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); - - if (trackedItem && item != trackedItem) { - QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); - QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged())); - trackedItem = 0; - } - - if (!trackedItem && item) { - trackedItem = item; - QObject::connect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); - QObject::connect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged())); - } - if (trackedItem && trackedItem != oldTracked) - q->trackedPositionChanged(); -} - -void QmlGraphicsListViewPrivate::createHighlight() -{ - Q_Q(QmlGraphicsListView); - if (highlight) { - if (trackedItem == highlight) - trackedItem = 0; - delete highlight->item; - delete highlight; - highlight = 0; - delete highlightPosAnimator; - delete highlightSizeAnimator; - highlightPosAnimator = 0; - highlightSizeAnimator = 0; - } - - if (currentItem) { - QmlGraphicsItem *item = 0; - if (highlightComponent) { - QmlContext *highlightContext = new QmlContext(qmlContext(q)); - QObject *nobj = highlightComponent->create(highlightContext); - if (nobj) { - highlightContext->setParent(nobj); - item = qobject_cast(nobj); - if (!item) { - delete nobj; - } else { - item->setParent(q->viewport()); - } - } else { - delete highlightContext; - } - } else { - item = new QmlGraphicsItem; - item->setParent(q->viewport()); - } - if (item) { - item->setZValue(0); - highlight = new FxListItem(item, q); - if (orient == QmlGraphicsListView::Vertical) - highlight->item->setHeight(currentItem->item->height()); - else - highlight->item->setWidth(currentItem->item->width()); - const QLatin1String posProp(orient == QmlGraphicsListView::Vertical ? "y" : "x"); - highlightPosAnimator = new QmlEaseFollow(q); - highlightPosAnimator->setTarget(QmlMetaProperty(highlight->item, posProp)); - highlightPosAnimator->setVelocity(highlightMoveSpeed); - highlightPosAnimator->setEnabled(autoHighlight); - const QLatin1String sizeProp(orient == QmlGraphicsListView::Vertical ? "height" : "width"); - highlightSizeAnimator = new QmlEaseFollow(q); - highlightSizeAnimator->setVelocity(highlightResizeSpeed); - highlightSizeAnimator->setTarget(QmlMetaProperty(highlight->item, sizeProp)); - highlightSizeAnimator->setEnabled(autoHighlight); - } - } -} - -void QmlGraphicsListViewPrivate::updateHighlight() -{ - if ((!currentItem && highlight) || (currentItem && !highlight)) - createHighlight(); - if (currentItem && autoHighlight && highlight && !moving) { - // auto-update highlight - highlightPosAnimator->setSourceValue(currentItem->position()); - highlightSizeAnimator->setSourceValue(currentItem->size()); - if (orient == QmlGraphicsListView::Vertical) { - if (highlight->item->width() == 0) - highlight->item->setWidth(currentItem->item->width()); - } else { - if (highlight->item->height() == 0) - highlight->item->setHeight(currentItem->item->height()); - } - } - updateTrackedItem(); -} - -void QmlGraphicsListViewPrivate::updateSections() -{ - if (!sectionExpression.isEmpty()) { - QString prevSection; - if (visibleIndex > 0) - prevSection = sectionAt(visibleIndex-1); - for (int i = 0; i < visibleItems.count(); ++i) { - if (visibleItems.at(i)->index != -1) { - QmlGraphicsListViewAttached *attached = visibleItems.at(i)->attached; - attached->setPrevSection(prevSection); - prevSection = attached->section(); - } - } - } -} - -void QmlGraphicsListViewPrivate::updateCurrentSection() -{ - if (sectionExpression.isEmpty() || visibleItems.isEmpty()) { - currentSection = QString(); - return; - } - int index = 0; - while (visibleItems.at(index)->endPosition() < position() && index < visibleItems.count()) - ++index; - - if (index < visibleItems.count()) - currentSection = visibleItems.at(index)->attached->section(); - else - currentSection = visibleItems.first()->attached->section(); -} - -void QmlGraphicsListViewPrivate::updateCurrent(int modelIndex) -{ - Q_Q(QmlGraphicsListView); - if (!isValid() || modelIndex < 0 || modelIndex >= model->count()) { - if (currentItem) { - currentItem->attached->setIsCurrentItem(false); - releaseItem(currentItem); - currentItem = 0; - currentIndex = -1; - updateHighlight(); - emit q->currentIndexChanged(); - } - return; - } - - if (currentItem && currentIndex == modelIndex) { - updateHighlight(); - return; - } - FxListItem *oldCurrentItem = currentItem; - currentIndex = modelIndex; - currentItem = createItem(modelIndex); - if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item)) - oldCurrentItem->attached->setIsCurrentItem(false); - if (currentItem) { - if (modelIndex == visibleIndex - 1) { - // We can calculate exact postion in this case - currentItem->setPosition(visibleItems.first()->position() - currentItem->size() - spacing); - } else { - // Create current item now and position as best we can. - // Its position will be corrected when it becomes visible. - currentItem->setPosition(positionAt(modelIndex)); - } - currentItem->item->setFocus(true); - currentItem->attached->setIsCurrentItem(true); - } - updateHighlight(); - emit q->currentIndexChanged(); - // Release the old current item - releaseItem(oldCurrentItem); -} - -void QmlGraphicsListViewPrivate::updateAverage() -{ - if (!visibleItems.count()) - return; - qreal sum = 0.0; - for (int i = 0; i < visibleItems.count(); ++i) - sum += visibleItems.at(i)->size(); - averageSize = sum / visibleItems.count(); -} - -void QmlGraphicsListViewPrivate::fixupPosition() -{ - if (orient == QmlGraphicsListView::Vertical) - fixupY(); - else - fixupX(); -} - -void QmlGraphicsListViewPrivate::fixupY() -{ - QmlGraphicsFlickablePrivate::fixupY(); - if (orient == QmlGraphicsListView::Horizontal) - return; - - if (haveHighlightRange && highlightRange == QmlGraphicsListView::StrictlyEnforceRange) { - if (currentItem && highlight && currentItem->position() != highlight->position()) { - moveReason = Mouse; - timeline.clear(); - timeline.move(_moveY, -(currentItem->position() - highlightRangeStart), QEasingCurve(QEasingCurve::InOutQuad), 200); - } - } -} - -void QmlGraphicsListViewPrivate::fixupX() -{ - QmlGraphicsFlickablePrivate::fixupX(); - if (orient == QmlGraphicsListView::Vertical) - return; - - if (haveHighlightRange && highlightRange == QmlGraphicsListView::StrictlyEnforceRange) { - if (currentItem && highlight && currentItem->position() != highlight->position()) { - moveReason = Mouse; - timeline.clear(); - timeline.move(_moveX, -(currentItem->position() - highlightRangeStart), QEasingCurve(QEasingCurve::InOutQuad), 200); - } - } -} - -void QmlGraphicsListViewPrivate::flickX(qreal velocity) -{ - Q_Q(QmlGraphicsListView); - - if (!haveHighlightRange || highlightRange != QmlGraphicsListView::StrictlyEnforceRange) { - QmlGraphicsFlickablePrivate::flickX(velocity); - return; - } - - qreal maxDistance = -1; - // -ve velocity means list is moving up - if (velocity > 0) { - if (_moveX.value() < q->minXExtent()) - maxDistance = qAbs(q->minXExtent() -_moveX.value() + (overShoot?30:0)); - flickTargetX = q->minXExtent(); - } else { - if (_moveX.value() > q->maxXExtent()) - maxDistance = qAbs(q->maxXExtent() - _moveX.value()) + (overShoot?30:0); - flickTargetX = q->maxXExtent(); - } - if (maxDistance > 0) { - qreal v = velocity; - if (maxVelocity != -1 && maxVelocity < qAbs(v)) { - if (v < 0) - v = -maxVelocity; - else - v = maxVelocity; - } - qreal accel = deceleration; - qreal v2 = v * v; - qreal maxAccel = v2 / (2.0f * maxDistance); - if (maxAccel < accel) { - // If we are not flicking to the end then attempt to stop exactly on an item boundary - qreal dist = v2 / accel / 2.0; - if (v > 0) - dist = -dist; - dist = -_moveX.value() - snapPosAt(-(_moveX.value() - highlightRangeStart) + dist) + highlightRangeStart; - if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { - timeline.reset(_moveX); - fixupX(); - return; - } - accel = v2 / (2.0f * qAbs(dist)); - } - timeline.reset(_moveX); - timeline.accel(_moveX, v, accel, maxDistance); - timeline.execute(fixupXEvent); - if (!flicked) { - flicked = true; - emit q->flickingChanged(); - emit q->flickStarted(); - } - } else { - timeline.reset(_moveX); - fixupX(); - } -} - -void QmlGraphicsListViewPrivate::flickY(qreal velocity) -{ - Q_Q(QmlGraphicsListView); - - if (!haveHighlightRange || highlightRange != QmlGraphicsListView::StrictlyEnforceRange) { - QmlGraphicsFlickablePrivate::flickY(velocity); - return; - } - - qreal maxDistance = -1; - // -ve velocity means list is moving up - if (velocity > 0) { - if (_moveY.value() < q->minYExtent()) - maxDistance = qAbs(q->minYExtent() -_moveY.value() + (overShoot?30:0)); - flickTargetY = q->minYExtent(); - } else { - if (_moveY.value() > q->maxYExtent()) - maxDistance = qAbs(q->maxYExtent() - _moveY.value()) + (overShoot?30:0); - flickTargetY = q->maxYExtent(); - } - if (maxDistance > 0) { - qreal v = velocity; - if (maxVelocity != -1 && maxVelocity < qAbs(v)) { - if (v < 0) - v = -maxVelocity; - else - v = maxVelocity; - } - qreal accel = deceleration; - qreal v2 = v * v; - qreal maxAccel = v2 / (2.0f * maxDistance); - if (maxAccel < accel) { - // If we are not flicking to the end then attempt to stop exactly on an item boundary - qreal dist = v2 / accel / 2.0; - if (v > 0) - dist = -dist; - dist = -_moveY.value() - snapPosAt(-(_moveY.value() - highlightRangeStart) + dist) + highlightRangeStart; - if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { - timeline.reset(_moveY); - fixupY(); - return; - } - accel = v2 / (2.0f * qAbs(dist)); - } - timeline.reset(_moveY); - timeline.accel(_moveY, v, accel, maxDistance); - timeline.execute(fixupYEvent); - if (!flicked) { - flicked = true; - emit q->flickingChanged(); - emit q->flickStarted(); - } - } else { - timeline.reset(_moveY); - fixupY(); - } -} - -//---------------------------------------------------------------------------- - -/*! - \qmlclass ListView - \inherits Flickable - \brief The ListView item provides a list view of items provided by a model. - - The model is typically provided by a QAbstractListModel "C++ model object", - but can also be created directly in QML. The items are laid out vertically - or horizontally and may be flicked to scroll. - - The below example creates a very simple vertical list, using a QML model. - \image trivialListView.png - - The user interface defines a delegate to display an item, a highlight, - and the ListView which uses the above. - - \snippet doc/src/snippets/declarative/listview/listview.qml 3 - - The model is defined as a ListModel using QML: - \quotefile doc/src/snippets/declarative/listview/dummydata/ContactModel.qml - - In this case ListModel is a handy way for us to test our UI. In practice - the model would be implemented in C++, or perhaps via a SQL data source. -*/ - -QmlGraphicsListView::QmlGraphicsListView(QmlGraphicsItem *parent) - : QmlGraphicsFlickable(*(new QmlGraphicsListViewPrivate), parent) -{ - Q_D(QmlGraphicsListView); - d->init(); -} - -QmlGraphicsListView::~QmlGraphicsListView() -{ - Q_D(QmlGraphicsListView); - d->clear(); - if (d->ownModel) - delete d->model; -} - -/*! - \qmlattachedproperty bool ListView::isCurrentItem - This attched property is true if this delegate is the current item; otherwise false. - - It is attached to each instance of the delegate. - - This property may be used to adjust the appearance of the current item, for example: - - \snippet doc/src/snippets/declarative/listview/highlight.qml 0 -*/ - -/*! - \qmlattachedproperty ListView ListView::view - This attached property holds the view that manages this delegate instance. - - It is attached to each instance of the delegate. -*/ - -/*! - \qmlattachedproperty string ListView::prevSection - This attached property holds the section of the previous element. - - It is attached to each instance of the delegate. - - The section is evaluated using the \l {ListView::sectionExpression}{sectionExpression} property. -*/ - -/*! - \qmlattachedproperty string ListView::section - This attached property holds the section of this element. - - It is attached to each instance of the delegate. - - The section is evaluated using the \l {ListView::sectionExpression}{sectionExpression} property. -*/ - -/*! - \qmlattachedproperty bool ListView::delayRemove - This attached property holds whether the delegate may be destroyed. - - It is attached to each instance of the delegate. - - It is sometimes necessary to delay the destruction of an item - until an animation completes. - - The example below ensures that the animation completes before - the item is removed from the list. - - \code - Component { - id: myDelegate - Item { - id: wrapper - ListView.onRemove: SequentialAnimation { - PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: true } - NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" } - PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: false } - } - } - } - \endcode -*/ - -/*! - \qmlattachedsignal ListView::onAdd() - This attached handler is called immediately after an item is added to the view. -*/ - -/*! - \qmlattachedsignal ListView::onRemove() - This attached handler is called immediately before an item is removed from the view. -*/ - -/*! - \qmlproperty model ListView::model - This property holds the model providing data for the list. - - The model provides a set of data that is used to create the items - for the view. For large or dynamic datasets the model is usually - provided by a C++ model object. The C++ model object must be a \l - {QAbstractItemModel} subclass or a simple list. - - Models can also be created directly in QML, using a \l{ListModel}, - \l{XmlListModel} or \l{VisualItemModel}. - - \sa {qmlmodels}{Data Models} -*/ -QVariant QmlGraphicsListView::model() const -{ - Q_D(const QmlGraphicsListView); - return d->modelVariant; -} - -void QmlGraphicsListView::setModel(const QVariant &model) -{ - Q_D(QmlGraphicsListView); - if (d->model) { - disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); - disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); - disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); - disconnect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); - disconnect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); - } - d->clear(); - d->modelVariant = model; - QObject *object = qvariant_cast(model); - QmlGraphicsVisualModel *vim = 0; - if (object && (vim = qobject_cast(object))) { - if (d->ownModel) { - delete d->model; - d->ownModel = false; - } - d->model = vim; - } else { - if (!d->ownModel) { - d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); - d->ownModel = true; - } - if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) - dataModel->setModel(model); - } - if (d->model) { - if (d->currentIndex >= d->model->count() || d->currentIndex < 0) - setCurrentIndex(0); - else - d->updateCurrent(d->currentIndex); - connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); - connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); - connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); - connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); - connect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); - refill(); - emit countChanged(); - } -} - -/*! - \qmlproperty component ListView::delegate - - The delegate provides a template describing what each item in the view should look and act like. - - Here is an example delegate: - \snippet doc/src/snippets/declarative/listview/listview.qml 0 -*/ -QmlComponent *QmlGraphicsListView::delegate() const -{ - Q_D(const QmlGraphicsListView); - if (d->model) { - if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) - return dataModel->delegate(); - } - - return 0; -} - -void QmlGraphicsListView::setDelegate(QmlComponent *delegate) -{ - Q_D(QmlGraphicsListView); - if (!d->ownModel) { - d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); - d->ownModel = true; - } - if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) { - dataModel->setDelegate(delegate); - d->updateCurrent(d->currentIndex); - refill(); - } -} - -/*! - \qmlproperty int ListView::currentIndex - \qmlproperty Item ListView::currentItem - - \c currentIndex holds the index of the current item. - \c currentItem is the current item. Note that the position of the current item - may only be approximate until it becomes visible in the view. -*/ -int QmlGraphicsListView::currentIndex() const -{ - Q_D(const QmlGraphicsListView); - return d->currentIndex; -} - -void QmlGraphicsListView::setCurrentIndex(int index) -{ - Q_D(QmlGraphicsListView); - d->moveReason = QmlGraphicsListViewPrivate::Other; - if (d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) { - cancelFlick(); - d->updateCurrent(index); - } else { - d->currentIndex = index; - } -} - -QmlGraphicsItem *QmlGraphicsListView::currentItem() -{ - Q_D(QmlGraphicsListView); - if (!d->currentItem) - return 0; - return d->currentItem->item; -} - -/*! - \qmlproperty int ListView::count - This property holds the number of items in the view. -*/ -int QmlGraphicsListView::count() const -{ - Q_D(const QmlGraphicsListView); - if (d->model) - return d->model->count(); - return 0; -} - -/*! - \qmlproperty component ListView::highlight - This property holds the component to use as the highlight. - - An instance of the highlight component will be created for each list. - The geometry of the resultant component instance will be managed by the list - so as to stay with the current item, unless the highlightFollowsCurrentItem - property is false. - - The below example demonstrates how to make a simple highlight - for a vertical list. - - \snippet doc/src/snippets/declarative/listview/listview.qml 1 - \image trivialListView.png - - \sa highlightFollowsCurrentItem -*/ -QmlComponent *QmlGraphicsListView::highlight() const -{ - Q_D(const QmlGraphicsListView); - return d->highlightComponent; -} - -void QmlGraphicsListView::setHighlight(QmlComponent *highlight) -{ - Q_D(QmlGraphicsListView); - delete d->highlightComponent; - d->highlightComponent = highlight; - d->updateCurrent(d->currentIndex); -} - -/*! - \qmlproperty bool ListView::highlightFollowsCurrentItem - This property holds whether the highlight is managed by the view. - - If highlightFollowsCurrentItem is true, the highlight will be moved smoothly - to follow the current item. If highlightFollowsCurrentItem is false, the - highlight will not be moved by the view, and must be implemented - by the highlight. The following example creates a highlight with - its motion defined by the spring \l {SpringFollow}: - - \snippet doc/src/snippets/declarative/listview/highlight.qml 1 - - Note that the highlight animation also affects the way that the view - is scrolled. This is because the view moves to maintain the - highlight within the preferred highlight range (or visible viewport). - - \sa highlight -*/ -bool QmlGraphicsListView::highlightFollowsCurrentItem() const -{ - Q_D(const QmlGraphicsListView); - return d->autoHighlight; -} - -void QmlGraphicsListView::setHighlightFollowsCurrentItem(bool autoHighlight) -{ - Q_D(QmlGraphicsListView); - d->autoHighlight = autoHighlight; - if (d->highlightPosAnimator) { - d->highlightPosAnimator->setEnabled(d->autoHighlight); - d->highlightSizeAnimator->setEnabled(d->autoHighlight); - } - d->updateHighlight(); -} - -/*! - \qmlproperty real ListView::preferredHighlightBegin - \qmlproperty real ListView::preferredHighlightEnd - \qmlproperty bool ListView::highlightRangeMode - - These properties set the preferred range of the highlight (current item) - within the view. - - If highlightRangeMode is set to \e ApplyRange the view will - attempt to maintain the highlight within the range, however - the highlight can move outside of the range at the ends of the list - or due to a mouse interaction. - - If highlightRangeMode is set to \e StrictlyEnforceRange the highlight will never - move outside of the range. This means that the current item will change - if a keyboard or mouse action would cause the highlight to move - outside of the range. - - The default value is \e NoHighlightRange. - - Note that a valid range requires preferredHighlightEnd to be greater - than or equal to preferredHighlightBegin. -*/ -qreal QmlGraphicsListView::preferredHighlightBegin() const -{ - Q_D(const QmlGraphicsListView); - return d->highlightRangeStart; -} - -void QmlGraphicsListView::setPreferredHighlightBegin(qreal start) -{ - Q_D(QmlGraphicsListView); - d->highlightRangeStart = start; - d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; -} - -qreal QmlGraphicsListView::preferredHighlightEnd() const -{ - Q_D(const QmlGraphicsListView); - return d->highlightRangeEnd; -} - -void QmlGraphicsListView::setPreferredHighlightEnd(qreal end) -{ - Q_D(QmlGraphicsListView); - d->highlightRangeEnd = end; - d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; -} - -QmlGraphicsListView::HighlightRangeMode QmlGraphicsListView::highlightRangeMode() const -{ - Q_D(const QmlGraphicsListView); - return d->highlightRange; -} - -void QmlGraphicsListView::setHighlightRangeMode(HighlightRangeMode mode) -{ - Q_D(QmlGraphicsListView); - d->highlightRange = mode; - d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; -} - -/*! - \qmlproperty real ListView::spacing - - This property holds the spacing to leave between items. -*/ -qreal QmlGraphicsListView::spacing() const -{ - Q_D(const QmlGraphicsListView); - return d->spacing; -} - -void QmlGraphicsListView::setSpacing(qreal spacing) -{ - Q_D(QmlGraphicsListView); - if (spacing != d->spacing) { - d->spacing = spacing; - d->layout(); - emit spacingChanged(); - } -} - -/*! - \qmlproperty enumeration ListView::orientation - This property holds the orientation of the list. - - Possible values are \c Vertical (default) and \c Horizontal. - - Vertical Example: - \image trivialListView.png - Horizontal Example: - \image ListViewHorizontal.png -*/ -QmlGraphicsListView::Orientation QmlGraphicsListView::orientation() const -{ - Q_D(const QmlGraphicsListView); - return d->orient; -} - -void QmlGraphicsListView::setOrientation(QmlGraphicsListView::Orientation orientation) -{ - Q_D(QmlGraphicsListView); - if (d->orient != orientation) { - d->orient = orientation; - if (d->orient == QmlGraphicsListView::Vertical) - setViewportWidth(-1); - else - setViewportHeight(-1); - d->clear(); - refill(); - emit orientationChanged(); - d->updateCurrent(d->currentIndex); - } -} - -/*! - \qmlproperty bool ListView::keyNavigationWraps - This property holds whether the list wraps key navigation - - If this property is true then key presses to move off of one end of the list will cause the - current item to jump to the other end. -*/ -bool QmlGraphicsListView::isWrapEnabled() const -{ - Q_D(const QmlGraphicsListView); - return d->wrap; -} - -void QmlGraphicsListView::setWrapEnabled(bool wrap) -{ - Q_D(QmlGraphicsListView); - d->wrap = wrap; -} - -/*! - \qmlproperty int ListView::cacheBuffer - This property holds the number of off-screen pixels to cache. - - This property determines the number of pixels above the top of the list - and below the bottom of the list to cache. Setting this value can make - scrolling the list smoother at the expense of additional memory usage. -*/ -int QmlGraphicsListView::cacheBuffer() const -{ - Q_D(const QmlGraphicsListView); - return d->buffer; -} - -void QmlGraphicsListView::setCacheBuffer(int b) -{ - Q_D(QmlGraphicsListView); - if (d->buffer != b) { - d->buffer = b; - if (isComponentComplete()) - refill(); - } -} - -/*! - \qmlproperty string ListView::sectionExpression - This property holds the expression to be evaluated for the section attached property. - - Each item in the list has attached properties named \c ListView.section and - \c ListView.prevSection. These may be used to place a section header for - related items. The example below assumes that the model is sorted by size of - pet. The section expression is the size property. If \c ListView.section and - \c ListView.prevSection differ, the item will display a section header. - - \snippet examples/declarative/listview/sections.qml 0 - - \image ListViewSections.png -*/ -QString QmlGraphicsListView::sectionExpression() const -{ - Q_D(const QmlGraphicsListView); - return d->sectionExpression; -} - -void QmlGraphicsListView::setSectionExpression(const QString &expression) -{ - Q_D(QmlGraphicsListView); - if (d->sectionExpression != expression) { - d->sectionExpression = expression; - emit sectionExpressionChanged(); - } -} - -QString QmlGraphicsListView::currentSection() const -{ - Q_D(const QmlGraphicsListView); - return d->currentSection; -} - -/*! - \qmlproperty real ListView::highlightMoveSpeed - - This property holds the moving animation speed of the highlight delegate. -*/ -qreal QmlGraphicsListView::highlightMoveSpeed() const -{ - Q_D(const QmlGraphicsListView);\ - return d->highlightMoveSpeed; -} - -void QmlGraphicsListView::setHighlightMoveSpeed(qreal speed) -{ - Q_D(QmlGraphicsListView);\ - if (d->highlightMoveSpeed != speed) - { - d->highlightMoveSpeed = speed; - emit highlightMoveSpeedChanged(); - } -} - -/*! - \qmlproperty real ListView::highlightResizeSpeed - - This property holds the resizing animation speed of the highlight delegate. -*/ -qreal QmlGraphicsListView::highlightResizeSpeed() const -{ - Q_D(const QmlGraphicsListView);\ - return d->highlightResizeSpeed; -} - -void QmlGraphicsListView::setHighlightResizeSpeed(qreal speed) -{ - Q_D(QmlGraphicsListView);\ - if (d->highlightResizeSpeed != speed) - { - d->highlightResizeSpeed = speed; - emit highlightResizeSpeedChanged(); - } -} - -void QmlGraphicsListView::viewportMoved() -{ - Q_D(QmlGraphicsListView); - QmlGraphicsFlickable::viewportMoved(); - refill(); - if (isFlicking() || d->moving) - d->moveReason = QmlGraphicsListViewPrivate::Mouse; - if (d->moveReason == QmlGraphicsListViewPrivate::Mouse) { - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) { - int idx = d->snapIndex(); - if (idx >= 0 && idx != d->currentIndex) - d->updateCurrent(idx); - - qreal pos = d->currentItem->position(); - if (pos > d->position() + d->highlightRangeEnd - 1 - d->highlight->size()) - pos = d->position() + d->highlightRangeEnd - 1 - d->highlight->size(); - if (pos < d->position() + d->highlightRangeStart) - pos = d->position() + d->highlightRangeStart; - d->highlight->setPosition(pos); - } - } -} - -qreal QmlGraphicsListView::minYExtent() const -{ - Q_D(const QmlGraphicsListView); - if (d->orient == QmlGraphicsListView::Horizontal) - return QmlGraphicsFlickable::minYExtent(); - qreal extent = -d->startPosition(); - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) - extent += d->highlightRangeStart; - - return extent; -} - -qreal QmlGraphicsListView::maxYExtent() const -{ - Q_D(const QmlGraphicsListView); - if (d->orient == QmlGraphicsListView::Horizontal) - return QmlGraphicsFlickable::maxYExtent(); - qreal extent; - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) - extent = -(d->positionAt(count()-1) - d->highlightRangeEnd); - else - extent = -(d->endPosition() - height()); - qreal minY = minYExtent(); - if (extent > minY) - extent = minY; - return extent; -} - -qreal QmlGraphicsListView::minXExtent() const -{ - Q_D(const QmlGraphicsListView); - if (d->orient == QmlGraphicsListView::Vertical) - return QmlGraphicsFlickable::minXExtent(); - qreal extent = -d->startPosition(); - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) - extent += d->highlightRangeStart; - - return extent; -} - -qreal QmlGraphicsListView::maxXExtent() const -{ - Q_D(const QmlGraphicsListView); - if (d->orient == QmlGraphicsListView::Vertical) - return QmlGraphicsFlickable::maxXExtent(); - qreal extent; - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) - extent = -(d->positionAt(count()-1) - d->highlightRangeEnd); - else - extent = -(d->endPosition() - width()); - qreal minX = minXExtent(); - if (extent > minX) - extent = minX; - return extent; -} - -void QmlGraphicsListView::keyPressEvent(QKeyEvent *event) -{ - Q_D(QmlGraphicsListView); - QmlGraphicsFlickable::keyPressEvent(event); - if (event->isAccepted()) - return; - - if (d->model && d->model->count() && d->interactive) { - if ((d->orient == QmlGraphicsListView::Horizontal && event->key() == Qt::Key_Left) - || (d->orient == QmlGraphicsListView::Vertical && event->key() == Qt::Key_Up)) { - if (currentIndex() > 0 || (d->wrap && !event->isAutoRepeat())) { - d->moveReason = QmlGraphicsListViewPrivate::Key; - decrementCurrentIndex(); - event->accept(); - return; - } else if (d->wrap) { - event->accept(); - return; - } - } else if ((d->orient == QmlGraphicsListView::Horizontal && event->key() == Qt::Key_Right) - || (d->orient == QmlGraphicsListView::Vertical && event->key() == Qt::Key_Down)) { - if (currentIndex() < d->model->count() - 1 || (d->wrap && !event->isAutoRepeat())) { - d->moveReason = QmlGraphicsListViewPrivate::Key; - incrementCurrentIndex(); - event->accept(); - return; - } else if (d->wrap) { - event->accept(); - return; - } - } - } - d->moveReason = QmlGraphicsListViewPrivate::Other; - event->ignore(); -} - -/*! - \qmlmethod ListView::incrementCurrentIndex - - Increments the current index. The current index will wrap - if keyNavigationWraps is true and it is currently at the end. -*/ -void QmlGraphicsListView::incrementCurrentIndex() -{ - Q_D(QmlGraphicsListView); - if (currentIndex() < d->model->count() - 1 || d->wrap) { - int index = currentIndex()+1; - cancelFlick(); - d->updateCurrent(index < d->model->count() ? index : 0); - } -} - -/*! - \qmlmethod ListView::decrementCurrentIndex - - Decrements the current index. The current index will wrap - if keyNavigationWraps is true and it is currently at the beginning. -*/ -void QmlGraphicsListView::decrementCurrentIndex() -{ - Q_D(QmlGraphicsListView); - if (currentIndex() > 0 || d->wrap) { - int index = currentIndex()-1; - cancelFlick(); - d->updateCurrent(index >= 0 ? index : d->model->count()-1); - } -} - -void QmlGraphicsListView::componentComplete() -{ - Q_D(QmlGraphicsListView); - QmlGraphicsFlickable::componentComplete(); - if (d->currentIndex < 0) - d->updateCurrent(0); - refill(); - d->fixupPosition(); -} - -void QmlGraphicsListView::refill() -{ - Q_D(QmlGraphicsListView); - d->refill(d->position(), d->position()+d->size()-1); -} - -void QmlGraphicsListView::trackedPositionChanged() -{ - Q_D(QmlGraphicsListView); - if (!d->trackedItem) - return; - if (!isFlicking() && !d->moving && d->moveReason != QmlGraphicsListViewPrivate::Mouse) { - const qreal trackedPos = d->trackedItem->position(); - const qreal viewPos = d->position(); - if (d->haveHighlightRange) { - if (d->highlightRange == StrictlyEnforceRange) { - qreal pos = viewPos; - if (trackedPos > pos + d->highlightRangeEnd - d->trackedItem->size()) - pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size(); - if (trackedPos < pos + d->highlightRangeStart) - pos = trackedPos - d->highlightRangeStart; - d->setPosition(pos); - } else { - qreal pos = viewPos; - if (trackedPos < d->startPosition() + d->highlightRangeStart) { - pos = d->startPosition(); - } else if (d->trackedItem->endPosition() > d->endPosition() - d->size() + d->highlightRangeEnd) { - pos = d->endPosition() - d->size(); - } else { - if (trackedPos < viewPos + d->highlightRangeStart) { - pos = trackedPos - d->highlightRangeStart; - } else if (trackedPos > viewPos + d->highlightRangeEnd - d->trackedItem->size()) { - pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size(); - } - } - d->setPosition(pos); - } - } else { - if (trackedPos < viewPos && d->currentItem->position() < viewPos) { - d->setPosition(d->currentItem->position() < trackedPos ? trackedPos : d->currentItem->position()); - d->fixupPosition(); - } else if (d->trackedItem->endPosition() > viewPos + d->size() - && d->currentItem->endPosition() > viewPos + d->size()) { - qreal pos; - if (d->trackedItem->endPosition() < d->currentItem->endPosition()) { - pos = d->trackedItem->endPosition() - d->size(); - if (d->trackedItem->size() > d->size()) - pos = trackedPos; - } else { - pos = d->currentItem->endPosition() - d->size(); - if (d->currentItem->size() > d->size()) - pos = d->currentItem->position(); - } - d->setPosition(pos); - d->fixupPosition(); - } - } - } -} - -void QmlGraphicsListView::itemResized() -{ - Q_D(QmlGraphicsListView); - QmlGraphicsItem *item = qobject_cast(sender()); - if (item) { - d->layout(); - d->fixupPosition(); - } -} - -void QmlGraphicsListView::itemsInserted(int modelIndex, int count) -{ - Q_D(QmlGraphicsListView); - d->updateUnrequestedIndexes(); - if (!d->visibleItems.count() || d->model->count() <= 1) { - d->layout(); - d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); - emit countChanged(); - return; - } - - if (!d->mapRangeFromModel(modelIndex, count)) { - int i = d->visibleItems.count() - 1; - while (i > 0 && d->visibleItems.at(i)->index == -1) - --i; - if (d->visibleItems.at(i)->index + 1 == modelIndex) { - // Special case of appending an item to the model. - modelIndex = d->visibleIndex + d->visibleItems.count(); - } else { - if (modelIndex + count - 1 < d->visibleIndex) { - // Insert before visible items - d->visibleIndex += count; - for (int i = 0; i < d->visibleItems.count(); ++i) { - FxListItem *listItem = d->visibleItems.at(i); - if (listItem->index != -1) - listItem->index += count; - } - } - if (d->currentIndex >= modelIndex) { - // adjust current item index - d->currentIndex += count; - if (d->currentItem) - d->currentItem->index = d->currentIndex; - } - d->layout(); - emit countChanged(); - return; - } - } - - // At least some of the added items will be visible - - int index = modelIndex - d->visibleIndex; - int to = d->buffer+d->position()+d->size()-1; - // index can be the next item past the end of the visible items list (i.e. appended) - int pos = index < d->visibleItems.count() ? d->visibleItems.at(index)->position() - : d->visibleItems.at(index-1)->endPosition()+d->spacing+1; - int initialPos = pos; - QList added; - for (int i = 0; i < count && pos <= to; ++i) { - FxListItem *item = d->createItem(modelIndex + i); - d->visibleItems.insert(index, item); - item->setPosition(pos); - added.append(item); - pos += item->size() + d->spacing; - ++index; - } - if (d->currentIndex >= modelIndex) { - // adjust current item index - d->currentIndex += count; - if (d->currentItem) { - d->currentItem->index = d->currentIndex; - d->currentItem->setPosition(d->currentItem->position() + (pos - initialPos)); - } - } - if (pos > to) { - // We didn't insert all our new items, which means anything - // beyond the current index is not visible - remove it. - while (d->visibleItems.count() > index) - d->releaseItem(d->visibleItems.takeLast()); - } else { - // Update the indexes of the following visible items. - for (; index < d->visibleItems.count(); ++index) { - FxListItem *listItem = d->visibleItems.at(index); - if (listItem->item != d->currentItem->item) - listItem->setPosition(listItem->position() + (pos - initialPos)); - if (listItem->index != -1) - listItem->index += count; - } - } - // everything is in order now - emit add() signal - for (int j = 0; j < added.count(); ++j) - added.at(j)->attached->emitAdd(); - d->updateUnrequestedPositions(); - d->updateViewport(); - emit countChanged(); -} - -void QmlGraphicsListView::itemsRemoved(int modelIndex, int count) -{ - Q_D(QmlGraphicsListView); - d->updateUnrequestedIndexes(); - bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; - if (!d->mapRangeFromModel(modelIndex, count)) { - if (modelIndex + count - 1 < d->visibleIndex) { - // Items removed before our visible items. - d->visibleIndex -= count; - for (int i = 0; i < d->visibleItems.count(); ++i) { - FxListItem *listItem = d->visibleItems.at(i); - if (listItem->index != -1) - listItem->index -= count; - } - } - if (d->currentIndex >= modelIndex + count) { - d->currentIndex -= count; - if (d->currentItem) - d->currentItem->index -= count; - } else if (currentRemoved) { - // current item has been removed. - d->releaseItem(d->currentItem); - d->currentItem = 0; - d->currentIndex = -1; - d->updateCurrent(qMin(modelIndex, d->model->count()-1)); - } - d->layout(); - d->updateSections(); - emit countChanged(); - return; - } - - // Remove the items from the visible list, skipping anything already marked for removal - QList::Iterator it = d->visibleItems.begin(); - while (it != d->visibleItems.end()) { - FxListItem *item = *it; - if (item->index == -1 || item->index < modelIndex) { - // already removed, or before removed items - ++it; - } else if (item->index >= modelIndex + count) { - // after removed items - item->index -= count; - ++it; - } else { - // removed item - item->attached->emitRemove(); - if (item->attached->delayRemove()) { - item->index = -1; - connect(item->attached, SIGNAL(delayRemoveChanged()), this, SLOT(destroyRemoved()), Qt::QueuedConnection); - ++it; - } else { - it = d->visibleItems.erase(it); - d->releaseItem(item); - } - } - } - - // fix current - if (d->currentIndex >= modelIndex + count) { - d->currentIndex -= count; - if (d->currentItem) - d->currentItem->index -= count; - } else if (currentRemoved) { - // current item has been removed. - d->currentItem->attached->setIsCurrentItem(false); - d->releaseItem(d->currentItem); - d->currentItem = 0; - d->currentIndex = -1; - d->updateCurrent(qMin(modelIndex, d->model->count()-1)); - } - - // update visibleIndex - for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { - if ((*it)->index != -1) { - d->visibleIndex = (*it)->index; - break; - } - } - - if (d->visibleItems.isEmpty()) { - d->visibleIndex = 0; - d->visiblePos = 0; - d->timeline.clear(); - d->setPosition(0); - if (d->model->count() == 0) - update(); - else - refill(); - } else { - // Correct the positioning of the items - d->layout(); - d->updateSections(); - } - - emit countChanged(); -} - -void QmlGraphicsListView::destroyRemoved() -{ - Q_D(QmlGraphicsListView); - for (QList::Iterator it = d->visibleItems.begin(); - it != d->visibleItems.end();) { - FxListItem *listItem = *it; - if (listItem->index == -1 && listItem->attached->delayRemove() == false) { - d->releaseItem(listItem); - it = d->visibleItems.erase(it); - } else { - ++it; - } - } - - // Correct the positioning of the items - d->layout(); -} - -void QmlGraphicsListView::itemsMoved(int from, int to, int count) -{ - Q_D(QmlGraphicsListView); - qreal firstItemPos = d->visibleItems.first()->position(); - QHash moved; - int moveBy = 0; - - QList::Iterator it = d->visibleItems.begin(); - while (it != d->visibleItems.end()) { - FxListItem *item = *it; - if (item->index >= from && item->index < from + count) { - // take the items that are moving - item->index += (to-from); - moved.insert(item->index, item); - moveBy += item->size(); - it = d->visibleItems.erase(it); - } else { - // move everything after the moved items. - if (item->index > from && item->index != -1) - item->index -= count; - ++it; - } - } - - int remaining = count; - int endIndex = d->visibleIndex; - it = d->visibleItems.begin(); - while (it != d->visibleItems.end()) { - FxListItem *item = *it; - if (remaining && item->index >= to && item->index < to + count) { - // place items in the target position, reusing any existing items - FxListItem *movedItem = moved.take(item->index); - if (!movedItem) - movedItem = d->createItem(item->index); - it = d->visibleItems.insert(it, movedItem); - ++it; - --remaining; - } else { - if (item->index != -1) { - if (item->index >= to) { - // update everything after the moved items. - item->index += count; - } - endIndex = item->index; - } - ++it; - } - } - - // If we have moved items to the end of the visible items - // then add any existing moved items that we have - while (FxListItem *item = moved.take(endIndex+1)) { - d->visibleItems.append(item); - ++endIndex; - } - - // Whatever moved items remain are no longer visible items. - while (moved.count()) - d->releaseItem(moved.take(moved.begin().key())); - - // Ensure we don't cause an ugly list scroll. - d->visibleItems.first()->setPosition(firstItemPos); - - d->layout(); -} - -void QmlGraphicsListView::createdItem(int index, QmlGraphicsItem *item) -{ - Q_D(QmlGraphicsListView); - if (d->requestedIndex != index) { - item->setParentItem(viewport()); - d->unrequestedItems.insert(item, index); - if (d->orient == QmlGraphicsListView::Vertical) - item->setY(d->positionAt(index)); - else - item->setX(d->positionAt(index)); - } -} - -void QmlGraphicsListView::destroyingItem(QmlGraphicsItem *item) -{ - Q_D(QmlGraphicsListView); - d->unrequestedItems.remove(item); -} - -QmlGraphicsListViewAttached *QmlGraphicsListView::qmlAttachedProperties(QObject *obj) -{ - return QmlGraphicsListViewAttached::properties(obj); -} - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ListView,QmlGraphicsListView) - -QT_END_NAMESPACE -#include "qfxlistview.moc" diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h deleted file mode 100644 index 19e88c7..0000000 --- a/src/declarative/fx/qfxlistview.h +++ /dev/null @@ -1,186 +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 QFXLISTVIEW_H -#define QFXLISTVIEW_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QmlGraphicsVisualModel; -class QmlGraphicsListViewAttached; -class QmlGraphicsListViewPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable -{ - Q_OBJECT - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsListView) - - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) - Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) - - Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin) - Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd) - Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode) - - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) - Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) - Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) - Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) - Q_PROPERTY(QString sectionExpression READ sectionExpression WRITE setSectionExpression NOTIFY sectionExpressionChanged) - Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) - - Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) - Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) - Q_ENUMS(HighlightRangeMode) - Q_ENUMS(Orientation) - Q_CLASSINFO("DefaultProperty", "data") - -public: - QmlGraphicsListView(QmlGraphicsItem *parent=0); - ~QmlGraphicsListView(); - - QVariant model() const; - void setModel(const QVariant &); - - QmlComponent *delegate() const; - void setDelegate(QmlComponent *); - - int currentIndex() const; - void setCurrentIndex(int idx); - - QmlGraphicsItem *currentItem(); - int count() const; - - QmlComponent *highlight() const; - void setHighlight(QmlComponent *highlight); - - bool highlightFollowsCurrentItem() const; - void setHighlightFollowsCurrentItem(bool); - - enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange }; - HighlightRangeMode highlightRangeMode() const; - void setHighlightRangeMode(HighlightRangeMode mode); - - qreal preferredHighlightBegin() const; - void setPreferredHighlightBegin(qreal); - - qreal preferredHighlightEnd() const; - void setPreferredHighlightEnd(qreal); - - qreal spacing() const; - void setSpacing(qreal spacing); - - enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical }; - Orientation orientation() const; - void setOrientation(Orientation); - - bool isWrapEnabled() const; - void setWrapEnabled(bool); - - int cacheBuffer() const; - void setCacheBuffer(int); - - QString sectionExpression() const; - void setSectionExpression(const QString &); - QString currentSection() const; - - qreal highlightMoveSpeed() const; - void setHighlightMoveSpeed(qreal); - - qreal highlightResizeSpeed() const; - void setHighlightResizeSpeed(qreal); - - static QmlGraphicsListViewAttached *qmlAttachedProperties(QObject *); - -public Q_SLOTS: - void incrementCurrentIndex(); - void decrementCurrentIndex(); - -Q_SIGNALS: - void countChanged(); - void spacingChanged(); - void orientationChanged(); - void currentIndexChanged(); - void currentSectionChanged(); - void sectionExpressionChanged(); - void highlightMoveSpeedChanged(); - void highlightResizeSpeedChanged(); - -protected: - virtual void viewportMoved(); - virtual qreal minYExtent() const; - virtual qreal maxYExtent() const; - virtual qreal minXExtent() const; - virtual qreal maxXExtent() const; - virtual void keyPressEvent(QKeyEvent *); - virtual void componentComplete(); - -private Q_SLOTS: - void refill(); - void trackedPositionChanged(); - void itemResized(); - void itemsInserted(int index, int count); - void itemsRemoved(int index, int count); - void itemsMoved(int from, int to, int count); - void destroyRemoved(); - void createdItem(int index, QmlGraphicsItem *item); - void destroyingItem(QmlGraphicsItem *item); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPEINFO(QmlGraphicsListView, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QmlGraphicsListView) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qfxloader.cpp b/src/declarative/fx/qfxloader.cpp deleted file mode 100644 index af51282..0000000 --- a/src/declarative/fx/qfxloader.cpp +++ /dev/null @@ -1,390 +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 "qfxloader_p.h" -#include - -QT_BEGIN_NAMESPACE - -QmlGraphicsLoaderPrivate::QmlGraphicsLoaderPrivate() -: item(0), component(0), ownComponent(false), resizeMode(QmlGraphicsLoader::SizeLoaderToItem) -{ -} - -QmlGraphicsLoaderPrivate::~QmlGraphicsLoaderPrivate() -{ -} - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QmlGraphicsLoader) - -/*! - \qmlclass Loader - \inherits Item - - \brief The Loader item allows dynamically loading an Item-based - subtree from a QML URL or Component. - - Loader instantiates an item from a component. The component to - instantiate may be specified directly by the \c sourceComponent - property, or loaded from a URL via the \c source property. - - It is also an effective means of delaying the creation of a component - until it is required: - \code - Loader { id: pageLoader } - Rectangle { - MouseRegion { anchors.fill: parent; onClicked: pageLoader.source = "Page1.qml" } - } - \endcode -*/ - -/*! - \internal - \class QmlGraphicsLoader - \qmlclass Loader - */ - -/*! - Create a new QmlGraphicsLoader instance. - */ -QmlGraphicsLoader::QmlGraphicsLoader(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsLoaderPrivate), parent) -{ -} - -/*! - Destroy the loader instance. - */ -QmlGraphicsLoader::~QmlGraphicsLoader() -{ -} - -/*! - \qmlproperty url Loader::source - This property holds the URL of the QML component to - instantiate. - - \sa status, progress -*/ -QUrl QmlGraphicsLoader::source() const -{ - Q_D(const QmlGraphicsLoader); - return d->source; -} - -void QmlGraphicsLoader::setSource(const QUrl &url) -{ - Q_D(QmlGraphicsLoader); - if (d->source == url) - return; - - if (d->ownComponent) { - delete d->component; - d->component = 0; - } - delete d->item; - d->item = 0; - - d->source = url; - if (d->source.isEmpty()) { - emit sourceChanged(); - emit statusChanged(); - emit progressChanged(); - emit itemChanged(); - return; - } - - d->component = new QmlComponent(qmlEngine(this), d->source, this); - d->ownComponent = true; - if (!d->component->isLoading()) { - d->_q_sourceLoaded(); - } else { - connect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), - this, SLOT(_q_sourceLoaded())); - connect(d->component, SIGNAL(progressChanged(qreal)), - this, SIGNAL(progressChanged())); - emit statusChanged(); - emit progressChanged(); - emit sourceChanged(); - emit itemChanged(); - } -} - -/*! - \qmlproperty Component Loader::sourceComponent - The sourceComponent property holds the \l{Component} to instantiate. - - \qml - Item { - Component { - id: redSquare - Rectangle { color: "red"; width: 10; height: 10 } - } - - Loader { sourceComponent: redSquare } - Loader { sourceComponent: redSquare; x: 10 } - } - \endqml - - \sa source -*/ - -QmlComponent *QmlGraphicsLoader::sourceComponent() const -{ - Q_D(const QmlGraphicsLoader); - return d->component; -} - -void QmlGraphicsLoader::setSourceComponent(QmlComponent *comp) -{ - Q_D(QmlGraphicsLoader); - if (comp == d->component) - return; - - d->source = QUrl(); - if (d->ownComponent) { - delete d->component; - d->component = 0; - } - delete d->item; - d->item = 0; - - d->component = comp; - d->ownComponent = false; - if (!d->component) { - emit sourceChanged(); - emit statusChanged(); - emit progressChanged(); - emit itemChanged(); - return; - } - - if (!d->component->isLoading()) { - d->_q_sourceLoaded(); - } else { - connect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), - this, SLOT(_q_sourceLoaded())); - connect(d->component, SIGNAL(progressChanged(qreal)), - this, SIGNAL(progressChanged())); - emit progressChanged(); - emit sourceChanged(); - emit statusChanged(); - emit itemChanged(); - } -} - -void QmlGraphicsLoaderPrivate::_q_sourceLoaded() -{ - Q_Q(QmlGraphicsLoader); - - if (component) { - QmlContext *ctxt = new QmlContext(qmlContext(q)); - ctxt->addDefaultObject(q); - - if (!component->errors().isEmpty()) { - qWarning() << component->errors(); - emit q->sourceChanged(); - emit q->statusChanged(); - emit q->progressChanged(); - return; - } - - QObject *obj = component->create(ctxt); - if (obj) { - item = qobject_cast(obj); - if (item) { - item->setParentItem(q); -// item->setFocus(true); - QmlGraphicsItem *resizeItem = 0; - if (resizeMode == QmlGraphicsLoader::SizeLoaderToItem) - resizeItem = item; - else if (resizeMode == QmlGraphicsLoader::SizeItemToLoader) - resizeItem = q; - if (resizeItem) { - QObject::connect(resizeItem, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); - QObject::connect(resizeItem, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); - } - _q_updateSize(); - } - } else { - delete obj; - source = QUrl(); - } - emit q->sourceChanged(); - emit q->statusChanged(); - emit q->progressChanged(); - emit q->itemChanged(); - } -} - -/*! - \qmlproperty enum Loader::status - - This property holds the status of QML loading. It can be one of: - \list - \o Null - no QML source has been set - \o Ready - the QML source has been loaded - \o Loading - the QML source is currently being loaded - \o Error - an error occurred while loading the QML source - \endlist - - \sa progress -*/ - -QmlGraphicsLoader::Status QmlGraphicsLoader::status() const -{ - Q_D(const QmlGraphicsLoader); - - if (d->component) - return static_cast(d->component->status()); - - if (d->item) - return Ready; - - return d->source.isEmpty() ? Null : Error; -} - -/*! - \qmlproperty real Loader::progress - - This property holds the progress of QML data loading, from 0.0 (nothing loaded) - to 1.0 (finished). - - \sa status -*/ -qreal QmlGraphicsLoader::progress() const -{ - Q_D(const QmlGraphicsLoader); - - if (d->item) - return 1.0; - - if (d->component) - return d->component->progress(); - - return 0.0; -} - -/*! - \qmlproperty enum Loader::resizeMode - - This property determines how the Loader or item are resized: - \list - \o NoResize - no item will be resized - \o SizeLoaderToItem - the Loader will be sized to the size of the item, unless the size of the Loader has been otherwise specified. - \o SizeItemToLoader - the item will be sized to the size of the Loader. - \endlist - - The default resizeMode is SizeLoaderToItem. -*/ -QmlGraphicsLoader::ResizeMode QmlGraphicsLoader::resizeMode() const -{ - Q_D(const QmlGraphicsLoader); - return d->resizeMode; -} - -void QmlGraphicsLoader::setResizeMode(ResizeMode mode) -{ - Q_D(QmlGraphicsLoader); - if (mode == d->resizeMode) - return; - - if (d->item) { - QmlGraphicsItem *resizeItem = 0; - if (d->resizeMode == SizeLoaderToItem) - resizeItem = d->item; - else if (d->resizeMode == SizeItemToLoader) - resizeItem = this; - if (resizeItem) { - disconnect(resizeItem, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); - disconnect(resizeItem, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); - } - } - - d->resizeMode = mode; - - if (d->item) { - QmlGraphicsItem *resizeItem = 0; - if (d->resizeMode == SizeLoaderToItem) - resizeItem = d->item; - else if (d->resizeMode == SizeItemToLoader) - resizeItem = this; - if (resizeItem) { - connect(resizeItem, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); - connect(resizeItem, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); - } - - d->_q_updateSize(); - } -} - -void QmlGraphicsLoaderPrivate::_q_updateSize() -{ - Q_Q(QmlGraphicsLoader); - if (!item) - return; - switch (resizeMode) { - case QmlGraphicsLoader::SizeLoaderToItem: - q->setImplicitWidth(item->width()); - q->setImplicitHeight(item->height()); - break; - case QmlGraphicsLoader::SizeItemToLoader: - item->setWidth(q->width()); - item->setHeight(q->height()); - break; - default: - break; - } -} - -/*! - \qmlproperty Item Loader::item - This property holds the top-level item created from source. -*/ -QmlGraphicsItem *QmlGraphicsLoader::item() const -{ - Q_D(const QmlGraphicsLoader); - return d->item; -} - -QT_END_NAMESPACE - -#include "moc_qfxloader.cpp" diff --git a/src/declarative/fx/qfxloader.h b/src/declarative/fx/qfxloader.h deleted file mode 100644 index b838ed0..0000000 --- a/src/declarative/fx/qfxloader.h +++ /dev/null @@ -1,107 +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 QFXLOADER_H -#define QFXLOADER_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsLoaderPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsLoader : public QmlGraphicsItem -{ - Q_OBJECT - Q_ENUMS(Status) - Q_ENUMS(ResizeMode) - - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(QmlComponent *sourceComponent READ sourceComponent WRITE setSourceComponent NOTIFY sourceChanged) - Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) - Q_PROPERTY(QmlGraphicsItem *item READ item NOTIFY itemChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - //### sourceItem - -public: - QmlGraphicsLoader(QmlGraphicsItem *parent=0); - virtual ~QmlGraphicsLoader(); - - QUrl source() const; - void setSource(const QUrl &); - - QmlComponent *sourceComponent() const; - void setSourceComponent(QmlComponent *); - - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - - enum ResizeMode { NoResize, SizeLoaderToItem, SizeItemToLoader }; - ResizeMode resizeMode() const; - void setResizeMode(ResizeMode mode); - - QmlGraphicsItem *item() const; - -Q_SIGNALS: - void itemChanged(); - void sourceChanged(); - void statusChanged(); - void progressChanged(); - -private: - Q_DISABLE_COPY(QmlGraphicsLoader) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsLoader) - Q_PRIVATE_SLOT(d_func(), void _q_sourceLoaded()) - Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsLoader) - -QT_END_HEADER - -#endif // QFXLOADER_H diff --git a/src/declarative/fx/qfxloader_p.h b/src/declarative/fx/qfxloader_p.h deleted file mode 100644 index 336c884..0000000 --- a/src/declarative/fx/qfxloader_p.h +++ /dev/null @@ -1,82 +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 QFXLOADER_P_H -#define QFXLOADER_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 "qfxitem_p.h" -#include "qfxloader.h" - -QT_BEGIN_NAMESPACE - -class QmlContext; -class QmlGraphicsLoaderPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsLoader) - -public: - QmlGraphicsLoaderPrivate(); - ~QmlGraphicsLoaderPrivate(); - - QUrl source; - QmlGraphicsItem *item; - QmlComponent *component; - bool ownComponent; - QmlGraphicsLoader::ResizeMode resizeMode; - - void _q_sourceLoaded(); - void _q_updateSize(); -}; - -QT_END_NAMESPACE - -#endif // QFXLOADER_P_H diff --git a/src/declarative/fx/qfxmouseregion.cpp b/src/declarative/fx/qfxmouseregion.cpp deleted file mode 100644 index 8acf32c..0000000 --- a/src/declarative/fx/qfxmouseregion.cpp +++ /dev/null @@ -1,649 +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 "qfxmouseregion.h" -#include "qfxmouseregion_p.h" -#include "qfxevents_p.h" -#include - - -QT_BEGIN_NAMESPACE -static const qreal DragThreshold = 5; -static const int PressAndHoldDelay = 800; - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Drag,QmlGraphicsDrag) -QmlGraphicsDrag::QmlGraphicsDrag(QObject *parent) -: QObject(parent), _target(0), _axis(XandYAxis), _xmin(0), _xmax(0), _ymin(0), _ymax(0) -{ -} - -QmlGraphicsDrag::~QmlGraphicsDrag() -{ -} - -QmlGraphicsItem *QmlGraphicsDrag::target() const -{ - return _target; -} - -void QmlGraphicsDrag::setTarget(QmlGraphicsItem *t) -{ - _target = t; -} - -QmlGraphicsDrag::Axis QmlGraphicsDrag::axis() const -{ - return _axis; -} - -void QmlGraphicsDrag::setAxis(QmlGraphicsDrag::Axis a) -{ - _axis = a; -} - -qreal QmlGraphicsDrag::xmin() const -{ - return _xmin; -} - -void QmlGraphicsDrag::setXmin(qreal m) -{ - _xmin = m; -} - -qreal QmlGraphicsDrag::xmax() const -{ - return _xmax; -} - -void QmlGraphicsDrag::setXmax(qreal m) -{ - _xmax = m; -} - -qreal QmlGraphicsDrag::ymin() const -{ - return _ymin; -} - -void QmlGraphicsDrag::setYmin(qreal m) -{ - _ymin = m; -} - -qreal QmlGraphicsDrag::ymax() const -{ - return _ymax; -} - -void QmlGraphicsDrag::setYmax(qreal m) -{ - _ymax = m; -} - -/*! - \qmlclass MouseRegion - \brief The MouseRegion item enables simple mouse handling. - \inherits Item - - A MouseRegion is typically used in conjunction with a visible item, - where the MouseRegion effectively 'proxies' mouse handling for that - item. For example, we can put a MouseRegion in a Rectangle that changes - the Rectangle color to red when clicked: - \snippet doc/src/snippets/declarative/mouseregion.qml 0 - - Many MouseRegion signals pass a \l {MouseEvent}{mouse} parameter that contains - additional information about the mouse event, such as the position, button, - and any key modifiers. - - Below we have the previous - example extended so as to give a different color when you right click. - \snippet doc/src/snippets/declarative/mouseregion.qml 1 - - For basic key handling, see the \l {Keys}{Keys attached property}. - - MouseRegion is an invisible item: it is never painted. - - \sa MouseEvent -*/ - -/*! - \qmlsignal MouseRegion::onEntered - - This handler is called when the mouse enters the mouse region. -*/ - -/*! - \qmlsignal MouseRegion::onExited - - This handler is called when the mouse exists the mouse region. -*/ - -/*! - \qmlsignal MouseRegion::onPositionChanged(mouse) - - This handler is called when the mouse position changes. - - The \l {MouseEvent}{mouse} parameter provides information about the mouse, including the x and y - position, and any buttons currently pressed. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. -*/ - -/*! - \qmlsignal MouseRegion::onClicked(mouse) - - This handler is called when there is a click. A click is defined as a press followed by a release, - both inside the MouseRegion (pressing, moving outside the MouseRegion, and then moving back inside and - releasing is also considered a click). - - The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y - position of the release of the click, and whether the click wasHeld. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. -*/ - -/*! - \qmlsignal MouseRegion::onPressed(mouse) - - This handler is called when there is a press. - The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y - position and which button was pressed. - - The \e accepted property of the MouseEvent parameter determines whether this MouseRegion - will handle the press and all future mouse events until release. The default is to accept - the event and not allow other MouseRegions beneath this one to handle the event. If \e accepted - is set to false, no further events will be sent to this MouseRegion until the button is next - pressed. -*/ - -/*! - \qmlsignal MouseRegion::onReleased(mouse) - - This handler is called when there is a release. - The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y - position of the release of the click, and whether the click wasHeld. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. -*/ - -/*! - \qmlsignal MouseRegion::onPressAndHold(mouse) - - This handler is called when there is a long press (currently 800ms). - The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y - position of the press, and which button is pressed. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. -*/ - -/*! - \qmlsignal MouseRegion::onDoubleClicked(mouse) - - This handler is called when there is a double-click (a press followed by a release followed by a press). - The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y - position of the release of the click, and whether the click wasHeld. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. -*/ - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,MouseRegion,QmlGraphicsMouseRegion) - -/*! - \internal - \class QmlGraphicsMouseRegion - \brief The QmlGraphicsMouseRegion class provides a simple mouse handling abstraction for use within Qml. - - \ingroup group_coreitems - - All QmlGraphicsItem derived classes can do mouse handling but the QmlGraphicsMouseRegion class exposes mouse - handling data as properties and tracks flicking and dragging of the mouse. - - A QmlGraphicsMouseRegion object can be instantiated in Qml using the tag \l MouseRegion. - */ -QmlGraphicsMouseRegion::QmlGraphicsMouseRegion(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsMouseRegionPrivate), parent) -{ - Q_D(QmlGraphicsMouseRegion); - d->init(); -} - -QmlGraphicsMouseRegion::QmlGraphicsMouseRegion(QmlGraphicsMouseRegionPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ - Q_D(QmlGraphicsMouseRegion); - d->init(); -} - -QmlGraphicsMouseRegion::~QmlGraphicsMouseRegion() -{ -} - -/*! - \qmlproperty real MouseRegion::mouseX - \qmlproperty real MouseRegion::mouseY - These properties hold the coordinates of the mouse. - - If the hoverEnabled property is false then these properties will only be valid - while a button is pressed, and will remain valid as long as the button is held - even if the mouse is moved outside the region. - - If hoverEnabled is true then these properties will be valid: - \list - \i when no button is pressed, but the mouse is within the MouseRegion (containsMouse is true). - \i if a button is pressed and held, even if it has since moved out of the region. - \endlist - - The coordinates are relative to the MouseRegion. -*/ -qreal QmlGraphicsMouseRegion::mouseX() const -{ - Q_D(const QmlGraphicsMouseRegion); - return d->lastPos.x(); -} - -qreal QmlGraphicsMouseRegion::mouseY() const -{ - Q_D(const QmlGraphicsMouseRegion); - return d->lastPos.y(); -} - -/*! - \qmlproperty bool MouseRegion::enabled - This property holds whether the item accepts mouse events. -*/ -bool QmlGraphicsMouseRegion::isEnabled() const -{ - Q_D(const QmlGraphicsMouseRegion); - return d->absorb; -} - -void QmlGraphicsMouseRegion::setEnabled(bool a) -{ - Q_D(QmlGraphicsMouseRegion); - if (a != d->absorb) { - d->absorb = a; - emit enabledChanged(); - } -} -/*! - \qmlproperty MouseButtons MouseRegion::pressedButtons - This property holds the mouse buttons currently pressed. - - It contains a bitwise combination of: - \list - \o Qt.LeftButton - \o Qt.RightButton - \o Qt.MidButton - \endlist - - The code below displays "right" when the right mouse buttons is pressed: - \code - Text { - text: mr.pressedButtons & Qt.RightButton ? "right" : "" - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - MouseRegion { - id: mr - acceptedButtons: Qt.LeftButton | Qt.RightButton - anchors.fill: parent - } - } - \endcode - - \sa acceptedButtons -*/ -Qt::MouseButtons QmlGraphicsMouseRegion::pressedButtons() const -{ - Q_D(const QmlGraphicsMouseRegion); - return d->lastButtons; -} - -void QmlGraphicsMouseRegion::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - d->moved = false; - if (!d->absorb) - QmlGraphicsItem::mousePressEvent(event); - else { - d->longPress = false; - d->saveEvent(event); - d->dragX = drag()->axis() & QmlGraphicsDrag::XAxis; - d->dragY = drag()->axis() & QmlGraphicsDrag::YAxis; - d->dragged = false; - setHovered(true); - d->start = event->pos(); - d->startScene = event->scenePos(); - // we should only start timer if pressAndHold is connected to. - if (d->isConnected("pressAndHold(QmlGraphicsMouseEvent*)")) - d->pressAndHoldTimer.start(PressAndHoldDelay, this); - setKeepMouseGrab(false); - event->setAccepted(setPressed(true)); - } -} - -void QmlGraphicsMouseRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->absorb) { - QmlGraphicsItem::mouseMoveEvent(event); - return; - } - - d->saveEvent(event); - - // ### we should skip this if these signals aren't used - // ### can GV handle this for us? - bool contains = boundingRect().contains(d->lastPos); - if (d->hovered && !contains) - setHovered(false); - else if (!d->hovered && contains) - setHovered(true); - - if (drag()->target()) { - if (!d->moved) { - if (d->dragX) d->startX = drag()->target()->x(); - if (d->dragY) d->startY = drag()->target()->y(); - } - - QPointF startLocalPos; - QPointF curLocalPos; - if (drag()->target()->parent()) { - startLocalPos = drag()->target()->parentItem()->mapFromScene(d->startScene); - curLocalPos = drag()->target()->parentItem()->mapFromScene(event->scenePos()); - } else { - startLocalPos = d->startScene; - curLocalPos = event->scenePos(); - } - - qreal dx = qAbs(curLocalPos.x() - startLocalPos.x()); - qreal dy = qAbs(curLocalPos.y() - startLocalPos.y()); - if ((d->dragX && !(dx < DragThreshold)) || (d->dragY && !(dy < DragThreshold))) - d->dragged = true; - if (!keepMouseGrab()) { - if ((!d->dragY && dy < DragThreshold && d->dragX && dx > DragThreshold) - || (!d->dragX && dx < DragThreshold && d->dragY && dy > DragThreshold) - || (d->dragX && d->dragY)) { - setKeepMouseGrab(true); - } - } - - if (d->dragX) { - qreal x = (curLocalPos.x() - startLocalPos.x()) + d->startX; - if (x < drag()->xmin()) - x = drag()->xmin(); - else if (x > drag()->xmax()) - x = drag()->xmax(); - drag()->target()->setX(x); - } - if (d->dragY) { - qreal y = (curLocalPos.y() - startLocalPos.y()) + d->startY; - if (y < drag()->ymin()) - y = drag()->ymin(); - else if (y > drag()->ymax()) - y = drag()->ymax(); - drag()->target()->setY(y); - } - } - d->moved = true; - QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); - emit positionChanged(&me); -} - - -void QmlGraphicsMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->absorb) { - QmlGraphicsItem::mouseReleaseEvent(event); - } else { - d->saveEvent(event); - setPressed(false); - // If we don't accept hover, we need to reset containsMouse. - if (!acceptHoverEvents()) - setHovered(false); - setKeepMouseGrab(false); - } -} - -void QmlGraphicsMouseRegion::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->absorb) { - QmlGraphicsItem::mouseDoubleClickEvent(event); - } else { - QmlGraphicsItem::mouseDoubleClickEvent(event); - if (event->isAccepted()) { - // Only deliver the event if we have accepted the press. - d->saveEvent(event); - QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false); - emit this->doubleClicked(&me); - } - } -} - -void QmlGraphicsMouseRegion::hoverEnterEvent(QGraphicsSceneHoverEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->absorb) - QmlGraphicsItem::hoverEnterEvent(event); - else - setHovered(true); -} - -void QmlGraphicsMouseRegion::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->absorb) { - QmlGraphicsItem::hoverEnterEvent(event); - } else { - d->lastPos = event->pos(); - QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, d->lastButtons, d->lastModifiers, false, d->longPress); - emit positionChanged(&me); - } -} - -void QmlGraphicsMouseRegion::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (!d->absorb) - QmlGraphicsItem::hoverLeaveEvent(event); - else - setHovered(false); -} - -bool QmlGraphicsMouseRegion::sceneEvent(QEvent *event) -{ - bool rv = QmlGraphicsItem::sceneEvent(event); - if (event->type() == QEvent::UngrabMouse) { - Q_D(QmlGraphicsMouseRegion); - if (d->pressed) { - // if our mouse grab has been removed (probably by Flickable), fix our - // state - d->pressed = false; - setKeepMouseGrab(false); - emit pressedChanged(); - //emit hoveredChanged(); - } - } - return rv; -} - -void QmlGraphicsMouseRegion::timerEvent(QTimerEvent *event) -{ - Q_D(QmlGraphicsMouseRegion); - if (event->timerId() == d->pressAndHoldTimer.timerId()) { - d->pressAndHoldTimer.stop(); - if (d->pressed && d->dragged == false && d->hovered == true) { - d->longPress = true; - QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); - emit pressAndHold(&me); - } - } -} - -/*! - \qmlproperty bool MouseRegion::hoverEnabled - This property holds whether hover events are handled. - - By default, mouse events are only handled in response to a button event, or when a button is - pressed. Hover enables handling of all mouse events even when no mouse button is - pressed. - - This property affects the containsMouse property and the onEntered, onExited and onPositionChanged signals. -*/ - -/*! - \qmlproperty bool MouseRegion::containsMouse - This property holds whether the mouse is currently inside the mouse region. - - \warning This property is not updated if the region moves under the mouse: \e containsMouse will not change. - In addition, if hoverEnabled is false, containsMouse will only be valid when the mouse is pressed. -*/ -bool QmlGraphicsMouseRegion::hovered() const -{ - Q_D(const QmlGraphicsMouseRegion); - return d->hovered; -} - -/*! - \qmlproperty bool MouseRegion::pressed - This property holds whether the mouse region is currently pressed. -*/ -bool QmlGraphicsMouseRegion::pressed() const -{ - Q_D(const QmlGraphicsMouseRegion); - return d->pressed; -} - -void QmlGraphicsMouseRegion::setHovered(bool h) -{ - Q_D(QmlGraphicsMouseRegion); - if (d->hovered != h) { - d->hovered = h; - emit hoveredChanged(); - d->hovered ? emit entered() : emit exited(); - } -} - -/*! - \qmlproperty Qt::MouseButtons MouseRegion::acceptedButtons - This property holds the mouse buttons that the mouse region reacts to. - - The available buttons are: - \list - \o Qt.LeftButton - \o Qt.RightButton - \o Qt.MiddleButton - \endlist - - To accept more than one button the flags can be combined with the - "|" (or) operator: - - \code - MouseRegion { acceptedButtons: Qt.LeftButton | Qt.RightButton } - \endcode - - The default is to accept the Left button. -*/ -Qt::MouseButtons QmlGraphicsMouseRegion::acceptedButtons() const -{ - return acceptedMouseButtons(); -} - -void QmlGraphicsMouseRegion::setAcceptedButtons(Qt::MouseButtons buttons) -{ - if (buttons != acceptedMouseButtons()) { - setAcceptedMouseButtons(buttons); - emit acceptedButtonsChanged(); - } -} - -bool QmlGraphicsMouseRegion::setPressed(bool p) -{ - Q_D(QmlGraphicsMouseRegion); - bool isclick = d->pressed == true && p == false && d->dragged == false && d->hovered == true; - - if (d->pressed != p) { - d->pressed = p; - QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress); - if (d->pressed) { - emit positionChanged(&me); - emit pressed(&me); - } else { - emit released(&me); - if (isclick) - emit clicked(&me); - } - - emit pressedChanged(); - return me.isAccepted(); - } - return false; -} - -QmlGraphicsDrag *QmlGraphicsMouseRegion::drag() -{ - Q_D(QmlGraphicsMouseRegion); - return &(d->drag); -} - -/*! - \qmlproperty Item MouseRegion::drag.target - \qmlproperty Axis MouseRegion::drag.axis - \qmlproperty real MouseRegion::drag.minimumX - \qmlproperty real MouseRegion::drag.maximumX - \qmlproperty real MouseRegion::drag.minimumY - \qmlproperty real MouseRegion::drag.maximumY - - drag provides a convenient way to make an item draggable. - - \list - \i \c target specifies the item to drag. - \i \c axis specifies whether dragging can be done horizontally (XAxis), vertically (YAxis), or both (XandYAxis) - \i the minimum and maximum properties limit how far the target can be dragged along the corresponding axes. - \endlist - - The following example uses drag to reduce the opacity of an image as it moves to the right: - \snippet doc/src/snippets/declarative/drag.qml 0 -*/ - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxmouseregion.h b/src/declarative/fx/qfxmouseregion.h deleted file mode 100644 index 41c3d0e..0000000 --- a/src/declarative/fx/qfxmouseregion.h +++ /dev/null @@ -1,180 +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 QFXMOUSEREGION_H -#define QFXMOUSEREGION_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QmlGraphicsDrag : public QObject -{ - Q_OBJECT - - Q_ENUMS(Axis) - Q_PROPERTY(QmlGraphicsItem *target READ target WRITE setTarget) - Q_PROPERTY(Axis axis READ axis WRITE setAxis) - Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin) - Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax) - Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin) - Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax) - //### consider drag and drop - -public: - QmlGraphicsDrag(QObject *parent=0); - ~QmlGraphicsDrag(); - - QmlGraphicsItem *target() const; - void setTarget(QmlGraphicsItem *); - - enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 }; - Axis axis() const; - void setAxis(Axis); - - qreal xmin() const; - void setXmin(qreal); - qreal xmax() const; - void setXmax(qreal); - qreal ymin() const; - void setYmin(qreal); - qreal ymax() const; - void setYmax(qreal); - -private: - QmlGraphicsItem *_target; - Axis _axis; - qreal _xmin; - qreal _xmax; - qreal _ymin; - qreal _ymax; - Q_DISABLE_COPY(QmlGraphicsDrag) -}; - -class QmlGraphicsMouseEvent; -class QmlGraphicsMouseRegionPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsMouseRegion : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(qreal mouseX READ mouseX NOTIFY positionChanged) - Q_PROPERTY(qreal mouseY READ mouseY NOTIFY positionChanged) - Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) - Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged) - Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) - Q_PROPERTY(bool hoverEnabled READ acceptHoverEvents WRITE setAcceptHoverEvents) - Q_PROPERTY(QmlGraphicsDrag *drag READ drag) //### add flicking to QmlGraphicsDrag or add a QmlGraphicsFlick ??? - -public: - QmlGraphicsMouseRegion(QmlGraphicsItem *parent=0); - ~QmlGraphicsMouseRegion(); - - qreal mouseX() const; - qreal mouseY() const; - - bool isEnabled() const; - void setEnabled(bool); - - bool hovered() const; - bool pressed() const; - - Qt::MouseButtons pressedButtons() const; - - Qt::MouseButtons acceptedButtons() const; - void setAcceptedButtons(Qt::MouseButtons buttons); - - QmlGraphicsDrag *drag(); - -Q_SIGNALS: - void hoveredChanged(); - void pressedChanged(); - void enabledChanged(); - void acceptedButtonsChanged(); - void positionChanged(QmlGraphicsMouseEvent *mouse); - - void pressed(QmlGraphicsMouseEvent *mouse); - void pressAndHold(QmlGraphicsMouseEvent *mouse); - void released(QmlGraphicsMouseEvent *mouse); - void clicked(QmlGraphicsMouseEvent *mouse); - void doubleClicked(QmlGraphicsMouseEvent *mouse); - void entered(); - void exited(); - -protected: - void setHovered(bool); - bool setPressed(bool); - - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void hoverEnterEvent(QGraphicsSceneHoverEvent *event); - void hoverMoveEvent(QGraphicsSceneHoverEvent *event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - bool sceneEvent(QEvent *); - void timerEvent(QTimerEvent *event); - -private: - void handlePress(); - void handleRelease(); - -protected: - QmlGraphicsMouseRegion(QmlGraphicsMouseRegionPrivate &dd, QmlGraphicsItem *parent); - -private: - Q_DISABLE_COPY(QmlGraphicsMouseRegion) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsMouseRegion) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsDrag) -QML_DECLARE_TYPE(QmlGraphicsMouseRegion) - -QT_END_HEADER - -#endif // QFXMOUSEREGION_H diff --git a/src/declarative/fx/qfxmouseregion_p.h b/src/declarative/fx/qfxmouseregion_p.h deleted file mode 100644 index 66efb6f..0000000 --- a/src/declarative/fx/qfxmouseregion_p.h +++ /dev/null @@ -1,114 +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 QFXMOUSEREGION_P_H -#define QFXMOUSEREGION_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 "qdatetime.h" -#include "qbasictimer.h" -#include "qgraphicssceneevent.h" -#include "qfxitem_p.h" - -QT_BEGIN_NAMESPACE - -class QmlGraphicsMouseRegionPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsMouseRegion) - -public: - QmlGraphicsMouseRegionPrivate() - : absorb(true), hovered(false), pressed(false), longPress(false), drag(0) - { - } - - void init() - { - Q_Q(QmlGraphicsMouseRegion); - q->setAcceptedMouseButtons(Qt::LeftButton); - } - - void saveEvent(QGraphicsSceneMouseEvent *event) { - lastPos = event->pos(); - lastButton = event->button(); - lastButtons = event->buttons(); - lastModifiers = event->modifiers(); - } - - bool isConnected(const char *signal) { - Q_Q(QmlGraphicsMouseRegion); - int idx = QObjectPrivate::get(q)->signalIndex(signal); - return QObjectPrivate::get(q)->isSignalConnected(idx); - } - - bool absorb : 1; - bool hovered : 1; - bool pressed : 1; - bool longPress : 1; - bool moved : 1; - bool dragX : 1; - bool dragY : 1; - bool dragged : 1; - QmlGraphicsDrag drag; - QPointF start; - QPointF startScene; - qreal startX; - qreal startY; - QPointF lastPos; - Qt::MouseButton lastButton; - Qt::MouseButtons lastButtons; - Qt::KeyboardModifiers lastModifiers; - QBasicTimer pressAndHoldTimer; -}; - -QT_END_NAMESPACE - -#endif // QFXMOUSEREGION_P_H diff --git a/src/declarative/fx/qfxpainteditem.cpp b/src/declarative/fx/qfxpainteditem.cpp deleted file mode 100644 index 24d9602..0000000 --- a/src/declarative/fx/qfxpainteditem.cpp +++ /dev/null @@ -1,387 +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 "qfxpainteditem.h" -#include "qfxpainteditem_p.h" - -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \class QmlGraphicsPaintedItem - \brief The QmlGraphicsPaintedItem class is an abstract base class for QmlView items that want cached painting. - \internal - - This is a convenience class for implementing items that paint their contents - using a QPainter. The contents of the item are cached behind the scenes. - The dirtyCache() function should be called if the contents change to - ensure the cache is refreshed the next time painting occurs. - - To subclass QmlGraphicsPaintedItem, you must reimplement drawContents() to draw - the contents of the item. -*/ - -/*! - \fn void QmlGraphicsPaintedItem::drawContents(QPainter *painter, const QRect &rect) - - This function is called when the cache needs to be refreshed. When - sub-classing QmlGraphicsPaintedItem this function should be implemented so as to - paint the contents of the item using the given \a painter for the - area of the contents specified by \a rect. -*/ - -/*! - \property QmlGraphicsPaintedItem::contentsSize - \brief The size of the contents - - The contents size is the size of the item in regards to how it is painted - using the drawContents() function. This is distinct from the size of the - item in regards to height() and width(). -*/ - -// XXX bug in WebKit - can call repaintRequested and other cache-changing functions from within render! -static int inpaint=0; -static int inpaint_clearcache=0; - -/*! - Marks areas of the cache that intersect with the given \a rect as dirty and - in need of being refreshed. - - \sa clearCache() -*/ -void QmlGraphicsPaintedItem::dirtyCache(const QRect& rect) -{ - Q_D(QmlGraphicsPaintedItem); - for (int i=0; i < d->imagecache.count(); ) { - QmlGraphicsPaintedItemPrivate::ImageCacheItem *c = d->imagecache[i]; - QRect isect = (c->area & rect) | c->dirty; - if (isect == c->area && !inpaint) { - delete d->imagecache.takeAt(i); - } else { - c->dirty = isect; - ++i; - } - } -} - -/*! - Marks the entirety of the contents cache as dirty. - - \sa dirtyCache() -*/ -void QmlGraphicsPaintedItem::clearCache() -{ - if (inpaint) { - inpaint_clearcache=1; - return; - } - Q_D(QmlGraphicsPaintedItem); - qDeleteAll(d->imagecache); - d->imagecache.clear(); -} - -/*! - Returns the size of the contents. - - \sa setContentsSize() -*/ -QSize QmlGraphicsPaintedItem::contentsSize() const -{ - Q_D(const QmlGraphicsPaintedItem); - return d->contentsSize; -} - -/*! - Sets the size of the contents to the given \a size. - - \sa contentsSize() -*/ -void QmlGraphicsPaintedItem::setContentsSize(const QSize &size) -{ - Q_D(QmlGraphicsPaintedItem); - if (d->contentsSize == size) return; - d->contentsSize = size; - clearCache(); - update(); -} - -/*! - Constructs a new QmlGraphicsPaintedItem with the given \a parent. -*/ -QmlGraphicsPaintedItem::QmlGraphicsPaintedItem(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsPaintedItemPrivate), parent) -{ - init(); -} - -/*! - \internal - Constructs a new QmlGraphicsPaintedItem with the given \a parent and - initialized private data member \a dd. -*/ -QmlGraphicsPaintedItem::QmlGraphicsPaintedItem(QmlGraphicsPaintedItemPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ - init(); -} - -/*! - Destroys the image item. -*/ -QmlGraphicsPaintedItem::~QmlGraphicsPaintedItem() -{ - clearCache(); -} - -/*! - \internal -*/ -void QmlGraphicsPaintedItem::init() -{ - connect(this,SIGNAL(widthChanged()),this,SLOT(clearCache())); - connect(this,SIGNAL(heightChanged()),this,SLOT(clearCache())); - connect(this,SIGNAL(visibleChanged()),this,SLOT(clearCache())); -} - -void QmlGraphicsPaintedItem::setCacheFrozen(bool frozen) -{ - Q_D(QmlGraphicsPaintedItem); - if (d->cachefrozen == frozen) - return; - d->cachefrozen = frozen; - // XXX clear cache? -} - -/*! - \reimp -*/ -void QmlGraphicsPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - Q_D(QmlGraphicsPaintedItem); - const QRect content(QPoint(0,0),d->contentsSize); - if (content.width() <= 0 || content.height() <= 0) - return; - - ++inpaint; - - QRectF clipf = p->clipRegion().boundingRect(); - if (clipf.isEmpty()) - clipf = mapToScene(content).boundingRect(); // ### Inefficient: Maps toScene and then fromScene - else - clipf = mapToScene(clipf).boundingRect(); - - const QRect clip = mapFromScene(clipf).boundingRect().toRect(); - - QRegion topaint(clip); - topaint &= content; - QRegion uncached(content); - - int cachesize=0; - for (int i=0; iimagecache.count(); ++i) { - QRect area = d->imagecache[i]->area; - if (topaint.contains(area)) { - QRectF target(area.x(), area.y(), area.width(), area.height()); - if (!d->cachefrozen) { - if (!d->imagecache[i]->dirty.isNull() && topaint.contains(d->imagecache[i]->dirty)) { - QPainter qp(&d->imagecache[i]->image); - qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smooth); - qp.translate(-area.x(), -area.y()); - if (d->fillColor.isValid()){ - if(d->fillColor.alpha() < 255){ - // ### Might not work outside of raster paintengine - QPainter::CompositionMode prev = qp.compositionMode(); - qp.setCompositionMode(QPainter::CompositionMode_Source); - qp.fillRect(d->imagecache[i]->dirty,d->fillColor); - qp.setCompositionMode(prev); - }else{ - qp.fillRect(d->imagecache[i]->dirty,d->fillColor); - } - } - qp.setClipRect(d->imagecache[i]->dirty); - drawContents(&qp, d->imagecache[i]->dirty); - d->imagecache[i]->dirty = QRect(); - } - } - p->drawPixmap(target.toRect(), d->imagecache[i]->image); - topaint -= area; - d->imagecache[i]->age=0; - } else { - d->imagecache[i]->age++; - } - cachesize += area.width()*area.height(); - uncached -= area; - } - - if (!topaint.isEmpty()) { - if (!d->cachefrozen) { - // Find a sensible larger area, otherwise will paint lots of tiny images. - QRect biggerrect = topaint.boundingRect().adjusted(-64,-64,128,128); - cachesize += biggerrect.width() * biggerrect.height(); - while (d->imagecache.count() && cachesize > d->max_imagecache_size) { - int oldest=-1; - int age=-1; - for (int i=0; iimagecache.count(); ++i) { - int a = d->imagecache[i]->age; - if (a > age) { - oldest = i; - age = a; - } - } - cachesize -= d->imagecache[oldest]->area.width()*d->imagecache[oldest]->area.height(); - uncached += d->imagecache[oldest]->area; - d->imagecache.removeAt(oldest); - } - const QRegion bigger = QRegion(biggerrect) & uncached; - const QVector rects = bigger.rects(); - for (int i = 0; i < rects.count(); ++i) { - const QRect &r = rects.at(i); - QPixmap img(r.size()); - if (d->fillColor.isValid()) - img.fill(d->fillColor); - { - QPainter qp(&img); - qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smooth); - - qp.translate(-r.x(),-r.y()); - drawContents(&qp, r); - } - QmlGraphicsPaintedItemPrivate::ImageCacheItem *newitem = new QmlGraphicsPaintedItemPrivate::ImageCacheItem; - newitem->area = r; - newitem->image = img; - d->imagecache.append(newitem); - p->drawPixmap(r, newitem->image); - } - } else { - const QVector rects = uncached.rects(); - for (int i = 0; i < rects.count(); ++i) - p->fillRect(rects.at(i), Qt::lightGray); - } - } - - if (inpaint_clearcache) { - clearCache(); - inpaint_clearcache = 0; - } - - --inpaint; -} - -/*! - \qmlproperty int PaintedItem::cacheSize - - This property holds the maximum number of pixels of image cache to - allow. The default is 0.1 megapixels. The cache will not be larger - than the (unscaled) size of the item. -*/ - -/*! - \property QmlGraphicsPaintedItem::cacheSize - - The maximum number of pixels of image cache to allow. The default - is 0.1 megapixels. The cache will not be larger than the (unscaled) - size of the QmlGraphicsPaintedItem. -*/ -int QmlGraphicsPaintedItem::cacheSize() const -{ - Q_D(const QmlGraphicsPaintedItem); - return d->max_imagecache_size; -} - -void QmlGraphicsPaintedItem::setCacheSize(int pixels) -{ - Q_D(QmlGraphicsPaintedItem); - if (pixels < d->max_imagecache_size) { - int cachesize=0; - for (int i=0; iimagecache.count(); ++i) { - QRect area = d->imagecache[i]->area; - cachesize += area.width()*area.height(); - } - while (d->imagecache.count() && cachesize > pixels) { - int oldest=-1; - int age=-1; - for (int i=0; iimagecache.count(); ++i) { - int a = d->imagecache[i]->age; - if (a > age) { - oldest = i; - age = a; - } - } - cachesize -= d->imagecache[oldest]->area.width()*d->imagecache[oldest]->area.height(); - d->imagecache.removeAt(oldest); - } - } - d->max_imagecache_size = pixels; -} - -/*! - \property QmlGraphicsPaintedItem::fillColor - - The color to be used to fill the item prior to calling drawContents(). - By default, this is Qt::transparent. - - Performance improvements can be achieved if subclasses call this with either an - invalid color (QColor()), or an appropriate solid color. -*/ -void QmlGraphicsPaintedItem::setFillColor(const QColor& c) -{ - Q_D(QmlGraphicsPaintedItem); - if (d->fillColor == c) - return; - d->fillColor = c; - emit fillColorChanged(); - update(); -} - -QColor QmlGraphicsPaintedItem::fillColor() const -{ - Q_D(const QmlGraphicsPaintedItem); - return d->fillColor; -} - - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpainteditem.h b/src/declarative/fx/qfxpainteditem.h deleted file mode 100644 index 33f938c..0000000 --- a/src/declarative/fx/qfxpainteditem.h +++ /dev/null @@ -1,105 +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 QFXIMAGEITEM_H -#define QFXIMAGEITEM_H - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsPaintedItemPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsPaintedItem : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QSize contentsSize READ contentsSize WRITE setContentsSize) - Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY fillColorChanged) - Q_PROPERTY(int cacheSize READ cacheSize WRITE setCacheSize) - -public: - QmlGraphicsPaintedItem(QmlGraphicsItem *parent=0); - ~QmlGraphicsPaintedItem(); - - QSize contentsSize() const; - void setContentsSize(const QSize &); - - int cacheSize() const; - void setCacheSize(int pixels); - - QColor fillColor() const; - void setFillColor(const QColor&); - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -protected: - QmlGraphicsPaintedItem(QmlGraphicsPaintedItemPrivate &dd, QmlGraphicsItem *parent); - - virtual void drawContents(QPainter *p, const QRect &) = 0; - - void setCacheFrozen(bool); - -Q_SIGNALS: - void fillColorChanged(); - -protected Q_SLOTS: - void dirtyCache(const QRect &); - void clearCache(); - -private: - void init(); - Q_DISABLE_COPY(QmlGraphicsPaintedItem) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsPaintedItem) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsPaintedItem) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qfxpainteditem_p.h b/src/declarative/fx/qfxpainteditem_p.h deleted file mode 100644 index cc7f697..0000000 --- a/src/declarative/fx/qfxpainteditem_p.h +++ /dev/null @@ -1,88 +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 QFXIMAGEITEM_P_H -#define QFXIMAGEITEM_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 - -QT_BEGIN_NAMESPACE - -class QmlGraphicsPaintedItemPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsPaintedItem) - -public: - QmlGraphicsPaintedItemPrivate() - : max_imagecache_size(100000), fillColor(Qt::transparent), cachefrozen(false) - { - } - - struct ImageCacheItem { - ImageCacheItem() : age(0) {} - ~ImageCacheItem() { } - int age; - QRect area; - QRect dirty; // one dirty area (allows optimization of common cases) - QPixmap image; - }; - - QList imagecache; - - int max_imagecache_size; - QSize contentsSize; - QColor fillColor; - bool cachefrozen; -}; - -QT_END_NAMESPACE -#endif diff --git a/src/declarative/fx/qfxpath.cpp b/src/declarative/fx/qfxpath.cpp deleted file mode 100644 index a9bd233..0000000 --- a/src/declarative/fx/qfxpath.cpp +++ /dev/null @@ -1,839 +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 "qfxpath.h" -#include "qfxpath_p.h" -#include -#include -#include - - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Path,QmlGraphicsPath) -QML_DEFINE_NOCREATE_TYPE(QmlGraphicsPathElement) -QML_DEFINE_NOCREATE_TYPE(QmlGraphicsCurve) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathAttribute,QmlGraphicsPathAttribute) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathPercent,QmlGraphicsPathPercent) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathLine,QmlGraphicsPathLine) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathQuad,QmlGraphicsPathQuad) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathCubic,QmlGraphicsPathCubic) - -/*! - \qmlclass PathElement - \brief PathElement is the base path type. - - This type is the base for all path types. It cannot - be instantiated. - - \sa Path, PathAttribute, PathPercent, PathLine, PathQuad, PathCubic -*/ - -/*! - \internal - \class QmlGraphicsPathElement - \ingroup group_utility -*/ - -/*! - \qmlclass Path QmlGraphicsPath - \brief A Path object defines a path for use by \l PathView. - - A Path is composed of one or more path segments - PathLine, PathQuad, - PathCubic. - - The spacing of the items along the Path can be adjusted via a - PathPercent object. - - PathAttribute allows named attributes with values to be defined - along the path. - - \sa PathView, PathAttribute, PathPercent, PathLine, PathQuad, PathCubic -*/ - -/*! - \internal - \class QmlGraphicsPath - \ingroup group_utility - \brief The QmlGraphicsPath class defines a path. - \sa QmlGraphicsPathView -*/ -QmlGraphicsPath::QmlGraphicsPath(QObject *parent) - : QObject(*(new QmlGraphicsPathPrivate), parent) -{ -} - -QmlGraphicsPath::QmlGraphicsPath(QmlGraphicsPathPrivate &dd, QObject *parent) - : QObject(dd, parent) -{ -} - -QmlGraphicsPath::~QmlGraphicsPath() -{ -} - -/*! - \qmlproperty real Path::startX - \qmlproperty real Path::startY - This property holds the starting position of the path. -*/ -qreal QmlGraphicsPath::startX() const -{ - Q_D(const QmlGraphicsPath); - return d->startX; -} - -void QmlGraphicsPath::setStartX(qreal x) -{ - Q_D(QmlGraphicsPath); - d->startX = x; -} - -qreal QmlGraphicsPath::startY() const -{ - Q_D(const QmlGraphicsPath); - return d->startY; -} - -void QmlGraphicsPath::setStartY(qreal y) -{ - Q_D(QmlGraphicsPath); - d->startY = y; -} - -/*! - \qmlproperty list Path::pathElements - This property holds the objects composing the path. - - \default - - A path can contain the following path objects: - \list - \i \l PathLine - a straight line to a given position. - \i \l PathQuad - a quadratic Bezier curve to a given position with a control point. - \i \l PathCubic - a cubic Bezier curve to a given position with two control points. - \i \l PathAttribute - an attribute at a given position in the path. - \i \l PathPercent - a way to spread out items along various segments of the path. - \endlist - - \snippet doc/src/snippets/declarative/pathview/pathattributes.qml 2 -*/ - -QList* QmlGraphicsPath::pathElements() -{ - Q_D(QmlGraphicsPath); - return &(d->_pathElements); -} - -void QmlGraphicsPath::interpolate(int idx, const QString &name, qreal value) -{ - Q_D(QmlGraphicsPath); - if (!idx) - return; - - qreal lastValue = 0; - qreal lastPercent = 0; - int search = idx - 1; - while(search >= 0) { - const AttributePoint &point = d->_attributePoints.at(search); - if (point.values.contains(name)) { - lastValue = point.values.value(name); - lastPercent = point.origpercent; - break; - } - --search; - } - - ++search; - - const AttributePoint &curPoint = d->_attributePoints.at(idx); - - for (int ii = search; ii < idx; ++ii) { - AttributePoint &point = d->_attributePoints[ii]; - - qreal val = lastValue + (value - lastValue) * (point.origpercent - lastPercent) / (curPoint.origpercent - lastPercent); - point.values.insert(name, val); - } -} - -void QmlGraphicsPath::endpoint(const QString &name) -{ - Q_D(QmlGraphicsPath); - const AttributePoint &first = d->_attributePoints.first(); - qreal val = first.values.value(name); - for (int ii = d->_attributePoints.count() - 1; ii >= 0; ii--) { - const AttributePoint &point = d->_attributePoints.at(ii); - if (point.values.contains(name)) { - for (int jj = ii + 1; jj < d->_attributePoints.count(); ++jj) { - AttributePoint &setPoint = d->_attributePoints[jj]; - setPoint.values.insert(name, val); - } - return; - } - } -} - -void QmlGraphicsPath::processPath() -{ - Q_D(QmlGraphicsPath); - - d->_pointCache.clear(); - d->_attributePoints.clear(); - d->_path = QPainterPath(); - - AttributePoint first; - for (int ii = 0; ii < d->_attributes.count(); ++ii) - first.values[d->_attributes.at(ii)] = 0; - d->_attributePoints << first; - - d->_path.moveTo(d->startX, d->startY); - - foreach (QmlGraphicsPathElement *pathElement, d->_pathElements) { - if (QmlGraphicsCurve *curve = qobject_cast(pathElement)) { - curve->addToPath(d->_path); - AttributePoint p; - p.origpercent = d->_path.length(); - d->_attributePoints << p; - } else if (QmlGraphicsPathAttribute *attribute = qobject_cast(pathElement)) { - AttributePoint &point = d->_attributePoints.last(); - point.values[attribute->name()] = attribute->value(); - interpolate(d->_attributePoints.count() - 1, attribute->name(), attribute->value()); - } else if (QmlGraphicsPathPercent *percent = qobject_cast(pathElement)) { - AttributePoint &point = d->_attributePoints.last(); - point.values[QLatin1String("_qfx_percent")] = percent->value(); - interpolate(d->_attributePoints.count() - 1, QLatin1String("_qfx_percent"), percent->value()); - } - } - - // Fixup end points - const AttributePoint &last = d->_attributePoints.last(); - for (int ii = 0; ii < d->_attributes.count(); ++ii) { - if (!last.values.contains(d->_attributes.at(ii))) - endpoint(d->_attributes.at(ii)); - } - - // Adjust percent - qreal length = d->_path.length(); - qreal prevpercent = 0; - qreal prevorigpercent = 0; - for (int ii = 0; ii < d->_attributePoints.count(); ++ii) { - const AttributePoint &point = d->_attributePoints.at(ii); - if (point.values.contains(QLatin1String("_qfx_percent"))) { //special string for QmlGraphicsPathPercent - if ( ii > 0) { - qreal scale = (d->_attributePoints[ii].origpercent/length - prevorigpercent) / - (point.values.value(QLatin1String("_qfx_percent"))-prevpercent); - d->_attributePoints[ii].scale = scale; - } - d->_attributePoints[ii].origpercent /= length; - d->_attributePoints[ii].percent = point.values.value(QLatin1String("_qfx_percent")); - prevorigpercent = d->_attributePoints[ii].origpercent; - prevpercent = d->_attributePoints[ii].percent; - } else { - d->_attributePoints[ii].origpercent /= length; - d->_attributePoints[ii].percent = d->_attributePoints[ii].origpercent; - } - } - - emit changed(); -} - -void QmlGraphicsPath::componentComplete() -{ - Q_D(QmlGraphicsPath); - QSet attrs; - // First gather up all the attributes - foreach (QmlGraphicsPathElement *pathElement, d->_pathElements) { - if (QmlGraphicsPathAttribute *attribute = - qobject_cast(pathElement)) - attrs.insert(attribute->name()); - } - d->_attributes = attrs.toList(); - - processPath(); - - foreach (QmlGraphicsPathElement *pathElement, d->_pathElements) - connect(pathElement, SIGNAL(changed()), this, SLOT(processPath())); -} - -QPainterPath QmlGraphicsPath::path() const -{ - Q_D(const QmlGraphicsPath); - return d->_path; -} - -QStringList QmlGraphicsPath::attributes() const -{ - Q_D(const QmlGraphicsPath); - return d->_attributes; -} -#include - -static inline QBezier nextBezier(const QPainterPath &path, int *from, qreal *bezLength) -{ - const int lastElement = path.elementCount() - 1; - for (int i=*from; i <= lastElement; ++i) { - const QPainterPath::Element &e = path.elementAt(i); - - switch (e.type) { - case QPainterPath::MoveToElement: - break; - case QPainterPath::LineToElement: - { - QLineF line(path.elementAt(i-1), e); - *bezLength = line.length(); - QPointF a = path.elementAt(i-1); - QPointF delta = e - a; - *from = i+1; - return QBezier::fromPoints(a, a + delta / 3, a + 2 * delta / 3, e); - } - case QPainterPath::CurveToElement: - { - QBezier b = QBezier::fromPoints(path.elementAt(i-1), - e, - path.elementAt(i+1), - path.elementAt(i+2)); - *bezLength = b.length(); - *from = i+3; - return b; - } - default: - break; - } - } - *from = lastElement; - *bezLength = 0; - return QBezier(); -} - -void QmlGraphicsPath::createPointCache() const -{ - Q_D(const QmlGraphicsPath); -#ifdef Q_ENABLE_PERFORMANCE_LOG - QmlPerfTimer pc; -#endif - qreal pathLength = d->_path.length(); - const int points = int(pathLength*2); - const int lastElement = d->_path.elementCount() - 1; - d->_pointCache.resize(points+1); - - int currElement = 0; - qreal bezLength = 0; - QBezier currBez = nextBezier(d->_path, &currElement, &bezLength); - qreal currLength = bezLength; - qreal epc = currLength / pathLength; - - for (int i = 0; i < d->_pointCache.size(); i++) { - //find which set we are in - qreal prevPercent = 0; - qreal prevOrigPercent = 0; - for (int ii = 0; ii < d->_attributePoints.count(); ++ii) { - qreal percent = qreal(i)/points; - const AttributePoint &point = d->_attributePoints.at(ii); - if (percent < point.percent || ii == d->_attributePoints.count() - 1) { //### || is special case for very last item - qreal elementPercent = (percent - prevPercent); - - qreal spc = prevOrigPercent + elementPercent * point.scale; - - while (spc > epc) { - if (currElement > lastElement) - break; - currBez = nextBezier(d->_path, &currElement, &bezLength); - if (bezLength == 0.0) { - currLength = pathLength; - epc = 1.0; - break; - } - currLength += bezLength; - epc = currLength / pathLength; - } - qreal realT = (pathLength * spc - (currLength - bezLength)) / bezLength; - d->_pointCache[i] = currBez.pointAt(qBound(qreal(0), realT, qreal(1))); - break; - } - prevOrigPercent = point.origpercent; - prevPercent = point.percent; - } - } -} - -QPointF QmlGraphicsPath::pointAt(qreal p) const -{ - Q_D(const QmlGraphicsPath); - if (d->_pointCache.isEmpty()) { - createPointCache(); - } - int idx = qRound(p*d->_pointCache.size()); - if (idx >= d->_pointCache.size()) - idx = d->_pointCache.size() - 1; - else if (idx < 0) - idx = 0; - return d->_pointCache.at(idx); -} - -qreal QmlGraphicsPath::attributeAt(const QString &name, qreal percent) const -{ - Q_D(const QmlGraphicsPath); - if (percent < 0 || percent > 1) - return 0; - - for (int ii = 0; ii < d->_attributePoints.count(); ++ii) { - const AttributePoint &point = d->_attributePoints.at(ii); - - if (point.percent == percent) { - return point.values.value(name); - } else if (point.percent > percent) { - qreal lastValue = - ii?(d->_attributePoints.at(ii - 1).values.value(name)):0; - qreal lastPercent = - ii?(d->_attributePoints.at(ii - 1).percent):0; - qreal curValue = point.values.value(name); - qreal curPercent = point.percent; - - return lastValue + (curValue - lastValue) * (percent - lastPercent) / (curPercent - lastPercent); - } - } - - return 0; -} - -/****************************************************************************/ - -qreal QmlGraphicsCurve::x() const -{ - return _x; -} - -void QmlGraphicsCurve::setX(qreal x) -{ - if (_x != x) { - _x = x; - emit changed(); - } -} - -qreal QmlGraphicsCurve::y() const -{ - return _y; -} - -void QmlGraphicsCurve::setY(qreal y) -{ - if (_y != y) { - _y = y; - emit changed(); - } -} - -/****************************************************************************/ - -/*! - \qmlclass PathAttribute - \brief The PathAttribute allows setting an attribute at a given position in a Path. - - The PathAttribute object allows attibutes consisting of a name and - a value to be specified for the endpoints of path segments. The - attributes are exposed to the delegate as - \l{qmlintroduction.html#attached-properties} {Attached Properties}. - The value of an attribute at any particular point is interpolated - from the PathAttributes bounding the point. - - The example below shows a path with the items scaled to 30% with - opacity 50% at the top of the path and scaled 100% with opacity - 100% at the bottom. Note the use of the PathView.scale and - PathView.opacity attached properties to set the scale and opacity - of the delegate. - - \table - \row - \o \image declarative-pathattribute.png - \o - \snippet doc/src/snippets/declarative/pathview/pathattributes.qml 0 - \endtable - - \sa Path -*/ - -/*! - \internal - \class QmlGraphicsPathAttribute - \ingroup group_utility - \brief The QmlGraphicsPathAttribute class allows to set the value of an attribute at a given position in the path. - - \sa QmlGraphicsPath -*/ - - -/*! - \qmlproperty string PathAttribute::name - the name of the attribute to change. -*/ - -/*! - the name of the attribute to change. -*/ - -QString QmlGraphicsPathAttribute::name() const -{ - return _name; -} - -void QmlGraphicsPathAttribute::setName(const QString &name) -{ - _name = name; -} - -/*! - \qmlproperty string PathAttribute::value - the new value of the attribute. -*/ - -/*! - the new value of the attribute. -*/ -qreal QmlGraphicsPathAttribute::value() const -{ - return _value; -} - -void QmlGraphicsPathAttribute::setValue(qreal value) -{ - if (_value != value) { - _value = value; - emit changed(); - } -} - -/****************************************************************************/ - -/*! - \qmlclass PathLine - \brief The PathLine defines a straight line. - - The example below creates a path consisting of a straight line from - 0,100 to 200,100: - - \qml - Path { - startX: 0; startY: 100 - PathLine { x: 200; y: 100 } - } - \endqml - - \sa Path, PathQuad, PathCubic -*/ - -/*! - \internal - \class QmlGraphicsPathLine - \ingroup group_utility - \brief The QmlGraphicsPathLine class defines a straight line. - - \sa QmlGraphicsPath -*/ - -/*! - \qmlproperty real PathLine::x - \qmlproperty real PathLine::y - - Defines the end point of the line. -*/ - -void QmlGraphicsPathLine::addToPath(QPainterPath &path) -{ - path.lineTo(x(), y()); -} - -/****************************************************************************/ - -/*! - \qmlclass PathQuad - \brief The PathQuad defines a quadratic Bezier curve with a control point. - - The following QML produces the path shown below: - \table - \row - \o \image declarative-pathquad.png - \o - \qml - Path { - startX: 0; startY: 0 - PathQuad x: 200; y: 0; controlX: 100; controlY: 150 } - } - \endqml - \endtable - - \sa Path, PathCubic, PathLine -*/ - -/*! - \internal - \class QmlGraphicsPathQuad - \ingroup group_utility - \brief The QmlGraphicsPathQuad class defines a quadratic Bezier curve with a control point. - - \sa QmlGraphicsPath -*/ - - -/*! - \qmlproperty real PathQuad::x - \qmlproperty real PathQuad::y - - Defines the end point of the curve. -*/ - -/*! - \qmlproperty real PathQuad::controlX - \qmlproperty real PathQuad::controlY - - Defines the position of the control point. -*/ - -/*! - the x position of the control point. -*/ -qreal QmlGraphicsPathQuad::controlX() const -{ - return _controlX; -} - -void QmlGraphicsPathQuad::setControlX(qreal x) -{ - if (_controlX != x) { - _controlX = x; - emit changed(); - } -} - - -/*! - the y position of the control point. -*/ -qreal QmlGraphicsPathQuad::controlY() const -{ - return _controlY; -} - -void QmlGraphicsPathQuad::setControlY(qreal y) -{ - if (_controlY != y) { - _controlY = y; - emit changed(); - } -} - -void QmlGraphicsPathQuad::addToPath(QPainterPath &path) -{ - path.quadTo(controlX(), controlY(), x(), y()); -} - -/****************************************************************************/ - -/*! - \qmlclass PathCubic - \brief The PathCubic defines a cubic Bezier curve with two control points. - - The following QML produces the path shown below: - \table - \row - \o \image declarative-pathcubic.png - \o - \qml - Path { - startX: 20; startY: 0 - PathCubic { - x: 180; y: 0; control1X: -10; control1Y: 90 - control2X: 210; control2Y: 90 - } - } - \endqml - \endtable - - \sa Path, PathQuad, PathLine -*/ - -/*! - \internal - \class QmlGraphicsPathCubic - \ingroup group_utility - \brief The QmlGraphicsPathCubic class defines a cubic Bezier curve with two control points. - - \sa QmlGraphicsPath -*/ - -/*! - \qmlproperty real PathCubic::x - \qmlproperty real PathCubic::y - - Defines the end point of the curve. -*/ - -/*! - \qmlproperty real PathCubic::control1X - \qmlproperty real PathCubic::control1Y - - Defines the position of the first control point. -*/ -qreal QmlGraphicsPathCubic::control1X() const -{ - return _control1X; -} - -void QmlGraphicsPathCubic::setControl1X(qreal x) -{ - if (_control1X != x) { - _control1X = x; - emit changed(); - } -} - -qreal QmlGraphicsPathCubic::control1Y() const -{ - return _control1Y; -} - -void QmlGraphicsPathCubic::setControl1Y(qreal y) -{ - if (_control1Y != y) { - _control1Y = y; - emit changed(); - } -} - -/*! - \qmlproperty real PathCubic::control2X - \qmlproperty real PathCubic::control2Y - - Defines the position of the second control point. -*/ -qreal QmlGraphicsPathCubic::control2X() const -{ - return _control2X; -} - -void QmlGraphicsPathCubic::setControl2X(qreal x) -{ - if (_control2X != x) { - _control2X = x; - emit changed(); - } -} - -qreal QmlGraphicsPathCubic::control2Y() const -{ - return _control2Y; -} - -void QmlGraphicsPathCubic::setControl2Y(qreal y) -{ - if (_control2Y != y) { - _control2Y = y; - emit changed(); - } -} - -void QmlGraphicsPathCubic::addToPath(QPainterPath &path) -{ - path.cubicTo(control1X(), control1Y(), control2X(), control2Y(), x(), y()); -} - -/****************************************************************************/ - -/*! - \qmlclass PathPercent - \brief The PathPercent manipulates the way a path is interpreted. - - The examples below show the normal distrubution of items along a path - compared to a distribution which places 50% of the items along the - PathLine section of the path. - \table - \row - \o \image declarative-nopercent.png - \o - \qml - Path { - startX: 20; startY: 0 - PathQuad { x: 50; y: 80; controlX: 0; controlY: 80 } - PathLine { x: 150; y: 80 } - PathQuad { x: 180; y: 0; controlX: 200; controlY: 80 } - } - \endqml - \row - \o \image declarative-percent.png - \o - \qml - Path { - startX: 20; startY: 0 - PathQuad { x: 50; y: 80; controlX: 0; controlY: 80 } - PathPercent { value: 0.25 } - PathLine { x: 150; y: 80 } - PathPercent { value: 0.75 } - PathQuad { x: 180; y: 0; controlX: 200; controlY: 80 } - PathPercent { value: 1 } - } - \endqml - \endtable - - \sa Path -*/ - -/*! - \internal - \class QmlGraphicsPathPercent - \ingroup group_utility - \brief The QmlGraphicsPathPercent class manipulates the way a path is interpreted. - - QmlGraphicsPathPercent allows you to bunch up items (or spread out items) along various - segments of a QmlGraphicsPathView's path. - - \sa QmlGraphicsPath - -*/ - -qreal QmlGraphicsPathPercent::value() const -{ - return _value; -} - -void QmlGraphicsPathPercent::setValue(qreal value) -{ - _value = value; -} -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpath.h b/src/declarative/fx/qfxpath.h deleted file mode 100644 index e724474..0000000 --- a/src/declarative/fx/qfxpath.h +++ /dev/null @@ -1,259 +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 QFXPATH_H -#define QFXPATH_H - -#include -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class Q_DECLARATIVE_EXPORT QmlGraphicsPathElement : public QObject -{ - Q_OBJECT -public: - QmlGraphicsPathElement(QObject *parent=0) : QObject(parent) {} -Q_SIGNALS: - void changed(); -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsPathAttribute : public QmlGraphicsPathElement -{ - Q_OBJECT - - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) -public: - QmlGraphicsPathAttribute(QObject *parent=0) : QmlGraphicsPathElement(parent), _value(0) {} - - - QString name() const; - void setName(const QString &name); - - qreal value() const; - void setValue(qreal value); - -private: - QString _name; - qreal _value; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsCurve : public QmlGraphicsPathElement -{ - Q_OBJECT - - Q_PROPERTY(qreal x READ x WRITE setX NOTIFY changed) - Q_PROPERTY(qreal y READ y WRITE setY NOTIFY changed) -public: - QmlGraphicsCurve(QObject *parent=0) : QmlGraphicsPathElement(parent), _x(0), _y(0) {} - - qreal x() const; - void setX(qreal x); - - qreal y() const; - void setY(qreal y); - - virtual void addToPath(QPainterPath &) {} - -private: - qreal _x; - qreal _y; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsPathLine : public QmlGraphicsCurve -{ - Q_OBJECT -public: - QmlGraphicsPathLine(QObject *parent=0) : QmlGraphicsCurve(parent) {} - - void addToPath(QPainterPath &path); -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsPathQuad : public QmlGraphicsCurve -{ - Q_OBJECT - - Q_PROPERTY(qreal controlX READ controlX WRITE setControlX NOTIFY changed) - Q_PROPERTY(qreal controlY READ controlY WRITE setControlY NOTIFY changed) -public: - QmlGraphicsPathQuad(QObject *parent=0) : QmlGraphicsCurve(parent), _controlX(0), _controlY(0) {} - - qreal controlX() const; - void setControlX(qreal x); - - qreal controlY() const; - void setControlY(qreal y); - - void addToPath(QPainterPath &path); - -private: - qreal _controlX; - qreal _controlY; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsPathCubic : public QmlGraphicsCurve -{ - Q_OBJECT - - Q_PROPERTY(qreal control1X READ control1X WRITE setControl1X NOTIFY changed) - Q_PROPERTY(qreal control1Y READ control1Y WRITE setControl1Y NOTIFY changed) - Q_PROPERTY(qreal control2X READ control2X WRITE setControl2X NOTIFY changed) - Q_PROPERTY(qreal control2Y READ control2Y WRITE setControl2Y NOTIFY changed) -public: - QmlGraphicsPathCubic(QObject *parent=0) : QmlGraphicsCurve(parent), _control1X(0), _control1Y(0), _control2X(0), _control2Y(0) {} - - qreal control1X() const; - void setControl1X(qreal x); - - qreal control1Y() const; - void setControl1Y(qreal y); - - qreal control2X() const; - void setControl2X(qreal x); - - qreal control2Y() const; - void setControl2Y(qreal y); - - void addToPath(QPainterPath &path); - -private: - int _control1X; - int _control1Y; - int _control2X; - int _control2Y; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsPathPercent : public QmlGraphicsPathElement -{ - Q_OBJECT - Q_PROPERTY(qreal value READ value WRITE setValue) -public: - QmlGraphicsPathPercent(QObject *parent=0) : QmlGraphicsPathElement(parent) {} - - qreal value() const; - void setValue(qreal value); - -private: - qreal _value; -}; - -class QmlGraphicsPathPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsPath : public QObject, public QmlParserStatus -{ - Q_OBJECT - - Q_INTERFACES(QmlParserStatus) - Q_PROPERTY(QList* pathElements READ pathElements) - Q_PROPERTY(qreal startX READ startX WRITE setStartX) - Q_PROPERTY(qreal startY READ startY WRITE setStartY) - Q_CLASSINFO("DefaultProperty", "pathElements") - Q_INTERFACES(QmlParserStatus) -public: - QmlGraphicsPath(QObject *parent=0); - ~QmlGraphicsPath(); - - QList* pathElements(); - - qreal startX() const; - void setStartX(qreal x); - - qreal startY() const; - void setStartY(qreal y); - - QPainterPath path() const; - QStringList attributes() const; - qreal attributeAt(const QString &, qreal) const; - QPointF pointAt(qreal) const; - -Q_SIGNALS: - void changed(); - -protected: - virtual void componentComplete(); - QmlGraphicsPath(QmlGraphicsPathPrivate &dd, QObject *parent); - -private Q_SLOTS: - void processPath(); - -private: - struct AttributePoint { - AttributePoint() : percent(0), scale(1), origpercent(0) {} - AttributePoint(const AttributePoint &other) - : percent(other.percent), scale(other.scale), origpercent(other.origpercent), values(other.values) {} - AttributePoint &operator=(const AttributePoint &other) { - percent = other.percent; scale = other.scale; origpercent = other.origpercent; values = other.values; return *this; - } - qreal percent; //massaged percent along the painter path - qreal scale; - qreal origpercent; //'real' percent along the painter path - QHash values; - }; - - void interpolate(int idx, const QString &name, qreal value); - void endpoint(const QString &name); - void createPointCache() const; - -private: - Q_DISABLE_COPY(QmlGraphicsPath) - Q_DECLARE_PRIVATE(QmlGraphicsPath) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsPathElement) -QML_DECLARE_TYPE(QmlGraphicsPathAttribute) -QML_DECLARE_TYPE(QmlGraphicsCurve) -QML_DECLARE_TYPE(QmlGraphicsPathLine) -QML_DECLARE_TYPE(QmlGraphicsPathQuad) -QML_DECLARE_TYPE(QmlGraphicsPathCubic) -QML_DECLARE_TYPE(QmlGraphicsPathPercent) -QML_DECLARE_TYPE(QmlGraphicsPath) - -QT_END_HEADER - -#endif // QFXPATH_H diff --git a/src/declarative/fx/qfxpath_p.h b/src/declarative/fx/qfxpath_p.h deleted file mode 100644 index 49bd0d8..0000000 --- a/src/declarative/fx/qfxpath_p.h +++ /dev/null @@ -1,79 +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 QFXPATH_P_H -#define QFXPATH_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/qobject_p.h" -#include "qfxpath.h" -#include "qml.h" - - -QT_BEGIN_NAMESPACE -class QmlGraphicsPathPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsPath) - -public: - QmlGraphicsPathPrivate() : startX(0), startY(0) { } - - QPainterPath _path; - QList _pathElements; - mutable QVector _pointCache; - QList _attributePoints; - QStringList _attributes; - int startX; - int startY; -}; - -QT_END_NAMESPACE -#endif diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp deleted file mode 100644 index fd7d734..0000000 --- a/src/declarative/fx/qfxpathview.cpp +++ /dev/null @@ -1,913 +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 -#include -#include -#include "qmlstate.h" -#include "qlistmodelinterface.h" -#include "qmlopenmetaobject.h" - -#include "qfxpathview.h" -#include "qfxpathview_p.h" -#include - -static const int FlickThreshold = 5; - -QT_BEGIN_NAMESPACE - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathView,QmlGraphicsPathView) - -class QmlGraphicsPathViewAttached : public QObject -{ - Q_OBJECT -public: - QmlGraphicsPathViewAttached(QObject *parent) - : QObject(parent), mo(new QmlOpenMetaObject(this)) - { - } - - ~QmlGraphicsPathViewAttached() - { - QmlGraphicsPathView::attachedProperties.remove(parent()); - } - - QVariant value(const QByteArray &name) const - { - return mo->value(name); - } - void setValue(const QByteArray &name, const QVariant &val) - { - mo->setValue(name, val); - } - -private: - QmlOpenMetaObject *mo; -}; - - -/*! - \internal - \class QmlGraphicsPathView - \brief The QmlGraphicsPathView class lays out items provided by a model on a path. - - \ingroup group_views - - The model must be a \l QListModelInterface subclass. - - \sa QmlGraphicsPath -*/ - -/*! - \qmlclass PathView - \brief The PathView element lays out model-provided items on a path. - \inherits Item - - The model is typically provided by a QAbstractListModel "C++ model object", but can also be created directly in QML. - - The items are laid out along a path defined by a \l Path and may be flicked to scroll. - - \snippet doc/src/snippets/declarative/pathview/pathview.qml 0 - - \image pathview.gif - - \sa Path -*/ - -QmlGraphicsPathView::QmlGraphicsPathView(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsPathViewPrivate), parent) -{ - Q_D(QmlGraphicsPathView); - d->init(); -} - -QmlGraphicsPathView::QmlGraphicsPathView(QmlGraphicsPathViewPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ - Q_D(QmlGraphicsPathView); - d->init(); -} - -QmlGraphicsPathView::~QmlGraphicsPathView() -{ - Q_D(QmlGraphicsPathView); - if (d->ownModel) - delete d->model; -} - -/*! - \qmlproperty model PathView::model - This property holds the model providing data for the view. - - The model provides a set of data that is used to create the items for the view. - For large or dynamic datasets the model is usually provided by a C++ model object. - Models can also be created directly in XML, using the ListModel element. - - \sa {qmlmodels}{Data Models} -*/ -QVariant QmlGraphicsPathView::model() const -{ - Q_D(const QmlGraphicsPathView); - return d->modelVariant; -} - -void QmlGraphicsPathView::setModel(const QVariant &model) -{ - Q_D(QmlGraphicsPathView); - if (d->model) { - disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); - disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); - disconnect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); - for (int i=0; iitems.count(); i++){ - QmlGraphicsItem *p = d->items[i]; - d->model->release(p); - } - d->items.clear(); - } - - d->modelVariant = model; - QObject *object = qvariant_cast(model); - QmlGraphicsVisualModel *vim = 0; - if (object && (vim = qobject_cast(object))) { - if (d->ownModel) { - delete d->model; - d->ownModel = false; - } - d->model = vim; - } else { - if (!d->ownModel) { - d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); - d->ownModel = true; - } - if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) - dataModel->setModel(model); - } - if (d->model) { - connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); - connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); - connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); - } - d->firstIndex = 0; - d->pathOffset = 0; - d->regenerate(); - d->fixOffset(); -} - -/*! - \qmlproperty int PathView::count - This property holds the number of items in the model. -*/ -int QmlGraphicsPathView::count() const -{ - Q_D(const QmlGraphicsPathView); - return d->model ? d->model->count() : 0; -} - -/*! - \qmlproperty Path PathView::path - \default - This property holds the path used to lay out the items. - For more information see the \l Path documentation. -*/ -QmlGraphicsPath *QmlGraphicsPathView::path() const -{ - Q_D(const QmlGraphicsPathView); - return d->path; -} - -void QmlGraphicsPathView::setPath(QmlGraphicsPath *path) -{ - Q_D(QmlGraphicsPathView); - d->path = path; - connect(d->path, SIGNAL(changed()), this, SLOT(refill())); - d->regenerate(); -} - -/*! - \qmlproperty int PathView::currentIndex - This property holds the index of the current item. -*/ -int QmlGraphicsPathView::currentIndex() const -{ - Q_D(const QmlGraphicsPathView); - return d->currentIndex; -} - -void QmlGraphicsPathView::setCurrentIndex(int idx) -{ - Q_D(QmlGraphicsPathView); - if (d->model && d->model->count()) - idx = qAbs(idx % d->model->count()); - if (d->model && idx != d->currentIndex) { - d->currentIndex = idx; - if (d->model->count()) { - d->snapToCurrent(); - int itemIndex = (idx - d->firstIndex + d->model->count()) % d->model->count(); - if (itemIndex < d->items.count()) - d->items.at(itemIndex)->setFocus(true); - } - emit currentIndexChanged(); - } -} - -/*! - \qmlproperty real PathView::offset - - The offset specifies how far along the path the items are from their initial positions. -*/ -qreal QmlGraphicsPathView::offset() const -{ - Q_D(const QmlGraphicsPathView); - return d->_offset; -} - -void QmlGraphicsPathView::setOffset(qreal offset) -{ - Q_D(QmlGraphicsPathView); - d->setOffset(offset); - d->updateCurrent(); -} - -void QmlGraphicsPathViewPrivate::setOffset(qreal o) -{ - Q_Q(QmlGraphicsPathView); - if (_offset != o) { - _offset = fmod(o, 100.0); - if (_offset < 0) - _offset = 100.0 + _offset; - q->refill(); - } -} - -/*! - \qmlproperty real PathView::snapPosition - - This property determines the position (0-100) the nearest item will snap to. -*/ -qreal QmlGraphicsPathView::snapPosition() const -{ - Q_D(const QmlGraphicsPathView); - return d->snapPos; -} - -void QmlGraphicsPathView::setSnapPosition(qreal pos) -{ - Q_D(QmlGraphicsPathView); - d->snapPos = pos/100; - d->fixOffset(); -} - -/*! - \qmlproperty real PathView::dragMargin - This property holds the maximum distance from the path that initiate mouse dragging. - - By default the path can only be dragged by clicking on an item. If - dragMargin is greater than zero, a drag can be initiated by clicking - within dragMargin pixels of the path. -*/ -qreal QmlGraphicsPathView::dragMargin() const -{ - Q_D(const QmlGraphicsPathView); - return d->dragMargin; -} - -void QmlGraphicsPathView::setDragMargin(qreal dragMargin) -{ - Q_D(QmlGraphicsPathView); - d->dragMargin = dragMargin; -} - -/*! - \qmlproperty component PathView::delegate - - The delegate provides a template describing what each item in the view should look and act like. - - Here is an example delegate: - \snippet doc/src/snippets/declarative/pathview/pathview.qml 1 -*/ -QmlComponent *QmlGraphicsPathView::delegate() const -{ - Q_D(const QmlGraphicsPathView); - if (d->model) { - if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) - return dataModel->delegate(); - } - - return 0; -} - -void QmlGraphicsPathView::setDelegate(QmlComponent *c) -{ - Q_D(QmlGraphicsPathView); - if (!d->ownModel) { - d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); - d->ownModel = true; - } - if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) { - dataModel->setDelegate(c); - d->regenerate(); - } -} - -/*! - \qmlproperty int PathView::pathItemCount - This property holds the number of items visible on the path at any one time -*/ -int QmlGraphicsPathView::pathItemCount() const -{ - Q_D(const QmlGraphicsPathView); - return d->pathItems; -} - -void QmlGraphicsPathView::setPathItemCount(int i) -{ - Q_D(QmlGraphicsPathView); - if (i == d->pathItems) - return; - d->pathItems = i; - d->regenerate(); -} - -QPointF QmlGraphicsPathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const -{ - //XXX maybe do recursively at increasing resolution. - qreal mindist = 1e10; // big number - QPointF nearPoint = path->pointAt(0); - qreal nearPc = 0; - for (qreal i=1; i < 1000; i++) { - QPointF pt = path->pointAt(i/1000.0); - QPointF diff = pt - point; - qreal dist = diff.x()*diff.x() + diff.y()*diff.y(); - if (dist < mindist) { - nearPoint = pt; - nearPc = i; - mindist = dist; - } - } - - if (nearPercent) - *nearPercent = nearPc / 10.0; - - return nearPoint; -} - - -void QmlGraphicsPathView::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsPathView); - if (!d->items.count()) - return; - QPointF scenePoint = mapToScene(event->pos()); - int idx = 0; - for (; idx < d->items.count(); ++idx) { - QRectF rect = d->items.at(idx)->boundingRect(); - rect = d->items.at(idx)->mapToScene(rect).boundingRect(); - if (rect.contains(scenePoint)) - break; - } - if (idx == d->items.count() && d->dragMargin == 0.) // didn't click on an item - return; - - d->startPoint = d->pointNear(event->pos(), &d->startPc); - if (idx == d->items.count()) { - qreal distance = qAbs(event->pos().x() - d->startPoint.x()) + qAbs(event->pos().y() - d->startPoint.y()); - if (distance > d->dragMargin) - return; - } - - d->stealMouse = false; - d->lastElapsed = 0; - d->lastDist = 0; - QmlGraphicsItemPrivate::start(d->lastPosTime); - d->tl.clear(); -} - -void QmlGraphicsPathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsPathView); - if (d->lastPosTime.isNull()) - return; - - if (!d->stealMouse) { - QPointF delta = event->pos() - d->startPoint; - if (qAbs(delta.x()) > FlickThreshold && qAbs(delta.y()) > FlickThreshold) - d->stealMouse = true; - } - - if (d->stealMouse) { - d->moveReason = QmlGraphicsPathViewPrivate::Mouse; - qreal newPc; - d->pointNear(event->pos(), &newPc); - qreal diff = newPc - d->startPc; - if (diff) { - setOffset(d->_offset + diff); - - if (diff > 50) - diff -= 100; - else if (diff < -50) - diff += 100; - - d->lastElapsed = QmlGraphicsItemPrivate::restart(d->lastPosTime); - d->lastDist = diff; - d->startPc = newPc; - } - } -} - -void QmlGraphicsPathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) -{ - Q_D(QmlGraphicsPathView); - if (d->lastPosTime.isNull()) - return; - - qreal elapsed = qreal(d->lastElapsed + QmlGraphicsItemPrivate::elapsed(d->lastPosTime)) / 1000.; - qreal velocity = elapsed > 0. ? d->lastDist / elapsed : 0; - if (d->model && d->model->count() && qAbs(velocity) > 5) { - if (velocity > 100) - velocity = 100; - else if (velocity < -100) - velocity = -100; - qreal inc = fmod(d->_offset - d->snapPos, 100.0 / d->model->count()); - qreal dist = qAbs(velocity/2 - fmod(velocity/2, 100.0 / d->model->count()) - inc); - d->moveOffset.setValue(d->_offset); - d->tl.accel(d->moveOffset, velocity, 10, dist); - d->tl.execute(d->fixupOffsetEvent); - } else { - d->fixOffset(); - } - - d->lastPosTime = QTime(); - d->stealMouse = false; - ungrabMouse(); -} - -bool QmlGraphicsPathView::sendMouseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsPathView); - QGraphicsSceneMouseEvent mouseEvent(event->type()); - QRectF myRect = mapToScene(QRectF(0, 0, width(), height())).boundingRect(); - QGraphicsScene *s = scene(); - QmlGraphicsItem *grabber = s ? qobject_cast(s->mouseGrabberItem()) : 0; - if ((d->stealMouse || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) { - mouseEvent.setAccepted(false); - for (int i = 0x1; i <= 0x10; i <<= 1) { - if (event->buttons() & i) { - Qt::MouseButton button = Qt::MouseButton(i); - mouseEvent.setButtonDownPos(button, mapFromScene(event->buttonDownPos(button))); - } - } - mouseEvent.setScenePos(event->scenePos()); - mouseEvent.setLastScenePos(event->lastScenePos()); - mouseEvent.setPos(mapFromScene(event->scenePos())); - mouseEvent.setLastPos(mapFromScene(event->lastScenePos())); - - switch(mouseEvent.type()) { - case QEvent::GraphicsSceneMouseMove: - mouseMoveEvent(&mouseEvent); - break; - case QEvent::GraphicsSceneMousePress: - mousePressEvent(&mouseEvent); - break; - case QEvent::GraphicsSceneMouseRelease: - mouseReleaseEvent(&mouseEvent); - break; - default: - break; - } - grabber = qobject_cast(s->mouseGrabberItem()); - if (grabber && d->stealMouse && !grabber->keepMouseGrab() && grabber != this) - grabMouse(); - - return d->stealMouse; - } else if (!d->lastPosTime.isNull()) { - d->lastPosTime = QTime(); - } - return false; -} - -bool QmlGraphicsPathView::sceneEventFilter(QGraphicsItem *i, QEvent *e) -{ - if (!isVisible()) - return QmlGraphicsItem::sceneEventFilter(i, e); - - switch (e->type()) { - case QEvent::GraphicsSceneMousePress: - case QEvent::GraphicsSceneMouseMove: - case QEvent::GraphicsSceneMouseRelease: - { - bool ret = sendMouseEvent(static_cast(e)); - if (e->type() == QEvent::GraphicsSceneMouseRelease) - return ret; - break; - } - default: - break; - } - - return QmlGraphicsItem::sceneEventFilter(i, e); -} - -void QmlGraphicsPathView::componentComplete() -{ - Q_D(QmlGraphicsPathView); - QmlGraphicsItem::componentComplete(); - d->regenerate(); - - // move to correct offset - if (d->items.count()) { - int itemIndex = (d->currentIndex - d->firstIndex + d->model->count()) % d->model->count(); - - itemIndex += d->pathOffset; - itemIndex %= d->items.count(); - qreal targetOffset = fmod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), 100); - - if (targetOffset < 0) - targetOffset = 100.0 + targetOffset; - if (targetOffset != d->_offset) { - d->moveOffset.setValue(targetOffset); - } - } -} - -void QmlGraphicsPathViewPrivate::regenerate() -{ - Q_Q(QmlGraphicsPathView); - if (!q->isComponentComplete()) - return; - - for (int i=0; i= model->count()) - firstIndex = model->count()-1; - if (pathOffset >= model->count()) - pathOffset = model->count()-1; - - int numItems = pathItems >= 0 ? pathItems : model->count(); - for (int i=0; i < numItems && i < model->count(); ++i){ - int index = (i + firstIndex) % model->count(); - QmlGraphicsItem *item = getItem(index); - if (!item) { - qWarning() << "PathView: Cannot create item, index" << (i + firstIndex) % model->count(); - return; - } - items.append(item); - item->setZValue(i); - if (currentIndex == index) - item->setFocus(true); - } - q->refill(); -} - -void QmlGraphicsPathViewPrivate::updateItem(QmlGraphicsItem *item, qreal percent) -{ - if (QObject *obj = QmlGraphicsPathView::qmlAttachedProperties(item)) { - foreach(const QString &attr, path->attributes()) - static_cast(obj)->setValue(attr.toUtf8(), path->attributeAt(attr, percent)); - } - QPointF pf = path->pointAt(percent); - item->setX(pf.x() - item->width()*item->scale()/2); - item->setY(pf.y() - item->height()*item->scale()/2); -} - -void QmlGraphicsPathView::refill() -{ - Q_D(QmlGraphicsPathView); - if (!d->isValid() || !isComponentComplete()) - return; - - QList positions; - for (int i=0; iitems.count(); i++){ - qreal percent = i * (100. / d->items.count()); - percent = percent + d->_offset; - percent = fmod(percent,100.); - positions << qAbs(percent/100.0); - } - - if (d->pathItems==-1) { - for (int i=0; iupdateItem(d->items.at(i), positions[i]); - return; - } - - QList rotatedPositions; - for (int i=0; iitems.count(); i++) - rotatedPositions << positions[(i + d->pathOffset + d->items.count()) % d->items.count()]; - - int wrapIndex= -1; - for (int i=0; iitems.count()-1; i++) { - if (rotatedPositions[i] > rotatedPositions[i+1]){ - wrapIndex = i; - break; - } - } - if (wrapIndex != -1 ){ - //A wraparound has occured - if (wrapIndex < d->items.count()/2){ - while(wrapIndex-- >= 0){ - QmlGraphicsItem* p = d->items.takeFirst(); - d->updateItem(p, 0.0); - d->releaseItem(p); - d->firstIndex++; - d->firstIndex %= d->model->count(); - int index = (d->firstIndex + d->items.count())%d->model->count(); - QmlGraphicsItem *item = d->getItem(index); - item->setZValue(wrapIndex); - if (d->currentIndex == index) - item->setFocus(true); - d->items << item; - d->pathOffset++; - d->pathOffset=d->pathOffset % d->items.count(); - } - } else { - while(wrapIndex++ < d->items.count()-1){ - QmlGraphicsItem* p = d->items.takeLast(); - d->updateItem(p, 1.0); - d->releaseItem(p); - d->firstIndex--; - if (d->firstIndex < 0) - d->firstIndex = d->model->count() - 1; - QmlGraphicsItem *item = d->getItem(d->firstIndex); - item->setZValue(d->firstIndex); - if (d->currentIndex == d->firstIndex) - item->setFocus(true); - d->items.prepend(item); - d->pathOffset--; - if (d->pathOffset < 0) - d->pathOffset = d->items.count() - 1; - } - } - for (int i=0; iitems.count(); i++) - rotatedPositions[i] = positions[(i + d->pathOffset + d->items.count()) - % d->items.count()]; - } - for (int i=0; iitems.count(); i++) - d->updateItem(d->items.at(i), rotatedPositions[i]); -} - -void QmlGraphicsPathView::itemsInserted(int modelIndex, int count) -{ - //XXX support animated insertion - Q_D(QmlGraphicsPathView); - if (!d->isValid() || !isComponentComplete()) - return; - if (d->pathItems == -1) { - for (int i = 0; i < count; ++i) { - QmlGraphicsItem *item = d->getItem(modelIndex + i); - item->setZValue(modelIndex + i); - d->items.insert(modelIndex + i, item); - } - refill(); - } else { - //XXX This is pretty heavy handed until we reference count items. - d->regenerate(); - } - - // make sure the current item is still at the snap position - int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count(); - itemIndex += d->pathOffset; - itemIndex %= d->items.count(); - qreal targetOffset = fmod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), 100); - - if (targetOffset < 0) - targetOffset = 100.0 + targetOffset; - if (targetOffset != d->_offset) - d->moveOffset.setValue(targetOffset); -} - -void QmlGraphicsPathView::itemsRemoved(int modelIndex, int count) -{ - //XXX support animated removal - Q_D(QmlGraphicsPathView); - if (!d->isValid() || !isComponentComplete()) - return; - if (d->pathItems == -1) { - for (int i = 0; i < count; ++i) { - QmlGraphicsItem* p = d->items.takeAt(modelIndex); - d->model->release(p); - } - d->snapToCurrent(); - refill(); - } else { - d->regenerate(); - } - - if (d->model->count() == 0) { - d->currentIndex = -1; - d->moveOffset.setValue(0); - return; - } - - // make sure the current item is still at the snap position - if (d->currentIndex >= d->model->count()) - d->currentIndex = d->model->count() - 1; - int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count(); - itemIndex += d->pathOffset; - itemIndex %= d->items.count(); - qreal targetOffset = fmod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), 100); - - if (targetOffset < 0) - targetOffset = 100.0 + targetOffset; - if (targetOffset != d->_offset) - d->moveOffset.setValue(targetOffset); -} - -void QmlGraphicsPathView::createdItem(int index, QmlGraphicsItem *item) -{ - Q_D(QmlGraphicsPathView); - if (d->requestedIndex != index) { - item->setParentItem(this); - d->updateItem(item, index < d->firstIndex ? 0.0 : 1.0); - } -} - -void QmlGraphicsPathView::destroyingItem(QmlGraphicsItem *item) -{ - Q_UNUSED(item); -} - -void QmlGraphicsPathView::ticked() -{ - Q_D(QmlGraphicsPathView); - d->updateCurrent(); -} - -// find the item closest to the snap position -int QmlGraphicsPathViewPrivate::calcCurrentIndex() -{ - int current = -1; - if (model && items.count()) { - _offset = fmod(_offset, 100.0); - if (_offset < 0) - _offset += 100.0; - - if (pathItems == -1) { - qreal delta = fmod(_offset - snapPos, 100.0); - if (delta < 0) - delta = 100.0 + delta; - int ii = model->count() - qRound(delta * model->count() / 100); - if (ii < 0) - ii = 0; - current = ii; - } else { - qreal bestDiff=1e9; - int bestI=-1; - for (int i=0; icount()); - } - - return current; -} - -void QmlGraphicsPathViewPrivate::updateCurrent() -{ - Q_Q(QmlGraphicsPathView); - if (moveReason != Mouse) - return; - int idx = calcCurrentIndex(); - if (model && idx != currentIndex) { - currentIndex = idx; - int itemIndex = (idx - firstIndex + model->count()) % model->count(); - if (itemIndex < items.count()) - items.at(itemIndex)->setFocus(true); - emit q->currentIndexChanged(); - } -} - -void QmlGraphicsPathViewPrivate::fixOffset() -{ - Q_Q(QmlGraphicsPathView); - if (model && items.count()) { - int curr = calcCurrentIndex(); - if (curr != currentIndex) - q->setCurrentIndex(curr); - else - snapToCurrent(); - } -} - -void QmlGraphicsPathViewPrivate::snapToCurrent() -{ - if (!model || model->count() <= 0) - return; - - int itemIndex = (currentIndex - firstIndex + model->count()) % model->count(); - - //Rounds is the number of times round to make the current item visible - int rounds = itemIndex / items.count(); - int otherWayRounds = (model->count() - (itemIndex)) / items.count() + 1; - if (otherWayRounds < rounds) - rounds = -otherWayRounds; - - itemIndex += pathOffset; - itemIndex %= items.count(); - qreal targetOffset = fmod(100 + (snapPos*100) - 100.0 * itemIndex / items.count(), 100); - - if (targetOffset < 0) - targetOffset = 100.0 + targetOffset; - if (targetOffset == _offset && rounds == 0) - return; - - moveReason = Other; - tl.clear(); - moveOffset.setValue(_offset); - - if (rounds!=0){ - //Compensate if the targetOffset would bring the target it from off the screen - qreal distance = targetOffset - _offset; - if (distance <= -50) - rounds--; - if (distance > 50) - rounds++; - tl.move(moveOffset, targetOffset + 100.0*(-rounds), QEasingCurve(QEasingCurve::InOutQuad), - int(100*items.count()*qMax((qreal)(2.0/items.count()),(qreal)qAbs(rounds)))); - tl.execute(fixupOffsetEvent); - return; - } - - if (targetOffset - _offset > 50.0) { - qreal distance = 100 - targetOffset + _offset; - tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * _offset / distance)); - tl.set(moveOffset, 100.0); - tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * (100-targetOffset) / distance)); - } else if (targetOffset - _offset <= -50.0) { - qreal distance = 100 - _offset + targetOffset; - tl.move(moveOffset, 100.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * (100-_offset) / distance)); - tl.set(moveOffset, 0.0); - tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * targetOffset / distance)); - } else { - tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), 200); - } -} - -QHash QmlGraphicsPathView::attachedProperties; -QObject *QmlGraphicsPathView::qmlAttachedProperties(QObject *obj) -{ - QObject *rv = attachedProperties.value(obj); - if (!rv) { - rv = new QmlGraphicsPathViewAttached(obj); - attachedProperties.insert(obj, rv); - } - return rv; -} - -QT_END_NAMESPACE - -#include "qfxpathview.moc" diff --git a/src/declarative/fx/qfxpathview.h b/src/declarative/fx/qfxpathview.h deleted file mode 100644 index e961106..0000000 --- a/src/declarative/fx/qfxpathview.h +++ /dev/null @@ -1,138 +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 QFXPATHVIEW_H -#define QFXPATHVIEW_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QListModelInterface; -class QmlGraphicsPathViewPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsPathView : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QmlGraphicsPath *path READ path WRITE setPath) - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged) - Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition) - Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin) - Q_PROPERTY(int count READ count) - Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount) - -public: - QmlGraphicsPathView(QmlGraphicsItem *parent=0); - virtual ~QmlGraphicsPathView(); - - QVariant model() const; - void setModel(const QVariant &); - - QmlGraphicsPath *path() const; - void setPath(QmlGraphicsPath *); - - int currentIndex() const; - void setCurrentIndex(int idx); - - qreal offset() const; - void setOffset(qreal offset); - - qreal snapPosition() const; - void setSnapPosition(qreal pos); - - qreal dragMargin() const; - void setDragMargin(qreal margin); - - int count() const; - - QmlComponent *delegate() const; - void setDelegate(QmlComponent *); - - int pathItemCount() const; - void setPathItemCount(int); - - static QObject *qmlAttachedProperties(QObject *); - -Q_SIGNALS: - void currentIndexChanged(); - void offsetChanged(); - -protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *); - bool sendMouseEvent(QGraphicsSceneMouseEvent *event); - bool sceneEventFilter(QGraphicsItem *, QEvent *); - void componentComplete(); - -private Q_SLOTS: - void refill(); - void ticked(); - void itemsInserted(int index, int count); - void itemsRemoved(int index, int count); - void createdItem(int index, QmlGraphicsItem *item); - void destroyingItem(QmlGraphicsItem *item); - -protected: - QmlGraphicsPathView(QmlGraphicsPathViewPrivate &dd, QmlGraphicsItem *parent); - -private: - friend class QmlGraphicsPathViewAttached; - static QHash attachedProperties; - Q_DISABLE_COPY(QmlGraphicsPathView) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsPathView) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsPathView) -QML_DECLARE_TYPEINFO(QmlGraphicsPathView, QML_HAS_ATTACHED_PROPERTIES) -QT_END_HEADER - -#endif // QFXPATHVIEW_H diff --git a/src/declarative/fx/qfxpathview_p.h b/src/declarative/fx/qfxpathview_p.h deleted file mode 100644 index 23b468c..0000000 --- a/src/declarative/fx/qfxpathview_p.h +++ /dev/null @@ -1,151 +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 QFXPATHVIEW_P_H -#define QFXPATHVIEW_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 "qdatetime.h" -#include "qfxpathview.h" -#include "qfxitem_p.h" -#include "qfxvisualitemmodel.h" -#include "qml.h" -#include "private/qmlanimation_p.h" - -QT_BEGIN_NAMESPACE - -typedef struct PathViewItem{ - int index; - QmlGraphicsItem* item; -}PathViewItem; - -class QmlGraphicsPathViewPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsPathView) - -public: - QmlGraphicsPathViewPrivate() - : path(0), currentIndex(0), startPc(0), lastDist(0) - , lastElapsed(0), stealMouse(false), ownModel(false), activeItem(0) - , snapPos(0), dragMargin(0), moveOffset(this, &QmlGraphicsPathViewPrivate::setOffset) - , firstIndex(0), pathItems(-1), pathOffset(0), requestedIndex(-1), model(0) - , moveReason(Other) - { - fixupOffsetEvent = QmlTimeLineEvent::timeLineEvent(&moveOffset, this); - } - - void init() - { - Q_Q(QmlGraphicsPathView); - _offset = 0; - q->setAcceptedMouseButtons(Qt::LeftButton); - q->setFlag(QGraphicsItem::ItemIsFocusScope); - q->setFiltersChildEvents(true); - q->connect(&tl, SIGNAL(updated()), q, SLOT(ticked())); - } - - QmlGraphicsItem *getItem(int modelIndex) { - Q_Q(QmlGraphicsPathView); - requestedIndex = modelIndex; - QmlGraphicsItem *item = model->item(modelIndex); - if (item) - item->setParentItem(q); - requestedIndex = -1; - return item; - } - void releaseItem(QmlGraphicsItem *item) { - model->release(item); - } - - bool isValid() const { - return model && model->count() > 0 && model->isValid() && path; - } - - int calcCurrentIndex(); - void updateCurrent(); - void fixOffset(); - void setOffset(qreal offset); - void regenerate(); - void updateItem(QmlGraphicsItem *, qreal); - void snapToCurrent(); - QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const; - - QmlGraphicsPath *path; - int currentIndex; - qreal startPc; - QPointF startPoint; - qreal lastDist; - int lastElapsed; - qreal _offset; - bool stealMouse : 1; - bool ownModel : 1; - QTime lastPosTime; - QPointF lastPos; - QmlGraphicsItem *activeItem; - qreal snapPos; - qreal dragMargin; - QmlTimeLine tl; - QmlTimeLineValueProxy moveOffset; - QmlTimeLineEvent fixupOffsetEvent; - int firstIndex; - int pathItems; - int pathOffset; - int requestedIndex; - QList items; - QmlGraphicsVisualModel *model; - QVariant modelVariant; - enum MovementReason { Other, Key, Mouse }; - MovementReason moveReason; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/declarative/fx/qfxpixmapcache.cpp b/src/declarative/fx/qfxpixmapcache.cpp deleted file mode 100644 index 4d6104c..0000000 --- a/src/declarative/fx/qfxpixmapcache.cpp +++ /dev/null @@ -1,282 +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 "qfxpixmapcache.h" -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QSharedNetworkReply; -typedef QHash QmlGraphicsSharedNetworkReplyHash; -static QmlGraphicsSharedNetworkReplyHash qfxActiveNetworkReplies; - -class QSharedNetworkReply -{ -public: - QSharedNetworkReply(QNetworkReply *r) : reply(r), refCount(1) {} - ~QSharedNetworkReply() - { - reply->deleteLater(); - } - QNetworkReply *reply; - QPixmap pixmap; // ensure reference to pixmap to QPixmapCache does not discard - - int refCount; - void addRef() - { - ++refCount; - } - void release() - { - Q_ASSERT(refCount > 0); - --refCount; - if (refCount == 0) { - QString key = reply->url().toString(); - qfxActiveNetworkReplies.remove(key); - delete this; - } - } -}; - -static bool readImage(QIODevice *dev, QPixmap *pixmap) - { - QImageReader imgio(dev); - -//#define QT_TEST_SCALED_SIZE -#ifdef QT_TEST_SCALED_SIZE - /* - Some mechanism is needed for loading images at a limited size, especially - for remote images. Loading only thumbnails of remote progressive JPEG - images can be efficient. (Qt jpeg handler does not do so currently) - */ - - QSize limit(60,60); - QSize sz = imgio.size(); - if (sz.width() > limit.width() || sz.height() > limit.height()) { - sz.scale(limit,Qt::KeepAspectRatio); - imgio.setScaledSize(sz); - } -#endif - - QImage img; - if (imgio.read(&img)) { -#ifdef QT_TEST_SCALED_SIZE - if (!sz.isValid()) - img = img.scaled(limit,Qt::KeepAspectRatio); -#endif - *pixmap = QPixmap::fromImage(img); - return true; - } else { - qWarning() << imgio.errorString(); - return false; - } - } - -/*! - \internal - \class QmlGraphicsPixmapCache - \brief Enacapsultes a pixmap for QmlGraphics items. - - This class is NOT reentrant. - */ - -static QString toLocalFileOrQrc(const QUrl& url) -{ - QString r = url.toLocalFile(); - if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) - r = QLatin1Char(':') + url.path(); - return r; -} - -/*! - Finds the cached pixmap corresponding to \a url. - A previous call to get() must have requested the URL, - and the QNetworkReply must have finished before calling - this function. - - Returns true if the image was loaded without error. -*/ -bool QmlGraphicsPixmapCache::find(const QUrl& url, QPixmap *pixmap) -{ -#ifdef Q_ENABLE_PERFORMANCE_LOG - QmlPerfTimer perf; -#endif - - QString key = url.toString(); - bool ok = true; - if (!QPixmapCache::find(key,pixmap)) { -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - QString lf = toLocalFileOrQrc(url); - if (!lf.isEmpty()) { - QFile f(lf); - if (f.open(QIODevice::ReadOnly)) { - if (!readImage(&f, pixmap)) { - qWarning() << "Format error loading" << url; - *pixmap = QPixmap(); - ok = false; - } - } else { - *pixmap = QPixmap(); - ok = false; - } - } else -#endif - { - QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter == qfxActiveNetworkReplies.end()) { - // API usage error - qWarning() << "QmlGraphicsPixmapCache: URL not loaded" << url; - ok = false; - } else { - if ((*iter)->reply->error()) { - qWarning() << "Network error loading" << url << (*iter)->reply->errorString(); - *pixmap = QPixmap(); - ok = false; - } else if (!readImage((*iter)->reply, pixmap)) { - qWarning() << "Format error loading" << url; - *pixmap = QPixmap(); - ok = false; - } else { - if ((*iter)->refCount > 1) - (*iter)->pixmap = *pixmap; - } - (*iter)->release(); - } - } - QPixmapCache::insert(key, *pixmap); - } else { - ok = !pixmap->isNull(); -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - if (url.scheme()!=QLatin1String("file")) -#endif - // We may be the second finder. Still need to check for active replies. - { - QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter != qfxActiveNetworkReplies.end()) - (*iter)->release(); - } - } - return ok; -} - -/*! - Starts a network request to load \a url. - - Returns a QNetworkReply if the image is not immediately available, otherwise - returns 0. Caller should connect to QNetworkReply::finished() to then call - find() when the image is available. - - The returned QNetworkReply will be deleted when all get() calls are - matched by a corresponding find() call. -*/ -QNetworkReply *QmlGraphicsPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap *pixmap) -{ -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - QString lf = toLocalFileOrQrc(url); - if (!lf.isEmpty()) { - QString key = url.toString(); - if (!QPixmapCache::find(key,pixmap)) { - QFile f(lf); - if (f.open(QIODevice::ReadOnly)) { - if (!readImage(&f, pixmap)) { - qWarning() << "Format error loading" << url; - *pixmap = QPixmap(); - } - } else - *pixmap = QPixmap(); - QPixmapCache::insert(key, *pixmap); - } - return 0; - } -#endif - - QString key = url.toString(); - if (QPixmapCache::find(key,pixmap)) { - return 0; - } - - QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter == qfxActiveNetworkReplies.end()) { - QNetworkRequest req(url); - QSharedNetworkReply *item = new QSharedNetworkReply(engine->networkAccessManager()->get(req)); - iter = qfxActiveNetworkReplies.insert(key, item); - } else { - (*iter)->addRef(); - } - - return (*iter)->reply; -} - -/*! - Cancels a previous call to get(). - - May also cancel loading (eg. if no other pending request). - - Any connections from the QNetworkReply returned by get() to \a obj will be - disconnected. -*/ -void QmlGraphicsPixmapCache::cancelGet(const QUrl& url, QObject* obj) -{ - QString key = url.toString(); - QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter == qfxActiveNetworkReplies.end()) - return; - if (obj) - QObject::disconnect((*iter)->reply, 0, obj, 0); - (*iter)->release(); -} - -/*! - This function is mainly for test verification. It returns the number of - requests that are still unfinished. -*/ -int QmlGraphicsPixmapCache::pendingRequests() -{ - return qfxActiveNetworkReplies.count(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpixmapcache.h b/src/declarative/fx/qfxpixmapcache.h deleted file mode 100644 index 2a5c4fa..0000000 --- a/src/declarative/fx/qfxpixmapcache.h +++ /dev/null @@ -1,72 +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 QFXPIXMAPCACHE_H -#define QFXPIXMAPCACHE_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlEngine; -class QNetworkReply; -class Q_DECLARATIVE_EXPORT QmlGraphicsPixmapCache -{ -public: - static QNetworkReply *get(QmlEngine *, const QUrl& url, QPixmap *pixmap); - static void cancelGet(const QUrl& url, QObject* obj); - - static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QmlGraphicsPixmapCache::get, and any returned reply finished. - - static int pendingRequests(); // mainly for test verification -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QFXPIXMAPCACHE_H diff --git a/src/declarative/fx/qfxpositioners.cpp b/src/declarative/fx/qfxpositioners.cpp deleted file mode 100644 index d7ae49d..0000000 --- a/src/declarative/fx/qfxpositioners.cpp +++ /dev/null @@ -1,921 +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 -#include -#include "qml.h" -#include "qmlstate.h" -#include "qmlstategroup.h" -#include "qmlstateoperations.h" -#include "private/qfxperf_p.h" -#include "qfxpositioners.h" -#include "qfxpositioners_p.h" - - -QT_BEGIN_NAMESPACE - -/*! - \internal - \class QmlGraphicsBasePositioner - \ingroup group_layouts - \brief The QmlGraphicsBasePositioner class provides a base for QmlGraphics layouts. - - To create a QmlGraphics Positioner, simply subclass QmlGraphicsBasePositioner and implement - doLayout(), which is automatically called when the layout might need - updating. - - It is strongly recommended that in your implementation of doLayout() - that you use the move, remove and add transitions when those conditions - arise. You can use the applyAdd, applyMove and applyRemove functions - to do this easily. - - Note also that the subclass is responsible for adding the - spacing in between items. -*/ -QmlGraphicsBasePositioner::QmlGraphicsBasePositioner(AutoUpdateType at, QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsBasePositionerPrivate), parent) -{ - Q_D(QmlGraphicsBasePositioner); - d->init(at); -} - -QmlGraphicsBasePositioner::QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, AutoUpdateType at, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ - Q_D(QmlGraphicsBasePositioner); - d->init(at); -} - -int QmlGraphicsBasePositioner::spacing() const -{ - Q_D(const QmlGraphicsBasePositioner); - return d->_spacing; -} - -void QmlGraphicsBasePositioner::setSpacing(int s) -{ - Q_D(QmlGraphicsBasePositioner); - if (s==d->_spacing) - return; - d->_spacing = s; - prePositioning(); - emit spacingChanged(); -} - -QmlTransition *QmlGraphicsBasePositioner::move() const -{ - Q_D(const QmlGraphicsBasePositioner); - return d->moveTransition; -} - -void QmlGraphicsBasePositioner::setMove(QmlTransition *mt) -{ - Q_D(QmlGraphicsBasePositioner); - d->moveTransition = mt; -} - -QmlTransition *QmlGraphicsBasePositioner::add() const -{ - Q_D(const QmlGraphicsBasePositioner); - return d->addTransition; -} - -void QmlGraphicsBasePositioner::setAdd(QmlTransition *add) -{ - Q_D(QmlGraphicsBasePositioner); - d->addTransition = add; -} - -QmlTransition *QmlGraphicsBasePositioner::remove() const -{ - Q_D(const QmlGraphicsBasePositioner); - return d->removeTransition; -} - -void QmlGraphicsBasePositioner::setRemove(QmlTransition *remove) -{ - Q_D(QmlGraphicsBasePositioner); - d->removeTransition = remove; -} - -void QmlGraphicsBasePositioner::componentComplete() -{ - QmlGraphicsItem::componentComplete(); -#ifdef Q_ENABLE_PERFORMANCE_LOG - QmlPerfTimer cc; -#endif - prePositioning(); -} - -QVariant QmlGraphicsBasePositioner::itemChange(GraphicsItemChange change, - const QVariant &value) -{ - if (change == ItemChildAddedChange || - change == ItemChildRemovedChange) { - prePositioning(); - } - - return QmlGraphicsItem::itemChange(change, value); -} - -bool QmlGraphicsBasePositioner::event(QEvent *e) -{ - Q_D(QmlGraphicsBasePositioner); - if (e->type() == QEvent::User) { - d->_ep = false; - d->_stableItems += d->_newItems; - d->_leavingItems.clear(); - d->_newItems.clear(); - return true; - } - return QmlGraphicsItem::event(e); -} - -/*! - Items that have just been added to the positioner. This includes invisible items - that have turned visible. -*/ -QSet* QmlGraphicsBasePositioner::newItems() -{ - Q_D(QmlGraphicsBasePositioner); - return &d->_newItems; -} - -/*! - Items that are visible in the positioner, not including ones that have just been added. -*/ -QSet* QmlGraphicsBasePositioner::items() -{ - Q_D(QmlGraphicsBasePositioner); - return &d->_stableItems; -} - -/*! - Items that have just left the positioner. This includes visible items - that have turned invisible. -*/ -QSet* QmlGraphicsBasePositioner::leavingItems() -{ - Q_D(QmlGraphicsBasePositioner); - return &d->_leavingItems; -} - -void QmlGraphicsBasePositioner::prePositioning() -{ - Q_D(QmlGraphicsBasePositioner); - if (!isComponentComplete() || d->_movingItem) - return; - - if (!d->_ep) { - d->_ep = true; - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - } - QSet allItems; - QList children = childItems(); - for (int ii = 0; ii < children.count(); ++ii) { - QmlGraphicsItem *child = qobject_cast(children.at(ii)); - if (!child) - continue; - if (!d->_items.contains(child)){ - QObject::connect(child, SIGNAL(visibleChanged()), - this, SLOT(prePositioning())); - QObject::connect(child, SIGNAL(opacityChanged()), - this, SLOT(prePositioning())); - QObject::connect(child, SIGNAL(heightChanged()), - this, SLOT(prePositioning())); - QObject::connect(child, SIGNAL(widthChanged()), - this, SLOT(prePositioning())); - d->_items += child; - } - if (child->opacity() == 0.0){ - if (d->_stableItems.contains(child)){ - d->_leavingItems += child; - d->_stableItems -= child; - } - }else if (!d->_stableItems.contains(child)){ - d->_newItems+=child; - } - allItems += child; - } - QSet deletedItems = d->_items - allItems; - foreach(QmlGraphicsItem *child, d->_items){ - if (!allItems.contains(child)){ - if (!deletedItems.contains(child)) { - QObject::disconnect(child, SIGNAL(opacityChanged()), - this, SLOT(prePositioning())); - QObject::disconnect(child, SIGNAL(heightChanged()), - this, SLOT(prePositioning())); - QObject::disconnect(child, SIGNAL(widthChanged()), - this, SLOT(prePositioning())); - } - d->_items -= child; - } - } - d->_animated.clear(); - doPositioning(); - finishApplyTransitions(); - //Set implicit size to the size of its children - //###To keep this valid, do we need to update on pos change as well? - qreal h = 0.0f; - qreal w = 0.0f; - foreach(QmlGraphicsItem *child, d->_items){ - if(!child->isVisible() || child->opacity() <= 0) - continue; - h = qMax(h, child->y() + child->height()); - w = qMax(w, child->x() + child->width()); - } - setImplicitHeight(h); - setImplicitWidth(w); -} - -void QmlGraphicsBasePositioner::applyTransition(const QList >& changes, QmlGraphicsItem* target, QmlStateOperation::ActionList &actions) -{ - Q_D(QmlGraphicsBasePositioner); - if (!target) - return; - - for (int ii=0; ii_animated << target; -} - -void QmlGraphicsBasePositioner::finishApplyTransitions() -{ - Q_D(QmlGraphicsBasePositioner); - // Note that if a transition is not set the transition manager will - // apply the changes directly, in the case someone uses applyAdd/Move/Remove - // without testing add()/move()/remove(). - d->addTransitionManager.transition(d->addActions, d->addTransition); - d->moveTransitionManager.transition(d->moveActions, d->moveTransition); - d->removeTransitionManager.transition(d->removeActions, d->removeTransition); - d->addActions.clear(); - d->moveActions.clear(); - d->removeActions.clear(); -} -void QmlGraphicsBasePositioner::setMovingItem(QmlGraphicsItem *i) -{ - Q_D(QmlGraphicsBasePositioner); - d->_movingItem = i; -} - -/*! - Applies the positioner's add transition to the \a target item.\a changes is a list of property,value - pairs which will be changed on the target using the add transition. -*/ -void QmlGraphicsBasePositioner::applyAdd(const QList >& changes, QmlGraphicsItem* target) -{ - Q_D(QmlGraphicsBasePositioner); - applyTransition(changes,target, d->addActions); -} - -/*! - Applies the positioner's move transition to the \a target.\a changes is a list of property,value pairs - which will be changed on the target using the move transition. -*/ -void QmlGraphicsBasePositioner::applyMove(const QList >& changes, QmlGraphicsItem* target) -{ - Q_D(QmlGraphicsBasePositioner); - applyTransition(changes,target, d->moveActions); -} - -/*! - Applies the positioner's remove transition to the \a target item.\a changes is a list of - property,value pairs which will be changed on the target using the remove transition. -*/ -void QmlGraphicsBasePositioner::applyRemove(const QList >& changes, QmlGraphicsItem* target) -{ - Q_D(QmlGraphicsBasePositioner); - applyTransition(changes,target, d->removeActions); -} - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Column,QmlGraphicsColumn) -/*! - \qmlclass Column - \brief The Column item lines up its children vertically. - \inherits Item - - The Column item positions its child items so that they are vertically - aligned and not overlapping. Spacing between items can be added. - - The below example positions differently shaped rectangles using a Column. - \table - \row - \o \image verticalpositioner_example.png - \o - \qml -Column { - spacing: 2 - Rectangle { color: "red"; width: 50; height: 50 } - Rectangle { color: "green"; width: 20; height: 50 } - Rectangle { color: "blue"; width: 50; height: 20 } -} - \endqml - \endtable - - Column also provides for transitions to be set when items are added, moved, - or removed in the positioner. Adding and removing apply both to items which are deleted - or have their position in the document changed so as to no longer be children of the positioner, - as well as to items which have their opacity set to or from zero so as to appear or disappear. - - \table - \row - \o \image verticalpositioner_transition.gif - \o - \qml -Column { - spacing: 2 - remove: ... - add: ... - move: ... - ... -} - \endqml - \endtable - - Note that the positioner assumes that the x and y positions of its children - will not change. If you manually change the x or y properties in script, bind - the x or y properties, or use anchors on a child of a positioner, then the - positioner may exhibit strange behaviour. - -*/ -/*! - \qmlproperty Transition Column::remove - This property holds the transition to apply when removing an item from the positioner. The transition is only applied to the removed items. - - Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. - - Note that if the item counts as removed because its opacity is zero it will not be visible during the transition unless you set the opacity in the transition, like in the below example. - - \table - \row - \o \image positioner-remove.gif - \o - \qml -Column { - remove: Transition { - NumberAnimation { - properties: "opacity" - from: 1 - to: 0 - duration: 500 - } - } -} - \endqml - \endtable - -*/ -/*! - \qmlproperty Transition Column::add - This property holds the transition to be applied when adding an item to the positioner. The transition will only be applied to the added item(s). - - Added can mean that either the object has been created or reparented, and thus is now a child or the positioner, or that the object has had its opacity increased from zero, and thus is now visible. - - \table - \row - \o \image positioner-add.gif - \o - \qml -Column { - add: Transition { - NumberAnimation { - properties: "opacity" - from: 0 - to: 1 - duration: 500 - } - } -} - \endqml - \endtable - -*/ -/*! - \qmlproperty Transition Column::move - This property holds the transition to apply when moving an item within the positioner. - - This can happen when other items are added or removed from the positioner, or when items resize themselves. - - \table - \row - \o \image positioner-move.gif - \o - \qml -Column { - move: Transition { - NumberAnimation { - properties: "y" - ease: "easeOutBounce" - } - } -} - \endqml - \endtable -*/ -/*! - \qmlproperty int Column::spacing - - spacing is the amount in pixels left empty between each adjacent - item, and defaults to 0. - - The below example places a Grid containing a red, a blue and a - green rectangle on a gray background. The area the grid positioner - occupies is colored white. The top positioner has the default of no spacing, - and the bottom positioner has its spacing set to 2. - - \image spacing_a.png - \image spacing_b.png - -*/ -/*! - \internal - \class QmlGraphicsColumn - \brief The QmlGraphicsColumn class lines up items vertically. - \ingroup group_positioners -*/ -QmlGraphicsColumn::QmlGraphicsColumn(QmlGraphicsItem *parent) -: QmlGraphicsBasePositioner(Vertical, parent) -{ -} - -void QmlGraphicsColumn::doPositioning() -{ - int voffset = 0; - - foreach(QmlGraphicsItem* item, *leavingItems()){ - if (remove()){ - QList > changes; - applyRemove(changes, item); - } - } - - QList children = childItems(); - for (int ii = 0; ii < children.count(); ++ii) { - QmlGraphicsItem *child = qobject_cast(children.at(ii)); - if (!child || child->opacity() == 0.0) - continue; - - bool needMove = (child->y() != voffset || child->x()); - - QList > changes; - changes << qMakePair(QString(QLatin1String("y")),QVariant(voffset)); - changes << qMakePair(QString(QLatin1String("x")),QVariant(0)); - if (needMove && items()->contains(child) && move()) { - applyMove(changes,child); - } else if (!items()->contains(child) && add()) { - applyAdd(changes,child); - } else if (needMove) { - setMovingItem(child); - child->setY(voffset); - setMovingItem(0); - } - voffset += child->height(); - voffset += spacing(); - } -} - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Row,QmlGraphicsRow) -/*! - \qmlclass Row - \brief The Row item lines up its children horizontally. - \inherits Item - - The Row item positions its child items so that they are - horizontally aligned and not overlapping. Spacing can be added between the - items, and a margin around all items can also be added. It also provides for - transitions to be set when items are added, moved, or removed in the - positioner. Adding and removing apply both to items which are deleted or have - their position in the document changed so as to no longer be children of the - positioner, as well as to items which have their opacity set to or from zero - so as to appear or disappear. - - The below example lays out differently shaped rectangles using a Row. - \qml -Row { - spacing: 2 - Rectangle { color: "red"; width: 50; height: 50 } - Rectangle { color: "green"; width: 20; height: 50 } - Rectangle { color: "blue"; width: 50; height: 20 } -} - \endqml - \image horizontalpositioner_example.png - - Note that the positioner assumes that the x and y positions of its children - will not change. If you manually change the x or y properties in script, bind - the x or y properties, or use anchors on a child of a positioner, then the - positioner may exhibit strange behaviour. - -*/ -/*! - \qmlproperty Transition Row::remove - This property holds the transition to apply when removing an item from the positioner. - The transition will only be applied to the removed item(s). - - Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. - - Note that if the item counts as removed because its opacity is zero it will not be visible during the transition unless you set the opacity in the transition, like in the below example. - - \qml -Row { - remove: Transition { - NumberAnimation { - properties: "opacity" - from: 1 - to: 0 - duration: 500 - } - } -} - \endqml - -*/ -/*! - \qmlproperty Transition Row::add - This property holds the transition to apply when adding an item to the positioner. - The transition will only be applied to the added item(s). - - Added can mean that either the object has been created or reparented, and thus is now a child or the positioner, or that the object has had its opacity increased from zero, and thus is now visible. - - \qml -Row { - add: Transition { - NumberAnimation { - properties: "opacity" - from: 0 - to: 1 - duration: 500 - } - } -} - \endqml - -*/ -/*! - \qmlproperty Transition Row::move - This property holds the transition to apply when moving an item within the positioner. - - This can happen when other items are added or removed from the positioner, or when items resize themselves. - - \qml -Row { - id: positioner - move: Transition { - NumberAnimation { - properties: "x" - ease: "easeOutBounce" - } - } -} - \endqml - -*/ -/*! - \qmlproperty int Row::spacing - - spacing is the amount in pixels left empty between each adjacent - item, and defaults to 0. - - The below example places a Grid containing a red, a blue and a - green rectangle on a gray background. The area the grid positioner - occupies is colored white. The top positioner has the default of no spacing, - and the bottom positioner has its spacing set to 2. - - \image spacing_a.png - \image spacing_b.png - -*/ -/*! - \internal - \class QmlGraphicsRow - \brief The QmlGraphicsRow class lines up items horizontally. - \ingroup group_positioners -*/ -QmlGraphicsRow::QmlGraphicsRow(QmlGraphicsItem *parent) -: QmlGraphicsBasePositioner(Horizontal, parent) -{ -} - -void QmlGraphicsRow::doPositioning() -{ - int hoffset = 0; - - foreach(QmlGraphicsItem* item, *leavingItems()){ - if (remove()){ - QList > changes; - applyRemove(changes, item); - } - } - QList children = childItems(); - for (int ii = 0; ii < children.count(); ++ii) { - QmlGraphicsItem *child = qobject_cast(children.at(ii)); - if (!child || child->opacity() == 0.0) - continue; - - bool needMove = (child->x() != hoffset || child->y()); - - QList > changes; - changes << qMakePair(QString(QLatin1String("x")),QVariant(hoffset)); - changes << qMakePair(QString(QLatin1String("y")),QVariant(0)); - if (needMove && items()->contains(child) && move()) { - applyMove(changes,child); - } else if (!items()->contains(child) && add()) { - applyAdd(changes,child); - } else if (needMove) { - setMovingItem(child); - child->setX(hoffset); - setMovingItem(0); - } - if(child->width() && child->height()){//don't advance for invisible children - hoffset += child->width(); - hoffset += spacing(); - } - } -} - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Grid,QmlGraphicsGrid) - -/*! - \qmlclass Grid QmlGraphicsGrid - \brief The Grid item positions its children in a grid. - \inherits Item - - The Grid item positions its child items so that they are - aligned in a grid and are not overlapping. Spacing can be added - between the items. It also provides for transitions to be set when items are - added, moved, or removed in the positioner. Adding and removing apply - both to items which are deleted or have their position in the - document changed so as to no longer be children of the positioner, as - well as to items which have their opacity set to or from zero so - as to appear or disappear. - - The Grid defaults to using four columns, and as many rows as - are necessary to fit all the child items. The number of rows - and/or the number of columns can be constrained by setting the rows - or columns properties. The grid positioner calculates a grid with - rectangular cells of sufficient size to hold all items, and then - places the items in the cells, going across then down, and - positioning each item at the (0,0) corner of the cell. The below - example demonstrates this. - - \table - \row - \o \image gridLayout_example.png - \o - \qml -Grid { - columns: 3 - spacing: 2 - Rectangle { color: "red"; width: 50; height: 50 } - Rectangle { color: "green"; width: 20; height: 50 } - Rectangle { color: "blue"; width: 50; height: 20 } - Rectangle { color: "cyan"; width: 50; height: 50 } - Rectangle { color: "magenta"; width: 10; height: 10 } -} - \endqml - \endtable - - Note that the positioner assumes that the x and y positions of its children - will not change. If you manually change the x or y properties in script, bind - the x or y properties, or use anchors on a child of a positioner, then the - positioner may exhibit strange behaviour. -*/ -/*! - \qmlproperty Transition Grid::remove - This property holds the transition to apply when removing an item from the positioner. - The transition is only applied to the removed item(s). - - Removed can mean that either the object has been deleted or - reparented, and thus is now longer a child of the positioner, or that - the object has had its opacity set to zero, and thus is no longer - visible. - - Note that if the item counts as removed because its opacity is - zero it will not be visible during the transition unless you set - the opacity in the transition, like in the below example. - - \qml -Grid { - remove: Transition { - NumberAnimation { - properties: "opacity" - from: 1 - to: 0 - duration: 500 - } - } -} - \endqml - -*/ -/*! - \qmlproperty Transition Grid::add - This property holds the transition to apply when adding an item to the positioner. - The transition is only applied to the added item(s). - - Added can mean that either the object has been created or - reparented, and thus is now a child or the positioner, or that the - object has had its opacity increased from zero, and thus is now - visible. - - \qml -Grid { - add: Transition { - NumberAnimation { - properties: "opacity" - from: 0 - to: 1 - duration: 500 - } - } -} - \endqml - -*/ -/*! - \qmlproperty Transition Grid::move - This property holds the transition to apply when moving an item within the positioner. - - This can happen when other items are added or removed from the positioner, or - when items resize themselves. - - \qml -Grid { - move: Transition { - NumberAnimation { - properties: "x,y" - ease: "easeOutBounce" - } - } -} - \endqml - -*/ -/*! - \qmlproperty int Grid::spacing - - spacing is the amount in pixels left empty between each adjacent - item, and defaults to 0. - - The below example places a Grid containing a red, a blue and a - green rectangle on a gray background. The area the grid positioner - occupies is colored white. The top positioner has the default of no spacing, - and the bottom positioner has its spacing set to 2. - - \image spacing_a.png - \image spacing_b.png - -*/ -/*! - \internal - \class QmlGraphicsGrid - \brief The QmlGraphicsGrid class lays out items in a grid. - \ingroup group_layouts - -*/ -QmlGraphicsGrid::QmlGraphicsGrid(QmlGraphicsItem *parent) : - QmlGraphicsBasePositioner(Both, parent) -{ - _columns=-1; - _rows=-1; -} - -/*! - \qmlproperty int Grid::columns - This property holds the number of columns in the grid. - - When the columns property is set the Grid will always have - that many columns. Note that if you do not have enough items to - fill this many columns some columns will be of zero width. -*/ - -/*! - \qmlproperty int Grid::rows - This property holds the number of rows in the grid. - - When the rows property is set the Grid will always have that - many rows. Note that if you do not have enough items to fill this - many rows some rows will be of zero width. -*/ - -void QmlGraphicsGrid::doPositioning() -{ - int c=_columns,r=_rows;//Actual number of rows/columns - int numVisible = items()->size() + newItems()->size(); - if (_columns==-1 && _rows==-1){ - c = 4; - r = (numVisible+3)/4; - }else if (_rows==-1){ - r = (numVisible+(_columns-1))/_columns; - }else if (_columns==-1){ - c = (numVisible+(_rows-1))/_rows; - } - - QList maxColWidth; - QList maxRowHeight; - int childIndex =0; - QList children = childItems(); - for (int i=0; i(children.at(childIndex++)); - if (!child || child->opacity() == 0.0) - continue; - if (child->width() > maxColWidth[j]) - maxColWidth[j] = child->width(); - if (child->height() > maxRowHeight[i]) - maxRowHeight[i] = child->height(); - } - } - - int xoffset=0; - int yoffset=0; - int curRow =0; - int curCol =0; - foreach(QmlGraphicsItem* item, *leavingItems()){ - if (remove()){ - QList > changes; - applyRemove(changes, item); - } - } - foreach(QGraphicsItem* schild, children){ - QmlGraphicsItem *child = qobject_cast(schild); - if (!child || child->opacity() == 0.0) - continue; - bool needMove = (child->x()!=xoffset)||(child->y()!=yoffset); - QList > changes; - changes << qMakePair(QString(QLatin1String("x")),QVariant(xoffset)); - changes << qMakePair(QString(QLatin1String("y")),QVariant(yoffset)); - if (newItems()->contains(child) && add()) { - applyAdd(changes,child); - } else if (needMove) { - if (move()){ - applyMove(changes,child); - }else{ - setMovingItem(child); - child->setPos(QPointF(xoffset, yoffset)); - setMovingItem(0); - } - } - xoffset+=maxColWidth[curCol]+spacing(); - curCol++; - curCol%=c; - if (!curCol){ - yoffset+=maxRowHeight[curRow]+spacing(); - xoffset=0; - curRow++; - if (curRow>=r) - break; - } - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpositioners.h b/src/declarative/fx/qfxpositioners.h deleted file mode 100644 index 29c121c..0000000 --- a/src/declarative/fx/qfxpositioners.h +++ /dev/null @@ -1,167 +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 QFXLAYOUTS_H -#define QFXLAYOUTS_H - -#include -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlGraphicsBasePositionerPrivate; - -class Q_DECLARATIVE_EXPORT QmlGraphicsBasePositioner : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) - Q_PROPERTY(QmlTransition *move READ move WRITE setMove) - Q_PROPERTY(QmlTransition *add READ add WRITE setAdd) - Q_PROPERTY(QmlTransition *remove READ remove WRITE setRemove) -public: - enum AutoUpdateType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 }; - QmlGraphicsBasePositioner(AutoUpdateType, QmlGraphicsItem *parent); - - int spacing() const; - void setSpacing(int); - - QmlTransition *move() const; - void setMove(QmlTransition *); - - QmlTransition *add() const; - void setAdd(QmlTransition *); - - QmlTransition *remove() const; - void setRemove(QmlTransition *); - -protected: - virtual void componentComplete(); - virtual QVariant itemChange(GraphicsItemChange, const QVariant &); - virtual bool event(QEvent *); - QSet* newItems(); - QSet* leavingItems(); - QSet* items(); - void applyAdd(const QList >& changes, QmlGraphicsItem* target); - void applyMove(const QList >& changes, QmlGraphicsItem* target); - void applyRemove(const QList >& changes, QmlGraphicsItem* target); - void finishApplyTransitions(); - -Q_SIGNALS: - void layoutItemChanged(); - void spacingChanged(); - -protected Q_SLOTS: - virtual void doPositioning()=0; - -private Q_SLOTS: - void prePositioning(); - -protected: - QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, AutoUpdateType at, QmlGraphicsItem *parent); - void setMovingItem(QmlGraphicsItem *); - -private: - void applyTransition(const QList >& changes, QmlGraphicsItem* target, - QmlStateOperation::ActionList &actions); - Q_DISABLE_COPY(QmlGraphicsBasePositioner) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsBasePositioner) -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsColumn : public QmlGraphicsBasePositioner -{ - Q_OBJECT -public: - QmlGraphicsColumn(QmlGraphicsItem *parent=0); -protected Q_SLOTS: - virtual void doPositioning(); -private: - Q_DISABLE_COPY(QmlGraphicsColumn) -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsRow: public QmlGraphicsBasePositioner -{ - Q_OBJECT -public: - QmlGraphicsRow(QmlGraphicsItem *parent=0); -protected Q_SLOTS: - virtual void doPositioning(); -private: - Q_DISABLE_COPY(QmlGraphicsRow) -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGrid : public QmlGraphicsBasePositioner -{ - Q_OBJECT - Q_PROPERTY(int rows READ rows WRITE setRows) - Q_PROPERTY(int columns READ columns WRITE setcolumns) -public: - QmlGraphicsGrid(QmlGraphicsItem *parent=0); - - int rows() const {return _rows;} - void setRows(const int rows){_rows = rows;} - - int columns() const {return _columns;} - void setcolumns(const int columns){_columns = columns;} -protected Q_SLOTS: - virtual void doPositioning(); - -private: - int _rows; - int _columns; - Q_DISABLE_COPY(QmlGraphicsGrid) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsColumn) -QML_DECLARE_TYPE(QmlGraphicsRow) -QML_DECLARE_TYPE(QmlGraphicsGrid) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qfxpositioners_p.h b/src/declarative/fx/qfxpositioners_p.h deleted file mode 100644 index fdc11bb..0000000 --- a/src/declarative/fx/qfxpositioners_p.h +++ /dev/null @@ -1,105 +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 QFXLAYOUTS_P_H -#define QFXLAYOUTS_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 -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QmlGraphicsBasePositionerPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsBasePositioner) - -public: - QmlGraphicsBasePositionerPrivate() - : _ep(false), _componentComplete(false), _spacing(0), - aut(QmlGraphicsBasePositioner::None), moveTransition(0), addTransition(0), - removeTransition(0), _movingItem(0) - { - } - - void init(QmlGraphicsBasePositioner::AutoUpdateType at) - { - aut = at; - } - - bool _ep; - bool _componentComplete; - int _spacing; - QmlGraphicsBasePositioner::AutoUpdateType aut; - QmlTransition *moveTransition; - QmlTransition *addTransition; - QmlTransition *removeTransition; - QSet _items; - QSet _leavingItems; - QSet _stableItems; - QSet _newItems; - QSet _animated; - QmlStateOperation::ActionList addActions; - QmlStateOperation::ActionList moveActions; - QmlStateOperation::ActionList removeActions; - QmlTransitionManager addTransitionManager; - QmlTransitionManager moveTransitionManager; - QmlTransitionManager removeTransitionManager; -// QmlStateGroup *stateGroup; - QmlGraphicsItem *_movingItem; -}; - -QT_END_NAMESPACE -#endif diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp deleted file mode 100644 index 7ebacf0..0000000 --- a/src/declarative/fx/qfxrect.cpp +++ /dev/null @@ -1,475 +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 "qfxrect.h" -#include "qfxrect_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pen,QmlGraphicsPen) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GradientStop,QmlGraphicsGradientStop) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Gradient,QmlGraphicsGradient) - -/*! - \internal - \class QmlGraphicsPen - \brief The QmlGraphicsPen class provides a pen used for drawing rectangle borders on a QmlView. - - By default, the pen is invalid and nothing is drawn. You must either set a color (then the default - width is 1) or a width (then the default color is black). - - A width of 1 indicates is a single-pixel line on the border of the item being painted. - - Example: - \qml - Rectangle { border.width: 2; border.color: "red" ... } - \endqml -*/ - -void QmlGraphicsPen::setColor(const QColor &c) -{ - _color = c; - _valid = _color.alpha() ? true : false; - emit penChanged(); -} - -void QmlGraphicsPen::setWidth(int w) -{ - if (_width == w && _valid) - return; - - _width = w; - _valid = (_width < 1) ? false : true; - emit penChanged(); -} - - -/*! - \qmlclass GradientStop QmlGraphicsGradientStop - \brief The GradientStop item defines the color at a position in a Gradient - - \sa Gradient -*/ - -/*! - \qmlproperty real GradientStop::position - \qmlproperty color GradientStop::color - - Sets a \e color at a \e position in a gradient. -*/ - -void QmlGraphicsGradientStop::updateGradient() -{ - if (QmlGraphicsGradient *grad = qobject_cast(parent())) - grad->doUpdate(); -} - -/*! - \qmlclass Gradient QmlGraphicsGradient - \brief The Gradient item defines a gradient fill. - - A gradient is defined by two or more colors, which will be blended seemlessly. The - colors are specified at their position in the range 0.0 - 1.0 via - the GradientStop item. For example, the following code paints a - rectangle with a gradient starting with red, blending to yellow at 1/3 of the - size of the rectangle, and ending with Green: - - \table - \row - \o \image gradient.png - \o \quotefile doc/src/snippets/declarative/gradient.qml - \endtable - - \sa GradientStop -*/ - -/*! - \qmlproperty list Gradient::stops - This property holds the gradient stops describing the gradient. -*/ - -const QGradient *QmlGraphicsGradient::gradient() const -{ - if (!m_gradient && !m_stops.isEmpty()) { - m_gradient = new QLinearGradient(0,0,0,1.0); - for (int i = 0; i < m_stops.count(); ++i) { - const QmlGraphicsGradientStop *stop = m_stops.at(i); - m_gradient->setCoordinateMode(QGradient::ObjectBoundingMode); - m_gradient->setColorAt(stop->position(), stop->color()); - } - } - - return m_gradient; -} - -void QmlGraphicsGradient::doUpdate() -{ - delete m_gradient; - m_gradient = 0; - emit updated(); -} - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rectangle,QmlGraphicsRect) - -/*! - \qmlclass Rectangle QmlGraphicsRect - \brief The Rectangle item allows you to add rectangles to a scene. - \inherits Item - - A Rectangle is painted having a solid fill (color) and an optional border. - You can also create rounded rectangles using the radius property. - - \qml - Rectangle { - width: 100 - height: 100 - color: "red" - border.color: "black" - border.width: 5 - radius: 10 - } - \endqml - - \image declarative-rect.png -*/ - -/*! - \internal - \class QmlGraphicsRect - \brief The QmlGraphicsRect class provides a rectangle item that you can add to a QmlView. -*/ -QmlGraphicsRect::QmlGraphicsRect(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsRectPrivate), parent) -{ - Q_D(QmlGraphicsRect); - d->init(); - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -QmlGraphicsRect::QmlGraphicsRect(QmlGraphicsRectPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ - Q_D(QmlGraphicsRect); - d->init(); - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -void QmlGraphicsRect::doUpdate() -{ - Q_D(QmlGraphicsRect); - d->rectImage = QPixmap(); - const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - d->setPaintMargin((pw+1)/2); - update(); -} - -/*! - \qmlproperty int Rectangle::border.width - \qmlproperty color Rectangle::border.color - - The width and color used to draw the border of the rectangle. - - A width of 1 creates a thin line. For no line, use a width of 0 or a transparent color. - - To keep the border smooth (rather than blurry), odd widths cause the rectangle to be painted at - a half-pixel offset; -*/ -QmlGraphicsPen *QmlGraphicsRect::border() -{ - Q_D(QmlGraphicsRect); - return d->getPen(); -} - -/*! - \qmlproperty Gradient Rectangle::gradient - - The gradient to use to fill the rectangle. - - This property allows for the construction of simple vertical gradients. - Other gradients may by formed by adding rotation to the rectangle. - - \table - \row - \o \image declarative-rect_gradient.png - \o - \qml - Rectangle { y: 0; width: 80; height: 80; color: "lightsteelblue" } - Rectangle { y: 100; width: 80; height: 80 - gradient: Gradient { - GradientStop { position: 0.0; color: "lightsteelblue" } - GradientStop { position: 1.0; color: "blue" } - } - } - Rectangle { rotation: 90; x: 80; y: 200; width: 80; height: 80 - gradient: Gradient { - GradientStop { position: 0.0; color: "lightsteelblue" } - GradientStop { position: 1.0; color: "blue" } - } - } - // The x offset is needed because the rotation is from the top left corner - \endqml - \endtable - - If both a gradient and a color are specified, the gradient will be used. - - \sa Gradient, color -*/ -QmlGraphicsGradient *QmlGraphicsRect::gradient() const -{ - Q_D(const QmlGraphicsRect); - return d->gradient; -} - -void QmlGraphicsRect::setGradient(QmlGraphicsGradient *gradient) -{ - Q_D(QmlGraphicsRect); - if (d->gradient == gradient) - return; - if (d->gradient) - disconnect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); - d->gradient = gradient; - if (d->gradient) - connect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); - update(); -} - - -/*! - \qmlproperty real Rectangle::radius - This property holds the corner radius used to draw a rounded rectangle. - - If radius is non-zero, the rectangle will be painted as a rounded rectangle, otherwise it will be - painted as a normal rectangle. The same radius is used by all 4 corners; there is currently - no way to specify different radii for different corners. -*/ -qreal QmlGraphicsRect::radius() const -{ - Q_D(const QmlGraphicsRect); - return d->radius; -} - -void QmlGraphicsRect::setRadius(qreal radius) -{ - Q_D(QmlGraphicsRect); - if (d->radius == radius) - return; - - d->radius = radius; - d->rectImage = QPixmap(); - update(); - emit radiusChanged(); -} - -/*! - \qmlproperty color Rectangle::color - This property holds the color used to fill the rectangle. - - \qml - // green rectangle using hexidecimal notation - Rectangle { color: "#00FF00" } - - // steelblue rectangle using SVG color name - Rectangle { color: "steelblue" } - \endqml - - The default color is white. - - If both a gradient and a color are specified, the gradient will be used. -*/ -QColor QmlGraphicsRect::color() const -{ - Q_D(const QmlGraphicsRect); - return d->color; -} - -void QmlGraphicsRect::setColor(const QColor &c) -{ - Q_D(QmlGraphicsRect); - if (d->color == c) - return; - - d->color = c; - d->rectImage = QPixmap(); - update(); - emit colorChanged(); -} - -void QmlGraphicsRect::generateRoundedRect() -{ - Q_D(QmlGraphicsRect); - if (d->rectImage.isNull()) { - const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - const int radius = qCeil(d->radius); //ensure odd numbered width/height so we get 1-pixel center - d->rectImage = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2); - d->rectImage.fill(Qt::transparent); - QPainter p(&(d->rectImage)); - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(d->pen->color()), d->pen->width()); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); - } - p.setBrush(d->color); - if (pw%2) - p.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1)), d->radius, d->radius); - else - p.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw), d->radius, d->radius); - } -} - -void QmlGraphicsRect::generateBorderedRect() -{ - Q_D(QmlGraphicsRect); - if (d->rectImage.isNull()) { - const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - d->rectImage = QPixmap(pw*2 + 3, pw*2 + 3); - d->rectImage.fill(Qt::transparent); - QPainter p(&(d->rectImage)); - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(d->pen->color()), d->pen->width()); - pn.setJoinStyle(Qt::MiterJoin); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); - } - p.setBrush(d->color); - if (pw%2) - p.drawRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1))); - else - p.drawRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw)); - } -} - -void QmlGraphicsRect::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - Q_D(QmlGraphicsRect); - if (d->radius > 0 || (d->pen && d->pen->isValid()) - || (d->gradient && d->gradient->gradient()) ) { - drawRect(*p); - } - else { - bool oldAA = p->testRenderHint(QPainter::Antialiasing); - if (d->smooth) - p->setRenderHints(QPainter::Antialiasing, true); - p->fillRect(QRectF(0, 0, width(), height()), d->color); - if (d->smooth) - p->setRenderHint(QPainter::Antialiasing, oldAA); - } -} - -void QmlGraphicsRect::drawRect(QPainter &p) -{ - Q_D(QmlGraphicsRect); - if (d->gradient && d->gradient->gradient()) { - // XXX This path is still slower than the image path - // Image path won't work for gradients though - bool oldAA = p.testRenderHint(QPainter::Antialiasing); - if (d->smooth) - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(d->pen->color()), d->pen->width()); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); - } - p.setBrush(*d->gradient->gradient()); - if (d->radius > 0.) - p.drawRoundedRect(0, 0, width(), height(), d->radius, d->radius); - else - p.drawRect(0, 0, width(), height()); - if (d->smooth) - p.setRenderHint(QPainter::Antialiasing, oldAA); - } else { - bool oldAA = p.testRenderHint(QPainter::Antialiasing); - bool oldSmooth = p.testRenderHint(QPainter::SmoothPixmapTransform); - if (d->smooth) - p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); - - const int pw = d->pen && d->pen->isValid() ? (d->pen->width()+1)/2*2 : 0; - - if (d->radius > 0) - generateRoundedRect(); - else - generateBorderedRect(); - - int xOffset = (d->rectImage.width()-1)/2; - int yOffset = (d->rectImage.height()-1)/2; - Q_ASSERT(d->rectImage.width() == 2*xOffset + 1); - Q_ASSERT(d->rectImage.height() == 2*yOffset + 1); - - QMargins margins(xOffset, yOffset, xOffset, yOffset); - QTileRules rules(Qt::StretchTile, Qt::StretchTile); - //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects - qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width()+pw, height()+pw), margins, d->rectImage, d->rectImage.rect(), margins, rules); - - if (d->smooth) { - p.setRenderHint(QPainter::Antialiasing, oldAA); - p.setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); - } - } -} - -/*! - \qmlproperty bool Rectangle::smooth - - Set this property if you want the item to be smoothly scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If - the item is displayed at its natural size, this property has no visual or - performance effect. - - \note Generally scaling artifacts are only visible if the item is stationary on - the screen. A common pattern when animating an item is to disable smooth - filtering at the beginning of the animation and reenable it at the conclusion. - - \image rect-smooth.png -*/ - -QRectF QmlGraphicsRect::boundingRect() const -{ - Q_D(const QmlGraphicsRect); - return QRectF(-d->paintmargin, -d->paintmargin, d->width+d->paintmargin*2, d->height+d->paintmargin*2); -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxrect.h b/src/declarative/fx/qfxrect.h deleted file mode 100644 index 5154a8a..0000000 --- a/src/declarative/fx/qfxrect.h +++ /dev/null @@ -1,189 +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 QFXRECT_H -#define QFXRECT_H - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class Q_DECLARATIVE_EXPORT QmlGraphicsPen : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged) - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged) -public: - QmlGraphicsPen(QObject *parent=0) - : QObject(parent), _width(1), _color("#000000"), _valid(false) - {} - - int width() const { return _width; } - void setWidth(int w); - - QColor color() const { return _color; } - void setColor(const QColor &c); - - bool isValid() { return _valid; }; - -Q_SIGNALS: - void penChanged(); - -private: - int _width; - QColor _color; - bool _valid; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGradientStop : public QObject -{ - Q_OBJECT - - Q_PROPERTY(qreal position READ position WRITE setPosition) - Q_PROPERTY(QColor color READ color WRITE setColor) - -public: - QmlGraphicsGradientStop(QObject *parent=0) : QObject(parent) {} - - qreal position() const { return m_position; } - void setPosition(qreal position) { m_position = position; updateGradient(); } - - QColor color() const { return m_color; } - void setColor(const QColor &color) { m_color = color; updateGradient(); } - -private: - void updateGradient(); - -private: - qreal m_position; - QColor m_color; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGradient : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QList *stops READ stops) - Q_CLASSINFO("DefaultProperty", "stops") - -public: - QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} - ~QmlGraphicsGradient() { delete m_gradient; } - - QList *stops() { return &m_stops; } - - const QGradient *gradient() const; - -Q_SIGNALS: - void updated(); - -private: - void doUpdate(); - -private: - QList m_stops; - mutable QGradient *m_gradient; - friend class QmlGraphicsGradientStop; -}; - -class QmlGraphicsRectPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsRect : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) - Q_PROPERTY(QmlGraphicsGradient *gradient READ gradient WRITE setGradient) - Q_PROPERTY(QmlGraphicsPen * border READ border CONSTANT) - Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) -public: - QmlGraphicsRect(QmlGraphicsItem *parent=0); - - QColor color() const; - void setColor(const QColor &); - - QmlGraphicsPen *border(); - - QmlGraphicsGradient *gradient() const; - void setGradient(QmlGraphicsGradient *gradient); - - qreal radius() const; - void setRadius(qreal radius); - - QRectF boundingRect() const; - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -Q_SIGNALS: - void colorChanged(); - void radiusChanged(); - -private Q_SLOTS: - void doUpdate(); - -private: - void generateRoundedRect(); - void generateBorderedRect(); - void drawRect(QPainter &painter); - -protected: - QmlGraphicsRect(QmlGraphicsRectPrivate &dd, QmlGraphicsItem *parent); - -private: - Q_DISABLE_COPY(QmlGraphicsRect) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRect) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsPen) -QML_DECLARE_TYPE(QmlGraphicsGradientStop) -QML_DECLARE_TYPE(QmlGraphicsGradient) -QML_DECLARE_TYPE(QmlGraphicsRect) - -QT_END_HEADER - -#endif // QFXRECT_H diff --git a/src/declarative/fx/qfxrect_p.h b/src/declarative/fx/qfxrect_p.h deleted file mode 100644 index d67209e..0000000 --- a/src/declarative/fx/qfxrect_p.h +++ /dev/null @@ -1,109 +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 QFXRECT_P_H -#define QFXRECT_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 "qfxitem_p.h" - -QT_BEGIN_NAMESPACE - -class QmlGraphicsGradient; -class QmlGraphicsRect; -class QmlGraphicsRectPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsRect) - -public: - QmlGraphicsRectPrivate() : - color(Qt::white), gradient(0), pen(0), radius(0), paintmargin(0) - { - } - - ~QmlGraphicsRectPrivate() - { - delete pen; - } - - void init() - { - } - - QColor getColor(); - QColor color; - QmlGraphicsGradient *gradient; - QmlGraphicsPen *getPen() { - if (!pen) { - Q_Q(QmlGraphicsRect); - pen = new QmlGraphicsPen; - QObject::connect(pen, SIGNAL(penChanged()), q, SLOT(doUpdate())); - } - return pen; - } - QmlGraphicsPen *pen; - qreal radius; - qreal paintmargin; - QPixmap rectImage; - - void setPaintMargin(qreal margin) - { - Q_Q(QmlGraphicsRect); - if (margin == paintmargin) - return; - q->prepareGeometryChange(); - paintmargin = margin; - } -}; - -QT_END_NAMESPACE - -#endif // QFXRECT_P_H diff --git a/src/declarative/fx/qfxrepeater.cpp b/src/declarative/fx/qfxrepeater.cpp deleted file mode 100644 index e8e44cc..0000000 --- a/src/declarative/fx/qfxrepeater.cpp +++ /dev/null @@ -1,320 +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 "qfxrepeater.h" -#include "qfxrepeater_p.h" -#include "qmllistaccessor.h" -#include "qfxvisualitemmodel.h" -#include - - -QT_BEGIN_NAMESPACE -QmlGraphicsRepeaterPrivate::QmlGraphicsRepeaterPrivate() -: model(0), ownModel(false) -{ -} - -QmlGraphicsRepeaterPrivate::~QmlGraphicsRepeaterPrivate() -{ -} - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Repeater,QmlGraphicsRepeater) - -/*! - \qmlclass Repeater - \inherits Item - - \brief The Repeater item allows you to repeat a component based on a model. - - The Repeater item is used when you want to create a large number of - similar items. For each entry in the model, an item is instantiated - in a context seeded with data from the model. If the repeater will - be instantiating a large number of instances, it may be more efficient to - use one of Qt Declarative's \l {xmlViews}{view items}. - - The model may be either an object list, a string list, a number or a Qt model. - In each case, the data element and the index is exposed to each instantiated - component. - - The index is always exposed as an accessible \c index property. - In the case of an object or string list, the data element (of type string - or object) is available as the \c modelData property. In the case of a Qt model, - all roles are available as named properties just like in the view classes. The - following example shows how to use the index property inside the instantiated - items. - - \snippet doc/src/snippets/declarative/repeater-index.qml 0 - - \image repeater-index.png - - Items instantiated by the Repeater are inserted, in order, as - children of the Repeater's parent. The insertion starts immediately after - the repeater's position in its parent stacking list. This is to allow - you to use a Repeater inside a layout. The following QML example shows how - the instantiated items would visually appear stacked between the red and - blue rectangles. - - \snippet doc/src/snippets/declarative/repeater.qml 0 - - \image repeater.png - - The repeater instance continues to own all items it instantiates, even - if they are otherwise manipulated. It is illegal to manually remove an item - created by the Repeater. - */ - -/*! - \internal - \class QmlGraphicsRepeater - \qmlclass Repeater - - XXX Repeater is very conservative in how it instatiates/deletes items. Also - new model entries will not be created and old ones will not be removed. - */ - -/*! - Create a new QmlGraphicsRepeater instance. - */ -QmlGraphicsRepeater::QmlGraphicsRepeater(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsRepeaterPrivate), parent) -{ -} - -/*! - \internal - */ -QmlGraphicsRepeater::QmlGraphicsRepeater(QmlGraphicsRepeaterPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ -} - -/*! - Destroy the repeater instance. All items it instantiated are also - destroyed. - */ -QmlGraphicsRepeater::~QmlGraphicsRepeater() -{ -} - -/*! - \qmlproperty any Repeater::model - - The model providing data for the repeater. - - The model may be either an object list, a string list, a number or a Qt model. - In each case, the data element and the index is exposed to each instantiated - component. The index is always exposed as an accessible \c index property. - In the case of an object or string list, the data element (of type string - or object) is available as the \c modelData property. In the case of a Qt model, - all roles are available as named properties just like in the view classes. - - As a special case the model can also be merely a number. In this case it will - create that many instances of the component. They will also be assigned an index - based on the order they are created. - - Models can also be created directly in QML, using a \l{ListModel} or \l{XmlListModel}. - - \sa {qmlmodels}{Data Models} -*/ -QVariant QmlGraphicsRepeater::model() const -{ - Q_D(const QmlGraphicsRepeater); - return d->dataSource; -} - -void QmlGraphicsRepeater::setModel(const QVariant &model) -{ - Q_D(QmlGraphicsRepeater); - clear(); - if (d->model) { - disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); - disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); - disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); - /* - disconnect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); - disconnect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); - */ - } - d->dataSource = model; - QObject *object = qvariant_cast(model); - QmlGraphicsVisualModel *vim = 0; - if (object && (vim = qobject_cast(object))) { - if (d->ownModel) { - delete d->model; - d->ownModel = false; - } - d->model = vim; - } else { - if (!d->ownModel) { - d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); - d->ownModel = true; - } - if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) - dataModel->setModel(model); - } - if (d->model) { - connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); - connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); - connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); - /* - connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); - connect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); - */ - regenerate(); - emit countChanged(); - } -} - -/*! - \qmlproperty Component Repeater::delegate - \default - - The delegate provides a template describing what each item instantiated by the repeater should look and act like. - */ -QmlComponent *QmlGraphicsRepeater::delegate() const -{ - Q_D(const QmlGraphicsRepeater); - if (d->model) { - if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) - return dataModel->delegate(); - } - - return 0; -} - -void QmlGraphicsRepeater::setDelegate(QmlComponent *delegate) -{ - Q_D(QmlGraphicsRepeater); - if (!d->ownModel) { - d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); - d->ownModel = true; - } - if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) { - dataModel->setDelegate(delegate); - regenerate(); - } -} - -/*! - \qmlproperty int Repeater::count - - This property holds the number of items in the repeater. -*/ -int QmlGraphicsRepeater::count() const -{ - Q_D(const QmlGraphicsRepeater); - if (d->model) - return d->model->count(); - return 0; -} - - -/*! - \internal - */ -void QmlGraphicsRepeater::componentComplete() -{ - QmlGraphicsItem::componentComplete(); - regenerate(); -} - -/*! - \internal - */ -QVariant QmlGraphicsRepeater::itemChange(GraphicsItemChange change, - const QVariant &value) -{ - QVariant rv = QmlGraphicsItem::itemChange(change, value); - if (change == ItemParentHasChanged) { - regenerate(); - } - - return rv; -} - -void QmlGraphicsRepeater::clear() -{ - Q_D(QmlGraphicsRepeater); - if (d->model) { - foreach (QmlGraphicsItem *item, d->deletables) - d->model->release(item); - } - d->deletables.clear(); -} - -/*! - \internal - */ -void QmlGraphicsRepeater::regenerate() -{ - Q_D(QmlGraphicsRepeater); - - clear(); - - if (!d->model || !d->model->count() || !d->model->isValid() || !parentItem() || !isComponentComplete()) - return; - - for (int ii = 0; ii < count(); ++ii) { - QmlGraphicsItem *item = d->model->item(ii); - if (item) { - item->setParent(parentItem()); - item->stackBefore(this); - d->deletables << item; - } - } -} - -void QmlGraphicsRepeater::itemsInserted(int, int) -{ - regenerate(); -} - -void QmlGraphicsRepeater::itemsRemoved(int, int) -{ - regenerate(); -} - -void QmlGraphicsRepeater::itemsMoved(int,int,int) -{ - regenerate(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxrepeater.h b/src/declarative/fx/qfxrepeater.h deleted file mode 100644 index f8a03cc..0000000 --- a/src/declarative/fx/qfxrepeater.h +++ /dev/null @@ -1,103 +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 QFXREPEATER_H -#define QFXREPEATER_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsRepeaterPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsRepeater : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_CLASSINFO("DefaultProperty", "delegate") - -public: - QmlGraphicsRepeater(QmlGraphicsItem *parent=0); - virtual ~QmlGraphicsRepeater(); - - QVariant model() const; - void setModel(const QVariant &); - - QmlComponent *delegate() const; - void setDelegate(QmlComponent *); - - int count() const; - -Q_SIGNALS: - void countChanged(); - -private: - void clear(); - void regenerate(); - -protected: - virtual void componentComplete(); - QVariant itemChange(GraphicsItemChange change, const QVariant &value); - QmlGraphicsRepeater(QmlGraphicsRepeaterPrivate &dd, QmlGraphicsItem *parent); - -private Q_SLOTS: - void itemsInserted(int,int); - void itemsRemoved(int,int); - void itemsMoved(int,int,int); - -private: - Q_DISABLE_COPY(QmlGraphicsRepeater) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRepeater) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsRepeater) - -QT_END_HEADER - -#endif // QFXREPEATER_H diff --git a/src/declarative/fx/qfxrepeater_p.h b/src/declarative/fx/qfxrepeater_p.h deleted file mode 100644 index eb35352..0000000 --- a/src/declarative/fx/qfxrepeater_p.h +++ /dev/null @@ -1,81 +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 QFXREPEATER_P_H -#define QFXREPEATER_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 "qfxitem_p.h" -#include "qfxrepeater.h" -#include - - -QT_BEGIN_NAMESPACE - -class QmlContext; -class QmlGraphicsVisualModel; -class QmlGraphicsRepeaterPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsRepeater) - -public: - QmlGraphicsRepeaterPrivate(); - ~QmlGraphicsRepeaterPrivate(); - - QmlGraphicsVisualModel *model; - QVariant dataSource; - bool ownModel; - - QList > deletables; -}; - -QT_END_NAMESPACE -#endif // QFXREPEATER_P_H diff --git a/src/declarative/fx/qfxscalegrid.cpp b/src/declarative/fx/qfxscalegrid.cpp deleted file mode 100644 index 2012616..0000000 --- a/src/declarative/fx/qfxscalegrid.cpp +++ /dev/null @@ -1,212 +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 -#include -#include -#include "qfxscalegrid_p.h" - - -QT_BEGIN_NAMESPACE -/*! - \internal - \class QmlGraphicsScaleGrid - \brief The QmlGraphicsScaleGrid class allows you to specify a 3x3 grid to use in scaling an image. -*/ -QML_DEFINE_NOCREATE_TYPE(QmlGraphicsScaleGrid) - -QmlGraphicsScaleGrid::QmlGraphicsScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0) -{ -} - -QmlGraphicsScaleGrid::~QmlGraphicsScaleGrid() -{ -} - -bool QmlGraphicsScaleGrid::isNull() const -{ - return !_left && !_top && !_right && !_bottom; -} - -void QmlGraphicsScaleGrid::setLeft(int pos) -{ - if (_left != pos) { - _left = pos; - emit borderChanged(); - } -} - -void QmlGraphicsScaleGrid::setTop(int pos) -{ - if (_top != pos) { - _top = pos; - emit borderChanged(); - } -} - -void QmlGraphicsScaleGrid::setRight(int pos) -{ - if (_right != pos) { - _right = pos; - emit borderChanged(); - } -} - -void QmlGraphicsScaleGrid::setBottom(int pos) -{ - if (_bottom != pos) { - _bottom = pos; - emit borderChanged(); - } -} - -QmlGraphicsGridScaledImage::QmlGraphicsGridScaledImage() -: _l(-1), _r(-1), _t(-1), _b(-1), - _h(QmlGraphicsBorderImage::Stretch), _v(QmlGraphicsBorderImage::Stretch) -{ -} - -QmlGraphicsGridScaledImage::QmlGraphicsGridScaledImage(const QmlGraphicsGridScaledImage &o) -: _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix) -{ -} - -QmlGraphicsGridScaledImage &QmlGraphicsGridScaledImage::operator=(const QmlGraphicsGridScaledImage &o) -{ - _l = o._l; - _r = o._r; - _t = o._t; - _b = o._b; - _h = o._h; - _v = o._v; - _pix = o._pix; - return *this; -} - -QmlGraphicsGridScaledImage::QmlGraphicsGridScaledImage(QIODevice *data) -: _l(-1), _r(-1), _t(-1), _b(-1), _h(QmlGraphicsBorderImage::Stretch), _v(QmlGraphicsBorderImage::Stretch) -{ - int l = -1; - int r = -1; - int t = -1; - int b = -1; - QString imgFile; - - while(!data->atEnd()) { - QString line = QString::fromUtf8(data->readLine().trimmed()); - if (line.isEmpty() || line.startsWith(QLatin1String("#"))) - continue; - - QStringList list = line.split(QLatin1Char(':')); - if (list.count() != 2) - return; - - list[0] = list[0].trimmed(); - list[1] = list[1].trimmed(); - - if (list[0] == QLatin1String("border.left")) - l = list[1].toInt(); - else if (list[0] == QLatin1String("border.right")) - r = list[1].toInt(); - else if (list[0] == QLatin1String("border.top")) - t = list[1].toInt(); - else if (list[0] == QLatin1String("border.bottom")) - b = list[1].toInt(); - else if (list[0] == QLatin1String("source")) - imgFile = list[1]; - else if (list[0] == QLatin1String("horizontalTileRule")) - _h = stringToRule(list[1]); - else if (list[0] == QLatin1String("verticalTileRule")) - _v = stringToRule(list[1]); - } - - if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty()) - return; - - _l = l; _r = r; _t = t; _b = b; - - _pix = imgFile; -} - -QmlGraphicsBorderImage::TileMode QmlGraphicsGridScaledImage::stringToRule(const QString &s) -{ - if (s == QLatin1String("Stretch")) - return QmlGraphicsBorderImage::Stretch; - if (s == QLatin1String("Repeat")) - return QmlGraphicsBorderImage::Repeat; - if (s == QLatin1String("Round")) - return QmlGraphicsBorderImage::Round; - - qWarning() << "Unknown tile rule specified. Using Stretch"; - return QmlGraphicsBorderImage::Stretch; -} - -bool QmlGraphicsGridScaledImage::isValid() const -{ - return _l >= 0; -} - -int QmlGraphicsGridScaledImage::gridLeft() const -{ - return _l; -} - -int QmlGraphicsGridScaledImage::gridRight() const -{ - return _r; -} - -int QmlGraphicsGridScaledImage::gridTop() const -{ - return _t; -} - -int QmlGraphicsGridScaledImage::gridBottom() const -{ - return _b; -} - -QString QmlGraphicsGridScaledImage::pixmapUrl() const -{ - return _pix; -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxscalegrid_p.h b/src/declarative/fx/qfxscalegrid_p.h deleted file mode 100644 index f065f9d..0000000 --- a/src/declarative/fx/qfxscalegrid_p.h +++ /dev/null @@ -1,133 +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 QFXSCALEGRID_H -#define QFXSCALEGRID_H - -#include -#include -#include -#include -#include -#include "qfxborderimage.h" - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QmlGraphicsScaleGrid : public QObject -{ - Q_OBJECT - Q_ENUMS(TileRule) - - Q_PROPERTY(int left READ left WRITE setLeft NOTIFY borderChanged) - Q_PROPERTY(int top READ top WRITE setTop NOTIFY borderChanged) - Q_PROPERTY(int right READ right WRITE setRight NOTIFY borderChanged) - Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY borderChanged) - -public: - QmlGraphicsScaleGrid(QObject *parent=0); - ~QmlGraphicsScaleGrid(); - - bool isNull() const; - - int left() const { return _left; } - void setLeft(int); - - int top() const { return _top; } - void setTop(int); - - int right() const { return _right; } - void setRight(int); - - int bottom() const { return _bottom; } - void setBottom(int); - -Q_SIGNALS: - void borderChanged(); - -private: - int _left; - int _top; - int _right; - int _bottom; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGridScaledImage -{ -public: - QmlGraphicsGridScaledImage(); - QmlGraphicsGridScaledImage(const QmlGraphicsGridScaledImage &); - QmlGraphicsGridScaledImage(QIODevice*); - QmlGraphicsGridScaledImage &operator=(const QmlGraphicsGridScaledImage &); - bool isValid() const; - int gridLeft() const; - int gridRight() const; - int gridTop() const; - int gridBottom() const; - QmlGraphicsBorderImage::TileMode horizontalTileRule() const { return _h; } - QmlGraphicsBorderImage::TileMode verticalTileRule() const { return _v; } - - QString pixmapUrl() const; - -private: - static QmlGraphicsBorderImage::TileMode stringToRule(const QString &); - -private: - int _l; - int _r; - int _t; - int _b; - QmlGraphicsBorderImage::TileMode _h; - QmlGraphicsBorderImage::TileMode _v; - QString _pix; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsScaleGrid) - -QT_END_HEADER - -#endif // QFXSCALEGRID_H diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp deleted file mode 100644 index 77b3ab4..0000000 --- a/src/declarative/fx/qfxtext.cpp +++ /dev/null @@ -1,840 +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 "qfxtext.h" -#include "qfxtext_p.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Text,QmlGraphicsText) - -/*! - \qmlclass Text QmlGraphicsText - \brief The Text item allows you to add formatted text to a scene. - \inherits Item - - It can display both plain and rich text. For example: - - \qml - Text { text: "Hello World!"; font.family: "Helvetica"; font.pointSize: 24; color: "red" } - Text { text: "Hello World!" } - \endqml - - \image declarative-text.png - - If height and width are not explicitly set, Text will attempt to determine how - much room is needed and set it accordingly. Unless \c wrap is set, it will always - prefer width to height (all text will be placed on a single line). - - The \c elide property can alternatively be used to fit a single line of - plain text to a set width. - - Text provides read-only text. For editable text, see \l TextEdit. -*/ - -/*! - \internal - \class QmlGraphicsText - \qmlclass Text - \ingroup group_coreitems - - \brief The QmlGraphicsText class provides a formatted text item that you can add to a QmlView. - - Text was designed for read-only text; it does not allow for any text editing. - It can display both plain and rich text. For example: - - \qml - Text { text: "Hello World!"; font.family: "Helvetica"; font.pointSize: 24; color: "red" } - Text { text: "Hello World!" } - \endqml - - \image text.png - - If height and width are not explicitly set, Text will attempt to determine how - much room is needed and set it accordingly. Unless \c wrap is set, it will always - prefer width to height (all text will be placed on a single line). - - The \c elide property can alternatively be used to fit a line of plain text to a set width. - - A QmlGraphicsText object can be instantiated in Qml using the tag \c Text. -*/ -QmlGraphicsText::QmlGraphicsText(QmlGraphicsItem *parent) - : QmlGraphicsItem(*(new QmlGraphicsTextPrivate), parent) -{ - setAcceptedMouseButtons(Qt::LeftButton); - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -QmlGraphicsText::QmlGraphicsText(QmlGraphicsTextPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsItem(dd, parent) -{ - setAcceptedMouseButtons(Qt::LeftButton); - setFlag(QGraphicsItem::ItemHasNoContents, false); -} - -QmlGraphicsText::~QmlGraphicsText() -{ -} - -/*! - \qmlproperty string Text::font.family - \qmlproperty bool Text::font.bold - \qmlproperty bool Text::font.italic - \qmlproperty bool Text::font.underline - \qmlproperty real Text::font.pointSize - \qmlproperty int Text::font.pixelSize - - Set the Text's font attributes. -*/ -QFont QmlGraphicsText::font() const -{ - Q_D(const QmlGraphicsText); - return d->font; -} - -void QmlGraphicsText::setFont(const QFont &font) -{ - Q_D(QmlGraphicsText); - d->font = font; - - d->imgDirty = true; - d->updateSize(); - update(); -} - -void QmlGraphicsText::setText(const QString &n) -{ -#ifdef Q_ENABLE_PERFORMANCE_LOG - QmlPerfTimer st; -#endif - Q_D(QmlGraphicsText); - if (d->text == n) - return; - - d->richText = d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(n)); - if (d->richText) { - if (!d->doc) - { - d->control = new QTextControl(this); - d->control->setTextInteractionFlags(Qt::TextBrowserInteraction); - d->doc = d->control->document(); - d->doc->setDocumentMargin(0); - } - d->doc->setHtml(n); - } - - d->text = n; - d->imgDirty = true; - d->updateSize(); - emit textChanged(d->text); - update(); -} - -/*! - \qmlproperty string Text::text - - The text to display. Text supports both plain and rich text strings. - - The item will try to automatically determine whether the text should - be treated as rich text. This determination is made using Qt::mightBeRichText(). -*/ -QString QmlGraphicsText::text() const -{ - Q_D(const QmlGraphicsText); - return d->text; -} - -void QmlGraphicsText::setColor(const QColor &color) -{ - Q_D(QmlGraphicsText); - if (d->color == color) - return; - - d->imgDirty = true; - d->color = color; - update(); -} - -/*! - \qmlproperty color Text::color - - The text color. - - \qml - //green text using hexadecimal notation - Text { color: "#00FF00"; ... } - - //steelblue text using SVG color name - Text { color: "steelblue"; ... } - \endqml -*/ - -QColor QmlGraphicsText::color() const -{ - Q_D(const QmlGraphicsText); - return d->color; -} - -/*! - \qmlproperty enumeration Text::style - - Set an additional text style. - - Supported text styles are \c Normal, \c Outline, \c Raised and \c Sunken. - - \qml - Row { - Text { font.pointSize: 24; text: "Normal" } - Text { font.pointSize: 24; text: "Raised"; style: Text.Raised; styleColor: "#AAAAAA" } - Text { font.pointSize: 24; text: "Outline"; style: Text.Outline; styleColor: "red" } - Text { font.pointSize: 24; text: "Sunken"; style: Text.Sunken; styleColor: "#AAAAAA" } - } - \endqml - - \image declarative-textstyle.png -*/ -QmlGraphicsText::TextStyle QmlGraphicsText::style() const -{ - Q_D(const QmlGraphicsText); - return d->style; -} - -void QmlGraphicsText::setStyle(QmlGraphicsText::TextStyle style) -{ - Q_D(QmlGraphicsText); - if (d->style == style) - return; - - d->imgDirty = true; - d->style = style; - update(); -} - -void QmlGraphicsText::setStyleColor(const QColor &color) -{ - Q_D(QmlGraphicsText); - if (d->styleColor == color) - return; - - d->imgDirty = true; - d->styleColor = color; - update(); -} - -/*! - \qmlproperty color Text::styleColor - - Defines the secondary color used by text styles. - - \c styleColor is used as the outline color for outlined text, and as the - shadow color for raised or sunken text. If no style has been set, it is not - used at all. - */ -QColor QmlGraphicsText::styleColor() const -{ - Q_D(const QmlGraphicsText); - return d->styleColor; -} - -/*! - \qmlproperty enumeration Text::horizontalAlignment - \qmlproperty enumeration Text::verticalAlignment - - Sets the horizontal and vertical alignment of the text within the Text items - width and height. By default, the text is top-left aligned. - - The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and - \c AlignHCenter. The valid values for \c verticalAlignment are \c AlignTop, \c AlignBottom - and \c AlignVCenter. -*/ -QmlGraphicsText::HAlignment QmlGraphicsText::hAlign() const -{ - Q_D(const QmlGraphicsText); - return d->hAlign; -} - -void QmlGraphicsText::setHAlign(HAlignment align) -{ - Q_D(QmlGraphicsText); - d->hAlign = align; -} - -QmlGraphicsText::VAlignment QmlGraphicsText::vAlign() const -{ - Q_D(const QmlGraphicsText); - return d->vAlign; -} - -void QmlGraphicsText::setVAlign(VAlignment align) -{ - Q_D(QmlGraphicsText); - d->vAlign = align; -} - -/*! - \qmlproperty bool Text::wrap - - Set this property to wrap the text to the Text item's width. The text will only - wrap if an explicit width has been set. - - Wrapping is done on word boundaries (i.e. it is a "word-wrap"). If the text cannot be - word-wrapped to the specified width it will be partially drawn outside of the item's bounds. - If this is undesirable then enable clipping on the item (Item::clip). - - Wrapping is off by default. -*/ -//### Future may provide choice of wrap modes, such as QTextOption::WrapAtWordBoundaryOrAnywhere -bool QmlGraphicsText::wrap() const -{ - Q_D(const QmlGraphicsText); - return d->wrap; -} - -void QmlGraphicsText::setWrap(bool w) -{ - Q_D(QmlGraphicsText); - if (w == d->wrap) - return; - - d->wrap = w; - - d->imgDirty = true; - d->updateSize(); -} - -/*! - \qmlproperty enumeration Text::textFormat - - The way the text property should be displayed. - - Supported text formats are \c AutoText, \c PlainText and \c RichText. - - The default is AutoText. If the text format is AutoText the text element - will automatically determine whether the text should be treated as - rich text. This determination is made using Qt::mightBeRichText(). - - \table - \row - \o - \qml -Column { - TextEdit { - font.pointSize: 24 - text: "Hello World!" - } - TextEdit { - font.pointSize: 24 - textFormat: "RichText" - text: "Hello World!" - } - TextEdit { - font.pointSize: 24 - textFormat: "PlainText" - text: "Hello World!" - } -} - \endqml - \o \image declarative-textformat.png - \endtable -*/ - -QmlGraphicsText::TextFormat QmlGraphicsText::textFormat() const -{ - Q_D(const QmlGraphicsText); - return d->format; -} - -void QmlGraphicsText::setTextFormat(TextFormat format) -{ - Q_D(QmlGraphicsText); - if (format == d->format) - return; - bool wasRich = d->richText; - d->richText = format == RichText || (format == AutoText && Qt::mightBeRichText(d->text)); - - if (wasRich && !d->richText) { - //### delete control? (and vice-versa below) - d->imgDirty = true; - d->updateSize(); - update(); - } else if (!wasRich && d->richText) { - if (!d->doc) - { - d->control = new QTextControl(this); - d->control->setTextInteractionFlags(Qt::TextBrowserInteraction); - d->doc = d->control->document(); - d->doc->setDocumentMargin(0); - } - d->doc->setHtml(d->text); - d->imgDirty = true; - d->updateSize(); - update(); - } - d->format = format; -} - -/*! - \qmlproperty enumeration Text::elide - - Set this property to elide parts of the text fit to the Text item's width. - The text will only elide if an explicit width has been set. - - This property cannot be used with wrap enabled or with rich text. - - Eliding can be \c ElideNone (the default), \c ElideLeft, \c ElideMiddle, or \c ElideRight. - - If the text is a multi-length string, and the mode is not \c ElideNone, - the first string that fits will be used, otherwise the last will be elided. - - Multi-length strings are ordered from longest to shortest, separated by the - Unicode "String Terminator" character \c U009C (write this in QML with \c{"\\x9C"}). -*/ -QmlGraphicsText::TextElideMode QmlGraphicsText::elideMode() const -{ - Q_D(const QmlGraphicsText); - return d->elideMode; -} - -void QmlGraphicsText::setElideMode(QmlGraphicsText::TextElideMode mode) -{ - Q_D(QmlGraphicsText); - if (mode == d->elideMode) - return; - - d->elideMode = mode; - - d->imgDirty = true; - d->updateSize(); -} - -void QmlGraphicsText::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - Q_D(QmlGraphicsText); - if (newGeometry.width() != oldGeometry.width()) { - if (d->wrap || d->elideMode != QmlGraphicsText::ElideNone) { - d->imgDirty = true; - d->updateSize(); - } - } - QmlGraphicsItem::geometryChanged(newGeometry, oldGeometry); -} - -void QmlGraphicsTextPrivate::updateSize() -{ - Q_Q(QmlGraphicsText); - if (q->isComponentComplete()) { - QFontMetrics fm(font); - if (text.isEmpty()) { - q->setImplicitHeight(fm.height()); - return; - } - - int dy = q->height(); - QString tmp; - QSize size(0, 0); - - //setup instance of QTextLayout for all cases other than richtext - if (!richText) - { - tmp = text; - tmp.replace(QLatin1Char('\n'), QChar::LineSeparator); - singleline = !tmp.contains(QChar::LineSeparator); - if (singleline && elideMode != QmlGraphicsText::ElideNone && q->widthValid()) - tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); // XXX still worth layout...? - layout.clearLayout(); - layout.setFont(font); - layout.setText(tmp); - size = setupTextLayout(&layout); - cachedLayoutSize = size; - } - if (richText) { - singleline = false; // richtext can't elide or be optimized for single-line case - doc->setDefaultFont(font); - QTextOption option((Qt::Alignment)int(hAlign | vAlign)); - if (wrap) - option.setWrapMode(QTextOption::WordWrap); - else - option.setWrapMode(QTextOption::NoWrap); - doc->setDefaultTextOption(option); - if (wrap && !q->heightValid() && q->widthValid()) - doc->setTextWidth(q->width()); - else - doc->setTextWidth(doc->idealWidth()); // ### Text does not align if width is not set (QTextDoc bug) - dy -= (int)doc->size().height(); - } else { - dy -= size.height(); - } - int yoff = 0; - - if (q->heightValid()) { - if (vAlign == QmlGraphicsText::AlignBottom) - yoff = dy; - else if (vAlign == QmlGraphicsText::AlignVCenter) - yoff = dy/2; - } - q->setBaselineOffset(fm.ascent() + yoff); - - //### need to comfirm cost of always setting these for richText - q->setImplicitWidth(richText ? (int)doc->idealWidth() : size.width()); - q->setImplicitHeight(richText ? (int)doc->size().height() : size.height()); - } else { - dirty = true; - } -} - -// ### text layout handling should be profiled and optimized as needed -// what about QStackTextEngine engine(tmp, d->font.font()); QTextLayout textLayout(&engine); - -void QmlGraphicsTextPrivate::drawOutline() -{ - QPixmap img = QPixmap(imgCache.size()); - img.fill(Qt::transparent); - - QPainter ppm(&img); - - QPoint pos(imgCache.rect().topLeft()); - pos += QPoint(-1, 0); - ppm.drawPixmap(pos, imgStyleCache); - pos += QPoint(2, 0); - ppm.drawPixmap(pos, imgStyleCache); - pos += QPoint(-1, -1); - ppm.drawPixmap(pos, imgStyleCache); - pos += QPoint(0, 2); - ppm.drawPixmap(pos, imgStyleCache); - - pos += QPoint(0, -1); - ppm.drawPixmap(pos, imgCache); - ppm.end(); - - imgCache = img; -} - -void QmlGraphicsTextPrivate::drawOutline(int yOffset) -{ - QPixmap img = QPixmap(imgCache.size()); - img.fill(Qt::transparent); - - QPainter ppm(&img); - - QPoint pos(imgCache.rect().topLeft()); - pos += QPoint(0, yOffset); - ppm.drawPixmap(pos, imgStyleCache); - - pos += QPoint(0, -yOffset); - ppm.drawPixmap(pos, imgCache); - ppm.end(); - - imgCache = img; -} - -QSize QmlGraphicsTextPrivate::setupTextLayout(QTextLayout *layout) -{ - Q_Q(QmlGraphicsText); - layout->setCacheEnabled(true); - - QFontMetrics fm = QFontMetrics(font); - - int height = 0; - qreal widthUsed = 0; - qreal lineWidth = 0; - - //set manual width - if ((wrap || elideMode != QmlGraphicsText::ElideNone) && q->widthValid()) - lineWidth = q->width(); - - layout->beginLayout(); - - while (1) { - QTextLine line = layout->createLine(); - if (!line.isValid()) - break; - - if ((wrap || elideMode != QmlGraphicsText::ElideNone) && q->widthValid()) - line.setLineWidth(lineWidth); - } - layout->endLayout(); - - for (int i = 0; i < layout->lineCount(); ++i) { - QTextLine line = layout->lineAt(i); - widthUsed = qMax(widthUsed, line.naturalTextWidth()); - line.setPosition(QPointF(0, height)); - height += int(line.height()); - } - return QSize((int)widthUsed, height); -} - -QPixmap QmlGraphicsTextPrivate::wrappedTextImage(bool drawStyle) -{ - //do layout - QSize size = cachedLayoutSize; - - int x = 0; - for (int i = 0; i < layout.lineCount(); ++i) { - QTextLine line = layout.lineAt(i); - if (hAlign == QmlGraphicsText::AlignLeft) { - x = 0; - } else if (hAlign == QmlGraphicsText::AlignRight) { - x = size.width() - (int)line.naturalTextWidth(); - } else if (hAlign == QmlGraphicsText::AlignHCenter) { - x = (size.width() - (int)line.naturalTextWidth()) / 2; - } - line.setPosition(QPoint(x, (int)line.y())); - } - - //paint text - QPixmap img(size); - if (!size.isEmpty()) { - img.fill(Qt::transparent); - QPainter p(&img); - if (drawStyle) { - p.setPen(styleColor); - } - else - p.setPen(color); - p.setFont(font); - layout.draw(&p, QPointF(0, 0)); - } - return img; -} - -QPixmap QmlGraphicsTextPrivate::richTextImage(bool drawStyle) -{ - QSize size = doc->size().toSize(); - - //paint text - QPixmap img(size); - img.fill(Qt::transparent); - QPainter p(&img); - - if (drawStyle) { - QPalette pal = control->palette(); - pal.setColor(QPalette::Text, styleColor); - control->setPalette(pal); - QTextOption colorOption; - colorOption.setFlags(QTextOption::SuppressColors); - doc->setDefaultTextOption(colorOption); - } else { - QPalette pal = control->palette(); - pal.setColor(QPalette::Text, color); - control->setPalette(pal); - } - control->drawContents(&p, QRectF(QPointF(0, 0), QSizeF(size))); - if (drawStyle) - doc->setDefaultTextOption(QTextOption()); - return img; -} - -void QmlGraphicsTextPrivate::checkImgCache() -{ - if (!imgDirty) - return; - - bool empty = text.isEmpty(); - if (empty) { - imgCache = QPixmap(); - imgStyleCache = QPixmap(); - } else if (richText) { - imgCache = richTextImage(false); - if (style != QmlGraphicsText::Normal) - imgStyleCache = richTextImage(true); //### should use styleColor - } else { - imgCache = wrappedTextImage(false); - if (style != QmlGraphicsText::Normal) - imgStyleCache = wrappedTextImage(true); //### should use styleColor - } - if (!empty) - switch (style) { - case QmlGraphicsText::Outline: - drawOutline(); - break; - case QmlGraphicsText::Sunken: - drawOutline(-1); - break; - case QmlGraphicsText::Raised: - drawOutline(1); - break; - default: - break; - } - - imgDirty = false; -} - -void QmlGraphicsText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - Q_D(QmlGraphicsText); - d->checkImgCache(); - if (d->imgCache.isNull()) - return; - - bool oldAA = p->testRenderHint(QPainter::Antialiasing); - bool oldSmooth = p->testRenderHint(QPainter::SmoothPixmapTransform); - if (d->smooth) - p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); - - int w = width(); - int h = height(); - - int x = 0; - int y = 0; - - switch (d->hAlign) { - case AlignLeft: - x = 0; - break; - case AlignRight: - x = w - d->imgCache.width(); - break; - case AlignHCenter: - x = (w - d->imgCache.width()) / 2; - break; - } - - switch (d->vAlign) { - case AlignTop: - y = 0; - break; - case AlignBottom: - y = h - d->imgCache.height(); - break; - case AlignVCenter: - y = (h - d->imgCache.height()) / 2; - break; - } - - bool needClip = !clip() && (d->imgCache.width() > width() || - d->imgCache.height() > height()); - - if (needClip) { - p->save(); - p->setClipRect(boundingRect(), Qt::IntersectClip); - } - p->drawPixmap(x, y, d->imgCache); - if (needClip) - p->restore(); - - if (d->smooth) { - p->setRenderHint(QPainter::Antialiasing, oldAA); - p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); - } -} - -/*! - \qmlproperty bool Text::smooth - - Set this property if you want the text to be smoothly scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If - the item is displayed at its natural size, this property has no visual or - performance effect. - - \note Generally scaling artifacts are only visible if the item is stationary on - the screen. A common pattern when animating an item is to disable smooth - filtering at the beginning of the animation and reenable it at the conclusion. -*/ - -void QmlGraphicsText::componentComplete() -{ - Q_D(QmlGraphicsText); -#ifdef Q_ENABLE_PERFORMANCE_LOG - QmlPerfTimer cc; -#endif - QmlGraphicsItem::componentComplete(); - if (d->dirty) { - d->updateSize(); - d->dirty = false; - } -} - -/*! - \overload - Handles the given mouse \a event. - */ -void QmlGraphicsText::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsText); - - if (!d->richText || !d->doc || d->control->anchorAt(event->pos()).isEmpty()) { - event->setAccepted(false); - d->activeLink = QString(); - } else { - d->activeLink = d->control->anchorAt(event->pos()); - } - - // ### may malfunction if two of the same links are clicked & dragged onto each other) - - if (!event->isAccepted()) - QmlGraphicsItem::mousePressEvent(event); - -} - -/*! - \qmlsignal Text::linkActivated(link) - - This handler is called when the user clicks on a link embedded in the text. -*/ - -/*! - \overload - Handles the given mouse \a event. - */ -void QmlGraphicsText::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsText); - - // ### confirm the link, and send a signal out - if (d->richText && d->doc && d->activeLink == d->control->anchorAt(event->pos())) - emit linkActivated(d->activeLink); - else - event->setAccepted(false); - - if (!event->isAccepted()) - QmlGraphicsItem::mouseReleaseEvent(event); -} -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxtext.h b/src/declarative/fx/qfxtext.h deleted file mode 100644 index bc2fb4f..0000000 --- a/src/declarative/fx/qfxtext.h +++ /dev/null @@ -1,151 +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 QFXTEXT_H -#define QFXTEXT_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlGraphicsTextPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsText : public QmlGraphicsItem -{ - Q_OBJECT - Q_ENUMS(HAlignment) - Q_ENUMS(VAlignment) - Q_ENUMS(TextStyle) - Q_ENUMS(TextFormat) - Q_ENUMS(TextElideMode) - - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(TextStyle style READ style WRITE setStyle) - Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor) - Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) - Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign) - Q_PROPERTY(bool wrap READ wrap WRITE setWrap) //### there are several wrap modes in Qt - Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) - Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode) //### elideMode? - -public: - QmlGraphicsText(QmlGraphicsItem *parent=0); - ~QmlGraphicsText(); - - enum HAlignment { AlignLeft = Qt::AlignLeft, - AlignRight = Qt::AlignRight, - AlignHCenter = Qt::AlignHCenter }; - enum VAlignment { AlignTop = Qt::AlignTop, - AlignBottom = Qt::AlignBottom, - AlignVCenter = Qt::AlignVCenter }; - enum TextStyle { Normal, - Outline, - Raised, - Sunken }; - enum TextFormat { PlainText = Qt::PlainText, - RichText = Qt::RichText, - AutoText = Qt::AutoText }; - enum TextElideMode { ElideLeft = Qt::ElideLeft, - ElideRight = Qt::ElideRight, - ElideMiddle = Qt::ElideMiddle, - ElideNone = Qt::ElideNone }; - - QString text() const; - void setText(const QString &); - - QFont font() const; - void setFont(const QFont &font); - - QColor color() const; - void setColor(const QColor &c); - - TextStyle style() const; - void setStyle(TextStyle style); - - QColor styleColor() const; - void setStyleColor(const QColor &c); - - HAlignment hAlign() const; - void setHAlign(HAlignment align); - - VAlignment vAlign() const; - void setVAlign(VAlignment align); - - bool wrap() const; - void setWrap(bool w); - - TextFormat textFormat() const; - void setTextFormat(TextFormat format); - - TextElideMode elideMode() const; - void setElideMode(TextElideMode); - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - - virtual void componentComplete(); - -Q_SIGNALS: - void textChanged(const QString &text); - void linkActivated(const QString &link); - -protected: - QmlGraphicsText(QmlGraphicsTextPrivate &dd, QmlGraphicsItem *parent); - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - -private: - Q_DISABLE_COPY(QmlGraphicsText) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsText) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsText) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qfxtext_p.h b/src/declarative/fx/qfxtext_p.h deleted file mode 100644 index 436aa08..0000000 --- a/src/declarative/fx/qfxtext_p.h +++ /dev/null @@ -1,113 +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 QFXTEXT_P_H -#define QFXTEXT_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 "qfxitem.h" -#include "qfxitem_p.h" -#include "qml.h" -#include - -QT_BEGIN_NAMESPACE - -class QTextLayout; -class QTextDocument; -class QTextControl; - -class QmlGraphicsTextPrivate : public QmlGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsText) -public: - QmlGraphicsTextPrivate() - : color((QRgb)0), style(QmlGraphicsText::Normal), imgDirty(true), - hAlign(QmlGraphicsText::AlignLeft), vAlign(QmlGraphicsText::AlignTop), elideMode(QmlGraphicsText::ElideNone), - dirty(true), wrap(false), richText(false), singleline(false), control(0), doc(0), - format(QmlGraphicsText::AutoText) - { - } - - void updateSize(); - void checkImgCache(); - - void drawOutline(); - void drawOutline(int yOffset); - - QPixmap wrappedTextImage(bool drawStyle); - QPixmap richTextImage(bool drawStyle); - QSize setupTextLayout(QTextLayout *layout); - - QString text; - QFont font; - QColor color; - QmlGraphicsText::TextStyle style; - QColor styleColor; - QString activeLink; - bool imgDirty; - QPixmap imgCache; - QPixmap imgStyleCache; - QmlGraphicsText::HAlignment hAlign; - QmlGraphicsText::VAlignment vAlign; - QmlGraphicsText::TextElideMode elideMode; - bool dirty; - bool wrap; - bool richText; - bool singleline; - QTextControl *control; - QTextDocument *doc; - QTextLayout layout; - QSize cachedLayoutSize; - QmlGraphicsText::TextFormat format; -}; - -QT_END_NAMESPACE -#endif diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp deleted file mode 100644 index ddb9194..0000000 --- a/src/declarative/fx/qfxtextedit.cpp +++ /dev/null @@ -1,1085 +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 -#include "qfxtextedit_p.h" -#include -#include -#include "qfxevents_p.h" -#include -#include -#include -#include - -#include -#include - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,TextEdit,QmlGraphicsTextEdit) - -/*! - \qmlclass TextEdit - \brief The TextEdit item allows you to add editable formatted text to a scene. - - It can display both plain and rich text. For example: - - \qml -TextEdit { - id: edit - text: "Hello World!" - focus: true - font.family: "Helvetica" - font.pointSize: 20 - color: "blue" - width: 240 -} - \endqml - - \image declarative-textedit.gif - - \sa Text -*/ - -/*! - \internal - \class QmlGraphicsTextEdit - \qmlclass TextEdit - \ingroup group_coreitems - - \brief The QmlGraphicsTextEdit class provides an editable formatted text item that you can add to a QmlView. - - It can display both plain and rich text. - - \image declarative-textedit.png - - A QmlGraphicsTextEdit object can be instantiated in Qml using the tag \c <TextEdit>. -*/ - -/*! - Constructs a new QmlGraphicsTextEdit. -*/ -QmlGraphicsTextEdit::QmlGraphicsTextEdit(QmlGraphicsItem *parent) -: QmlGraphicsPaintedItem(*(new QmlGraphicsTextEditPrivate), parent) -{ - Q_D(QmlGraphicsTextEdit); - d->init(); -} - -/*! -\internal -*/ -QmlGraphicsTextEdit::QmlGraphicsTextEdit(QmlGraphicsTextEditPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsPaintedItem(dd, parent) -{ - Q_D(QmlGraphicsTextEdit); - d->init(); -} - -QString QmlGraphicsTextEdit::text() const -{ - Q_D(const QmlGraphicsTextEdit); - - if (d->richText) - return d->document->toHtml(); - else - return d->document->toPlainText(); -} - -/*! - \qmlproperty string TextEdit::font.family - \qmlproperty bool TextEdit::font.bold - \qmlproperty bool TextEdit::font.italic - \qmlproperty bool TextEdit::font.underline - \qmlproperty real TextEdit::font.pointSize - \qmlproperty int TextEdit::font.pixelSize - - Set the TextEdit's font attributes. -*/ - -/*! - \qmlproperty string TextEdit::text - - The text to display. If the text format is AutoText the text edit will - automatically determine whether the text should be treated as - rich text. This determination is made using Qt::mightBeRichText(). -*/ -void QmlGraphicsTextEdit::setText(const QString &text) -{ - Q_D(QmlGraphicsTextEdit); - if (QmlGraphicsTextEdit::text() == text) - return; - d->text = text; - d->richText = d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(text)); - if (d->richText) { - d->control->setHtml(text); - } else { - d->control->setPlainText(text); - } - q_textChanged(); - updateSize(); -} - -/*! - \qmlproperty enumeration TextEdit::textFormat - - The way the text property should be displayed. - - Supported text formats are \c AutoText, \c PlainText and \c RichText. - - The default is AutoText. If the text format is AutoText the text edit - will automatically determine whether the text should be treated as - rich text. This determination is made using Qt::mightBeRichText(). - - \table - \row - \o - \qml -Column { - TextEdit { - font.pointSize: 24 - text: "Hello World!" - } - TextEdit { - font.pointSize: 24 - textFormat: "RichText" - text: "Hello World!" - } - TextEdit { - font.pointSize: 24 - textFormat: "PlainText" - text: "Hello World!" - } -} - \endqml - \o \image declarative-textformat.png - \endtable -*/ -QmlGraphicsTextEdit::TextFormat QmlGraphicsTextEdit::textFormat() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->format; -} - -void QmlGraphicsTextEdit::setTextFormat(TextFormat format) -{ - Q_D(QmlGraphicsTextEdit); - if (format == d->format) - return; - bool wasRich = d->richText; - d->richText = format == RichText || (format == AutoText && Qt::mightBeRichText(d->text)); - - if (wasRich && !d->richText) { - d->control->setPlainText(d->text); - updateSize(); - } else if (!wasRich && d->richText) { - d->control->setHtml(d->text); - updateSize(); - } - d->format = format; -} - -QFont QmlGraphicsTextEdit::font() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->font; -} - -void QmlGraphicsTextEdit::setFont(const QFont &font) -{ - Q_D(QmlGraphicsTextEdit); - d->font = font; - - clearCache(); - d->document->setDefaultFont(d->font); - if(d->cursor){ - d->cursor->setHeight(QFontMetrics(d->font).height()); - moveCursorDelegate(); - } - updateSize(); - update(); -} - -/*! - \qmlproperty color TextEdit::color - - The text color. - - \qml -// green text using hexadecimal notation -TextEdit { color: "#00FF00"; ... } - -// steelblue text using SVG color name -TextEdit { color: "steelblue"; ... } - \endqml -*/ -QColor QmlGraphicsTextEdit::color() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->color; -} - -void QmlGraphicsTextEdit::setColor(const QColor &color) -{ - Q_D(QmlGraphicsTextEdit); - if (d->color == color) - return; - - clearCache(); - d->color = color; - QPalette pal = d->control->palette(); - pal.setColor(QPalette::Text, color); - d->control->setPalette(pal); - update(); -} - -/*! - \qmlproperty color TextEdit::selectionColor - - The text highlight color, used behind selections. -*/ -QColor QmlGraphicsTextEdit::selectionColor() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->selectionColor; -} - -void QmlGraphicsTextEdit::setSelectionColor(const QColor &color) -{ - Q_D(QmlGraphicsTextEdit); - if (d->selectionColor == color) - return; - - clearCache(); - d->selectionColor = color; - QPalette pal = d->control->palette(); - pal.setColor(QPalette::Highlight, color); - d->control->setPalette(pal); - update(); -} - -/*! - \qmlproperty color TextEdit::selectedTextColor - - The selected text color, used in selections. -*/ -QColor QmlGraphicsTextEdit::selectedTextColor() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->selectedTextColor; -} - -void QmlGraphicsTextEdit::setSelectedTextColor(const QColor &color) -{ - Q_D(QmlGraphicsTextEdit); - if (d->selectedTextColor == color) - return; - - clearCache(); - d->selectedTextColor = color; - QPalette pal = d->control->palette(); - pal.setColor(QPalette::HighlightedText, color); - d->control->setPalette(pal); - update(); -} - -/*! - \qmlproperty enumeration TextEdit::horizontalAlignment - \qmlproperty enumeration TextEdit::verticalAlignment - - Sets the horizontal and vertical alignment of the text within the TextEdit items - width and height. By default, the text is top-left aligned. - - The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and - \c AlignHCenter. The valid values for \c verticalAlignment are \c AlignTop, \c AlignBottom - and \c AlignVCenter. -*/ -QmlGraphicsTextEdit::HAlignment QmlGraphicsTextEdit::hAlign() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->hAlign; -} - -void QmlGraphicsTextEdit::setHAlign(QmlGraphicsTextEdit::HAlignment alignment) -{ - Q_D(QmlGraphicsTextEdit); - if (alignment == d->hAlign) - return; - d->hAlign = alignment; - d->updateDefaultTextOption(); - updateSize(); -} - -QmlGraphicsTextEdit::VAlignment QmlGraphicsTextEdit::vAlign() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->vAlign; -} - -void QmlGraphicsTextEdit::setVAlign(QmlGraphicsTextEdit::VAlignment alignment) -{ - Q_D(QmlGraphicsTextEdit); - if (alignment == d->vAlign) - return; - d->vAlign = alignment; - d->updateDefaultTextOption(); - updateSize(); -} - -bool QmlGraphicsTextEdit::wrap() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->wrap; -} - -/*! - \qmlproperty bool TextEdit::wrap - - Set this property to wrap the text to the TextEdit item's width. - The text will only wrap if an explicit width has been set. - - Wrapping is done on word boundaries (i.e. it is a "word-wrap"). Wrapping is off by default. -*/ -void QmlGraphicsTextEdit::setWrap(bool w) -{ - Q_D(QmlGraphicsTextEdit); - if (w == d->wrap) - return; - d->wrap = w; - d->updateDefaultTextOption(); - updateSize(); -} - -/*! - \qmlproperty bool TextEdit::cursorVisible - If true the text edit shows a cursor. - - This property is set and unset when the text edit gets focus, but it can also - be set directly (useful, for example, if a KeyProxy might forward keys to it). -*/ -bool QmlGraphicsTextEdit::isCursorVisible() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->cursorVisible; -} - -void QmlGraphicsTextEdit::setCursorVisible(bool on) -{ - Q_D(QmlGraphicsTextEdit); - if (d->cursorVisible == on) - return; - d->cursorVisible = on; - QFocusEvent focusEvent(on ? QEvent::FocusIn : QEvent::FocusOut); - if (!on && !d->persistentSelection) - d->control->setCursorIsFocusIndicator(true); - d->control->processEvent(&focusEvent, QPointF(0, 0)); -} - -/*! - \qmlproperty int TextEdit::cursorPosition - The position of the cursor in the TextEdit. -*/ -int QmlGraphicsTextEdit::cursorPosition() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->control->textCursor().position(); -} - -void QmlGraphicsTextEdit::setCursorPosition(int pos) -{ - Q_D(QmlGraphicsTextEdit); - QTextCursor cursor = d->control->textCursor(); - if (cursor.position() == pos) - return; - cursor.setPosition(pos); - d->control->setTextCursor(cursor); -} - -/*! - \qmlproperty Component TextEdit::cursorDelegate - The delegate for the cursor in the TextEdit. - - If you set a cursorDelegate for a TextEdit, this delegate will be used for - drawing the cursor instead of the standard cursor. An instance of the - delegate will be created and managed by the text edit when a cursor is - needed, and the x and y properties of delegate instance will be set so as - to be one pixel before the top left of the current character. - - Note that the root item of the delegate component must be a QmlGraphicsItem or - QmlGraphicsItem derived item. -*/ -QmlComponent* QmlGraphicsTextEdit::cursorDelegate() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->cursorComponent; -} - -void QmlGraphicsTextEdit::setCursorDelegate(QmlComponent* c) -{ - Q_D(QmlGraphicsTextEdit); - if(d->cursorComponent){ - if(d->cursor){ - disconnect(d->control, SIGNAL(cursorPositionChanged()), - this, SLOT(moveCursorDelegate())); - d->control->setCursorWidth(-1); - dirtyCache(cursorRect()); - delete d->cursor; - d->cursor = 0; - } - } - d->cursorComponent = c; - if(c && c->isReady()){ - loadCursorDelegate(); - }else{ - if(c) - connect(c, SIGNAL(statusChanged()), - this, SLOT(loadCursorDelegate())); - } -} - -void QmlGraphicsTextEdit::loadCursorDelegate() -{ - Q_D(QmlGraphicsTextEdit); - if(d->cursorComponent->isLoading()) - return; - d->cursor = qobject_cast(d->cursorComponent->create(qmlContext(this))); - if(d->cursor){ - connect(d->control, SIGNAL(cursorPositionChanged()), - this, SLOT(moveCursorDelegate())); - d->control->setCursorWidth(0); - dirtyCache(cursorRect()); - d->cursor->setParentItem(this); - d->cursor->setHeight(QFontMetrics(d->font).height()); - moveCursorDelegate(); - }else{ - qWarning() << QLatin1String("Error loading cursor delegate for TextEdit:") + objectName(); - } -} - -/*! - \qmlproperty int TextEdit::selectionStart - - The cursor position before the first character in the current selection. - Setting this and selectionEnd allows you to specify a selection in the - text edit. - - Note that if selectionStart == selectionEnd then there is no current - selection. If you attempt to set selectionStart to a value outside of - the current text, selectionStart will not be changed. - - \sa selectionEnd, cursorPosition, selectedText -*/ -int QmlGraphicsTextEdit::selectionStart() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->control->textCursor().selectionStart(); -} - -void QmlGraphicsTextEdit::setSelectionStart(int s) -{ - Q_D(QmlGraphicsTextEdit); - if(d->lastSelectionStart == s || s < 0 || s > text().length()) - return; - d->lastSelectionStart = s; - d->updateSelection();// Will emit the relevant signals -} - -/*! - \qmlproperty int TextEdit::selectionEnd - - The cursor position after the last character in the current selection. - Setting this and selectionStart allows you to specify a selection in the - text edit. - - Note that if selectionStart == selectionEnd then there is no current - selection. If you attempt to set selectionEnd to a value outside of - the current text, selectionEnd will not be changed. - - \sa selectionStart, cursorPosition, selectedText -*/ -int QmlGraphicsTextEdit::selectionEnd() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->control->textCursor().selectionEnd(); -} - -void QmlGraphicsTextEdit::setSelectionEnd(int s) -{ - Q_D(QmlGraphicsTextEdit); - if(d->lastSelectionEnd == s || s < 0 || s > text().length()) - return; - d->lastSelectionEnd = s; - d->updateSelection();// Will emit the relevant signals -} - -/*! - \qmlproperty string TextEdit::selectedText - - This read-only property provides the text currently selected in the - text edit. - - It is equivalent to the following snippet, but is faster and easier - to use. - \code - //myTextEdit is the id of the TextEdit - myTextEdit.text.toString().substring(myTextEdit.selectionStart, - myTextEdit.selectionEnd); - \endcode -*/ -QString QmlGraphicsTextEdit::selectedText() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->control->textCursor().selectedText(); -} - -/*! - \qmlproperty bool TextEdit::focusOnPress - - Whether the TextEdit should gain focus on a mouse press. By default this is - set to false; -*/ -bool QmlGraphicsTextEdit::focusOnPress() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->focusOnPress; -} - -void QmlGraphicsTextEdit::setFocusOnPress(bool on) -{ - Q_D(QmlGraphicsTextEdit); - if (d->focusOnPress == on) - return; - d->focusOnPress = on; -} - -/*! - \qmlproperty bool TextEdit::persistentSelection - - Whether the TextEdit should keep the selection visible when it loses focus to another - item in the scene. By default this is set to true; -*/ -bool QmlGraphicsTextEdit::persistentSelection() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->persistentSelection; -} - -void QmlGraphicsTextEdit::setPersistentSelection(bool on) -{ - Q_D(QmlGraphicsTextEdit); - if (d->persistentSelection == on) - return; - d->persistentSelection = on; -} - -qreal QmlGraphicsTextEdit::textMargin() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->textMargin; -} - -void QmlGraphicsTextEdit::setTextMargin(qreal margin) -{ - Q_D(QmlGraphicsTextEdit); - if (d->textMargin == margin) - return; - d->textMargin = margin; - d->document->setDocumentMargin(d->textMargin); -} - -void QmlGraphicsTextEdit::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - if (newGeometry.width() != oldGeometry.width()) - updateSize(); - QmlGraphicsPaintedItem::geometryChanged(newGeometry, oldGeometry); -} - -/*! - Ensures any delayed caching or data loading the class - needs to performed is complete. -*/ -void QmlGraphicsTextEdit::componentComplete() -{ - Q_D(QmlGraphicsTextEdit); - QmlGraphicsPaintedItem::componentComplete(); - if (d->dirty) { - updateSize(); - d->dirty = false; - } -} - -/*! - \qmlproperty bool TextEdit::readOnly - - Whether the user an interact with the TextEdit item. If this - property is set to true the text cannot be edited by user interaction. - - By default this property is false. -*/ -void QmlGraphicsTextEdit::setReadOnly(bool r) -{ - Q_D(QmlGraphicsTextEdit); - - Qt::TextInteractionFlags flags = Qt::NoTextInteraction; - if (r) { - flags = Qt::TextSelectableByMouse; - } else { - flags = Qt::TextEditorInteraction; - } - d->control->setTextInteractionFlags(flags); - if (!r) - d->control->moveCursor(QTextCursor::End); -} - -bool QmlGraphicsTextEdit::isReadOnly() const -{ - Q_D(const QmlGraphicsTextEdit); - return !(d->control->textInteractionFlags() & Qt::TextEditable); -} - -/*! - Sets how the text edit should interact with user input to the given - \a flags. -*/ -void QmlGraphicsTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags) -{ - Q_D(QmlGraphicsTextEdit); - d->control->setTextInteractionFlags(flags); -} - -/*! - Returns the flags specifying how the text edit should interact - with user input. -*/ -Qt::TextInteractionFlags QmlGraphicsTextEdit::textInteractionFlags() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->control->textInteractionFlags(); -} - -/*! - Returns the cursor for the point at the given \a pos on the - text edit. -*/ -QTextCursor QmlGraphicsTextEdit::cursorForPosition(const QPoint &pos) const -{ - Q_D(const QmlGraphicsTextEdit); - return d->control->cursorForPosition(pos); -} - -/*! - Returns the rectangle where the given text \a cursor is rendered - within the text edit. -*/ -QRect QmlGraphicsTextEdit::cursorRect(const QTextCursor &cursor) const -{ - Q_D(const QmlGraphicsTextEdit); - if (cursor.isNull()) - return QRect(); - - return d->control->cursorRect(cursor).toRect(); -} - -/*! - Returns the rectangle where the text cursor is rendered - within the text edit. -*/ -QRect QmlGraphicsTextEdit::cursorRect() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->control->cursorRect().toRect(); -} - - -/*! - Sets the text cursor for the text edit to the given \a cursor. -*/ -void QmlGraphicsTextEdit::setTextCursor(const QTextCursor &cursor) -{ - Q_D(QmlGraphicsTextEdit); - d->control->setTextCursor(cursor); -} - -/*! - Returns the text cursor for the text edit. -*/ -QTextCursor QmlGraphicsTextEdit::textCursor() const -{ - Q_D(const QmlGraphicsTextEdit); - return d->control->textCursor(); -} - -/*! -Moves the cursor by performing the given \a operation. - -If \a mode is QTextCursor::KeepAnchor, the cursor selects the text it moves over. This is the same effect that the user achieves when they hold down the Shift key and move the cursor with the cursor keys. -*/ -void QmlGraphicsTextEdit::moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode) -{ - Q_D(QmlGraphicsTextEdit); - d->control->moveCursor(operation, mode); -} - -/*! -\overload -Handles the given \a event. -*/ -bool QmlGraphicsTextEdit::event(QEvent *event) -{ - Q_D(QmlGraphicsTextEdit); - if (event->type() == QEvent::ShortcutOverride) { - d->control->processEvent(event, QPointF(0, 0)); - return event->isAccepted(); - } - return QmlGraphicsPaintedItem::event(event); -} - -/*! -\overload -Handles the given key \a event. -*/ -void QmlGraphicsTextEdit::keyPressEvent(QKeyEvent *event) -{ - Q_D(QmlGraphicsTextEdit); - //### this causes non-standard cursor behavior in some cases. - // is it still needed? - /*QTextCursor c = textCursor(); - QTextCursor::MoveOperation op = QTextCursor::NoMove; - if (event == QKeySequence::MoveToNextChar) { - op = QTextCursor::Right; - } else if (event == QKeySequence::MoveToPreviousChar) { - op = QTextCursor::Left; - } else if (event == QKeySequence::MoveToNextWord) { - op = QTextCursor::WordRight; - } else if (event == QKeySequence::MoveToPreviousWord) { - op = QTextCursor::WordLeft; - } else if (event == QKeySequence::MoveToNextLine) { - op = QTextCursor::Down; - } else if (event == QKeySequence::MoveToPreviousLine) { - op = QTextCursor::Up; - } - - if (op != QTextCursor::NoMove && !c.movePosition(op)) - event->ignore(); - else*/ - d->control->processEvent(event, QPointF(0, 0)); - - if (!event->isAccepted()) - QmlGraphicsPaintedItem::keyPressEvent(event); -} - -/*! -\overload -Handles the given key \a event. -*/ -void QmlGraphicsTextEdit::keyReleaseEvent(QKeyEvent *event) -{ - Q_D(QmlGraphicsTextEdit); - d->control->processEvent(event, QPointF(0, 0)); - if (!event->isAccepted()) - QmlGraphicsPaintedItem::keyReleaseEvent(event); -} - -/*! - \overload - Handles changing of the focus property. Focus is applied to the control - even if the edit does not have active focus. This is because things - like KeyProxy can give the behavior of focus even when hasFocus() isn't - true. -*/ -void QmlGraphicsTextEdit::focusChanged(bool hasFocus) -{ - setCursorVisible(hasFocus); - QmlGraphicsItem::focusChanged(hasFocus); -} - -/*! - Causes all text to be selected. -*/ -void QmlGraphicsTextEdit::selectAll() -{ - Q_D(QmlGraphicsTextEdit); - d->control->selectAll(); -} - -/*! -\overload -Handles the given mouse \a event. -*/ -void QmlGraphicsTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsTextEdit); - if (d->focusOnPress) - setFocus(true); - d->control->processEvent(event, QPointF(0, 0)); - if (!event->isAccepted()) - QmlGraphicsPaintedItem::mousePressEvent(event); -} - -/*! -\overload -Handles the given mouse \a event. -*/ -void QmlGraphicsTextEdit::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsTextEdit); - d->control->processEvent(event, QPointF(0, 0)); - if (!event->isAccepted()) - QmlGraphicsPaintedItem::mousePressEvent(event); -} - -/*! -\overload -Handles the given mouse \a event. -*/ -void QmlGraphicsTextEdit::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsTextEdit); - d->control->processEvent(event, QPointF(0, 0)); - if (!event->isAccepted()) - QmlGraphicsPaintedItem::mouseDoubleClickEvent(event); -} - -/*! -\overload -Handles the given mouse \a event. -*/ -void QmlGraphicsTextEdit::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsTextEdit); - d->control->processEvent(event, QPointF(0, 0)); - if (!event->isAccepted()) - QmlGraphicsPaintedItem::mousePressEvent(event); -} - -/*! -\overload -Handles the given input method \a event. -*/ -void QmlGraphicsTextEdit::inputMethodEvent(QInputMethodEvent *event) -{ - Q_D(QmlGraphicsTextEdit); - d->control->processEvent(event, QPointF(0, 0)); -} - -/*! -\overload -Returns the value of the given \a property. -*/ -QVariant QmlGraphicsTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const -{ - Q_D(const QmlGraphicsTextEdit); - return d->control->inputMethodQuery(property); -} - -/*! -Draws the contents of the text edit using the given \a painter within -the given \a bounds. -*/ -void QmlGraphicsTextEdit::drawContents(QPainter *painter, const QRect &bounds) -{ - Q_D(QmlGraphicsTextEdit); - - painter->setRenderHint(QPainter::TextAntialiasing, true); - - d->control->drawContents(painter, bounds); -} - -void QmlGraphicsTextEdit::updateImgCache(const QRectF &r) -{ - dirtyCache(r.toRect()); - emit update(); -} - -/*! - \qmlproperty bool TextEdit::smooth - - Set this property if you want the text to be smoothly scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If - the item is displayed at its natural size, this property has no visual or - performance effect. - - \note Generally scaling artifacts are only visible if the item is stationary on - the screen. A common pattern when animating an item is to disable smooth - filtering at the beginning of the animation and reenable it at the conclusion. -*/ - -void QmlGraphicsTextEditPrivate::init() -{ - Q_Q(QmlGraphicsTextEdit); - - q->setSmoothTransform(smooth); - q->setAcceptedMouseButtons(Qt::LeftButton); - q->setFlag(QGraphicsItem::ItemHasNoContents, false); - q->setFlag(QGraphicsItem::ItemAcceptsInputMethod); - - control = new QTextControl(q); - - QObject::connect(control, SIGNAL(updateRequest(QRectF)), q, SLOT(updateImgCache(QRectF))); - - QObject::connect(control, SIGNAL(textChanged()), q, SLOT(q_textChanged())); - QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged())); - QObject::connect(control, SIGNAL(selectionChanged()), q, SLOT(updateSelectionMarkers())); - QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(updateSelectionMarkers())); - QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SIGNAL(cursorPositionChanged())); - - document = control->document(); - document->setDefaultFont(font); - document->setDocumentMargin(textMargin); - document->setUndoRedoEnabled(false); // flush undo buffer. - document->setUndoRedoEnabled(true); - updateDefaultTextOption(); -} - -void QmlGraphicsTextEdit::q_textChanged() -{ - if (!widthValid()) - updateSize(); //### optimize: we get 3 calls to updateSize every time a letter is typed - emit textChanged(text()); -} - -void QmlGraphicsTextEdit::moveCursorDelegate() -{ - Q_D(QmlGraphicsTextEdit); - if(!d->cursor) - return; - QRectF cursorRect = d->control->cursorRect(); - d->cursor->setX(cursorRect.x()); - d->cursor->setY(cursorRect.y()); -} - -void QmlGraphicsTextEditPrivate::updateSelection() -{ - Q_Q(QmlGraphicsTextEdit); - QTextCursor cursor = control->textCursor(); - bool startChange = (lastSelectionStart != cursor.selectionStart()); - bool endChange = (lastSelectionEnd != cursor.selectionEnd()); - //### Is it worth calculating a more minimal set of movements? - cursor.beginEditBlock(); - cursor.setPosition(lastSelectionStart, QTextCursor::MoveAnchor); - cursor.setPosition(lastSelectionEnd, QTextCursor::KeepAnchor); - cursor.endEditBlock(); - control->setTextCursor(cursor); - if(startChange) - q->selectionStartChanged(); - if(endChange) - q->selectionEndChanged(); - startChange = (lastSelectionStart != control->textCursor().selectionStart()); - endChange = (lastSelectionEnd != control->textCursor().selectionEnd()); - if(startChange || endChange) - qWarning() << "QmlGraphicsTextEditPrivate::updateSelection() has failed you."; -} - -void QmlGraphicsTextEdit::updateSelectionMarkers() -{ - Q_D(QmlGraphicsTextEdit); - if(d->lastSelectionStart != d->control->textCursor().selectionStart()){ - d->lastSelectionStart = d->control->textCursor().selectionStart(); - emit selectionStartChanged(); - } - if(d->lastSelectionEnd != d->control->textCursor().selectionEnd()){ - d->lastSelectionEnd = d->control->textCursor().selectionEnd(); - emit selectionEndChanged(); - } -} - -//### we should perhaps be a bit smarter here -- depending on what has changed, we shouldn't -// need to do all the calculations each time -void QmlGraphicsTextEdit::updateSize() -{ - Q_D(QmlGraphicsTextEdit); - if (isComponentComplete()) { - QFontMetrics fm = QFontMetrics(d->font); - int dy = height(); - // ### assumes that if the width is set, the text will fill to edges - // ### (unless wrap is false, then clipping will occur) - if (widthValid()) - d->document->setTextWidth(width()); - dy -= (int)d->document->size().height(); - - int yoff = 0; - if (heightValid()) { - if (d->vAlign == AlignBottom) - yoff = dy; - else if (d->vAlign == AlignVCenter) - yoff = dy/2; - } - setBaselineOffset(fm.ascent() + yoff + d->textMargin); - - //### need to comfirm cost of always setting these - int newWidth = (int)d->document->idealWidth(); - d->document->setTextWidth(newWidth); // ### QTextDoc> Alignment will not work unless textWidth is set. Does Text need this line as well? - int cursorWidth = 1; - if(d->cursor) - cursorWidth = d->cursor->width(); - newWidth += cursorWidth; - if(!d->document->isEmpty()) - newWidth += 3;// ### Need a better way of accounting for space between char and cursor - // ### Setting the implicitWidth triggers another updateSize(), and unless there are bindings nothing has changed. - setImplicitWidth(newWidth); - setImplicitHeight(d->text.isEmpty() ? fm.height() : (int)d->document->size().height()); - - setContentsSize(QSize(width(), height())); - } else { - d->dirty = true; - } - emit update(); -} - -void QmlGraphicsTextEditPrivate::updateDefaultTextOption() -{ - QTextOption opt = document->defaultTextOption(); - int oldAlignment = opt.alignment(); - opt.setAlignment((Qt::Alignment)(int)(hAlign | vAlign)); - - QTextOption::WrapMode oldWrapMode = opt.wrapMode(); - - if (wrap) - opt.setWrapMode(QTextOption::WordWrap); - else - opt.setWrapMode(QTextOption::NoWrap); - - if (oldWrapMode == opt.wrapMode() && oldAlignment == opt.alignment()) - return; - document->setDefaultTextOption(opt); -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h deleted file mode 100644 index 28eb180..0000000 --- a/src/declarative/fx/qfxtextedit.h +++ /dev/null @@ -1,234 +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 QFXTEXTEDIT_H -#define QFXTEXTEDIT_H - -#include -#include - -#include -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QmlGraphicsTextEditPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsTextEdit : public QmlGraphicsPaintedItem -{ - Q_OBJECT - Q_ENUMS(VAlignment) - Q_ENUMS(HAlignment) - Q_ENUMS(TextFormat) - - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) - Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign) - Q_PROPERTY(bool wrap READ wrap WRITE setWrap) //### other wrap modes - Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) - Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) - Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) - Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) - Q_PROPERTY(QmlComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate) - Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) - Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) - Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged) - Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) - Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection) - Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin) - -public: - QmlGraphicsTextEdit(QmlGraphicsItem *parent=0); - - enum HAlignment { - AlignLeft = Qt::AlignLeft, - AlignRight = Qt::AlignRight, - AlignHCenter = Qt::AlignHCenter - }; - - enum VAlignment { - AlignTop = Qt::AlignTop, - AlignBottom = Qt::AlignBottom, - AlignVCenter = Qt::AlignVCenter - }; - - enum TextFormat { - PlainText = Qt::PlainText, - RichText = Qt::RichText, - AutoText = Qt::AutoText - }; - - QString text() const; - void setText(const QString &); - - TextFormat textFormat() const; - void setTextFormat(TextFormat format); - - QFont font() const; - void setFont(const QFont &font); - - QColor color() const; - void setColor(const QColor &c); - - QColor selectionColor() const; - void setSelectionColor(const QColor &c); - - QColor selectedTextColor() const; - void setSelectedTextColor(const QColor &c); - - HAlignment hAlign() const; - void setHAlign(HAlignment align); - - VAlignment vAlign() const; - void setVAlign(VAlignment align); - - bool wrap() const; - void setWrap(bool w); - - bool isCursorVisible() const; - void setCursorVisible(bool on); - - int cursorPosition() const; - void setCursorPosition(int pos); - - QmlComponent* cursorDelegate() const; - void setCursorDelegate(QmlComponent*); - - int selectionStart() const; - void setSelectionStart(int); - - int selectionEnd() const; - void setSelectionEnd(int); - - QString selectedText() const; - - bool focusOnPress() const; - void setFocusOnPress(bool on); - - bool persistentSelection() const; - void setPersistentSelection(bool on); - - qreal textMargin() const; - void setTextMargin(qreal margin); - - virtual void componentComplete(); - - /* FROM EDIT */ - void setReadOnly(bool); - bool isReadOnly() const; - - void setTextInteractionFlags(Qt::TextInteractionFlags flags); - Qt::TextInteractionFlags textInteractionFlags() const; - - QTextCursor cursorForPosition(const QPoint &pos) const; - QRect cursorRect(const QTextCursor &cursor) const; - QRect cursorRect() const; - - void setTextCursor(const QTextCursor &cursor); - QTextCursor textCursor() const; - - void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor); - - QVariant inputMethodQuery(Qt::InputMethodQuery property) const; - -Q_SIGNALS: - void textChanged(const QString &); - void cursorPositionChanged(); - void selectionStartChanged(); - void selectionEndChanged(); - void selectionChanged(); - -public Q_SLOTS: - void selectAll(); - -private Q_SLOTS: - void updateImgCache(const QRectF &rect); - void q_textChanged(); - void updateSelectionMarkers(); - void moveCursorDelegate(); - void loadCursorDelegate(); - -private: - void updateSize(); - -protected: - QmlGraphicsTextEdit(QmlGraphicsTextEditPrivate &dd, QmlGraphicsItem *parent); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - - bool event(QEvent *); - void keyPressEvent(QKeyEvent *); - void keyReleaseEvent(QKeyEvent *); - - void focusChanged(bool); - - // mouse filter? - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - - void inputMethodEvent(QInputMethodEvent *e); - - void drawContents(QPainter *, const QRect &); -private: - Q_DISABLE_COPY(QmlGraphicsTextEdit) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsTextEdit) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsTextEdit) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qfxtextedit_p.h b/src/declarative/fx/qfxtextedit_p.h deleted file mode 100644 index ca65109..0000000 --- a/src/declarative/fx/qfxtextedit_p.h +++ /dev/null @@ -1,113 +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 QFXTEXTEDIT_P_H -#define QFXTEXTEDIT_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 "qfxitem.h" -#include "qfxpainteditem_p.h" -#include "qml.h" - - -QT_BEGIN_NAMESPACE -class QTextLayout; -class QTextDocument; -class QTextControl; -class QmlGraphicsTextEditPrivate : public QmlGraphicsPaintedItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsTextEdit) - -public: - QmlGraphicsTextEditPrivate() - : color("black"), imgDirty(true), hAlign(QmlGraphicsTextEdit::AlignLeft), vAlign(QmlGraphicsTextEdit::AlignTop), - dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(false), - persistentSelection(true), textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0), - cursorComponent(0), cursor(0), format(QmlGraphicsTextEdit::AutoText), document(0) - { - } - - void init(); - - void updateDefaultTextOption(); - void relayoutDocument(); - void updateSelection(); - - QString text; - QFont font; - QColor color; - QColor selectionColor; - QColor selectedTextColor; - QString style; - QColor styleColor; - bool imgDirty; - QPixmap imgCache; - QPixmap imgStyleCache; - QmlGraphicsTextEdit::HAlignment hAlign; - QmlGraphicsTextEdit::VAlignment vAlign; - bool dirty; - bool wrap; - bool richText; - bool cursorVisible; - bool focusOnPress; - bool persistentSelection; - qreal textMargin; - int lastSelectionStart; - int lastSelectionEnd; - QmlComponent* cursorComponent; - QmlGraphicsItem* cursor; - QmlGraphicsTextEdit::TextFormat format; - QTextDocument *document; - QTextControl *control; -}; - -QT_END_NAMESPACE -#endif diff --git a/src/declarative/fx/qfxtextinput.cpp b/src/declarative/fx/qfxtextinput.cpp deleted file mode 100644 index 930768d..0000000 --- a/src/declarative/fx/qfxtextinput.cpp +++ /dev/null @@ -1,777 +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 "qfxtextinput.h" -#include "qfxtextinput_p.h" -#include "qmlinfo.h" -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,TextInput,QmlGraphicsTextInput); -QML_DEFINE_NOCREATE_TYPE(QValidator); -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,QIntValidator,QIntValidator); - -/*! - \qmlclass TextInput - The TextInput item allows you to add an editable line of text to a scene. - - TextInput can only display a single line of text, and can only display - plain text. However it can provide addition input constraints on the text. - - Input constraints include setting a QValidator, an input mask, or a - maximum input length. -*/ -QmlGraphicsTextInput::QmlGraphicsTextInput(QmlGraphicsItem* parent) - : QmlGraphicsPaintedItem(*(new QmlGraphicsTextInputPrivate), parent) -{ - Q_D(QmlGraphicsTextInput); - d->init(); -} - -/* - \internal -*/ -QmlGraphicsTextInput::QmlGraphicsTextInput(QmlGraphicsTextInputPrivate &dd, QmlGraphicsItem* parent) - : QmlGraphicsPaintedItem(dd, parent) -{ - Q_D(QmlGraphicsTextInput); - d->init(); -} - -QmlGraphicsTextInput::~QmlGraphicsTextInput() -{ -} - -/*! - \qmlproperty string TextInput::text - - The text in the TextInput. -*/ - -QString QmlGraphicsTextInput::text() const -{ - Q_D(const QmlGraphicsTextInput); - return d->control->text(); -} - -void QmlGraphicsTextInput::setText(const QString &s) -{ - Q_D(QmlGraphicsTextInput); - if(s == text()) - return; - d->control->setText(s); - //emit textChanged(); -} - -/*! - \qmlproperty string TextInput::font.family - \qmlproperty bool TextInput::font.bold - \qmlproperty bool TextInput::font.italic - \qmlproperty bool TextInput::font.underline - \qmlproperty real TextInput::font.pointSize - \qmlproperty int TextInput::font.pixelSize - - Set the TextInput's font attributes. -*/ -QFont QmlGraphicsTextInput::font() const -{ - Q_D(const QmlGraphicsTextInput); - return d->font; -} - -void QmlGraphicsTextInput::setFont(const QFont &font) -{ - Q_D(QmlGraphicsTextInput); - d->font = font; - - d->control->setFont(d->font); - if(d->cursorItem){ - d->cursorItem->setHeight(QFontMetrics(d->font).height()); - moveCursor(); - } - updateSize(); -} - -/*! - \qmlproperty color TextInput::color - - The text color. -*/ -QColor QmlGraphicsTextInput::color() const -{ - Q_D(const QmlGraphicsTextInput); - return d->color; -} - -void QmlGraphicsTextInput::setColor(const QColor &c) -{ - Q_D(QmlGraphicsTextInput); - d->color = c; -} - - -/*! - \qmlproperty color TextInput::selectionColor - - The text highlight color, used behind selections. -*/ -QColor QmlGraphicsTextInput::selectionColor() const -{ - Q_D(const QmlGraphicsTextInput); - return d->selectionColor; -} - -void QmlGraphicsTextInput::setSelectionColor(const QColor &color) -{ - Q_D(QmlGraphicsTextInput); - if (d->selectionColor == color) - return; - - d->selectionColor = color; - QPalette p = d->control->palette(); - p.setColor(QPalette::Highlight, d->selectionColor); - d->control->setPalette(p); -} - -/*! - \qmlproperty color TextInput::selectedTextColor - - The highlighted text color, used in selections. -*/ -QColor QmlGraphicsTextInput::selectedTextColor() const -{ - Q_D(const QmlGraphicsTextInput); - return d->selectedTextColor; -} - -void QmlGraphicsTextInput::setSelectedTextColor(const QColor &color) -{ - Q_D(QmlGraphicsTextInput); - if (d->selectedTextColor == color) - return; - - d->selectedTextColor = color; - QPalette p = d->control->palette(); - p.setColor(QPalette::HighlightedText, d->selectedTextColor); - d->control->setPalette(p); -} - -/*! - \qmlproperty enumeration TextInput::horizontalAlignment - - Sets the horizontal alignment of the text within the TextInput item's - width and height. By default, the text is left aligned. - - TextInput does not have vertical alignment, as the natural height is - exactly the height of the single line of text. If you set the height - manually to something larger, TextInput will always be top aligned - vertically. You can use anchors to align it however you want within - another item. - - The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and - \c AlignHCenter. -*/ -QmlGraphicsTextInput::HAlignment QmlGraphicsTextInput::hAlign() const -{ - Q_D(const QmlGraphicsTextInput); - return d->hAlign; -} - -void QmlGraphicsTextInput::setHAlign(HAlignment align) -{ - Q_D(QmlGraphicsTextInput); - d->hAlign = align; - //TODO: implement -} - -bool QmlGraphicsTextInput::isReadOnly() const -{ - Q_D(const QmlGraphicsTextInput); - return d->control->isReadOnly(); -} - -void QmlGraphicsTextInput::setReadOnly(bool ro) -{ - Q_D(QmlGraphicsTextInput); - d->control->setReadOnly(ro); -} - -int QmlGraphicsTextInput::maxLength() const -{ - Q_D(const QmlGraphicsTextInput); - return d->control->maxLength(); -} - -void QmlGraphicsTextInput::setMaxLength(int ml) -{ - Q_D(QmlGraphicsTextInput); - d->control->setMaxLength(ml); -} - -/*! - \qmlproperty bool TextInput::cursorVisible - If true the text edit shows a cursor. - - This property is set and unset when the line edit gets focus, but it can also - be set directly (useful, for example, if a KeyProxy might forward keys to it). -*/ -bool QmlGraphicsTextInput::isCursorVisible() const -{ - Q_D(const QmlGraphicsTextInput); - return d->cursorVisible; -} - -void QmlGraphicsTextInput::setCursorVisible(bool on) -{ - Q_D(QmlGraphicsTextInput); - if (d->cursorVisible == on) - return; - d->cursorVisible = on; - d->control->setCursorBlinkPeriod(on?QApplication::cursorFlashTime():0); - //d->control should emit the cursor update regions -} - -/*! - \qmlproperty int TextInput::cursorPosition - The position of the cursor in the TextInput. -*/ -int QmlGraphicsTextInput::cursorPosition() const -{ - Q_D(const QmlGraphicsTextInput); - return d->control->cursor(); -} -void QmlGraphicsTextInput::setCursorPosition(int cp) -{ - Q_D(QmlGraphicsTextInput); - d->control->moveCursor(cp); -} - -/*! - \internal - - Returns a Rect which encompasses the cursor, but which may be larger than is - required. Ignores custom cursor delegates. -*/ -QRect QmlGraphicsTextInput::cursorRect() const -{ - Q_D(const QmlGraphicsTextInput); - return d->control->cursorRect(); -} - -/*! - \qmlproperty int TextInput::selectionStart - - The cursor position before the first character in the current selection. - Setting this and selectionEnd allows you to specify a selection in the - text edit. - - Note that if selectionStart == selectionEnd then there is no current - selection. If you attempt to set selectionStart to a value outside of - the current text, selectionStart will not be changed. - - \sa selectionEnd, cursorPosition, selectedText -*/ -int QmlGraphicsTextInput::selectionStart() const -{ - Q_D(const QmlGraphicsTextInput); - return d->lastSelectionStart; -} - -void QmlGraphicsTextInput::setSelectionStart(int s) -{ - Q_D(QmlGraphicsTextInput); - if(d->lastSelectionStart == s || s < 0 || s > text().length()) - return; - d->lastSelectionStart = s; - d->control->setSelection(s, d->lastSelectionEnd - s); -} - -/*! - \qmlproperty int TextInput::selectionEnd - - The cursor position after the last character in the current selection. - Setting this and selectionStart allows you to specify a selection in the - text edit. - - Note that if selectionStart == selectionEnd then there is no current - selection. If you attempt to set selectionEnd to a value outside of - the current text, selectionEnd will not be changed. - - \sa selectionStart, cursorPosition, selectedText -*/ -int QmlGraphicsTextInput::selectionEnd() const -{ - Q_D(const QmlGraphicsTextInput); - return d->lastSelectionEnd; -} - -void QmlGraphicsTextInput::setSelectionEnd(int s) -{ - Q_D(QmlGraphicsTextInput); - if(d->lastSelectionEnd == s || s < 0 || s > text().length()) - return; - d->lastSelectionEnd = s; - d->control->setSelection(d->lastSelectionStart, s - d->lastSelectionStart); -} - -/*! - \qmlproperty string TextInput::selectedText - - This read-only property provides the text currently selected in the - text input. - - It is equivalent to the following snippet, but is faster and easier - to use. - - \qml - myTextInput.text.toString().substring(myTextInput.selectionStart, - myTextInput.selectionEnd); - \endqml -*/ -QString QmlGraphicsTextInput::selectedText() const -{ - Q_D(const QmlGraphicsTextInput); - return d->control->selectedText(); -} - -/*! - \qmlproperty bool TextInput::focusOnPress - - Whether the TextInput should gain focus on a mouse press. By default this is - set to true. -*/ -bool QmlGraphicsTextInput::focusOnPress() const -{ - Q_D(const QmlGraphicsTextInput); - return d->focusOnPress; -} - -void QmlGraphicsTextInput::setFocusOnPress(bool b) -{ - Q_D(QmlGraphicsTextInput); - d->focusOnPress = b; -} - -/*! - \qmlproperty QValidator* TextInput::validator - - Allows you to set a QValidator on the TextInput. When a validator is set - the TextInput will only accept input which leaves the text property in - an acceptable or intermediate state. The accepted signal will only be sent - if the text is in an acceptable state when enter is pressed. - - \sa acceptableInput, inputMask -*/ -QValidator* QmlGraphicsTextInput::validator() const -{ - Q_D(const QmlGraphicsTextInput); - //###const cast isn't good, but needed for property system? - return const_cast(d->control->validator()); -} - -void QmlGraphicsTextInput::setValidator(QValidator* v) -{ - Q_D(QmlGraphicsTextInput); - d->control->setValidator(v); - if(!d->control->hasAcceptableInput()){ - d->oldValidity = false; - emit acceptableInputChanged(); - } -} - -/*! - \qmlproperty string TextInput::inputMask - - Allows you to set an input mask on the TextInput, restricting the allowable - text inputs. See QLineEdit::inputMask for further details, as the exact - same mask strings are used by TextInput. - - \sa acceptableInput, validator -*/ -QString QmlGraphicsTextInput::inputMask() const -{ - Q_D(const QmlGraphicsTextInput); - return d->control->inputMask(); -} - -void QmlGraphicsTextInput::setInputMask(const QString &im) -{ - Q_D(QmlGraphicsTextInput); - d->control->setInputMask(im); -} - -/*! - \qmlproperty bool TextInput::acceptableInput - - This property is always true unless a validator or input mask has been set. - If a validator or input mask has been set, this property will only be true - if the current text is acceptable to the validator or input mask as a final - string (not as an intermediate string). -*/ -bool QmlGraphicsTextInput::hasAcceptableInput() const -{ - Q_D(const QmlGraphicsTextInput); - return d->control->hasAcceptableInput(); -} - -/*! - \qmlproperty TextInput.EchoMode TextInput::echoMode - - Specifies how the text should be displayed in the TextInput. - The default is Normal, which displays the text as it is. Other values - are Password, which displays asterixes instead of characters, NoEcho, - which displays nothing, and PasswordEchoOnEdit, which displays all but the - current character as asterixes. - -*/ -QmlGraphicsTextInput::EchoMode QmlGraphicsTextInput::echoMode() const -{ - Q_D(const QmlGraphicsTextInput); - return (QmlGraphicsTextInput::EchoMode)d->control->echoMode(); -} - -void QmlGraphicsTextInput::setEchoMode(QmlGraphicsTextInput::EchoMode echo) -{ - Q_D(QmlGraphicsTextInput); - d->control->setEchoMode((uint)echo); -} - -/*! - \qmlproperty Component TextInput::cursorDelegate - The delegate for the cursor in the TextInput. - - If you set a cursorDelegate for a TextInput, this delegate will be used for - drawing the cursor instead of the standard cursor. An instance of the - delegate will be created and managed by the TextInput when a cursor is - needed, and the x property of delegate instance will be set so as - to be one pixel before the top left of the current character. - - Note that the root item of the delegate component must be a QmlGraphicsItem or - QmlGraphicsItem derived item. -*/ -QmlComponent* QmlGraphicsTextInput::cursorDelegate() const -{ - Q_D(const QmlGraphicsTextInput); - return d->cursorComponent; -} - -void QmlGraphicsTextInput::setCursorDelegate(QmlComponent* c) -{ - Q_D(QmlGraphicsTextInput); - d->cursorComponent = c; - if(!c){ - //note that the components are owned by something else - disconnect(d->control, SIGNAL(cursorPositionChanged(int, int)), - this, SLOT(moveCursor())); - delete d->cursorItem; - }else{ - d->startCreatingCursor(); - } -} - -void QmlGraphicsTextInputPrivate::startCreatingCursor() -{ - Q_Q(QmlGraphicsTextInput); - q->connect(control, SIGNAL(cursorPositionChanged(int, int)), - q, SLOT(moveCursor())); - if(cursorComponent->isReady()){ - q->createCursor(); - }else if(cursorComponent->isLoading()){ - q->connect(cursorComponent, SIGNAL(statusChanged(int)), - q, SLOT(createCursor())); - }else{//isError - qmlInfo(QmlGraphicsTextInput::tr("Could not load cursor delegate"), q); - qWarning() << cursorComponent->errors(); - } -} - -void QmlGraphicsTextInput::createCursor() -{ - Q_D(QmlGraphicsTextInput); - if(d->cursorComponent->isError()){ - qmlInfo(tr("Could not load cursor delegate"),this); - qWarning() << d->cursorComponent->errors(); - return; - } - - if(!d->cursorComponent->isReady()) - return; - - if(d->cursorItem) - delete d->cursorItem; - d->cursorItem = qobject_cast(d->cursorComponent->create()); - if(!d->cursorItem){ - qmlInfo(tr("Could not instantiate cursor delegate"),this); - //The failed instantiation should print its own error messages - return; - } - - d->cursorItem->setParentItem(this); - d->cursorItem->setX(d->control->cursorToX()); - d->cursorItem->setHeight(d->control->height()); -} - -void QmlGraphicsTextInput::moveCursor() -{ - Q_D(QmlGraphicsTextInput); - if(!d->cursorItem) - return; - d->cursorItem->setX(d->control->cursorToX() - d->hscroll); -} - -int QmlGraphicsTextInput::xToPos(int x) -{ - Q_D(const QmlGraphicsTextInput); - return d->control->xToPos(x - d->hscroll); -} - -void QmlGraphicsTextInput::focusChanged(bool hasFocus) -{ - Q_D(QmlGraphicsTextInput); - d->focused = hasFocus; - setCursorVisible(hasFocus); - QmlGraphicsItem::focusChanged(hasFocus); -} - -void QmlGraphicsTextInput::keyPressEvent(QKeyEvent* ev) -{ - Q_D(QmlGraphicsTextInput); - if((d->control->cursor() == 0 && ev->key() == Qt::Key_Left) - || (d->control->cursor() == d->control->text().length() - && ev->key() == Qt::Key_Right)){ - //ignore when moving off the end - ev->ignore(); - }else{ - d->control->processKeyEvent(ev); - } - if (!ev->isAccepted()) - QmlGraphicsPaintedItem::keyPressEvent(ev); -} - -void QmlGraphicsTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QmlGraphicsTextInput); - if(d->focusOnPress){ - setFocus(true); - setCursorVisible(true); - d->focused = true; - } - d->control->processEvent(event); -} - -bool QmlGraphicsTextInput::event(QEvent* ev) -{ - Q_D(QmlGraphicsTextInput); - //Anything we don't deal with ourselves, pass to the control - bool handled = false; - switch(ev->type()){ - case QEvent::KeyPress: - case QEvent::KeyRelease://###Should the control be doing anything with release? - case QEvent::GraphicsSceneMousePress: - break; - default: - handled = d->control->processEvent(ev); - } - if(!handled) - return QmlGraphicsPaintedItem::event(ev); - return true; -} - -void QmlGraphicsTextInput::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - if (newGeometry.width() != oldGeometry.width()) - updateSize(); - QmlGraphicsPaintedItem::geometryChanged(newGeometry, oldGeometry); -} - -void QmlGraphicsTextInput::drawContents(QPainter *p, const QRect &r) -{ - Q_D(QmlGraphicsTextInput); - p->setRenderHint(QPainter::TextAntialiasing, true); - p->save(); - p->setPen(QPen(d->color)); - int flags = QLineControl::DrawText; - if(!isReadOnly() && d->cursorVisible && !d->cursorItem) - flags |= QLineControl::DrawCursor; - if (d->control->hasSelectedText()){ - flags |= QLineControl::DrawSelections; - } - - QPoint offset = QPoint(0,0); - QRect clipRect = r; - d->control->draw(p, offset, clipRect, flags); - - p->restore(); -} - -void QmlGraphicsTextInput::selectAll() -{ - Q_D(QmlGraphicsTextInput); - d->control->setSelection(0, d->control->text().length()); -} - - -/*! - \qmlproperty bool TextInput::smooth - - Set this property if you want the text to be smoothly scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If - the item is displayed at its natural size, this property has no visual or - performance effect. - - \note Generally scaling artifacts are only visible if the item is stationary on - the screen. A common pattern when animating an item is to disable smooth - filtering at the beginning of the animation and reenable it at the conclusion. -*/ - -void QmlGraphicsTextInputPrivate::init() -{ - Q_Q(QmlGraphicsTextInput); - control->setCursorWidth(1); - control->setPasswordCharacter(QLatin1Char('*')); - control->setLayoutDirection(Qt::LeftToRight); - q->setSmoothTransform(smooth); - q->setAcceptedMouseButtons(Qt::LeftButton); - q->setFlag(QGraphicsItem::ItemHasNoContents, false); - q->setFlag(QGraphicsItem::ItemAcceptsInputMethod); - q->connect(control, SIGNAL(cursorPositionChanged(int,int)), - q, SLOT(cursorPosChanged())); - q->connect(control, SIGNAL(selectionChanged()), - q, SLOT(selectionChanged())); - q->connect(control, SIGNAL(textChanged(const QString &)), - q, SLOT(q_textChanged())); - q->connect(control, SIGNAL(accepted()), - q, SIGNAL(accepted())); - q->connect(control, SIGNAL(updateNeeded(QRect)), - q, SLOT(updateRect(QRect))); - q->connect(control, SIGNAL(cursorPositionChanged(int,int)), - q, SLOT(updateRect()));//TODO: Only update rect between pos's - q->connect(control, SIGNAL(selectionChanged()), - q, SLOT(updateRect()));//TODO: Only update rect in selection - //Note that above TODOs probably aren't that big a savings - q->updateSize(); - oldValidity = control->hasAcceptableInput(); - lastSelectionStart = 0; - lastSelectionEnd = 0; -} - -void QmlGraphicsTextInput::cursorPosChanged() -{ - Q_D(QmlGraphicsTextInput); - emit cursorPositionChanged(); - - if(!d->control->hasSelectedText()){ - if(d->lastSelectionStart != d->control->cursor()){ - d->lastSelectionStart = d->control->cursor(); - emit selectionStartChanged(); - } - if(d->lastSelectionEnd != d->control->cursor()){ - d->lastSelectionEnd = d->control->cursor(); - emit selectionEndChanged(); - } - } -} - -void QmlGraphicsTextInput::selectionChanged() -{ - Q_D(QmlGraphicsTextInput); - emit selectedTextChanged(); - - if(d->lastSelectionStart != d->control->selectionStart()){ - d->lastSelectionStart = d->control->selectionStart(); - if(d->lastSelectionStart == -1) - d->lastSelectionStart = d->control->cursor(); - emit selectionStartChanged(); - } - if(d->lastSelectionEnd != d->control->selectionEnd()){ - d->lastSelectionEnd = d->control->selectionEnd(); - if(d->lastSelectionEnd == -1) - d->lastSelectionEnd = d->control->cursor(); - emit selectionEndChanged(); - } -} - -void QmlGraphicsTextInput::q_textChanged() -{ - Q_D(QmlGraphicsTextInput); - updateSize(); - emit textChanged(); - if(hasAcceptableInput() != d->oldValidity){ - d->oldValidity = hasAcceptableInput(); - emit acceptableInputChanged(); - } -} - -void QmlGraphicsTextInput::updateRect(const QRect &r) -{ - if(r == QRect()) - clearCache(); - else - dirtyCache(r); - update(); -} - -void QmlGraphicsTextInput::updateSize(bool needsRedraw) -{ - Q_D(QmlGraphicsTextInput); - int w = width(); - int h = height(); - setImplicitHeight(d->control->height()); - int cursorWidth = d->control->cursorWidth(); - if(d->cursorItem) - cursorWidth = d->cursorItem->width(); - //### Is QFontMetrics too slow? - QFontMetricsF fm(d->font); - setImplicitWidth(fm.width(d->control->displayText())+cursorWidth); - setContentsSize(QSize(width(), height()));//Repaints if changed - if(w==width() && h==height() && needsRedraw){ - clearCache(); - update(); - } -} - -QT_END_NAMESPACE - diff --git a/src/declarative/fx/qfxtextinput.h b/src/declarative/fx/qfxtextinput.h deleted file mode 100644 index ada32f9..0000000 --- a/src/declarative/fx/qfxtextinput.h +++ /dev/null @@ -1,209 +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 QFXTEXTINPUT_H -#define QFXTEXTINPUT_H - -#include "qfxtext.h" -#include "qfxpainteditem.h" -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsTextInputPrivate; -class QValidator; -class Q_DECLARATIVE_EXPORT QmlGraphicsTextInput : public QmlGraphicsPaintedItem -{ - Q_OBJECT - Q_ENUMS(HAlignment) - Q_ENUMS(EchoMode) - - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) - - Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) - Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) - Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) - Q_PROPERTY(QmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate) - Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) - Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) - Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged) - - Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength) - Q_PROPERTY(QValidator* validator READ validator WRITE setValidator) - Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask) - Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged) - Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode) - Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) - -public: - QmlGraphicsTextInput(QmlGraphicsItem* parent=0); - ~QmlGraphicsTextInput(); - - enum EchoMode {//To match QLineEdit::EchoMode - Normal, - NoEcho, - Password, - PasswordEchoOnEdit - }; - - enum HAlignment { - AlignLeft = Qt::AlignLeft, - AlignRight = Qt::AlignRight, - AlignHCenter = Qt::AlignHCenter - }; - - //### Should we have this function, x based properties, - //### or copy TextEdit with x instead of QTextCursor? - Q_INVOKABLE int xToPos(int x); - - QString text() const; - void setText(const QString &); - - QFont font() const; - void setFont(const QFont &font); - - QColor color() const; - void setColor(const QColor &c); - - QColor selectionColor() const; - void setSelectionColor(const QColor &c); - - QColor selectedTextColor() const; - void setSelectedTextColor(const QColor &c); - - HAlignment hAlign() const; - void setHAlign(HAlignment align); - - bool isReadOnly() const; - void setReadOnly(bool); - - bool isCursorVisible() const; - void setCursorVisible(bool on); - - int cursorPosition() const; - void setCursorPosition(int cp); - - QRect cursorRect() const; - - int selectionStart() const; - void setSelectionStart(int); - - int selectionEnd() const; - void setSelectionEnd(int); - - QString selectedText() const; - - int maxLength() const; - void setMaxLength(int ml); - - QValidator * validator() const; - void setValidator(QValidator* v); - - QString inputMask() const; - void setInputMask(const QString &im); - - EchoMode echoMode() const; - void setEchoMode(EchoMode echo); - - QmlComponent* cursorDelegate() const; - void setCursorDelegate(QmlComponent*); - - bool focusOnPress() const; - void setFocusOnPress(bool); - - bool hasAcceptableInput() const; - - void drawContents(QPainter *p,const QRect &r); -Q_SIGNALS: - void textChanged(); - void cursorPositionChanged(); - void selectionStartChanged(); - void selectionEndChanged(); - void selectedTextChanged(); - void accepted(); - void acceptableInputChanged(); - -protected: - QmlGraphicsTextInput(QmlGraphicsTextInputPrivate &dd, QmlGraphicsItem *parent); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void keyPressEvent(QKeyEvent* ev); - bool event(QEvent *e); - - void focusChanged(bool hasFocus); - -public Q_SLOTS: - void selectAll(); - -private Q_SLOTS: - void updateSize(bool needsRedraw = true); - void q_textChanged(); - void selectionChanged(); - void createCursor(); - void moveCursor(); - void cursorPosChanged(); - void updateRect(const QRect &r = QRect()); - -private: - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsTextInput) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsTextInput) -QML_DECLARE_TYPE(QValidator) -QML_DECLARE_TYPE(QIntValidator) - -QT_END_HEADER - -#endif // QFXTEXTINPUT_H diff --git a/src/declarative/fx/qfxtextinput_p.h b/src/declarative/fx/qfxtextinput_p.h deleted file mode 100644 index be8c946..0000000 --- a/src/declarative/fx/qfxtextinput_p.h +++ /dev/null @@ -1,109 +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 QFXTEXTINPUT_P_H -#define QFXTEXTINPUT_P_H - -#include "qfxtextinput.h" -#include "qml.h" -#include "qfxpainteditem_p.h" -#include "private/qlinecontrol_p.h" -#include -// -// 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. - -QT_BEGIN_NAMESPACE - -class QmlGraphicsTextInputPrivate : public QmlGraphicsPaintedItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsTextInput) -public: - QmlGraphicsTextInputPrivate() : control(new QLineControl(QString())), - color((QRgb)0), style(QmlGraphicsText::Normal), - styleColor((QRgb)0), hAlign(QmlGraphicsTextInput::AlignLeft), - hscroll(0), oldScroll(0), focused(false), focusOnPress(true), - cursorVisible(false) - { - } - - ~QmlGraphicsTextInputPrivate() - { - delete control; - } - - void init(); - void startCreatingCursor(); - - QLineControl* control; - - QFont font; - QColor color; - QColor selectionColor; - QColor selectedTextColor; - QmlGraphicsText::TextStyle style; - QColor styleColor; - QmlGraphicsTextInput::HAlignment hAlign; - QPointer cursorComponent; - QPointer cursorItem; - - int lastSelectionStart; - int lastSelectionEnd; - int oldHeight; - int oldWidth; - bool oldValidity; - int hscroll; - int oldScroll; - bool focused; - bool focusOnPress; - bool cursorVisible; -}; - -QT_END_NAMESPACE - -#endif - diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp deleted file mode 100644 index 681e360..0000000 --- a/src/declarative/fx/qfxvisualitemmodel.cpp +++ /dev/null @@ -1,1032 +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 "qlistmodelinterface.h" -#include "qfxitem.h" -#include -#include -#include "qmlpackage.h" -#include "qhash.h" -#include "qlist.h" -#include "private/qobject_p.h" -#include "private/qmetaobjectbuilder_p.h" -#include "qmlopenmetaobject.h" -#include "qmllistaccessor.h" -#include "qmlinfo.h" -#include "qfxvisualitemmodel.h" -#include "private/qguard_p.h" -#include - -QML_DECLARE_TYPE(QListModelInterface) - -QT_BEGIN_NAMESPACE - -class QmlGraphicsVisualItemModelAttached : public QObject -{ - Q_OBJECT - -public: - QmlGraphicsVisualItemModelAttached(QObject *parent) - : QObject(parent), m_index(0) {} - ~QmlGraphicsVisualItemModelAttached() { - attachedProperties.remove(parent()); - } - - Q_PROPERTY(int index READ index NOTIFY indexChanged) - int index() const { return m_index; } - void setIndex(int idx) { - if (m_index != idx) { - m_index = idx; - emit indexChanged(); - } - } - - static QmlGraphicsVisualItemModelAttached *properties(QObject *obj) { - QmlGraphicsVisualItemModelAttached *rv = attachedProperties.value(obj); - if (!rv) { - rv = new QmlGraphicsVisualItemModelAttached(obj); - attachedProperties.insert(obj, rv); - } - return rv; - } - -Q_SIGNALS: - void indexChanged(); - -public: - int m_index; - - static QHash attachedProperties; -}; - -QHash QmlGraphicsVisualItemModelAttached::attachedProperties; - - -class QmlGraphicsVisualItemModelPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsVisualItemModel) -public: - QmlGraphicsVisualItemModelPrivate() : QObjectPrivate(), children(this) {} - - struct ItemList : public QmlConcreteList - { - ItemList(QmlGraphicsVisualItemModelPrivate *m) : QmlConcreteList(), model(m) {} - - void append(QmlGraphicsItem *item); - - QmlGraphicsVisualItemModelPrivate *model; - }; - - void itemAppended() { - Q_Q(QmlGraphicsVisualItemModel); - QmlGraphicsVisualItemModelAttached *attached = QmlGraphicsVisualItemModelAttached::properties(children.last()); - attached->setIndex(children.count()-1); - emit q->itemsInserted(children.count()-1, 1); - emit q->countChanged(); - } - - void emitChildrenChanged() { - Q_Q(QmlGraphicsVisualItemModel); - emit q->childrenChanged(); - } - ItemList children; -}; - - -/*! - \qmlclass VisualItemModel QmlGraphicsVisualItemModel - \brief The VisualItemModel allows items to be provided to a view. - - The children of the VisualItemModel are provided in a model which - can be used in a view. Note that no delegate should be - provided to a view since the VisualItemModel contains the - visual delegate (items). - - An item can determine its index within the - model via the VisualItemModel.index attached property. - - The example below places three colored rectangles in a ListView. - \code - Item { - VisualItemModel { - id: itemModel - Rectangle { height: 30; width: 80; color: "red" } - Rectangle { height: 30; width: 80; color: "green" } - Rectangle { height: 30; width: 80; color: "blue" } - } - - ListView { - anchors.fill: parent - model: itemModel - } - } - \endcode -*/ -QmlGraphicsVisualItemModel::QmlGraphicsVisualItemModel() - : QmlGraphicsVisualModel(*(new QmlGraphicsVisualItemModelPrivate)) -{ -} - -QmlList *QmlGraphicsVisualItemModel::children() -{ - Q_D(QmlGraphicsVisualItemModel); - return &(d->children); -} - -/*! - \qmlproperty int VisualItemModel::count - - The number of items in the model. This property is readonly. -*/ -int QmlGraphicsVisualItemModel::count() const -{ - Q_D(const QmlGraphicsVisualItemModel); - return d->children.count(); -} - -bool QmlGraphicsVisualItemModel::isValid() const -{ - return true; -} - -QmlGraphicsItem *QmlGraphicsVisualItemModel::item(int index, bool) -{ - Q_D(QmlGraphicsVisualItemModel); - return d->children.at(index); -} - -QmlGraphicsVisualModel::ReleaseFlags QmlGraphicsVisualItemModel::release(QmlGraphicsItem *) -{ - // Nothing to do - return 0; -} - -void QmlGraphicsVisualItemModel::completeItem() -{ - // Nothing to do -} - -QVariant QmlGraphicsVisualItemModel::evaluate(int index, const QString &expression, QObject *objectContext) -{ - Q_D(QmlGraphicsVisualItemModel); - QmlContext *ccontext = qmlContext(this); - QmlContext *ctxt = new QmlContext(ccontext); - ctxt->addDefaultObject(d->children.at(index)); - QmlExpression e(ctxt, expression, objectContext); - e.setTrackChange(false); - QVariant value = e.value(); - delete ctxt; - return value; -} - -int QmlGraphicsVisualItemModel::indexOf(QmlGraphicsItem *item, QObject *) const -{ - Q_D(const QmlGraphicsVisualItemModel); - return d->children.indexOf(item); -} - -void QmlGraphicsVisualItemModelPrivate::ItemList::append(QmlGraphicsItem *item) -{ - QmlConcreteList::append(item); - item->QObject::setParent(model->q_ptr); - model->itemAppended(); - - model->emitChildrenChanged(); -} - -QmlGraphicsVisualItemModelAttached *QmlGraphicsVisualItemModel::qmlAttachedProperties(QObject *obj) -{ - return QmlGraphicsVisualItemModelAttached::properties(obj); -} - - -class QmlGraphicsVisualDataModelParts; -class QmlGraphicsVisualDataModelData; -class QmlGraphicsVisualDataModelPrivate : public QObjectPrivate -{ -public: - QmlGraphicsVisualDataModelPrivate(QmlContext *); - - static QmlGraphicsVisualDataModelPrivate *get(QmlGraphicsVisualDataModel *m) { - return static_cast(QObjectPrivate::get(m)); - } - - QGuard m_listModelInterface; - QGuard m_abstractItemModel; - QGuard m_visualItemModel; - QString m_part; - - QmlComponent *m_delegate; - QmlContext *m_context; - QList m_roles; - QHash m_roleNames; - void ensureRoles() { - if (m_roleNames.isEmpty()) { - if (m_listModelInterface) { - m_roles = m_listModelInterface->roles(); - for (int ii = 0; ii < m_roles.count(); ++ii) - m_roleNames.insert(m_listModelInterface->toString(m_roles.at(ii)), m_roles.at(ii)); - if (m_roles.count() == 1) - m_roleNames.insert(QLatin1String("modelData"), m_roles.at(0)); - } else if (m_abstractItemModel) { - for (QHash::const_iterator it = m_abstractItemModel->roleNames().begin(); - it != m_abstractItemModel->roleNames().end(); ++it) { - m_roles.append(it.key()); - m_roleNames.insert(QString::fromUtf8(*it), it.key()); - } - if (m_roles.count() == 1) - m_roleNames.insert(QLatin1String("modelData"), m_roles.at(0)); - } else if (m_listAccessor) { - m_roleNames.insert(QLatin1String("modelData"), 0); - if (m_listAccessor->type() == QmlListAccessor::Instance) { - if (QObject *object = m_listAccessor->at(0).value()) { - int count = object->metaObject()->propertyCount(); - for (int ii = 1; ii < count; ++ii) { - const QMetaProperty &prop = object->metaObject()->property(ii); - m_roleNames.insert(QString::fromUtf8(prop.name()), 0); - } - } - } - } - } - } - - struct ObjectRef { - ObjectRef(QObject *object=0) : obj(object), ref(1) {} - QObject *obj; - int ref; - }; - class Cache : public QHash { - public: - QObject *getItem(int index) { - QObject *item = 0; - QHash::iterator it = find(index); - if (it != end()) { - (*it).ref++; - item = (*it).obj; - } - return item; - } - QObject *item(int index) { - QObject *item = 0; - QHash::const_iterator it = find(index); - if (it != end()) - item = (*it).obj; - return item; - } - void insertItem(int index, QObject *obj) { - insert(index, ObjectRef(obj)); - } - bool releaseItem(QObject *obj) { - QHash::iterator it = begin(); - for (; it != end(); ++it) { - ObjectRef &objRef = *it; - if (objRef.obj == obj) { - if (--objRef.ref == 0) { - erase(it); - return true; - } - break; - } - } - return false; - } - }; - - Cache m_cache; - QHash m_packaged; - - QmlGraphicsVisualDataModelParts *m_parts; - friend class QmlGraphicsVisualItemParts; - - QmlGraphicsVisualDataModelData *data(QObject *item); - - QVariant m_modelVariant; - QmlListAccessor *m_listAccessor; - - int modelCount() const { - if (m_visualItemModel) - return m_visualItemModel->count(); - if (m_listModelInterface) - return m_listModelInterface->count(); - if (m_abstractItemModel) - return m_abstractItemModel->rowCount(); - if (m_listAccessor) - return m_listAccessor->count(); - return 0; - } -}; - -class QmlGraphicsVisualDataModelDataMetaObject : public QmlOpenMetaObject -{ -public: - QmlGraphicsVisualDataModelDataMetaObject(QObject *parent) - : QmlOpenMetaObject(parent) {} - - virtual QVariant propertyCreated(int, QMetaPropertyBuilder &); - virtual int createProperty(const char *, const char *); - -private: - friend class QmlGraphicsVisualDataModelData; - QList roles; -}; - -class QmlGraphicsVisualDataModelData : public QObject -{ -Q_OBJECT -public: - QmlGraphicsVisualDataModelData(int index, QmlGraphicsVisualDataModel *model); - ~QmlGraphicsVisualDataModelData(); - - Q_PROPERTY(int index READ index NOTIFY indexChanged) - int index() const; - void setIndex(int index); - - int count() const; - int role(int) const; - void setValue(int, const QVariant &); - -Q_SIGNALS: - void indexChanged(); - -private: - friend class QmlGraphicsVisualDataModelDataMetaObject; - int m_index; - QGuard m_model; - QmlGraphicsVisualDataModelDataMetaObject *m_meta; -}; - -int QmlGraphicsVisualDataModelData::count() const -{ - return m_meta->count(); -} - -int QmlGraphicsVisualDataModelData::role(int id) const -{ - Q_ASSERT(id >= 0 && id < count()); - return m_meta->roles.at(id); -} - -void QmlGraphicsVisualDataModelData::setValue(int id, const QVariant &val) -{ - m_meta->setValue(id, val); -} - -int QmlGraphicsVisualDataModelDataMetaObject::createProperty(const char *name, const char *type) -{ - QmlGraphicsVisualDataModelData *data = - static_cast(object()); - - if (!data->m_model) - return -1; - - QmlGraphicsVisualDataModelPrivate *model = QmlGraphicsVisualDataModelPrivate::get(data->m_model); - - if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) { - model->ensureRoles(); - if (model->m_roleNames.contains(QString::fromUtf8(name))) { - return QmlOpenMetaObject::createProperty(name, type); - } else if (model->m_listAccessor->type() == QmlListAccessor::QmlList) { - QObject *object = model->m_listAccessor->at(data->m_index).value(); - if (object && object->property(name).isValid()) - return QmlOpenMetaObject::createProperty(name, type); - } - } else { - model->ensureRoles(); - QString sname = QString::fromUtf8(name); - if (model->m_roleNames.contains(sname)) - return QmlOpenMetaObject::createProperty(name, type); - } - return -1; -} - -QVariant -QmlGraphicsVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuilder &prop) -{ - prop.setWritable(false); - - QmlGraphicsVisualDataModelData *data = - static_cast(object()); - - Q_ASSERT(data->m_model); - QmlGraphicsVisualDataModelPrivate *model = QmlGraphicsVisualDataModelPrivate::get(data->m_model); - - QString name = QString::fromUtf8(prop.name()); - if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) { - if (name == QLatin1String("modelData")) { - if (model->m_listAccessor->type() == QmlListAccessor::Instance) { - QObject *object = model->m_listAccessor->at(0).value(); - return object->metaObject()->property(1).read(object); // the first property after objectName - } - return model->m_listAccessor->at(data->m_index); - } else { - // return any property of a single object instance. - QObject *object = model->m_listAccessor->at(data->m_index).value(); - return object->property(prop.name()); - } - } else if (model->m_listModelInterface) { - model->ensureRoles(); - QHash::const_iterator it = model->m_roleNames.find(name); - if (it != model->m_roleNames.end()) { - roles.append(*it); - QHash values = model->m_listModelInterface->data(data->m_index, QList() << *it); - if (values.isEmpty()) - return QVariant(); - else - return values.value(*it); - } else if (model->m_roles.count() == 1 && name == QLatin1String("modelData")) { - //for compatability with other lists, assign modelData if there is only a single role - QHash values = model->m_listModelInterface->data(data->m_index, QList() << model->m_roles.first()); - if (values.isEmpty()) - return QVariant(); - else - return *values.begin(); - } - } else if (model->m_abstractItemModel) { - model->ensureRoles(); - QHash::const_iterator it = model->m_roleNames.find(name); - if (it != model->m_roleNames.end()) { - roles.append(*it); - QModelIndex index = model->m_abstractItemModel->index(data->m_index, 0); - return model->m_abstractItemModel->data(index, *it); - } - } - Q_ASSERT(!"Can never be reached"); - return QVariant(); -} - -QmlGraphicsVisualDataModelData::QmlGraphicsVisualDataModelData(int index, - QmlGraphicsVisualDataModel *model) -: m_index(index), m_model(model), - m_meta(new QmlGraphicsVisualDataModelDataMetaObject(this)) -{ -} - -QmlGraphicsVisualDataModelData::~QmlGraphicsVisualDataModelData() -{ -} - -int QmlGraphicsVisualDataModelData::index() const -{ - return m_index; -} - -// This is internal only - it should not be set from qml -void QmlGraphicsVisualDataModelData::setIndex(int index) -{ - m_index = index; - emit indexChanged(); -} - -class QmlGraphicsVisualDataModelPartsMetaObject : public QmlOpenMetaObject -{ -public: - QmlGraphicsVisualDataModelPartsMetaObject(QObject *parent) - : QmlOpenMetaObject(parent) {} - - virtual QVariant propertyCreated(int, QMetaPropertyBuilder &); -}; - -class QmlGraphicsVisualDataModelParts : public QObject -{ -Q_OBJECT -public: - QmlGraphicsVisualDataModelParts(QmlGraphicsVisualDataModel *parent); - -private: - friend class QmlGraphicsVisualDataModelPartsMetaObject; - QmlGraphicsVisualDataModel *model; -}; - -QVariant -QmlGraphicsVisualDataModelPartsMetaObject::propertyCreated(int, QMetaPropertyBuilder &prop) -{ - prop.setWritable(false); - - QmlGraphicsVisualDataModel *m = new QmlGraphicsVisualDataModel; - m->setParent(object()); - m->setPart(QString::fromUtf8(prop.name())); - m->setModel(QVariant::fromValue(static_cast(object())->model)); - - QVariant var = QVariant::fromValue((QObject *)m); - return var; -} - -QmlGraphicsVisualDataModelParts::QmlGraphicsVisualDataModelParts(QmlGraphicsVisualDataModel *parent) -: QObject(parent), model(parent) -{ - new QmlGraphicsVisualDataModelPartsMetaObject(this); -} - -QmlGraphicsVisualDataModelPrivate::QmlGraphicsVisualDataModelPrivate(QmlContext *ctxt) -: m_listModelInterface(0), m_abstractItemModel(0), m_visualItemModel(0), m_delegate(0) -, m_context(ctxt), m_parts(0), m_listAccessor(0) -{ -} - -QmlGraphicsVisualDataModelData *QmlGraphicsVisualDataModelPrivate::data(QObject *item) -{ - QmlGraphicsVisualDataModelData *dataItem = - item->findChild(); - Q_ASSERT(dataItem); - return dataItem; -} - -QmlGraphicsVisualDataModel::QmlGraphicsVisualDataModel() -: QmlGraphicsVisualModel(*(new QmlGraphicsVisualDataModelPrivate(0))) -{ -} - -QmlGraphicsVisualDataModel::QmlGraphicsVisualDataModel(QmlContext *ctxt) -: QmlGraphicsVisualModel(*(new QmlGraphicsVisualDataModelPrivate(ctxt))) -{ -} - -QmlGraphicsVisualDataModel::~QmlGraphicsVisualDataModel() -{ - Q_D(QmlGraphicsVisualDataModel); - if (d->m_listAccessor) - delete d->m_listAccessor; -} - -QVariant QmlGraphicsVisualDataModel::model() const -{ - Q_D(const QmlGraphicsVisualDataModel); - return d->m_modelVariant; -} - -void QmlGraphicsVisualDataModel::setModel(const QVariant &model) -{ - Q_D(QmlGraphicsVisualDataModel); - delete d->m_listAccessor; - d->m_listAccessor = 0; - d->m_modelVariant = model; - if (d->m_listModelInterface) { - // Assume caller has released all items. - QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsChanged(int,int,QList)), - this, SLOT(_q_itemsChanged(int,int,QList))); - QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsInserted(int,int)), - this, SLOT(_q_itemsInserted(int,int))); - QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsRemoved(int,int)), - this, SLOT(_q_itemsRemoved(int,int))); - QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsMoved(int,int,int)), - this, SLOT(_q_itemsMoved(int,int,int))); - d->m_listModelInterface = 0; - } else if (d->m_abstractItemModel) { - QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsInserted(const QModelIndex &,int,int)), - this, SLOT(_q_rowsInserted(const QModelIndex &,int,int))); - QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsRemoved(const QModelIndex &,int,int)), - this, SLOT(_q_rowsRemoved(const QModelIndex &,int,int))); - QObject::disconnect(d->m_abstractItemModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), - this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); - } else if (d->m_visualItemModel) { - QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), - this, SIGNAL(itemsInserted(int,int))); - QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsRemoved(int,int)), - this, SIGNAL(itemsRemoved(int,int))); - QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsMoved(int,int,int)), - this, SIGNAL(itemsMoved(int,int,int))); - QObject::disconnect(d->m_visualItemModel, SIGNAL(createdPackage(int,QmlPackage*)), - this, SLOT(_q_createdPackage(int,QmlPackage*))); - QObject::disconnect(d->m_visualItemModel, SIGNAL(destroyingPackage(QmlPackage*)), - this, SLOT(_q_destroyingPackage(QmlPackage*))); - d->m_visualItemModel = 0; - } - - d->m_roles.clear(); - d->m_roleNames.clear(); - - QObject *object = qvariant_cast(model); - if (object && (d->m_listModelInterface = qobject_cast(object))) { - QObject::connect(d->m_listModelInterface, SIGNAL(itemsChanged(int,int,QList)), - this, SLOT(_q_itemsChanged(int,int,QList))); - QObject::connect(d->m_listModelInterface, SIGNAL(itemsInserted(int,int)), - this, SLOT(_q_itemsInserted(int,int))); - QObject::connect(d->m_listModelInterface, SIGNAL(itemsRemoved(int,int)), - this, SLOT(_q_itemsRemoved(int,int))); - QObject::connect(d->m_listModelInterface, SIGNAL(itemsMoved(int,int,int)), - this, SLOT(_q_itemsMoved(int,int,int))); - if (d->m_delegate && d->m_listModelInterface->count()) - emit itemsInserted(0, d->m_listModelInterface->count()); - return; - } else if (object && (d->m_abstractItemModel = qobject_cast(object))) { - QObject::connect(d->m_abstractItemModel, SIGNAL(rowsInserted(const QModelIndex &,int,int)), - this, SLOT(_q_rowsInserted(const QModelIndex &,int,int))); - QObject::connect(d->m_abstractItemModel, SIGNAL(rowsRemoved(const QModelIndex &,int,int)), - this, SLOT(_q_rowsRemoved(const QModelIndex &,int,int))); - QObject::connect(d->m_abstractItemModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), - this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); - return; - } - if ((d->m_visualItemModel = qvariant_cast(model))) { - QObject::connect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), - this, SIGNAL(itemsInserted(int,int))); - QObject::connect(d->m_visualItemModel, SIGNAL(itemsRemoved(int,int)), - this, SIGNAL(itemsRemoved(int,int))); - QObject::connect(d->m_visualItemModel, SIGNAL(itemsMoved(int,int,int)), - this, SIGNAL(itemsMoved(int,int,int))); - QObject::connect(d->m_visualItemModel, SIGNAL(createdPackage(int,QmlPackage*)), - this, SLOT(_q_createdPackage(int,QmlPackage*))); - QObject::connect(d->m_visualItemModel, SIGNAL(destroyingPackage(QmlPackage*)), - this, SLOT(_q_destroyingPackage(QmlPackage*))); - return; - } - d->m_listAccessor = new QmlListAccessor; - d->m_listAccessor->setList(model, d->m_context?d->m_context->engine():qmlEngine(this)); - if (d->m_delegate && d->modelCount()) { - emit itemsInserted(0, d->modelCount()); - emit countChanged(); - } -} - -QmlComponent *QmlGraphicsVisualDataModel::delegate() const -{ - Q_D(const QmlGraphicsVisualDataModel); - if (d->m_visualItemModel) - return d->m_visualItemModel->delegate(); - return d->m_delegate; -} - -void QmlGraphicsVisualDataModel::setDelegate(QmlComponent *delegate) -{ - Q_D(QmlGraphicsVisualDataModel); - d->m_delegate = delegate; - if (d->modelCount()) { - emit itemsInserted(0, d->modelCount()); - emit countChanged(); - } -} - -QString QmlGraphicsVisualDataModel::part() const -{ - Q_D(const QmlGraphicsVisualDataModel); - return d->m_part; -} - -void QmlGraphicsVisualDataModel::setPart(const QString &part) -{ - Q_D(QmlGraphicsVisualDataModel); - d->m_part = part; -} - -int QmlGraphicsVisualDataModel::count() const -{ - Q_D(const QmlGraphicsVisualDataModel); - return d->modelCount(); -} - -QmlGraphicsItem *QmlGraphicsVisualDataModel::item(int index, bool complete) -{ - Q_D(QmlGraphicsVisualDataModel); - if (d->m_visualItemModel) - return d->m_visualItemModel->item(index, d->m_part.toUtf8(), complete); - return item(index, QByteArray(), complete); -} - -/* - Returns ReleaseStatus flags. -*/ -QmlGraphicsVisualDataModel::ReleaseFlags QmlGraphicsVisualDataModel::release(QmlGraphicsItem *item) -{ - Q_D(QmlGraphicsVisualDataModel); - if (d->m_visualItemModel) - return d->m_visualItemModel->release(item); - - ReleaseFlags stat = 0; - QObject *obj = item; - bool inPackage = false; - - QHash::iterator it = d->m_packaged.find(item); - if (it != d->m_packaged.end()) { - QmlPackage *package = *it; - d->m_packaged.erase(it); - if (d->m_packaged.contains(item)) - stat |= Referenced; - inPackage = true; - obj = package; // fall through and delete - } - - if (d->m_cache.releaseItem(obj)) { - if (inPackage) - emit destroyingPackage(qobject_cast(obj)); - stat |= Destroyed; - obj->setParent(0); - obj->deleteLater(); - } else if (!inPackage) { - stat |= Referenced; - } - - return stat; -} - -QObject *QmlGraphicsVisualDataModel::parts() -{ - Q_D(QmlGraphicsVisualDataModel); - if (!d->m_parts) - d->m_parts = new QmlGraphicsVisualDataModelParts(this); - return d->m_parts; -} - -QmlGraphicsItem *QmlGraphicsVisualDataModel::item(int index, const QByteArray &viewId, bool complete) -{ - Q_D(QmlGraphicsVisualDataModel); - if (d->m_visualItemModel) - return d->m_visualItemModel->item(index, viewId, complete); - - if (d->modelCount() <= 0 || !d->m_delegate) - return 0; - - QObject *nobj = d->m_cache.getItem(index); - if (!nobj) { - QmlContext *ccontext = d->m_context; - if (!ccontext) ccontext = qmlContext(this); - QmlContext *ctxt = new QmlContext(ccontext); - QmlGraphicsVisualDataModelData *data = new QmlGraphicsVisualDataModelData(index, this); - ctxt->setContextProperty(QLatin1String("model"), data); - ctxt->addDefaultObject(data); - nobj = d->m_delegate->beginCreate(ctxt); - if (complete) - d->m_delegate->completeCreate(); - if (nobj) { - ctxt->setParent(nobj); - data->setParent(nobj); - d->m_cache.insertItem(index, nobj); - if (QmlPackage *package = qobject_cast(nobj)) - emit createdPackage(index, package); - } else { - delete data; - delete ctxt; - qWarning() << d->m_delegate->errors(); - } - } - QmlGraphicsItem *item = qobject_cast(nobj); - if (!item) { - QmlPackage *package = qobject_cast(nobj); - if (package) { - QObject *o = package->part(QString::fromUtf8(viewId)); - item = qobject_cast(o); - if (item) - d->m_packaged.insertMulti(item, package); - } - } - if (!item) { - d->m_cache.releaseItem(nobj); - qmlInfo(QmlGraphicsVisualDataModel::tr("Delegate component must be Item type."), d->m_delegate); - } - - return item; -} - -void QmlGraphicsVisualDataModel::completeItem() -{ - Q_D(QmlGraphicsVisualDataModel); - if (d->m_visualItemModel) { - d->m_visualItemModel->completeItem(); - return; - } - - d->m_delegate->completeCreate(); -} - -QVariant QmlGraphicsVisualDataModel::evaluate(int index, const QString &expression, QObject *objectContext) -{ - Q_D(QmlGraphicsVisualDataModel); - if (d->m_visualItemModel) - return d->m_visualItemModel->evaluate(index, expression, objectContext); - - if ((!d->m_listModelInterface && !d->m_abstractItemModel) || !d->m_delegate) - return QVariant(); - - QVariant value; - QObject *nobj = d->m_cache.item(index); - if (nobj) { - QmlGraphicsItem *item = qobject_cast(nobj); - if (item) { - QmlExpression e(qmlContext(item), expression, objectContext); - e.setTrackChange(false); - value = e.value(); - } - } else { - QmlContext *ccontext = d->m_context; - if (!ccontext) ccontext = qmlContext(this); - QmlContext *ctxt = new QmlContext(ccontext); - QmlGraphicsVisualDataModelData *data = new QmlGraphicsVisualDataModelData(index, this); - ctxt->addDefaultObject(data); - QmlExpression e(ctxt, expression, objectContext); - e.setTrackChange(false); - value = e.value(); - delete data; - delete ctxt; - } - - return value; -} - -int QmlGraphicsVisualDataModel::indexOf(QmlGraphicsItem *item, QObject *objectContext) const -{ - QmlExpression e(qmlContext(item), QLatin1String("index"), objectContext); - e.setTrackChange(false); - QVariant value = e.value(); - if (value.isValid()) - return value.toInt(); - return -1; -} - -void QmlGraphicsVisualDataModel::_q_itemsChanged(int index, int count, - const QList &roles) -{ - Q_D(QmlGraphicsVisualDataModel); - // XXX - highly inefficient - for (int ii = index; ii < index + count; ++ii) { - - if (QObject *item = d->m_cache.item(ii)) { - QmlGraphicsVisualDataModelData *data = d->data(item); - - for (int prop = 0; prop < data->count(); ++prop) { - - int role = data->role(prop); - if (roles.contains(role)) { - if (d->m_listModelInterface) { - data->setValue(prop, d->m_listModelInterface->data(ii, QList() << role).value(role)); - } else if (d->m_abstractItemModel) { - QModelIndex index = d->m_abstractItemModel->index(ii, 0); - data->setValue(prop, d->m_abstractItemModel->data(index, role)); - } - } - } - } - - } -} - -void QmlGraphicsVisualDataModel::_q_itemsInserted(int index, int count) -{ - Q_D(QmlGraphicsVisualDataModel); - // XXX - highly inefficient - QHash items; - for (QHash::Iterator iter = d->m_cache.begin(); - iter != d->m_cache.end(); ) { - - if (iter.key() >= index) { - QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; - int index = iter.key() + count; - iter = d->m_cache.erase(iter); - - items.insert(index, objRef); - - QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); - data->setIndex(index); - } else { - ++iter; - } - } - d->m_cache.unite(items); - - emit itemsInserted(index, count); - emit countChanged(); -} - -void QmlGraphicsVisualDataModel::_q_itemsRemoved(int index, int count) -{ - Q_D(QmlGraphicsVisualDataModel); - // XXX - highly inefficient - QHash items; - for (QHash::Iterator iter = d->m_cache.begin(); - iter != d->m_cache.end(); ) { - if (iter.key() >= index && iter.key() < index + count) { - QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; - iter = d->m_cache.erase(iter); - items.insertMulti(-1, objRef); //XXX perhaps better to maintain separately - QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); - data->setIndex(-1); - } else if (iter.key() >= index + count) { - QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; - int index = iter.key() - count; - iter = d->m_cache.erase(iter); - items.insert(index, objRef); - QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); - data->setIndex(index); - } else { - ++iter; - } - } - - d->m_cache.unite(items); - emit itemsRemoved(index, count); - emit countChanged(); -} - -void QmlGraphicsVisualDataModel::_q_itemsMoved(int from, int to, int count) -{ - Q_D(QmlGraphicsVisualDataModel); - // XXX - highly inefficient - QHash items; - for (QHash::Iterator iter = d->m_cache.begin(); - iter != d->m_cache.end(); ) { - - if (iter.key() >= from && iter.key() < from + count) { - QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; - int index = iter.key() - from + to; - iter = d->m_cache.erase(iter); - - items.insert(index, objRef); - - QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); - data->setIndex(index); - } else { - ++iter; - } - } - for (QHash::Iterator iter = d->m_cache.begin(); - iter != d->m_cache.end(); ) { - - if (iter.key() >= qMin(from,to) && iter.key() < qMax(from+count,to+count)) { - QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; - int index = iter.key() + from - to; - iter = d->m_cache.erase(iter); - - items.insert(index, objRef); - - QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); - data->setIndex(index); - } else { - ++iter; - } - } - d->m_cache.unite(items); - - emit itemsMoved(from, to, count); -} - -void QmlGraphicsVisualDataModel::_q_rowsInserted(const QModelIndex &, int begin, int end) -{ - _q_itemsInserted(begin, end - begin + 1); -} - -void QmlGraphicsVisualDataModel::_q_rowsRemoved(const QModelIndex &, int begin, int end) -{ - _q_itemsRemoved(begin, end - begin + 1); -} - -void QmlGraphicsVisualDataModel::_q_dataChanged(const QModelIndex &begin, const QModelIndex &end) -{ - Q_D(QmlGraphicsVisualDataModel); - _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); -} - -void QmlGraphicsVisualDataModel::_q_createdPackage(int index, QmlPackage *package) -{ - Q_D(QmlGraphicsVisualDataModel); - emit createdItem(index, qobject_cast(package->part(d->m_part))); -} - -void QmlGraphicsVisualDataModel::_q_destroyingPackage(QmlPackage *package) -{ - Q_D(QmlGraphicsVisualDataModel); - emit destroyingItem(qobject_cast(package->part(d->m_part))); -} - -QML_DEFINE_NOCREATE_TYPE(QmlGraphicsVisualModel); -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisualItemModel,QmlGraphicsVisualItemModel) -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisualDataModel,QmlGraphicsVisualDataModel) - -QT_END_NAMESPACE -#include "qfxvisualitemmodel.moc" diff --git a/src/declarative/fx/qfxvisualitemmodel.h b/src/declarative/fx/qfxvisualitemmodel.h deleted file mode 100644 index 7f7a13f..0000000 --- a/src/declarative/fx/qfxvisualitemmodel.h +++ /dev/null @@ -1,203 +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 QFXVISUALDATAMODEL_H -#define QFXVISUALDATAMODEL_H - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -/***************************************************************************** - ***************************************************************************** - XXX Experimental - ***************************************************************************** -*****************************************************************************/ - -class QmlGraphicsItem; -class QmlComponent; -class QmlPackage; -class QmlGraphicsVisualDataModelPrivate; - -class Q_DECLARATIVE_EXPORT QmlGraphicsVisualModel : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int count READ count NOTIFY countChanged) - -public: - QmlGraphicsVisualModel() {} - virtual ~QmlGraphicsVisualModel() {} - - enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 }; - Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag) - - virtual int count() const = 0; - virtual bool isValid() const = 0; - virtual QmlGraphicsItem *item(int index, bool complete=true) = 0; - virtual ReleaseFlags release(QmlGraphicsItem *item) = 0; - virtual void completeItem() = 0; - virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext) = 0; - - virtual int indexOf(QmlGraphicsItem *item, QObject *objectContext) const = 0; - -Q_SIGNALS: - void countChanged(); - void itemsInserted(int index, int count); - void itemsRemoved(int index, int count); - void itemsMoved(int from, int to, int count); - void createdItem(int index, QmlGraphicsItem *item); - void destroyingItem(QmlGraphicsItem *item); - -protected: - QmlGraphicsVisualModel(QObjectPrivate &dd, QObject *parent = 0) - : QObject(dd, parent) {} - -private: - Q_DISABLE_COPY(QmlGraphicsVisualModel) -}; - -class QmlGraphicsVisualItemModelAttached; -class QmlGraphicsVisualItemModelPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsVisualItemModel : public QmlGraphicsVisualModel -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlGraphicsVisualItemModel) - - Q_PROPERTY(QmlList* children READ children NOTIFY childrenChanged DESIGNABLE false) - Q_CLASSINFO("DefaultProperty", "children") - -public: - QmlGraphicsVisualItemModel(); - virtual ~QmlGraphicsVisualItemModel() {} - - virtual int count() const; - virtual bool isValid() const; - virtual QmlGraphicsItem *item(int index, bool complete=true); - virtual ReleaseFlags release(QmlGraphicsItem *item); - virtual void completeItem(); - virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext); - - virtual int indexOf(QmlGraphicsItem *item, QObject *objectContext) const; - - QmlList *children(); - - static QmlGraphicsVisualItemModelAttached *qmlAttachedProperties(QObject *obj); - -signals: - void childrenChanged(); - -private: - Q_DISABLE_COPY(QmlGraphicsVisualItemModel) -}; - - -class Q_DECLARATIVE_EXPORT QmlGraphicsVisualDataModel : public QmlGraphicsVisualModel -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlGraphicsVisualDataModel) - - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(QString part READ part WRITE setPart) - Q_PROPERTY(QObject *parts READ parts CONSTANT) - Q_CLASSINFO("DefaultProperty", "delegate") -public: - QmlGraphicsVisualDataModel(); - QmlGraphicsVisualDataModel(QmlContext *); - virtual ~QmlGraphicsVisualDataModel(); - - QVariant model() const; - void setModel(const QVariant &); - - QmlComponent *delegate() const; - void setDelegate(QmlComponent *); - - QString part() const; - void setPart(const QString &); - - int count() const; - bool isValid() const { return delegate() != 0; } - QmlGraphicsItem *item(int index, bool complete=true); - QmlGraphicsItem *item(int index, const QByteArray &, bool complete=true); - ReleaseFlags release(QmlGraphicsItem *item); - void completeItem(); - QVariant evaluate(int index, const QString &expression, QObject *objectContext); - - int indexOf(QmlGraphicsItem *item, QObject *objectContext) const; - - QObject *parts(); - -Q_SIGNALS: - void createdPackage(int index, QmlPackage *package); - void destroyingPackage(QmlPackage *package); - -private Q_SLOTS: - void _q_itemsChanged(int, int, const QList &); - void _q_itemsInserted(int index, int count); - void _q_itemsRemoved(int index, int count); - void _q_itemsMoved(int from, int to, int count); - void _q_rowsInserted(const QModelIndex &,int,int); - void _q_rowsRemoved(const QModelIndex &,int,int); - void _q_dataChanged(const QModelIndex&,const QModelIndex&); - void _q_createdPackage(int index, QmlPackage *package); - void _q_destroyingPackage(QmlPackage *package); - -private: - Q_DISABLE_COPY(QmlGraphicsVisualDataModel) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsVisualModel) -QML_DECLARE_TYPE(QmlGraphicsVisualItemModel) -QML_DECLARE_TYPEINFO(QmlGraphicsVisualItemModel, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QmlGraphicsVisualDataModel) - -QT_END_HEADER - -#endif // QFXVISUALDATAMODEL_H diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp deleted file mode 100644 index e6f0a1d..0000000 --- a/src/declarative/fx/qfxwebview.cpp +++ /dev/null @@ -1,1388 +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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "qml.h" -#include "qmlengine.h" -#include "qmlstate.h" -#include "qlistmodelinterface.h" - -#include "qfxwebview.h" -#include - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,WebView,QmlGraphicsWebView) -QML_DEFINE_NOCREATE_TYPE(QAction) - -static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system - -class QmlGraphicsWebSettings : public QObject { - Q_OBJECT - - Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily) - Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily WRITE setFixedFontFamily) - Q_PROPERTY(QString serifFontFamily READ serifFontFamily WRITE setSerifFontFamily) - Q_PROPERTY(QString sansSerifFontFamily READ sansSerifFontFamily WRITE setSansSerifFontFamily) - Q_PROPERTY(QString cursiveFontFamily READ cursiveFontFamily WRITE setCursiveFontFamily) - Q_PROPERTY(QString fantasyFontFamily READ fantasyFontFamily WRITE setFantasyFontFamily) - - Q_PROPERTY(int minimumFontSize READ minimumFontSize WRITE setMinimumFontSize) - Q_PROPERTY(int minimumLogicalFontSize READ minimumLogicalFontSize WRITE setMinimumLogicalFontSize) - Q_PROPERTY(int defaultFontSize READ defaultFontSize WRITE setDefaultFontSize) - Q_PROPERTY(int defaultFixedFontSize READ defaultFixedFontSize WRITE setDefaultFixedFontSize) - - Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages) - Q_PROPERTY(bool javascriptEnabled READ javascriptEnabled WRITE setJavascriptEnabled) - Q_PROPERTY(bool javaEnabled READ javaEnabled WRITE setJavaEnabled) - Q_PROPERTY(bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled) - Q_PROPERTY(bool privateBrowsingEnabled READ privateBrowsingEnabled WRITE setPrivateBrowsingEnabled) - Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows) - Q_PROPERTY(bool javascriptCanAccessClipboard READ javascriptCanAccessClipboard WRITE setJavascriptCanAccessClipboard) - Q_PROPERTY(bool developerExtrasEnabled READ developerExtrasEnabled WRITE setDeveloperExtrasEnabled) - Q_PROPERTY(bool linksIncludedInFocusChain READ linksIncludedInFocusChain WRITE setLinksIncludedInFocusChain) - Q_PROPERTY(bool zoomTextOnly READ zoomTextOnly WRITE setZoomTextOnly) - Q_PROPERTY(bool printElementBackgrounds READ printElementBackgrounds WRITE setPrintElementBackgrounds) - Q_PROPERTY(bool offlineStorageDatabaseEnabled READ offlineStorageDatabaseEnabled WRITE setOfflineStorageDatabaseEnabled) - Q_PROPERTY(bool offlineWebApplicationCacheEnabled READ offlineWebApplicationCacheEnabled WRITE setOfflineWebApplicationCacheEnabled) - Q_PROPERTY(bool localStorageDatabaseEnabled READ localStorageDatabaseEnabled WRITE setLocalStorageDatabaseEnabled) - Q_PROPERTY(bool localContentCanAccessRemoteUrls READ localContentCanAccessRemoteUrls WRITE setLocalContentCanAccessRemoteUrls) - -public: - QmlGraphicsWebSettings() {} - - QString standardFontFamily() const { return s->fontFamily(QWebSettings::StandardFont); } - void setStandardFontFamily(const QString& f) { s->setFontFamily(QWebSettings::StandardFont,f); } - QString fixedFontFamily() const { return s->fontFamily(QWebSettings::FixedFont); } - void setFixedFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FixedFont,f); } - QString serifFontFamily() const { return s->fontFamily(QWebSettings::SerifFont); } - void setSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SerifFont,f); } - QString sansSerifFontFamily() const { return s->fontFamily(QWebSettings::SansSerifFont); } - void setSansSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SansSerifFont,f); } - QString cursiveFontFamily() const { return s->fontFamily(QWebSettings::CursiveFont); } - void setCursiveFontFamily(const QString& f) { s->setFontFamily(QWebSettings::CursiveFont,f); } - QString fantasyFontFamily() const { return s->fontFamily(QWebSettings::FantasyFont); } - void setFantasyFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FantasyFont,f); } - - int minimumFontSize() const { return s->fontSize(QWebSettings::MinimumFontSize); } - void setMinimumFontSize(int size) { s->setFontSize(QWebSettings::MinimumFontSize,size); } - int minimumLogicalFontSize() const { return s->fontSize(QWebSettings::MinimumLogicalFontSize); } - void setMinimumLogicalFontSize(int size) { s->setFontSize(QWebSettings::MinimumLogicalFontSize,size); } - int defaultFontSize() const { return s->fontSize(QWebSettings::DefaultFontSize); } - void setDefaultFontSize(int size) { s->setFontSize(QWebSettings::DefaultFontSize,size); } - int defaultFixedFontSize() const { return s->fontSize(QWebSettings::DefaultFixedFontSize); } - void setDefaultFixedFontSize(int size) { s->setFontSize(QWebSettings::DefaultFixedFontSize,size); } - - bool autoLoadImages() const { return s->testAttribute(QWebSettings::AutoLoadImages); } - void setAutoLoadImages(bool on) { s->setAttribute(QWebSettings::AutoLoadImages, on); } - bool javascriptEnabled() const { return s->testAttribute(QWebSettings::JavascriptEnabled); } - void setJavascriptEnabled(bool on) { s->setAttribute(QWebSettings::JavascriptEnabled, on); } - bool javaEnabled() const { return s->testAttribute(QWebSettings::JavaEnabled); } - void setJavaEnabled(bool on) { s->setAttribute(QWebSettings::JavaEnabled, on); } - bool pluginsEnabled() const { return s->testAttribute(QWebSettings::PluginsEnabled); } - void setPluginsEnabled(bool on) { s->setAttribute(QWebSettings::PluginsEnabled, on); } - bool privateBrowsingEnabled() const { return s->testAttribute(QWebSettings::PrivateBrowsingEnabled); } - void setPrivateBrowsingEnabled(bool on) { s->setAttribute(QWebSettings::PrivateBrowsingEnabled, on); } - bool javascriptCanOpenWindows() const { return s->testAttribute(QWebSettings::JavascriptCanOpenWindows); } - void setJavascriptCanOpenWindows(bool on) { s->setAttribute(QWebSettings::JavascriptCanOpenWindows, on); } - bool javascriptCanAccessClipboard() const { return s->testAttribute(QWebSettings::JavascriptCanAccessClipboard); } - void setJavascriptCanAccessClipboard(bool on) { s->setAttribute(QWebSettings::JavascriptCanAccessClipboard, on); } - bool developerExtrasEnabled() const { return s->testAttribute(QWebSettings::DeveloperExtrasEnabled); } - void setDeveloperExtrasEnabled(bool on) { s->setAttribute(QWebSettings::DeveloperExtrasEnabled, on); } - bool linksIncludedInFocusChain() const { return s->testAttribute(QWebSettings::LinksIncludedInFocusChain); } - void setLinksIncludedInFocusChain(bool on) { s->setAttribute(QWebSettings::LinksIncludedInFocusChain, on); } - bool zoomTextOnly() const { return s->testAttribute(QWebSettings::ZoomTextOnly); } - void setZoomTextOnly(bool on) { s->setAttribute(QWebSettings::ZoomTextOnly, on); } - bool printElementBackgrounds() const { return s->testAttribute(QWebSettings::PrintElementBackgrounds); } - void setPrintElementBackgrounds(bool on) { s->setAttribute(QWebSettings::PrintElementBackgrounds, on); } - bool offlineStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::OfflineStorageDatabaseEnabled); } - void setOfflineStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, on); } - bool offlineWebApplicationCacheEnabled() const { return s->testAttribute(QWebSettings::OfflineWebApplicationCacheEnabled); } - void setOfflineWebApplicationCacheEnabled(bool on) { s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, on); } - bool localStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::LocalStorageDatabaseEnabled); } - void setLocalStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, on); } - bool localContentCanAccessRemoteUrls() const { return s->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls); } - void setLocalContentCanAccessRemoteUrls(bool on) { s->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, on); } - - QWebSettings *s; -}; - -QML_DECLARE_TYPE(QmlGraphicsWebSettings) -QML_DEFINE_NOCREATE_TYPE(QmlGraphicsWebSettings) - -class QmlGraphicsWebViewPrivate : public QmlGraphicsPaintedItemPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsWebView) - -public: - QmlGraphicsWebViewPrivate() - : QmlGraphicsPaintedItemPrivate(), page(0), preferredwidth(0), pagewidth(0), - progress(1.0), status(QmlGraphicsWebView::Null), pending(PendingNone), - newWindowComponent(0), newWindowParent(0), - windowObjects(this), - rendering(true) - { - } - - QUrl url; // page url might be different if it has not loaded yet - QWebPage *page; - - int preferredwidth; - int pagewidth; - qreal progress; - QmlGraphicsWebView::Status status; - QString statusText; - enum { PendingNone, PendingUrl, PendingHtml, PendingContent } pending; - QUrl pending_url; - QString pending_string; - QByteArray pending_data; - mutable QmlGraphicsWebSettings settings; - QmlComponent *newWindowComponent; - QmlGraphicsItem *newWindowParent; - - void updateWindowObjects(); - class WindowObjectList : public QmlConcreteList - { - public: - WindowObjectList(QmlGraphicsWebViewPrivate *p) - : priv(p) {} - virtual void append(QObject *v) { - QmlConcreteList::append(v); - priv->updateWindowObjects(); - } - private: - QmlGraphicsWebViewPrivate *priv; - } windowObjects; - - bool rendering; -}; - -/*! - \qmlclass WebView - \brief The WebView item allows you to add web content to a canvas. - \inherits Item - - A WebView renders web content based on a URL. - - If the width and height of the item is not set, they will - dynamically adjust to a size appropriate for the content. - This width may be large for typical online web pages. - - If the preferredWidth is set, the width will be this amount or larger, - usually laying out the web content to fit the preferredWidth. - - \qml - WebView { - url: "http://www.nokia.com" - width: 490 - height: 400 - scale: 0.5 - smooth: true - } - \endqml - - \image webview.png - - The item includes no scrolling, scaling, - toolbars, etc., those must be implemented around WebView. See the WebBrowser example - for a demonstration of this. -*/ - -/*! - \internal - \class QmlGraphicsWebView - \brief The QmlGraphicsWebView class allows you to add web content to a QmlView. - - A WebView renders web content base on a URL. - - \image webview.png - - The item includes no scrolling, scaling, - toolbars, etc., those must be implemented around WebView. See the WebBrowser example - for a demonstration of this. - - A QmlGraphicsWebView object can be instantiated in Qml using the tag \l WebView. -*/ - -QmlGraphicsWebView::QmlGraphicsWebView(QmlGraphicsItem *parent) - : QmlGraphicsPaintedItem(*(new QmlGraphicsWebViewPrivate), parent) -{ - init(); -} - -QmlGraphicsWebView::QmlGraphicsWebView(QmlGraphicsWebViewPrivate &dd, QmlGraphicsItem *parent) - : QmlGraphicsPaintedItem(dd, parent) -{ - init(); -} - -QmlGraphicsWebView::~QmlGraphicsWebView() -{ - Q_D(QmlGraphicsWebView); - delete d->page; -} - -void QmlGraphicsWebView::init() -{ - Q_D(QmlGraphicsWebView); - - setAcceptHoverEvents(true); - setAcceptedMouseButtons(Qt::LeftButton); - setFlag(QGraphicsItem::ItemHasNoContents, false); - - d->page = 0; -} - -void QmlGraphicsWebView::componentComplete() -{ - QmlGraphicsPaintedItem::componentComplete(); - Q_D(QmlGraphicsWebView); - switch (d->pending) { - case QmlGraphicsWebViewPrivate::PendingUrl: - setUrl(d->pending_url); - break; - case QmlGraphicsWebViewPrivate::PendingHtml: - setHtml(d->pending_string, d->pending_url); - break; - case QmlGraphicsWebViewPrivate::PendingContent: - setContent(d->pending_data, d->pending_string, d->pending_url); - break; - default: - break; - } - d->pending = QmlGraphicsWebViewPrivate::PendingNone; - d->updateWindowObjects(); -} - -QmlGraphicsWebView::Status QmlGraphicsWebView::status() const -{ - Q_D(const QmlGraphicsWebView); - return d->status; -} - - -/*! - \qmlproperty real WebView::progress - This property holds the progress of loading the current URL, from 0 to 1. - - \sa onLoadFinished() onLoadFailed() -*/ -qreal QmlGraphicsWebView::progress() const -{ - Q_D(const QmlGraphicsWebView); - return d->progress; -} - -void QmlGraphicsWebView::doLoadStarted() -{ - Q_D(QmlGraphicsWebView); - - if (!d->url.isEmpty()) { - d->status = Loading; - emit statusChanged(d->status); - } - emit loadStarted(); -} - -void QmlGraphicsWebView::doLoadProgress(int p) -{ - Q_D(QmlGraphicsWebView); - if (d->progress == p/100.0) - return; - d->progress = p/100.0; - emit progressChanged(); -} - -void QmlGraphicsWebView::pageUrlChanged() -{ - Q_D(QmlGraphicsWebView); - - // Reset zooming to full - qreal zf = 1.0; - if (d->preferredwidth) { - if (d->pagewidth) - zf = qreal(d->preferredwidth)/d->pagewidth; - page()->mainFrame()->setZoomFactor(zf); - page()->setViewportSize(QSize(d->preferredwidth,-1)); - } else { - page()->mainFrame()->setZoomFactor(zf); - page()->setViewportSize(QSize(-1,-1)); - } - emit zooming(zf,0,0); - expandToWebPage(); - - if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank"))) - || d->url != page()->mainFrame()->url()) - { - d->url = page()->mainFrame()->url(); - if (d->url == QUrl(QLatin1String("about:blank"))) - d->url = QUrl(); - emit urlChanged(); - } -} - -void QmlGraphicsWebView::doLoadFinished(bool ok) -{ - Q_D(QmlGraphicsWebView); - - if (title().isEmpty()) - pageUrlChanged(); // XXX bug 232556 - pages with no title never get urlChanged() - - if (ok) { - d->status = d->url.isEmpty() ? Null : Ready; - emit loadFinished(); - } else { - d->status = Error; - emit loadFailed(); - } - emit statusChanged(d->status); -} - -/*! - \qmlproperty url WebView::url - This property holds the URL to the page displayed in this item. It can be set, - but also can change spontaneously (eg. because of network redirection). - - If the url is empty, the page is blank. - - The url is always absolute (QML will resolve relative URL strings in the context - of the containing QML document). -*/ -QUrl QmlGraphicsWebView::url() const -{ - Q_D(const QmlGraphicsWebView); - return d->url; -} - -void QmlGraphicsWebView::setUrl(const QUrl &url) -{ - Q_D(QmlGraphicsWebView); - if (url == d->url) - return; - - if (isComponentComplete()) { - d->url = url; - qreal zf = 1.0; - if (d->preferredwidth) { - if (d->pagewidth) - zf = qreal(d->preferredwidth)/d->pagewidth; - page()->setViewportSize(QSize(d->preferredwidth,-1)); - } else { - page()->setViewportSize(QSize(-1,-1)); - } - page()->mainFrame()->setZoomFactor(zf); - QUrl seturl = url; - if (seturl.isEmpty()) - seturl = QUrl(QLatin1String("about:blank")); - - Q_ASSERT(!seturl.isRelative()); - - page()->mainFrame()->load(seturl); - - emit urlChanged(); - } else { - d->pending = d->PendingUrl; - d->pending_url = url; - } -} - -/*! - \qmlproperty int WebView::preferredWidth - This property holds the ideal width for displaying the current URL. -*/ -int QmlGraphicsWebView::preferredWidth() const -{ - Q_D(const QmlGraphicsWebView); - return d->preferredwidth; -} - -void QmlGraphicsWebView::setPreferredWidth(int iw) -{ - Q_D(QmlGraphicsWebView); - if (d->preferredwidth == iw) return; - if (d->pagewidth) { - if (d->preferredwidth) { - setZoomFactor(zoomFactor()*iw/d->preferredwidth); - } else { - setZoomFactor(qreal(iw)/d->pagewidth); - } - } - d->preferredwidth = iw; - expandToWebPage(); - emit preferredWidthChanged(); -} - -/*! - \qmlproperty int WebView::webPageWidth - This property holds the page width suggested to the web engine. -*/ -int QmlGraphicsWebView::webPageWidth() const -{ - Q_D(const QmlGraphicsWebView); - return d->pagewidth; -} - -void QmlGraphicsWebView::setWebPageWidth(int pw) -{ - Q_D(QmlGraphicsWebView); - if (d->pagewidth == pw) return; - d->pagewidth = pw; - expandToWebPage(); -} - -/*! - Evaluates the \a scriptSource JavaScript inside the main frame - context and returns the result of the last executed statement. -*/ -QVariant QmlGraphicsWebView::evaluateJavaScript(const QString &scriptSource) -{ - return this->page()->mainFrame()->evaluateJavaScript(scriptSource); -} - -void QmlGraphicsWebView::focusChanged(bool hasFocus) -{ - QFocusEvent e(hasFocus ? QEvent::FocusIn : QEvent::FocusOut); - page()->event(&e); - QmlGraphicsItem::focusChanged(hasFocus); -} - -void QmlGraphicsWebView::contentsSizeChanged(const QSize&) -{ - expandToWebPage(); -} - -void QmlGraphicsWebView::expandToWebPage() -{ - Q_D(QmlGraphicsWebView); - QSize cs = page()->mainFrame()->contentsSize(); - qreal zoom = zoomFactor(); - if (cs.width() < d->preferredwidth*zoom) - cs.setWidth(d->preferredwidth*zoom); - if (widthValid()) - cs.setWidth(width()); - if (heightValid()) - cs.setHeight(height()); - if (cs != page()->viewportSize()) { - page()->setViewportSize(cs); - clearCache(); - setImplicitWidth(cs.width()); - setImplicitHeight(cs.height()); - } -} - -void QmlGraphicsWebView::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - if (newGeometry.size() != oldGeometry.size()) - expandToWebPage(); - QmlGraphicsPaintedItem::geometryChanged(newGeometry, oldGeometry); -} - -void QmlGraphicsWebView::paintPage(const QRect& r) -{ - Q_D(QmlGraphicsWebView); - if (d->page->mainFrame()->contentsSize() != contentsSize()) - setContentsSize(d->page->mainFrame()->contentsSize()); - dirtyCache(r); - update(); -} - -/*! - \qmlproperty int WebView::pixelCacheSize - - This property holds the maximum number of pixels of image cache to - allow. The default is 0.1 megapixels. The cache will not be larger - than the (unscaled) size of the WebView. -*/ -int QmlGraphicsWebView::pixelCacheSize() const -{ - Q_D(const QmlGraphicsWebView); - return d->max_imagecache_size; -} - -void QmlGraphicsWebView::setPixelCacheSize(int pixels) -{ - Q_D(QmlGraphicsWebView); - if (pixels < d->max_imagecache_size) { - int cachesize=0; - for (int i=0; iimagecache.count(); ++i) { - QRect area = d->imagecache[i]->area; - cachesize += area.width()*area.height(); - } - while (d->imagecache.count() && cachesize > pixels) { - int oldest=-1; - int age=-1; - for (int i=0; iimagecache.count(); ++i) { - int a = d->imagecache[i]->age; - if (a > age) { - oldest = i; - age = a; - } - } - cachesize -= d->imagecache[oldest]->area.width()*d->imagecache[oldest]->area.height(); - d->imagecache.removeAt(oldest); - } - } - d->max_imagecache_size = pixels; -} - -/*! - \qmlproperty list WebView::javaScriptWindowObjects - - This property is a list of object that are available from within - the webview's JavaScript context. - - The \a object will be inserted as a child of the frame's window - object, under the name given by the attached property \c WebView.windowObjectName. - - \qml - WebView { - javaScriptWindowObjects: Object { - WebView.windowObjectName: "coordinates" - } - } - \endqml - - Properties of the object will be exposed as JavaScript properties and slots as - JavaScript methods. - - If Javascript is not enabled for this page, then this property does nothing. -*/ -QmlList *QmlGraphicsWebView::javaScriptWindowObjects() -{ - Q_D(QmlGraphicsWebView); - return &d->windowObjects; -} - -class QmlGraphicsWebViewAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString windowObjectName READ windowObjectName WRITE setWindowObjectName) -public: - QmlGraphicsWebViewAttached(QObject *parent) - : QObject(parent) - { - } - - QString windowObjectName() const - { - return m_windowObjectName; - } - - void setWindowObjectName(const QString &n) - { - m_windowObjectName = n; - } - -private: - QString m_windowObjectName; -}; - -QmlGraphicsWebViewAttached *QmlGraphicsWebView::qmlAttachedProperties(QObject *o) -{ - return new QmlGraphicsWebViewAttached(o); -} - -void QmlGraphicsWebViewPrivate::updateWindowObjects() -{ - Q_Q(QmlGraphicsWebView); - if (!q->isComponentComplete() || !page) - return; - - for (int ii = 0; ii < windowObjects.count(); ++ii) { - QObject *object = windowObjects.at(ii); - QmlGraphicsWebViewAttached *attached = static_cast(qmlAttachedPropertiesObject(object)); - if (attached && !attached->windowObjectName().isEmpty()) { - page->mainFrame()->addToJavaScriptWindowObject(attached->windowObjectName(), object); - } - } -} - -bool QmlGraphicsWebView::renderingEnabled() const -{ - Q_D(const QmlGraphicsWebView); - return d->rendering; -} - -void QmlGraphicsWebView::setRenderingEnabled(bool enabled) -{ - Q_D(QmlGraphicsWebView); - if (d->rendering == enabled) - return; - d->rendering = enabled; - setCacheFrozen(!enabled); - if (enabled) - clearCache(); -} - - -void QmlGraphicsWebView::drawContents(QPainter *p, const QRect &r) -{ - Q_D(QmlGraphicsWebView); - if (d->rendering) - page()->mainFrame()->render(p,r); -} - -static QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) -{ - QEvent::Type t; - switch(e->type()) { - default: - case QEvent::GraphicsSceneMousePress: - t = QEvent::MouseButtonPress; - break; - case QEvent::GraphicsSceneMouseRelease: - t = QEvent::MouseButtonRelease; - break; - case QEvent::GraphicsSceneMouseMove: - t = QEvent::MouseMove; - break; - case QGraphicsSceneEvent::GraphicsSceneMouseDoubleClick: - t = QEvent::MouseButtonDblClick; - break; - } - - QMouseEvent *me = new QMouseEvent(t, e->pos().toPoint(), e->button(), e->buttons(), 0); - return me; -} - -static QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *e) -{ - QEvent::Type t = QEvent::MouseMove; - - QMouseEvent *me = new QMouseEvent(t, e->pos().toPoint(), Qt::NoButton, Qt::NoButton, 0); - - return me; -} - - -/*! - \qmlsignal WebView::onDoubleClick(clickx,clicky) - - The WebView does not pass double-click events to the web engine, but rather - emits this signals. -*/ - -void QmlGraphicsWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - emit doubleClick(me->x(),me->y()); - delete me; -} - -void QmlGraphicsWebView::heuristicZoom(int clickX, int clickY) -{ - Q_D(QmlGraphicsWebView); - qreal ozf = zoomFactor(); - QRect showarea = elementAreaAt(clickX, clickY, 1, 1); - qreal z = qreal(preferredWidth())*ozf/showarea.width()*.95; - if ((z/ozf > 0.99 && z/ozf <1.01) || z < qreal(d->preferredwidth)/d->pagewidth) { - // zoom out - z = qreal(d->preferredwidth)/d->pagewidth; - } - QRectF r(showarea.left()/ozf*z, showarea.top()/ozf*z, showarea.width()/ozf*z, showarea.height()/ozf*z); - emit zooming(z,r.x()+r.width()/2, r.y()+r.height()/2); -} - -void QmlGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - setFocus (true); - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - page()->event(me); - event->setAccepted( -/* - It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit - Might be a bug in WebKit, though - */ -#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) { - QmlGraphicsPaintedItem::mousePressEvent(event); - } -} - -void QmlGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - page()->event(me); - event->setAccepted( -/* - It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraphicsScene will not send all the events to WebKit - */ -#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) { - QmlGraphicsPaintedItem::mouseReleaseEvent(event); - } -} - -void QmlGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - QMouseEvent *me = sceneMouseEventToMouseEvent(event); - page()->event(me); - event->setAccepted( -/* - It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit - Might be a bug in WebKit, though - */ -#if 1 // QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) - QmlGraphicsPaintedItem::mouseMoveEvent(event); - -} -void QmlGraphicsWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) -{ - QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event); - page()->event(me); - event->setAccepted( -#if QT_VERSION <= 0x040500 // XXX see bug 230835 - true -#else - me->isAccepted() -#endif - ); - delete me; - if (!event->isAccepted()) - QmlGraphicsPaintedItem::hoverMoveEvent(event); -} - -void QmlGraphicsWebView::keyPressEvent(QKeyEvent* event) -{ - page()->event(event); - if (!event->isAccepted()) - QmlGraphicsPaintedItem::keyPressEvent(event); -} - -void QmlGraphicsWebView::keyReleaseEvent(QKeyEvent* event) -{ - page()->event(event); - if (!event->isAccepted()) - QmlGraphicsPaintedItem::keyReleaseEvent(event); -} - -bool QmlGraphicsWebView::sceneEvent(QEvent *event) -{ - if (event->type() == QEvent::KeyPress) { - QKeyEvent *k = static_cast(event); - if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) { - if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? - page()->event(event); - if (event->isAccepted()) - return true; - } - } - } - return QmlGraphicsPaintedItem::sceneEvent(event); -} - - - -/*! - \qmlproperty action WebView::back - This property holds the action for causing the previous URL in the history to be displayed. -*/ -QAction *QmlGraphicsWebView::backAction() const -{ - return page()->action(QWebPage::Back); -} - -/*! - \qmlproperty action WebView::forward - This property holds the action for causing the next URL in the history to be displayed. -*/ -QAction *QmlGraphicsWebView::forwardAction() const -{ - return page()->action(QWebPage::Forward); -} - -/*! - \qmlproperty action WebView::reload - This property holds the action for reloading with the current URL -*/ -QAction *QmlGraphicsWebView::reloadAction() const -{ - return page()->action(QWebPage::Reload); -} - -/*! - \qmlproperty action WebView::stop - This property holds the action for stopping loading with the current URL -*/ -QAction *QmlGraphicsWebView::stopAction() const -{ - return page()->action(QWebPage::Stop); -} - -/*! - \qmlproperty real WebView::title - This property holds the title of the web page currently viewed - - By default, this property contains an empty string. -*/ -QString QmlGraphicsWebView::title() const -{ - return page()->mainFrame()->title(); -} - - - -/*! - \qmlproperty pixmap WebView::icon - This property holds the icon associated with the web page currently viewed -*/ -QPixmap QmlGraphicsWebView::icon() const -{ - return page()->mainFrame()->icon().pixmap(QSize(256,256)); -} - - -/*! - \qmlproperty real WebView::textSizeMultiplier - This property holds the multiplier used to scale the text in a Web page -*/ -void QmlGraphicsWebView::setTextSizeMultiplier(qreal factor) -{ - page()->mainFrame()->setTextSizeMultiplier(factor); -} - -qreal QmlGraphicsWebView::textSizeMultiplier() const -{ - return page()->mainFrame()->textSizeMultiplier(); -} - -/*! - \qmlproperty real WebView::zoomFactor - This property holds the multiplier used to scale the contents of a Web page. -*/ -void QmlGraphicsWebView::setZoomFactor(qreal factor) -{ - Q_D(QmlGraphicsWebView); - if (factor == page()->mainFrame()->zoomFactor()) - return; - - page()->mainFrame()->setZoomFactor(factor); - page()->setViewportSize(QSize(d->pagewidth*factor,-1)); - expandToWebPage(); - - emit zoomFactorChanged(); -} - -qreal QmlGraphicsWebView::zoomFactor() const -{ - return page()->mainFrame()->zoomFactor(); -} - -/*! - \qmlproperty string WebView::statusText - - This property is the current status suggested by the current web page. In a web browser, - such status is often shown in some kind of status bar. -*/ -void QmlGraphicsWebView::setStatusText(const QString& s) -{ - Q_D(QmlGraphicsWebView); - d->statusText = s; - emit statusTextChanged(); -} - -void QmlGraphicsWebView::windowObjectCleared() -{ - Q_D(QmlGraphicsWebView); - d->updateWindowObjects(); -} - -QString QmlGraphicsWebView::statusText() const -{ - Q_D(const QmlGraphicsWebView); - return d->statusText; -} - -QWebPage *QmlGraphicsWebView::page() const -{ - Q_D(const QmlGraphicsWebView); - - if (!d->page) { - QmlGraphicsWebView *self = const_cast(this); - QWebPage *wp = new QmlGraphicsWebPage(self); - - // QML items don't default to having a background, - // even though most we pages will set one anyway. - QPalette pal = QApplication::palette(); - pal.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0)); - wp->setPalette(pal); - - wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager()); - - self->setPage(wp); - - return wp; - } - - return d->page; -} - - -// The QObject interface to settings(). -/*! - \qmlproperty string WebView::settings.standardFontFamily - \qmlproperty string WebView::settings.fixedFontFamily - \qmlproperty string WebView::settings.serifFontFamily - \qmlproperty string WebView::settings.sansSerifFontFamily - \qmlproperty string WebView::settings.cursiveFontFamily - \qmlproperty string WebView::settings.fantasyFontFamily - - \qmlproperty int WebView::settings.minimumFontSize - \qmlproperty int WebView::settings.minimumLogicalFontSize - \qmlproperty int WebView::settings.defaultFontSize - \qmlproperty int WebView::settings.defaultFixedFontSize - - \qmlproperty bool WebView::settings.autoLoadImages - \qmlproperty bool WebView::settings.javascriptEnabled - \qmlproperty bool WebView::settings.javaEnabled - \qmlproperty bool WebView::settings.pluginsEnabled - \qmlproperty bool WebView::settings.privateBrowsingEnabled - \qmlproperty bool WebView::settings.javascriptCanOpenWindows - \qmlproperty bool WebView::settings.javascriptCanAccessClipboard - \qmlproperty bool WebView::settings.developerExtrasEnabled - \qmlproperty bool WebView::settings.linksIncludedInFocusChain - \qmlproperty bool WebView::settings.zoomTextOnly - \qmlproperty bool WebView::settings.printElementBackgrounds - \qmlproperty bool WebView::settings.offlineStorageDatabaseEnabled - \qmlproperty bool WebView::settings.offlineWebApplicationCacheEnabled - \qmlproperty bool WebView::settings.localStorageDatabaseEnabled - \qmlproperty bool WebView::settings.localContentCanAccessRemoteUrls - - These properties give access to the settings controlling the web view. - - See QWebSettings for details of these properties. - - \qml - WebView { - settings.pluginsEnabled: true - settings.standardFontFamily: "Arial" - ... - } - \endqml -*/ -QmlGraphicsWebSettings *QmlGraphicsWebView::settingsObject() const -{ - Q_D(const QmlGraphicsWebView); - d->settings.s = page()->settings(); - return &d->settings; -} - -void QmlGraphicsWebView::setPage(QWebPage *page) -{ - Q_D(QmlGraphicsWebView); - if (d->page == page) - return; - if (d->page) { - if (d->page->parent() == this) { - delete d->page; - } else { - d->page->disconnect(this); - } - } - d->page = page; - d->page->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : -1, -1)); - d->page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); - d->page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); - connect(d->page,SIGNAL(repaintRequested(QRect)),this,SLOT(paintPage(QRect))); - connect(d->page->mainFrame(),SIGNAL(urlChanged(QUrl)),this,SLOT(pageUrlChanged())); - connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); - connect(d->page->mainFrame(), SIGNAL(iconChanged()), this, SIGNAL(iconChanged())); - connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SLOT(contentsSizeChanged(QSize))); - - connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted())); - connect(d->page,SIGNAL(loadProgress(int)),this,SLOT(doLoadProgress(int))); - connect(d->page,SIGNAL(loadFinished(bool)),this,SLOT(doLoadFinished(bool))); - connect(d->page,SIGNAL(statusBarMessage(QString)),this,SLOT(setStatusText(QString))); - - connect(d->page->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT(windowObjectCleared())); -} - -/*! - \qmlsignal WebView::onLoadStarted() - - This handler is called when the web engine begins loading - a page. - - \sa progress onLoadFinished() onLoadFailed() -*/ - -/*! - \qmlsignal WebView::onLoadFinished() - - This handler is called when the web engine finishes loading - a page, including any component content. - - \sa progress onLoadFailed() -*/ - -/*! - \qmlsignal WebView::onLoadFailed() - - This handler is called when the web engine fails loading - a page or any component content. - - \sa progress onLoadFinished() -*/ - -void QmlGraphicsWebView::load(const QNetworkRequest &request, - QNetworkAccessManager::Operation operation, - const QByteArray &body) -{ - page()->mainFrame()->load(request, operation, body); -} - -QString QmlGraphicsWebView::html() const -{ - return page()->mainFrame()->toHtml(); -} - -/*! - \qmlproperty string WebView::html - This property holds HTML text set directly - - The html property can be set as a string. - - \qml - WebView { - html: "

This is HTML." - } - \endqml -*/ -void QmlGraphicsWebView::setHtml(const QString &html, const QUrl &baseUrl) -{ - Q_D(QmlGraphicsWebView); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), height())); - if (isComponentComplete()) - page()->mainFrame()->setHtml(html, baseUrl); - else { - d->pending = d->PendingHtml; - d->pending_url = baseUrl; - d->pending_string = html; - } -} - -void QmlGraphicsWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) -{ - Q_D(QmlGraphicsWebView); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), height())); - - if (isComponentComplete()) - page()->mainFrame()->setContent(data,mimeType,qmlContext(this)->resolvedUrl(baseUrl)); - else { - d->pending = d->PendingContent; - d->pending_url = baseUrl; - d->pending_string = mimeType; - d->pending_data = data; - } -} - -QWebHistory *QmlGraphicsWebView::history() const -{ - return page()->history(); -} - -QWebSettings *QmlGraphicsWebView::settings() const -{ - return page()->settings(); -} - -QmlGraphicsWebView *QmlGraphicsWebView::createWindow(QWebPage::WebWindowType type) -{ - Q_D(QmlGraphicsWebView); - switch (type) { - case QWebPage::WebBrowserWindow: { - if (!d->newWindowComponent && d->newWindowParent) - qWarning("WebView::newWindowComponent not set - WebView::newWindowParent ignored"); - else if (d->newWindowComponent && !d->newWindowParent) - qWarning("WebView::newWindowParent not set - WebView::newWindowComponent ignored"); - else if (d->newWindowComponent && d->newWindowParent) { - QmlGraphicsWebView *webview = 0; - QmlContext *windowContext = new QmlContext(qmlContext(this)); - - QObject *nobj = d->newWindowComponent->create(windowContext); - if (nobj) { - windowContext->setParent(nobj); - QmlGraphicsItem *item = qobject_cast(nobj); - if (!item) { - delete nobj; - } else { - webview = item->findChild(); - if (!webview) { - delete item; - } else { - item->setParent(d->newWindowParent); - } - } - } else { - delete windowContext; - } - - return webview; - } - } - break; - case QWebPage::WebModalDialog: { - // Not supported - } - } - return 0; -} - -/*! - \qmlproperty component WebView::newWindowComponent - - This property holds the component to use for new windows. - The component must have a WebView somewhere in its structure. - - When the web engine requests a new window, it will be an instance of - this component. - - The parent of the new window is set by newWindowParent. It must be set. -*/ -QmlComponent *QmlGraphicsWebView::newWindowComponent() const -{ - Q_D(const QmlGraphicsWebView); - return d->newWindowComponent; -} - -void QmlGraphicsWebView::setNewWindowComponent(QmlComponent *newWindow) -{ - Q_D(QmlGraphicsWebView); - delete d->newWindowComponent; - d->newWindowComponent = newWindow; -} - - -/*! - \qmlproperty item WebView::newWindowParent - - The parent item for new windows. - - \sa newWindowComponent -*/ -QmlGraphicsItem *QmlGraphicsWebView::newWindowParent() const -{ - Q_D(const QmlGraphicsWebView); - return d->newWindowParent; -} - -void QmlGraphicsWebView::setNewWindowParent(QmlGraphicsItem *parent) -{ - Q_D(QmlGraphicsWebView); - delete d->newWindowParent; - d->newWindowParent = parent; -} - -/*! - Returns the area of the largest element at position (\a x,\a y) that is no larger - than \a maxwidth by \a maxheight pixels. - - May return an area larger in the case when no smaller element is at the position. -*/ -QRect QmlGraphicsWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const -{ - QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x,y)); - QWebElement element = hit.enclosingBlockElement(); - QWebElement parent = element.parent(); - if (maxwidth<=0) maxwidth = INT_MAX; - if (maxheight<=0) maxheight = INT_MAX; - while (!parent.isNull() && parent.geometry().width() <= maxwidth && parent.geometry().height() <= maxheight) { - element = parent; - parent = element.parent(); - } - return element.geometry(); -} - -/*! - \internal - \class QmlGraphicsWebPage - \brief The QmlGraphicsWebPage class is a QWebPage that can create QML plugins. - - \sa QmlGraphicsWebView -*/ -QmlGraphicsWebPage::QmlGraphicsWebPage(QmlGraphicsWebView *parent) : - QWebPage(parent) -{ -} - -QmlGraphicsWebPage::~QmlGraphicsWebPage() -{ -} - -/* - Qt WebKit does not understand non-QWidget plugins, so dummy widgets - are created, parented to a single dummy tool window. - - The requirements for QML object plugins are input to the Qt WebKit - non-QWidget plugin support, which will obsolete this kludge. -*/ -class QWidget_Dummy_Plugin : public QWidget -{ - Q_OBJECT -public: - static QWidget *dummy_shared_parent() - { - static QWidget *dsp = 0; - if (!dsp) { - dsp = new QWidget(0,Qt::Tool); - dsp->setGeometry(-10000,-10000,0,0); - dsp->show(); - } - return dsp; - } - QWidget_Dummy_Plugin(const QUrl& url, QmlGraphicsWebView *view, const QStringList ¶mNames, const QStringList ¶mValues) : - QWidget(dummy_shared_parent()), - propertyNames(paramNames), - propertyValues(paramValues), - webview(view) - { - QmlEngine *engine = qmlEngine(webview); - component = new QmlComponent(engine, url, this); - item = 0; - if (component->isLoading()) - connect(component, SIGNAL(statusChanged(QmlComponent::Status)), this, SLOT(qmlLoaded())); - else - qmlLoaded(); - } - -public Q_SLOTS: - void qmlLoaded() - { - if (component->isError()) { - // ### Could instead give these errors to the WebView to handle. - qWarning() << component->errors(); - return; - } - item = qobject_cast(component->create(qmlContext(webview))); - item->setParent(webview); - QString jsObjName; - for (int i=0; isetProperty(propertyNames[i].toUtf8(),propertyValues[i]); - if (propertyNames[i] == QLatin1String("objectname")) - jsObjName = propertyValues[i]; - } - } - if (!jsObjName.isNull()) { - QWebFrame *f = webview->page()->mainFrame(); - f->addToJavaScriptWindowObject(jsObjName, item); - } - resizeEvent(0); - delete component; - component = 0; - } - void resizeEvent(QResizeEvent*) - { - if (item) { - item->setX(x()); - item->setY(y()); - item->setWidth(width()); - item->setHeight(height()); - } - } - -private: - QmlComponent *component; - QmlGraphicsItem *item; - QStringList propertyNames, propertyValues; - QmlGraphicsWebView *webview; -}; - -QmlGraphicsWebView *QmlGraphicsWebPage::viewItem() -{ - return static_cast(parent()); -} - -QObject *QmlGraphicsWebPage::createPlugin(const QString &, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) -{ - QUrl comp = qmlContext(viewItem())->resolvedUrl(url); - return new QWidget_Dummy_Plugin(comp,viewItem(),paramNames,paramValues); -} - -QWebPage *QmlGraphicsWebPage::createWindow(WebWindowType type) -{ - QmlGraphicsWebView *newView = viewItem()->createWindow(type); - if (newView) - return newView->page(); - return 0; -} - -QT_END_NAMESPACE - -#include "qfxwebview.moc" diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h deleted file mode 100644 index e567197..0000000 --- a/src/declarative/fx/qfxwebview.h +++ /dev/null @@ -1,251 +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 QFXWEBVIEW_H -#define QFXWEBVIEW_H - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_HEADER - -class QWebHistory; -class QWebSettings; - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlGraphicsWebViewPrivate; -class QNetworkRequest; -class QmlGraphicsWebView; - -class Q_DECLARATIVE_EXPORT QmlGraphicsWebPage : public QWebPage -{ - Q_OBJECT -public: - explicit QmlGraphicsWebPage(QmlGraphicsWebView *parent); - ~QmlGraphicsWebPage(); -protected: - QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); - QWebPage *createWindow(WebWindowType type); - -private: - QmlGraphicsWebView *viewItem(); -}; - - -class QmlGraphicsWebViewAttached; -class QmlGraphicsWebSettings; - -//### TODO: browser plugins - -class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem -{ - Q_OBJECT - - Q_ENUMS(Status) - - Q_PROPERTY(QString title READ title NOTIFY titleChanged) - Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged) - Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false) - Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) - Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) - - Q_PROPERTY(QString html READ html WRITE setHtml) - - Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) - Q_PROPERTY(int webPageWidth READ webPageWidth WRITE setWebPageWidth) - Q_PROPERTY(int pixelCacheSize READ pixelCacheSize WRITE setPixelCacheSize) - Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - - Q_PROPERTY(QAction* reload READ reloadAction CONSTANT) - Q_PROPERTY(QAction* back READ backAction CONSTANT) - Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) - Q_PROPERTY(QAction* stop READ stopAction CONSTANT) - - Q_PROPERTY(QmlGraphicsWebSettings* settings READ settingsObject CONSTANT) - - Q_PROPERTY(QmlList* javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) - - Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent) - Q_PROPERTY(QmlGraphicsItem* newWindowParent READ newWindowParent WRITE setNewWindowParent) - - Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled) - -public: - QmlGraphicsWebView(QmlGraphicsItem *parent=0); - ~QmlGraphicsWebView(); - - QUrl url() const; - void setUrl(const QUrl &); - - QString title() const; - - QPixmap icon() const; - - qreal textSizeMultiplier() const; - void setTextSizeMultiplier(qreal); - - qreal zoomFactor() const; - void setZoomFactor(qreal); - - int preferredWidth() const; - void setPreferredWidth(int); - int webPageWidth() const; - void setWebPageWidth(int); - - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - QString statusText() const; - - QAction *reloadAction() const; - QAction *backAction() const; - QAction *forwardAction() const; - QAction *stopAction() const; - - QWebPage *page() const; - void setPage(QWebPage *page); - - void load(const QNetworkRequest &request, - QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, - const QByteArray &body = QByteArray()); - - QString html() const; - - void setHtml(const QString &html, const QUrl &baseUrl = QUrl()); - void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()); - - QWebHistory *history() const; - QWebSettings *settings() const; - QmlGraphicsWebSettings *settingsObject() const; - - int pixelCacheSize() const; - void setPixelCacheSize(int pixels); - - bool renderingEnabled() const; - void setRenderingEnabled(bool); - - QmlList *javaScriptWindowObjects(); - - static QmlGraphicsWebViewAttached *qmlAttachedProperties(QObject *); - - QmlComponent *newWindowComponent() const; - void setNewWindowComponent(QmlComponent *newWindow); - QmlGraphicsItem *newWindowParent() const; - void setNewWindowParent(QmlGraphicsItem *newWindow); - -Q_SIGNALS: - void preferredWidthChanged(); - void preferredHeightChanged(); - void urlChanged(); - void progressChanged(); - void statusChanged(Status); - void titleChanged(const QString&); - void iconChanged(); - void statusTextChanged(); - void zoomFactorChanged(); - - void loadStarted(); - void loadFinished(); - void loadFailed(); - - void doubleClick(int clickX, int clickY); - - void zooming(qreal zoom, int centerX, int centerY); - -public Q_SLOTS: - QVariant evaluateJavaScript(const QString&); - void heuristicZoom(int clickX, int clickY); - -private Q_SLOTS: - void expandToWebPage(); - void paintPage(const QRect&); - void doLoadStarted(); - void doLoadProgress(int p); - void doLoadFinished(bool ok); - void setStatusText(const QString&); - void windowObjectCleared(); - void pageUrlChanged(); - void contentsSizeChanged(const QSize&); - -protected: - QmlGraphicsWebView(QmlGraphicsWebViewPrivate &dd, QmlGraphicsItem *parent); - - void drawContents(QPainter *, const QRect &); - - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - void hoverMoveEvent (QGraphicsSceneHoverEvent * event); - void keyPressEvent(QKeyEvent* event); - void keyReleaseEvent(QKeyEvent* event); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - virtual void focusChanged(bool); - virtual bool sceneEvent(QEvent *event); - QmlGraphicsWebView *createWindow(QWebPage::WebWindowType type); - QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; - -private: - void init(); - virtual void componentComplete(); - Q_DISABLE_COPY(QmlGraphicsWebView) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsWebView) - friend class QmlGraphicsWebPage; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsWebView) -QML_DECLARE_TYPEINFO(QmlGraphicsWebView, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QAction) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qmlgraphicsanchors.cpp b/src/declarative/fx/qmlgraphicsanchors.cpp new file mode 100644 index 0000000..d0e26d8 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsanchors.cpp @@ -0,0 +1,962 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsanchors_p.h" +#include "qmlgraphicsitem.h" +#include "qmlgraphicsitem_p.h" +#include +#include + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Anchors,QmlGraphicsAnchors) + +//TODO: should we cache relationships, so we don't have to check each time (parent-child or sibling)? +//TODO: support non-parent, non-sibling (need to find lowest common ancestor) + +//### const item? +//local position +static qreal position(QmlGraphicsItem *item, QmlGraphicsAnchorLine::AnchorLine anchorLine) +{ + qreal ret = 0.0; + switch(anchorLine) { + case QmlGraphicsAnchorLine::Left: + ret = item->x(); + break; + case QmlGraphicsAnchorLine::Right: + ret = item->x() + item->width(); + break; + case QmlGraphicsAnchorLine::Top: + ret = item->y(); + break; + case QmlGraphicsAnchorLine::Bottom: + ret = item->y() + item->height(); + break; + case QmlGraphicsAnchorLine::HCenter: + ret = item->x() + item->width()/2; + break; + case QmlGraphicsAnchorLine::VCenter: + ret = item->y() + item->height()/2; + break; + case QmlGraphicsAnchorLine::Baseline: + ret = item->y() + item->baselineOffset(); + break; + default: + break; + } + + return ret; +} + +//position when origin is 0,0 +static qreal adjustedPosition(QmlGraphicsItem *item, QmlGraphicsAnchorLine::AnchorLine anchorLine) +{ + int ret = 0; + switch(anchorLine) { + case QmlGraphicsAnchorLine::Left: + ret = 0; + break; + case QmlGraphicsAnchorLine::Right: + ret = item->width(); + break; + case QmlGraphicsAnchorLine::Top: + ret = 0; + break; + case QmlGraphicsAnchorLine::Bottom: + ret = item->height(); + break; + case QmlGraphicsAnchorLine::HCenter: + ret = item->width()/2; + break; + case QmlGraphicsAnchorLine::VCenter: + ret = item->height()/2; + break; + case QmlGraphicsAnchorLine::Baseline: + ret = item->baselineOffset(); + break; + default: + break; + } + + return ret; +} + +/*! + \internal + \class QmlGraphicsAnchors + \ingroup group_layouts + \brief The QmlGraphicsAnchors class provides a way to lay out items relative to other items. + + \warning Currently, only anchoring to siblings or parent is supported. +*/ + +QmlGraphicsAnchors::QmlGraphicsAnchors(QObject *parent) + : QObject(*new QmlGraphicsAnchorsPrivate(), parent) +{ +} + +QmlGraphicsAnchors::~QmlGraphicsAnchors() +{ + Q_D(QmlGraphicsAnchors); + d->remDepend(d->fill); + d->remDepend(d->centerIn); + d->remDepend(d->left.item); + d->remDepend(d->right.item); + d->remDepend(d->top.item); + d->remDepend(d->bottom.item); + d->remDepend(d->vCenter.item); + d->remDepend(d->hCenter.item); + d->remDepend(d->baseline.item); +} + +void QmlGraphicsAnchorsPrivate::fillChanged() +{ + if (!fill || !isItemComplete()) + return; + + if (fill == item->parentItem()) { //child-parent + setItemPos(QPointF(leftMargin, topMargin)); + } else if (fill->parentItem() == item->parentItem()) { //siblings + setItemPos(QPointF(fill->x()+leftMargin, fill->y()+topMargin)); + } + setItemWidth(fill->width()-leftMargin-rightMargin); + setItemHeight(fill->height()-topMargin-bottomMargin); +} + +void QmlGraphicsAnchorsPrivate::centerInChanged() +{ + if (!centerIn || fill || !isItemComplete()) + return; + + if (centerIn == item->parentItem()) { + QPointF p((item->parentItem()->width() - item->width()) / 2., + (item->parentItem()->height() - item->height()) / 2.); + setItemPos(p); + + } else if (centerIn->parentItem() == item->parentItem()) { + + QPointF p(centerIn->x() + (centerIn->width() - item->width()) / 2., + centerIn->y() + (centerIn->height() - item->height()) / 2.); + setItemPos(p); + } +} + +void QmlGraphicsAnchorsPrivate::clearItem(QmlGraphicsItem *item) +{ + if (!item) + return; + if (fill == item) + fill = 0; + if (centerIn == item) + centerIn = 0; + if (left.item == item) { + left.item = 0; + usedAnchors &= ~QmlGraphicsAnchors::HasLeftAnchor; + } + if (right.item == item) { + right.item = 0; + usedAnchors &= ~QmlGraphicsAnchors::HasRightAnchor; + } + if (top.item == item) { + top.item = 0; + usedAnchors &= ~QmlGraphicsAnchors::HasTopAnchor; + } + if (bottom.item == item) { + bottom.item = 0; + usedAnchors &= ~QmlGraphicsAnchors::HasBottomAnchor; + } + if (vCenter.item == item) { + vCenter.item = 0; + usedAnchors &= ~QmlGraphicsAnchors::HasVCenterAnchor; + } + if (hCenter.item == item) { + hCenter.item = 0; + usedAnchors &= ~QmlGraphicsAnchors::HasHCenterAnchor; + } + if (baseline.item == item) { + baseline.item = 0; + usedAnchors &= ~QmlGraphicsAnchors::HasBaselineAnchor; + } +} + +void QmlGraphicsAnchorsPrivate::addDepend(QmlGraphicsItem *item) +{ + Q_Q(QmlGraphicsAnchors); + if (!item) + return; + QmlGraphicsItemPrivate *p = + static_cast(QGraphicsItemPrivate::get(item)); + p->dependantAnchors.append(q); +} + +void QmlGraphicsAnchorsPrivate::remDepend(QmlGraphicsItem *item) +{ + Q_Q(QmlGraphicsAnchors); + if (!item) + return; + QmlGraphicsItemPrivate *p = + static_cast(QGraphicsItemPrivate::get(item)); + p->dependantAnchors.removeOne(q); +} + +bool QmlGraphicsAnchorsPrivate::isItemComplete() const +{ + return componentComplete; +} + +void QmlGraphicsAnchors::classBegin() +{ + Q_D(QmlGraphicsAnchors); + d->componentComplete = false; +} + +void QmlGraphicsAnchors::componentComplete() +{ + Q_D(QmlGraphicsAnchors); + d->componentComplete = true; +} + +void QmlGraphicsAnchorsPrivate::setItemHeight(qreal v) +{ + updatingMe = true; + item->setHeight(v); + updatingMe = false; +} + +void QmlGraphicsAnchorsPrivate::setItemWidth(qreal v) +{ + updatingMe = true; + item->setWidth(v); + updatingMe = false; +} + +void QmlGraphicsAnchorsPrivate::setItemX(qreal v) +{ + updatingMe = true; + item->setX(v); + updatingMe = false; +} + +void QmlGraphicsAnchorsPrivate::setItemY(qreal v) +{ + updatingMe = true; + item->setY(v); + updatingMe = false; +} + +void QmlGraphicsAnchorsPrivate::setItemPos(const QPointF &v) +{ + updatingMe = true; + item->setPos(v); + updatingMe = false; +} + +void QmlGraphicsAnchorsPrivate::updateMe() +{ + if (updatingMe) { + updatingMe = false; + return; + } + + fillChanged(); + centerInChanged(); + updateHorizontalAnchors(); + updateVerticalAnchors(); +} + +void QmlGraphicsAnchorsPrivate::updateOnComplete() +{ + fillChanged(); + centerInChanged(); + updateHorizontalAnchors(); + updateVerticalAnchors(); +} + +void QmlGraphicsAnchorsPrivate::update(QmlGraphicsItem *, const QRectF &newG, const QRectF &oldG) +{ + fillChanged(); + centerInChanged(); + + if (newG.x() != oldG.x() || newG.width() != oldG.width()) + updateHorizontalAnchors(); + if (newG.y() != oldG.y() || newG.height() != oldG.height()) + updateVerticalAnchors(); +} + +QmlGraphicsItem *QmlGraphicsAnchors::fill() const +{ + Q_D(const QmlGraphicsAnchors); + return d->fill; +} + +void QmlGraphicsAnchors::setFill(QmlGraphicsItem *f) +{ + Q_D(QmlGraphicsAnchors); + if (!f) { + d->remDepend(d->fill); + d->fill = f; + return; + } + if (f != d->item->parentItem() && f->parentItem() != d->item->parentItem()){ + qmlInfo(tr("Can't anchor to an item that isn't a parent or sibling."), d->item); + return; + } + d->remDepend(d->fill); + d->fill = f; + d->addDepend(d->fill); + + d->fillChanged(); +} + +QmlGraphicsItem *QmlGraphicsAnchors::centerIn() const +{ + Q_D(const QmlGraphicsAnchors); + return d->centerIn; +} + +void QmlGraphicsAnchors::setCenterIn(QmlGraphicsItem* c) +{ + Q_D(QmlGraphicsAnchors); + if (!c) { + d->remDepend(d->centerIn); + d->centerIn = c; + return; + } + if (c != d->item->parentItem() && c->parentItem() != d->item->parentItem()){ + qmlInfo(tr("Can't anchor to an item that isn't a parent or sibling."), d->item); + return; + } + + d->remDepend(d->centerIn); + d->centerIn = c; + d->addDepend(d->centerIn); + + d->centerInChanged(); +} + +bool QmlGraphicsAnchorsPrivate::calcStretch(const QmlGraphicsAnchorLine &edge1, + const QmlGraphicsAnchorLine &edge2, + int offset1, + int offset2, + QmlGraphicsAnchorLine::AnchorLine line, + int &stretch) +{ + bool edge1IsParent = (edge1.item == item->parentItem()); + bool edge2IsParent = (edge2.item == item->parentItem()); + bool edge1IsSibling = (edge1.item->parentItem() == item->parentItem()); + bool edge2IsSibling = (edge2.item->parentItem() == item->parentItem()); + + bool invalid = false; + if ((edge2IsParent && edge1IsParent) || (edge2IsSibling && edge1IsSibling)) { + stretch = ((int)position(edge2.item, edge2.anchorLine) + offset2) + - ((int)position(edge1.item, edge1.anchorLine) + offset1); + } else if (edge2IsParent && edge1IsSibling) { + stretch = ((int)position(edge2.item, edge2.anchorLine) + offset2) + - ((int)position(item->parentItem(), line) + + (int)position(edge1.item, edge1.anchorLine) + offset1); + } else if (edge2IsSibling && edge1IsParent) { + stretch = ((int)position(item->parentItem(), line) + (int)position(edge2.item, edge2.anchorLine) + offset2) + - ((int)position(edge1.item, edge1.anchorLine) + offset1); + } else + invalid = true; + + return invalid; +} + +void QmlGraphicsAnchorsPrivate::updateVerticalAnchors() +{ + if (fill || centerIn || !isItemComplete()) + return; + + if (updatingVerticalAnchor < 2) { + ++updatingVerticalAnchor; + if (usedAnchors & QmlGraphicsAnchors::HasTopAnchor) { + //Handle stretching + bool invalid = true; + int height = 0; + if (usedAnchors & QmlGraphicsAnchors::HasBottomAnchor) { + invalid = calcStretch(top, bottom, topMargin, -bottomMargin, QmlGraphicsAnchorLine::Top, height); + } else if (usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor) { + invalid = calcStretch(top, vCenter, topMargin, vCenterOffset, QmlGraphicsAnchorLine::Top, height); + height *= 2; + } + if (!invalid) + setItemHeight(height); + + //Handle top + if (top.item == item->parentItem()) { + setItemY(adjustedPosition(top.item, top.anchorLine) + topMargin); + } else if (top.item->parentItem() == item->parentItem()) { + setItemY(position(top.item, top.anchorLine) + topMargin); + } + } else if (usedAnchors & QmlGraphicsAnchors::HasBottomAnchor) { + //Handle stretching (top + bottom case is handled above) + if (usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor) { + int height = 0; + bool invalid = calcStretch(vCenter, bottom, vCenterOffset, -bottomMargin, + QmlGraphicsAnchorLine::Top, height); + if (!invalid) + setItemHeight(height*2); + } + + //Handle bottom + if (bottom.item == item->parentItem()) { + setItemY(adjustedPosition(bottom.item, bottom.anchorLine) - item->height() - bottomMargin); + } else if (bottom.item->parentItem() == item->parentItem()) { + setItemY(position(bottom.item, bottom.anchorLine) - item->height() - bottomMargin); + } + } else if (usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor) { + //(stetching handled above) + + //Handle vCenter + if (vCenter.item == item->parentItem()) { + setItemY(adjustedPosition(vCenter.item, vCenter.anchorLine) + - item->height()/2 + vCenterOffset); + } else if (vCenter.item->parentItem() == item->parentItem()) { + setItemY(position(vCenter.item, vCenter.anchorLine) - item->height()/2 + vCenterOffset); + } + } else if (usedAnchors & QmlGraphicsAnchors::HasBaselineAnchor) { + //Handle baseline + if (baseline.item->parentItem() == item->parentItem()) { + setItemY(position(baseline.item, baseline.anchorLine) - item->baselineOffset() + baselineOffset); + } + } + --updatingVerticalAnchor; + } else { + // ### Make this certain :) + qmlInfo(QmlGraphicsAnchors::tr("Possible anchor loop detected on vertical anchor."), item); + } +} + +void QmlGraphicsAnchorsPrivate::updateHorizontalAnchors() +{ + if (fill || centerIn || !isItemComplete()) + return; + + if (updatingHorizontalAnchor < 2) { + ++updatingHorizontalAnchor; + + if (usedAnchors & QmlGraphicsAnchors::HasLeftAnchor) { + //Handle stretching + bool invalid = true; + int width = 0; + if (usedAnchors & QmlGraphicsAnchors::HasRightAnchor) { + invalid = calcStretch(left, right, leftMargin, -rightMargin, QmlGraphicsAnchorLine::Left, width); + } else if (usedAnchors & QmlGraphicsAnchors::HasHCenterAnchor) { + invalid = calcStretch(left, hCenter, leftMargin, hCenterOffset, QmlGraphicsAnchorLine::Left, width); + width *= 2; + } + if (!invalid) + setItemWidth(width); + + //Handle left + if (left.item == item->parentItem()) { + setItemX(adjustedPosition(left.item, left.anchorLine) + leftMargin); + } else if (left.item->parentItem() == item->parentItem()) { + setItemX(position(left.item, left.anchorLine) + leftMargin); + } + } else if (usedAnchors & QmlGraphicsAnchors::HasRightAnchor) { + //Handle stretching (left + right case is handled in updateLeftAnchor) + if (usedAnchors & QmlGraphicsAnchors::HasHCenterAnchor) { + int width = 0; + bool invalid = calcStretch(hCenter, right, hCenterOffset, -rightMargin, + QmlGraphicsAnchorLine::Left, width); + if (!invalid) + setItemWidth(width*2); + } + + //Handle right + if (right.item == item->parentItem()) { + setItemX(adjustedPosition(right.item, right.anchorLine) - item->width() - rightMargin); + } else if (right.item->parentItem() == item->parentItem()) { + setItemX(position(right.item, right.anchorLine) - item->width() - rightMargin); + } + } else if (usedAnchors & QmlGraphicsAnchors::HasHCenterAnchor) { + //Handle hCenter + if (hCenter.item == item->parentItem()) { + setItemX(adjustedPosition(hCenter.item, hCenter.anchorLine) - item->width()/2 + hCenterOffset); + } else if (hCenter.item->parentItem() == item->parentItem()) { + setItemX(position(hCenter.item, hCenter.anchorLine) - item->width()/2 + hCenterOffset); + } + } + + --updatingHorizontalAnchor; + } else { + // ### Make this certain :) + qmlInfo(QmlGraphicsAnchors::tr("Possible anchor loop detected on horizontal anchor."), item); + } +} + +QmlGraphicsAnchorLine QmlGraphicsAnchors::top() const +{ + Q_D(const QmlGraphicsAnchors); + return d->top; +} + +void QmlGraphicsAnchors::setTop(const QmlGraphicsAnchorLine &edge) +{ + Q_D(QmlGraphicsAnchors); + if (!d->checkVAnchorValid(edge)) + return; + + d->usedAnchors |= HasTopAnchor; + + if (!d->checkVValid()) { + d->usedAnchors &= ~HasTopAnchor; + return; + } + + d->remDepend(d->top.item); + d->top = edge; + d->addDepend(d->top.item); + d->updateVerticalAnchors(); +} + +void QmlGraphicsAnchors::resetTop() +{ + Q_D(QmlGraphicsAnchors); + d->usedAnchors &= ~HasTopAnchor; + d->remDepend(d->top.item); + d->top = QmlGraphicsAnchorLine(); + d->updateVerticalAnchors(); +} + +QmlGraphicsAnchorLine QmlGraphicsAnchors::bottom() const +{ + Q_D(const QmlGraphicsAnchors); + return d->bottom; +} + +void QmlGraphicsAnchors::setBottom(const QmlGraphicsAnchorLine &edge) +{ + Q_D(QmlGraphicsAnchors); + if (!d->checkVAnchorValid(edge)) + return; + + d->usedAnchors |= HasBottomAnchor; + + if (!d->checkVValid()) { + d->usedAnchors &= ~HasBottomAnchor; + return; + } + + d->remDepend(d->bottom.item); + d->bottom = edge; + d->addDepend(d->bottom.item); + d->updateVerticalAnchors(); +} + +void QmlGraphicsAnchors::resetBottom() +{ + Q_D(QmlGraphicsAnchors); + d->usedAnchors &= ~HasBottomAnchor; + d->remDepend(d->bottom.item); + d->bottom = QmlGraphicsAnchorLine(); + d->updateVerticalAnchors(); +} + +QmlGraphicsAnchorLine QmlGraphicsAnchors::verticalCenter() const +{ + Q_D(const QmlGraphicsAnchors); + return d->vCenter; +} + +void QmlGraphicsAnchors::setVerticalCenter(const QmlGraphicsAnchorLine &edge) +{ + Q_D(QmlGraphicsAnchors); + if (!d->checkVAnchorValid(edge)) + return; + + d->usedAnchors |= HasVCenterAnchor; + + if (!d->checkVValid()) { + d->usedAnchors &= ~HasVCenterAnchor; + return; + } + + d->remDepend(d->vCenter.item); + d->vCenter = edge; + d->addDepend(d->vCenter.item); + d->updateVerticalAnchors(); +} + +void QmlGraphicsAnchors::resetVerticalCenter() +{ + Q_D(QmlGraphicsAnchors); + d->usedAnchors &= ~HasVCenterAnchor; + d->remDepend(d->vCenter.item); + d->vCenter = QmlGraphicsAnchorLine(); + d->updateVerticalAnchors(); +} + +QmlGraphicsAnchorLine QmlGraphicsAnchors::baseline() const +{ + Q_D(const QmlGraphicsAnchors); + return d->baseline; +} + +void QmlGraphicsAnchors::setBaseline(const QmlGraphicsAnchorLine &edge) +{ + Q_D(QmlGraphicsAnchors); + if (!d->checkVAnchorValid(edge)) + return; + + d->usedAnchors |= HasBaselineAnchor; + + if (!d->checkVValid()) { + d->usedAnchors &= ~HasBaselineAnchor; + return; + } + + d->remDepend(d->baseline.item); + d->baseline = edge; + d->addDepend(d->baseline.item); + d->updateVerticalAnchors(); +} + +void QmlGraphicsAnchors::resetBaseline() +{ + Q_D(QmlGraphicsAnchors); + d->usedAnchors &= ~HasBaselineAnchor; + d->remDepend(d->baseline.item); + d->baseline = QmlGraphicsAnchorLine(); + d->updateVerticalAnchors(); +} + +QmlGraphicsAnchorLine QmlGraphicsAnchors::left() const +{ + Q_D(const QmlGraphicsAnchors); + return d->left; +} + +void QmlGraphicsAnchors::setLeft(const QmlGraphicsAnchorLine &edge) +{ + Q_D(QmlGraphicsAnchors); + if (!d->checkHAnchorValid(edge)) + return; + + d->usedAnchors |= HasLeftAnchor; + + if (!d->checkHValid()) { + d->usedAnchors &= ~HasLeftAnchor; + return; + } + + d->remDepend(d->left.item); + d->left = edge; + d->addDepend(d->left.item); + d->updateHorizontalAnchors(); +} + +void QmlGraphicsAnchors::resetLeft() +{ + Q_D(QmlGraphicsAnchors); + d->usedAnchors &= ~HasLeftAnchor; + d->remDepend(d->left.item); + d->left = QmlGraphicsAnchorLine(); + d->updateHorizontalAnchors(); +} + +QmlGraphicsAnchorLine QmlGraphicsAnchors::right() const +{ + Q_D(const QmlGraphicsAnchors); + return d->right; +} + +void QmlGraphicsAnchors::setRight(const QmlGraphicsAnchorLine &edge) +{ + Q_D(QmlGraphicsAnchors); + if (!d->checkHAnchorValid(edge)) + return; + + d->usedAnchors |= HasRightAnchor; + + if (!d->checkHValid()) { + d->usedAnchors &= ~HasRightAnchor; + return; + } + + d->remDepend(d->right.item); + d->right = edge; + d->addDepend(d->right.item); + + d->updateHorizontalAnchors(); +} + +void QmlGraphicsAnchors::resetRight() +{ + Q_D(QmlGraphicsAnchors); + d->usedAnchors &= ~HasRightAnchor; + d->remDepend(d->right.item); + d->right = QmlGraphicsAnchorLine(); + d->updateHorizontalAnchors(); +} + +QmlGraphicsAnchorLine QmlGraphicsAnchors::horizontalCenter() const +{ + Q_D(const QmlGraphicsAnchors); + return d->hCenter; +} + +void QmlGraphicsAnchors::setHorizontalCenter(const QmlGraphicsAnchorLine &edge) +{ + Q_D(QmlGraphicsAnchors); + if (!d->checkHAnchorValid(edge)) + return; + + d->usedAnchors |= HasHCenterAnchor; + + if (!d->checkHValid()) { + d->usedAnchors &= ~HasHCenterAnchor; + return; + } + + d->remDepend(d->hCenter.item); + d->hCenter = edge; + d->addDepend(d->hCenter.item); + d->updateHorizontalAnchors(); +} + +void QmlGraphicsAnchors::resetHorizontalCenter() +{ + Q_D(QmlGraphicsAnchors); + d->usedAnchors &= ~HasHCenterAnchor; + d->remDepend(d->hCenter.item); + d->hCenter = QmlGraphicsAnchorLine(); + d->updateHorizontalAnchors(); +} + +qreal QmlGraphicsAnchors::leftMargin() const +{ + Q_D(const QmlGraphicsAnchors); + return d->leftMargin; +} + +void QmlGraphicsAnchors::setLeftMargin(qreal offset) +{ + Q_D(QmlGraphicsAnchors); + if (d->leftMargin == offset) + return; + d->leftMargin = offset; + d->updateHorizontalAnchors(); + emit leftMarginChanged(); +} + +qreal QmlGraphicsAnchors::rightMargin() const +{ + Q_D(const QmlGraphicsAnchors); + return d->rightMargin; +} + +void QmlGraphicsAnchors::setRightMargin(qreal offset) +{ + Q_D(QmlGraphicsAnchors); + if (d->rightMargin == offset) + return; + d->rightMargin = offset; + d->updateHorizontalAnchors(); + emit rightMarginChanged(); +} + +qreal QmlGraphicsAnchors::horizontalCenterOffset() const +{ + Q_D(const QmlGraphicsAnchors); + return d->hCenterOffset; +} + +void QmlGraphicsAnchors::setHorizontalCenterOffset(qreal offset) +{ + Q_D(QmlGraphicsAnchors); + if (d->hCenterOffset == offset) + return; + d->hCenterOffset = offset; + d->updateHorizontalAnchors(); + emit horizontalCenterOffsetChanged(); +} + +qreal QmlGraphicsAnchors::topMargin() const +{ + Q_D(const QmlGraphicsAnchors); + return d->topMargin; +} + +void QmlGraphicsAnchors::setTopMargin(qreal offset) +{ + Q_D(QmlGraphicsAnchors); + if (d->topMargin == offset) + return; + d->topMargin = offset; + d->updateVerticalAnchors(); + emit topMarginChanged(); +} + +qreal QmlGraphicsAnchors::bottomMargin() const +{ + Q_D(const QmlGraphicsAnchors); + return d->bottomMargin; +} + +void QmlGraphicsAnchors::setBottomMargin(qreal offset) +{ + Q_D(QmlGraphicsAnchors); + if (d->bottomMargin == offset) + return; + d->bottomMargin = offset; + d->updateVerticalAnchors(); + emit bottomMarginChanged(); +} + +qreal QmlGraphicsAnchors::verticalCenterOffset() const +{ + Q_D(const QmlGraphicsAnchors); + return d->vCenterOffset; +} + +void QmlGraphicsAnchors::setVerticalCenterOffset(qreal offset) +{ + Q_D(QmlGraphicsAnchors); + if (d->vCenterOffset == offset) + return; + d->vCenterOffset = offset; + d->updateVerticalAnchors(); + emit verticalCenterOffsetChanged(); +} + +qreal QmlGraphicsAnchors::baselineOffset() const +{ + Q_D(const QmlGraphicsAnchors); + return d->baselineOffset; +} + +void QmlGraphicsAnchors::setBaselineOffset(qreal offset) +{ + Q_D(QmlGraphicsAnchors); + if (d->baselineOffset == offset) + return; + d->baselineOffset = offset; + d->updateVerticalAnchors(); + emit baselineOffsetChanged(); +} + +QmlGraphicsAnchors::UsedAnchors QmlGraphicsAnchors::usedAnchors() const +{ + Q_D(const QmlGraphicsAnchors); + return d->usedAnchors; +} + +void QmlGraphicsAnchors::setItem(QmlGraphicsItem *item) +{ + Q_D(QmlGraphicsAnchors); + d->item = item; +} + +bool QmlGraphicsAnchorsPrivate::checkHValid() const +{ + if (usedAnchors & QmlGraphicsAnchors::HasLeftAnchor && + usedAnchors & QmlGraphicsAnchors::HasRightAnchor && + usedAnchors & QmlGraphicsAnchors::HasHCenterAnchor) { + qmlInfo(QmlGraphicsAnchors::tr("Can't specify left, right, and hcenter anchors."), item); + return false; + } + + return true; +} + +bool QmlGraphicsAnchorsPrivate::checkHAnchorValid(QmlGraphicsAnchorLine anchor) const +{ + if (!anchor.item) { + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor to a null item."), item); + return false; + } else if (anchor.anchorLine & QmlGraphicsAnchorLine::Vertical_Mask) { + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor a horizontal edge to a vertical edge."), item); + return false; + } else if (anchor.item != item->parentItem() && anchor.item->parentItem() != item->parentItem()){ + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor to an item that isn't a parent or sibling."), item); + return false; + } else if (anchor.item == item) { + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor item to self."), item); + return false; + } + + return true; +} + +bool QmlGraphicsAnchorsPrivate::checkVValid() const +{ + if (usedAnchors & QmlGraphicsAnchors::HasTopAnchor && + usedAnchors & QmlGraphicsAnchors::HasBottomAnchor && + usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor) { + qmlInfo(QmlGraphicsAnchors::tr("Can't specify top, bottom, and vcenter anchors."), item); + return false; + } else if (usedAnchors & QmlGraphicsAnchors::HasBaselineAnchor && + (usedAnchors & QmlGraphicsAnchors::HasTopAnchor || + usedAnchors & QmlGraphicsAnchors::HasBottomAnchor || + usedAnchors & QmlGraphicsAnchors::HasVCenterAnchor)) { + qmlInfo(QmlGraphicsAnchors::tr("Baseline anchor can't be used in conjunction with top, bottom, or vcenter anchors."), item); + return false; + } + + return true; +} + +bool QmlGraphicsAnchorsPrivate::checkVAnchorValid(QmlGraphicsAnchorLine anchor) const +{ + if (!anchor.item) { + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor to a null item."), item); + return false; + } else if (anchor.anchorLine & QmlGraphicsAnchorLine::Horizontal_Mask) { + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor a vertical edge to a horizontal edge."), item); + return false; + } else if (anchor.item != item->parentItem() && anchor.item->parentItem() != item->parentItem()){ + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor to an item that isn't a parent or sibling."), item); + return false; + } else if (anchor.item == item){ + qmlInfo(QmlGraphicsAnchors::tr("Can't anchor item to self."), item); + return false; + } + + return true; +} + +QT_END_NAMESPACE + +#include "moc_qmlgraphicsanchors.cpp" + diff --git a/src/declarative/fx/qmlgraphicsanchors.h b/src/declarative/fx/qmlgraphicsanchors.h new file mode 100644 index 0000000..de7214d --- /dev/null +++ b/src/declarative/fx/qmlgraphicsanchors.h @@ -0,0 +1,180 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSANCHORS_H +#define QMLGRAPHICSANCHORS_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsAnchorsPrivate; +class QmlGraphicsAnchorLine; +class Q_DECLARATIVE_EXPORT QmlGraphicsAnchors : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QmlGraphicsAnchorLine left READ left WRITE setLeft RESET resetLeft) + Q_PROPERTY(QmlGraphicsAnchorLine right READ right WRITE setRight RESET resetRight) + Q_PROPERTY(QmlGraphicsAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter) + Q_PROPERTY(QmlGraphicsAnchorLine top READ top WRITE setTop RESET resetTop) + Q_PROPERTY(QmlGraphicsAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom) + Q_PROPERTY(QmlGraphicsAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter) + Q_PROPERTY(QmlGraphicsAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline) + Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged) + Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) + Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged()) + Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) + Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) + Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged()) + Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged()) + Q_PROPERTY(QmlGraphicsItem *fill READ fill WRITE setFill) + Q_PROPERTY(QmlGraphicsItem *centerIn READ centerIn WRITE setCenterIn) + +public: + QmlGraphicsAnchors(QObject *parent=0); + virtual ~QmlGraphicsAnchors(); + + enum UsedAnchor { + HasLeftAnchor = 0x01, + HasRightAnchor = 0x02, + HasTopAnchor = 0x04, + HasBottomAnchor = 0x08, + HasHCenterAnchor = 0x10, + HasVCenterAnchor = 0x20, + HasBaselineAnchor = 0x40, + Horizontal_Mask = HasLeftAnchor | HasRightAnchor | HasHCenterAnchor, + Vertical_Mask = HasTopAnchor | HasBottomAnchor | HasVCenterAnchor | HasBaselineAnchor + }; + Q_DECLARE_FLAGS(UsedAnchors, UsedAnchor) + + QmlGraphicsAnchorLine left() const; + void setLeft(const QmlGraphicsAnchorLine &edge); + void resetLeft(); + + QmlGraphicsAnchorLine right() const; + void setRight(const QmlGraphicsAnchorLine &edge); + void resetRight(); + + QmlGraphicsAnchorLine horizontalCenter() const; + void setHorizontalCenter(const QmlGraphicsAnchorLine &edge); + void resetHorizontalCenter(); + + QmlGraphicsAnchorLine top() const; + void setTop(const QmlGraphicsAnchorLine &edge); + void resetTop(); + + QmlGraphicsAnchorLine bottom() const; + void setBottom(const QmlGraphicsAnchorLine &edge); + void resetBottom(); + + QmlGraphicsAnchorLine verticalCenter() const; + void setVerticalCenter(const QmlGraphicsAnchorLine &edge); + void resetVerticalCenter(); + + QmlGraphicsAnchorLine baseline() const; + void setBaseline(const QmlGraphicsAnchorLine &edge); + void resetBaseline(); + + qreal leftMargin() const; + void setLeftMargin(qreal); + + qreal rightMargin() const; + void setRightMargin(qreal); + + qreal horizontalCenterOffset() const; + void setHorizontalCenterOffset(qreal); + + qreal topMargin() const; + void setTopMargin(qreal); + + qreal bottomMargin() const; + void setBottomMargin(qreal); + + qreal verticalCenterOffset() const; + void setVerticalCenterOffset(qreal); + + qreal baselineOffset() const; + void setBaselineOffset(qreal); + + QmlGraphicsItem *fill() const; + void setFill(QmlGraphicsItem *); + + QmlGraphicsItem *centerIn() const; + void setCenterIn(QmlGraphicsItem *); + + UsedAnchors usedAnchors() const; + + void setItem(QmlGraphicsItem *item); + + void classBegin(); + void componentComplete(); + +Q_SIGNALS: + void leftMarginChanged(); + void rightMarginChanged(); + void topMarginChanged(); + void bottomMarginChanged(); + void verticalCenterOffsetChanged(); + void horizontalCenterOffsetChanged(); + void baselineOffsetChanged(); + +private: + friend class QmlGraphicsItem; + Q_DISABLE_COPY(QmlGraphicsAnchors) + Q_DECLARE_PRIVATE(QmlGraphicsAnchors) +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(QmlGraphicsAnchors::UsedAnchors) + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsAnchors) + +QT_END_HEADER + +#endif diff --git a/src/declarative/fx/qmlgraphicsanchors_p.h b/src/declarative/fx/qmlgraphicsanchors_p.h new file mode 100644 index 0000000..3986cd6 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsanchors_p.h @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSANCHORS_P_H +#define QMLGRAPHICSANCHORS_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 "qmlgraphicsanchors.h" +#include "private/qobject_p.h" + +QT_BEGIN_NAMESPACE + +class QmlGraphicsAnchorLine +{ +public: + QmlGraphicsAnchorLine() : item(0), anchorLine(Invalid) + { + } + + enum AnchorLine { + Invalid = 0x0, + Left = 0x01, + Right = 0x02, + Top = 0x04, + Bottom = 0x08, + HCenter = 0x10, + VCenter = 0x20, + Baseline = 0x40, + Horizontal_Mask = Left | Right | HCenter, + Vertical_Mask = Top | Bottom | VCenter | Baseline + }; + + QmlGraphicsItem *item; + AnchorLine anchorLine; +}; +Q_DECLARE_METATYPE(QmlGraphicsAnchorLine) + +class QmlGraphicsAnchorsPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsAnchors) +public: + QmlGraphicsAnchorsPrivate() + : updatingMe(false), updatingHorizontalAnchor(0), + updatingVerticalAnchor(0), item(0), usedAnchors(0), fill(0), + centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), + bottomMargin(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0), + componentComplete(true) + { + } + + void init() + { + } + + void clearItem(QmlGraphicsItem *); + + void addDepend(QmlGraphicsItem *); + void remDepend(QmlGraphicsItem *); + bool isItemComplete() const; + + bool updatingMe; + int updatingHorizontalAnchor; + int updatingVerticalAnchor; + + void setItemHeight(qreal); + void setItemWidth(qreal); + void setItemX(qreal); + void setItemY(qreal); + void setItemPos(const QPointF &); + + void updateOnComplete(); + void updateMe(); + void update(QmlGraphicsItem *, const QRectF &, const QRectF &); + + bool checkHValid() const; + bool checkVValid() const; + bool checkHAnchorValid(QmlGraphicsAnchorLine anchor) const; + bool checkVAnchorValid(QmlGraphicsAnchorLine anchor) const; + bool calcStretch(const QmlGraphicsAnchorLine &edge1, const QmlGraphicsAnchorLine &edge2, int offset1, int offset2, QmlGraphicsAnchorLine::AnchorLine line, int &stretch); + + void updateHorizontalAnchors(); + void updateVerticalAnchors(); + void fillChanged(); + void centerInChanged(); + + QmlGraphicsItem *item; + QmlGraphicsAnchors::UsedAnchors usedAnchors; + + QmlGraphicsItem *fill; + QmlGraphicsItem *centerIn; + + QmlGraphicsAnchorLine left; + QmlGraphicsAnchorLine right; + QmlGraphicsAnchorLine top; + QmlGraphicsAnchorLine bottom; + QmlGraphicsAnchorLine vCenter; + QmlGraphicsAnchorLine hCenter; + QmlGraphicsAnchorLine baseline; + + qreal leftMargin; + qreal rightMargin; + qreal topMargin; + qreal bottomMargin; + qreal vCenterOffset; + qreal hCenterOffset; + qreal baselineOffset; + + bool componentComplete; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/declarative/fx/qmlgraphicsborderimage.cpp b/src/declarative/fx/qmlgraphicsborderimage.cpp new file mode 100644 index 0000000..c346366 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsborderimage.cpp @@ -0,0 +1,411 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsborderimage.h" +#include "qmlgraphicsborderimage_p.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,BorderImage,QmlGraphicsBorderImage) + +/*! + \qmlclass BorderImage QmlGraphicsBorderImage + \brief The BorderImage element provides an image that can be used as a border. + \inherits Item + + \snippet examples/declarative/border-image/example.qml 0 + + \image BorderImage.png + + \sa examples/declarative/border-image + */ + +/*! + \internal + \class QmlGraphicsBorderImage BorderImage + \brief The QmlGraphicsBorderImage class provides an image item that you can add to a QmlView. +*/ + +QmlGraphicsBorderImage::QmlGraphicsBorderImage(QmlGraphicsItem *parent) + : QmlGraphicsImageBase(*(new QmlGraphicsBorderImagePrivate), parent) +{ + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QmlGraphicsBorderImage::~QmlGraphicsBorderImage() +{ + Q_D(QmlGraphicsBorderImage); + if (d->sciReply) + d->sciReply->deleteLater(); + if (d->sciPendingPixmapCache) + QmlGraphicsPixmapCache::cancelGet(d->sciurl, this); +} +/*! + \qmlproperty enum BorderImage::status + + This property holds the status of image loading. It can be one of: + \list + \o Null - no image has been set + \o Ready - the image has been loaded + \o Loading - the image is currently being loaded + \o Error - an error occurred while loading the image + \endlist + + \sa progress +*/ + +/*! + \qmlproperty real BorderImage::progress + + This property holds the progress of image loading, from 0.0 (nothing loaded) + to 1.0 (finished). + + \sa status +*/ + +/*! + \qmlproperty bool BorderImage::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 image 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. +*/ + +/*! + \qmlproperty url BorderImage::source + + BorderImage can handle any image format supported by Qt, loaded from any URL scheme supported by Qt. + + It can also handle .sci files, which are a Qml-specific format. A .sci file uses a simple text-based format that specifies + the borders, the image file and the tile rules. + + The following .sci file sets the borders to 10 on each side for the image \c picture.png: + \qml + border.left: 10 + border.top: 10 + border.bottom: 10 + border.right: 10 + source: picture.png + \endqml + + The URL may be absolute, or relative to the URL of the component. +*/ + +static QString toLocalFileOrQrc(const QUrl& url) +{ + QString r = url.toLocalFile(); + if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) + r = QLatin1Char(':') + url.path(); + return r; +} + + +void QmlGraphicsBorderImage::setSource(const QUrl &url) +{ + Q_D(QmlGraphicsBorderImage); + //equality is fairly expensive, so we bypass for simple, common case + if ((d->url.isEmpty() == url.isEmpty()) && url == d->url) + return; + + if (d->sciReply) { + d->sciReply->deleteLater(); + d->sciReply = 0; + } + + if (d->pendingPixmapCache) { + QmlGraphicsPixmapCache::cancelGet(d->url, this); + d->pendingPixmapCache = false; + } + if (d->sciPendingPixmapCache) { + QmlGraphicsPixmapCache::cancelGet(d->sciurl, this); + d->sciPendingPixmapCache = false; + } + + d->url = url; + d->sciurl = QUrl(); + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } + + if (url.isEmpty()) { + d->pix = QPixmap(); + d->status = Null; + d->progress = 1.0; + setImplicitWidth(0); + setImplicitHeight(0); + emit statusChanged(d->status); + emit sourceChanged(d->url); + emit progressChanged(1.0); + update(); + } else { + d->status = Loading; + if (d->url.path().endsWith(QLatin1String(".sci"))) { +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + QString lf = toLocalFileOrQrc(d->url); + if (!lf.isEmpty()) { + QFile file(lf); + file.open(QIODevice::ReadOnly); + setGridScaledImage(QmlGraphicsGridScaledImage(&file)); + } else +#endif + { + QNetworkRequest req(d->url); + d->sciReply = qmlEngine(this)->networkAccessManager()->get(req); + QObject::connect(d->sciReply, SIGNAL(finished()), + this, SLOT(sciRequestFinished())); + } + } else { + QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->pix); + if (reply) { + d->pendingPixmapCache = true; + connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); + connect(reply, SIGNAL(downloadProgress(qint64,qint64)), + this, SLOT(requestProgress(qint64,qint64))); + } else { + //### should be unified with requestFinished + setImplicitWidth(d->pix.width()); + setImplicitHeight(d->pix.height()); + + if (d->status == Loading) + d->status = Ready; + d->progress = 1.0; + emit statusChanged(d->status); + emit sourceChanged(d->url); + emit progressChanged(1.0); + update(); + } + } + } + + emit statusChanged(d->status); +} + +/*! + \qmlproperty int BorderImage::border.left + \qmlproperty int BorderImage::border.right + \qmlproperty int BorderImage::border.top + \qmlproperty int BorderImage::border.bottom + + \target ImagexmlpropertiesscaleGrid + + The 4 border lines (2 horizontal and 2 vertical) break an image into 9 sections, as shown below: + + \image declarative-scalegrid.png + + When the image is scaled: + \list + \i the corners (sections 1, 3, 7, and 9) are not scaled at all + \i the middle (section 5) is scaled according to BorderImage::horizontalTileMode and BorderImage::verticalTileMode + \i sections 2 and 8 are scaled according to BorderImage::horizontalTileMode + \i sections 4 and 6 are scaled according to BorderImage::verticalTileMode + \endlist + + Each border line (left, right, top, and bottom) specifies an offset from the respective side. For example, \c{border.bottom: 10} sets the bottom line 10 pixels up from the bottom of the image. + + The border lines can also be specified using a + \l {BorderImage::source}{.sci file}. +*/ + +QmlGraphicsScaleGrid *QmlGraphicsBorderImage::border() +{ + Q_D(QmlGraphicsBorderImage); + return d->getScaleGrid(); +} + +/*! + \qmlproperty TileMode BorderImage::horizontalTileMode + \qmlproperty TileMode BorderImage::verticalTileMode + + This property describes how to repeat or stretch the middle parts of the border image. + + \list + \o Stretch - Scale the image to fit to the available area. + \o Repeat - Tile the image until there is no more space. May crop the last image. + \o Round - Like Repeat, but scales the images down to ensure that the last image is not cropped. + \endlist +*/ +QmlGraphicsBorderImage::TileMode QmlGraphicsBorderImage::horizontalTileMode() const +{ + Q_D(const QmlGraphicsBorderImage); + return d->horizontalTileMode; +} + +void QmlGraphicsBorderImage::setHorizontalTileMode(TileMode t) +{ + Q_D(QmlGraphicsBorderImage); + if (t != d->horizontalTileMode) { + d->horizontalTileMode = t; + emit horizontalTileModeChanged(); + update(); + } +} + +QmlGraphicsBorderImage::TileMode QmlGraphicsBorderImage::verticalTileMode() const +{ + Q_D(const QmlGraphicsBorderImage); + return d->verticalTileMode; +} + +void QmlGraphicsBorderImage::setVerticalTileMode(TileMode t) +{ + Q_D(QmlGraphicsBorderImage); + if (t != d->verticalTileMode) { + d->verticalTileMode = t; + emit verticalTileModeChanged(); + update(); + } +} + +void QmlGraphicsBorderImage::setGridScaledImage(const QmlGraphicsGridScaledImage& sci) +{ + Q_D(QmlGraphicsBorderImage); + if (!sci.isValid()) { + d->status = Error; + emit statusChanged(d->status); + } else { + QmlGraphicsScaleGrid *sg = border(); + sg->setTop(sci.gridTop()); + sg->setBottom(sci.gridBottom()); + sg->setLeft(sci.gridLeft()); + sg->setRight(sci.gridRight()); + d->horizontalTileMode = sci.horizontalTileRule(); + d->verticalTileMode = sci.verticalTileRule(); + + d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); + QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->sciurl, &d->pix); + if (reply) { + d->sciPendingPixmapCache = true; + connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); + connect(reply, SIGNAL(downloadProgress(qint64,qint64)), + this, SLOT(requestProgress(qint64,qint64))); + } else { + //### should be unified with requestFinished + setImplicitWidth(d->pix.width()); + setImplicitHeight(d->pix.height()); + + if (d->status == Loading) + d->status = Ready; + d->progress = 1.0; + emit statusChanged(d->status); + emit sourceChanged(d->url); + emit progressChanged(1.0); + update(); + } + } +} + +void QmlGraphicsBorderImage::requestFinished() +{ + Q_D(QmlGraphicsBorderImage); + + if (d->url.path().endsWith(QLatin1String(".sci"))) { + d->sciPendingPixmapCache = false; + QmlGraphicsPixmapCache::find(d->sciurl, &d->pix); + } else { + d->pendingPixmapCache = false; + if (!QmlGraphicsPixmapCache::find(d->url, &d->pix)) + d->status = Error; + } + setImplicitWidth(d->pix.width()); + setImplicitHeight(d->pix.height()); + + if (d->status == Loading) + d->status = Ready; + d->progress = 1.0; + emit statusChanged(d->status); + emit sourceChanged(d->url); + emit progressChanged(1.0); + update(); +} + +void QmlGraphicsBorderImage::sciRequestFinished() +{ + Q_D(QmlGraphicsBorderImage); + if (d->sciReply->error() != QNetworkReply::NoError) { + d->status = Error; + d->sciReply->deleteLater(); + d->sciReply = 0; + emit statusChanged(d->status); + } else { + QmlGraphicsGridScaledImage sci(d->sciReply); + d->sciReply->deleteLater(); + d->sciReply = 0; + setGridScaledImage(sci); + } +} + +void QmlGraphicsBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + Q_D(QmlGraphicsBorderImage); + if (d->pix.isNull()) + return; + + bool oldAA = p->testRenderHint(QPainter::Antialiasing); + bool oldSmooth = p->testRenderHint(QPainter::SmoothPixmapTransform); + if (d->smooth) + p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); + + QMargins margins(border()->top(), border()->left(), border()->bottom(), border()->right()); + QTileRules rules((Qt::TileRule)d->horizontalTileMode, (Qt::TileRule)d->verticalTileMode); + qDrawBorderPixmap(p, QRect(0, 0, (int)d->width, (int)d->height), margins, d->pix, d->pix.rect(), margins, rules); + if (d->smooth) { + p->setRenderHint(QPainter::Antialiasing, oldAA); + p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); + } +} + +QmlGraphicsBorderImage::QmlGraphicsBorderImage(QmlGraphicsBorderImagePrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsImageBase(dd, parent) +{ + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsborderimage.h b/src/declarative/fx/qmlgraphicsborderimage.h new file mode 100644 index 0000000..e3c50bb --- /dev/null +++ b/src/declarative/fx/qmlgraphicsborderimage.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSBORDERIMAGE_H +#define QMLGRAPHICSBORDERIMAGE_H + +#include +#include "qmlgraphicsimagebase.h" + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsScaleGrid; +class QmlGraphicsGridScaledImage; +class QmlGraphicsBorderImagePrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsBorderImage : public QmlGraphicsImageBase +{ + Q_OBJECT + Q_ENUMS(TileMode) + + Q_PROPERTY(QmlGraphicsScaleGrid *border READ border CONSTANT) + Q_PROPERTY(TileMode horizontalTileMode READ horizontalTileMode WRITE setHorizontalTileMode NOTIFY horizontalTileModeChanged) + Q_PROPERTY(TileMode verticalTileMode READ verticalTileMode WRITE setVerticalTileMode NOTIFY verticalTileModeChanged) + +public: + QmlGraphicsBorderImage(QmlGraphicsItem *parent=0); + ~QmlGraphicsBorderImage(); + + QmlGraphicsScaleGrid *border(); + + enum TileMode { Stretch = Qt::StretchTile, Repeat = Qt::RepeatTile, Round = Qt::RoundTile }; + + TileMode horizontalTileMode() const; + void setHorizontalTileMode(TileMode); + + TileMode verticalTileMode() const; + void setVerticalTileMode(TileMode); + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + void setSource(const QUrl &url); + +Q_SIGNALS: + void horizontalTileModeChanged(); + void verticalTileModeChanged(); + +protected: + QmlGraphicsBorderImage(QmlGraphicsBorderImagePrivate &dd, QmlGraphicsItem *parent); + +private: + void setGridScaledImage(const QmlGraphicsGridScaledImage& sci); + +private Q_SLOTS: + void requestFinished(); + void sciRequestFinished(); + +private: + Q_DISABLE_COPY(QmlGraphicsBorderImage) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsBorderImage) +}; + +QT_END_NAMESPACE +QML_DECLARE_TYPE(QmlGraphicsBorderImage) +QT_END_HEADER + +#endif // QMLGRAPHICSBORDERIMAGE_H diff --git a/src/declarative/fx/qmlgraphicsborderimage_p.h b/src/declarative/fx/qmlgraphicsborderimage_p.h new file mode 100644 index 0000000..fb905cd --- /dev/null +++ b/src/declarative/fx/qmlgraphicsborderimage_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSBORDERIMAGE_P_H +#define QMLGRAPHICSBORDERIMAGE_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 "qmlgraphicsimagebase_p.h" +#include "qmlgraphicsscalegrid_p.h" + +QT_BEGIN_NAMESPACE + +class QNetworkReply; +class QmlGraphicsBorderImagePrivate : public QmlGraphicsImageBasePrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsBorderImage) + +public: + QmlGraphicsBorderImagePrivate() + : border(0), sciReply(0), + sciPendingPixmapCache(false), + horizontalTileMode(QmlGraphicsBorderImage::Stretch), + verticalTileMode(QmlGraphicsBorderImage::Stretch) + { + } + + ~QmlGraphicsBorderImagePrivate() + { + } + + QmlGraphicsScaleGrid *getScaleGrid() + { + Q_Q(QmlGraphicsBorderImage); + if (!border) + border = new QmlGraphicsScaleGrid(q); + return border; + } + + QmlGraphicsScaleGrid *border; + QUrl sciurl; + QNetworkReply *sciReply; + bool sciPendingPixmapCache; + QmlGraphicsBorderImage::TileMode horizontalTileMode; + QmlGraphicsBorderImage::TileMode verticalTileMode; +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSBORDERIMAGE_P_H diff --git a/src/declarative/fx/qmlgraphicseffects.cpp b/src/declarative/fx/qmlgraphicseffects.cpp new file mode 100644 index 0000000..ebdd880 --- /dev/null +++ b/src/declarative/fx/qmlgraphicseffects.cpp @@ -0,0 +1,238 @@ +#include +#include +#include + +QML_DECLARE_TYPE(QGraphicsEffect) +QML_DEFINE_NOCREATE_TYPE(QGraphicsEffect) + +QML_DECLARE_TYPE(QGraphicsBlurEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Blur,QGraphicsBlurEffect) + +/*! + \qmlclass Blur + \brief The Blur object provides a blur effect. + + A blur effect blurs the source item. This effect is useful for reducing details, + such as when the source loses focus and you want to draw attention to other + elements. The level of detail can be modified using the blurRadius property. + Use blurHint to choose the quality or performance blur hints. + + By default, the blur radius is 5 pixels. + + \img graphicseffect-blur.png +*/ + +/*! + \qmlproperty real Blur::blurRadius + + blurRadius controls how blurry an item will appear. + Using a smaller radius results in a sharper appearance, whereas a bigger + radius results in a more blurred appearance. + + By default, the blur radius is 5 pixels. +*/ +/*! + \qmlproperty enumeration Blur::blurHint + + Use the Qt.PerformanceHint hint to say that you want a faster blur, + and the Qt.QualityHint hint to say that you prefer a higher quality blur. + + When animating the blur radius it's recommended to use Qt.PerformanceHint. + + By default, the blur hint is Qt.PerformanceHint. +*/ + +QML_DECLARE_TYPE(QGraphicsGrayscaleEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Grayscale,QGraphicsGrayscaleEffect) + +/*! + \qmlclass Grayscale + \brief The Grayscale object provides a grayscale effect. + + A grayscale effect renders the source item in shades of gray. + + \img graphicseffect-grayscale.png +*/ + +/*! + \qmlproperty real Grayscale::strength + + To what extent the source item is "grayed". A strength of 0.0 is equal to no effect, + while 1.0 means full grayscale. By default, the strength is 1.0. +*/ + +QML_DECLARE_TYPE(QGraphicsColorizeEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Colorize,QGraphicsColorizeEffect) + +/*! + \qmlclass Colorize + \brief The Colorize object provides a colorize effect. + + A colorize effect renders the source item with a tint of its color. + + By default, the color is light blue. + + \img graphicseffect-colorize.png +*/ + +/*! + \qmlproperty color Colorize::color + The color of the effect. + + By default, the color is light blue. +*/ + +/*! + \qmlproperty real Colorize::strength + + To what extent the source item is "colored". A strength of 0.0 is equal to no effect, + while 1.0 means full colorization. By default, the strength is 1.0. +*/ + +QML_DECLARE_TYPE(QGraphicsPixelizeEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pixelize,QGraphicsPixelizeEffect) + +/*! + \qmlclass Pixelize + \brief The Pixelize object provides a pixelize effect. + + A pixelize effect renders the source item in lower resolution. The resolution + can be modified using the pixelSize property. + + By default, the pixel size is 3. + + \img graphicseffect-pixelize.png +*/ + +/*! + \qmlproperty int Pixelize::pixelSize + The size of a pixel in the effect. + + Setting the pixel size to 2 means two pixels in the source item will be used to + represent one pixel in the output. Using a bigger size results in lower resolution. + + By default, the pixel size is 3. +*/ + + +QML_DECLARE_TYPE(QGraphicsDropShadowEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,DropShadow,QGraphicsDropShadowEffect) + +/*! + \qmlclass DropShadow + \brief The DropShadow object provides a drop shadow effect. + + A drop shadow effect renders the source item with a drop shadow. The color of + the drop shadow can be modified using the color property. The drop + shadow offset can be modified using the xOffset and yOffset properties and the blur + radius of the drop shadow can be changed with the blurRadius property. + + By default, the drop shadow is a semi-transparent dark gray shadow, + blurred with a radius of 1 at an offset of 8 pixels towards the lower right. + + \img graphicseffect-drop-shadow.png +*/ + +/*! + \qmlproperty real DropShadow::xOffset + \qmlproperty real DropShadow::yOffset + The shadow offset in pixels. + + By default, xOffset and yOffset are 8 pixels. +*/ + +/*! + \qmlproperty real DropShadow::blurRadius + The blur radius in pixels of the drop shadow. + + Using a smaller radius results in a sharper shadow, whereas using a bigger + radius results in a more blurred shadow. + + By default, the blur radius is 1 pixel. +*/ + +/*! + \qmlproperty color DropShadow::color + The color of the drop shadow. + + By default, the drop color is a semi-transparent dark gray. +*/ + +QML_DECLARE_TYPE(QGraphicsOpacityEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Opacity,QGraphicsOpacityEffect) + +/*! + \qmlclass Opacity + \brief The Opacity object provides an opacity effect. + + An opacity effect renders the source with an opacity. This effect is useful + for making the source semi-transparent, similar to a fade-in/fade-out + sequence. The opacity can be modified using the opacity property. + + By default, the opacity is 0.7. + + \img graphicseffect-opacity.png +*/ + +/*! + \qmlproperty real Opacity::opacity + This property specifies how opaque an item should appear. + + The value should be in the range of 0.0 to 1.0, where 0.0 is + fully transparent and 1.0 is fully opaque. + + By default, the opacity is 0.7. +*/ + +QML_DECLARE_TYPE(QGraphicsBloomEffect) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Bloom,QGraphicsBloomEffect) + +/*! + \qmlclass Bloom + \brief The Bloom object provides a bloom/glow effect. + + A bloom/glow effect adds fringes of light around bright areas in the source item. + + \img graphicseffect-bloom.png +*/ + +/*! + \qmlproperty real Bloom::blurRadius + The blur radius in pixels of the effect. + + Using a smaller radius results in a sharper appearance, whereas a bigger + radius results in a more blurred appearance. + + By default, the blur radius is 5 pixels. +*/ + +/*! + \qmlproperty enumeration Bloom::blurHint + + Use the Qt.PerformanceHint hint to say that you want a faster blur, + and the Qt.QualityHint hint to say that you prefer a higher quality blur. + + When animating the blur radius it's recommended to use Qt.PerformanceHint. + + By default, the blur hint is Qt.PerformanceHint. +*/ + +/*! + \qmlproperty int Bloom::brightness + This property specifies how bright the glow should appear. + + The value should be in the range of 0 to 255, where 0 is dark + and 255 is bright. + + By default, the brightness is 70. +*/ + +/*! + \qmlproperty real Bloom::strength + The strength of the glow. + + A strength of 0.0 is equal to no effect, while 1.0 means maximum glow. + + By default, the strength is 0.7. +*/ + diff --git a/src/declarative/fx/qmlgraphicsevents.cpp b/src/declarative/fx/qmlgraphicsevents.cpp new file mode 100644 index 0000000..468b223 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsevents.cpp @@ -0,0 +1,195 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsevents_p.h" + +QT_BEGIN_NAMESPACE +/*! + \qmlclass KeyEvent QmlGraphicsKeyEvent + \brief The KeyEvent object provides information about a key event. + + For example, the following changes the Item's state property when the Enter + key is pressed: + \qml +Item { + focus: true + Keys.onPressed: { if (event.key == Qt.Key_Enter) state = 'ShowDetails'; } +} + \endqml +*/ + +/*! + \internal + \class QmlGraphicsKeyEvent +*/ + +/*! + \qmlproperty int KeyEvent::key + + This property holds the code of the key that was pressed or released. + + See \l {Qt::Key}{Qt.Key} for the list of keyboard codes. These codes are + independent of the underlying window system. Note that this + function does not distinguish between capital and non-capital + letters, use the text() function (returning the Unicode text the + key generated) for this purpose. + + A value of either 0 or \l {Qt::Key_unknown}{Qt.Key_Unknown} means that the event is not + the result of a known key; for example, it may be the result of + a compose sequence, a keyboard macro, or due to key event + compression. +*/ + +/*! + \qmlproperty string KeyEvent::text + + This property holds the Unicode text that the key generated. + The text returned can be an empty string in cases where modifier keys, + such as Shift, Control, Alt, and Meta, are being pressed or released. + In such cases \c key will contain a valid value +*/ + +/*! + \qmlproperty bool KeyEvent::isAutoRepeat + + This property holds whether this event comes from an auto-repeating key. +*/ + +/*! + \qmlproperty int KeyEvent::count + + This property holds the number of keys involved in this event. If \l KeyEvent::text + is not empty, this is simply the length of the string. +*/ + +/*! + \qmlproperty bool KeyEvent::accepted + + Setting \a accepted to true prevents the key event from being + propagated to the item's parent. + + Generally, if the item acts on the key event then it should be accepted + so that ancestor items do not also respond to the same event. +*/ + + +/*! + \qmlclass MouseEvent QmlGraphicsMouseEvent + \brief The MouseEvent object provides information about a mouse event. + + The position of the mouse can be found via the x and y properties. + The button that caused the event is available via the button property. +*/ + +/*! + \internal + \class QmlGraphicsMouseEvent +*/ + +/*! + \qmlproperty int MouseEvent::x + \qmlproperty int MouseEvent::y + + These properties hold the position of the mouse event. +*/ + +/*! + \qmlproperty enum MouseEvent::button + + This property holds the button that caused the event. It can be one of: + \list + \o Qt.LeftButton + \o Qt.RightButton + \o Qt.MidButton + \endlist +*/ + +/*! + \qmlproperty bool MouseEvent::wasHeld + + This property is true if the mouse button has been held pressed longer the + threshold (800ms). +*/ + +/*! + \qmlproperty int MouseEvent::buttons + + This property holds the mouse buttons pressed when the event was generated. + For mouse move events, this is all buttons that are pressed down. For mouse + press and double click events this includes the button that caused the event. + For mouse release events this excludes the button that caused the event. + + It contains a bitwise combination of: + \list + \o Qt.LeftButton + \o Qt.RightButton + \o Qt.MidButton + \endlist +*/ + +/*! + \qmlproperty int MouseEvent::modifiers + + This property holds the keyboard modifier flags that existed immediately + before the event occurred. + + It contains a bitwise combination of: + \list + \o Qt.NoModifier - No modifier key is pressed. + \o Qt.ShiftModifier - A Shift key on the keyboard is pressed. + \o Qt.ControlModifier - A Ctrl key on the keyboard is pressed. + \o Qt.AltModifier - An Alt key on the keyboard is pressed. + \o Qt.MetaModifier - A Meta key on the keyboard is pressed. + \o Qt.KeypadModifier - A keypad button is pressed. + \endlist + + For example, to react to a Shift key + Left mouse button click: + \qml +MouseRegion { + onClicked: { if (mouse.button == Qt.LeftButton && mouse.modifiers & Qt.ShiftModifier) doSomething(); } +} + \endqml +*/ + +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsKeyEvent) +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsMouseEvent) + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsevents_p.h b/src/declarative/fx/qmlgraphicsevents_p.h new file mode 100644 index 0000000..f093932 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsevents_p.h @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSEVENTS_P_H +#define QMLGRAPHICSEVENTS_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 +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlGraphicsKeyEvent : public QObject +{ + Q_OBJECT + Q_PROPERTY(int key READ key) + Q_PROPERTY(QString text READ text) + Q_PROPERTY(int modifiers READ modifiers) + Q_PROPERTY(bool isAutoRepeat READ isAutoRepeat) + Q_PROPERTY(int count READ count) + Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) + +public: + QmlGraphicsKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text=QString(), bool autorep=false, ushort count=1) + : event(type, key, modifiers, text, autorep, count) { event.setAccepted(false); } + QmlGraphicsKeyEvent(const QKeyEvent &ke) + : event(ke) { event.setAccepted(false); } + + int key() const { return event.key(); } + QString text() const { return event.text(); } + int modifiers() const { return event.modifiers(); } + bool isAutoRepeat() const { return event.isAutoRepeat(); } + int count() const { return event.count(); } + + bool isAccepted() { return event.isAccepted(); } + void setAccepted(bool accepted) { event.setAccepted(accepted); } + +private: + QKeyEvent event; +}; + +class QmlGraphicsMouseEvent : public QObject +{ + Q_OBJECT + Q_PROPERTY(int x READ x) + Q_PROPERTY(int y READ y) + Q_PROPERTY(int button READ button) + Q_PROPERTY(int buttons READ buttons) + Q_PROPERTY(int modifiers READ modifiers) + Q_PROPERTY(bool wasHeld READ wasHeld) + Q_PROPERTY(bool isClick READ isClick) + Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) + +public: + QmlGraphicsMouseEvent(int x, int y, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers + , bool isClick=false, bool wasHeld=false) + : _x(x), _y(y), _button(button), _buttons(buttons), _modifiers(modifiers) + , _wasHeld(wasHeld), _isClick(isClick), _accepted(true) {} + + int x() const { return _x; } + int y() const { return _y; } + int button() const { return _button; } + int buttons() const { return _buttons; } + int modifiers() const { return _modifiers; } + bool wasHeld() const { return _wasHeld; } + bool isClick() const { return _isClick; } + + bool isAccepted() { return _accepted; } + void setAccepted(bool accepted) { _accepted = accepted; } + +private: + int _x; + int _y; + Qt::MouseButton _button; + Qt::MouseButtons _buttons; + Qt::KeyboardModifiers _modifiers; + bool _wasHeld; + bool _isClick; + bool _accepted; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsKeyEvent) +QML_DECLARE_TYPE(QmlGraphicsMouseEvent) + +#endif // QMLGRAPHICSEVENTS_P_H diff --git a/src/declarative/fx/qmlgraphicsflickable.cpp b/src/declarative/fx/qmlgraphicsflickable.cpp new file mode 100644 index 0000000..ed964aa --- /dev/null +++ b/src/declarative/fx/qmlgraphicsflickable.cpp @@ -0,0 +1,1283 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsflickable.h" +#include "qmlgraphicsflickable_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + + +// These are highly device dependant. +// DragThreshold determines how far the "mouse" must move before +// we begin a drag. +// FlickThreshold determines how far the "mouse" must have moved +// before we perform a flick. +static const int DragThreshold = 8; +static const int FlickThreshold = 20; + +// Really slow flicks can be annoying. +static const int minimumFlickVelocity = 200; + +class QmlGraphicsFlickableVisibleArea : public QObject +{ + Q_OBJECT + + Q_PROPERTY(qreal xPosition READ xPosition NOTIFY pageChanged) + Q_PROPERTY(qreal yPosition READ yPosition NOTIFY pageChanged) + Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY pageChanged) + Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY pageChanged) + +public: + QmlGraphicsFlickableVisibleArea(QmlGraphicsFlickable *parent=0); + + qreal xPosition() const; + qreal widthRatio() const; + qreal yPosition() const; + qreal heightRatio() const; + + void updateVisible(); + +signals: + void pageChanged(); + +private: + QmlGraphicsFlickable *flickable; + qreal m_xPosition; + qreal m_widthRatio; + qreal m_yPosition; + qreal m_heightRatio; +}; + +QmlGraphicsFlickableVisibleArea::QmlGraphicsFlickableVisibleArea(QmlGraphicsFlickable *parent) + : QObject(parent), flickable(parent), m_xPosition(0.), m_widthRatio(0.) + , m_yPosition(0.), m_heightRatio(0.) +{ +} + +qreal QmlGraphicsFlickableVisibleArea::widthRatio() const +{ + return m_widthRatio; +} + +qreal QmlGraphicsFlickableVisibleArea::xPosition() const +{ + return m_xPosition; +} + +qreal QmlGraphicsFlickableVisibleArea::heightRatio() const +{ + return m_heightRatio; +} + +qreal QmlGraphicsFlickableVisibleArea::yPosition() const +{ + return m_yPosition; +} + +void QmlGraphicsFlickableVisibleArea::updateVisible() +{ + QmlGraphicsFlickablePrivate *p = static_cast(QGraphicsItemPrivate::get(flickable)); + bool pageChange = false; + + // Vertical + const qreal viewheight = flickable->height(); + const qreal maxyextent = -flickable->maxYExtent(); + qreal pagePos = -p->_moveY.value() / (maxyextent + viewheight); + qreal pageSize = viewheight / (maxyextent + viewheight); + + if (pageSize != m_heightRatio) { + m_heightRatio = pageSize; + pageChange = true; + } + if (pagePos != m_yPosition) { + m_yPosition = pagePos; + pageChange = true; + } + + // Horizontal + const qreal viewwidth = flickable->width(); + const qreal maxxextent = -flickable->maxXExtent(); + pagePos = -p->_moveX.value() / (maxxextent + viewwidth); + pageSize = viewwidth / (maxxextent + viewwidth); + + if (pageSize != m_widthRatio) { + m_widthRatio = pageSize; + pageChange = true; + } + if (pagePos != m_xPosition) { + m_xPosition = pagePos; + pageChange = true; + } + if (pageChange) + emit pageChanged(); +} + + +QmlGraphicsFlickablePrivate::QmlGraphicsFlickablePrivate() + : viewport(new QmlGraphicsItem), _moveX(viewport, &QmlGraphicsItem::setX), _moveY(viewport, &QmlGraphicsItem::setY) + , vWidth(-1), vHeight(-1), overShoot(true), flicked(false), moving(false), stealMouse(false) + , pressed(false), atXEnd(false), atXBeginning(true), atYEnd(false), atYBeginning(true) + , interactive(true), deceleration(500), maxVelocity(5000), reportedVelocitySmoothing(100) + , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0) + , horizontalVelocity(this), verticalVelocity(this), vTime(0), visibleArea(0) +{ + fixupXEvent = QmlTimeLineEvent::timeLineEvent(&_moveX, this); + fixupYEvent = QmlTimeLineEvent::timeLineEvent(&_moveY, this); +} + +void QmlGraphicsFlickablePrivate::init() +{ + Q_Q(QmlGraphicsFlickable); + viewport->setParent(q); + QObject::connect(&timeline, SIGNAL(updated()), q, SLOT(ticked())); + QObject::connect(&timeline, SIGNAL(completed()), q, SLOT(movementEnding())); + q->setAcceptedMouseButtons(Qt::LeftButton); + q->setFiltersChildEvents(true); + QObject::connect(viewport, SIGNAL(xChanged()), q, SIGNAL(positionXChanged())); + QObject::connect(viewport, SIGNAL(yChanged()), q, SIGNAL(positionYChanged())); + QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(heightChange())); + QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(widthChange())); +} + +void QmlGraphicsFlickablePrivate::flickX(qreal velocity) +{ + Q_Q(QmlGraphicsFlickable); + qreal maxDistance = -1; + if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. + velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; + // -ve velocity means list is moving up + if (velocity > 0) { + if (_moveX.value() < q->minXExtent()) + maxDistance = qAbs(q->minXExtent() -_moveX.value() + (overShoot?30:0)); + flickTargetX = q->minXExtent(); + } else { + if (_moveX.value() > q->maxXExtent()) + maxDistance = qAbs(q->maxXExtent() - _moveX.value()) + (overShoot?30:0); + flickTargetX = q->maxXExtent(); + } + if (maxDistance > 0) { + qreal v = velocity; + if (maxVelocity != -1 && maxVelocity < qAbs(v)) { + if (v < 0) + v = -maxVelocity; + else + v = maxVelocity; + } + timeline.reset(_moveX); + timeline.accel(_moveX, v, deceleration, maxDistance); + timeline.execute(fixupXEvent); + if (!flicked) { + flicked = true; + emit q->flickingChanged(); + emit q->flickStarted(); + } + } else { + timeline.reset(_moveX); + fixupX(); + } +} + +void QmlGraphicsFlickablePrivate::flickY(qreal velocity) +{ + Q_Q(QmlGraphicsFlickable); + qreal maxDistance = -1; + // -ve velocity means list is moving up + if (velocity > 0) { + if (_moveY.value() < q->minYExtent()) + maxDistance = qAbs(q->minYExtent() -_moveY.value() + (overShoot?30:0)); + flickTargetY = q->minYExtent(); + } else { + if (_moveY.value() > q->maxYExtent()) + maxDistance = qAbs(q->maxYExtent() - _moveY.value()) + (overShoot?30:0); + flickTargetY = q->maxYExtent(); + } + if (maxDistance > 0) { + qreal v = velocity; + if (maxVelocity != -1 && maxVelocity < qAbs(v)) { + if (v < 0) + v = -maxVelocity; + else + v = maxVelocity; + } + timeline.reset(_moveY); + timeline.accel(_moveY, v, deceleration, maxDistance); + timeline.execute(fixupYEvent); + if (!flicked) { + flicked = true; + emit q->flickingChanged(); + emit q->flickStarted(); + } + } else { + timeline.reset(_moveY); + fixupY(); + } +} + +void QmlGraphicsFlickablePrivate::fixupX() +{ + Q_Q(QmlGraphicsFlickable); + if (!q->xflick() || _moveX.timeLine()) + return; + + vTime = timeline.time(); + + if (_moveX.value() > q->minXExtent() || (q->maxXExtent() > q->minXExtent())) { + timeline.reset(_moveX); + if (_moveX.value() != q->minXExtent()) + timeline.move(_moveX, q->minXExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); + //emit flickingChanged(); + } else if (_moveX.value() < q->maxXExtent()) { + timeline.reset(_moveX); + timeline.move(_moveX, q->maxXExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); + //emit flickingChanged(); + } else { + flicked = false; + } +} + +void QmlGraphicsFlickablePrivate::fixupY() +{ + Q_Q(QmlGraphicsFlickable); + if (!q->yflick() || _moveY.timeLine()) + return; + + vTime = timeline.time(); + + if (_moveY.value() > q->minYExtent() || (q->maxYExtent() > q->minYExtent())) { + timeline.reset(_moveY); + if (_moveY.value() != q->minYExtent()) + timeline.move(_moveY, q->minYExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); + //emit flickingChanged(); + } else if (_moveY.value() < q->maxYExtent()) { + timeline.reset(_moveY); + timeline.move(_moveY, q->maxYExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); + //emit flickingChanged(); + } else { + flicked = false; + } +} + +void QmlGraphicsFlickablePrivate::updateBeginningEnd() +{ + Q_Q(QmlGraphicsFlickable); + bool atBoundaryChange = false; + + // Vertical + const int maxyextent = int(-q->maxYExtent()); + const qreal ypos = -_moveY.value(); + bool atBeginning = (ypos <= 0.0); + bool atEnd = (maxyextent <= ypos); + + if (atBeginning != atYBeginning) { + atYBeginning = atBeginning; + atBoundaryChange = true; + } + if (atEnd != atYEnd) { + atYEnd = atEnd; + atBoundaryChange = true; + } + + // Horizontal + const int maxxextent = int(-q->maxXExtent()); + const qreal xpos = -_moveX.value(); + atBeginning = (xpos <= 0.0); + atEnd = (maxxextent <= xpos); + + if (atBeginning != atXBeginning) { + atXBeginning = atBeginning; + atBoundaryChange = true; + } + if (atEnd != atXEnd) { + atXEnd = atEnd; + atBoundaryChange = true; + } + + if (atBoundaryChange) + emit q->isAtBoundaryChanged(); + + if (visibleArea) + visibleArea->updateVisible(); +} + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flickable,QmlGraphicsFlickable) + +/*! + \qmlclass Flickable + \brief The Flickable item provides a surface that can be "flicked". + \inherits Item + + Flickable places its children on a surface that can be dragged and flicked. + + \code + Flickable { + width: 200; height: 200; viewportWidth: image.width; viewportHeight: image.height + Image { id: image; source: "bigimage.png" } + } + \endcode + + \image flickable.gif + + \note Flickable does not automatically clip its contents. If + it is not full-screen it is likely that \c clip should be set + to true. + + \note Due to an implementation detail items placed inside a flickable cannot anchor to it by + id, use 'parent' instead. +*/ + +/*! + \internal + \class QmlGraphicsFlickable + \brief The QmlGraphicsFlickable class provides a view that can be "flicked". + + \ingroup group_widgets + + QmlGraphicsFlickable allows its children to be dragged and flicked. + +\code +Flickable { + width: 320; height: 480; viewportWidth: image.width; viewportHeight: image.height + Image { id: image; source: "bigimage.png" } +} +\endcode + + Note that QmlGraphicsFlickable does not automatically clip its contents. If + it is not full-screen it is likely that QmlGraphicsItem::clip should be set + to true. + +*/ + +/*! + \qmlproperty real Flickable::visibleArea.xPosition + \qmlproperty real Flickable::visibleArea.widthRatio + \qmlproperty real Flickable::visibleArea.yPosition + \qmlproperty real Flickable::visibleArea.heightRatio + + These properties describe the position and size of the currently viewed area. + The size is defined as the percentage of the full view currently visible, + scaled to 0.0 - 1.0. The page position is in the range 0.0 (beginning) to + size ratio (end), i.e. yPosition is in the range 0.0 - heightRatio. + + These properties are typically used to draw a scrollbar, for example: + \code + Rectangle { + opacity: 0.5; anchors.right: MyListView.right-2; width: 6 + y: MyListView.visibleArea.yPosition * MyListView.height + height: MyListView.visibleArea.heightRatio * MyListView.height + } + \endcode +*/ + +QmlGraphicsFlickable::QmlGraphicsFlickable(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsFlickablePrivate), parent) +{ + Q_D(QmlGraphicsFlickable); + d->init(); +} + +QmlGraphicsFlickable::QmlGraphicsFlickable(QmlGraphicsFlickablePrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ + Q_D(QmlGraphicsFlickable); + d->init(); +} + +QmlGraphicsFlickable::~QmlGraphicsFlickable() +{ +} + +/*! + \qmlproperty int Flickable::viewportX + \qmlproperty int Flickable::viewportY + + These properties hold the surface coordinate currently at the top-left + corner of the Flickable. For example, if you flick an image up 100 pixels, + \c yPosition will be 100. +*/ +qreal QmlGraphicsFlickable::viewportX() const +{ + Q_D(const QmlGraphicsFlickable); + return -d->_moveX.value(); +} + +void QmlGraphicsFlickable::setViewportX(qreal pos) +{ + Q_D(QmlGraphicsFlickable); + pos = qRound(pos); + d->timeline.reset(d->_moveX); + if (-pos != d->_moveX.value()) { + d->_moveX.setValue(-pos); + viewportMoved(); + } +} + +qreal QmlGraphicsFlickable::viewportY() const +{ + Q_D(const QmlGraphicsFlickable); + return -d->_moveY.value(); +} + +void QmlGraphicsFlickable::setViewportY(qreal pos) +{ + Q_D(QmlGraphicsFlickable); + pos = qRound(pos); + d->timeline.reset(d->_moveY); + if (-pos != d->_moveY.value()) { + d->_moveY.setValue(-pos); + viewportMoved(); + } +} + +/*! + \qmlproperty bool Flickable::interactive + + A user cannot drag or flick a Flickable that is not interactive. + + This property is useful for temporarily disabling flicking. This allows + special interaction with Flickable's children: for example, you might want to + freeze a flickable map while viewing detailed information on a location popup that is a child of the Flickable. +*/ +bool QmlGraphicsFlickable::isInteractive() const +{ + Q_D(const QmlGraphicsFlickable); + return d->interactive; +} + +void QmlGraphicsFlickable::setInteractive(bool interactive) +{ + Q_D(QmlGraphicsFlickable); + d->interactive = interactive; + if (!interactive && d->flicked) { + d->timeline.clear(); + d->flicked = false; + emit flickingChanged(); + emit flickEnded(); + } +} + +/*! + \qmlproperty real Flickable::horizontalVelocity + \qmlproperty real Flickable::verticalVelocity + \qmlproperty real Flickable::reportedVelocitySmoothing + + The instantaneous velocity of movement along the x and y axes, in pixels/sec. + + The reported velocity is smoothed to avoid erratic output. + reportedVelocitySmoothing determines how much smoothing is applied. +*/ +qreal QmlGraphicsFlickable::horizontalVelocity() const +{ + Q_D(const QmlGraphicsFlickable); + return d->horizontalVelocity.value(); +} + +qreal QmlGraphicsFlickable::verticalVelocity() const +{ + Q_D(const QmlGraphicsFlickable); + return d->verticalVelocity.value(); +} + +/*! + \qmlproperty bool Flickable::atXBeginning + \qmlproperty bool Flickable::atXEnd + \qmlproperty bool Flickable::atYBeginning + \qmlproperty bool Flickable::atYEnd + + These properties are true if the flickable view is positioned at the beginning, + or end respecively. +*/ +bool QmlGraphicsFlickable::isAtXEnd() const +{ + Q_D(const QmlGraphicsFlickable); + return d->atXEnd; +} + +bool QmlGraphicsFlickable::isAtXBeginning() const +{ + Q_D(const QmlGraphicsFlickable); + return d->atXBeginning; +} + +bool QmlGraphicsFlickable::isAtYEnd() const +{ + Q_D(const QmlGraphicsFlickable); + return d->atYEnd; +} + +bool QmlGraphicsFlickable::isAtYBeginning() const +{ + Q_D(const QmlGraphicsFlickable); + return d->atYBeginning; +} + +void QmlGraphicsFlickable::ticked() +{ + viewportMoved(); +} + +QmlGraphicsItem *QmlGraphicsFlickable::viewport() +{ + Q_D(QmlGraphicsFlickable); + return d->viewport; +} + +qreal QmlGraphicsFlickable::visibleX() const +{ + Q_D(const QmlGraphicsFlickable); + return -d->_moveX.value(); +} + +qreal QmlGraphicsFlickable::visibleY() const +{ + Q_D(const QmlGraphicsFlickable); + return -d->_moveY.value(); +} + +QmlGraphicsFlickableVisibleArea *QmlGraphicsFlickable::visibleArea() +{ + Q_D(QmlGraphicsFlickable); + if (!d->visibleArea) + d->visibleArea = new QmlGraphicsFlickableVisibleArea(this); + return d->visibleArea; +} + +void QmlGraphicsFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if (interactive && timeline.isActive() && (qAbs(velocityX) > 10 || qAbs(velocityY) > 10)) + stealMouse = true; // If we've been flicked then steal the click. + else + stealMouse = false; + pressed = true; + timeline.clear(); + velocityX = 0; + velocityY = 0; + lastPos = QPoint(); + QmlGraphicsItemPrivate::start(lastPosTime); + pressPos = event->pos(); + pressX = _moveX.value(); + pressY = _moveY.value(); + flicked = false; + QmlGraphicsItemPrivate::start(pressTime); + QmlGraphicsItemPrivate::start(velocityTime); +} + +void QmlGraphicsFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + Q_Q(QmlGraphicsFlickable); + if (!interactive || lastPosTime.isNull()) + return; + bool rejectY = false; + bool rejectX = false; + bool moved = false; + + if (q->yflick()) { + int dy = int(event->pos().y() - pressPos.y()); + if (qAbs(dy) > DragThreshold || QmlGraphicsItemPrivate::elapsed(pressTime) > 200) { + qreal newY = dy + pressY; + const qreal minY = q->minYExtent(); + const qreal maxY = q->maxYExtent(); + if (newY > minY) + newY = minY + (newY - minY) / 2; + if (newY < maxY && maxY - minY < 0) + newY = maxY + (newY - maxY) / 2; + if (!q->overShoot() && (newY > minY || newY < maxY)) { + if (newY > minY) + newY = minY; + else if (newY < maxY) + newY = maxY; + else + rejectY = true; + } + if (!rejectY) { + _moveY.setValue(newY); + moved = true; + } + if (qAbs(dy) > DragThreshold) + stealMouse = true; + } + } + + if (q->xflick()) { + int dx = int(event->pos().x() - pressPos.x()); + if (qAbs(dx) > DragThreshold || QmlGraphicsItemPrivate::elapsed(pressTime) > 200) { + qreal newX = dx + pressX; + const qreal minX = q->minXExtent(); + const qreal maxX = q->maxXExtent(); + if (newX > minX) + newX = minX + (newX - minX) / 2; + if (newX < maxX && maxX - minX < 0) + newX = maxX + (newX - maxX) / 2; + if (!q->overShoot() && (newX > minX || newX < maxX)) { + if (newX > minX) + newX = minX; + else if (newX < maxX) + newX = maxX; + else + rejectX = true; + } + if (!rejectX) { + _moveX.setValue(newX); + moved = true; + } + + if (qAbs(dx) > DragThreshold) + stealMouse = true; + } + } + + if (!lastPos.isNull()) { + qreal elapsed = qreal(QmlGraphicsItemPrivate::restart(lastPosTime)) / 1000.; + if (elapsed <= 0) + elapsed = 1; + if (q->yflick()) { + qreal diff = event->pos().y() - lastPos.y(); + // average to reduce the effect of spurious moves + velocityY += diff / elapsed; + velocityY /= 2; + } + + if (q->xflick()) { + qreal diff = event->pos().x() - lastPos.x(); + // average to reduce the effect of spurious moves + velocityX += diff / elapsed; + velocityX /= 2; + } + } + + if (rejectY) velocityY = 0; + if (rejectX) velocityX = 0; + + if (moved) { + q->movementStarting(); + q->viewportMoved(); + } + + lastPos = event->pos(); +} + +void QmlGraphicsFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + Q_Q(QmlGraphicsFlickable); + pressed = false; + if (lastPosTime.isNull()) + return; + + if (QmlGraphicsItemPrivate::elapsed(lastPosTime) > 100) { + // if we drag then pause before release we should not cause a flick. + velocityX = 0.0; + velocityY = 0.0; + } + + vTime = timeline.time(); + if (qAbs(velocityY) > 10 && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) { + qreal velocity = velocityY; + if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. + velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; + flickY(velocity); + } else { + fixupY(); + } + + if (qAbs(velocityX) > 10 && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) { + qreal velocity = velocityX; + if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. + velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; + flickX(velocity); + } else { + fixupX(); + } + + stealMouse = false; + lastPosTime = QTime(); + + if (!timeline.isActive()) + q->movementEnding(); +} + +void QmlGraphicsFlickable::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsFlickable); + d->handleMousePressEvent(event); + event->accept(); +} + +void QmlGraphicsFlickable::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsFlickable); + d->handleMouseMoveEvent(event); + event->accept(); +} + +void QmlGraphicsFlickable::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsFlickable); + d->clearDelayedPress(); + d->handleMouseReleaseEvent(event); + event->accept(); + ungrabMouse(); +} + +void QmlGraphicsFlickablePrivate::captureDelayedPress(QGraphicsSceneMouseEvent *event) +{ + Q_Q(QmlGraphicsFlickable); + if (!q->scene() || pressDelay <= 0) + return; + delayedPressTarget = q->scene()->mouseGrabberItem(); + delayedPressEvent = new QGraphicsSceneMouseEvent(event->type()); + delayedPressEvent->setAccepted(false); + for (int i = 0x1; i <= 0x10; i <<= 1) { + if (event->buttons() & i) { + Qt::MouseButton button = Qt::MouseButton(i); + delayedPressEvent->setButtonDownPos(button, event->buttonDownPos(button)); + delayedPressEvent->setButtonDownScenePos(button, event->buttonDownScenePos(button)); + delayedPressEvent->setButtonDownScreenPos(button, event->buttonDownScreenPos(button)); + } + } + delayedPressEvent->setButtons(event->buttons()); + delayedPressEvent->setButton(event->button()); + delayedPressEvent->setPos(event->pos()); + delayedPressEvent->setScenePos(event->scenePos()); + delayedPressEvent->setScreenPos(event->screenPos()); + delayedPressEvent->setLastPos(event->lastPos()); + delayedPressEvent->setLastScenePos(event->lastScenePos()); + delayedPressEvent->setLastScreenPos(event->lastScreenPos()); + delayedPressEvent->setModifiers(event->modifiers()); + delayedPressTimer.start(pressDelay, q); +} + +void QmlGraphicsFlickablePrivate::clearDelayedPress() +{ + if (delayedPressEvent) { + delayedPressTimer.stop(); + delete delayedPressEvent; + delayedPressEvent = 0; + } +} + +void QmlGraphicsFlickable::timerEvent(QTimerEvent *event) +{ + Q_D(QmlGraphicsFlickable); + if (event->timerId() == d->delayedPressTimer.timerId()) { + d->delayedPressTimer.stop(); + if (d->delayedPressEvent) { + QmlGraphicsItem *grabber = scene() ? qobject_cast(scene()->mouseGrabberItem()) : 0; + if (!grabber || grabber != this) + scene()->sendEvent(d->delayedPressTarget, d->delayedPressEvent); + delete d->delayedPressEvent; + d->delayedPressEvent = 0; + } + } +} + +qreal QmlGraphicsFlickable::minYExtent() const +{ + return 0.0; +} + +qreal QmlGraphicsFlickable::minXExtent() const +{ + return 0.0; +} + +/* returns -ve */ +qreal QmlGraphicsFlickable::maxXExtent() const +{ + return width() - vWidth(); +} +/* returns -ve */ +qreal QmlGraphicsFlickable::maxYExtent() const +{ + return height() - vHeight(); +} + +void QmlGraphicsFlickable::viewportMoved() +{ + Q_D(QmlGraphicsFlickable); + + int elapsed = QmlGraphicsItemPrivate::elapsed(d->velocityTime); + + if (elapsed) { + qreal prevY = d->lastFlickablePosition.x(); + qreal prevX = d->lastFlickablePosition.y(); + d->velocityTimeline.clear(); + if (d->pressed) { + qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / elapsed; + qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / elapsed; + d->velocityTimeline.move(d->horizontalVelocity, horizontalVelocity, d->reportedVelocitySmoothing); + d->velocityTimeline.move(d->horizontalVelocity, 0, d->reportedVelocitySmoothing); + d->velocityTimeline.move(d->verticalVelocity, verticalVelocity, d->reportedVelocitySmoothing); + d->velocityTimeline.move(d->verticalVelocity, 0, d->reportedVelocitySmoothing); + } else { + if (d->timeline.time() != d->vTime) { + qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / (d->timeline.time() - d->vTime); + qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / (d->timeline.time() - d->vTime); + d->horizontalVelocity.setValue(horizontalVelocity); + d->verticalVelocity.setValue(verticalVelocity); + } + d->vTime = d->timeline.time(); + } + } + + d->lastFlickablePosition = QPointF(d->_moveY.value(), d->_moveX.value()); + QmlGraphicsItemPrivate::restart(d->velocityTime); + d->updateBeginningEnd(); + + if (d->flicked) { + // Near an end and it seems that the extent has changed? + // Recalculate the flick so that we don't end up in an odd position. + if (d->velocityY > 0) { + const qreal minY = minYExtent(); + if (minY - d->_moveY.value() < height()/3 && minY != d->flickTargetY) + d->flickY(-d->verticalVelocity.value()); + } else { + const qreal maxY = maxYExtent(); + if (d->_moveY.value() - maxY < height()/3 && maxY != d->flickTargetY) + d->flickY(-d->verticalVelocity.value()); + } + + if (d->velocityX > 0) { + const qreal minX = minXExtent(); + if (minX - d->_moveX.value() < height()/3 && minX != d->flickTargetX) + d->flickX(-d->horizontalVelocity.value()); + } else { + const qreal maxX = maxXExtent(); + if (d->_moveX.value() - maxX < height()/3 && maxX != d->flickTargetX) + d->flickX(-d->horizontalVelocity.value()); + } + } +} + +void QmlGraphicsFlickable::cancelFlick() +{ + Q_D(QmlGraphicsFlickable); + d->timeline.reset(d->_moveX); + d->timeline.reset(d->_moveY); + movementEnding(); +} + +void QmlGraphicsFlickablePrivate::data_removeAt(int) +{ + // ### +} + +int QmlGraphicsFlickablePrivate::data_count() const +{ + // ### + return 0; +} + +void QmlGraphicsFlickablePrivate::data_append(QObject *o) +{ + Q_Q(QmlGraphicsFlickable); + QmlGraphicsItem *i = qobject_cast(o); + if (i) + viewport->fxChildren()->append(i); + else + o->setParent(q); +} + +void QmlGraphicsFlickablePrivate::data_insert(int, QObject *) +{ + // ### +} + +QObject *QmlGraphicsFlickablePrivate::data_at(int) const +{ + // ### + return 0; +} + +void QmlGraphicsFlickablePrivate::data_clear() +{ + // ### +} + + +QmlList *QmlGraphicsFlickable::flickableData() +{ + Q_D(QmlGraphicsFlickable); + return &d->data; +} + +QmlList *QmlGraphicsFlickable::flickableChildren() +{ + Q_D(QmlGraphicsFlickable); + return d->viewport->fxChildren(); +} + +/*! + \qmlproperty bool Flickable::overShoot + This property holds the number of pixels the surface may overshoot the + Flickable's boundaries when flicked. + + If overShoot is non-zero the contents can be flicked beyond the boundary + of the Flickable before being moved back to the boundary. This provides + the feeling that the edges of the view are soft, rather than a hard + physical boundary. +*/ +bool QmlGraphicsFlickable::overShoot() const +{ + Q_D(const QmlGraphicsFlickable); + return d->overShoot; +} + +void QmlGraphicsFlickable::setOverShoot(bool o) +{ + Q_D(QmlGraphicsFlickable); + d->overShoot = o; +} + +/*! + \qmlproperty int Flickable::viewportWidth + \qmlproperty int Flickable::viewportHeight + + The dimensions of the viewport (the surface controlled by Flickable). Typically this + should be set to the combined size of the items placed in the Flickable. + + \code + Flickable { + width: 320; height: 480; viewportWidth: image.width; viewportHeight: image.height + Image { id: image; source: "bigimage.png" } + } + \endcode +*/ +qreal QmlGraphicsFlickable::viewportWidth() const +{ + Q_D(const QmlGraphicsFlickable); + return d->vWidth; +} + +void QmlGraphicsFlickable::setViewportWidth(qreal w) +{ + Q_D(QmlGraphicsFlickable); + if (d->vWidth == w) + return; + d->vWidth = w; + if (w < 0) + d->viewport->setWidth(width()); + else + d->viewport->setWidth(w); + // Make sure that we're entirely in view. + if (!d->pressed) + d->fixupX(); + emit viewportWidthChanged(); + d->updateBeginningEnd(); +} + +void QmlGraphicsFlickable::widthChange() +{ + Q_D(QmlGraphicsFlickable); + if (d->vWidth < 0) { + d->viewport->setWidth(width()); + emit viewportWidthChanged(); + } + d->updateBeginningEnd(); +} + +void QmlGraphicsFlickable::heightChange() +{ + Q_D(QmlGraphicsFlickable); + if (d->vHeight < 0) { + d->viewport->setHeight(height()); + emit viewportHeightChanged(); + } + d->updateBeginningEnd(); +} + +qreal QmlGraphicsFlickable::viewportHeight() const +{ + Q_D(const QmlGraphicsFlickable); + return d->vHeight; +} + +void QmlGraphicsFlickable::setViewportHeight(qreal h) +{ + Q_D(QmlGraphicsFlickable); + if (d->vHeight == h) + return; + d->vHeight = h; + if (h < 0) + d->viewport->setHeight(height()); + else + d->viewport->setHeight(h); + // Make sure that we're entirely in view. + if (!d->pressed) + d->fixupY(); + emit viewportHeightChanged(); + d->updateBeginningEnd(); +} + +qreal QmlGraphicsFlickable::vWidth() const +{ + Q_D(const QmlGraphicsFlickable); + if (d->vWidth < 0) + return width(); + else + return d->vWidth; +} + +qreal QmlGraphicsFlickable::vHeight() const +{ + Q_D(const QmlGraphicsFlickable); + if (d->vHeight < 0) + return height(); + else + return d->vHeight; +} + +bool QmlGraphicsFlickable::xflick() const +{ + return vWidth() != width(); +} + +bool QmlGraphicsFlickable::yflick() const +{ + return vHeight() != height(); +} + +bool QmlGraphicsFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsFlickable); + QGraphicsSceneMouseEvent mouseEvent(event->type()); + QRectF myRect = mapToScene(QRectF(0, 0, width(), height())).boundingRect(); + + QGraphicsScene *s = scene(); + QmlGraphicsItem *grabber = s ? qobject_cast(s->mouseGrabberItem()) : 0; + if ((d->stealMouse || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) { + mouseEvent.setAccepted(false); + for (int i = 0x1; i <= 0x10; i <<= 1) { + if (event->buttons() & i) { + Qt::MouseButton button = Qt::MouseButton(i); + mouseEvent.setButtonDownPos(button, mapFromScene(event->buttonDownPos(button))); + } + } + mouseEvent.setScenePos(event->scenePos()); + mouseEvent.setLastScenePos(event->lastScenePos()); + mouseEvent.setPos(mapFromScene(event->scenePos())); + mouseEvent.setLastPos(mapFromScene(event->lastScenePos())); + + switch(mouseEvent.type()) { + case QEvent::GraphicsSceneMouseMove: + d->handleMouseMoveEvent(&mouseEvent); + break; + case QEvent::GraphicsSceneMousePress: + if (d->delayedPressEvent) + return false; + + d->handleMousePressEvent(&mouseEvent); + d->captureDelayedPress(event); + break; + case QEvent::GraphicsSceneMouseRelease: + if (d->delayedPressEvent) { + scene()->sendEvent(d->delayedPressTarget, d->delayedPressEvent); + d->clearDelayedPress(); + } + d->handleMouseReleaseEvent(&mouseEvent); + break; + default: + break; + } + grabber = qobject_cast(s->mouseGrabberItem()); + if (grabber && d->stealMouse && !grabber->keepMouseGrab() && grabber != this) { + d->clearDelayedPress(); + grabMouse(); + } + + return d->stealMouse || d->delayedPressEvent; + } else if (!d->lastPosTime.isNull()) { + d->lastPosTime = QTime(); + } + if (mouseEvent.type() == QEvent::GraphicsSceneMouseRelease) + d->clearDelayedPress(); + return false; +} + +bool QmlGraphicsFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e) +{ + if (!isVisible()) + return QmlGraphicsItem::sceneEventFilter(i, e); + switch (e->type()) { + case QEvent::GraphicsSceneMousePress: + case QEvent::GraphicsSceneMouseMove: + case QEvent::GraphicsSceneMouseRelease: + return sendMouseEvent(static_cast(e)); + default: + break; + } + + return QmlGraphicsItem::sceneEventFilter(i, e); +} + +/*! + \qmlproperty real Flickable::maximumFlickVelocity + This property holds the maximum velocity that the user can flick the view in pixels/second. + + The default is 5000 pixels/s +*/ +qreal QmlGraphicsFlickable::maximumFlickVelocity() const +{ + Q_D(const QmlGraphicsFlickable); + return d->maxVelocity; +} + +void QmlGraphicsFlickable::setMaximumFlickVelocity(qreal v) +{ + Q_D(QmlGraphicsFlickable); + if (v == d->maxVelocity) + return; + d->maxVelocity = v; +} + +/*! + \qmlproperty real Flickable::maximumFlickVelocity + This property holds the rate at which a flick will decelerate. + + The default is 500. +*/ +qreal QmlGraphicsFlickable::flickDeceleration() const +{ + Q_D(const QmlGraphicsFlickable); + return d->deceleration; +} + +void QmlGraphicsFlickable::setFlickDeceleration(qreal deceleration) +{ + Q_D(QmlGraphicsFlickable); + d->deceleration = deceleration; +} + +bool QmlGraphicsFlickable::isFlicking() const +{ + Q_D(const QmlGraphicsFlickable); + return d->flicked; +} + +/*! + \qmlproperty int Flickable::pressDelay + + This property holds the time to delay (ms) delivering a press to + children of the Flickable. This can be useful where reacting + to a press before a flicking action has undesireable effects. + + If the flickable is dragged/flicked before the delay times out + the press event will not be delivered. If the button is released + within the timeout, both the press and release will be delivered. +*/ +int QmlGraphicsFlickable::pressDelay() const +{ + Q_D(const QmlGraphicsFlickable); + return d->pressDelay; +} + +void QmlGraphicsFlickable::setPressDelay(int delay) +{ + Q_D(QmlGraphicsFlickable); + if (d->pressDelay == delay) + return; + d->pressDelay = delay; +} + +qreal QmlGraphicsFlickable::reportedVelocitySmoothing() const +{ + Q_D(const QmlGraphicsFlickable); + return d->reportedVelocitySmoothing; +} + +void QmlGraphicsFlickable::setReportedVelocitySmoothing(qreal reportedVelocitySmoothing) +{ + Q_D(QmlGraphicsFlickable); + Q_ASSERT(reportedVelocitySmoothing >= 0); + if (reportedVelocitySmoothing == d->reportedVelocitySmoothing) + return; + d->reportedVelocitySmoothing = reportedVelocitySmoothing; + emit reportedVelocitySmoothingChanged(reportedVelocitySmoothing); +} + +bool QmlGraphicsFlickable::isMoving() const +{ + Q_D(const QmlGraphicsFlickable); + return d->moving; +} + +void QmlGraphicsFlickable::movementStarting() +{ + Q_D(QmlGraphicsFlickable); + if (!d->moving) { + d->moving = true; + emit movingChanged(); + emit movementStarted(); + } +} + +void QmlGraphicsFlickable::movementEnding() +{ + Q_D(QmlGraphicsFlickable); + if (d->moving) { + d->moving = false; + emit movingChanged(); + emit movementEnded(); + } + if (d->flicked) { + d->flicked = false; + emit flickingChanged(); + emit flickEnded(); + } + d->horizontalVelocity.setValue(0); + d->verticalVelocity.setValue(0); +} + +void QmlGraphicsFlickablePrivate::updateVelocity() +{ + Q_Q(QmlGraphicsFlickable); + emit q->horizontalVelocityChanged(); + emit q->verticalVelocityChanged(); +} + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsFlickableVisibleArea) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisibleArea,QmlGraphicsFlickableVisibleArea) + +#include "qfxflickable.moc" diff --git a/src/declarative/fx/qmlgraphicsflickable.h b/src/declarative/fx/qmlgraphicsflickable.h new file mode 100644 index 0000000..f7ef0088 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsflickable.h @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSFLICKABLE_H +#define QMLGRAPHICSFLICKABLE_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsFlickablePrivate; +class QmlGraphicsFlickableVisibleArea; +class Q_DECLARATIVE_EXPORT QmlGraphicsFlickable : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(qreal viewportWidth READ viewportWidth WRITE setViewportWidth NOTIFY viewportWidthChanged) + Q_PROPERTY(qreal viewportHeight READ viewportHeight WRITE setViewportHeight NOTIFY viewportHeightChanged) + Q_PROPERTY(qreal viewportX READ viewportX WRITE setViewportX NOTIFY positionXChanged) + Q_PROPERTY(qreal viewportY READ viewportY WRITE setViewportY NOTIFY positionYChanged) + + Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged) + Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged) + Q_PROPERTY(qreal reportedVelocitySmoothing READ reportedVelocitySmoothing WRITE setReportedVelocitySmoothing NOTIFY reportedVelocitySmoothingChanged) + + Q_PROPERTY(bool overShoot READ overShoot WRITE setOverShoot) + Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity) + Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration) + Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) + Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) + + Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive) + Q_PROPERTY(int pressDelay READ pressDelay WRITE setPressDelay) + + Q_PROPERTY(bool atXEnd READ isAtXEnd NOTIFY isAtBoundaryChanged) + Q_PROPERTY(bool atYEnd READ isAtYEnd NOTIFY isAtBoundaryChanged) + Q_PROPERTY(bool atXBeginning READ isAtXBeginning NOTIFY isAtBoundaryChanged) + Q_PROPERTY(bool atYBeginning READ isAtYBeginning NOTIFY isAtBoundaryChanged) + + Q_PROPERTY(QmlGraphicsFlickableVisibleArea *visibleArea READ visibleArea CONSTANT) + + Q_PROPERTY(QmlList* flickableData READ flickableData) + Q_PROPERTY(QmlList* flickableChildren READ flickableChildren) + Q_CLASSINFO("DefaultProperty", "flickableData") + +public: + QmlGraphicsFlickable(QmlGraphicsItem *parent=0); + ~QmlGraphicsFlickable(); + + QmlList *flickableData(); + QmlList *flickableChildren(); + + bool overShoot() const; + void setOverShoot(bool); + + qreal viewportWidth() const; + void setViewportWidth(qreal); + + qreal viewportHeight() const; + void setViewportHeight(qreal); + + qreal viewportX() const; + void setViewportX(qreal pos); + + qreal viewportY() const; + void setViewportY(qreal pos); + + bool isMoving() const; + bool isFlicking() const; + + int pressDelay() const; + void setPressDelay(int delay); + + qreal reportedVelocitySmoothing() const; + void setReportedVelocitySmoothing(qreal); + + qreal maximumFlickVelocity() const; + void setMaximumFlickVelocity(qreal); + + qreal flickDeceleration() const; + void setFlickDeceleration(qreal); + + bool isInteractive() const; + void setInteractive(bool); + + qreal horizontalVelocity() const; + qreal verticalVelocity() const; + + bool isAtXEnd() const; + bool isAtXBeginning() const; + bool isAtYEnd() const; + bool isAtYBeginning() const; + + QmlGraphicsItem *viewport(); + +Q_SIGNALS: + void viewportWidthChanged(); + void viewportHeightChanged(); + void positionXChanged(); + void positionYChanged(); + void movingChanged(); + void flickingChanged(); + void movementStarted(); + void movementEnded(); + void flickStarted(); + void flickEnded(); + void reportedVelocitySmoothingChanged(int); + void horizontalVelocityChanged(); + void verticalVelocityChanged(); + void isAtBoundaryChanged(); + void pageChanged(); + +protected: + virtual bool sceneEventFilter(QGraphicsItem *, QEvent *); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void timerEvent(QTimerEvent *event); + + qreal visibleX() const; + qreal visibleY() const; + + QmlGraphicsFlickableVisibleArea *visibleArea(); + +protected Q_SLOTS: + virtual void ticked(); + void movementStarting(); + void movementEnding(); + void heightChange(); + void widthChange(); + +protected: + virtual qreal minXExtent() const; + virtual qreal minYExtent() const; + virtual qreal maxXExtent() const; + virtual qreal maxYExtent() const; + qreal vWidth() const; + qreal vHeight() const; + virtual void viewportMoved(); + bool sendMouseEvent(QGraphicsSceneMouseEvent *event); + + bool xflick() const; + bool yflick() const; + void cancelFlick(); + +protected: + QmlGraphicsFlickable(QmlGraphicsFlickablePrivate &dd, QmlGraphicsItem *parent); + +private: + Q_DISABLE_COPY(QmlGraphicsFlickable) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsFlickable) + friend class QmlGraphicsFlickableVisibleArea; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsFlickable) + +QT_END_HEADER + +#endif diff --git a/src/declarative/fx/qmlgraphicsflickable_p.h b/src/declarative/fx/qmlgraphicsflickable_p.h new file mode 100644 index 0000000..d9f917d --- /dev/null +++ b/src/declarative/fx/qmlgraphicsflickable_p.h @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSFLICKABLE_P_H +#define QMLGRAPHICSFLICKABLE_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 "qdatetime.h" +#include "qmlgraphicsflickable.h" +#include "qmlgraphicsitem_p.h" +#include "qml.h" +#include "private/qmltimeline_p.h" +#include "private/qmlanimation_p.h" + +QT_BEGIN_NAMESPACE + +class QmlGraphicsFlickableVisibleArea; +class QmlGraphicsFlickablePrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsFlickable) + +public: + QmlGraphicsFlickablePrivate(); + void init(); + virtual void flickX(qreal velocity); + virtual void flickY(qreal velocity); + virtual void fixupX(); + virtual void fixupY(); + void updateBeginningEnd(); + + void captureDelayedPress(QGraphicsSceneMouseEvent *event); + void clearDelayedPress(); + +public: + QmlGraphicsItem *viewport; + QmlTimeLineValueProxy _moveX; + QmlTimeLineValueProxy _moveY; + QmlTimeLine timeline; + qreal vWidth; + qreal vHeight; + bool overShoot : 1; + bool flicked : 1; + bool moving : 1; + bool stealMouse : 1; + bool pressed : 1; + bool atXEnd : 1; + bool atXBeginning : 1; + bool atYEnd : 1; + bool atYBeginning : 1; + bool interactive : 1; + QTime lastPosTime; + QPointF lastPos; + QPointF pressPos; + qreal pressX; + qreal pressY; + qreal velocityX; + qreal velocityY; + QTime pressTime; + QmlTimeLineEvent fixupXEvent; + QmlTimeLineEvent fixupYEvent; + qreal deceleration; + qreal maxVelocity; + QTime velocityTime; + QPointF lastFlickablePosition; + qreal reportedVelocitySmoothing; + int flickTargetX; + int flickTargetY; + QGraphicsSceneMouseEvent *delayedPressEvent; + QGraphicsItem *delayedPressTarget; + QBasicTimer delayedPressTimer; + int pressDelay; + + void updateVelocity(); + struct Velocity : public QmlTimeLineValue + { + Velocity(QmlGraphicsFlickablePrivate *p) + : parent(p) {} + virtual void setValue(qreal v) { + QmlTimeLineValue::setValue(v); + parent->updateVelocity(); + } + QmlGraphicsFlickablePrivate *parent; + }; + Velocity horizontalVelocity; + Velocity verticalVelocity; + int vTime; + QmlTimeLine velocityTimeline; + QmlGraphicsFlickableVisibleArea *visibleArea; + + void handleMousePressEvent(QGraphicsSceneMouseEvent *); + void handleMouseMoveEvent(QGraphicsSceneMouseEvent *); + void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *); + + // flickableData property + void data_removeAt(int); + int data_count() const; + void data_append(QObject *); + void data_insert(int, QObject *); + QObject *data_at(int) const; + void data_clear(); + + friend class QmlGraphicsFlickableVisibleArea; + QML_DECLARE_LIST_PROXY(QmlGraphicsFlickablePrivate, QObject *, data) +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/declarative/fx/qmlgraphicsflipable.cpp b/src/declarative/fx/qmlgraphicsflipable.cpp new file mode 100644 index 0000000..4df35f1 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsflipable.cpp @@ -0,0 +1,236 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsflipable.h" +#include "private/qmlgraphicsitem_p.h" +#include "QtGui/qgraphicstransform.h" +#include + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flipable,QmlGraphicsFlipable) + +class QmlGraphicsFlipablePrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsFlipable) +public: + QmlGraphicsFlipablePrivate() : current(QmlGraphicsFlipable::Front), front(0), back(0) {} + + void updateSceneTransformFromParent(); + + QmlGraphicsFlipable::Side current; + QmlGraphicsItem *front; + QmlGraphicsItem *back; +}; + +/*! + \qmlclass Flipable QmlGraphicsFlipable + \brief The Flipable item provides a surface that can be flipped. + \inherits Item + + Flipable allows you to specify a front and a back and then flip between those sides. + + \qml + Flipable { + id: flipable + width: 40 + height: 40 + axis: Axis { + startX: 20 + startY: 0 + endX: 20 + endY: 40 + } + front: Image { source: "front.png" } + back: Image { source: "back.png" } + states: [ + State { + name: "back" + SetProperty { + target: flipable + property: "rotation" + value: 180 + } + } + ] + transitions: [ + Transition { + NumberAnimation { + easing: "easeInOutQuad" + properties: "rotation" + } + } + ] +} + \endqml + + \image flipable.gif +*/ + +/*! + \internal + \class QmlGraphicsFlipable + \brief The QmlGraphicsFlipable class provides a flipable surface. + + \ingroup group_widgets + + QmlGraphicsFlipable allows you to specify a front and a back, as well as an + axis for the flip. +*/ + +QmlGraphicsFlipable::QmlGraphicsFlipable(QmlGraphicsItem *parent) +: QmlGraphicsItem(*(new QmlGraphicsFlipablePrivate), parent) +{ +} + +QmlGraphicsFlipable::~QmlGraphicsFlipable() +{ +} + +/*! + \qmlproperty Item Flipable::front + \qmlproperty Item Flipable::back + + The front and back sides of the flipable. +*/ + +QmlGraphicsItem *QmlGraphicsFlipable::front() +{ + Q_D(const QmlGraphicsFlipable); + return d->front; +} + +void QmlGraphicsFlipable::setFront(QmlGraphicsItem *front) +{ + Q_D(QmlGraphicsFlipable); + if (d->front) { + qmlInfo(tr("front is a write-once property"),this); + return; + } + d->front = front; + fxChildren()->append(d->front); + if (Back == d->current) + d->front->setOpacity(0.); +} + +QmlGraphicsItem *QmlGraphicsFlipable::back() +{ + Q_D(const QmlGraphicsFlipable); + return d->back; +} + +void QmlGraphicsFlipable::setBack(QmlGraphicsItem *back) +{ + Q_D(QmlGraphicsFlipable); + if (d->back) { + qmlInfo(tr("back is a write-once property"),this); + return; + } + d->back = back; + fxChildren()->append(d->back); + if (Front == d->current) + d->back->setOpacity(0.); +} + +/*! + \qmlproperty enumeration Flipable::side + + The side of the Flippable currently visible. Possible values are \c + Front and \c Back. +*/ +QmlGraphicsFlipable::Side QmlGraphicsFlipable::side() const +{ + Q_D(const QmlGraphicsFlipable); + if (d->dirtySceneTransform) + const_cast(d)->updateSceneTransformFromParent(); + + return d->current; +} + +// determination on the currently visible side of the flipable +// has to be done on the complete scene transform to give +// correct results. +void QmlGraphicsFlipablePrivate::updateSceneTransformFromParent() +{ + Q_Q(QmlGraphicsFlipable); + + QmlGraphicsItemPrivate::updateSceneTransformFromParent(); + QPointF p1(0, 0); + QPointF p2(1, 0); + QPointF p3(1, 1); + + p1 = sceneTransform.map(p1); + p2 = sceneTransform.map(p2); + p3 = sceneTransform.map(p3); + + qreal cross = (p1.x() - p2.x()) * (p3.y() - p2.y()) - + (p1.y() - p2.y()) * (p3.x() - p2.x()); + + QmlGraphicsFlipable::Side newSide; + if (cross > 0) { + newSide = QmlGraphicsFlipable::Back; + } else { + newSide = QmlGraphicsFlipable::Front; + } + + if (newSide != current) { + current = newSide; + if (current == QmlGraphicsFlipable::Back) { + QTransform mat; + mat.translate(back->width()/2,back->height()/2); + if (back->width() && p1.x() >= p2.x()) + mat.rotate(180, Qt::YAxis); + if (back->height() && p2.y() >= p3.y()) + mat.rotate(180, Qt::XAxis); + mat.translate(-back->width()/2,-back->height()/2); + back->setTransform(mat); + } + if (front) + front->setOpacity((current==QmlGraphicsFlipable::Front)?1.:0.); + if (back) + back->setOpacity((current==QmlGraphicsFlipable::Back)?1.:0.); + emit q->sideChanged(); + } +} + +QT_END_NAMESPACE + +#include "moc_qmlgraphicsflipable.cpp" diff --git a/src/declarative/fx/qmlgraphicsflipable.h b/src/declarative/fx/qmlgraphicsflipable.h new file mode 100644 index 0000000..7f92d65 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsflipable.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 QMLGRAPHICSFLIPABLE_H +#define QMLGRAPHICSFLIPABLE_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsFlipablePrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsFlipable : public QmlGraphicsItem +{ + Q_OBJECT + + Q_ENUMS(Side) + Q_PROPERTY(QmlGraphicsItem *front READ front WRITE setFront) + Q_PROPERTY(QmlGraphicsItem *back READ back WRITE setBack) + Q_PROPERTY(Side side READ side NOTIFY sideChanged) + //### flipAxis + //### flipRotation +public: + QmlGraphicsFlipable(QmlGraphicsItem *parent=0); + ~QmlGraphicsFlipable(); + + QmlGraphicsItem *front(); + void setFront(QmlGraphicsItem *); + + QmlGraphicsItem *back(); + void setBack(QmlGraphicsItem *); + + enum Side { Front, Back }; + Side side() const; + +Q_SIGNALS: + void sideChanged(); + +private: + Q_DISABLE_COPY(QmlGraphicsFlipable) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsFlipable) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsFlipable) + +QT_END_HEADER + +#endif // QMLGRAPHICSFLIPABLE_H diff --git a/src/declarative/fx/qmlgraphicsfocuspanel.cpp b/src/declarative/fx/qmlgraphicsfocuspanel.cpp new file mode 100644 index 0000000..db8fcdb --- /dev/null +++ b/src/declarative/fx/qmlgraphicsfocuspanel.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsfocuspanel.h" +#include +#include + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FocusPanel,QmlGraphicsFocusPanel) + +/*! + \qmlclass FocusPanel + \brief The FocusPanel item explicitly creates a focus panel. + \inherits Item + + Focus panels assist in keyboard focus handling when building QML + applications. All the details are covered in the + \l {qmlfocus}{keyboard focus documentation}. +*/ + +/*! + \internal + \class QmlGraphicsFocusPanel +*/ + +QmlGraphicsFocusPanel::QmlGraphicsFocusPanel(QmlGraphicsItem *parent) : + QmlGraphicsItem(parent) +{ + setFlag(ItemIsPanel); +} + +QmlGraphicsFocusPanel::~QmlGraphicsFocusPanel() +{ +} + +/*! + \qmlproperty bool FocusPanel::active + + Sets whether the item is the active focus panel. +*/ + +bool QmlGraphicsFocusPanel::sceneEvent(QEvent *event) +{ + if (event->type() == QEvent::WindowActivate || + event->type() == QEvent::WindowDeactivate) + emit activeChanged(); + return QmlGraphicsItem::sceneEvent(event); +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsfocuspanel.h b/src/declarative/fx/qmlgraphicsfocuspanel.h new file mode 100644 index 0000000..2c4f792 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsfocuspanel.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 QMLGRAPHICSFOCUSPANEL_H +#define QMLGRAPHICSFOCUSPANEL_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class Q_DECLARATIVE_EXPORT QmlGraphicsFocusPanel : public QmlGraphicsItem +{ + Q_OBJECT + Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) +public: + QmlGraphicsFocusPanel(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsFocusPanel(); + +Q_SIGNALS: + void activeChanged(); + +protected: + bool sceneEvent(QEvent *event); + +private: + Q_DISABLE_COPY(QmlGraphicsFocusPanel) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsFocusPanel) + +QT_END_HEADER + +#endif // QMLGRAPHICSFOCUSPANEL_H diff --git a/src/declarative/fx/qmlgraphicsfocusscope.cpp b/src/declarative/fx/qmlgraphicsfocusscope.cpp new file mode 100644 index 0000000..e957085 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsfocusscope.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsfocusscope.h" + + +QT_BEGIN_NAMESPACE +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,FocusScope,QmlGraphicsFocusScope) + +/*! + \qmlclass FocusScope + \brief The FocusScope object explicitly creates a focus scope. + \inherits Item + + Focus scopes assist in keyboard focus handling when building reusable QML + components. All the details are covered in the + \l {qmlfocus}{keyboard focus documentation}. +*/ + +/*! + \internal + \class QmlGraphicsFocusScope +*/ + +QmlGraphicsFocusScope::QmlGraphicsFocusScope(QmlGraphicsItem *parent) : + QmlGraphicsItem(parent) +{ + setFlag(QGraphicsItem::ItemIsFocusScope); +} + +QmlGraphicsFocusScope::~QmlGraphicsFocusScope() +{ +} +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsfocusscope.h b/src/declarative/fx/qmlgraphicsfocusscope.h new file mode 100644 index 0000000..28d1f4f --- /dev/null +++ b/src/declarative/fx/qmlgraphicsfocusscope.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSFOCUSSCOPE_H +#define QMLGRAPHICSFOCUSSCOPE_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +//### set component root as focusscope +class Q_DECLARATIVE_EXPORT QmlGraphicsFocusScope : public QmlGraphicsItem +{ + Q_OBJECT +public: + QmlGraphicsFocusScope(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsFocusScope(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsFocusScope) + +QT_END_HEADER + +#endif // QMLGRAPHICSFOCUSSCOPE_H diff --git a/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.cpp b/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.cpp new file mode 100644 index 0000000..87193cd --- /dev/null +++ b/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.cpp @@ -0,0 +1,230 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsgraphicsobjectcontainer.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlGraphicsGraphicsObjectContainerPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsGraphicsObjectContainer) + +public: + QmlGraphicsGraphicsObjectContainerPrivate() : QmlGraphicsItemPrivate(), graphicsObject(0), syncedResize(false) + { } + + void _q_updateSize(); + + void setFiltering(bool on) + { + Q_Q(QmlGraphicsGraphicsObjectContainer); + if (graphicsObject && graphicsObject->isWidget()) { + if (!on) { + graphicsObject->removeEventFilter(q); + QObject::disconnect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); + QObject::disconnect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); + } else { + graphicsObject->installEventFilter(q); + QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); + QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); + } + } + } + + + QGraphicsObject *graphicsObject; + bool syncedResize; +}; + + +/*! + \qmlclass GraphicsObjectContainer QmlGraphicsGraphicsObjectContainer + \brief The GraphicsObjectContainer element allows you to add QGraphicsObjects into Fluid UI elements. +*/ + +/*! + \internal + \class QmlGraphicsGraphicsObjectContainer + \brief The QmlGraphicsGraphicsObjectContainer class allows you to add QGraphicsObjects into Fluid UI applications. +*/ + +QML_DEFINE_NOCREATE_TYPE(QGraphicsObject) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GraphicsObjectContainer,QmlGraphicsGraphicsObjectContainer) + +QmlGraphicsGraphicsObjectContainer::QmlGraphicsGraphicsObjectContainer(QmlGraphicsItem *parent) +: QmlGraphicsItem(*new QmlGraphicsGraphicsObjectContainerPrivate, parent) +{ +} + +QmlGraphicsGraphicsObjectContainer::~QmlGraphicsGraphicsObjectContainer() +{ +} + +QGraphicsObject *QmlGraphicsGraphicsObjectContainer::graphicsObject() const +{ + Q_D(const QmlGraphicsGraphicsObjectContainer); + return d->graphicsObject; +} + +/*! + \qmlproperty QGraphicsObject GraphicsObjectContainer::graphicsObject + The QGraphicsObject associated with this element. +*/ +void QmlGraphicsGraphicsObjectContainer::setGraphicsObject(QGraphicsObject *object) +{ + Q_D(QmlGraphicsGraphicsObjectContainer); + if (object == d->graphicsObject) + return; + + //### remove previously set item? + + d->setFiltering(false); + + d->graphicsObject = object; + + if (d->graphicsObject) { + d->graphicsObject->setParentItem(this); + + if (d->syncedResize && d->graphicsObject->isWidget()) { + QGraphicsWidget *gw = static_cast(d->graphicsObject); + QSizeF gwSize = gw->size(); //### should we use sizeHint? + QSizeF newSize = gwSize; + if (heightValid()) + newSize.setHeight(height()); + if (widthValid()) + newSize.setWidth(width()); + if (gwSize != newSize) + gw->resize(newSize); + + gwSize = gw->size(); + setImplicitWidth(gwSize.width()); + setImplicitHeight(gwSize.height()); + + d->setFiltering(true); + } + } +} + +QVariant QmlGraphicsGraphicsObjectContainer::itemChange(GraphicsItemChange change, const QVariant &value) +{ + Q_D(QmlGraphicsGraphicsObjectContainer); + if (change == ItemSceneHasChanged) { + QGraphicsObject *o = d->graphicsObject; + d->graphicsObject = 0; + setGraphicsObject(o); + } + return QmlGraphicsItem::itemChange(change, value); +} + +bool QmlGraphicsGraphicsObjectContainer::eventFilter(QObject *watched, QEvent *e) +{ + Q_D(QmlGraphicsGraphicsObjectContainer); + if (watched == d->graphicsObject && e->type() == QEvent::GraphicsSceneResize) { + if (d->graphicsObject && d->graphicsObject->isWidget() && d->syncedResize) { + QSizeF newSize = static_cast(d->graphicsObject)->size(); + setImplicitWidth(newSize.width()); + setImplicitHeight(newSize.height()); + } + } + return QmlGraphicsItem::eventFilter(watched, e); +} + +/*! + \qmlproperty bool GraphicsObjectContainer::synchronizedResizing + + This property determines whether or not the container and graphics object will synchronize their + sizes. + + \note This property only applies when wrapping a QGraphicsWidget. + + If synchronizedResizing is enabled, the container and widget will + synchronize their sizes as follows. + \list + \o If a size has been set on the container, the widget will be resized to the container. + Any changes in the container's size will be reflected in the widget. + + \o \e Otherwise, the container will initially be sized to the preferred size of the widget. + Any changes to the container's size will be reflected in the widget, and any changes to the + widget's size will be reflected in the container. + \endlist +*/ +bool QmlGraphicsGraphicsObjectContainer::synchronizedResizing() const +{ + Q_D(const QmlGraphicsGraphicsObjectContainer); + return d->syncedResize; +} + +void QmlGraphicsGraphicsObjectContainer::setSynchronizedResizing(bool on) +{ + Q_D(QmlGraphicsGraphicsObjectContainer); + if (on == d->syncedResize) + return; + + d->syncedResize = on; + d->setFiltering(on); +} + +void QmlGraphicsGraphicsObjectContainerPrivate::_q_updateSize() +{ + if (!graphicsObject || !graphicsObject->isWidget() || !syncedResize) + return; + + QGraphicsWidget *gw = static_cast(graphicsObject); + const QSizeF newSize(width, height); + gw->resize(newSize); + + //### will respecting the widgets min/max ever get us in trouble? (all other items always + // size to exactly what you tell them) + /*QSizeF constrainedSize = newSize.expandedTo(gw->minimumSize()).boundedTo(gw->maximumSize()); + gw->resize(constrainedSize); + if (constrainedSize != newSize) { + setImplicitWidth(constrainedSize.width()); + setImplicitHeight(constrainedSize.height()); + }*/ +} + +QT_END_NAMESPACE + +#include "moc_qmlgraphicsgraphicsobjectcontainer.cpp" diff --git a/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.h b/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.h new file mode 100644 index 0000000..0189e2f --- /dev/null +++ b/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSGRAPHICSOBJECTCONTAINER_H +#define QMLGRAPHICSGRAPHICSOBJECTCONTAINER_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QGraphicsObject; +class QmlGraphicsGraphicsObjectContainerPrivate; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGraphicsObjectContainer : public QmlGraphicsItem +{ + Q_OBJECT + + Q_CLASSINFO("DefaultProperty", "graphicsObject") + Q_PROPERTY(QGraphicsObject *graphicsObject READ graphicsObject WRITE setGraphicsObject) + Q_PROPERTY(bool synchronizedResizing READ synchronizedResizing WRITE setSynchronizedResizing) + +public: + QmlGraphicsGraphicsObjectContainer(QmlGraphicsItem *parent = 0); + ~QmlGraphicsGraphicsObjectContainer(); + + QGraphicsObject *graphicsObject() const; + void setGraphicsObject(QGraphicsObject *); + + bool synchronizedResizing() const; + void setSynchronizedResizing(bool on); + +protected: + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + bool eventFilter(QObject *watched, QEvent *e); + +private: + Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsGraphicsObjectContainer) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QGraphicsObject) +QML_DECLARE_TYPE(QmlGraphicsGraphicsObjectContainer) + +QT_END_HEADER + +#endif // QMLGRAPHICSGRAPHICSOBJECTCONTAINER_H diff --git a/src/declarative/fx/qmlgraphicsgridview.cpp b/src/declarative/fx/qmlgraphicsgridview.cpp new file mode 100644 index 0000000..d512b8c --- /dev/null +++ b/src/declarative/fx/qmlgraphicsgridview.cpp @@ -0,0 +1,1585 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsvisualitemmodel.h" +#include "qlistmodelinterface.h" +#include "qmleasefollow.h" +#include "private/qmlgraphicsflickable_p.h" +#include "qmlgraphicsgridview.h" + +#include + +QT_BEGIN_NAMESPACE + +class QmlGraphicsGridViewAttached : public QObject +{ + Q_OBJECT +public: + QmlGraphicsGridViewAttached(QObject *parent) + : QObject(parent), m_isCurrent(false), m_delayRemove(false) {} + ~QmlGraphicsGridViewAttached() { + attachedProperties.remove(parent()); + } + + Q_PROPERTY(QmlGraphicsGridView *view READ view CONSTANT) + QmlGraphicsGridView *view() { return m_view; } + + Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) + bool isCurrentItem() const { return m_isCurrent; } + void setIsCurrentItem(bool c) { + if (m_isCurrent != c) { + m_isCurrent = c; + emit currentItemChanged(); + } + } + + Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged) + bool delayRemove() const { return m_delayRemove; } + void setDelayRemove(bool delay) { + if (m_delayRemove != delay) { + m_delayRemove = delay; + emit delayRemoveChanged(); + } + } + + static QmlGraphicsGridViewAttached *properties(QObject *obj) { + QmlGraphicsGridViewAttached *rv = attachedProperties.value(obj); + if (!rv) { + rv = new QmlGraphicsGridViewAttached(obj); + attachedProperties.insert(obj, rv); + } + return rv; + } + + void emitAdd() { emit add(); } + void emitRemove() { emit remove(); } + +Q_SIGNALS: + void currentItemChanged(); + void delayRemoveChanged(); + void add(); + void remove(); + +public: + QmlGraphicsGridView *m_view; + bool m_isCurrent; + bool m_delayRemove; + + static QHash attachedProperties; +}; + +QHash QmlGraphicsGridViewAttached::attachedProperties; + + +//---------------------------------------------------------------------------- + +class FxGridItem +{ +public: + FxGridItem(QmlGraphicsItem *i, QmlGraphicsGridView *v) : item(i), view(v) { + attached = QmlGraphicsGridViewAttached::properties(item); + attached->m_view = view; + } + ~FxGridItem() {} + + qreal rowPos() const { return (view->flow() == QmlGraphicsGridView::LeftToRight ? item->y() : item->x()); } + qreal colPos() const { return (view->flow() == QmlGraphicsGridView::LeftToRight ? item->x() : item->y()); } + qreal endRowPos() const { + return view->flow() == QmlGraphicsGridView::LeftToRight + ? item->y() + view->cellHeight() - 1 + : item->x() + view->cellWidth() - 1; + } + void setPosition(qreal col, qreal row) { + if (view->flow() == QmlGraphicsGridView::LeftToRight) { + item->setPos(QPointF(col, row)); + } else { + item->setPos(QPointF(row, col)); + } + } + + QmlGraphicsItem *item; + QmlGraphicsGridView *view; + QmlGraphicsGridViewAttached *attached; + int index; +}; + +//---------------------------------------------------------------------------- + +class QmlGraphicsGridViewPrivate : public QmlGraphicsFlickablePrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsGridView) + +public: + QmlGraphicsGridViewPrivate() + : model(0), currentItem(0), flow(QmlGraphicsGridView::LeftToRight) + , visiblePos(0), visibleIndex(0) , currentIndex(-1) + , cellWidth(100), cellHeight(100), columns(1), requestedIndex(-1) + , highlightComponent(0), highlight(0), trackedItem(0) + , moveReason(Other), buffer(0), highlightXAnimator(0), highlightYAnimator(0) + , ownModel(false), wrap(false), autoHighlight(true) + , fixCurrentVisibility(false) {} + + void init(); + void clear(); + FxGridItem *createItem(int modelIndex); + void releaseItem(FxGridItem *item); + void refill(qreal from, qreal to); + + void updateGrid(); + void layout(bool removed=false); + void updateUnrequestedIndexes(); + void updateUnrequestedPositions(); + void updateTrackedItem(); + void createHighlight(); + void updateHighlight(); + void updateCurrent(int modelIndex); + + FxGridItem *visibleItem(int modelIndex) const { + if (modelIndex >= visibleIndex && modelIndex < visibleIndex + visibleItems.count()) { + for (int i = modelIndex - visibleIndex; i < visibleItems.count(); ++i) { + FxGridItem *item = visibleItems.at(i); + if (item->index == modelIndex) + return item; + } + } + return 0; + } + + qreal position() const { + Q_Q(const QmlGraphicsGridView); + return flow == QmlGraphicsGridView::LeftToRight ? q->viewportY() : q->viewportX(); + } + void setPosition(qreal pos) { + Q_Q(QmlGraphicsGridView); + if (flow == QmlGraphicsGridView::LeftToRight) + q->setViewportY(pos); + else + q->setViewportX(pos); + } + int size() const { + Q_Q(const QmlGraphicsGridView); + return flow == QmlGraphicsGridView::LeftToRight ? q->height() : q->width(); + } + qreal startPosition() const { + qreal pos = 0; + if (!visibleItems.isEmpty()) + pos = visibleItems.first()->rowPos() - visibleIndex / columns * rowSize(); + return pos; + } + + qreal endPosition() const { + qreal pos = 0; + if (model && model->count()) + pos = rowPosAt(model->count() - 1) + rowSize(); + return pos; + } + + bool isValid() const { + return model && model->count() && model->isValid(); + } + + int rowSize() const { + return flow == QmlGraphicsGridView::LeftToRight ? cellHeight : cellWidth; + } + int colSize() const { + return flow == QmlGraphicsGridView::LeftToRight ? cellWidth : cellHeight; + } + + qreal colPosAt(int modelIndex) const { + if (FxGridItem *item = visibleItem(modelIndex)) + return item->colPos(); + if (!visibleItems.isEmpty()) { + if (modelIndex < visibleIndex) { + int count = (visibleIndex - modelIndex) % columns; + int col = visibleItems.first()->colPos() / colSize(); + col = (columns - count + col) % columns; + return col * colSize(); + } else { + int count = columns - 1 - (modelIndex - visibleItems.last()->index - 1) % columns; + return visibleItems.last()->colPos() - count * colSize(); + } + } else { + return (modelIndex % columns) * colSize(); + } + return 0; + } + qreal rowPosAt(int modelIndex) const { + if (FxGridItem *item = visibleItem(modelIndex)) + return item->rowPos(); + if (!visibleItems.isEmpty()) { + if (modelIndex < visibleIndex) { + int firstCol = visibleItems.first()->colPos() / colSize(); + int col = visibleIndex - modelIndex + (columns - firstCol - 1); + int rows = col / columns; + return visibleItems.first()->rowPos() - rows * rowSize(); + } else { + int count = modelIndex - visibleItems.last()->index; + int col = visibleItems.last()->colPos() + count * colSize(); + int rows = col / (columns * colSize()); + return visibleItems.last()->rowPos() + rows * rowSize(); + } + } else { + return (modelIndex / columns) * rowSize(); + } + return 0; + } + + // Map a model index to visibleItems list index. + // These may differ if removed items are still present in the visible list, + // e.g. doing a removal animation + int mapFromModel(int modelIndex) const { + if (modelIndex < visibleIndex || modelIndex >= visibleIndex + visibleItems.count()) + return -1; + for (int i = 0; i < visibleItems.count(); ++i) { + FxGridItem *listItem = visibleItems.at(i); + if (listItem->index == modelIndex) + return i + visibleIndex; + if (listItem->index > modelIndex) + return -1; + } + return -1; // Not in visibleList + } + + // for debugging only + void checkVisible() const { + int skip = 0; + for (int i = 0; i < visibleItems.count(); ++i) { + FxGridItem *listItem = visibleItems.at(i); + if (listItem->index == -1) { + ++skip; + } else if (listItem->index != visibleIndex + i - skip) { + for (int j = 0; j < visibleItems.count(); j++) + qDebug() << " index" << j << "item index" << visibleItems.at(j)->index; + qFatal("index %d %d %d", visibleIndex, i, listItem->index); + } + } + } + + QmlGraphicsVisualModel *model; + QVariant modelVariant; + QList visibleItems; + QHash unrequestedItems; + FxGridItem *currentItem; + QmlGraphicsGridView::Flow flow; + int visiblePos; + int visibleIndex; + int currentIndex; + int cellWidth; + int cellHeight; + int columns; + int requestedIndex; + QmlComponent *highlightComponent; + FxGridItem *highlight; + FxGridItem *trackedItem; + enum MovementReason { Other, Key, Mouse }; + MovementReason moveReason; + int buffer; + QmlEaseFollow *highlightXAnimator; + QmlEaseFollow *highlightYAnimator; + + int ownModel : 1; + int wrap : 1; + int autoHighlight : 1; + int fixCurrentVisibility : 1; +}; + +void QmlGraphicsGridViewPrivate::init() +{ + Q_Q(QmlGraphicsGridView); + q->setFlag(QGraphicsItem::ItemIsFocusScope); + QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(sizeChange())); + QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(sizeChange())); +} + +void QmlGraphicsGridViewPrivate::clear() +{ + for (int i = 0; i < visibleItems.count(); ++i) + releaseItem(visibleItems.at(i)); + visibleItems.clear(); + visiblePos = 0; + visibleIndex = 0; + releaseItem(currentItem); + currentItem = 0; + currentIndex = -1; + createHighlight(); + trackedItem = 0; +} + +FxGridItem *QmlGraphicsGridViewPrivate::createItem(int modelIndex) +{ + Q_Q(QmlGraphicsGridView); + // create object + requestedIndex = modelIndex; + FxGridItem *listItem = 0; + if (QmlGraphicsItem *item = model->item(modelIndex, false)) { + listItem = new FxGridItem(item, q); + listItem->index = modelIndex; + // complete + model->completeItem(); + listItem->item->setZValue(modelIndex + 1); + listItem->item->setParent(q->viewport()); + } + requestedIndex = 0; + return listItem; +} + + +void QmlGraphicsGridViewPrivate::releaseItem(FxGridItem *item) +{ + Q_Q(QmlGraphicsGridView); + if (!item) + return; + if (trackedItem == item) { + QObject::disconnect(trackedItem->item, SIGNAL(yChanged()), q, SLOT(trackedPositionChanged())); + QObject::disconnect(trackedItem->item, SIGNAL(xChanged()), q, SLOT(trackedPositionChanged())); + trackedItem = 0; + } + if (model->release(item->item) == 0) { + // item was not destroyed, and we no longer reference it. + unrequestedItems.insert(item->item, model->indexOf(item->item, q)); + } + delete item; +} + +void QmlGraphicsGridViewPrivate::refill(qreal from, qreal to) +{ + Q_Q(QmlGraphicsGridView); + if (!isValid() || !q->isComponentComplete()) + return; + + from -= buffer; + to += buffer; + bool changed = false; + + int colPos = 0; + int rowPos = 0; + int modelIndex = 0; + if (visibleItems.count()) { + rowPos = visibleItems.last()->rowPos(); + colPos = visibleItems.last()->colPos() + colSize(); + if (colPos > colSize() * (columns-1)) { + colPos = 0; + rowPos += rowSize(); + } + int i = visibleItems.count() - 1; + while (i > 0 && visibleItems.at(i)->index == -1) + --i; + modelIndex = visibleItems.at(i)->index + 1; + } + + FxGridItem *item = 0; + while (modelIndex < model->count() && rowPos <= to) { + //qDebug() << "refill: append item" << modelIndex; + if (!(item = createItem(modelIndex))) + break; + item->setPosition(colPos, rowPos); + visibleItems.append(item); + colPos += colSize(); + if (colPos > colSize() * (columns-1)) { + colPos = 0; + rowPos += rowSize(); + } + ++modelIndex; + changed = true; + } + + if (visibleItems.count()) { + rowPos = visibleItems.first()->rowPos(); + colPos = visibleItems.first()->colPos() - colSize(); + if (colPos < 0) { + colPos = colSize() * (columns - 1); + rowPos -= rowSize(); + } + } + while (visibleIndex > 0 && rowPos + rowSize() - 1 >= from){ + //qDebug() << "refill: prepend item" << visibleIndex-1 << "top pos" << rowPos << colPos; + if (!(item = createItem(visibleIndex-1))) + break; + --visibleIndex; + item->setPosition(colPos, rowPos); + visibleItems.prepend(item); + colPos -= colSize(); + if (colPos < 0) { + colPos = colSize() * (columns - 1); + rowPos -= rowSize(); + } + changed = true; + } + + while (visibleItems.count() > 1 && (item = visibleItems.first()) && item->endRowPos() < from) { + if (item->attached->delayRemove()) + break; + //qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endRowPos(); + if (item->index != -1) + visibleIndex++; + visibleItems.removeFirst(); + releaseItem(item); + changed = true; + } + while (visibleItems.count() > 1 && (item = visibleItems.last()) && item->rowPos() > to) { + if (item->attached->delayRemove()) + break; + //qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1; + visibleItems.removeLast(); + releaseItem(item); + changed = true; + } + if (changed) { + if (flow == QmlGraphicsGridView::LeftToRight) + q->setViewportHeight(endPosition() - startPosition()); + else + q->setViewportWidth(endPosition() - startPosition()); + } +} + +void QmlGraphicsGridViewPrivate::updateGrid() +{ + Q_Q(QmlGraphicsGridView); + columns = (int)qMax((flow == QmlGraphicsGridView::LeftToRight ? q->width() : q->height()) / colSize(), qreal(1.)); + if (isValid()) { + if (flow == QmlGraphicsGridView::LeftToRight) + q->setViewportHeight(endPosition() - startPosition()); + else + q->setViewportWidth(endPosition() - startPosition()); + } +} + +void QmlGraphicsGridViewPrivate::layout(bool removed) +{ + Q_Q(QmlGraphicsGridView); + if (visibleItems.count()) { + qreal rowPos = visibleItems.first()->rowPos(); + qreal colPos = visibleItems.first()->colPos(); + if (visibleIndex % columns != 0) { + if (removed) + rowPos -= rowSize(); + colPos = (visibleIndex % columns) * colSize(); + visibleItems.first()->setPosition(colPos, rowPos); + } else if (colPos != 0) { + colPos = 0; + visibleItems.first()->setPosition(colPos, rowPos); + } + for (int i = 1; i < visibleItems.count(); ++i) { + FxGridItem *item = visibleItems.at(i); + colPos += colSize(); + if (colPos > colSize() * (columns-1)) { + colPos = 0; + rowPos += rowSize(); + } + item->setPosition(colPos, rowPos); + } + } + q->refill(); + q->trackedPositionChanged(); + updateHighlight(); + if (flow == QmlGraphicsGridView::LeftToRight) { + q->setViewportHeight(endPosition() - startPosition()); + fixupY(); + } else { + q->setViewportWidth(endPosition() - startPosition()); + fixupX(); + } + updateUnrequestedPositions(); +} + +void QmlGraphicsGridViewPrivate::updateUnrequestedIndexes() +{ + Q_Q(QmlGraphicsGridView); + QHash::iterator it; + for (it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) + *it = model->indexOf(it.key(), q); +} + +void QmlGraphicsGridViewPrivate::updateUnrequestedPositions() +{ + QHash::const_iterator it; + for (it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) { + if (flow == QmlGraphicsGridView::LeftToRight) { + it.key()->setPos(QPointF(colPosAt(*it), rowPosAt(*it))); + } else { + it.key()->setPos(QPointF(rowPosAt(*it), colPosAt(*it))); + } + } +} + +void QmlGraphicsGridViewPrivate::updateTrackedItem() +{ + Q_Q(QmlGraphicsGridView); + FxGridItem *item = currentItem; + if (highlight) + item = highlight; + + if (trackedItem && item != trackedItem) { + QObject::disconnect(trackedItem->item, SIGNAL(yChanged()), q, SLOT(trackedPositionChanged())); + QObject::disconnect(trackedItem->item, SIGNAL(xChanged()), q, SLOT(trackedPositionChanged())); + trackedItem = 0; + } + + if (!trackedItem && item) { + trackedItem = item; + QObject::connect(trackedItem->item, SIGNAL(yChanged()), q, SLOT(trackedPositionChanged())); + QObject::connect(trackedItem->item, SIGNAL(xChanged()), q, SLOT(trackedPositionChanged())); + q->trackedPositionChanged(); + } + if (trackedItem) + q->trackedPositionChanged(); +} + +void QmlGraphicsGridViewPrivate::createHighlight() +{ + Q_Q(QmlGraphicsGridView); + if (highlight) { + if (trackedItem == highlight) + trackedItem = 0; + delete highlight->item; + delete highlight; + highlight = 0; + delete highlightXAnimator; + delete highlightYAnimator; + highlightXAnimator = 0; + highlightYAnimator = 0; + } + + if (!highlightComponent) + return; + + if (currentItem) { + QmlContext *highlightContext = new QmlContext(qmlContext(q)); + QObject *nobj = highlightComponent->create(highlightContext); + if (nobj) { + highlightContext->setParent(nobj); + QmlGraphicsItem *item = qobject_cast(nobj); + if (item) { + item->setParent(q->viewport()); + highlight = new FxGridItem(item, q); + highlightXAnimator = new QmlEaseFollow(q); + highlightXAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("x"))); + highlightXAnimator->setDuration(150); + highlightXAnimator->setEnabled(autoHighlight); + highlightYAnimator = new QmlEaseFollow(q); + highlightYAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("y"))); + highlightYAnimator->setDuration(150); + highlightYAnimator->setEnabled(autoHighlight); + } else { + delete highlightContext; + } + } + } +} + +void QmlGraphicsGridViewPrivate::updateHighlight() +{ + if ((!currentItem && highlight) || (currentItem && !highlight)) + createHighlight(); + updateTrackedItem(); + if (currentItem && autoHighlight && highlight) { + // auto-update highlight + highlightXAnimator->setSourceValue(currentItem->item->x()); + highlightYAnimator->setSourceValue(currentItem->item->y()); + highlight->item->setWidth(currentItem->item->width()); + highlight->item->setHeight(currentItem->item->height()); + } +} + +void QmlGraphicsGridViewPrivate::updateCurrent(int modelIndex) +{ + Q_Q(QmlGraphicsGridView); + if (!isValid() || modelIndex < 0 || modelIndex >= model->count()) { + if (currentItem) { + currentItem->attached->setIsCurrentItem(false); + releaseItem(currentItem); + currentItem = 0; + currentIndex = -1; + updateHighlight(); + emit q->currentIndexChanged(); + } + return; + } + + if (currentItem && currentIndex == modelIndex) { + updateHighlight(); + return; + } + + FxGridItem *oldCurrentItem = currentItem; + currentIndex = modelIndex; + currentItem = createItem(modelIndex); + fixCurrentVisibility = true; + if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item)) + oldCurrentItem->attached->setIsCurrentItem(false); + if (currentItem) { + currentItem->setPosition(colPosAt(modelIndex), rowPosAt(modelIndex)); + currentItem->item->setFocus(true); + currentItem->attached->setIsCurrentItem(true); + } + updateHighlight(); + emit q->currentIndexChanged(); + releaseItem(oldCurrentItem); +} + +//---------------------------------------------------------------------------- + +/*! + \qmlclass GridView + \inherits Flickable + \brief The GridView item provides a grid view of items provided by a model. + + The model is typically provided by a QAbstractListModel "C++ model object", + but can also be created directly in QML. + + The items are laid out top to bottom (vertically) or left to right (horizontally) + and may be flicked to scroll. + + The below example creates a very simple grid, using a QML model. + + \image gridview.png + + \snippet doc/src/snippets/declarative/gridview/gridview.qml 3 + + The model is defined as a ListModel using QML: + \quotefile doc/src/snippets/declarative/gridview/dummydata/ContactModel.qml + + In this case ListModel is a handy way for us to test our UI. In practice + the model would be implemented in C++, or perhaps via a SQL data source. +*/ +QmlGraphicsGridView::QmlGraphicsGridView(QmlGraphicsItem *parent) + : QmlGraphicsFlickable(*(new QmlGraphicsGridViewPrivate), parent) +{ + Q_D(QmlGraphicsGridView); + d->init(); +} + +QmlGraphicsGridView::~QmlGraphicsGridView() +{ + Q_D(QmlGraphicsGridView); + d->clear(); + if (d->ownModel) + delete d->model; +} + +/*! + \qmlattachedproperty bool GridView::isCurrentItem + This attched property is true if this delegate is the current item; otherwise false. + + It is attached to each instance of the delegate. +*/ + +/*! + \qmlattachedproperty GridView GridView::view + This attached property holds the view that manages this delegate instance. + + It is attached to each instance of the delegate. +*/ + +/*! + \qmlattachedproperty bool GridView::delayRemove + This attached property holds whether the delegate may be destroyed. + + It is attached to each instance of the delegate. + + It is sometimes necessary to delay the destruction of an item + until an animation completes. + + The example below ensures that the animation completes before + the item is removed from the grid. + + \code + Component { + id: myDelegate + Item { + id: wrapper + GridView.onRemove: SequentialAnimation { + PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: true } + NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" } + PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: false } + } + } + } + \endcode +*/ + +/*! + \qmlattachedsignal GridView::onAdd() + This attached handler is called immediately after an item is added to the view. +*/ + +/*! + \qmlattachedsignal GridView::onRemove() + This attached handler is called immediately before an item is removed from the view. +*/ + + +/*! + \qmlproperty model GridView::model + This property holds the model providing data for the grid. + + The model provides a set of data that is used to create the items + for the view. For large or dynamic datasets the model is usually + provided by a C++ model object. The C++ model object must be a \l + {QAbstractItemModel} subclass, a VisualModel, or a simple list. + + \sa {qmlmodels}{Data Models} +*/ +QVariant QmlGraphicsGridView::model() const +{ + Q_D(const QmlGraphicsGridView); + return d->modelVariant; +} + +void QmlGraphicsGridView::setModel(const QVariant &model) +{ + Q_D(QmlGraphicsGridView); + if (d->model) { + disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); + disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + disconnect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + disconnect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); + } + d->clear(); + d->modelVariant = model; + QObject *object = qvariant_cast(model); + QmlGraphicsVisualModel *vim = 0; + if (object && (vim = qobject_cast(object))) { + if (d->ownModel) { + delete d->model; + d->ownModel = false; + } + d->model = vim; + } else { + if (!d->ownModel) { + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); + d->ownModel = true; + } + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) + dataModel->setModel(model); + } + if (d->model) { + if (d->currentIndex >= d->model->count() || d->currentIndex < 0) + setCurrentIndex(0); + else + d->updateCurrent(d->currentIndex); + connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); + connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + connect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); + refill(); + emit countChanged(); + } +} + +/*! + \qmlproperty component GridView::delegate + + The delegate provides a template describing what each item in the view should look and act like. + + Here is an example delegate: + \snippet doc/src/snippets/declarative/gridview/gridview.qml 0 +*/ +QmlComponent *QmlGraphicsGridView::delegate() const +{ + Q_D(const QmlGraphicsGridView); + if (d->model) { + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) + return dataModel->delegate(); + } + + return 0; +} + +void QmlGraphicsGridView::setDelegate(QmlComponent *delegate) +{ + Q_D(QmlGraphicsGridView); + if (!d->ownModel) { + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); + d->ownModel = true; + } + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) { + dataModel->setDelegate(delegate); + d->updateCurrent(d->currentIndex); + refill(); + } +} + +/*! + \qmlproperty int GridView::currentIndex + \qmlproperty Item GridView::currentItem + + \c currentIndex holds the index of the current item. + \c currentItem is the current item. Note that the position of the current item + may only be approximate until it becomes visible in the view. +*/ +int QmlGraphicsGridView::currentIndex() const +{ + Q_D(const QmlGraphicsGridView); + return d->currentIndex; +} + +void QmlGraphicsGridView::setCurrentIndex(int index) +{ + Q_D(QmlGraphicsGridView); + if (d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) { + cancelFlick(); + d->updateCurrent(index); + } else { + d->currentIndex = index; + } +} + +QmlGraphicsItem *QmlGraphicsGridView::currentItem() +{ + Q_D(QmlGraphicsGridView); + if (!d->currentItem) + return 0; + return d->currentItem->item; +} + +/*! + \qmlproperty int GridView::count + This property holds the number of items in the view. +*/ +int QmlGraphicsGridView::count() const +{ + Q_D(const QmlGraphicsGridView); + if (d->model) + return d->model->count(); + return 0; +} + +/*! + \qmlproperty component GridView::highlight + This property holds the component to use as the highlight. + + An instance of the highlight component will be created for each view. + The geometry of the resultant component instance will be managed by the view + so as to stay with the current item, unless the highlightFollowsCurrentItem property is false. + + The below example demonstrates how to make a simple highlight: + \snippet doc/src/snippets/declarative/gridview/gridview.qml 1 + + \sa highlightFollowsCurrentItem +*/ +QmlComponent *QmlGraphicsGridView::highlight() const +{ + Q_D(const QmlGraphicsGridView); + return d->highlightComponent; +} + +void QmlGraphicsGridView::setHighlight(QmlComponent *highlight) +{ + Q_D(QmlGraphicsGridView); + delete d->highlightComponent; + d->highlightComponent = highlight; + d->updateCurrent(d->currentIndex); +} + +/*! + \qmlproperty bool GridView::highlightFollowsCurrentItem + This property sets whether the highlight is managed by the view. + + If highlightFollowsCurrentItem is true, the highlight will be moved smoothly + to follow the current item. If highlightFollowsCurrentItem is false, the + highlight will not be moved by the view, and must be implemented + by the highlight component, for example: + + \code + Component { + id: myHighlight + Rectangle { + id: wrapper; color: "lightsteelblue"; radius: 4; width: 320; height: 60 > + y: SpringFollow { source: Wrapper.GridView.view.currentItem.y; spring: 3; damping: 0.2 } + x: SpringFollow { source: Wrapper.GridView.view.currentItem.x; spring: 3; damping: 0.2 } + } + } + \endcode +*/ +bool QmlGraphicsGridView::highlightFollowsCurrentItem() const +{ + Q_D(const QmlGraphicsGridView); + return d->autoHighlight; +} + +void QmlGraphicsGridView::setHighlightFollowsCurrentItem(bool autoHighlight) +{ + Q_D(QmlGraphicsGridView); + d->autoHighlight = autoHighlight; + if (d->highlightXAnimator) { + d->highlightXAnimator->setEnabled(d->autoHighlight); + d->highlightYAnimator->setEnabled(d->autoHighlight); + } + d->updateHighlight(); +} + +/*! + \qmlproperty enumeration GridView::flow + This property holds the flow of the grid. + + Possible values are \c LeftToRight (default) and \c TopToBottom. + + If \a flow is \c LeftToRight, the view will scroll vertically. + If \a flow is \c TopToBottom, the view will scroll horizontally. +*/ +QmlGraphicsGridView::Flow QmlGraphicsGridView::flow() const +{ + Q_D(const QmlGraphicsGridView); + return d->flow; +} + +void QmlGraphicsGridView::setFlow(Flow flow) +{ + Q_D(QmlGraphicsGridView); + if (d->flow != flow) { + d->flow = flow; + if (d->flow == LeftToRight) + setViewportWidth(-1); + else + setViewportHeight(-1); + d->clear(); + d->updateGrid(); + refill(); + d->updateCurrent(d->currentIndex); + } +} + +/*! + \qmlproperty bool GridView::keyNavigationWraps + This property holds whether the grid wraps key navigation + + If this property is true then key presses to move off of one end of the grid will cause the + selection to jump to the other side. +*/ +bool QmlGraphicsGridView::isWrapEnabled() const +{ + Q_D(const QmlGraphicsGridView); + return d->wrap; +} + +void QmlGraphicsGridView::setWrapEnabled(bool wrap) +{ + Q_D(QmlGraphicsGridView); + d->wrap = wrap; +} + +/*! + \qmlproperty int GridView::cacheBuffer + This property holds the number of off-screen pixels to cache. + + This property determines the number of pixels above the top of the view + and below the bottom of the view to cache. Setting this value can make + scrolling the view smoother at the expense of additional memory usage. +*/ +int QmlGraphicsGridView::cacheBuffer() const +{ + Q_D(const QmlGraphicsGridView); + return d->buffer; +} + +void QmlGraphicsGridView::setCacheBuffer(int buffer) +{ + Q_D(QmlGraphicsGridView); + if (d->buffer != buffer) { + d->buffer = buffer; + if (isComponentComplete()) + refill(); + } +} + +/*! + \qmlproperty int GridView::cellWidth + \qmlproperty int GridView::cellHeight + + These properties holds the width and height of each cell in the grid + + The default sell size is 100x100. +*/ +int QmlGraphicsGridView::cellWidth() const +{ + Q_D(const QmlGraphicsGridView); + return d->cellWidth; +} + +void QmlGraphicsGridView::setCellWidth(int cellWidth) +{ + Q_D(QmlGraphicsGridView); + if (cellWidth != d->cellWidth && cellWidth > 0) { + d->cellWidth = qMax(1, cellWidth); + d->updateGrid(); + emit cellWidthChanged(); + d->layout(); + } +} + +int QmlGraphicsGridView::cellHeight() const +{ + Q_D(const QmlGraphicsGridView); + return d->cellHeight; +} + +void QmlGraphicsGridView::setCellHeight(int cellHeight) +{ + Q_D(QmlGraphicsGridView); + if (cellHeight != d->cellHeight && cellHeight > 0) { + d->cellHeight = qMax(1, cellHeight); + d->updateGrid(); + emit cellHeightChanged(); + d->layout(); + } +} + +void QmlGraphicsGridView::sizeChange() +{ + Q_D(QmlGraphicsGridView); + if (isComponentComplete()) { + d->updateGrid(); + d->layout(); + } +} + +void QmlGraphicsGridView::viewportMoved() +{ + QmlGraphicsFlickable::viewportMoved(); + refill(); +} + +qreal QmlGraphicsGridView::minYExtent() const +{ + Q_D(const QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::TopToBottom) + return QmlGraphicsFlickable::minYExtent(); + return -d->startPosition(); +} + +qreal QmlGraphicsGridView::maxYExtent() const +{ + Q_D(const QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::TopToBottom) + return QmlGraphicsFlickable::maxYExtent(); + return -(d->endPosition() - height()); +} + +qreal QmlGraphicsGridView::minXExtent() const +{ + Q_D(const QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::LeftToRight) + return QmlGraphicsFlickable::minXExtent(); + return -d->startPosition(); +} + +qreal QmlGraphicsGridView::maxXExtent() const +{ + Q_D(const QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::LeftToRight) + return QmlGraphicsFlickable::maxXExtent(); + return -(d->endPosition() - width()); +} + +void QmlGraphicsGridView::keyPressEvent(QKeyEvent *event) +{ + Q_D(QmlGraphicsGridView); + QmlGraphicsFlickable::keyPressEvent(event); + if (event->isAccepted()) + return; + + if (d->model && d->model->count() && d->interactive) { + d->moveReason = QmlGraphicsGridViewPrivate::Key; + int oldCurrent = currentIndex(); + switch (event->key()) { + case Qt::Key_Up: + moveCurrentIndexUp(); + break; + case Qt::Key_Down: + moveCurrentIndexDown(); + break; + case Qt::Key_Left: + moveCurrentIndexLeft(); + break; + case Qt::Key_Right: + moveCurrentIndexRight(); + break; + default: + break; + } + if (oldCurrent != currentIndex()) { + event->accept(); + return; + } + } + d->moveReason = QmlGraphicsGridViewPrivate::Other; + event->ignore(); +} + +/*! + \qmlmethod GridView::moveCurrentIndexUp + + Move the currentIndex up one item in the view. + The current index will wrap if keyNavigationWraps is true and it + is currently at the end. +*/ +void QmlGraphicsGridView::moveCurrentIndexUp() +{ + Q_D(QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::LeftToRight) { + if (currentIndex() >= d->columns || d->wrap) { + int index = currentIndex() - d->columns; + setCurrentIndex(index >= 0 ? index : d->model->count()-1); + } + } else { + if (currentIndex() > 0 || d->wrap) { + int index = currentIndex() - 1; + setCurrentIndex(index >= 0 ? index : d->model->count()-1); + } + } +} + +/*! + \qmlmethod GridView::moveCurrentIndexDown + + Move the currentIndex down one item in the view. + The current index will wrap if keyNavigationWraps is true and it + is currently at the end. +*/ +void QmlGraphicsGridView::moveCurrentIndexDown() +{ + Q_D(QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::LeftToRight) { + if (currentIndex() < d->model->count() - d->columns || d->wrap) { + int index = currentIndex()+d->columns; + setCurrentIndex(index < d->model->count() ? index : 0); + } + } else { + if (currentIndex() < d->model->count() - 1 || d->wrap) { + int index = currentIndex() + 1; + setCurrentIndex(index < d->model->count() ? index : 0); + } + } +} + +/*! + \qmlmethod GridView::moveCurrentIndexLeft + + Move the currentIndex left one item in the view. + The current index will wrap if keyNavigationWraps is true and it + is currently at the end. +*/ +void QmlGraphicsGridView::moveCurrentIndexLeft() +{ + Q_D(QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::LeftToRight) { + if (currentIndex() > 0 || d->wrap) { + int index = currentIndex() - 1; + setCurrentIndex(index >= 0 ? index : d->model->count()-1); + } + } else { + if (currentIndex() >= d->columns || d->wrap) { + int index = currentIndex() - d->columns; + setCurrentIndex(index >= 0 ? index : d->model->count()-1); + } + } +} + +/*! + \qmlmethod GridView::moveCurrentIndexRight + + Move the currentIndex right one item in the view. + The current index will wrap if keyNavigationWraps is true and it + is currently at the end. +*/ +void QmlGraphicsGridView::moveCurrentIndexRight() +{ + Q_D(QmlGraphicsGridView); + if (d->flow == QmlGraphicsGridView::LeftToRight) { + if (currentIndex() < d->model->count() - 1 || d->wrap) { + int index = currentIndex() + 1; + setCurrentIndex(index < d->model->count() ? index : 0); + } + } else { + if (currentIndex() < d->model->count() - d->columns || d->wrap) { + int index = currentIndex()+d->columns; + setCurrentIndex(index < d->model->count() ? index : 0); + } + } +} + +void QmlGraphicsGridView::componentComplete() +{ + Q_D(QmlGraphicsGridView); + QmlGraphicsFlickable::componentComplete(); + d->updateGrid(); + if (d->currentIndex < 0) + d->updateCurrent(0); + refill(); +} + +void QmlGraphicsGridView::trackedPositionChanged() +{ + Q_D(QmlGraphicsGridView); + if (!d->trackedItem) + return; + if (!isFlicking() && !d->pressed && d->moveReason == QmlGraphicsGridViewPrivate::Key) { + if (d->trackedItem->rowPos() < d->position()) { + d->setPosition(d->trackedItem->rowPos()); + } else if (d->trackedItem->endRowPos() > d->position() + d->size()) { + qreal pos = d->trackedItem->endRowPos() - d->size(); + if (d->rowSize() > d->size()) + pos = d->trackedItem->rowPos(); + d->setPosition(pos); + } + } +} + +void QmlGraphicsGridView::itemsInserted(int modelIndex, int count) +{ + Q_D(QmlGraphicsGridView); + if (!d->visibleItems.count() || d->model->count() <= 1) { + refill(); + d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); + emit countChanged(); + return; + } + + int index = d->mapFromModel(modelIndex); + if (index == -1) { + int i = d->visibleItems.count() - 1; + while (i > 0 && d->visibleItems.at(i)->index == -1) + --i; + if (d->visibleItems.at(i)->index + 1 == modelIndex) { + // Special case of appending an item to the model. + index = d->visibleIndex + d->visibleItems.count(); + } else { + if (modelIndex + count - 1 < d->visibleIndex) { + // Insert before visible items + d->visibleIndex += count; + for (int i = 0; i < d->visibleItems.count(); ++i) { + FxGridItem *listItem = d->visibleItems.at(i); + if (listItem->index != -1) + listItem->index += count; + } + } + if (d->currentIndex >= modelIndex) { + // adjust current item index + d->currentIndex += count; + if (d->currentItem) + d->currentItem->index = d->currentIndex; + } + d->layout(); + emit countChanged(); + return; + } + } + + // At least some of the added items will be visible + int insertCount = count; + if (index < d->visibleIndex) { + insertCount -= d->visibleIndex - index; + index = d->visibleIndex; + modelIndex = d->visibleIndex; + } + + index -= d->visibleIndex; + int to = d->buffer+d->position()+d->size()-1; + int colPos, rowPos; + if (index < d->visibleItems.count()) { + colPos = d->visibleItems.at(index)->colPos(); + rowPos = d->visibleItems.at(index)->rowPos(); + } else { + // appending items to visible list + colPos = d->visibleItems.at(index-1)->colPos() + d->colSize(); + rowPos = d->visibleItems.at(index-1)->rowPos(); + if (colPos > d->colSize() * (d->columns-1)) { + colPos = 0; + rowPos += d->rowSize(); + } + } + + QList added; + int i = 0; + for (; i < insertCount && rowPos + d->rowSize() - 1 <= to; ++i) { + int mod = (modelIndex+i) % d->columns; + while (mod++ < d->columns && modelIndex + i < d->model->count() && i < insertCount) { + FxGridItem *item = d->createItem(modelIndex + i); + d->visibleItems.insert(index, item); + item->setPosition(colPos, rowPos); + added.append(item); + colPos += d->colSize(); + if (colPos > d->colSize() * (d->columns-1)) { + colPos = 0; + rowPos += d->rowSize(); + } + ++index; + ++i; + } + } + + if (d->currentIndex >= modelIndex) { + // adjust current item index + d->currentIndex += count; + if (d->currentItem) { + d->currentItem->index = d->currentIndex; + d->currentItem->setPosition(d->colPosAt(d->currentIndex), d->rowPosAt(d->currentIndex)); + } + } + if (i < insertCount) { + // We didn't insert all our new items, which means anything + // beyond the current index is not visible - remove it. + while (d->visibleItems.count() > index) + d->releaseItem(d->visibleItems.takeLast()); + } else { + // Update the indexes of the following visible items. + for (; index < d->visibleItems.count(); ++index) { + FxGridItem *listItem = d->visibleItems.at(index); + if (listItem->index != -1) + listItem->index += count; + } + } + // everything is in order now - emit add() signal + for (int j = 0; j < added.count(); ++j) + added.at(j)->attached->emitAdd(); + d->layout(); + emit countChanged(); +} + +void QmlGraphicsGridView::itemsRemoved(int modelIndex, int count) +{ + Q_D(QmlGraphicsGridView); + bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; + int index = d->mapFromModel(modelIndex); + if (index == -1) { + if (modelIndex + count - 1 < d->visibleIndex) { + // Items removed before our visible items. + d->visibleIndex -= count; + for (int i = 0; i < d->visibleItems.count(); ++i) { + FxGridItem *listItem = d->visibleItems.at(i); + if (listItem->index != -1) + listItem->index -= count; + } + } + if (d->currentIndex >= modelIndex + count) { + d->currentIndex -= count; + if (d->currentItem) + d->currentItem->index -= count; + } else if (currentRemoved) { + // current item has been removed. + d->releaseItem(d->currentItem); + d->currentItem = 0; + d->currentIndex = -1; + d->updateCurrent(qMin(modelIndex, d->model->count()-1)); + } + d->layout(true); + emit countChanged(); + return; + } + + // Remove the items from the visible list, skipping anything already marked for removal + QList::Iterator it = d->visibleItems.begin(); + while (it != d->visibleItems.end()) { + FxGridItem *item = *it; + if (item->index == -1 || item->index < modelIndex) { + // already removed, or before removed items + ++it; + } else if (item->index >= modelIndex + count) { + // after removed items + item->index -= count; + ++it; + } else { + // removed item + item->attached->emitRemove(); + if (item->attached->delayRemove()) { + item->index = -1; + connect(item->attached, SIGNAL(delayRemoveChanged()), this, SLOT(destroyRemoved()), Qt::QueuedConnection); + ++it; + } else { + it = d->visibleItems.erase(it); + d->releaseItem(item); + } + } + } + + // fix current + if (d->currentIndex >= modelIndex + count) { + d->currentIndex -= count; + if (d->currentItem) + d->currentItem->index -= count; + } else if (currentRemoved) { + // current item has been removed. + d->releaseItem(d->currentItem); + d->currentItem = 0; + d->currentIndex = -1; + d->updateCurrent(qMin(modelIndex, d->model->count()-1)); + } + + // update visibleIndex + for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { + if ((*it)->index != -1) { + d->visibleIndex = (*it)->index; + break; + } + } + + if (d->visibleItems.isEmpty()) { + d->visibleIndex = 0; + d->setPosition(0); + refill(); + } else { + // Correct the positioning of the items + d->layout(); + } + emit countChanged(); +} + +void QmlGraphicsGridView::destroyRemoved() +{ + Q_D(QmlGraphicsGridView); + for (QList::Iterator it = d->visibleItems.begin(); + it != d->visibleItems.end();) { + FxGridItem *listItem = *it; + if (listItem->index == -1 && listItem->attached->delayRemove() == false) { + d->releaseItem(listItem); + it = d->visibleItems.erase(it); + } else { + ++it; + } + } + + // Correct the positioning of the items + d->layout(); +} + +void QmlGraphicsGridView::itemsMoved(int from, int to, int count) +{ + Q_D(QmlGraphicsGridView); + QHash moved; + + QList::Iterator it = d->visibleItems.begin(); + while (it != d->visibleItems.end()) { + FxGridItem *item = *it; + if (item->index >= from && item->index < from + count) { + // take the items that are moving + item->index += (to-from); + moved.insert(item->index, item); + it = d->visibleItems.erase(it); + } else { + if (item->index > from && item->index != -1) { + // move everything after the moved items. + item->index -= count; + } + ++it; + } + } + + int remaining = count; + int endIndex = d->visibleIndex; + it = d->visibleItems.begin(); + while (it != d->visibleItems.end()) { + FxGridItem *item = *it; + if (remaining && item->index >= to && item->index < to + count) { + // place items in the target position, reusing any existing items + FxGridItem *movedItem = moved.take(item->index); + if (!movedItem) + movedItem = d->createItem(item->index); + it = d->visibleItems.insert(it, movedItem); + ++it; + --remaining; + } else { + if (item->index != -1) { + if (item->index >= to) { + // update everything after the moved items. + item->index += count; + } + endIndex = item->index; + } + ++it; + } + } + + // If we have moved items to the end of the visible items + // then add any existing moved items that we have + while (FxGridItem *item = moved.take(endIndex+1)) { + d->visibleItems.append(item); + ++endIndex; + } + + // Whatever moved items remain are no longer visible items. + while (moved.count()) + d->releaseItem(moved.take(moved.begin().key())); + + d->layout(); +} + +void QmlGraphicsGridView::createdItem(int index, QmlGraphicsItem *item) +{ + Q_D(QmlGraphicsGridView); + item->setParentItem(this); + if (d->requestedIndex != index) { + item->setParentItem(this); + d->unrequestedItems.insert(item, index); + if (d->flow == QmlGraphicsGridView::LeftToRight) { + item->setPos(QPointF(d->colPosAt(index), d->rowPosAt(index))); + } else { + item->setPos(QPointF(d->rowPosAt(index), d->colPosAt(index))); + } + } +} + +void QmlGraphicsGridView::destroyingItem(QmlGraphicsItem *item) +{ + Q_D(QmlGraphicsGridView); + d->unrequestedItems.remove(item); +} + + +void QmlGraphicsGridView::refill() +{ + Q_D(QmlGraphicsGridView); + d->refill(d->position(), d->position()+d->size()-1); +} + + +QmlGraphicsGridViewAttached *QmlGraphicsGridView::qmlAttachedProperties(QObject *obj) +{ + return QmlGraphicsGridViewAttached::properties(obj); +} + +QML_DEFINE_TYPE(Qt, 4,6, (QT_VERSION&0x00ff00)>>8, GridView, QmlGraphicsGridView) + +QT_END_NAMESPACE + +#include "qfxgridview.moc" diff --git a/src/declarative/fx/qmlgraphicsgridview.h b/src/declarative/fx/qmlgraphicsgridview.h new file mode 100644 index 0000000..1582529 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsgridview.h @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSGRIDVIEW_H +#define QMLGRAPHICSGRIDVIEW_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlGraphicsVisualModel; +class QmlGraphicsGridViewAttached; +class QmlGraphicsGridViewPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsGridView : public QmlGraphicsFlickable +{ + Q_OBJECT + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsGridView) + + Q_PROPERTY(QVariant model READ model WRITE setModel) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) + Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) + Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) + Q_PROPERTY(Flow flow READ flow WRITE setFlow) + Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) + Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) + Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged) + Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged) + Q_CLASSINFO("DefaultProperty", "data") + +public: + QmlGraphicsGridView(QmlGraphicsItem *parent=0); + ~QmlGraphicsGridView(); + + QVariant model() const; + void setModel(const QVariant &); + + QmlComponent *delegate() const; + void setDelegate(QmlComponent *); + + int currentIndex() const; + void setCurrentIndex(int idx); + + QmlGraphicsItem *currentItem(); + int count() const; + + QmlComponent *highlight() const; + void setHighlight(QmlComponent *highlight); + + bool highlightFollowsCurrentItem() const; + void setHighlightFollowsCurrentItem(bool); + + Q_ENUMS(Flow) + enum Flow { LeftToRight, TopToBottom }; + Flow flow() const; + void setFlow(Flow); + + bool isWrapEnabled() const; + void setWrapEnabled(bool); + + int cacheBuffer() const; + void setCacheBuffer(int); + + int cellWidth() const; + void setCellWidth(int); + + int cellHeight() const; + void setCellHeight(int); + + static QmlGraphicsGridViewAttached *qmlAttachedProperties(QObject *); + +public Q_SLOTS: + void moveCurrentIndexUp(); + void moveCurrentIndexDown(); + void moveCurrentIndexLeft(); + void moveCurrentIndexRight(); + +Q_SIGNALS: + void countChanged(); + void currentIndexChanged(); + void cellWidthChanged(); + void cellHeightChanged(); + +protected: + virtual void viewportMoved(); + virtual qreal minYExtent() const; + virtual qreal maxYExtent() const; + virtual qreal minXExtent() const; + virtual qreal maxXExtent() const; + virtual void keyPressEvent(QKeyEvent *); + virtual void componentComplete(); + +private Q_SLOTS: + void trackedPositionChanged(); + void itemsInserted(int index, int count); + void itemsRemoved(int index, int count); + void itemsMoved(int from, int to, int count); + void destroyRemoved(); + void createdItem(int index, QmlGraphicsItem *item); + void destroyingItem(QmlGraphicsItem *item); + void sizeChange(); + +private: + void refill(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsGridView) +QML_DECLARE_TYPEINFO(QmlGraphicsGridView, QML_HAS_ATTACHED_PROPERTIES) + +QT_END_HEADER + +#endif diff --git a/src/declarative/fx/qmlgraphicsimage.cpp b/src/declarative/fx/qmlgraphicsimage.cpp new file mode 100644 index 0000000..a6156ce --- /dev/null +++ b/src/declarative/fx/qmlgraphicsimage.cpp @@ -0,0 +1,301 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsimage.h" +#include "qmlgraphicsimage_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Image,QmlGraphicsImage) + +/*! + \qmlclass Image QmlGraphicsImage + \brief The Image element allows you to add bitmaps to a scene. + \inherits Item + + The Image element supports untransformed, stretched and tiled. + + For an explanation of stretching and tiling, see the fillMode property description. + + Examples: + \table + \row + \o \image declarative-qtlogo1.png + \o Untransformed + \qml + Image { source: "pics/qtlogo.png" } + \endqml + \row + \o \image declarative-qtlogo2.png + \o fillMode: Stretch (default) + \qml + Image { + width: 160 + height: 160 + source: "pics/qtlogo.png" + } + \endqml + \row + \o \image declarative-qtlogo3.png + \o fillMode: Tile + \qml + Image { + fillMode: Image.Tile + width: 160; height: 160 + source: "pics/qtlogo.png" + } + \endqml + \row + \o \image declarative-qtlogo6.png + \o fillMode: TileVertically + \qml + Image { + fillMode: Image.TileVertically + width: 160; height: 160 + source: "pics/qtlogo.png" + } + \endqml + \row + \o \image declarative-qtlogo5.png + \o fillMode: TileHorizontally + \qml + Image { + fillMode: Image.TileHorizontally + width: 160; height: 160 + source: "pics/qtlogo.png" + } + \endqml + \endtable + */ + +/*! + \internal + \class QmlGraphicsImage Image + \brief The QmlGraphicsImage class provides an image item that you can add to a QmlView. + + \ingroup group_coreitems + + Example: + \qml + Image { source: "pics/star.png" } + \endqml + + A QmlGraphicsImage object can be instantiated in Qml using the tag \l Image. +*/ + +QmlGraphicsImage::QmlGraphicsImage(QmlGraphicsItem *parent) + : QmlGraphicsImageBase(*(new QmlGraphicsImagePrivate), parent) +{ + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QmlGraphicsImage::QmlGraphicsImage(QmlGraphicsImagePrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsImageBase(dd, parent) +{ + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QmlGraphicsImage::~QmlGraphicsImage() +{ +} + +QPixmap QmlGraphicsImage::pixmap() const +{ + Q_D(const QmlGraphicsImage); + return d->pix; +} + +void QmlGraphicsImage::setPixmap(const QPixmap &pix) +{ + Q_D(QmlGraphicsImage); + if (!d->url.isEmpty()) + return; + d->pix = pix; + + setImplicitWidth(d->pix.width()); + setImplicitHeight(d->pix.height()); + + update(); +} + +/*! + \qmlproperty enumeration Image::fillMode + + Set this property to define what happens when the image set for the item is smaller + than the size of the item. + + \list + \o Stretch - the image is scaled to fit + \o PreserveAspectFit - the image is scaled uniformly to fit without cropping + \o PreserveAspectCrop - the image is scaled uniformly to fill, cropping if necessary + \o Tile - the image is duplicated horizontally and vertically + \o TileVertically - the image is stretched horizontally and tiled vertically + \o TileHorizontally - the image is stretched vertically and tiled horizontally + \endlist + + \image declarative-image_fillMode.gif + \sa examples/declarative/fillmode + \sa examples/declarative/aspectratio +*/ +QmlGraphicsImage::FillMode QmlGraphicsImage::fillMode() const +{ + Q_D(const QmlGraphicsImage); + return d->fillMode; +} + +void QmlGraphicsImage::setFillMode(FillMode mode) +{ + Q_D(QmlGraphicsImage); + if (d->fillMode == mode) + return; + d->fillMode = mode; + update(); + emit fillModeChanged(); +} + +/*! + \qmlproperty enum Image::status + + This property holds the status of image loading. It can be one of: + \list + \o Null - no image has been set + \o Ready - the image has been loaded + \o Loading - the image is currently being loaded + \o Error - an error occurred while loading the image + \endlist + + \sa progress +*/ + +/*! + \qmlproperty real Image::progress + + This property holds the progress of image loading, from 0.0 (nothing loaded) + to 1.0 (finished). + + \sa status +*/ + +/*! + \qmlproperty bool Image::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 image 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. +*/ + +/*! + \qmlproperty url Image::source + + Image can handle any image format supported by Qt, loaded from any URL scheme supported by Qt. + + The URL may be absolute, or relative to the URL of the component. +*/ + +void QmlGraphicsImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + Q_D(QmlGraphicsImage); + if (d->pix.isNull()) + return; + + bool oldAA = p->testRenderHint(QPainter::Antialiasing); + bool oldSmooth = p->testRenderHint(QPainter::SmoothPixmapTransform); + if (d->smooth) + p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); + + if (width() != d->pix.width() || height() != d->pix.height()) { + if (d->fillMode >= Tile) { + if (d->fillMode == Tile) + p->drawTiledPixmap(QRectF(0,0,width(),height()), d->pix); + else if (d->fillMode == TileVertically) + p->drawTiledPixmap(QRectF(0,0,d->pix.width(),height()), d->pix); + else + p->drawTiledPixmap(QRectF(0,0,width(),d->pix.height()), d->pix); + } else { + qreal widthScale = width() / qreal(d->pix.width()); + qreal heightScale = height() / qreal(d->pix.height()); + + QTransform scale; + + if (d->fillMode == PreserveAspectFit) { + if (widthScale < heightScale) { + heightScale = widthScale; + scale.translate(0, (height() - heightScale * d->pix.height()) / 2); + } else if(heightScale < widthScale) { + widthScale = heightScale; + scale.translate((width() - widthScale * d->pix.width()) / 2, 0); + } + } else if (d->fillMode == PreserveAspectCrop) { + if (widthScale < heightScale) { + widthScale = heightScale; + scale.translate((width() - widthScale * d->pix.width()) / 2, 0); + } else if(heightScale < widthScale) { + heightScale = widthScale; + scale.translate(0, (height() - heightScale * d->pix.height()) / 2); + } + } + + scale.scale(widthScale, heightScale); + QTransform old = p->transform(); + p->setWorldTransform(scale * old); + p->drawPixmap(0, 0, d->pix); + p->setWorldTransform(old); + } + } else { + p->drawPixmap(0, 0, d->pix); + } + + if (d->smooth) { + p->setRenderHint(QPainter::Antialiasing, oldAA); + p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); + } +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsimage.h b/src/declarative/fx/qmlgraphicsimage.h new file mode 100644 index 0000000..167ecd4 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsimage.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSIMAGE_H +#define QMLGRAPHICSIMAGE_H + +#include +#include "qmlgraphicsimagebase.h" + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsImagePrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsImage : public QmlGraphicsImageBase +{ + Q_OBJECT + Q_ENUMS(FillMode) + + Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap DESIGNABLE false) + Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) + +public: + QmlGraphicsImage(QmlGraphicsItem *parent=0); + ~QmlGraphicsImage(); + + enum FillMode { Stretch, PreserveAspectFit, PreserveAspectCrop, Tile, TileVertically, TileHorizontally }; + FillMode fillMode() const; + void setFillMode(FillMode); + + QPixmap pixmap() const; + void setPixmap(const QPixmap &); + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +Q_SIGNALS: + void fillModeChanged(); + +protected: + QmlGraphicsImage(QmlGraphicsImagePrivate &dd, QmlGraphicsItem *parent); + +private: + Q_DISABLE_COPY(QmlGraphicsImage) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsImage) +}; + +QT_END_NAMESPACE +QML_DECLARE_TYPE(QmlGraphicsImage) +QT_END_HEADER + +#endif // QMLGRAPHICSIMAGE_H diff --git a/src/declarative/fx/qmlgraphicsimage_p.h b/src/declarative/fx/qmlgraphicsimage_p.h new file mode 100644 index 0000000..c5bcf8e --- /dev/null +++ b/src/declarative/fx/qmlgraphicsimage_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 QMLGRAPHICSIMAGE_P_H +#define QMLGRAPHICSIMAGE_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 "qmlgraphicsitem_p.h" +#include "qmlgraphicsimagebase_p.h" + +QT_BEGIN_NAMESPACE + +class QmlGraphicsImagePrivate : public QmlGraphicsImageBasePrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsImage) + +public: + QmlGraphicsImagePrivate() + : fillMode(QmlGraphicsImage::Stretch) + { + } + + QmlGraphicsImage::FillMode fillMode; + +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSIMAGE_P_H diff --git a/src/declarative/fx/qmlgraphicsimagebase.cpp b/src/declarative/fx/qmlgraphicsimagebase.cpp new file mode 100644 index 0000000..d71438d --- /dev/null +++ b/src/declarative/fx/qmlgraphicsimagebase.cpp @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsimagebase.h" +#include "qmlgraphicsimagebase_p.h" +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QmlGraphicsImageBase::QmlGraphicsImageBase(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsImageBasePrivate), parent) +{ + setFlag(QGraphicsItem::ItemHasNoContents, true); +} + +QmlGraphicsImageBase::QmlGraphicsImageBase(QmlGraphicsImageBasePrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ + setFlag(QGraphicsItem::ItemHasNoContents, true); +} + +QmlGraphicsImageBase::~QmlGraphicsImageBase() +{ + Q_D(QmlGraphicsImageBase); + if (d->pendingPixmapCache) + QmlGraphicsPixmapCache::cancelGet(d->url, this); +} + +QmlGraphicsImageBase::Status QmlGraphicsImageBase::status() const +{ + Q_D(const QmlGraphicsImageBase); + return d->status; +} + + +qreal QmlGraphicsImageBase::progress() const +{ + Q_D(const QmlGraphicsImageBase); + return d->progress; +} + +QUrl QmlGraphicsImageBase::source() const +{ + Q_D(const QmlGraphicsImageBase); + return d->url; +} + +void QmlGraphicsImageBase::setSource(const QUrl &url) +{ + Q_D(QmlGraphicsImageBase); + //equality is fairly expensive, so we bypass for simple, common case + if ((d->url.isEmpty() == url.isEmpty()) && url == d->url) + return; + + if (d->pendingPixmapCache) { + QmlGraphicsPixmapCache::cancelGet(d->url, this); + d->pendingPixmapCache = false; + } + + d->url = url; + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } + + if (url.isEmpty()) { + d->pix = QPixmap(); + d->status = Null; + d->progress = 1.0; + setImplicitWidth(0); + setImplicitHeight(0); + emit statusChanged(d->status); + emit sourceChanged(d->url); + emit progressChanged(1.0); + update(); + } else { + d->status = Loading; + QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->pix); + if (reply) { + d->pendingPixmapCache = true; + connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); + connect(reply, SIGNAL(downloadProgress(qint64,qint64)), + this, SLOT(requestProgress(qint64,qint64))); + } else { + //### should be unified with requestFinished + setImplicitWidth(d->pix.width()); + setImplicitHeight(d->pix.height()); + + if (d->status == Loading) + d->status = Ready; + d->progress = 1.0; + emit statusChanged(d->status); + emit sourceChanged(d->url); + emit progressChanged(1.0); + update(); + } + } + + emit statusChanged(d->status); +} + +void QmlGraphicsImageBase::requestFinished() +{ + Q_D(QmlGraphicsImageBase); + + d->pendingPixmapCache = false; + + if (!QmlGraphicsPixmapCache::find(d->url, &d->pix)) + d->status = Error; + setImplicitWidth(d->pix.width()); + setImplicitHeight(d->pix.height()); + + if (d->status == Loading) + d->status = Ready; + d->progress = 1.0; + emit statusChanged(d->status); + emit sourceChanged(d->url); + emit progressChanged(1.0); + update(); +} + +void QmlGraphicsImageBase::requestProgress(qint64 received, qint64 total) +{ + Q_D(QmlGraphicsImageBase); + if (d->status == Loading && total > 0) { + d->progress = qreal(received)/total; + emit progressChanged(d->progress); + } +} + + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsimagebase.h b/src/declarative/fx/qmlgraphicsimagebase.h new file mode 100644 index 0000000..3ad0e4b --- /dev/null +++ b/src/declarative/fx/qmlgraphicsimagebase.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSIMAGEBASE_H +#define QMLGRAPHICSIMAGEBASE_H + +#include + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +class QmlGraphicsImageBasePrivate; +class QmlGraphicsImageBase : public QmlGraphicsItem +{ + Q_OBJECT + Q_ENUMS(Status) + + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) + +public: + QmlGraphicsImageBase(QmlGraphicsItem *parent = 0); + ~QmlGraphicsImageBase(); + enum Status { Null, Ready, Loading, Error }; + Status status() const; + qreal progress() const; + + QUrl source() const; + virtual void setSource(const QUrl &url); + +Q_SIGNALS: + void sourceChanged(const QUrl &); + void statusChanged(Status); + void progressChanged(qreal progress); + +protected: + QmlGraphicsImageBase(QmlGraphicsImageBasePrivate &dd, QmlGraphicsItem *parent); + +private Q_SLOTS: + virtual void requestFinished(); + void requestProgress(qint64,qint64); + +private: + Q_DISABLE_COPY(QmlGraphicsImageBase) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsImageBase) +}; + +QT_END_NAMESPACE +QT_END_HEADER + +#endif // QMLGRAPHICSIMAGEBASE_H diff --git a/src/declarative/fx/qmlgraphicsimagebase_p.h b/src/declarative/fx/qmlgraphicsimagebase_p.h new file mode 100644 index 0000000..5fd5f11 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsimagebase_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSIMAGEBASE_P_H +#define QMLGRAPHICSIMAGEBASE_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 "qmlgraphicsitem_p.h" +#include + +QT_BEGIN_NAMESPACE + +class QNetworkReply; +class QmlGraphicsImageBasePrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsImageBase) + +public: + QmlGraphicsImageBasePrivate() + : status(QmlGraphicsImageBase::Null), + progress(0.0), + pendingPixmapCache(false) + { + } + + QPixmap pix; + QmlGraphicsImageBase::Status status; + QUrl url; + qreal progress; + bool pendingPixmapCache; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/declarative/fx/qmlgraphicsitem.cpp b/src/declarative/fx/qmlgraphicsitem.cpp new file mode 100644 index 0000000..d5b31d0 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsitem.cpp @@ -0,0 +1,2921 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include "qmlstate.h" +#include "qlistmodelinterface.h" + +#include "qmlview.h" +#include "qmlstategroup.h" + +#include "qmlgraphicsitem_p.h" +#include "qmlgraphicsitem.h" +#include "qmlgraphicsevents_p.h" +#include + +QT_BEGIN_NAMESPACE + +#ifndef FLT_MAX +#define FLT_MAX 1E+37 +#endif + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Item,QmlGraphicsItem) + +QML_DEFINE_NOCREATE_TYPE(QGraphicsTransform); +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Scale,QGraphicsScale) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) + +#include "qmlgraphicseffects.cpp" + +/*! + \qmlclass Transform + \brief The Transform elements provide a way of building advanced transformations on Items. + + The Transform elements let you create and control advanced transformations that can be configured + independently using specialized properties. + + You can assign any number of Transform elements to an Item. Each Transform is applied in order, + one at a time, to the Item it's assigned to. + + \sa Rotation, Scale +*/ + +/*! + \qmlclass Scale + \brief The Scale object provides a way to scale an Item. + + The Scale object gives more control over scaling than using Item's scale property. Specifically, + it allows a different scale for the x and y axes, and allows the scale to be relative to an + arbitrary point. + + The following example scales the X axis of the Rectangle, relative to its interior point 25, 25: + \qml + Rectangle { + width: 100; height: 100 + color: "blue" + transform: Scale { origin.x: 25; origin.y: 25; xScale: 3} + } + \endqml +*/ + +/*! + \qmlproperty real Scale::origin.x + \qmlproperty real Scale::origin.y + + The point that the item is scaled from (i.e., the point that stays fixed relative to the parent as + the rest of the item grows). By default the origin is 0, 0. +*/ + +/*! + \qmlproperty real Scale::xScale + + The scaling factor for the X axis. +*/ + +/*! + \qmlproperty real Scale::yScale + + The scaling factor for the Y axis. +*/ + +/*! + \qmlclass Rotation + \brief The Rotation object provides a way to rotate an Item. + + The Rotation object gives more control over rotation than using Item's rotation property. + Specifically, it allows (z axis) rotation to be relative to an arbitrary point. + + The following example rotates a Rectangle around its interior point 25, 25: + \qml + Rectangle { + width: 100; height: 100 + color: "blue" + transform: Rotation { origin.x: 25; origin.y: 25; angle: 45} + } + \endqml + + Rotation also provides a way to specify 3D-like rotations for Items. For these types of + rotations you must specify the axis to rotate around in addition to the origin point. + + The following example shows various 3D-like rotations applied to an \l Image. + \snippet doc/src/snippets/declarative/rotation.qml 0 + + \image axisrotation.png +*/ + +/*! + \qmlproperty real Rotation::origin.x + \qmlproperty real Rotation::origin.y + + The origin point of the rotation (i.e., the point that stays fixed relative to the parent as + the rest of the item rotates). By default the origin is 0, 0. +*/ + +/*! + \qmlproperty real Rotation::axis.x + \qmlproperty real Rotation::axis.y + \qmlproperty real Rotation::axis.z + + The axis to rotate around. For simple (2D) rotation around a point, you do not need to specify an axis, + as the default axis is the z axis (\c{ axis { x: 0; y: 0; z: 0 } }). + + For a typical 3D-like rotation you will usually specify both the origin and the axis. + + \image 3d-rotation-axis.png +*/ + +/*! + \qmlproperty real Rotation::angle + + The angle to rotate, in degrees clockwise. +*/ + + +/*! + \group group_animation + \title Animation +*/ + +/*! + \group group_coreitems + \title Basic Items +*/ + +/*! + \group group_effects + \title Effects +*/ + +/*! + \group group_layouts + \title Layouts +*/ + +/*! + \group group_states + \title States and Transitions +*/ + +/*! + \group group_utility + \title Utility +*/ + +/*! + \group group_views + \title Views +*/ + +/*! + \group group_widgets + \title Widgets +*/ + +/*! + \internal + \class QmlGraphicsContents + \ingroup group_utility + \brief The QmlGraphicsContents class gives access to the height and width of an item's contents. + +*/ + +QmlGraphicsContents::QmlGraphicsContents() : m_x(0), m_y(0), m_width(0), m_height(0) +{ +} + +/*! + \qmlproperty real Item::childrenRect.x + \qmlproperty real Item::childrenRect.y + \qmlproperty real Item::childrenRect.width + \qmlproperty real Item::childrenRect.height + + The childrenRect properties allow an item access to the geometry of its + children. This property is useful if you have an item that needs to be + sized to fit its children. +*/ + +QRectF QmlGraphicsContents::rectF() const +{ + return QRectF(m_x, m_y, m_width, m_height); +} + +//TODO: optimization: only check sender(), if there is one +void QmlGraphicsContents::calcHeight() +{ + qreal oldy = m_y; + qreal oldheight = m_height; + + qreal top = FLT_MAX; + qreal bottom = 0; + + QList children = m_item->childItems(); + for (int i = 0; i < children.count(); ++i) { + QmlGraphicsItem *child = qobject_cast(children.at(i)); + if(!child)//### Should this be ignoring non-QmlGraphicsItem graphicsobjects? + continue; + qreal y = child->y(); + if (y + child->height() > bottom) + bottom = y + child->height(); + if (y < top) + top = y; + } + if (!children.isEmpty()) + m_y = top; + m_height = qMax(bottom - top, qreal(0.0)); + + if (m_height != oldheight || m_y != oldy) + emit rectChanged(); +} + +//TODO: optimization: only check sender(), if there is one +void QmlGraphicsContents::calcWidth() +{ + qreal oldx = m_x; + qreal oldwidth = m_width; + + qreal left = FLT_MAX; + qreal right = 0; + + QList children = m_item->childItems(); + for (int i = 0; i < children.count(); ++i) { + QmlGraphicsItem *child = qobject_cast(children.at(i)); + if(!child)//### Should this be ignoring non-QmlGraphicsItem graphicsobjects? + continue; + qreal x = child->x(); + if (x + child->width() > right) + right = x + child->width(); + if (x < left) + left = x; + } + if (!children.isEmpty()) + m_x = left; + m_width = qMax(right - left, qreal(0.0)); + + if (m_width != oldwidth || m_x != oldx) + emit rectChanged(); +} + +void QmlGraphicsContents::setItem(QmlGraphicsItem *item) +{ + m_item = item; + + QList children = m_item->childItems(); + for (int i = 0; i < children.count(); ++i) { + QmlGraphicsItem *child = qobject_cast(children.at(i)); + if(!child)//### Should this be ignoring non-QmlGraphicsItem graphicsobjects? + continue; + connect(child, SIGNAL(heightChanged()), this, SLOT(calcHeight())); + connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight())); + connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth())); + connect(child, SIGNAL(xChanged()), this, SLOT(calcWidth())); + connect(this, SIGNAL(rectChanged()), m_item, SIGNAL(childrenRectChanged())); + } + + calcHeight(); + calcWidth(); +} + +/* + Key filters can be installed on a QmlGraphicsItem, but not removed. Currently they + are only used by attached objects (which are only destroyed on Item + destruction), so this isn't a problem. If in future this becomes any form + of public API, they will have to support removal too. +*/ +class QmlGraphicsItemKeyFilter +{ +public: + QmlGraphicsItemKeyFilter(QmlGraphicsItem * = 0); + virtual ~QmlGraphicsItemKeyFilter(); + + virtual void keyPressed(QKeyEvent *event); + virtual void keyReleased(QKeyEvent *event); + virtual void inputMethodEvent(QInputMethodEvent *event); + virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; + virtual void componentComplete(); + +private: + QmlGraphicsItemKeyFilter *m_next; +}; + +QmlGraphicsItemKeyFilter::QmlGraphicsItemKeyFilter(QmlGraphicsItem *item) +: m_next(0) +{ + QmlGraphicsItemPrivate *p = + item?static_cast(QGraphicsItemPrivate::get(item)):0; + if (p) { + m_next = p->keyHandler; + p->keyHandler = this; + } +} + +QmlGraphicsItemKeyFilter::~QmlGraphicsItemKeyFilter() +{ +} + +void QmlGraphicsItemKeyFilter::keyPressed(QKeyEvent *event) +{ + if (m_next) m_next->keyPressed(event); +} + +void QmlGraphicsItemKeyFilter::keyReleased(QKeyEvent *event) +{ + if (m_next) m_next->keyReleased(event); +} + +void QmlGraphicsItemKeyFilter::inputMethodEvent(QInputMethodEvent *event) +{ + if (m_next) m_next->inputMethodEvent(event); +} + +QVariant QmlGraphicsItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query) const +{ + if (m_next) return m_next->inputMethodQuery(query); + return QVariant(); +} + +void QmlGraphicsItemKeyFilter::componentComplete() +{ + if (m_next) m_next->componentComplete(); +} + +class QmlGraphicsKeyNavigationAttachedPrivate : public QObjectPrivate +{ +public: + QmlGraphicsKeyNavigationAttachedPrivate() + : QObjectPrivate(), left(0), right(0), up(0), down(0) {} + + QmlGraphicsItem *left; + QmlGraphicsItem *right; + QmlGraphicsItem *up; + QmlGraphicsItem *down; +}; + +class QmlGraphicsKeyNavigationAttached : public QObject, public QmlGraphicsItemKeyFilter +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlGraphicsKeyNavigationAttached) + + Q_PROPERTY(QmlGraphicsItem *left READ left WRITE setLeft NOTIFY changed) + Q_PROPERTY(QmlGraphicsItem *right READ right WRITE setRight NOTIFY changed) + Q_PROPERTY(QmlGraphicsItem *up READ up WRITE setUp NOTIFY changed) + Q_PROPERTY(QmlGraphicsItem *down READ down WRITE setDown NOTIFY changed) +public: + QmlGraphicsKeyNavigationAttached(QObject * = 0); + + QmlGraphicsItem *left() const; + void setLeft(QmlGraphicsItem *); + QmlGraphicsItem *right() const; + void setRight(QmlGraphicsItem *); + QmlGraphicsItem *up() const; + void setUp(QmlGraphicsItem *); + QmlGraphicsItem *down() const; + void setDown(QmlGraphicsItem *); + + static QmlGraphicsKeyNavigationAttached *qmlAttachedProperties(QObject *); + +Q_SIGNALS: + void changed(); + +private: + virtual void keyPressed(QKeyEvent *event); + virtual void keyReleased(QKeyEvent *event); +}; + +QmlGraphicsKeyNavigationAttached::QmlGraphicsKeyNavigationAttached(QObject *parent) +: QObject(*(new QmlGraphicsKeyNavigationAttachedPrivate), parent), + QmlGraphicsItemKeyFilter(qobject_cast(parent)) +{ +} + +QmlGraphicsKeyNavigationAttached * +QmlGraphicsKeyNavigationAttached::qmlAttachedProperties(QObject *obj) +{ + return new QmlGraphicsKeyNavigationAttached(obj); +} + +QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::left() const +{ + Q_D(const QmlGraphicsKeyNavigationAttached); + return d->left; +} + +void QmlGraphicsKeyNavigationAttached::setLeft(QmlGraphicsItem *i) +{ + Q_D(QmlGraphicsKeyNavigationAttached); + d->left = i; + emit changed(); +} + +QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::right() const +{ + Q_D(const QmlGraphicsKeyNavigationAttached); + return d->right; +} + +void QmlGraphicsKeyNavigationAttached::setRight(QmlGraphicsItem *i) +{ + Q_D(QmlGraphicsKeyNavigationAttached); + d->right = i; + emit changed(); +} + +QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::up() const +{ + Q_D(const QmlGraphicsKeyNavigationAttached); + return d->up; +} + +void QmlGraphicsKeyNavigationAttached::setUp(QmlGraphicsItem *i) +{ + Q_D(QmlGraphicsKeyNavigationAttached); + d->up = i; + emit changed(); +} + +QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::down() const +{ + Q_D(const QmlGraphicsKeyNavigationAttached); + return d->down; +} + +void QmlGraphicsKeyNavigationAttached::setDown(QmlGraphicsItem *i) +{ + Q_D(QmlGraphicsKeyNavigationAttached); + d->down = i; + emit changed(); +} + +void QmlGraphicsKeyNavigationAttached::keyPressed(QKeyEvent *event) +{ + Q_D(QmlGraphicsKeyNavigationAttached); + + event->ignore(); + + switch(event->key()) { + case Qt::Key_Left: + if (d->left) { + d->left->setFocus(true); + event->accept(); + } + break; + case Qt::Key_Right: + if (d->right) { + d->right->setFocus(true); + event->accept(); + } + break; + case Qt::Key_Up: + if (d->up) { + d->up->setFocus(true); + event->accept(); + } + break; + case Qt::Key_Down: + if (d->down) { + d->down->setFocus(true); + event->accept(); + } + break; + default: + break; + } + + if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyPressed(event); +} + +void QmlGraphicsKeyNavigationAttached::keyReleased(QKeyEvent *event) +{ + Q_D(QmlGraphicsKeyNavigationAttached); + + event->ignore(); + + switch(event->key()) { + case Qt::Key_Left: + if (d->left) { + event->accept(); + } + break; + case Qt::Key_Right: + if (d->right) { + event->accept(); + } + break; + case Qt::Key_Up: + if (d->up) { + event->accept(); + } + break; + case Qt::Key_Down: + if (d->down) { + event->accept(); + } + break; + default: + break; + } + + if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyReleased(event); +} + +/*! + \qmlclass Keys + \brief The Keys attached property provides key handling to Items. + + All visual primitives support key handling via the \e Keys + attached property. Keys can be handled via the \e onPressed + and \e onReleased signal properties. + + The signal properties have a \l KeyEvent parameter, named + \e event which contains details of the event. If a key is + handled \e event.accepted should be set to true to prevent the + event from propagating up the item heirarchy. + + \code + Item { + focus: true + Keys.onPressed: { + if (event.key == Qt.Key_Left) { + print("move left"); + event.accepted = true; + } + } + } + \endcode + + Some keys may alternatively be handled via specific signal properties, + for example \e onSelectPressed. These handlers automatically set + \e event.accepted to true. + + \code + Item { + focus: true + Keys.onLeftPressed: print("move left") + } + \endcode + + See \l {Qt::Key}{Qt.Key} for the list of keyboard codes. + + \sa KeyEvent +*/ + +/*! + \qmlproperty bool Keys::enabled + + This flags enables key handling if true (default); otherwise + no key handlers will be called. +*/ + +/*! + \qmlproperty List Keys::forwardTo + + This property provides a way to forward key presses, key releases, and keyboard input + coming from input methods to other items. This can be useful when you want + one item to handle some keys (e.g. the up and down arrow keys), and another item to + handle other keys (e.g. the left and right arrow keys). Once an item that has been + forwarded keys accepts the event it is no longer forwarded to items later in the + list. + + This example forwards key events to two lists: + \qml + ListView { id: list1 ... } + ListView { id: list2 ... } + Keys.forwardTo: [list1, list2] + focus: true + \endqml +*/ + +/*! + \qmlsignal Keys::onPressed(event) + + This handler is called when a key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onReleased(event) + + This handler is called when a key has been released. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit0Pressed(event) + + This handler is called when the digit '0' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit1Pressed(event) + + This handler is called when the digit '1' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit2Pressed(event) + + This handler is called when the digit '2' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit3Pressed(event) + + This handler is called when the digit '3' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit4Pressed(event) + + This handler is called when the digit '4' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit5Pressed(event) + + This handler is called when the digit '5' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit6Pressed(event) + + This handler is called when the digit '6' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit7Pressed(event) + + This handler is called when the digit '7' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit8Pressed(event) + + This handler is called when the digit '8' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit9Pressed(event) + + This handler is called when the digit '9' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onLeftPressed(event) + + This handler is called when the Left arrow has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onRightPressed(event) + + This handler is called when the Right arrow has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onUpPressed(event) + + This handler is called when the Up arrow has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDownPressed(event) + + This handler is called when the Down arrow has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onAsteriskPressed(event) + + This handler is called when the Asterisk '*' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onEscapePressed(event) + + This handler is called when the Escape key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onReturnPressed(event) + + This handler is called when the Return key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onEnterPressed(event) + + This handler is called when the Enter key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDeletePressed(event) + + This handler is called when the Delete key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onSpacePressed(event) + + This handler is called when the Space key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onBackPressed(event) + + This handler is called when the Back key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onCancelPressed(event) + + This handler is called when the Cancel key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onSelectPressed(event) + + This handler is called when the Select key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onYesPressed(event) + + This handler is called when the Yes key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onNoPressed(event) + + This handler is called when the No key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onContext1Pressed(event) + + This handler is called when the Context1 key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onContext2Pressed(event) + + This handler is called when the Context2 key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onContext3Pressed(event) + + This handler is called when the Context3 key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onContext4Pressed(event) + + This handler is called when the Context4 key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onCallPressed(event) + + This handler is called when the Call key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onHangupPressed(event) + + This handler is called when the Hangup key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onFlipPressed(event) + + This handler is called when the Flip key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onMenuPressed(event) + + This handler is called when the Menu key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onVolumeUpPressed(event) + + This handler is called when the VolumeUp key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onVolumeDownPressed(event) + + This handler is called when the VolumeDown key has been pressed. The \a event + parameter provides information about the event. +*/ + + +class QmlGraphicsKeysAttachedPrivate : public QObjectPrivate +{ +public: + QmlGraphicsKeysAttachedPrivate() + : QObjectPrivate(), inPress(false), inRelease(false) + , inIM(false), enabled(true), imeItem(0), item(0) + {} + + bool isConnected(const char *signalName); + + QGraphicsItem *finalFocusProxy(QGraphicsItem *item) const + { + QGraphicsItem *fp; + while ((fp = item->focusProxy())) + item = fp; + return item; + } + + //loop detection + bool inPress:1; + bool inRelease:1; + bool inIM:1; + + bool enabled : 1; + + QGraphicsItem *imeItem; + QList targets; + QmlGraphicsItem *item; +}; + +class QmlGraphicsKeysAttached : public QObject, public QmlGraphicsItemKeyFilter +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlGraphicsKeysAttached) + + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(QList *forwardTo READ forwardTo) + +public: + QmlGraphicsKeysAttached(QObject *parent=0); + ~QmlGraphicsKeysAttached(); + + bool enabled() const { Q_D(const QmlGraphicsKeysAttached); return d->enabled; } + void setEnabled(bool enabled) { + Q_D(QmlGraphicsKeysAttached); + if (enabled != d->enabled) { + d->enabled = enabled; + emit enabledChanged(); + } + } + + QList *forwardTo() { + Q_D(QmlGraphicsKeysAttached); + return &d->targets; + } + + virtual void componentComplete(); + + static QmlGraphicsKeysAttached *qmlAttachedProperties(QObject *); + +Q_SIGNALS: + void enabledChanged(); + void pressed(QmlGraphicsKeyEvent *event); + void released(QmlGraphicsKeyEvent *event); + void digit0Pressed(QmlGraphicsKeyEvent *event); + void digit1Pressed(QmlGraphicsKeyEvent *event); + void digit2Pressed(QmlGraphicsKeyEvent *event); + void digit3Pressed(QmlGraphicsKeyEvent *event); + void digit4Pressed(QmlGraphicsKeyEvent *event); + void digit5Pressed(QmlGraphicsKeyEvent *event); + void digit6Pressed(QmlGraphicsKeyEvent *event); + void digit7Pressed(QmlGraphicsKeyEvent *event); + void digit8Pressed(QmlGraphicsKeyEvent *event); + void digit9Pressed(QmlGraphicsKeyEvent *event); + + void leftPressed(QmlGraphicsKeyEvent *event); + void rightPressed(QmlGraphicsKeyEvent *event); + void upPressed(QmlGraphicsKeyEvent *event); + void downPressed(QmlGraphicsKeyEvent *event); + + void asteriskPressed(QmlGraphicsKeyEvent *event); + void numberSignPressed(QmlGraphicsKeyEvent *event); + void escapePressed(QmlGraphicsKeyEvent *event); + void returnPressed(QmlGraphicsKeyEvent *event); + void enterPressed(QmlGraphicsKeyEvent *event); + void deletePressed(QmlGraphicsKeyEvent *event); + void spacePressed(QmlGraphicsKeyEvent *event); + void backPressed(QmlGraphicsKeyEvent *event); + void cancelPressed(QmlGraphicsKeyEvent *event); + void selectPressed(QmlGraphicsKeyEvent *event); + void yesPressed(QmlGraphicsKeyEvent *event); + void noPressed(QmlGraphicsKeyEvent *event); + void context1Pressed(QmlGraphicsKeyEvent *event); + void context2Pressed(QmlGraphicsKeyEvent *event); + void context3Pressed(QmlGraphicsKeyEvent *event); + void context4Pressed(QmlGraphicsKeyEvent *event); + void callPressed(QmlGraphicsKeyEvent *event); + void hangupPressed(QmlGraphicsKeyEvent *event); + void flipPressed(QmlGraphicsKeyEvent *event); + void menuPressed(QmlGraphicsKeyEvent *event); + void volumeUpPressed(QmlGraphicsKeyEvent *event); + void volumeDownPressed(QmlGraphicsKeyEvent *event); + +private: + virtual void keyPressed(QKeyEvent *event); + virtual void keyReleased(QKeyEvent *event); + virtual void inputMethodEvent(QInputMethodEvent *); + virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; + + const QByteArray keyToSignal(int key) { + QByteArray keySignal; + if (key >= Qt::Key_0 && key <= Qt::Key_9) { + keySignal = "digit0Pressed"; + keySignal[5] = '0' + (key - Qt::Key_0); + } else { + int i = 0; + while (sigMap[i].key && sigMap[i].key != key) + ++i; + keySignal = sigMap[i].sig; + } + return keySignal; + } + + struct SigMap { + int key; + const char *sig; + }; + + static const SigMap sigMap[]; +}; + +const QmlGraphicsKeysAttached::SigMap QmlGraphicsKeysAttached::sigMap[] = { + { Qt::Key_Left, "leftPressed" }, + { Qt::Key_Right, "rightPressed" }, + { Qt::Key_Up, "upPressed" }, + { Qt::Key_Down, "downPressed" }, + { Qt::Key_Asterisk, "asteriskPressed" }, + { Qt::Key_NumberSign, "numberSignPressed" }, + { Qt::Key_Escape, "escapePressed" }, + { Qt::Key_Return, "returnPressed" }, + { Qt::Key_Enter, "enterPressed" }, + { Qt::Key_Delete, "deletePressed" }, + { Qt::Key_Space, "spacePressed" }, + { Qt::Key_Back, "backPressed" }, + { Qt::Key_Cancel, "cancelPressed" }, + { Qt::Key_Select, "selectPressed" }, + { Qt::Key_Yes, "yesPressed" }, + { Qt::Key_No, "noPressed" }, + { Qt::Key_Context1, "context1Pressed" }, + { Qt::Key_Context2, "context2Pressed" }, + { Qt::Key_Context3, "context3Pressed" }, + { Qt::Key_Context4, "context4Pressed" }, + { Qt::Key_Call, "callPressed" }, + { Qt::Key_Hangup, "hangupPressed" }, + { Qt::Key_Flip, "flipPressed" }, + { Qt::Key_Menu, "menuPressed" }, + { Qt::Key_VolumeUp, "volumeUpPressed" }, + { Qt::Key_VolumeDown, "volumeDownPressed" }, + { 0, 0 } +}; + +bool QmlGraphicsKeysAttachedPrivate::isConnected(const char *signalName) +{ + return isSignalConnected(signalIndex(signalName)); +} + +QmlGraphicsKeysAttached::QmlGraphicsKeysAttached(QObject *parent) +: QObject(*(new QmlGraphicsKeysAttachedPrivate), parent), + QmlGraphicsItemKeyFilter(qobject_cast(parent)) +{ + Q_D(QmlGraphicsKeysAttached); + d->item = qobject_cast(parent); +} + +QmlGraphicsKeysAttached::~QmlGraphicsKeysAttached() +{ +} + +void QmlGraphicsKeysAttached::componentComplete() +{ + Q_D(QmlGraphicsKeysAttached); + if (d->item) { + for (int ii = 0; ii < d->targets.count(); ++ii) { + QGraphicsItem *targetItem = d->finalFocusProxy(d->targets.at(ii)); + if (targetItem && (targetItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) { + d->item->setFlag(QGraphicsItem::ItemAcceptsInputMethod); + break; + } + } + } +} + +void QmlGraphicsKeysAttached::keyPressed(QKeyEvent *event) +{ + Q_D(QmlGraphicsKeysAttached); + if (!d->enabled || d->inPress) { + event->ignore(); + return; + } + + // first process forwards + if (d->item && d->item->scene()) { + d->inPress = true; + for (int ii = 0; ii < d->targets.count(); ++ii) { + QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); + if (i) { + d->item->scene()->sendEvent(i, event); + if (event->isAccepted()) { + d->inPress = false; + return; + } + } + } + d->inPress = false; + } + + QmlGraphicsKeyEvent ke(*event); + QByteArray keySignal = keyToSignal(event->key()); + if (!keySignal.isEmpty()) { + keySignal += "(QmlGraphicsKeyEvent*)"; + if (d->isConnected(keySignal)) { + // If we specifically handle a key then default to accepted + ke.setAccepted(true); + int idx = QmlGraphicsKeysAttached::staticMetaObject.indexOfSignal(keySignal); + metaObject()->method(idx).invoke(this, Q_ARG(QmlGraphicsKeysAttached, &ke)); + } + } + if (!ke.isAccepted()) + emit pressed(&ke); + event->setAccepted(ke.isAccepted()); + + if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyPressed(event); +} + +void QmlGraphicsKeysAttached::keyReleased(QKeyEvent *event) +{ + Q_D(QmlGraphicsKeysAttached); + if (!d->enabled || d->inRelease) { + event->ignore(); + return; + } + + if (d->item && d->item->scene()) { + d->inRelease = true; + for (int ii = 0; ii < d->targets.count(); ++ii) { + QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); + if (i) { + d->item->scene()->sendEvent(i, event); + if (event->isAccepted()) { + d->inRelease = false; + return; + } + } + } + d->inRelease = false; + } + + QmlGraphicsKeyEvent ke(*event); + emit released(&ke); + event->setAccepted(ke.isAccepted()); + + if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyReleased(event); +} + +void QmlGraphicsKeysAttached::inputMethodEvent(QInputMethodEvent *event) +{ + Q_D(QmlGraphicsKeysAttached); + if (d->item && !d->inIM && d->item->scene()) { + d->inIM = true; + for (int ii = 0; ii < d->targets.count(); ++ii) { + QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); + if (i && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod)) { + d->item->scene()->sendEvent(i, event); + if (event->isAccepted()) { + d->imeItem = i; + d->inIM = false; + return; + } + } + } + d->inIM = false; + } + if (!event->isAccepted()) QmlGraphicsItemKeyFilter::inputMethodEvent(event); +} + +class QmlGraphicsItemAccessor : public QGraphicsItem +{ +public: + QVariant doInputMethodQuery(Qt::InputMethodQuery query) const { + return QGraphicsItem::inputMethodQuery(query); + } +}; + +QVariant QmlGraphicsKeysAttached::inputMethodQuery(Qt::InputMethodQuery query) const +{ + Q_D(const QmlGraphicsKeysAttached); + if (d->item) { + for (int ii = 0; ii < d->targets.count(); ++ii) { + QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); + if (i && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod) && i == d->imeItem) { //### how robust is i == d->imeItem check? + QVariant v = static_cast(i)->doInputMethodQuery(query); + if (v.type() == QVariant::RectF) + v = d->item->mapRectFromItem(i, v.toRectF()); //### cost? + return v; + } + } + } + return QmlGraphicsItemKeyFilter::inputMethodQuery(query); +} + +QmlGraphicsKeysAttached *QmlGraphicsKeysAttached::qmlAttachedProperties(QObject *obj) +{ + return new QmlGraphicsKeysAttached(obj); +} + +/*! + \class QmlGraphicsItem + \brief The QmlGraphicsItem class provides the most basic of all visual items in QML. + + All visual items in Qt Declarative inherit from QmlGraphicsItem. Although QmlGraphicsItem + has no visual appearance, it defines all the properties that are + common across visual items - such as the x and y position, the + width and height, \l {anchor-layout}{anchoring} and key handling. + + You can subclass QmlGraphicsItem to provide your own custom visual item that inherits + these features. +*/ + +/*! + \qmlclass Item QmlGraphicsItem + \brief The Item is the most basic of all visual items in QML. + + All visual items in Qt Declarative inherit from Item. Although Item + has no visual appearance, it defines all the properties that are + common across visual items - such as the x and y position, the + width and height, \l {anchor-layout}{anchoring} and key handling. + + Item is also useful for grouping items together. + + \qml + Item { + Image { + file: "tile.png" + } + Image { + x: 80 + width: 100 + height: 100 + file: "tile.png" + } + Image { + x: 190 + width: 100 + height: 100 + tile: true + file: "tile.png" + } + } + \endqml + + \section1 Key Handling + + Key handling is available to all Item-based visual elements via the \l {Keys}{Keys} + attached property. The \e Keys attached property provides basic handlers such + as \l {Keys::onPressed(event)}{onPressed} and \l {Keys::onReleased(event)}{onReleased}, + as well as handlers for specific keys, such as + \l {Keys::onCancelPressed(event)}{onCancelPressed}. The example below + assigns \l {qmlfocus}{focus} to the item and handles + the Left key via the general \e onPressed handler and the Select key via the + onSelectPressed handler: + + \qml + Item { + focus: true + Keys.onPressed: { + if (event.key == Qt.Key_Left) { + print("move left"); + event.accepted = true; + } + } + Keys.onSelectPressed: print("Selected"); + } + \endqml + + See the \l {Keys}{Keys} attached property for detailed documentation. + + \ingroup group_coreitems +*/ + +/*! + \property QmlGraphicsItem::baseline + \internal +*/ + +/*! + \property QmlGraphicsItem::effect + \internal +*/ + +/*! + \property QmlGraphicsItem::focus + \internal +*/ + +/*! + \property QmlGraphicsItem::wantsFocus + \internal +*/ + +/*! + \property QmlGraphicsItem::transformOrigin + \internal +*/ + +/*! + \fn void QmlGraphicsItem::childrenRectChanged() + \internal +*/ + +/*! + \fn void QmlGraphicsItem::baselineOffsetChanged() + \internal +*/ + +/*! + \fn void QmlGraphicsItem::widthChanged() + \internal +*/ + +/*! + \fn void QmlGraphicsItem::heightChanged() + \internal +*/ + +/*! + \fn void QmlGraphicsItem::stateChanged(const QString &state) + \internal +*/ + +/*! + \fn void QmlGraphicsItem::parentChanged() + \internal +*/ + +/*! + \fn void QmlGraphicsItem::focusChanged() + \internal +*/ + +/*! + \fn void QmlGraphicsItem::wantsFocusChanged() + \internal +*/ + +static inline void qfxitem_registerAnchorLine() { + static bool registered = false; + if (!registered) { + qRegisterMetaType("QmlGraphicsAnchorLine"); + registered = true; + } +} + +/*! + \fn QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItem *parent) + + Constructs a QmlGraphicsItem with the given \a parent. +*/ +QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItem* parent) + : QGraphicsObject(*(new QmlGraphicsItemPrivate), parent, 0) +{ + Q_D(QmlGraphicsItem); + qfxitem_registerAnchorLine(); + d->init(parent); +} + +/*! \internal +*/ +QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItemPrivate &dd, QmlGraphicsItem *parent) + : QGraphicsObject(dd, parent, 0) +{ + Q_D(QmlGraphicsItem); + qfxitem_registerAnchorLine(); + d->init(parent); +} + +/*! + Destroys the QmlGraphicsItem. +*/ +QmlGraphicsItem::~QmlGraphicsItem() +{ + Q_D(QmlGraphicsItem); + for (int ii = 0; ii < d->dependantAnchors.count(); ++ii) { + QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); + anchor->d_func()->clearItem(this); + } + if (!d->parent || (parentItem() && !parentItem()->QGraphicsItem::d_ptr->inDestructor)) + for (int ii = 0; ii < d->dependantAnchors.count(); ++ii) { + QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); + if (anchor->d_func()->item && anchor->d_func()->item->parentItem() != this) //child will be deleted anyway + anchor->d_func()->updateOnComplete(); + } + d->dependantAnchors.clear(); + delete d->_anchorLines; d->_anchorLines = 0; + delete d->_anchors; d->_anchors = 0; +} + +/*! + \qmlproperty enum Item::transformOrigin + This property holds the origin point around which scale and rotation transform. + + Nine transform origins are available, as shown in the image below. + + \image declarative-transformorigin.png + + This example scales an image about its center. + \qml + Image { + source: "myimage.png" + transformOrigin: Item.Center + scale: 4 + } + \endqml + + The default transform origin is \c TopLeft. +*/ + +/*! + \qmlproperty Item Item::parent + This property holds the parent of the item. +*/ + +/*! + \property QmlGraphicsItem::parent + This property holds the parent of the item. +*/ +void QmlGraphicsItem::setParentItem(QmlGraphicsItem *parent) +{ + QmlGraphicsItem *oldParent = parentItem(); + if (parent == oldParent || !parent) return; + + QObject::setParent(parent); + QGraphicsObject::setParentItem(parent); +} + +/*! + Returns the QmlGraphicsItem parent of this item. +*/ +QmlGraphicsItem *QmlGraphicsItem::parentItem() const +{ + return qobject_cast(QGraphicsObject::parentItem()); +} + +/*! + \qmlproperty list Item::children + \qmlproperty list Item::resources + + The children property contains the list of visual children of this item. + The resources property contains non-visual resources that you want to + reference by name. + + Generally you can rely on Item's default property to handle all this for + you, but it can come in handy in some cases. + + \qml + Item { + children: [ + Text {}, + Rectangle {} + ] + resources: [ + Component { + id: myComponent + Text {} + } + ] + } + \endqml +*/ + +/*! + \property QmlGraphicsItem::children + \internal +*/ + +/*! + \property QmlGraphicsItem::resources + \internal +*/ + +/*! + Returns true if construction of the QML component is complete; otherwise + returns false. + + It is often desireable to delay some processing until the component is + completed. + + \sa componentComplete() +*/ +bool QmlGraphicsItem::isComponentComplete() const +{ + Q_D(const QmlGraphicsItem); + return d->_componentComplete; +} + +/*! + \property QmlGraphicsItem::anchors + \internal +*/ + +/*! \internal */ +QmlGraphicsAnchors *QmlGraphicsItem::anchors() +{ + Q_D(QmlGraphicsItem); + return d->anchors(); +} + +void QmlGraphicsItemPrivate::data_removeAt(int) +{ + // ### +} + +int QmlGraphicsItemPrivate::data_count() const +{ + // ### + return 0; +} + +void QmlGraphicsItemPrivate::data_append(QObject *o) +{ + Q_Q(QmlGraphicsItem); + QmlGraphicsItem *i = qobject_cast(o); + if (i) + q->fxChildren()->append(i); + else + resources_append(o); +} + +void QmlGraphicsItemPrivate::data_insert(int, QObject *) +{ + // ### +} + +QObject *QmlGraphicsItemPrivate::data_at(int) const +{ + // ### + return 0; +} + +void QmlGraphicsItemPrivate::data_clear() +{ + // ### +} + +void QmlGraphicsItemPrivate::resources_removeAt(int) +{ + // ### +} + +int QmlGraphicsItemPrivate::resources_count() const +{ + Q_Q(const QmlGraphicsItem); + return q->children().count(); +} + +void QmlGraphicsItemPrivate::resources_append(QObject *o) +{ + Q_Q(QmlGraphicsItem); + o->setParent(q); +} + +void QmlGraphicsItemPrivate::resources_insert(int, QObject *) +{ + // ### +} + +QObject *QmlGraphicsItemPrivate::resources_at(int idx) const +{ + Q_Q(const QmlGraphicsItem); + QObjectList children = q->children(); + if (idx < children.count()) + return children.at(idx); + else + return 0; +} + +void QmlGraphicsItemPrivate::resources_clear() +{ + // ### +} + +void QmlGraphicsItemPrivate::children_removeAt(int) +{ + // ### +} + +int QmlGraphicsItemPrivate::children_count() const +{ + Q_Q(const QmlGraphicsItem); + return q->childItems().count(); +} + +void QmlGraphicsItemPrivate::children_append(QmlGraphicsItem *i) +{ + Q_Q(QmlGraphicsItem); + i->setParentItem(q); +} + +void QmlGraphicsItemPrivate::children_insert(int, QmlGraphicsItem *) +{ + // ### +} + +QmlGraphicsItem *QmlGraphicsItemPrivate::children_at(int idx) const +{ + Q_Q(const QmlGraphicsItem); + QList children = q->childItems(); + if (idx < children.count()) + return qobject_cast(children.at(idx)); + else + return 0; +} + +void QmlGraphicsItemPrivate::children_clear() +{ + // ### +} + + +void QmlGraphicsItemPrivate::transform_removeAt(int i) +{ + if (!transformData) + return; + transformData->graphicsTransforms.removeAt(i); + dirtySceneTransform = 1; +} + +int QmlGraphicsItemPrivate::transform_count() const +{ + return transformData ? transformData->graphicsTransforms.size() : 0; +} + +void QmlGraphicsItemPrivate::transform_append(QGraphicsTransform *item) +{ + appendGraphicsTransform(item); +} + +void QmlGraphicsItemPrivate::transform_insert(int, QGraphicsTransform *) +{ + // ### +} + +QGraphicsTransform *QmlGraphicsItemPrivate::transform_at(int idx) const +{ + if (!transformData) + return 0; + return transformData->graphicsTransforms.at(idx); +} + +void QmlGraphicsItemPrivate::transform_clear() +{ + if (!transformData) + return; + Q_Q(QmlGraphicsItem); + q->setTransformations(QList()); +} + +/*! + \qmlproperty list Item::data + \default + + The data property is allows you to freely mix visual children and resources + of an item. If you assign a visual item to the data list it becomes + a child and if you assign any other object type, it is added as a resource. + + So you can write: + \qml + Item { + Text {} + Rectangle {} + Script {} + } + \endqml + + instead of: + \qml + Item { + children: [ + Text {}, + Rectangle {} + ] + resources: [ + Script {} + ] + } + \endqml + + data is a behind-the-scenes property: you should never need to explicitly + specify it. + */ + +/*! + \property QmlGraphicsItem::data + \internal +*/ + +/*! \internal */ +QmlList *QmlGraphicsItem::data() +{ + Q_D(QmlGraphicsItem); + return &d->data; +} + +/*! + \property QmlGraphicsItem::childrenRect + \brief The geometry of an item's children. + + childrenRect provides an easy way to access the (collective) position and size of the item's children. +*/ +QRectF QmlGraphicsItem::childrenRect() +{ + Q_D(QmlGraphicsItem); + if (!d->_contents) { + d->_contents = new QmlGraphicsContents; + d->_contents->setParent(this); + d->_contents->setItem(this); + } + return d->_contents->rectF(); +} + +bool QmlGraphicsItem::clip() const +{ + return flags() & ItemClipsChildrenToShape; +} + +void QmlGraphicsItem::setClip(bool c) +{ + setFlag(ItemClipsChildrenToShape, c); +} + +/*! + \qmlproperty real Item::x + \qmlproperty real Item::y + \qmlproperty real Item::width + \qmlproperty real Item::height + + Defines the item's position and size relative to its parent. + + \qml + Item { x: 100; y: 100; width: 100; height: 100 } + \endqml + */ + +/*! + \property QmlGraphicsItem::width + + Defines the item's width relative to its parent. + */ + +/*! + \property QmlGraphicsItem::height + + Defines the item's height relative to its parent. + */ + +/*! + \qmlproperty real Item::z + + Sets the stacking order of the item. By default the stacking order is 0. + + Items with a higher stacking value are drawn on top of items with a + lower stacking order. Items with the same stacking value are drawn + bottom up in the order they appear. Items with a negative stacking + value are drawn under their parent's content. + + The following example shows the various effects of stacking order. + + \table + \row + \o \image declarative-item_stacking1.png + \o Same \c z - later children above earlier children: + \qml + Item { + Rectangle { + color: "red" + width: 100; height: 100 + } + Rectangle { + color: "blue" + x: 50; y: 50; width: 100; height: 100 + } + } + \endqml + \row + \o \image declarative-item_stacking2.png + \o Higher \c z on top: + \qml + Item { + Rectangle { + z: 1 + color: "red" + width: 100; height: 100 + } + Rectangle { + color: "blue" + x: 50; y: 50; width: 100; height: 100 + } + } + \endqml + \row + \o \image declarative-item_stacking3.png + \o Same \c z - children above parents: + \qml + Item { + Rectangle { + color: "red" + width: 100; height: 100 + Rectangle { + color: "blue" + x: 50; y: 50; width: 100; height: 100 + } + } + } + \endqml + \row + \o \image declarative-item_stacking4.png + \o Lower \c z below: + \qml + Item { + Rectangle { + color: "red" + width: 100; height: 100 + Rectangle { + z: -1 + color: "blue" + x: 50; y: 50; width: 100; height: 100 + } + } + } + \endqml + \endtable + */ + +/*! + This function is called to handle this item's changes in + geometry from \a oldGeometry to \a newGeometry. If the two + geometries are the same, it doesn't do anything. + */ +void QmlGraphicsItem::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) +{ + Q_D(QmlGraphicsItem); + + if (d->_anchors) + d->_anchors->d_func()->updateMe(); + + if (transformOrigin() != QmlGraphicsItem::TopLeft) + setTransformOriginPoint(d->computeTransformOrigin()); + + if (newGeometry.x() != oldGeometry.x()) + emit xChanged(); + if (newGeometry.width() != oldGeometry.width()) + emit widthChanged(); + if (newGeometry.y() != oldGeometry.y()) + emit yChanged(); + if (newGeometry.height() != oldGeometry.height()) + emit heightChanged(); + + for(int ii = 0; ii < d->dependantAnchors.count(); ++ii) { + QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); + anchor->d_func()->update(this, newGeometry, oldGeometry); + } +} + +/*! \internal */ +void QmlGraphicsItem::keyPressEvent(QKeyEvent *event) +{ + Q_D(QmlGraphicsItem); + if (d->keyHandler) + d->keyHandler->keyPressed(event); + else + event->ignore(); +} + +/*! \internal */ +void QmlGraphicsItem::keyReleaseEvent(QKeyEvent *event) +{ + Q_D(QmlGraphicsItem); + if (d->keyHandler) + d->keyHandler->keyReleased(event); + else + event->ignore(); +} + +/*! \internal */ +void QmlGraphicsItem::inputMethodEvent(QInputMethodEvent *event) +{ + Q_D(QmlGraphicsItem); + if (d->keyHandler) + d->keyHandler->inputMethodEvent(event); + else + event->ignore(); +} + +/*! \internal */ +QVariant QmlGraphicsItem::inputMethodQuery(Qt::InputMethodQuery query) const +{ + Q_D(const QmlGraphicsItem); + QVariant v; + if (d->keyHandler) + v = d->keyHandler->inputMethodQuery(query); + + if (!v.isValid()) + v = QGraphicsObject::inputMethodQuery(query); + + return v; +} + +/*! + \qmlproperty string Item::id + This property holds the identifier for the item. + + The identifier can be used in bindings and other expressions to + refer to the item. For example: + + \qml + Text { id: myText; ... } + Text { text: myText.text } + \endqml + + The identifier is available throughout to the \l {components}{component} + where it is declared. The identifier must be unique in thecomponent. +*/ + +/*! + \internal +*/ +QmlGraphicsAnchorLine QmlGraphicsItem::left() const +{ + Q_D(const QmlGraphicsItem); + return d->anchorLines()->left; +} + +/*! + \internal +*/ +QmlGraphicsAnchorLine QmlGraphicsItem::right() const +{ + Q_D(const QmlGraphicsItem); + return d->anchorLines()->right; +} + +/*! + \internal +*/ +QmlGraphicsAnchorLine QmlGraphicsItem::horizontalCenter() const +{ + Q_D(const QmlGraphicsItem); + return d->anchorLines()->hCenter; +} + +/*! + \internal +*/ +QmlGraphicsAnchorLine QmlGraphicsItem::top() const +{ + Q_D(const QmlGraphicsItem); + return d->anchorLines()->top; +} + +/*! + \internal +*/ +QmlGraphicsAnchorLine QmlGraphicsItem::bottom() const +{ + Q_D(const QmlGraphicsItem); + return d->anchorLines()->bottom; +} + +/*! + \internal +*/ +QmlGraphicsAnchorLine QmlGraphicsItem::verticalCenter() const +{ + Q_D(const QmlGraphicsItem); + return d->anchorLines()->vCenter; +} + + +/*! + \internal +*/ +QmlGraphicsAnchorLine QmlGraphicsItem::baseline() const +{ + Q_D(const QmlGraphicsItem); + return d->anchorLines()->baseline; +} + +/*! + \property QmlGraphicsItem::top + \internal +*/ + +/*! + \property QmlGraphicsItem::bottom + \internal +*/ + +/*! + \property QmlGraphicsItem::left + \internal +*/ + +/*! + \property QmlGraphicsItem::right + \internal +*/ + +/*! + \property QmlGraphicsItem::horizontalCenter + \internal +*/ + +/*! + \property QmlGraphicsItem::verticalCenter + \internal +*/ + +/*! + \qmlproperty AnchorLine Item::top + \qmlproperty AnchorLine Item::bottom + \qmlproperty AnchorLine Item::left + \qmlproperty AnchorLine Item::right + \qmlproperty AnchorLine Item::horizontalCenter + \qmlproperty AnchorLine Item::verticalCenter + \qmlproperty AnchorLine Item::baseline + + The anchor lines of the item. + + For more information see \l {anchor-layout}{Anchor Layouts}. +*/ + +/*! + \qmlproperty AnchorLine Item::anchors.top + \qmlproperty AnchorLine Item::anchors.bottom + \qmlproperty AnchorLine Item::anchors.left + \qmlproperty AnchorLine Item::anchors.right + \qmlproperty AnchorLine Item::anchors.horizontalCenter + \qmlproperty AnchorLine Item::anchors.verticalCenter + \qmlproperty AnchorLine Item::anchors.baseline + + \qmlproperty Item Item::anchors.fill + \qmlproperty Item Item::anchors.centerIn + + \qmlproperty real Item::anchors.topMargin + \qmlproperty real Item::anchors.bottomMargin + \qmlproperty real Item::anchors.leftMargin + \qmlproperty real Item::anchors.rightMargin + \qmlproperty real Item::anchors.horizontalCenterOffset + \qmlproperty real Item::anchors.verticalCenterOffset + \qmlproperty real Item::anchors.baselineOffset + + Anchors provide a way to position an item by specifying its + relationship with other items. + + Margins apply to top, bottom, left, right, and fill anchors. + + Offsets apply for horizontal center, vertical center, and baseline anchors. + + \table + \row + \o \image declarative-anchors_example.png + \o Text anchored to Image, horizontally centered and vertically below, with a margin. + \qml + Image { id: pic; ... } + Text { + id: label + anchors.horizontalCenter: pic.horizontalCenter + anchors.top: pic.bottom + anchors.topMargin: 5 + ... + } + \endqml + \row + \o \image declarative-anchors_example2.png + \o + Left of Text anchored to right of Image, with a margin. The y + property of both defaults to 0. + + \qml + Image { id: pic; ... } + Text { + id: label + anchors.left: pic.right + anchors.leftMargin: 5 + ... + } + \endqml + \endtable + + anchors.fill provides a convenient way for one item to have the + same geometry as another item, and is equivalent to connecting all + four directional anchors. + + \note You can only anchor an item to siblings or a parent. + + For more information see \l {anchor-layout}{Anchor Layouts}. +*/ + +/*! + \property QmlGraphicsItem::baselineOffset + \brief The position of the item's baseline in local coordinates. + + The baseline of a Text item is the imaginary line on which the text + sits. Controls containing text usually set their baseline to the + baseline of their text. + + For non-text items, a default baseline offset of 0 is used. +*/ +qreal QmlGraphicsItem::baselineOffset() const +{ + Q_D(const QmlGraphicsItem); + if (!d->_baselineOffset.isValid()) { + return 0.0; + } else + return d->_baselineOffset; +} + +void QmlGraphicsItem::setBaselineOffset(qreal offset) +{ + Q_D(QmlGraphicsItem); + if (offset == d->_baselineOffset) + return; + + d->_baselineOffset = offset; + emit baselineOffsetChanged(); + + for(int ii = 0; ii < d->dependantAnchors.count(); ++ii) { + QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); + anchor->d_func()->updateVerticalAnchors(); + } +} + +/*! + \qmlproperty real Item::rotation + This property holds the rotation of the item in degrees clockwise. + + This specifies how many degrees to rotate the item around its transformOrigin. + The default rotation is 0 degrees (i.e. not rotated at all). + + \table + \row + \o \image declarative-rotation.png + \o + \qml + Rectangle { + color: "blue" + width: 100; height: 100 + Rectangle { + color: "green" + width: 25; height: 25 + } + Rectangle { + color: "red" + x: 25; y: 25; width: 50; height: 50 + rotation: 30 + } + } + \endqml + \endtable +*/ + +/*! + \qmlproperty real Item::scale + This property holds the scale of the item. + + A scale of less than 1 means the item will be displayed smaller than + normal, and a scale of greater than 1 means the item will be + displayed larger than normal. A negative scale means the item will + be mirrored. + + By default, items are displayed at a scale of 1 (i.e. at their + normal size). + + Scaling is from the item's transformOrigin. + + \table + \row + \o \image declarative-scale.png + \o + \qml + Rectangle { + color: "blue" + width: 100; height: 100 + Rectangle { + color: "green" + width: 25; height: 25 + } + Rectangle { + color: "red" + x: 25; y: 25; width: 50; height: 50 + scale: 1.4 + } + } + \endqml + \endtable +*/ + +/*! + \qmlproperty real Item::opacity + + The opacity of the item. Opacity is specified as a number between 0 + (fully transparent) and 1 (fully opaque). The default is 1. + + Opacity is an \e inherited attribute. That is, the opacity is + also applied individually to child items. In almost all cases this + is what you want. If you can spot the issue in the following + example, you might need to use an opacity filter (not yet available) instead. + + \table + \row + \o \image declarative-item_opacity1.png + \o + \qml + Item { + Rectangle { + color: "red" + width: 100; height: 100 + Rectangle { + color: "blue" + x: 50; y: 50; width: 100; height: 100 + } + } + } + \endqml + \row + \o \image declarative-item_opacity2.png + \o + \qml + Item { + Rectangle { + opacity: 0.5 + color: "red" + width: 100; height: 100 + Rectangle { + color: "blue" + x: 50; y: 50; width: 100; height: 100 + } + } + } + \endqml + \endtable +*/ + +/*! + Returns a value indicating whether mouse input should + remain with this item exclusively. + + \sa setKeepMouseGrab() + */ +bool QmlGraphicsItem::keepMouseGrab() const +{ + Q_D(const QmlGraphicsItem); + return d->_keepMouse; +} + +/*! + The flag indicating whether the mouse should remain + with this item is set to \a keep. + + This is useful for items that wish to grab and keep mouse + interaction following a predefined gesture. For example, + an item that is interested in horizontal mouse movement + may set keepMouseGrab to true once a threshold has been + exceeded. Once keepMouseGrab has been set to true, filtering + items will not react to mouse events. + + If the item does not indicate that it wishes to retain mouse grab, + a filtering item may steal the grab. For example, Flickable may attempt + to steal a mouse grab if it detects that the user has begun to + move the viewport. + + \sa keepMouseGrab + */ +void QmlGraphicsItem::setKeepMouseGrab(bool keep) +{ + Q_D(QmlGraphicsItem); + d->_keepMouse = keep; +} + +/*! + \internal + + This function emits the \e focusChanged signal. + + Subclasses overriding this function should call up + to their base class. +*/ +void QmlGraphicsItem::focusChanged(bool flag) +{ + Q_UNUSED(flag); + emit focusChanged(); +} + +/*! \internal */ +QmlList *QmlGraphicsItem::fxChildren() +{ + Q_D(QmlGraphicsItem); + return &(d->children); +} + +/*! \internal */ +QmlList *QmlGraphicsItem::resources() +{ + Q_D(QmlGraphicsItem); + return &(d->resources); +} + +/*! + \qmlproperty list Item::states + This property holds a list of states defined by the item. + + \qml + Item { + states: [ + State { ... }, + State { ... } + ... + ] + } + \endqml + + \sa {qmlstate}{States} +*/ + +/*! + \property QmlGraphicsItem::states + \internal +*/ +/*! \internal */ +QmlList* QmlGraphicsItem::states() +{ + Q_D(QmlGraphicsItem); + return d->states()->statesProperty(); +} + +/*! + \qmlproperty list Item::transitions + This property holds a list of transitions defined by the item. + + \qml + Item { + transitions: [ + Transition { ... }, + Transition { ... } + ... + ] + } + \endqml + + \sa {state-transitions}{Transitions} +*/ + +/*! + \property QmlGraphicsItem::transitions + \internal +*/ + +/*! \internal */ +QmlList* QmlGraphicsItem::transitions() +{ + Q_D(QmlGraphicsItem); + return d->states()->transitionsProperty(); +} + +/* + \qmlproperty list Item::filter + This property holds a list of graphical filters to be applied to the item. + + \l {Filter}{Filters} include things like \l {Blur}{blurring} + the item, or giving it a \l Reflection. Some + filters may not be available on all canvases; if a filter is not + available on a certain canvas, it will simply not be applied for + that canvas (but the QML will still be considered valid). + + \qml + Item { + filter: [ + Blur { ... }, + Relection { ... } + ... + ] + } + \endqml +*/ + +/*! + \qmlproperty bool Item::clip + This property holds whether clipping is enabled. + + if clipping is enabled, an item will clip its own painting, as well + as the painting of its children, to its bounding rectangle. + + Non-rectangular clipping regions are not supported for performance reasons. +*/ + +/*! + \property QmlGraphicsItem::clip + This property holds whether clipping is enabled. + + if clipping is enabled, an item will clip its own painting, as well + as the painting of its children, to its bounding rectangle. + + Non-rectangular clipping regions are not supported for performance reasons. +*/ + +/*! + \qmlproperty string Item::state + + This property holds the name of the current state of the item. + + This property is often used in scripts to change between states. For + example: + + \qml + Script { + function toggle() { + if (button.state == 'On') + button.state = 'Off'; + else + button.state = 'On'; + } + } + \endqml + + If the item is in its base state (i.e. no explicit state has been + set), \c state will be a blank string. Likewise, you can return an + item to its base state by setting its current state to \c ''. + + \sa {qmlstates}{States} +*/ + +/*! + \property QmlGraphicsItem::state + \internal +*/ + +/*! \internal */ +QString QmlGraphicsItem::state() const +{ + Q_D(const QmlGraphicsItem); + if (!d->_stateGroup) + return QString(); + else + return d->_stateGroup->state(); +} + +/*! \internal */ +void QmlGraphicsItem::setState(const QString &state) +{ + Q_D(QmlGraphicsItem); + d->states()->setState(state); +} + +/*! + \qmlproperty list Item::transform + This property holds the list of transformations to apply. + + For more information see \l Transform. +*/ + +/*! + \property QmlGraphicsItem::transform + \internal +*/ + +/*! \internal */ +QmlList* QmlGraphicsItem::transform() +{ + Q_D(QmlGraphicsItem); + return &(d->transform); +} + +/*! + \internal + + classBegin() is called when the item is constructed, but its + properties have not yet been set. + + \sa componentComplete(), isComponentComplete() +*/ +void QmlGraphicsItem::classBegin() +{ + Q_D(QmlGraphicsItem); + d->_componentComplete = false; + if (d->_stateGroup) + d->_stateGroup->classBegin(); + if (d->_anchors) + d->_anchors->classBegin(); +} + +/*! + \internal + + componentComplete() is called when all items in the component + have been constructed. It is often desireable to delay some + processing until the component is complete an all bindings in the + component have been resolved. +*/ +void QmlGraphicsItem::componentComplete() +{ +#ifdef Q_ENABLE_PERFORMANCE_LOG + QmlPerfTimer cc; +#endif + + Q_D(QmlGraphicsItem); + d->_componentComplete = true; + if (d->_stateGroup) + d->_stateGroup->componentComplete(); + if (d->_anchors) { + d->_anchors->componentComplete(); + d->_anchors->d_func()->updateOnComplete(); + } + if (d->keyHandler) + d->keyHandler->componentComplete(); +} + +QmlStateGroup *QmlGraphicsItemPrivate::states() +{ + Q_Q(QmlGraphicsItem); + if (!_stateGroup) { + _stateGroup = new QmlStateGroup(q); + if (!_componentComplete) + _stateGroup->classBegin(); + QObject::connect(_stateGroup, SIGNAL(stateChanged(QString)), + q, SIGNAL(stateChanged(QString))); + } + + return _stateGroup; +} + +QmlGraphicsItemPrivate::AnchorLines::AnchorLines(QmlGraphicsItem *q) +{ + left.item = q; + left.anchorLine = QmlGraphicsAnchorLine::Left; + right.item = q; + right.anchorLine = QmlGraphicsAnchorLine::Right; + hCenter.item = q; + hCenter.anchorLine = QmlGraphicsAnchorLine::HCenter; + top.item = q; + top.anchorLine = QmlGraphicsAnchorLine::Top; + bottom.item = q; + bottom.anchorLine = QmlGraphicsAnchorLine::Bottom; + vCenter.item = q; + vCenter.anchorLine = QmlGraphicsAnchorLine::VCenter; + baseline.item = q; + baseline.anchorLine = QmlGraphicsAnchorLine::Baseline; +} + +QPointF QmlGraphicsItemPrivate::computeTransformOrigin() const +{ + Q_Q(const QmlGraphicsItem); + + QRectF br = q->boundingRect(); + + switch(origin) { + default: + case QmlGraphicsItem::TopLeft: + return QPointF(0, 0); + case QmlGraphicsItem::Top: + return QPointF(br.width() / 2., 0); + case QmlGraphicsItem::TopRight: + return QPointF(br.width(), 0); + case QmlGraphicsItem::Left: + return QPointF(0, br.height() / 2.); + case QmlGraphicsItem::Center: + return QPointF(br.width() / 2., br.height() / 2.); + case QmlGraphicsItem::Right: + return QPointF(br.width(), br.height() / 2.); + case QmlGraphicsItem::BottomLeft: + return QPointF(0, br.height()); + case QmlGraphicsItem::Bottom: + return QPointF(br.width() / 2., br.height()); + case QmlGraphicsItem::BottomRight: + return QPointF(br.width(), br.height()); + } +} + +/*! \internal */ +bool QmlGraphicsItem::sceneEvent(QEvent *event) +{ + bool rv = QGraphicsItem::sceneEvent(event); + + if (event->type() == QEvent::FocusIn || + event->type() == QEvent::FocusOut) { + focusChanged(hasFocus()); + } + + return rv; +} + +/*! \internal */ +QVariant QmlGraphicsItem::itemChange(GraphicsItemChange change, + const QVariant &value) +{ + if (change == ItemParentHasChanged) { + emit parentChanged(); + } + + return QGraphicsItem::itemChange(change, value); +} + +/*! \internal */ +QRectF QmlGraphicsItem::boundingRect() const +{ + Q_D(const QmlGraphicsItem); + return QRectF(0, 0, d->width, d->height); +} + +/*! + \enum QmlGraphicsItem::TransformOrigin + + Controls the point about which simple transforms like scale apply. + + \value TopLeft The top-left corner of the item. + \value Top The center point of the top of the item. + \value TopRight The top-right corner of the item. + \value Left The left most point of the vertical middle. + \value Center The center of the item. + \value Right The right most point of the vertical middle. + \value BottomLeft The bottom-left corner of the item. + \value Bottom The center point of the bottom of the item. + \value BottomRight The bottom-right corner of the item. +*/ + +/*! + Returns the current transform origin. +*/ +QmlGraphicsItem::TransformOrigin QmlGraphicsItem::transformOrigin() const +{ + Q_D(const QmlGraphicsItem); + return d->origin; +} + +/*! + Set the transform \a origin. +*/ +void QmlGraphicsItem::setTransformOrigin(TransformOrigin origin) +{ + Q_D(QmlGraphicsItem); + if (origin != d->origin) { + d->origin = origin; + QGraphicsItem::setTransformOriginPoint(d->computeTransformOrigin()); + } +} + +/*! + \property QmlGraphicsItem::smooth + \brief whether the item is smoothly transformed. + + This property is provided purely for the purpose of optimization. Turning + smooth transforms off is faster, but looks worse; turning smooth + transformations on is slower, but looks better. + + By default smooth transformations are off. +*/ + +/*! + Returns true if the item should be drawn with antialiasing and + smooth pixmap filtering, false otherwise. + + The default is false. + + \sa setSmoothTransform() +*/ +bool QmlGraphicsItem::smoothTransform() const +{ + Q_D(const QmlGraphicsItem); + return d->smooth; +} + +/*! + Sets whether the item should be drawn with antialiasing and + smooth pixmap filtering to \a smooth. + + \sa smoothTransform() +*/ +void QmlGraphicsItem::setSmoothTransform(bool smooth) +{ + Q_D(QmlGraphicsItem); + if (d->smooth == smooth) + return; + d->smooth = smooth; + update(); +} + +qreal QmlGraphicsItem::width() const +{ + Q_D(const QmlGraphicsItem); + return d->width; +} + +void QmlGraphicsItem::setWidth(qreal w) +{ + Q_D(QmlGraphicsItem); + d->widthValid = true; + if (d->width == w) + return; + + qreal oldWidth = d->width; + + prepareGeometryChange(); + d->width = w; + update(); + + geometryChanged(QRectF(x(), y(), width(), height()), + QRectF(x(), y(), oldWidth, height())); +} + +void QmlGraphicsItem::resetWidth() +{ + Q_D(QmlGraphicsItem); + d->widthValid = false; + setImplicitWidth(implicitWidth()); +} + +qreal QmlGraphicsItem::implicitWidth() const +{ + Q_D(const QmlGraphicsItem); + return d->implicitWidth; +} + +void QmlGraphicsItem::setImplicitWidth(qreal w) +{ + Q_D(QmlGraphicsItem); + d->implicitWidth = w; + if (d->width == w || widthValid()) + return; + + qreal oldWidth = d->width; + + prepareGeometryChange(); + d->width = w; + update(); + + geometryChanged(QRectF(x(), y(), width(), height()), + QRectF(x(), y(), oldWidth, height())); +} + +bool QmlGraphicsItem::widthValid() const +{ + Q_D(const QmlGraphicsItem); + return d->widthValid; +} + +qreal QmlGraphicsItem::height() const +{ + Q_D(const QmlGraphicsItem); + return d->height; +} + +void QmlGraphicsItem::setHeight(qreal h) +{ + Q_D(QmlGraphicsItem); + d->heightValid = true; + if (d->height == h) + return; + + qreal oldHeight = d->height; + + prepareGeometryChange(); + d->height = h; + update(); + + geometryChanged(QRectF(x(), y(), width(), height()), + QRectF(x(), y(), width(), oldHeight)); +} + +void QmlGraphicsItem::resetHeight() +{ + Q_D(QmlGraphicsItem); + d->heightValid = false; + setImplicitHeight(implicitHeight()); +} + +qreal QmlGraphicsItem::implicitHeight() const +{ + Q_D(const QmlGraphicsItem); + return d->implicitHeight; +} + +void QmlGraphicsItem::setImplicitHeight(qreal h) +{ + Q_D(QmlGraphicsItem); + d->implicitHeight = h; + if (d->height == h || heightValid()) + return; + + qreal oldHeight = d->height; + + prepareGeometryChange(); + d->height = h; + update(); + + geometryChanged(QRectF(x(), y(), width(), height()), + QRectF(x(), y(), width(), oldHeight)); +} + +bool QmlGraphicsItem::heightValid() const +{ + Q_D(const QmlGraphicsItem); + return d->heightValid; +} + +/*! + \qmlproperty bool Item::wantsFocus + + This property indicates whether the item has has an active focus request. +*/ + +/*! \internal */ +bool QmlGraphicsItem::wantsFocus() const +{ + return focusItem() != 0; +} + +/*! + \qmlproperty bool Item::focus + This property indicates whether the item has keyboard input focus. Set this + property to true to request focus. +*/ + +/*! \internal */ +bool QmlGraphicsItem::hasFocus() const +{ + return QGraphicsItem::hasFocus(); +} + +/*! \internal */ +void QmlGraphicsItem::setFocus(bool focus) +{ + if (focus) + QGraphicsItem::setFocus(Qt::OtherFocusReason); + else + QGraphicsItem::clearFocus(); +} + +/*! + \reimp + \internal +*/ +void QmlGraphicsItem::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) +{ +} + +/*! + \reimp + \internal +*/ +bool QmlGraphicsItem::event(QEvent *ev) +{ + return QGraphicsObject::event(ev); +} + +QDebug operator<<(QDebug debug, QmlGraphicsItem *item) +{ + if (!item) { + debug << "QmlGraphicsItem(0)"; + return debug; + } + + debug << item->metaObject()->className() << "(this =" << ((void*)item) + << ", parent =" << ((void*)item->parentItem()) + << ", geometry =" << QRectF(item->pos(), QSizeF(item->width(), item->height())) + << ", z =" << item->zValue() << ")"; + return debug; +} + +int QmlGraphicsItemPrivate::consistentTime = -1; +void QmlGraphicsItemPrivate::setConsistentTime(int t) +{ + consistentTime = t; +} + +QTime QmlGraphicsItemPrivate::currentTime() +{ + if (consistentTime == -1) + return QTime::currentTime(); + else + return QTime(0, 0).addMSecs(consistentTime); +} + +void QmlGraphicsItemPrivate::start(QTime &t) +{ + t = currentTime(); +} + +int QmlGraphicsItemPrivate::elapsed(QTime &t) +{ + int n = t.msecsTo(currentTime()); + if (n < 0) // passed midnight + n += 86400 * 1000; + return n; +} + +int QmlGraphicsItemPrivate::restart(QTime &t) +{ + QTime time = currentTime(); + int n = t.msecsTo(time); + if (n < 0) // passed midnight + n += 86400*1000; + t = time; + return n; +} + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsKeysAttached) +QML_DECLARE_TYPEINFO(QmlGraphicsKeysAttached, QML_HAS_ATTACHED_PROPERTIES) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Keys,QmlGraphicsKeysAttached) +QML_DECLARE_TYPE(QmlGraphicsKeyNavigationAttached) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,KeyNavigation,QmlGraphicsKeyNavigationAttached) + +#include "moc_qmlgraphicsitem.cpp" +#include "qfxitem.moc" diff --git a/src/declarative/fx/qmlgraphicsitem.h b/src/declarative/fx/qmlgraphicsitem.h new file mode 100644 index 0000000..0672dd6 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsitem.h @@ -0,0 +1,238 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSITEM_H +#define QMLGRAPHICSITEM_H + +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlState; +class QmlGraphicsAnchorLine; +class QmlTransition; +class QmlGraphicsKeyEvent; +class QmlGraphicsAnchors; +class QmlGraphicsItemPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsItem : public QGraphicsObject, public QmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QmlParserStatus) + + Q_PROPERTY(QmlGraphicsItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL) + Q_PROPERTY(QmlList *data READ data DESIGNABLE false) + Q_PROPERTY(QmlList* children READ fxChildren DESIGNABLE false) + Q_PROPERTY(QmlList* resources READ resources DESIGNABLE false) + Q_PROPERTY(QmlList* states READ states DESIGNABLE false) + Q_PROPERTY(QmlList* transitions READ transitions DESIGNABLE false) + Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) + Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL) + Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL) + Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL) + Q_PROPERTY(QmlGraphicsAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine left READ left CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine right READ right CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine top READ top CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine bottom READ bottom CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL) + Q_PROPERTY(QmlGraphicsAnchorLine baseline READ baseline CONSTANT FINAL) + Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged) + Q_PROPERTY(bool clip READ clip WRITE setClip) // ### move to QGI/QGO, NOTIFY + Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL) + Q_PROPERTY(bool wantsFocus READ wantsFocus NOTIFY wantsFocusChanged) + Q_PROPERTY(QmlList* transform READ transform DESIGNABLE false FINAL) + Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin) + Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform) + Q_PROPERTY(QGraphicsEffect *effect READ graphicsEffect WRITE setGraphicsEffect) + Q_ENUMS(TransformOrigin) + Q_CLASSINFO("DefaultProperty", "data") + +public: + enum TransformOrigin { + TopLeft, Top, TopRight, + Left, Center, Right, + BottomLeft, Bottom, BottomRight + }; + + QmlGraphicsItem(QmlGraphicsItem *parent = 0); + virtual ~QmlGraphicsItem(); + + QmlGraphicsItem *parentItem() const; + void setParentItem(QmlGraphicsItem *parent); + void setParent(QmlGraphicsItem *parent) { setParentItem(parent); } + + QmlList *data(); + QmlList *fxChildren(); + QmlList *resources(); + + QmlGraphicsAnchors *anchors(); + QRectF childrenRect(); + + bool clip() const; + void setClip(bool); + + QmlList* states(); + QmlList* transitions(); + + QString state() const; + void setState(const QString &); + + qreal baselineOffset() const; + void setBaselineOffset(qreal); + + QmlList *transform(); + + qreal width() const; + void setWidth(qreal); + void resetWidth(); + qreal implicitWidth() const; + + qreal height() const; + void setHeight(qreal); + void resetHeight(); + qreal implicitHeight() const; + + TransformOrigin transformOrigin() const; + void setTransformOrigin(TransformOrigin); + + bool smoothTransform() const; + void setSmoothTransform(bool); + + QRectF boundingRect() const; + virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + + bool wantsFocus() const; + bool hasFocus() const; + void setFocus(bool); + + bool keepMouseGrab() const; + void setKeepMouseGrab(bool); + +Q_SIGNALS: + void widthChanged(); + void heightChanged(); + void childrenRectChanged(); + void baselineOffsetChanged(); + void stateChanged(const QString &); + void focusChanged(); + void wantsFocusChanged(); + void parentChanged(); + +protected: + bool isComponentComplete() const; + virtual bool sceneEvent(QEvent *); + virtual bool event(QEvent *); + virtual QVariant itemChange(GraphicsItemChange, const QVariant &); + + void setImplicitWidth(qreal); + bool widthValid() const; // ### better name? + void setImplicitHeight(qreal); + bool heightValid() const; // ### better name? + + virtual void classBegin(); + virtual void componentComplete(); + virtual void focusChanged(bool); + virtual void keyPressEvent(QKeyEvent *event); + virtual void keyReleaseEvent(QKeyEvent *event); + virtual void inputMethodEvent(QInputMethodEvent *); + virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + +protected: + QmlGraphicsItem(QmlGraphicsItemPrivate &dd, QmlGraphicsItem *parent = 0); + +private: + // ### public? + QmlGraphicsAnchorLine left() const; + QmlGraphicsAnchorLine right() const; + QmlGraphicsAnchorLine horizontalCenter() const; + QmlGraphicsAnchorLine top() const; + QmlGraphicsAnchorLine bottom() const; + QmlGraphicsAnchorLine verticalCenter() const; + QmlGraphicsAnchorLine baseline() const; + + friend class QmlStatePrivate; + friend class QmlGraphicsAnchors; + Q_DISABLE_COPY(QmlGraphicsItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsItem) +}; + +template + T qobject_cast(QGraphicsObject *o) +{ + QObject *obj = o; + return qobject_cast(obj); +} + +// ### move to QGO +template +T qobject_cast(QGraphicsItem *item) +{ + if (!item) return 0; + QObject *o = item->toGraphicsObject(); + return qobject_cast(o); +} + +QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QmlGraphicsItem *item); + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsItem) +QML_DECLARE_TYPE(QGraphicsTransform) +QML_DECLARE_TYPE(QGraphicsScale) +QML_DECLARE_TYPE(QGraphicsRotation) + +QT_END_HEADER + +#endif // QMLGRAPHICSITEM_H diff --git a/src/declarative/fx/qmlgraphicsitem_p.h b/src/declarative/fx/qmlgraphicsitem_p.h new file mode 100644 index 0000000..799374a --- /dev/null +++ b/src/declarative/fx/qmlgraphicsitem_p.h @@ -0,0 +1,245 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSITEM_P_H +#define QMLGRAPHICSITEM_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QNetworkReply; +class QmlGraphicsItemKeyFilter; + +//### merge into private? +class QmlGraphicsContents : public QObject +{ + Q_OBJECT +public: + QmlGraphicsContents(); + + QRectF rectF() const; + + void setItem(QmlGraphicsItem *item); + +public Q_SLOTS: + void calcHeight(); + void calcWidth(); + +Q_SIGNALS: + void rectChanged(); + +private: + QmlGraphicsItem *m_item; + qreal m_x; + qreal m_y; + qreal m_width; + qreal m_height; +}; + +class QmlGraphicsItemPrivate : public QGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsItem) + +public: + QmlGraphicsItemPrivate() + : _anchors(0), _contents(0), + _baselineOffset(0), + _anchorLines(0), + _stateGroup(0), origin(QmlGraphicsItem::TopLeft), + widthValid(false), heightValid(false), + _componentComplete(true), _keepMouse(false), + smooth(false), keyHandler(0), + width(0), height(0), implicitWidth(0), implicitHeight(0) + {} + ~QmlGraphicsItemPrivate() + { delete _anchors; } + + void init(QmlGraphicsItem *parent) + { + Q_Q(QmlGraphicsItem); + + if (parent) + q->setParentItem(parent); + _baselineOffset.invalidate(); + q->setAcceptedMouseButtons(Qt::NoButton); + q->setFlags(QGraphicsItem::ItemHasNoContents | + QGraphicsItem::ItemIsFocusable | + QGraphicsItem::ItemNegativeZStacksBehindParent); + mouseSetsFocus = false; + } + + QString _id; + + // data property + void data_removeAt(int); + int data_count() const; + void data_append(QObject *); + void data_insert(int, QObject *); + QObject *data_at(int) const; + void data_clear(); + QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QObject *, data) + + // resources property + void resources_removeAt(int); + int resources_count() const; + void resources_append(QObject *); + void resources_insert(int, QObject *); + QObject *resources_at(int) const; + void resources_clear(); + QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QObject *, resources) + + // children property + void children_removeAt(int); + int children_count() const; + void children_append(QmlGraphicsItem *); + void children_insert(int, QmlGraphicsItem *); + QmlGraphicsItem *children_at(int) const; + void children_clear(); + QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QmlGraphicsItem *, children) + + // transform property + void transform_removeAt(int); + int transform_count() const; + void transform_append(QGraphicsTransform *); + void transform_insert(int, QGraphicsTransform *); + QGraphicsTransform *transform_at(int) const; + void transform_clear(); + QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QGraphicsTransform *, transform) + + QmlGraphicsAnchors *anchors() { + if (!_anchors) { + Q_Q(QmlGraphicsItem); + _anchors = new QmlGraphicsAnchors; + _anchors->setItem(q); + if (!_componentComplete) + _anchors->classBegin(); + } + return _anchors; + } + QList dependantAnchors; + QmlGraphicsAnchors *_anchors; + QmlGraphicsContents *_contents; + + QmlNullableValue _baselineOffset; + + struct AnchorLines { + AnchorLines(QmlGraphicsItem *); + QmlGraphicsAnchorLine left; + QmlGraphicsAnchorLine right; + QmlGraphicsAnchorLine hCenter; + QmlGraphicsAnchorLine top; + QmlGraphicsAnchorLine bottom; + QmlGraphicsAnchorLine vCenter; + QmlGraphicsAnchorLine baseline; + }; + mutable AnchorLines *_anchorLines; + AnchorLines *anchorLines() const { + Q_Q(const QmlGraphicsItem); + if (!_anchorLines) _anchorLines = + new AnchorLines(const_cast(q)); + return _anchorLines; + } + + QmlStateGroup *states(); + QmlStateGroup *_stateGroup; + + QmlGraphicsItem::TransformOrigin origin:4; + bool widthValid:1; + bool heightValid:1; + bool _componentComplete:1; + bool _keepMouse:1; + bool smooth:1; + + QmlGraphicsItemKeyFilter *keyHandler; + + qreal width; + qreal height; + qreal implicitWidth; + qreal implicitHeight; + + QPointF computeTransformOrigin() const; + + virtual void setPosHelper(const QPointF &pos) + { + Q_Q(QmlGraphicsItem); + QRectF oldGeometry(this->pos.x(), this->pos.y(), width, height); + QGraphicsItemPrivate::setPosHelper(pos); + q->geometryChanged(QRectF(this->pos.x(), this->pos.y(), width, height), oldGeometry); + } + + // Reimplemented from QGraphicsItemPrivate + virtual void subFocusItemChange() + { + emit q_func()->wantsFocusChanged(); + } + + static int consistentTime; + static QTime currentTime(); + static void Q_DECLARATIVE_EXPORT setConsistentTime(int t); + static void start(QTime &); + static int elapsed(QTime &); + static int restart(QTime &); +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSITEM_P_H diff --git a/src/declarative/fx/qmlgraphicslayoutitem.cpp b/src/declarative/fx/qmlgraphicslayoutitem.cpp new file mode 100644 index 0000000..b75f787 --- /dev/null +++ b/src/declarative/fx/qmlgraphicslayoutitem.cpp @@ -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$ +** +****************************************************************************/ + +#include "qmlgraphicslayoutitem.h" +#include +#include + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,LayoutItem,QmlGraphicsLayoutItem) + +/*! + \qmlclass LayoutItem QmlGraphicsLayoutItem + \brief The LayoutItem element allows you to place your Fluid UI elements inside a classical Qt layout. +*/ + +/*! + \internal + \class QmlGraphicsLayoutItem + \brief The QmlGraphicsLayoutItem class allows you to place your Fluid UI elements inside a classical Qt layout. +*/ + + +/*! + \qmlproperty QSizeF LayoutItem::maximumSize + + The maximumSize property can be set to specify the maximum desired size of this LayoutItem +*/ + +/*! + \qmlproperty QSizeF LayoutItem::minimumSize + + The minimumSize property can be set to specify the minimum desired size of this LayoutItem +*/ + +/*! + \qmlproperty QSizeF LayoutItem::preferredSize + + The preferredSize property can be set to specify the preferred size of this LayoutItem +*/ + +QmlGraphicsLayoutItem::QmlGraphicsLayoutItem(QmlGraphicsItem* parent) + : QmlGraphicsItem(parent), m_maximumSize(INT_MAX,INT_MAX), m_minimumSize(0,0), m_preferredSize(0,0) +{ + setGraphicsItem(this); +} + +void QmlGraphicsLayoutItem::setGeometry(const QRectF & rect) +{ + setX(rect.x()); + setY(rect.y()); + setWidth(rect.width()); + setHeight(rect.height()); +} + +QSizeF QmlGraphicsLayoutItem::sizeHint(Qt::SizeHint w, const QSizeF &constraint) const +{ + Q_UNUSED(constraint); + if(w == Qt::MinimumSize){ + return m_minimumSize; + }else if(w == Qt::MaximumSize){ + return m_maximumSize; + }else{ + return m_preferredSize; + } +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicslayoutitem.h b/src/declarative/fx/qmlgraphicslayoutitem.h new file mode 100644 index 0000000..184001a --- /dev/null +++ b/src/declarative/fx/qmlgraphicslayoutitem.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSGRAPHICSLAYOUTITEM_H +#define QMLGRAPHICSGRAPHICSLAYOUTITEM_H +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsLayoutItem : public QmlGraphicsItem, public QGraphicsLayoutItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayoutItem) + Q_PROPERTY(QSizeF maximumSize READ maximumSize WRITE setMaximumSize NOTIFY maximumSizeChanged) + Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize NOTIFY minimumSizeChanged) + Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize NOTIFY preferredSizeChanged) +public: + QmlGraphicsLayoutItem(QmlGraphicsItem* parent=0); + + QSizeF maximumSize() const { return m_maximumSize; } + void setMaximumSize(const QSizeF &s) { if(s==m_maximumSize) return; m_maximumSize = s; emit maximumSizeChanged(); } + + QSizeF minimumSize() const { return m_minimumSize; } + void setMinimumSize(const QSizeF &s) { if(s==m_minimumSize) return; m_minimumSize = s; emit minimumSizeChanged(); } + + QSizeF preferredSize() const { return m_preferredSize; } + void setPreferredSize(const QSizeF &s) { if(s==m_preferredSize) return; m_preferredSize = s; emit preferredSizeChanged(); } + + virtual void setGeometry(const QRectF & rect); +protected: + virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; + +Q_SIGNALS: + void maximumSizeChanged(); + void minimumSizeChanged(); + void preferredSizeChanged(); + +private: + QSizeF m_maximumSize; + QSizeF m_minimumSize; + QSizeF m_preferredSize; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsLayoutItem) + +QT_END_HEADER +#endif diff --git a/src/declarative/fx/qmlgraphicslistview.cpp b/src/declarative/fx/qmlgraphicslistview.cpp new file mode 100644 index 0000000..62ca23d --- /dev/null +++ b/src/declarative/fx/qmlgraphicslistview.cpp @@ -0,0 +1,2035 @@ +/**************************************************************************** +** +** 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/qmlgraphicsflickable_p.h" +#include "qmleasefollow.h" +#include "qlistmodelinterface.h" +#include "qmlgraphicsvisualitemmodel.h" +#include "qmlgraphicslistview.h" +#include + +#include + +QT_BEGIN_NAMESPACE +class QmlGraphicsListViewAttached : public QObject +{ + Q_OBJECT +public: + QmlGraphicsListViewAttached(QObject *parent) + : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {} + ~QmlGraphicsListViewAttached() { + attachedProperties.remove(parent()); + } + + Q_PROPERTY(QmlGraphicsListView *view READ view CONSTANT) + QmlGraphicsListView *view() { return m_view; } + + Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) + bool isCurrentItem() const { return m_isCurrent; } + void setIsCurrentItem(bool c) { + if (m_isCurrent != c) { + m_isCurrent = c; + emit currentItemChanged(); + } + } + + Q_PROPERTY(QString prevSection READ prevSection NOTIFY prevSectionChanged) + QString prevSection() const { return m_prevSection; } + void setPrevSection(const QString §) { + if (m_prevSection != sect) { + m_prevSection = sect; + emit prevSectionChanged(); + } + } + + Q_PROPERTY(QString section READ section NOTIFY sectionChanged) + QString section() const { return m_section; } + void setSection(const QString §) { + if (m_section != sect) { + m_section = sect; + emit sectionChanged(); + } + } + + Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged) + bool delayRemove() const { return m_delayRemove; } + void setDelayRemove(bool delay) { + if (m_delayRemove != delay) { + m_delayRemove = delay; + emit delayRemoveChanged(); + } + } + + static QmlGraphicsListViewAttached *properties(QObject *obj) { + QmlGraphicsListViewAttached *rv = attachedProperties.value(obj); + if (!rv) { + rv = new QmlGraphicsListViewAttached(obj); + attachedProperties.insert(obj, rv); + } + return rv; + } + + void emitAdd() { emit add(); } + void emitRemove() { emit remove(); } + +Q_SIGNALS: + void currentItemChanged(); + void sectionChanged(); + void prevSectionChanged(); + void delayRemoveChanged(); + void add(); + void remove(); + +public: + QmlGraphicsListView *m_view; + bool m_isCurrent; + mutable QString m_section; + QString m_prevSection; + bool m_delayRemove; + + static QHash attachedProperties; +}; + +QHash QmlGraphicsListViewAttached::attachedProperties; + +//---------------------------------------------------------------------------- + +class FxListItem +{ +public: + FxListItem(QmlGraphicsItem *i, QmlGraphicsListView *v) : item(i), view(v) { + attached = QmlGraphicsListViewAttached::properties(item); + attached->m_view = view; + } + ~FxListItem() {} + + qreal position() const { return (view->orientation() == QmlGraphicsListView::Vertical ? item->y() : item->x()); } + int size() const { return (view->orientation() == QmlGraphicsListView::Vertical ? item->height() : item->width()); } + qreal endPosition() const { + return (view->orientation() == QmlGraphicsListView::Vertical + ? item->y() + (item->height() > 0 ? item->height() : 1) + : item->x() + (item->width() > 0 ? item->width() : 1)) - 1; + } + void setPosition(qreal pos) { + if (view->orientation() == QmlGraphicsListView::Vertical) { + item->setY(pos); + } else { + item->setX(pos); + } + } + + QmlGraphicsItem *item; + QmlGraphicsListView *view; + QmlGraphicsListViewAttached *attached; + int index; +}; + +//---------------------------------------------------------------------------- + +class QmlGraphicsListViewPrivate : public QmlGraphicsFlickablePrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsListView) + +public: + QmlGraphicsListViewPrivate() + : model(0), currentItem(0), orient(QmlGraphicsListView::Vertical) + , visiblePos(0), visibleIndex(0) + , averageSize(100.0), currentIndex(-1), requestedIndex(-1) + , highlightRangeStart(0), highlightRangeEnd(0) + , highlightComponent(0), highlight(0), trackedItem(0) + , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0.0) + , highlightMoveSpeed(400), highlightResizeSpeed(400), highlightRange(QmlGraphicsListView::NoHighlightRange) + , ownModel(false), wrap(false), autoHighlight(true) + , haveHighlightRange(false) + {} + + void init(); + void clear(); + FxListItem *createItem(int modelIndex); + void releaseItem(FxListItem *item); + + FxListItem *visibleItem(int modelIndex) const { + if (modelIndex >= visibleIndex && modelIndex < visibleIndex + visibleItems.count()) { + for (int i = modelIndex - visibleIndex; i < visibleItems.count(); ++i) { + FxListItem *item = visibleItems.at(i); + if (item->index == modelIndex) + return item; + } + } + return 0; + } + + qreal position() const { + Q_Q(const QmlGraphicsListView); + return orient == QmlGraphicsListView::Vertical ? q->viewportY() : q->viewportX(); + } + void setPosition(qreal pos) { + Q_Q(QmlGraphicsListView); + if (orient == QmlGraphicsListView::Vertical) + q->setViewportY(pos); + else + q->setViewportX(pos); + } + qreal size() const { + Q_Q(const QmlGraphicsListView); + return orient == QmlGraphicsListView::Vertical ? q->height() : q->width(); + } + + qreal startPosition() const { + qreal pos = 0; + if (!visibleItems.isEmpty()) { + pos = visibleItems.first()->position(); + if (visibleIndex > 0) + pos -= visibleIndex * (averageSize + spacing) - spacing; + } + return pos; + } + + qreal endPosition() const { + qreal pos = 0; + if (!visibleItems.isEmpty()) { + int invisibleCount = visibleItems.count() - visibleIndex; + for (int i = visibleItems.count()-1; i >= 0; --i) { + if (visibleItems.at(i)->index != -1) { + invisibleCount = model->count() - visibleItems.at(i)->index - 1; + break; + } + } + pos = visibleItems.last()->endPosition() + invisibleCount * (averageSize + spacing); + } + return pos; + } + + qreal positionAt(int modelIndex) const { + if (FxListItem *item = visibleItem(modelIndex)) + return item->position(); + if (!visibleItems.isEmpty()) { + if (modelIndex < visibleIndex) { + int count = visibleIndex - modelIndex; + return visibleItems.first()->position() - count * (averageSize + spacing); + } else { + int idx = visibleItems.count() - 1; + while (idx >= 0 && visibleItems.at(idx)->index == -1) + --idx; + if (idx < 0) + idx = visibleIndex; + else + idx = visibleItems.at(idx)->index; + int count = modelIndex - idx - 1; + return visibleItems.last()->endPosition() + spacing + count * (averageSize + spacing) + 1; + } + } + return 0; + } + + QString sectionAt(int modelIndex) { + Q_Q(QmlGraphicsListView); + if (FxListItem *item = visibleItem(modelIndex)) + return item->attached->section(); + QString section; + if (!sectionExpression.isEmpty()) + section = model->evaluate(modelIndex, sectionExpression, q).toString(); + return section; + } + + bool isValid() const { + return model && model->count() && model->isValid(); + } + + int snapIndex() { + int index = currentIndex; + for (int i = 0; i < visibleItems.count(); ++i) { + FxListItem *item = visibleItems[i]; + if (item->index == -1) + continue; + qreal itemTop = item->position(); + if (itemTop >= highlight->position()-item->size()/2 && itemTop < highlight->position()+item->size()/2) + return item->index; + } + return index; + } + + //XXX Rough. Only works for fixed size items. + qreal snapPosAt(qreal pos) { + return qRound((pos - startPosition()) / averageSize) * averageSize + startPosition(); + } + + int lastVisibleIndex() const { + int lastIndex = -1; + for (int i = visibleItems.count()-1; i >= 0; --i) { + FxListItem *listItem = visibleItems.at(i); + if (listItem->index != -1) { + lastIndex = listItem->index; + break; + } + } + return lastIndex; + } + + // map a model index to visibleItems index. + // These may differ if removed items are still present in the visible list, + // e.g. doing a removal animation + int mapFromModel(int modelIndex) const { + if (modelIndex < visibleIndex || modelIndex >= visibleIndex + visibleItems.count()) + return -1; + for (int i = 0; i < visibleItems.count(); ++i) { + FxListItem *listItem = visibleItems.at(i); + if (listItem->index == modelIndex) + return i + visibleIndex; + if (listItem->index > modelIndex) + return -1; + } + return -1; // Not in visibleList + } + + bool mapRangeFromModel(int &index, int &count) const { + if (index + count < visibleIndex) + return false; + + int lastIndex = -1; + for (int i = visibleItems.count()-1; i >= 0; --i) { + FxListItem *listItem = visibleItems.at(i); + if (listItem->index != -1) { + lastIndex = listItem->index; + break; + } + } + + if (index > lastIndex) + return false; + + int last = qMin(index + count - 1, lastIndex); + index = qMax(index, visibleIndex); + count = last - index + 1; + + return true; + } + + void updateViewport() { + Q_Q(QmlGraphicsListView); + if (orient == QmlGraphicsListView::Vertical) + q->setViewportHeight(endPosition() - startPosition()); + else + q->setViewportWidth(endPosition() - startPosition()); + } + + + // for debugging only + void checkVisible() const { + int skip = 0; + for (int i = 0; i < visibleItems.count(); ++i) { + FxListItem *listItem = visibleItems.at(i); + if (listItem->index == -1) { + ++skip; + } else if (listItem->index != visibleIndex + i - skip) { + qFatal("index %d %d %d", visibleIndex, i, listItem->index); + } + } + } + + void refill(qreal from, qreal to); + void layout(); + void updateUnrequestedIndexes(); + void updateUnrequestedPositions(); + void updateTrackedItem(); + void createHighlight(); + void updateHighlight(); + void updateSections(); + void updateCurrentSection(); + void updateCurrent(int); + void updateAverage(); + void fixupPosition(); + virtual void fixupY(); + virtual void fixupX(); + virtual void flickX(qreal velocity); + virtual void flickY(qreal velocity); + + QmlGraphicsVisualModel *model; + QVariant modelVariant; + QList visibleItems; + QHash unrequestedItems; + FxListItem *currentItem; + QmlGraphicsListView::Orientation orient; + int visiblePos; + int visibleIndex; + qreal averageSize; + int currentIndex; + int requestedIndex; + qreal highlightRangeStart; + qreal highlightRangeEnd; + QmlComponent *highlightComponent; + FxListItem *highlight; + FxListItem *trackedItem; + enum MovementReason { Other, Key, Mouse }; + MovementReason moveReason; + int buffer; + QmlEaseFollow *highlightPosAnimator; + QmlEaseFollow *highlightSizeAnimator; + QString sectionExpression; + QString currentSection; + qreal spacing; + qreal highlightMoveSpeed; + qreal highlightResizeSpeed; + QmlGraphicsListView::HighlightRangeMode highlightRange; + + bool ownModel : 1; + bool wrap : 1; + bool autoHighlight : 1; + bool haveHighlightRange : 1; +}; + +void QmlGraphicsListViewPrivate::init() +{ + Q_Q(QmlGraphicsListView); + q->setFlag(QGraphicsItem::ItemIsFocusScope); + QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(refill())); + QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(refill())); +} + +void QmlGraphicsListViewPrivate::clear() +{ + for (int i = 0; i < visibleItems.count(); ++i) + releaseItem(visibleItems.at(i)); + visibleItems.clear(); + visiblePos = 0; + visibleIndex = 0; + releaseItem(currentItem); + currentItem = 0; + currentIndex = -1; + createHighlight(); + trackedItem = 0; +} + +FxListItem *QmlGraphicsListViewPrivate::createItem(int modelIndex) +{ + Q_Q(QmlGraphicsListView); + // create object + requestedIndex = modelIndex; + FxListItem *listItem = 0; + if (QmlGraphicsItem *item = model->item(modelIndex, false)) { + listItem = new FxListItem(item, q); + listItem->index = modelIndex; + // initialise attached properties + if (!sectionExpression.isEmpty()) { + QmlExpression e(qmlContext(listItem->item), sectionExpression, q); + e.setTrackChange(false); + listItem->attached->m_section = e.value().toString(); + if (modelIndex > 0) { + if (FxListItem *item = visibleItem(modelIndex-1)) + listItem->attached->m_prevSection = item->attached->section(); + else + listItem->attached->m_prevSection = sectionAt(modelIndex-1); + } + } + // complete + model->completeItem(); + listItem->item->setZValue(1); + listItem->item->setParent(q->viewport()); + if (orient == QmlGraphicsListView::Vertical) + QObject::connect(listItem->item, SIGNAL(heightChanged()), q, SLOT(itemResized())); + else + QObject::connect(listItem->item, SIGNAL(widthChanged()), q, SLOT(itemResized())); + } + requestedIndex = -1; + + return listItem; +} + +void QmlGraphicsListViewPrivate::releaseItem(FxListItem *item) +{ + Q_Q(QmlGraphicsListView); + if (!item) + return; + if (trackedItem == item) { + const char *notifier1 = orient == QmlGraphicsListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); + const char *notifier2 = orient == QmlGraphicsListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); + QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); + QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged())); + trackedItem = 0; + } + if (model->release(item->item) == 0) { + // item was not destroyed, and we no longer reference it. + unrequestedItems.insert(item->item, model->indexOf(item->item, q)); + if (orient == QmlGraphicsListView::Vertical) + QObject::disconnect(item->item, SIGNAL(heightChanged()), q, SLOT(itemResized())); + else + QObject::disconnect(item->item, SIGNAL(widthChanged()), q, SLOT(itemResized())); + } + delete item; +} + +void QmlGraphicsListViewPrivate::refill(qreal from, qreal to) +{ + Q_Q(QmlGraphicsListView); + if (!isValid() || !q->isComponentComplete()) + return; + from -= buffer; + to += buffer; + int modelIndex = 0; + qreal itemEnd = visiblePos-1; + if (!visibleItems.isEmpty()) { + visiblePos = visibleItems.first()->position(); + itemEnd = visibleItems.last()->endPosition() + spacing; + int i = visibleItems.count() - 1; + while (i > 0 && visibleItems.at(i)->index == -1) + --i; + modelIndex = visibleItems.at(i)->index + 1; + } + + bool changed = false; + FxListItem *item = 0; + int pos = itemEnd + 1; + while (modelIndex < model->count() && pos <= to) { + //qDebug() << "refill: append item" << modelIndex; + if (!(item = createItem(modelIndex))) + break; + item->setPosition(pos); + pos += item->size() + spacing; + visibleItems.append(item); + ++modelIndex; + changed = true; + } + while (visibleIndex > 0 && visibleIndex <= model->count() && visiblePos > from) { + //qDebug() << "refill: prepend item" << visibleIndex-1 << "current top pos" << visiblePos; + if (!(item = createItem(visibleIndex-1))) + break; + --visibleIndex; + visiblePos -= item->size() + spacing; + item->setPosition(visiblePos); + visibleItems.prepend(item); + changed = true; + } + + while (visibleItems.count() > 1 && (item = visibleItems.first()) && item->endPosition() < from) { + if (item->attached->delayRemove()) + break; + //qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endPosition(); + if (item->index != -1) + visibleIndex++; + visibleItems.removeFirst(); + releaseItem(item); + changed = true; + } + while (visibleItems.count() > 1 && (item = visibleItems.last()) && item->position() > to) { + if (item->attached->delayRemove()) + break; + //qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1; + visibleItems.removeLast(); + releaseItem(item); + changed = true; + } + if (changed) { + if (visibleItems.count()) + visiblePos = visibleItems.first()->position(); + updateAverage(); + if (!sectionExpression.isEmpty()) + updateCurrentSection(); + updateViewport(); + } +} + +void QmlGraphicsListViewPrivate::layout() +{ + Q_Q(QmlGraphicsListView); + if (!visibleItems.isEmpty()) { + int oldEnd = visibleItems.last()->endPosition(); + int pos = visibleItems.first()->endPosition() + spacing + 1; + for (int i=1; i < visibleItems.count(); ++i) { + FxListItem *item = visibleItems.at(i); + item->setPosition(pos); + pos += item->size() + spacing; + } + // move current item if it is after the visible items. + if (currentItem && currentIndex > lastVisibleIndex()) + currentItem->setPosition(currentItem->position() + (visibleItems.last()->endPosition() - oldEnd)); + } + if (!isValid()) + return; + q->refill(); + updateHighlight(); + fixupPosition(); + updateUnrequestedPositions(); + updateViewport(); +} + +void QmlGraphicsListViewPrivate::updateUnrequestedIndexes() +{ + Q_Q(QmlGraphicsListView); + QHash::iterator it; + for (it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) + *it = model->indexOf(it.key(), q); +} + +void QmlGraphicsListViewPrivate::updateUnrequestedPositions() +{ + QHash::const_iterator it; + for (it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) { + if (visibleItem(*it)) + continue; + if (orient == QmlGraphicsListView::Vertical) + it.key()->setY(positionAt(*it)); + else + it.key()->setX(positionAt(*it)); + } +} + +void QmlGraphicsListViewPrivate::updateTrackedItem() +{ + Q_Q(QmlGraphicsListView); + FxListItem *item = currentItem; + if (highlight) + item = highlight; + + FxListItem *oldTracked = trackedItem; + + const char *notifier1 = orient == QmlGraphicsListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); + const char *notifier2 = orient == QmlGraphicsListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); + + if (trackedItem && item != trackedItem) { + QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); + QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged())); + trackedItem = 0; + } + + if (!trackedItem && item) { + trackedItem = item; + QObject::connect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); + QObject::connect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged())); + } + if (trackedItem && trackedItem != oldTracked) + q->trackedPositionChanged(); +} + +void QmlGraphicsListViewPrivate::createHighlight() +{ + Q_Q(QmlGraphicsListView); + if (highlight) { + if (trackedItem == highlight) + trackedItem = 0; + delete highlight->item; + delete highlight; + highlight = 0; + delete highlightPosAnimator; + delete highlightSizeAnimator; + highlightPosAnimator = 0; + highlightSizeAnimator = 0; + } + + if (currentItem) { + QmlGraphicsItem *item = 0; + if (highlightComponent) { + QmlContext *highlightContext = new QmlContext(qmlContext(q)); + QObject *nobj = highlightComponent->create(highlightContext); + if (nobj) { + highlightContext->setParent(nobj); + item = qobject_cast(nobj); + if (!item) { + delete nobj; + } else { + item->setParent(q->viewport()); + } + } else { + delete highlightContext; + } + } else { + item = new QmlGraphicsItem; + item->setParent(q->viewport()); + } + if (item) { + item->setZValue(0); + highlight = new FxListItem(item, q); + if (orient == QmlGraphicsListView::Vertical) + highlight->item->setHeight(currentItem->item->height()); + else + highlight->item->setWidth(currentItem->item->width()); + const QLatin1String posProp(orient == QmlGraphicsListView::Vertical ? "y" : "x"); + highlightPosAnimator = new QmlEaseFollow(q); + highlightPosAnimator->setTarget(QmlMetaProperty(highlight->item, posProp)); + highlightPosAnimator->setVelocity(highlightMoveSpeed); + highlightPosAnimator->setEnabled(autoHighlight); + const QLatin1String sizeProp(orient == QmlGraphicsListView::Vertical ? "height" : "width"); + highlightSizeAnimator = new QmlEaseFollow(q); + highlightSizeAnimator->setVelocity(highlightResizeSpeed); + highlightSizeAnimator->setTarget(QmlMetaProperty(highlight->item, sizeProp)); + highlightSizeAnimator->setEnabled(autoHighlight); + } + } +} + +void QmlGraphicsListViewPrivate::updateHighlight() +{ + if ((!currentItem && highlight) || (currentItem && !highlight)) + createHighlight(); + if (currentItem && autoHighlight && highlight && !moving) { + // auto-update highlight + highlightPosAnimator->setSourceValue(currentItem->position()); + highlightSizeAnimator->setSourceValue(currentItem->size()); + if (orient == QmlGraphicsListView::Vertical) { + if (highlight->item->width() == 0) + highlight->item->setWidth(currentItem->item->width()); + } else { + if (highlight->item->height() == 0) + highlight->item->setHeight(currentItem->item->height()); + } + } + updateTrackedItem(); +} + +void QmlGraphicsListViewPrivate::updateSections() +{ + if (!sectionExpression.isEmpty()) { + QString prevSection; + if (visibleIndex > 0) + prevSection = sectionAt(visibleIndex-1); + for (int i = 0; i < visibleItems.count(); ++i) { + if (visibleItems.at(i)->index != -1) { + QmlGraphicsListViewAttached *attached = visibleItems.at(i)->attached; + attached->setPrevSection(prevSection); + prevSection = attached->section(); + } + } + } +} + +void QmlGraphicsListViewPrivate::updateCurrentSection() +{ + if (sectionExpression.isEmpty() || visibleItems.isEmpty()) { + currentSection = QString(); + return; + } + int index = 0; + while (visibleItems.at(index)->endPosition() < position() && index < visibleItems.count()) + ++index; + + if (index < visibleItems.count()) + currentSection = visibleItems.at(index)->attached->section(); + else + currentSection = visibleItems.first()->attached->section(); +} + +void QmlGraphicsListViewPrivate::updateCurrent(int modelIndex) +{ + Q_Q(QmlGraphicsListView); + if (!isValid() || modelIndex < 0 || modelIndex >= model->count()) { + if (currentItem) { + currentItem->attached->setIsCurrentItem(false); + releaseItem(currentItem); + currentItem = 0; + currentIndex = -1; + updateHighlight(); + emit q->currentIndexChanged(); + } + return; + } + + if (currentItem && currentIndex == modelIndex) { + updateHighlight(); + return; + } + FxListItem *oldCurrentItem = currentItem; + currentIndex = modelIndex; + currentItem = createItem(modelIndex); + if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item)) + oldCurrentItem->attached->setIsCurrentItem(false); + if (currentItem) { + if (modelIndex == visibleIndex - 1) { + // We can calculate exact postion in this case + currentItem->setPosition(visibleItems.first()->position() - currentItem->size() - spacing); + } else { + // Create current item now and position as best we can. + // Its position will be corrected when it becomes visible. + currentItem->setPosition(positionAt(modelIndex)); + } + currentItem->item->setFocus(true); + currentItem->attached->setIsCurrentItem(true); + } + updateHighlight(); + emit q->currentIndexChanged(); + // Release the old current item + releaseItem(oldCurrentItem); +} + +void QmlGraphicsListViewPrivate::updateAverage() +{ + if (!visibleItems.count()) + return; + qreal sum = 0.0; + for (int i = 0; i < visibleItems.count(); ++i) + sum += visibleItems.at(i)->size(); + averageSize = sum / visibleItems.count(); +} + +void QmlGraphicsListViewPrivate::fixupPosition() +{ + if (orient == QmlGraphicsListView::Vertical) + fixupY(); + else + fixupX(); +} + +void QmlGraphicsListViewPrivate::fixupY() +{ + QmlGraphicsFlickablePrivate::fixupY(); + if (orient == QmlGraphicsListView::Horizontal) + return; + + if (haveHighlightRange && highlightRange == QmlGraphicsListView::StrictlyEnforceRange) { + if (currentItem && highlight && currentItem->position() != highlight->position()) { + moveReason = Mouse; + timeline.clear(); + timeline.move(_moveY, -(currentItem->position() - highlightRangeStart), QEasingCurve(QEasingCurve::InOutQuad), 200); + } + } +} + +void QmlGraphicsListViewPrivate::fixupX() +{ + QmlGraphicsFlickablePrivate::fixupX(); + if (orient == QmlGraphicsListView::Vertical) + return; + + if (haveHighlightRange && highlightRange == QmlGraphicsListView::StrictlyEnforceRange) { + if (currentItem && highlight && currentItem->position() != highlight->position()) { + moveReason = Mouse; + timeline.clear(); + timeline.move(_moveX, -(currentItem->position() - highlightRangeStart), QEasingCurve(QEasingCurve::InOutQuad), 200); + } + } +} + +void QmlGraphicsListViewPrivate::flickX(qreal velocity) +{ + Q_Q(QmlGraphicsListView); + + if (!haveHighlightRange || highlightRange != QmlGraphicsListView::StrictlyEnforceRange) { + QmlGraphicsFlickablePrivate::flickX(velocity); + return; + } + + qreal maxDistance = -1; + // -ve velocity means list is moving up + if (velocity > 0) { + if (_moveX.value() < q->minXExtent()) + maxDistance = qAbs(q->minXExtent() -_moveX.value() + (overShoot?30:0)); + flickTargetX = q->minXExtent(); + } else { + if (_moveX.value() > q->maxXExtent()) + maxDistance = qAbs(q->maxXExtent() - _moveX.value()) + (overShoot?30:0); + flickTargetX = q->maxXExtent(); + } + if (maxDistance > 0) { + qreal v = velocity; + if (maxVelocity != -1 && maxVelocity < qAbs(v)) { + if (v < 0) + v = -maxVelocity; + else + v = maxVelocity; + } + qreal accel = deceleration; + qreal v2 = v * v; + qreal maxAccel = v2 / (2.0f * maxDistance); + if (maxAccel < accel) { + // If we are not flicking to the end then attempt to stop exactly on an item boundary + qreal dist = v2 / accel / 2.0; + if (v > 0) + dist = -dist; + dist = -_moveX.value() - snapPosAt(-(_moveX.value() - highlightRangeStart) + dist) + highlightRangeStart; + if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { + timeline.reset(_moveX); + fixupX(); + return; + } + accel = v2 / (2.0f * qAbs(dist)); + } + timeline.reset(_moveX); + timeline.accel(_moveX, v, accel, maxDistance); + timeline.execute(fixupXEvent); + if (!flicked) { + flicked = true; + emit q->flickingChanged(); + emit q->flickStarted(); + } + } else { + timeline.reset(_moveX); + fixupX(); + } +} + +void QmlGraphicsListViewPrivate::flickY(qreal velocity) +{ + Q_Q(QmlGraphicsListView); + + if (!haveHighlightRange || highlightRange != QmlGraphicsListView::StrictlyEnforceRange) { + QmlGraphicsFlickablePrivate::flickY(velocity); + return; + } + + qreal maxDistance = -1; + // -ve velocity means list is moving up + if (velocity > 0) { + if (_moveY.value() < q->minYExtent()) + maxDistance = qAbs(q->minYExtent() -_moveY.value() + (overShoot?30:0)); + flickTargetY = q->minYExtent(); + } else { + if (_moveY.value() > q->maxYExtent()) + maxDistance = qAbs(q->maxYExtent() - _moveY.value()) + (overShoot?30:0); + flickTargetY = q->maxYExtent(); + } + if (maxDistance > 0) { + qreal v = velocity; + if (maxVelocity != -1 && maxVelocity < qAbs(v)) { + if (v < 0) + v = -maxVelocity; + else + v = maxVelocity; + } + qreal accel = deceleration; + qreal v2 = v * v; + qreal maxAccel = v2 / (2.0f * maxDistance); + if (maxAccel < accel) { + // If we are not flicking to the end then attempt to stop exactly on an item boundary + qreal dist = v2 / accel / 2.0; + if (v > 0) + dist = -dist; + dist = -_moveY.value() - snapPosAt(-(_moveY.value() - highlightRangeStart) + dist) + highlightRangeStart; + if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { + timeline.reset(_moveY); + fixupY(); + return; + } + accel = v2 / (2.0f * qAbs(dist)); + } + timeline.reset(_moveY); + timeline.accel(_moveY, v, accel, maxDistance); + timeline.execute(fixupYEvent); + if (!flicked) { + flicked = true; + emit q->flickingChanged(); + emit q->flickStarted(); + } + } else { + timeline.reset(_moveY); + fixupY(); + } +} + +//---------------------------------------------------------------------------- + +/*! + \qmlclass ListView + \inherits Flickable + \brief The ListView item provides a list view of items provided by a model. + + The model is typically provided by a QAbstractListModel "C++ model object", + but can also be created directly in QML. The items are laid out vertically + or horizontally and may be flicked to scroll. + + The below example creates a very simple vertical list, using a QML model. + \image trivialListView.png + + The user interface defines a delegate to display an item, a highlight, + and the ListView which uses the above. + + \snippet doc/src/snippets/declarative/listview/listview.qml 3 + + The model is defined as a ListModel using QML: + \quotefile doc/src/snippets/declarative/listview/dummydata/ContactModel.qml + + In this case ListModel is a handy way for us to test our UI. In practice + the model would be implemented in C++, or perhaps via a SQL data source. +*/ + +QmlGraphicsListView::QmlGraphicsListView(QmlGraphicsItem *parent) + : QmlGraphicsFlickable(*(new QmlGraphicsListViewPrivate), parent) +{ + Q_D(QmlGraphicsListView); + d->init(); +} + +QmlGraphicsListView::~QmlGraphicsListView() +{ + Q_D(QmlGraphicsListView); + d->clear(); + if (d->ownModel) + delete d->model; +} + +/*! + \qmlattachedproperty bool ListView::isCurrentItem + This attched property is true if this delegate is the current item; otherwise false. + + It is attached to each instance of the delegate. + + This property may be used to adjust the appearance of the current item, for example: + + \snippet doc/src/snippets/declarative/listview/highlight.qml 0 +*/ + +/*! + \qmlattachedproperty ListView ListView::view + This attached property holds the view that manages this delegate instance. + + It is attached to each instance of the delegate. +*/ + +/*! + \qmlattachedproperty string ListView::prevSection + This attached property holds the section of the previous element. + + It is attached to each instance of the delegate. + + The section is evaluated using the \l {ListView::sectionExpression}{sectionExpression} property. +*/ + +/*! + \qmlattachedproperty string ListView::section + This attached property holds the section of this element. + + It is attached to each instance of the delegate. + + The section is evaluated using the \l {ListView::sectionExpression}{sectionExpression} property. +*/ + +/*! + \qmlattachedproperty bool ListView::delayRemove + This attached property holds whether the delegate may be destroyed. + + It is attached to each instance of the delegate. + + It is sometimes necessary to delay the destruction of an item + until an animation completes. + + The example below ensures that the animation completes before + the item is removed from the list. + + \code + Component { + id: myDelegate + Item { + id: wrapper + ListView.onRemove: SequentialAnimation { + PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: true } + NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing: "easeInOutQuad" } + PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: false } + } + } + } + \endcode +*/ + +/*! + \qmlattachedsignal ListView::onAdd() + This attached handler is called immediately after an item is added to the view. +*/ + +/*! + \qmlattachedsignal ListView::onRemove() + This attached handler is called immediately before an item is removed from the view. +*/ + +/*! + \qmlproperty model ListView::model + This property holds the model providing data for the list. + + The model provides a set of data that is used to create the items + for the view. For large or dynamic datasets the model is usually + provided by a C++ model object. The C++ model object must be a \l + {QAbstractItemModel} subclass or a simple list. + + Models can also be created directly in QML, using a \l{ListModel}, + \l{XmlListModel} or \l{VisualItemModel}. + + \sa {qmlmodels}{Data Models} +*/ +QVariant QmlGraphicsListView::model() const +{ + Q_D(const QmlGraphicsListView); + return d->modelVariant; +} + +void QmlGraphicsListView::setModel(const QVariant &model) +{ + Q_D(QmlGraphicsListView); + if (d->model) { + disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); + disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + disconnect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + disconnect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); + } + d->clear(); + d->modelVariant = model; + QObject *object = qvariant_cast(model); + QmlGraphicsVisualModel *vim = 0; + if (object && (vim = qobject_cast(object))) { + if (d->ownModel) { + delete d->model; + d->ownModel = false; + } + d->model = vim; + } else { + if (!d->ownModel) { + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); + d->ownModel = true; + } + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) + dataModel->setModel(model); + } + if (d->model) { + if (d->currentIndex >= d->model->count() || d->currentIndex < 0) + setCurrentIndex(0); + else + d->updateCurrent(d->currentIndex); + connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); + connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + connect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); + refill(); + emit countChanged(); + } +} + +/*! + \qmlproperty component ListView::delegate + + The delegate provides a template describing what each item in the view should look and act like. + + Here is an example delegate: + \snippet doc/src/snippets/declarative/listview/listview.qml 0 +*/ +QmlComponent *QmlGraphicsListView::delegate() const +{ + Q_D(const QmlGraphicsListView); + if (d->model) { + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) + return dataModel->delegate(); + } + + return 0; +} + +void QmlGraphicsListView::setDelegate(QmlComponent *delegate) +{ + Q_D(QmlGraphicsListView); + if (!d->ownModel) { + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); + d->ownModel = true; + } + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) { + dataModel->setDelegate(delegate); + d->updateCurrent(d->currentIndex); + refill(); + } +} + +/*! + \qmlproperty int ListView::currentIndex + \qmlproperty Item ListView::currentItem + + \c currentIndex holds the index of the current item. + \c currentItem is the current item. Note that the position of the current item + may only be approximate until it becomes visible in the view. +*/ +int QmlGraphicsListView::currentIndex() const +{ + Q_D(const QmlGraphicsListView); + return d->currentIndex; +} + +void QmlGraphicsListView::setCurrentIndex(int index) +{ + Q_D(QmlGraphicsListView); + d->moveReason = QmlGraphicsListViewPrivate::Other; + if (d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) { + cancelFlick(); + d->updateCurrent(index); + } else { + d->currentIndex = index; + } +} + +QmlGraphicsItem *QmlGraphicsListView::currentItem() +{ + Q_D(QmlGraphicsListView); + if (!d->currentItem) + return 0; + return d->currentItem->item; +} + +/*! + \qmlproperty int ListView::count + This property holds the number of items in the view. +*/ +int QmlGraphicsListView::count() const +{ + Q_D(const QmlGraphicsListView); + if (d->model) + return d->model->count(); + return 0; +} + +/*! + \qmlproperty component ListView::highlight + This property holds the component to use as the highlight. + + An instance of the highlight component will be created for each list. + The geometry of the resultant component instance will be managed by the list + so as to stay with the current item, unless the highlightFollowsCurrentItem + property is false. + + The below example demonstrates how to make a simple highlight + for a vertical list. + + \snippet doc/src/snippets/declarative/listview/listview.qml 1 + \image trivialListView.png + + \sa highlightFollowsCurrentItem +*/ +QmlComponent *QmlGraphicsListView::highlight() const +{ + Q_D(const QmlGraphicsListView); + return d->highlightComponent; +} + +void QmlGraphicsListView::setHighlight(QmlComponent *highlight) +{ + Q_D(QmlGraphicsListView); + delete d->highlightComponent; + d->highlightComponent = highlight; + d->updateCurrent(d->currentIndex); +} + +/*! + \qmlproperty bool ListView::highlightFollowsCurrentItem + This property holds whether the highlight is managed by the view. + + If highlightFollowsCurrentItem is true, the highlight will be moved smoothly + to follow the current item. If highlightFollowsCurrentItem is false, the + highlight will not be moved by the view, and must be implemented + by the highlight. The following example creates a highlight with + its motion defined by the spring \l {SpringFollow}: + + \snippet doc/src/snippets/declarative/listview/highlight.qml 1 + + Note that the highlight animation also affects the way that the view + is scrolled. This is because the view moves to maintain the + highlight within the preferred highlight range (or visible viewport). + + \sa highlight +*/ +bool QmlGraphicsListView::highlightFollowsCurrentItem() const +{ + Q_D(const QmlGraphicsListView); + return d->autoHighlight; +} + +void QmlGraphicsListView::setHighlightFollowsCurrentItem(bool autoHighlight) +{ + Q_D(QmlGraphicsListView); + d->autoHighlight = autoHighlight; + if (d->highlightPosAnimator) { + d->highlightPosAnimator->setEnabled(d->autoHighlight); + d->highlightSizeAnimator->setEnabled(d->autoHighlight); + } + d->updateHighlight(); +} + +/*! + \qmlproperty real ListView::preferredHighlightBegin + \qmlproperty real ListView::preferredHighlightEnd + \qmlproperty bool ListView::highlightRangeMode + + These properties set the preferred range of the highlight (current item) + within the view. + + If highlightRangeMode is set to \e ApplyRange the view will + attempt to maintain the highlight within the range, however + the highlight can move outside of the range at the ends of the list + or due to a mouse interaction. + + If highlightRangeMode is set to \e StrictlyEnforceRange the highlight will never + move outside of the range. This means that the current item will change + if a keyboard or mouse action would cause the highlight to move + outside of the range. + + The default value is \e NoHighlightRange. + + Note that a valid range requires preferredHighlightEnd to be greater + than or equal to preferredHighlightBegin. +*/ +qreal QmlGraphicsListView::preferredHighlightBegin() const +{ + Q_D(const QmlGraphicsListView); + return d->highlightRangeStart; +} + +void QmlGraphicsListView::setPreferredHighlightBegin(qreal start) +{ + Q_D(QmlGraphicsListView); + d->highlightRangeStart = start; + d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; +} + +qreal QmlGraphicsListView::preferredHighlightEnd() const +{ + Q_D(const QmlGraphicsListView); + return d->highlightRangeEnd; +} + +void QmlGraphicsListView::setPreferredHighlightEnd(qreal end) +{ + Q_D(QmlGraphicsListView); + d->highlightRangeEnd = end; + d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; +} + +QmlGraphicsListView::HighlightRangeMode QmlGraphicsListView::highlightRangeMode() const +{ + Q_D(const QmlGraphicsListView); + return d->highlightRange; +} + +void QmlGraphicsListView::setHighlightRangeMode(HighlightRangeMode mode) +{ + Q_D(QmlGraphicsListView); + d->highlightRange = mode; + d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; +} + +/*! + \qmlproperty real ListView::spacing + + This property holds the spacing to leave between items. +*/ +qreal QmlGraphicsListView::spacing() const +{ + Q_D(const QmlGraphicsListView); + return d->spacing; +} + +void QmlGraphicsListView::setSpacing(qreal spacing) +{ + Q_D(QmlGraphicsListView); + if (spacing != d->spacing) { + d->spacing = spacing; + d->layout(); + emit spacingChanged(); + } +} + +/*! + \qmlproperty enumeration ListView::orientation + This property holds the orientation of the list. + + Possible values are \c Vertical (default) and \c Horizontal. + + Vertical Example: + \image trivialListView.png + Horizontal Example: + \image ListViewHorizontal.png +*/ +QmlGraphicsListView::Orientation QmlGraphicsListView::orientation() const +{ + Q_D(const QmlGraphicsListView); + return d->orient; +} + +void QmlGraphicsListView::setOrientation(QmlGraphicsListView::Orientation orientation) +{ + Q_D(QmlGraphicsListView); + if (d->orient != orientation) { + d->orient = orientation; + if (d->orient == QmlGraphicsListView::Vertical) + setViewportWidth(-1); + else + setViewportHeight(-1); + d->clear(); + refill(); + emit orientationChanged(); + d->updateCurrent(d->currentIndex); + } +} + +/*! + \qmlproperty bool ListView::keyNavigationWraps + This property holds whether the list wraps key navigation + + If this property is true then key presses to move off of one end of the list will cause the + current item to jump to the other end. +*/ +bool QmlGraphicsListView::isWrapEnabled() const +{ + Q_D(const QmlGraphicsListView); + return d->wrap; +} + +void QmlGraphicsListView::setWrapEnabled(bool wrap) +{ + Q_D(QmlGraphicsListView); + d->wrap = wrap; +} + +/*! + \qmlproperty int ListView::cacheBuffer + This property holds the number of off-screen pixels to cache. + + This property determines the number of pixels above the top of the list + and below the bottom of the list to cache. Setting this value can make + scrolling the list smoother at the expense of additional memory usage. +*/ +int QmlGraphicsListView::cacheBuffer() const +{ + Q_D(const QmlGraphicsListView); + return d->buffer; +} + +void QmlGraphicsListView::setCacheBuffer(int b) +{ + Q_D(QmlGraphicsListView); + if (d->buffer != b) { + d->buffer = b; + if (isComponentComplete()) + refill(); + } +} + +/*! + \qmlproperty string ListView::sectionExpression + This property holds the expression to be evaluated for the section attached property. + + Each item in the list has attached properties named \c ListView.section and + \c ListView.prevSection. These may be used to place a section header for + related items. The example below assumes that the model is sorted by size of + pet. The section expression is the size property. If \c ListView.section and + \c ListView.prevSection differ, the item will display a section header. + + \snippet examples/declarative/listview/sections.qml 0 + + \image ListViewSections.png +*/ +QString QmlGraphicsListView::sectionExpression() const +{ + Q_D(const QmlGraphicsListView); + return d->sectionExpression; +} + +void QmlGraphicsListView::setSectionExpression(const QString &expression) +{ + Q_D(QmlGraphicsListView); + if (d->sectionExpression != expression) { + d->sectionExpression = expression; + emit sectionExpressionChanged(); + } +} + +QString QmlGraphicsListView::currentSection() const +{ + Q_D(const QmlGraphicsListView); + return d->currentSection; +} + +/*! + \qmlproperty real ListView::highlightMoveSpeed + + This property holds the moving animation speed of the highlight delegate. +*/ +qreal QmlGraphicsListView::highlightMoveSpeed() const +{ + Q_D(const QmlGraphicsListView);\ + return d->highlightMoveSpeed; +} + +void QmlGraphicsListView::setHighlightMoveSpeed(qreal speed) +{ + Q_D(QmlGraphicsListView);\ + if (d->highlightMoveSpeed != speed) + { + d->highlightMoveSpeed = speed; + emit highlightMoveSpeedChanged(); + } +} + +/*! + \qmlproperty real ListView::highlightResizeSpeed + + This property holds the resizing animation speed of the highlight delegate. +*/ +qreal QmlGraphicsListView::highlightResizeSpeed() const +{ + Q_D(const QmlGraphicsListView);\ + return d->highlightResizeSpeed; +} + +void QmlGraphicsListView::setHighlightResizeSpeed(qreal speed) +{ + Q_D(QmlGraphicsListView);\ + if (d->highlightResizeSpeed != speed) + { + d->highlightResizeSpeed = speed; + emit highlightResizeSpeedChanged(); + } +} + +void QmlGraphicsListView::viewportMoved() +{ + Q_D(QmlGraphicsListView); + QmlGraphicsFlickable::viewportMoved(); + refill(); + if (isFlicking() || d->moving) + d->moveReason = QmlGraphicsListViewPrivate::Mouse; + if (d->moveReason == QmlGraphicsListViewPrivate::Mouse) { + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) { + int idx = d->snapIndex(); + if (idx >= 0 && idx != d->currentIndex) + d->updateCurrent(idx); + + qreal pos = d->currentItem->position(); + if (pos > d->position() + d->highlightRangeEnd - 1 - d->highlight->size()) + pos = d->position() + d->highlightRangeEnd - 1 - d->highlight->size(); + if (pos < d->position() + d->highlightRangeStart) + pos = d->position() + d->highlightRangeStart; + d->highlight->setPosition(pos); + } + } +} + +qreal QmlGraphicsListView::minYExtent() const +{ + Q_D(const QmlGraphicsListView); + if (d->orient == QmlGraphicsListView::Horizontal) + return QmlGraphicsFlickable::minYExtent(); + qreal extent = -d->startPosition(); + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + extent += d->highlightRangeStart; + + return extent; +} + +qreal QmlGraphicsListView::maxYExtent() const +{ + Q_D(const QmlGraphicsListView); + if (d->orient == QmlGraphicsListView::Horizontal) + return QmlGraphicsFlickable::maxYExtent(); + qreal extent; + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + extent = -(d->positionAt(count()-1) - d->highlightRangeEnd); + else + extent = -(d->endPosition() - height()); + qreal minY = minYExtent(); + if (extent > minY) + extent = minY; + return extent; +} + +qreal QmlGraphicsListView::minXExtent() const +{ + Q_D(const QmlGraphicsListView); + if (d->orient == QmlGraphicsListView::Vertical) + return QmlGraphicsFlickable::minXExtent(); + qreal extent = -d->startPosition(); + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + extent += d->highlightRangeStart; + + return extent; +} + +qreal QmlGraphicsListView::maxXExtent() const +{ + Q_D(const QmlGraphicsListView); + if (d->orient == QmlGraphicsListView::Vertical) + return QmlGraphicsFlickable::maxXExtent(); + qreal extent; + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + extent = -(d->positionAt(count()-1) - d->highlightRangeEnd); + else + extent = -(d->endPosition() - width()); + qreal minX = minXExtent(); + if (extent > minX) + extent = minX; + return extent; +} + +void QmlGraphicsListView::keyPressEvent(QKeyEvent *event) +{ + Q_D(QmlGraphicsListView); + QmlGraphicsFlickable::keyPressEvent(event); + if (event->isAccepted()) + return; + + if (d->model && d->model->count() && d->interactive) { + if ((d->orient == QmlGraphicsListView::Horizontal && event->key() == Qt::Key_Left) + || (d->orient == QmlGraphicsListView::Vertical && event->key() == Qt::Key_Up)) { + if (currentIndex() > 0 || (d->wrap && !event->isAutoRepeat())) { + d->moveReason = QmlGraphicsListViewPrivate::Key; + decrementCurrentIndex(); + event->accept(); + return; + } else if (d->wrap) { + event->accept(); + return; + } + } else if ((d->orient == QmlGraphicsListView::Horizontal && event->key() == Qt::Key_Right) + || (d->orient == QmlGraphicsListView::Vertical && event->key() == Qt::Key_Down)) { + if (currentIndex() < d->model->count() - 1 || (d->wrap && !event->isAutoRepeat())) { + d->moveReason = QmlGraphicsListViewPrivate::Key; + incrementCurrentIndex(); + event->accept(); + return; + } else if (d->wrap) { + event->accept(); + return; + } + } + } + d->moveReason = QmlGraphicsListViewPrivate::Other; + event->ignore(); +} + +/*! + \qmlmethod ListView::incrementCurrentIndex + + Increments the current index. The current index will wrap + if keyNavigationWraps is true and it is currently at the end. +*/ +void QmlGraphicsListView::incrementCurrentIndex() +{ + Q_D(QmlGraphicsListView); + if (currentIndex() < d->model->count() - 1 || d->wrap) { + int index = currentIndex()+1; + cancelFlick(); + d->updateCurrent(index < d->model->count() ? index : 0); + } +} + +/*! + \qmlmethod ListView::decrementCurrentIndex + + Decrements the current index. The current index will wrap + if keyNavigationWraps is true and it is currently at the beginning. +*/ +void QmlGraphicsListView::decrementCurrentIndex() +{ + Q_D(QmlGraphicsListView); + if (currentIndex() > 0 || d->wrap) { + int index = currentIndex()-1; + cancelFlick(); + d->updateCurrent(index >= 0 ? index : d->model->count()-1); + } +} + +void QmlGraphicsListView::componentComplete() +{ + Q_D(QmlGraphicsListView); + QmlGraphicsFlickable::componentComplete(); + if (d->currentIndex < 0) + d->updateCurrent(0); + refill(); + d->fixupPosition(); +} + +void QmlGraphicsListView::refill() +{ + Q_D(QmlGraphicsListView); + d->refill(d->position(), d->position()+d->size()-1); +} + +void QmlGraphicsListView::trackedPositionChanged() +{ + Q_D(QmlGraphicsListView); + if (!d->trackedItem) + return; + if (!isFlicking() && !d->moving && d->moveReason != QmlGraphicsListViewPrivate::Mouse) { + const qreal trackedPos = d->trackedItem->position(); + const qreal viewPos = d->position(); + if (d->haveHighlightRange) { + if (d->highlightRange == StrictlyEnforceRange) { + qreal pos = viewPos; + if (trackedPos > pos + d->highlightRangeEnd - d->trackedItem->size()) + pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size(); + if (trackedPos < pos + d->highlightRangeStart) + pos = trackedPos - d->highlightRangeStart; + d->setPosition(pos); + } else { + qreal pos = viewPos; + if (trackedPos < d->startPosition() + d->highlightRangeStart) { + pos = d->startPosition(); + } else if (d->trackedItem->endPosition() > d->endPosition() - d->size() + d->highlightRangeEnd) { + pos = d->endPosition() - d->size(); + } else { + if (trackedPos < viewPos + d->highlightRangeStart) { + pos = trackedPos - d->highlightRangeStart; + } else if (trackedPos > viewPos + d->highlightRangeEnd - d->trackedItem->size()) { + pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size(); + } + } + d->setPosition(pos); + } + } else { + if (trackedPos < viewPos && d->currentItem->position() < viewPos) { + d->setPosition(d->currentItem->position() < trackedPos ? trackedPos : d->currentItem->position()); + d->fixupPosition(); + } else if (d->trackedItem->endPosition() > viewPos + d->size() + && d->currentItem->endPosition() > viewPos + d->size()) { + qreal pos; + if (d->trackedItem->endPosition() < d->currentItem->endPosition()) { + pos = d->trackedItem->endPosition() - d->size(); + if (d->trackedItem->size() > d->size()) + pos = trackedPos; + } else { + pos = d->currentItem->endPosition() - d->size(); + if (d->currentItem->size() > d->size()) + pos = d->currentItem->position(); + } + d->setPosition(pos); + d->fixupPosition(); + } + } + } +} + +void QmlGraphicsListView::itemResized() +{ + Q_D(QmlGraphicsListView); + QmlGraphicsItem *item = qobject_cast(sender()); + if (item) { + d->layout(); + d->fixupPosition(); + } +} + +void QmlGraphicsListView::itemsInserted(int modelIndex, int count) +{ + Q_D(QmlGraphicsListView); + d->updateUnrequestedIndexes(); + if (!d->visibleItems.count() || d->model->count() <= 1) { + d->layout(); + d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); + emit countChanged(); + return; + } + + if (!d->mapRangeFromModel(modelIndex, count)) { + int i = d->visibleItems.count() - 1; + while (i > 0 && d->visibleItems.at(i)->index == -1) + --i; + if (d->visibleItems.at(i)->index + 1 == modelIndex) { + // Special case of appending an item to the model. + modelIndex = d->visibleIndex + d->visibleItems.count(); + } else { + if (modelIndex + count - 1 < d->visibleIndex) { + // Insert before visible items + d->visibleIndex += count; + for (int i = 0; i < d->visibleItems.count(); ++i) { + FxListItem *listItem = d->visibleItems.at(i); + if (listItem->index != -1) + listItem->index += count; + } + } + if (d->currentIndex >= modelIndex) { + // adjust current item index + d->currentIndex += count; + if (d->currentItem) + d->currentItem->index = d->currentIndex; + } + d->layout(); + emit countChanged(); + return; + } + } + + // At least some of the added items will be visible + + int index = modelIndex - d->visibleIndex; + int to = d->buffer+d->position()+d->size()-1; + // index can be the next item past the end of the visible items list (i.e. appended) + int pos = index < d->visibleItems.count() ? d->visibleItems.at(index)->position() + : d->visibleItems.at(index-1)->endPosition()+d->spacing+1; + int initialPos = pos; + QList added; + for (int i = 0; i < count && pos <= to; ++i) { + FxListItem *item = d->createItem(modelIndex + i); + d->visibleItems.insert(index, item); + item->setPosition(pos); + added.append(item); + pos += item->size() + d->spacing; + ++index; + } + if (d->currentIndex >= modelIndex) { + // adjust current item index + d->currentIndex += count; + if (d->currentItem) { + d->currentItem->index = d->currentIndex; + d->currentItem->setPosition(d->currentItem->position() + (pos - initialPos)); + } + } + if (pos > to) { + // We didn't insert all our new items, which means anything + // beyond the current index is not visible - remove it. + while (d->visibleItems.count() > index) + d->releaseItem(d->visibleItems.takeLast()); + } else { + // Update the indexes of the following visible items. + for (; index < d->visibleItems.count(); ++index) { + FxListItem *listItem = d->visibleItems.at(index); + if (listItem->item != d->currentItem->item) + listItem->setPosition(listItem->position() + (pos - initialPos)); + if (listItem->index != -1) + listItem->index += count; + } + } + // everything is in order now - emit add() signal + for (int j = 0; j < added.count(); ++j) + added.at(j)->attached->emitAdd(); + d->updateUnrequestedPositions(); + d->updateViewport(); + emit countChanged(); +} + +void QmlGraphicsListView::itemsRemoved(int modelIndex, int count) +{ + Q_D(QmlGraphicsListView); + d->updateUnrequestedIndexes(); + bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; + if (!d->mapRangeFromModel(modelIndex, count)) { + if (modelIndex + count - 1 < d->visibleIndex) { + // Items removed before our visible items. + d->visibleIndex -= count; + for (int i = 0; i < d->visibleItems.count(); ++i) { + FxListItem *listItem = d->visibleItems.at(i); + if (listItem->index != -1) + listItem->index -= count; + } + } + if (d->currentIndex >= modelIndex + count) { + d->currentIndex -= count; + if (d->currentItem) + d->currentItem->index -= count; + } else if (currentRemoved) { + // current item has been removed. + d->releaseItem(d->currentItem); + d->currentItem = 0; + d->currentIndex = -1; + d->updateCurrent(qMin(modelIndex, d->model->count()-1)); + } + d->layout(); + d->updateSections(); + emit countChanged(); + return; + } + + // Remove the items from the visible list, skipping anything already marked for removal + QList::Iterator it = d->visibleItems.begin(); + while (it != d->visibleItems.end()) { + FxListItem *item = *it; + if (item->index == -1 || item->index < modelIndex) { + // already removed, or before removed items + ++it; + } else if (item->index >= modelIndex + count) { + // after removed items + item->index -= count; + ++it; + } else { + // removed item + item->attached->emitRemove(); + if (item->attached->delayRemove()) { + item->index = -1; + connect(item->attached, SIGNAL(delayRemoveChanged()), this, SLOT(destroyRemoved()), Qt::QueuedConnection); + ++it; + } else { + it = d->visibleItems.erase(it); + d->releaseItem(item); + } + } + } + + // fix current + if (d->currentIndex >= modelIndex + count) { + d->currentIndex -= count; + if (d->currentItem) + d->currentItem->index -= count; + } else if (currentRemoved) { + // current item has been removed. + d->currentItem->attached->setIsCurrentItem(false); + d->releaseItem(d->currentItem); + d->currentItem = 0; + d->currentIndex = -1; + d->updateCurrent(qMin(modelIndex, d->model->count()-1)); + } + + // update visibleIndex + for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { + if ((*it)->index != -1) { + d->visibleIndex = (*it)->index; + break; + } + } + + if (d->visibleItems.isEmpty()) { + d->visibleIndex = 0; + d->visiblePos = 0; + d->timeline.clear(); + d->setPosition(0); + if (d->model->count() == 0) + update(); + else + refill(); + } else { + // Correct the positioning of the items + d->layout(); + d->updateSections(); + } + + emit countChanged(); +} + +void QmlGraphicsListView::destroyRemoved() +{ + Q_D(QmlGraphicsListView); + for (QList::Iterator it = d->visibleItems.begin(); + it != d->visibleItems.end();) { + FxListItem *listItem = *it; + if (listItem->index == -1 && listItem->attached->delayRemove() == false) { + d->releaseItem(listItem); + it = d->visibleItems.erase(it); + } else { + ++it; + } + } + + // Correct the positioning of the items + d->layout(); +} + +void QmlGraphicsListView::itemsMoved(int from, int to, int count) +{ + Q_D(QmlGraphicsListView); + qreal firstItemPos = d->visibleItems.first()->position(); + QHash moved; + int moveBy = 0; + + QList::Iterator it = d->visibleItems.begin(); + while (it != d->visibleItems.end()) { + FxListItem *item = *it; + if (item->index >= from && item->index < from + count) { + // take the items that are moving + item->index += (to-from); + moved.insert(item->index, item); + moveBy += item->size(); + it = d->visibleItems.erase(it); + } else { + // move everything after the moved items. + if (item->index > from && item->index != -1) + item->index -= count; + ++it; + } + } + + int remaining = count; + int endIndex = d->visibleIndex; + it = d->visibleItems.begin(); + while (it != d->visibleItems.end()) { + FxListItem *item = *it; + if (remaining && item->index >= to && item->index < to + count) { + // place items in the target position, reusing any existing items + FxListItem *movedItem = moved.take(item->index); + if (!movedItem) + movedItem = d->createItem(item->index); + it = d->visibleItems.insert(it, movedItem); + ++it; + --remaining; + } else { + if (item->index != -1) { + if (item->index >= to) { + // update everything after the moved items. + item->index += count; + } + endIndex = item->index; + } + ++it; + } + } + + // If we have moved items to the end of the visible items + // then add any existing moved items that we have + while (FxListItem *item = moved.take(endIndex+1)) { + d->visibleItems.append(item); + ++endIndex; + } + + // Whatever moved items remain are no longer visible items. + while (moved.count()) + d->releaseItem(moved.take(moved.begin().key())); + + // Ensure we don't cause an ugly list scroll. + d->visibleItems.first()->setPosition(firstItemPos); + + d->layout(); +} + +void QmlGraphicsListView::createdItem(int index, QmlGraphicsItem *item) +{ + Q_D(QmlGraphicsListView); + if (d->requestedIndex != index) { + item->setParentItem(viewport()); + d->unrequestedItems.insert(item, index); + if (d->orient == QmlGraphicsListView::Vertical) + item->setY(d->positionAt(index)); + else + item->setX(d->positionAt(index)); + } +} + +void QmlGraphicsListView::destroyingItem(QmlGraphicsItem *item) +{ + Q_D(QmlGraphicsListView); + d->unrequestedItems.remove(item); +} + +QmlGraphicsListViewAttached *QmlGraphicsListView::qmlAttachedProperties(QObject *obj) +{ + return QmlGraphicsListViewAttached::properties(obj); +} + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ListView,QmlGraphicsListView) + +QT_END_NAMESPACE +#include "qfxlistview.moc" diff --git a/src/declarative/fx/qmlgraphicslistview.h b/src/declarative/fx/qmlgraphicslistview.h new file mode 100644 index 0000000..1c19c38 --- /dev/null +++ b/src/declarative/fx/qmlgraphicslistview.h @@ -0,0 +1,186 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSLISTVIEW_H +#define QMLGRAPHICSLISTVIEW_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + + +class QmlGraphicsVisualModel; +class QmlGraphicsListViewAttached; +class QmlGraphicsListViewPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable +{ + Q_OBJECT + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsListView) + + Q_PROPERTY(QVariant model READ model WRITE setModel) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) + Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) + Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) + + Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin) + Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd) + Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode) + + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) + Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) + Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) + Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) + Q_PROPERTY(QString sectionExpression READ sectionExpression WRITE setSectionExpression NOTIFY sectionExpressionChanged) + Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) + + Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) + Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) + Q_ENUMS(HighlightRangeMode) + Q_ENUMS(Orientation) + Q_CLASSINFO("DefaultProperty", "data") + +public: + QmlGraphicsListView(QmlGraphicsItem *parent=0); + ~QmlGraphicsListView(); + + QVariant model() const; + void setModel(const QVariant &); + + QmlComponent *delegate() const; + void setDelegate(QmlComponent *); + + int currentIndex() const; + void setCurrentIndex(int idx); + + QmlGraphicsItem *currentItem(); + int count() const; + + QmlComponent *highlight() const; + void setHighlight(QmlComponent *highlight); + + bool highlightFollowsCurrentItem() const; + void setHighlightFollowsCurrentItem(bool); + + enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange }; + HighlightRangeMode highlightRangeMode() const; + void setHighlightRangeMode(HighlightRangeMode mode); + + qreal preferredHighlightBegin() const; + void setPreferredHighlightBegin(qreal); + + qreal preferredHighlightEnd() const; + void setPreferredHighlightEnd(qreal); + + qreal spacing() const; + void setSpacing(qreal spacing); + + enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical }; + Orientation orientation() const; + void setOrientation(Orientation); + + bool isWrapEnabled() const; + void setWrapEnabled(bool); + + int cacheBuffer() const; + void setCacheBuffer(int); + + QString sectionExpression() const; + void setSectionExpression(const QString &); + QString currentSection() const; + + qreal highlightMoveSpeed() const; + void setHighlightMoveSpeed(qreal); + + qreal highlightResizeSpeed() const; + void setHighlightResizeSpeed(qreal); + + static QmlGraphicsListViewAttached *qmlAttachedProperties(QObject *); + +public Q_SLOTS: + void incrementCurrentIndex(); + void decrementCurrentIndex(); + +Q_SIGNALS: + void countChanged(); + void spacingChanged(); + void orientationChanged(); + void currentIndexChanged(); + void currentSectionChanged(); + void sectionExpressionChanged(); + void highlightMoveSpeedChanged(); + void highlightResizeSpeedChanged(); + +protected: + virtual void viewportMoved(); + virtual qreal minYExtent() const; + virtual qreal maxYExtent() const; + virtual qreal minXExtent() const; + virtual qreal maxXExtent() const; + virtual void keyPressEvent(QKeyEvent *); + virtual void componentComplete(); + +private Q_SLOTS: + void refill(); + void trackedPositionChanged(); + void itemResized(); + void itemsInserted(int index, int count); + void itemsRemoved(int index, int count); + void itemsMoved(int from, int to, int count); + void destroyRemoved(); + void createdItem(int index, QmlGraphicsItem *item); + void destroyingItem(QmlGraphicsItem *item); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QmlGraphicsListView, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QmlGraphicsListView) + +QT_END_HEADER + +#endif diff --git a/src/declarative/fx/qmlgraphicsloader.cpp b/src/declarative/fx/qmlgraphicsloader.cpp new file mode 100644 index 0000000..b2a9c4f --- /dev/null +++ b/src/declarative/fx/qmlgraphicsloader.cpp @@ -0,0 +1,390 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsloader_p.h" +#include + +QT_BEGIN_NAMESPACE + +QmlGraphicsLoaderPrivate::QmlGraphicsLoaderPrivate() +: item(0), component(0), ownComponent(false), resizeMode(QmlGraphicsLoader::SizeLoaderToItem) +{ +} + +QmlGraphicsLoaderPrivate::~QmlGraphicsLoaderPrivate() +{ +} + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QmlGraphicsLoader) + +/*! + \qmlclass Loader + \inherits Item + + \brief The Loader item allows dynamically loading an Item-based + subtree from a QML URL or Component. + + Loader instantiates an item from a component. The component to + instantiate may be specified directly by the \c sourceComponent + property, or loaded from a URL via the \c source property. + + It is also an effective means of delaying the creation of a component + until it is required: + \code + Loader { id: pageLoader } + Rectangle { + MouseRegion { anchors.fill: parent; onClicked: pageLoader.source = "Page1.qml" } + } + \endcode +*/ + +/*! + \internal + \class QmlGraphicsLoader + \qmlclass Loader + */ + +/*! + Create a new QmlGraphicsLoader instance. + */ +QmlGraphicsLoader::QmlGraphicsLoader(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsLoaderPrivate), parent) +{ +} + +/*! + Destroy the loader instance. + */ +QmlGraphicsLoader::~QmlGraphicsLoader() +{ +} + +/*! + \qmlproperty url Loader::source + This property holds the URL of the QML component to + instantiate. + + \sa status, progress +*/ +QUrl QmlGraphicsLoader::source() const +{ + Q_D(const QmlGraphicsLoader); + return d->source; +} + +void QmlGraphicsLoader::setSource(const QUrl &url) +{ + Q_D(QmlGraphicsLoader); + if (d->source == url) + return; + + if (d->ownComponent) { + delete d->component; + d->component = 0; + } + delete d->item; + d->item = 0; + + d->source = url; + if (d->source.isEmpty()) { + emit sourceChanged(); + emit statusChanged(); + emit progressChanged(); + emit itemChanged(); + return; + } + + d->component = new QmlComponent(qmlEngine(this), d->source, this); + d->ownComponent = true; + if (!d->component->isLoading()) { + d->_q_sourceLoaded(); + } else { + connect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), + this, SLOT(_q_sourceLoaded())); + connect(d->component, SIGNAL(progressChanged(qreal)), + this, SIGNAL(progressChanged())); + emit statusChanged(); + emit progressChanged(); + emit sourceChanged(); + emit itemChanged(); + } +} + +/*! + \qmlproperty Component Loader::sourceComponent + The sourceComponent property holds the \l{Component} to instantiate. + + \qml + Item { + Component { + id: redSquare + Rectangle { color: "red"; width: 10; height: 10 } + } + + Loader { sourceComponent: redSquare } + Loader { sourceComponent: redSquare; x: 10 } + } + \endqml + + \sa source +*/ + +QmlComponent *QmlGraphicsLoader::sourceComponent() const +{ + Q_D(const QmlGraphicsLoader); + return d->component; +} + +void QmlGraphicsLoader::setSourceComponent(QmlComponent *comp) +{ + Q_D(QmlGraphicsLoader); + if (comp == d->component) + return; + + d->source = QUrl(); + if (d->ownComponent) { + delete d->component; + d->component = 0; + } + delete d->item; + d->item = 0; + + d->component = comp; + d->ownComponent = false; + if (!d->component) { + emit sourceChanged(); + emit statusChanged(); + emit progressChanged(); + emit itemChanged(); + return; + } + + if (!d->component->isLoading()) { + d->_q_sourceLoaded(); + } else { + connect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), + this, SLOT(_q_sourceLoaded())); + connect(d->component, SIGNAL(progressChanged(qreal)), + this, SIGNAL(progressChanged())); + emit progressChanged(); + emit sourceChanged(); + emit statusChanged(); + emit itemChanged(); + } +} + +void QmlGraphicsLoaderPrivate::_q_sourceLoaded() +{ + Q_Q(QmlGraphicsLoader); + + if (component) { + QmlContext *ctxt = new QmlContext(qmlContext(q)); + ctxt->addDefaultObject(q); + + if (!component->errors().isEmpty()) { + qWarning() << component->errors(); + emit q->sourceChanged(); + emit q->statusChanged(); + emit q->progressChanged(); + return; + } + + QObject *obj = component->create(ctxt); + if (obj) { + item = qobject_cast(obj); + if (item) { + item->setParentItem(q); +// item->setFocus(true); + QmlGraphicsItem *resizeItem = 0; + if (resizeMode == QmlGraphicsLoader::SizeLoaderToItem) + resizeItem = item; + else if (resizeMode == QmlGraphicsLoader::SizeItemToLoader) + resizeItem = q; + if (resizeItem) { + QObject::connect(resizeItem, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); + QObject::connect(resizeItem, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); + } + _q_updateSize(); + } + } else { + delete obj; + source = QUrl(); + } + emit q->sourceChanged(); + emit q->statusChanged(); + emit q->progressChanged(); + emit q->itemChanged(); + } +} + +/*! + \qmlproperty enum Loader::status + + This property holds the status of QML loading. It can be one of: + \list + \o Null - no QML source has been set + \o Ready - the QML source has been loaded + \o Loading - the QML source is currently being loaded + \o Error - an error occurred while loading the QML source + \endlist + + \sa progress +*/ + +QmlGraphicsLoader::Status QmlGraphicsLoader::status() const +{ + Q_D(const QmlGraphicsLoader); + + if (d->component) + return static_cast(d->component->status()); + + if (d->item) + return Ready; + + return d->source.isEmpty() ? Null : Error; +} + +/*! + \qmlproperty real Loader::progress + + This property holds the progress of QML data loading, from 0.0 (nothing loaded) + to 1.0 (finished). + + \sa status +*/ +qreal QmlGraphicsLoader::progress() const +{ + Q_D(const QmlGraphicsLoader); + + if (d->item) + return 1.0; + + if (d->component) + return d->component->progress(); + + return 0.0; +} + +/*! + \qmlproperty enum Loader::resizeMode + + This property determines how the Loader or item are resized: + \list + \o NoResize - no item will be resized + \o SizeLoaderToItem - the Loader will be sized to the size of the item, unless the size of the Loader has been otherwise specified. + \o SizeItemToLoader - the item will be sized to the size of the Loader. + \endlist + + The default resizeMode is SizeLoaderToItem. +*/ +QmlGraphicsLoader::ResizeMode QmlGraphicsLoader::resizeMode() const +{ + Q_D(const QmlGraphicsLoader); + return d->resizeMode; +} + +void QmlGraphicsLoader::setResizeMode(ResizeMode mode) +{ + Q_D(QmlGraphicsLoader); + if (mode == d->resizeMode) + return; + + if (d->item) { + QmlGraphicsItem *resizeItem = 0; + if (d->resizeMode == SizeLoaderToItem) + resizeItem = d->item; + else if (d->resizeMode == SizeItemToLoader) + resizeItem = this; + if (resizeItem) { + disconnect(resizeItem, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); + disconnect(resizeItem, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); + } + } + + d->resizeMode = mode; + + if (d->item) { + QmlGraphicsItem *resizeItem = 0; + if (d->resizeMode == SizeLoaderToItem) + resizeItem = d->item; + else if (d->resizeMode == SizeItemToLoader) + resizeItem = this; + if (resizeItem) { + connect(resizeItem, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); + connect(resizeItem, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); + } + + d->_q_updateSize(); + } +} + +void QmlGraphicsLoaderPrivate::_q_updateSize() +{ + Q_Q(QmlGraphicsLoader); + if (!item) + return; + switch (resizeMode) { + case QmlGraphicsLoader::SizeLoaderToItem: + q->setImplicitWidth(item->width()); + q->setImplicitHeight(item->height()); + break; + case QmlGraphicsLoader::SizeItemToLoader: + item->setWidth(q->width()); + item->setHeight(q->height()); + break; + default: + break; + } +} + +/*! + \qmlproperty Item Loader::item + This property holds the top-level item created from source. +*/ +QmlGraphicsItem *QmlGraphicsLoader::item() const +{ + Q_D(const QmlGraphicsLoader); + return d->item; +} + +QT_END_NAMESPACE + +#include "moc_qmlgraphicsloader.cpp" diff --git a/src/declarative/fx/qmlgraphicsloader.h b/src/declarative/fx/qmlgraphicsloader.h new file mode 100644 index 0000000..98f764f --- /dev/null +++ b/src/declarative/fx/qmlgraphicsloader.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSLOADER_H +#define QMLGRAPHICSLOADER_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsLoaderPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsLoader : public QmlGraphicsItem +{ + Q_OBJECT + Q_ENUMS(Status) + Q_ENUMS(ResizeMode) + + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QmlComponent *sourceComponent READ sourceComponent WRITE setSourceComponent NOTIFY sourceChanged) + Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) + Q_PROPERTY(QmlGraphicsItem *item READ item NOTIFY itemChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) + //### sourceItem + +public: + QmlGraphicsLoader(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsLoader(); + + QUrl source() const; + void setSource(const QUrl &); + + QmlComponent *sourceComponent() const; + void setSourceComponent(QmlComponent *); + + enum Status { Null, Ready, Loading, Error }; + Status status() const; + qreal progress() const; + + enum ResizeMode { NoResize, SizeLoaderToItem, SizeItemToLoader }; + ResizeMode resizeMode() const; + void setResizeMode(ResizeMode mode); + + QmlGraphicsItem *item() const; + +Q_SIGNALS: + void itemChanged(); + void sourceChanged(); + void statusChanged(); + void progressChanged(); + +private: + Q_DISABLE_COPY(QmlGraphicsLoader) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsLoader) + Q_PRIVATE_SLOT(d_func(), void _q_sourceLoaded()) + Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsLoader) + +QT_END_HEADER + +#endif // QMLGRAPHICSLOADER_H diff --git a/src/declarative/fx/qmlgraphicsloader_p.h b/src/declarative/fx/qmlgraphicsloader_p.h new file mode 100644 index 0000000..ea55334 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsloader_p.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSLOADER_P_H +#define QMLGRAPHICSLOADER_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 "qmlgraphicsitem_p.h" +#include "qmlgraphicsloader.h" + +QT_BEGIN_NAMESPACE + +class QmlContext; +class QmlGraphicsLoaderPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsLoader) + +public: + QmlGraphicsLoaderPrivate(); + ~QmlGraphicsLoaderPrivate(); + + QUrl source; + QmlGraphicsItem *item; + QmlComponent *component; + bool ownComponent; + QmlGraphicsLoader::ResizeMode resizeMode; + + void _q_sourceLoaded(); + void _q_updateSize(); +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSLOADER_P_H diff --git a/src/declarative/fx/qmlgraphicsmouseregion.cpp b/src/declarative/fx/qmlgraphicsmouseregion.cpp new file mode 100644 index 0000000..7ad1ac2 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsmouseregion.cpp @@ -0,0 +1,649 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsmouseregion.h" +#include "qmlgraphicsmouseregion_p.h" +#include "qmlgraphicsevents_p.h" +#include + + +QT_BEGIN_NAMESPACE +static const qreal DragThreshold = 5; +static const int PressAndHoldDelay = 800; + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Drag,QmlGraphicsDrag) +QmlGraphicsDrag::QmlGraphicsDrag(QObject *parent) +: QObject(parent), _target(0), _axis(XandYAxis), _xmin(0), _xmax(0), _ymin(0), _ymax(0) +{ +} + +QmlGraphicsDrag::~QmlGraphicsDrag() +{ +} + +QmlGraphicsItem *QmlGraphicsDrag::target() const +{ + return _target; +} + +void QmlGraphicsDrag::setTarget(QmlGraphicsItem *t) +{ + _target = t; +} + +QmlGraphicsDrag::Axis QmlGraphicsDrag::axis() const +{ + return _axis; +} + +void QmlGraphicsDrag::setAxis(QmlGraphicsDrag::Axis a) +{ + _axis = a; +} + +qreal QmlGraphicsDrag::xmin() const +{ + return _xmin; +} + +void QmlGraphicsDrag::setXmin(qreal m) +{ + _xmin = m; +} + +qreal QmlGraphicsDrag::xmax() const +{ + return _xmax; +} + +void QmlGraphicsDrag::setXmax(qreal m) +{ + _xmax = m; +} + +qreal QmlGraphicsDrag::ymin() const +{ + return _ymin; +} + +void QmlGraphicsDrag::setYmin(qreal m) +{ + _ymin = m; +} + +qreal QmlGraphicsDrag::ymax() const +{ + return _ymax; +} + +void QmlGraphicsDrag::setYmax(qreal m) +{ + _ymax = m; +} + +/*! + \qmlclass MouseRegion + \brief The MouseRegion item enables simple mouse handling. + \inherits Item + + A MouseRegion is typically used in conjunction with a visible item, + where the MouseRegion effectively 'proxies' mouse handling for that + item. For example, we can put a MouseRegion in a Rectangle that changes + the Rectangle color to red when clicked: + \snippet doc/src/snippets/declarative/mouseregion.qml 0 + + Many MouseRegion signals pass a \l {MouseEvent}{mouse} parameter that contains + additional information about the mouse event, such as the position, button, + and any key modifiers. + + Below we have the previous + example extended so as to give a different color when you right click. + \snippet doc/src/snippets/declarative/mouseregion.qml 1 + + For basic key handling, see the \l {Keys}{Keys attached property}. + + MouseRegion is an invisible item: it is never painted. + + \sa MouseEvent +*/ + +/*! + \qmlsignal MouseRegion::onEntered + + This handler is called when the mouse enters the mouse region. +*/ + +/*! + \qmlsignal MouseRegion::onExited + + This handler is called when the mouse exists the mouse region. +*/ + +/*! + \qmlsignal MouseRegion::onPositionChanged(mouse) + + This handler is called when the mouse position changes. + + The \l {MouseEvent}{mouse} parameter provides information about the mouse, including the x and y + position, and any buttons currently pressed. + + The \e accepted property of the MouseEvent parameter is ignored in this handler. +*/ + +/*! + \qmlsignal MouseRegion::onClicked(mouse) + + This handler is called when there is a click. A click is defined as a press followed by a release, + both inside the MouseRegion (pressing, moving outside the MouseRegion, and then moving back inside and + releasing is also considered a click). + + The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y + position of the release of the click, and whether the click wasHeld. + + The \e accepted property of the MouseEvent parameter is ignored in this handler. +*/ + +/*! + \qmlsignal MouseRegion::onPressed(mouse) + + This handler is called when there is a press. + The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y + position and which button was pressed. + + The \e accepted property of the MouseEvent parameter determines whether this MouseRegion + will handle the press and all future mouse events until release. The default is to accept + the event and not allow other MouseRegions beneath this one to handle the event. If \e accepted + is set to false, no further events will be sent to this MouseRegion until the button is next + pressed. +*/ + +/*! + \qmlsignal MouseRegion::onReleased(mouse) + + This handler is called when there is a release. + The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y + position of the release of the click, and whether the click wasHeld. + + The \e accepted property of the MouseEvent parameter is ignored in this handler. +*/ + +/*! + \qmlsignal MouseRegion::onPressAndHold(mouse) + + This handler is called when there is a long press (currently 800ms). + The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y + position of the press, and which button is pressed. + + The \e accepted property of the MouseEvent parameter is ignored in this handler. +*/ + +/*! + \qmlsignal MouseRegion::onDoubleClicked(mouse) + + This handler is called when there is a double-click (a press followed by a release followed by a press). + The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y + position of the release of the click, and whether the click wasHeld. + + The \e accepted property of the MouseEvent parameter is ignored in this handler. +*/ + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,MouseRegion,QmlGraphicsMouseRegion) + +/*! + \internal + \class QmlGraphicsMouseRegion + \brief The QmlGraphicsMouseRegion class provides a simple mouse handling abstraction for use within Qml. + + \ingroup group_coreitems + + All QmlGraphicsItem derived classes can do mouse handling but the QmlGraphicsMouseRegion class exposes mouse + handling data as properties and tracks flicking and dragging of the mouse. + + A QmlGraphicsMouseRegion object can be instantiated in Qml using the tag \l MouseRegion. + */ +QmlGraphicsMouseRegion::QmlGraphicsMouseRegion(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsMouseRegionPrivate), parent) +{ + Q_D(QmlGraphicsMouseRegion); + d->init(); +} + +QmlGraphicsMouseRegion::QmlGraphicsMouseRegion(QmlGraphicsMouseRegionPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ + Q_D(QmlGraphicsMouseRegion); + d->init(); +} + +QmlGraphicsMouseRegion::~QmlGraphicsMouseRegion() +{ +} + +/*! + \qmlproperty real MouseRegion::mouseX + \qmlproperty real MouseRegion::mouseY + These properties hold the coordinates of the mouse. + + If the hoverEnabled property is false then these properties will only be valid + while a button is pressed, and will remain valid as long as the button is held + even if the mouse is moved outside the region. + + If hoverEnabled is true then these properties will be valid: + \list + \i when no button is pressed, but the mouse is within the MouseRegion (containsMouse is true). + \i if a button is pressed and held, even if it has since moved out of the region. + \endlist + + The coordinates are relative to the MouseRegion. +*/ +qreal QmlGraphicsMouseRegion::mouseX() const +{ + Q_D(const QmlGraphicsMouseRegion); + return d->lastPos.x(); +} + +qreal QmlGraphicsMouseRegion::mouseY() const +{ + Q_D(const QmlGraphicsMouseRegion); + return d->lastPos.y(); +} + +/*! + \qmlproperty bool MouseRegion::enabled + This property holds whether the item accepts mouse events. +*/ +bool QmlGraphicsMouseRegion::isEnabled() const +{ + Q_D(const QmlGraphicsMouseRegion); + return d->absorb; +} + +void QmlGraphicsMouseRegion::setEnabled(bool a) +{ + Q_D(QmlGraphicsMouseRegion); + if (a != d->absorb) { + d->absorb = a; + emit enabledChanged(); + } +} +/*! + \qmlproperty MouseButtons MouseRegion::pressedButtons + This property holds the mouse buttons currently pressed. + + It contains a bitwise combination of: + \list + \o Qt.LeftButton + \o Qt.RightButton + \o Qt.MidButton + \endlist + + The code below displays "right" when the right mouse buttons is pressed: + \code + Text { + text: mr.pressedButtons & Qt.RightButton ? "right" : "" + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + MouseRegion { + id: mr + acceptedButtons: Qt.LeftButton | Qt.RightButton + anchors.fill: parent + } + } + \endcode + + \sa acceptedButtons +*/ +Qt::MouseButtons QmlGraphicsMouseRegion::pressedButtons() const +{ + Q_D(const QmlGraphicsMouseRegion); + return d->lastButtons; +} + +void QmlGraphicsMouseRegion::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsMouseRegion); + d->moved = false; + if (!d->absorb) + QmlGraphicsItem::mousePressEvent(event); + else { + d->longPress = false; + d->saveEvent(event); + d->dragX = drag()->axis() & QmlGraphicsDrag::XAxis; + d->dragY = drag()->axis() & QmlGraphicsDrag::YAxis; + d->dragged = false; + setHovered(true); + d->start = event->pos(); + d->startScene = event->scenePos(); + // we should only start timer if pressAndHold is connected to. + if (d->isConnected("pressAndHold(QmlGraphicsMouseEvent*)")) + d->pressAndHoldTimer.start(PressAndHoldDelay, this); + setKeepMouseGrab(false); + event->setAccepted(setPressed(true)); + } +} + +void QmlGraphicsMouseRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsMouseRegion); + if (!d->absorb) { + QmlGraphicsItem::mouseMoveEvent(event); + return; + } + + d->saveEvent(event); + + // ### we should skip this if these signals aren't used + // ### can GV handle this for us? + bool contains = boundingRect().contains(d->lastPos); + if (d->hovered && !contains) + setHovered(false); + else if (!d->hovered && contains) + setHovered(true); + + if (drag()->target()) { + if (!d->moved) { + if (d->dragX) d->startX = drag()->target()->x(); + if (d->dragY) d->startY = drag()->target()->y(); + } + + QPointF startLocalPos; + QPointF curLocalPos; + if (drag()->target()->parent()) { + startLocalPos = drag()->target()->parentItem()->mapFromScene(d->startScene); + curLocalPos = drag()->target()->parentItem()->mapFromScene(event->scenePos()); + } else { + startLocalPos = d->startScene; + curLocalPos = event->scenePos(); + } + + qreal dx = qAbs(curLocalPos.x() - startLocalPos.x()); + qreal dy = qAbs(curLocalPos.y() - startLocalPos.y()); + if ((d->dragX && !(dx < DragThreshold)) || (d->dragY && !(dy < DragThreshold))) + d->dragged = true; + if (!keepMouseGrab()) { + if ((!d->dragY && dy < DragThreshold && d->dragX && dx > DragThreshold) + || (!d->dragX && dx < DragThreshold && d->dragY && dy > DragThreshold) + || (d->dragX && d->dragY)) { + setKeepMouseGrab(true); + } + } + + if (d->dragX) { + qreal x = (curLocalPos.x() - startLocalPos.x()) + d->startX; + if (x < drag()->xmin()) + x = drag()->xmin(); + else if (x > drag()->xmax()) + x = drag()->xmax(); + drag()->target()->setX(x); + } + if (d->dragY) { + qreal y = (curLocalPos.y() - startLocalPos.y()) + d->startY; + if (y < drag()->ymin()) + y = drag()->ymin(); + else if (y > drag()->ymax()) + y = drag()->ymax(); + drag()->target()->setY(y); + } + } + d->moved = true; + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); + emit positionChanged(&me); +} + + +void QmlGraphicsMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsMouseRegion); + if (!d->absorb) { + QmlGraphicsItem::mouseReleaseEvent(event); + } else { + d->saveEvent(event); + setPressed(false); + // If we don't accept hover, we need to reset containsMouse. + if (!acceptHoverEvents()) + setHovered(false); + setKeepMouseGrab(false); + } +} + +void QmlGraphicsMouseRegion::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsMouseRegion); + if (!d->absorb) { + QmlGraphicsItem::mouseDoubleClickEvent(event); + } else { + QmlGraphicsItem::mouseDoubleClickEvent(event); + if (event->isAccepted()) { + // Only deliver the event if we have accepted the press. + d->saveEvent(event); + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false); + emit this->doubleClicked(&me); + } + } +} + +void QmlGraphicsMouseRegion::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + Q_D(QmlGraphicsMouseRegion); + if (!d->absorb) + QmlGraphicsItem::hoverEnterEvent(event); + else + setHovered(true); +} + +void QmlGraphicsMouseRegion::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_D(QmlGraphicsMouseRegion); + if (!d->absorb) { + QmlGraphicsItem::hoverEnterEvent(event); + } else { + d->lastPos = event->pos(); + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, d->lastButtons, d->lastModifiers, false, d->longPress); + emit positionChanged(&me); + } +} + +void QmlGraphicsMouseRegion::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_D(QmlGraphicsMouseRegion); + if (!d->absorb) + QmlGraphicsItem::hoverLeaveEvent(event); + else + setHovered(false); +} + +bool QmlGraphicsMouseRegion::sceneEvent(QEvent *event) +{ + bool rv = QmlGraphicsItem::sceneEvent(event); + if (event->type() == QEvent::UngrabMouse) { + Q_D(QmlGraphicsMouseRegion); + if (d->pressed) { + // if our mouse grab has been removed (probably by Flickable), fix our + // state + d->pressed = false; + setKeepMouseGrab(false); + emit pressedChanged(); + //emit hoveredChanged(); + } + } + return rv; +} + +void QmlGraphicsMouseRegion::timerEvent(QTimerEvent *event) +{ + Q_D(QmlGraphicsMouseRegion); + if (event->timerId() == d->pressAndHoldTimer.timerId()) { + d->pressAndHoldTimer.stop(); + if (d->pressed && d->dragged == false && d->hovered == true) { + d->longPress = true; + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); + emit pressAndHold(&me); + } + } +} + +/*! + \qmlproperty bool MouseRegion::hoverEnabled + This property holds whether hover events are handled. + + By default, mouse events are only handled in response to a button event, or when a button is + pressed. Hover enables handling of all mouse events even when no mouse button is + pressed. + + This property affects the containsMouse property and the onEntered, onExited and onPositionChanged signals. +*/ + +/*! + \qmlproperty bool MouseRegion::containsMouse + This property holds whether the mouse is currently inside the mouse region. + + \warning This property is not updated if the region moves under the mouse: \e containsMouse will not change. + In addition, if hoverEnabled is false, containsMouse will only be valid when the mouse is pressed. +*/ +bool QmlGraphicsMouseRegion::hovered() const +{ + Q_D(const QmlGraphicsMouseRegion); + return d->hovered; +} + +/*! + \qmlproperty bool MouseRegion::pressed + This property holds whether the mouse region is currently pressed. +*/ +bool QmlGraphicsMouseRegion::pressed() const +{ + Q_D(const QmlGraphicsMouseRegion); + return d->pressed; +} + +void QmlGraphicsMouseRegion::setHovered(bool h) +{ + Q_D(QmlGraphicsMouseRegion); + if (d->hovered != h) { + d->hovered = h; + emit hoveredChanged(); + d->hovered ? emit entered() : emit exited(); + } +} + +/*! + \qmlproperty Qt::MouseButtons MouseRegion::acceptedButtons + This property holds the mouse buttons that the mouse region reacts to. + + The available buttons are: + \list + \o Qt.LeftButton + \o Qt.RightButton + \o Qt.MiddleButton + \endlist + + To accept more than one button the flags can be combined with the + "|" (or) operator: + + \code + MouseRegion { acceptedButtons: Qt.LeftButton | Qt.RightButton } + \endcode + + The default is to accept the Left button. +*/ +Qt::MouseButtons QmlGraphicsMouseRegion::acceptedButtons() const +{ + return acceptedMouseButtons(); +} + +void QmlGraphicsMouseRegion::setAcceptedButtons(Qt::MouseButtons buttons) +{ + if (buttons != acceptedMouseButtons()) { + setAcceptedMouseButtons(buttons); + emit acceptedButtonsChanged(); + } +} + +bool QmlGraphicsMouseRegion::setPressed(bool p) +{ + Q_D(QmlGraphicsMouseRegion); + bool isclick = d->pressed == true && p == false && d->dragged == false && d->hovered == true; + + if (d->pressed != p) { + d->pressed = p; + QmlGraphicsMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress); + if (d->pressed) { + emit positionChanged(&me); + emit pressed(&me); + } else { + emit released(&me); + if (isclick) + emit clicked(&me); + } + + emit pressedChanged(); + return me.isAccepted(); + } + return false; +} + +QmlGraphicsDrag *QmlGraphicsMouseRegion::drag() +{ + Q_D(QmlGraphicsMouseRegion); + return &(d->drag); +} + +/*! + \qmlproperty Item MouseRegion::drag.target + \qmlproperty Axis MouseRegion::drag.axis + \qmlproperty real MouseRegion::drag.minimumX + \qmlproperty real MouseRegion::drag.maximumX + \qmlproperty real MouseRegion::drag.minimumY + \qmlproperty real MouseRegion::drag.maximumY + + drag provides a convenient way to make an item draggable. + + \list + \i \c target specifies the item to drag. + \i \c axis specifies whether dragging can be done horizontally (XAxis), vertically (YAxis), or both (XandYAxis) + \i the minimum and maximum properties limit how far the target can be dragged along the corresponding axes. + \endlist + + The following example uses drag to reduce the opacity of an image as it moves to the right: + \snippet doc/src/snippets/declarative/drag.qml 0 +*/ + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsmouseregion.h b/src/declarative/fx/qmlgraphicsmouseregion.h new file mode 100644 index 0000000..9874fbf --- /dev/null +++ b/src/declarative/fx/qmlgraphicsmouseregion.h @@ -0,0 +1,180 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSMOUSEREGION_H +#define QMLGRAPHICSMOUSEREGION_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class Q_DECLARATIVE_EXPORT QmlGraphicsDrag : public QObject +{ + Q_OBJECT + + Q_ENUMS(Axis) + Q_PROPERTY(QmlGraphicsItem *target READ target WRITE setTarget) + Q_PROPERTY(Axis axis READ axis WRITE setAxis) + Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin) + Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax) + Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin) + Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax) + //### consider drag and drop + +public: + QmlGraphicsDrag(QObject *parent=0); + ~QmlGraphicsDrag(); + + QmlGraphicsItem *target() const; + void setTarget(QmlGraphicsItem *); + + enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 }; + Axis axis() const; + void setAxis(Axis); + + qreal xmin() const; + void setXmin(qreal); + qreal xmax() const; + void setXmax(qreal); + qreal ymin() const; + void setYmin(qreal); + qreal ymax() const; + void setYmax(qreal); + +private: + QmlGraphicsItem *_target; + Axis _axis; + qreal _xmin; + qreal _xmax; + qreal _ymin; + qreal _ymax; + Q_DISABLE_COPY(QmlGraphicsDrag) +}; + +class QmlGraphicsMouseEvent; +class QmlGraphicsMouseRegionPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsMouseRegion : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(qreal mouseX READ mouseX NOTIFY positionChanged) + Q_PROPERTY(qreal mouseY READ mouseY NOTIFY positionChanged) + Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) + Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged) + Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) + Q_PROPERTY(bool hoverEnabled READ acceptHoverEvents WRITE setAcceptHoverEvents) + Q_PROPERTY(QmlGraphicsDrag *drag READ drag) //### add flicking to QmlGraphicsDrag or add a QmlGraphicsFlick ??? + +public: + QmlGraphicsMouseRegion(QmlGraphicsItem *parent=0); + ~QmlGraphicsMouseRegion(); + + qreal mouseX() const; + qreal mouseY() const; + + bool isEnabled() const; + void setEnabled(bool); + + bool hovered() const; + bool pressed() const; + + Qt::MouseButtons pressedButtons() const; + + Qt::MouseButtons acceptedButtons() const; + void setAcceptedButtons(Qt::MouseButtons buttons); + + QmlGraphicsDrag *drag(); + +Q_SIGNALS: + void hoveredChanged(); + void pressedChanged(); + void enabledChanged(); + void acceptedButtonsChanged(); + void positionChanged(QmlGraphicsMouseEvent *mouse); + + void pressed(QmlGraphicsMouseEvent *mouse); + void pressAndHold(QmlGraphicsMouseEvent *mouse); + void released(QmlGraphicsMouseEvent *mouse); + void clicked(QmlGraphicsMouseEvent *mouse); + void doubleClicked(QmlGraphicsMouseEvent *mouse); + void entered(); + void exited(); + +protected: + void setHovered(bool); + bool setPressed(bool); + + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverMoveEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + bool sceneEvent(QEvent *); + void timerEvent(QTimerEvent *event); + +private: + void handlePress(); + void handleRelease(); + +protected: + QmlGraphicsMouseRegion(QmlGraphicsMouseRegionPrivate &dd, QmlGraphicsItem *parent); + +private: + Q_DISABLE_COPY(QmlGraphicsMouseRegion) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsMouseRegion) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsDrag) +QML_DECLARE_TYPE(QmlGraphicsMouseRegion) + +QT_END_HEADER + +#endif // QMLGRAPHICSMOUSEREGION_H diff --git a/src/declarative/fx/qmlgraphicsmouseregion_p.h b/src/declarative/fx/qmlgraphicsmouseregion_p.h new file mode 100644 index 0000000..71b31b4 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsmouseregion_p.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSMOUSEREGION_P_H +#define QMLGRAPHICSMOUSEREGION_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 "qdatetime.h" +#include "qbasictimer.h" +#include "qgraphicssceneevent.h" +#include "qmlgraphicsitem_p.h" + +QT_BEGIN_NAMESPACE + +class QmlGraphicsMouseRegionPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsMouseRegion) + +public: + QmlGraphicsMouseRegionPrivate() + : absorb(true), hovered(false), pressed(false), longPress(false), drag(0) + { + } + + void init() + { + Q_Q(QmlGraphicsMouseRegion); + q->setAcceptedMouseButtons(Qt::LeftButton); + } + + void saveEvent(QGraphicsSceneMouseEvent *event) { + lastPos = event->pos(); + lastButton = event->button(); + lastButtons = event->buttons(); + lastModifiers = event->modifiers(); + } + + bool isConnected(const char *signal) { + Q_Q(QmlGraphicsMouseRegion); + int idx = QObjectPrivate::get(q)->signalIndex(signal); + return QObjectPrivate::get(q)->isSignalConnected(idx); + } + + bool absorb : 1; + bool hovered : 1; + bool pressed : 1; + bool longPress : 1; + bool moved : 1; + bool dragX : 1; + bool dragY : 1; + bool dragged : 1; + QmlGraphicsDrag drag; + QPointF start; + QPointF startScene; + qreal startX; + qreal startY; + QPointF lastPos; + Qt::MouseButton lastButton; + Qt::MouseButtons lastButtons; + Qt::KeyboardModifiers lastModifiers; + QBasicTimer pressAndHoldTimer; +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSMOUSEREGION_P_H diff --git a/src/declarative/fx/qmlgraphicspainteditem.cpp b/src/declarative/fx/qmlgraphicspainteditem.cpp new file mode 100644 index 0000000..43d0318 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspainteditem.cpp @@ -0,0 +1,387 @@ +/**************************************************************************** +** +** 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 "qmlgraphicspainteditem.h" +#include "qmlgraphicspainteditem_p.h" + +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \class QmlGraphicsPaintedItem + \brief The QmlGraphicsPaintedItem class is an abstract base class for QmlView items that want cached painting. + \internal + + This is a convenience class for implementing items that paint their contents + using a QPainter. The contents of the item are cached behind the scenes. + The dirtyCache() function should be called if the contents change to + ensure the cache is refreshed the next time painting occurs. + + To subclass QmlGraphicsPaintedItem, you must reimplement drawContents() to draw + the contents of the item. +*/ + +/*! + \fn void QmlGraphicsPaintedItem::drawContents(QPainter *painter, const QRect &rect) + + This function is called when the cache needs to be refreshed. When + sub-classing QmlGraphicsPaintedItem this function should be implemented so as to + paint the contents of the item using the given \a painter for the + area of the contents specified by \a rect. +*/ + +/*! + \property QmlGraphicsPaintedItem::contentsSize + \brief The size of the contents + + The contents size is the size of the item in regards to how it is painted + using the drawContents() function. This is distinct from the size of the + item in regards to height() and width(). +*/ + +// XXX bug in WebKit - can call repaintRequested and other cache-changing functions from within render! +static int inpaint=0; +static int inpaint_clearcache=0; + +/*! + Marks areas of the cache that intersect with the given \a rect as dirty and + in need of being refreshed. + + \sa clearCache() +*/ +void QmlGraphicsPaintedItem::dirtyCache(const QRect& rect) +{ + Q_D(QmlGraphicsPaintedItem); + for (int i=0; i < d->imagecache.count(); ) { + QmlGraphicsPaintedItemPrivate::ImageCacheItem *c = d->imagecache[i]; + QRect isect = (c->area & rect) | c->dirty; + if (isect == c->area && !inpaint) { + delete d->imagecache.takeAt(i); + } else { + c->dirty = isect; + ++i; + } + } +} + +/*! + Marks the entirety of the contents cache as dirty. + + \sa dirtyCache() +*/ +void QmlGraphicsPaintedItem::clearCache() +{ + if (inpaint) { + inpaint_clearcache=1; + return; + } + Q_D(QmlGraphicsPaintedItem); + qDeleteAll(d->imagecache); + d->imagecache.clear(); +} + +/*! + Returns the size of the contents. + + \sa setContentsSize() +*/ +QSize QmlGraphicsPaintedItem::contentsSize() const +{ + Q_D(const QmlGraphicsPaintedItem); + return d->contentsSize; +} + +/*! + Sets the size of the contents to the given \a size. + + \sa contentsSize() +*/ +void QmlGraphicsPaintedItem::setContentsSize(const QSize &size) +{ + Q_D(QmlGraphicsPaintedItem); + if (d->contentsSize == size) return; + d->contentsSize = size; + clearCache(); + update(); +} + +/*! + Constructs a new QmlGraphicsPaintedItem with the given \a parent. +*/ +QmlGraphicsPaintedItem::QmlGraphicsPaintedItem(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsPaintedItemPrivate), parent) +{ + init(); +} + +/*! + \internal + Constructs a new QmlGraphicsPaintedItem with the given \a parent and + initialized private data member \a dd. +*/ +QmlGraphicsPaintedItem::QmlGraphicsPaintedItem(QmlGraphicsPaintedItemPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ + init(); +} + +/*! + Destroys the image item. +*/ +QmlGraphicsPaintedItem::~QmlGraphicsPaintedItem() +{ + clearCache(); +} + +/*! + \internal +*/ +void QmlGraphicsPaintedItem::init() +{ + connect(this,SIGNAL(widthChanged()),this,SLOT(clearCache())); + connect(this,SIGNAL(heightChanged()),this,SLOT(clearCache())); + connect(this,SIGNAL(visibleChanged()),this,SLOT(clearCache())); +} + +void QmlGraphicsPaintedItem::setCacheFrozen(bool frozen) +{ + Q_D(QmlGraphicsPaintedItem); + if (d->cachefrozen == frozen) + return; + d->cachefrozen = frozen; + // XXX clear cache? +} + +/*! + \reimp +*/ +void QmlGraphicsPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + Q_D(QmlGraphicsPaintedItem); + const QRect content(QPoint(0,0),d->contentsSize); + if (content.width() <= 0 || content.height() <= 0) + return; + + ++inpaint; + + QRectF clipf = p->clipRegion().boundingRect(); + if (clipf.isEmpty()) + clipf = mapToScene(content).boundingRect(); // ### Inefficient: Maps toScene and then fromScene + else + clipf = mapToScene(clipf).boundingRect(); + + const QRect clip = mapFromScene(clipf).boundingRect().toRect(); + + QRegion topaint(clip); + topaint &= content; + QRegion uncached(content); + + int cachesize=0; + for (int i=0; iimagecache.count(); ++i) { + QRect area = d->imagecache[i]->area; + if (topaint.contains(area)) { + QRectF target(area.x(), area.y(), area.width(), area.height()); + if (!d->cachefrozen) { + if (!d->imagecache[i]->dirty.isNull() && topaint.contains(d->imagecache[i]->dirty)) { + QPainter qp(&d->imagecache[i]->image); + qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smooth); + qp.translate(-area.x(), -area.y()); + if (d->fillColor.isValid()){ + if(d->fillColor.alpha() < 255){ + // ### Might not work outside of raster paintengine + QPainter::CompositionMode prev = qp.compositionMode(); + qp.setCompositionMode(QPainter::CompositionMode_Source); + qp.fillRect(d->imagecache[i]->dirty,d->fillColor); + qp.setCompositionMode(prev); + }else{ + qp.fillRect(d->imagecache[i]->dirty,d->fillColor); + } + } + qp.setClipRect(d->imagecache[i]->dirty); + drawContents(&qp, d->imagecache[i]->dirty); + d->imagecache[i]->dirty = QRect(); + } + } + p->drawPixmap(target.toRect(), d->imagecache[i]->image); + topaint -= area; + d->imagecache[i]->age=0; + } else { + d->imagecache[i]->age++; + } + cachesize += area.width()*area.height(); + uncached -= area; + } + + if (!topaint.isEmpty()) { + if (!d->cachefrozen) { + // Find a sensible larger area, otherwise will paint lots of tiny images. + QRect biggerrect = topaint.boundingRect().adjusted(-64,-64,128,128); + cachesize += biggerrect.width() * biggerrect.height(); + while (d->imagecache.count() && cachesize > d->max_imagecache_size) { + int oldest=-1; + int age=-1; + for (int i=0; iimagecache.count(); ++i) { + int a = d->imagecache[i]->age; + if (a > age) { + oldest = i; + age = a; + } + } + cachesize -= d->imagecache[oldest]->area.width()*d->imagecache[oldest]->area.height(); + uncached += d->imagecache[oldest]->area; + d->imagecache.removeAt(oldest); + } + const QRegion bigger = QRegion(biggerrect) & uncached; + const QVector rects = bigger.rects(); + for (int i = 0; i < rects.count(); ++i) { + const QRect &r = rects.at(i); + QPixmap img(r.size()); + if (d->fillColor.isValid()) + img.fill(d->fillColor); + { + QPainter qp(&img); + qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smooth); + + qp.translate(-r.x(),-r.y()); + drawContents(&qp, r); + } + QmlGraphicsPaintedItemPrivate::ImageCacheItem *newitem = new QmlGraphicsPaintedItemPrivate::ImageCacheItem; + newitem->area = r; + newitem->image = img; + d->imagecache.append(newitem); + p->drawPixmap(r, newitem->image); + } + } else { + const QVector rects = uncached.rects(); + for (int i = 0; i < rects.count(); ++i) + p->fillRect(rects.at(i), Qt::lightGray); + } + } + + if (inpaint_clearcache) { + clearCache(); + inpaint_clearcache = 0; + } + + --inpaint; +} + +/*! + \qmlproperty int PaintedItem::cacheSize + + This property holds the maximum number of pixels of image cache to + allow. The default is 0.1 megapixels. The cache will not be larger + than the (unscaled) size of the item. +*/ + +/*! + \property QmlGraphicsPaintedItem::cacheSize + + The maximum number of pixels of image cache to allow. The default + is 0.1 megapixels. The cache will not be larger than the (unscaled) + size of the QmlGraphicsPaintedItem. +*/ +int QmlGraphicsPaintedItem::cacheSize() const +{ + Q_D(const QmlGraphicsPaintedItem); + return d->max_imagecache_size; +} + +void QmlGraphicsPaintedItem::setCacheSize(int pixels) +{ + Q_D(QmlGraphicsPaintedItem); + if (pixels < d->max_imagecache_size) { + int cachesize=0; + for (int i=0; iimagecache.count(); ++i) { + QRect area = d->imagecache[i]->area; + cachesize += area.width()*area.height(); + } + while (d->imagecache.count() && cachesize > pixels) { + int oldest=-1; + int age=-1; + for (int i=0; iimagecache.count(); ++i) { + int a = d->imagecache[i]->age; + if (a > age) { + oldest = i; + age = a; + } + } + cachesize -= d->imagecache[oldest]->area.width()*d->imagecache[oldest]->area.height(); + d->imagecache.removeAt(oldest); + } + } + d->max_imagecache_size = pixels; +} + +/*! + \property QmlGraphicsPaintedItem::fillColor + + The color to be used to fill the item prior to calling drawContents(). + By default, this is Qt::transparent. + + Performance improvements can be achieved if subclasses call this with either an + invalid color (QColor()), or an appropriate solid color. +*/ +void QmlGraphicsPaintedItem::setFillColor(const QColor& c) +{ + Q_D(QmlGraphicsPaintedItem); + if (d->fillColor == c) + return; + d->fillColor = c; + emit fillColorChanged(); + update(); +} + +QColor QmlGraphicsPaintedItem::fillColor() const +{ + Q_D(const QmlGraphicsPaintedItem); + return d->fillColor; +} + + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicspainteditem.h b/src/declarative/fx/qmlgraphicspainteditem.h new file mode 100644 index 0000000..7ff55a5 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspainteditem.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSIMAGEITEM_H +#define QMLGRAPHICSIMAGEITEM_H + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsPaintedItemPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsPaintedItem : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(QSize contentsSize READ contentsSize WRITE setContentsSize) + Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY fillColorChanged) + Q_PROPERTY(int cacheSize READ cacheSize WRITE setCacheSize) + +public: + QmlGraphicsPaintedItem(QmlGraphicsItem *parent=0); + ~QmlGraphicsPaintedItem(); + + QSize contentsSize() const; + void setContentsSize(const QSize &); + + int cacheSize() const; + void setCacheSize(int pixels); + + QColor fillColor() const; + void setFillColor(const QColor&); + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +protected: + QmlGraphicsPaintedItem(QmlGraphicsPaintedItemPrivate &dd, QmlGraphicsItem *parent); + + virtual void drawContents(QPainter *p, const QRect &) = 0; + + void setCacheFrozen(bool); + +Q_SIGNALS: + void fillColorChanged(); + +protected Q_SLOTS: + void dirtyCache(const QRect &); + void clearCache(); + +private: + void init(); + Q_DISABLE_COPY(QmlGraphicsPaintedItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsPaintedItem) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsPaintedItem) + +QT_END_HEADER + +#endif diff --git a/src/declarative/fx/qmlgraphicspainteditem_p.h b/src/declarative/fx/qmlgraphicspainteditem_p.h new file mode 100644 index 0000000..d5cd673 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspainteditem_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSIMAGEITEM_P_H +#define QMLGRAPHICSIMAGEITEM_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 + +QT_BEGIN_NAMESPACE + +class QmlGraphicsPaintedItemPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsPaintedItem) + +public: + QmlGraphicsPaintedItemPrivate() + : max_imagecache_size(100000), fillColor(Qt::transparent), cachefrozen(false) + { + } + + struct ImageCacheItem { + ImageCacheItem() : age(0) {} + ~ImageCacheItem() { } + int age; + QRect area; + QRect dirty; // one dirty area (allows optimization of common cases) + QPixmap image; + }; + + QList imagecache; + + int max_imagecache_size; + QSize contentsSize; + QColor fillColor; + bool cachefrozen; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/declarative/fx/qmlgraphicspath.cpp b/src/declarative/fx/qmlgraphicspath.cpp new file mode 100644 index 0000000..15dbfef --- /dev/null +++ b/src/declarative/fx/qmlgraphicspath.cpp @@ -0,0 +1,839 @@ +/**************************************************************************** +** +** 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 "qmlgraphicspath.h" +#include "qmlgraphicspath_p.h" +#include +#include +#include + + +QT_BEGIN_NAMESPACE +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Path,QmlGraphicsPath) +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsPathElement) +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsCurve) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathAttribute,QmlGraphicsPathAttribute) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathPercent,QmlGraphicsPathPercent) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathLine,QmlGraphicsPathLine) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathQuad,QmlGraphicsPathQuad) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathCubic,QmlGraphicsPathCubic) + +/*! + \qmlclass PathElement + \brief PathElement is the base path type. + + This type is the base for all path types. It cannot + be instantiated. + + \sa Path, PathAttribute, PathPercent, PathLine, PathQuad, PathCubic +*/ + +/*! + \internal + \class QmlGraphicsPathElement + \ingroup group_utility +*/ + +/*! + \qmlclass Path QmlGraphicsPath + \brief A Path object defines a path for use by \l PathView. + + A Path is composed of one or more path segments - PathLine, PathQuad, + PathCubic. + + The spacing of the items along the Path can be adjusted via a + PathPercent object. + + PathAttribute allows named attributes with values to be defined + along the path. + + \sa PathView, PathAttribute, PathPercent, PathLine, PathQuad, PathCubic +*/ + +/*! + \internal + \class QmlGraphicsPath + \ingroup group_utility + \brief The QmlGraphicsPath class defines a path. + \sa QmlGraphicsPathView +*/ +QmlGraphicsPath::QmlGraphicsPath(QObject *parent) + : QObject(*(new QmlGraphicsPathPrivate), parent) +{ +} + +QmlGraphicsPath::QmlGraphicsPath(QmlGraphicsPathPrivate &dd, QObject *parent) + : QObject(dd, parent) +{ +} + +QmlGraphicsPath::~QmlGraphicsPath() +{ +} + +/*! + \qmlproperty real Path::startX + \qmlproperty real Path::startY + This property holds the starting position of the path. +*/ +qreal QmlGraphicsPath::startX() const +{ + Q_D(const QmlGraphicsPath); + return d->startX; +} + +void QmlGraphicsPath::setStartX(qreal x) +{ + Q_D(QmlGraphicsPath); + d->startX = x; +} + +qreal QmlGraphicsPath::startY() const +{ + Q_D(const QmlGraphicsPath); + return d->startY; +} + +void QmlGraphicsPath::setStartY(qreal y) +{ + Q_D(QmlGraphicsPath); + d->startY = y; +} + +/*! + \qmlproperty list Path::pathElements + This property holds the objects composing the path. + + \default + + A path can contain the following path objects: + \list + \i \l PathLine - a straight line to a given position. + \i \l PathQuad - a quadratic Bezier curve to a given position with a control point. + \i \l PathCubic - a cubic Bezier curve to a given position with two control points. + \i \l PathAttribute - an attribute at a given position in the path. + \i \l PathPercent - a way to spread out items along various segments of the path. + \endlist + + \snippet doc/src/snippets/declarative/pathview/pathattributes.qml 2 +*/ + +QList* QmlGraphicsPath::pathElements() +{ + Q_D(QmlGraphicsPath); + return &(d->_pathElements); +} + +void QmlGraphicsPath::interpolate(int idx, const QString &name, qreal value) +{ + Q_D(QmlGraphicsPath); + if (!idx) + return; + + qreal lastValue = 0; + qreal lastPercent = 0; + int search = idx - 1; + while(search >= 0) { + const AttributePoint &point = d->_attributePoints.at(search); + if (point.values.contains(name)) { + lastValue = point.values.value(name); + lastPercent = point.origpercent; + break; + } + --search; + } + + ++search; + + const AttributePoint &curPoint = d->_attributePoints.at(idx); + + for (int ii = search; ii < idx; ++ii) { + AttributePoint &point = d->_attributePoints[ii]; + + qreal val = lastValue + (value - lastValue) * (point.origpercent - lastPercent) / (curPoint.origpercent - lastPercent); + point.values.insert(name, val); + } +} + +void QmlGraphicsPath::endpoint(const QString &name) +{ + Q_D(QmlGraphicsPath); + const AttributePoint &first = d->_attributePoints.first(); + qreal val = first.values.value(name); + for (int ii = d->_attributePoints.count() - 1; ii >= 0; ii--) { + const AttributePoint &point = d->_attributePoints.at(ii); + if (point.values.contains(name)) { + for (int jj = ii + 1; jj < d->_attributePoints.count(); ++jj) { + AttributePoint &setPoint = d->_attributePoints[jj]; + setPoint.values.insert(name, val); + } + return; + } + } +} + +void QmlGraphicsPath::processPath() +{ + Q_D(QmlGraphicsPath); + + d->_pointCache.clear(); + d->_attributePoints.clear(); + d->_path = QPainterPath(); + + AttributePoint first; + for (int ii = 0; ii < d->_attributes.count(); ++ii) + first.values[d->_attributes.at(ii)] = 0; + d->_attributePoints << first; + + d->_path.moveTo(d->startX, d->startY); + + foreach (QmlGraphicsPathElement *pathElement, d->_pathElements) { + if (QmlGraphicsCurve *curve = qobject_cast(pathElement)) { + curve->addToPath(d->_path); + AttributePoint p; + p.origpercent = d->_path.length(); + d->_attributePoints << p; + } else if (QmlGraphicsPathAttribute *attribute = qobject_cast(pathElement)) { + AttributePoint &point = d->_attributePoints.last(); + point.values[attribute->name()] = attribute->value(); + interpolate(d->_attributePoints.count() - 1, attribute->name(), attribute->value()); + } else if (QmlGraphicsPathPercent *percent = qobject_cast(pathElement)) { + AttributePoint &point = d->_attributePoints.last(); + point.values[QLatin1String("_qfx_percent")] = percent->value(); + interpolate(d->_attributePoints.count() - 1, QLatin1String("_qfx_percent"), percent->value()); + } + } + + // Fixup end points + const AttributePoint &last = d->_attributePoints.last(); + for (int ii = 0; ii < d->_attributes.count(); ++ii) { + if (!last.values.contains(d->_attributes.at(ii))) + endpoint(d->_attributes.at(ii)); + } + + // Adjust percent + qreal length = d->_path.length(); + qreal prevpercent = 0; + qreal prevorigpercent = 0; + for (int ii = 0; ii < d->_attributePoints.count(); ++ii) { + const AttributePoint &point = d->_attributePoints.at(ii); + if (point.values.contains(QLatin1String("_qfx_percent"))) { //special string for QmlGraphicsPathPercent + if ( ii > 0) { + qreal scale = (d->_attributePoints[ii].origpercent/length - prevorigpercent) / + (point.values.value(QLatin1String("_qfx_percent"))-prevpercent); + d->_attributePoints[ii].scale = scale; + } + d->_attributePoints[ii].origpercent /= length; + d->_attributePoints[ii].percent = point.values.value(QLatin1String("_qfx_percent")); + prevorigpercent = d->_attributePoints[ii].origpercent; + prevpercent = d->_attributePoints[ii].percent; + } else { + d->_attributePoints[ii].origpercent /= length; + d->_attributePoints[ii].percent = d->_attributePoints[ii].origpercent; + } + } + + emit changed(); +} + +void QmlGraphicsPath::componentComplete() +{ + Q_D(QmlGraphicsPath); + QSet attrs; + // First gather up all the attributes + foreach (QmlGraphicsPathElement *pathElement, d->_pathElements) { + if (QmlGraphicsPathAttribute *attribute = + qobject_cast(pathElement)) + attrs.insert(attribute->name()); + } + d->_attributes = attrs.toList(); + + processPath(); + + foreach (QmlGraphicsPathElement *pathElement, d->_pathElements) + connect(pathElement, SIGNAL(changed()), this, SLOT(processPath())); +} + +QPainterPath QmlGraphicsPath::path() const +{ + Q_D(const QmlGraphicsPath); + return d->_path; +} + +QStringList QmlGraphicsPath::attributes() const +{ + Q_D(const QmlGraphicsPath); + return d->_attributes; +} +#include + +static inline QBezier nextBezier(const QPainterPath &path, int *from, qreal *bezLength) +{ + const int lastElement = path.elementCount() - 1; + for (int i=*from; i <= lastElement; ++i) { + const QPainterPath::Element &e = path.elementAt(i); + + switch (e.type) { + case QPainterPath::MoveToElement: + break; + case QPainterPath::LineToElement: + { + QLineF line(path.elementAt(i-1), e); + *bezLength = line.length(); + QPointF a = path.elementAt(i-1); + QPointF delta = e - a; + *from = i+1; + return QBezier::fromPoints(a, a + delta / 3, a + 2 * delta / 3, e); + } + case QPainterPath::CurveToElement: + { + QBezier b = QBezier::fromPoints(path.elementAt(i-1), + e, + path.elementAt(i+1), + path.elementAt(i+2)); + *bezLength = b.length(); + *from = i+3; + return b; + } + default: + break; + } + } + *from = lastElement; + *bezLength = 0; + return QBezier(); +} + +void QmlGraphicsPath::createPointCache() const +{ + Q_D(const QmlGraphicsPath); +#ifdef Q_ENABLE_PERFORMANCE_LOG + QmlPerfTimer pc; +#endif + qreal pathLength = d->_path.length(); + const int points = int(pathLength*2); + const int lastElement = d->_path.elementCount() - 1; + d->_pointCache.resize(points+1); + + int currElement = 0; + qreal bezLength = 0; + QBezier currBez = nextBezier(d->_path, &currElement, &bezLength); + qreal currLength = bezLength; + qreal epc = currLength / pathLength; + + for (int i = 0; i < d->_pointCache.size(); i++) { + //find which set we are in + qreal prevPercent = 0; + qreal prevOrigPercent = 0; + for (int ii = 0; ii < d->_attributePoints.count(); ++ii) { + qreal percent = qreal(i)/points; + const AttributePoint &point = d->_attributePoints.at(ii); + if (percent < point.percent || ii == d->_attributePoints.count() - 1) { //### || is special case for very last item + qreal elementPercent = (percent - prevPercent); + + qreal spc = prevOrigPercent + elementPercent * point.scale; + + while (spc > epc) { + if (currElement > lastElement) + break; + currBez = nextBezier(d->_path, &currElement, &bezLength); + if (bezLength == 0.0) { + currLength = pathLength; + epc = 1.0; + break; + } + currLength += bezLength; + epc = currLength / pathLength; + } + qreal realT = (pathLength * spc - (currLength - bezLength)) / bezLength; + d->_pointCache[i] = currBez.pointAt(qBound(qreal(0), realT, qreal(1))); + break; + } + prevOrigPercent = point.origpercent; + prevPercent = point.percent; + } + } +} + +QPointF QmlGraphicsPath::pointAt(qreal p) const +{ + Q_D(const QmlGraphicsPath); + if (d->_pointCache.isEmpty()) { + createPointCache(); + } + int idx = qRound(p*d->_pointCache.size()); + if (idx >= d->_pointCache.size()) + idx = d->_pointCache.size() - 1; + else if (idx < 0) + idx = 0; + return d->_pointCache.at(idx); +} + +qreal QmlGraphicsPath::attributeAt(const QString &name, qreal percent) const +{ + Q_D(const QmlGraphicsPath); + if (percent < 0 || percent > 1) + return 0; + + for (int ii = 0; ii < d->_attributePoints.count(); ++ii) { + const AttributePoint &point = d->_attributePoints.at(ii); + + if (point.percent == percent) { + return point.values.value(name); + } else if (point.percent > percent) { + qreal lastValue = + ii?(d->_attributePoints.at(ii - 1).values.value(name)):0; + qreal lastPercent = + ii?(d->_attributePoints.at(ii - 1).percent):0; + qreal curValue = point.values.value(name); + qreal curPercent = point.percent; + + return lastValue + (curValue - lastValue) * (percent - lastPercent) / (curPercent - lastPercent); + } + } + + return 0; +} + +/****************************************************************************/ + +qreal QmlGraphicsCurve::x() const +{ + return _x; +} + +void QmlGraphicsCurve::setX(qreal x) +{ + if (_x != x) { + _x = x; + emit changed(); + } +} + +qreal QmlGraphicsCurve::y() const +{ + return _y; +} + +void QmlGraphicsCurve::setY(qreal y) +{ + if (_y != y) { + _y = y; + emit changed(); + } +} + +/****************************************************************************/ + +/*! + \qmlclass PathAttribute + \brief The PathAttribute allows setting an attribute at a given position in a Path. + + The PathAttribute object allows attibutes consisting of a name and + a value to be specified for the endpoints of path segments. The + attributes are exposed to the delegate as + \l{qmlintroduction.html#attached-properties} {Attached Properties}. + The value of an attribute at any particular point is interpolated + from the PathAttributes bounding the point. + + The example below shows a path with the items scaled to 30% with + opacity 50% at the top of the path and scaled 100% with opacity + 100% at the bottom. Note the use of the PathView.scale and + PathView.opacity attached properties to set the scale and opacity + of the delegate. + + \table + \row + \o \image declarative-pathattribute.png + \o + \snippet doc/src/snippets/declarative/pathview/pathattributes.qml 0 + \endtable + + \sa Path +*/ + +/*! + \internal + \class QmlGraphicsPathAttribute + \ingroup group_utility + \brief The QmlGraphicsPathAttribute class allows to set the value of an attribute at a given position in the path. + + \sa QmlGraphicsPath +*/ + + +/*! + \qmlproperty string PathAttribute::name + the name of the attribute to change. +*/ + +/*! + the name of the attribute to change. +*/ + +QString QmlGraphicsPathAttribute::name() const +{ + return _name; +} + +void QmlGraphicsPathAttribute::setName(const QString &name) +{ + _name = name; +} + +/*! + \qmlproperty string PathAttribute::value + the new value of the attribute. +*/ + +/*! + the new value of the attribute. +*/ +qreal QmlGraphicsPathAttribute::value() const +{ + return _value; +} + +void QmlGraphicsPathAttribute::setValue(qreal value) +{ + if (_value != value) { + _value = value; + emit changed(); + } +} + +/****************************************************************************/ + +/*! + \qmlclass PathLine + \brief The PathLine defines a straight line. + + The example below creates a path consisting of a straight line from + 0,100 to 200,100: + + \qml + Path { + startX: 0; startY: 100 + PathLine { x: 200; y: 100 } + } + \endqml + + \sa Path, PathQuad, PathCubic +*/ + +/*! + \internal + \class QmlGraphicsPathLine + \ingroup group_utility + \brief The QmlGraphicsPathLine class defines a straight line. + + \sa QmlGraphicsPath +*/ + +/*! + \qmlproperty real PathLine::x + \qmlproperty real PathLine::y + + Defines the end point of the line. +*/ + +void QmlGraphicsPathLine::addToPath(QPainterPath &path) +{ + path.lineTo(x(), y()); +} + +/****************************************************************************/ + +/*! + \qmlclass PathQuad + \brief The PathQuad defines a quadratic Bezier curve with a control point. + + The following QML produces the path shown below: + \table + \row + \o \image declarative-pathquad.png + \o + \qml + Path { + startX: 0; startY: 0 + PathQuad x: 200; y: 0; controlX: 100; controlY: 150 } + } + \endqml + \endtable + + \sa Path, PathCubic, PathLine +*/ + +/*! + \internal + \class QmlGraphicsPathQuad + \ingroup group_utility + \brief The QmlGraphicsPathQuad class defines a quadratic Bezier curve with a control point. + + \sa QmlGraphicsPath +*/ + + +/*! + \qmlproperty real PathQuad::x + \qmlproperty real PathQuad::y + + Defines the end point of the curve. +*/ + +/*! + \qmlproperty real PathQuad::controlX + \qmlproperty real PathQuad::controlY + + Defines the position of the control point. +*/ + +/*! + the x position of the control point. +*/ +qreal QmlGraphicsPathQuad::controlX() const +{ + return _controlX; +} + +void QmlGraphicsPathQuad::setControlX(qreal x) +{ + if (_controlX != x) { + _controlX = x; + emit changed(); + } +} + + +/*! + the y position of the control point. +*/ +qreal QmlGraphicsPathQuad::controlY() const +{ + return _controlY; +} + +void QmlGraphicsPathQuad::setControlY(qreal y) +{ + if (_controlY != y) { + _controlY = y; + emit changed(); + } +} + +void QmlGraphicsPathQuad::addToPath(QPainterPath &path) +{ + path.quadTo(controlX(), controlY(), x(), y()); +} + +/****************************************************************************/ + +/*! + \qmlclass PathCubic + \brief The PathCubic defines a cubic Bezier curve with two control points. + + The following QML produces the path shown below: + \table + \row + \o \image declarative-pathcubic.png + \o + \qml + Path { + startX: 20; startY: 0 + PathCubic { + x: 180; y: 0; control1X: -10; control1Y: 90 + control2X: 210; control2Y: 90 + } + } + \endqml + \endtable + + \sa Path, PathQuad, PathLine +*/ + +/*! + \internal + \class QmlGraphicsPathCubic + \ingroup group_utility + \brief The QmlGraphicsPathCubic class defines a cubic Bezier curve with two control points. + + \sa QmlGraphicsPath +*/ + +/*! + \qmlproperty real PathCubic::x + \qmlproperty real PathCubic::y + + Defines the end point of the curve. +*/ + +/*! + \qmlproperty real PathCubic::control1X + \qmlproperty real PathCubic::control1Y + + Defines the position of the first control point. +*/ +qreal QmlGraphicsPathCubic::control1X() const +{ + return _control1X; +} + +void QmlGraphicsPathCubic::setControl1X(qreal x) +{ + if (_control1X != x) { + _control1X = x; + emit changed(); + } +} + +qreal QmlGraphicsPathCubic::control1Y() const +{ + return _control1Y; +} + +void QmlGraphicsPathCubic::setControl1Y(qreal y) +{ + if (_control1Y != y) { + _control1Y = y; + emit changed(); + } +} + +/*! + \qmlproperty real PathCubic::control2X + \qmlproperty real PathCubic::control2Y + + Defines the position of the second control point. +*/ +qreal QmlGraphicsPathCubic::control2X() const +{ + return _control2X; +} + +void QmlGraphicsPathCubic::setControl2X(qreal x) +{ + if (_control2X != x) { + _control2X = x; + emit changed(); + } +} + +qreal QmlGraphicsPathCubic::control2Y() const +{ + return _control2Y; +} + +void QmlGraphicsPathCubic::setControl2Y(qreal y) +{ + if (_control2Y != y) { + _control2Y = y; + emit changed(); + } +} + +void QmlGraphicsPathCubic::addToPath(QPainterPath &path) +{ + path.cubicTo(control1X(), control1Y(), control2X(), control2Y(), x(), y()); +} + +/****************************************************************************/ + +/*! + \qmlclass PathPercent + \brief The PathPercent manipulates the way a path is interpreted. + + The examples below show the normal distrubution of items along a path + compared to a distribution which places 50% of the items along the + PathLine section of the path. + \table + \row + \o \image declarative-nopercent.png + \o + \qml + Path { + startX: 20; startY: 0 + PathQuad { x: 50; y: 80; controlX: 0; controlY: 80 } + PathLine { x: 150; y: 80 } + PathQuad { x: 180; y: 0; controlX: 200; controlY: 80 } + } + \endqml + \row + \o \image declarative-percent.png + \o + \qml + Path { + startX: 20; startY: 0 + PathQuad { x: 50; y: 80; controlX: 0; controlY: 80 } + PathPercent { value: 0.25 } + PathLine { x: 150; y: 80 } + PathPercent { value: 0.75 } + PathQuad { x: 180; y: 0; controlX: 200; controlY: 80 } + PathPercent { value: 1 } + } + \endqml + \endtable + + \sa Path +*/ + +/*! + \internal + \class QmlGraphicsPathPercent + \ingroup group_utility + \brief The QmlGraphicsPathPercent class manipulates the way a path is interpreted. + + QmlGraphicsPathPercent allows you to bunch up items (or spread out items) along various + segments of a QmlGraphicsPathView's path. + + \sa QmlGraphicsPath + +*/ + +qreal QmlGraphicsPathPercent::value() const +{ + return _value; +} + +void QmlGraphicsPathPercent::setValue(qreal value) +{ + _value = value; +} +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicspath.h b/src/declarative/fx/qmlgraphicspath.h new file mode 100644 index 0000000..db6c84f --- /dev/null +++ b/src/declarative/fx/qmlgraphicspath.h @@ -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$ +** +****************************************************************************/ + +#ifndef QMLGRAPHICSPATH_H +#define QMLGRAPHICSPATH_H + +#include +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class Q_DECLARATIVE_EXPORT QmlGraphicsPathElement : public QObject +{ + Q_OBJECT +public: + QmlGraphicsPathElement(QObject *parent=0) : QObject(parent) {} +Q_SIGNALS: + void changed(); +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsPathAttribute : public QmlGraphicsPathElement +{ + Q_OBJECT + + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) +public: + QmlGraphicsPathAttribute(QObject *parent=0) : QmlGraphicsPathElement(parent), _value(0) {} + + + QString name() const; + void setName(const QString &name); + + qreal value() const; + void setValue(qreal value); + +private: + QString _name; + qreal _value; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsCurve : public QmlGraphicsPathElement +{ + Q_OBJECT + + Q_PROPERTY(qreal x READ x WRITE setX NOTIFY changed) + Q_PROPERTY(qreal y READ y WRITE setY NOTIFY changed) +public: + QmlGraphicsCurve(QObject *parent=0) : QmlGraphicsPathElement(parent), _x(0), _y(0) {} + + qreal x() const; + void setX(qreal x); + + qreal y() const; + void setY(qreal y); + + virtual void addToPath(QPainterPath &) {} + +private: + qreal _x; + qreal _y; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsPathLine : public QmlGraphicsCurve +{ + Q_OBJECT +public: + QmlGraphicsPathLine(QObject *parent=0) : QmlGraphicsCurve(parent) {} + + void addToPath(QPainterPath &path); +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsPathQuad : public QmlGraphicsCurve +{ + Q_OBJECT + + Q_PROPERTY(qreal controlX READ controlX WRITE setControlX NOTIFY changed) + Q_PROPERTY(qreal controlY READ controlY WRITE setControlY NOTIFY changed) +public: + QmlGraphicsPathQuad(QObject *parent=0) : QmlGraphicsCurve(parent), _controlX(0), _controlY(0) {} + + qreal controlX() const; + void setControlX(qreal x); + + qreal controlY() const; + void setControlY(qreal y); + + void addToPath(QPainterPath &path); + +private: + qreal _controlX; + qreal _controlY; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsPathCubic : public QmlGraphicsCurve +{ + Q_OBJECT + + Q_PROPERTY(qreal control1X READ control1X WRITE setControl1X NOTIFY changed) + Q_PROPERTY(qreal control1Y READ control1Y WRITE setControl1Y NOTIFY changed) + Q_PROPERTY(qreal control2X READ control2X WRITE setControl2X NOTIFY changed) + Q_PROPERTY(qreal control2Y READ control2Y WRITE setControl2Y NOTIFY changed) +public: + QmlGraphicsPathCubic(QObject *parent=0) : QmlGraphicsCurve(parent), _control1X(0), _control1Y(0), _control2X(0), _control2Y(0) {} + + qreal control1X() const; + void setControl1X(qreal x); + + qreal control1Y() const; + void setControl1Y(qreal y); + + qreal control2X() const; + void setControl2X(qreal x); + + qreal control2Y() const; + void setControl2Y(qreal y); + + void addToPath(QPainterPath &path); + +private: + int _control1X; + int _control1Y; + int _control2X; + int _control2Y; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsPathPercent : public QmlGraphicsPathElement +{ + Q_OBJECT + Q_PROPERTY(qreal value READ value WRITE setValue) +public: + QmlGraphicsPathPercent(QObject *parent=0) : QmlGraphicsPathElement(parent) {} + + qreal value() const; + void setValue(qreal value); + +private: + qreal _value; +}; + +class QmlGraphicsPathPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsPath : public QObject, public QmlParserStatus +{ + Q_OBJECT + + Q_INTERFACES(QmlParserStatus) + Q_PROPERTY(QList* pathElements READ pathElements) + Q_PROPERTY(qreal startX READ startX WRITE setStartX) + Q_PROPERTY(qreal startY READ startY WRITE setStartY) + Q_CLASSINFO("DefaultProperty", "pathElements") + Q_INTERFACES(QmlParserStatus) +public: + QmlGraphicsPath(QObject *parent=0); + ~QmlGraphicsPath(); + + QList* pathElements(); + + qreal startX() const; + void setStartX(qreal x); + + qreal startY() const; + void setStartY(qreal y); + + QPainterPath path() const; + QStringList attributes() const; + qreal attributeAt(const QString &, qreal) const; + QPointF pointAt(qreal) const; + +Q_SIGNALS: + void changed(); + +protected: + virtual void componentComplete(); + QmlGraphicsPath(QmlGraphicsPathPrivate &dd, QObject *parent); + +private Q_SLOTS: + void processPath(); + +private: + struct AttributePoint { + AttributePoint() : percent(0), scale(1), origpercent(0) {} + AttributePoint(const AttributePoint &other) + : percent(other.percent), scale(other.scale), origpercent(other.origpercent), values(other.values) {} + AttributePoint &operator=(const AttributePoint &other) { + percent = other.percent; scale = other.scale; origpercent = other.origpercent; values = other.values; return *this; + } + qreal percent; //massaged percent along the painter path + qreal scale; + qreal origpercent; //'real' percent along the painter path + QHash values; + }; + + void interpolate(int idx, const QString &name, qreal value); + void endpoint(const QString &name); + void createPointCache() const; + +private: + Q_DISABLE_COPY(QmlGraphicsPath) + Q_DECLARE_PRIVATE(QmlGraphicsPath) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsPathElement) +QML_DECLARE_TYPE(QmlGraphicsPathAttribute) +QML_DECLARE_TYPE(QmlGraphicsCurve) +QML_DECLARE_TYPE(QmlGraphicsPathLine) +QML_DECLARE_TYPE(QmlGraphicsPathQuad) +QML_DECLARE_TYPE(QmlGraphicsPathCubic) +QML_DECLARE_TYPE(QmlGraphicsPathPercent) +QML_DECLARE_TYPE(QmlGraphicsPath) + +QT_END_HEADER + +#endif // QMLGRAPHICSPATH_H diff --git a/src/declarative/fx/qmlgraphicspath_p.h b/src/declarative/fx/qmlgraphicspath_p.h new file mode 100644 index 0000000..7c0e1ea --- /dev/null +++ b/src/declarative/fx/qmlgraphicspath_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSPATH_P_H +#define QMLGRAPHICSPATH_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/qobject_p.h" +#include "qmlgraphicspath.h" +#include "qml.h" + + +QT_BEGIN_NAMESPACE +class QmlGraphicsPathPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsPath) + +public: + QmlGraphicsPathPrivate() : startX(0), startY(0) { } + + QPainterPath _path; + QList _pathElements; + mutable QVector _pointCache; + QList _attributePoints; + QStringList _attributes; + int startX; + int startY; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/declarative/fx/qmlgraphicspathview.cpp b/src/declarative/fx/qmlgraphicspathview.cpp new file mode 100644 index 0000000..48d9fc8 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspathview.cpp @@ -0,0 +1,913 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include "qmlstate.h" +#include "qlistmodelinterface.h" +#include "qmlopenmetaobject.h" + +#include "qmlgraphicspathview.h" +#include "qmlgraphicspathview_p.h" +#include + +static const int FlickThreshold = 5; + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,PathView,QmlGraphicsPathView) + +class QmlGraphicsPathViewAttached : public QObject +{ + Q_OBJECT +public: + QmlGraphicsPathViewAttached(QObject *parent) + : QObject(parent), mo(new QmlOpenMetaObject(this)) + { + } + + ~QmlGraphicsPathViewAttached() + { + QmlGraphicsPathView::attachedProperties.remove(parent()); + } + + QVariant value(const QByteArray &name) const + { + return mo->value(name); + } + void setValue(const QByteArray &name, const QVariant &val) + { + mo->setValue(name, val); + } + +private: + QmlOpenMetaObject *mo; +}; + + +/*! + \internal + \class QmlGraphicsPathView + \brief The QmlGraphicsPathView class lays out items provided by a model on a path. + + \ingroup group_views + + The model must be a \l QListModelInterface subclass. + + \sa QmlGraphicsPath +*/ + +/*! + \qmlclass PathView + \brief The PathView element lays out model-provided items on a path. + \inherits Item + + The model is typically provided by a QAbstractListModel "C++ model object", but can also be created directly in QML. + + The items are laid out along a path defined by a \l Path and may be flicked to scroll. + + \snippet doc/src/snippets/declarative/pathview/pathview.qml 0 + + \image pathview.gif + + \sa Path +*/ + +QmlGraphicsPathView::QmlGraphicsPathView(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsPathViewPrivate), parent) +{ + Q_D(QmlGraphicsPathView); + d->init(); +} + +QmlGraphicsPathView::QmlGraphicsPathView(QmlGraphicsPathViewPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ + Q_D(QmlGraphicsPathView); + d->init(); +} + +QmlGraphicsPathView::~QmlGraphicsPathView() +{ + Q_D(QmlGraphicsPathView); + if (d->ownModel) + delete d->model; +} + +/*! + \qmlproperty model PathView::model + This property holds the model providing data for the view. + + The model provides a set of data that is used to create the items for the view. + For large or dynamic datasets the model is usually provided by a C++ model object. + Models can also be created directly in XML, using the ListModel element. + + \sa {qmlmodels}{Data Models} +*/ +QVariant QmlGraphicsPathView::model() const +{ + Q_D(const QmlGraphicsPathView); + return d->modelVariant; +} + +void QmlGraphicsPathView::setModel(const QVariant &model) +{ + Q_D(QmlGraphicsPathView); + if (d->model) { + disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); + disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + disconnect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + for (int i=0; iitems.count(); i++){ + QmlGraphicsItem *p = d->items[i]; + d->model->release(p); + } + d->items.clear(); + } + + d->modelVariant = model; + QObject *object = qvariant_cast(model); + QmlGraphicsVisualModel *vim = 0; + if (object && (vim = qobject_cast(object))) { + if (d->ownModel) { + delete d->model; + d->ownModel = false; + } + d->model = vim; + } else { + if (!d->ownModel) { + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); + d->ownModel = true; + } + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) + dataModel->setModel(model); + } + if (d->model) { + connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); + connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + } + d->firstIndex = 0; + d->pathOffset = 0; + d->regenerate(); + d->fixOffset(); +} + +/*! + \qmlproperty int PathView::count + This property holds the number of items in the model. +*/ +int QmlGraphicsPathView::count() const +{ + Q_D(const QmlGraphicsPathView); + return d->model ? d->model->count() : 0; +} + +/*! + \qmlproperty Path PathView::path + \default + This property holds the path used to lay out the items. + For more information see the \l Path documentation. +*/ +QmlGraphicsPath *QmlGraphicsPathView::path() const +{ + Q_D(const QmlGraphicsPathView); + return d->path; +} + +void QmlGraphicsPathView::setPath(QmlGraphicsPath *path) +{ + Q_D(QmlGraphicsPathView); + d->path = path; + connect(d->path, SIGNAL(changed()), this, SLOT(refill())); + d->regenerate(); +} + +/*! + \qmlproperty int PathView::currentIndex + This property holds the index of the current item. +*/ +int QmlGraphicsPathView::currentIndex() const +{ + Q_D(const QmlGraphicsPathView); + return d->currentIndex; +} + +void QmlGraphicsPathView::setCurrentIndex(int idx) +{ + Q_D(QmlGraphicsPathView); + if (d->model && d->model->count()) + idx = qAbs(idx % d->model->count()); + if (d->model && idx != d->currentIndex) { + d->currentIndex = idx; + if (d->model->count()) { + d->snapToCurrent(); + int itemIndex = (idx - d->firstIndex + d->model->count()) % d->model->count(); + if (itemIndex < d->items.count()) + d->items.at(itemIndex)->setFocus(true); + } + emit currentIndexChanged(); + } +} + +/*! + \qmlproperty real PathView::offset + + The offset specifies how far along the path the items are from their initial positions. +*/ +qreal QmlGraphicsPathView::offset() const +{ + Q_D(const QmlGraphicsPathView); + return d->_offset; +} + +void QmlGraphicsPathView::setOffset(qreal offset) +{ + Q_D(QmlGraphicsPathView); + d->setOffset(offset); + d->updateCurrent(); +} + +void QmlGraphicsPathViewPrivate::setOffset(qreal o) +{ + Q_Q(QmlGraphicsPathView); + if (_offset != o) { + _offset = fmod(o, 100.0); + if (_offset < 0) + _offset = 100.0 + _offset; + q->refill(); + } +} + +/*! + \qmlproperty real PathView::snapPosition + + This property determines the position (0-100) the nearest item will snap to. +*/ +qreal QmlGraphicsPathView::snapPosition() const +{ + Q_D(const QmlGraphicsPathView); + return d->snapPos; +} + +void QmlGraphicsPathView::setSnapPosition(qreal pos) +{ + Q_D(QmlGraphicsPathView); + d->snapPos = pos/100; + d->fixOffset(); +} + +/*! + \qmlproperty real PathView::dragMargin + This property holds the maximum distance from the path that initiate mouse dragging. + + By default the path can only be dragged by clicking on an item. If + dragMargin is greater than zero, a drag can be initiated by clicking + within dragMargin pixels of the path. +*/ +qreal QmlGraphicsPathView::dragMargin() const +{ + Q_D(const QmlGraphicsPathView); + return d->dragMargin; +} + +void QmlGraphicsPathView::setDragMargin(qreal dragMargin) +{ + Q_D(QmlGraphicsPathView); + d->dragMargin = dragMargin; +} + +/*! + \qmlproperty component PathView::delegate + + The delegate provides a template describing what each item in the view should look and act like. + + Here is an example delegate: + \snippet doc/src/snippets/declarative/pathview/pathview.qml 1 +*/ +QmlComponent *QmlGraphicsPathView::delegate() const +{ + Q_D(const QmlGraphicsPathView); + if (d->model) { + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) + return dataModel->delegate(); + } + + return 0; +} + +void QmlGraphicsPathView::setDelegate(QmlComponent *c) +{ + Q_D(QmlGraphicsPathView); + if (!d->ownModel) { + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); + d->ownModel = true; + } + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) { + dataModel->setDelegate(c); + d->regenerate(); + } +} + +/*! + \qmlproperty int PathView::pathItemCount + This property holds the number of items visible on the path at any one time +*/ +int QmlGraphicsPathView::pathItemCount() const +{ + Q_D(const QmlGraphicsPathView); + return d->pathItems; +} + +void QmlGraphicsPathView::setPathItemCount(int i) +{ + Q_D(QmlGraphicsPathView); + if (i == d->pathItems) + return; + d->pathItems = i; + d->regenerate(); +} + +QPointF QmlGraphicsPathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const +{ + //XXX maybe do recursively at increasing resolution. + qreal mindist = 1e10; // big number + QPointF nearPoint = path->pointAt(0); + qreal nearPc = 0; + for (qreal i=1; i < 1000; i++) { + QPointF pt = path->pointAt(i/1000.0); + QPointF diff = pt - point; + qreal dist = diff.x()*diff.x() + diff.y()*diff.y(); + if (dist < mindist) { + nearPoint = pt; + nearPc = i; + mindist = dist; + } + } + + if (nearPercent) + *nearPercent = nearPc / 10.0; + + return nearPoint; +} + + +void QmlGraphicsPathView::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsPathView); + if (!d->items.count()) + return; + QPointF scenePoint = mapToScene(event->pos()); + int idx = 0; + for (; idx < d->items.count(); ++idx) { + QRectF rect = d->items.at(idx)->boundingRect(); + rect = d->items.at(idx)->mapToScene(rect).boundingRect(); + if (rect.contains(scenePoint)) + break; + } + if (idx == d->items.count() && d->dragMargin == 0.) // didn't click on an item + return; + + d->startPoint = d->pointNear(event->pos(), &d->startPc); + if (idx == d->items.count()) { + qreal distance = qAbs(event->pos().x() - d->startPoint.x()) + qAbs(event->pos().y() - d->startPoint.y()); + if (distance > d->dragMargin) + return; + } + + d->stealMouse = false; + d->lastElapsed = 0; + d->lastDist = 0; + QmlGraphicsItemPrivate::start(d->lastPosTime); + d->tl.clear(); +} + +void QmlGraphicsPathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsPathView); + if (d->lastPosTime.isNull()) + return; + + if (!d->stealMouse) { + QPointF delta = event->pos() - d->startPoint; + if (qAbs(delta.x()) > FlickThreshold && qAbs(delta.y()) > FlickThreshold) + d->stealMouse = true; + } + + if (d->stealMouse) { + d->moveReason = QmlGraphicsPathViewPrivate::Mouse; + qreal newPc; + d->pointNear(event->pos(), &newPc); + qreal diff = newPc - d->startPc; + if (diff) { + setOffset(d->_offset + diff); + + if (diff > 50) + diff -= 100; + else if (diff < -50) + diff += 100; + + d->lastElapsed = QmlGraphicsItemPrivate::restart(d->lastPosTime); + d->lastDist = diff; + d->startPc = newPc; + } + } +} + +void QmlGraphicsPathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) +{ + Q_D(QmlGraphicsPathView); + if (d->lastPosTime.isNull()) + return; + + qreal elapsed = qreal(d->lastElapsed + QmlGraphicsItemPrivate::elapsed(d->lastPosTime)) / 1000.; + qreal velocity = elapsed > 0. ? d->lastDist / elapsed : 0; + if (d->model && d->model->count() && qAbs(velocity) > 5) { + if (velocity > 100) + velocity = 100; + else if (velocity < -100) + velocity = -100; + qreal inc = fmod(d->_offset - d->snapPos, 100.0 / d->model->count()); + qreal dist = qAbs(velocity/2 - fmod(velocity/2, 100.0 / d->model->count()) - inc); + d->moveOffset.setValue(d->_offset); + d->tl.accel(d->moveOffset, velocity, 10, dist); + d->tl.execute(d->fixupOffsetEvent); + } else { + d->fixOffset(); + } + + d->lastPosTime = QTime(); + d->stealMouse = false; + ungrabMouse(); +} + +bool QmlGraphicsPathView::sendMouseEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsPathView); + QGraphicsSceneMouseEvent mouseEvent(event->type()); + QRectF myRect = mapToScene(QRectF(0, 0, width(), height())).boundingRect(); + QGraphicsScene *s = scene(); + QmlGraphicsItem *grabber = s ? qobject_cast(s->mouseGrabberItem()) : 0; + if ((d->stealMouse || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) { + mouseEvent.setAccepted(false); + for (int i = 0x1; i <= 0x10; i <<= 1) { + if (event->buttons() & i) { + Qt::MouseButton button = Qt::MouseButton(i); + mouseEvent.setButtonDownPos(button, mapFromScene(event->buttonDownPos(button))); + } + } + mouseEvent.setScenePos(event->scenePos()); + mouseEvent.setLastScenePos(event->lastScenePos()); + mouseEvent.setPos(mapFromScene(event->scenePos())); + mouseEvent.setLastPos(mapFromScene(event->lastScenePos())); + + switch(mouseEvent.type()) { + case QEvent::GraphicsSceneMouseMove: + mouseMoveEvent(&mouseEvent); + break; + case QEvent::GraphicsSceneMousePress: + mousePressEvent(&mouseEvent); + break; + case QEvent::GraphicsSceneMouseRelease: + mouseReleaseEvent(&mouseEvent); + break; + default: + break; + } + grabber = qobject_cast(s->mouseGrabberItem()); + if (grabber && d->stealMouse && !grabber->keepMouseGrab() && grabber != this) + grabMouse(); + + return d->stealMouse; + } else if (!d->lastPosTime.isNull()) { + d->lastPosTime = QTime(); + } + return false; +} + +bool QmlGraphicsPathView::sceneEventFilter(QGraphicsItem *i, QEvent *e) +{ + if (!isVisible()) + return QmlGraphicsItem::sceneEventFilter(i, e); + + switch (e->type()) { + case QEvent::GraphicsSceneMousePress: + case QEvent::GraphicsSceneMouseMove: + case QEvent::GraphicsSceneMouseRelease: + { + bool ret = sendMouseEvent(static_cast(e)); + if (e->type() == QEvent::GraphicsSceneMouseRelease) + return ret; + break; + } + default: + break; + } + + return QmlGraphicsItem::sceneEventFilter(i, e); +} + +void QmlGraphicsPathView::componentComplete() +{ + Q_D(QmlGraphicsPathView); + QmlGraphicsItem::componentComplete(); + d->regenerate(); + + // move to correct offset + if (d->items.count()) { + int itemIndex = (d->currentIndex - d->firstIndex + d->model->count()) % d->model->count(); + + itemIndex += d->pathOffset; + itemIndex %= d->items.count(); + qreal targetOffset = fmod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), 100); + + if (targetOffset < 0) + targetOffset = 100.0 + targetOffset; + if (targetOffset != d->_offset) { + d->moveOffset.setValue(targetOffset); + } + } +} + +void QmlGraphicsPathViewPrivate::regenerate() +{ + Q_Q(QmlGraphicsPathView); + if (!q->isComponentComplete()) + return; + + for (int i=0; i= model->count()) + firstIndex = model->count()-1; + if (pathOffset >= model->count()) + pathOffset = model->count()-1; + + int numItems = pathItems >= 0 ? pathItems : model->count(); + for (int i=0; i < numItems && i < model->count(); ++i){ + int index = (i + firstIndex) % model->count(); + QmlGraphicsItem *item = getItem(index); + if (!item) { + qWarning() << "PathView: Cannot create item, index" << (i + firstIndex) % model->count(); + return; + } + items.append(item); + item->setZValue(i); + if (currentIndex == index) + item->setFocus(true); + } + q->refill(); +} + +void QmlGraphicsPathViewPrivate::updateItem(QmlGraphicsItem *item, qreal percent) +{ + if (QObject *obj = QmlGraphicsPathView::qmlAttachedProperties(item)) { + foreach(const QString &attr, path->attributes()) + static_cast(obj)->setValue(attr.toUtf8(), path->attributeAt(attr, percent)); + } + QPointF pf = path->pointAt(percent); + item->setX(pf.x() - item->width()*item->scale()/2); + item->setY(pf.y() - item->height()*item->scale()/2); +} + +void QmlGraphicsPathView::refill() +{ + Q_D(QmlGraphicsPathView); + if (!d->isValid() || !isComponentComplete()) + return; + + QList positions; + for (int i=0; iitems.count(); i++){ + qreal percent = i * (100. / d->items.count()); + percent = percent + d->_offset; + percent = fmod(percent,100.); + positions << qAbs(percent/100.0); + } + + if (d->pathItems==-1) { + for (int i=0; iupdateItem(d->items.at(i), positions[i]); + return; + } + + QList rotatedPositions; + for (int i=0; iitems.count(); i++) + rotatedPositions << positions[(i + d->pathOffset + d->items.count()) % d->items.count()]; + + int wrapIndex= -1; + for (int i=0; iitems.count()-1; i++) { + if (rotatedPositions[i] > rotatedPositions[i+1]){ + wrapIndex = i; + break; + } + } + if (wrapIndex != -1 ){ + //A wraparound has occured + if (wrapIndex < d->items.count()/2){ + while(wrapIndex-- >= 0){ + QmlGraphicsItem* p = d->items.takeFirst(); + d->updateItem(p, 0.0); + d->releaseItem(p); + d->firstIndex++; + d->firstIndex %= d->model->count(); + int index = (d->firstIndex + d->items.count())%d->model->count(); + QmlGraphicsItem *item = d->getItem(index); + item->setZValue(wrapIndex); + if (d->currentIndex == index) + item->setFocus(true); + d->items << item; + d->pathOffset++; + d->pathOffset=d->pathOffset % d->items.count(); + } + } else { + while(wrapIndex++ < d->items.count()-1){ + QmlGraphicsItem* p = d->items.takeLast(); + d->updateItem(p, 1.0); + d->releaseItem(p); + d->firstIndex--; + if (d->firstIndex < 0) + d->firstIndex = d->model->count() - 1; + QmlGraphicsItem *item = d->getItem(d->firstIndex); + item->setZValue(d->firstIndex); + if (d->currentIndex == d->firstIndex) + item->setFocus(true); + d->items.prepend(item); + d->pathOffset--; + if (d->pathOffset < 0) + d->pathOffset = d->items.count() - 1; + } + } + for (int i=0; iitems.count(); i++) + rotatedPositions[i] = positions[(i + d->pathOffset + d->items.count()) + % d->items.count()]; + } + for (int i=0; iitems.count(); i++) + d->updateItem(d->items.at(i), rotatedPositions[i]); +} + +void QmlGraphicsPathView::itemsInserted(int modelIndex, int count) +{ + //XXX support animated insertion + Q_D(QmlGraphicsPathView); + if (!d->isValid() || !isComponentComplete()) + return; + if (d->pathItems == -1) { + for (int i = 0; i < count; ++i) { + QmlGraphicsItem *item = d->getItem(modelIndex + i); + item->setZValue(modelIndex + i); + d->items.insert(modelIndex + i, item); + } + refill(); + } else { + //XXX This is pretty heavy handed until we reference count items. + d->regenerate(); + } + + // make sure the current item is still at the snap position + int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count(); + itemIndex += d->pathOffset; + itemIndex %= d->items.count(); + qreal targetOffset = fmod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), 100); + + if (targetOffset < 0) + targetOffset = 100.0 + targetOffset; + if (targetOffset != d->_offset) + d->moveOffset.setValue(targetOffset); +} + +void QmlGraphicsPathView::itemsRemoved(int modelIndex, int count) +{ + //XXX support animated removal + Q_D(QmlGraphicsPathView); + if (!d->isValid() || !isComponentComplete()) + return; + if (d->pathItems == -1) { + for (int i = 0; i < count; ++i) { + QmlGraphicsItem* p = d->items.takeAt(modelIndex); + d->model->release(p); + } + d->snapToCurrent(); + refill(); + } else { + d->regenerate(); + } + + if (d->model->count() == 0) { + d->currentIndex = -1; + d->moveOffset.setValue(0); + return; + } + + // make sure the current item is still at the snap position + if (d->currentIndex >= d->model->count()) + d->currentIndex = d->model->count() - 1; + int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count(); + itemIndex += d->pathOffset; + itemIndex %= d->items.count(); + qreal targetOffset = fmod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), 100); + + if (targetOffset < 0) + targetOffset = 100.0 + targetOffset; + if (targetOffset != d->_offset) + d->moveOffset.setValue(targetOffset); +} + +void QmlGraphicsPathView::createdItem(int index, QmlGraphicsItem *item) +{ + Q_D(QmlGraphicsPathView); + if (d->requestedIndex != index) { + item->setParentItem(this); + d->updateItem(item, index < d->firstIndex ? 0.0 : 1.0); + } +} + +void QmlGraphicsPathView::destroyingItem(QmlGraphicsItem *item) +{ + Q_UNUSED(item); +} + +void QmlGraphicsPathView::ticked() +{ + Q_D(QmlGraphicsPathView); + d->updateCurrent(); +} + +// find the item closest to the snap position +int QmlGraphicsPathViewPrivate::calcCurrentIndex() +{ + int current = -1; + if (model && items.count()) { + _offset = fmod(_offset, 100.0); + if (_offset < 0) + _offset += 100.0; + + if (pathItems == -1) { + qreal delta = fmod(_offset - snapPos, 100.0); + if (delta < 0) + delta = 100.0 + delta; + int ii = model->count() - qRound(delta * model->count() / 100); + if (ii < 0) + ii = 0; + current = ii; + } else { + qreal bestDiff=1e9; + int bestI=-1; + for (int i=0; icount()); + } + + return current; +} + +void QmlGraphicsPathViewPrivate::updateCurrent() +{ + Q_Q(QmlGraphicsPathView); + if (moveReason != Mouse) + return; + int idx = calcCurrentIndex(); + if (model && idx != currentIndex) { + currentIndex = idx; + int itemIndex = (idx - firstIndex + model->count()) % model->count(); + if (itemIndex < items.count()) + items.at(itemIndex)->setFocus(true); + emit q->currentIndexChanged(); + } +} + +void QmlGraphicsPathViewPrivate::fixOffset() +{ + Q_Q(QmlGraphicsPathView); + if (model && items.count()) { + int curr = calcCurrentIndex(); + if (curr != currentIndex) + q->setCurrentIndex(curr); + else + snapToCurrent(); + } +} + +void QmlGraphicsPathViewPrivate::snapToCurrent() +{ + if (!model || model->count() <= 0) + return; + + int itemIndex = (currentIndex - firstIndex + model->count()) % model->count(); + + //Rounds is the number of times round to make the current item visible + int rounds = itemIndex / items.count(); + int otherWayRounds = (model->count() - (itemIndex)) / items.count() + 1; + if (otherWayRounds < rounds) + rounds = -otherWayRounds; + + itemIndex += pathOffset; + itemIndex %= items.count(); + qreal targetOffset = fmod(100 + (snapPos*100) - 100.0 * itemIndex / items.count(), 100); + + if (targetOffset < 0) + targetOffset = 100.0 + targetOffset; + if (targetOffset == _offset && rounds == 0) + return; + + moveReason = Other; + tl.clear(); + moveOffset.setValue(_offset); + + if (rounds!=0){ + //Compensate if the targetOffset would bring the target it from off the screen + qreal distance = targetOffset - _offset; + if (distance <= -50) + rounds--; + if (distance > 50) + rounds++; + tl.move(moveOffset, targetOffset + 100.0*(-rounds), QEasingCurve(QEasingCurve::InOutQuad), + int(100*items.count()*qMax((qreal)(2.0/items.count()),(qreal)qAbs(rounds)))); + tl.execute(fixupOffsetEvent); + return; + } + + if (targetOffset - _offset > 50.0) { + qreal distance = 100 - targetOffset + _offset; + tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * _offset / distance)); + tl.set(moveOffset, 100.0); + tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * (100-targetOffset) / distance)); + } else if (targetOffset - _offset <= -50.0) { + qreal distance = 100 - _offset + targetOffset; + tl.move(moveOffset, 100.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * (100-_offset) / distance)); + tl.set(moveOffset, 0.0); + tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * targetOffset / distance)); + } else { + tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), 200); + } +} + +QHash QmlGraphicsPathView::attachedProperties; +QObject *QmlGraphicsPathView::qmlAttachedProperties(QObject *obj) +{ + QObject *rv = attachedProperties.value(obj); + if (!rv) { + rv = new QmlGraphicsPathViewAttached(obj); + attachedProperties.insert(obj, rv); + } + return rv; +} + +QT_END_NAMESPACE + +#include "qfxpathview.moc" diff --git a/src/declarative/fx/qmlgraphicspathview.h b/src/declarative/fx/qmlgraphicspathview.h new file mode 100644 index 0000000..3bb5d1f --- /dev/null +++ b/src/declarative/fx/qmlgraphicspathview.h @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSPATHVIEW_H +#define QMLGRAPHICSPATHVIEW_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QListModelInterface; +class QmlGraphicsPathViewPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsPathView : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(QVariant model READ model WRITE setModel) + Q_PROPERTY(QmlGraphicsPath *path READ path WRITE setPath) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged) + Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition) + Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin) + Q_PROPERTY(int count READ count) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount) + +public: + QmlGraphicsPathView(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsPathView(); + + QVariant model() const; + void setModel(const QVariant &); + + QmlGraphicsPath *path() const; + void setPath(QmlGraphicsPath *); + + int currentIndex() const; + void setCurrentIndex(int idx); + + qreal offset() const; + void setOffset(qreal offset); + + qreal snapPosition() const; + void setSnapPosition(qreal pos); + + qreal dragMargin() const; + void setDragMargin(qreal margin); + + int count() const; + + QmlComponent *delegate() const; + void setDelegate(QmlComponent *); + + int pathItemCount() const; + void setPathItemCount(int); + + static QObject *qmlAttachedProperties(QObject *); + +Q_SIGNALS: + void currentIndexChanged(); + void offsetChanged(); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *); + bool sendMouseEvent(QGraphicsSceneMouseEvent *event); + bool sceneEventFilter(QGraphicsItem *, QEvent *); + void componentComplete(); + +private Q_SLOTS: + void refill(); + void ticked(); + void itemsInserted(int index, int count); + void itemsRemoved(int index, int count); + void createdItem(int index, QmlGraphicsItem *item); + void destroyingItem(QmlGraphicsItem *item); + +protected: + QmlGraphicsPathView(QmlGraphicsPathViewPrivate &dd, QmlGraphicsItem *parent); + +private: + friend class QmlGraphicsPathViewAttached; + static QHash attachedProperties; + Q_DISABLE_COPY(QmlGraphicsPathView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsPathView) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsPathView) +QML_DECLARE_TYPEINFO(QmlGraphicsPathView, QML_HAS_ATTACHED_PROPERTIES) +QT_END_HEADER + +#endif // QMLGRAPHICSPATHVIEW_H diff --git a/src/declarative/fx/qmlgraphicspathview_p.h b/src/declarative/fx/qmlgraphicspathview_p.h new file mode 100644 index 0000000..22ee075 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspathview_p.h @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSPATHVIEW_P_H +#define QMLGRAPHICSPATHVIEW_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 "qdatetime.h" +#include "qmlgraphicspathview.h" +#include "qmlgraphicsitem_p.h" +#include "qmlgraphicsvisualitemmodel.h" +#include "qml.h" +#include "private/qmlanimation_p.h" + +QT_BEGIN_NAMESPACE + +typedef struct PathViewItem{ + int index; + QmlGraphicsItem* item; +}PathViewItem; + +class QmlGraphicsPathViewPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsPathView) + +public: + QmlGraphicsPathViewPrivate() + : path(0), currentIndex(0), startPc(0), lastDist(0) + , lastElapsed(0), stealMouse(false), ownModel(false), activeItem(0) + , snapPos(0), dragMargin(0), moveOffset(this, &QmlGraphicsPathViewPrivate::setOffset) + , firstIndex(0), pathItems(-1), pathOffset(0), requestedIndex(-1), model(0) + , moveReason(Other) + { + fixupOffsetEvent = QmlTimeLineEvent::timeLineEvent(&moveOffset, this); + } + + void init() + { + Q_Q(QmlGraphicsPathView); + _offset = 0; + q->setAcceptedMouseButtons(Qt::LeftButton); + q->setFlag(QGraphicsItem::ItemIsFocusScope); + q->setFiltersChildEvents(true); + q->connect(&tl, SIGNAL(updated()), q, SLOT(ticked())); + } + + QmlGraphicsItem *getItem(int modelIndex) { + Q_Q(QmlGraphicsPathView); + requestedIndex = modelIndex; + QmlGraphicsItem *item = model->item(modelIndex); + if (item) + item->setParentItem(q); + requestedIndex = -1; + return item; + } + void releaseItem(QmlGraphicsItem *item) { + model->release(item); + } + + bool isValid() const { + return model && model->count() > 0 && model->isValid() && path; + } + + int calcCurrentIndex(); + void updateCurrent(); + void fixOffset(); + void setOffset(qreal offset); + void regenerate(); + void updateItem(QmlGraphicsItem *, qreal); + void snapToCurrent(); + QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const; + + QmlGraphicsPath *path; + int currentIndex; + qreal startPc; + QPointF startPoint; + qreal lastDist; + int lastElapsed; + qreal _offset; + bool stealMouse : 1; + bool ownModel : 1; + QTime lastPosTime; + QPointF lastPos; + QmlGraphicsItem *activeItem; + qreal snapPos; + qreal dragMargin; + QmlTimeLine tl; + QmlTimeLineValueProxy moveOffset; + QmlTimeLineEvent fixupOffsetEvent; + int firstIndex; + int pathItems; + int pathOffset; + int requestedIndex; + QList items; + QmlGraphicsVisualModel *model; + QVariant modelVariant; + enum MovementReason { Other, Key, Mouse }; + MovementReason moveReason; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/declarative/fx/qmlgraphicspixmapcache.cpp b/src/declarative/fx/qmlgraphicspixmapcache.cpp new file mode 100644 index 0000000..e347a8b --- /dev/null +++ b/src/declarative/fx/qmlgraphicspixmapcache.cpp @@ -0,0 +1,282 @@ +/**************************************************************************** +** +** 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 "qmlgraphicspixmapcache.h" +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QSharedNetworkReply; +typedef QHash QmlGraphicsSharedNetworkReplyHash; +static QmlGraphicsSharedNetworkReplyHash qfxActiveNetworkReplies; + +class QSharedNetworkReply +{ +public: + QSharedNetworkReply(QNetworkReply *r) : reply(r), refCount(1) {} + ~QSharedNetworkReply() + { + reply->deleteLater(); + } + QNetworkReply *reply; + QPixmap pixmap; // ensure reference to pixmap to QPixmapCache does not discard + + int refCount; + void addRef() + { + ++refCount; + } + void release() + { + Q_ASSERT(refCount > 0); + --refCount; + if (refCount == 0) { + QString key = reply->url().toString(); + qfxActiveNetworkReplies.remove(key); + delete this; + } + } +}; + +static bool readImage(QIODevice *dev, QPixmap *pixmap) + { + QImageReader imgio(dev); + +//#define QT_TEST_SCALED_SIZE +#ifdef QT_TEST_SCALED_SIZE + /* + Some mechanism is needed for loading images at a limited size, especially + for remote images. Loading only thumbnails of remote progressive JPEG + images can be efficient. (Qt jpeg handler does not do so currently) + */ + + QSize limit(60,60); + QSize sz = imgio.size(); + if (sz.width() > limit.width() || sz.height() > limit.height()) { + sz.scale(limit,Qt::KeepAspectRatio); + imgio.setScaledSize(sz); + } +#endif + + QImage img; + if (imgio.read(&img)) { +#ifdef QT_TEST_SCALED_SIZE + if (!sz.isValid()) + img = img.scaled(limit,Qt::KeepAspectRatio); +#endif + *pixmap = QPixmap::fromImage(img); + return true; + } else { + qWarning() << imgio.errorString(); + return false; + } + } + +/*! + \internal + \class QmlGraphicsPixmapCache + \brief Enacapsultes a pixmap for QmlGraphics items. + + This class is NOT reentrant. + */ + +static QString toLocalFileOrQrc(const QUrl& url) +{ + QString r = url.toLocalFile(); + if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) + r = QLatin1Char(':') + url.path(); + return r; +} + +/*! + Finds the cached pixmap corresponding to \a url. + A previous call to get() must have requested the URL, + and the QNetworkReply must have finished before calling + this function. + + Returns true if the image was loaded without error. +*/ +bool QmlGraphicsPixmapCache::find(const QUrl& url, QPixmap *pixmap) +{ +#ifdef Q_ENABLE_PERFORMANCE_LOG + QmlPerfTimer perf; +#endif + + QString key = url.toString(); + bool ok = true; + if (!QPixmapCache::find(key,pixmap)) { +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + QString lf = toLocalFileOrQrc(url); + if (!lf.isEmpty()) { + QFile f(lf); + if (f.open(QIODevice::ReadOnly)) { + if (!readImage(&f, pixmap)) { + qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + ok = false; + } + } else { + *pixmap = QPixmap(); + ok = false; + } + } else +#endif + { + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) { + // API usage error + qWarning() << "QmlGraphicsPixmapCache: URL not loaded" << url; + ok = false; + } else { + if ((*iter)->reply->error()) { + qWarning() << "Network error loading" << url << (*iter)->reply->errorString(); + *pixmap = QPixmap(); + ok = false; + } else if (!readImage((*iter)->reply, pixmap)) { + qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + ok = false; + } else { + if ((*iter)->refCount > 1) + (*iter)->pixmap = *pixmap; + } + (*iter)->release(); + } + } + QPixmapCache::insert(key, *pixmap); + } else { + ok = !pixmap->isNull(); +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + if (url.scheme()!=QLatin1String("file")) +#endif + // We may be the second finder. Still need to check for active replies. + { + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter != qfxActiveNetworkReplies.end()) + (*iter)->release(); + } + } + return ok; +} + +/*! + Starts a network request to load \a url. + + Returns a QNetworkReply if the image is not immediately available, otherwise + returns 0. Caller should connect to QNetworkReply::finished() to then call + find() when the image is available. + + The returned QNetworkReply will be deleted when all get() calls are + matched by a corresponding find() call. +*/ +QNetworkReply *QmlGraphicsPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap *pixmap) +{ +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + QString lf = toLocalFileOrQrc(url); + if (!lf.isEmpty()) { + QString key = url.toString(); + if (!QPixmapCache::find(key,pixmap)) { + QFile f(lf); + if (f.open(QIODevice::ReadOnly)) { + if (!readImage(&f, pixmap)) { + qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + } + } else + *pixmap = QPixmap(); + QPixmapCache::insert(key, *pixmap); + } + return 0; + } +#endif + + QString key = url.toString(); + if (QPixmapCache::find(key,pixmap)) { + return 0; + } + + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) { + QNetworkRequest req(url); + QSharedNetworkReply *item = new QSharedNetworkReply(engine->networkAccessManager()->get(req)); + iter = qfxActiveNetworkReplies.insert(key, item); + } else { + (*iter)->addRef(); + } + + return (*iter)->reply; +} + +/*! + Cancels a previous call to get(). + + May also cancel loading (eg. if no other pending request). + + Any connections from the QNetworkReply returned by get() to \a obj will be + disconnected. +*/ +void QmlGraphicsPixmapCache::cancelGet(const QUrl& url, QObject* obj) +{ + QString key = url.toString(); + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) + return; + if (obj) + QObject::disconnect((*iter)->reply, 0, obj, 0); + (*iter)->release(); +} + +/*! + This function is mainly for test verification. It returns the number of + requests that are still unfinished. +*/ +int QmlGraphicsPixmapCache::pendingRequests() +{ + return qfxActiveNetworkReplies.count(); +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicspixmapcache.h b/src/declarative/fx/qmlgraphicspixmapcache.h new file mode 100644 index 0000000..5094665 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspixmapcache.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSPIXMAPCACHE_H +#define QMLGRAPHICSPIXMAPCACHE_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlEngine; +class QNetworkReply; +class Q_DECLARATIVE_EXPORT QmlGraphicsPixmapCache +{ +public: + static QNetworkReply *get(QmlEngine *, const QUrl& url, QPixmap *pixmap); + static void cancelGet(const QUrl& url, QObject* obj); + + static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QmlGraphicsPixmapCache::get, and any returned reply finished. + + static int pendingRequests(); // mainly for test verification +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLGRAPHICSPIXMAPCACHE_H diff --git a/src/declarative/fx/qmlgraphicspositioners.cpp b/src/declarative/fx/qmlgraphicspositioners.cpp new file mode 100644 index 0000000..31950e6 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspositioners.cpp @@ -0,0 +1,921 @@ +/**************************************************************************** +** +** 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 +#include +#include "qml.h" +#include "qmlstate.h" +#include "qmlstategroup.h" +#include "qmlstateoperations.h" +#include "private/qfxperf_p.h" +#include "qmlgraphicspositioners.h" +#include "qmlgraphicspositioners_p.h" + + +QT_BEGIN_NAMESPACE + +/*! + \internal + \class QmlGraphicsBasePositioner + \ingroup group_layouts + \brief The QmlGraphicsBasePositioner class provides a base for QmlGraphics layouts. + + To create a QmlGraphics Positioner, simply subclass QmlGraphicsBasePositioner and implement + doLayout(), which is automatically called when the layout might need + updating. + + It is strongly recommended that in your implementation of doLayout() + that you use the move, remove and add transitions when those conditions + arise. You can use the applyAdd, applyMove and applyRemove functions + to do this easily. + + Note also that the subclass is responsible for adding the + spacing in between items. +*/ +QmlGraphicsBasePositioner::QmlGraphicsBasePositioner(AutoUpdateType at, QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsBasePositionerPrivate), parent) +{ + Q_D(QmlGraphicsBasePositioner); + d->init(at); +} + +QmlGraphicsBasePositioner::QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, AutoUpdateType at, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ + Q_D(QmlGraphicsBasePositioner); + d->init(at); +} + +int QmlGraphicsBasePositioner::spacing() const +{ + Q_D(const QmlGraphicsBasePositioner); + return d->_spacing; +} + +void QmlGraphicsBasePositioner::setSpacing(int s) +{ + Q_D(QmlGraphicsBasePositioner); + if (s==d->_spacing) + return; + d->_spacing = s; + prePositioning(); + emit spacingChanged(); +} + +QmlTransition *QmlGraphicsBasePositioner::move() const +{ + Q_D(const QmlGraphicsBasePositioner); + return d->moveTransition; +} + +void QmlGraphicsBasePositioner::setMove(QmlTransition *mt) +{ + Q_D(QmlGraphicsBasePositioner); + d->moveTransition = mt; +} + +QmlTransition *QmlGraphicsBasePositioner::add() const +{ + Q_D(const QmlGraphicsBasePositioner); + return d->addTransition; +} + +void QmlGraphicsBasePositioner::setAdd(QmlTransition *add) +{ + Q_D(QmlGraphicsBasePositioner); + d->addTransition = add; +} + +QmlTransition *QmlGraphicsBasePositioner::remove() const +{ + Q_D(const QmlGraphicsBasePositioner); + return d->removeTransition; +} + +void QmlGraphicsBasePositioner::setRemove(QmlTransition *remove) +{ + Q_D(QmlGraphicsBasePositioner); + d->removeTransition = remove; +} + +void QmlGraphicsBasePositioner::componentComplete() +{ + QmlGraphicsItem::componentComplete(); +#ifdef Q_ENABLE_PERFORMANCE_LOG + QmlPerfTimer cc; +#endif + prePositioning(); +} + +QVariant QmlGraphicsBasePositioner::itemChange(GraphicsItemChange change, + const QVariant &value) +{ + if (change == ItemChildAddedChange || + change == ItemChildRemovedChange) { + prePositioning(); + } + + return QmlGraphicsItem::itemChange(change, value); +} + +bool QmlGraphicsBasePositioner::event(QEvent *e) +{ + Q_D(QmlGraphicsBasePositioner); + if (e->type() == QEvent::User) { + d->_ep = false; + d->_stableItems += d->_newItems; + d->_leavingItems.clear(); + d->_newItems.clear(); + return true; + } + return QmlGraphicsItem::event(e); +} + +/*! + Items that have just been added to the positioner. This includes invisible items + that have turned visible. +*/ +QSet* QmlGraphicsBasePositioner::newItems() +{ + Q_D(QmlGraphicsBasePositioner); + return &d->_newItems; +} + +/*! + Items that are visible in the positioner, not including ones that have just been added. +*/ +QSet* QmlGraphicsBasePositioner::items() +{ + Q_D(QmlGraphicsBasePositioner); + return &d->_stableItems; +} + +/*! + Items that have just left the positioner. This includes visible items + that have turned invisible. +*/ +QSet* QmlGraphicsBasePositioner::leavingItems() +{ + Q_D(QmlGraphicsBasePositioner); + return &d->_leavingItems; +} + +void QmlGraphicsBasePositioner::prePositioning() +{ + Q_D(QmlGraphicsBasePositioner); + if (!isComponentComplete() || d->_movingItem) + return; + + if (!d->_ep) { + d->_ep = true; + QCoreApplication::postEvent(this, new QEvent(QEvent::User)); + } + QSet allItems; + QList children = childItems(); + for (int ii = 0; ii < children.count(); ++ii) { + QmlGraphicsItem *child = qobject_cast(children.at(ii)); + if (!child) + continue; + if (!d->_items.contains(child)){ + QObject::connect(child, SIGNAL(visibleChanged()), + this, SLOT(prePositioning())); + QObject::connect(child, SIGNAL(opacityChanged()), + this, SLOT(prePositioning())); + QObject::connect(child, SIGNAL(heightChanged()), + this, SLOT(prePositioning())); + QObject::connect(child, SIGNAL(widthChanged()), + this, SLOT(prePositioning())); + d->_items += child; + } + if (child->opacity() == 0.0){ + if (d->_stableItems.contains(child)){ + d->_leavingItems += child; + d->_stableItems -= child; + } + }else if (!d->_stableItems.contains(child)){ + d->_newItems+=child; + } + allItems += child; + } + QSet deletedItems = d->_items - allItems; + foreach(QmlGraphicsItem *child, d->_items){ + if (!allItems.contains(child)){ + if (!deletedItems.contains(child)) { + QObject::disconnect(child, SIGNAL(opacityChanged()), + this, SLOT(prePositioning())); + QObject::disconnect(child, SIGNAL(heightChanged()), + this, SLOT(prePositioning())); + QObject::disconnect(child, SIGNAL(widthChanged()), + this, SLOT(prePositioning())); + } + d->_items -= child; + } + } + d->_animated.clear(); + doPositioning(); + finishApplyTransitions(); + //Set implicit size to the size of its children + //###To keep this valid, do we need to update on pos change as well? + qreal h = 0.0f; + qreal w = 0.0f; + foreach(QmlGraphicsItem *child, d->_items){ + if(!child->isVisible() || child->opacity() <= 0) + continue; + h = qMax(h, child->y() + child->height()); + w = qMax(w, child->x() + child->width()); + } + setImplicitHeight(h); + setImplicitWidth(w); +} + +void QmlGraphicsBasePositioner::applyTransition(const QList >& changes, QmlGraphicsItem* target, QmlStateOperation::ActionList &actions) +{ + Q_D(QmlGraphicsBasePositioner); + if (!target) + return; + + for (int ii=0; ii_animated << target; +} + +void QmlGraphicsBasePositioner::finishApplyTransitions() +{ + Q_D(QmlGraphicsBasePositioner); + // Note that if a transition is not set the transition manager will + // apply the changes directly, in the case someone uses applyAdd/Move/Remove + // without testing add()/move()/remove(). + d->addTransitionManager.transition(d->addActions, d->addTransition); + d->moveTransitionManager.transition(d->moveActions, d->moveTransition); + d->removeTransitionManager.transition(d->removeActions, d->removeTransition); + d->addActions.clear(); + d->moveActions.clear(); + d->removeActions.clear(); +} +void QmlGraphicsBasePositioner::setMovingItem(QmlGraphicsItem *i) +{ + Q_D(QmlGraphicsBasePositioner); + d->_movingItem = i; +} + +/*! + Applies the positioner's add transition to the \a target item.\a changes is a list of property,value + pairs which will be changed on the target using the add transition. +*/ +void QmlGraphicsBasePositioner::applyAdd(const QList >& changes, QmlGraphicsItem* target) +{ + Q_D(QmlGraphicsBasePositioner); + applyTransition(changes,target, d->addActions); +} + +/*! + Applies the positioner's move transition to the \a target.\a changes is a list of property,value pairs + which will be changed on the target using the move transition. +*/ +void QmlGraphicsBasePositioner::applyMove(const QList >& changes, QmlGraphicsItem* target) +{ + Q_D(QmlGraphicsBasePositioner); + applyTransition(changes,target, d->moveActions); +} + +/*! + Applies the positioner's remove transition to the \a target item.\a changes is a list of + property,value pairs which will be changed on the target using the remove transition. +*/ +void QmlGraphicsBasePositioner::applyRemove(const QList >& changes, QmlGraphicsItem* target) +{ + Q_D(QmlGraphicsBasePositioner); + applyTransition(changes,target, d->removeActions); +} + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Column,QmlGraphicsColumn) +/*! + \qmlclass Column + \brief The Column item lines up its children vertically. + \inherits Item + + The Column item positions its child items so that they are vertically + aligned and not overlapping. Spacing between items can be added. + + The below example positions differently shaped rectangles using a Column. + \table + \row + \o \image verticalpositioner_example.png + \o + \qml +Column { + spacing: 2 + Rectangle { color: "red"; width: 50; height: 50 } + Rectangle { color: "green"; width: 20; height: 50 } + Rectangle { color: "blue"; width: 50; height: 20 } +} + \endqml + \endtable + + Column also provides for transitions to be set when items are added, moved, + or removed in the positioner. Adding and removing apply both to items which are deleted + or have their position in the document changed so as to no longer be children of the positioner, + as well as to items which have their opacity set to or from zero so as to appear or disappear. + + \table + \row + \o \image verticalpositioner_transition.gif + \o + \qml +Column { + spacing: 2 + remove: ... + add: ... + move: ... + ... +} + \endqml + \endtable + + Note that the positioner assumes that the x and y positions of its children + will not change. If you manually change the x or y properties in script, bind + the x or y properties, or use anchors on a child of a positioner, then the + positioner may exhibit strange behaviour. + +*/ +/*! + \qmlproperty Transition Column::remove + This property holds the transition to apply when removing an item from the positioner. The transition is only applied to the removed items. + + Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. + + Note that if the item counts as removed because its opacity is zero it will not be visible during the transition unless you set the opacity in the transition, like in the below example. + + \table + \row + \o \image positioner-remove.gif + \o + \qml +Column { + remove: Transition { + NumberAnimation { + properties: "opacity" + from: 1 + to: 0 + duration: 500 + } + } +} + \endqml + \endtable + +*/ +/*! + \qmlproperty Transition Column::add + This property holds the transition to be applied when adding an item to the positioner. The transition will only be applied to the added item(s). + + Added can mean that either the object has been created or reparented, and thus is now a child or the positioner, or that the object has had its opacity increased from zero, and thus is now visible. + + \table + \row + \o \image positioner-add.gif + \o + \qml +Column { + add: Transition { + NumberAnimation { + properties: "opacity" + from: 0 + to: 1 + duration: 500 + } + } +} + \endqml + \endtable + +*/ +/*! + \qmlproperty Transition Column::move + This property holds the transition to apply when moving an item within the positioner. + + This can happen when other items are added or removed from the positioner, or when items resize themselves. + + \table + \row + \o \image positioner-move.gif + \o + \qml +Column { + move: Transition { + NumberAnimation { + properties: "y" + ease: "easeOutBounce" + } + } +} + \endqml + \endtable +*/ +/*! + \qmlproperty int Column::spacing + + spacing is the amount in pixels left empty between each adjacent + item, and defaults to 0. + + The below example places a Grid containing a red, a blue and a + green rectangle on a gray background. The area the grid positioner + occupies is colored white. The top positioner has the default of no spacing, + and the bottom positioner has its spacing set to 2. + + \image spacing_a.png + \image spacing_b.png + +*/ +/*! + \internal + \class QmlGraphicsColumn + \brief The QmlGraphicsColumn class lines up items vertically. + \ingroup group_positioners +*/ +QmlGraphicsColumn::QmlGraphicsColumn(QmlGraphicsItem *parent) +: QmlGraphicsBasePositioner(Vertical, parent) +{ +} + +void QmlGraphicsColumn::doPositioning() +{ + int voffset = 0; + + foreach(QmlGraphicsItem* item, *leavingItems()){ + if (remove()){ + QList > changes; + applyRemove(changes, item); + } + } + + QList children = childItems(); + for (int ii = 0; ii < children.count(); ++ii) { + QmlGraphicsItem *child = qobject_cast(children.at(ii)); + if (!child || child->opacity() == 0.0) + continue; + + bool needMove = (child->y() != voffset || child->x()); + + QList > changes; + changes << qMakePair(QString(QLatin1String("y")),QVariant(voffset)); + changes << qMakePair(QString(QLatin1String("x")),QVariant(0)); + if (needMove && items()->contains(child) && move()) { + applyMove(changes,child); + } else if (!items()->contains(child) && add()) { + applyAdd(changes,child); + } else if (needMove) { + setMovingItem(child); + child->setY(voffset); + setMovingItem(0); + } + voffset += child->height(); + voffset += spacing(); + } +} + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Row,QmlGraphicsRow) +/*! + \qmlclass Row + \brief The Row item lines up its children horizontally. + \inherits Item + + The Row item positions its child items so that they are + horizontally aligned and not overlapping. Spacing can be added between the + items, and a margin around all items can also be added. It also provides for + transitions to be set when items are added, moved, or removed in the + positioner. Adding and removing apply both to items which are deleted or have + their position in the document changed so as to no longer be children of the + positioner, as well as to items which have their opacity set to or from zero + so as to appear or disappear. + + The below example lays out differently shaped rectangles using a Row. + \qml +Row { + spacing: 2 + Rectangle { color: "red"; width: 50; height: 50 } + Rectangle { color: "green"; width: 20; height: 50 } + Rectangle { color: "blue"; width: 50; height: 20 } +} + \endqml + \image horizontalpositioner_example.png + + Note that the positioner assumes that the x and y positions of its children + will not change. If you manually change the x or y properties in script, bind + the x or y properties, or use anchors on a child of a positioner, then the + positioner may exhibit strange behaviour. + +*/ +/*! + \qmlproperty Transition Row::remove + This property holds the transition to apply when removing an item from the positioner. + The transition will only be applied to the removed item(s). + + Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. + + Note that if the item counts as removed because its opacity is zero it will not be visible during the transition unless you set the opacity in the transition, like in the below example. + + \qml +Row { + remove: Transition { + NumberAnimation { + properties: "opacity" + from: 1 + to: 0 + duration: 500 + } + } +} + \endqml + +*/ +/*! + \qmlproperty Transition Row::add + This property holds the transition to apply when adding an item to the positioner. + The transition will only be applied to the added item(s). + + Added can mean that either the object has been created or reparented, and thus is now a child or the positioner, or that the object has had its opacity increased from zero, and thus is now visible. + + \qml +Row { + add: Transition { + NumberAnimation { + properties: "opacity" + from: 0 + to: 1 + duration: 500 + } + } +} + \endqml + +*/ +/*! + \qmlproperty Transition Row::move + This property holds the transition to apply when moving an item within the positioner. + + This can happen when other items are added or removed from the positioner, or when items resize themselves. + + \qml +Row { + id: positioner + move: Transition { + NumberAnimation { + properties: "x" + ease: "easeOutBounce" + } + } +} + \endqml + +*/ +/*! + \qmlproperty int Row::spacing + + spacing is the amount in pixels left empty between each adjacent + item, and defaults to 0. + + The below example places a Grid containing a red, a blue and a + green rectangle on a gray background. The area the grid positioner + occupies is colored white. The top positioner has the default of no spacing, + and the bottom positioner has its spacing set to 2. + + \image spacing_a.png + \image spacing_b.png + +*/ +/*! + \internal + \class QmlGraphicsRow + \brief The QmlGraphicsRow class lines up items horizontally. + \ingroup group_positioners +*/ +QmlGraphicsRow::QmlGraphicsRow(QmlGraphicsItem *parent) +: QmlGraphicsBasePositioner(Horizontal, parent) +{ +} + +void QmlGraphicsRow::doPositioning() +{ + int hoffset = 0; + + foreach(QmlGraphicsItem* item, *leavingItems()){ + if (remove()){ + QList > changes; + applyRemove(changes, item); + } + } + QList children = childItems(); + for (int ii = 0; ii < children.count(); ++ii) { + QmlGraphicsItem *child = qobject_cast(children.at(ii)); + if (!child || child->opacity() == 0.0) + continue; + + bool needMove = (child->x() != hoffset || child->y()); + + QList > changes; + changes << qMakePair(QString(QLatin1String("x")),QVariant(hoffset)); + changes << qMakePair(QString(QLatin1String("y")),QVariant(0)); + if (needMove && items()->contains(child) && move()) { + applyMove(changes,child); + } else if (!items()->contains(child) && add()) { + applyAdd(changes,child); + } else if (needMove) { + setMovingItem(child); + child->setX(hoffset); + setMovingItem(0); + } + if(child->width() && child->height()){//don't advance for invisible children + hoffset += child->width(); + hoffset += spacing(); + } + } +} + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Grid,QmlGraphicsGrid) + +/*! + \qmlclass Grid QmlGraphicsGrid + \brief The Grid item positions its children in a grid. + \inherits Item + + The Grid item positions its child items so that they are + aligned in a grid and are not overlapping. Spacing can be added + between the items. It also provides for transitions to be set when items are + added, moved, or removed in the positioner. Adding and removing apply + both to items which are deleted or have their position in the + document changed so as to no longer be children of the positioner, as + well as to items which have their opacity set to or from zero so + as to appear or disappear. + + The Grid defaults to using four columns, and as many rows as + are necessary to fit all the child items. The number of rows + and/or the number of columns can be constrained by setting the rows + or columns properties. The grid positioner calculates a grid with + rectangular cells of sufficient size to hold all items, and then + places the items in the cells, going across then down, and + positioning each item at the (0,0) corner of the cell. The below + example demonstrates this. + + \table + \row + \o \image gridLayout_example.png + \o + \qml +Grid { + columns: 3 + spacing: 2 + Rectangle { color: "red"; width: 50; height: 50 } + Rectangle { color: "green"; width: 20; height: 50 } + Rectangle { color: "blue"; width: 50; height: 20 } + Rectangle { color: "cyan"; width: 50; height: 50 } + Rectangle { color: "magenta"; width: 10; height: 10 } +} + \endqml + \endtable + + Note that the positioner assumes that the x and y positions of its children + will not change. If you manually change the x or y properties in script, bind + the x or y properties, or use anchors on a child of a positioner, then the + positioner may exhibit strange behaviour. +*/ +/*! + \qmlproperty Transition Grid::remove + This property holds the transition to apply when removing an item from the positioner. + The transition is only applied to the removed item(s). + + Removed can mean that either the object has been deleted or + reparented, and thus is now longer a child of the positioner, or that + the object has had its opacity set to zero, and thus is no longer + visible. + + Note that if the item counts as removed because its opacity is + zero it will not be visible during the transition unless you set + the opacity in the transition, like in the below example. + + \qml +Grid { + remove: Transition { + NumberAnimation { + properties: "opacity" + from: 1 + to: 0 + duration: 500 + } + } +} + \endqml + +*/ +/*! + \qmlproperty Transition Grid::add + This property holds the transition to apply when adding an item to the positioner. + The transition is only applied to the added item(s). + + Added can mean that either the object has been created or + reparented, and thus is now a child or the positioner, or that the + object has had its opacity increased from zero, and thus is now + visible. + + \qml +Grid { + add: Transition { + NumberAnimation { + properties: "opacity" + from: 0 + to: 1 + duration: 500 + } + } +} + \endqml + +*/ +/*! + \qmlproperty Transition Grid::move + This property holds the transition to apply when moving an item within the positioner. + + This can happen when other items are added or removed from the positioner, or + when items resize themselves. + + \qml +Grid { + move: Transition { + NumberAnimation { + properties: "x,y" + ease: "easeOutBounce" + } + } +} + \endqml + +*/ +/*! + \qmlproperty int Grid::spacing + + spacing is the amount in pixels left empty between each adjacent + item, and defaults to 0. + + The below example places a Grid containing a red, a blue and a + green rectangle on a gray background. The area the grid positioner + occupies is colored white. The top positioner has the default of no spacing, + and the bottom positioner has its spacing set to 2. + + \image spacing_a.png + \image spacing_b.png + +*/ +/*! + \internal + \class QmlGraphicsGrid + \brief The QmlGraphicsGrid class lays out items in a grid. + \ingroup group_layouts + +*/ +QmlGraphicsGrid::QmlGraphicsGrid(QmlGraphicsItem *parent) : + QmlGraphicsBasePositioner(Both, parent) +{ + _columns=-1; + _rows=-1; +} + +/*! + \qmlproperty int Grid::columns + This property holds the number of columns in the grid. + + When the columns property is set the Grid will always have + that many columns. Note that if you do not have enough items to + fill this many columns some columns will be of zero width. +*/ + +/*! + \qmlproperty int Grid::rows + This property holds the number of rows in the grid. + + When the rows property is set the Grid will always have that + many rows. Note that if you do not have enough items to fill this + many rows some rows will be of zero width. +*/ + +void QmlGraphicsGrid::doPositioning() +{ + int c=_columns,r=_rows;//Actual number of rows/columns + int numVisible = items()->size() + newItems()->size(); + if (_columns==-1 && _rows==-1){ + c = 4; + r = (numVisible+3)/4; + }else if (_rows==-1){ + r = (numVisible+(_columns-1))/_columns; + }else if (_columns==-1){ + c = (numVisible+(_rows-1))/_rows; + } + + QList maxColWidth; + QList maxRowHeight; + int childIndex =0; + QList children = childItems(); + for (int i=0; i(children.at(childIndex++)); + if (!child || child->opacity() == 0.0) + continue; + if (child->width() > maxColWidth[j]) + maxColWidth[j] = child->width(); + if (child->height() > maxRowHeight[i]) + maxRowHeight[i] = child->height(); + } + } + + int xoffset=0; + int yoffset=0; + int curRow =0; + int curCol =0; + foreach(QmlGraphicsItem* item, *leavingItems()){ + if (remove()){ + QList > changes; + applyRemove(changes, item); + } + } + foreach(QGraphicsItem* schild, children){ + QmlGraphicsItem *child = qobject_cast(schild); + if (!child || child->opacity() == 0.0) + continue; + bool needMove = (child->x()!=xoffset)||(child->y()!=yoffset); + QList > changes; + changes << qMakePair(QString(QLatin1String("x")),QVariant(xoffset)); + changes << qMakePair(QString(QLatin1String("y")),QVariant(yoffset)); + if (newItems()->contains(child) && add()) { + applyAdd(changes,child); + } else if (needMove) { + if (move()){ + applyMove(changes,child); + }else{ + setMovingItem(child); + child->setPos(QPointF(xoffset, yoffset)); + setMovingItem(0); + } + } + xoffset+=maxColWidth[curCol]+spacing(); + curCol++; + curCol%=c; + if (!curCol){ + yoffset+=maxRowHeight[curRow]+spacing(); + xoffset=0; + curRow++; + if (curRow>=r) + break; + } + } +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicspositioners.h b/src/declarative/fx/qmlgraphicspositioners.h new file mode 100644 index 0000000..e252ed8 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspositioners.h @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSLAYOUTS_H +#define QMLGRAPHICSLAYOUTS_H + +#include +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlGraphicsBasePositionerPrivate; + +class Q_DECLARATIVE_EXPORT QmlGraphicsBasePositioner : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) + Q_PROPERTY(QmlTransition *move READ move WRITE setMove) + Q_PROPERTY(QmlTransition *add READ add WRITE setAdd) + Q_PROPERTY(QmlTransition *remove READ remove WRITE setRemove) +public: + enum AutoUpdateType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 }; + QmlGraphicsBasePositioner(AutoUpdateType, QmlGraphicsItem *parent); + + int spacing() const; + void setSpacing(int); + + QmlTransition *move() const; + void setMove(QmlTransition *); + + QmlTransition *add() const; + void setAdd(QmlTransition *); + + QmlTransition *remove() const; + void setRemove(QmlTransition *); + +protected: + virtual void componentComplete(); + virtual QVariant itemChange(GraphicsItemChange, const QVariant &); + virtual bool event(QEvent *); + QSet* newItems(); + QSet* leavingItems(); + QSet* items(); + void applyAdd(const QList >& changes, QmlGraphicsItem* target); + void applyMove(const QList >& changes, QmlGraphicsItem* target); + void applyRemove(const QList >& changes, QmlGraphicsItem* target); + void finishApplyTransitions(); + +Q_SIGNALS: + void layoutItemChanged(); + void spacingChanged(); + +protected Q_SLOTS: + virtual void doPositioning()=0; + +private Q_SLOTS: + void prePositioning(); + +protected: + QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, AutoUpdateType at, QmlGraphicsItem *parent); + void setMovingItem(QmlGraphicsItem *); + +private: + void applyTransition(const QList >& changes, QmlGraphicsItem* target, + QmlStateOperation::ActionList &actions); + Q_DISABLE_COPY(QmlGraphicsBasePositioner) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsBasePositioner) +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsColumn : public QmlGraphicsBasePositioner +{ + Q_OBJECT +public: + QmlGraphicsColumn(QmlGraphicsItem *parent=0); +protected Q_SLOTS: + virtual void doPositioning(); +private: + Q_DISABLE_COPY(QmlGraphicsColumn) +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsRow: public QmlGraphicsBasePositioner +{ + Q_OBJECT +public: + QmlGraphicsRow(QmlGraphicsItem *parent=0); +protected Q_SLOTS: + virtual void doPositioning(); +private: + Q_DISABLE_COPY(QmlGraphicsRow) +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGrid : public QmlGraphicsBasePositioner +{ + Q_OBJECT + Q_PROPERTY(int rows READ rows WRITE setRows) + Q_PROPERTY(int columns READ columns WRITE setcolumns) +public: + QmlGraphicsGrid(QmlGraphicsItem *parent=0); + + int rows() const {return _rows;} + void setRows(const int rows){_rows = rows;} + + int columns() const {return _columns;} + void setcolumns(const int columns){_columns = columns;} +protected Q_SLOTS: + virtual void doPositioning(); + +private: + int _rows; + int _columns; + Q_DISABLE_COPY(QmlGraphicsGrid) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsColumn) +QML_DECLARE_TYPE(QmlGraphicsRow) +QML_DECLARE_TYPE(QmlGraphicsGrid) + +QT_END_HEADER + +#endif diff --git a/src/declarative/fx/qmlgraphicspositioners_p.h b/src/declarative/fx/qmlgraphicspositioners_p.h new file mode 100644 index 0000000..f8ca6fd --- /dev/null +++ b/src/declarative/fx/qmlgraphicspositioners_p.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSLAYOUTS_P_H +#define QMLGRAPHICSLAYOUTS_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 +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QmlGraphicsBasePositionerPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsBasePositioner) + +public: + QmlGraphicsBasePositionerPrivate() + : _ep(false), _componentComplete(false), _spacing(0), + aut(QmlGraphicsBasePositioner::None), moveTransition(0), addTransition(0), + removeTransition(0), _movingItem(0) + { + } + + void init(QmlGraphicsBasePositioner::AutoUpdateType at) + { + aut = at; + } + + bool _ep; + bool _componentComplete; + int _spacing; + QmlGraphicsBasePositioner::AutoUpdateType aut; + QmlTransition *moveTransition; + QmlTransition *addTransition; + QmlTransition *removeTransition; + QSet _items; + QSet _leavingItems; + QSet _stableItems; + QSet _newItems; + QSet _animated; + QmlStateOperation::ActionList addActions; + QmlStateOperation::ActionList moveActions; + QmlStateOperation::ActionList removeActions; + QmlTransitionManager addTransitionManager; + QmlTransitionManager moveTransitionManager; + QmlTransitionManager removeTransitionManager; +// QmlStateGroup *stateGroup; + QmlGraphicsItem *_movingItem; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/declarative/fx/qmlgraphicsrect.cpp b/src/declarative/fx/qmlgraphicsrect.cpp new file mode 100644 index 0000000..1784ae1 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsrect.cpp @@ -0,0 +1,475 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsrect.h" +#include "qmlgraphicsrect_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Pen,QmlGraphicsPen) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GradientStop,QmlGraphicsGradientStop) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Gradient,QmlGraphicsGradient) + +/*! + \internal + \class QmlGraphicsPen + \brief The QmlGraphicsPen class provides a pen used for drawing rectangle borders on a QmlView. + + By default, the pen is invalid and nothing is drawn. You must either set a color (then the default + width is 1) or a width (then the default color is black). + + A width of 1 indicates is a single-pixel line on the border of the item being painted. + + Example: + \qml + Rectangle { border.width: 2; border.color: "red" ... } + \endqml +*/ + +void QmlGraphicsPen::setColor(const QColor &c) +{ + _color = c; + _valid = _color.alpha() ? true : false; + emit penChanged(); +} + +void QmlGraphicsPen::setWidth(int w) +{ + if (_width == w && _valid) + return; + + _width = w; + _valid = (_width < 1) ? false : true; + emit penChanged(); +} + + +/*! + \qmlclass GradientStop QmlGraphicsGradientStop + \brief The GradientStop item defines the color at a position in a Gradient + + \sa Gradient +*/ + +/*! + \qmlproperty real GradientStop::position + \qmlproperty color GradientStop::color + + Sets a \e color at a \e position in a gradient. +*/ + +void QmlGraphicsGradientStop::updateGradient() +{ + if (QmlGraphicsGradient *grad = qobject_cast(parent())) + grad->doUpdate(); +} + +/*! + \qmlclass Gradient QmlGraphicsGradient + \brief The Gradient item defines a gradient fill. + + A gradient is defined by two or more colors, which will be blended seemlessly. The + colors are specified at their position in the range 0.0 - 1.0 via + the GradientStop item. For example, the following code paints a + rectangle with a gradient starting with red, blending to yellow at 1/3 of the + size of the rectangle, and ending with Green: + + \table + \row + \o \image gradient.png + \o \quotefile doc/src/snippets/declarative/gradient.qml + \endtable + + \sa GradientStop +*/ + +/*! + \qmlproperty list Gradient::stops + This property holds the gradient stops describing the gradient. +*/ + +const QGradient *QmlGraphicsGradient::gradient() const +{ + if (!m_gradient && !m_stops.isEmpty()) { + m_gradient = new QLinearGradient(0,0,0,1.0); + for (int i = 0; i < m_stops.count(); ++i) { + const QmlGraphicsGradientStop *stop = m_stops.at(i); + m_gradient->setCoordinateMode(QGradient::ObjectBoundingMode); + m_gradient->setColorAt(stop->position(), stop->color()); + } + } + + return m_gradient; +} + +void QmlGraphicsGradient::doUpdate() +{ + delete m_gradient; + m_gradient = 0; + emit updated(); +} + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rectangle,QmlGraphicsRect) + +/*! + \qmlclass Rectangle QmlGraphicsRect + \brief The Rectangle item allows you to add rectangles to a scene. + \inherits Item + + A Rectangle is painted having a solid fill (color) and an optional border. + You can also create rounded rectangles using the radius property. + + \qml + Rectangle { + width: 100 + height: 100 + color: "red" + border.color: "black" + border.width: 5 + radius: 10 + } + \endqml + + \image declarative-rect.png +*/ + +/*! + \internal + \class QmlGraphicsRect + \brief The QmlGraphicsRect class provides a rectangle item that you can add to a QmlView. +*/ +QmlGraphicsRect::QmlGraphicsRect(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsRectPrivate), parent) +{ + Q_D(QmlGraphicsRect); + d->init(); + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QmlGraphicsRect::QmlGraphicsRect(QmlGraphicsRectPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ + Q_D(QmlGraphicsRect); + d->init(); + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +void QmlGraphicsRect::doUpdate() +{ + Q_D(QmlGraphicsRect); + d->rectImage = QPixmap(); + const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; + d->setPaintMargin((pw+1)/2); + update(); +} + +/*! + \qmlproperty int Rectangle::border.width + \qmlproperty color Rectangle::border.color + + The width and color used to draw the border of the rectangle. + + A width of 1 creates a thin line. For no line, use a width of 0 or a transparent color. + + To keep the border smooth (rather than blurry), odd widths cause the rectangle to be painted at + a half-pixel offset; +*/ +QmlGraphicsPen *QmlGraphicsRect::border() +{ + Q_D(QmlGraphicsRect); + return d->getPen(); +} + +/*! + \qmlproperty Gradient Rectangle::gradient + + The gradient to use to fill the rectangle. + + This property allows for the construction of simple vertical gradients. + Other gradients may by formed by adding rotation to the rectangle. + + \table + \row + \o \image declarative-rect_gradient.png + \o + \qml + Rectangle { y: 0; width: 80; height: 80; color: "lightsteelblue" } + Rectangle { y: 100; width: 80; height: 80 + gradient: Gradient { + GradientStop { position: 0.0; color: "lightsteelblue" } + GradientStop { position: 1.0; color: "blue" } + } + } + Rectangle { rotation: 90; x: 80; y: 200; width: 80; height: 80 + gradient: Gradient { + GradientStop { position: 0.0; color: "lightsteelblue" } + GradientStop { position: 1.0; color: "blue" } + } + } + // The x offset is needed because the rotation is from the top left corner + \endqml + \endtable + + If both a gradient and a color are specified, the gradient will be used. + + \sa Gradient, color +*/ +QmlGraphicsGradient *QmlGraphicsRect::gradient() const +{ + Q_D(const QmlGraphicsRect); + return d->gradient; +} + +void QmlGraphicsRect::setGradient(QmlGraphicsGradient *gradient) +{ + Q_D(QmlGraphicsRect); + if (d->gradient == gradient) + return; + if (d->gradient) + disconnect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); + d->gradient = gradient; + if (d->gradient) + connect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); + update(); +} + + +/*! + \qmlproperty real Rectangle::radius + This property holds the corner radius used to draw a rounded rectangle. + + If radius is non-zero, the rectangle will be painted as a rounded rectangle, otherwise it will be + painted as a normal rectangle. The same radius is used by all 4 corners; there is currently + no way to specify different radii for different corners. +*/ +qreal QmlGraphicsRect::radius() const +{ + Q_D(const QmlGraphicsRect); + return d->radius; +} + +void QmlGraphicsRect::setRadius(qreal radius) +{ + Q_D(QmlGraphicsRect); + if (d->radius == radius) + return; + + d->radius = radius; + d->rectImage = QPixmap(); + update(); + emit radiusChanged(); +} + +/*! + \qmlproperty color Rectangle::color + This property holds the color used to fill the rectangle. + + \qml + // green rectangle using hexidecimal notation + Rectangle { color: "#00FF00" } + + // steelblue rectangle using SVG color name + Rectangle { color: "steelblue" } + \endqml + + The default color is white. + + If both a gradient and a color are specified, the gradient will be used. +*/ +QColor QmlGraphicsRect::color() const +{ + Q_D(const QmlGraphicsRect); + return d->color; +} + +void QmlGraphicsRect::setColor(const QColor &c) +{ + Q_D(QmlGraphicsRect); + if (d->color == c) + return; + + d->color = c; + d->rectImage = QPixmap(); + update(); + emit colorChanged(); +} + +void QmlGraphicsRect::generateRoundedRect() +{ + Q_D(QmlGraphicsRect); + if (d->rectImage.isNull()) { + const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; + const int radius = qCeil(d->radius); //ensure odd numbered width/height so we get 1-pixel center + d->rectImage = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2); + d->rectImage.fill(Qt::transparent); + QPainter p(&(d->rectImage)); + p.setRenderHint(QPainter::Antialiasing); + if (d->pen && d->pen->isValid()) { + QPen pn(QColor(d->pen->color()), d->pen->width()); + p.setPen(pn); + } else { + p.setPen(Qt::NoPen); + } + p.setBrush(d->color); + if (pw%2) + p.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1)), d->radius, d->radius); + else + p.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw), d->radius, d->radius); + } +} + +void QmlGraphicsRect::generateBorderedRect() +{ + Q_D(QmlGraphicsRect); + if (d->rectImage.isNull()) { + const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; + d->rectImage = QPixmap(pw*2 + 3, pw*2 + 3); + d->rectImage.fill(Qt::transparent); + QPainter p(&(d->rectImage)); + p.setRenderHint(QPainter::Antialiasing); + if (d->pen && d->pen->isValid()) { + QPen pn(QColor(d->pen->color()), d->pen->width()); + pn.setJoinStyle(Qt::MiterJoin); + p.setPen(pn); + } else { + p.setPen(Qt::NoPen); + } + p.setBrush(d->color); + if (pw%2) + p.drawRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1))); + else + p.drawRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw)); + } +} + +void QmlGraphicsRect::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + Q_D(QmlGraphicsRect); + if (d->radius > 0 || (d->pen && d->pen->isValid()) + || (d->gradient && d->gradient->gradient()) ) { + drawRect(*p); + } + else { + bool oldAA = p->testRenderHint(QPainter::Antialiasing); + if (d->smooth) + p->setRenderHints(QPainter::Antialiasing, true); + p->fillRect(QRectF(0, 0, width(), height()), d->color); + if (d->smooth) + p->setRenderHint(QPainter::Antialiasing, oldAA); + } +} + +void QmlGraphicsRect::drawRect(QPainter &p) +{ + Q_D(QmlGraphicsRect); + if (d->gradient && d->gradient->gradient()) { + // XXX This path is still slower than the image path + // Image path won't work for gradients though + bool oldAA = p.testRenderHint(QPainter::Antialiasing); + if (d->smooth) + p.setRenderHint(QPainter::Antialiasing); + if (d->pen && d->pen->isValid()) { + QPen pn(QColor(d->pen->color()), d->pen->width()); + p.setPen(pn); + } else { + p.setPen(Qt::NoPen); + } + p.setBrush(*d->gradient->gradient()); + if (d->radius > 0.) + p.drawRoundedRect(0, 0, width(), height(), d->radius, d->radius); + else + p.drawRect(0, 0, width(), height()); + if (d->smooth) + p.setRenderHint(QPainter::Antialiasing, oldAA); + } else { + bool oldAA = p.testRenderHint(QPainter::Antialiasing); + bool oldSmooth = p.testRenderHint(QPainter::SmoothPixmapTransform); + if (d->smooth) + p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); + + const int pw = d->pen && d->pen->isValid() ? (d->pen->width()+1)/2*2 : 0; + + if (d->radius > 0) + generateRoundedRect(); + else + generateBorderedRect(); + + int xOffset = (d->rectImage.width()-1)/2; + int yOffset = (d->rectImage.height()-1)/2; + Q_ASSERT(d->rectImage.width() == 2*xOffset + 1); + Q_ASSERT(d->rectImage.height() == 2*yOffset + 1); + + QMargins margins(xOffset, yOffset, xOffset, yOffset); + QTileRules rules(Qt::StretchTile, Qt::StretchTile); + //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects + qDrawBorderPixmap(&p, QRect(-pw/2, -pw/2, width()+pw, height()+pw), margins, d->rectImage, d->rectImage.rect(), margins, rules); + + if (d->smooth) { + p.setRenderHint(QPainter::Antialiasing, oldAA); + p.setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); + } + } +} + +/*! + \qmlproperty bool Rectangle::smooth + + Set this property if you want the item to be smoothly scaled or + transformed. Smooth filtering gives better visual quality, but is slower. If + the item is displayed at its natural size, this property has no visual or + performance effect. + + \note Generally scaling artifacts are only visible if the item is stationary on + the screen. A common pattern when animating an item is to disable smooth + filtering at the beginning of the animation and reenable it at the conclusion. + + \image rect-smooth.png +*/ + +QRectF QmlGraphicsRect::boundingRect() const +{ + Q_D(const QmlGraphicsRect); + return QRectF(-d->paintmargin, -d->paintmargin, d->width+d->paintmargin*2, d->height+d->paintmargin*2); +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsrect.h b/src/declarative/fx/qmlgraphicsrect.h new file mode 100644 index 0000000..454b2f1 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsrect.h @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSRECT_H +#define QMLGRAPHICSRECT_H + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class Q_DECLARATIVE_EXPORT QmlGraphicsPen : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged) +public: + QmlGraphicsPen(QObject *parent=0) + : QObject(parent), _width(1), _color("#000000"), _valid(false) + {} + + int width() const { return _width; } + void setWidth(int w); + + QColor color() const { return _color; } + void setColor(const QColor &c); + + bool isValid() { return _valid; }; + +Q_SIGNALS: + void penChanged(); + +private: + int _width; + QColor _color; + bool _valid; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGradientStop : public QObject +{ + Q_OBJECT + + Q_PROPERTY(qreal position READ position WRITE setPosition) + Q_PROPERTY(QColor color READ color WRITE setColor) + +public: + QmlGraphicsGradientStop(QObject *parent=0) : QObject(parent) {} + + qreal position() const { return m_position; } + void setPosition(qreal position) { m_position = position; updateGradient(); } + + QColor color() const { return m_color; } + void setColor(const QColor &color) { m_color = color; updateGradient(); } + +private: + void updateGradient(); + +private: + qreal m_position; + QColor m_color; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGradient : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QList *stops READ stops) + Q_CLASSINFO("DefaultProperty", "stops") + +public: + QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} + ~QmlGraphicsGradient() { delete m_gradient; } + + QList *stops() { return &m_stops; } + + const QGradient *gradient() const; + +Q_SIGNALS: + void updated(); + +private: + void doUpdate(); + +private: + QList m_stops; + mutable QGradient *m_gradient; + friend class QmlGraphicsGradientStop; +}; + +class QmlGraphicsRectPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsRect : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QmlGraphicsGradient *gradient READ gradient WRITE setGradient) + Q_PROPERTY(QmlGraphicsPen * border READ border CONSTANT) + Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) +public: + QmlGraphicsRect(QmlGraphicsItem *parent=0); + + QColor color() const; + void setColor(const QColor &); + + QmlGraphicsPen *border(); + + QmlGraphicsGradient *gradient() const; + void setGradient(QmlGraphicsGradient *gradient); + + qreal radius() const; + void setRadius(qreal radius); + + QRectF boundingRect() const; + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +Q_SIGNALS: + void colorChanged(); + void radiusChanged(); + +private Q_SLOTS: + void doUpdate(); + +private: + void generateRoundedRect(); + void generateBorderedRect(); + void drawRect(QPainter &painter); + +protected: + QmlGraphicsRect(QmlGraphicsRectPrivate &dd, QmlGraphicsItem *parent); + +private: + Q_DISABLE_COPY(QmlGraphicsRect) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRect) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsPen) +QML_DECLARE_TYPE(QmlGraphicsGradientStop) +QML_DECLARE_TYPE(QmlGraphicsGradient) +QML_DECLARE_TYPE(QmlGraphicsRect) + +QT_END_HEADER + +#endif // QMLGRAPHICSRECT_H diff --git a/src/declarative/fx/qmlgraphicsrect_p.h b/src/declarative/fx/qmlgraphicsrect_p.h new file mode 100644 index 0000000..f44e8de --- /dev/null +++ b/src/declarative/fx/qmlgraphicsrect_p.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSRECT_P_H +#define QMLGRAPHICSRECT_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 "qmlgraphicsitem_p.h" + +QT_BEGIN_NAMESPACE + +class QmlGraphicsGradient; +class QmlGraphicsRect; +class QmlGraphicsRectPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsRect) + +public: + QmlGraphicsRectPrivate() : + color(Qt::white), gradient(0), pen(0), radius(0), paintmargin(0) + { + } + + ~QmlGraphicsRectPrivate() + { + delete pen; + } + + void init() + { + } + + QColor getColor(); + QColor color; + QmlGraphicsGradient *gradient; + QmlGraphicsPen *getPen() { + if (!pen) { + Q_Q(QmlGraphicsRect); + pen = new QmlGraphicsPen; + QObject::connect(pen, SIGNAL(penChanged()), q, SLOT(doUpdate())); + } + return pen; + } + QmlGraphicsPen *pen; + qreal radius; + qreal paintmargin; + QPixmap rectImage; + + void setPaintMargin(qreal margin) + { + Q_Q(QmlGraphicsRect); + if (margin == paintmargin) + return; + q->prepareGeometryChange(); + paintmargin = margin; + } +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSRECT_P_H diff --git a/src/declarative/fx/qmlgraphicsrepeater.cpp b/src/declarative/fx/qmlgraphicsrepeater.cpp new file mode 100644 index 0000000..608f948 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsrepeater.cpp @@ -0,0 +1,320 @@ +/**************************************************************************** +** +** 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 "qmlgraphicsrepeater.h" +#include "qmlgraphicsrepeater_p.h" +#include "qmllistaccessor.h" +#include "qmlgraphicsvisualitemmodel.h" +#include + + +QT_BEGIN_NAMESPACE +QmlGraphicsRepeaterPrivate::QmlGraphicsRepeaterPrivate() +: model(0), ownModel(false) +{ +} + +QmlGraphicsRepeaterPrivate::~QmlGraphicsRepeaterPrivate() +{ +} + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Repeater,QmlGraphicsRepeater) + +/*! + \qmlclass Repeater + \inherits Item + + \brief The Repeater item allows you to repeat a component based on a model. + + The Repeater item is used when you want to create a large number of + similar items. For each entry in the model, an item is instantiated + in a context seeded with data from the model. If the repeater will + be instantiating a large number of instances, it may be more efficient to + use one of Qt Declarative's \l {xmlViews}{view items}. + + The model may be either an object list, a string list, a number or a Qt model. + In each case, the data element and the index is exposed to each instantiated + component. + + The index is always exposed as an accessible \c index property. + In the case of an object or string list, the data element (of type string + or object) is available as the \c modelData property. In the case of a Qt model, + all roles are available as named properties just like in the view classes. The + following example shows how to use the index property inside the instantiated + items. + + \snippet doc/src/snippets/declarative/repeater-index.qml 0 + + \image repeater-index.png + + Items instantiated by the Repeater are inserted, in order, as + children of the Repeater's parent. The insertion starts immediately after + the repeater's position in its parent stacking list. This is to allow + you to use a Repeater inside a layout. The following QML example shows how + the instantiated items would visually appear stacked between the red and + blue rectangles. + + \snippet doc/src/snippets/declarative/repeater.qml 0 + + \image repeater.png + + The repeater instance continues to own all items it instantiates, even + if they are otherwise manipulated. It is illegal to manually remove an item + created by the Repeater. + */ + +/*! + \internal + \class QmlGraphicsRepeater + \qmlclass Repeater + + XXX Repeater is very conservative in how it instatiates/deletes items. Also + new model entries will not be created and old ones will not be removed. + */ + +/*! + Create a new QmlGraphicsRepeater instance. + */ +QmlGraphicsRepeater::QmlGraphicsRepeater(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsRepeaterPrivate), parent) +{ +} + +/*! + \internal + */ +QmlGraphicsRepeater::QmlGraphicsRepeater(QmlGraphicsRepeaterPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ +} + +/*! + Destroy the repeater instance. All items it instantiated are also + destroyed. + */ +QmlGraphicsRepeater::~QmlGraphicsRepeater() +{ +} + +/*! + \qmlproperty any Repeater::model + + The model providing data for the repeater. + + The model may be either an object list, a string list, a number or a Qt model. + In each case, the data element and the index is exposed to each instantiated + component. The index is always exposed as an accessible \c index property. + In the case of an object or string list, the data element (of type string + or object) is available as the \c modelData property. In the case of a Qt model, + all roles are available as named properties just like in the view classes. + + As a special case the model can also be merely a number. In this case it will + create that many instances of the component. They will also be assigned an index + based on the order they are created. + + Models can also be created directly in QML, using a \l{ListModel} or \l{XmlListModel}. + + \sa {qmlmodels}{Data Models} +*/ +QVariant QmlGraphicsRepeater::model() const +{ + Q_D(const QmlGraphicsRepeater); + return d->dataSource; +} + +void QmlGraphicsRepeater::setModel(const QVariant &model) +{ + Q_D(QmlGraphicsRepeater); + clear(); + if (d->model) { + disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); + disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + /* + disconnect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + disconnect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); + */ + } + d->dataSource = model; + QObject *object = qvariant_cast(model); + QmlGraphicsVisualModel *vim = 0; + if (object && (vim = qobject_cast(object))) { + if (d->ownModel) { + delete d->model; + d->ownModel = false; + } + d->model = vim; + } else { + if (!d->ownModel) { + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); + d->ownModel = true; + } + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) + dataModel->setModel(model); + } + if (d->model) { + connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); + connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); + connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + /* + connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); + connect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); + */ + regenerate(); + emit countChanged(); + } +} + +/*! + \qmlproperty Component Repeater::delegate + \default + + The delegate provides a template describing what each item instantiated by the repeater should look and act like. + */ +QmlComponent *QmlGraphicsRepeater::delegate() const +{ + Q_D(const QmlGraphicsRepeater); + if (d->model) { + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) + return dataModel->delegate(); + } + + return 0; +} + +void QmlGraphicsRepeater::setDelegate(QmlComponent *delegate) +{ + Q_D(QmlGraphicsRepeater); + if (!d->ownModel) { + d->model = new QmlGraphicsVisualDataModel(qmlContext(this)); + d->ownModel = true; + } + if (QmlGraphicsVisualDataModel *dataModel = qobject_cast(d->model)) { + dataModel->setDelegate(delegate); + regenerate(); + } +} + +/*! + \qmlproperty int Repeater::count + + This property holds the number of items in the repeater. +*/ +int QmlGraphicsRepeater::count() const +{ + Q_D(const QmlGraphicsRepeater); + if (d->model) + return d->model->count(); + return 0; +} + + +/*! + \internal + */ +void QmlGraphicsRepeater::componentComplete() +{ + QmlGraphicsItem::componentComplete(); + regenerate(); +} + +/*! + \internal + */ +QVariant QmlGraphicsRepeater::itemChange(GraphicsItemChange change, + const QVariant &value) +{ + QVariant rv = QmlGraphicsItem::itemChange(change, value); + if (change == ItemParentHasChanged) { + regenerate(); + } + + return rv; +} + +void QmlGraphicsRepeater::clear() +{ + Q_D(QmlGraphicsRepeater); + if (d->model) { + foreach (QmlGraphicsItem *item, d->deletables) + d->model->release(item); + } + d->deletables.clear(); +} + +/*! + \internal + */ +void QmlGraphicsRepeater::regenerate() +{ + Q_D(QmlGraphicsRepeater); + + clear(); + + if (!d->model || !d->model->count() || !d->model->isValid() || !parentItem() || !isComponentComplete()) + return; + + for (int ii = 0; ii < count(); ++ii) { + QmlGraphicsItem *item = d->model->item(ii); + if (item) { + item->setParent(parentItem()); + item->stackBefore(this); + d->deletables << item; + } + } +} + +void QmlGraphicsRepeater::itemsInserted(int, int) +{ + regenerate(); +} + +void QmlGraphicsRepeater::itemsRemoved(int, int) +{ + regenerate(); +} + +void QmlGraphicsRepeater::itemsMoved(int,int,int) +{ + regenerate(); +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsrepeater.h b/src/declarative/fx/qmlgraphicsrepeater.h new file mode 100644 index 0000000..9cb7d45 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsrepeater.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSREPEATER_H +#define QMLGRAPHICSREPEATER_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsRepeaterPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsRepeater : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(QVariant model READ model WRITE setModel) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_CLASSINFO("DefaultProperty", "delegate") + +public: + QmlGraphicsRepeater(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsRepeater(); + + QVariant model() const; + void setModel(const QVariant &); + + QmlComponent *delegate() const; + void setDelegate(QmlComponent *); + + int count() const; + +Q_SIGNALS: + void countChanged(); + +private: + void clear(); + void regenerate(); + +protected: + virtual void componentComplete(); + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + QmlGraphicsRepeater(QmlGraphicsRepeaterPrivate &dd, QmlGraphicsItem *parent); + +private Q_SLOTS: + void itemsInserted(int,int); + void itemsRemoved(int,int); + void itemsMoved(int,int,int); + +private: + Q_DISABLE_COPY(QmlGraphicsRepeater) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRepeater) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsRepeater) + +QT_END_HEADER + +#endif // QMLGRAPHICSREPEATER_H diff --git a/src/declarative/fx/qmlgraphicsrepeater_p.h b/src/declarative/fx/qmlgraphicsrepeater_p.h new file mode 100644 index 0000000..7c111da --- /dev/null +++ b/src/declarative/fx/qmlgraphicsrepeater_p.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSREPEATER_P_H +#define QMLGRAPHICSREPEATER_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 "qmlgraphicsitem_p.h" +#include "qmlgraphicsrepeater.h" +#include + + +QT_BEGIN_NAMESPACE + +class QmlContext; +class QmlGraphicsVisualModel; +class QmlGraphicsRepeaterPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsRepeater) + +public: + QmlGraphicsRepeaterPrivate(); + ~QmlGraphicsRepeaterPrivate(); + + QmlGraphicsVisualModel *model; + QVariant dataSource; + bool ownModel; + + QList > deletables; +}; + +QT_END_NAMESPACE +#endif // QMLGRAPHICSREPEATER_P_H diff --git a/src/declarative/fx/qmlgraphicsscalegrid.cpp b/src/declarative/fx/qmlgraphicsscalegrid.cpp new file mode 100644 index 0000000..fdf44cf --- /dev/null +++ b/src/declarative/fx/qmlgraphicsscalegrid.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 +#include +#include +#include "qmlgraphicsscalegrid_p.h" + + +QT_BEGIN_NAMESPACE +/*! + \internal + \class QmlGraphicsScaleGrid + \brief The QmlGraphicsScaleGrid class allows you to specify a 3x3 grid to use in scaling an image. +*/ +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsScaleGrid) + +QmlGraphicsScaleGrid::QmlGraphicsScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0) +{ +} + +QmlGraphicsScaleGrid::~QmlGraphicsScaleGrid() +{ +} + +bool QmlGraphicsScaleGrid::isNull() const +{ + return !_left && !_top && !_right && !_bottom; +} + +void QmlGraphicsScaleGrid::setLeft(int pos) +{ + if (_left != pos) { + _left = pos; + emit borderChanged(); + } +} + +void QmlGraphicsScaleGrid::setTop(int pos) +{ + if (_top != pos) { + _top = pos; + emit borderChanged(); + } +} + +void QmlGraphicsScaleGrid::setRight(int pos) +{ + if (_right != pos) { + _right = pos; + emit borderChanged(); + } +} + +void QmlGraphicsScaleGrid::setBottom(int pos) +{ + if (_bottom != pos) { + _bottom = pos; + emit borderChanged(); + } +} + +QmlGraphicsGridScaledImage::QmlGraphicsGridScaledImage() +: _l(-1), _r(-1), _t(-1), _b(-1), + _h(QmlGraphicsBorderImage::Stretch), _v(QmlGraphicsBorderImage::Stretch) +{ +} + +QmlGraphicsGridScaledImage::QmlGraphicsGridScaledImage(const QmlGraphicsGridScaledImage &o) +: _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix) +{ +} + +QmlGraphicsGridScaledImage &QmlGraphicsGridScaledImage::operator=(const QmlGraphicsGridScaledImage &o) +{ + _l = o._l; + _r = o._r; + _t = o._t; + _b = o._b; + _h = o._h; + _v = o._v; + _pix = o._pix; + return *this; +} + +QmlGraphicsGridScaledImage::QmlGraphicsGridScaledImage(QIODevice *data) +: _l(-1), _r(-1), _t(-1), _b(-1), _h(QmlGraphicsBorderImage::Stretch), _v(QmlGraphicsBorderImage::Stretch) +{ + int l = -1; + int r = -1; + int t = -1; + int b = -1; + QString imgFile; + + while(!data->atEnd()) { + QString line = QString::fromUtf8(data->readLine().trimmed()); + if (line.isEmpty() || line.startsWith(QLatin1String("#"))) + continue; + + QStringList list = line.split(QLatin1Char(':')); + if (list.count() != 2) + return; + + list[0] = list[0].trimmed(); + list[1] = list[1].trimmed(); + + if (list[0] == QLatin1String("border.left")) + l = list[1].toInt(); + else if (list[0] == QLatin1String("border.right")) + r = list[1].toInt(); + else if (list[0] == QLatin1String("border.top")) + t = list[1].toInt(); + else if (list[0] == QLatin1String("border.bottom")) + b = list[1].toInt(); + else if (list[0] == QLatin1String("source")) + imgFile = list[1]; + else if (list[0] == QLatin1String("horizontalTileRule")) + _h = stringToRule(list[1]); + else if (list[0] == QLatin1String("verticalTileRule")) + _v = stringToRule(list[1]); + } + + if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty()) + return; + + _l = l; _r = r; _t = t; _b = b; + + _pix = imgFile; +} + +QmlGraphicsBorderImage::TileMode QmlGraphicsGridScaledImage::stringToRule(const QString &s) +{ + if (s == QLatin1String("Stretch")) + return QmlGraphicsBorderImage::Stretch; + if (s == QLatin1String("Repeat")) + return QmlGraphicsBorderImage::Repeat; + if (s == QLatin1String("Round")) + return QmlGraphicsBorderImage::Round; + + qWarning() << "Unknown tile rule specified. Using Stretch"; + return QmlGraphicsBorderImage::Stretch; +} + +bool QmlGraphicsGridScaledImage::isValid() const +{ + return _l >= 0; +} + +int QmlGraphicsGridScaledImage::gridLeft() const +{ + return _l; +} + +int QmlGraphicsGridScaledImage::gridRight() const +{ + return _r; +} + +int QmlGraphicsGridScaledImage::gridTop() const +{ + return _t; +} + +int QmlGraphicsGridScaledImage::gridBottom() const +{ + return _b; +} + +QString QmlGraphicsGridScaledImage::pixmapUrl() const +{ + return _pix; +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsscalegrid_p.h b/src/declarative/fx/qmlgraphicsscalegrid_p.h new file mode 100644 index 0000000..040db4c --- /dev/null +++ b/src/declarative/fx/qmlgraphicsscalegrid_p.h @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSSCALEGRID_H +#define QMLGRAPHICSSCALEGRID_H + +#include +#include +#include +#include +#include +#include "qmlgraphicsborderimage.h" + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class Q_DECLARATIVE_EXPORT QmlGraphicsScaleGrid : public QObject +{ + Q_OBJECT + Q_ENUMS(TileRule) + + Q_PROPERTY(int left READ left WRITE setLeft NOTIFY borderChanged) + Q_PROPERTY(int top READ top WRITE setTop NOTIFY borderChanged) + Q_PROPERTY(int right READ right WRITE setRight NOTIFY borderChanged) + Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY borderChanged) + +public: + QmlGraphicsScaleGrid(QObject *parent=0); + ~QmlGraphicsScaleGrid(); + + bool isNull() const; + + int left() const { return _left; } + void setLeft(int); + + int top() const { return _top; } + void setTop(int); + + int right() const { return _right; } + void setRight(int); + + int bottom() const { return _bottom; } + void setBottom(int); + +Q_SIGNALS: + void borderChanged(); + +private: + int _left; + int _top; + int _right; + int _bottom; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGridScaledImage +{ +public: + QmlGraphicsGridScaledImage(); + QmlGraphicsGridScaledImage(const QmlGraphicsGridScaledImage &); + QmlGraphicsGridScaledImage(QIODevice*); + QmlGraphicsGridScaledImage &operator=(const QmlGraphicsGridScaledImage &); + bool isValid() const; + int gridLeft() const; + int gridRight() const; + int gridTop() const; + int gridBottom() const; + QmlGraphicsBorderImage::TileMode horizontalTileRule() const { return _h; } + QmlGraphicsBorderImage::TileMode verticalTileRule() const { return _v; } + + QString pixmapUrl() const; + +private: + static QmlGraphicsBorderImage::TileMode stringToRule(const QString &); + +private: + int _l; + int _r; + int _t; + int _b; + QmlGraphicsBorderImage::TileMode _h; + QmlGraphicsBorderImage::TileMode _v; + QString _pix; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsScaleGrid) + +QT_END_HEADER + +#endif // QMLGRAPHICSSCALEGRID_H diff --git a/src/declarative/fx/qmlgraphicstext.cpp b/src/declarative/fx/qmlgraphicstext.cpp new file mode 100644 index 0000000..f5ea55f --- /dev/null +++ b/src/declarative/fx/qmlgraphicstext.cpp @@ -0,0 +1,840 @@ +/**************************************************************************** +** +** 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 "qmlgraphicstext.h" +#include "qmlgraphicstext_p.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Text,QmlGraphicsText) + +/*! + \qmlclass Text QmlGraphicsText + \brief The Text item allows you to add formatted text to a scene. + \inherits Item + + It can display both plain and rich text. For example: + + \qml + Text { text: "Hello World!"; font.family: "Helvetica"; font.pointSize: 24; color: "red" } + Text { text: "Hello World!" } + \endqml + + \image declarative-text.png + + If height and width are not explicitly set, Text will attempt to determine how + much room is needed and set it accordingly. Unless \c wrap is set, it will always + prefer width to height (all text will be placed on a single line). + + The \c elide property can alternatively be used to fit a single line of + plain text to a set width. + + Text provides read-only text. For editable text, see \l TextEdit. +*/ + +/*! + \internal + \class QmlGraphicsText + \qmlclass Text + \ingroup group_coreitems + + \brief The QmlGraphicsText class provides a formatted text item that you can add to a QmlView. + + Text was designed for read-only text; it does not allow for any text editing. + It can display both plain and rich text. For example: + + \qml + Text { text: "Hello World!"; font.family: "Helvetica"; font.pointSize: 24; color: "red" } + Text { text: "Hello World!" } + \endqml + + \image text.png + + If height and width are not explicitly set, Text will attempt to determine how + much room is needed and set it accordingly. Unless \c wrap is set, it will always + prefer width to height (all text will be placed on a single line). + + The \c elide property can alternatively be used to fit a line of plain text to a set width. + + A QmlGraphicsText object can be instantiated in Qml using the tag \c Text. +*/ +QmlGraphicsText::QmlGraphicsText(QmlGraphicsItem *parent) + : QmlGraphicsItem(*(new QmlGraphicsTextPrivate), parent) +{ + setAcceptedMouseButtons(Qt::LeftButton); + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QmlGraphicsText::QmlGraphicsText(QmlGraphicsTextPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsItem(dd, parent) +{ + setAcceptedMouseButtons(Qt::LeftButton); + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +QmlGraphicsText::~QmlGraphicsText() +{ +} + +/*! + \qmlproperty string Text::font.family + \qmlproperty bool Text::font.bold + \qmlproperty bool Text::font.italic + \qmlproperty bool Text::font.underline + \qmlproperty real Text::font.pointSize + \qmlproperty int Text::font.pixelSize + + Set the Text's font attributes. +*/ +QFont QmlGraphicsText::font() const +{ + Q_D(const QmlGraphicsText); + return d->font; +} + +void QmlGraphicsText::setFont(const QFont &font) +{ + Q_D(QmlGraphicsText); + d->font = font; + + d->imgDirty = true; + d->updateSize(); + update(); +} + +void QmlGraphicsText::setText(const QString &n) +{ +#ifdef Q_ENABLE_PERFORMANCE_LOG + QmlPerfTimer st; +#endif + Q_D(QmlGraphicsText); + if (d->text == n) + return; + + d->richText = d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(n)); + if (d->richText) { + if (!d->doc) + { + d->control = new QTextControl(this); + d->control->setTextInteractionFlags(Qt::TextBrowserInteraction); + d->doc = d->control->document(); + d->doc->setDocumentMargin(0); + } + d->doc->setHtml(n); + } + + d->text = n; + d->imgDirty = true; + d->updateSize(); + emit textChanged(d->text); + update(); +} + +/*! + \qmlproperty string Text::text + + The text to display. Text supports both plain and rich text strings. + + The item will try to automatically determine whether the text should + be treated as rich text. This determination is made using Qt::mightBeRichText(). +*/ +QString QmlGraphicsText::text() const +{ + Q_D(const QmlGraphicsText); + return d->text; +} + +void QmlGraphicsText::setColor(const QColor &color) +{ + Q_D(QmlGraphicsText); + if (d->color == color) + return; + + d->imgDirty = true; + d->color = color; + update(); +} + +/*! + \qmlproperty color Text::color + + The text color. + + \qml + //green text using hexadecimal notation + Text { color: "#00FF00"; ... } + + //steelblue text using SVG color name + Text { color: "steelblue"; ... } + \endqml +*/ + +QColor QmlGraphicsText::color() const +{ + Q_D(const QmlGraphicsText); + return d->color; +} + +/*! + \qmlproperty enumeration Text::style + + Set an additional text style. + + Supported text styles are \c Normal, \c Outline, \c Raised and \c Sunken. + + \qml + Row { + Text { font.pointSize: 24; text: "Normal" } + Text { font.pointSize: 24; text: "Raised"; style: Text.Raised; styleColor: "#AAAAAA" } + Text { font.pointSize: 24; text: "Outline"; style: Text.Outline; styleColor: "red" } + Text { font.pointSize: 24; text: "Sunken"; style: Text.Sunken; styleColor: "#AAAAAA" } + } + \endqml + + \image declarative-textstyle.png +*/ +QmlGraphicsText::TextStyle QmlGraphicsText::style() const +{ + Q_D(const QmlGraphicsText); + return d->style; +} + +void QmlGraphicsText::setStyle(QmlGraphicsText::TextStyle style) +{ + Q_D(QmlGraphicsText); + if (d->style == style) + return; + + d->imgDirty = true; + d->style = style; + update(); +} + +void QmlGraphicsText::setStyleColor(const QColor &color) +{ + Q_D(QmlGraphicsText); + if (d->styleColor == color) + return; + + d->imgDirty = true; + d->styleColor = color; + update(); +} + +/*! + \qmlproperty color Text::styleColor + + Defines the secondary color used by text styles. + + \c styleColor is used as the outline color for outlined text, and as the + shadow color for raised or sunken text. If no style has been set, it is not + used at all. + */ +QColor QmlGraphicsText::styleColor() const +{ + Q_D(const QmlGraphicsText); + return d->styleColor; +} + +/*! + \qmlproperty enumeration Text::horizontalAlignment + \qmlproperty enumeration Text::verticalAlignment + + Sets the horizontal and vertical alignment of the text within the Text items + width and height. By default, the text is top-left aligned. + + The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and + \c AlignHCenter. The valid values for \c verticalAlignment are \c AlignTop, \c AlignBottom + and \c AlignVCenter. +*/ +QmlGraphicsText::HAlignment QmlGraphicsText::hAlign() const +{ + Q_D(const QmlGraphicsText); + return d->hAlign; +} + +void QmlGraphicsText::setHAlign(HAlignment align) +{ + Q_D(QmlGraphicsText); + d->hAlign = align; +} + +QmlGraphicsText::VAlignment QmlGraphicsText::vAlign() const +{ + Q_D(const QmlGraphicsText); + return d->vAlign; +} + +void QmlGraphicsText::setVAlign(VAlignment align) +{ + Q_D(QmlGraphicsText); + d->vAlign = align; +} + +/*! + \qmlproperty bool Text::wrap + + Set this property to wrap the text to the Text item's width. The text will only + wrap if an explicit width has been set. + + Wrapping is done on word boundaries (i.e. it is a "word-wrap"). If the text cannot be + word-wrapped to the specified width it will be partially drawn outside of the item's bounds. + If this is undesirable then enable clipping on the item (Item::clip). + + Wrapping is off by default. +*/ +//### Future may provide choice of wrap modes, such as QTextOption::WrapAtWordBoundaryOrAnywhere +bool QmlGraphicsText::wrap() const +{ + Q_D(const QmlGraphicsText); + return d->wrap; +} + +void QmlGraphicsText::setWrap(bool w) +{ + Q_D(QmlGraphicsText); + if (w == d->wrap) + return; + + d->wrap = w; + + d->imgDirty = true; + d->updateSize(); +} + +/*! + \qmlproperty enumeration Text::textFormat + + The way the text property should be displayed. + + Supported text formats are \c AutoText, \c PlainText and \c RichText. + + The default is AutoText. If the text format is AutoText the text element + will automatically determine whether the text should be treated as + rich text. This determination is made using Qt::mightBeRichText(). + + \table + \row + \o + \qml +Column { + TextEdit { + font.pointSize: 24 + text: "Hello World!" + } + TextEdit { + font.pointSize: 24 + textFormat: "RichText" + text: "Hello World!" + } + TextEdit { + font.pointSize: 24 + textFormat: "PlainText" + text: "Hello World!" + } +} + \endqml + \o \image declarative-textformat.png + \endtable +*/ + +QmlGraphicsText::TextFormat QmlGraphicsText::textFormat() const +{ + Q_D(const QmlGraphicsText); + return d->format; +} + +void QmlGraphicsText::setTextFormat(TextFormat format) +{ + Q_D(QmlGraphicsText); + if (format == d->format) + return; + bool wasRich = d->richText; + d->richText = format == RichText || (format == AutoText && Qt::mightBeRichText(d->text)); + + if (wasRich && !d->richText) { + //### delete control? (and vice-versa below) + d->imgDirty = true; + d->updateSize(); + update(); + } else if (!wasRich && d->richText) { + if (!d->doc) + { + d->control = new QTextControl(this); + d->control->setTextInteractionFlags(Qt::TextBrowserInteraction); + d->doc = d->control->document(); + d->doc->setDocumentMargin(0); + } + d->doc->setHtml(d->text); + d->imgDirty = true; + d->updateSize(); + update(); + } + d->format = format; +} + +/*! + \qmlproperty enumeration Text::elide + + Set this property to elide parts of the text fit to the Text item's width. + The text will only elide if an explicit width has been set. + + This property cannot be used with wrap enabled or with rich text. + + Eliding can be \c ElideNone (the default), \c ElideLeft, \c ElideMiddle, or \c ElideRight. + + If the text is a multi-length string, and the mode is not \c ElideNone, + the first string that fits will be used, otherwise the last will be elided. + + Multi-length strings are ordered from longest to shortest, separated by the + Unicode "String Terminator" character \c U009C (write this in QML with \c{"\\x9C"}). +*/ +QmlGraphicsText::TextElideMode QmlGraphicsText::elideMode() const +{ + Q_D(const QmlGraphicsText); + return d->elideMode; +} + +void QmlGraphicsText::setElideMode(QmlGraphicsText::TextElideMode mode) +{ + Q_D(QmlGraphicsText); + if (mode == d->elideMode) + return; + + d->elideMode = mode; + + d->imgDirty = true; + d->updateSize(); +} + +void QmlGraphicsText::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) +{ + Q_D(QmlGraphicsText); + if (newGeometry.width() != oldGeometry.width()) { + if (d->wrap || d->elideMode != QmlGraphicsText::ElideNone) { + d->imgDirty = true; + d->updateSize(); + } + } + QmlGraphicsItem::geometryChanged(newGeometry, oldGeometry); +} + +void QmlGraphicsTextPrivate::updateSize() +{ + Q_Q(QmlGraphicsText); + if (q->isComponentComplete()) { + QFontMetrics fm(font); + if (text.isEmpty()) { + q->setImplicitHeight(fm.height()); + return; + } + + int dy = q->height(); + QString tmp; + QSize size(0, 0); + + //setup instance of QTextLayout for all cases other than richtext + if (!richText) + { + tmp = text; + tmp.replace(QLatin1Char('\n'), QChar::LineSeparator); + singleline = !tmp.contains(QChar::LineSeparator); + if (singleline && elideMode != QmlGraphicsText::ElideNone && q->widthValid()) + tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); // XXX still worth layout...? + layout.clearLayout(); + layout.setFont(font); + layout.setText(tmp); + size = setupTextLayout(&layout); + cachedLayoutSize = size; + } + if (richText) { + singleline = false; // richtext can't elide or be optimized for single-line case + doc->setDefaultFont(font); + QTextOption option((Qt::Alignment)int(hAlign | vAlign)); + if (wrap) + option.setWrapMode(QTextOption::WordWrap); + else + option.setWrapMode(QTextOption::NoWrap); + doc->setDefaultTextOption(option); + if (wrap && !q->heightValid() && q->widthValid()) + doc->setTextWidth(q->width()); + else + doc->setTextWidth(doc->idealWidth()); // ### Text does not align if width is not set (QTextDoc bug) + dy -= (int)doc->size().height(); + } else { + dy -= size.height(); + } + int yoff = 0; + + if (q->heightValid()) { + if (vAlign == QmlGraphicsText::AlignBottom) + yoff = dy; + else if (vAlign == QmlGraphicsText::AlignVCenter) + yoff = dy/2; + } + q->setBaselineOffset(fm.ascent() + yoff); + + //### need to comfirm cost of always setting these for richText + q->setImplicitWidth(richText ? (int)doc->idealWidth() : size.width()); + q->setImplicitHeight(richText ? (int)doc->size().height() : size.height()); + } else { + dirty = true; + } +} + +// ### text layout handling should be profiled and optimized as needed +// what about QStackTextEngine engine(tmp, d->font.font()); QTextLayout textLayout(&engine); + +void QmlGraphicsTextPrivate::drawOutline() +{ + QPixmap img = QPixmap(imgCache.size()); + img.fill(Qt::transparent); + + QPainter ppm(&img); + + QPoint pos(imgCache.rect().topLeft()); + pos += QPoint(-1, 0); + ppm.drawPixmap(pos, imgStyleCache); + pos += QPoint(2, 0); + ppm.drawPixmap(pos, imgStyleCache); + pos += QPoint(-1, -1); + ppm.drawPixmap(pos, imgStyleCache); + pos += QPoint(0, 2); + ppm.drawPixmap(pos, imgStyleCache); + + pos += QPoint(0, -1); + ppm.drawPixmap(pos, imgCache); + ppm.end(); + + imgCache = img; +} + +void QmlGraphicsTextPrivate::drawOutline(int yOffset) +{ + QPixmap img = QPixmap(imgCache.size()); + img.fill(Qt::transparent); + + QPainter ppm(&img); + + QPoint pos(imgCache.rect().topLeft()); + pos += QPoint(0, yOffset); + ppm.drawPixmap(pos, imgStyleCache); + + pos += QPoint(0, -yOffset); + ppm.drawPixmap(pos, imgCache); + ppm.end(); + + imgCache = img; +} + +QSize QmlGraphicsTextPrivate::setupTextLayout(QTextLayout *layout) +{ + Q_Q(QmlGraphicsText); + layout->setCacheEnabled(true); + + QFontMetrics fm = QFontMetrics(font); + + int height = 0; + qreal widthUsed = 0; + qreal lineWidth = 0; + + //set manual width + if ((wrap || elideMode != QmlGraphicsText::ElideNone) && q->widthValid()) + lineWidth = q->width(); + + layout->beginLayout(); + + while (1) { + QTextLine line = layout->createLine(); + if (!line.isValid()) + break; + + if ((wrap || elideMode != QmlGraphicsText::ElideNone) && q->widthValid()) + line.setLineWidth(lineWidth); + } + layout->endLayout(); + + for (int i = 0; i < layout->lineCount(); ++i) { + QTextLine line = layout->lineAt(i); + widthUsed = qMax(widthUsed, line.naturalTextWidth()); + line.setPosition(QPointF(0, height)); + height += int(line.height()); + } + return QSize((int)widthUsed, height); +} + +QPixmap QmlGraphicsTextPrivate::wrappedTextImage(bool drawStyle) +{ + //do layout + QSize size = cachedLayoutSize; + + int x = 0; + for (int i = 0; i < layout.lineCount(); ++i) { + QTextLine line = layout.lineAt(i); + if (hAlign == QmlGraphicsText::AlignLeft) { + x = 0; + } else if (hAlign == QmlGraphicsText::AlignRight) { + x = size.width() - (int)line.naturalTextWidth(); + } else if (hAlign == QmlGraphicsText::AlignHCenter) { + x = (size.width() - (int)line.naturalTextWidth()) / 2; + } + line.setPosition(QPoint(x, (int)line.y())); + } + + //paint text + QPixmap img(size); + if (!size.isEmpty()) { + img.fill(Qt::transparent); + QPainter p(&img); + if (drawStyle) { + p.setPen(styleColor); + } + else + p.setPen(color); + p.setFont(font); + layout.draw(&p, QPointF(0, 0)); + } + return img; +} + +QPixmap QmlGraphicsTextPrivate::richTextImage(bool drawStyle) +{ + QSize size = doc->size().toSize(); + + //paint text + QPixmap img(size); + img.fill(Qt::transparent); + QPainter p(&img); + + if (drawStyle) { + QPalette pal = control->palette(); + pal.setColor(QPalette::Text, styleColor); + control->setPalette(pal); + QTextOption colorOption; + colorOption.setFlags(QTextOption::SuppressColors); + doc->setDefaultTextOption(colorOption); + } else { + QPalette pal = control->palette(); + pal.setColor(QPalette::Text, color); + control->setPalette(pal); + } + control->drawContents(&p, QRectF(QPointF(0, 0), QSizeF(size))); + if (drawStyle) + doc->setDefaultTextOption(QTextOption()); + return img; +} + +void QmlGraphicsTextPrivate::checkImgCache() +{ + if (!imgDirty) + return; + + bool empty = text.isEmpty(); + if (empty) { + imgCache = QPixmap(); + imgStyleCache = QPixmap(); + } else if (richText) { + imgCache = richTextImage(false); + if (style != QmlGraphicsText::Normal) + imgStyleCache = richTextImage(true); //### should use styleColor + } else { + imgCache = wrappedTextImage(false); + if (style != QmlGraphicsText::Normal) + imgStyleCache = wrappedTextImage(true); //### should use styleColor + } + if (!empty) + switch (style) { + case QmlGraphicsText::Outline: + drawOutline(); + break; + case QmlGraphicsText::Sunken: + drawOutline(-1); + break; + case QmlGraphicsText::Raised: + drawOutline(1); + break; + default: + break; + } + + imgDirty = false; +} + +void QmlGraphicsText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + Q_D(QmlGraphicsText); + d->checkImgCache(); + if (d->imgCache.isNull()) + return; + + bool oldAA = p->testRenderHint(QPainter::Antialiasing); + bool oldSmooth = p->testRenderHint(QPainter::SmoothPixmapTransform); + if (d->smooth) + p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); + + int w = width(); + int h = height(); + + int x = 0; + int y = 0; + + switch (d->hAlign) { + case AlignLeft: + x = 0; + break; + case AlignRight: + x = w - d->imgCache.width(); + break; + case AlignHCenter: + x = (w - d->imgCache.width()) / 2; + break; + } + + switch (d->vAlign) { + case AlignTop: + y = 0; + break; + case AlignBottom: + y = h - d->imgCache.height(); + break; + case AlignVCenter: + y = (h - d->imgCache.height()) / 2; + break; + } + + bool needClip = !clip() && (d->imgCache.width() > width() || + d->imgCache.height() > height()); + + if (needClip) { + p->save(); + p->setClipRect(boundingRect(), Qt::IntersectClip); + } + p->drawPixmap(x, y, d->imgCache); + if (needClip) + p->restore(); + + if (d->smooth) { + p->setRenderHint(QPainter::Antialiasing, oldAA); + p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); + } +} + +/*! + \qmlproperty bool Text::smooth + + Set this property if you want the text to be smoothly scaled or + transformed. Smooth filtering gives better visual quality, but is slower. If + the item is displayed at its natural size, this property has no visual or + performance effect. + + \note Generally scaling artifacts are only visible if the item is stationary on + the screen. A common pattern when animating an item is to disable smooth + filtering at the beginning of the animation and reenable it at the conclusion. +*/ + +void QmlGraphicsText::componentComplete() +{ + Q_D(QmlGraphicsText); +#ifdef Q_ENABLE_PERFORMANCE_LOG + QmlPerfTimer cc; +#endif + QmlGraphicsItem::componentComplete(); + if (d->dirty) { + d->updateSize(); + d->dirty = false; + } +} + +/*! + \overload + Handles the given mouse \a event. + */ +void QmlGraphicsText::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsText); + + if (!d->richText || !d->doc || d->control->anchorAt(event->pos()).isEmpty()) { + event->setAccepted(false); + d->activeLink = QString(); + } else { + d->activeLink = d->control->anchorAt(event->pos()); + } + + // ### may malfunction if two of the same links are clicked & dragged onto each other) + + if (!event->isAccepted()) + QmlGraphicsItem::mousePressEvent(event); + +} + +/*! + \qmlsignal Text::linkActivated(link) + + This handler is called when the user clicks on a link embedded in the text. +*/ + +/*! + \overload + Handles the given mouse \a event. + */ +void QmlGraphicsText::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsText); + + // ### confirm the link, and send a signal out + if (d->richText && d->doc && d->activeLink == d->control->anchorAt(event->pos())) + emit linkActivated(d->activeLink); + else + event->setAccepted(false); + + if (!event->isAccepted()) + QmlGraphicsItem::mouseReleaseEvent(event); +} +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicstext.h b/src/declarative/fx/qmlgraphicstext.h new file mode 100644 index 0000000..619de87 --- /dev/null +++ b/src/declarative/fx/qmlgraphicstext.h @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSTEXT_H +#define QMLGRAPHICSTEXT_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlGraphicsTextPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsText : public QmlGraphicsItem +{ + Q_OBJECT + Q_ENUMS(HAlignment) + Q_ENUMS(VAlignment) + Q_ENUMS(TextStyle) + Q_ENUMS(TextFormat) + Q_ENUMS(TextElideMode) + + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(TextStyle style READ style WRITE setStyle) + Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor) + Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) + Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign) + Q_PROPERTY(bool wrap READ wrap WRITE setWrap) //### there are several wrap modes in Qt + Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) + Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode) //### elideMode? + +public: + QmlGraphicsText(QmlGraphicsItem *parent=0); + ~QmlGraphicsText(); + + enum HAlignment { AlignLeft = Qt::AlignLeft, + AlignRight = Qt::AlignRight, + AlignHCenter = Qt::AlignHCenter }; + enum VAlignment { AlignTop = Qt::AlignTop, + AlignBottom = Qt::AlignBottom, + AlignVCenter = Qt::AlignVCenter }; + enum TextStyle { Normal, + Outline, + Raised, + Sunken }; + enum TextFormat { PlainText = Qt::PlainText, + RichText = Qt::RichText, + AutoText = Qt::AutoText }; + enum TextElideMode { ElideLeft = Qt::ElideLeft, + ElideRight = Qt::ElideRight, + ElideMiddle = Qt::ElideMiddle, + ElideNone = Qt::ElideNone }; + + QString text() const; + void setText(const QString &); + + QFont font() const; + void setFont(const QFont &font); + + QColor color() const; + void setColor(const QColor &c); + + TextStyle style() const; + void setStyle(TextStyle style); + + QColor styleColor() const; + void setStyleColor(const QColor &c); + + HAlignment hAlign() const; + void setHAlign(HAlignment align); + + VAlignment vAlign() const; + void setVAlign(VAlignment align); + + bool wrap() const; + void setWrap(bool w); + + TextFormat textFormat() const; + void setTextFormat(TextFormat format); + + TextElideMode elideMode() const; + void setElideMode(TextElideMode); + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + + virtual void componentComplete(); + +Q_SIGNALS: + void textChanged(const QString &text); + void linkActivated(const QString &link); + +protected: + QmlGraphicsText(QmlGraphicsTextPrivate &dd, QmlGraphicsItem *parent); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + +private: + Q_DISABLE_COPY(QmlGraphicsText) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsText) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsText) + +QT_END_HEADER + +#endif diff --git a/src/declarative/fx/qmlgraphicstext_p.h b/src/declarative/fx/qmlgraphicstext_p.h new file mode 100644 index 0000000..bf14c6f --- /dev/null +++ b/src/declarative/fx/qmlgraphicstext_p.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSTEXT_P_H +#define QMLGRAPHICSTEXT_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 "qmlgraphicsitem.h" +#include "qmlgraphicsitem_p.h" +#include "qml.h" +#include + +QT_BEGIN_NAMESPACE + +class QTextLayout; +class QTextDocument; +class QTextControl; + +class QmlGraphicsTextPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsText) +public: + QmlGraphicsTextPrivate() + : color((QRgb)0), style(QmlGraphicsText::Normal), imgDirty(true), + hAlign(QmlGraphicsText::AlignLeft), vAlign(QmlGraphicsText::AlignTop), elideMode(QmlGraphicsText::ElideNone), + dirty(true), wrap(false), richText(false), singleline(false), control(0), doc(0), + format(QmlGraphicsText::AutoText) + { + } + + void updateSize(); + void checkImgCache(); + + void drawOutline(); + void drawOutline(int yOffset); + + QPixmap wrappedTextImage(bool drawStyle); + QPixmap richTextImage(bool drawStyle); + QSize setupTextLayout(QTextLayout *layout); + + QString text; + QFont font; + QColor color; + QmlGraphicsText::TextStyle style; + QColor styleColor; + QString activeLink; + bool imgDirty; + QPixmap imgCache; + QPixmap imgStyleCache; + QmlGraphicsText::HAlignment hAlign; + QmlGraphicsText::VAlignment vAlign; + QmlGraphicsText::TextElideMode elideMode; + bool dirty; + bool wrap; + bool richText; + bool singleline; + QTextControl *control; + QTextDocument *doc; + QTextLayout layout; + QSize cachedLayoutSize; + QmlGraphicsText::TextFormat format; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/declarative/fx/qmlgraphicstextedit.cpp b/src/declarative/fx/qmlgraphicstextedit.cpp new file mode 100644 index 0000000..24c64c1 --- /dev/null +++ b/src/declarative/fx/qmlgraphicstextedit.cpp @@ -0,0 +1,1085 @@ +/**************************************************************************** +** +** 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 +#include "qmlgraphicstextedit_p.h" +#include +#include +#include "qmlgraphicsevents_p.h" +#include +#include +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,TextEdit,QmlGraphicsTextEdit) + +/*! + \qmlclass TextEdit + \brief The TextEdit item allows you to add editable formatted text to a scene. + + It can display both plain and rich text. For example: + + \qml +TextEdit { + id: edit + text: "Hello World!" + focus: true + font.family: "Helvetica" + font.pointSize: 20 + color: "blue" + width: 240 +} + \endqml + + \image declarative-textedit.gif + + \sa Text +*/ + +/*! + \internal + \class QmlGraphicsTextEdit + \qmlclass TextEdit + \ingroup group_coreitems + + \brief The QmlGraphicsTextEdit class provides an editable formatted text item that you can add to a QmlView. + + It can display both plain and rich text. + + \image declarative-textedit.png + + A QmlGraphicsTextEdit object can be instantiated in Qml using the tag \c <TextEdit>. +*/ + +/*! + Constructs a new QmlGraphicsTextEdit. +*/ +QmlGraphicsTextEdit::QmlGraphicsTextEdit(QmlGraphicsItem *parent) +: QmlGraphicsPaintedItem(*(new QmlGraphicsTextEditPrivate), parent) +{ + Q_D(QmlGraphicsTextEdit); + d->init(); +} + +/*! +\internal +*/ +QmlGraphicsTextEdit::QmlGraphicsTextEdit(QmlGraphicsTextEditPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsPaintedItem(dd, parent) +{ + Q_D(QmlGraphicsTextEdit); + d->init(); +} + +QString QmlGraphicsTextEdit::text() const +{ + Q_D(const QmlGraphicsTextEdit); + + if (d->richText) + return d->document->toHtml(); + else + return d->document->toPlainText(); +} + +/*! + \qmlproperty string TextEdit::font.family + \qmlproperty bool TextEdit::font.bold + \qmlproperty bool TextEdit::font.italic + \qmlproperty bool TextEdit::font.underline + \qmlproperty real TextEdit::font.pointSize + \qmlproperty int TextEdit::font.pixelSize + + Set the TextEdit's font attributes. +*/ + +/*! + \qmlproperty string TextEdit::text + + The text to display. If the text format is AutoText the text edit will + automatically determine whether the text should be treated as + rich text. This determination is made using Qt::mightBeRichText(). +*/ +void QmlGraphicsTextEdit::setText(const QString &text) +{ + Q_D(QmlGraphicsTextEdit); + if (QmlGraphicsTextEdit::text() == text) + return; + d->text = text; + d->richText = d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(text)); + if (d->richText) { + d->control->setHtml(text); + } else { + d->control->setPlainText(text); + } + q_textChanged(); + updateSize(); +} + +/*! + \qmlproperty enumeration TextEdit::textFormat + + The way the text property should be displayed. + + Supported text formats are \c AutoText, \c PlainText and \c RichText. + + The default is AutoText. If the text format is AutoText the text edit + will automatically determine whether the text should be treated as + rich text. This determination is made using Qt::mightBeRichText(). + + \table + \row + \o + \qml +Column { + TextEdit { + font.pointSize: 24 + text: "Hello World!" + } + TextEdit { + font.pointSize: 24 + textFormat: "RichText" + text: "Hello World!" + } + TextEdit { + font.pointSize: 24 + textFormat: "PlainText" + text: "Hello World!" + } +} + \endqml + \o \image declarative-textformat.png + \endtable +*/ +QmlGraphicsTextEdit::TextFormat QmlGraphicsTextEdit::textFormat() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->format; +} + +void QmlGraphicsTextEdit::setTextFormat(TextFormat format) +{ + Q_D(QmlGraphicsTextEdit); + if (format == d->format) + return; + bool wasRich = d->richText; + d->richText = format == RichText || (format == AutoText && Qt::mightBeRichText(d->text)); + + if (wasRich && !d->richText) { + d->control->setPlainText(d->text); + updateSize(); + } else if (!wasRich && d->richText) { + d->control->setHtml(d->text); + updateSize(); + } + d->format = format; +} + +QFont QmlGraphicsTextEdit::font() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->font; +} + +void QmlGraphicsTextEdit::setFont(const QFont &font) +{ + Q_D(QmlGraphicsTextEdit); + d->font = font; + + clearCache(); + d->document->setDefaultFont(d->font); + if(d->cursor){ + d->cursor->setHeight(QFontMetrics(d->font).height()); + moveCursorDelegate(); + } + updateSize(); + update(); +} + +/*! + \qmlproperty color TextEdit::color + + The text color. + + \qml +// green text using hexadecimal notation +TextEdit { color: "#00FF00"; ... } + +// steelblue text using SVG color name +TextEdit { color: "steelblue"; ... } + \endqml +*/ +QColor QmlGraphicsTextEdit::color() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->color; +} + +void QmlGraphicsTextEdit::setColor(const QColor &color) +{ + Q_D(QmlGraphicsTextEdit); + if (d->color == color) + return; + + clearCache(); + d->color = color; + QPalette pal = d->control->palette(); + pal.setColor(QPalette::Text, color); + d->control->setPalette(pal); + update(); +} + +/*! + \qmlproperty color TextEdit::selectionColor + + The text highlight color, used behind selections. +*/ +QColor QmlGraphicsTextEdit::selectionColor() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->selectionColor; +} + +void QmlGraphicsTextEdit::setSelectionColor(const QColor &color) +{ + Q_D(QmlGraphicsTextEdit); + if (d->selectionColor == color) + return; + + clearCache(); + d->selectionColor = color; + QPalette pal = d->control->palette(); + pal.setColor(QPalette::Highlight, color); + d->control->setPalette(pal); + update(); +} + +/*! + \qmlproperty color TextEdit::selectedTextColor + + The selected text color, used in selections. +*/ +QColor QmlGraphicsTextEdit::selectedTextColor() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->selectedTextColor; +} + +void QmlGraphicsTextEdit::setSelectedTextColor(const QColor &color) +{ + Q_D(QmlGraphicsTextEdit); + if (d->selectedTextColor == color) + return; + + clearCache(); + d->selectedTextColor = color; + QPalette pal = d->control->palette(); + pal.setColor(QPalette::HighlightedText, color); + d->control->setPalette(pal); + update(); +} + +/*! + \qmlproperty enumeration TextEdit::horizontalAlignment + \qmlproperty enumeration TextEdit::verticalAlignment + + Sets the horizontal and vertical alignment of the text within the TextEdit items + width and height. By default, the text is top-left aligned. + + The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and + \c AlignHCenter. The valid values for \c verticalAlignment are \c AlignTop, \c AlignBottom + and \c AlignVCenter. +*/ +QmlGraphicsTextEdit::HAlignment QmlGraphicsTextEdit::hAlign() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->hAlign; +} + +void QmlGraphicsTextEdit::setHAlign(QmlGraphicsTextEdit::HAlignment alignment) +{ + Q_D(QmlGraphicsTextEdit); + if (alignment == d->hAlign) + return; + d->hAlign = alignment; + d->updateDefaultTextOption(); + updateSize(); +} + +QmlGraphicsTextEdit::VAlignment QmlGraphicsTextEdit::vAlign() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->vAlign; +} + +void QmlGraphicsTextEdit::setVAlign(QmlGraphicsTextEdit::VAlignment alignment) +{ + Q_D(QmlGraphicsTextEdit); + if (alignment == d->vAlign) + return; + d->vAlign = alignment; + d->updateDefaultTextOption(); + updateSize(); +} + +bool QmlGraphicsTextEdit::wrap() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->wrap; +} + +/*! + \qmlproperty bool TextEdit::wrap + + Set this property to wrap the text to the TextEdit item's width. + The text will only wrap if an explicit width has been set. + + Wrapping is done on word boundaries (i.e. it is a "word-wrap"). Wrapping is off by default. +*/ +void QmlGraphicsTextEdit::setWrap(bool w) +{ + Q_D(QmlGraphicsTextEdit); + if (w == d->wrap) + return; + d->wrap = w; + d->updateDefaultTextOption(); + updateSize(); +} + +/*! + \qmlproperty bool TextEdit::cursorVisible + If true the text edit shows a cursor. + + This property is set and unset when the text edit gets focus, but it can also + be set directly (useful, for example, if a KeyProxy might forward keys to it). +*/ +bool QmlGraphicsTextEdit::isCursorVisible() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->cursorVisible; +} + +void QmlGraphicsTextEdit::setCursorVisible(bool on) +{ + Q_D(QmlGraphicsTextEdit); + if (d->cursorVisible == on) + return; + d->cursorVisible = on; + QFocusEvent focusEvent(on ? QEvent::FocusIn : QEvent::FocusOut); + if (!on && !d->persistentSelection) + d->control->setCursorIsFocusIndicator(true); + d->control->processEvent(&focusEvent, QPointF(0, 0)); +} + +/*! + \qmlproperty int TextEdit::cursorPosition + The position of the cursor in the TextEdit. +*/ +int QmlGraphicsTextEdit::cursorPosition() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->control->textCursor().position(); +} + +void QmlGraphicsTextEdit::setCursorPosition(int pos) +{ + Q_D(QmlGraphicsTextEdit); + QTextCursor cursor = d->control->textCursor(); + if (cursor.position() == pos) + return; + cursor.setPosition(pos); + d->control->setTextCursor(cursor); +} + +/*! + \qmlproperty Component TextEdit::cursorDelegate + The delegate for the cursor in the TextEdit. + + If you set a cursorDelegate for a TextEdit, this delegate will be used for + drawing the cursor instead of the standard cursor. An instance of the + delegate will be created and managed by the text edit when a cursor is + needed, and the x and y properties of delegate instance will be set so as + to be one pixel before the top left of the current character. + + Note that the root item of the delegate component must be a QmlGraphicsItem or + QmlGraphicsItem derived item. +*/ +QmlComponent* QmlGraphicsTextEdit::cursorDelegate() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->cursorComponent; +} + +void QmlGraphicsTextEdit::setCursorDelegate(QmlComponent* c) +{ + Q_D(QmlGraphicsTextEdit); + if(d->cursorComponent){ + if(d->cursor){ + disconnect(d->control, SIGNAL(cursorPositionChanged()), + this, SLOT(moveCursorDelegate())); + d->control->setCursorWidth(-1); + dirtyCache(cursorRect()); + delete d->cursor; + d->cursor = 0; + } + } + d->cursorComponent = c; + if(c && c->isReady()){ + loadCursorDelegate(); + }else{ + if(c) + connect(c, SIGNAL(statusChanged()), + this, SLOT(loadCursorDelegate())); + } +} + +void QmlGraphicsTextEdit::loadCursorDelegate() +{ + Q_D(QmlGraphicsTextEdit); + if(d->cursorComponent->isLoading()) + return; + d->cursor = qobject_cast(d->cursorComponent->create(qmlContext(this))); + if(d->cursor){ + connect(d->control, SIGNAL(cursorPositionChanged()), + this, SLOT(moveCursorDelegate())); + d->control->setCursorWidth(0); + dirtyCache(cursorRect()); + d->cursor->setParentItem(this); + d->cursor->setHeight(QFontMetrics(d->font).height()); + moveCursorDelegate(); + }else{ + qWarning() << QLatin1String("Error loading cursor delegate for TextEdit:") + objectName(); + } +} + +/*! + \qmlproperty int TextEdit::selectionStart + + The cursor position before the first character in the current selection. + Setting this and selectionEnd allows you to specify a selection in the + text edit. + + Note that if selectionStart == selectionEnd then there is no current + selection. If you attempt to set selectionStart to a value outside of + the current text, selectionStart will not be changed. + + \sa selectionEnd, cursorPosition, selectedText +*/ +int QmlGraphicsTextEdit::selectionStart() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->control->textCursor().selectionStart(); +} + +void QmlGraphicsTextEdit::setSelectionStart(int s) +{ + Q_D(QmlGraphicsTextEdit); + if(d->lastSelectionStart == s || s < 0 || s > text().length()) + return; + d->lastSelectionStart = s; + d->updateSelection();// Will emit the relevant signals +} + +/*! + \qmlproperty int TextEdit::selectionEnd + + The cursor position after the last character in the current selection. + Setting this and selectionStart allows you to specify a selection in the + text edit. + + Note that if selectionStart == selectionEnd then there is no current + selection. If you attempt to set selectionEnd to a value outside of + the current text, selectionEnd will not be changed. + + \sa selectionStart, cursorPosition, selectedText +*/ +int QmlGraphicsTextEdit::selectionEnd() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->control->textCursor().selectionEnd(); +} + +void QmlGraphicsTextEdit::setSelectionEnd(int s) +{ + Q_D(QmlGraphicsTextEdit); + if(d->lastSelectionEnd == s || s < 0 || s > text().length()) + return; + d->lastSelectionEnd = s; + d->updateSelection();// Will emit the relevant signals +} + +/*! + \qmlproperty string TextEdit::selectedText + + This read-only property provides the text currently selected in the + text edit. + + It is equivalent to the following snippet, but is faster and easier + to use. + \code + //myTextEdit is the id of the TextEdit + myTextEdit.text.toString().substring(myTextEdit.selectionStart, + myTextEdit.selectionEnd); + \endcode +*/ +QString QmlGraphicsTextEdit::selectedText() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->control->textCursor().selectedText(); +} + +/*! + \qmlproperty bool TextEdit::focusOnPress + + Whether the TextEdit should gain focus on a mouse press. By default this is + set to false; +*/ +bool QmlGraphicsTextEdit::focusOnPress() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->focusOnPress; +} + +void QmlGraphicsTextEdit::setFocusOnPress(bool on) +{ + Q_D(QmlGraphicsTextEdit); + if (d->focusOnPress == on) + return; + d->focusOnPress = on; +} + +/*! + \qmlproperty bool TextEdit::persistentSelection + + Whether the TextEdit should keep the selection visible when it loses focus to another + item in the scene. By default this is set to true; +*/ +bool QmlGraphicsTextEdit::persistentSelection() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->persistentSelection; +} + +void QmlGraphicsTextEdit::setPersistentSelection(bool on) +{ + Q_D(QmlGraphicsTextEdit); + if (d->persistentSelection == on) + return; + d->persistentSelection = on; +} + +qreal QmlGraphicsTextEdit::textMargin() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->textMargin; +} + +void QmlGraphicsTextEdit::setTextMargin(qreal margin) +{ + Q_D(QmlGraphicsTextEdit); + if (d->textMargin == margin) + return; + d->textMargin = margin; + d->document->setDocumentMargin(d->textMargin); +} + +void QmlGraphicsTextEdit::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) +{ + if (newGeometry.width() != oldGeometry.width()) + updateSize(); + QmlGraphicsPaintedItem::geometryChanged(newGeometry, oldGeometry); +} + +/*! + Ensures any delayed caching or data loading the class + needs to performed is complete. +*/ +void QmlGraphicsTextEdit::componentComplete() +{ + Q_D(QmlGraphicsTextEdit); + QmlGraphicsPaintedItem::componentComplete(); + if (d->dirty) { + updateSize(); + d->dirty = false; + } +} + +/*! + \qmlproperty bool TextEdit::readOnly + + Whether the user an interact with the TextEdit item. If this + property is set to true the text cannot be edited by user interaction. + + By default this property is false. +*/ +void QmlGraphicsTextEdit::setReadOnly(bool r) +{ + Q_D(QmlGraphicsTextEdit); + + Qt::TextInteractionFlags flags = Qt::NoTextInteraction; + if (r) { + flags = Qt::TextSelectableByMouse; + } else { + flags = Qt::TextEditorInteraction; + } + d->control->setTextInteractionFlags(flags); + if (!r) + d->control->moveCursor(QTextCursor::End); +} + +bool QmlGraphicsTextEdit::isReadOnly() const +{ + Q_D(const QmlGraphicsTextEdit); + return !(d->control->textInteractionFlags() & Qt::TextEditable); +} + +/*! + Sets how the text edit should interact with user input to the given + \a flags. +*/ +void QmlGraphicsTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags) +{ + Q_D(QmlGraphicsTextEdit); + d->control->setTextInteractionFlags(flags); +} + +/*! + Returns the flags specifying how the text edit should interact + with user input. +*/ +Qt::TextInteractionFlags QmlGraphicsTextEdit::textInteractionFlags() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->control->textInteractionFlags(); +} + +/*! + Returns the cursor for the point at the given \a pos on the + text edit. +*/ +QTextCursor QmlGraphicsTextEdit::cursorForPosition(const QPoint &pos) const +{ + Q_D(const QmlGraphicsTextEdit); + return d->control->cursorForPosition(pos); +} + +/*! + Returns the rectangle where the given text \a cursor is rendered + within the text edit. +*/ +QRect QmlGraphicsTextEdit::cursorRect(const QTextCursor &cursor) const +{ + Q_D(const QmlGraphicsTextEdit); + if (cursor.isNull()) + return QRect(); + + return d->control->cursorRect(cursor).toRect(); +} + +/*! + Returns the rectangle where the text cursor is rendered + within the text edit. +*/ +QRect QmlGraphicsTextEdit::cursorRect() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->control->cursorRect().toRect(); +} + + +/*! + Sets the text cursor for the text edit to the given \a cursor. +*/ +void QmlGraphicsTextEdit::setTextCursor(const QTextCursor &cursor) +{ + Q_D(QmlGraphicsTextEdit); + d->control->setTextCursor(cursor); +} + +/*! + Returns the text cursor for the text edit. +*/ +QTextCursor QmlGraphicsTextEdit::textCursor() const +{ + Q_D(const QmlGraphicsTextEdit); + return d->control->textCursor(); +} + +/*! +Moves the cursor by performing the given \a operation. + +If \a mode is QTextCursor::KeepAnchor, the cursor selects the text it moves over. This is the same effect that the user achieves when they hold down the Shift key and move the cursor with the cursor keys. +*/ +void QmlGraphicsTextEdit::moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode) +{ + Q_D(QmlGraphicsTextEdit); + d->control->moveCursor(operation, mode); +} + +/*! +\overload +Handles the given \a event. +*/ +bool QmlGraphicsTextEdit::event(QEvent *event) +{ + Q_D(QmlGraphicsTextEdit); + if (event->type() == QEvent::ShortcutOverride) { + d->control->processEvent(event, QPointF(0, 0)); + return event->isAccepted(); + } + return QmlGraphicsPaintedItem::event(event); +} + +/*! +\overload +Handles the given key \a event. +*/ +void QmlGraphicsTextEdit::keyPressEvent(QKeyEvent *event) +{ + Q_D(QmlGraphicsTextEdit); + //### this causes non-standard cursor behavior in some cases. + // is it still needed? + /*QTextCursor c = textCursor(); + QTextCursor::MoveOperation op = QTextCursor::NoMove; + if (event == QKeySequence::MoveToNextChar) { + op = QTextCursor::Right; + } else if (event == QKeySequence::MoveToPreviousChar) { + op = QTextCursor::Left; + } else if (event == QKeySequence::MoveToNextWord) { + op = QTextCursor::WordRight; + } else if (event == QKeySequence::MoveToPreviousWord) { + op = QTextCursor::WordLeft; + } else if (event == QKeySequence::MoveToNextLine) { + op = QTextCursor::Down; + } else if (event == QKeySequence::MoveToPreviousLine) { + op = QTextCursor::Up; + } + + if (op != QTextCursor::NoMove && !c.movePosition(op)) + event->ignore(); + else*/ + d->control->processEvent(event, QPointF(0, 0)); + + if (!event->isAccepted()) + QmlGraphicsPaintedItem::keyPressEvent(event); +} + +/*! +\overload +Handles the given key \a event. +*/ +void QmlGraphicsTextEdit::keyReleaseEvent(QKeyEvent *event) +{ + Q_D(QmlGraphicsTextEdit); + d->control->processEvent(event, QPointF(0, 0)); + if (!event->isAccepted()) + QmlGraphicsPaintedItem::keyReleaseEvent(event); +} + +/*! + \overload + Handles changing of the focus property. Focus is applied to the control + even if the edit does not have active focus. This is because things + like KeyProxy can give the behavior of focus even when hasFocus() isn't + true. +*/ +void QmlGraphicsTextEdit::focusChanged(bool hasFocus) +{ + setCursorVisible(hasFocus); + QmlGraphicsItem::focusChanged(hasFocus); +} + +/*! + Causes all text to be selected. +*/ +void QmlGraphicsTextEdit::selectAll() +{ + Q_D(QmlGraphicsTextEdit); + d->control->selectAll(); +} + +/*! +\overload +Handles the given mouse \a event. +*/ +void QmlGraphicsTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsTextEdit); + if (d->focusOnPress) + setFocus(true); + d->control->processEvent(event, QPointF(0, 0)); + if (!event->isAccepted()) + QmlGraphicsPaintedItem::mousePressEvent(event); +} + +/*! +\overload +Handles the given mouse \a event. +*/ +void QmlGraphicsTextEdit::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsTextEdit); + d->control->processEvent(event, QPointF(0, 0)); + if (!event->isAccepted()) + QmlGraphicsPaintedItem::mousePressEvent(event); +} + +/*! +\overload +Handles the given mouse \a event. +*/ +void QmlGraphicsTextEdit::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsTextEdit); + d->control->processEvent(event, QPointF(0, 0)); + if (!event->isAccepted()) + QmlGraphicsPaintedItem::mouseDoubleClickEvent(event); +} + +/*! +\overload +Handles the given mouse \a event. +*/ +void QmlGraphicsTextEdit::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsTextEdit); + d->control->processEvent(event, QPointF(0, 0)); + if (!event->isAccepted()) + QmlGraphicsPaintedItem::mousePressEvent(event); +} + +/*! +\overload +Handles the given input method \a event. +*/ +void QmlGraphicsTextEdit::inputMethodEvent(QInputMethodEvent *event) +{ + Q_D(QmlGraphicsTextEdit); + d->control->processEvent(event, QPointF(0, 0)); +} + +/*! +\overload +Returns the value of the given \a property. +*/ +QVariant QmlGraphicsTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const +{ + Q_D(const QmlGraphicsTextEdit); + return d->control->inputMethodQuery(property); +} + +/*! +Draws the contents of the text edit using the given \a painter within +the given \a bounds. +*/ +void QmlGraphicsTextEdit::drawContents(QPainter *painter, const QRect &bounds) +{ + Q_D(QmlGraphicsTextEdit); + + painter->setRenderHint(QPainter::TextAntialiasing, true); + + d->control->drawContents(painter, bounds); +} + +void QmlGraphicsTextEdit::updateImgCache(const QRectF &r) +{ + dirtyCache(r.toRect()); + emit update(); +} + +/*! + \qmlproperty bool TextEdit::smooth + + Set this property if you want the text to be smoothly scaled or + transformed. Smooth filtering gives better visual quality, but is slower. If + the item is displayed at its natural size, this property has no visual or + performance effect. + + \note Generally scaling artifacts are only visible if the item is stationary on + the screen. A common pattern when animating an item is to disable smooth + filtering at the beginning of the animation and reenable it at the conclusion. +*/ + +void QmlGraphicsTextEditPrivate::init() +{ + Q_Q(QmlGraphicsTextEdit); + + q->setSmoothTransform(smooth); + q->setAcceptedMouseButtons(Qt::LeftButton); + q->setFlag(QGraphicsItem::ItemHasNoContents, false); + q->setFlag(QGraphicsItem::ItemAcceptsInputMethod); + + control = new QTextControl(q); + + QObject::connect(control, SIGNAL(updateRequest(QRectF)), q, SLOT(updateImgCache(QRectF))); + + QObject::connect(control, SIGNAL(textChanged()), q, SLOT(q_textChanged())); + QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged())); + QObject::connect(control, SIGNAL(selectionChanged()), q, SLOT(updateSelectionMarkers())); + QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(updateSelectionMarkers())); + QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SIGNAL(cursorPositionChanged())); + + document = control->document(); + document->setDefaultFont(font); + document->setDocumentMargin(textMargin); + document->setUndoRedoEnabled(false); // flush undo buffer. + document->setUndoRedoEnabled(true); + updateDefaultTextOption(); +} + +void QmlGraphicsTextEdit::q_textChanged() +{ + if (!widthValid()) + updateSize(); //### optimize: we get 3 calls to updateSize every time a letter is typed + emit textChanged(text()); +} + +void QmlGraphicsTextEdit::moveCursorDelegate() +{ + Q_D(QmlGraphicsTextEdit); + if(!d->cursor) + return; + QRectF cursorRect = d->control->cursorRect(); + d->cursor->setX(cursorRect.x()); + d->cursor->setY(cursorRect.y()); +} + +void QmlGraphicsTextEditPrivate::updateSelection() +{ + Q_Q(QmlGraphicsTextEdit); + QTextCursor cursor = control->textCursor(); + bool startChange = (lastSelectionStart != cursor.selectionStart()); + bool endChange = (lastSelectionEnd != cursor.selectionEnd()); + //### Is it worth calculating a more minimal set of movements? + cursor.beginEditBlock(); + cursor.setPosition(lastSelectionStart, QTextCursor::MoveAnchor); + cursor.setPosition(lastSelectionEnd, QTextCursor::KeepAnchor); + cursor.endEditBlock(); + control->setTextCursor(cursor); + if(startChange) + q->selectionStartChanged(); + if(endChange) + q->selectionEndChanged(); + startChange = (lastSelectionStart != control->textCursor().selectionStart()); + endChange = (lastSelectionEnd != control->textCursor().selectionEnd()); + if(startChange || endChange) + qWarning() << "QmlGraphicsTextEditPrivate::updateSelection() has failed you."; +} + +void QmlGraphicsTextEdit::updateSelectionMarkers() +{ + Q_D(QmlGraphicsTextEdit); + if(d->lastSelectionStart != d->control->textCursor().selectionStart()){ + d->lastSelectionStart = d->control->textCursor().selectionStart(); + emit selectionStartChanged(); + } + if(d->lastSelectionEnd != d->control->textCursor().selectionEnd()){ + d->lastSelectionEnd = d->control->textCursor().selectionEnd(); + emit selectionEndChanged(); + } +} + +//### we should perhaps be a bit smarter here -- depending on what has changed, we shouldn't +// need to do all the calculations each time +void QmlGraphicsTextEdit::updateSize() +{ + Q_D(QmlGraphicsTextEdit); + if (isComponentComplete()) { + QFontMetrics fm = QFontMetrics(d->font); + int dy = height(); + // ### assumes that if the width is set, the text will fill to edges + // ### (unless wrap is false, then clipping will occur) + if (widthValid()) + d->document->setTextWidth(width()); + dy -= (int)d->document->size().height(); + + int yoff = 0; + if (heightValid()) { + if (d->vAlign == AlignBottom) + yoff = dy; + else if (d->vAlign == AlignVCenter) + yoff = dy/2; + } + setBaselineOffset(fm.ascent() + yoff + d->textMargin); + + //### need to comfirm cost of always setting these + int newWidth = (int)d->document->idealWidth(); + d->document->setTextWidth(newWidth); // ### QTextDoc> Alignment will not work unless textWidth is set. Does Text need this line as well? + int cursorWidth = 1; + if(d->cursor) + cursorWidth = d->cursor->width(); + newWidth += cursorWidth; + if(!d->document->isEmpty()) + newWidth += 3;// ### Need a better way of accounting for space between char and cursor + // ### Setting the implicitWidth triggers another updateSize(), and unless there are bindings nothing has changed. + setImplicitWidth(newWidth); + setImplicitHeight(d->text.isEmpty() ? fm.height() : (int)d->document->size().height()); + + setContentsSize(QSize(width(), height())); + } else { + d->dirty = true; + } + emit update(); +} + +void QmlGraphicsTextEditPrivate::updateDefaultTextOption() +{ + QTextOption opt = document->defaultTextOption(); + int oldAlignment = opt.alignment(); + opt.setAlignment((Qt::Alignment)(int)(hAlign | vAlign)); + + QTextOption::WrapMode oldWrapMode = opt.wrapMode(); + + if (wrap) + opt.setWrapMode(QTextOption::WordWrap); + else + opt.setWrapMode(QTextOption::NoWrap); + + if (oldWrapMode == opt.wrapMode() && oldAlignment == opt.alignment()) + return; + document->setDefaultTextOption(opt); +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicstextedit.h b/src/declarative/fx/qmlgraphicstextedit.h new file mode 100644 index 0000000..57f7449 --- /dev/null +++ b/src/declarative/fx/qmlgraphicstextedit.h @@ -0,0 +1,234 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSTEXTEDIT_H +#define QMLGRAPHICSTEXTEDIT_H + +#include +#include + +#include +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + + +class QmlGraphicsTextEditPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsTextEdit : public QmlGraphicsPaintedItem +{ + Q_OBJECT + Q_ENUMS(VAlignment) + Q_ENUMS(HAlignment) + Q_ENUMS(TextFormat) + + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) + Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign) + Q_PROPERTY(bool wrap READ wrap WRITE setWrap) //### other wrap modes + Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) + Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) + Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) + Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) + Q_PROPERTY(QmlComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate) + Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) + Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) + Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged) + Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) + Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection) + Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin) + +public: + QmlGraphicsTextEdit(QmlGraphicsItem *parent=0); + + enum HAlignment { + AlignLeft = Qt::AlignLeft, + AlignRight = Qt::AlignRight, + AlignHCenter = Qt::AlignHCenter + }; + + enum VAlignment { + AlignTop = Qt::AlignTop, + AlignBottom = Qt::AlignBottom, + AlignVCenter = Qt::AlignVCenter + }; + + enum TextFormat { + PlainText = Qt::PlainText, + RichText = Qt::RichText, + AutoText = Qt::AutoText + }; + + QString text() const; + void setText(const QString &); + + TextFormat textFormat() const; + void setTextFormat(TextFormat format); + + QFont font() const; + void setFont(const QFont &font); + + QColor color() const; + void setColor(const QColor &c); + + QColor selectionColor() const; + void setSelectionColor(const QColor &c); + + QColor selectedTextColor() const; + void setSelectedTextColor(const QColor &c); + + HAlignment hAlign() const; + void setHAlign(HAlignment align); + + VAlignment vAlign() const; + void setVAlign(VAlignment align); + + bool wrap() const; + void setWrap(bool w); + + bool isCursorVisible() const; + void setCursorVisible(bool on); + + int cursorPosition() const; + void setCursorPosition(int pos); + + QmlComponent* cursorDelegate() const; + void setCursorDelegate(QmlComponent*); + + int selectionStart() const; + void setSelectionStart(int); + + int selectionEnd() const; + void setSelectionEnd(int); + + QString selectedText() const; + + bool focusOnPress() const; + void setFocusOnPress(bool on); + + bool persistentSelection() const; + void setPersistentSelection(bool on); + + qreal textMargin() const; + void setTextMargin(qreal margin); + + virtual void componentComplete(); + + /* FROM EDIT */ + void setReadOnly(bool); + bool isReadOnly() const; + + void setTextInteractionFlags(Qt::TextInteractionFlags flags); + Qt::TextInteractionFlags textInteractionFlags() const; + + QTextCursor cursorForPosition(const QPoint &pos) const; + QRect cursorRect(const QTextCursor &cursor) const; + QRect cursorRect() const; + + void setTextCursor(const QTextCursor &cursor); + QTextCursor textCursor() const; + + void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor); + + QVariant inputMethodQuery(Qt::InputMethodQuery property) const; + +Q_SIGNALS: + void textChanged(const QString &); + void cursorPositionChanged(); + void selectionStartChanged(); + void selectionEndChanged(); + void selectionChanged(); + +public Q_SLOTS: + void selectAll(); + +private Q_SLOTS: + void updateImgCache(const QRectF &rect); + void q_textChanged(); + void updateSelectionMarkers(); + void moveCursorDelegate(); + void loadCursorDelegate(); + +private: + void updateSize(); + +protected: + QmlGraphicsTextEdit(QmlGraphicsTextEditPrivate &dd, QmlGraphicsItem *parent); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + + bool event(QEvent *); + void keyPressEvent(QKeyEvent *); + void keyReleaseEvent(QKeyEvent *); + + void focusChanged(bool); + + // mouse filter? + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + + void inputMethodEvent(QInputMethodEvent *e); + + void drawContents(QPainter *, const QRect &); +private: + Q_DISABLE_COPY(QmlGraphicsTextEdit) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsTextEdit) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsTextEdit) + +QT_END_HEADER + +#endif diff --git a/src/declarative/fx/qmlgraphicstextedit_p.h b/src/declarative/fx/qmlgraphicstextedit_p.h new file mode 100644 index 0000000..7a163f8 --- /dev/null +++ b/src/declarative/fx/qmlgraphicstextedit_p.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSTEXTEDIT_P_H +#define QMLGRAPHICSTEXTEDIT_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 "qmlgraphicsitem.h" +#include "qmlgraphicspainteditem_p.h" +#include "qml.h" + + +QT_BEGIN_NAMESPACE +class QTextLayout; +class QTextDocument; +class QTextControl; +class QmlGraphicsTextEditPrivate : public QmlGraphicsPaintedItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsTextEdit) + +public: + QmlGraphicsTextEditPrivate() + : color("black"), imgDirty(true), hAlign(QmlGraphicsTextEdit::AlignLeft), vAlign(QmlGraphicsTextEdit::AlignTop), + dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(false), + persistentSelection(true), textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0), + cursorComponent(0), cursor(0), format(QmlGraphicsTextEdit::AutoText), document(0) + { + } + + void init(); + + void updateDefaultTextOption(); + void relayoutDocument(); + void updateSelection(); + + QString text; + QFont font; + QColor color; + QColor selectionColor; + QColor selectedTextColor; + QString style; + QColor styleColor; + bool imgDirty; + QPixmap imgCache; + QPixmap imgStyleCache; + QmlGraphicsTextEdit::HAlignment hAlign; + QmlGraphicsTextEdit::VAlignment vAlign; + bool dirty; + bool wrap; + bool richText; + bool cursorVisible; + bool focusOnPress; + bool persistentSelection; + qreal textMargin; + int lastSelectionStart; + int lastSelectionEnd; + QmlComponent* cursorComponent; + QmlGraphicsItem* cursor; + QmlGraphicsTextEdit::TextFormat format; + QTextDocument *document; + QTextControl *control; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/declarative/fx/qmlgraphicstextinput.cpp b/src/declarative/fx/qmlgraphicstextinput.cpp new file mode 100644 index 0000000..17e6f7c --- /dev/null +++ b/src/declarative/fx/qmlgraphicstextinput.cpp @@ -0,0 +1,777 @@ +/**************************************************************************** +** +** 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 "qmlgraphicstextinput.h" +#include "qmlgraphicstextinput_p.h" +#include "qmlinfo.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,TextInput,QmlGraphicsTextInput); +QML_DEFINE_NOCREATE_TYPE(QValidator); +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,QIntValidator,QIntValidator); + +/*! + \qmlclass TextInput + The TextInput item allows you to add an editable line of text to a scene. + + TextInput can only display a single line of text, and can only display + plain text. However it can provide addition input constraints on the text. + + Input constraints include setting a QValidator, an input mask, or a + maximum input length. +*/ +QmlGraphicsTextInput::QmlGraphicsTextInput(QmlGraphicsItem* parent) + : QmlGraphicsPaintedItem(*(new QmlGraphicsTextInputPrivate), parent) +{ + Q_D(QmlGraphicsTextInput); + d->init(); +} + +/* + \internal +*/ +QmlGraphicsTextInput::QmlGraphicsTextInput(QmlGraphicsTextInputPrivate &dd, QmlGraphicsItem* parent) + : QmlGraphicsPaintedItem(dd, parent) +{ + Q_D(QmlGraphicsTextInput); + d->init(); +} + +QmlGraphicsTextInput::~QmlGraphicsTextInput() +{ +} + +/*! + \qmlproperty string TextInput::text + + The text in the TextInput. +*/ + +QString QmlGraphicsTextInput::text() const +{ + Q_D(const QmlGraphicsTextInput); + return d->control->text(); +} + +void QmlGraphicsTextInput::setText(const QString &s) +{ + Q_D(QmlGraphicsTextInput); + if(s == text()) + return; + d->control->setText(s); + //emit textChanged(); +} + +/*! + \qmlproperty string TextInput::font.family + \qmlproperty bool TextInput::font.bold + \qmlproperty bool TextInput::font.italic + \qmlproperty bool TextInput::font.underline + \qmlproperty real TextInput::font.pointSize + \qmlproperty int TextInput::font.pixelSize + + Set the TextInput's font attributes. +*/ +QFont QmlGraphicsTextInput::font() const +{ + Q_D(const QmlGraphicsTextInput); + return d->font; +} + +void QmlGraphicsTextInput::setFont(const QFont &font) +{ + Q_D(QmlGraphicsTextInput); + d->font = font; + + d->control->setFont(d->font); + if(d->cursorItem){ + d->cursorItem->setHeight(QFontMetrics(d->font).height()); + moveCursor(); + } + updateSize(); +} + +/*! + \qmlproperty color TextInput::color + + The text color. +*/ +QColor QmlGraphicsTextInput::color() const +{ + Q_D(const QmlGraphicsTextInput); + return d->color; +} + +void QmlGraphicsTextInput::setColor(const QColor &c) +{ + Q_D(QmlGraphicsTextInput); + d->color = c; +} + + +/*! + \qmlproperty color TextInput::selectionColor + + The text highlight color, used behind selections. +*/ +QColor QmlGraphicsTextInput::selectionColor() const +{ + Q_D(const QmlGraphicsTextInput); + return d->selectionColor; +} + +void QmlGraphicsTextInput::setSelectionColor(const QColor &color) +{ + Q_D(QmlGraphicsTextInput); + if (d->selectionColor == color) + return; + + d->selectionColor = color; + QPalette p = d->control->palette(); + p.setColor(QPalette::Highlight, d->selectionColor); + d->control->setPalette(p); +} + +/*! + \qmlproperty color TextInput::selectedTextColor + + The highlighted text color, used in selections. +*/ +QColor QmlGraphicsTextInput::selectedTextColor() const +{ + Q_D(const QmlGraphicsTextInput); + return d->selectedTextColor; +} + +void QmlGraphicsTextInput::setSelectedTextColor(const QColor &color) +{ + Q_D(QmlGraphicsTextInput); + if (d->selectedTextColor == color) + return; + + d->selectedTextColor = color; + QPalette p = d->control->palette(); + p.setColor(QPalette::HighlightedText, d->selectedTextColor); + d->control->setPalette(p); +} + +/*! + \qmlproperty enumeration TextInput::horizontalAlignment + + Sets the horizontal alignment of the text within the TextInput item's + width and height. By default, the text is left aligned. + + TextInput does not have vertical alignment, as the natural height is + exactly the height of the single line of text. If you set the height + manually to something larger, TextInput will always be top aligned + vertically. You can use anchors to align it however you want within + another item. + + The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and + \c AlignHCenter. +*/ +QmlGraphicsTextInput::HAlignment QmlGraphicsTextInput::hAlign() const +{ + Q_D(const QmlGraphicsTextInput); + return d->hAlign; +} + +void QmlGraphicsTextInput::setHAlign(HAlignment align) +{ + Q_D(QmlGraphicsTextInput); + d->hAlign = align; + //TODO: implement +} + +bool QmlGraphicsTextInput::isReadOnly() const +{ + Q_D(const QmlGraphicsTextInput); + return d->control->isReadOnly(); +} + +void QmlGraphicsTextInput::setReadOnly(bool ro) +{ + Q_D(QmlGraphicsTextInput); + d->control->setReadOnly(ro); +} + +int QmlGraphicsTextInput::maxLength() const +{ + Q_D(const QmlGraphicsTextInput); + return d->control->maxLength(); +} + +void QmlGraphicsTextInput::setMaxLength(int ml) +{ + Q_D(QmlGraphicsTextInput); + d->control->setMaxLength(ml); +} + +/*! + \qmlproperty bool TextInput::cursorVisible + If true the text edit shows a cursor. + + This property is set and unset when the line edit gets focus, but it can also + be set directly (useful, for example, if a KeyProxy might forward keys to it). +*/ +bool QmlGraphicsTextInput::isCursorVisible() const +{ + Q_D(const QmlGraphicsTextInput); + return d->cursorVisible; +} + +void QmlGraphicsTextInput::setCursorVisible(bool on) +{ + Q_D(QmlGraphicsTextInput); + if (d->cursorVisible == on) + return; + d->cursorVisible = on; + d->control->setCursorBlinkPeriod(on?QApplication::cursorFlashTime():0); + //d->control should emit the cursor update regions +} + +/*! + \qmlproperty int TextInput::cursorPosition + The position of the cursor in the TextInput. +*/ +int QmlGraphicsTextInput::cursorPosition() const +{ + Q_D(const QmlGraphicsTextInput); + return d->control->cursor(); +} +void QmlGraphicsTextInput::setCursorPosition(int cp) +{ + Q_D(QmlGraphicsTextInput); + d->control->moveCursor(cp); +} + +/*! + \internal + + Returns a Rect which encompasses the cursor, but which may be larger than is + required. Ignores custom cursor delegates. +*/ +QRect QmlGraphicsTextInput::cursorRect() const +{ + Q_D(const QmlGraphicsTextInput); + return d->control->cursorRect(); +} + +/*! + \qmlproperty int TextInput::selectionStart + + The cursor position before the first character in the current selection. + Setting this and selectionEnd allows you to specify a selection in the + text edit. + + Note that if selectionStart == selectionEnd then there is no current + selection. If you attempt to set selectionStart to a value outside of + the current text, selectionStart will not be changed. + + \sa selectionEnd, cursorPosition, selectedText +*/ +int QmlGraphicsTextInput::selectionStart() const +{ + Q_D(const QmlGraphicsTextInput); + return d->lastSelectionStart; +} + +void QmlGraphicsTextInput::setSelectionStart(int s) +{ + Q_D(QmlGraphicsTextInput); + if(d->lastSelectionStart == s || s < 0 || s > text().length()) + return; + d->lastSelectionStart = s; + d->control->setSelection(s, d->lastSelectionEnd - s); +} + +/*! + \qmlproperty int TextInput::selectionEnd + + The cursor position after the last character in the current selection. + Setting this and selectionStart allows you to specify a selection in the + text edit. + + Note that if selectionStart == selectionEnd then there is no current + selection. If you attempt to set selectionEnd to a value outside of + the current text, selectionEnd will not be changed. + + \sa selectionStart, cursorPosition, selectedText +*/ +int QmlGraphicsTextInput::selectionEnd() const +{ + Q_D(const QmlGraphicsTextInput); + return d->lastSelectionEnd; +} + +void QmlGraphicsTextInput::setSelectionEnd(int s) +{ + Q_D(QmlGraphicsTextInput); + if(d->lastSelectionEnd == s || s < 0 || s > text().length()) + return; + d->lastSelectionEnd = s; + d->control->setSelection(d->lastSelectionStart, s - d->lastSelectionStart); +} + +/*! + \qmlproperty string TextInput::selectedText + + This read-only property provides the text currently selected in the + text input. + + It is equivalent to the following snippet, but is faster and easier + to use. + + \qml + myTextInput.text.toString().substring(myTextInput.selectionStart, + myTextInput.selectionEnd); + \endqml +*/ +QString QmlGraphicsTextInput::selectedText() const +{ + Q_D(const QmlGraphicsTextInput); + return d->control->selectedText(); +} + +/*! + \qmlproperty bool TextInput::focusOnPress + + Whether the TextInput should gain focus on a mouse press. By default this is + set to true. +*/ +bool QmlGraphicsTextInput::focusOnPress() const +{ + Q_D(const QmlGraphicsTextInput); + return d->focusOnPress; +} + +void QmlGraphicsTextInput::setFocusOnPress(bool b) +{ + Q_D(QmlGraphicsTextInput); + d->focusOnPress = b; +} + +/*! + \qmlproperty QValidator* TextInput::validator + + Allows you to set a QValidator on the TextInput. When a validator is set + the TextInput will only accept input which leaves the text property in + an acceptable or intermediate state. The accepted signal will only be sent + if the text is in an acceptable state when enter is pressed. + + \sa acceptableInput, inputMask +*/ +QValidator* QmlGraphicsTextInput::validator() const +{ + Q_D(const QmlGraphicsTextInput); + //###const cast isn't good, but needed for property system? + return const_cast(d->control->validator()); +} + +void QmlGraphicsTextInput::setValidator(QValidator* v) +{ + Q_D(QmlGraphicsTextInput); + d->control->setValidator(v); + if(!d->control->hasAcceptableInput()){ + d->oldValidity = false; + emit acceptableInputChanged(); + } +} + +/*! + \qmlproperty string TextInput::inputMask + + Allows you to set an input mask on the TextInput, restricting the allowable + text inputs. See QLineEdit::inputMask for further details, as the exact + same mask strings are used by TextInput. + + \sa acceptableInput, validator +*/ +QString QmlGraphicsTextInput::inputMask() const +{ + Q_D(const QmlGraphicsTextInput); + return d->control->inputMask(); +} + +void QmlGraphicsTextInput::setInputMask(const QString &im) +{ + Q_D(QmlGraphicsTextInput); + d->control->setInputMask(im); +} + +/*! + \qmlproperty bool TextInput::acceptableInput + + This property is always true unless a validator or input mask has been set. + If a validator or input mask has been set, this property will only be true + if the current text is acceptable to the validator or input mask as a final + string (not as an intermediate string). +*/ +bool QmlGraphicsTextInput::hasAcceptableInput() const +{ + Q_D(const QmlGraphicsTextInput); + return d->control->hasAcceptableInput(); +} + +/*! + \qmlproperty TextInput.EchoMode TextInput::echoMode + + Specifies how the text should be displayed in the TextInput. + The default is Normal, which displays the text as it is. Other values + are Password, which displays asterixes instead of characters, NoEcho, + which displays nothing, and PasswordEchoOnEdit, which displays all but the + current character as asterixes. + +*/ +QmlGraphicsTextInput::EchoMode QmlGraphicsTextInput::echoMode() const +{ + Q_D(const QmlGraphicsTextInput); + return (QmlGraphicsTextInput::EchoMode)d->control->echoMode(); +} + +void QmlGraphicsTextInput::setEchoMode(QmlGraphicsTextInput::EchoMode echo) +{ + Q_D(QmlGraphicsTextInput); + d->control->setEchoMode((uint)echo); +} + +/*! + \qmlproperty Component TextInput::cursorDelegate + The delegate for the cursor in the TextInput. + + If you set a cursorDelegate for a TextInput, this delegate will be used for + drawing the cursor instead of the standard cursor. An instance of the + delegate will be created and managed by the TextInput when a cursor is + needed, and the x property of delegate instance will be set so as + to be one pixel before the top left of the current character. + + Note that the root item of the delegate component must be a QmlGraphicsItem or + QmlGraphicsItem derived item. +*/ +QmlComponent* QmlGraphicsTextInput::cursorDelegate() const +{ + Q_D(const QmlGraphicsTextInput); + return d->cursorComponent; +} + +void QmlGraphicsTextInput::setCursorDelegate(QmlComponent* c) +{ + Q_D(QmlGraphicsTextInput); + d->cursorComponent = c; + if(!c){ + //note that the components are owned by something else + disconnect(d->control, SIGNAL(cursorPositionChanged(int, int)), + this, SLOT(moveCursor())); + delete d->cursorItem; + }else{ + d->startCreatingCursor(); + } +} + +void QmlGraphicsTextInputPrivate::startCreatingCursor() +{ + Q_Q(QmlGraphicsTextInput); + q->connect(control, SIGNAL(cursorPositionChanged(int, int)), + q, SLOT(moveCursor())); + if(cursorComponent->isReady()){ + q->createCursor(); + }else if(cursorComponent->isLoading()){ + q->connect(cursorComponent, SIGNAL(statusChanged(int)), + q, SLOT(createCursor())); + }else{//isError + qmlInfo(QmlGraphicsTextInput::tr("Could not load cursor delegate"), q); + qWarning() << cursorComponent->errors(); + } +} + +void QmlGraphicsTextInput::createCursor() +{ + Q_D(QmlGraphicsTextInput); + if(d->cursorComponent->isError()){ + qmlInfo(tr("Could not load cursor delegate"),this); + qWarning() << d->cursorComponent->errors(); + return; + } + + if(!d->cursorComponent->isReady()) + return; + + if(d->cursorItem) + delete d->cursorItem; + d->cursorItem = qobject_cast(d->cursorComponent->create()); + if(!d->cursorItem){ + qmlInfo(tr("Could not instantiate cursor delegate"),this); + //The failed instantiation should print its own error messages + return; + } + + d->cursorItem->setParentItem(this); + d->cursorItem->setX(d->control->cursorToX()); + d->cursorItem->setHeight(d->control->height()); +} + +void QmlGraphicsTextInput::moveCursor() +{ + Q_D(QmlGraphicsTextInput); + if(!d->cursorItem) + return; + d->cursorItem->setX(d->control->cursorToX() - d->hscroll); +} + +int QmlGraphicsTextInput::xToPos(int x) +{ + Q_D(const QmlGraphicsTextInput); + return d->control->xToPos(x - d->hscroll); +} + +void QmlGraphicsTextInput::focusChanged(bool hasFocus) +{ + Q_D(QmlGraphicsTextInput); + d->focused = hasFocus; + setCursorVisible(hasFocus); + QmlGraphicsItem::focusChanged(hasFocus); +} + +void QmlGraphicsTextInput::keyPressEvent(QKeyEvent* ev) +{ + Q_D(QmlGraphicsTextInput); + if((d->control->cursor() == 0 && ev->key() == Qt::Key_Left) + || (d->control->cursor() == d->control->text().length() + && ev->key() == Qt::Key_Right)){ + //ignore when moving off the end + ev->ignore(); + }else{ + d->control->processKeyEvent(ev); + } + if (!ev->isAccepted()) + QmlGraphicsPaintedItem::keyPressEvent(ev); +} + +void QmlGraphicsTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QmlGraphicsTextInput); + if(d->focusOnPress){ + setFocus(true); + setCursorVisible(true); + d->focused = true; + } + d->control->processEvent(event); +} + +bool QmlGraphicsTextInput::event(QEvent* ev) +{ + Q_D(QmlGraphicsTextInput); + //Anything we don't deal with ourselves, pass to the control + bool handled = false; + switch(ev->type()){ + case QEvent::KeyPress: + case QEvent::KeyRelease://###Should the control be doing anything with release? + case QEvent::GraphicsSceneMousePress: + break; + default: + handled = d->control->processEvent(ev); + } + if(!handled) + return QmlGraphicsPaintedItem::event(ev); + return true; +} + +void QmlGraphicsTextInput::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) +{ + if (newGeometry.width() != oldGeometry.width()) + updateSize(); + QmlGraphicsPaintedItem::geometryChanged(newGeometry, oldGeometry); +} + +void QmlGraphicsTextInput::drawContents(QPainter *p, const QRect &r) +{ + Q_D(QmlGraphicsTextInput); + p->setRenderHint(QPainter::TextAntialiasing, true); + p->save(); + p->setPen(QPen(d->color)); + int flags = QLineControl::DrawText; + if(!isReadOnly() && d->cursorVisible && !d->cursorItem) + flags |= QLineControl::DrawCursor; + if (d->control->hasSelectedText()){ + flags |= QLineControl::DrawSelections; + } + + QPoint offset = QPoint(0,0); + QRect clipRect = r; + d->control->draw(p, offset, clipRect, flags); + + p->restore(); +} + +void QmlGraphicsTextInput::selectAll() +{ + Q_D(QmlGraphicsTextInput); + d->control->setSelection(0, d->control->text().length()); +} + + +/*! + \qmlproperty bool TextInput::smooth + + Set this property if you want the text to be smoothly scaled or + transformed. Smooth filtering gives better visual quality, but is slower. If + the item is displayed at its natural size, this property has no visual or + performance effect. + + \note Generally scaling artifacts are only visible if the item is stationary on + the screen. A common pattern when animating an item is to disable smooth + filtering at the beginning of the animation and reenable it at the conclusion. +*/ + +void QmlGraphicsTextInputPrivate::init() +{ + Q_Q(QmlGraphicsTextInput); + control->setCursorWidth(1); + control->setPasswordCharacter(QLatin1Char('*')); + control->setLayoutDirection(Qt::LeftToRight); + q->setSmoothTransform(smooth); + q->setAcceptedMouseButtons(Qt::LeftButton); + q->setFlag(QGraphicsItem::ItemHasNoContents, false); + q->setFlag(QGraphicsItem::ItemAcceptsInputMethod); + q->connect(control, SIGNAL(cursorPositionChanged(int,int)), + q, SLOT(cursorPosChanged())); + q->connect(control, SIGNAL(selectionChanged()), + q, SLOT(selectionChanged())); + q->connect(control, SIGNAL(textChanged(const QString &)), + q, SLOT(q_textChanged())); + q->connect(control, SIGNAL(accepted()), + q, SIGNAL(accepted())); + q->connect(control, SIGNAL(updateNeeded(QRect)), + q, SLOT(updateRect(QRect))); + q->connect(control, SIGNAL(cursorPositionChanged(int,int)), + q, SLOT(updateRect()));//TODO: Only update rect between pos's + q->connect(control, SIGNAL(selectionChanged()), + q, SLOT(updateRect()));//TODO: Only update rect in selection + //Note that above TODOs probably aren't that big a savings + q->updateSize(); + oldValidity = control->hasAcceptableInput(); + lastSelectionStart = 0; + lastSelectionEnd = 0; +} + +void QmlGraphicsTextInput::cursorPosChanged() +{ + Q_D(QmlGraphicsTextInput); + emit cursorPositionChanged(); + + if(!d->control->hasSelectedText()){ + if(d->lastSelectionStart != d->control->cursor()){ + d->lastSelectionStart = d->control->cursor(); + emit selectionStartChanged(); + } + if(d->lastSelectionEnd != d->control->cursor()){ + d->lastSelectionEnd = d->control->cursor(); + emit selectionEndChanged(); + } + } +} + +void QmlGraphicsTextInput::selectionChanged() +{ + Q_D(QmlGraphicsTextInput); + emit selectedTextChanged(); + + if(d->lastSelectionStart != d->control->selectionStart()){ + d->lastSelectionStart = d->control->selectionStart(); + if(d->lastSelectionStart == -1) + d->lastSelectionStart = d->control->cursor(); + emit selectionStartChanged(); + } + if(d->lastSelectionEnd != d->control->selectionEnd()){ + d->lastSelectionEnd = d->control->selectionEnd(); + if(d->lastSelectionEnd == -1) + d->lastSelectionEnd = d->control->cursor(); + emit selectionEndChanged(); + } +} + +void QmlGraphicsTextInput::q_textChanged() +{ + Q_D(QmlGraphicsTextInput); + updateSize(); + emit textChanged(); + if(hasAcceptableInput() != d->oldValidity){ + d->oldValidity = hasAcceptableInput(); + emit acceptableInputChanged(); + } +} + +void QmlGraphicsTextInput::updateRect(const QRect &r) +{ + if(r == QRect()) + clearCache(); + else + dirtyCache(r); + update(); +} + +void QmlGraphicsTextInput::updateSize(bool needsRedraw) +{ + Q_D(QmlGraphicsTextInput); + int w = width(); + int h = height(); + setImplicitHeight(d->control->height()); + int cursorWidth = d->control->cursorWidth(); + if(d->cursorItem) + cursorWidth = d->cursorItem->width(); + //### Is QFontMetrics too slow? + QFontMetricsF fm(d->font); + setImplicitWidth(fm.width(d->control->displayText())+cursorWidth); + setContentsSize(QSize(width(), height()));//Repaints if changed + if(w==width() && h==height() && needsRedraw){ + clearCache(); + update(); + } +} + +QT_END_NAMESPACE + diff --git a/src/declarative/fx/qmlgraphicstextinput.h b/src/declarative/fx/qmlgraphicstextinput.h new file mode 100644 index 0000000..1b143e0 --- /dev/null +++ b/src/declarative/fx/qmlgraphicstextinput.h @@ -0,0 +1,209 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSTEXTINPUT_H +#define QMLGRAPHICSTEXTINPUT_H + +#include "qmlgraphicstext.h" +#include "qmlgraphicspainteditem.h" +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsTextInputPrivate; +class QValidator; +class Q_DECLARATIVE_EXPORT QmlGraphicsTextInput : public QmlGraphicsPaintedItem +{ + Q_OBJECT + Q_ENUMS(HAlignment) + Q_ENUMS(EchoMode) + + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) + + Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) + Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) + Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) + Q_PROPERTY(QmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate) + Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) + Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) + Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged) + + Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength) + Q_PROPERTY(QValidator* validator READ validator WRITE setValidator) + Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask) + Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged) + Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode) + Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) + +public: + QmlGraphicsTextInput(QmlGraphicsItem* parent=0); + ~QmlGraphicsTextInput(); + + enum EchoMode {//To match QLineEdit::EchoMode + Normal, + NoEcho, + Password, + PasswordEchoOnEdit + }; + + enum HAlignment { + AlignLeft = Qt::AlignLeft, + AlignRight = Qt::AlignRight, + AlignHCenter = Qt::AlignHCenter + }; + + //### Should we have this function, x based properties, + //### or copy TextEdit with x instead of QTextCursor? + Q_INVOKABLE int xToPos(int x); + + QString text() const; + void setText(const QString &); + + QFont font() const; + void setFont(const QFont &font); + + QColor color() const; + void setColor(const QColor &c); + + QColor selectionColor() const; + void setSelectionColor(const QColor &c); + + QColor selectedTextColor() const; + void setSelectedTextColor(const QColor &c); + + HAlignment hAlign() const; + void setHAlign(HAlignment align); + + bool isReadOnly() const; + void setReadOnly(bool); + + bool isCursorVisible() const; + void setCursorVisible(bool on); + + int cursorPosition() const; + void setCursorPosition(int cp); + + QRect cursorRect() const; + + int selectionStart() const; + void setSelectionStart(int); + + int selectionEnd() const; + void setSelectionEnd(int); + + QString selectedText() const; + + int maxLength() const; + void setMaxLength(int ml); + + QValidator * validator() const; + void setValidator(QValidator* v); + + QString inputMask() const; + void setInputMask(const QString &im); + + EchoMode echoMode() const; + void setEchoMode(EchoMode echo); + + QmlComponent* cursorDelegate() const; + void setCursorDelegate(QmlComponent*); + + bool focusOnPress() const; + void setFocusOnPress(bool); + + bool hasAcceptableInput() const; + + void drawContents(QPainter *p,const QRect &r); +Q_SIGNALS: + void textChanged(); + void cursorPositionChanged(); + void selectionStartChanged(); + void selectionEndChanged(); + void selectedTextChanged(); + void accepted(); + void acceptableInputChanged(); + +protected: + QmlGraphicsTextInput(QmlGraphicsTextInputPrivate &dd, QmlGraphicsItem *parent); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void keyPressEvent(QKeyEvent* ev); + bool event(QEvent *e); + + void focusChanged(bool hasFocus); + +public Q_SLOTS: + void selectAll(); + +private Q_SLOTS: + void updateSize(bool needsRedraw = true); + void q_textChanged(); + void selectionChanged(); + void createCursor(); + void moveCursor(); + void cursorPosChanged(); + void updateRect(const QRect &r = QRect()); + +private: + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsTextInput) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsTextInput) +QML_DECLARE_TYPE(QValidator) +QML_DECLARE_TYPE(QIntValidator) + +QT_END_HEADER + +#endif // QMLGRAPHICSTEXTINPUT_H diff --git a/src/declarative/fx/qmlgraphicstextinput_p.h b/src/declarative/fx/qmlgraphicstextinput_p.h new file mode 100644 index 0000000..010dfe1 --- /dev/null +++ b/src/declarative/fx/qmlgraphicstextinput_p.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSTEXTINPUT_P_H +#define QMLGRAPHICSTEXTINPUT_P_H + +#include "qmlgraphicstextinput.h" +#include "qml.h" +#include "qmlgraphicspainteditem_p.h" +#include "private/qlinecontrol_p.h" +#include +// +// 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. + +QT_BEGIN_NAMESPACE + +class QmlGraphicsTextInputPrivate : public QmlGraphicsPaintedItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsTextInput) +public: + QmlGraphicsTextInputPrivate() : control(new QLineControl(QString())), + color((QRgb)0), style(QmlGraphicsText::Normal), + styleColor((QRgb)0), hAlign(QmlGraphicsTextInput::AlignLeft), + hscroll(0), oldScroll(0), focused(false), focusOnPress(true), + cursorVisible(false) + { + } + + ~QmlGraphicsTextInputPrivate() + { + delete control; + } + + void init(); + void startCreatingCursor(); + + QLineControl* control; + + QFont font; + QColor color; + QColor selectionColor; + QColor selectedTextColor; + QmlGraphicsText::TextStyle style; + QColor styleColor; + QmlGraphicsTextInput::HAlignment hAlign; + QPointer cursorComponent; + QPointer cursorItem; + + int lastSelectionStart; + int lastSelectionEnd; + int oldHeight; + int oldWidth; + bool oldValidity; + int hscroll; + int oldScroll; + bool focused; + bool focusOnPress; + bool cursorVisible; +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/declarative/fx/qmlgraphicsvisualitemmodel.cpp b/src/declarative/fx/qmlgraphicsvisualitemmodel.cpp new file mode 100644 index 0000000..b9b0237 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsvisualitemmodel.cpp @@ -0,0 +1,1032 @@ +/**************************************************************************** +** +** 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 "qlistmodelinterface.h" +#include "qmlgraphicsitem.h" +#include +#include +#include "qmlpackage.h" +#include "qhash.h" +#include "qlist.h" +#include "private/qobject_p.h" +#include "private/qmetaobjectbuilder_p.h" +#include "qmlopenmetaobject.h" +#include "qmllistaccessor.h" +#include "qmlinfo.h" +#include "qmlgraphicsvisualitemmodel.h" +#include "private/qguard_p.h" +#include + +QML_DECLARE_TYPE(QListModelInterface) + +QT_BEGIN_NAMESPACE + +class QmlGraphicsVisualItemModelAttached : public QObject +{ + Q_OBJECT + +public: + QmlGraphicsVisualItemModelAttached(QObject *parent) + : QObject(parent), m_index(0) {} + ~QmlGraphicsVisualItemModelAttached() { + attachedProperties.remove(parent()); + } + + Q_PROPERTY(int index READ index NOTIFY indexChanged) + int index() const { return m_index; } + void setIndex(int idx) { + if (m_index != idx) { + m_index = idx; + emit indexChanged(); + } + } + + static QmlGraphicsVisualItemModelAttached *properties(QObject *obj) { + QmlGraphicsVisualItemModelAttached *rv = attachedProperties.value(obj); + if (!rv) { + rv = new QmlGraphicsVisualItemModelAttached(obj); + attachedProperties.insert(obj, rv); + } + return rv; + } + +Q_SIGNALS: + void indexChanged(); + +public: + int m_index; + + static QHash attachedProperties; +}; + +QHash QmlGraphicsVisualItemModelAttached::attachedProperties; + + +class QmlGraphicsVisualItemModelPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsVisualItemModel) +public: + QmlGraphicsVisualItemModelPrivate() : QObjectPrivate(), children(this) {} + + struct ItemList : public QmlConcreteList + { + ItemList(QmlGraphicsVisualItemModelPrivate *m) : QmlConcreteList(), model(m) {} + + void append(QmlGraphicsItem *item); + + QmlGraphicsVisualItemModelPrivate *model; + }; + + void itemAppended() { + Q_Q(QmlGraphicsVisualItemModel); + QmlGraphicsVisualItemModelAttached *attached = QmlGraphicsVisualItemModelAttached::properties(children.last()); + attached->setIndex(children.count()-1); + emit q->itemsInserted(children.count()-1, 1); + emit q->countChanged(); + } + + void emitChildrenChanged() { + Q_Q(QmlGraphicsVisualItemModel); + emit q->childrenChanged(); + } + ItemList children; +}; + + +/*! + \qmlclass VisualItemModel QmlGraphicsVisualItemModel + \brief The VisualItemModel allows items to be provided to a view. + + The children of the VisualItemModel are provided in a model which + can be used in a view. Note that no delegate should be + provided to a view since the VisualItemModel contains the + visual delegate (items). + + An item can determine its index within the + model via the VisualItemModel.index attached property. + + The example below places three colored rectangles in a ListView. + \code + Item { + VisualItemModel { + id: itemModel + Rectangle { height: 30; width: 80; color: "red" } + Rectangle { height: 30; width: 80; color: "green" } + Rectangle { height: 30; width: 80; color: "blue" } + } + + ListView { + anchors.fill: parent + model: itemModel + } + } + \endcode +*/ +QmlGraphicsVisualItemModel::QmlGraphicsVisualItemModel() + : QmlGraphicsVisualModel(*(new QmlGraphicsVisualItemModelPrivate)) +{ +} + +QmlList *QmlGraphicsVisualItemModel::children() +{ + Q_D(QmlGraphicsVisualItemModel); + return &(d->children); +} + +/*! + \qmlproperty int VisualItemModel::count + + The number of items in the model. This property is readonly. +*/ +int QmlGraphicsVisualItemModel::count() const +{ + Q_D(const QmlGraphicsVisualItemModel); + return d->children.count(); +} + +bool QmlGraphicsVisualItemModel::isValid() const +{ + return true; +} + +QmlGraphicsItem *QmlGraphicsVisualItemModel::item(int index, bool) +{ + Q_D(QmlGraphicsVisualItemModel); + return d->children.at(index); +} + +QmlGraphicsVisualModel::ReleaseFlags QmlGraphicsVisualItemModel::release(QmlGraphicsItem *) +{ + // Nothing to do + return 0; +} + +void QmlGraphicsVisualItemModel::completeItem() +{ + // Nothing to do +} + +QVariant QmlGraphicsVisualItemModel::evaluate(int index, const QString &expression, QObject *objectContext) +{ + Q_D(QmlGraphicsVisualItemModel); + QmlContext *ccontext = qmlContext(this); + QmlContext *ctxt = new QmlContext(ccontext); + ctxt->addDefaultObject(d->children.at(index)); + QmlExpression e(ctxt, expression, objectContext); + e.setTrackChange(false); + QVariant value = e.value(); + delete ctxt; + return value; +} + +int QmlGraphicsVisualItemModel::indexOf(QmlGraphicsItem *item, QObject *) const +{ + Q_D(const QmlGraphicsVisualItemModel); + return d->children.indexOf(item); +} + +void QmlGraphicsVisualItemModelPrivate::ItemList::append(QmlGraphicsItem *item) +{ + QmlConcreteList::append(item); + item->QObject::setParent(model->q_ptr); + model->itemAppended(); + + model->emitChildrenChanged(); +} + +QmlGraphicsVisualItemModelAttached *QmlGraphicsVisualItemModel::qmlAttachedProperties(QObject *obj) +{ + return QmlGraphicsVisualItemModelAttached::properties(obj); +} + + +class QmlGraphicsVisualDataModelParts; +class QmlGraphicsVisualDataModelData; +class QmlGraphicsVisualDataModelPrivate : public QObjectPrivate +{ +public: + QmlGraphicsVisualDataModelPrivate(QmlContext *); + + static QmlGraphicsVisualDataModelPrivate *get(QmlGraphicsVisualDataModel *m) { + return static_cast(QObjectPrivate::get(m)); + } + + QGuard m_listModelInterface; + QGuard m_abstractItemModel; + QGuard m_visualItemModel; + QString m_part; + + QmlComponent *m_delegate; + QmlContext *m_context; + QList m_roles; + QHash m_roleNames; + void ensureRoles() { + if (m_roleNames.isEmpty()) { + if (m_listModelInterface) { + m_roles = m_listModelInterface->roles(); + for (int ii = 0; ii < m_roles.count(); ++ii) + m_roleNames.insert(m_listModelInterface->toString(m_roles.at(ii)), m_roles.at(ii)); + if (m_roles.count() == 1) + m_roleNames.insert(QLatin1String("modelData"), m_roles.at(0)); + } else if (m_abstractItemModel) { + for (QHash::const_iterator it = m_abstractItemModel->roleNames().begin(); + it != m_abstractItemModel->roleNames().end(); ++it) { + m_roles.append(it.key()); + m_roleNames.insert(QString::fromUtf8(*it), it.key()); + } + if (m_roles.count() == 1) + m_roleNames.insert(QLatin1String("modelData"), m_roles.at(0)); + } else if (m_listAccessor) { + m_roleNames.insert(QLatin1String("modelData"), 0); + if (m_listAccessor->type() == QmlListAccessor::Instance) { + if (QObject *object = m_listAccessor->at(0).value()) { + int count = object->metaObject()->propertyCount(); + for (int ii = 1; ii < count; ++ii) { + const QMetaProperty &prop = object->metaObject()->property(ii); + m_roleNames.insert(QString::fromUtf8(prop.name()), 0); + } + } + } + } + } + } + + struct ObjectRef { + ObjectRef(QObject *object=0) : obj(object), ref(1) {} + QObject *obj; + int ref; + }; + class Cache : public QHash { + public: + QObject *getItem(int index) { + QObject *item = 0; + QHash::iterator it = find(index); + if (it != end()) { + (*it).ref++; + item = (*it).obj; + } + return item; + } + QObject *item(int index) { + QObject *item = 0; + QHash::const_iterator it = find(index); + if (it != end()) + item = (*it).obj; + return item; + } + void insertItem(int index, QObject *obj) { + insert(index, ObjectRef(obj)); + } + bool releaseItem(QObject *obj) { + QHash::iterator it = begin(); + for (; it != end(); ++it) { + ObjectRef &objRef = *it; + if (objRef.obj == obj) { + if (--objRef.ref == 0) { + erase(it); + return true; + } + break; + } + } + return false; + } + }; + + Cache m_cache; + QHash m_packaged; + + QmlGraphicsVisualDataModelParts *m_parts; + friend class QmlGraphicsVisualItemParts; + + QmlGraphicsVisualDataModelData *data(QObject *item); + + QVariant m_modelVariant; + QmlListAccessor *m_listAccessor; + + int modelCount() const { + if (m_visualItemModel) + return m_visualItemModel->count(); + if (m_listModelInterface) + return m_listModelInterface->count(); + if (m_abstractItemModel) + return m_abstractItemModel->rowCount(); + if (m_listAccessor) + return m_listAccessor->count(); + return 0; + } +}; + +class QmlGraphicsVisualDataModelDataMetaObject : public QmlOpenMetaObject +{ +public: + QmlGraphicsVisualDataModelDataMetaObject(QObject *parent) + : QmlOpenMetaObject(parent) {} + + virtual QVariant propertyCreated(int, QMetaPropertyBuilder &); + virtual int createProperty(const char *, const char *); + +private: + friend class QmlGraphicsVisualDataModelData; + QList roles; +}; + +class QmlGraphicsVisualDataModelData : public QObject +{ +Q_OBJECT +public: + QmlGraphicsVisualDataModelData(int index, QmlGraphicsVisualDataModel *model); + ~QmlGraphicsVisualDataModelData(); + + Q_PROPERTY(int index READ index NOTIFY indexChanged) + int index() const; + void setIndex(int index); + + int count() const; + int role(int) const; + void setValue(int, const QVariant &); + +Q_SIGNALS: + void indexChanged(); + +private: + friend class QmlGraphicsVisualDataModelDataMetaObject; + int m_index; + QGuard m_model; + QmlGraphicsVisualDataModelDataMetaObject *m_meta; +}; + +int QmlGraphicsVisualDataModelData::count() const +{ + return m_meta->count(); +} + +int QmlGraphicsVisualDataModelData::role(int id) const +{ + Q_ASSERT(id >= 0 && id < count()); + return m_meta->roles.at(id); +} + +void QmlGraphicsVisualDataModelData::setValue(int id, const QVariant &val) +{ + m_meta->setValue(id, val); +} + +int QmlGraphicsVisualDataModelDataMetaObject::createProperty(const char *name, const char *type) +{ + QmlGraphicsVisualDataModelData *data = + static_cast(object()); + + if (!data->m_model) + return -1; + + QmlGraphicsVisualDataModelPrivate *model = QmlGraphicsVisualDataModelPrivate::get(data->m_model); + + if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) { + model->ensureRoles(); + if (model->m_roleNames.contains(QString::fromUtf8(name))) { + return QmlOpenMetaObject::createProperty(name, type); + } else if (model->m_listAccessor->type() == QmlListAccessor::QmlList) { + QObject *object = model->m_listAccessor->at(data->m_index).value(); + if (object && object->property(name).isValid()) + return QmlOpenMetaObject::createProperty(name, type); + } + } else { + model->ensureRoles(); + QString sname = QString::fromUtf8(name); + if (model->m_roleNames.contains(sname)) + return QmlOpenMetaObject::createProperty(name, type); + } + return -1; +} + +QVariant +QmlGraphicsVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuilder &prop) +{ + prop.setWritable(false); + + QmlGraphicsVisualDataModelData *data = + static_cast(object()); + + Q_ASSERT(data->m_model); + QmlGraphicsVisualDataModelPrivate *model = QmlGraphicsVisualDataModelPrivate::get(data->m_model); + + QString name = QString::fromUtf8(prop.name()); + if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) { + if (name == QLatin1String("modelData")) { + if (model->m_listAccessor->type() == QmlListAccessor::Instance) { + QObject *object = model->m_listAccessor->at(0).value(); + return object->metaObject()->property(1).read(object); // the first property after objectName + } + return model->m_listAccessor->at(data->m_index); + } else { + // return any property of a single object instance. + QObject *object = model->m_listAccessor->at(data->m_index).value(); + return object->property(prop.name()); + } + } else if (model->m_listModelInterface) { + model->ensureRoles(); + QHash::const_iterator it = model->m_roleNames.find(name); + if (it != model->m_roleNames.end()) { + roles.append(*it); + QHash values = model->m_listModelInterface->data(data->m_index, QList() << *it); + if (values.isEmpty()) + return QVariant(); + else + return values.value(*it); + } else if (model->m_roles.count() == 1 && name == QLatin1String("modelData")) { + //for compatability with other lists, assign modelData if there is only a single role + QHash values = model->m_listModelInterface->data(data->m_index, QList() << model->m_roles.first()); + if (values.isEmpty()) + return QVariant(); + else + return *values.begin(); + } + } else if (model->m_abstractItemModel) { + model->ensureRoles(); + QHash::const_iterator it = model->m_roleNames.find(name); + if (it != model->m_roleNames.end()) { + roles.append(*it); + QModelIndex index = model->m_abstractItemModel->index(data->m_index, 0); + return model->m_abstractItemModel->data(index, *it); + } + } + Q_ASSERT(!"Can never be reached"); + return QVariant(); +} + +QmlGraphicsVisualDataModelData::QmlGraphicsVisualDataModelData(int index, + QmlGraphicsVisualDataModel *model) +: m_index(index), m_model(model), + m_meta(new QmlGraphicsVisualDataModelDataMetaObject(this)) +{ +} + +QmlGraphicsVisualDataModelData::~QmlGraphicsVisualDataModelData() +{ +} + +int QmlGraphicsVisualDataModelData::index() const +{ + return m_index; +} + +// This is internal only - it should not be set from qml +void QmlGraphicsVisualDataModelData::setIndex(int index) +{ + m_index = index; + emit indexChanged(); +} + +class QmlGraphicsVisualDataModelPartsMetaObject : public QmlOpenMetaObject +{ +public: + QmlGraphicsVisualDataModelPartsMetaObject(QObject *parent) + : QmlOpenMetaObject(parent) {} + + virtual QVariant propertyCreated(int, QMetaPropertyBuilder &); +}; + +class QmlGraphicsVisualDataModelParts : public QObject +{ +Q_OBJECT +public: + QmlGraphicsVisualDataModelParts(QmlGraphicsVisualDataModel *parent); + +private: + friend class QmlGraphicsVisualDataModelPartsMetaObject; + QmlGraphicsVisualDataModel *model; +}; + +QVariant +QmlGraphicsVisualDataModelPartsMetaObject::propertyCreated(int, QMetaPropertyBuilder &prop) +{ + prop.setWritable(false); + + QmlGraphicsVisualDataModel *m = new QmlGraphicsVisualDataModel; + m->setParent(object()); + m->setPart(QString::fromUtf8(prop.name())); + m->setModel(QVariant::fromValue(static_cast(object())->model)); + + QVariant var = QVariant::fromValue((QObject *)m); + return var; +} + +QmlGraphicsVisualDataModelParts::QmlGraphicsVisualDataModelParts(QmlGraphicsVisualDataModel *parent) +: QObject(parent), model(parent) +{ + new QmlGraphicsVisualDataModelPartsMetaObject(this); +} + +QmlGraphicsVisualDataModelPrivate::QmlGraphicsVisualDataModelPrivate(QmlContext *ctxt) +: m_listModelInterface(0), m_abstractItemModel(0), m_visualItemModel(0), m_delegate(0) +, m_context(ctxt), m_parts(0), m_listAccessor(0) +{ +} + +QmlGraphicsVisualDataModelData *QmlGraphicsVisualDataModelPrivate::data(QObject *item) +{ + QmlGraphicsVisualDataModelData *dataItem = + item->findChild(); + Q_ASSERT(dataItem); + return dataItem; +} + +QmlGraphicsVisualDataModel::QmlGraphicsVisualDataModel() +: QmlGraphicsVisualModel(*(new QmlGraphicsVisualDataModelPrivate(0))) +{ +} + +QmlGraphicsVisualDataModel::QmlGraphicsVisualDataModel(QmlContext *ctxt) +: QmlGraphicsVisualModel(*(new QmlGraphicsVisualDataModelPrivate(ctxt))) +{ +} + +QmlGraphicsVisualDataModel::~QmlGraphicsVisualDataModel() +{ + Q_D(QmlGraphicsVisualDataModel); + if (d->m_listAccessor) + delete d->m_listAccessor; +} + +QVariant QmlGraphicsVisualDataModel::model() const +{ + Q_D(const QmlGraphicsVisualDataModel); + return d->m_modelVariant; +} + +void QmlGraphicsVisualDataModel::setModel(const QVariant &model) +{ + Q_D(QmlGraphicsVisualDataModel); + delete d->m_listAccessor; + d->m_listAccessor = 0; + d->m_modelVariant = model; + if (d->m_listModelInterface) { + // Assume caller has released all items. + QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsChanged(int,int,QList)), + this, SLOT(_q_itemsChanged(int,int,QList))); + QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsInserted(int,int)), + this, SLOT(_q_itemsInserted(int,int))); + QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsRemoved(int,int)), + this, SLOT(_q_itemsRemoved(int,int))); + QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsMoved(int,int,int)), + this, SLOT(_q_itemsMoved(int,int,int))); + d->m_listModelInterface = 0; + } else if (d->m_abstractItemModel) { + QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsInserted(const QModelIndex &,int,int)), + this, SLOT(_q_rowsInserted(const QModelIndex &,int,int))); + QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsRemoved(const QModelIndex &,int,int)), + this, SLOT(_q_rowsRemoved(const QModelIndex &,int,int))); + QObject::disconnect(d->m_abstractItemModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), + this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); + } else if (d->m_visualItemModel) { + QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), + this, SIGNAL(itemsInserted(int,int))); + QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsRemoved(int,int)), + this, SIGNAL(itemsRemoved(int,int))); + QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsMoved(int,int,int)), + this, SIGNAL(itemsMoved(int,int,int))); + QObject::disconnect(d->m_visualItemModel, SIGNAL(createdPackage(int,QmlPackage*)), + this, SLOT(_q_createdPackage(int,QmlPackage*))); + QObject::disconnect(d->m_visualItemModel, SIGNAL(destroyingPackage(QmlPackage*)), + this, SLOT(_q_destroyingPackage(QmlPackage*))); + d->m_visualItemModel = 0; + } + + d->m_roles.clear(); + d->m_roleNames.clear(); + + QObject *object = qvariant_cast(model); + if (object && (d->m_listModelInterface = qobject_cast(object))) { + QObject::connect(d->m_listModelInterface, SIGNAL(itemsChanged(int,int,QList)), + this, SLOT(_q_itemsChanged(int,int,QList))); + QObject::connect(d->m_listModelInterface, SIGNAL(itemsInserted(int,int)), + this, SLOT(_q_itemsInserted(int,int))); + QObject::connect(d->m_listModelInterface, SIGNAL(itemsRemoved(int,int)), + this, SLOT(_q_itemsRemoved(int,int))); + QObject::connect(d->m_listModelInterface, SIGNAL(itemsMoved(int,int,int)), + this, SLOT(_q_itemsMoved(int,int,int))); + if (d->m_delegate && d->m_listModelInterface->count()) + emit itemsInserted(0, d->m_listModelInterface->count()); + return; + } else if (object && (d->m_abstractItemModel = qobject_cast(object))) { + QObject::connect(d->m_abstractItemModel, SIGNAL(rowsInserted(const QModelIndex &,int,int)), + this, SLOT(_q_rowsInserted(const QModelIndex &,int,int))); + QObject::connect(d->m_abstractItemModel, SIGNAL(rowsRemoved(const QModelIndex &,int,int)), + this, SLOT(_q_rowsRemoved(const QModelIndex &,int,int))); + QObject::connect(d->m_abstractItemModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), + this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); + return; + } + if ((d->m_visualItemModel = qvariant_cast(model))) { + QObject::connect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), + this, SIGNAL(itemsInserted(int,int))); + QObject::connect(d->m_visualItemModel, SIGNAL(itemsRemoved(int,int)), + this, SIGNAL(itemsRemoved(int,int))); + QObject::connect(d->m_visualItemModel, SIGNAL(itemsMoved(int,int,int)), + this, SIGNAL(itemsMoved(int,int,int))); + QObject::connect(d->m_visualItemModel, SIGNAL(createdPackage(int,QmlPackage*)), + this, SLOT(_q_createdPackage(int,QmlPackage*))); + QObject::connect(d->m_visualItemModel, SIGNAL(destroyingPackage(QmlPackage*)), + this, SLOT(_q_destroyingPackage(QmlPackage*))); + return; + } + d->m_listAccessor = new QmlListAccessor; + d->m_listAccessor->setList(model, d->m_context?d->m_context->engine():qmlEngine(this)); + if (d->m_delegate && d->modelCount()) { + emit itemsInserted(0, d->modelCount()); + emit countChanged(); + } +} + +QmlComponent *QmlGraphicsVisualDataModel::delegate() const +{ + Q_D(const QmlGraphicsVisualDataModel); + if (d->m_visualItemModel) + return d->m_visualItemModel->delegate(); + return d->m_delegate; +} + +void QmlGraphicsVisualDataModel::setDelegate(QmlComponent *delegate) +{ + Q_D(QmlGraphicsVisualDataModel); + d->m_delegate = delegate; + if (d->modelCount()) { + emit itemsInserted(0, d->modelCount()); + emit countChanged(); + } +} + +QString QmlGraphicsVisualDataModel::part() const +{ + Q_D(const QmlGraphicsVisualDataModel); + return d->m_part; +} + +void QmlGraphicsVisualDataModel::setPart(const QString &part) +{ + Q_D(QmlGraphicsVisualDataModel); + d->m_part = part; +} + +int QmlGraphicsVisualDataModel::count() const +{ + Q_D(const QmlGraphicsVisualDataModel); + return d->modelCount(); +} + +QmlGraphicsItem *QmlGraphicsVisualDataModel::item(int index, bool complete) +{ + Q_D(QmlGraphicsVisualDataModel); + if (d->m_visualItemModel) + return d->m_visualItemModel->item(index, d->m_part.toUtf8(), complete); + return item(index, QByteArray(), complete); +} + +/* + Returns ReleaseStatus flags. +*/ +QmlGraphicsVisualDataModel::ReleaseFlags QmlGraphicsVisualDataModel::release(QmlGraphicsItem *item) +{ + Q_D(QmlGraphicsVisualDataModel); + if (d->m_visualItemModel) + return d->m_visualItemModel->release(item); + + ReleaseFlags stat = 0; + QObject *obj = item; + bool inPackage = false; + + QHash::iterator it = d->m_packaged.find(item); + if (it != d->m_packaged.end()) { + QmlPackage *package = *it; + d->m_packaged.erase(it); + if (d->m_packaged.contains(item)) + stat |= Referenced; + inPackage = true; + obj = package; // fall through and delete + } + + if (d->m_cache.releaseItem(obj)) { + if (inPackage) + emit destroyingPackage(qobject_cast(obj)); + stat |= Destroyed; + obj->setParent(0); + obj->deleteLater(); + } else if (!inPackage) { + stat |= Referenced; + } + + return stat; +} + +QObject *QmlGraphicsVisualDataModel::parts() +{ + Q_D(QmlGraphicsVisualDataModel); + if (!d->m_parts) + d->m_parts = new QmlGraphicsVisualDataModelParts(this); + return d->m_parts; +} + +QmlGraphicsItem *QmlGraphicsVisualDataModel::item(int index, const QByteArray &viewId, bool complete) +{ + Q_D(QmlGraphicsVisualDataModel); + if (d->m_visualItemModel) + return d->m_visualItemModel->item(index, viewId, complete); + + if (d->modelCount() <= 0 || !d->m_delegate) + return 0; + + QObject *nobj = d->m_cache.getItem(index); + if (!nobj) { + QmlContext *ccontext = d->m_context; + if (!ccontext) ccontext = qmlContext(this); + QmlContext *ctxt = new QmlContext(ccontext); + QmlGraphicsVisualDataModelData *data = new QmlGraphicsVisualDataModelData(index, this); + ctxt->setContextProperty(QLatin1String("model"), data); + ctxt->addDefaultObject(data); + nobj = d->m_delegate->beginCreate(ctxt); + if (complete) + d->m_delegate->completeCreate(); + if (nobj) { + ctxt->setParent(nobj); + data->setParent(nobj); + d->m_cache.insertItem(index, nobj); + if (QmlPackage *package = qobject_cast(nobj)) + emit createdPackage(index, package); + } else { + delete data; + delete ctxt; + qWarning() << d->m_delegate->errors(); + } + } + QmlGraphicsItem *item = qobject_cast(nobj); + if (!item) { + QmlPackage *package = qobject_cast(nobj); + if (package) { + QObject *o = package->part(QString::fromUtf8(viewId)); + item = qobject_cast(o); + if (item) + d->m_packaged.insertMulti(item, package); + } + } + if (!item) { + d->m_cache.releaseItem(nobj); + qmlInfo(QmlGraphicsVisualDataModel::tr("Delegate component must be Item type."), d->m_delegate); + } + + return item; +} + +void QmlGraphicsVisualDataModel::completeItem() +{ + Q_D(QmlGraphicsVisualDataModel); + if (d->m_visualItemModel) { + d->m_visualItemModel->completeItem(); + return; + } + + d->m_delegate->completeCreate(); +} + +QVariant QmlGraphicsVisualDataModel::evaluate(int index, const QString &expression, QObject *objectContext) +{ + Q_D(QmlGraphicsVisualDataModel); + if (d->m_visualItemModel) + return d->m_visualItemModel->evaluate(index, expression, objectContext); + + if ((!d->m_listModelInterface && !d->m_abstractItemModel) || !d->m_delegate) + return QVariant(); + + QVariant value; + QObject *nobj = d->m_cache.item(index); + if (nobj) { + QmlGraphicsItem *item = qobject_cast(nobj); + if (item) { + QmlExpression e(qmlContext(item), expression, objectContext); + e.setTrackChange(false); + value = e.value(); + } + } else { + QmlContext *ccontext = d->m_context; + if (!ccontext) ccontext = qmlContext(this); + QmlContext *ctxt = new QmlContext(ccontext); + QmlGraphicsVisualDataModelData *data = new QmlGraphicsVisualDataModelData(index, this); + ctxt->addDefaultObject(data); + QmlExpression e(ctxt, expression, objectContext); + e.setTrackChange(false); + value = e.value(); + delete data; + delete ctxt; + } + + return value; +} + +int QmlGraphicsVisualDataModel::indexOf(QmlGraphicsItem *item, QObject *objectContext) const +{ + QmlExpression e(qmlContext(item), QLatin1String("index"), objectContext); + e.setTrackChange(false); + QVariant value = e.value(); + if (value.isValid()) + return value.toInt(); + return -1; +} + +void QmlGraphicsVisualDataModel::_q_itemsChanged(int index, int count, + const QList &roles) +{ + Q_D(QmlGraphicsVisualDataModel); + // XXX - highly inefficient + for (int ii = index; ii < index + count; ++ii) { + + if (QObject *item = d->m_cache.item(ii)) { + QmlGraphicsVisualDataModelData *data = d->data(item); + + for (int prop = 0; prop < data->count(); ++prop) { + + int role = data->role(prop); + if (roles.contains(role)) { + if (d->m_listModelInterface) { + data->setValue(prop, d->m_listModelInterface->data(ii, QList() << role).value(role)); + } else if (d->m_abstractItemModel) { + QModelIndex index = d->m_abstractItemModel->index(ii, 0); + data->setValue(prop, d->m_abstractItemModel->data(index, role)); + } + } + } + } + + } +} + +void QmlGraphicsVisualDataModel::_q_itemsInserted(int index, int count) +{ + Q_D(QmlGraphicsVisualDataModel); + // XXX - highly inefficient + QHash items; + for (QHash::Iterator iter = d->m_cache.begin(); + iter != d->m_cache.end(); ) { + + if (iter.key() >= index) { + QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; + int index = iter.key() + count; + iter = d->m_cache.erase(iter); + + items.insert(index, objRef); + + QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); + data->setIndex(index); + } else { + ++iter; + } + } + d->m_cache.unite(items); + + emit itemsInserted(index, count); + emit countChanged(); +} + +void QmlGraphicsVisualDataModel::_q_itemsRemoved(int index, int count) +{ + Q_D(QmlGraphicsVisualDataModel); + // XXX - highly inefficient + QHash items; + for (QHash::Iterator iter = d->m_cache.begin(); + iter != d->m_cache.end(); ) { + if (iter.key() >= index && iter.key() < index + count) { + QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; + iter = d->m_cache.erase(iter); + items.insertMulti(-1, objRef); //XXX perhaps better to maintain separately + QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); + data->setIndex(-1); + } else if (iter.key() >= index + count) { + QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; + int index = iter.key() - count; + iter = d->m_cache.erase(iter); + items.insert(index, objRef); + QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); + data->setIndex(index); + } else { + ++iter; + } + } + + d->m_cache.unite(items); + emit itemsRemoved(index, count); + emit countChanged(); +} + +void QmlGraphicsVisualDataModel::_q_itemsMoved(int from, int to, int count) +{ + Q_D(QmlGraphicsVisualDataModel); + // XXX - highly inefficient + QHash items; + for (QHash::Iterator iter = d->m_cache.begin(); + iter != d->m_cache.end(); ) { + + if (iter.key() >= from && iter.key() < from + count) { + QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; + int index = iter.key() - from + to; + iter = d->m_cache.erase(iter); + + items.insert(index, objRef); + + QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); + data->setIndex(index); + } else { + ++iter; + } + } + for (QHash::Iterator iter = d->m_cache.begin(); + iter != d->m_cache.end(); ) { + + if (iter.key() >= qMin(from,to) && iter.key() < qMax(from+count,to+count)) { + QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; + int index = iter.key() + from - to; + iter = d->m_cache.erase(iter); + + items.insert(index, objRef); + + QmlGraphicsVisualDataModelData *data = d->data(objRef.obj); + data->setIndex(index); + } else { + ++iter; + } + } + d->m_cache.unite(items); + + emit itemsMoved(from, to, count); +} + +void QmlGraphicsVisualDataModel::_q_rowsInserted(const QModelIndex &, int begin, int end) +{ + _q_itemsInserted(begin, end - begin + 1); +} + +void QmlGraphicsVisualDataModel::_q_rowsRemoved(const QModelIndex &, int begin, int end) +{ + _q_itemsRemoved(begin, end - begin + 1); +} + +void QmlGraphicsVisualDataModel::_q_dataChanged(const QModelIndex &begin, const QModelIndex &end) +{ + Q_D(QmlGraphicsVisualDataModel); + _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); +} + +void QmlGraphicsVisualDataModel::_q_createdPackage(int index, QmlPackage *package) +{ + Q_D(QmlGraphicsVisualDataModel); + emit createdItem(index, qobject_cast(package->part(d->m_part))); +} + +void QmlGraphicsVisualDataModel::_q_destroyingPackage(QmlPackage *package) +{ + Q_D(QmlGraphicsVisualDataModel); + emit destroyingItem(qobject_cast(package->part(d->m_part))); +} + +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsVisualModel); +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisualItemModel,QmlGraphicsVisualItemModel) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisualDataModel,QmlGraphicsVisualDataModel) + +QT_END_NAMESPACE +#include "qfxvisualitemmodel.moc" diff --git a/src/declarative/fx/qmlgraphicsvisualitemmodel.h b/src/declarative/fx/qmlgraphicsvisualitemmodel.h new file mode 100644 index 0000000..fb36531 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsvisualitemmodel.h @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSVISUALDATAMODEL_H +#define QMLGRAPHICSVISUALDATAMODEL_H + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +/***************************************************************************** + ***************************************************************************** + XXX Experimental + ***************************************************************************** +*****************************************************************************/ + +class QmlGraphicsItem; +class QmlComponent; +class QmlPackage; +class QmlGraphicsVisualDataModelPrivate; + +class Q_DECLARATIVE_EXPORT QmlGraphicsVisualModel : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int count READ count NOTIFY countChanged) + +public: + QmlGraphicsVisualModel() {} + virtual ~QmlGraphicsVisualModel() {} + + enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 }; + Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag) + + virtual int count() const = 0; + virtual bool isValid() const = 0; + virtual QmlGraphicsItem *item(int index, bool complete=true) = 0; + virtual ReleaseFlags release(QmlGraphicsItem *item) = 0; + virtual void completeItem() = 0; + virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext) = 0; + + virtual int indexOf(QmlGraphicsItem *item, QObject *objectContext) const = 0; + +Q_SIGNALS: + void countChanged(); + void itemsInserted(int index, int count); + void itemsRemoved(int index, int count); + void itemsMoved(int from, int to, int count); + void createdItem(int index, QmlGraphicsItem *item); + void destroyingItem(QmlGraphicsItem *item); + +protected: + QmlGraphicsVisualModel(QObjectPrivate &dd, QObject *parent = 0) + : QObject(dd, parent) {} + +private: + Q_DISABLE_COPY(QmlGraphicsVisualModel) +}; + +class QmlGraphicsVisualItemModelAttached; +class QmlGraphicsVisualItemModelPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsVisualItemModel : public QmlGraphicsVisualModel +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlGraphicsVisualItemModel) + + Q_PROPERTY(QmlList* children READ children NOTIFY childrenChanged DESIGNABLE false) + Q_CLASSINFO("DefaultProperty", "children") + +public: + QmlGraphicsVisualItemModel(); + virtual ~QmlGraphicsVisualItemModel() {} + + virtual int count() const; + virtual bool isValid() const; + virtual QmlGraphicsItem *item(int index, bool complete=true); + virtual ReleaseFlags release(QmlGraphicsItem *item); + virtual void completeItem(); + virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext); + + virtual int indexOf(QmlGraphicsItem *item, QObject *objectContext) const; + + QmlList *children(); + + static QmlGraphicsVisualItemModelAttached *qmlAttachedProperties(QObject *obj); + +signals: + void childrenChanged(); + +private: + Q_DISABLE_COPY(QmlGraphicsVisualItemModel) +}; + + +class Q_DECLARATIVE_EXPORT QmlGraphicsVisualDataModel : public QmlGraphicsVisualModel +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlGraphicsVisualDataModel) + + Q_PROPERTY(QVariant model READ model WRITE setModel) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(QString part READ part WRITE setPart) + Q_PROPERTY(QObject *parts READ parts CONSTANT) + Q_CLASSINFO("DefaultProperty", "delegate") +public: + QmlGraphicsVisualDataModel(); + QmlGraphicsVisualDataModel(QmlContext *); + virtual ~QmlGraphicsVisualDataModel(); + + QVariant model() const; + void setModel(const QVariant &); + + QmlComponent *delegate() const; + void setDelegate(QmlComponent *); + + QString part() const; + void setPart(const QString &); + + int count() const; + bool isValid() const { return delegate() != 0; } + QmlGraphicsItem *item(int index, bool complete=true); + QmlGraphicsItem *item(int index, const QByteArray &, bool complete=true); + ReleaseFlags release(QmlGraphicsItem *item); + void completeItem(); + QVariant evaluate(int index, const QString &expression, QObject *objectContext); + + int indexOf(QmlGraphicsItem *item, QObject *objectContext) const; + + QObject *parts(); + +Q_SIGNALS: + void createdPackage(int index, QmlPackage *package); + void destroyingPackage(QmlPackage *package); + +private Q_SLOTS: + void _q_itemsChanged(int, int, const QList &); + void _q_itemsInserted(int index, int count); + void _q_itemsRemoved(int index, int count); + void _q_itemsMoved(int from, int to, int count); + void _q_rowsInserted(const QModelIndex &,int,int); + void _q_rowsRemoved(const QModelIndex &,int,int); + void _q_dataChanged(const QModelIndex&,const QModelIndex&); + void _q_createdPackage(int index, QmlPackage *package); + void _q_destroyingPackage(QmlPackage *package); + +private: + Q_DISABLE_COPY(QmlGraphicsVisualDataModel) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsVisualModel) +QML_DECLARE_TYPE(QmlGraphicsVisualItemModel) +QML_DECLARE_TYPEINFO(QmlGraphicsVisualItemModel, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QmlGraphicsVisualDataModel) + +QT_END_HEADER + +#endif // QMLGRAPHICSVISUALDATAMODEL_H diff --git a/src/declarative/fx/qmlgraphicswebview.cpp b/src/declarative/fx/qmlgraphicswebview.cpp new file mode 100644 index 0000000..d9044cf --- /dev/null +++ b/src/declarative/fx/qmlgraphicswebview.cpp @@ -0,0 +1,1388 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qml.h" +#include "qmlengine.h" +#include "qmlstate.h" +#include "qlistmodelinterface.h" + +#include "qmlgraphicswebview.h" +#include + +QT_BEGIN_NAMESPACE +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,WebView,QmlGraphicsWebView) +QML_DEFINE_NOCREATE_TYPE(QAction) + +static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system + +class QmlGraphicsWebSettings : public QObject { + Q_OBJECT + + Q_PROPERTY(QString standardFontFamily READ standardFontFamily WRITE setStandardFontFamily) + Q_PROPERTY(QString fixedFontFamily READ fixedFontFamily WRITE setFixedFontFamily) + Q_PROPERTY(QString serifFontFamily READ serifFontFamily WRITE setSerifFontFamily) + Q_PROPERTY(QString sansSerifFontFamily READ sansSerifFontFamily WRITE setSansSerifFontFamily) + Q_PROPERTY(QString cursiveFontFamily READ cursiveFontFamily WRITE setCursiveFontFamily) + Q_PROPERTY(QString fantasyFontFamily READ fantasyFontFamily WRITE setFantasyFontFamily) + + Q_PROPERTY(int minimumFontSize READ minimumFontSize WRITE setMinimumFontSize) + Q_PROPERTY(int minimumLogicalFontSize READ minimumLogicalFontSize WRITE setMinimumLogicalFontSize) + Q_PROPERTY(int defaultFontSize READ defaultFontSize WRITE setDefaultFontSize) + Q_PROPERTY(int defaultFixedFontSize READ defaultFixedFontSize WRITE setDefaultFixedFontSize) + + Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages) + Q_PROPERTY(bool javascriptEnabled READ javascriptEnabled WRITE setJavascriptEnabled) + Q_PROPERTY(bool javaEnabled READ javaEnabled WRITE setJavaEnabled) + Q_PROPERTY(bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled) + Q_PROPERTY(bool privateBrowsingEnabled READ privateBrowsingEnabled WRITE setPrivateBrowsingEnabled) + Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows) + Q_PROPERTY(bool javascriptCanAccessClipboard READ javascriptCanAccessClipboard WRITE setJavascriptCanAccessClipboard) + Q_PROPERTY(bool developerExtrasEnabled READ developerExtrasEnabled WRITE setDeveloperExtrasEnabled) + Q_PROPERTY(bool linksIncludedInFocusChain READ linksIncludedInFocusChain WRITE setLinksIncludedInFocusChain) + Q_PROPERTY(bool zoomTextOnly READ zoomTextOnly WRITE setZoomTextOnly) + Q_PROPERTY(bool printElementBackgrounds READ printElementBackgrounds WRITE setPrintElementBackgrounds) + Q_PROPERTY(bool offlineStorageDatabaseEnabled READ offlineStorageDatabaseEnabled WRITE setOfflineStorageDatabaseEnabled) + Q_PROPERTY(bool offlineWebApplicationCacheEnabled READ offlineWebApplicationCacheEnabled WRITE setOfflineWebApplicationCacheEnabled) + Q_PROPERTY(bool localStorageDatabaseEnabled READ localStorageDatabaseEnabled WRITE setLocalStorageDatabaseEnabled) + Q_PROPERTY(bool localContentCanAccessRemoteUrls READ localContentCanAccessRemoteUrls WRITE setLocalContentCanAccessRemoteUrls) + +public: + QmlGraphicsWebSettings() {} + + QString standardFontFamily() const { return s->fontFamily(QWebSettings::StandardFont); } + void setStandardFontFamily(const QString& f) { s->setFontFamily(QWebSettings::StandardFont,f); } + QString fixedFontFamily() const { return s->fontFamily(QWebSettings::FixedFont); } + void setFixedFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FixedFont,f); } + QString serifFontFamily() const { return s->fontFamily(QWebSettings::SerifFont); } + void setSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SerifFont,f); } + QString sansSerifFontFamily() const { return s->fontFamily(QWebSettings::SansSerifFont); } + void setSansSerifFontFamily(const QString& f) { s->setFontFamily(QWebSettings::SansSerifFont,f); } + QString cursiveFontFamily() const { return s->fontFamily(QWebSettings::CursiveFont); } + void setCursiveFontFamily(const QString& f) { s->setFontFamily(QWebSettings::CursiveFont,f); } + QString fantasyFontFamily() const { return s->fontFamily(QWebSettings::FantasyFont); } + void setFantasyFontFamily(const QString& f) { s->setFontFamily(QWebSettings::FantasyFont,f); } + + int minimumFontSize() const { return s->fontSize(QWebSettings::MinimumFontSize); } + void setMinimumFontSize(int size) { s->setFontSize(QWebSettings::MinimumFontSize,size); } + int minimumLogicalFontSize() const { return s->fontSize(QWebSettings::MinimumLogicalFontSize); } + void setMinimumLogicalFontSize(int size) { s->setFontSize(QWebSettings::MinimumLogicalFontSize,size); } + int defaultFontSize() const { return s->fontSize(QWebSettings::DefaultFontSize); } + void setDefaultFontSize(int size) { s->setFontSize(QWebSettings::DefaultFontSize,size); } + int defaultFixedFontSize() const { return s->fontSize(QWebSettings::DefaultFixedFontSize); } + void setDefaultFixedFontSize(int size) { s->setFontSize(QWebSettings::DefaultFixedFontSize,size); } + + bool autoLoadImages() const { return s->testAttribute(QWebSettings::AutoLoadImages); } + void setAutoLoadImages(bool on) { s->setAttribute(QWebSettings::AutoLoadImages, on); } + bool javascriptEnabled() const { return s->testAttribute(QWebSettings::JavascriptEnabled); } + void setJavascriptEnabled(bool on) { s->setAttribute(QWebSettings::JavascriptEnabled, on); } + bool javaEnabled() const { return s->testAttribute(QWebSettings::JavaEnabled); } + void setJavaEnabled(bool on) { s->setAttribute(QWebSettings::JavaEnabled, on); } + bool pluginsEnabled() const { return s->testAttribute(QWebSettings::PluginsEnabled); } + void setPluginsEnabled(bool on) { s->setAttribute(QWebSettings::PluginsEnabled, on); } + bool privateBrowsingEnabled() const { return s->testAttribute(QWebSettings::PrivateBrowsingEnabled); } + void setPrivateBrowsingEnabled(bool on) { s->setAttribute(QWebSettings::PrivateBrowsingEnabled, on); } + bool javascriptCanOpenWindows() const { return s->testAttribute(QWebSettings::JavascriptCanOpenWindows); } + void setJavascriptCanOpenWindows(bool on) { s->setAttribute(QWebSettings::JavascriptCanOpenWindows, on); } + bool javascriptCanAccessClipboard() const { return s->testAttribute(QWebSettings::JavascriptCanAccessClipboard); } + void setJavascriptCanAccessClipboard(bool on) { s->setAttribute(QWebSettings::JavascriptCanAccessClipboard, on); } + bool developerExtrasEnabled() const { return s->testAttribute(QWebSettings::DeveloperExtrasEnabled); } + void setDeveloperExtrasEnabled(bool on) { s->setAttribute(QWebSettings::DeveloperExtrasEnabled, on); } + bool linksIncludedInFocusChain() const { return s->testAttribute(QWebSettings::LinksIncludedInFocusChain); } + void setLinksIncludedInFocusChain(bool on) { s->setAttribute(QWebSettings::LinksIncludedInFocusChain, on); } + bool zoomTextOnly() const { return s->testAttribute(QWebSettings::ZoomTextOnly); } + void setZoomTextOnly(bool on) { s->setAttribute(QWebSettings::ZoomTextOnly, on); } + bool printElementBackgrounds() const { return s->testAttribute(QWebSettings::PrintElementBackgrounds); } + void setPrintElementBackgrounds(bool on) { s->setAttribute(QWebSettings::PrintElementBackgrounds, on); } + bool offlineStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::OfflineStorageDatabaseEnabled); } + void setOfflineStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, on); } + bool offlineWebApplicationCacheEnabled() const { return s->testAttribute(QWebSettings::OfflineWebApplicationCacheEnabled); } + void setOfflineWebApplicationCacheEnabled(bool on) { s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, on); } + bool localStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::LocalStorageDatabaseEnabled); } + void setLocalStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, on); } + bool localContentCanAccessRemoteUrls() const { return s->testAttribute(QWebSettings::LocalContentCanAccessRemoteUrls); } + void setLocalContentCanAccessRemoteUrls(bool on) { s->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, on); } + + QWebSettings *s; +}; + +QML_DECLARE_TYPE(QmlGraphicsWebSettings) +QML_DEFINE_NOCREATE_TYPE(QmlGraphicsWebSettings) + +class QmlGraphicsWebViewPrivate : public QmlGraphicsPaintedItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsWebView) + +public: + QmlGraphicsWebViewPrivate() + : QmlGraphicsPaintedItemPrivate(), page(0), preferredwidth(0), pagewidth(0), + progress(1.0), status(QmlGraphicsWebView::Null), pending(PendingNone), + newWindowComponent(0), newWindowParent(0), + windowObjects(this), + rendering(true) + { + } + + QUrl url; // page url might be different if it has not loaded yet + QWebPage *page; + + int preferredwidth; + int pagewidth; + qreal progress; + QmlGraphicsWebView::Status status; + QString statusText; + enum { PendingNone, PendingUrl, PendingHtml, PendingContent } pending; + QUrl pending_url; + QString pending_string; + QByteArray pending_data; + mutable QmlGraphicsWebSettings settings; + QmlComponent *newWindowComponent; + QmlGraphicsItem *newWindowParent; + + void updateWindowObjects(); + class WindowObjectList : public QmlConcreteList + { + public: + WindowObjectList(QmlGraphicsWebViewPrivate *p) + : priv(p) {} + virtual void append(QObject *v) { + QmlConcreteList::append(v); + priv->updateWindowObjects(); + } + private: + QmlGraphicsWebViewPrivate *priv; + } windowObjects; + + bool rendering; +}; + +/*! + \qmlclass WebView + \brief The WebView item allows you to add web content to a canvas. + \inherits Item + + A WebView renders web content based on a URL. + + If the width and height of the item is not set, they will + dynamically adjust to a size appropriate for the content. + This width may be large for typical online web pages. + + If the preferredWidth is set, the width will be this amount or larger, + usually laying out the web content to fit the preferredWidth. + + \qml + WebView { + url: "http://www.nokia.com" + width: 490 + height: 400 + scale: 0.5 + smooth: true + } + \endqml + + \image webview.png + + The item includes no scrolling, scaling, + toolbars, etc., those must be implemented around WebView. See the WebBrowser example + for a demonstration of this. +*/ + +/*! + \internal + \class QmlGraphicsWebView + \brief The QmlGraphicsWebView class allows you to add web content to a QmlView. + + A WebView renders web content base on a URL. + + \image webview.png + + The item includes no scrolling, scaling, + toolbars, etc., those must be implemented around WebView. See the WebBrowser example + for a demonstration of this. + + A QmlGraphicsWebView object can be instantiated in Qml using the tag \l WebView. +*/ + +QmlGraphicsWebView::QmlGraphicsWebView(QmlGraphicsItem *parent) + : QmlGraphicsPaintedItem(*(new QmlGraphicsWebViewPrivate), parent) +{ + init(); +} + +QmlGraphicsWebView::QmlGraphicsWebView(QmlGraphicsWebViewPrivate &dd, QmlGraphicsItem *parent) + : QmlGraphicsPaintedItem(dd, parent) +{ + init(); +} + +QmlGraphicsWebView::~QmlGraphicsWebView() +{ + Q_D(QmlGraphicsWebView); + delete d->page; +} + +void QmlGraphicsWebView::init() +{ + Q_D(QmlGraphicsWebView); + + setAcceptHoverEvents(true); + setAcceptedMouseButtons(Qt::LeftButton); + setFlag(QGraphicsItem::ItemHasNoContents, false); + + d->page = 0; +} + +void QmlGraphicsWebView::componentComplete() +{ + QmlGraphicsPaintedItem::componentComplete(); + Q_D(QmlGraphicsWebView); + switch (d->pending) { + case QmlGraphicsWebViewPrivate::PendingUrl: + setUrl(d->pending_url); + break; + case QmlGraphicsWebViewPrivate::PendingHtml: + setHtml(d->pending_string, d->pending_url); + break; + case QmlGraphicsWebViewPrivate::PendingContent: + setContent(d->pending_data, d->pending_string, d->pending_url); + break; + default: + break; + } + d->pending = QmlGraphicsWebViewPrivate::PendingNone; + d->updateWindowObjects(); +} + +QmlGraphicsWebView::Status QmlGraphicsWebView::status() const +{ + Q_D(const QmlGraphicsWebView); + return d->status; +} + + +/*! + \qmlproperty real WebView::progress + This property holds the progress of loading the current URL, from 0 to 1. + + \sa onLoadFinished() onLoadFailed() +*/ +qreal QmlGraphicsWebView::progress() const +{ + Q_D(const QmlGraphicsWebView); + return d->progress; +} + +void QmlGraphicsWebView::doLoadStarted() +{ + Q_D(QmlGraphicsWebView); + + if (!d->url.isEmpty()) { + d->status = Loading; + emit statusChanged(d->status); + } + emit loadStarted(); +} + +void QmlGraphicsWebView::doLoadProgress(int p) +{ + Q_D(QmlGraphicsWebView); + if (d->progress == p/100.0) + return; + d->progress = p/100.0; + emit progressChanged(); +} + +void QmlGraphicsWebView::pageUrlChanged() +{ + Q_D(QmlGraphicsWebView); + + // Reset zooming to full + qreal zf = 1.0; + if (d->preferredwidth) { + if (d->pagewidth) + zf = qreal(d->preferredwidth)/d->pagewidth; + page()->mainFrame()->setZoomFactor(zf); + page()->setViewportSize(QSize(d->preferredwidth,-1)); + } else { + page()->mainFrame()->setZoomFactor(zf); + page()->setViewportSize(QSize(-1,-1)); + } + emit zooming(zf,0,0); + expandToWebPage(); + + if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank"))) + || d->url != page()->mainFrame()->url()) + { + d->url = page()->mainFrame()->url(); + if (d->url == QUrl(QLatin1String("about:blank"))) + d->url = QUrl(); + emit urlChanged(); + } +} + +void QmlGraphicsWebView::doLoadFinished(bool ok) +{ + Q_D(QmlGraphicsWebView); + + if (title().isEmpty()) + pageUrlChanged(); // XXX bug 232556 - pages with no title never get urlChanged() + + if (ok) { + d->status = d->url.isEmpty() ? Null : Ready; + emit loadFinished(); + } else { + d->status = Error; + emit loadFailed(); + } + emit statusChanged(d->status); +} + +/*! + \qmlproperty url WebView::url + This property holds the URL to the page displayed in this item. It can be set, + but also can change spontaneously (eg. because of network redirection). + + If the url is empty, the page is blank. + + The url is always absolute (QML will resolve relative URL strings in the context + of the containing QML document). +*/ +QUrl QmlGraphicsWebView::url() const +{ + Q_D(const QmlGraphicsWebView); + return d->url; +} + +void QmlGraphicsWebView::setUrl(const QUrl &url) +{ + Q_D(QmlGraphicsWebView); + if (url == d->url) + return; + + if (isComponentComplete()) { + d->url = url; + qreal zf = 1.0; + if (d->preferredwidth) { + if (d->pagewidth) + zf = qreal(d->preferredwidth)/d->pagewidth; + page()->setViewportSize(QSize(d->preferredwidth,-1)); + } else { + page()->setViewportSize(QSize(-1,-1)); + } + page()->mainFrame()->setZoomFactor(zf); + QUrl seturl = url; + if (seturl.isEmpty()) + seturl = QUrl(QLatin1String("about:blank")); + + Q_ASSERT(!seturl.isRelative()); + + page()->mainFrame()->load(seturl); + + emit urlChanged(); + } else { + d->pending = d->PendingUrl; + d->pending_url = url; + } +} + +/*! + \qmlproperty int WebView::preferredWidth + This property holds the ideal width for displaying the current URL. +*/ +int QmlGraphicsWebView::preferredWidth() const +{ + Q_D(const QmlGraphicsWebView); + return d->preferredwidth; +} + +void QmlGraphicsWebView::setPreferredWidth(int iw) +{ + Q_D(QmlGraphicsWebView); + if (d->preferredwidth == iw) return; + if (d->pagewidth) { + if (d->preferredwidth) { + setZoomFactor(zoomFactor()*iw/d->preferredwidth); + } else { + setZoomFactor(qreal(iw)/d->pagewidth); + } + } + d->preferredwidth = iw; + expandToWebPage(); + emit preferredWidthChanged(); +} + +/*! + \qmlproperty int WebView::webPageWidth + This property holds the page width suggested to the web engine. +*/ +int QmlGraphicsWebView::webPageWidth() const +{ + Q_D(const QmlGraphicsWebView); + return d->pagewidth; +} + +void QmlGraphicsWebView::setWebPageWidth(int pw) +{ + Q_D(QmlGraphicsWebView); + if (d->pagewidth == pw) return; + d->pagewidth = pw; + expandToWebPage(); +} + +/*! + Evaluates the \a scriptSource JavaScript inside the main frame + context and returns the result of the last executed statement. +*/ +QVariant QmlGraphicsWebView::evaluateJavaScript(const QString &scriptSource) +{ + return this->page()->mainFrame()->evaluateJavaScript(scriptSource); +} + +void QmlGraphicsWebView::focusChanged(bool hasFocus) +{ + QFocusEvent e(hasFocus ? QEvent::FocusIn : QEvent::FocusOut); + page()->event(&e); + QmlGraphicsItem::focusChanged(hasFocus); +} + +void QmlGraphicsWebView::contentsSizeChanged(const QSize&) +{ + expandToWebPage(); +} + +void QmlGraphicsWebView::expandToWebPage() +{ + Q_D(QmlGraphicsWebView); + QSize cs = page()->mainFrame()->contentsSize(); + qreal zoom = zoomFactor(); + if (cs.width() < d->preferredwidth*zoom) + cs.setWidth(d->preferredwidth*zoom); + if (widthValid()) + cs.setWidth(width()); + if (heightValid()) + cs.setHeight(height()); + if (cs != page()->viewportSize()) { + page()->setViewportSize(cs); + clearCache(); + setImplicitWidth(cs.width()); + setImplicitHeight(cs.height()); + } +} + +void QmlGraphicsWebView::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) +{ + if (newGeometry.size() != oldGeometry.size()) + expandToWebPage(); + QmlGraphicsPaintedItem::geometryChanged(newGeometry, oldGeometry); +} + +void QmlGraphicsWebView::paintPage(const QRect& r) +{ + Q_D(QmlGraphicsWebView); + if (d->page->mainFrame()->contentsSize() != contentsSize()) + setContentsSize(d->page->mainFrame()->contentsSize()); + dirtyCache(r); + update(); +} + +/*! + \qmlproperty int WebView::pixelCacheSize + + This property holds the maximum number of pixels of image cache to + allow. The default is 0.1 megapixels. The cache will not be larger + than the (unscaled) size of the WebView. +*/ +int QmlGraphicsWebView::pixelCacheSize() const +{ + Q_D(const QmlGraphicsWebView); + return d->max_imagecache_size; +} + +void QmlGraphicsWebView::setPixelCacheSize(int pixels) +{ + Q_D(QmlGraphicsWebView); + if (pixels < d->max_imagecache_size) { + int cachesize=0; + for (int i=0; iimagecache.count(); ++i) { + QRect area = d->imagecache[i]->area; + cachesize += area.width()*area.height(); + } + while (d->imagecache.count() && cachesize > pixels) { + int oldest=-1; + int age=-1; + for (int i=0; iimagecache.count(); ++i) { + int a = d->imagecache[i]->age; + if (a > age) { + oldest = i; + age = a; + } + } + cachesize -= d->imagecache[oldest]->area.width()*d->imagecache[oldest]->area.height(); + d->imagecache.removeAt(oldest); + } + } + d->max_imagecache_size = pixels; +} + +/*! + \qmlproperty list WebView::javaScriptWindowObjects + + This property is a list of object that are available from within + the webview's JavaScript context. + + The \a object will be inserted as a child of the frame's window + object, under the name given by the attached property \c WebView.windowObjectName. + + \qml + WebView { + javaScriptWindowObjects: Object { + WebView.windowObjectName: "coordinates" + } + } + \endqml + + Properties of the object will be exposed as JavaScript properties and slots as + JavaScript methods. + + If Javascript is not enabled for this page, then this property does nothing. +*/ +QmlList *QmlGraphicsWebView::javaScriptWindowObjects() +{ + Q_D(QmlGraphicsWebView); + return &d->windowObjects; +} + +class QmlGraphicsWebViewAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString windowObjectName READ windowObjectName WRITE setWindowObjectName) +public: + QmlGraphicsWebViewAttached(QObject *parent) + : QObject(parent) + { + } + + QString windowObjectName() const + { + return m_windowObjectName; + } + + void setWindowObjectName(const QString &n) + { + m_windowObjectName = n; + } + +private: + QString m_windowObjectName; +}; + +QmlGraphicsWebViewAttached *QmlGraphicsWebView::qmlAttachedProperties(QObject *o) +{ + return new QmlGraphicsWebViewAttached(o); +} + +void QmlGraphicsWebViewPrivate::updateWindowObjects() +{ + Q_Q(QmlGraphicsWebView); + if (!q->isComponentComplete() || !page) + return; + + for (int ii = 0; ii < windowObjects.count(); ++ii) { + QObject *object = windowObjects.at(ii); + QmlGraphicsWebViewAttached *attached = static_cast(qmlAttachedPropertiesObject(object)); + if (attached && !attached->windowObjectName().isEmpty()) { + page->mainFrame()->addToJavaScriptWindowObject(attached->windowObjectName(), object); + } + } +} + +bool QmlGraphicsWebView::renderingEnabled() const +{ + Q_D(const QmlGraphicsWebView); + return d->rendering; +} + +void QmlGraphicsWebView::setRenderingEnabled(bool enabled) +{ + Q_D(QmlGraphicsWebView); + if (d->rendering == enabled) + return; + d->rendering = enabled; + setCacheFrozen(!enabled); + if (enabled) + clearCache(); +} + + +void QmlGraphicsWebView::drawContents(QPainter *p, const QRect &r) +{ + Q_D(QmlGraphicsWebView); + if (d->rendering) + page()->mainFrame()->render(p,r); +} + +static QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) +{ + QEvent::Type t; + switch(e->type()) { + default: + case QEvent::GraphicsSceneMousePress: + t = QEvent::MouseButtonPress; + break; + case QEvent::GraphicsSceneMouseRelease: + t = QEvent::MouseButtonRelease; + break; + case QEvent::GraphicsSceneMouseMove: + t = QEvent::MouseMove; + break; + case QGraphicsSceneEvent::GraphicsSceneMouseDoubleClick: + t = QEvent::MouseButtonDblClick; + break; + } + + QMouseEvent *me = new QMouseEvent(t, e->pos().toPoint(), e->button(), e->buttons(), 0); + return me; +} + +static QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *e) +{ + QEvent::Type t = QEvent::MouseMove; + + QMouseEvent *me = new QMouseEvent(t, e->pos().toPoint(), Qt::NoButton, Qt::NoButton, 0); + + return me; +} + + +/*! + \qmlsignal WebView::onDoubleClick(clickx,clicky) + + The WebView does not pass double-click events to the web engine, but rather + emits this signals. +*/ + +void QmlGraphicsWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + emit doubleClick(me->x(),me->y()); + delete me; +} + +void QmlGraphicsWebView::heuristicZoom(int clickX, int clickY) +{ + Q_D(QmlGraphicsWebView); + qreal ozf = zoomFactor(); + QRect showarea = elementAreaAt(clickX, clickY, 1, 1); + qreal z = qreal(preferredWidth())*ozf/showarea.width()*.95; + if ((z/ozf > 0.99 && z/ozf <1.01) || z < qreal(d->preferredwidth)/d->pagewidth) { + // zoom out + z = qreal(d->preferredwidth)/d->pagewidth; + } + QRectF r(showarea.left()/ozf*z, showarea.top()/ozf*z, showarea.width()/ozf*z, showarea.height()/ozf*z); + emit zooming(z,r.x()+r.width()/2, r.y()+r.height()/2); +} + +void QmlGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + setFocus (true); + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + page()->event(me); + event->setAccepted( +/* + It is not correct to send the press event upwards, if it is not accepted by WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit + Might be a bug in WebKit, though + */ +#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) { + QmlGraphicsPaintedItem::mousePressEvent(event); + } +} + +void QmlGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + page()->event(me); + event->setAccepted( +/* + It is not correct to send the press event upwards, if it is not accepted by WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send all the events to WebKit + */ +#if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) { + QmlGraphicsPaintedItem::mouseReleaseEvent(event); + } +} + +void QmlGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + QMouseEvent *me = sceneMouseEventToMouseEvent(event); + page()->event(me); + event->setAccepted( +/* + It is not correct to send the press event upwards, if it is not accepted by WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit + Might be a bug in WebKit, though + */ +#if 1 // QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) + QmlGraphicsPaintedItem::mouseMoveEvent(event); + +} +void QmlGraphicsWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) +{ + QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event); + page()->event(me); + event->setAccepted( +#if QT_VERSION <= 0x040500 // XXX see bug 230835 + true +#else + me->isAccepted() +#endif + ); + delete me; + if (!event->isAccepted()) + QmlGraphicsPaintedItem::hoverMoveEvent(event); +} + +void QmlGraphicsWebView::keyPressEvent(QKeyEvent* event) +{ + page()->event(event); + if (!event->isAccepted()) + QmlGraphicsPaintedItem::keyPressEvent(event); +} + +void QmlGraphicsWebView::keyReleaseEvent(QKeyEvent* event) +{ + page()->event(event); + if (!event->isAccepted()) + QmlGraphicsPaintedItem::keyReleaseEvent(event); +} + +bool QmlGraphicsWebView::sceneEvent(QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *k = static_cast(event); + if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) { + if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? + page()->event(event); + if (event->isAccepted()) + return true; + } + } + } + return QmlGraphicsPaintedItem::sceneEvent(event); +} + + + +/*! + \qmlproperty action WebView::back + This property holds the action for causing the previous URL in the history to be displayed. +*/ +QAction *QmlGraphicsWebView::backAction() const +{ + return page()->action(QWebPage::Back); +} + +/*! + \qmlproperty action WebView::forward + This property holds the action for causing the next URL in the history to be displayed. +*/ +QAction *QmlGraphicsWebView::forwardAction() const +{ + return page()->action(QWebPage::Forward); +} + +/*! + \qmlproperty action WebView::reload + This property holds the action for reloading with the current URL +*/ +QAction *QmlGraphicsWebView::reloadAction() const +{ + return page()->action(QWebPage::Reload); +} + +/*! + \qmlproperty action WebView::stop + This property holds the action for stopping loading with the current URL +*/ +QAction *QmlGraphicsWebView::stopAction() const +{ + return page()->action(QWebPage::Stop); +} + +/*! + \qmlproperty real WebView::title + This property holds the title of the web page currently viewed + + By default, this property contains an empty string. +*/ +QString QmlGraphicsWebView::title() const +{ + return page()->mainFrame()->title(); +} + + + +/*! + \qmlproperty pixmap WebView::icon + This property holds the icon associated with the web page currently viewed +*/ +QPixmap QmlGraphicsWebView::icon() const +{ + return page()->mainFrame()->icon().pixmap(QSize(256,256)); +} + + +/*! + \qmlproperty real WebView::textSizeMultiplier + This property holds the multiplier used to scale the text in a Web page +*/ +void QmlGraphicsWebView::setTextSizeMultiplier(qreal factor) +{ + page()->mainFrame()->setTextSizeMultiplier(factor); +} + +qreal QmlGraphicsWebView::textSizeMultiplier() const +{ + return page()->mainFrame()->textSizeMultiplier(); +} + +/*! + \qmlproperty real WebView::zoomFactor + This property holds the multiplier used to scale the contents of a Web page. +*/ +void QmlGraphicsWebView::setZoomFactor(qreal factor) +{ + Q_D(QmlGraphicsWebView); + if (factor == page()->mainFrame()->zoomFactor()) + return; + + page()->mainFrame()->setZoomFactor(factor); + page()->setViewportSize(QSize(d->pagewidth*factor,-1)); + expandToWebPage(); + + emit zoomFactorChanged(); +} + +qreal QmlGraphicsWebView::zoomFactor() const +{ + return page()->mainFrame()->zoomFactor(); +} + +/*! + \qmlproperty string WebView::statusText + + This property is the current status suggested by the current web page. In a web browser, + such status is often shown in some kind of status bar. +*/ +void QmlGraphicsWebView::setStatusText(const QString& s) +{ + Q_D(QmlGraphicsWebView); + d->statusText = s; + emit statusTextChanged(); +} + +void QmlGraphicsWebView::windowObjectCleared() +{ + Q_D(QmlGraphicsWebView); + d->updateWindowObjects(); +} + +QString QmlGraphicsWebView::statusText() const +{ + Q_D(const QmlGraphicsWebView); + return d->statusText; +} + +QWebPage *QmlGraphicsWebView::page() const +{ + Q_D(const QmlGraphicsWebView); + + if (!d->page) { + QmlGraphicsWebView *self = const_cast(this); + QWebPage *wp = new QmlGraphicsWebPage(self); + + // QML items don't default to having a background, + // even though most we pages will set one anyway. + QPalette pal = QApplication::palette(); + pal.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0)); + wp->setPalette(pal); + + wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager()); + + self->setPage(wp); + + return wp; + } + + return d->page; +} + + +// The QObject interface to settings(). +/*! + \qmlproperty string WebView::settings.standardFontFamily + \qmlproperty string WebView::settings.fixedFontFamily + \qmlproperty string WebView::settings.serifFontFamily + \qmlproperty string WebView::settings.sansSerifFontFamily + \qmlproperty string WebView::settings.cursiveFontFamily + \qmlproperty string WebView::settings.fantasyFontFamily + + \qmlproperty int WebView::settings.minimumFontSize + \qmlproperty int WebView::settings.minimumLogicalFontSize + \qmlproperty int WebView::settings.defaultFontSize + \qmlproperty int WebView::settings.defaultFixedFontSize + + \qmlproperty bool WebView::settings.autoLoadImages + \qmlproperty bool WebView::settings.javascriptEnabled + \qmlproperty bool WebView::settings.javaEnabled + \qmlproperty bool WebView::settings.pluginsEnabled + \qmlproperty bool WebView::settings.privateBrowsingEnabled + \qmlproperty bool WebView::settings.javascriptCanOpenWindows + \qmlproperty bool WebView::settings.javascriptCanAccessClipboard + \qmlproperty bool WebView::settings.developerExtrasEnabled + \qmlproperty bool WebView::settings.linksIncludedInFocusChain + \qmlproperty bool WebView::settings.zoomTextOnly + \qmlproperty bool WebView::settings.printElementBackgrounds + \qmlproperty bool WebView::settings.offlineStorageDatabaseEnabled + \qmlproperty bool WebView::settings.offlineWebApplicationCacheEnabled + \qmlproperty bool WebView::settings.localStorageDatabaseEnabled + \qmlproperty bool WebView::settings.localContentCanAccessRemoteUrls + + These properties give access to the settings controlling the web view. + + See QWebSettings for details of these properties. + + \qml + WebView { + settings.pluginsEnabled: true + settings.standardFontFamily: "Arial" + ... + } + \endqml +*/ +QmlGraphicsWebSettings *QmlGraphicsWebView::settingsObject() const +{ + Q_D(const QmlGraphicsWebView); + d->settings.s = page()->settings(); + return &d->settings; +} + +void QmlGraphicsWebView::setPage(QWebPage *page) +{ + Q_D(QmlGraphicsWebView); + if (d->page == page) + return; + if (d->page) { + if (d->page->parent() == this) { + delete d->page; + } else { + d->page->disconnect(this); + } + } + d->page = page; + d->page->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : -1, -1)); + d->page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); + d->page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); + connect(d->page,SIGNAL(repaintRequested(QRect)),this,SLOT(paintPage(QRect))); + connect(d->page->mainFrame(),SIGNAL(urlChanged(QUrl)),this,SLOT(pageUrlChanged())); + connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); + connect(d->page->mainFrame(), SIGNAL(iconChanged()), this, SIGNAL(iconChanged())); + connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SLOT(contentsSizeChanged(QSize))); + + connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted())); + connect(d->page,SIGNAL(loadProgress(int)),this,SLOT(doLoadProgress(int))); + connect(d->page,SIGNAL(loadFinished(bool)),this,SLOT(doLoadFinished(bool))); + connect(d->page,SIGNAL(statusBarMessage(QString)),this,SLOT(setStatusText(QString))); + + connect(d->page->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT(windowObjectCleared())); +} + +/*! + \qmlsignal WebView::onLoadStarted() + + This handler is called when the web engine begins loading + a page. + + \sa progress onLoadFinished() onLoadFailed() +*/ + +/*! + \qmlsignal WebView::onLoadFinished() + + This handler is called when the web engine finishes loading + a page, including any component content. + + \sa progress onLoadFailed() +*/ + +/*! + \qmlsignal WebView::onLoadFailed() + + This handler is called when the web engine fails loading + a page or any component content. + + \sa progress onLoadFinished() +*/ + +void QmlGraphicsWebView::load(const QNetworkRequest &request, + QNetworkAccessManager::Operation operation, + const QByteArray &body) +{ + page()->mainFrame()->load(request, operation, body); +} + +QString QmlGraphicsWebView::html() const +{ + return page()->mainFrame()->toHtml(); +} + +/*! + \qmlproperty string WebView::html + This property holds HTML text set directly + + The html property can be set as a string. + + \qml + WebView { + html: "

This is HTML." + } + \endqml +*/ +void QmlGraphicsWebView::setHtml(const QString &html, const QUrl &baseUrl) +{ + Q_D(QmlGraphicsWebView); + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), height())); + if (isComponentComplete()) + page()->mainFrame()->setHtml(html, baseUrl); + else { + d->pending = d->PendingHtml; + d->pending_url = baseUrl; + d->pending_string = html; + } +} + +void QmlGraphicsWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) +{ + Q_D(QmlGraphicsWebView); + page()->setViewportSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), height())); + + if (isComponentComplete()) + page()->mainFrame()->setContent(data,mimeType,qmlContext(this)->resolvedUrl(baseUrl)); + else { + d->pending = d->PendingContent; + d->pending_url = baseUrl; + d->pending_string = mimeType; + d->pending_data = data; + } +} + +QWebHistory *QmlGraphicsWebView::history() const +{ + return page()->history(); +} + +QWebSettings *QmlGraphicsWebView::settings() const +{ + return page()->settings(); +} + +QmlGraphicsWebView *QmlGraphicsWebView::createWindow(QWebPage::WebWindowType type) +{ + Q_D(QmlGraphicsWebView); + switch (type) { + case QWebPage::WebBrowserWindow: { + if (!d->newWindowComponent && d->newWindowParent) + qWarning("WebView::newWindowComponent not set - WebView::newWindowParent ignored"); + else if (d->newWindowComponent && !d->newWindowParent) + qWarning("WebView::newWindowParent not set - WebView::newWindowComponent ignored"); + else if (d->newWindowComponent && d->newWindowParent) { + QmlGraphicsWebView *webview = 0; + QmlContext *windowContext = new QmlContext(qmlContext(this)); + + QObject *nobj = d->newWindowComponent->create(windowContext); + if (nobj) { + windowContext->setParent(nobj); + QmlGraphicsItem *item = qobject_cast(nobj); + if (!item) { + delete nobj; + } else { + webview = item->findChild(); + if (!webview) { + delete item; + } else { + item->setParent(d->newWindowParent); + } + } + } else { + delete windowContext; + } + + return webview; + } + } + break; + case QWebPage::WebModalDialog: { + // Not supported + } + } + return 0; +} + +/*! + \qmlproperty component WebView::newWindowComponent + + This property holds the component to use for new windows. + The component must have a WebView somewhere in its structure. + + When the web engine requests a new window, it will be an instance of + this component. + + The parent of the new window is set by newWindowParent. It must be set. +*/ +QmlComponent *QmlGraphicsWebView::newWindowComponent() const +{ + Q_D(const QmlGraphicsWebView); + return d->newWindowComponent; +} + +void QmlGraphicsWebView::setNewWindowComponent(QmlComponent *newWindow) +{ + Q_D(QmlGraphicsWebView); + delete d->newWindowComponent; + d->newWindowComponent = newWindow; +} + + +/*! + \qmlproperty item WebView::newWindowParent + + The parent item for new windows. + + \sa newWindowComponent +*/ +QmlGraphicsItem *QmlGraphicsWebView::newWindowParent() const +{ + Q_D(const QmlGraphicsWebView); + return d->newWindowParent; +} + +void QmlGraphicsWebView::setNewWindowParent(QmlGraphicsItem *parent) +{ + Q_D(QmlGraphicsWebView); + delete d->newWindowParent; + d->newWindowParent = parent; +} + +/*! + Returns the area of the largest element at position (\a x,\a y) that is no larger + than \a maxwidth by \a maxheight pixels. + + May return an area larger in the case when no smaller element is at the position. +*/ +QRect QmlGraphicsWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const +{ + QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x,y)); + QWebElement element = hit.enclosingBlockElement(); + QWebElement parent = element.parent(); + if (maxwidth<=0) maxwidth = INT_MAX; + if (maxheight<=0) maxheight = INT_MAX; + while (!parent.isNull() && parent.geometry().width() <= maxwidth && parent.geometry().height() <= maxheight) { + element = parent; + parent = element.parent(); + } + return element.geometry(); +} + +/*! + \internal + \class QmlGraphicsWebPage + \brief The QmlGraphicsWebPage class is a QWebPage that can create QML plugins. + + \sa QmlGraphicsWebView +*/ +QmlGraphicsWebPage::QmlGraphicsWebPage(QmlGraphicsWebView *parent) : + QWebPage(parent) +{ +} + +QmlGraphicsWebPage::~QmlGraphicsWebPage() +{ +} + +/* + Qt WebKit does not understand non-QWidget plugins, so dummy widgets + are created, parented to a single dummy tool window. + + The requirements for QML object plugins are input to the Qt WebKit + non-QWidget plugin support, which will obsolete this kludge. +*/ +class QWidget_Dummy_Plugin : public QWidget +{ + Q_OBJECT +public: + static QWidget *dummy_shared_parent() + { + static QWidget *dsp = 0; + if (!dsp) { + dsp = new QWidget(0,Qt::Tool); + dsp->setGeometry(-10000,-10000,0,0); + dsp->show(); + } + return dsp; + } + QWidget_Dummy_Plugin(const QUrl& url, QmlGraphicsWebView *view, const QStringList ¶mNames, const QStringList ¶mValues) : + QWidget(dummy_shared_parent()), + propertyNames(paramNames), + propertyValues(paramValues), + webview(view) + { + QmlEngine *engine = qmlEngine(webview); + component = new QmlComponent(engine, url, this); + item = 0; + if (component->isLoading()) + connect(component, SIGNAL(statusChanged(QmlComponent::Status)), this, SLOT(qmlLoaded())); + else + qmlLoaded(); + } + +public Q_SLOTS: + void qmlLoaded() + { + if (component->isError()) { + // ### Could instead give these errors to the WebView to handle. + qWarning() << component->errors(); + return; + } + item = qobject_cast(component->create(qmlContext(webview))); + item->setParent(webview); + QString jsObjName; + for (int i=0; isetProperty(propertyNames[i].toUtf8(),propertyValues[i]); + if (propertyNames[i] == QLatin1String("objectname")) + jsObjName = propertyValues[i]; + } + } + if (!jsObjName.isNull()) { + QWebFrame *f = webview->page()->mainFrame(); + f->addToJavaScriptWindowObject(jsObjName, item); + } + resizeEvent(0); + delete component; + component = 0; + } + void resizeEvent(QResizeEvent*) + { + if (item) { + item->setX(x()); + item->setY(y()); + item->setWidth(width()); + item->setHeight(height()); + } + } + +private: + QmlComponent *component; + QmlGraphicsItem *item; + QStringList propertyNames, propertyValues; + QmlGraphicsWebView *webview; +}; + +QmlGraphicsWebView *QmlGraphicsWebPage::viewItem() +{ + return static_cast(parent()); +} + +QObject *QmlGraphicsWebPage::createPlugin(const QString &, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) +{ + QUrl comp = qmlContext(viewItem())->resolvedUrl(url); + return new QWidget_Dummy_Plugin(comp,viewItem(),paramNames,paramValues); +} + +QWebPage *QmlGraphicsWebPage::createWindow(WebWindowType type) +{ + QmlGraphicsWebView *newView = viewItem()->createWindow(type); + if (newView) + return newView->page(); + return 0; +} + +QT_END_NAMESPACE + +#include "qfxwebview.moc" diff --git a/src/declarative/fx/qmlgraphicswebview.h b/src/declarative/fx/qmlgraphicswebview.h new file mode 100644 index 0000000..81f7bcd --- /dev/null +++ b/src/declarative/fx/qmlgraphicswebview.h @@ -0,0 +1,251 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSWEBVIEW_H +#define QMLGRAPHICSWEBVIEW_H + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_HEADER + +class QWebHistory; +class QWebSettings; + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlGraphicsWebViewPrivate; +class QNetworkRequest; +class QmlGraphicsWebView; + +class Q_DECLARATIVE_EXPORT QmlGraphicsWebPage : public QWebPage +{ + Q_OBJECT +public: + explicit QmlGraphicsWebPage(QmlGraphicsWebView *parent); + ~QmlGraphicsWebPage(); +protected: + QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); + QWebPage *createWindow(WebWindowType type); + +private: + QmlGraphicsWebView *viewItem(); +}; + + +class QmlGraphicsWebViewAttached; +class QmlGraphicsWebSettings; + +//### TODO: browser plugins + +class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem +{ + Q_OBJECT + + Q_ENUMS(Status) + + Q_PROPERTY(QString title READ title NOTIFY titleChanged) + Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged) + Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false) + Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) + Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) + + Q_PROPERTY(QString html READ html WRITE setHtml) + + Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) + Q_PROPERTY(int webPageWidth READ webPageWidth WRITE setWebPageWidth) + Q_PROPERTY(int pixelCacheSize READ pixelCacheSize WRITE setPixelCacheSize) + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + + Q_PROPERTY(QAction* reload READ reloadAction CONSTANT) + Q_PROPERTY(QAction* back READ backAction CONSTANT) + Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) + Q_PROPERTY(QAction* stop READ stopAction CONSTANT) + + Q_PROPERTY(QmlGraphicsWebSettings* settings READ settingsObject CONSTANT) + + Q_PROPERTY(QmlList* javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) + + Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent) + Q_PROPERTY(QmlGraphicsItem* newWindowParent READ newWindowParent WRITE setNewWindowParent) + + Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled) + +public: + QmlGraphicsWebView(QmlGraphicsItem *parent=0); + ~QmlGraphicsWebView(); + + QUrl url() const; + void setUrl(const QUrl &); + + QString title() const; + + QPixmap icon() const; + + qreal textSizeMultiplier() const; + void setTextSizeMultiplier(qreal); + + qreal zoomFactor() const; + void setZoomFactor(qreal); + + int preferredWidth() const; + void setPreferredWidth(int); + int webPageWidth() const; + void setWebPageWidth(int); + + enum Status { Null, Ready, Loading, Error }; + Status status() const; + qreal progress() const; + QString statusText() const; + + QAction *reloadAction() const; + QAction *backAction() const; + QAction *forwardAction() const; + QAction *stopAction() const; + + QWebPage *page() const; + void setPage(QWebPage *page); + + void load(const QNetworkRequest &request, + QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, + const QByteArray &body = QByteArray()); + + QString html() const; + + void setHtml(const QString &html, const QUrl &baseUrl = QUrl()); + void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()); + + QWebHistory *history() const; + QWebSettings *settings() const; + QmlGraphicsWebSettings *settingsObject() const; + + int pixelCacheSize() const; + void setPixelCacheSize(int pixels); + + bool renderingEnabled() const; + void setRenderingEnabled(bool); + + QmlList *javaScriptWindowObjects(); + + static QmlGraphicsWebViewAttached *qmlAttachedProperties(QObject *); + + QmlComponent *newWindowComponent() const; + void setNewWindowComponent(QmlComponent *newWindow); + QmlGraphicsItem *newWindowParent() const; + void setNewWindowParent(QmlGraphicsItem *newWindow); + +Q_SIGNALS: + void preferredWidthChanged(); + void preferredHeightChanged(); + void urlChanged(); + void progressChanged(); + void statusChanged(Status); + void titleChanged(const QString&); + void iconChanged(); + void statusTextChanged(); + void zoomFactorChanged(); + + void loadStarted(); + void loadFinished(); + void loadFailed(); + + void doubleClick(int clickX, int clickY); + + void zooming(qreal zoom, int centerX, int centerY); + +public Q_SLOTS: + QVariant evaluateJavaScript(const QString&); + void heuristicZoom(int clickX, int clickY); + +private Q_SLOTS: + void expandToWebPage(); + void paintPage(const QRect&); + void doLoadStarted(); + void doLoadProgress(int p); + void doLoadFinished(bool ok); + void setStatusText(const QString&); + void windowObjectCleared(); + void pageUrlChanged(); + void contentsSizeChanged(const QSize&); + +protected: + QmlGraphicsWebView(QmlGraphicsWebViewPrivate &dd, QmlGraphicsItem *parent); + + void drawContents(QPainter *, const QRect &); + + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void hoverMoveEvent (QGraphicsSceneHoverEvent * event); + void keyPressEvent(QKeyEvent* event); + void keyReleaseEvent(QKeyEvent* event); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + virtual void focusChanged(bool); + virtual bool sceneEvent(QEvent *event); + QmlGraphicsWebView *createWindow(QWebPage::WebWindowType type); + QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; + +private: + void init(); + virtual void componentComplete(); + Q_DISABLE_COPY(QmlGraphicsWebView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsWebView) + friend class QmlGraphicsWebPage; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsWebView) +QML_DECLARE_TYPEINFO(QmlGraphicsWebView, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QAction) + +QT_END_HEADER + +#endif diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 1bd9199..5c328cf 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -46,8 +46,8 @@ #include "qmlstateoperations.h" #include #include -#include -#include +#include +#include #include #include diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h index 903998d..f2bcd49 100644 --- a/src/declarative/util/qmlstateoperations.h +++ b/src/declarative/util/qmlstateoperations.h @@ -43,8 +43,8 @@ #define QMLSTATEOPERATIONS_H #include -#include -#include +#include +#include #include QT_BEGIN_HEADER diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index ac67cb8..91d443a 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -52,7 +52,7 @@ #include "qbasictimer.h" #include "qml.h" -#include "qfxitem.h" +#include "qmlgraphicsitem.h" #include "private/qperformancelog_p.h" #include "private/qfxperf_p.h" diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index fea6ef3..ec6a951 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include class tst_anchors : public QObject diff --git a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp index 46c953d..099daec 100644 --- a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp +++ b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp @@ -2,9 +2,9 @@ #include #include #include -#include -#include -#include "qfxanimatedimageitem.h" +#include +#include +#include "qmlgraphicsanimatedimageitem.h" class tst_animatedimage : public QObject { diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index b5cc9d4..eaf4d14 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include class tst_animations : public QObject diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 079e2e7..b225a7d 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include class tst_behaviors : public QObject diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index 70755ff..0b9e402 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include class tst_QmlGraphicsLayouts : public QObject diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index be65338..4e0f6cb 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/tests/auto/declarative/pathview/tst_pathview.cpp b/tests/auto/declarative/pathview/tst_pathview.cpp index d5b922a..013edf5 100644 --- a/tests/auto/declarative/pathview/tst_pathview.cpp +++ b/tests/auto/declarative/pathview/tst_pathview.cpp @@ -1,9 +1,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/tests/auto/declarative/qfxloader/qfxloader.pro b/tests/auto/declarative/qfxloader/qfxloader.pro index aee52cc..8be8cdf 100644 --- a/tests/auto/declarative/qfxloader/qfxloader.pro +++ b/tests/auto/declarative/qfxloader/qfxloader.pro @@ -2,6 +2,6 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle -SOURCES += tst_qfxloader.cpp +SOURCES += tst_qmlgraphicsloader.cpp DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp index 99fecc3..c54c151 100644 --- a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp +++ b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include class tst_qfxloader : public QObject diff --git a/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro b/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro index 218eeff..1df2f4e 100644 --- a/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro +++ b/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro @@ -3,7 +3,7 @@ contains(QT_CONFIG,declarative): QT += declarative QT += network macx:CONFIG -= app_bundle -SOURCES += tst_qfxpixmapcache.cpp +SOURCES += tst_qmlgraphicspixmapcache.cpp # QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage # LIBS += -lgcov diff --git a/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp b/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp index e735066..14f3f19 100644 --- a/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp +++ b/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/tests/auto/declarative/qfxtext/qfxtext.pro b/tests/auto/declarative/qfxtext/qfxtext.pro index 1f3fe37..1d8c59f 100644 --- a/tests/auto/declarative/qfxtext/qfxtext.pro +++ b/tests/auto/declarative/qfxtext/qfxtext.pro @@ -2,4 +2,4 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle -SOURCES += tst_qfxtext.cpp +SOURCES += tst_qmlgraphicstext.cpp diff --git a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp index 12cac68..4011851 100644 --- a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp +++ b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include class tst_qfxtext : public QObject diff --git a/tests/auto/declarative/qfxtextedit/qfxtextedit.pro b/tests/auto/declarative/qfxtextedit/qfxtextedit.pro index b5e0464..9e6a71a 100644 --- a/tests/auto/declarative/qfxtextedit/qfxtextedit.pro +++ b/tests/auto/declarative/qfxtextedit/qfxtextedit.pro @@ -2,7 +2,7 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle -SOURCES += tst_qfxtextedit.cpp +SOURCES += tst_qmlgraphicstextedit.cpp # Define SRCDIR equal to test's source directory DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp index 0565fd4..cab8666 100644 --- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp +++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/auto/declarative/qfxtextinput/qfxtextinput.pro b/tests/auto/declarative/qfxtextinput/qfxtextinput.pro index fe2e3e3..fd75fec 100644 --- a/tests/auto/declarative/qfxtextinput/qfxtextinput.pro +++ b/tests/auto/declarative/qfxtextinput/qfxtextinput.pro @@ -2,7 +2,7 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle -SOURCES += tst_qfxtextinput.cpp +SOURCES += tst_qmlgraphicstextinput.cpp # Define SRCDIR equal to test's source directory DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxwebview/qfxwebview.pro b/tests/auto/declarative/qfxwebview/qfxwebview.pro index b75e057..cce3df2 100644 --- a/tests/auto/declarative/qfxwebview/qfxwebview.pro +++ b/tests/auto/declarative/qfxwebview/qfxwebview.pro @@ -2,7 +2,7 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative macx:CONFIG -= app_bundle -SOURCES += tst_qfxwebview.cpp +SOURCES += tst_qmlgraphicswebview.cpp # Define SRCDIR equal to test's source directory DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp index 6e3336c..eeaef89 100644 --- a/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp +++ b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp @@ -2,7 +2,7 @@ #include "../../../shared/util.h" #include #include -#include +#include #include #include #include diff --git a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp index d11771c..f3e62ab 100644 --- a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp +++ b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include class tst_QmlPropertyMap : public QObject diff --git a/tests/auto/declarative/repeater/tst_repeater.cpp b/tests/auto/declarative/repeater/tst_repeater.cpp index 0622028..8354005 100644 --- a/tests/auto/declarative/repeater/tst_repeater.cpp +++ b/tests/auto/declarative/repeater/tst_repeater.cpp @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include #include class tst_QmlGraphicsRepeater : public QObject diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp index e938ee4..ce73c0c 100644 --- a/tests/auto/declarative/sql/tst_sql.cpp +++ b/tests/auto/declarative/sql/tst_sql.cpp @@ -2,7 +2,7 @@ #include "../../../shared/util.h" #include #include -#include +#include #include #include #include diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index 91b6d0b..218baf8 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include class tst_states : public QObject { diff --git a/tools/qmldebugger/standalone/engine.cpp b/tools/qmldebugger/standalone/engine.cpp index f1eada8..92c54eb 100644 --- a/tools/qmldebugger/standalone/engine.cpp +++ b/tools/qmldebugger/standalone/engine.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include "engine.h" diff --git a/tools/qmlviewer/qfxtester.cpp b/tools/qmlviewer/qfxtester.cpp index a105701..b09c736 100644 --- a/tools/qmlviewer/qfxtester.cpp +++ b/tools/qmlviewer/qfxtester.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE -- cgit v0.12 From cda9193904d5f19b0d53487e0fe3b2d9cd422621 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 30 Oct 2009 15:31:30 +1000 Subject: fix macros --- src/declarative/widgets/graphicswidgets.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/widgets/graphicswidgets.h b/src/declarative/widgets/graphicswidgets.h index 2b39db3..2871e5b 100644 --- a/src/declarative/widgets/graphicswidgets.h +++ b/src/declarative/widgets/graphicswidgets.h @@ -54,13 +54,13 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) +QT_END_NAMESPACE + QML_DECLARE_TYPE(QGraphicsView) QML_DECLARE_TYPE_HASMETATYPE(QGraphicsScene) QML_DECLARE_TYPE(QGraphicsWidget) QML_DECLARE_INTERFACE_HASMETATYPE(QGraphicsItem) -QT_END_NAMESPACE - QT_END_HEADER #endif // GRAPHICSWIDGETS_H -- cgit v0.12 From fed23e1171d12c4b069652acacc2d718c9691c12 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 30 Oct 2009 15:35:59 +1000 Subject: fix headers --- examples/declarative/extending/adding/person.h | 40 ++++++++++++++++++++++ .../declarative/extending/attached/birthdayparty.h | 40 ++++++++++++++++++++++ examples/declarative/extending/attached/person.h | 40 ++++++++++++++++++++++ .../declarative/extending/binding/birthdayparty.h | 40 ++++++++++++++++++++++ .../declarative/extending/binding/happybirthday.h | 40 ++++++++++++++++++++++ examples/declarative/extending/binding/person.h | 40 ++++++++++++++++++++++ .../declarative/extending/coercion/birthdayparty.h | 40 ++++++++++++++++++++++ examples/declarative/extending/coercion/person.h | 40 ++++++++++++++++++++++ .../declarative/extending/default/birthdayparty.h | 40 ++++++++++++++++++++++ examples/declarative/extending/default/person.h | 40 ++++++++++++++++++++++ examples/declarative/extending/extended/lineedit.h | 40 ++++++++++++++++++++++ .../declarative/extending/grouped/birthdayparty.h | 40 ++++++++++++++++++++++ examples/declarative/extending/grouped/person.h | 40 ++++++++++++++++++++++ .../extending/properties/birthdayparty.h | 40 ++++++++++++++++++++++ examples/declarative/extending/properties/person.h | 40 ++++++++++++++++++++++ .../declarative/extending/signal/birthdayparty.h | 40 ++++++++++++++++++++++ examples/declarative/extending/signal/person.h | 40 ++++++++++++++++++++++ .../extending/valuesource/birthdayparty.h | 40 ++++++++++++++++++++++ .../extending/valuesource/happybirthday.h | 40 ++++++++++++++++++++++ .../declarative/extending/valuesource/person.h | 40 ++++++++++++++++++++++ examples/declarative/loader/qmlfolderlistmodel.h | 34 +++++++++--------- src/declarative/debugger/qmldebug.cpp | 32 ++++++++--------- src/declarative/debugger/qmldebugclient.cpp | 32 ++++++++--------- src/declarative/debugger/qmldebuggerstatus.cpp | 32 ++++++++--------- src/declarative/debugger/qmldebugservice.cpp | 32 ++++++++--------- src/declarative/debugger/qpacketprotocol.cpp | 32 ++++++++--------- tests/benchmarks/declarative/binding/testtypes.cpp | 40 ++++++++++++++++++++++ tests/benchmarks/declarative/binding/testtypes.h | 40 ++++++++++++++++++++++ .../declarative/qmlcomponent/testtypes.cpp | 40 ++++++++++++++++++++++ .../declarative/qmlcomponent/testtypes.h | 40 ++++++++++++++++++++++ 30 files changed, 1057 insertions(+), 97 deletions(-) diff --git a/examples/declarative/extending/adding/person.h b/examples/declarative/extending/adding/person.h index 3bef2d4..1a01586 100644 --- a/examples/declarative/extending/adding/person.h +++ b/examples/declarative/extending/adding/person.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef PERSON_H #define PERSON_H diff --git a/examples/declarative/extending/attached/birthdayparty.h b/examples/declarative/extending/attached/birthdayparty.h index 2ea065c..ffebe5f 100644 --- a/examples/declarative/extending/attached/birthdayparty.h +++ b/examples/declarative/extending/attached/birthdayparty.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H diff --git a/examples/declarative/extending/attached/person.h b/examples/declarative/extending/attached/person.h index 07dfe0e..c5b7727 100644 --- a/examples/declarative/extending/attached/person.h +++ b/examples/declarative/extending/attached/person.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef PERSON_H #define PERSON_H diff --git a/examples/declarative/extending/binding/birthdayparty.h b/examples/declarative/extending/binding/birthdayparty.h index 2757561..7fde54e 100644 --- a/examples/declarative/extending/binding/birthdayparty.h +++ b/examples/declarative/extending/binding/birthdayparty.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H diff --git a/examples/declarative/extending/binding/happybirthday.h b/examples/declarative/extending/binding/happybirthday.h index fff2df0..5a492c7 100644 --- a/examples/declarative/extending/binding/happybirthday.h +++ b/examples/declarative/extending/binding/happybirthday.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef HAPPYBIRTHDAY_H #define HAPPYBIRTHDAY_H diff --git a/examples/declarative/extending/binding/person.h b/examples/declarative/extending/binding/person.h index 41513b9..ad77d69 100644 --- a/examples/declarative/extending/binding/person.h +++ b/examples/declarative/extending/binding/person.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef PERSON_H #define PERSON_H diff --git a/examples/declarative/extending/coercion/birthdayparty.h b/examples/declarative/extending/coercion/birthdayparty.h index 2557d1a..810cee3 100644 --- a/examples/declarative/extending/coercion/birthdayparty.h +++ b/examples/declarative/extending/coercion/birthdayparty.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H diff --git a/examples/declarative/extending/coercion/person.h b/examples/declarative/extending/coercion/person.h index de14019..7cfd3d6 100644 --- a/examples/declarative/extending/coercion/person.h +++ b/examples/declarative/extending/coercion/person.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef PERSON_H #define PERSON_H diff --git a/examples/declarative/extending/default/birthdayparty.h b/examples/declarative/extending/default/birthdayparty.h index 084da10..cafe4c7 100644 --- a/examples/declarative/extending/default/birthdayparty.h +++ b/examples/declarative/extending/default/birthdayparty.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H diff --git a/examples/declarative/extending/default/person.h b/examples/declarative/extending/default/person.h index 872186c..6fd9232 100644 --- a/examples/declarative/extending/default/person.h +++ b/examples/declarative/extending/default/person.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef PERSON_H #define PERSON_H diff --git a/examples/declarative/extending/extended/lineedit.h b/examples/declarative/extending/extended/lineedit.h index 79fe977..3f03ba1 100644 --- a/examples/declarative/extending/extended/lineedit.h +++ b/examples/declarative/extending/extended/lineedit.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef LINEEDIT_H #define LINEEDIT_H diff --git a/examples/declarative/extending/grouped/birthdayparty.h b/examples/declarative/extending/grouped/birthdayparty.h index 3d53319..ba8a68d 100644 --- a/examples/declarative/extending/grouped/birthdayparty.h +++ b/examples/declarative/extending/grouped/birthdayparty.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H diff --git a/examples/declarative/extending/grouped/person.h b/examples/declarative/extending/grouped/person.h index b83eb5b..5cd3e8f 100644 --- a/examples/declarative/extending/grouped/person.h +++ b/examples/declarative/extending/grouped/person.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef PERSON_H #define PERSON_H diff --git a/examples/declarative/extending/properties/birthdayparty.h b/examples/declarative/extending/properties/birthdayparty.h index 1804980..7bc3c3f 100644 --- a/examples/declarative/extending/properties/birthdayparty.h +++ b/examples/declarative/extending/properties/birthdayparty.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H diff --git a/examples/declarative/extending/properties/person.h b/examples/declarative/extending/properties/person.h index 2bc98c1..1c69f5a 100644 --- a/examples/declarative/extending/properties/person.h +++ b/examples/declarative/extending/properties/person.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef PERSON_H #define PERSON_H diff --git a/examples/declarative/extending/signal/birthdayparty.h b/examples/declarative/extending/signal/birthdayparty.h index 5dea2e8..56a809e 100644 --- a/examples/declarative/extending/signal/birthdayparty.h +++ b/examples/declarative/extending/signal/birthdayparty.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H diff --git a/examples/declarative/extending/signal/person.h b/examples/declarative/extending/signal/person.h index 07dfe0e..c5b7727 100644 --- a/examples/declarative/extending/signal/person.h +++ b/examples/declarative/extending/signal/person.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef PERSON_H #define PERSON_H diff --git a/examples/declarative/extending/valuesource/birthdayparty.h b/examples/declarative/extending/valuesource/birthdayparty.h index 75a2477..11e1fdf 100644 --- a/examples/declarative/extending/valuesource/birthdayparty.h +++ b/examples/declarative/extending/valuesource/birthdayparty.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H diff --git a/examples/declarative/extending/valuesource/happybirthday.h b/examples/declarative/extending/valuesource/happybirthday.h index 18ac1f4..4e8e87c 100644 --- a/examples/declarative/extending/valuesource/happybirthday.h +++ b/examples/declarative/extending/valuesource/happybirthday.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef HAPPYBIRTHDAY_H #define HAPPYBIRTHDAY_H diff --git a/examples/declarative/extending/valuesource/person.h b/examples/declarative/extending/valuesource/person.h index 07dfe0e..c5b7727 100644 --- a/examples/declarative/extending/valuesource/person.h +++ b/examples/declarative/extending/valuesource/person.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef PERSON_H #define PERSON_H diff --git a/examples/declarative/loader/qmlfolderlistmodel.h b/examples/declarative/loader/qmlfolderlistmodel.h index 49b508d..f4fa9ed 100644 --- a/examples/declarative/loader/qmlfolderlistmodel.h +++ b/examples/declarative/loader/qmlfolderlistmodel.h @@ -1,16 +1,17 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the QtDeclarative module of the Qt Toolkit. +** This file is part of the examples 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. +** contained in the Technology Preview License Agreement accompanying +** this package. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -20,21 +21,20 @@ ** 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. +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** ** -** 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$ ** ****************************************************************************/ diff --git a/src/declarative/debugger/qmldebug.cpp b/src/declarative/debugger/qmldebug.cpp index c19abe3..85a0cf8 100644 --- a/src/declarative/debugger/qmldebug.cpp +++ b/src/declarative/debugger/qmldebug.cpp @@ -1,7 +1,8 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtDeclarative module of the Qt Toolkit. ** @@ -9,8 +10,8 @@ ** 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. +** contained in the Technology Preview License Agreement accompanying +** this package. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -20,21 +21,20 @@ ** 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. +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** ** -** 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$ ** ****************************************************************************/ diff --git a/src/declarative/debugger/qmldebugclient.cpp b/src/declarative/debugger/qmldebugclient.cpp index 3171808..3e805d6 100644 --- a/src/declarative/debugger/qmldebugclient.cpp +++ b/src/declarative/debugger/qmldebugclient.cpp @@ -1,7 +1,8 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtDeclarative module of the Qt Toolkit. ** @@ -9,8 +10,8 @@ ** 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. +** contained in the Technology Preview License Agreement accompanying +** this package. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -20,21 +21,20 @@ ** 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. +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** ** -** 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$ ** ****************************************************************************/ diff --git a/src/declarative/debugger/qmldebuggerstatus.cpp b/src/declarative/debugger/qmldebuggerstatus.cpp index d46a21d..f8ee210 100644 --- a/src/declarative/debugger/qmldebuggerstatus.cpp +++ b/src/declarative/debugger/qmldebuggerstatus.cpp @@ -1,7 +1,8 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtDeclarative module of the Qt Toolkit. ** @@ -9,8 +10,8 @@ ** 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. +** contained in the Technology Preview License Agreement accompanying +** this package. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -20,21 +21,20 @@ ** 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. +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** ** -** 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$ ** ****************************************************************************/ diff --git a/src/declarative/debugger/qmldebugservice.cpp b/src/declarative/debugger/qmldebugservice.cpp index 6913def..ca9811c 100644 --- a/src/declarative/debugger/qmldebugservice.cpp +++ b/src/declarative/debugger/qmldebugservice.cpp @@ -1,7 +1,8 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtDeclarative module of the Qt Toolkit. ** @@ -9,8 +10,8 @@ ** 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. +** contained in the Technology Preview License Agreement accompanying +** this package. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -20,21 +21,20 @@ ** 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. +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** ** -** 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$ ** ****************************************************************************/ diff --git a/src/declarative/debugger/qpacketprotocol.cpp b/src/declarative/debugger/qpacketprotocol.cpp index 84882dd..5a85104 100644 --- a/src/declarative/debugger/qpacketprotocol.cpp +++ b/src/declarative/debugger/qpacketprotocol.cpp @@ -1,7 +1,8 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtDeclarative module of the Qt Toolkit. ** @@ -9,8 +10,8 @@ ** 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. +** contained in the Technology Preview License Agreement accompanying +** this package. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -20,21 +21,20 @@ ** 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. +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** ** -** 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$ ** ****************************************************************************/ diff --git a/tests/benchmarks/declarative/binding/testtypes.cpp b/tests/benchmarks/declarative/binding/testtypes.cpp index 60e69e2..9dad523 100644 --- a/tests/benchmarks/declarative/binding/testtypes.cpp +++ b/tests/benchmarks/declarative/binding/testtypes.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #include "testtypes.h" QML_DEFINE_TYPE(MyQmlObject, MyQmlObject); diff --git a/tests/benchmarks/declarative/binding/testtypes.h b/tests/benchmarks/declarative/binding/testtypes.h index 20bf5f7..c0586b1 100644 --- a/tests/benchmarks/declarative/binding/testtypes.h +++ b/tests/benchmarks/declarative/binding/testtypes.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef TESTTYPES_H #define TESTTYPES_H diff --git a/tests/benchmarks/declarative/qmlcomponent/testtypes.cpp b/tests/benchmarks/declarative/qmlcomponent/testtypes.cpp index 5021bf3..8350211 100644 --- a/tests/benchmarks/declarative/qmlcomponent/testtypes.cpp +++ b/tests/benchmarks/declarative/qmlcomponent/testtypes.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #include "testtypes.h" QML_DEFINE_TYPE(Qt/test, 4, 6, 6, MyQmlObject, MyQmlObject); diff --git a/tests/benchmarks/declarative/qmlcomponent/testtypes.h b/tests/benchmarks/declarative/qmlcomponent/testtypes.h index 20bf5f7..c0586b1 100644 --- a/tests/benchmarks/declarative/qmlcomponent/testtypes.h +++ b/tests/benchmarks/declarative/qmlcomponent/testtypes.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef TESTTYPES_H #define TESTTYPES_H -- cgit v0.12 From 564894627debad93433f16506ccf32afeb23d004 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 30 Oct 2009 16:12:18 +1000 Subject: Make private headers _p --- src/declarative/3rdparty/3rdparty.pri | 2 +- src/declarative/3rdparty/qlistmodelinterface.cpp | 2 +- src/declarative/3rdparty/qlistmodelinterface.h | 86 ---- src/declarative/3rdparty/qlistmodelinterface_p.h | 86 ++++ src/declarative/debugger/debugger.pri | 10 +- src/declarative/debugger/qmldebug.cpp | 4 +- src/declarative/debugger/qmldebug.h | 314 ------------ src/declarative/debugger/qmldebug_p.h | 314 ++++++++++++ src/declarative/debugger/qmldebugclient.cpp | 4 +- src/declarative/debugger/qmldebugclient.h | 99 ---- src/declarative/debugger/qmldebugclient_p.h | 99 ++++ src/declarative/debugger/qmldebuggerstatus.cpp | 2 +- src/declarative/debugger/qmldebuggerstatus.h | 66 --- src/declarative/debugger/qmldebuggerstatus_p.h | 66 +++ src/declarative/debugger/qmldebugservice.cpp | 4 +- src/declarative/debugger/qmldebugservice.h | 88 ---- src/declarative/debugger/qmldebugservice_p.h | 88 ++++ src/declarative/debugger/qpacketprotocol.cpp | 2 +- src/declarative/debugger/qpacketprotocol.h | 122 ----- src/declarative/debugger/qpacketprotocol_p.h | 122 +++++ src/declarative/extra/extra.pri | 18 +- src/declarative/extra/qmlbehavior.cpp | 6 +- src/declarative/extra/qmlbehavior.h | 84 ---- src/declarative/extra/qmlbehavior_p.h | 84 ++++ src/declarative/extra/qmldatetimeformatter.cpp | 2 +- src/declarative/extra/qmldatetimeformatter.h | 116 ----- src/declarative/extra/qmldatetimeformatter_p.h | 116 +++++ src/declarative/extra/qmlfontloader.cpp | 2 +- src/declarative/extra/qmlfontloader.h | 94 ---- src/declarative/extra/qmlfontloader_p.h | 94 ++++ .../extra/qmlgraphicsanimatedimageitem.cpp | 2 +- .../extra/qmlgraphicsanimatedimageitem.h | 106 ---- .../extra/qmlgraphicsanimatedimageitem_p.h | 77 ++- .../extra/qmlgraphicsanimatedimageitem_p_p.h | 81 ++++ src/declarative/extra/qmlgraphicsintegermodel.cpp | 2 +- src/declarative/extra/qmlgraphicsintegermodel.h | 86 ---- src/declarative/extra/qmlgraphicsintegermodel_p.h | 86 ++++ src/declarative/extra/qmlgraphicsparticles.cpp | 8 +- src/declarative/extra/qmlgraphicsparticles.h | 230 --------- src/declarative/extra/qmlgraphicsparticles_p.h | 230 +++++++++ src/declarative/extra/qmlnumberformatter.cpp | 2 +- src/declarative/extra/qmlnumberformatter.h | 92 ---- src/declarative/extra/qmlnumberformatter_p.h | 92 ++++ src/declarative/extra/qmlxmllistmodel.cpp | 2 +- src/declarative/extra/qmlxmllistmodel.h | 134 ----- src/declarative/extra/qmlxmllistmodel_p.h | 134 +++++ src/declarative/extra/qnumberformat.cpp | 2 +- src/declarative/extra/qnumberformat.h | 173 ------- src/declarative/extra/qnumberformat_p.h | 173 +++++++ src/declarative/fx/fx.pri | 60 +-- src/declarative/fx/qmlgraphicsanchors.cpp | 6 +- src/declarative/fx/qmlgraphicsanchors.h | 180 ------- src/declarative/fx/qmlgraphicsanchors_p.h | 234 +++++---- src/declarative/fx/qmlgraphicsanchors_p_p.h | 160 ++++++ src/declarative/fx/qmlgraphicsborderimage.cpp | 2 +- src/declarative/fx/qmlgraphicsborderimage.h | 105 ---- src/declarative/fx/qmlgraphicsborderimage_p.h | 96 ++-- src/declarative/fx/qmlgraphicsborderimage_p_p.h | 97 ++++ src/declarative/fx/qmlgraphicsevents.cpp | 2 +- src/declarative/fx/qmlgraphicsevents_p.h | 137 ------ src/declarative/fx/qmlgraphicsevents_p_p.h | 137 ++++++ src/declarative/fx/qmlgraphicsflickable.cpp | 4 +- src/declarative/fx/qmlgraphicsflickable.h | 203 -------- src/declarative/fx/qmlgraphicsflickable_p.h | 245 ++++++---- src/declarative/fx/qmlgraphicsflickable_p_p.h | 156 ++++++ src/declarative/fx/qmlgraphicsflipable.cpp | 4 +- src/declarative/fx/qmlgraphicsflipable.h | 94 ---- src/declarative/fx/qmlgraphicsflipable_p.h | 94 ++++ src/declarative/fx/qmlgraphicsfocuspanel.cpp | 2 +- src/declarative/fx/qmlgraphicsfocuspanel.h | 77 --- src/declarative/fx/qmlgraphicsfocuspanel_p.h | 77 +++ src/declarative/fx/qmlgraphicsfocusscope.cpp | 2 +- src/declarative/fx/qmlgraphicsfocusscope.h | 68 --- src/declarative/fx/qmlgraphicsfocusscope_p.h | 68 +++ .../fx/qmlgraphicsgraphicsobjectcontainer.cpp | 6 +- .../fx/qmlgraphicsgraphicsobjectcontainer.h | 90 ---- .../fx/qmlgraphicsgraphicsobjectcontainer_p.h | 90 ++++ src/declarative/fx/qmlgraphicsgridview.cpp | 12 +- src/declarative/fx/qmlgraphicsgridview.h | 157 ------ src/declarative/fx/qmlgraphicsgridview_p.h | 157 ++++++ src/declarative/fx/qmlgraphicsimage.cpp | 2 +- src/declarative/fx/qmlgraphicsimage.h | 90 ---- src/declarative/fx/qmlgraphicsimage_p.h | 57 ++- src/declarative/fx/qmlgraphicsimage_p_p.h | 77 +++ src/declarative/fx/qmlgraphicsimagebase.cpp | 4 +- src/declarative/fx/qmlgraphicsimagebase.h | 90 ---- src/declarative/fx/qmlgraphicsimagebase_p.h | 67 +-- src/declarative/fx/qmlgraphicsimagebase_p_p.h | 83 ++++ src/declarative/fx/qmlgraphicsitem.cpp | 17 +- src/declarative/fx/qmlgraphicsitem_p.h | 6 +- src/declarative/fx/qmlgraphicslayoutitem.cpp | 2 +- src/declarative/fx/qmlgraphicslayoutitem.h | 93 ---- src/declarative/fx/qmlgraphicslayoutitem_p.h | 93 ++++ src/declarative/fx/qmlgraphicslistview.cpp | 13 +- src/declarative/fx/qmlgraphicslistview.h | 186 ------- src/declarative/fx/qmlgraphicslistview_p.h | 186 +++++++ src/declarative/fx/qmlgraphicsloader.cpp | 6 +- src/declarative/fx/qmlgraphicsloader.h | 107 ---- src/declarative/fx/qmlgraphicsloader_p.h | 83 ++-- src/declarative/fx/qmlgraphicsloader_p_p.h | 82 ++++ src/declarative/fx/qmlgraphicsmouseregion.cpp | 4 +- src/declarative/fx/qmlgraphicsmouseregion.h | 180 ------- src/declarative/fx/qmlgraphicsmouseregion_p.h | 192 +++++--- src/declarative/fx/qmlgraphicsmouseregion_p_p.h | 114 +++++ src/declarative/fx/qmlgraphicspainteditem.cpp | 2 +- src/declarative/fx/qmlgraphicspainteditem.h | 105 ---- src/declarative/fx/qmlgraphicspainteditem_p.h | 91 ++-- src/declarative/fx/qmlgraphicspainteditem_p_p.h | 88 ++++ src/declarative/fx/qmlgraphicspath.cpp | 4 +- src/declarative/fx/qmlgraphicspath.h | 259 ---------- src/declarative/fx/qmlgraphicspath_p.h | 234 +++++++-- src/declarative/fx/qmlgraphicspath_p_p.h | 79 +++ src/declarative/fx/qmlgraphicspathview.cpp | 12 +- src/declarative/fx/qmlgraphicspathview.h | 138 ------ src/declarative/fx/qmlgraphicspathview_p.h | 183 ++++--- src/declarative/fx/qmlgraphicspathview_p_p.h | 151 ++++++ src/declarative/fx/qmlgraphicspixmapcache.cpp | 4 +- src/declarative/fx/qmlgraphicspixmapcache.h | 72 --- src/declarative/fx/qmlgraphicspixmapcache_p.h | 72 +++ src/declarative/fx/qmlgraphicspositioners.cpp | 12 +- src/declarative/fx/qmlgraphicspositioners.h | 167 ------- src/declarative/fx/qmlgraphicspositioners_p.h | 168 +++++-- src/declarative/fx/qmlgraphicspositioners_p_p.h | 105 ++++ src/declarative/fx/qmlgraphicsrect.cpp | 2 +- src/declarative/fx/qmlgraphicsrect.h | 189 -------- src/declarative/fx/qmlgraphicsrect_p.h | 196 +++++--- src/declarative/fx/qmlgraphicsrect_p_p.h | 109 +++++ src/declarative/fx/qmlgraphicsrepeater.cpp | 8 +- src/declarative/fx/qmlgraphicsrepeater.h | 103 ---- src/declarative/fx/qmlgraphicsrepeater_p.h | 76 +-- src/declarative/fx/qmlgraphicsrepeater_p_p.h | 81 ++++ src/declarative/fx/qmlgraphicsscalegrid.cpp | 2 +- src/declarative/fx/qmlgraphicsscalegrid_p.h | 133 ----- src/declarative/fx/qmlgraphicsscalegrid_p_p.h | 133 +++++ src/declarative/fx/qmlgraphicstext.cpp | 4 +- src/declarative/fx/qmlgraphicstext.h | 151 ------ src/declarative/fx/qmlgraphicstext_p.h | 164 ++++--- src/declarative/fx/qmlgraphicstext_p_p.h | 113 +++++ src/declarative/fx/qmlgraphicstextedit.cpp | 6 +- src/declarative/fx/qmlgraphicstextedit.h | 234 --------- src/declarative/fx/qmlgraphicstextedit_p.h | 241 ++++++--- src/declarative/fx/qmlgraphicstextedit_p_p.h | 113 +++++ src/declarative/fx/qmlgraphicstextinput.cpp | 2 +- src/declarative/fx/qmlgraphicstextinput.h | 209 -------- src/declarative/fx/qmlgraphicstextinput_p.h | 212 +++++--- src/declarative/fx/qmlgraphicstextinput_p_p.h | 109 +++++ src/declarative/fx/qmlgraphicsvisualitemmodel.cpp | 13 +- src/declarative/fx/qmlgraphicsvisualitemmodel.h | 203 -------- src/declarative/fx/qmlgraphicsvisualitemmodel_p.h | 203 ++++++++ src/declarative/fx/qmlgraphicswebview.cpp | 10 +- src/declarative/fx/qmlgraphicswebview.h | 251 ---------- src/declarative/fx/qmlgraphicswebview_p.h | 251 ++++++++++ src/declarative/qml/qmlbasicscript.cpp | 2 +- src/declarative/qml/qmlbinding.cpp | 2 +- src/declarative/qml/qmlcompiler.cpp | 2 +- src/declarative/qml/qmlcomponent.cpp | 2 +- src/declarative/qml/qmlengine.cpp | 2 +- src/declarative/qml/qmlenginedebug_p.h | 2 +- src/declarative/qml/qmlmetaproperty.cpp | 2 +- src/declarative/qml/qmlparser.cpp | 2 +- src/declarative/qml/qmlscriptparser.cpp | 2 +- src/declarative/qml/qmlvme.cpp | 2 +- src/declarative/qml/qmlwatcher.cpp | 2 +- src/declarative/util/qfxperf.cpp | 2 +- src/declarative/util/qfxperf_p.h | 90 ---- src/declarative/util/qfxperf_p_p.h | 90 ++++ src/declarative/util/qmlanimation.cpp | 8 +- src/declarative/util/qmlanimation.h | 407 ---------------- src/declarative/util/qmlanimation_p.h | 539 +++++++++++---------- src/declarative/util/qmlanimation_p_p.h | 362 ++++++++++++++ src/declarative/util/qmlbind.cpp | 4 +- src/declarative/util/qmlbind.h | 92 ---- src/declarative/util/qmlbind_p.h | 92 ++++ src/declarative/util/qmlconnection.cpp | 2 +- src/declarative/util/qmlconnection.h | 92 ---- src/declarative/util/qmlconnection_p.h | 92 ++++ src/declarative/util/qmleasefollow.cpp | 4 +- src/declarative/util/qmleasefollow.h | 113 ----- src/declarative/util/qmleasefollow_p.h | 113 +++++ src/declarative/util/qmllistaccessor.cpp | 2 +- src/declarative/util/qmllistaccessor.h | 85 ---- src/declarative/util/qmllistaccessor_p.h | 85 ++++ src/declarative/util/qmllistmodel.cpp | 4 +- src/declarative/util/qmllistmodel.h | 103 ---- src/declarative/util/qmllistmodel_p.h | 103 ++++ src/declarative/util/qmlnullablevalue_p.h | 81 ---- src/declarative/util/qmlnullablevalue_p_p.h | 81 ++++ src/declarative/util/qmlopenmetaobject.cpp | 2 +- src/declarative/util/qmlopenmetaobject.h | 91 ---- src/declarative/util/qmlopenmetaobject_p.h | 91 ++++ src/declarative/util/qmlpackage.cpp | 2 +- src/declarative/util/qmlpackage.h | 88 ---- src/declarative/util/qmlpackage_p.h | 88 ++++ src/declarative/util/qmlpropertychanges.cpp | 4 +- src/declarative/util/qmlpropertychanges.h | 84 ---- src/declarative/util/qmlpropertychanges_p.h | 84 ++++ src/declarative/util/qmlpropertymap.cpp | 4 +- src/declarative/util/qmlpropertymap.h | 91 ---- src/declarative/util/qmlpropertymap_p.h | 91 ++++ src/declarative/util/qmlspringfollow.cpp | 4 +- src/declarative/util/qmlspringfollow.h | 113 ----- src/declarative/util/qmlspringfollow_p.h | 113 +++++ src/declarative/util/qmlstate.cpp | 12 +- src/declarative/util/qmlstate.h | 174 ------- src/declarative/util/qmlstate_p.h | 167 ++++--- src/declarative/util/qmlstate_p_p.h | 121 +++++ src/declarative/util/qmlstategroup.cpp | 4 +- src/declarative/util/qmlstategroup.h | 94 ---- src/declarative/util/qmlstategroup_p.h | 94 ++++ src/declarative/util/qmlstateoperations.cpp | 10 +- src/declarative/util/qmlstateoperations.h | 177 ------- src/declarative/util/qmlstateoperations_p.h | 177 +++++++ src/declarative/util/qmlsystempalette.cpp | 2 +- src/declarative/util/qmlsystempalette.h | 122 ----- src/declarative/util/qmlsystempalette_p.h | 122 +++++ src/declarative/util/qmltimeline.cpp | 2 +- src/declarative/util/qmltimeline_p.h | 224 --------- src/declarative/util/qmltimeline_p_p.h | 224 +++++++++ src/declarative/util/qmltimer.cpp | 2 +- src/declarative/util/qmltimer.h | 108 ----- src/declarative/util/qmltimer_p.h | 108 +++++ src/declarative/util/qmltransition.cpp | 10 +- src/declarative/util/qmltransition.h | 99 ---- src/declarative/util/qmltransition_p.h | 99 ++++ src/declarative/util/qmltransitionmanager.cpp | 4 +- src/declarative/util/qmltransitionmanager_p.h | 85 ---- src/declarative/util/qmltransitionmanager_p_p.h | 85 ++++ src/declarative/util/qmlview.cpp | 8 +- src/declarative/util/qperformancelog.cpp | 2 +- src/declarative/util/qperformancelog_p.h | 141 ------ src/declarative/util/qperformancelog_p_p.h | 141 ++++++ src/declarative/util/util.pri | 44 +- src/declarative/widgets/graphicslayouts.cpp | 2 +- src/declarative/widgets/graphicslayouts.h | 193 -------- src/declarative/widgets/graphicslayouts_p.h | 193 ++++++++ src/declarative/widgets/graphicswidgets.cpp | 2 +- src/declarative/widgets/graphicswidgets.h | 62 --- src/declarative/widgets/graphicswidgets_p.h | 62 +++ src/declarative/widgets/widgets.pri | 4 +- tests/auto/declarative/anchors/tst_anchors.cpp | 4 +- .../animatedimage/tst_animatedimage.cpp | 6 +- .../auto/declarative/animations/tst_animations.cpp | 2 +- tests/auto/declarative/behaviors/tst_behaviors.cpp | 2 +- .../datetimeformatter/tst_datetimeformatter.cpp | 2 +- tests/auto/declarative/layouts/tst_layouts.cpp | 4 +- tests/auto/declarative/listview/tst_listview.cpp | 6 +- .../numberformatter/tst_numberformatter.cpp | 4 +- tests/auto/declarative/pathview/tst_pathview.cpp | 8 +- tests/auto/declarative/qfxloader/tst_qfxloader.cpp | 2 +- .../qfxpixmapcache/tst_qfxpixmapcache.cpp | 2 +- tests/auto/declarative/qfxtext/tst_qfxtext.cpp | 2 +- .../declarative/qfxtextedit/tst_qfxtextedit.cpp | 2 +- .../auto/declarative/qfxwebview/tst_qfxwebview.cpp | 2 +- .../qmllistaccessor/tst_qmllistaccessor.cpp | 2 +- .../qmlpropertymap/tst_qmlpropertymap.cpp | 4 +- tests/auto/declarative/qmltimer/tst_qmltimer.cpp | 2 +- tests/auto/declarative/repeater/tst_repeater.cpp | 6 +- tests/auto/declarative/sql/tst_sql.cpp | 2 +- tests/auto/declarative/states/tst_states.cpp | 2 +- .../qmldebugger/creatorplugin/qmlinspectormode.cpp | 4 +- .../creatorplugin/qmlinspectorplugin.cpp | 4 +- tools/qmldebugger/standalone/canvasframerate.cpp | 2 +- tools/qmldebugger/standalone/canvasframerate.h | 2 +- tools/qmldebugger/standalone/engine.cpp | 4 +- tools/qmldebugger/standalone/engine.h | 2 +- .../qmldebugger/standalone/expressionquerywidget.h | 2 +- .../standalone/objectpropertiesview.cpp | 6 +- .../qmldebugger/standalone/objectpropertiesview.h | 2 +- tools/qmldebugger/standalone/objecttree.cpp | 6 +- tools/qmldebugger/standalone/qmldebugger.h | 2 +- tools/qmldebugger/standalone/watchtable.cpp | 2 +- tools/qmlviewer/qmlviewer.cpp | 2 +- 272 files changed, 10468 insertions(+), 10467 deletions(-) delete mode 100644 src/declarative/3rdparty/qlistmodelinterface.h create mode 100644 src/declarative/3rdparty/qlistmodelinterface_p.h delete mode 100644 src/declarative/debugger/qmldebug.h create mode 100644 src/declarative/debugger/qmldebug_p.h delete mode 100644 src/declarative/debugger/qmldebugclient.h create mode 100644 src/declarative/debugger/qmldebugclient_p.h delete mode 100644 src/declarative/debugger/qmldebuggerstatus.h create mode 100644 src/declarative/debugger/qmldebuggerstatus_p.h delete mode 100644 src/declarative/debugger/qmldebugservice.h create mode 100644 src/declarative/debugger/qmldebugservice_p.h delete mode 100644 src/declarative/debugger/qpacketprotocol.h create mode 100644 src/declarative/debugger/qpacketprotocol_p.h delete mode 100644 src/declarative/extra/qmlbehavior.h create mode 100644 src/declarative/extra/qmlbehavior_p.h delete mode 100644 src/declarative/extra/qmldatetimeformatter.h create mode 100644 src/declarative/extra/qmldatetimeformatter_p.h delete mode 100644 src/declarative/extra/qmlfontloader.h create mode 100644 src/declarative/extra/qmlfontloader_p.h delete mode 100644 src/declarative/extra/qmlgraphicsanimatedimageitem.h create mode 100644 src/declarative/extra/qmlgraphicsanimatedimageitem_p_p.h delete mode 100644 src/declarative/extra/qmlgraphicsintegermodel.h create mode 100644 src/declarative/extra/qmlgraphicsintegermodel_p.h delete mode 100644 src/declarative/extra/qmlgraphicsparticles.h create mode 100644 src/declarative/extra/qmlgraphicsparticles_p.h delete mode 100644 src/declarative/extra/qmlnumberformatter.h create mode 100644 src/declarative/extra/qmlnumberformatter_p.h delete mode 100644 src/declarative/extra/qmlxmllistmodel.h create mode 100644 src/declarative/extra/qmlxmllistmodel_p.h delete mode 100644 src/declarative/extra/qnumberformat.h create mode 100644 src/declarative/extra/qnumberformat_p.h delete mode 100644 src/declarative/fx/qmlgraphicsanchors.h create mode 100644 src/declarative/fx/qmlgraphicsanchors_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicsborderimage.h create mode 100644 src/declarative/fx/qmlgraphicsborderimage_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicsevents_p.h create mode 100644 src/declarative/fx/qmlgraphicsevents_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicsflickable.h create mode 100644 src/declarative/fx/qmlgraphicsflickable_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicsflipable.h create mode 100644 src/declarative/fx/qmlgraphicsflipable_p.h delete mode 100644 src/declarative/fx/qmlgraphicsfocuspanel.h create mode 100644 src/declarative/fx/qmlgraphicsfocuspanel_p.h delete mode 100644 src/declarative/fx/qmlgraphicsfocusscope.h create mode 100644 src/declarative/fx/qmlgraphicsfocusscope_p.h delete mode 100644 src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.h create mode 100644 src/declarative/fx/qmlgraphicsgraphicsobjectcontainer_p.h delete mode 100644 src/declarative/fx/qmlgraphicsgridview.h create mode 100644 src/declarative/fx/qmlgraphicsgridview_p.h delete mode 100644 src/declarative/fx/qmlgraphicsimage.h create mode 100644 src/declarative/fx/qmlgraphicsimage_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicsimagebase.h create mode 100644 src/declarative/fx/qmlgraphicsimagebase_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicslayoutitem.h create mode 100644 src/declarative/fx/qmlgraphicslayoutitem_p.h delete mode 100644 src/declarative/fx/qmlgraphicslistview.h create mode 100644 src/declarative/fx/qmlgraphicslistview_p.h delete mode 100644 src/declarative/fx/qmlgraphicsloader.h create mode 100644 src/declarative/fx/qmlgraphicsloader_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicsmouseregion.h create mode 100644 src/declarative/fx/qmlgraphicsmouseregion_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicspainteditem.h create mode 100644 src/declarative/fx/qmlgraphicspainteditem_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicspath.h create mode 100644 src/declarative/fx/qmlgraphicspath_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicspathview.h create mode 100644 src/declarative/fx/qmlgraphicspathview_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicspixmapcache.h create mode 100644 src/declarative/fx/qmlgraphicspixmapcache_p.h delete mode 100644 src/declarative/fx/qmlgraphicspositioners.h create mode 100644 src/declarative/fx/qmlgraphicspositioners_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicsrect.h create mode 100644 src/declarative/fx/qmlgraphicsrect_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicsrepeater.h create mode 100644 src/declarative/fx/qmlgraphicsrepeater_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicsscalegrid_p.h create mode 100644 src/declarative/fx/qmlgraphicsscalegrid_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicstext.h create mode 100644 src/declarative/fx/qmlgraphicstext_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicstextedit.h create mode 100644 src/declarative/fx/qmlgraphicstextedit_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicstextinput.h create mode 100644 src/declarative/fx/qmlgraphicstextinput_p_p.h delete mode 100644 src/declarative/fx/qmlgraphicsvisualitemmodel.h create mode 100644 src/declarative/fx/qmlgraphicsvisualitemmodel_p.h delete mode 100644 src/declarative/fx/qmlgraphicswebview.h create mode 100644 src/declarative/fx/qmlgraphicswebview_p.h delete mode 100644 src/declarative/util/qfxperf_p.h create mode 100644 src/declarative/util/qfxperf_p_p.h delete mode 100644 src/declarative/util/qmlanimation.h create mode 100644 src/declarative/util/qmlanimation_p_p.h delete mode 100644 src/declarative/util/qmlbind.h create mode 100644 src/declarative/util/qmlbind_p.h delete mode 100644 src/declarative/util/qmlconnection.h create mode 100644 src/declarative/util/qmlconnection_p.h delete mode 100644 src/declarative/util/qmleasefollow.h create mode 100644 src/declarative/util/qmleasefollow_p.h delete mode 100644 src/declarative/util/qmllistaccessor.h create mode 100644 src/declarative/util/qmllistaccessor_p.h delete mode 100644 src/declarative/util/qmllistmodel.h create mode 100644 src/declarative/util/qmllistmodel_p.h delete mode 100644 src/declarative/util/qmlnullablevalue_p.h create mode 100644 src/declarative/util/qmlnullablevalue_p_p.h delete mode 100644 src/declarative/util/qmlopenmetaobject.h create mode 100644 src/declarative/util/qmlopenmetaobject_p.h delete mode 100644 src/declarative/util/qmlpackage.h create mode 100644 src/declarative/util/qmlpackage_p.h delete mode 100644 src/declarative/util/qmlpropertychanges.h create mode 100644 src/declarative/util/qmlpropertychanges_p.h delete mode 100644 src/declarative/util/qmlpropertymap.h create mode 100644 src/declarative/util/qmlpropertymap_p.h delete mode 100644 src/declarative/util/qmlspringfollow.h create mode 100644 src/declarative/util/qmlspringfollow_p.h delete mode 100644 src/declarative/util/qmlstate.h create mode 100644 src/declarative/util/qmlstate_p_p.h delete mode 100644 src/declarative/util/qmlstategroup.h create mode 100644 src/declarative/util/qmlstategroup_p.h delete mode 100644 src/declarative/util/qmlstateoperations.h create mode 100644 src/declarative/util/qmlstateoperations_p.h delete mode 100644 src/declarative/util/qmlsystempalette.h create mode 100644 src/declarative/util/qmlsystempalette_p.h delete mode 100644 src/declarative/util/qmltimeline_p.h create mode 100644 src/declarative/util/qmltimeline_p_p.h delete mode 100644 src/declarative/util/qmltimer.h create mode 100644 src/declarative/util/qmltimer_p.h delete mode 100644 src/declarative/util/qmltransition.h create mode 100644 src/declarative/util/qmltransition_p.h delete mode 100644 src/declarative/util/qmltransitionmanager_p.h create mode 100644 src/declarative/util/qmltransitionmanager_p_p.h delete mode 100644 src/declarative/util/qperformancelog_p.h create mode 100644 src/declarative/util/qperformancelog_p_p.h delete mode 100644 src/declarative/widgets/graphicslayouts.h create mode 100644 src/declarative/widgets/graphicslayouts_p.h delete mode 100644 src/declarative/widgets/graphicswidgets.h create mode 100644 src/declarative/widgets/graphicswidgets_p.h diff --git a/src/declarative/3rdparty/3rdparty.pri b/src/declarative/3rdparty/3rdparty.pri index fc78cb2..09cf0bb 100644 --- a/src/declarative/3rdparty/3rdparty.pri +++ b/src/declarative/3rdparty/3rdparty.pri @@ -1,5 +1,5 @@ HEADERS += \ - 3rdparty/qlistmodelinterface.h\ + 3rdparty/qlistmodelinterface_p.h\ SOURCES += \ 3rdparty/qlistmodelinterface.cpp \ diff --git a/src/declarative/3rdparty/qlistmodelinterface.cpp b/src/declarative/3rdparty/qlistmodelinterface.cpp index b47ed8b..cfd4cff 100644 --- a/src/declarative/3rdparty/qlistmodelinterface.cpp +++ b/src/declarative/3rdparty/qlistmodelinterface.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qlistmodelinterface.h" +#include "qlistmodelinterface_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/3rdparty/qlistmodelinterface.h b/src/declarative/3rdparty/qlistmodelinterface.h deleted file mode 100644 index 44c4a24..0000000 --- a/src/declarative/3rdparty/qlistmodelinterface.h +++ /dev/null @@ -1,86 +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 QLISTMODELINTERFACE_H -#define QLISTMODELINTERFACE_H - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QListModelInterface : public QObject -{ - Q_OBJECT - public: - QListModelInterface(QObject *parent = 0) : QObject(parent) {} - virtual ~QListModelInterface() {} - - virtual int count() const = 0; - virtual QHash data(int index, const QList& roles = QList()) const = 0; - virtual bool setData(int index, const QHash& values) - { Q_UNUSED(index); Q_UNUSED(values); return false; } - - virtual QList roles() const = 0; - virtual QString toString(int role) const = 0; - - Q_SIGNALS: - void itemsInserted(int index, int count); - void itemsRemoved(int index, int count); - void itemsMoved(int from, int to, int count); - void itemsChanged(int index, int count, const QList &roles); - - protected: - QListModelInterface(QObjectPrivate &dd, QObject *parent) - : QObject(dd, parent) {} -}; - - -QT_END_NAMESPACE - -QT_END_HEADER -#endif //QTREEMODELINTERFACE_H diff --git a/src/declarative/3rdparty/qlistmodelinterface_p.h b/src/declarative/3rdparty/qlistmodelinterface_p.h new file mode 100644 index 0000000..44c4a24 --- /dev/null +++ b/src/declarative/3rdparty/qlistmodelinterface_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 QLISTMODELINTERFACE_H +#define QLISTMODELINTERFACE_H + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class Q_DECLARATIVE_EXPORT QListModelInterface : public QObject +{ + Q_OBJECT + public: + QListModelInterface(QObject *parent = 0) : QObject(parent) {} + virtual ~QListModelInterface() {} + + virtual int count() const = 0; + virtual QHash data(int index, const QList& roles = QList()) const = 0; + virtual bool setData(int index, const QHash& values) + { Q_UNUSED(index); Q_UNUSED(values); return false; } + + virtual QList roles() const = 0; + virtual QString toString(int role) const = 0; + + Q_SIGNALS: + void itemsInserted(int index, int count); + void itemsRemoved(int index, int count); + void itemsMoved(int from, int to, int count); + void itemsChanged(int index, int count, const QList &roles); + + protected: + QListModelInterface(QObjectPrivate &dd, QObject *parent) + : QObject(dd, parent) {} +}; + + +QT_END_NAMESPACE + +QT_END_HEADER +#endif //QTREEMODELINTERFACE_H diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri index 82746fc..6cffb28 100644 --- a/src/declarative/debugger/debugger.pri +++ b/src/declarative/debugger/debugger.pri @@ -4,8 +4,8 @@ SOURCES += debugger/qmldebuggerstatus.cpp \ debugger/qmldebugclient.cpp \ debugger/qmldebug.cpp -HEADERS += debugger/qmldebuggerstatus.h \ - debugger/qpacketprotocol.h \ - debugger/qmldebugservice.h \ - debugger/qmldebugclient.h \ - debugger/qmldebug.h +HEADERS += debugger/qmldebuggerstatus_p.h \ + debugger/qpacketprotocol_p.h \ + debugger/qmldebugservice_p.h \ + debugger/qmldebugclient_p.h \ + debugger/qmldebug_p.h diff --git a/src/declarative/debugger/qmldebug.cpp b/src/declarative/debugger/qmldebug.cpp index 5a8cda0..69a7326 100644 --- a/src/declarative/debugger/qmldebug.cpp +++ b/src/declarative/debugger/qmldebug.cpp @@ -1,5 +1,5 @@ -#include "qmldebug.h" -#include "qmldebugclient.h" +#include "qmldebug_p.h" +#include "qmldebugclient_p.h" #include #include diff --git a/src/declarative/debugger/qmldebug.h b/src/declarative/debugger/qmldebug.h deleted file mode 100644 index bd076ff..0000000 --- a/src/declarative/debugger/qmldebug.h +++ /dev/null @@ -1,314 +0,0 @@ -#ifndef QMLDEBUG_H -#define QMLDEBUG_H - -#include -#include -#include - -class QmlDebugConnection; -class QmlDebugWatch; -class QmlDebugPropertyWatch; -class QmlDebugObjectExpressionWatch; -class QmlDebugEnginesQuery; -class QmlDebugRootContextQuery; -class QmlDebugObjectQuery; -class QmlDebugExpressionQuery; -class QmlDebugPropertyReference; -class QmlDebugContextReference; -class QmlDebugObjectReference; -class QmlDebugFileReference; -class QmlDebugEngineReference; -class QmlEngineDebugPrivate; -class Q_DECLARATIVE_EXPORT QmlEngineDebug : public QObject -{ -Q_OBJECT -public: - QmlEngineDebug(QmlDebugConnection *, QObject * = 0); - - QmlDebugPropertyWatch *addWatch(const QmlDebugPropertyReference &, - QObject *parent = 0); - QmlDebugWatch *addWatch(const QmlDebugContextReference &, const QString &, - QObject *parent = 0); - QmlDebugObjectExpressionWatch *addWatch(const QmlDebugObjectReference &, const QString &, - QObject *parent = 0); - QmlDebugWatch *addWatch(const QmlDebugObjectReference &, - QObject *parent = 0); - QmlDebugWatch *addWatch(const QmlDebugFileReference &, - QObject *parent = 0); - - void removeWatch(QmlDebugWatch *watch); - - QmlDebugEnginesQuery *queryAvailableEngines(QObject *parent = 0); - QmlDebugRootContextQuery *queryRootContexts(const QmlDebugEngineReference &, - QObject *parent = 0); - QmlDebugObjectQuery *queryObject(const QmlDebugObjectReference &, - QObject *parent = 0); - QmlDebugObjectQuery *queryObjectRecursive(const QmlDebugObjectReference &, - QObject *parent = 0); - QmlDebugExpressionQuery *queryExpressionResult(int objectDebugId, - const QString &expr, - QObject *parent = 0); - -private: - Q_DECLARE_PRIVATE(QmlEngineDebug) -}; - -class Q_DECLARATIVE_EXPORT QmlDebugWatch : public QObject -{ -Q_OBJECT -public: - enum State { Waiting, Active, Inactive, Dead }; - - QmlDebugWatch(QObject *); - - int queryId() const; - int objectDebugId() const; - State state() const; - -signals: - void stateChanged(State); - //void objectChanged(int, const QmlDebugObjectReference &); - //void valueChanged(int, const QVariant &); - - // Server sends value as string if it is a user-type variant - void valueChanged(const QByteArray &name, const QVariant &value); - -private: - friend class QmlEngineDebug; - friend class QmlEngineDebugPrivate; - void setState(State); - State m_state; - int m_queryId; - int m_objectDebugId; -}; - -class Q_DECLARATIVE_EXPORT QmlDebugPropertyWatch : public QmlDebugWatch -{ - Q_OBJECT -public: - QmlDebugPropertyWatch(QObject *parent); - - QString name() const; - -private: - friend class QmlEngineDebug; - QString m_name; -}; - -class Q_DECLARATIVE_EXPORT QmlDebugObjectExpressionWatch : public QmlDebugWatch -{ - Q_OBJECT -public: - QmlDebugObjectExpressionWatch(QObject *parent); - - QString expression() const; - -private: - friend class QmlEngineDebug; - QString m_expr; - int m_debugId; -}; - - -class Q_DECLARATIVE_EXPORT QmlDebugQuery : public QObject -{ -Q_OBJECT -public: - enum State { Waiting, Error, Completed }; - - State state() const; - bool isWaiting() const; - -// bool waitUntilCompleted(); - -signals: - void stateChanged(State); - -protected: - QmlDebugQuery(QObject *); - -private: - friend class QmlEngineDebug; - friend class QmlEngineDebugPrivate; - void setState(State); - State m_state; -}; - -class Q_DECLARATIVE_EXPORT QmlDebugFileReference -{ -public: - QmlDebugFileReference(); - QmlDebugFileReference(const QmlDebugFileReference &); - QmlDebugFileReference &operator=(const QmlDebugFileReference &); - - QUrl url() const; - void setUrl(const QUrl &); - int lineNumber() const; - void setLineNumber(int); - int columnNumber() const; - void setColumnNumber(int); - -private: - friend class QmlEngineDebugPrivate; - QUrl m_url; - int m_lineNumber; - int m_columnNumber; -}; - -class Q_DECLARATIVE_EXPORT QmlDebugEngineReference -{ -public: - QmlDebugEngineReference(); - QmlDebugEngineReference(int); - QmlDebugEngineReference(const QmlDebugEngineReference &); - QmlDebugEngineReference &operator=(const QmlDebugEngineReference &); - - int debugId() const; - QString name() const; - -private: - friend class QmlEngineDebugPrivate; - int m_debugId; - QString m_name; -}; - -class Q_DECLARATIVE_EXPORT QmlDebugObjectReference -{ -public: - QmlDebugObjectReference(); - QmlDebugObjectReference(int); - QmlDebugObjectReference(const QmlDebugObjectReference &); - QmlDebugObjectReference &operator=(const QmlDebugObjectReference &); - - int debugId() const; - QString className() const; - QString name() const; - - QmlDebugFileReference source() const; - int contextDebugId() const; - - QList properties() const; - QList children() const; - -private: - friend class QmlEngineDebugPrivate; - int m_debugId; - QString m_class; - QString m_name; - QmlDebugFileReference m_source; - int m_contextDebugId; - QList m_properties; - QList m_children; -}; - -class Q_DECLARATIVE_EXPORT QmlDebugContextReference -{ -public: - QmlDebugContextReference(); - QmlDebugContextReference(const QmlDebugContextReference &); - QmlDebugContextReference &operator=(const QmlDebugContextReference &); - - int debugId() const; - QString name() const; - - QList objects() const; - QList contexts() const; - -private: - friend class QmlEngineDebugPrivate; - int m_debugId; - QString m_name; - QList m_objects; - QList m_contexts; -}; - -class Q_DECLARATIVE_EXPORT QmlDebugPropertyReference -{ -public: - QmlDebugPropertyReference(); - QmlDebugPropertyReference(const QmlDebugPropertyReference &); - QmlDebugPropertyReference &operator=(const QmlDebugPropertyReference &); - - int objectDebugId() const; - QString name() const; - QVariant value() const; - QString valueTypeName() const; - QString binding() const; - bool hasNotifySignal() const; - -private: - friend class QmlEngineDebugPrivate; - int m_objectDebugId; - QString m_name; - QVariant m_value; - QString m_valueTypeName; - QString m_binding; - bool m_hasNotifySignal; -}; - - -class Q_DECLARATIVE_EXPORT QmlDebugEnginesQuery : public QmlDebugQuery -{ -Q_OBJECT -public: - virtual ~QmlDebugEnginesQuery(); - QList engines() const; -private: - friend class QmlEngineDebug; - friend class QmlEngineDebugPrivate; - QmlDebugEnginesQuery(QObject *); - QmlEngineDebug *m_client; - int m_queryId; - QList m_engines; -}; - -class Q_DECLARATIVE_EXPORT QmlDebugRootContextQuery : public QmlDebugQuery -{ -Q_OBJECT -public: - virtual ~QmlDebugRootContextQuery(); - QmlDebugContextReference rootContext() const; -private: - friend class QmlEngineDebug; - friend class QmlEngineDebugPrivate; - QmlDebugRootContextQuery(QObject *); - QmlEngineDebug *m_client; - int m_queryId; - QmlDebugContextReference m_context; -}; - -class Q_DECLARATIVE_EXPORT QmlDebugObjectQuery : public QmlDebugQuery -{ -Q_OBJECT -public: - virtual ~QmlDebugObjectQuery(); - QmlDebugObjectReference object() const; -private: - friend class QmlEngineDebug; - friend class QmlEngineDebugPrivate; - QmlDebugObjectQuery(QObject *); - QmlEngineDebug *m_client; - int m_queryId; - QmlDebugObjectReference m_object; - -}; - -class Q_DECLARATIVE_EXPORT QmlDebugExpressionQuery : public QmlDebugQuery -{ -Q_OBJECT -public: - virtual ~QmlDebugExpressionQuery(); - QString expression() const; - QVariant result() const; -private: - friend class QmlEngineDebug; - friend class QmlEngineDebugPrivate; - QmlDebugExpressionQuery(QObject *); - QmlEngineDebug *m_client; - int m_queryId; - QString m_expr; - QVariant m_result; - -}; - -#endif // QMLDEBUG_H diff --git a/src/declarative/debugger/qmldebug_p.h b/src/declarative/debugger/qmldebug_p.h new file mode 100644 index 0000000..bd076ff --- /dev/null +++ b/src/declarative/debugger/qmldebug_p.h @@ -0,0 +1,314 @@ +#ifndef QMLDEBUG_H +#define QMLDEBUG_H + +#include +#include +#include + +class QmlDebugConnection; +class QmlDebugWatch; +class QmlDebugPropertyWatch; +class QmlDebugObjectExpressionWatch; +class QmlDebugEnginesQuery; +class QmlDebugRootContextQuery; +class QmlDebugObjectQuery; +class QmlDebugExpressionQuery; +class QmlDebugPropertyReference; +class QmlDebugContextReference; +class QmlDebugObjectReference; +class QmlDebugFileReference; +class QmlDebugEngineReference; +class QmlEngineDebugPrivate; +class Q_DECLARATIVE_EXPORT QmlEngineDebug : public QObject +{ +Q_OBJECT +public: + QmlEngineDebug(QmlDebugConnection *, QObject * = 0); + + QmlDebugPropertyWatch *addWatch(const QmlDebugPropertyReference &, + QObject *parent = 0); + QmlDebugWatch *addWatch(const QmlDebugContextReference &, const QString &, + QObject *parent = 0); + QmlDebugObjectExpressionWatch *addWatch(const QmlDebugObjectReference &, const QString &, + QObject *parent = 0); + QmlDebugWatch *addWatch(const QmlDebugObjectReference &, + QObject *parent = 0); + QmlDebugWatch *addWatch(const QmlDebugFileReference &, + QObject *parent = 0); + + void removeWatch(QmlDebugWatch *watch); + + QmlDebugEnginesQuery *queryAvailableEngines(QObject *parent = 0); + QmlDebugRootContextQuery *queryRootContexts(const QmlDebugEngineReference &, + QObject *parent = 0); + QmlDebugObjectQuery *queryObject(const QmlDebugObjectReference &, + QObject *parent = 0); + QmlDebugObjectQuery *queryObjectRecursive(const QmlDebugObjectReference &, + QObject *parent = 0); + QmlDebugExpressionQuery *queryExpressionResult(int objectDebugId, + const QString &expr, + QObject *parent = 0); + +private: + Q_DECLARE_PRIVATE(QmlEngineDebug) +}; + +class Q_DECLARATIVE_EXPORT QmlDebugWatch : public QObject +{ +Q_OBJECT +public: + enum State { Waiting, Active, Inactive, Dead }; + + QmlDebugWatch(QObject *); + + int queryId() const; + int objectDebugId() const; + State state() const; + +signals: + void stateChanged(State); + //void objectChanged(int, const QmlDebugObjectReference &); + //void valueChanged(int, const QVariant &); + + // Server sends value as string if it is a user-type variant + void valueChanged(const QByteArray &name, const QVariant &value); + +private: + friend class QmlEngineDebug; + friend class QmlEngineDebugPrivate; + void setState(State); + State m_state; + int m_queryId; + int m_objectDebugId; +}; + +class Q_DECLARATIVE_EXPORT QmlDebugPropertyWatch : public QmlDebugWatch +{ + Q_OBJECT +public: + QmlDebugPropertyWatch(QObject *parent); + + QString name() const; + +private: + friend class QmlEngineDebug; + QString m_name; +}; + +class Q_DECLARATIVE_EXPORT QmlDebugObjectExpressionWatch : public QmlDebugWatch +{ + Q_OBJECT +public: + QmlDebugObjectExpressionWatch(QObject *parent); + + QString expression() const; + +private: + friend class QmlEngineDebug; + QString m_expr; + int m_debugId; +}; + + +class Q_DECLARATIVE_EXPORT QmlDebugQuery : public QObject +{ +Q_OBJECT +public: + enum State { Waiting, Error, Completed }; + + State state() const; + bool isWaiting() const; + +// bool waitUntilCompleted(); + +signals: + void stateChanged(State); + +protected: + QmlDebugQuery(QObject *); + +private: + friend class QmlEngineDebug; + friend class QmlEngineDebugPrivate; + void setState(State); + State m_state; +}; + +class Q_DECLARATIVE_EXPORT QmlDebugFileReference +{ +public: + QmlDebugFileReference(); + QmlDebugFileReference(const QmlDebugFileReference &); + QmlDebugFileReference &operator=(const QmlDebugFileReference &); + + QUrl url() const; + void setUrl(const QUrl &); + int lineNumber() const; + void setLineNumber(int); + int columnNumber() const; + void setColumnNumber(int); + +private: + friend class QmlEngineDebugPrivate; + QUrl m_url; + int m_lineNumber; + int m_columnNumber; +}; + +class Q_DECLARATIVE_EXPORT QmlDebugEngineReference +{ +public: + QmlDebugEngineReference(); + QmlDebugEngineReference(int); + QmlDebugEngineReference(const QmlDebugEngineReference &); + QmlDebugEngineReference &operator=(const QmlDebugEngineReference &); + + int debugId() const; + QString name() const; + +private: + friend class QmlEngineDebugPrivate; + int m_debugId; + QString m_name; +}; + +class Q_DECLARATIVE_EXPORT QmlDebugObjectReference +{ +public: + QmlDebugObjectReference(); + QmlDebugObjectReference(int); + QmlDebugObjectReference(const QmlDebugObjectReference &); + QmlDebugObjectReference &operator=(const QmlDebugObjectReference &); + + int debugId() const; + QString className() const; + QString name() const; + + QmlDebugFileReference source() const; + int contextDebugId() const; + + QList properties() const; + QList children() const; + +private: + friend class QmlEngineDebugPrivate; + int m_debugId; + QString m_class; + QString m_name; + QmlDebugFileReference m_source; + int m_contextDebugId; + QList m_properties; + QList m_children; +}; + +class Q_DECLARATIVE_EXPORT QmlDebugContextReference +{ +public: + QmlDebugContextReference(); + QmlDebugContextReference(const QmlDebugContextReference &); + QmlDebugContextReference &operator=(const QmlDebugContextReference &); + + int debugId() const; + QString name() const; + + QList objects() const; + QList contexts() const; + +private: + friend class QmlEngineDebugPrivate; + int m_debugId; + QString m_name; + QList m_objects; + QList m_contexts; +}; + +class Q_DECLARATIVE_EXPORT QmlDebugPropertyReference +{ +public: + QmlDebugPropertyReference(); + QmlDebugPropertyReference(const QmlDebugPropertyReference &); + QmlDebugPropertyReference &operator=(const QmlDebugPropertyReference &); + + int objectDebugId() const; + QString name() const; + QVariant value() const; + QString valueTypeName() const; + QString binding() const; + bool hasNotifySignal() const; + +private: + friend class QmlEngineDebugPrivate; + int m_objectDebugId; + QString m_name; + QVariant m_value; + QString m_valueTypeName; + QString m_binding; + bool m_hasNotifySignal; +}; + + +class Q_DECLARATIVE_EXPORT QmlDebugEnginesQuery : public QmlDebugQuery +{ +Q_OBJECT +public: + virtual ~QmlDebugEnginesQuery(); + QList engines() const; +private: + friend class QmlEngineDebug; + friend class QmlEngineDebugPrivate; + QmlDebugEnginesQuery(QObject *); + QmlEngineDebug *m_client; + int m_queryId; + QList m_engines; +}; + +class Q_DECLARATIVE_EXPORT QmlDebugRootContextQuery : public QmlDebugQuery +{ +Q_OBJECT +public: + virtual ~QmlDebugRootContextQuery(); + QmlDebugContextReference rootContext() const; +private: + friend class QmlEngineDebug; + friend class QmlEngineDebugPrivate; + QmlDebugRootContextQuery(QObject *); + QmlEngineDebug *m_client; + int m_queryId; + QmlDebugContextReference m_context; +}; + +class Q_DECLARATIVE_EXPORT QmlDebugObjectQuery : public QmlDebugQuery +{ +Q_OBJECT +public: + virtual ~QmlDebugObjectQuery(); + QmlDebugObjectReference object() const; +private: + friend class QmlEngineDebug; + friend class QmlEngineDebugPrivate; + QmlDebugObjectQuery(QObject *); + QmlEngineDebug *m_client; + int m_queryId; + QmlDebugObjectReference m_object; + +}; + +class Q_DECLARATIVE_EXPORT QmlDebugExpressionQuery : public QmlDebugQuery +{ +Q_OBJECT +public: + virtual ~QmlDebugExpressionQuery(); + QString expression() const; + QVariant result() const; +private: + friend class QmlEngineDebug; + friend class QmlEngineDebugPrivate; + QmlDebugExpressionQuery(QObject *); + QmlEngineDebug *m_client; + int m_queryId; + QString m_expr; + QVariant m_result; + +}; + +#endif // QMLDEBUG_H diff --git a/src/declarative/debugger/qmldebugclient.cpp b/src/declarative/debugger/qmldebugclient.cpp index 3171808..7264e14 100644 --- a/src/declarative/debugger/qmldebugclient.cpp +++ b/src/declarative/debugger/qmldebugclient.cpp @@ -39,9 +39,9 @@ ** ****************************************************************************/ -#include "qmldebugclient.h" +#include "qmldebugclient_p.h" #include -#include +#include #include #include diff --git a/src/declarative/debugger/qmldebugclient.h b/src/declarative/debugger/qmldebugclient.h deleted file mode 100644 index 6397670..0000000 --- a/src/declarative/debugger/qmldebugclient.h +++ /dev/null @@ -1,99 +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 QMLDEBUGCLIENT_H -#define QMLDEBUGCLIENT_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlDebugConnectionPrivate; -class Q_DECLARATIVE_EXPORT QmlDebugConnection : public QTcpSocket -{ - Q_OBJECT - Q_DISABLE_COPY(QmlDebugConnection) -public: - QmlDebugConnection(QObject * = 0); - - bool isConnected() const; -private: - QmlDebugConnectionPrivate *d; - friend class QmlDebugClient; - friend class QmlDebugClientPrivate; -}; - -class QmlDebugClientPrivate; -class Q_DECLARATIVE_EXPORT QmlDebugClient : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlDebugClient) - Q_DISABLE_COPY(QmlDebugClient) - -public: - QmlDebugClient(const QString &, QmlDebugConnection *parent); - - QString name() const; - - bool isEnabled() const; - void setEnabled(bool); - - bool isConnected() const; - - void sendMessage(const QByteArray &); - -protected: - virtual void messageReceived(const QByteArray &); - -private: - friend class QmlDebugConnection; - friend class QmlDebugConnectionPrivate; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMLDEBUGCLIENT_H diff --git a/src/declarative/debugger/qmldebugclient_p.h b/src/declarative/debugger/qmldebugclient_p.h new file mode 100644 index 0000000..6397670 --- /dev/null +++ b/src/declarative/debugger/qmldebugclient_p.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** 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 QMLDEBUGCLIENT_H +#define QMLDEBUGCLIENT_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlDebugConnectionPrivate; +class Q_DECLARATIVE_EXPORT QmlDebugConnection : public QTcpSocket +{ + Q_OBJECT + Q_DISABLE_COPY(QmlDebugConnection) +public: + QmlDebugConnection(QObject * = 0); + + bool isConnected() const; +private: + QmlDebugConnectionPrivate *d; + friend class QmlDebugClient; + friend class QmlDebugClientPrivate; +}; + +class QmlDebugClientPrivate; +class Q_DECLARATIVE_EXPORT QmlDebugClient : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlDebugClient) + Q_DISABLE_COPY(QmlDebugClient) + +public: + QmlDebugClient(const QString &, QmlDebugConnection *parent); + + QString name() const; + + bool isEnabled() const; + void setEnabled(bool); + + bool isConnected() const; + + void sendMessage(const QByteArray &); + +protected: + virtual void messageReceived(const QByteArray &); + +private: + friend class QmlDebugConnection; + friend class QmlDebugConnectionPrivate; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLDEBUGCLIENT_H diff --git a/src/declarative/debugger/qmldebuggerstatus.cpp b/src/declarative/debugger/qmldebuggerstatus.cpp index d46a21d..d4404a5 100644 --- a/src/declarative/debugger/qmldebuggerstatus.cpp +++ b/src/declarative/debugger/qmldebuggerstatus.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmldebuggerstatus.h" +#include "qmldebuggerstatus_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/debugger/qmldebuggerstatus.h b/src/declarative/debugger/qmldebuggerstatus.h deleted file mode 100644 index a8480f4..0000000 --- a/src/declarative/debugger/qmldebuggerstatus.h +++ /dev/null @@ -1,66 +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 QMLDEBUGGERSTATUS_P_H -#define QMLDEBUGGERSTATUS_P_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QmlDebuggerStatus -{ -public: - virtual ~QmlDebuggerStatus(); - - virtual void setSelectedState(bool); -}; -Q_DECLARE_INTERFACE(QmlDebuggerStatus, "com.trolltech.qml.QmlDebuggerStatus") - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QLMDEBUGGERSTATUS_P_H diff --git a/src/declarative/debugger/qmldebuggerstatus_p.h b/src/declarative/debugger/qmldebuggerstatus_p.h new file mode 100644 index 0000000..a8480f4 --- /dev/null +++ b/src/declarative/debugger/qmldebuggerstatus_p.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 QMLDEBUGGERSTATUS_P_H +#define QMLDEBUGGERSTATUS_P_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class Q_DECLARATIVE_EXPORT QmlDebuggerStatus +{ +public: + virtual ~QmlDebuggerStatus(); + + virtual void setSelectedState(bool); +}; +Q_DECLARE_INTERFACE(QmlDebuggerStatus, "com.trolltech.qml.QmlDebuggerStatus") + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QLMDEBUGGERSTATUS_P_H diff --git a/src/declarative/debugger/qmldebugservice.cpp b/src/declarative/debugger/qmldebugservice.cpp index 6913def..241eee2 100644 --- a/src/declarative/debugger/qmldebugservice.cpp +++ b/src/declarative/debugger/qmldebugservice.cpp @@ -39,12 +39,12 @@ ** ****************************************************************************/ -#include "qmldebugservice.h" +#include "qmldebugservice_p.h" #include #include #include #include -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/declarative/debugger/qmldebugservice.h b/src/declarative/debugger/qmldebugservice.h deleted file mode 100644 index 5d20ba0..0000000 --- a/src/declarative/debugger/qmldebugservice.h +++ /dev/null @@ -1,88 +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 QMLDEBUGSERVICE_H -#define QMLDEBUGSERVICE_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QmlDebugServicePrivate; -class Q_DECLARATIVE_EXPORT QmlDebugService : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlDebugService) - Q_DISABLE_COPY(QmlDebugService) -public: - QmlDebugService(const QString &, QObject *parent = 0); - - QString name() const; - - bool isEnabled() const; - - void sendMessage(const QByteArray &); - - static int idForObject(QObject *); - static QObject *objectForId(int); - - - static bool isDebuggingEnabled(); - static QString objectToString(QObject *obj); - - static void waitForClients(); - -protected: - virtual void enabledChanged(bool); - virtual void messageReceived(const QByteArray &); - -private: - friend class QmlDebugServer; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMLDEBUGSERVICE_H - diff --git a/src/declarative/debugger/qmldebugservice_p.h b/src/declarative/debugger/qmldebugservice_p.h new file mode 100644 index 0000000..5d20ba0 --- /dev/null +++ b/src/declarative/debugger/qmldebugservice_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 QMLDEBUGSERVICE_H +#define QMLDEBUGSERVICE_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QmlDebugServicePrivate; +class Q_DECLARATIVE_EXPORT QmlDebugService : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlDebugService) + Q_DISABLE_COPY(QmlDebugService) +public: + QmlDebugService(const QString &, QObject *parent = 0); + + QString name() const; + + bool isEnabled() const; + + void sendMessage(const QByteArray &); + + static int idForObject(QObject *); + static QObject *objectForId(int); + + + static bool isDebuggingEnabled(); + static QString objectToString(QObject *obj); + + static void waitForClients(); + +protected: + virtual void enabledChanged(bool); + virtual void messageReceived(const QByteArray &); + +private: + friend class QmlDebugServer; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLDEBUGSERVICE_H + diff --git a/src/declarative/debugger/qpacketprotocol.cpp b/src/declarative/debugger/qpacketprotocol.cpp index 84882dd..604c8f6 100644 --- a/src/declarative/debugger/qpacketprotocol.cpp +++ b/src/declarative/debugger/qpacketprotocol.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qpacketprotocol.h" +#include "qpacketprotocol_p.h" #include QT_BEGIN_NAMESPACE diff --git a/src/declarative/debugger/qpacketprotocol.h b/src/declarative/debugger/qpacketprotocol.h deleted file mode 100644 index f3fb44b..0000000 --- a/src/declarative/debugger/qpacketprotocol.h +++ /dev/null @@ -1,122 +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 QPACKETPROTOCOL_H -#define QPACKETPROTOCOL_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QIODevice; -class QBuffer; -class QPacket; -class QPacketAutoSend; -class QPacketProtocolPrivate; - -class Q_DECLARATIVE_EXPORT QPacketProtocol : public QObject -{ -Q_OBJECT -public: - explicit QPacketProtocol(QIODevice * dev, QObject * parent = 0); - virtual ~QPacketProtocol(); - - qint32 maximumPacketSize() const; - qint32 setMaximumPacketSize(qint32); - - QPacketAutoSend send(); - void send(const QPacket &); - - qint64 packetsAvailable() const; - QPacket read(); - - void clear(); - - QIODevice * device(); - -signals: - void readyRead(); - void invalidPacket(); - void packetWritten(); - -private: - QPacketProtocolPrivate * d; -}; - - -class Q_DECLARATIVE_EXPORT QPacket : public QDataStream -{ -public: - QPacket(); - QPacket(const QPacket &); - virtual ~QPacket(); - - void clear(); - bool isEmpty() const; - -protected: - friend class QPacketProtocol; - QPacket(const QByteArray & ba); - QByteArray b; - QBuffer * buf; -}; - -class Q_DECLARATIVE_EXPORT QPacketAutoSend : public QPacket -{ -public: - virtual ~QPacketAutoSend(); - -private: - friend class QPacketProtocol; - QPacketAutoSend(QPacketProtocol *); - QPacketProtocol * p; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/declarative/debugger/qpacketprotocol_p.h b/src/declarative/debugger/qpacketprotocol_p.h new file mode 100644 index 0000000..f3fb44b --- /dev/null +++ b/src/declarative/debugger/qpacketprotocol_p.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** 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 QPACKETPROTOCOL_H +#define QPACKETPROTOCOL_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QIODevice; +class QBuffer; +class QPacket; +class QPacketAutoSend; +class QPacketProtocolPrivate; + +class Q_DECLARATIVE_EXPORT QPacketProtocol : public QObject +{ +Q_OBJECT +public: + explicit QPacketProtocol(QIODevice * dev, QObject * parent = 0); + virtual ~QPacketProtocol(); + + qint32 maximumPacketSize() const; + qint32 setMaximumPacketSize(qint32); + + QPacketAutoSend send(); + void send(const QPacket &); + + qint64 packetsAvailable() const; + QPacket read(); + + void clear(); + + QIODevice * device(); + +signals: + void readyRead(); + void invalidPacket(); + void packetWritten(); + +private: + QPacketProtocolPrivate * d; +}; + + +class Q_DECLARATIVE_EXPORT QPacket : public QDataStream +{ +public: + QPacket(); + QPacket(const QPacket &); + virtual ~QPacket(); + + void clear(); + bool isEmpty() const; + +protected: + friend class QPacketProtocol; + QPacket(const QByteArray & ba); + QByteArray b; + QBuffer * buf; +}; + +class Q_DECLARATIVE_EXPORT QPacketAutoSend : public QPacket +{ +public: + virtual ~QPacketAutoSend(); + +private: + friend class QPacketProtocol; + QPacketAutoSend(QPacketProtocol *); + QPacketProtocol * p; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/declarative/extra/extra.pri b/src/declarative/extra/extra.pri index 47cc8f8..9d0e760 100644 --- a/src/declarative/extra/extra.pri +++ b/src/declarative/extra/extra.pri @@ -9,19 +9,19 @@ SOURCES += \ extra/qmlfontloader.cpp HEADERS += \ - extra/qnumberformat.h \ - extra/qmlnumberformatter.h \ - extra/qmldatetimeformatter.h \ - extra/qmlgraphicsintegermodel.h \ - extra/qmlgraphicsanimatedimageitem.h \ + extra/qnumberformat_p.h \ + extra/qmlnumberformatter_p.h \ + extra/qmldatetimeformatter_p.h \ + extra/qmlgraphicsintegermodel_p.h \ extra/qmlgraphicsanimatedimageitem_p.h \ - extra/qmlgraphicsparticles.h \ - extra/qmlbehavior.h \ - extra/qmlfontloader.h + extra/qmlgraphicsanimatedimageitem_p_p.h \ + extra/qmlgraphicsparticles_p.h \ + extra/qmlbehavior_p.h \ + extra/qmlfontloader_p.h contains(QT_CONFIG, xmlpatterns) { QT+=xmlpatterns SOURCES += extra/qmlxmllistmodel.cpp - HEADERS += extra/qmlxmllistmodel.h + HEADERS += extra/qmlxmllistmodel_p.h } diff --git a/src/declarative/extra/qmlbehavior.cpp b/src/declarative/extra/qmlbehavior.cpp index 654cb4e..eac4220 100644 --- a/src/declarative/extra/qmlbehavior.cpp +++ b/src/declarative/extra/qmlbehavior.cpp @@ -40,9 +40,9 @@ ****************************************************************************/ #include -#include "qmlanimation.h" -#include "qmltransition.h" -#include "qmlbehavior.h" +#include +#include +#include "qmlbehavior_p.h" #include #include #include diff --git a/src/declarative/extra/qmlbehavior.h b/src/declarative/extra/qmlbehavior.h deleted file mode 100644 index 6508455..0000000 --- a/src/declarative/extra/qmlbehavior.h +++ /dev/null @@ -1,84 +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 QMLBEHAVIOR_H -#define QMLBEHAVIOR_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlAbstractAnimation; -class QmlBehaviorPrivate; -class Q_DECLARATIVE_EXPORT QmlBehavior : public QObject, public QmlPropertyValueInterceptor -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlBehavior) - - Q_INTERFACES(QmlPropertyValueInterceptor) - Q_CLASSINFO("DefaultProperty", "animation") - Q_PROPERTY(QmlAbstractAnimation *animation READ animation WRITE setAnimation) - -public: - QmlBehavior(QObject *parent=0); - ~QmlBehavior(); - - virtual void setTarget(const QmlMetaProperty &); - virtual void write(const QVariant &value); - - QmlAbstractAnimation *animation(); - void setAnimation(QmlAbstractAnimation *); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlBehavior) - -QT_END_HEADER - -#endif // QMLBEHAVIOR_H diff --git a/src/declarative/extra/qmlbehavior_p.h b/src/declarative/extra/qmlbehavior_p.h new file mode 100644 index 0000000..0c8fdfd --- /dev/null +++ b/src/declarative/extra/qmlbehavior_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 QMLBEHAVIOR_H +#define QMLBEHAVIOR_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlAbstractAnimation; +class QmlBehaviorPrivate; +class Q_DECLARATIVE_EXPORT QmlBehavior : public QObject, public QmlPropertyValueInterceptor +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlBehavior) + + Q_INTERFACES(QmlPropertyValueInterceptor) + Q_CLASSINFO("DefaultProperty", "animation") + Q_PROPERTY(QmlAbstractAnimation *animation READ animation WRITE setAnimation) + +public: + QmlBehavior(QObject *parent=0); + ~QmlBehavior(); + + virtual void setTarget(const QmlMetaProperty &); + virtual void write(const QVariant &value); + + QmlAbstractAnimation *animation(); + void setAnimation(QmlAbstractAnimation *); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlBehavior) + +QT_END_HEADER + +#endif // QMLBEHAVIOR_H diff --git a/src/declarative/extra/qmldatetimeformatter.cpp b/src/declarative/extra/qmldatetimeformatter.cpp index 9b3d37a..8d5deff 100644 --- a/src/declarative/extra/qmldatetimeformatter.cpp +++ b/src/declarative/extra/qmldatetimeformatter.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmldatetimeformatter.h" +#include "qmldatetimeformatter_p.h" #include "private/qobject_p.h" #include diff --git a/src/declarative/extra/qmldatetimeformatter.h b/src/declarative/extra/qmldatetimeformatter.h deleted file mode 100644 index be0ae02..0000000 --- a/src/declarative/extra/qmldatetimeformatter.h +++ /dev/null @@ -1,116 +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 QMLDATETIMEFORMATTER_H -#define QMLDATETIMEFORMATTER_H - -#include -#include - -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 componentComplete(); - -Q_SIGNALS: - void textChanged(); - -private: - Q_DISABLE_COPY(QmlDateTimeFormatter) - Q_DECLARE_PRIVATE(QmlDateTimeFormatter) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlDateTimeFormatter) - -QT_END_HEADER - -#endif diff --git a/src/declarative/extra/qmldatetimeformatter_p.h b/src/declarative/extra/qmldatetimeformatter_p.h new file mode 100644 index 0000000..be0ae02 --- /dev/null +++ b/src/declarative/extra/qmldatetimeformatter_p.h @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** 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 +#include + +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 componentComplete(); + +Q_SIGNALS: + void textChanged(); + +private: + Q_DISABLE_COPY(QmlDateTimeFormatter) + Q_DECLARE_PRIVATE(QmlDateTimeFormatter) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlDateTimeFormatter) + +QT_END_HEADER + +#endif diff --git a/src/declarative/extra/qmlfontloader.cpp b/src/declarative/extra/qmlfontloader.cpp index f9857f6..dffbc3f 100644 --- a/src/declarative/extra/qmlfontloader.cpp +++ b/src/declarative/extra/qmlfontloader.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "private/qobject_p.h" -#include "qmlfontloader.h" +#include "qmlfontloader_p.h" #include #include #include diff --git a/src/declarative/extra/qmlfontloader.h b/src/declarative/extra/qmlfontloader.h deleted file mode 100644 index c2c7a16..0000000 --- a/src/declarative/extra/qmlfontloader.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 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 - diff --git a/src/declarative/extra/qmlfontloader_p.h b/src/declarative/extra/qmlfontloader_p.h new file mode 100644 index 0000000..c2c7a16 --- /dev/null +++ b/src/declarative/extra/qmlfontloader_p.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 + diff --git a/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp b/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp index c22e56d..b781e75 100644 --- a/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp +++ b/src/declarative/extra/qmlgraphicsanimatedimageitem.cpp @@ -42,8 +42,8 @@ #include #include #include -#include "qmlgraphicsanimatedimageitem.h" #include "qmlgraphicsanimatedimageitem_p.h" +#include "qmlgraphicsanimatedimageitem_p_p.h" #include #include diff --git a/src/declarative/extra/qmlgraphicsanimatedimageitem.h b/src/declarative/extra/qmlgraphicsanimatedimageitem.h deleted file mode 100644 index c62a98e..0000000 --- a/src/declarative/extra/qmlgraphicsanimatedimageitem.h +++ /dev/null @@ -1,106 +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 QMLGRAPHICSANIMATEDIMAGEITEM_H -#define QMLGRAPHICSANIMATEDIMAGEITEM_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QMovie; -class QmlGraphicsAnimatedImageItemPrivate; - -class Q_DECLARATIVE_EXPORT QmlGraphicsAnimatedImageItem : public QmlGraphicsImage -{ - Q_OBJECT - - Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) - Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) - Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY frameChanged) - Q_PROPERTY(int frameCount READ frameCount) -public: - QmlGraphicsAnimatedImageItem(QmlGraphicsItem *parent=0); - ~QmlGraphicsAnimatedImageItem(); - - bool isPlaying() const; - void setPlaying(bool play); - - bool isPaused() const; - void setPaused(bool pause); - - int currentFrame() const; - void setCurrentFrame(int frame); - - int frameCount() const; - - // Extends QmlGraphicsImage's src property*/ - virtual void setSource(const QUrl&); - -Q_SIGNALS: - void playingChanged(); - void pausedChanged(); - void frameChanged(); - -private Q_SLOTS: - void movieUpdate(); - void movieRequestFinished(); - void playingStatusChanged(); - -protected: - QmlGraphicsAnimatedImageItem(QmlGraphicsAnimatedImageItemPrivate &dd, QmlGraphicsItem *parent); - -private: - Q_DISABLE_COPY(QmlGraphicsAnimatedImageItem) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsAnimatedImageItem) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsAnimatedImageItem) - -QT_END_HEADER - -#endif diff --git a/src/declarative/extra/qmlgraphicsanimatedimageitem_p.h b/src/declarative/extra/qmlgraphicsanimatedimageitem_p.h index 04f1b6e..b0b6f14 100644 --- a/src/declarative/extra/qmlgraphicsanimatedimageitem_p.h +++ b/src/declarative/extra/qmlgraphicsanimatedimageitem_p.h @@ -39,43 +39,68 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSANIMATEDIMAGE_P_H -#define QMLGRAPHICSANIMATEDIMAGE_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. -// +#ifndef QMLGRAPHICSANIMATEDIMAGEITEM_H +#define QMLGRAPHICSANIMATEDIMAGEITEM_H #include +QT_BEGIN_HEADER + QT_BEGIN_NAMESPACE +QT_MODULE(Declarative) + class QMovie; -class QNetworkReply; +class QmlGraphicsAnimatedImageItemPrivate; -class QmlGraphicsAnimatedImageItemPrivate : public QmlGraphicsImagePrivate +class Q_DECLARATIVE_EXPORT QmlGraphicsAnimatedImageItem : public QmlGraphicsImage { - Q_DECLARE_PUBLIC(QmlGraphicsAnimatedImageItem) + Q_OBJECT + Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) + Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) + Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY frameChanged) + Q_PROPERTY(int frameCount READ frameCount) public: - QmlGraphicsAnimatedImageItemPrivate() - : playing(true), paused(false), _movie(0), reply(0) - { - } - - bool playing; - bool paused; - QMovie *_movie; - QNetworkReply *reply; + QmlGraphicsAnimatedImageItem(QmlGraphicsItem *parent=0); + ~QmlGraphicsAnimatedImageItem(); + + bool isPlaying() const; + void setPlaying(bool play); + + bool isPaused() const; + void setPaused(bool pause); + + int currentFrame() const; + void setCurrentFrame(int frame); + + int frameCount() const; + + // Extends QmlGraphicsImage's src property*/ + virtual void setSource(const QUrl&); + +Q_SIGNALS: + void playingChanged(); + void pausedChanged(); + void frameChanged(); + +private Q_SLOTS: + void movieUpdate(); + void movieRequestFinished(); + void playingStatusChanged(); + +protected: + QmlGraphicsAnimatedImageItem(QmlGraphicsAnimatedImageItemPrivate &dd, QmlGraphicsItem *parent); + +private: + Q_DISABLE_COPY(QmlGraphicsAnimatedImageItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsAnimatedImageItem) }; QT_END_NAMESPACE -#endif // QMLGRAPHICSANIMATEDIMAGE_P_H +QML_DECLARE_TYPE(QmlGraphicsAnimatedImageItem) + +QT_END_HEADER + +#endif diff --git a/src/declarative/extra/qmlgraphicsanimatedimageitem_p_p.h b/src/declarative/extra/qmlgraphicsanimatedimageitem_p_p.h new file mode 100644 index 0000000..b43175f --- /dev/null +++ b/src/declarative/extra/qmlgraphicsanimatedimageitem_p_p.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSANIMATEDIMAGE_P_H +#define QMLGRAPHICSANIMATEDIMAGE_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 + +QT_BEGIN_NAMESPACE + +class QMovie; +class QNetworkReply; + +class QmlGraphicsAnimatedImageItemPrivate : public QmlGraphicsImagePrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsAnimatedImageItem) + +public: + QmlGraphicsAnimatedImageItemPrivate() + : playing(true), paused(false), _movie(0), reply(0) + { + } + + bool playing; + bool paused; + QMovie *_movie; + QNetworkReply *reply; +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSANIMATEDIMAGE_P_H diff --git a/src/declarative/extra/qmlgraphicsintegermodel.cpp b/src/declarative/extra/qmlgraphicsintegermodel.cpp index e83b9c9..2bbb19d 100644 --- a/src/declarative/extra/qmlgraphicsintegermodel.cpp +++ b/src/declarative/extra/qmlgraphicsintegermodel.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlgraphicsintegermodel.h" +#include "qmlgraphicsintegermodel_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/extra/qmlgraphicsintegermodel.h b/src/declarative/extra/qmlgraphicsintegermodel.h deleted file mode 100644 index 3cad05e..0000000 --- a/src/declarative/extra/qmlgraphicsintegermodel.h +++ /dev/null @@ -1,86 +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 QMLGRAPHICSINTMODEL_H -#define QMLGRAPHICSINTMODEL_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsIntegerModelPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsIntegerModel : public QListModelInterface -{ - Q_OBJECT -public: - QmlGraphicsIntegerModel(QObject *parent=0); - ~QmlGraphicsIntegerModel(); - - Q_PROPERTY(int minimum READ minimum WRITE setMinimum) - int minimum() const; - void setMinimum(int); - - Q_PROPERTY(int maximum READ maximum WRITE setMaximum) - int maximum() const; - void setMaximum(int); - - int count() const; - QHash data(int index, const QList &roles) const; - QList roles() const; - QString toString(int role) const; - -private: - QmlGraphicsIntegerModelPrivate *d; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsIntegerModel) - -QT_END_HEADER - -#endif diff --git a/src/declarative/extra/qmlgraphicsintegermodel_p.h b/src/declarative/extra/qmlgraphicsintegermodel_p.h new file mode 100644 index 0000000..706e478 --- /dev/null +++ b/src/declarative/extra/qmlgraphicsintegermodel_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSINTMODEL_H +#define QMLGRAPHICSINTMODEL_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsIntegerModelPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsIntegerModel : public QListModelInterface +{ + Q_OBJECT +public: + QmlGraphicsIntegerModel(QObject *parent=0); + ~QmlGraphicsIntegerModel(); + + Q_PROPERTY(int minimum READ minimum WRITE setMinimum) + int minimum() const; + void setMinimum(int); + + Q_PROPERTY(int maximum READ maximum WRITE setMaximum) + int maximum() const; + void setMaximum(int); + + int count() const; + QHash data(int index, const QList &roles) const; + QList roles() const; + QString toString(int role) const; + +private: + QmlGraphicsIntegerModelPrivate *d; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsIntegerModel) + +QT_END_HEADER + +#endif diff --git a/src/declarative/extra/qmlgraphicsparticles.cpp b/src/declarative/extra/qmlgraphicsparticles.cpp index dba3ac4..5a23126 100644 --- a/src/declarative/extra/qmlgraphicsparticles.cpp +++ b/src/declarative/extra/qmlgraphicsparticles.cpp @@ -50,12 +50,12 @@ #ifndef INT_MAX #define INT_MAX 2147483647 #endif -#include -#include -#include +#include +#include +#include #include -#include "qmlgraphicsparticles.h" +#include "qmlgraphicsparticles_p.h" #include #include #include diff --git a/src/declarative/extra/qmlgraphicsparticles.h b/src/declarative/extra/qmlgraphicsparticles.h deleted file mode 100644 index eed0d62..0000000 --- a/src/declarative/extra/qmlgraphicsparticles.h +++ /dev/null @@ -1,230 +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 QMLGRAPHICSPARTICLES_H -#define QMLGRAPHICSPARTICLES_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsParticle; -class QmlGraphicsParticles; -class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotion : public QObject -{ - Q_OBJECT -public: - QmlGraphicsParticleMotion(QObject *parent=0); - - virtual void advance(QmlGraphicsParticle &, int interval); - virtual void created(QmlGraphicsParticle &); - virtual void destroy(QmlGraphicsParticle &); -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionLinear : public QmlGraphicsParticleMotion -{ - Q_OBJECT -public: - QmlGraphicsParticleMotionLinear(QObject *parent=0) - : QmlGraphicsParticleMotion(parent) {} - - virtual void advance(QmlGraphicsParticle &, int interval); -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionGravity : public QmlGraphicsParticleMotion -{ - Q_OBJECT - - Q_PROPERTY(int xattractor READ xAttractor WRITE setXAttractor) - Q_PROPERTY(int yattractor READ yAttractor WRITE setYAttractor) - Q_PROPERTY(int acceleration READ acceleration WRITE setAcceleration) -public: - QmlGraphicsParticleMotionGravity(QObject *parent=0) - : QmlGraphicsParticleMotion(parent), _xAttr(0), _yAttr(0), _accel(0.00005) {} - - int xAttractor() const { return _xAttr; } - void setXAttractor(int x) { _xAttr = x; } - - int yAttractor() const { return _yAttr; } - void setYAttractor(int y) { _yAttr = y; } - - int acceleration() const { return int(_accel * 1000000); } - void setAcceleration(int accel) { _accel = qreal(accel)/1000000.0; } - - virtual void advance(QmlGraphicsParticle &, int interval); - -private: - int _xAttr; - int _yAttr; - qreal _accel; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionWander : public QmlGraphicsParticleMotion -{ - Q_OBJECT -public: - QmlGraphicsParticleMotionWander() - : QmlGraphicsParticleMotion(), particles(0), _xvariance(0), _yvariance(0) {} - - virtual void advance(QmlGraphicsParticle &, int interval); - virtual void created(QmlGraphicsParticle &); - virtual void destroy(QmlGraphicsParticle &); - - struct Data { - qreal x_targetV; - qreal y_targetV; - qreal x_peak; - qreal y_peak; - qreal x_var; - qreal y_var; - }; - - Q_PROPERTY(int xvariance READ xVariance WRITE setXVariance) - int xVariance() const { return int(_xvariance * 1000); } - void setXVariance(int var) { _xvariance = var / 1000.0; } - - Q_PROPERTY(int yvariance READ yVariance WRITE setYVariance) - int yVariance() const { return int(_yvariance * 1000); } - void setYVariance(int var) { _yvariance = var / 1000.0; } - - Q_PROPERTY(int pace READ pace WRITE setPace) - int pace() const { return int(_pace * 1000); } - void setPace(int pace) { _pace = pace / 1000.0; } - -private: - QmlGraphicsParticles *particles; - qreal _xvariance; - qreal _yvariance; - qreal _pace; -}; - -class QmlGraphicsParticlesPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsParticles : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QUrl source READ source WRITE setSource) - Q_PROPERTY(int count READ count WRITE setCount) - Q_PROPERTY(int lifeSpan READ lifeSpan WRITE setLifeSpan) - Q_PROPERTY(int lifeSpanDeviation READ lifeSpanDeviation WRITE setLifeSpanDeviation) - Q_PROPERTY(int fadeInDuration READ fadeInDuration WRITE setFadeInDuration) - Q_PROPERTY(int fadeOutDuration READ fadeOutDuration WRITE setFadeOutDuration) - Q_PROPERTY(qreal angle READ angle WRITE setAngle) - Q_PROPERTY(qreal angleDeviation READ angleDeviation WRITE setAngleDeviation) - Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) - Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation) - Q_PROPERTY(bool streamIn READ streamIn WRITE setStreamIn) - Q_PROPERTY(bool emitting READ emitting WRITE setEmitting) - Q_PROPERTY(QmlGraphicsParticleMotion *motion READ motion WRITE setMotion) - Q_CLASSINFO("DefaultProperty", "motion") - -public: - QmlGraphicsParticles(QmlGraphicsItem *parent=0); - ~QmlGraphicsParticles(); - - QUrl source() const; - void setSource(const QUrl &); - - int count() const; - void setCount(int cnt); - - int lifeSpan() const; - void setLifeSpan(int); - - int lifeSpanDeviation() const; - void setLifeSpanDeviation(int); - - int fadeInDuration() const; - void setFadeInDuration(int); - - int fadeOutDuration() const; - void setFadeOutDuration(int); - - qreal angle() const; - void setAngle(qreal); - - qreal angleDeviation() const; - void setAngleDeviation(qreal); - - qreal velocity() const; - void setVelocity(qreal); - - qreal velocityDeviation() const; - void setVelocityDeviation(qreal); - - bool streamIn() const; - void setStreamIn(bool); - - bool emitting() const; - void setEmitting(bool); - - QmlGraphicsParticleMotion *motion() const; - void setMotion(QmlGraphicsParticleMotion *); - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -protected: - virtual void componentComplete(); - QmlGraphicsParticles(QmlGraphicsParticlesPrivate &dd, QmlGraphicsItem *parent); - -private Q_SLOTS: - void imageLoaded(); - -private: - Q_DISABLE_COPY(QmlGraphicsParticles) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsParticles) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsParticleMotion) -QML_DECLARE_TYPE(QmlGraphicsParticleMotionLinear) -QML_DECLARE_TYPE(QmlGraphicsParticleMotionGravity) -QML_DECLARE_TYPE(QmlGraphicsParticleMotionWander) -QML_DECLARE_TYPE(QmlGraphicsParticles) - -QT_END_HEADER - -#endif diff --git a/src/declarative/extra/qmlgraphicsparticles_p.h b/src/declarative/extra/qmlgraphicsparticles_p.h new file mode 100644 index 0000000..eed0d62 --- /dev/null +++ b/src/declarative/extra/qmlgraphicsparticles_p.h @@ -0,0 +1,230 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSPARTICLES_H +#define QMLGRAPHICSPARTICLES_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsParticle; +class QmlGraphicsParticles; +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotion : public QObject +{ + Q_OBJECT +public: + QmlGraphicsParticleMotion(QObject *parent=0); + + virtual void advance(QmlGraphicsParticle &, int interval); + virtual void created(QmlGraphicsParticle &); + virtual void destroy(QmlGraphicsParticle &); +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionLinear : public QmlGraphicsParticleMotion +{ + Q_OBJECT +public: + QmlGraphicsParticleMotionLinear(QObject *parent=0) + : QmlGraphicsParticleMotion(parent) {} + + virtual void advance(QmlGraphicsParticle &, int interval); +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionGravity : public QmlGraphicsParticleMotion +{ + Q_OBJECT + + Q_PROPERTY(int xattractor READ xAttractor WRITE setXAttractor) + Q_PROPERTY(int yattractor READ yAttractor WRITE setYAttractor) + Q_PROPERTY(int acceleration READ acceleration WRITE setAcceleration) +public: + QmlGraphicsParticleMotionGravity(QObject *parent=0) + : QmlGraphicsParticleMotion(parent), _xAttr(0), _yAttr(0), _accel(0.00005) {} + + int xAttractor() const { return _xAttr; } + void setXAttractor(int x) { _xAttr = x; } + + int yAttractor() const { return _yAttr; } + void setYAttractor(int y) { _yAttr = y; } + + int acceleration() const { return int(_accel * 1000000); } + void setAcceleration(int accel) { _accel = qreal(accel)/1000000.0; } + + virtual void advance(QmlGraphicsParticle &, int interval); + +private: + int _xAttr; + int _yAttr; + qreal _accel; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsParticleMotionWander : public QmlGraphicsParticleMotion +{ + Q_OBJECT +public: + QmlGraphicsParticleMotionWander() + : QmlGraphicsParticleMotion(), particles(0), _xvariance(0), _yvariance(0) {} + + virtual void advance(QmlGraphicsParticle &, int interval); + virtual void created(QmlGraphicsParticle &); + virtual void destroy(QmlGraphicsParticle &); + + struct Data { + qreal x_targetV; + qreal y_targetV; + qreal x_peak; + qreal y_peak; + qreal x_var; + qreal y_var; + }; + + Q_PROPERTY(int xvariance READ xVariance WRITE setXVariance) + int xVariance() const { return int(_xvariance * 1000); } + void setXVariance(int var) { _xvariance = var / 1000.0; } + + Q_PROPERTY(int yvariance READ yVariance WRITE setYVariance) + int yVariance() const { return int(_yvariance * 1000); } + void setYVariance(int var) { _yvariance = var / 1000.0; } + + Q_PROPERTY(int pace READ pace WRITE setPace) + int pace() const { return int(_pace * 1000); } + void setPace(int pace) { _pace = pace / 1000.0; } + +private: + QmlGraphicsParticles *particles; + qreal _xvariance; + qreal _yvariance; + qreal _pace; +}; + +class QmlGraphicsParticlesPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsParticles : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(QUrl source READ source WRITE setSource) + Q_PROPERTY(int count READ count WRITE setCount) + Q_PROPERTY(int lifeSpan READ lifeSpan WRITE setLifeSpan) + Q_PROPERTY(int lifeSpanDeviation READ lifeSpanDeviation WRITE setLifeSpanDeviation) + Q_PROPERTY(int fadeInDuration READ fadeInDuration WRITE setFadeInDuration) + Q_PROPERTY(int fadeOutDuration READ fadeOutDuration WRITE setFadeOutDuration) + Q_PROPERTY(qreal angle READ angle WRITE setAngle) + Q_PROPERTY(qreal angleDeviation READ angleDeviation WRITE setAngleDeviation) + Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) + Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation) + Q_PROPERTY(bool streamIn READ streamIn WRITE setStreamIn) + Q_PROPERTY(bool emitting READ emitting WRITE setEmitting) + Q_PROPERTY(QmlGraphicsParticleMotion *motion READ motion WRITE setMotion) + Q_CLASSINFO("DefaultProperty", "motion") + +public: + QmlGraphicsParticles(QmlGraphicsItem *parent=0); + ~QmlGraphicsParticles(); + + QUrl source() const; + void setSource(const QUrl &); + + int count() const; + void setCount(int cnt); + + int lifeSpan() const; + void setLifeSpan(int); + + int lifeSpanDeviation() const; + void setLifeSpanDeviation(int); + + int fadeInDuration() const; + void setFadeInDuration(int); + + int fadeOutDuration() const; + void setFadeOutDuration(int); + + qreal angle() const; + void setAngle(qreal); + + qreal angleDeviation() const; + void setAngleDeviation(qreal); + + qreal velocity() const; + void setVelocity(qreal); + + qreal velocityDeviation() const; + void setVelocityDeviation(qreal); + + bool streamIn() const; + void setStreamIn(bool); + + bool emitting() const; + void setEmitting(bool); + + QmlGraphicsParticleMotion *motion() const; + void setMotion(QmlGraphicsParticleMotion *); + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +protected: + virtual void componentComplete(); + QmlGraphicsParticles(QmlGraphicsParticlesPrivate &dd, QmlGraphicsItem *parent); + +private Q_SLOTS: + void imageLoaded(); + +private: + Q_DISABLE_COPY(QmlGraphicsParticles) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsParticles) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsParticleMotion) +QML_DECLARE_TYPE(QmlGraphicsParticleMotionLinear) +QML_DECLARE_TYPE(QmlGraphicsParticleMotionGravity) +QML_DECLARE_TYPE(QmlGraphicsParticleMotionWander) +QML_DECLARE_TYPE(QmlGraphicsParticles) + +QT_END_HEADER + +#endif diff --git a/src/declarative/extra/qmlnumberformatter.cpp b/src/declarative/extra/qmlnumberformatter.cpp index 5b76e45..8b477bb 100644 --- a/src/declarative/extra/qmlnumberformatter.cpp +++ b/src/declarative/extra/qmlnumberformatter.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlnumberformatter.h" +#include "qmlnumberformatter_p.h" #include "private/qobject_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/extra/qmlnumberformatter.h b/src/declarative/extra/qmlnumberformatter.h deleted file mode 100644 index d9abee7..0000000 --- a/src/declarative/extra/qmlnumberformatter.h +++ /dev/null @@ -1,92 +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 QMLNUMBERFORMATTER_H -#define QMLNUMBERFORMATTER_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlNumberFormatterPrivate; -class Q_DECLARATIVE_EXPORT QmlNumberFormatter : public QObject, public QmlParserStatus -{ - Q_OBJECT - Q_INTERFACES(QmlParserStatus) - - Q_PROPERTY(QString text READ text NOTIFY textChanged) - Q_PROPERTY(QString format READ format WRITE setFormat) - Q_PROPERTY(qreal number READ number WRITE setNumber) -public: - QmlNumberFormatter(QObject *parent=0); - ~QmlNumberFormatter(); - - QString text() const; - - qreal number() const; - void setNumber(const qreal &); - - QString format() const; - void setFormat(const QString &); - - virtual void classBegin(); - virtual void componentComplete(); - -Q_SIGNALS: - void textChanged(); - -private: - Q_DISABLE_COPY(QmlNumberFormatter) - Q_DECLARE_PRIVATE(QmlNumberFormatter) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlNumberFormatter) - -QT_END_HEADER - -#endif diff --git a/src/declarative/extra/qmlnumberformatter_p.h b/src/declarative/extra/qmlnumberformatter_p.h new file mode 100644 index 0000000..515f71a --- /dev/null +++ b/src/declarative/extra/qmlnumberformatter_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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 QMLNUMBERFORMATTER_H +#define QMLNUMBERFORMATTER_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlNumberFormatterPrivate; +class Q_DECLARATIVE_EXPORT QmlNumberFormatter : public QObject, public QmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QmlParserStatus) + + Q_PROPERTY(QString text READ text NOTIFY textChanged) + Q_PROPERTY(QString format READ format WRITE setFormat) + Q_PROPERTY(qreal number READ number WRITE setNumber) +public: + QmlNumberFormatter(QObject *parent=0); + ~QmlNumberFormatter(); + + QString text() const; + + qreal number() const; + void setNumber(const qreal &); + + QString format() const; + void setFormat(const QString &); + + virtual void classBegin(); + virtual void componentComplete(); + +Q_SIGNALS: + void textChanged(); + +private: + Q_DISABLE_COPY(QmlNumberFormatter) + Q_DECLARE_PRIVATE(QmlNumberFormatter) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlNumberFormatter) + +QT_END_HEADER + +#endif diff --git a/src/declarative/extra/qmlxmllistmodel.cpp b/src/declarative/extra/qmlxmllistmodel.cpp index a3c96fd..98d836b 100644 --- a/src/declarative/extra/qmlxmllistmodel.cpp +++ b/src/declarative/extra/qmlxmllistmodel.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlxmllistmodel.h" +#include "qmlxmllistmodel_p.h" #include "private/qobject_p.h" #include diff --git a/src/declarative/extra/qmlxmllistmodel.h b/src/declarative/extra/qmlxmllistmodel.h deleted file mode 100644 index 1bcc008..0000000 --- a/src/declarative/extra/qmlxmllistmodel.h +++ /dev/null @@ -1,134 +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 QMLXMLLISTMODEL_H -#define QMLXMLLISTMODEL_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlContext; - -class QmlXmlListModelRole; - -class QmlXmlListModelPrivate; -class Q_DECLARATIVE_EXPORT QmlXmlListModel : public QListModelInterface, public QmlParserStatus -{ - Q_OBJECT - Q_INTERFACES(QmlParserStatus) - Q_ENUMS(Status) - - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource) - Q_PROPERTY(QString xml READ xml WRITE setXml) - Q_PROPERTY(QString query READ query WRITE setQuery) - Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations) - Q_PROPERTY(QmlList *roles READ roleObjects) - Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_CLASSINFO("DefaultProperty", "roles") - -public: - QmlXmlListModel(QObject *parent = 0); - ~QmlXmlListModel(); - - virtual QHash data(int index, const QList &roles = (QList())) const; - virtual int count() const; - virtual QList roles() const; - virtual QString toString(int role) const; - - QmlList *roleObjects(); - - QUrl source() const; - void setSource(const QUrl&); - - QString xml() const; - void setXml(const QString&); - - QString query() const; - void setQuery(const QString&); - - QString namespaceDeclarations() const; - void setNamespaceDeclarations(const QString&); - - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - - virtual void classBegin(); - virtual void componentComplete(); - -signals: - void statusChanged(Status); - void progressChanged(qreal progress); - void countChanged(); - -public Q_SLOTS: - // ### need to use/expose Expiry to guess when to call this? - // ### property to auto-call this on reasonable Expiry? - // ### LastModified/Age also useful to guess. - // ### Probably also applies to other network-requesting types. - void reload(); - -private Q_SLOTS: - void requestFinished(); - void requestProgress(qint64,qint64); - void queryCompleted(int,int); - -private: - Q_DECLARE_PRIVATE(QmlXmlListModel) - Q_DISABLE_COPY(QmlXmlListModel) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlXmlListModel) - -QT_END_HEADER - -#endif // QMLXMLLISTMODEL_H diff --git a/src/declarative/extra/qmlxmllistmodel_p.h b/src/declarative/extra/qmlxmllistmodel_p.h new file mode 100644 index 0000000..1bcc008 --- /dev/null +++ b/src/declarative/extra/qmlxmllistmodel_p.h @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** 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 QMLXMLLISTMODEL_H +#define QMLXMLLISTMODEL_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlContext; + +class QmlXmlListModelRole; + +class QmlXmlListModelPrivate; +class Q_DECLARATIVE_EXPORT QmlXmlListModel : public QListModelInterface, public QmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QmlParserStatus) + Q_ENUMS(Status) + + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) + Q_PROPERTY(QUrl source READ source WRITE setSource) + Q_PROPERTY(QString xml READ xml WRITE setXml) + Q_PROPERTY(QString query READ query WRITE setQuery) + Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations) + Q_PROPERTY(QmlList *roles READ roleObjects) + Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_CLASSINFO("DefaultProperty", "roles") + +public: + QmlXmlListModel(QObject *parent = 0); + ~QmlXmlListModel(); + + virtual QHash data(int index, const QList &roles = (QList())) const; + virtual int count() const; + virtual QList roles() const; + virtual QString toString(int role) const; + + QmlList *roleObjects(); + + QUrl source() const; + void setSource(const QUrl&); + + QString xml() const; + void setXml(const QString&); + + QString query() const; + void setQuery(const QString&); + + QString namespaceDeclarations() const; + void setNamespaceDeclarations(const QString&); + + enum Status { Null, Ready, Loading, Error }; + Status status() const; + qreal progress() const; + + virtual void classBegin(); + virtual void componentComplete(); + +signals: + void statusChanged(Status); + void progressChanged(qreal progress); + void countChanged(); + +public Q_SLOTS: + // ### need to use/expose Expiry to guess when to call this? + // ### property to auto-call this on reasonable Expiry? + // ### LastModified/Age also useful to guess. + // ### Probably also applies to other network-requesting types. + void reload(); + +private Q_SLOTS: + void requestFinished(); + void requestProgress(qint64,qint64); + void queryCompleted(int,int); + +private: + Q_DECLARE_PRIVATE(QmlXmlListModel) + Q_DISABLE_COPY(QmlXmlListModel) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlXmlListModel) + +QT_END_HEADER + +#endif // QMLXMLLISTMODEL_H diff --git a/src/declarative/extra/qnumberformat.cpp b/src/declarative/extra/qnumberformat.cpp index cde2fb0..7e28491 100644 --- a/src/declarative/extra/qnumberformat.cpp +++ b/src/declarative/extra/qnumberformat.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qnumberformat.h" +#include "qnumberformat_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/extra/qnumberformat.h b/src/declarative/extra/qnumberformat.h deleted file mode 100644 index 830cf79..0000000 --- a/src/declarative/extra/qnumberformat.h +++ /dev/null @@ -1,173 +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 NUMBERFORMAT_H -#define NUMBERFORMAT_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -// TODO -// be able to set Locale, instead of default system for dynamic formatting -// add currency support -// add additional syntax, extend to format scientific, percentiles, significant digits etc - - -class QNumberFormat : public QObject -{ - Q_OBJECT - Q_ENUMS(NumberType) -public: - QNumberFormat(QObject *parent=0); - ~QNumberFormat(); - - enum NumberType { - Percent, - Scientific, - Currency, - Decimal - }; - - //external property, only visible - Q_PROPERTY(QString text READ text NOTIFY textChanged) - - //mutatable properties to modify the output (text) - Q_PROPERTY(qreal number READ number WRITE setNumber) - Q_PROPERTY(QString format READ format WRITE setFormat) - Q_PROPERTY(QLocale locale READ locale WRITE setLocale) - - //Format specific settings - Q_PROPERTY(unsigned short groupingSeparator READ groupingSeparator WRITE setGroupingSeparator) - Q_PROPERTY(unsigned short decimalSeperator READ decimalSeparator WRITE setDecimalSeparator) - Q_PROPERTY(unsigned int groupingSize READ groupingSize WRITE setGroupingSize) - Q_PROPERTY(unsigned short currencySymbol READ currencySymbol WRITE setCurrencySymbol) - - - QString text() const { return _text; } - - qreal number() const { return _number; } - void setNumber(qreal n) { - if (_number == n) - return; - _number = n; - updateText(); - } - - QString format() const { return _format; } - void setFormat(const QString &format) { - if (format.isEmpty()) - _format = QString::null; - else if (_format == format) - return; - - _format = format; - updateText(); - } - - QLocale locale() const { return _locale; } - void setLocale(const QLocale &locale) { _locale = locale; updateText(); } - - //Do we deal with unicode standard? or create our own - // ### since this is the backend for the number conversions, we will use the unicode - // the front-end will handle the QChar/QString -> short int - - unsigned short groupingSeparator() { return _groupingSeparator.unicode(); } - void setGroupingSeparator(unsigned short unicodeSymbol) - { - _groupingSeparator = QChar(unicodeSymbol); - } - - unsigned short decimalSeparator() { return _decimalSeparator.unicode(); } - void setDecimalSeparator(unsigned short unicodeSymbol) - { - _decimalSeparator = QChar(unicodeSymbol); - } - - unsigned short currencySymbol() { return _currencySymbol.unicode(); } - void setCurrencySymbol(unsigned short unicodeSymbol) - { - _currencySymbol = QChar(unicodeSymbol); - } - - unsigned int groupingSize() { return _groupingSize; } - void setGroupingSize(unsigned int size) - { - _groupingSize = size; - } - -Q_SIGNALS: - void textChanged(); - -private: - void updateText(); - void handleFormat(); - QString formatInteger(const QString &formatInt, const QString &integer); - QString formatDecimal(const QString &formatDec, const QString &decimal); - - qreal _number; - NumberType _type; - QChar _groupingSeparator; - QChar _decimalSeparator; - QChar _currencySymbol; - unsigned int _groupingSize; - - QLocale _locale; - QString _format; - - // only hooked member at the moment - QString _text; - -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QNumberFormat) - -QT_END_HEADER - -#endif diff --git a/src/declarative/extra/qnumberformat_p.h b/src/declarative/extra/qnumberformat_p.h new file mode 100644 index 0000000..830cf79 --- /dev/null +++ b/src/declarative/extra/qnumberformat_p.h @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** 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 NUMBERFORMAT_H +#define NUMBERFORMAT_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +// TODO +// be able to set Locale, instead of default system for dynamic formatting +// add currency support +// add additional syntax, extend to format scientific, percentiles, significant digits etc + + +class QNumberFormat : public QObject +{ + Q_OBJECT + Q_ENUMS(NumberType) +public: + QNumberFormat(QObject *parent=0); + ~QNumberFormat(); + + enum NumberType { + Percent, + Scientific, + Currency, + Decimal + }; + + //external property, only visible + Q_PROPERTY(QString text READ text NOTIFY textChanged) + + //mutatable properties to modify the output (text) + Q_PROPERTY(qreal number READ number WRITE setNumber) + Q_PROPERTY(QString format READ format WRITE setFormat) + Q_PROPERTY(QLocale locale READ locale WRITE setLocale) + + //Format specific settings + Q_PROPERTY(unsigned short groupingSeparator READ groupingSeparator WRITE setGroupingSeparator) + Q_PROPERTY(unsigned short decimalSeperator READ decimalSeparator WRITE setDecimalSeparator) + Q_PROPERTY(unsigned int groupingSize READ groupingSize WRITE setGroupingSize) + Q_PROPERTY(unsigned short currencySymbol READ currencySymbol WRITE setCurrencySymbol) + + + QString text() const { return _text; } + + qreal number() const { return _number; } + void setNumber(qreal n) { + if (_number == n) + return; + _number = n; + updateText(); + } + + QString format() const { return _format; } + void setFormat(const QString &format) { + if (format.isEmpty()) + _format = QString::null; + else if (_format == format) + return; + + _format = format; + updateText(); + } + + QLocale locale() const { return _locale; } + void setLocale(const QLocale &locale) { _locale = locale; updateText(); } + + //Do we deal with unicode standard? or create our own + // ### since this is the backend for the number conversions, we will use the unicode + // the front-end will handle the QChar/QString -> short int + + unsigned short groupingSeparator() { return _groupingSeparator.unicode(); } + void setGroupingSeparator(unsigned short unicodeSymbol) + { + _groupingSeparator = QChar(unicodeSymbol); + } + + unsigned short decimalSeparator() { return _decimalSeparator.unicode(); } + void setDecimalSeparator(unsigned short unicodeSymbol) + { + _decimalSeparator = QChar(unicodeSymbol); + } + + unsigned short currencySymbol() { return _currencySymbol.unicode(); } + void setCurrencySymbol(unsigned short unicodeSymbol) + { + _currencySymbol = QChar(unicodeSymbol); + } + + unsigned int groupingSize() { return _groupingSize; } + void setGroupingSize(unsigned int size) + { + _groupingSize = size; + } + +Q_SIGNALS: + void textChanged(); + +private: + void updateText(); + void handleFormat(); + QString formatInteger(const QString &formatInt, const QString &integer); + QString formatDecimal(const QString &formatDec, const QString &decimal); + + qreal _number; + NumberType _type; + QChar _groupingSeparator; + QChar _decimalSeparator; + QChar _currencySymbol; + unsigned int _groupingSize; + + QLocale _locale; + QString _format; + + // only hooked member at the moment + QString _text; + +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QNumberFormat) + +QT_END_HEADER + +#endif diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index 7759ab1..20e1503 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -1,49 +1,49 @@ HEADERS += \ - fx/qmlgraphicsanchors.h \ fx/qmlgraphicsanchors_p.h \ - fx/qmlgraphicsevents_p.h \ - fx/qmlgraphicsflickable.h \ + fx/qmlgraphicsanchors_p_p.h \ + fx/qmlgraphicsevents_p_p.h \ fx/qmlgraphicsflickable_p.h \ - fx/qmlgraphicsflipable.h \ - fx/qmlgraphicsgridview.h \ - fx/qmlgraphicsimage.h \ - fx/qmlgraphicsimagebase.h \ - fx/qmlgraphicsborderimage.h \ - fx/qmlgraphicspainteditem.h \ - fx/qmlgraphicspainteditem_p.h \ + fx/qmlgraphicsflickable_p_p.h \ + fx/qmlgraphicsflipable_p.h \ + fx/qmlgraphicsgridview_p.h \ fx/qmlgraphicsimage_p.h \ - fx/qmlgraphicsborderimage_p.h \ fx/qmlgraphicsimagebase_p.h \ + fx/qmlgraphicsborderimage_p.h \ + fx/qmlgraphicspainteditem_p.h \ + fx/qmlgraphicspainteditem_p_p.h \ + fx/qmlgraphicsimage_p_p.h \ + fx/qmlgraphicsborderimage_p_p.h \ + fx/qmlgraphicsimagebase_p_p.h \ fx/qmlgraphicsitem.h \ fx/qmlgraphicsitem_p.h \ - fx/qmlgraphicsfocuspanel.h \ - fx/qmlgraphicsfocusscope.h \ - fx/qmlgraphicspositioners.h \ + fx/qmlgraphicsfocuspanel_p.h \ + fx/qmlgraphicsfocusscope_p.h \ fx/qmlgraphicspositioners_p.h \ - fx/qmlgraphicsloader.h \ + fx/qmlgraphicspositioners_p_p.h \ fx/qmlgraphicsloader_p.h \ - fx/qmlgraphicsmouseregion.h \ + fx/qmlgraphicsloader_p_p.h \ fx/qmlgraphicsmouseregion_p.h \ - fx/qmlgraphicspath.h \ + fx/qmlgraphicsmouseregion_p_p.h \ fx/qmlgraphicspath_p.h \ - fx/qmlgraphicspathview.h \ + fx/qmlgraphicspath_p_p.h \ fx/qmlgraphicspathview_p.h \ - fx/qmlgraphicsrect.h \ + fx/qmlgraphicspathview_p_p.h \ fx/qmlgraphicsrect_p.h \ - fx/qmlgraphicsrepeater.h \ + fx/qmlgraphicsrect_p_p.h \ fx/qmlgraphicsrepeater_p.h \ - fx/qmlgraphicsscalegrid_p.h \ - fx/qmlgraphicstextinput.h \ + fx/qmlgraphicsrepeater_p_p.h \ + fx/qmlgraphicsscalegrid_p_p.h \ fx/qmlgraphicstextinput_p.h \ - fx/qmlgraphicstextedit.h \ + fx/qmlgraphicstextinput_p_p.h \ fx/qmlgraphicstextedit_p.h \ - fx/qmlgraphicstext.h \ + fx/qmlgraphicstextedit_p_p.h \ fx/qmlgraphicstext_p.h \ - fx/qmlgraphicspixmapcache.h \ - fx/qmlgraphicsvisualitemmodel.h \ - fx/qmlgraphicslistview.h \ - fx/qmlgraphicsgraphicsobjectcontainer.h \ - fx/qmlgraphicslayoutitem.h \ + fx/qmlgraphicstext_p_p.h \ + fx/qmlgraphicspixmapcache_p.h \ + fx/qmlgraphicsvisualitemmodel_p.h \ + fx/qmlgraphicslistview_p.h \ + fx/qmlgraphicsgraphicsobjectcontainer_p.h \ + fx/qmlgraphicslayoutitem_p.h \ fx/qmlgraphicseffects.cpp SOURCES += \ @@ -79,6 +79,6 @@ SOURCES += \ contains(QT_CONFIG, webkit) { QT+=webkit SOURCES += fx/qmlgraphicswebview.cpp - HEADERS += fx/qmlgraphicswebview.h + HEADERS += fx/qmlgraphicswebview_p.h } diff --git a/src/declarative/fx/qmlgraphicsanchors.cpp b/src/declarative/fx/qmlgraphicsanchors.cpp index d0e26d8..fc1a1c6 100644 --- a/src/declarative/fx/qmlgraphicsanchors.cpp +++ b/src/declarative/fx/qmlgraphicsanchors.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlgraphicsanchors_p.h" +#include "qmlgraphicsanchors_p_p.h" #include "qmlgraphicsitem.h" #include "qmlgraphicsitem_p.h" #include @@ -956,7 +956,7 @@ bool QmlGraphicsAnchorsPrivate::checkVAnchorValid(QmlGraphicsAnchorLine anchor) return true; } -QT_END_NAMESPACE +#include "moc_qmlgraphicsanchors_p.cpp" -#include "moc_qmlgraphicsanchors.cpp" +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsanchors.h b/src/declarative/fx/qmlgraphicsanchors.h deleted file mode 100644 index de7214d..0000000 --- a/src/declarative/fx/qmlgraphicsanchors.h +++ /dev/null @@ -1,180 +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 QMLGRAPHICSANCHORS_H -#define QMLGRAPHICSANCHORS_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsAnchorsPrivate; -class QmlGraphicsAnchorLine; -class Q_DECLARATIVE_EXPORT QmlGraphicsAnchors : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QmlGraphicsAnchorLine left READ left WRITE setLeft RESET resetLeft) - Q_PROPERTY(QmlGraphicsAnchorLine right READ right WRITE setRight RESET resetRight) - Q_PROPERTY(QmlGraphicsAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter) - Q_PROPERTY(QmlGraphicsAnchorLine top READ top WRITE setTop RESET resetTop) - Q_PROPERTY(QmlGraphicsAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom) - Q_PROPERTY(QmlGraphicsAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter) - Q_PROPERTY(QmlGraphicsAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline) - Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged) - Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) - Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged()) - Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) - Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) - Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged()) - Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged()) - Q_PROPERTY(QmlGraphicsItem *fill READ fill WRITE setFill) - Q_PROPERTY(QmlGraphicsItem *centerIn READ centerIn WRITE setCenterIn) - -public: - QmlGraphicsAnchors(QObject *parent=0); - virtual ~QmlGraphicsAnchors(); - - enum UsedAnchor { - HasLeftAnchor = 0x01, - HasRightAnchor = 0x02, - HasTopAnchor = 0x04, - HasBottomAnchor = 0x08, - HasHCenterAnchor = 0x10, - HasVCenterAnchor = 0x20, - HasBaselineAnchor = 0x40, - Horizontal_Mask = HasLeftAnchor | HasRightAnchor | HasHCenterAnchor, - Vertical_Mask = HasTopAnchor | HasBottomAnchor | HasVCenterAnchor | HasBaselineAnchor - }; - Q_DECLARE_FLAGS(UsedAnchors, UsedAnchor) - - QmlGraphicsAnchorLine left() const; - void setLeft(const QmlGraphicsAnchorLine &edge); - void resetLeft(); - - QmlGraphicsAnchorLine right() const; - void setRight(const QmlGraphicsAnchorLine &edge); - void resetRight(); - - QmlGraphicsAnchorLine horizontalCenter() const; - void setHorizontalCenter(const QmlGraphicsAnchorLine &edge); - void resetHorizontalCenter(); - - QmlGraphicsAnchorLine top() const; - void setTop(const QmlGraphicsAnchorLine &edge); - void resetTop(); - - QmlGraphicsAnchorLine bottom() const; - void setBottom(const QmlGraphicsAnchorLine &edge); - void resetBottom(); - - QmlGraphicsAnchorLine verticalCenter() const; - void setVerticalCenter(const QmlGraphicsAnchorLine &edge); - void resetVerticalCenter(); - - QmlGraphicsAnchorLine baseline() const; - void setBaseline(const QmlGraphicsAnchorLine &edge); - void resetBaseline(); - - qreal leftMargin() const; - void setLeftMargin(qreal); - - qreal rightMargin() const; - void setRightMargin(qreal); - - qreal horizontalCenterOffset() const; - void setHorizontalCenterOffset(qreal); - - qreal topMargin() const; - void setTopMargin(qreal); - - qreal bottomMargin() const; - void setBottomMargin(qreal); - - qreal verticalCenterOffset() const; - void setVerticalCenterOffset(qreal); - - qreal baselineOffset() const; - void setBaselineOffset(qreal); - - QmlGraphicsItem *fill() const; - void setFill(QmlGraphicsItem *); - - QmlGraphicsItem *centerIn() const; - void setCenterIn(QmlGraphicsItem *); - - UsedAnchors usedAnchors() const; - - void setItem(QmlGraphicsItem *item); - - void classBegin(); - void componentComplete(); - -Q_SIGNALS: - void leftMarginChanged(); - void rightMarginChanged(); - void topMarginChanged(); - void bottomMarginChanged(); - void verticalCenterOffsetChanged(); - void horizontalCenterOffsetChanged(); - void baselineOffsetChanged(); - -private: - friend class QmlGraphicsItem; - Q_DISABLE_COPY(QmlGraphicsAnchors) - Q_DECLARE_PRIVATE(QmlGraphicsAnchors) -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(QmlGraphicsAnchors::UsedAnchors) - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsAnchors) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qmlgraphicsanchors_p.h b/src/declarative/fx/qmlgraphicsanchors_p.h index 3986cd6..de7214d 100644 --- a/src/declarative/fx/qmlgraphicsanchors_p.h +++ b/src/declarative/fx/qmlgraphicsanchors_p.h @@ -39,122 +39,142 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSANCHORS_P_H -#define QMLGRAPHICSANCHORS_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 "qmlgraphicsanchors.h" -#include "private/qobject_p.h" +#ifndef QMLGRAPHICSANCHORS_H +#define QMLGRAPHICSANCHORS_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QmlGraphicsAnchorLine +QT_MODULE(Declarative) + +class QmlGraphicsAnchorsPrivate; +class QmlGraphicsAnchorLine; +class Q_DECLARATIVE_EXPORT QmlGraphicsAnchors : public QObject { + Q_OBJECT + + Q_PROPERTY(QmlGraphicsAnchorLine left READ left WRITE setLeft RESET resetLeft) + Q_PROPERTY(QmlGraphicsAnchorLine right READ right WRITE setRight RESET resetRight) + Q_PROPERTY(QmlGraphicsAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter) + Q_PROPERTY(QmlGraphicsAnchorLine top READ top WRITE setTop RESET resetTop) + Q_PROPERTY(QmlGraphicsAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom) + Q_PROPERTY(QmlGraphicsAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter) + Q_PROPERTY(QmlGraphicsAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline) + Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged) + Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) + Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged()) + Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) + Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) + Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged()) + Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged()) + Q_PROPERTY(QmlGraphicsItem *fill READ fill WRITE setFill) + Q_PROPERTY(QmlGraphicsItem *centerIn READ centerIn WRITE setCenterIn) + public: - QmlGraphicsAnchorLine() : item(0), anchorLine(Invalid) - { - } - - enum AnchorLine { - Invalid = 0x0, - Left = 0x01, - Right = 0x02, - Top = 0x04, - Bottom = 0x08, - HCenter = 0x10, - VCenter = 0x20, - Baseline = 0x40, - Horizontal_Mask = Left | Right | HCenter, - Vertical_Mask = Top | Bottom | VCenter | Baseline + QmlGraphicsAnchors(QObject *parent=0); + virtual ~QmlGraphicsAnchors(); + + enum UsedAnchor { + HasLeftAnchor = 0x01, + HasRightAnchor = 0x02, + HasTopAnchor = 0x04, + HasBottomAnchor = 0x08, + HasHCenterAnchor = 0x10, + HasVCenterAnchor = 0x20, + HasBaselineAnchor = 0x40, + Horizontal_Mask = HasLeftAnchor | HasRightAnchor | HasHCenterAnchor, + Vertical_Mask = HasTopAnchor | HasBottomAnchor | HasVCenterAnchor | HasBaselineAnchor }; + Q_DECLARE_FLAGS(UsedAnchors, UsedAnchor) - QmlGraphicsItem *item; - AnchorLine anchorLine; -}; -Q_DECLARE_METATYPE(QmlGraphicsAnchorLine) + QmlGraphicsAnchorLine left() const; + void setLeft(const QmlGraphicsAnchorLine &edge); + void resetLeft(); -class QmlGraphicsAnchorsPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlGraphicsAnchors) -public: - QmlGraphicsAnchorsPrivate() - : updatingMe(false), updatingHorizontalAnchor(0), - updatingVerticalAnchor(0), item(0), usedAnchors(0), fill(0), - centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), - bottomMargin(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0), - componentComplete(true) - { - } - - void init() - { - } - - void clearItem(QmlGraphicsItem *); - - void addDepend(QmlGraphicsItem *); - void remDepend(QmlGraphicsItem *); - bool isItemComplete() const; - - bool updatingMe; - int updatingHorizontalAnchor; - int updatingVerticalAnchor; - - void setItemHeight(qreal); - void setItemWidth(qreal); - void setItemX(qreal); - void setItemY(qreal); - void setItemPos(const QPointF &); - - void updateOnComplete(); - void updateMe(); - void update(QmlGraphicsItem *, const QRectF &, const QRectF &); - - bool checkHValid() const; - bool checkVValid() const; - bool checkHAnchorValid(QmlGraphicsAnchorLine anchor) const; - bool checkVAnchorValid(QmlGraphicsAnchorLine anchor) const; - bool calcStretch(const QmlGraphicsAnchorLine &edge1, const QmlGraphicsAnchorLine &edge2, int offset1, int offset2, QmlGraphicsAnchorLine::AnchorLine line, int &stretch); - - void updateHorizontalAnchors(); - void updateVerticalAnchors(); - void fillChanged(); - void centerInChanged(); - - QmlGraphicsItem *item; - QmlGraphicsAnchors::UsedAnchors usedAnchors; - - QmlGraphicsItem *fill; - QmlGraphicsItem *centerIn; - - QmlGraphicsAnchorLine left; - QmlGraphicsAnchorLine right; - QmlGraphicsAnchorLine top; - QmlGraphicsAnchorLine bottom; - QmlGraphicsAnchorLine vCenter; - QmlGraphicsAnchorLine hCenter; - QmlGraphicsAnchorLine baseline; - - qreal leftMargin; - qreal rightMargin; - qreal topMargin; - qreal bottomMargin; - qreal vCenterOffset; - qreal hCenterOffset; - qreal baselineOffset; - - bool componentComplete; + QmlGraphicsAnchorLine right() const; + void setRight(const QmlGraphicsAnchorLine &edge); + void resetRight(); + + QmlGraphicsAnchorLine horizontalCenter() const; + void setHorizontalCenter(const QmlGraphicsAnchorLine &edge); + void resetHorizontalCenter(); + + QmlGraphicsAnchorLine top() const; + void setTop(const QmlGraphicsAnchorLine &edge); + void resetTop(); + + QmlGraphicsAnchorLine bottom() const; + void setBottom(const QmlGraphicsAnchorLine &edge); + void resetBottom(); + + QmlGraphicsAnchorLine verticalCenter() const; + void setVerticalCenter(const QmlGraphicsAnchorLine &edge); + void resetVerticalCenter(); + + QmlGraphicsAnchorLine baseline() const; + void setBaseline(const QmlGraphicsAnchorLine &edge); + void resetBaseline(); + + qreal leftMargin() const; + void setLeftMargin(qreal); + + qreal rightMargin() const; + void setRightMargin(qreal); + + qreal horizontalCenterOffset() const; + void setHorizontalCenterOffset(qreal); + + qreal topMargin() const; + void setTopMargin(qreal); + + qreal bottomMargin() const; + void setBottomMargin(qreal); + + qreal verticalCenterOffset() const; + void setVerticalCenterOffset(qreal); + + qreal baselineOffset() const; + void setBaselineOffset(qreal); + + QmlGraphicsItem *fill() const; + void setFill(QmlGraphicsItem *); + + QmlGraphicsItem *centerIn() const; + void setCenterIn(QmlGraphicsItem *); + + UsedAnchors usedAnchors() const; + + void setItem(QmlGraphicsItem *item); + + void classBegin(); + void componentComplete(); + +Q_SIGNALS: + void leftMarginChanged(); + void rightMarginChanged(); + void topMarginChanged(); + void bottomMarginChanged(); + void verticalCenterOffsetChanged(); + void horizontalCenterOffsetChanged(); + void baselineOffsetChanged(); + +private: + friend class QmlGraphicsItem; + Q_DISABLE_COPY(QmlGraphicsAnchors) + Q_DECLARE_PRIVATE(QmlGraphicsAnchors) }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QmlGraphicsAnchors::UsedAnchors) QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsAnchors) + +QT_END_HEADER + #endif diff --git a/src/declarative/fx/qmlgraphicsanchors_p_p.h b/src/declarative/fx/qmlgraphicsanchors_p_p.h new file mode 100644 index 0000000..7a3a9d2 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsanchors_p_p.h @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSANCHORS_P_H +#define QMLGRAPHICSANCHORS_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 "qmlgraphicsanchors_p.h" +#include "private/qobject_p.h" + +QT_BEGIN_NAMESPACE + +class QmlGraphicsAnchorLine +{ +public: + QmlGraphicsAnchorLine() : item(0), anchorLine(Invalid) + { + } + + enum AnchorLine { + Invalid = 0x0, + Left = 0x01, + Right = 0x02, + Top = 0x04, + Bottom = 0x08, + HCenter = 0x10, + VCenter = 0x20, + Baseline = 0x40, + Horizontal_Mask = Left | Right | HCenter, + Vertical_Mask = Top | Bottom | VCenter | Baseline + }; + + QmlGraphicsItem *item; + AnchorLine anchorLine; +}; +Q_DECLARE_METATYPE(QmlGraphicsAnchorLine) + +class QmlGraphicsAnchorsPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsAnchors) +public: + QmlGraphicsAnchorsPrivate() + : updatingMe(false), updatingHorizontalAnchor(0), + updatingVerticalAnchor(0), item(0), usedAnchors(0), fill(0), + centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), + bottomMargin(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0), + componentComplete(true) + { + } + + void init() + { + } + + void clearItem(QmlGraphicsItem *); + + void addDepend(QmlGraphicsItem *); + void remDepend(QmlGraphicsItem *); + bool isItemComplete() const; + + bool updatingMe; + int updatingHorizontalAnchor; + int updatingVerticalAnchor; + + void setItemHeight(qreal); + void setItemWidth(qreal); + void setItemX(qreal); + void setItemY(qreal); + void setItemPos(const QPointF &); + + void updateOnComplete(); + void updateMe(); + void update(QmlGraphicsItem *, const QRectF &, const QRectF &); + + bool checkHValid() const; + bool checkVValid() const; + bool checkHAnchorValid(QmlGraphicsAnchorLine anchor) const; + bool checkVAnchorValid(QmlGraphicsAnchorLine anchor) const; + bool calcStretch(const QmlGraphicsAnchorLine &edge1, const QmlGraphicsAnchorLine &edge2, int offset1, int offset2, QmlGraphicsAnchorLine::AnchorLine line, int &stretch); + + void updateHorizontalAnchors(); + void updateVerticalAnchors(); + void fillChanged(); + void centerInChanged(); + + QmlGraphicsItem *item; + QmlGraphicsAnchors::UsedAnchors usedAnchors; + + QmlGraphicsItem *fill; + QmlGraphicsItem *centerIn; + + QmlGraphicsAnchorLine left; + QmlGraphicsAnchorLine right; + QmlGraphicsAnchorLine top; + QmlGraphicsAnchorLine bottom; + QmlGraphicsAnchorLine vCenter; + QmlGraphicsAnchorLine hCenter; + QmlGraphicsAnchorLine baseline; + + qreal leftMargin; + qreal rightMargin; + qreal topMargin; + qreal bottomMargin; + qreal vCenterOffset; + qreal hCenterOffset; + qreal baselineOffset; + + bool componentComplete; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/declarative/fx/qmlgraphicsborderimage.cpp b/src/declarative/fx/qmlgraphicsborderimage.cpp index c346366..daa8085 100644 --- a/src/declarative/fx/qmlgraphicsborderimage.cpp +++ b/src/declarative/fx/qmlgraphicsborderimage.cpp @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#include "qmlgraphicsborderimage.h" #include "qmlgraphicsborderimage_p.h" +#include "qmlgraphicsborderimage_p_p.h" #include #include #include diff --git a/src/declarative/fx/qmlgraphicsborderimage.h b/src/declarative/fx/qmlgraphicsborderimage.h deleted file mode 100644 index e3c50bb..0000000 --- a/src/declarative/fx/qmlgraphicsborderimage.h +++ /dev/null @@ -1,105 +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 QMLGRAPHICSBORDERIMAGE_H -#define QMLGRAPHICSBORDERIMAGE_H - -#include -#include "qmlgraphicsimagebase.h" - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsScaleGrid; -class QmlGraphicsGridScaledImage; -class QmlGraphicsBorderImagePrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsBorderImage : public QmlGraphicsImageBase -{ - Q_OBJECT - Q_ENUMS(TileMode) - - Q_PROPERTY(QmlGraphicsScaleGrid *border READ border CONSTANT) - Q_PROPERTY(TileMode horizontalTileMode READ horizontalTileMode WRITE setHorizontalTileMode NOTIFY horizontalTileModeChanged) - Q_PROPERTY(TileMode verticalTileMode READ verticalTileMode WRITE setVerticalTileMode NOTIFY verticalTileModeChanged) - -public: - QmlGraphicsBorderImage(QmlGraphicsItem *parent=0); - ~QmlGraphicsBorderImage(); - - QmlGraphicsScaleGrid *border(); - - enum TileMode { Stretch = Qt::StretchTile, Repeat = Qt::RepeatTile, Round = Qt::RoundTile }; - - TileMode horizontalTileMode() const; - void setHorizontalTileMode(TileMode); - - TileMode verticalTileMode() const; - void setVerticalTileMode(TileMode); - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - void setSource(const QUrl &url); - -Q_SIGNALS: - void horizontalTileModeChanged(); - void verticalTileModeChanged(); - -protected: - QmlGraphicsBorderImage(QmlGraphicsBorderImagePrivate &dd, QmlGraphicsItem *parent); - -private: - void setGridScaledImage(const QmlGraphicsGridScaledImage& sci); - -private Q_SLOTS: - void requestFinished(); - void sciRequestFinished(); - -private: - Q_DISABLE_COPY(QmlGraphicsBorderImage) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsBorderImage) -}; - -QT_END_NAMESPACE -QML_DECLARE_TYPE(QmlGraphicsBorderImage) -QT_END_HEADER - -#endif // QMLGRAPHICSBORDERIMAGE_H diff --git a/src/declarative/fx/qmlgraphicsborderimage_p.h b/src/declarative/fx/qmlgraphicsborderimage_p.h index fb905cd..da43a23 100644 --- a/src/declarative/fx/qmlgraphicsborderimage_p.h +++ b/src/declarative/fx/qmlgraphicsborderimage_p.h @@ -39,59 +39,67 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSBORDERIMAGE_P_H -#define QMLGRAPHICSBORDERIMAGE_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. -// +#ifndef QMLGRAPHICSBORDERIMAGE_H +#define QMLGRAPHICSBORDERIMAGE_H +#include #include "qmlgraphicsimagebase_p.h" -#include "qmlgraphicsscalegrid_p.h" +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QNetworkReply; -class QmlGraphicsBorderImagePrivate : public QmlGraphicsImageBasePrivate +QT_MODULE(Declarative) + +class QmlGraphicsScaleGrid; +class QmlGraphicsGridScaledImage; +class QmlGraphicsBorderImagePrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsBorderImage : public QmlGraphicsImageBase { - Q_DECLARE_PUBLIC(QmlGraphicsBorderImage) + Q_OBJECT + Q_ENUMS(TileMode) + + Q_PROPERTY(QmlGraphicsScaleGrid *border READ border CONSTANT) + Q_PROPERTY(TileMode horizontalTileMode READ horizontalTileMode WRITE setHorizontalTileMode NOTIFY horizontalTileModeChanged) + Q_PROPERTY(TileMode verticalTileMode READ verticalTileMode WRITE setVerticalTileMode NOTIFY verticalTileModeChanged) public: - QmlGraphicsBorderImagePrivate() - : border(0), sciReply(0), - sciPendingPixmapCache(false), - horizontalTileMode(QmlGraphicsBorderImage::Stretch), - verticalTileMode(QmlGraphicsBorderImage::Stretch) - { - } - - ~QmlGraphicsBorderImagePrivate() - { - } - - QmlGraphicsScaleGrid *getScaleGrid() - { - Q_Q(QmlGraphicsBorderImage); - if (!border) - border = new QmlGraphicsScaleGrid(q); - return border; - } - - QmlGraphicsScaleGrid *border; - QUrl sciurl; - QNetworkReply *sciReply; - bool sciPendingPixmapCache; - QmlGraphicsBorderImage::TileMode horizontalTileMode; - QmlGraphicsBorderImage::TileMode verticalTileMode; + QmlGraphicsBorderImage(QmlGraphicsItem *parent=0); + ~QmlGraphicsBorderImage(); + + QmlGraphicsScaleGrid *border(); + + enum TileMode { Stretch = Qt::StretchTile, Repeat = Qt::RepeatTile, Round = Qt::RoundTile }; + + TileMode horizontalTileMode() const; + void setHorizontalTileMode(TileMode); + + TileMode verticalTileMode() const; + void setVerticalTileMode(TileMode); + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + void setSource(const QUrl &url); + +Q_SIGNALS: + void horizontalTileModeChanged(); + void verticalTileModeChanged(); + +protected: + QmlGraphicsBorderImage(QmlGraphicsBorderImagePrivate &dd, QmlGraphicsItem *parent); + +private: + void setGridScaledImage(const QmlGraphicsGridScaledImage& sci); + +private Q_SLOTS: + void requestFinished(); + void sciRequestFinished(); + +private: + Q_DISABLE_COPY(QmlGraphicsBorderImage) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsBorderImage) }; QT_END_NAMESPACE +QML_DECLARE_TYPE(QmlGraphicsBorderImage) +QT_END_HEADER -#endif // QMLGRAPHICSBORDERIMAGE_P_H +#endif // QMLGRAPHICSBORDERIMAGE_H diff --git a/src/declarative/fx/qmlgraphicsborderimage_p_p.h b/src/declarative/fx/qmlgraphicsborderimage_p_p.h new file mode 100644 index 0000000..06ac38b --- /dev/null +++ b/src/declarative/fx/qmlgraphicsborderimage_p_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSBORDERIMAGE_P_H +#define QMLGRAPHICSBORDERIMAGE_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 "qmlgraphicsimagebase_p_p.h" +#include "qmlgraphicsscalegrid_p_p.h" + +QT_BEGIN_NAMESPACE + +class QNetworkReply; +class QmlGraphicsBorderImagePrivate : public QmlGraphicsImageBasePrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsBorderImage) + +public: + QmlGraphicsBorderImagePrivate() + : border(0), sciReply(0), + sciPendingPixmapCache(false), + horizontalTileMode(QmlGraphicsBorderImage::Stretch), + verticalTileMode(QmlGraphicsBorderImage::Stretch) + { + } + + ~QmlGraphicsBorderImagePrivate() + { + } + + QmlGraphicsScaleGrid *getScaleGrid() + { + Q_Q(QmlGraphicsBorderImage); + if (!border) + border = new QmlGraphicsScaleGrid(q); + return border; + } + + QmlGraphicsScaleGrid *border; + QUrl sciurl; + QNetworkReply *sciReply; + bool sciPendingPixmapCache; + QmlGraphicsBorderImage::TileMode horizontalTileMode; + QmlGraphicsBorderImage::TileMode verticalTileMode; +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSBORDERIMAGE_P_H diff --git a/src/declarative/fx/qmlgraphicsevents.cpp b/src/declarative/fx/qmlgraphicsevents.cpp index 468b223..a4d243f 100644 --- a/src/declarative/fx/qmlgraphicsevents.cpp +++ b/src/declarative/fx/qmlgraphicsevents.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlgraphicsevents_p.h" +#include "qmlgraphicsevents_p_p.h" QT_BEGIN_NAMESPACE /*! diff --git a/src/declarative/fx/qmlgraphicsevents_p.h b/src/declarative/fx/qmlgraphicsevents_p.h deleted file mode 100644 index f093932..0000000 --- a/src/declarative/fx/qmlgraphicsevents_p.h +++ /dev/null @@ -1,137 +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 QMLGRAPHICSEVENTS_P_H -#define QMLGRAPHICSEVENTS_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 -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QmlGraphicsKeyEvent : public QObject -{ - Q_OBJECT - Q_PROPERTY(int key READ key) - Q_PROPERTY(QString text READ text) - Q_PROPERTY(int modifiers READ modifiers) - Q_PROPERTY(bool isAutoRepeat READ isAutoRepeat) - Q_PROPERTY(int count READ count) - Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) - -public: - QmlGraphicsKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text=QString(), bool autorep=false, ushort count=1) - : event(type, key, modifiers, text, autorep, count) { event.setAccepted(false); } - QmlGraphicsKeyEvent(const QKeyEvent &ke) - : event(ke) { event.setAccepted(false); } - - int key() const { return event.key(); } - QString text() const { return event.text(); } - int modifiers() const { return event.modifiers(); } - bool isAutoRepeat() const { return event.isAutoRepeat(); } - int count() const { return event.count(); } - - bool isAccepted() { return event.isAccepted(); } - void setAccepted(bool accepted) { event.setAccepted(accepted); } - -private: - QKeyEvent event; -}; - -class QmlGraphicsMouseEvent : public QObject -{ - Q_OBJECT - Q_PROPERTY(int x READ x) - Q_PROPERTY(int y READ y) - Q_PROPERTY(int button READ button) - Q_PROPERTY(int buttons READ buttons) - Q_PROPERTY(int modifiers READ modifiers) - Q_PROPERTY(bool wasHeld READ wasHeld) - Q_PROPERTY(bool isClick READ isClick) - Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) - -public: - QmlGraphicsMouseEvent(int x, int y, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers - , bool isClick=false, bool wasHeld=false) - : _x(x), _y(y), _button(button), _buttons(buttons), _modifiers(modifiers) - , _wasHeld(wasHeld), _isClick(isClick), _accepted(true) {} - - int x() const { return _x; } - int y() const { return _y; } - int button() const { return _button; } - int buttons() const { return _buttons; } - int modifiers() const { return _modifiers; } - bool wasHeld() const { return _wasHeld; } - bool isClick() const { return _isClick; } - - bool isAccepted() { return _accepted; } - void setAccepted(bool accepted) { _accepted = accepted; } - -private: - int _x; - int _y; - Qt::MouseButton _button; - Qt::MouseButtons _buttons; - Qt::KeyboardModifiers _modifiers; - bool _wasHeld; - bool _isClick; - bool _accepted; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsKeyEvent) -QML_DECLARE_TYPE(QmlGraphicsMouseEvent) - -#endif // QMLGRAPHICSEVENTS_P_H diff --git a/src/declarative/fx/qmlgraphicsevents_p_p.h b/src/declarative/fx/qmlgraphicsevents_p_p.h new file mode 100644 index 0000000..f093932 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsevents_p_p.h @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSEVENTS_P_H +#define QMLGRAPHICSEVENTS_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 +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlGraphicsKeyEvent : public QObject +{ + Q_OBJECT + Q_PROPERTY(int key READ key) + Q_PROPERTY(QString text READ text) + Q_PROPERTY(int modifiers READ modifiers) + Q_PROPERTY(bool isAutoRepeat READ isAutoRepeat) + Q_PROPERTY(int count READ count) + Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) + +public: + QmlGraphicsKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text=QString(), bool autorep=false, ushort count=1) + : event(type, key, modifiers, text, autorep, count) { event.setAccepted(false); } + QmlGraphicsKeyEvent(const QKeyEvent &ke) + : event(ke) { event.setAccepted(false); } + + int key() const { return event.key(); } + QString text() const { return event.text(); } + int modifiers() const { return event.modifiers(); } + bool isAutoRepeat() const { return event.isAutoRepeat(); } + int count() const { return event.count(); } + + bool isAccepted() { return event.isAccepted(); } + void setAccepted(bool accepted) { event.setAccepted(accepted); } + +private: + QKeyEvent event; +}; + +class QmlGraphicsMouseEvent : public QObject +{ + Q_OBJECT + Q_PROPERTY(int x READ x) + Q_PROPERTY(int y READ y) + Q_PROPERTY(int button READ button) + Q_PROPERTY(int buttons READ buttons) + Q_PROPERTY(int modifiers READ modifiers) + Q_PROPERTY(bool wasHeld READ wasHeld) + Q_PROPERTY(bool isClick READ isClick) + Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) + +public: + QmlGraphicsMouseEvent(int x, int y, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers + , bool isClick=false, bool wasHeld=false) + : _x(x), _y(y), _button(button), _buttons(buttons), _modifiers(modifiers) + , _wasHeld(wasHeld), _isClick(isClick), _accepted(true) {} + + int x() const { return _x; } + int y() const { return _y; } + int button() const { return _button; } + int buttons() const { return _buttons; } + int modifiers() const { return _modifiers; } + bool wasHeld() const { return _wasHeld; } + bool isClick() const { return _isClick; } + + bool isAccepted() { return _accepted; } + void setAccepted(bool accepted) { _accepted = accepted; } + +private: + int _x; + int _y; + Qt::MouseButton _button; + Qt::MouseButtons _buttons; + Qt::KeyboardModifiers _modifiers; + bool _wasHeld; + bool _isClick; + bool _accepted; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsKeyEvent) +QML_DECLARE_TYPE(QmlGraphicsMouseEvent) + +#endif // QMLGRAPHICSEVENTS_P_H diff --git a/src/declarative/fx/qmlgraphicsflickable.cpp b/src/declarative/fx/qmlgraphicsflickable.cpp index ed964aa..3f317d1 100644 --- a/src/declarative/fx/qmlgraphicsflickable.cpp +++ b/src/declarative/fx/qmlgraphicsflickable.cpp @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#include "qmlgraphicsflickable.h" #include "qmlgraphicsflickable_p.h" +#include "qmlgraphicsflickable_p_p.h" #include #include @@ -1280,4 +1280,4 @@ QT_END_NAMESPACE QML_DECLARE_TYPE(QmlGraphicsFlickableVisibleArea) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisibleArea,QmlGraphicsFlickableVisibleArea) -#include "qfxflickable.moc" +#include "qmlgraphicsflickable.moc" diff --git a/src/declarative/fx/qmlgraphicsflickable.h b/src/declarative/fx/qmlgraphicsflickable.h deleted file mode 100644 index f7ef0088..0000000 --- a/src/declarative/fx/qmlgraphicsflickable.h +++ /dev/null @@ -1,203 +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 QMLGRAPHICSFLICKABLE_H -#define QMLGRAPHICSFLICKABLE_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsFlickablePrivate; -class QmlGraphicsFlickableVisibleArea; -class Q_DECLARATIVE_EXPORT QmlGraphicsFlickable : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(qreal viewportWidth READ viewportWidth WRITE setViewportWidth NOTIFY viewportWidthChanged) - Q_PROPERTY(qreal viewportHeight READ viewportHeight WRITE setViewportHeight NOTIFY viewportHeightChanged) - Q_PROPERTY(qreal viewportX READ viewportX WRITE setViewportX NOTIFY positionXChanged) - Q_PROPERTY(qreal viewportY READ viewportY WRITE setViewportY NOTIFY positionYChanged) - - Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged) - Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged) - Q_PROPERTY(qreal reportedVelocitySmoothing READ reportedVelocitySmoothing WRITE setReportedVelocitySmoothing NOTIFY reportedVelocitySmoothingChanged) - - Q_PROPERTY(bool overShoot READ overShoot WRITE setOverShoot) - Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity) - Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration) - Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) - Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) - - Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive) - Q_PROPERTY(int pressDelay READ pressDelay WRITE setPressDelay) - - Q_PROPERTY(bool atXEnd READ isAtXEnd NOTIFY isAtBoundaryChanged) - Q_PROPERTY(bool atYEnd READ isAtYEnd NOTIFY isAtBoundaryChanged) - Q_PROPERTY(bool atXBeginning READ isAtXBeginning NOTIFY isAtBoundaryChanged) - Q_PROPERTY(bool atYBeginning READ isAtYBeginning NOTIFY isAtBoundaryChanged) - - Q_PROPERTY(QmlGraphicsFlickableVisibleArea *visibleArea READ visibleArea CONSTANT) - - Q_PROPERTY(QmlList* flickableData READ flickableData) - Q_PROPERTY(QmlList* flickableChildren READ flickableChildren) - Q_CLASSINFO("DefaultProperty", "flickableData") - -public: - QmlGraphicsFlickable(QmlGraphicsItem *parent=0); - ~QmlGraphicsFlickable(); - - QmlList *flickableData(); - QmlList *flickableChildren(); - - bool overShoot() const; - void setOverShoot(bool); - - qreal viewportWidth() const; - void setViewportWidth(qreal); - - qreal viewportHeight() const; - void setViewportHeight(qreal); - - qreal viewportX() const; - void setViewportX(qreal pos); - - qreal viewportY() const; - void setViewportY(qreal pos); - - bool isMoving() const; - bool isFlicking() const; - - int pressDelay() const; - void setPressDelay(int delay); - - qreal reportedVelocitySmoothing() const; - void setReportedVelocitySmoothing(qreal); - - qreal maximumFlickVelocity() const; - void setMaximumFlickVelocity(qreal); - - qreal flickDeceleration() const; - void setFlickDeceleration(qreal); - - bool isInteractive() const; - void setInteractive(bool); - - qreal horizontalVelocity() const; - qreal verticalVelocity() const; - - bool isAtXEnd() const; - bool isAtXBeginning() const; - bool isAtYEnd() const; - bool isAtYBeginning() const; - - QmlGraphicsItem *viewport(); - -Q_SIGNALS: - void viewportWidthChanged(); - void viewportHeightChanged(); - void positionXChanged(); - void positionYChanged(); - void movingChanged(); - void flickingChanged(); - void movementStarted(); - void movementEnded(); - void flickStarted(); - void flickEnded(); - void reportedVelocitySmoothingChanged(int); - void horizontalVelocityChanged(); - void verticalVelocityChanged(); - void isAtBoundaryChanged(); - void pageChanged(); - -protected: - virtual bool sceneEventFilter(QGraphicsItem *, QEvent *); - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void timerEvent(QTimerEvent *event); - - qreal visibleX() const; - qreal visibleY() const; - - QmlGraphicsFlickableVisibleArea *visibleArea(); - -protected Q_SLOTS: - virtual void ticked(); - void movementStarting(); - void movementEnding(); - void heightChange(); - void widthChange(); - -protected: - virtual qreal minXExtent() const; - virtual qreal minYExtent() const; - virtual qreal maxXExtent() const; - virtual qreal maxYExtent() const; - qreal vWidth() const; - qreal vHeight() const; - virtual void viewportMoved(); - bool sendMouseEvent(QGraphicsSceneMouseEvent *event); - - bool xflick() const; - bool yflick() const; - void cancelFlick(); - -protected: - QmlGraphicsFlickable(QmlGraphicsFlickablePrivate &dd, QmlGraphicsItem *parent); - -private: - Q_DISABLE_COPY(QmlGraphicsFlickable) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsFlickable) - friend class QmlGraphicsFlickableVisibleArea; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsFlickable) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qmlgraphicsflickable_p.h b/src/declarative/fx/qmlgraphicsflickable_p.h index d9f917d..f7ef0088 100644 --- a/src/declarative/fx/qmlgraphicsflickable_p.h +++ b/src/declarative/fx/qmlgraphicsflickable_p.h @@ -39,118 +39,165 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSFLICKABLE_P_H -#define QMLGRAPHICSFLICKABLE_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 "qdatetime.h" -#include "qmlgraphicsflickable.h" -#include "qmlgraphicsitem_p.h" -#include "qml.h" -#include "private/qmltimeline_p.h" -#include "private/qmlanimation_p.h" +#ifndef QMLGRAPHICSFLICKABLE_H +#define QMLGRAPHICSFLICKABLE_H + +#include + +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE +QT_MODULE(Declarative) + +class QmlGraphicsFlickablePrivate; class QmlGraphicsFlickableVisibleArea; -class QmlGraphicsFlickablePrivate : public QmlGraphicsItemPrivate +class Q_DECLARATIVE_EXPORT QmlGraphicsFlickable : public QmlGraphicsItem { - Q_DECLARE_PUBLIC(QmlGraphicsFlickable) + Q_OBJECT -public: - QmlGraphicsFlickablePrivate(); - void init(); - virtual void flickX(qreal velocity); - virtual void flickY(qreal velocity); - virtual void fixupX(); - virtual void fixupY(); - void updateBeginningEnd(); + Q_PROPERTY(qreal viewportWidth READ viewportWidth WRITE setViewportWidth NOTIFY viewportWidthChanged) + Q_PROPERTY(qreal viewportHeight READ viewportHeight WRITE setViewportHeight NOTIFY viewportHeightChanged) + Q_PROPERTY(qreal viewportX READ viewportX WRITE setViewportX NOTIFY positionXChanged) + Q_PROPERTY(qreal viewportY READ viewportY WRITE setViewportY NOTIFY positionYChanged) + + Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged) + Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged) + Q_PROPERTY(qreal reportedVelocitySmoothing READ reportedVelocitySmoothing WRITE setReportedVelocitySmoothing NOTIFY reportedVelocitySmoothingChanged) + + Q_PROPERTY(bool overShoot READ overShoot WRITE setOverShoot) + Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity) + Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration) + Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) + Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) + + Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive) + Q_PROPERTY(int pressDelay READ pressDelay WRITE setPressDelay) + + Q_PROPERTY(bool atXEnd READ isAtXEnd NOTIFY isAtBoundaryChanged) + Q_PROPERTY(bool atYEnd READ isAtYEnd NOTIFY isAtBoundaryChanged) + Q_PROPERTY(bool atXBeginning READ isAtXBeginning NOTIFY isAtBoundaryChanged) + Q_PROPERTY(bool atYBeginning READ isAtYBeginning NOTIFY isAtBoundaryChanged) + + Q_PROPERTY(QmlGraphicsFlickableVisibleArea *visibleArea READ visibleArea CONSTANT) - void captureDelayedPress(QGraphicsSceneMouseEvent *event); - void clearDelayedPress(); + Q_PROPERTY(QmlList* flickableData READ flickableData) + Q_PROPERTY(QmlList* flickableChildren READ flickableChildren) + Q_CLASSINFO("DefaultProperty", "flickableData") public: - QmlGraphicsItem *viewport; - QmlTimeLineValueProxy _moveX; - QmlTimeLineValueProxy _moveY; - QmlTimeLine timeline; - qreal vWidth; - qreal vHeight; - bool overShoot : 1; - bool flicked : 1; - bool moving : 1; - bool stealMouse : 1; - bool pressed : 1; - bool atXEnd : 1; - bool atXBeginning : 1; - bool atYEnd : 1; - bool atYBeginning : 1; - bool interactive : 1; - QTime lastPosTime; - QPointF lastPos; - QPointF pressPos; - qreal pressX; - qreal pressY; - qreal velocityX; - qreal velocityY; - QTime pressTime; - QmlTimeLineEvent fixupXEvent; - QmlTimeLineEvent fixupYEvent; - qreal deceleration; - qreal maxVelocity; - QTime velocityTime; - QPointF lastFlickablePosition; - qreal reportedVelocitySmoothing; - int flickTargetX; - int flickTargetY; - QGraphicsSceneMouseEvent *delayedPressEvent; - QGraphicsItem *delayedPressTarget; - QBasicTimer delayedPressTimer; - int pressDelay; - - void updateVelocity(); - struct Velocity : public QmlTimeLineValue - { - Velocity(QmlGraphicsFlickablePrivate *p) - : parent(p) {} - virtual void setValue(qreal v) { - QmlTimeLineValue::setValue(v); - parent->updateVelocity(); - } - QmlGraphicsFlickablePrivate *parent; - }; - Velocity horizontalVelocity; - Velocity verticalVelocity; - int vTime; - QmlTimeLine velocityTimeline; - QmlGraphicsFlickableVisibleArea *visibleArea; - - void handleMousePressEvent(QGraphicsSceneMouseEvent *); - void handleMouseMoveEvent(QGraphicsSceneMouseEvent *); - void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *); - - // flickableData property - void data_removeAt(int); - int data_count() const; - void data_append(QObject *); - void data_insert(int, QObject *); - QObject *data_at(int) const; - void data_clear(); + QmlGraphicsFlickable(QmlGraphicsItem *parent=0); + ~QmlGraphicsFlickable(); + + QmlList *flickableData(); + QmlList *flickableChildren(); + + bool overShoot() const; + void setOverShoot(bool); + + qreal viewportWidth() const; + void setViewportWidth(qreal); + + qreal viewportHeight() const; + void setViewportHeight(qreal); + + qreal viewportX() const; + void setViewportX(qreal pos); + + qreal viewportY() const; + void setViewportY(qreal pos); + + bool isMoving() const; + bool isFlicking() const; + + int pressDelay() const; + void setPressDelay(int delay); + qreal reportedVelocitySmoothing() const; + void setReportedVelocitySmoothing(qreal); + + qreal maximumFlickVelocity() const; + void setMaximumFlickVelocity(qreal); + + qreal flickDeceleration() const; + void setFlickDeceleration(qreal); + + bool isInteractive() const; + void setInteractive(bool); + + qreal horizontalVelocity() const; + qreal verticalVelocity() const; + + bool isAtXEnd() const; + bool isAtXBeginning() const; + bool isAtYEnd() const; + bool isAtYBeginning() const; + + QmlGraphicsItem *viewport(); + +Q_SIGNALS: + void viewportWidthChanged(); + void viewportHeightChanged(); + void positionXChanged(); + void positionYChanged(); + void movingChanged(); + void flickingChanged(); + void movementStarted(); + void movementEnded(); + void flickStarted(); + void flickEnded(); + void reportedVelocitySmoothingChanged(int); + void horizontalVelocityChanged(); + void verticalVelocityChanged(); + void isAtBoundaryChanged(); + void pageChanged(); + +protected: + virtual bool sceneEventFilter(QGraphicsItem *, QEvent *); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void timerEvent(QTimerEvent *event); + + qreal visibleX() const; + qreal visibleY() const; + + QmlGraphicsFlickableVisibleArea *visibleArea(); + +protected Q_SLOTS: + virtual void ticked(); + void movementStarting(); + void movementEnding(); + void heightChange(); + void widthChange(); + +protected: + virtual qreal minXExtent() const; + virtual qreal minYExtent() const; + virtual qreal maxXExtent() const; + virtual qreal maxYExtent() const; + qreal vWidth() const; + qreal vHeight() const; + virtual void viewportMoved(); + bool sendMouseEvent(QGraphicsSceneMouseEvent *event); + + bool xflick() const; + bool yflick() const; + void cancelFlick(); + +protected: + QmlGraphicsFlickable(QmlGraphicsFlickablePrivate &dd, QmlGraphicsItem *parent); + +private: + Q_DISABLE_COPY(QmlGraphicsFlickable) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsFlickable) friend class QmlGraphicsFlickableVisibleArea; - QML_DECLARE_LIST_PROXY(QmlGraphicsFlickablePrivate, QObject *, data) }; QT_END_NAMESPACE +QML_DECLARE_TYPE(QmlGraphicsFlickable) + +QT_END_HEADER + #endif diff --git a/src/declarative/fx/qmlgraphicsflickable_p_p.h b/src/declarative/fx/qmlgraphicsflickable_p_p.h new file mode 100644 index 0000000..6b8bf9f --- /dev/null +++ b/src/declarative/fx/qmlgraphicsflickable_p_p.h @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSFLICKABLE_P_H +#define QMLGRAPHICSFLICKABLE_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 "qdatetime.h" +#include "qmlgraphicsflickable_p.h" +#include "qmlgraphicsitem_p.h" +#include "qml.h" +#include "private/qmltimeline_p_p.h" +#include "private/qmlanimation_p_p.h" + +QT_BEGIN_NAMESPACE + +class QmlGraphicsFlickableVisibleArea; +class QmlGraphicsFlickablePrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsFlickable) + +public: + QmlGraphicsFlickablePrivate(); + void init(); + virtual void flickX(qreal velocity); + virtual void flickY(qreal velocity); + virtual void fixupX(); + virtual void fixupY(); + void updateBeginningEnd(); + + void captureDelayedPress(QGraphicsSceneMouseEvent *event); + void clearDelayedPress(); + +public: + QmlGraphicsItem *viewport; + QmlTimeLineValueProxy _moveX; + QmlTimeLineValueProxy _moveY; + QmlTimeLine timeline; + qreal vWidth; + qreal vHeight; + bool overShoot : 1; + bool flicked : 1; + bool moving : 1; + bool stealMouse : 1; + bool pressed : 1; + bool atXEnd : 1; + bool atXBeginning : 1; + bool atYEnd : 1; + bool atYBeginning : 1; + bool interactive : 1; + QTime lastPosTime; + QPointF lastPos; + QPointF pressPos; + qreal pressX; + qreal pressY; + qreal velocityX; + qreal velocityY; + QTime pressTime; + QmlTimeLineEvent fixupXEvent; + QmlTimeLineEvent fixupYEvent; + qreal deceleration; + qreal maxVelocity; + QTime velocityTime; + QPointF lastFlickablePosition; + qreal reportedVelocitySmoothing; + int flickTargetX; + int flickTargetY; + QGraphicsSceneMouseEvent *delayedPressEvent; + QGraphicsItem *delayedPressTarget; + QBasicTimer delayedPressTimer; + int pressDelay; + + void updateVelocity(); + struct Velocity : public QmlTimeLineValue + { + Velocity(QmlGraphicsFlickablePrivate *p) + : parent(p) {} + virtual void setValue(qreal v) { + QmlTimeLineValue::setValue(v); + parent->updateVelocity(); + } + QmlGraphicsFlickablePrivate *parent; + }; + Velocity horizontalVelocity; + Velocity verticalVelocity; + int vTime; + QmlTimeLine velocityTimeline; + QmlGraphicsFlickableVisibleArea *visibleArea; + + void handleMousePressEvent(QGraphicsSceneMouseEvent *); + void handleMouseMoveEvent(QGraphicsSceneMouseEvent *); + void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *); + + // flickableData property + void data_removeAt(int); + int data_count() const; + void data_append(QObject *); + void data_insert(int, QObject *); + QObject *data_at(int) const; + void data_clear(); + + friend class QmlGraphicsFlickableVisibleArea; + QML_DECLARE_LIST_PROXY(QmlGraphicsFlickablePrivate, QObject *, data) +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/declarative/fx/qmlgraphicsflipable.cpp b/src/declarative/fx/qmlgraphicsflipable.cpp index 4df35f1..bec39ac 100644 --- a/src/declarative/fx/qmlgraphicsflipable.cpp +++ b/src/declarative/fx/qmlgraphicsflipable.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlgraphicsflipable.h" +#include "qmlgraphicsflipable_p.h" #include "private/qmlgraphicsitem_p.h" #include "QtGui/qgraphicstransform.h" #include @@ -232,5 +232,3 @@ void QmlGraphicsFlipablePrivate::updateSceneTransformFromParent() } QT_END_NAMESPACE - -#include "moc_qmlgraphicsflipable.cpp" diff --git a/src/declarative/fx/qmlgraphicsflipable.h b/src/declarative/fx/qmlgraphicsflipable.h deleted file mode 100644 index 7f92d65..0000000 --- a/src/declarative/fx/qmlgraphicsflipable.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 QMLGRAPHICSFLIPABLE_H -#define QMLGRAPHICSFLIPABLE_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsFlipablePrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsFlipable : public QmlGraphicsItem -{ - Q_OBJECT - - Q_ENUMS(Side) - Q_PROPERTY(QmlGraphicsItem *front READ front WRITE setFront) - Q_PROPERTY(QmlGraphicsItem *back READ back WRITE setBack) - Q_PROPERTY(Side side READ side NOTIFY sideChanged) - //### flipAxis - //### flipRotation -public: - QmlGraphicsFlipable(QmlGraphicsItem *parent=0); - ~QmlGraphicsFlipable(); - - QmlGraphicsItem *front(); - void setFront(QmlGraphicsItem *); - - QmlGraphicsItem *back(); - void setBack(QmlGraphicsItem *); - - enum Side { Front, Back }; - Side side() const; - -Q_SIGNALS: - void sideChanged(); - -private: - Q_DISABLE_COPY(QmlGraphicsFlipable) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsFlipable) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsFlipable) - -QT_END_HEADER - -#endif // QMLGRAPHICSFLIPABLE_H diff --git a/src/declarative/fx/qmlgraphicsflipable_p.h b/src/declarative/fx/qmlgraphicsflipable_p.h new file mode 100644 index 0000000..7f92d65 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsflipable_p.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 QMLGRAPHICSFLIPABLE_H +#define QMLGRAPHICSFLIPABLE_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsFlipablePrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsFlipable : public QmlGraphicsItem +{ + Q_OBJECT + + Q_ENUMS(Side) + Q_PROPERTY(QmlGraphicsItem *front READ front WRITE setFront) + Q_PROPERTY(QmlGraphicsItem *back READ back WRITE setBack) + Q_PROPERTY(Side side READ side NOTIFY sideChanged) + //### flipAxis + //### flipRotation +public: + QmlGraphicsFlipable(QmlGraphicsItem *parent=0); + ~QmlGraphicsFlipable(); + + QmlGraphicsItem *front(); + void setFront(QmlGraphicsItem *); + + QmlGraphicsItem *back(); + void setBack(QmlGraphicsItem *); + + enum Side { Front, Back }; + Side side() const; + +Q_SIGNALS: + void sideChanged(); + +private: + Q_DISABLE_COPY(QmlGraphicsFlipable) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsFlipable) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsFlipable) + +QT_END_HEADER + +#endif // QMLGRAPHICSFLIPABLE_H diff --git a/src/declarative/fx/qmlgraphicsfocuspanel.cpp b/src/declarative/fx/qmlgraphicsfocuspanel.cpp index db8fcdb..8de8832 100644 --- a/src/declarative/fx/qmlgraphicsfocuspanel.cpp +++ b/src/declarative/fx/qmlgraphicsfocuspanel.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlgraphicsfocuspanel.h" +#include "qmlgraphicsfocuspanel_p.h" #include #include diff --git a/src/declarative/fx/qmlgraphicsfocuspanel.h b/src/declarative/fx/qmlgraphicsfocuspanel.h deleted file mode 100644 index 2c4f792..0000000 --- a/src/declarative/fx/qmlgraphicsfocuspanel.h +++ /dev/null @@ -1,77 +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 QMLGRAPHICSFOCUSPANEL_H -#define QMLGRAPHICSFOCUSPANEL_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QmlGraphicsFocusPanel : public QmlGraphicsItem -{ - Q_OBJECT - Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) -public: - QmlGraphicsFocusPanel(QmlGraphicsItem *parent=0); - virtual ~QmlGraphicsFocusPanel(); - -Q_SIGNALS: - void activeChanged(); - -protected: - bool sceneEvent(QEvent *event); - -private: - Q_DISABLE_COPY(QmlGraphicsFocusPanel) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsFocusPanel) - -QT_END_HEADER - -#endif // QMLGRAPHICSFOCUSPANEL_H diff --git a/src/declarative/fx/qmlgraphicsfocuspanel_p.h b/src/declarative/fx/qmlgraphicsfocuspanel_p.h new file mode 100644 index 0000000..2c4f792 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsfocuspanel_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 QMLGRAPHICSFOCUSPANEL_H +#define QMLGRAPHICSFOCUSPANEL_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class Q_DECLARATIVE_EXPORT QmlGraphicsFocusPanel : public QmlGraphicsItem +{ + Q_OBJECT + Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) +public: + QmlGraphicsFocusPanel(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsFocusPanel(); + +Q_SIGNALS: + void activeChanged(); + +protected: + bool sceneEvent(QEvent *event); + +private: + Q_DISABLE_COPY(QmlGraphicsFocusPanel) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsFocusPanel) + +QT_END_HEADER + +#endif // QMLGRAPHICSFOCUSPANEL_H diff --git a/src/declarative/fx/qmlgraphicsfocusscope.cpp b/src/declarative/fx/qmlgraphicsfocusscope.cpp index e957085..e7b01b0 100644 --- a/src/declarative/fx/qmlgraphicsfocusscope.cpp +++ b/src/declarative/fx/qmlgraphicsfocusscope.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlgraphicsfocusscope.h" +#include "qmlgraphicsfocusscope_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsfocusscope.h b/src/declarative/fx/qmlgraphicsfocusscope.h deleted file mode 100644 index 28d1f4f..0000000 --- a/src/declarative/fx/qmlgraphicsfocusscope.h +++ /dev/null @@ -1,68 +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 QMLGRAPHICSFOCUSSCOPE_H -#define QMLGRAPHICSFOCUSSCOPE_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -//### set component root as focusscope -class Q_DECLARATIVE_EXPORT QmlGraphicsFocusScope : public QmlGraphicsItem -{ - Q_OBJECT -public: - QmlGraphicsFocusScope(QmlGraphicsItem *parent=0); - virtual ~QmlGraphicsFocusScope(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsFocusScope) - -QT_END_HEADER - -#endif // QMLGRAPHICSFOCUSSCOPE_H diff --git a/src/declarative/fx/qmlgraphicsfocusscope_p.h b/src/declarative/fx/qmlgraphicsfocusscope_p.h new file mode 100644 index 0000000..28d1f4f --- /dev/null +++ b/src/declarative/fx/qmlgraphicsfocusscope_p.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSFOCUSSCOPE_H +#define QMLGRAPHICSFOCUSSCOPE_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +//### set component root as focusscope +class Q_DECLARATIVE_EXPORT QmlGraphicsFocusScope : public QmlGraphicsItem +{ + Q_OBJECT +public: + QmlGraphicsFocusScope(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsFocusScope(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsFocusScope) + +QT_END_HEADER + +#endif // QMLGRAPHICSFOCUSSCOPE_H diff --git a/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.cpp b/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.cpp index 87193cd..e1f16d5 100644 --- a/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.cpp +++ b/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlgraphicsgraphicsobjectcontainer.h" +#include "qmlgraphicsgraphicsobjectcontainer_p.h" #include #include #include @@ -225,6 +225,6 @@ void QmlGraphicsGraphicsObjectContainerPrivate::_q_updateSize() }*/ } -QT_END_NAMESPACE +#include "moc_qmlgraphicsgraphicsobjectcontainer_p.cpp" -#include "moc_qmlgraphicsgraphicsobjectcontainer.cpp" +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.h b/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.h deleted file mode 100644 index 0189e2f..0000000 --- a/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer.h +++ /dev/null @@ -1,90 +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 QMLGRAPHICSGRAPHICSOBJECTCONTAINER_H -#define QMLGRAPHICSGRAPHICSOBJECTCONTAINER_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QGraphicsObject; -class QmlGraphicsGraphicsObjectContainerPrivate; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGraphicsObjectContainer : public QmlGraphicsItem -{ - Q_OBJECT - - Q_CLASSINFO("DefaultProperty", "graphicsObject") - Q_PROPERTY(QGraphicsObject *graphicsObject READ graphicsObject WRITE setGraphicsObject) - Q_PROPERTY(bool synchronizedResizing READ synchronizedResizing WRITE setSynchronizedResizing) - -public: - QmlGraphicsGraphicsObjectContainer(QmlGraphicsItem *parent = 0); - ~QmlGraphicsGraphicsObjectContainer(); - - QGraphicsObject *graphicsObject() const; - void setGraphicsObject(QGraphicsObject *); - - bool synchronizedResizing() const; - void setSynchronizedResizing(bool on); - -protected: - QVariant itemChange(GraphicsItemChange change, const QVariant &value); - bool eventFilter(QObject *watched, QEvent *e); - -private: - Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsGraphicsObjectContainer) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QGraphicsObject) -QML_DECLARE_TYPE(QmlGraphicsGraphicsObjectContainer) - -QT_END_HEADER - -#endif // QMLGRAPHICSGRAPHICSOBJECTCONTAINER_H diff --git a/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer_p.h b/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer_p.h new file mode 100644 index 0000000..0189e2f --- /dev/null +++ b/src/declarative/fx/qmlgraphicsgraphicsobjectcontainer_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSGRAPHICSOBJECTCONTAINER_H +#define QMLGRAPHICSGRAPHICSOBJECTCONTAINER_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QGraphicsObject; +class QmlGraphicsGraphicsObjectContainerPrivate; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGraphicsObjectContainer : public QmlGraphicsItem +{ + Q_OBJECT + + Q_CLASSINFO("DefaultProperty", "graphicsObject") + Q_PROPERTY(QGraphicsObject *graphicsObject READ graphicsObject WRITE setGraphicsObject) + Q_PROPERTY(bool synchronizedResizing READ synchronizedResizing WRITE setSynchronizedResizing) + +public: + QmlGraphicsGraphicsObjectContainer(QmlGraphicsItem *parent = 0); + ~QmlGraphicsGraphicsObjectContainer(); + + QGraphicsObject *graphicsObject() const; + void setGraphicsObject(QGraphicsObject *); + + bool synchronizedResizing() const; + void setSynchronizedResizing(bool on); + +protected: + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + bool eventFilter(QObject *watched, QEvent *e); + +private: + Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsGraphicsObjectContainer) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QGraphicsObject) +QML_DECLARE_TYPE(QmlGraphicsGraphicsObjectContainer) + +QT_END_HEADER + +#endif // QMLGRAPHICSGRAPHICSOBJECTCONTAINER_H diff --git a/src/declarative/fx/qmlgraphicsgridview.cpp b/src/declarative/fx/qmlgraphicsgridview.cpp index d512b8c..c191a84 100644 --- a/src/declarative/fx/qmlgraphicsgridview.cpp +++ b/src/declarative/fx/qmlgraphicsgridview.cpp @@ -39,11 +39,11 @@ ** ****************************************************************************/ -#include "qmlgraphicsvisualitemmodel.h" -#include "qlistmodelinterface.h" -#include "qmleasefollow.h" -#include "private/qmlgraphicsflickable_p.h" -#include "qmlgraphicsgridview.h" +#include "qmlgraphicsgridview_p.h" +#include +#include +#include +#include #include @@ -1582,4 +1582,4 @@ QML_DEFINE_TYPE(Qt, 4,6, (QT_VERSION&0x00ff00)>>8, GridView, QmlGraphicsGridView QT_END_NAMESPACE -#include "qfxgridview.moc" +#include "qmlgraphicsgridview.moc" diff --git a/src/declarative/fx/qmlgraphicsgridview.h b/src/declarative/fx/qmlgraphicsgridview.h deleted file mode 100644 index 1582529..0000000 --- a/src/declarative/fx/qmlgraphicsgridview.h +++ /dev/null @@ -1,157 +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 QMLGRAPHICSGRIDVIEW_H -#define QMLGRAPHICSGRIDVIEW_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlGraphicsVisualModel; -class QmlGraphicsGridViewAttached; -class QmlGraphicsGridViewPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsGridView : public QmlGraphicsFlickable -{ - Q_OBJECT - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsGridView) - - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) - Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) - Q_PROPERTY(Flow flow READ flow WRITE setFlow) - Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) - Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) - Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged) - Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged) - Q_CLASSINFO("DefaultProperty", "data") - -public: - QmlGraphicsGridView(QmlGraphicsItem *parent=0); - ~QmlGraphicsGridView(); - - QVariant model() const; - void setModel(const QVariant &); - - QmlComponent *delegate() const; - void setDelegate(QmlComponent *); - - int currentIndex() const; - void setCurrentIndex(int idx); - - QmlGraphicsItem *currentItem(); - int count() const; - - QmlComponent *highlight() const; - void setHighlight(QmlComponent *highlight); - - bool highlightFollowsCurrentItem() const; - void setHighlightFollowsCurrentItem(bool); - - Q_ENUMS(Flow) - enum Flow { LeftToRight, TopToBottom }; - Flow flow() const; - void setFlow(Flow); - - bool isWrapEnabled() const; - void setWrapEnabled(bool); - - int cacheBuffer() const; - void setCacheBuffer(int); - - int cellWidth() const; - void setCellWidth(int); - - int cellHeight() const; - void setCellHeight(int); - - static QmlGraphicsGridViewAttached *qmlAttachedProperties(QObject *); - -public Q_SLOTS: - void moveCurrentIndexUp(); - void moveCurrentIndexDown(); - void moveCurrentIndexLeft(); - void moveCurrentIndexRight(); - -Q_SIGNALS: - void countChanged(); - void currentIndexChanged(); - void cellWidthChanged(); - void cellHeightChanged(); - -protected: - virtual void viewportMoved(); - virtual qreal minYExtent() const; - virtual qreal maxYExtent() const; - virtual qreal minXExtent() const; - virtual qreal maxXExtent() const; - virtual void keyPressEvent(QKeyEvent *); - virtual void componentComplete(); - -private Q_SLOTS: - void trackedPositionChanged(); - void itemsInserted(int index, int count); - void itemsRemoved(int index, int count); - void itemsMoved(int from, int to, int count); - void destroyRemoved(); - void createdItem(int index, QmlGraphicsItem *item); - void destroyingItem(QmlGraphicsItem *item); - void sizeChange(); - -private: - void refill(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsGridView) -QML_DECLARE_TYPEINFO(QmlGraphicsGridView, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qmlgraphicsgridview_p.h b/src/declarative/fx/qmlgraphicsgridview_p.h new file mode 100644 index 0000000..d1aebf5 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsgridview_p.h @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSGRIDVIEW_H +#define QMLGRAPHICSGRIDVIEW_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlGraphicsVisualModel; +class QmlGraphicsGridViewAttached; +class QmlGraphicsGridViewPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsGridView : public QmlGraphicsFlickable +{ + Q_OBJECT + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsGridView) + + Q_PROPERTY(QVariant model READ model WRITE setModel) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) + Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) + Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) + Q_PROPERTY(Flow flow READ flow WRITE setFlow) + Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) + Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) + Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged) + Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged) + Q_CLASSINFO("DefaultProperty", "data") + +public: + QmlGraphicsGridView(QmlGraphicsItem *parent=0); + ~QmlGraphicsGridView(); + + QVariant model() const; + void setModel(const QVariant &); + + QmlComponent *delegate() const; + void setDelegate(QmlComponent *); + + int currentIndex() const; + void setCurrentIndex(int idx); + + QmlGraphicsItem *currentItem(); + int count() const; + + QmlComponent *highlight() const; + void setHighlight(QmlComponent *highlight); + + bool highlightFollowsCurrentItem() const; + void setHighlightFollowsCurrentItem(bool); + + Q_ENUMS(Flow) + enum Flow { LeftToRight, TopToBottom }; + Flow flow() const; + void setFlow(Flow); + + bool isWrapEnabled() const; + void setWrapEnabled(bool); + + int cacheBuffer() const; + void setCacheBuffer(int); + + int cellWidth() const; + void setCellWidth(int); + + int cellHeight() const; + void setCellHeight(int); + + static QmlGraphicsGridViewAttached *qmlAttachedProperties(QObject *); + +public Q_SLOTS: + void moveCurrentIndexUp(); + void moveCurrentIndexDown(); + void moveCurrentIndexLeft(); + void moveCurrentIndexRight(); + +Q_SIGNALS: + void countChanged(); + void currentIndexChanged(); + void cellWidthChanged(); + void cellHeightChanged(); + +protected: + virtual void viewportMoved(); + virtual qreal minYExtent() const; + virtual qreal maxYExtent() const; + virtual qreal minXExtent() const; + virtual qreal maxXExtent() const; + virtual void keyPressEvent(QKeyEvent *); + virtual void componentComplete(); + +private Q_SLOTS: + void trackedPositionChanged(); + void itemsInserted(int index, int count); + void itemsRemoved(int index, int count); + void itemsMoved(int from, int to, int count); + void destroyRemoved(); + void createdItem(int index, QmlGraphicsItem *item); + void destroyingItem(QmlGraphicsItem *item); + void sizeChange(); + +private: + void refill(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsGridView) +QML_DECLARE_TYPEINFO(QmlGraphicsGridView, QML_HAS_ATTACHED_PROPERTIES) + +QT_END_HEADER + +#endif diff --git a/src/declarative/fx/qmlgraphicsimage.cpp b/src/declarative/fx/qmlgraphicsimage.cpp index a6156ce..bc0db30 100644 --- a/src/declarative/fx/qmlgraphicsimage.cpp +++ b/src/declarative/fx/qmlgraphicsimage.cpp @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#include "qmlgraphicsimage.h" #include "qmlgraphicsimage_p.h" +#include "qmlgraphicsimage_p_p.h" #include #include diff --git a/src/declarative/fx/qmlgraphicsimage.h b/src/declarative/fx/qmlgraphicsimage.h deleted file mode 100644 index 167ecd4..0000000 --- a/src/declarative/fx/qmlgraphicsimage.h +++ /dev/null @@ -1,90 +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 QMLGRAPHICSIMAGE_H -#define QMLGRAPHICSIMAGE_H - -#include -#include "qmlgraphicsimagebase.h" - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsImagePrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsImage : public QmlGraphicsImageBase -{ - Q_OBJECT - Q_ENUMS(FillMode) - - Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap DESIGNABLE false) - Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) - -public: - QmlGraphicsImage(QmlGraphicsItem *parent=0); - ~QmlGraphicsImage(); - - enum FillMode { Stretch, PreserveAspectFit, PreserveAspectCrop, Tile, TileVertically, TileHorizontally }; - FillMode fillMode() const; - void setFillMode(FillMode); - - QPixmap pixmap() const; - void setPixmap(const QPixmap &); - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -Q_SIGNALS: - void fillModeChanged(); - -protected: - QmlGraphicsImage(QmlGraphicsImagePrivate &dd, QmlGraphicsItem *parent); - -private: - Q_DISABLE_COPY(QmlGraphicsImage) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsImage) -}; - -QT_END_NAMESPACE -QML_DECLARE_TYPE(QmlGraphicsImage) -QT_END_HEADER - -#endif // QMLGRAPHICSIMAGE_H diff --git a/src/declarative/fx/qmlgraphicsimage_p.h b/src/declarative/fx/qmlgraphicsimage_p.h index c5bcf8e..0a00e99 100644 --- a/src/declarative/fx/qmlgraphicsimage_p.h +++ b/src/declarative/fx/qmlgraphicsimage_p.h @@ -39,39 +39,52 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSIMAGE_P_H -#define QMLGRAPHICSIMAGE_P_H +#ifndef QMLGRAPHICSIMAGE_H +#define QMLGRAPHICSIMAGE_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 "qmlgraphicsitem_p.h" +#include #include "qmlgraphicsimagebase_p.h" +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QmlGraphicsImagePrivate : public QmlGraphicsImageBasePrivate +QT_MODULE(Declarative) + +class QmlGraphicsImagePrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsImage : public QmlGraphicsImageBase { - Q_DECLARE_PUBLIC(QmlGraphicsImage) + Q_OBJECT + Q_ENUMS(FillMode) + + Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap DESIGNABLE false) + Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) public: - QmlGraphicsImagePrivate() - : fillMode(QmlGraphicsImage::Stretch) - { - } + QmlGraphicsImage(QmlGraphicsItem *parent=0); + ~QmlGraphicsImage(); + + enum FillMode { Stretch, PreserveAspectFit, PreserveAspectCrop, Tile, TileVertically, TileHorizontally }; + FillMode fillMode() const; + void setFillMode(FillMode); + + QPixmap pixmap() const; + void setPixmap(const QPixmap &); + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +Q_SIGNALS: + void fillModeChanged(); - QmlGraphicsImage::FillMode fillMode; +protected: + QmlGraphicsImage(QmlGraphicsImagePrivate &dd, QmlGraphicsItem *parent); +private: + Q_DISABLE_COPY(QmlGraphicsImage) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsImage) }; QT_END_NAMESPACE +QML_DECLARE_TYPE(QmlGraphicsImage) +QT_END_HEADER -#endif // QMLGRAPHICSIMAGE_P_H +#endif // QMLGRAPHICSIMAGE_H diff --git a/src/declarative/fx/qmlgraphicsimage_p_p.h b/src/declarative/fx/qmlgraphicsimage_p_p.h new file mode 100644 index 0000000..51c6096 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsimage_p_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 QMLGRAPHICSIMAGE_P_H +#define QMLGRAPHICSIMAGE_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 "qmlgraphicsitem_p.h" +#include "qmlgraphicsimagebase_p_p.h" + +QT_BEGIN_NAMESPACE + +class QmlGraphicsImagePrivate : public QmlGraphicsImageBasePrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsImage) + +public: + QmlGraphicsImagePrivate() + : fillMode(QmlGraphicsImage::Stretch) + { + } + + QmlGraphicsImage::FillMode fillMode; + +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSIMAGE_P_H diff --git a/src/declarative/fx/qmlgraphicsimagebase.cpp b/src/declarative/fx/qmlgraphicsimagebase.cpp index d71438d..ccc5045 100644 --- a/src/declarative/fx/qmlgraphicsimagebase.cpp +++ b/src/declarative/fx/qmlgraphicsimagebase.cpp @@ -39,13 +39,13 @@ ** ****************************************************************************/ -#include "qmlgraphicsimagebase.h" #include "qmlgraphicsimagebase_p.h" +#include "qmlgraphicsimagebase_p_p.h" #include #include #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsimagebase.h b/src/declarative/fx/qmlgraphicsimagebase.h deleted file mode 100644 index 3ad0e4b..0000000 --- a/src/declarative/fx/qmlgraphicsimagebase.h +++ /dev/null @@ -1,90 +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 QMLGRAPHICSIMAGEBASE_H -#define QMLGRAPHICSIMAGEBASE_H - -#include - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - -class QmlGraphicsImageBasePrivate; -class QmlGraphicsImageBase : public QmlGraphicsItem -{ - Q_OBJECT - Q_ENUMS(Status) - - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - -public: - QmlGraphicsImageBase(QmlGraphicsItem *parent = 0); - ~QmlGraphicsImageBase(); - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - - QUrl source() const; - virtual void setSource(const QUrl &url); - -Q_SIGNALS: - void sourceChanged(const QUrl &); - void statusChanged(Status); - void progressChanged(qreal progress); - -protected: - QmlGraphicsImageBase(QmlGraphicsImageBasePrivate &dd, QmlGraphicsItem *parent); - -private Q_SLOTS: - virtual void requestFinished(); - void requestProgress(qint64,qint64); - -private: - Q_DISABLE_COPY(QmlGraphicsImageBase) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsImageBase) -}; - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QMLGRAPHICSIMAGEBASE_H diff --git a/src/declarative/fx/qmlgraphicsimagebase_p.h b/src/declarative/fx/qmlgraphicsimagebase_p.h index 5fd5f11..3ad0e4b 100644 --- a/src/declarative/fx/qmlgraphicsimagebase_p.h +++ b/src/declarative/fx/qmlgraphicsimagebase_p.h @@ -39,45 +39,52 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSIMAGEBASE_P_H -#define QMLGRAPHICSIMAGEBASE_P_H +#ifndef QMLGRAPHICSIMAGEBASE_H +#define QMLGRAPHICSIMAGEBASE_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 "qmlgraphicsitem_p.h" -#include +#include +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QNetworkReply; -class QmlGraphicsImageBasePrivate : public QmlGraphicsItemPrivate +class QmlGraphicsImageBasePrivate; +class QmlGraphicsImageBase : public QmlGraphicsItem { - Q_DECLARE_PUBLIC(QmlGraphicsImageBase) + Q_OBJECT + Q_ENUMS(Status) + + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) public: - QmlGraphicsImageBasePrivate() - : status(QmlGraphicsImageBase::Null), - progress(0.0), - pendingPixmapCache(false) - { - } + QmlGraphicsImageBase(QmlGraphicsItem *parent = 0); + ~QmlGraphicsImageBase(); + enum Status { Null, Ready, Loading, Error }; + Status status() const; + qreal progress() const; + + QUrl source() const; + virtual void setSource(const QUrl &url); + +Q_SIGNALS: + void sourceChanged(const QUrl &); + void statusChanged(Status); + void progressChanged(qreal progress); + +protected: + QmlGraphicsImageBase(QmlGraphicsImageBasePrivate &dd, QmlGraphicsItem *parent); + +private Q_SLOTS: + virtual void requestFinished(); + void requestProgress(qint64,qint64); - QPixmap pix; - QmlGraphicsImageBase::Status status; - QUrl url; - qreal progress; - bool pendingPixmapCache; +private: + Q_DISABLE_COPY(QmlGraphicsImageBase) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsImageBase) }; QT_END_NAMESPACE +QT_END_HEADER -#endif +#endif // QMLGRAPHICSIMAGEBASE_H diff --git a/src/declarative/fx/qmlgraphicsimagebase_p_p.h b/src/declarative/fx/qmlgraphicsimagebase_p_p.h new file mode 100644 index 0000000..5fd5f11 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsimagebase_p_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSIMAGEBASE_P_H +#define QMLGRAPHICSIMAGEBASE_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 "qmlgraphicsitem_p.h" +#include + +QT_BEGIN_NAMESPACE + +class QNetworkReply; +class QmlGraphicsImageBasePrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsImageBase) + +public: + QmlGraphicsImageBasePrivate() + : status(QmlGraphicsImageBase::Null), + progress(0.0), + pendingPixmapCache(false) + { + } + + QPixmap pix; + QmlGraphicsImageBase::Status status; + QUrl url; + qreal progress; + bool pendingPixmapCache; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/declarative/fx/qmlgraphicsitem.cpp b/src/declarative/fx/qmlgraphicsitem.cpp index d5b31d0..b689c41 100644 --- a/src/declarative/fx/qmlgraphicsitem.cpp +++ b/src/declarative/fx/qmlgraphicsitem.cpp @@ -47,21 +47,21 @@ #include #include #include -#include +#include #include #include #include -#include -#include "qmlstate.h" -#include "qlistmodelinterface.h" +#include +#include +#include #include "qmlview.h" -#include "qmlstategroup.h" +#include #include "qmlgraphicsitem_p.h" #include "qmlgraphicsitem.h" -#include "qmlgraphicsevents_p.h" +#include #include QT_BEGIN_NAMESPACE @@ -2909,6 +2909,9 @@ int QmlGraphicsItemPrivate::restart(QTime &t) return n; } +#include "qmlgraphicsitem.moc" +#include "moc_qmlgraphicsitem.cpp" + QT_END_NAMESPACE QML_DECLARE_TYPE(QmlGraphicsKeysAttached) @@ -2917,5 +2920,3 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Keys,QmlGraphicsKeysAttached) QML_DECLARE_TYPE(QmlGraphicsKeyNavigationAttached) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,KeyNavigation,QmlGraphicsKeyNavigationAttached) -#include "moc_qmlgraphicsitem.cpp" -#include "qfxitem.moc" diff --git a/src/declarative/fx/qmlgraphicsitem_p.h b/src/declarative/fx/qmlgraphicsitem_p.h index 799374a..83d87a7 100644 --- a/src/declarative/fx/qmlgraphicsitem_p.h +++ b/src/declarative/fx/qmlgraphicsitem_p.h @@ -54,10 +54,10 @@ // #include -#include -#include -#include +#include #include +#include +#include #include #include #include diff --git a/src/declarative/fx/qmlgraphicslayoutitem.cpp b/src/declarative/fx/qmlgraphicslayoutitem.cpp index b75f787..940b4bd 100644 --- a/src/declarative/fx/qmlgraphicslayoutitem.cpp +++ b/src/declarative/fx/qmlgraphicslayoutitem.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlgraphicslayoutitem.h" +#include "qmlgraphicslayoutitem_p.h" #include #include diff --git a/src/declarative/fx/qmlgraphicslayoutitem.h b/src/declarative/fx/qmlgraphicslayoutitem.h deleted file mode 100644 index 184001a..0000000 --- a/src/declarative/fx/qmlgraphicslayoutitem.h +++ /dev/null @@ -1,93 +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 QMLGRAPHICSGRAPHICSLAYOUTITEM_H -#define QMLGRAPHICSGRAPHICSLAYOUTITEM_H -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsLayoutItem : public QmlGraphicsItem, public QGraphicsLayoutItem -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayoutItem) - Q_PROPERTY(QSizeF maximumSize READ maximumSize WRITE setMaximumSize NOTIFY maximumSizeChanged) - Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize NOTIFY minimumSizeChanged) - Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize NOTIFY preferredSizeChanged) -public: - QmlGraphicsLayoutItem(QmlGraphicsItem* parent=0); - - QSizeF maximumSize() const { return m_maximumSize; } - void setMaximumSize(const QSizeF &s) { if(s==m_maximumSize) return; m_maximumSize = s; emit maximumSizeChanged(); } - - QSizeF minimumSize() const { return m_minimumSize; } - void setMinimumSize(const QSizeF &s) { if(s==m_minimumSize) return; m_minimumSize = s; emit minimumSizeChanged(); } - - QSizeF preferredSize() const { return m_preferredSize; } - void setPreferredSize(const QSizeF &s) { if(s==m_preferredSize) return; m_preferredSize = s; emit preferredSizeChanged(); } - - virtual void setGeometry(const QRectF & rect); -protected: - virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; - -Q_SIGNALS: - void maximumSizeChanged(); - void minimumSizeChanged(); - void preferredSizeChanged(); - -private: - QSizeF m_maximumSize; - QSizeF m_minimumSize; - QSizeF m_preferredSize; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsLayoutItem) - -QT_END_HEADER -#endif diff --git a/src/declarative/fx/qmlgraphicslayoutitem_p.h b/src/declarative/fx/qmlgraphicslayoutitem_p.h new file mode 100644 index 0000000..184001a --- /dev/null +++ b/src/declarative/fx/qmlgraphicslayoutitem_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSGRAPHICSLAYOUTITEM_H +#define QMLGRAPHICSGRAPHICSLAYOUTITEM_H +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlGraphicsLayoutItem : public QmlGraphicsItem, public QGraphicsLayoutItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayoutItem) + Q_PROPERTY(QSizeF maximumSize READ maximumSize WRITE setMaximumSize NOTIFY maximumSizeChanged) + Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize NOTIFY minimumSizeChanged) + Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize NOTIFY preferredSizeChanged) +public: + QmlGraphicsLayoutItem(QmlGraphicsItem* parent=0); + + QSizeF maximumSize() const { return m_maximumSize; } + void setMaximumSize(const QSizeF &s) { if(s==m_maximumSize) return; m_maximumSize = s; emit maximumSizeChanged(); } + + QSizeF minimumSize() const { return m_minimumSize; } + void setMinimumSize(const QSizeF &s) { if(s==m_minimumSize) return; m_minimumSize = s; emit minimumSizeChanged(); } + + QSizeF preferredSize() const { return m_preferredSize; } + void setPreferredSize(const QSizeF &s) { if(s==m_preferredSize) return; m_preferredSize = s; emit preferredSizeChanged(); } + + virtual void setGeometry(const QRectF & rect); +protected: + virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; + +Q_SIGNALS: + void maximumSizeChanged(); + void minimumSizeChanged(); + void preferredSizeChanged(); + +private: + QSizeF m_maximumSize; + QSizeF m_minimumSize; + QSizeF m_preferredSize; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsLayoutItem) + +QT_END_HEADER +#endif diff --git a/src/declarative/fx/qmlgraphicslistview.cpp b/src/declarative/fx/qmlgraphicslistview.cpp index 62ca23d..f92b755 100644 --- a/src/declarative/fx/qmlgraphicslistview.cpp +++ b/src/declarative/fx/qmlgraphicslistview.cpp @@ -39,11 +39,11 @@ ** ****************************************************************************/ -#include "private/qmlgraphicsflickable_p.h" -#include "qmleasefollow.h" -#include "qlistmodelinterface.h" -#include "qmlgraphicsvisualitemmodel.h" -#include "qmlgraphicslistview.h" +#include "private/qmlgraphicsflickable_p_p.h" +#include +#include +#include "qmlgraphicsvisualitemmodel_p.h" +#include "qmlgraphicslistview_p.h" #include #include @@ -2032,4 +2032,5 @@ QmlGraphicsListViewAttached *QmlGraphicsListView::qmlAttachedProperties(QObject QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ListView,QmlGraphicsListView) QT_END_NAMESPACE -#include "qfxlistview.moc" + +#include "qmlgraphicslistview.moc" diff --git a/src/declarative/fx/qmlgraphicslistview.h b/src/declarative/fx/qmlgraphicslistview.h deleted file mode 100644 index 1c19c38..0000000 --- a/src/declarative/fx/qmlgraphicslistview.h +++ /dev/null @@ -1,186 +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 QMLGRAPHICSLISTVIEW_H -#define QMLGRAPHICSLISTVIEW_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QmlGraphicsVisualModel; -class QmlGraphicsListViewAttached; -class QmlGraphicsListViewPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable -{ - Q_OBJECT - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsListView) - - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) - Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) - - Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin) - Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd) - Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode) - - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) - Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) - Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) - Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) - Q_PROPERTY(QString sectionExpression READ sectionExpression WRITE setSectionExpression NOTIFY sectionExpressionChanged) - Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) - - Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) - Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) - Q_ENUMS(HighlightRangeMode) - Q_ENUMS(Orientation) - Q_CLASSINFO("DefaultProperty", "data") - -public: - QmlGraphicsListView(QmlGraphicsItem *parent=0); - ~QmlGraphicsListView(); - - QVariant model() const; - void setModel(const QVariant &); - - QmlComponent *delegate() const; - void setDelegate(QmlComponent *); - - int currentIndex() const; - void setCurrentIndex(int idx); - - QmlGraphicsItem *currentItem(); - int count() const; - - QmlComponent *highlight() const; - void setHighlight(QmlComponent *highlight); - - bool highlightFollowsCurrentItem() const; - void setHighlightFollowsCurrentItem(bool); - - enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange }; - HighlightRangeMode highlightRangeMode() const; - void setHighlightRangeMode(HighlightRangeMode mode); - - qreal preferredHighlightBegin() const; - void setPreferredHighlightBegin(qreal); - - qreal preferredHighlightEnd() const; - void setPreferredHighlightEnd(qreal); - - qreal spacing() const; - void setSpacing(qreal spacing); - - enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical }; - Orientation orientation() const; - void setOrientation(Orientation); - - bool isWrapEnabled() const; - void setWrapEnabled(bool); - - int cacheBuffer() const; - void setCacheBuffer(int); - - QString sectionExpression() const; - void setSectionExpression(const QString &); - QString currentSection() const; - - qreal highlightMoveSpeed() const; - void setHighlightMoveSpeed(qreal); - - qreal highlightResizeSpeed() const; - void setHighlightResizeSpeed(qreal); - - static QmlGraphicsListViewAttached *qmlAttachedProperties(QObject *); - -public Q_SLOTS: - void incrementCurrentIndex(); - void decrementCurrentIndex(); - -Q_SIGNALS: - void countChanged(); - void spacingChanged(); - void orientationChanged(); - void currentIndexChanged(); - void currentSectionChanged(); - void sectionExpressionChanged(); - void highlightMoveSpeedChanged(); - void highlightResizeSpeedChanged(); - -protected: - virtual void viewportMoved(); - virtual qreal minYExtent() const; - virtual qreal maxYExtent() const; - virtual qreal minXExtent() const; - virtual qreal maxXExtent() const; - virtual void keyPressEvent(QKeyEvent *); - virtual void componentComplete(); - -private Q_SLOTS: - void refill(); - void trackedPositionChanged(); - void itemResized(); - void itemsInserted(int index, int count); - void itemsRemoved(int index, int count); - void itemsMoved(int from, int to, int count); - void destroyRemoved(); - void createdItem(int index, QmlGraphicsItem *item); - void destroyingItem(QmlGraphicsItem *item); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPEINFO(QmlGraphicsListView, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QmlGraphicsListView) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qmlgraphicslistview_p.h b/src/declarative/fx/qmlgraphicslistview_p.h new file mode 100644 index 0000000..212d4f4 --- /dev/null +++ b/src/declarative/fx/qmlgraphicslistview_p.h @@ -0,0 +1,186 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSLISTVIEW_H +#define QMLGRAPHICSLISTVIEW_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + + +class QmlGraphicsVisualModel; +class QmlGraphicsListViewAttached; +class QmlGraphicsListViewPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable +{ + Q_OBJECT + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsListView) + + Q_PROPERTY(QVariant model READ model WRITE setModel) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) + Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) + Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) + + Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin) + Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd) + Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode) + + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) + Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) + Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) + Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) + Q_PROPERTY(QString sectionExpression READ sectionExpression WRITE setSectionExpression NOTIFY sectionExpressionChanged) + Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) + + Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) + Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) + Q_ENUMS(HighlightRangeMode) + Q_ENUMS(Orientation) + Q_CLASSINFO("DefaultProperty", "data") + +public: + QmlGraphicsListView(QmlGraphicsItem *parent=0); + ~QmlGraphicsListView(); + + QVariant model() const; + void setModel(const QVariant &); + + QmlComponent *delegate() const; + void setDelegate(QmlComponent *); + + int currentIndex() const; + void setCurrentIndex(int idx); + + QmlGraphicsItem *currentItem(); + int count() const; + + QmlComponent *highlight() const; + void setHighlight(QmlComponent *highlight); + + bool highlightFollowsCurrentItem() const; + void setHighlightFollowsCurrentItem(bool); + + enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange }; + HighlightRangeMode highlightRangeMode() const; + void setHighlightRangeMode(HighlightRangeMode mode); + + qreal preferredHighlightBegin() const; + void setPreferredHighlightBegin(qreal); + + qreal preferredHighlightEnd() const; + void setPreferredHighlightEnd(qreal); + + qreal spacing() const; + void setSpacing(qreal spacing); + + enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical }; + Orientation orientation() const; + void setOrientation(Orientation); + + bool isWrapEnabled() const; + void setWrapEnabled(bool); + + int cacheBuffer() const; + void setCacheBuffer(int); + + QString sectionExpression() const; + void setSectionExpression(const QString &); + QString currentSection() const; + + qreal highlightMoveSpeed() const; + void setHighlightMoveSpeed(qreal); + + qreal highlightResizeSpeed() const; + void setHighlightResizeSpeed(qreal); + + static QmlGraphicsListViewAttached *qmlAttachedProperties(QObject *); + +public Q_SLOTS: + void incrementCurrentIndex(); + void decrementCurrentIndex(); + +Q_SIGNALS: + void countChanged(); + void spacingChanged(); + void orientationChanged(); + void currentIndexChanged(); + void currentSectionChanged(); + void sectionExpressionChanged(); + void highlightMoveSpeedChanged(); + void highlightResizeSpeedChanged(); + +protected: + virtual void viewportMoved(); + virtual qreal minYExtent() const; + virtual qreal maxYExtent() const; + virtual qreal minXExtent() const; + virtual qreal maxXExtent() const; + virtual void keyPressEvent(QKeyEvent *); + virtual void componentComplete(); + +private Q_SLOTS: + void refill(); + void trackedPositionChanged(); + void itemResized(); + void itemsInserted(int index, int count); + void itemsRemoved(int index, int count); + void itemsMoved(int from, int to, int count); + void destroyRemoved(); + void createdItem(int index, QmlGraphicsItem *item); + void destroyingItem(QmlGraphicsItem *item); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QmlGraphicsListView, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QmlGraphicsListView) + +QT_END_HEADER + +#endif diff --git a/src/declarative/fx/qmlgraphicsloader.cpp b/src/declarative/fx/qmlgraphicsloader.cpp index b2a9c4f..70839e1 100644 --- a/src/declarative/fx/qmlgraphicsloader.cpp +++ b/src/declarative/fx/qmlgraphicsloader.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlgraphicsloader_p.h" +#include "qmlgraphicsloader_p_p.h" #include QT_BEGIN_NAMESPACE @@ -385,6 +385,6 @@ QmlGraphicsItem *QmlGraphicsLoader::item() const return d->item; } -QT_END_NAMESPACE +#include "moc_qmlgraphicsloader_p.cpp" -#include "moc_qmlgraphicsloader.cpp" +QT_END_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsloader.h b/src/declarative/fx/qmlgraphicsloader.h deleted file mode 100644 index 98f764f..0000000 --- a/src/declarative/fx/qmlgraphicsloader.h +++ /dev/null @@ -1,107 +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 QMLGRAPHICSLOADER_H -#define QMLGRAPHICSLOADER_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsLoaderPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsLoader : public QmlGraphicsItem -{ - Q_OBJECT - Q_ENUMS(Status) - Q_ENUMS(ResizeMode) - - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(QmlComponent *sourceComponent READ sourceComponent WRITE setSourceComponent NOTIFY sourceChanged) - Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) - Q_PROPERTY(QmlGraphicsItem *item READ item NOTIFY itemChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - //### sourceItem - -public: - QmlGraphicsLoader(QmlGraphicsItem *parent=0); - virtual ~QmlGraphicsLoader(); - - QUrl source() const; - void setSource(const QUrl &); - - QmlComponent *sourceComponent() const; - void setSourceComponent(QmlComponent *); - - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - - enum ResizeMode { NoResize, SizeLoaderToItem, SizeItemToLoader }; - ResizeMode resizeMode() const; - void setResizeMode(ResizeMode mode); - - QmlGraphicsItem *item() const; - -Q_SIGNALS: - void itemChanged(); - void sourceChanged(); - void statusChanged(); - void progressChanged(); - -private: - Q_DISABLE_COPY(QmlGraphicsLoader) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsLoader) - Q_PRIVATE_SLOT(d_func(), void _q_sourceLoaded()) - Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsLoader) - -QT_END_HEADER - -#endif // QMLGRAPHICSLOADER_H diff --git a/src/declarative/fx/qmlgraphicsloader_p.h b/src/declarative/fx/qmlgraphicsloader_p.h index ea55334..98f764f 100644 --- a/src/declarative/fx/qmlgraphicsloader_p.h +++ b/src/declarative/fx/qmlgraphicsloader_p.h @@ -39,44 +39,69 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSLOADER_P_H -#define QMLGRAPHICSLOADER_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 "qmlgraphicsitem_p.h" -#include "qmlgraphicsloader.h" +#ifndef QMLGRAPHICSLOADER_H +#define QMLGRAPHICSLOADER_H + +#include + +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QmlContext; -class QmlGraphicsLoaderPrivate : public QmlGraphicsItemPrivate +QT_MODULE(Declarative) + +class QmlGraphicsLoaderPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsLoader : public QmlGraphicsItem { - Q_DECLARE_PUBLIC(QmlGraphicsLoader) + Q_OBJECT + Q_ENUMS(Status) + Q_ENUMS(ResizeMode) + + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QmlComponent *sourceComponent READ sourceComponent WRITE setSourceComponent NOTIFY sourceChanged) + Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) + Q_PROPERTY(QmlGraphicsItem *item READ item NOTIFY itemChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) + //### sourceItem public: - QmlGraphicsLoaderPrivate(); - ~QmlGraphicsLoaderPrivate(); + QmlGraphicsLoader(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsLoader(); + + QUrl source() const; + void setSource(const QUrl &); + + QmlComponent *sourceComponent() const; + void setSourceComponent(QmlComponent *); - QUrl source; - QmlGraphicsItem *item; - QmlComponent *component; - bool ownComponent; - QmlGraphicsLoader::ResizeMode resizeMode; + enum Status { Null, Ready, Loading, Error }; + Status status() const; + qreal progress() const; - void _q_sourceLoaded(); - void _q_updateSize(); + enum ResizeMode { NoResize, SizeLoaderToItem, SizeItemToLoader }; + ResizeMode resizeMode() const; + void setResizeMode(ResizeMode mode); + + QmlGraphicsItem *item() const; + +Q_SIGNALS: + void itemChanged(); + void sourceChanged(); + void statusChanged(); + void progressChanged(); + +private: + Q_DISABLE_COPY(QmlGraphicsLoader) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsLoader) + Q_PRIVATE_SLOT(d_func(), void _q_sourceLoaded()) + Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) }; QT_END_NAMESPACE -#endif // QMLGRAPHICSLOADER_P_H +QML_DECLARE_TYPE(QmlGraphicsLoader) + +QT_END_HEADER + +#endif // QMLGRAPHICSLOADER_H diff --git a/src/declarative/fx/qmlgraphicsloader_p_p.h b/src/declarative/fx/qmlgraphicsloader_p_p.h new file mode 100644 index 0000000..8761d5c --- /dev/null +++ b/src/declarative/fx/qmlgraphicsloader_p_p.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSLOADER_P_H +#define QMLGRAPHICSLOADER_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 "qmlgraphicsitem_p.h" +#include "qmlgraphicsloader_p.h" + +QT_BEGIN_NAMESPACE + +class QmlContext; +class QmlGraphicsLoaderPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsLoader) + +public: + QmlGraphicsLoaderPrivate(); + ~QmlGraphicsLoaderPrivate(); + + QUrl source; + QmlGraphicsItem *item; + QmlComponent *component; + bool ownComponent; + QmlGraphicsLoader::ResizeMode resizeMode; + + void _q_sourceLoaded(); + void _q_updateSize(); +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSLOADER_P_H diff --git a/src/declarative/fx/qmlgraphicsmouseregion.cpp b/src/declarative/fx/qmlgraphicsmouseregion.cpp index 7ad1ac2..5bdb5f0 100644 --- a/src/declarative/fx/qmlgraphicsmouseregion.cpp +++ b/src/declarative/fx/qmlgraphicsmouseregion.cpp @@ -39,9 +39,9 @@ ** ****************************************************************************/ -#include "qmlgraphicsmouseregion.h" #include "qmlgraphicsmouseregion_p.h" -#include "qmlgraphicsevents_p.h" +#include "qmlgraphicsmouseregion_p_p.h" +#include "qmlgraphicsevents_p_p.h" #include diff --git a/src/declarative/fx/qmlgraphicsmouseregion.h b/src/declarative/fx/qmlgraphicsmouseregion.h deleted file mode 100644 index 9874fbf..0000000 --- a/src/declarative/fx/qmlgraphicsmouseregion.h +++ /dev/null @@ -1,180 +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 QMLGRAPHICSMOUSEREGION_H -#define QMLGRAPHICSMOUSEREGION_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QmlGraphicsDrag : public QObject -{ - Q_OBJECT - - Q_ENUMS(Axis) - Q_PROPERTY(QmlGraphicsItem *target READ target WRITE setTarget) - Q_PROPERTY(Axis axis READ axis WRITE setAxis) - Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin) - Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax) - Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin) - Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax) - //### consider drag and drop - -public: - QmlGraphicsDrag(QObject *parent=0); - ~QmlGraphicsDrag(); - - QmlGraphicsItem *target() const; - void setTarget(QmlGraphicsItem *); - - enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 }; - Axis axis() const; - void setAxis(Axis); - - qreal xmin() const; - void setXmin(qreal); - qreal xmax() const; - void setXmax(qreal); - qreal ymin() const; - void setYmin(qreal); - qreal ymax() const; - void setYmax(qreal); - -private: - QmlGraphicsItem *_target; - Axis _axis; - qreal _xmin; - qreal _xmax; - qreal _ymin; - qreal _ymax; - Q_DISABLE_COPY(QmlGraphicsDrag) -}; - -class QmlGraphicsMouseEvent; -class QmlGraphicsMouseRegionPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsMouseRegion : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(qreal mouseX READ mouseX NOTIFY positionChanged) - Q_PROPERTY(qreal mouseY READ mouseY NOTIFY positionChanged) - Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) - Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged) - Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) - Q_PROPERTY(bool hoverEnabled READ acceptHoverEvents WRITE setAcceptHoverEvents) - Q_PROPERTY(QmlGraphicsDrag *drag READ drag) //### add flicking to QmlGraphicsDrag or add a QmlGraphicsFlick ??? - -public: - QmlGraphicsMouseRegion(QmlGraphicsItem *parent=0); - ~QmlGraphicsMouseRegion(); - - qreal mouseX() const; - qreal mouseY() const; - - bool isEnabled() const; - void setEnabled(bool); - - bool hovered() const; - bool pressed() const; - - Qt::MouseButtons pressedButtons() const; - - Qt::MouseButtons acceptedButtons() const; - void setAcceptedButtons(Qt::MouseButtons buttons); - - QmlGraphicsDrag *drag(); - -Q_SIGNALS: - void hoveredChanged(); - void pressedChanged(); - void enabledChanged(); - void acceptedButtonsChanged(); - void positionChanged(QmlGraphicsMouseEvent *mouse); - - void pressed(QmlGraphicsMouseEvent *mouse); - void pressAndHold(QmlGraphicsMouseEvent *mouse); - void released(QmlGraphicsMouseEvent *mouse); - void clicked(QmlGraphicsMouseEvent *mouse); - void doubleClicked(QmlGraphicsMouseEvent *mouse); - void entered(); - void exited(); - -protected: - void setHovered(bool); - bool setPressed(bool); - - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void hoverEnterEvent(QGraphicsSceneHoverEvent *event); - void hoverMoveEvent(QGraphicsSceneHoverEvent *event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - bool sceneEvent(QEvent *); - void timerEvent(QTimerEvent *event); - -private: - void handlePress(); - void handleRelease(); - -protected: - QmlGraphicsMouseRegion(QmlGraphicsMouseRegionPrivate &dd, QmlGraphicsItem *parent); - -private: - Q_DISABLE_COPY(QmlGraphicsMouseRegion) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsMouseRegion) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsDrag) -QML_DECLARE_TYPE(QmlGraphicsMouseRegion) - -QT_END_HEADER - -#endif // QMLGRAPHICSMOUSEREGION_H diff --git a/src/declarative/fx/qmlgraphicsmouseregion_p.h b/src/declarative/fx/qmlgraphicsmouseregion_p.h index 71b31b4..9874fbf 100644 --- a/src/declarative/fx/qmlgraphicsmouseregion_p.h +++ b/src/declarative/fx/qmlgraphicsmouseregion_p.h @@ -39,76 +39,142 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSMOUSEREGION_P_H -#define QMLGRAPHICSMOUSEREGION_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 "qdatetime.h" -#include "qbasictimer.h" -#include "qgraphicssceneevent.h" -#include "qmlgraphicsitem_p.h" +#ifndef QMLGRAPHICSMOUSEREGION_H +#define QMLGRAPHICSMOUSEREGION_H + +#include + +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QmlGraphicsMouseRegionPrivate : public QmlGraphicsItemPrivate +QT_MODULE(Declarative) + +class Q_DECLARATIVE_EXPORT QmlGraphicsDrag : public QObject { - Q_DECLARE_PUBLIC(QmlGraphicsMouseRegion) + Q_OBJECT + + Q_ENUMS(Axis) + Q_PROPERTY(QmlGraphicsItem *target READ target WRITE setTarget) + Q_PROPERTY(Axis axis READ axis WRITE setAxis) + Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin) + Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax) + Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin) + Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax) + //### consider drag and drop public: - QmlGraphicsMouseRegionPrivate() - : absorb(true), hovered(false), pressed(false), longPress(false), drag(0) - { - } - - void init() - { - Q_Q(QmlGraphicsMouseRegion); - q->setAcceptedMouseButtons(Qt::LeftButton); - } - - void saveEvent(QGraphicsSceneMouseEvent *event) { - lastPos = event->pos(); - lastButton = event->button(); - lastButtons = event->buttons(); - lastModifiers = event->modifiers(); - } - - bool isConnected(const char *signal) { - Q_Q(QmlGraphicsMouseRegion); - int idx = QObjectPrivate::get(q)->signalIndex(signal); - return QObjectPrivate::get(q)->isSignalConnected(idx); - } - - bool absorb : 1; - bool hovered : 1; - bool pressed : 1; - bool longPress : 1; - bool moved : 1; - bool dragX : 1; - bool dragY : 1; - bool dragged : 1; - QmlGraphicsDrag drag; - QPointF start; - QPointF startScene; - qreal startX; - qreal startY; - QPointF lastPos; - Qt::MouseButton lastButton; - Qt::MouseButtons lastButtons; - Qt::KeyboardModifiers lastModifiers; - QBasicTimer pressAndHoldTimer; + QmlGraphicsDrag(QObject *parent=0); + ~QmlGraphicsDrag(); + + QmlGraphicsItem *target() const; + void setTarget(QmlGraphicsItem *); + + enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 }; + Axis axis() const; + void setAxis(Axis); + + qreal xmin() const; + void setXmin(qreal); + qreal xmax() const; + void setXmax(qreal); + qreal ymin() const; + void setYmin(qreal); + qreal ymax() const; + void setYmax(qreal); + +private: + QmlGraphicsItem *_target; + Axis _axis; + qreal _xmin; + qreal _xmax; + qreal _ymin; + qreal _ymax; + Q_DISABLE_COPY(QmlGraphicsDrag) +}; + +class QmlGraphicsMouseEvent; +class QmlGraphicsMouseRegionPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsMouseRegion : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(qreal mouseX READ mouseX NOTIFY positionChanged) + Q_PROPERTY(qreal mouseY READ mouseY NOTIFY positionChanged) + Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) + Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged) + Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) + Q_PROPERTY(bool hoverEnabled READ acceptHoverEvents WRITE setAcceptHoverEvents) + Q_PROPERTY(QmlGraphicsDrag *drag READ drag) //### add flicking to QmlGraphicsDrag or add a QmlGraphicsFlick ??? + +public: + QmlGraphicsMouseRegion(QmlGraphicsItem *parent=0); + ~QmlGraphicsMouseRegion(); + + qreal mouseX() const; + qreal mouseY() const; + + bool isEnabled() const; + void setEnabled(bool); + + bool hovered() const; + bool pressed() const; + + Qt::MouseButtons pressedButtons() const; + + Qt::MouseButtons acceptedButtons() const; + void setAcceptedButtons(Qt::MouseButtons buttons); + + QmlGraphicsDrag *drag(); + +Q_SIGNALS: + void hoveredChanged(); + void pressedChanged(); + void enabledChanged(); + void acceptedButtonsChanged(); + void positionChanged(QmlGraphicsMouseEvent *mouse); + + void pressed(QmlGraphicsMouseEvent *mouse); + void pressAndHold(QmlGraphicsMouseEvent *mouse); + void released(QmlGraphicsMouseEvent *mouse); + void clicked(QmlGraphicsMouseEvent *mouse); + void doubleClicked(QmlGraphicsMouseEvent *mouse); + void entered(); + void exited(); + +protected: + void setHovered(bool); + bool setPressed(bool); + + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverMoveEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + bool sceneEvent(QEvent *); + void timerEvent(QTimerEvent *event); + +private: + void handlePress(); + void handleRelease(); + +protected: + QmlGraphicsMouseRegion(QmlGraphicsMouseRegionPrivate &dd, QmlGraphicsItem *parent); + +private: + Q_DISABLE_COPY(QmlGraphicsMouseRegion) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsMouseRegion) }; QT_END_NAMESPACE -#endif // QMLGRAPHICSMOUSEREGION_P_H +QML_DECLARE_TYPE(QmlGraphicsDrag) +QML_DECLARE_TYPE(QmlGraphicsMouseRegion) + +QT_END_HEADER + +#endif // QMLGRAPHICSMOUSEREGION_H diff --git a/src/declarative/fx/qmlgraphicsmouseregion_p_p.h b/src/declarative/fx/qmlgraphicsmouseregion_p_p.h new file mode 100644 index 0000000..71b31b4 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsmouseregion_p_p.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSMOUSEREGION_P_H +#define QMLGRAPHICSMOUSEREGION_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 "qdatetime.h" +#include "qbasictimer.h" +#include "qgraphicssceneevent.h" +#include "qmlgraphicsitem_p.h" + +QT_BEGIN_NAMESPACE + +class QmlGraphicsMouseRegionPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsMouseRegion) + +public: + QmlGraphicsMouseRegionPrivate() + : absorb(true), hovered(false), pressed(false), longPress(false), drag(0) + { + } + + void init() + { + Q_Q(QmlGraphicsMouseRegion); + q->setAcceptedMouseButtons(Qt::LeftButton); + } + + void saveEvent(QGraphicsSceneMouseEvent *event) { + lastPos = event->pos(); + lastButton = event->button(); + lastButtons = event->buttons(); + lastModifiers = event->modifiers(); + } + + bool isConnected(const char *signal) { + Q_Q(QmlGraphicsMouseRegion); + int idx = QObjectPrivate::get(q)->signalIndex(signal); + return QObjectPrivate::get(q)->isSignalConnected(idx); + } + + bool absorb : 1; + bool hovered : 1; + bool pressed : 1; + bool longPress : 1; + bool moved : 1; + bool dragX : 1; + bool dragY : 1; + bool dragged : 1; + QmlGraphicsDrag drag; + QPointF start; + QPointF startScene; + qreal startX; + qreal startY; + QPointF lastPos; + Qt::MouseButton lastButton; + Qt::MouseButtons lastButtons; + Qt::KeyboardModifiers lastModifiers; + QBasicTimer pressAndHoldTimer; +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSMOUSEREGION_P_H diff --git a/src/declarative/fx/qmlgraphicspainteditem.cpp b/src/declarative/fx/qmlgraphicspainteditem.cpp index 43d0318..5a8e711 100644 --- a/src/declarative/fx/qmlgraphicspainteditem.cpp +++ b/src/declarative/fx/qmlgraphicspainteditem.cpp @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#include "qmlgraphicspainteditem.h" #include "qmlgraphicspainteditem_p.h" +#include "qmlgraphicspainteditem_p_p.h" #include #include diff --git a/src/declarative/fx/qmlgraphicspainteditem.h b/src/declarative/fx/qmlgraphicspainteditem.h deleted file mode 100644 index 7ff55a5..0000000 --- a/src/declarative/fx/qmlgraphicspainteditem.h +++ /dev/null @@ -1,105 +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 QMLGRAPHICSIMAGEITEM_H -#define QMLGRAPHICSIMAGEITEM_H - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsPaintedItemPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsPaintedItem : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QSize contentsSize READ contentsSize WRITE setContentsSize) - Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY fillColorChanged) - Q_PROPERTY(int cacheSize READ cacheSize WRITE setCacheSize) - -public: - QmlGraphicsPaintedItem(QmlGraphicsItem *parent=0); - ~QmlGraphicsPaintedItem(); - - QSize contentsSize() const; - void setContentsSize(const QSize &); - - int cacheSize() const; - void setCacheSize(int pixels); - - QColor fillColor() const; - void setFillColor(const QColor&); - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -protected: - QmlGraphicsPaintedItem(QmlGraphicsPaintedItemPrivate &dd, QmlGraphicsItem *parent); - - virtual void drawContents(QPainter *p, const QRect &) = 0; - - void setCacheFrozen(bool); - -Q_SIGNALS: - void fillColorChanged(); - -protected Q_SLOTS: - void dirtyCache(const QRect &); - void clearCache(); - -private: - void init(); - Q_DISABLE_COPY(QmlGraphicsPaintedItem) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsPaintedItem) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsPaintedItem) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qmlgraphicspainteditem_p.h b/src/declarative/fx/qmlgraphicspainteditem_p.h index d5cd673..7ff55a5 100644 --- a/src/declarative/fx/qmlgraphicspainteditem_p.h +++ b/src/declarative/fx/qmlgraphicspainteditem_p.h @@ -39,50 +39,67 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSIMAGEITEM_P_H -#define QMLGRAPHICSIMAGEITEM_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 +#ifndef QMLGRAPHICSIMAGEITEM_H +#define QMLGRAPHICSIMAGEITEM_H + +#include +#include + + +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QmlGraphicsPaintedItemPrivate : public QmlGraphicsItemPrivate +QT_MODULE(Declarative) + +class QmlGraphicsPaintedItemPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsPaintedItem : public QmlGraphicsItem { - Q_DECLARE_PUBLIC(QmlGraphicsPaintedItem) + Q_OBJECT + + Q_PROPERTY(QSize contentsSize READ contentsSize WRITE setContentsSize) + Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY fillColorChanged) + Q_PROPERTY(int cacheSize READ cacheSize WRITE setCacheSize) public: - QmlGraphicsPaintedItemPrivate() - : max_imagecache_size(100000), fillColor(Qt::transparent), cachefrozen(false) - { - } - - struct ImageCacheItem { - ImageCacheItem() : age(0) {} - ~ImageCacheItem() { } - int age; - QRect area; - QRect dirty; // one dirty area (allows optimization of common cases) - QPixmap image; - }; - - QList imagecache; - - int max_imagecache_size; - QSize contentsSize; - QColor fillColor; - bool cachefrozen; + QmlGraphicsPaintedItem(QmlGraphicsItem *parent=0); + ~QmlGraphicsPaintedItem(); + + QSize contentsSize() const; + void setContentsSize(const QSize &); + + int cacheSize() const; + void setCacheSize(int pixels); + + QColor fillColor() const; + void setFillColor(const QColor&); + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +protected: + QmlGraphicsPaintedItem(QmlGraphicsPaintedItemPrivate &dd, QmlGraphicsItem *parent); + + virtual void drawContents(QPainter *p, const QRect &) = 0; + + void setCacheFrozen(bool); + +Q_SIGNALS: + void fillColorChanged(); + +protected Q_SLOTS: + void dirtyCache(const QRect &); + void clearCache(); + +private: + void init(); + Q_DISABLE_COPY(QmlGraphicsPaintedItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsPaintedItem) }; QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsPaintedItem) + +QT_END_HEADER + #endif diff --git a/src/declarative/fx/qmlgraphicspainteditem_p_p.h b/src/declarative/fx/qmlgraphicspainteditem_p_p.h new file mode 100644 index 0000000..d5cd673 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspainteditem_p_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSIMAGEITEM_P_H +#define QMLGRAPHICSIMAGEITEM_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 + +QT_BEGIN_NAMESPACE + +class QmlGraphicsPaintedItemPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsPaintedItem) + +public: + QmlGraphicsPaintedItemPrivate() + : max_imagecache_size(100000), fillColor(Qt::transparent), cachefrozen(false) + { + } + + struct ImageCacheItem { + ImageCacheItem() : age(0) {} + ~ImageCacheItem() { } + int age; + QRect area; + QRect dirty; // one dirty area (allows optimization of common cases) + QPixmap image; + }; + + QList imagecache; + + int max_imagecache_size; + QSize contentsSize; + QColor fillColor; + bool cachefrozen; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/declarative/fx/qmlgraphicspath.cpp b/src/declarative/fx/qmlgraphicspath.cpp index 15dbfef..193a2c6 100644 --- a/src/declarative/fx/qmlgraphicspath.cpp +++ b/src/declarative/fx/qmlgraphicspath.cpp @@ -39,9 +39,9 @@ ** ****************************************************************************/ -#include "qmlgraphicspath.h" #include "qmlgraphicspath_p.h" -#include +#include "qmlgraphicspath_p_p.h" +#include #include #include diff --git a/src/declarative/fx/qmlgraphicspath.h b/src/declarative/fx/qmlgraphicspath.h deleted file mode 100644 index db6c84f..0000000 --- a/src/declarative/fx/qmlgraphicspath.h +++ /dev/null @@ -1,259 +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 QMLGRAPHICSPATH_H -#define QMLGRAPHICSPATH_H - -#include -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class Q_DECLARATIVE_EXPORT QmlGraphicsPathElement : public QObject -{ - Q_OBJECT -public: - QmlGraphicsPathElement(QObject *parent=0) : QObject(parent) {} -Q_SIGNALS: - void changed(); -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsPathAttribute : public QmlGraphicsPathElement -{ - Q_OBJECT - - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) -public: - QmlGraphicsPathAttribute(QObject *parent=0) : QmlGraphicsPathElement(parent), _value(0) {} - - - QString name() const; - void setName(const QString &name); - - qreal value() const; - void setValue(qreal value); - -private: - QString _name; - qreal _value; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsCurve : public QmlGraphicsPathElement -{ - Q_OBJECT - - Q_PROPERTY(qreal x READ x WRITE setX NOTIFY changed) - Q_PROPERTY(qreal y READ y WRITE setY NOTIFY changed) -public: - QmlGraphicsCurve(QObject *parent=0) : QmlGraphicsPathElement(parent), _x(0), _y(0) {} - - qreal x() const; - void setX(qreal x); - - qreal y() const; - void setY(qreal y); - - virtual void addToPath(QPainterPath &) {} - -private: - qreal _x; - qreal _y; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsPathLine : public QmlGraphicsCurve -{ - Q_OBJECT -public: - QmlGraphicsPathLine(QObject *parent=0) : QmlGraphicsCurve(parent) {} - - void addToPath(QPainterPath &path); -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsPathQuad : public QmlGraphicsCurve -{ - Q_OBJECT - - Q_PROPERTY(qreal controlX READ controlX WRITE setControlX NOTIFY changed) - Q_PROPERTY(qreal controlY READ controlY WRITE setControlY NOTIFY changed) -public: - QmlGraphicsPathQuad(QObject *parent=0) : QmlGraphicsCurve(parent), _controlX(0), _controlY(0) {} - - qreal controlX() const; - void setControlX(qreal x); - - qreal controlY() const; - void setControlY(qreal y); - - void addToPath(QPainterPath &path); - -private: - qreal _controlX; - qreal _controlY; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsPathCubic : public QmlGraphicsCurve -{ - Q_OBJECT - - Q_PROPERTY(qreal control1X READ control1X WRITE setControl1X NOTIFY changed) - Q_PROPERTY(qreal control1Y READ control1Y WRITE setControl1Y NOTIFY changed) - Q_PROPERTY(qreal control2X READ control2X WRITE setControl2X NOTIFY changed) - Q_PROPERTY(qreal control2Y READ control2Y WRITE setControl2Y NOTIFY changed) -public: - QmlGraphicsPathCubic(QObject *parent=0) : QmlGraphicsCurve(parent), _control1X(0), _control1Y(0), _control2X(0), _control2Y(0) {} - - qreal control1X() const; - void setControl1X(qreal x); - - qreal control1Y() const; - void setControl1Y(qreal y); - - qreal control2X() const; - void setControl2X(qreal x); - - qreal control2Y() const; - void setControl2Y(qreal y); - - void addToPath(QPainterPath &path); - -private: - int _control1X; - int _control1Y; - int _control2X; - int _control2Y; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsPathPercent : public QmlGraphicsPathElement -{ - Q_OBJECT - Q_PROPERTY(qreal value READ value WRITE setValue) -public: - QmlGraphicsPathPercent(QObject *parent=0) : QmlGraphicsPathElement(parent) {} - - qreal value() const; - void setValue(qreal value); - -private: - qreal _value; -}; - -class QmlGraphicsPathPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsPath : public QObject, public QmlParserStatus -{ - Q_OBJECT - - Q_INTERFACES(QmlParserStatus) - Q_PROPERTY(QList* pathElements READ pathElements) - Q_PROPERTY(qreal startX READ startX WRITE setStartX) - Q_PROPERTY(qreal startY READ startY WRITE setStartY) - Q_CLASSINFO("DefaultProperty", "pathElements") - Q_INTERFACES(QmlParserStatus) -public: - QmlGraphicsPath(QObject *parent=0); - ~QmlGraphicsPath(); - - QList* pathElements(); - - qreal startX() const; - void setStartX(qreal x); - - qreal startY() const; - void setStartY(qreal y); - - QPainterPath path() const; - QStringList attributes() const; - qreal attributeAt(const QString &, qreal) const; - QPointF pointAt(qreal) const; - -Q_SIGNALS: - void changed(); - -protected: - virtual void componentComplete(); - QmlGraphicsPath(QmlGraphicsPathPrivate &dd, QObject *parent); - -private Q_SLOTS: - void processPath(); - -private: - struct AttributePoint { - AttributePoint() : percent(0), scale(1), origpercent(0) {} - AttributePoint(const AttributePoint &other) - : percent(other.percent), scale(other.scale), origpercent(other.origpercent), values(other.values) {} - AttributePoint &operator=(const AttributePoint &other) { - percent = other.percent; scale = other.scale; origpercent = other.origpercent; values = other.values; return *this; - } - qreal percent; //massaged percent along the painter path - qreal scale; - qreal origpercent; //'real' percent along the painter path - QHash values; - }; - - void interpolate(int idx, const QString &name, qreal value); - void endpoint(const QString &name); - void createPointCache() const; - -private: - Q_DISABLE_COPY(QmlGraphicsPath) - Q_DECLARE_PRIVATE(QmlGraphicsPath) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsPathElement) -QML_DECLARE_TYPE(QmlGraphicsPathAttribute) -QML_DECLARE_TYPE(QmlGraphicsCurve) -QML_DECLARE_TYPE(QmlGraphicsPathLine) -QML_DECLARE_TYPE(QmlGraphicsPathQuad) -QML_DECLARE_TYPE(QmlGraphicsPathCubic) -QML_DECLARE_TYPE(QmlGraphicsPathPercent) -QML_DECLARE_TYPE(QmlGraphicsPath) - -QT_END_HEADER - -#endif // QMLGRAPHICSPATH_H diff --git a/src/declarative/fx/qmlgraphicspath_p.h b/src/declarative/fx/qmlgraphicspath_p.h index 7c0e1ea..db6c84f 100644 --- a/src/declarative/fx/qmlgraphicspath_p.h +++ b/src/declarative/fx/qmlgraphicspath_p.h @@ -39,41 +39,221 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSPATH_P_H -#define QMLGRAPHICSPATH_P_H +#ifndef QMLGRAPHICSPATH_H +#define QMLGRAPHICSPATH_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 +#include +#include +#include -#include "private/qobject_p.h" -#include "qmlgraphicspath.h" -#include "qml.h" +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QmlGraphicsPathPrivate : public QObjectPrivate + +QT_MODULE(Declarative) +class Q_DECLARATIVE_EXPORT QmlGraphicsPathElement : public QObject +{ + Q_OBJECT +public: + QmlGraphicsPathElement(QObject *parent=0) : QObject(parent) {} +Q_SIGNALS: + void changed(); +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsPathAttribute : public QmlGraphicsPathElement +{ + Q_OBJECT + + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) +public: + QmlGraphicsPathAttribute(QObject *parent=0) : QmlGraphicsPathElement(parent), _value(0) {} + + + QString name() const; + void setName(const QString &name); + + qreal value() const; + void setValue(qreal value); + +private: + QString _name; + qreal _value; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsCurve : public QmlGraphicsPathElement +{ + Q_OBJECT + + Q_PROPERTY(qreal x READ x WRITE setX NOTIFY changed) + Q_PROPERTY(qreal y READ y WRITE setY NOTIFY changed) +public: + QmlGraphicsCurve(QObject *parent=0) : QmlGraphicsPathElement(parent), _x(0), _y(0) {} + + qreal x() const; + void setX(qreal x); + + qreal y() const; + void setY(qreal y); + + virtual void addToPath(QPainterPath &) {} + +private: + qreal _x; + qreal _y; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsPathLine : public QmlGraphicsCurve { - Q_DECLARE_PUBLIC(QmlGraphicsPath) + Q_OBJECT +public: + QmlGraphicsPathLine(QObject *parent=0) : QmlGraphicsCurve(parent) {} + + void addToPath(QPainterPath &path); +}; +class Q_DECLARATIVE_EXPORT QmlGraphicsPathQuad : public QmlGraphicsCurve +{ + Q_OBJECT + + Q_PROPERTY(qreal controlX READ controlX WRITE setControlX NOTIFY changed) + Q_PROPERTY(qreal controlY READ controlY WRITE setControlY NOTIFY changed) public: - QmlGraphicsPathPrivate() : startX(0), startY(0) { } - - QPainterPath _path; - QList _pathElements; - mutable QVector _pointCache; - QList _attributePoints; - QStringList _attributes; - int startX; - int startY; + QmlGraphicsPathQuad(QObject *parent=0) : QmlGraphicsCurve(parent), _controlX(0), _controlY(0) {} + + qreal controlX() const; + void setControlX(qreal x); + + qreal controlY() const; + void setControlY(qreal y); + + void addToPath(QPainterPath &path); + +private: + qreal _controlX; + qreal _controlY; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsPathCubic : public QmlGraphicsCurve +{ + Q_OBJECT + + Q_PROPERTY(qreal control1X READ control1X WRITE setControl1X NOTIFY changed) + Q_PROPERTY(qreal control1Y READ control1Y WRITE setControl1Y NOTIFY changed) + Q_PROPERTY(qreal control2X READ control2X WRITE setControl2X NOTIFY changed) + Q_PROPERTY(qreal control2Y READ control2Y WRITE setControl2Y NOTIFY changed) +public: + QmlGraphicsPathCubic(QObject *parent=0) : QmlGraphicsCurve(parent), _control1X(0), _control1Y(0), _control2X(0), _control2Y(0) {} + + qreal control1X() const; + void setControl1X(qreal x); + + qreal control1Y() const; + void setControl1Y(qreal y); + + qreal control2X() const; + void setControl2X(qreal x); + + qreal control2Y() const; + void setControl2Y(qreal y); + + void addToPath(QPainterPath &path); + +private: + int _control1X; + int _control1Y; + int _control2X; + int _control2Y; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsPathPercent : public QmlGraphicsPathElement +{ + Q_OBJECT + Q_PROPERTY(qreal value READ value WRITE setValue) +public: + QmlGraphicsPathPercent(QObject *parent=0) : QmlGraphicsPathElement(parent) {} + + qreal value() const; + void setValue(qreal value); + +private: + qreal _value; +}; + +class QmlGraphicsPathPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsPath : public QObject, public QmlParserStatus +{ + Q_OBJECT + + Q_INTERFACES(QmlParserStatus) + Q_PROPERTY(QList* pathElements READ pathElements) + Q_PROPERTY(qreal startX READ startX WRITE setStartX) + Q_PROPERTY(qreal startY READ startY WRITE setStartY) + Q_CLASSINFO("DefaultProperty", "pathElements") + Q_INTERFACES(QmlParserStatus) +public: + QmlGraphicsPath(QObject *parent=0); + ~QmlGraphicsPath(); + + QList* pathElements(); + + qreal startX() const; + void setStartX(qreal x); + + qreal startY() const; + void setStartY(qreal y); + + QPainterPath path() const; + QStringList attributes() const; + qreal attributeAt(const QString &, qreal) const; + QPointF pointAt(qreal) const; + +Q_SIGNALS: + void changed(); + +protected: + virtual void componentComplete(); + QmlGraphicsPath(QmlGraphicsPathPrivate &dd, QObject *parent); + +private Q_SLOTS: + void processPath(); + +private: + struct AttributePoint { + AttributePoint() : percent(0), scale(1), origpercent(0) {} + AttributePoint(const AttributePoint &other) + : percent(other.percent), scale(other.scale), origpercent(other.origpercent), values(other.values) {} + AttributePoint &operator=(const AttributePoint &other) { + percent = other.percent; scale = other.scale; origpercent = other.origpercent; values = other.values; return *this; + } + qreal percent; //massaged percent along the painter path + qreal scale; + qreal origpercent; //'real' percent along the painter path + QHash values; + }; + + void interpolate(int idx, const QString &name, qreal value); + void endpoint(const QString &name); + void createPointCache() const; + +private: + Q_DISABLE_COPY(QmlGraphicsPath) + Q_DECLARE_PRIVATE(QmlGraphicsPath) }; QT_END_NAMESPACE -#endif + +QML_DECLARE_TYPE(QmlGraphicsPathElement) +QML_DECLARE_TYPE(QmlGraphicsPathAttribute) +QML_DECLARE_TYPE(QmlGraphicsCurve) +QML_DECLARE_TYPE(QmlGraphicsPathLine) +QML_DECLARE_TYPE(QmlGraphicsPathQuad) +QML_DECLARE_TYPE(QmlGraphicsPathCubic) +QML_DECLARE_TYPE(QmlGraphicsPathPercent) +QML_DECLARE_TYPE(QmlGraphicsPath) + +QT_END_HEADER + +#endif // QMLGRAPHICSPATH_H diff --git a/src/declarative/fx/qmlgraphicspath_p_p.h b/src/declarative/fx/qmlgraphicspath_p_p.h new file mode 100644 index 0000000..c974318 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspath_p_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSPATH_P_H +#define QMLGRAPHICSPATH_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/qobject_p.h" +#include "qmlgraphicspath_p.h" +#include "qml.h" + + +QT_BEGIN_NAMESPACE +class QmlGraphicsPathPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsPath) + +public: + QmlGraphicsPathPrivate() : startX(0), startY(0) { } + + QPainterPath _path; + QList _pathElements; + mutable QVector _pointCache; + QList _attributePoints; + QStringList _attributes; + int startX; + int startY; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/declarative/fx/qmlgraphicspathview.cpp b/src/declarative/fx/qmlgraphicspathview.cpp index 48d9fc8..74b8a97 100644 --- a/src/declarative/fx/qmlgraphicspathview.cpp +++ b/src/declarative/fx/qmlgraphicspathview.cpp @@ -42,12 +42,12 @@ #include #include #include -#include "qmlstate.h" -#include "qlistmodelinterface.h" -#include "qmlopenmetaobject.h" +#include +#include +#include -#include "qmlgraphicspathview.h" -#include "qmlgraphicspathview_p.h" +#include +#include #include static const int FlickThreshold = 5; @@ -910,4 +910,4 @@ QObject *QmlGraphicsPathView::qmlAttachedProperties(QObject *obj) QT_END_NAMESPACE -#include "qfxpathview.moc" +#include "qmlgraphicspathview.moc" diff --git a/src/declarative/fx/qmlgraphicspathview.h b/src/declarative/fx/qmlgraphicspathview.h deleted file mode 100644 index 3bb5d1f..0000000 --- a/src/declarative/fx/qmlgraphicspathview.h +++ /dev/null @@ -1,138 +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 QMLGRAPHICSPATHVIEW_H -#define QMLGRAPHICSPATHVIEW_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QListModelInterface; -class QmlGraphicsPathViewPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsPathView : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QmlGraphicsPath *path READ path WRITE setPath) - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged) - Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition) - Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin) - Q_PROPERTY(int count READ count) - Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount) - -public: - QmlGraphicsPathView(QmlGraphicsItem *parent=0); - virtual ~QmlGraphicsPathView(); - - QVariant model() const; - void setModel(const QVariant &); - - QmlGraphicsPath *path() const; - void setPath(QmlGraphicsPath *); - - int currentIndex() const; - void setCurrentIndex(int idx); - - qreal offset() const; - void setOffset(qreal offset); - - qreal snapPosition() const; - void setSnapPosition(qreal pos); - - qreal dragMargin() const; - void setDragMargin(qreal margin); - - int count() const; - - QmlComponent *delegate() const; - void setDelegate(QmlComponent *); - - int pathItemCount() const; - void setPathItemCount(int); - - static QObject *qmlAttachedProperties(QObject *); - -Q_SIGNALS: - void currentIndexChanged(); - void offsetChanged(); - -protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *); - bool sendMouseEvent(QGraphicsSceneMouseEvent *event); - bool sceneEventFilter(QGraphicsItem *, QEvent *); - void componentComplete(); - -private Q_SLOTS: - void refill(); - void ticked(); - void itemsInserted(int index, int count); - void itemsRemoved(int index, int count); - void createdItem(int index, QmlGraphicsItem *item); - void destroyingItem(QmlGraphicsItem *item); - -protected: - QmlGraphicsPathView(QmlGraphicsPathViewPrivate &dd, QmlGraphicsItem *parent); - -private: - friend class QmlGraphicsPathViewAttached; - static QHash attachedProperties; - Q_DISABLE_COPY(QmlGraphicsPathView) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsPathView) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsPathView) -QML_DECLARE_TYPEINFO(QmlGraphicsPathView, QML_HAS_ATTACHED_PROPERTIES) -QT_END_HEADER - -#endif // QMLGRAPHICSPATHVIEW_H diff --git a/src/declarative/fx/qmlgraphicspathview_p.h b/src/declarative/fx/qmlgraphicspathview_p.h index 22ee075..e2edcc9 100644 --- a/src/declarative/fx/qmlgraphicspathview_p.h +++ b/src/declarative/fx/qmlgraphicspathview_p.h @@ -39,113 +39,100 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSPATHVIEW_P_H -#define QMLGRAPHICSPATHVIEW_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 "qdatetime.h" -#include "qmlgraphicspathview.h" -#include "qmlgraphicsitem_p.h" -#include "qmlgraphicsvisualitemmodel.h" -#include "qml.h" -#include "private/qmlanimation_p.h" +#ifndef QMLGRAPHICSPATHVIEW_H +#define QMLGRAPHICSPATHVIEW_H + +#include +#include + +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -typedef struct PathViewItem{ - int index; - QmlGraphicsItem* item; -}PathViewItem; +QT_MODULE(Declarative) -class QmlGraphicsPathViewPrivate : public QmlGraphicsItemPrivate +class QListModelInterface; +class QmlGraphicsPathViewPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsPathView : public QmlGraphicsItem { - Q_DECLARE_PUBLIC(QmlGraphicsPathView) + Q_OBJECT + + Q_PROPERTY(QVariant model READ model WRITE setModel) + Q_PROPERTY(QmlGraphicsPath *path READ path WRITE setPath) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged) + Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition) + Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin) + Q_PROPERTY(int count READ count) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount) public: - QmlGraphicsPathViewPrivate() - : path(0), currentIndex(0), startPc(0), lastDist(0) - , lastElapsed(0), stealMouse(false), ownModel(false), activeItem(0) - , snapPos(0), dragMargin(0), moveOffset(this, &QmlGraphicsPathViewPrivate::setOffset) - , firstIndex(0), pathItems(-1), pathOffset(0), requestedIndex(-1), model(0) - , moveReason(Other) - { - fixupOffsetEvent = QmlTimeLineEvent::timeLineEvent(&moveOffset, this); - } - - void init() - { - Q_Q(QmlGraphicsPathView); - _offset = 0; - q->setAcceptedMouseButtons(Qt::LeftButton); - q->setFlag(QGraphicsItem::ItemIsFocusScope); - q->setFiltersChildEvents(true); - q->connect(&tl, SIGNAL(updated()), q, SLOT(ticked())); - } - - QmlGraphicsItem *getItem(int modelIndex) { - Q_Q(QmlGraphicsPathView); - requestedIndex = modelIndex; - QmlGraphicsItem *item = model->item(modelIndex); - if (item) - item->setParentItem(q); - requestedIndex = -1; - return item; - } - void releaseItem(QmlGraphicsItem *item) { - model->release(item); - } - - bool isValid() const { - return model && model->count() > 0 && model->isValid() && path; - } - - int calcCurrentIndex(); - void updateCurrent(); - void fixOffset(); + QmlGraphicsPathView(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsPathView(); + + QVariant model() const; + void setModel(const QVariant &); + + QmlGraphicsPath *path() const; + void setPath(QmlGraphicsPath *); + + int currentIndex() const; + void setCurrentIndex(int idx); + + qreal offset() const; void setOffset(qreal offset); - void regenerate(); - void updateItem(QmlGraphicsItem *, qreal); - void snapToCurrent(); - QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const; - - QmlGraphicsPath *path; - int currentIndex; - qreal startPc; - QPointF startPoint; - qreal lastDist; - int lastElapsed; - qreal _offset; - bool stealMouse : 1; - bool ownModel : 1; - QTime lastPosTime; - QPointF lastPos; - QmlGraphicsItem *activeItem; - qreal snapPos; - qreal dragMargin; - QmlTimeLine tl; - QmlTimeLineValueProxy moveOffset; - QmlTimeLineEvent fixupOffsetEvent; - int firstIndex; - int pathItems; - int pathOffset; - int requestedIndex; - QList items; - QmlGraphicsVisualModel *model; - QVariant modelVariant; - enum MovementReason { Other, Key, Mouse }; - MovementReason moveReason; + + qreal snapPosition() const; + void setSnapPosition(qreal pos); + + qreal dragMargin() const; + void setDragMargin(qreal margin); + + int count() const; + + QmlComponent *delegate() const; + void setDelegate(QmlComponent *); + + int pathItemCount() const; + void setPathItemCount(int); + + static QObject *qmlAttachedProperties(QObject *); + +Q_SIGNALS: + void currentIndexChanged(); + void offsetChanged(); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *); + bool sendMouseEvent(QGraphicsSceneMouseEvent *event); + bool sceneEventFilter(QGraphicsItem *, QEvent *); + void componentComplete(); + +private Q_SLOTS: + void refill(); + void ticked(); + void itemsInserted(int index, int count); + void itemsRemoved(int index, int count); + void createdItem(int index, QmlGraphicsItem *item); + void destroyingItem(QmlGraphicsItem *item); + +protected: + QmlGraphicsPathView(QmlGraphicsPathViewPrivate &dd, QmlGraphicsItem *parent); + +private: + friend class QmlGraphicsPathViewAttached; + static QHash attachedProperties; + Q_DISABLE_COPY(QmlGraphicsPathView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsPathView) }; QT_END_NAMESPACE -#endif +QML_DECLARE_TYPE(QmlGraphicsPathView) +QML_DECLARE_TYPEINFO(QmlGraphicsPathView, QML_HAS_ATTACHED_PROPERTIES) +QT_END_HEADER + +#endif // QMLGRAPHICSPATHVIEW_H diff --git a/src/declarative/fx/qmlgraphicspathview_p_p.h b/src/declarative/fx/qmlgraphicspathview_p_p.h new file mode 100644 index 0000000..87a5090 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspathview_p_p.h @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSPATHVIEW_P_H +#define QMLGRAPHICSPATHVIEW_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 "qdatetime.h" +#include "qmlgraphicspathview_p.h" +#include "qmlgraphicsitem_p.h" +#include "qmlgraphicsvisualitemmodel_p.h" +#include "qml.h" +#include "private/qmlanimation_p_p.h" + +QT_BEGIN_NAMESPACE + +typedef struct PathViewItem{ + int index; + QmlGraphicsItem* item; +}PathViewItem; + +class QmlGraphicsPathViewPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsPathView) + +public: + QmlGraphicsPathViewPrivate() + : path(0), currentIndex(0), startPc(0), lastDist(0) + , lastElapsed(0), stealMouse(false), ownModel(false), activeItem(0) + , snapPos(0), dragMargin(0), moveOffset(this, &QmlGraphicsPathViewPrivate::setOffset) + , firstIndex(0), pathItems(-1), pathOffset(0), requestedIndex(-1), model(0) + , moveReason(Other) + { + fixupOffsetEvent = QmlTimeLineEvent::timeLineEvent(&moveOffset, this); + } + + void init() + { + Q_Q(QmlGraphicsPathView); + _offset = 0; + q->setAcceptedMouseButtons(Qt::LeftButton); + q->setFlag(QGraphicsItem::ItemIsFocusScope); + q->setFiltersChildEvents(true); + q->connect(&tl, SIGNAL(updated()), q, SLOT(ticked())); + } + + QmlGraphicsItem *getItem(int modelIndex) { + Q_Q(QmlGraphicsPathView); + requestedIndex = modelIndex; + QmlGraphicsItem *item = model->item(modelIndex); + if (item) + item->setParentItem(q); + requestedIndex = -1; + return item; + } + void releaseItem(QmlGraphicsItem *item) { + model->release(item); + } + + bool isValid() const { + return model && model->count() > 0 && model->isValid() && path; + } + + int calcCurrentIndex(); + void updateCurrent(); + void fixOffset(); + void setOffset(qreal offset); + void regenerate(); + void updateItem(QmlGraphicsItem *, qreal); + void snapToCurrent(); + QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const; + + QmlGraphicsPath *path; + int currentIndex; + qreal startPc; + QPointF startPoint; + qreal lastDist; + int lastElapsed; + qreal _offset; + bool stealMouse : 1; + bool ownModel : 1; + QTime lastPosTime; + QPointF lastPos; + QmlGraphicsItem *activeItem; + qreal snapPos; + qreal dragMargin; + QmlTimeLine tl; + QmlTimeLineValueProxy moveOffset; + QmlTimeLineEvent fixupOffsetEvent; + int firstIndex; + int pathItems; + int pathOffset; + int requestedIndex; + QList items; + QmlGraphicsVisualModel *model; + QVariant modelVariant; + enum MovementReason { Other, Key, Mouse }; + MovementReason moveReason; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/declarative/fx/qmlgraphicspixmapcache.cpp b/src/declarative/fx/qmlgraphicspixmapcache.cpp index e347a8b..37a1e20 100644 --- a/src/declarative/fx/qmlgraphicspixmapcache.cpp +++ b/src/declarative/fx/qmlgraphicspixmapcache.cpp @@ -39,12 +39,12 @@ ** ****************************************************************************/ -#include "qmlgraphicspixmapcache.h" +#include "qmlgraphicspixmapcache_p.h" #include #include #include #include -#include +#include #include #include #include diff --git a/src/declarative/fx/qmlgraphicspixmapcache.h b/src/declarative/fx/qmlgraphicspixmapcache.h deleted file mode 100644 index 5094665..0000000 --- a/src/declarative/fx/qmlgraphicspixmapcache.h +++ /dev/null @@ -1,72 +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 QMLGRAPHICSPIXMAPCACHE_H -#define QMLGRAPHICSPIXMAPCACHE_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlEngine; -class QNetworkReply; -class Q_DECLARATIVE_EXPORT QmlGraphicsPixmapCache -{ -public: - static QNetworkReply *get(QmlEngine *, const QUrl& url, QPixmap *pixmap); - static void cancelGet(const QUrl& url, QObject* obj); - - static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QmlGraphicsPixmapCache::get, and any returned reply finished. - - static int pendingRequests(); // mainly for test verification -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMLGRAPHICSPIXMAPCACHE_H diff --git a/src/declarative/fx/qmlgraphicspixmapcache_p.h b/src/declarative/fx/qmlgraphicspixmapcache_p.h new file mode 100644 index 0000000..5094665 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspixmapcache_p.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSPIXMAPCACHE_H +#define QMLGRAPHICSPIXMAPCACHE_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlEngine; +class QNetworkReply; +class Q_DECLARATIVE_EXPORT QmlGraphicsPixmapCache +{ +public: + static QNetworkReply *get(QmlEngine *, const QUrl& url, QPixmap *pixmap); + static void cancelGet(const QUrl& url, QObject* obj); + + static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QmlGraphicsPixmapCache::get, and any returned reply finished. + + static int pendingRequests(); // mainly for test verification +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLGRAPHICSPIXMAPCACHE_H diff --git a/src/declarative/fx/qmlgraphicspositioners.cpp b/src/declarative/fx/qmlgraphicspositioners.cpp index 31950e6..3f8a915 100644 --- a/src/declarative/fx/qmlgraphicspositioners.cpp +++ b/src/declarative/fx/qmlgraphicspositioners.cpp @@ -42,12 +42,12 @@ #include #include #include "qml.h" -#include "qmlstate.h" -#include "qmlstategroup.h" -#include "qmlstateoperations.h" -#include "private/qfxperf_p.h" -#include "qmlgraphicspositioners.h" -#include "qmlgraphicspositioners_p.h" +#include +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicspositioners.h b/src/declarative/fx/qmlgraphicspositioners.h deleted file mode 100644 index e252ed8..0000000 --- a/src/declarative/fx/qmlgraphicspositioners.h +++ /dev/null @@ -1,167 +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 QMLGRAPHICSLAYOUTS_H -#define QMLGRAPHICSLAYOUTS_H - -#include -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlGraphicsBasePositionerPrivate; - -class Q_DECLARATIVE_EXPORT QmlGraphicsBasePositioner : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) - Q_PROPERTY(QmlTransition *move READ move WRITE setMove) - Q_PROPERTY(QmlTransition *add READ add WRITE setAdd) - Q_PROPERTY(QmlTransition *remove READ remove WRITE setRemove) -public: - enum AutoUpdateType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 }; - QmlGraphicsBasePositioner(AutoUpdateType, QmlGraphicsItem *parent); - - int spacing() const; - void setSpacing(int); - - QmlTransition *move() const; - void setMove(QmlTransition *); - - QmlTransition *add() const; - void setAdd(QmlTransition *); - - QmlTransition *remove() const; - void setRemove(QmlTransition *); - -protected: - virtual void componentComplete(); - virtual QVariant itemChange(GraphicsItemChange, const QVariant &); - virtual bool event(QEvent *); - QSet* newItems(); - QSet* leavingItems(); - QSet* items(); - void applyAdd(const QList >& changes, QmlGraphicsItem* target); - void applyMove(const QList >& changes, QmlGraphicsItem* target); - void applyRemove(const QList >& changes, QmlGraphicsItem* target); - void finishApplyTransitions(); - -Q_SIGNALS: - void layoutItemChanged(); - void spacingChanged(); - -protected Q_SLOTS: - virtual void doPositioning()=0; - -private Q_SLOTS: - void prePositioning(); - -protected: - QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, AutoUpdateType at, QmlGraphicsItem *parent); - void setMovingItem(QmlGraphicsItem *); - -private: - void applyTransition(const QList >& changes, QmlGraphicsItem* target, - QmlStateOperation::ActionList &actions); - Q_DISABLE_COPY(QmlGraphicsBasePositioner) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsBasePositioner) -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsColumn : public QmlGraphicsBasePositioner -{ - Q_OBJECT -public: - QmlGraphicsColumn(QmlGraphicsItem *parent=0); -protected Q_SLOTS: - virtual void doPositioning(); -private: - Q_DISABLE_COPY(QmlGraphicsColumn) -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsRow: public QmlGraphicsBasePositioner -{ - Q_OBJECT -public: - QmlGraphicsRow(QmlGraphicsItem *parent=0); -protected Q_SLOTS: - virtual void doPositioning(); -private: - Q_DISABLE_COPY(QmlGraphicsRow) -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGrid : public QmlGraphicsBasePositioner -{ - Q_OBJECT - Q_PROPERTY(int rows READ rows WRITE setRows) - Q_PROPERTY(int columns READ columns WRITE setcolumns) -public: - QmlGraphicsGrid(QmlGraphicsItem *parent=0); - - int rows() const {return _rows;} - void setRows(const int rows){_rows = rows;} - - int columns() const {return _columns;} - void setcolumns(const int columns){_columns = columns;} -protected Q_SLOTS: - virtual void doPositioning(); - -private: - int _rows; - int _columns; - Q_DISABLE_COPY(QmlGraphicsGrid) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsColumn) -QML_DECLARE_TYPE(QmlGraphicsRow) -QML_DECLARE_TYPE(QmlGraphicsGrid) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qmlgraphicspositioners_p.h b/src/declarative/fx/qmlgraphicspositioners_p.h index f8ca6fd..3304e76 100644 --- a/src/declarative/fx/qmlgraphicspositioners_p.h +++ b/src/declarative/fx/qmlgraphicspositioners_p.h @@ -39,67 +39,129 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSLAYOUTS_P_H -#define QMLGRAPHICSLAYOUTS_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 +#ifndef QMLGRAPHICSLAYOUTS_H +#define QMLGRAPHICSLAYOUTS_H + #include #include -#include -#include -#include -#include +#include +#include + + +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QmlGraphicsBasePositionerPrivate : public QmlGraphicsItemPrivate + +QT_MODULE(Declarative) +class QmlGraphicsBasePositionerPrivate; + +class Q_DECLARATIVE_EXPORT QmlGraphicsBasePositioner : public QmlGraphicsItem { - Q_DECLARE_PUBLIC(QmlGraphicsBasePositioner) + Q_OBJECT + Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) + Q_PROPERTY(QmlTransition *move READ move WRITE setMove) + Q_PROPERTY(QmlTransition *add READ add WRITE setAdd) + Q_PROPERTY(QmlTransition *remove READ remove WRITE setRemove) public: - QmlGraphicsBasePositionerPrivate() - : _ep(false), _componentComplete(false), _spacing(0), - aut(QmlGraphicsBasePositioner::None), moveTransition(0), addTransition(0), - removeTransition(0), _movingItem(0) - { - } - - void init(QmlGraphicsBasePositioner::AutoUpdateType at) - { - aut = at; - } - - bool _ep; - bool _componentComplete; - int _spacing; - QmlGraphicsBasePositioner::AutoUpdateType aut; - QmlTransition *moveTransition; - QmlTransition *addTransition; - QmlTransition *removeTransition; - QSet _items; - QSet _leavingItems; - QSet _stableItems; - QSet _newItems; - QSet _animated; - QmlStateOperation::ActionList addActions; - QmlStateOperation::ActionList moveActions; - QmlStateOperation::ActionList removeActions; - QmlTransitionManager addTransitionManager; - QmlTransitionManager moveTransitionManager; - QmlTransitionManager removeTransitionManager; -// QmlStateGroup *stateGroup; - QmlGraphicsItem *_movingItem; + enum AutoUpdateType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 }; + QmlGraphicsBasePositioner(AutoUpdateType, QmlGraphicsItem *parent); + + int spacing() const; + void setSpacing(int); + + QmlTransition *move() const; + void setMove(QmlTransition *); + + QmlTransition *add() const; + void setAdd(QmlTransition *); + + QmlTransition *remove() const; + void setRemove(QmlTransition *); + +protected: + virtual void componentComplete(); + virtual QVariant itemChange(GraphicsItemChange, const QVariant &); + virtual bool event(QEvent *); + QSet* newItems(); + QSet* leavingItems(); + QSet* items(); + void applyAdd(const QList >& changes, QmlGraphicsItem* target); + void applyMove(const QList >& changes, QmlGraphicsItem* target); + void applyRemove(const QList >& changes, QmlGraphicsItem* target); + void finishApplyTransitions(); + +Q_SIGNALS: + void layoutItemChanged(); + void spacingChanged(); + +protected Q_SLOTS: + virtual void doPositioning()=0; + +private Q_SLOTS: + void prePositioning(); + +protected: + QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, AutoUpdateType at, QmlGraphicsItem *parent); + void setMovingItem(QmlGraphicsItem *); + +private: + void applyTransition(const QList >& changes, QmlGraphicsItem* target, + QmlStateOperation::ActionList &actions); + Q_DISABLE_COPY(QmlGraphicsBasePositioner) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsBasePositioner) +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsColumn : public QmlGraphicsBasePositioner +{ + Q_OBJECT +public: + QmlGraphicsColumn(QmlGraphicsItem *parent=0); +protected Q_SLOTS: + virtual void doPositioning(); +private: + Q_DISABLE_COPY(QmlGraphicsColumn) +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsRow: public QmlGraphicsBasePositioner +{ + Q_OBJECT +public: + QmlGraphicsRow(QmlGraphicsItem *parent=0); +protected Q_SLOTS: + virtual void doPositioning(); +private: + Q_DISABLE_COPY(QmlGraphicsRow) +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGrid : public QmlGraphicsBasePositioner +{ + Q_OBJECT + Q_PROPERTY(int rows READ rows WRITE setRows) + Q_PROPERTY(int columns READ columns WRITE setcolumns) +public: + QmlGraphicsGrid(QmlGraphicsItem *parent=0); + + int rows() const {return _rows;} + void setRows(const int rows){_rows = rows;} + + int columns() const {return _columns;} + void setcolumns(const int columns){_columns = columns;} +protected Q_SLOTS: + virtual void doPositioning(); + +private: + int _rows; + int _columns; + Q_DISABLE_COPY(QmlGraphicsGrid) }; QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsColumn) +QML_DECLARE_TYPE(QmlGraphicsRow) +QML_DECLARE_TYPE(QmlGraphicsGrid) + +QT_END_HEADER + #endif diff --git a/src/declarative/fx/qmlgraphicspositioners_p_p.h b/src/declarative/fx/qmlgraphicspositioners_p_p.h new file mode 100644 index 0000000..571b815 --- /dev/null +++ b/src/declarative/fx/qmlgraphicspositioners_p_p.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSLAYOUTS_P_H +#define QMLGRAPHICSLAYOUTS_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 +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QmlGraphicsBasePositionerPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsBasePositioner) + +public: + QmlGraphicsBasePositionerPrivate() + : _ep(false), _componentComplete(false), _spacing(0), + aut(QmlGraphicsBasePositioner::None), moveTransition(0), addTransition(0), + removeTransition(0), _movingItem(0) + { + } + + void init(QmlGraphicsBasePositioner::AutoUpdateType at) + { + aut = at; + } + + bool _ep; + bool _componentComplete; + int _spacing; + QmlGraphicsBasePositioner::AutoUpdateType aut; + QmlTransition *moveTransition; + QmlTransition *addTransition; + QmlTransition *removeTransition; + QSet _items; + QSet _leavingItems; + QSet _stableItems; + QSet _newItems; + QSet _animated; + QmlStateOperation::ActionList addActions; + QmlStateOperation::ActionList moveActions; + QmlStateOperation::ActionList removeActions; + QmlTransitionManager addTransitionManager; + QmlTransitionManager moveTransitionManager; + QmlTransitionManager removeTransitionManager; +// QmlStateGroup *stateGroup; + QmlGraphicsItem *_movingItem; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/declarative/fx/qmlgraphicsrect.cpp b/src/declarative/fx/qmlgraphicsrect.cpp index 1784ae1..e5c226c 100644 --- a/src/declarative/fx/qmlgraphicsrect.cpp +++ b/src/declarative/fx/qmlgraphicsrect.cpp @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#include "qmlgraphicsrect.h" #include "qmlgraphicsrect_p.h" +#include "qmlgraphicsrect_p_p.h" #include #include diff --git a/src/declarative/fx/qmlgraphicsrect.h b/src/declarative/fx/qmlgraphicsrect.h deleted file mode 100644 index 454b2f1..0000000 --- a/src/declarative/fx/qmlgraphicsrect.h +++ /dev/null @@ -1,189 +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 QMLGRAPHICSRECT_H -#define QMLGRAPHICSRECT_H - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class Q_DECLARATIVE_EXPORT QmlGraphicsPen : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged) - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged) -public: - QmlGraphicsPen(QObject *parent=0) - : QObject(parent), _width(1), _color("#000000"), _valid(false) - {} - - int width() const { return _width; } - void setWidth(int w); - - QColor color() const { return _color; } - void setColor(const QColor &c); - - bool isValid() { return _valid; }; - -Q_SIGNALS: - void penChanged(); - -private: - int _width; - QColor _color; - bool _valid; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGradientStop : public QObject -{ - Q_OBJECT - - Q_PROPERTY(qreal position READ position WRITE setPosition) - Q_PROPERTY(QColor color READ color WRITE setColor) - -public: - QmlGraphicsGradientStop(QObject *parent=0) : QObject(parent) {} - - qreal position() const { return m_position; } - void setPosition(qreal position) { m_position = position; updateGradient(); } - - QColor color() const { return m_color; } - void setColor(const QColor &color) { m_color = color; updateGradient(); } - -private: - void updateGradient(); - -private: - qreal m_position; - QColor m_color; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGradient : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QList *stops READ stops) - Q_CLASSINFO("DefaultProperty", "stops") - -public: - QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} - ~QmlGraphicsGradient() { delete m_gradient; } - - QList *stops() { return &m_stops; } - - const QGradient *gradient() const; - -Q_SIGNALS: - void updated(); - -private: - void doUpdate(); - -private: - QList m_stops; - mutable QGradient *m_gradient; - friend class QmlGraphicsGradientStop; -}; - -class QmlGraphicsRectPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsRect : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) - Q_PROPERTY(QmlGraphicsGradient *gradient READ gradient WRITE setGradient) - Q_PROPERTY(QmlGraphicsPen * border READ border CONSTANT) - Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) -public: - QmlGraphicsRect(QmlGraphicsItem *parent=0); - - QColor color() const; - void setColor(const QColor &); - - QmlGraphicsPen *border(); - - QmlGraphicsGradient *gradient() const; - void setGradient(QmlGraphicsGradient *gradient); - - qreal radius() const; - void setRadius(qreal radius); - - QRectF boundingRect() const; - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -Q_SIGNALS: - void colorChanged(); - void radiusChanged(); - -private Q_SLOTS: - void doUpdate(); - -private: - void generateRoundedRect(); - void generateBorderedRect(); - void drawRect(QPainter &painter); - -protected: - QmlGraphicsRect(QmlGraphicsRectPrivate &dd, QmlGraphicsItem *parent); - -private: - Q_DISABLE_COPY(QmlGraphicsRect) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRect) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsPen) -QML_DECLARE_TYPE(QmlGraphicsGradientStop) -QML_DECLARE_TYPE(QmlGraphicsGradient) -QML_DECLARE_TYPE(QmlGraphicsRect) - -QT_END_HEADER - -#endif // QMLGRAPHICSRECT_H diff --git a/src/declarative/fx/qmlgraphicsrect_p.h b/src/declarative/fx/qmlgraphicsrect_p.h index f44e8de..454b2f1 100644 --- a/src/declarative/fx/qmlgraphicsrect_p.h +++ b/src/declarative/fx/qmlgraphicsrect_p.h @@ -39,71 +39,151 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSRECT_P_H -#define QMLGRAPHICSRECT_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 "qmlgraphicsitem_p.h" +#ifndef QMLGRAPHICSRECT_H +#define QMLGRAPHICSRECT_H + +#include +#include + + +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QmlGraphicsGradient; -class QmlGraphicsRect; -class QmlGraphicsRectPrivate : public QmlGraphicsItemPrivate +QT_MODULE(Declarative) +class Q_DECLARATIVE_EXPORT QmlGraphicsPen : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged) +public: + QmlGraphicsPen(QObject *parent=0) + : QObject(parent), _width(1), _color("#000000"), _valid(false) + {} + + int width() const { return _width; } + void setWidth(int w); + + QColor color() const { return _color; } + void setColor(const QColor &c); + + bool isValid() { return _valid; }; + +Q_SIGNALS: + void penChanged(); + +private: + int _width; + QColor _color; + bool _valid; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGradientStop : public QObject { - Q_DECLARE_PUBLIC(QmlGraphicsRect) + Q_OBJECT + + Q_PROPERTY(qreal position READ position WRITE setPosition) + Q_PROPERTY(QColor color READ color WRITE setColor) public: - QmlGraphicsRectPrivate() : - color(Qt::white), gradient(0), pen(0), radius(0), paintmargin(0) - { - } - - ~QmlGraphicsRectPrivate() - { - delete pen; - } - - void init() - { - } - - QColor getColor(); - QColor color; - QmlGraphicsGradient *gradient; - QmlGraphicsPen *getPen() { - if (!pen) { - Q_Q(QmlGraphicsRect); - pen = new QmlGraphicsPen; - QObject::connect(pen, SIGNAL(penChanged()), q, SLOT(doUpdate())); - } - return pen; - } - QmlGraphicsPen *pen; - qreal radius; - qreal paintmargin; - QPixmap rectImage; - - void setPaintMargin(qreal margin) - { - Q_Q(QmlGraphicsRect); - if (margin == paintmargin) - return; - q->prepareGeometryChange(); - paintmargin = margin; - } + QmlGraphicsGradientStop(QObject *parent=0) : QObject(parent) {} + + qreal position() const { return m_position; } + void setPosition(qreal position) { m_position = position; updateGradient(); } + + QColor color() const { return m_color; } + void setColor(const QColor &color) { m_color = color; updateGradient(); } + +private: + void updateGradient(); + +private: + qreal m_position; + QColor m_color; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGradient : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QList *stops READ stops) + Q_CLASSINFO("DefaultProperty", "stops") + +public: + QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} + ~QmlGraphicsGradient() { delete m_gradient; } + + QList *stops() { return &m_stops; } + + const QGradient *gradient() const; + +Q_SIGNALS: + void updated(); + +private: + void doUpdate(); + +private: + QList m_stops; + mutable QGradient *m_gradient; + friend class QmlGraphicsGradientStop; +}; + +class QmlGraphicsRectPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsRect : public QmlGraphicsItem +{ + Q_OBJECT + + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QmlGraphicsGradient *gradient READ gradient WRITE setGradient) + Q_PROPERTY(QmlGraphicsPen * border READ border CONSTANT) + Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) +public: + QmlGraphicsRect(QmlGraphicsItem *parent=0); + + QColor color() const; + void setColor(const QColor &); + + QmlGraphicsPen *border(); + + QmlGraphicsGradient *gradient() const; + void setGradient(QmlGraphicsGradient *gradient); + + qreal radius() const; + void setRadius(qreal radius); + + QRectF boundingRect() const; + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +Q_SIGNALS: + void colorChanged(); + void radiusChanged(); + +private Q_SLOTS: + void doUpdate(); + +private: + void generateRoundedRect(); + void generateBorderedRect(); + void drawRect(QPainter &painter); + +protected: + QmlGraphicsRect(QmlGraphicsRectPrivate &dd, QmlGraphicsItem *parent); + +private: + Q_DISABLE_COPY(QmlGraphicsRect) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRect) }; QT_END_NAMESPACE -#endif // QMLGRAPHICSRECT_P_H +QML_DECLARE_TYPE(QmlGraphicsPen) +QML_DECLARE_TYPE(QmlGraphicsGradientStop) +QML_DECLARE_TYPE(QmlGraphicsGradient) +QML_DECLARE_TYPE(QmlGraphicsRect) + +QT_END_HEADER + +#endif // QMLGRAPHICSRECT_H diff --git a/src/declarative/fx/qmlgraphicsrect_p_p.h b/src/declarative/fx/qmlgraphicsrect_p_p.h new file mode 100644 index 0000000..f44e8de --- /dev/null +++ b/src/declarative/fx/qmlgraphicsrect_p_p.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSRECT_P_H +#define QMLGRAPHICSRECT_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 "qmlgraphicsitem_p.h" + +QT_BEGIN_NAMESPACE + +class QmlGraphicsGradient; +class QmlGraphicsRect; +class QmlGraphicsRectPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsRect) + +public: + QmlGraphicsRectPrivate() : + color(Qt::white), gradient(0), pen(0), radius(0), paintmargin(0) + { + } + + ~QmlGraphicsRectPrivate() + { + delete pen; + } + + void init() + { + } + + QColor getColor(); + QColor color; + QmlGraphicsGradient *gradient; + QmlGraphicsPen *getPen() { + if (!pen) { + Q_Q(QmlGraphicsRect); + pen = new QmlGraphicsPen; + QObject::connect(pen, SIGNAL(penChanged()), q, SLOT(doUpdate())); + } + return pen; + } + QmlGraphicsPen *pen; + qreal radius; + qreal paintmargin; + QPixmap rectImage; + + void setPaintMargin(qreal margin) + { + Q_Q(QmlGraphicsRect); + if (margin == paintmargin) + return; + q->prepareGeometryChange(); + paintmargin = margin; + } +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSRECT_P_H diff --git a/src/declarative/fx/qmlgraphicsrepeater.cpp b/src/declarative/fx/qmlgraphicsrepeater.cpp index 608f948..c50c220 100644 --- a/src/declarative/fx/qmlgraphicsrepeater.cpp +++ b/src/declarative/fx/qmlgraphicsrepeater.cpp @@ -39,11 +39,11 @@ ** ****************************************************************************/ -#include "qmlgraphicsrepeater.h" #include "qmlgraphicsrepeater_p.h" -#include "qmllistaccessor.h" -#include "qmlgraphicsvisualitemmodel.h" -#include +#include "qmlgraphicsrepeater_p_p.h" +#include +#include +#include QT_BEGIN_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsrepeater.h b/src/declarative/fx/qmlgraphicsrepeater.h deleted file mode 100644 index 9cb7d45..0000000 --- a/src/declarative/fx/qmlgraphicsrepeater.h +++ /dev/null @@ -1,103 +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 QMLGRAPHICSREPEATER_H -#define QMLGRAPHICSREPEATER_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsRepeaterPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsRepeater : public QmlGraphicsItem -{ - Q_OBJECT - - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_CLASSINFO("DefaultProperty", "delegate") - -public: - QmlGraphicsRepeater(QmlGraphicsItem *parent=0); - virtual ~QmlGraphicsRepeater(); - - QVariant model() const; - void setModel(const QVariant &); - - QmlComponent *delegate() const; - void setDelegate(QmlComponent *); - - int count() const; - -Q_SIGNALS: - void countChanged(); - -private: - void clear(); - void regenerate(); - -protected: - virtual void componentComplete(); - QVariant itemChange(GraphicsItemChange change, const QVariant &value); - QmlGraphicsRepeater(QmlGraphicsRepeaterPrivate &dd, QmlGraphicsItem *parent); - -private Q_SLOTS: - void itemsInserted(int,int); - void itemsRemoved(int,int); - void itemsMoved(int,int,int); - -private: - Q_DISABLE_COPY(QmlGraphicsRepeater) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRepeater) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsRepeater) - -QT_END_HEADER - -#endif // QMLGRAPHICSREPEATER_H diff --git a/src/declarative/fx/qmlgraphicsrepeater_p.h b/src/declarative/fx/qmlgraphicsrepeater_p.h index 7c111da..9cb7d45 100644 --- a/src/declarative/fx/qmlgraphicsrepeater_p.h +++ b/src/declarative/fx/qmlgraphicsrepeater_p.h @@ -39,43 +39,65 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSREPEATER_P_H -#define QMLGRAPHICSREPEATER_P_H +#ifndef QMLGRAPHICSREPEATER_H +#define QMLGRAPHICSREPEATER_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 "qmlgraphicsitem_p.h" -#include "qmlgraphicsrepeater.h" -#include +#include +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QmlContext; -class QmlGraphicsVisualModel; -class QmlGraphicsRepeaterPrivate : public QmlGraphicsItemPrivate +QT_MODULE(Declarative) + +class QmlGraphicsRepeaterPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsRepeater : public QmlGraphicsItem { - Q_DECLARE_PUBLIC(QmlGraphicsRepeater) + Q_OBJECT + + Q_PROPERTY(QVariant model READ model WRITE setModel) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_CLASSINFO("DefaultProperty", "delegate") public: - QmlGraphicsRepeaterPrivate(); - ~QmlGraphicsRepeaterPrivate(); + QmlGraphicsRepeater(QmlGraphicsItem *parent=0); + virtual ~QmlGraphicsRepeater(); + + QVariant model() const; + void setModel(const QVariant &); + + QmlComponent *delegate() const; + void setDelegate(QmlComponent *); + + int count() const; - QmlGraphicsVisualModel *model; - QVariant dataSource; - bool ownModel; +Q_SIGNALS: + void countChanged(); - QList > deletables; +private: + void clear(); + void regenerate(); + +protected: + virtual void componentComplete(); + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + QmlGraphicsRepeater(QmlGraphicsRepeaterPrivate &dd, QmlGraphicsItem *parent); + +private Q_SLOTS: + void itemsInserted(int,int); + void itemsRemoved(int,int); + void itemsMoved(int,int,int); + +private: + Q_DISABLE_COPY(QmlGraphicsRepeater) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsRepeater) }; QT_END_NAMESPACE -#endif // QMLGRAPHICSREPEATER_P_H + +QML_DECLARE_TYPE(QmlGraphicsRepeater) + +QT_END_HEADER + +#endif // QMLGRAPHICSREPEATER_H diff --git a/src/declarative/fx/qmlgraphicsrepeater_p_p.h b/src/declarative/fx/qmlgraphicsrepeater_p_p.h new file mode 100644 index 0000000..d8b83be --- /dev/null +++ b/src/declarative/fx/qmlgraphicsrepeater_p_p.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSREPEATER_P_H +#define QMLGRAPHICSREPEATER_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 "qmlgraphicsitem_p.h" +#include "qmlgraphicsrepeater_p.h" +#include + + +QT_BEGIN_NAMESPACE + +class QmlContext; +class QmlGraphicsVisualModel; +class QmlGraphicsRepeaterPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsRepeater) + +public: + QmlGraphicsRepeaterPrivate(); + ~QmlGraphicsRepeaterPrivate(); + + QmlGraphicsVisualModel *model; + QVariant dataSource; + bool ownModel; + + QList > deletables; +}; + +QT_END_NAMESPACE +#endif // QMLGRAPHICSREPEATER_P_H diff --git a/src/declarative/fx/qmlgraphicsscalegrid.cpp b/src/declarative/fx/qmlgraphicsscalegrid.cpp index fdf44cf..251f823 100644 --- a/src/declarative/fx/qmlgraphicsscalegrid.cpp +++ b/src/declarative/fx/qmlgraphicsscalegrid.cpp @@ -42,7 +42,7 @@ #include #include #include -#include "qmlgraphicsscalegrid_p.h" +#include "qmlgraphicsscalegrid_p_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/fx/qmlgraphicsscalegrid_p.h b/src/declarative/fx/qmlgraphicsscalegrid_p.h deleted file mode 100644 index 040db4c..0000000 --- a/src/declarative/fx/qmlgraphicsscalegrid_p.h +++ /dev/null @@ -1,133 +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 QMLGRAPHICSSCALEGRID_H -#define QMLGRAPHICSSCALEGRID_H - -#include -#include -#include -#include -#include -#include "qmlgraphicsborderimage.h" - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QmlGraphicsScaleGrid : public QObject -{ - Q_OBJECT - Q_ENUMS(TileRule) - - Q_PROPERTY(int left READ left WRITE setLeft NOTIFY borderChanged) - Q_PROPERTY(int top READ top WRITE setTop NOTIFY borderChanged) - Q_PROPERTY(int right READ right WRITE setRight NOTIFY borderChanged) - Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY borderChanged) - -public: - QmlGraphicsScaleGrid(QObject *parent=0); - ~QmlGraphicsScaleGrid(); - - bool isNull() const; - - int left() const { return _left; } - void setLeft(int); - - int top() const { return _top; } - void setTop(int); - - int right() const { return _right; } - void setRight(int); - - int bottom() const { return _bottom; } - void setBottom(int); - -Q_SIGNALS: - void borderChanged(); - -private: - int _left; - int _top; - int _right; - int _bottom; -}; - -class Q_DECLARATIVE_EXPORT QmlGraphicsGridScaledImage -{ -public: - QmlGraphicsGridScaledImage(); - QmlGraphicsGridScaledImage(const QmlGraphicsGridScaledImage &); - QmlGraphicsGridScaledImage(QIODevice*); - QmlGraphicsGridScaledImage &operator=(const QmlGraphicsGridScaledImage &); - bool isValid() const; - int gridLeft() const; - int gridRight() const; - int gridTop() const; - int gridBottom() const; - QmlGraphicsBorderImage::TileMode horizontalTileRule() const { return _h; } - QmlGraphicsBorderImage::TileMode verticalTileRule() const { return _v; } - - QString pixmapUrl() const; - -private: - static QmlGraphicsBorderImage::TileMode stringToRule(const QString &); - -private: - int _l; - int _r; - int _t; - int _b; - QmlGraphicsBorderImage::TileMode _h; - QmlGraphicsBorderImage::TileMode _v; - QString _pix; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsScaleGrid) - -QT_END_HEADER - -#endif // QMLGRAPHICSSCALEGRID_H diff --git a/src/declarative/fx/qmlgraphicsscalegrid_p_p.h b/src/declarative/fx/qmlgraphicsscalegrid_p_p.h new file mode 100644 index 0000000..d5acca2 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsscalegrid_p_p.h @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSSCALEGRID_H +#define QMLGRAPHICSSCALEGRID_H + +#include +#include +#include +#include +#include +#include "qmlgraphicsborderimage_p.h" + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class Q_DECLARATIVE_EXPORT QmlGraphicsScaleGrid : public QObject +{ + Q_OBJECT + Q_ENUMS(TileRule) + + Q_PROPERTY(int left READ left WRITE setLeft NOTIFY borderChanged) + Q_PROPERTY(int top READ top WRITE setTop NOTIFY borderChanged) + Q_PROPERTY(int right READ right WRITE setRight NOTIFY borderChanged) + Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY borderChanged) + +public: + QmlGraphicsScaleGrid(QObject *parent=0); + ~QmlGraphicsScaleGrid(); + + bool isNull() const; + + int left() const { return _left; } + void setLeft(int); + + int top() const { return _top; } + void setTop(int); + + int right() const { return _right; } + void setRight(int); + + int bottom() const { return _bottom; } + void setBottom(int); + +Q_SIGNALS: + void borderChanged(); + +private: + int _left; + int _top; + int _right; + int _bottom; +}; + +class Q_DECLARATIVE_EXPORT QmlGraphicsGridScaledImage +{ +public: + QmlGraphicsGridScaledImage(); + QmlGraphicsGridScaledImage(const QmlGraphicsGridScaledImage &); + QmlGraphicsGridScaledImage(QIODevice*); + QmlGraphicsGridScaledImage &operator=(const QmlGraphicsGridScaledImage &); + bool isValid() const; + int gridLeft() const; + int gridRight() const; + int gridTop() const; + int gridBottom() const; + QmlGraphicsBorderImage::TileMode horizontalTileRule() const { return _h; } + QmlGraphicsBorderImage::TileMode verticalTileRule() const { return _v; } + + QString pixmapUrl() const; + +private: + static QmlGraphicsBorderImage::TileMode stringToRule(const QString &); + +private: + int _l; + int _r; + int _t; + int _b; + QmlGraphicsBorderImage::TileMode _h; + QmlGraphicsBorderImage::TileMode _v; + QString _pix; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsScaleGrid) + +QT_END_HEADER + +#endif // QMLGRAPHICSSCALEGRID_H diff --git a/src/declarative/fx/qmlgraphicstext.cpp b/src/declarative/fx/qmlgraphicstext.cpp index f5ea55f..0b88cc5 100644 --- a/src/declarative/fx/qmlgraphicstext.cpp +++ b/src/declarative/fx/qmlgraphicstext.cpp @@ -39,11 +39,11 @@ ** ****************************************************************************/ -#include "qmlgraphicstext.h" #include "qmlgraphicstext_p.h" +#include "qmlgraphicstext_p_p.h" #include -#include +#include #include #include #include diff --git a/src/declarative/fx/qmlgraphicstext.h b/src/declarative/fx/qmlgraphicstext.h deleted file mode 100644 index 619de87..0000000 --- a/src/declarative/fx/qmlgraphicstext.h +++ /dev/null @@ -1,151 +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 QMLGRAPHICSTEXT_H -#define QMLGRAPHICSTEXT_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlGraphicsTextPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsText : public QmlGraphicsItem -{ - Q_OBJECT - Q_ENUMS(HAlignment) - Q_ENUMS(VAlignment) - Q_ENUMS(TextStyle) - Q_ENUMS(TextFormat) - Q_ENUMS(TextElideMode) - - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(TextStyle style READ style WRITE setStyle) - Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor) - Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) - Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign) - Q_PROPERTY(bool wrap READ wrap WRITE setWrap) //### there are several wrap modes in Qt - Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) - Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode) //### elideMode? - -public: - QmlGraphicsText(QmlGraphicsItem *parent=0); - ~QmlGraphicsText(); - - enum HAlignment { AlignLeft = Qt::AlignLeft, - AlignRight = Qt::AlignRight, - AlignHCenter = Qt::AlignHCenter }; - enum VAlignment { AlignTop = Qt::AlignTop, - AlignBottom = Qt::AlignBottom, - AlignVCenter = Qt::AlignVCenter }; - enum TextStyle { Normal, - Outline, - Raised, - Sunken }; - enum TextFormat { PlainText = Qt::PlainText, - RichText = Qt::RichText, - AutoText = Qt::AutoText }; - enum TextElideMode { ElideLeft = Qt::ElideLeft, - ElideRight = Qt::ElideRight, - ElideMiddle = Qt::ElideMiddle, - ElideNone = Qt::ElideNone }; - - QString text() const; - void setText(const QString &); - - QFont font() const; - void setFont(const QFont &font); - - QColor color() const; - void setColor(const QColor &c); - - TextStyle style() const; - void setStyle(TextStyle style); - - QColor styleColor() const; - void setStyleColor(const QColor &c); - - HAlignment hAlign() const; - void setHAlign(HAlignment align); - - VAlignment vAlign() const; - void setVAlign(VAlignment align); - - bool wrap() const; - void setWrap(bool w); - - TextFormat textFormat() const; - void setTextFormat(TextFormat format); - - TextElideMode elideMode() const; - void setElideMode(TextElideMode); - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - - virtual void componentComplete(); - -Q_SIGNALS: - void textChanged(const QString &text); - void linkActivated(const QString &link); - -protected: - QmlGraphicsText(QmlGraphicsTextPrivate &dd, QmlGraphicsItem *parent); - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - -private: - Q_DISABLE_COPY(QmlGraphicsText) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsText) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsText) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qmlgraphicstext_p.h b/src/declarative/fx/qmlgraphicstext_p.h index bf14c6f..619de87 100644 --- a/src/declarative/fx/qmlgraphicstext_p.h +++ b/src/declarative/fx/qmlgraphicstext_p.h @@ -39,75 +39,113 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSTEXT_P_H -#define QMLGRAPHICSTEXT_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 "qmlgraphicsitem.h" -#include "qmlgraphicsitem_p.h" -#include "qml.h" -#include +#ifndef QMLGRAPHICSTEXT_H +#define QMLGRAPHICSTEXT_H -QT_BEGIN_NAMESPACE +#include + +QT_BEGIN_HEADER -class QTextLayout; -class QTextDocument; -class QTextControl; +QT_BEGIN_NAMESPACE -class QmlGraphicsTextPrivate : public QmlGraphicsItemPrivate +QT_MODULE(Declarative) +class QmlGraphicsTextPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsText : public QmlGraphicsItem { - Q_DECLARE_PUBLIC(QmlGraphicsText) + Q_OBJECT + Q_ENUMS(HAlignment) + Q_ENUMS(VAlignment) + Q_ENUMS(TextStyle) + Q_ENUMS(TextFormat) + Q_ENUMS(TextElideMode) + + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(TextStyle style READ style WRITE setStyle) + Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor) + Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) + Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign) + Q_PROPERTY(bool wrap READ wrap WRITE setWrap) //### there are several wrap modes in Qt + Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) + Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode) //### elideMode? + public: - QmlGraphicsTextPrivate() - : color((QRgb)0), style(QmlGraphicsText::Normal), imgDirty(true), - hAlign(QmlGraphicsText::AlignLeft), vAlign(QmlGraphicsText::AlignTop), elideMode(QmlGraphicsText::ElideNone), - dirty(true), wrap(false), richText(false), singleline(false), control(0), doc(0), - format(QmlGraphicsText::AutoText) - { - } - - void updateSize(); - void checkImgCache(); - - void drawOutline(); - void drawOutline(int yOffset); - - QPixmap wrappedTextImage(bool drawStyle); - QPixmap richTextImage(bool drawStyle); - QSize setupTextLayout(QTextLayout *layout); - - QString text; - QFont font; - QColor color; - QmlGraphicsText::TextStyle style; - QColor styleColor; - QString activeLink; - bool imgDirty; - QPixmap imgCache; - QPixmap imgStyleCache; - QmlGraphicsText::HAlignment hAlign; - QmlGraphicsText::VAlignment vAlign; - QmlGraphicsText::TextElideMode elideMode; - bool dirty; - bool wrap; - bool richText; - bool singleline; - QTextControl *control; - QTextDocument *doc; - QTextLayout layout; - QSize cachedLayoutSize; - QmlGraphicsText::TextFormat format; + QmlGraphicsText(QmlGraphicsItem *parent=0); + ~QmlGraphicsText(); + + enum HAlignment { AlignLeft = Qt::AlignLeft, + AlignRight = Qt::AlignRight, + AlignHCenter = Qt::AlignHCenter }; + enum VAlignment { AlignTop = Qt::AlignTop, + AlignBottom = Qt::AlignBottom, + AlignVCenter = Qt::AlignVCenter }; + enum TextStyle { Normal, + Outline, + Raised, + Sunken }; + enum TextFormat { PlainText = Qt::PlainText, + RichText = Qt::RichText, + AutoText = Qt::AutoText }; + enum TextElideMode { ElideLeft = Qt::ElideLeft, + ElideRight = Qt::ElideRight, + ElideMiddle = Qt::ElideMiddle, + ElideNone = Qt::ElideNone }; + + QString text() const; + void setText(const QString &); + + QFont font() const; + void setFont(const QFont &font); + + QColor color() const; + void setColor(const QColor &c); + + TextStyle style() const; + void setStyle(TextStyle style); + + QColor styleColor() const; + void setStyleColor(const QColor &c); + + HAlignment hAlign() const; + void setHAlign(HAlignment align); + + VAlignment vAlign() const; + void setVAlign(VAlignment align); + + bool wrap() const; + void setWrap(bool w); + + TextFormat textFormat() const; + void setTextFormat(TextFormat format); + + TextElideMode elideMode() const; + void setElideMode(TextElideMode); + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + + virtual void componentComplete(); + +Q_SIGNALS: + void textChanged(const QString &text); + void linkActivated(const QString &link); + +protected: + QmlGraphicsText(QmlGraphicsTextPrivate &dd, QmlGraphicsItem *parent); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + +private: + Q_DISABLE_COPY(QmlGraphicsText) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsText) }; QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsText) + +QT_END_HEADER + #endif diff --git a/src/declarative/fx/qmlgraphicstext_p_p.h b/src/declarative/fx/qmlgraphicstext_p_p.h new file mode 100644 index 0000000..bf14c6f --- /dev/null +++ b/src/declarative/fx/qmlgraphicstext_p_p.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSTEXT_P_H +#define QMLGRAPHICSTEXT_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 "qmlgraphicsitem.h" +#include "qmlgraphicsitem_p.h" +#include "qml.h" +#include + +QT_BEGIN_NAMESPACE + +class QTextLayout; +class QTextDocument; +class QTextControl; + +class QmlGraphicsTextPrivate : public QmlGraphicsItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsText) +public: + QmlGraphicsTextPrivate() + : color((QRgb)0), style(QmlGraphicsText::Normal), imgDirty(true), + hAlign(QmlGraphicsText::AlignLeft), vAlign(QmlGraphicsText::AlignTop), elideMode(QmlGraphicsText::ElideNone), + dirty(true), wrap(false), richText(false), singleline(false), control(0), doc(0), + format(QmlGraphicsText::AutoText) + { + } + + void updateSize(); + void checkImgCache(); + + void drawOutline(); + void drawOutline(int yOffset); + + QPixmap wrappedTextImage(bool drawStyle); + QPixmap richTextImage(bool drawStyle); + QSize setupTextLayout(QTextLayout *layout); + + QString text; + QFont font; + QColor color; + QmlGraphicsText::TextStyle style; + QColor styleColor; + QString activeLink; + bool imgDirty; + QPixmap imgCache; + QPixmap imgStyleCache; + QmlGraphicsText::HAlignment hAlign; + QmlGraphicsText::VAlignment vAlign; + QmlGraphicsText::TextElideMode elideMode; + bool dirty; + bool wrap; + bool richText; + bool singleline; + QTextControl *control; + QTextDocument *doc; + QTextLayout layout; + QSize cachedLayoutSize; + QmlGraphicsText::TextFormat format; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/declarative/fx/qmlgraphicstextedit.cpp b/src/declarative/fx/qmlgraphicstextedit.cpp index 24c64c1..a42ccdd 100644 --- a/src/declarative/fx/qmlgraphicstextedit.cpp +++ b/src/declarative/fx/qmlgraphicstextedit.cpp @@ -39,11 +39,11 @@ ** ****************************************************************************/ -#include #include "qmlgraphicstextedit_p.h" +#include "qmlgraphicstextedit_p_p.h" #include -#include -#include "qmlgraphicsevents_p.h" +#include +#include #include #include #include diff --git a/src/declarative/fx/qmlgraphicstextedit.h b/src/declarative/fx/qmlgraphicstextedit.h deleted file mode 100644 index 57f7449..0000000 --- a/src/declarative/fx/qmlgraphicstextedit.h +++ /dev/null @@ -1,234 +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 QMLGRAPHICSTEXTEDIT_H -#define QMLGRAPHICSTEXTEDIT_H - -#include -#include - -#include -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QmlGraphicsTextEditPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsTextEdit : public QmlGraphicsPaintedItem -{ - Q_OBJECT - Q_ENUMS(VAlignment) - Q_ENUMS(HAlignment) - Q_ENUMS(TextFormat) - - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) - Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign) - Q_PROPERTY(bool wrap READ wrap WRITE setWrap) //### other wrap modes - Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) - Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) - Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) - Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) - Q_PROPERTY(QmlComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate) - Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) - Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) - Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged) - Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) - Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection) - Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin) - -public: - QmlGraphicsTextEdit(QmlGraphicsItem *parent=0); - - enum HAlignment { - AlignLeft = Qt::AlignLeft, - AlignRight = Qt::AlignRight, - AlignHCenter = Qt::AlignHCenter - }; - - enum VAlignment { - AlignTop = Qt::AlignTop, - AlignBottom = Qt::AlignBottom, - AlignVCenter = Qt::AlignVCenter - }; - - enum TextFormat { - PlainText = Qt::PlainText, - RichText = Qt::RichText, - AutoText = Qt::AutoText - }; - - QString text() const; - void setText(const QString &); - - TextFormat textFormat() const; - void setTextFormat(TextFormat format); - - QFont font() const; - void setFont(const QFont &font); - - QColor color() const; - void setColor(const QColor &c); - - QColor selectionColor() const; - void setSelectionColor(const QColor &c); - - QColor selectedTextColor() const; - void setSelectedTextColor(const QColor &c); - - HAlignment hAlign() const; - void setHAlign(HAlignment align); - - VAlignment vAlign() const; - void setVAlign(VAlignment align); - - bool wrap() const; - void setWrap(bool w); - - bool isCursorVisible() const; - void setCursorVisible(bool on); - - int cursorPosition() const; - void setCursorPosition(int pos); - - QmlComponent* cursorDelegate() const; - void setCursorDelegate(QmlComponent*); - - int selectionStart() const; - void setSelectionStart(int); - - int selectionEnd() const; - void setSelectionEnd(int); - - QString selectedText() const; - - bool focusOnPress() const; - void setFocusOnPress(bool on); - - bool persistentSelection() const; - void setPersistentSelection(bool on); - - qreal textMargin() const; - void setTextMargin(qreal margin); - - virtual void componentComplete(); - - /* FROM EDIT */ - void setReadOnly(bool); - bool isReadOnly() const; - - void setTextInteractionFlags(Qt::TextInteractionFlags flags); - Qt::TextInteractionFlags textInteractionFlags() const; - - QTextCursor cursorForPosition(const QPoint &pos) const; - QRect cursorRect(const QTextCursor &cursor) const; - QRect cursorRect() const; - - void setTextCursor(const QTextCursor &cursor); - QTextCursor textCursor() const; - - void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor); - - QVariant inputMethodQuery(Qt::InputMethodQuery property) const; - -Q_SIGNALS: - void textChanged(const QString &); - void cursorPositionChanged(); - void selectionStartChanged(); - void selectionEndChanged(); - void selectionChanged(); - -public Q_SLOTS: - void selectAll(); - -private Q_SLOTS: - void updateImgCache(const QRectF &rect); - void q_textChanged(); - void updateSelectionMarkers(); - void moveCursorDelegate(); - void loadCursorDelegate(); - -private: - void updateSize(); - -protected: - QmlGraphicsTextEdit(QmlGraphicsTextEditPrivate &dd, QmlGraphicsItem *parent); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - - bool event(QEvent *); - void keyPressEvent(QKeyEvent *); - void keyReleaseEvent(QKeyEvent *); - - void focusChanged(bool); - - // mouse filter? - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - - void inputMethodEvent(QInputMethodEvent *e); - - void drawContents(QPainter *, const QRect &); -private: - Q_DISABLE_COPY(QmlGraphicsTextEdit) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsTextEdit) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsTextEdit) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qmlgraphicstextedit_p.h b/src/declarative/fx/qmlgraphicstextedit_p.h index 7a163f8..57a9327 100644 --- a/src/declarative/fx/qmlgraphicstextedit_p.h +++ b/src/declarative/fx/qmlgraphicstextedit_p.h @@ -39,75 +39,196 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSTEXTEDIT_P_H -#define QMLGRAPHICSTEXTEDIT_P_H +#ifndef QMLGRAPHICSTEXTEDIT_H +#define QMLGRAPHICSTEXTEDIT_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 +#include -#include "qmlgraphicsitem.h" -#include "qmlgraphicspainteditem_p.h" -#include "qml.h" +#include +#include +#include +#include +QT_BEGIN_HEADER + QT_BEGIN_NAMESPACE -class QTextLayout; -class QTextDocument; -class QTextControl; -class QmlGraphicsTextEditPrivate : public QmlGraphicsPaintedItemPrivate + +QT_MODULE(Declarative) + + +class QmlGraphicsTextEditPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsTextEdit : public QmlGraphicsPaintedItem { - Q_DECLARE_PUBLIC(QmlGraphicsTextEdit) + Q_OBJECT + Q_ENUMS(VAlignment) + Q_ENUMS(HAlignment) + Q_ENUMS(TextFormat) + + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) + Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign) + Q_PROPERTY(bool wrap READ wrap WRITE setWrap) //### other wrap modes + Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) + Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) + Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) + Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) + Q_PROPERTY(QmlComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate) + Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) + Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) + Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged) + Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) + Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection) + Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin) public: - QmlGraphicsTextEditPrivate() - : color("black"), imgDirty(true), hAlign(QmlGraphicsTextEdit::AlignLeft), vAlign(QmlGraphicsTextEdit::AlignTop), - dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(false), - persistentSelection(true), textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0), - cursorComponent(0), cursor(0), format(QmlGraphicsTextEdit::AutoText), document(0) - { - } - - void init(); - - void updateDefaultTextOption(); - void relayoutDocument(); - void updateSelection(); - - QString text; - QFont font; - QColor color; - QColor selectionColor; - QColor selectedTextColor; - QString style; - QColor styleColor; - bool imgDirty; - QPixmap imgCache; - QPixmap imgStyleCache; - QmlGraphicsTextEdit::HAlignment hAlign; - QmlGraphicsTextEdit::VAlignment vAlign; - bool dirty; - bool wrap; - bool richText; - bool cursorVisible; - bool focusOnPress; - bool persistentSelection; - qreal textMargin; - int lastSelectionStart; - int lastSelectionEnd; - QmlComponent* cursorComponent; - QmlGraphicsItem* cursor; - QmlGraphicsTextEdit::TextFormat format; - QTextDocument *document; - QTextControl *control; + QmlGraphicsTextEdit(QmlGraphicsItem *parent=0); + + enum HAlignment { + AlignLeft = Qt::AlignLeft, + AlignRight = Qt::AlignRight, + AlignHCenter = Qt::AlignHCenter + }; + + enum VAlignment { + AlignTop = Qt::AlignTop, + AlignBottom = Qt::AlignBottom, + AlignVCenter = Qt::AlignVCenter + }; + + enum TextFormat { + PlainText = Qt::PlainText, + RichText = Qt::RichText, + AutoText = Qt::AutoText + }; + + QString text() const; + void setText(const QString &); + + TextFormat textFormat() const; + void setTextFormat(TextFormat format); + + QFont font() const; + void setFont(const QFont &font); + + QColor color() const; + void setColor(const QColor &c); + + QColor selectionColor() const; + void setSelectionColor(const QColor &c); + + QColor selectedTextColor() const; + void setSelectedTextColor(const QColor &c); + + HAlignment hAlign() const; + void setHAlign(HAlignment align); + + VAlignment vAlign() const; + void setVAlign(VAlignment align); + + bool wrap() const; + void setWrap(bool w); + + bool isCursorVisible() const; + void setCursorVisible(bool on); + + int cursorPosition() const; + void setCursorPosition(int pos); + + QmlComponent* cursorDelegate() const; + void setCursorDelegate(QmlComponent*); + + int selectionStart() const; + void setSelectionStart(int); + + int selectionEnd() const; + void setSelectionEnd(int); + + QString selectedText() const; + + bool focusOnPress() const; + void setFocusOnPress(bool on); + + bool persistentSelection() const; + void setPersistentSelection(bool on); + + qreal textMargin() const; + void setTextMargin(qreal margin); + + virtual void componentComplete(); + + /* FROM EDIT */ + void setReadOnly(bool); + bool isReadOnly() const; + + void setTextInteractionFlags(Qt::TextInteractionFlags flags); + Qt::TextInteractionFlags textInteractionFlags() const; + + QTextCursor cursorForPosition(const QPoint &pos) const; + QRect cursorRect(const QTextCursor &cursor) const; + QRect cursorRect() const; + + void setTextCursor(const QTextCursor &cursor); + QTextCursor textCursor() const; + + void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor); + + QVariant inputMethodQuery(Qt::InputMethodQuery property) const; + +Q_SIGNALS: + void textChanged(const QString &); + void cursorPositionChanged(); + void selectionStartChanged(); + void selectionEndChanged(); + void selectionChanged(); + +public Q_SLOTS: + void selectAll(); + +private Q_SLOTS: + void updateImgCache(const QRectF &rect); + void q_textChanged(); + void updateSelectionMarkers(); + void moveCursorDelegate(); + void loadCursorDelegate(); + +private: + void updateSize(); + +protected: + QmlGraphicsTextEdit(QmlGraphicsTextEditPrivate &dd, QmlGraphicsItem *parent); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + + bool event(QEvent *); + void keyPressEvent(QKeyEvent *); + void keyReleaseEvent(QKeyEvent *); + + void focusChanged(bool); + + // mouse filter? + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + + void inputMethodEvent(QInputMethodEvent *e); + + void drawContents(QPainter *, const QRect &); +private: + Q_DISABLE_COPY(QmlGraphicsTextEdit) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsTextEdit) }; QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsTextEdit) + +QT_END_HEADER + #endif diff --git a/src/declarative/fx/qmlgraphicstextedit_p_p.h b/src/declarative/fx/qmlgraphicstextedit_p_p.h new file mode 100644 index 0000000..9cba17e --- /dev/null +++ b/src/declarative/fx/qmlgraphicstextedit_p_p.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSTEXTEDIT_P_H +#define QMLGRAPHICSTEXTEDIT_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 "qmlgraphicsitem.h" +#include "qmlgraphicspainteditem_p_p.h" +#include "qml.h" + + +QT_BEGIN_NAMESPACE +class QTextLayout; +class QTextDocument; +class QTextControl; +class QmlGraphicsTextEditPrivate : public QmlGraphicsPaintedItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsTextEdit) + +public: + QmlGraphicsTextEditPrivate() + : color("black"), imgDirty(true), hAlign(QmlGraphicsTextEdit::AlignLeft), vAlign(QmlGraphicsTextEdit::AlignTop), + dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(false), + persistentSelection(true), textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0), + cursorComponent(0), cursor(0), format(QmlGraphicsTextEdit::AutoText), document(0) + { + } + + void init(); + + void updateDefaultTextOption(); + void relayoutDocument(); + void updateSelection(); + + QString text; + QFont font; + QColor color; + QColor selectionColor; + QColor selectedTextColor; + QString style; + QColor styleColor; + bool imgDirty; + QPixmap imgCache; + QPixmap imgStyleCache; + QmlGraphicsTextEdit::HAlignment hAlign; + QmlGraphicsTextEdit::VAlignment vAlign; + bool dirty; + bool wrap; + bool richText; + bool cursorVisible; + bool focusOnPress; + bool persistentSelection; + qreal textMargin; + int lastSelectionStart; + int lastSelectionEnd; + QmlComponent* cursorComponent; + QmlGraphicsItem* cursor; + QmlGraphicsTextEdit::TextFormat format; + QTextDocument *document; + QTextControl *control; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/declarative/fx/qmlgraphicstextinput.cpp b/src/declarative/fx/qmlgraphicstextinput.cpp index 17e6f7c..5df2484 100644 --- a/src/declarative/fx/qmlgraphicstextinput.cpp +++ b/src/declarative/fx/qmlgraphicstextinput.cpp @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#include "qmlgraphicstextinput.h" #include "qmlgraphicstextinput_p.h" +#include "qmlgraphicstextinput_p_p.h" #include "qmlinfo.h" #include #include diff --git a/src/declarative/fx/qmlgraphicstextinput.h b/src/declarative/fx/qmlgraphicstextinput.h deleted file mode 100644 index 1b143e0..0000000 --- a/src/declarative/fx/qmlgraphicstextinput.h +++ /dev/null @@ -1,209 +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 QMLGRAPHICSTEXTINPUT_H -#define QMLGRAPHICSTEXTINPUT_H - -#include "qmlgraphicstext.h" -#include "qmlgraphicspainteditem.h" -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlGraphicsTextInputPrivate; -class QValidator; -class Q_DECLARATIVE_EXPORT QmlGraphicsTextInput : public QmlGraphicsPaintedItem -{ - Q_OBJECT - Q_ENUMS(HAlignment) - Q_ENUMS(EchoMode) - - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) - - Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) - Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) - Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) - Q_PROPERTY(QmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate) - Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) - Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) - Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged) - - Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength) - Q_PROPERTY(QValidator* validator READ validator WRITE setValidator) - Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask) - Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged) - Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode) - Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) - -public: - QmlGraphicsTextInput(QmlGraphicsItem* parent=0); - ~QmlGraphicsTextInput(); - - enum EchoMode {//To match QLineEdit::EchoMode - Normal, - NoEcho, - Password, - PasswordEchoOnEdit - }; - - enum HAlignment { - AlignLeft = Qt::AlignLeft, - AlignRight = Qt::AlignRight, - AlignHCenter = Qt::AlignHCenter - }; - - //### Should we have this function, x based properties, - //### or copy TextEdit with x instead of QTextCursor? - Q_INVOKABLE int xToPos(int x); - - QString text() const; - void setText(const QString &); - - QFont font() const; - void setFont(const QFont &font); - - QColor color() const; - void setColor(const QColor &c); - - QColor selectionColor() const; - void setSelectionColor(const QColor &c); - - QColor selectedTextColor() const; - void setSelectedTextColor(const QColor &c); - - HAlignment hAlign() const; - void setHAlign(HAlignment align); - - bool isReadOnly() const; - void setReadOnly(bool); - - bool isCursorVisible() const; - void setCursorVisible(bool on); - - int cursorPosition() const; - void setCursorPosition(int cp); - - QRect cursorRect() const; - - int selectionStart() const; - void setSelectionStart(int); - - int selectionEnd() const; - void setSelectionEnd(int); - - QString selectedText() const; - - int maxLength() const; - void setMaxLength(int ml); - - QValidator * validator() const; - void setValidator(QValidator* v); - - QString inputMask() const; - void setInputMask(const QString &im); - - EchoMode echoMode() const; - void setEchoMode(EchoMode echo); - - QmlComponent* cursorDelegate() const; - void setCursorDelegate(QmlComponent*); - - bool focusOnPress() const; - void setFocusOnPress(bool); - - bool hasAcceptableInput() const; - - void drawContents(QPainter *p,const QRect &r); -Q_SIGNALS: - void textChanged(); - void cursorPositionChanged(); - void selectionStartChanged(); - void selectionEndChanged(); - void selectedTextChanged(); - void accepted(); - void acceptableInputChanged(); - -protected: - QmlGraphicsTextInput(QmlGraphicsTextInputPrivate &dd, QmlGraphicsItem *parent); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void keyPressEvent(QKeyEvent* ev); - bool event(QEvent *e); - - void focusChanged(bool hasFocus); - -public Q_SLOTS: - void selectAll(); - -private Q_SLOTS: - void updateSize(bool needsRedraw = true); - void q_textChanged(); - void selectionChanged(); - void createCursor(); - void moveCursor(); - void cursorPosChanged(); - void updateRect(const QRect &r = QRect()); - -private: - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsTextInput) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsTextInput) -QML_DECLARE_TYPE(QValidator) -QML_DECLARE_TYPE(QIntValidator) - -QT_END_HEADER - -#endif // QMLGRAPHICSTEXTINPUT_H diff --git a/src/declarative/fx/qmlgraphicstextinput_p.h b/src/declarative/fx/qmlgraphicstextinput_p.h index 010dfe1..10939a8 100644 --- a/src/declarative/fx/qmlgraphicstextinput_p.h +++ b/src/declarative/fx/qmlgraphicstextinput_p.h @@ -39,71 +39,171 @@ ** ****************************************************************************/ -#ifndef QMLGRAPHICSTEXTINPUT_P_H -#define QMLGRAPHICSTEXTINPUT_P_H +#ifndef QMLGRAPHICSTEXTINPUT_H +#define QMLGRAPHICSTEXTINPUT_H -#include "qmlgraphicstextinput.h" -#include "qml.h" +#include "qmlgraphicstext_p.h" #include "qmlgraphicspainteditem_p.h" -#include "private/qlinecontrol_p.h" -#include -// -// 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 +#include + +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QmlGraphicsTextInputPrivate : public QmlGraphicsPaintedItemPrivate +QT_MODULE(Declarative) + +class QmlGraphicsTextInputPrivate; +class QValidator; +class Q_DECLARATIVE_EXPORT QmlGraphicsTextInput : public QmlGraphicsPaintedItem { - Q_DECLARE_PUBLIC(QmlGraphicsTextInput) + Q_OBJECT + Q_ENUMS(HAlignment) + Q_ENUMS(EchoMode) + + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) + + Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) + Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) + Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) + Q_PROPERTY(QmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate) + Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) + Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) + Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged) + + Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength) + Q_PROPERTY(QValidator* validator READ validator WRITE setValidator) + Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask) + Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged) + Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode) + Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) + public: - QmlGraphicsTextInputPrivate() : control(new QLineControl(QString())), - color((QRgb)0), style(QmlGraphicsText::Normal), - styleColor((QRgb)0), hAlign(QmlGraphicsTextInput::AlignLeft), - hscroll(0), oldScroll(0), focused(false), focusOnPress(true), - cursorVisible(false) - { - } - - ~QmlGraphicsTextInputPrivate() - { - delete control; - } - - void init(); - void startCreatingCursor(); - - QLineControl* control; - - QFont font; - QColor color; - QColor selectionColor; - QColor selectedTextColor; - QmlGraphicsText::TextStyle style; - QColor styleColor; - QmlGraphicsTextInput::HAlignment hAlign; - QPointer cursorComponent; - QPointer cursorItem; - - int lastSelectionStart; - int lastSelectionEnd; - int oldHeight; - int oldWidth; - bool oldValidity; - int hscroll; - int oldScroll; - bool focused; - bool focusOnPress; - bool cursorVisible; + QmlGraphicsTextInput(QmlGraphicsItem* parent=0); + ~QmlGraphicsTextInput(); + + enum EchoMode {//To match QLineEdit::EchoMode + Normal, + NoEcho, + Password, + PasswordEchoOnEdit + }; + + enum HAlignment { + AlignLeft = Qt::AlignLeft, + AlignRight = Qt::AlignRight, + AlignHCenter = Qt::AlignHCenter + }; + + //### Should we have this function, x based properties, + //### or copy TextEdit with x instead of QTextCursor? + Q_INVOKABLE int xToPos(int x); + + QString text() const; + void setText(const QString &); + + QFont font() const; + void setFont(const QFont &font); + + QColor color() const; + void setColor(const QColor &c); + + QColor selectionColor() const; + void setSelectionColor(const QColor &c); + + QColor selectedTextColor() const; + void setSelectedTextColor(const QColor &c); + + HAlignment hAlign() const; + void setHAlign(HAlignment align); + + bool isReadOnly() const; + void setReadOnly(bool); + + bool isCursorVisible() const; + void setCursorVisible(bool on); + + int cursorPosition() const; + void setCursorPosition(int cp); + + QRect cursorRect() const; + + int selectionStart() const; + void setSelectionStart(int); + + int selectionEnd() const; + void setSelectionEnd(int); + + QString selectedText() const; + + int maxLength() const; + void setMaxLength(int ml); + + QValidator * validator() const; + void setValidator(QValidator* v); + + QString inputMask() const; + void setInputMask(const QString &im); + + EchoMode echoMode() const; + void setEchoMode(EchoMode echo); + + QmlComponent* cursorDelegate() const; + void setCursorDelegate(QmlComponent*); + + bool focusOnPress() const; + void setFocusOnPress(bool); + + bool hasAcceptableInput() const; + + void drawContents(QPainter *p,const QRect &r); +Q_SIGNALS: + void textChanged(); + void cursorPositionChanged(); + void selectionStartChanged(); + void selectionEndChanged(); + void selectedTextChanged(); + void accepted(); + void acceptableInputChanged(); + +protected: + QmlGraphicsTextInput(QmlGraphicsTextInputPrivate &dd, QmlGraphicsItem *parent); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void keyPressEvent(QKeyEvent* ev); + bool event(QEvent *e); + + void focusChanged(bool hasFocus); + +public Q_SLOTS: + void selectAll(); + +private Q_SLOTS: + void updateSize(bool needsRedraw = true); + void q_textChanged(); + void selectionChanged(); + void createCursor(); + void moveCursor(); + void cursorPosChanged(); + void updateRect(const QRect &r = QRect()); + +private: + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsTextInput) }; QT_END_NAMESPACE -#endif +QML_DECLARE_TYPE(QmlGraphicsTextInput) +QML_DECLARE_TYPE(QValidator) +QML_DECLARE_TYPE(QIntValidator) + +QT_END_HEADER +#endif // QMLGRAPHICSTEXTINPUT_H diff --git a/src/declarative/fx/qmlgraphicstextinput_p_p.h b/src/declarative/fx/qmlgraphicstextinput_p_p.h new file mode 100644 index 0000000..d17707f --- /dev/null +++ b/src/declarative/fx/qmlgraphicstextinput_p_p.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSTEXTINPUT_P_H +#define QMLGRAPHICSTEXTINPUT_P_H + +#include "qmlgraphicstextinput_p.h" +#include "qml.h" +#include "qmlgraphicspainteditem_p_p.h" +#include "private/qlinecontrol_p.h" +#include +// +// 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. + +QT_BEGIN_NAMESPACE + +class QmlGraphicsTextInputPrivate : public QmlGraphicsPaintedItemPrivate +{ + Q_DECLARE_PUBLIC(QmlGraphicsTextInput) +public: + QmlGraphicsTextInputPrivate() : control(new QLineControl(QString())), + color((QRgb)0), style(QmlGraphicsText::Normal), + styleColor((QRgb)0), hAlign(QmlGraphicsTextInput::AlignLeft), + hscroll(0), oldScroll(0), focused(false), focusOnPress(true), + cursorVisible(false) + { + } + + ~QmlGraphicsTextInputPrivate() + { + delete control; + } + + void init(); + void startCreatingCursor(); + + QLineControl* control; + + QFont font; + QColor color; + QColor selectionColor; + QColor selectedTextColor; + QmlGraphicsText::TextStyle style; + QColor styleColor; + QmlGraphicsTextInput::HAlignment hAlign; + QPointer cursorComponent; + QPointer cursorItem; + + int lastSelectionStart; + int lastSelectionEnd; + int oldHeight; + int oldWidth; + bool oldValidity; + int hscroll; + int oldScroll; + bool focused; + bool focusOnPress; + bool cursorVisible; +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/declarative/fx/qmlgraphicsvisualitemmodel.cpp b/src/declarative/fx/qmlgraphicsvisualitemmodel.cpp index b9b0237..3e8dfb4 100644 --- a/src/declarative/fx/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/fx/qmlgraphicsvisualitemmodel.cpp @@ -39,19 +39,19 @@ ** ****************************************************************************/ -#include "qlistmodelinterface.h" +#include #include "qmlgraphicsitem.h" #include #include -#include "qmlpackage.h" +#include #include "qhash.h" #include "qlist.h" #include "private/qobject_p.h" #include "private/qmetaobjectbuilder_p.h" -#include "qmlopenmetaobject.h" -#include "qmllistaccessor.h" +#include +#include #include "qmlinfo.h" -#include "qmlgraphicsvisualitemmodel.h" +#include "qmlgraphicsvisualitemmodel_p.h" #include "private/qguard_p.h" #include @@ -1029,4 +1029,5 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisualItemModel,QmlGraphicsVisua QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VisualDataModel,QmlGraphicsVisualDataModel) QT_END_NAMESPACE -#include "qfxvisualitemmodel.moc" + +#include "qmlgraphicsvisualitemmodel.moc" diff --git a/src/declarative/fx/qmlgraphicsvisualitemmodel.h b/src/declarative/fx/qmlgraphicsvisualitemmodel.h deleted file mode 100644 index fb36531..0000000 --- a/src/declarative/fx/qmlgraphicsvisualitemmodel.h +++ /dev/null @@ -1,203 +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 QMLGRAPHICSVISUALDATAMODEL_H -#define QMLGRAPHICSVISUALDATAMODEL_H - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -/***************************************************************************** - ***************************************************************************** - XXX Experimental - ***************************************************************************** -*****************************************************************************/ - -class QmlGraphicsItem; -class QmlComponent; -class QmlPackage; -class QmlGraphicsVisualDataModelPrivate; - -class Q_DECLARATIVE_EXPORT QmlGraphicsVisualModel : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int count READ count NOTIFY countChanged) - -public: - QmlGraphicsVisualModel() {} - virtual ~QmlGraphicsVisualModel() {} - - enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 }; - Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag) - - virtual int count() const = 0; - virtual bool isValid() const = 0; - virtual QmlGraphicsItem *item(int index, bool complete=true) = 0; - virtual ReleaseFlags release(QmlGraphicsItem *item) = 0; - virtual void completeItem() = 0; - virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext) = 0; - - virtual int indexOf(QmlGraphicsItem *item, QObject *objectContext) const = 0; - -Q_SIGNALS: - void countChanged(); - void itemsInserted(int index, int count); - void itemsRemoved(int index, int count); - void itemsMoved(int from, int to, int count); - void createdItem(int index, QmlGraphicsItem *item); - void destroyingItem(QmlGraphicsItem *item); - -protected: - QmlGraphicsVisualModel(QObjectPrivate &dd, QObject *parent = 0) - : QObject(dd, parent) {} - -private: - Q_DISABLE_COPY(QmlGraphicsVisualModel) -}; - -class QmlGraphicsVisualItemModelAttached; -class QmlGraphicsVisualItemModelPrivate; -class Q_DECLARATIVE_EXPORT QmlGraphicsVisualItemModel : public QmlGraphicsVisualModel -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlGraphicsVisualItemModel) - - Q_PROPERTY(QmlList* children READ children NOTIFY childrenChanged DESIGNABLE false) - Q_CLASSINFO("DefaultProperty", "children") - -public: - QmlGraphicsVisualItemModel(); - virtual ~QmlGraphicsVisualItemModel() {} - - virtual int count() const; - virtual bool isValid() const; - virtual QmlGraphicsItem *item(int index, bool complete=true); - virtual ReleaseFlags release(QmlGraphicsItem *item); - virtual void completeItem(); - virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext); - - virtual int indexOf(QmlGraphicsItem *item, QObject *objectContext) const; - - QmlList *children(); - - static QmlGraphicsVisualItemModelAttached *qmlAttachedProperties(QObject *obj); - -signals: - void childrenChanged(); - -private: - Q_DISABLE_COPY(QmlGraphicsVisualItemModel) -}; - - -class Q_DECLARATIVE_EXPORT QmlGraphicsVisualDataModel : public QmlGraphicsVisualModel -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlGraphicsVisualDataModel) - - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(QString part READ part WRITE setPart) - Q_PROPERTY(QObject *parts READ parts CONSTANT) - Q_CLASSINFO("DefaultProperty", "delegate") -public: - QmlGraphicsVisualDataModel(); - QmlGraphicsVisualDataModel(QmlContext *); - virtual ~QmlGraphicsVisualDataModel(); - - QVariant model() const; - void setModel(const QVariant &); - - QmlComponent *delegate() const; - void setDelegate(QmlComponent *); - - QString part() const; - void setPart(const QString &); - - int count() const; - bool isValid() const { return delegate() != 0; } - QmlGraphicsItem *item(int index, bool complete=true); - QmlGraphicsItem *item(int index, const QByteArray &, bool complete=true); - ReleaseFlags release(QmlGraphicsItem *item); - void completeItem(); - QVariant evaluate(int index, const QString &expression, QObject *objectContext); - - int indexOf(QmlGraphicsItem *item, QObject *objectContext) const; - - QObject *parts(); - -Q_SIGNALS: - void createdPackage(int index, QmlPackage *package); - void destroyingPackage(QmlPackage *package); - -private Q_SLOTS: - void _q_itemsChanged(int, int, const QList &); - void _q_itemsInserted(int index, int count); - void _q_itemsRemoved(int index, int count); - void _q_itemsMoved(int from, int to, int count); - void _q_rowsInserted(const QModelIndex &,int,int); - void _q_rowsRemoved(const QModelIndex &,int,int); - void _q_dataChanged(const QModelIndex&,const QModelIndex&); - void _q_createdPackage(int index, QmlPackage *package); - void _q_destroyingPackage(QmlPackage *package); - -private: - Q_DISABLE_COPY(QmlGraphicsVisualDataModel) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsVisualModel) -QML_DECLARE_TYPE(QmlGraphicsVisualItemModel) -QML_DECLARE_TYPEINFO(QmlGraphicsVisualItemModel, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QmlGraphicsVisualDataModel) - -QT_END_HEADER - -#endif // QMLGRAPHICSVISUALDATAMODEL_H diff --git a/src/declarative/fx/qmlgraphicsvisualitemmodel_p.h b/src/declarative/fx/qmlgraphicsvisualitemmodel_p.h new file mode 100644 index 0000000..fb36531 --- /dev/null +++ b/src/declarative/fx/qmlgraphicsvisualitemmodel_p.h @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSVISUALDATAMODEL_H +#define QMLGRAPHICSVISUALDATAMODEL_H + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +/***************************************************************************** + ***************************************************************************** + XXX Experimental + ***************************************************************************** +*****************************************************************************/ + +class QmlGraphicsItem; +class QmlComponent; +class QmlPackage; +class QmlGraphicsVisualDataModelPrivate; + +class Q_DECLARATIVE_EXPORT QmlGraphicsVisualModel : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int count READ count NOTIFY countChanged) + +public: + QmlGraphicsVisualModel() {} + virtual ~QmlGraphicsVisualModel() {} + + enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 }; + Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag) + + virtual int count() const = 0; + virtual bool isValid() const = 0; + virtual QmlGraphicsItem *item(int index, bool complete=true) = 0; + virtual ReleaseFlags release(QmlGraphicsItem *item) = 0; + virtual void completeItem() = 0; + virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext) = 0; + + virtual int indexOf(QmlGraphicsItem *item, QObject *objectContext) const = 0; + +Q_SIGNALS: + void countChanged(); + void itemsInserted(int index, int count); + void itemsRemoved(int index, int count); + void itemsMoved(int from, int to, int count); + void createdItem(int index, QmlGraphicsItem *item); + void destroyingItem(QmlGraphicsItem *item); + +protected: + QmlGraphicsVisualModel(QObjectPrivate &dd, QObject *parent = 0) + : QObject(dd, parent) {} + +private: + Q_DISABLE_COPY(QmlGraphicsVisualModel) +}; + +class QmlGraphicsVisualItemModelAttached; +class QmlGraphicsVisualItemModelPrivate; +class Q_DECLARATIVE_EXPORT QmlGraphicsVisualItemModel : public QmlGraphicsVisualModel +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlGraphicsVisualItemModel) + + Q_PROPERTY(QmlList* children READ children NOTIFY childrenChanged DESIGNABLE false) + Q_CLASSINFO("DefaultProperty", "children") + +public: + QmlGraphicsVisualItemModel(); + virtual ~QmlGraphicsVisualItemModel() {} + + virtual int count() const; + virtual bool isValid() const; + virtual QmlGraphicsItem *item(int index, bool complete=true); + virtual ReleaseFlags release(QmlGraphicsItem *item); + virtual void completeItem(); + virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext); + + virtual int indexOf(QmlGraphicsItem *item, QObject *objectContext) const; + + QmlList *children(); + + static QmlGraphicsVisualItemModelAttached *qmlAttachedProperties(QObject *obj); + +signals: + void childrenChanged(); + +private: + Q_DISABLE_COPY(QmlGraphicsVisualItemModel) +}; + + +class Q_DECLARATIVE_EXPORT QmlGraphicsVisualDataModel : public QmlGraphicsVisualModel +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlGraphicsVisualDataModel) + + Q_PROPERTY(QVariant model READ model WRITE setModel) + Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(QString part READ part WRITE setPart) + Q_PROPERTY(QObject *parts READ parts CONSTANT) + Q_CLASSINFO("DefaultProperty", "delegate") +public: + QmlGraphicsVisualDataModel(); + QmlGraphicsVisualDataModel(QmlContext *); + virtual ~QmlGraphicsVisualDataModel(); + + QVariant model() const; + void setModel(const QVariant &); + + QmlComponent *delegate() const; + void setDelegate(QmlComponent *); + + QString part() const; + void setPart(const QString &); + + int count() const; + bool isValid() const { return delegate() != 0; } + QmlGraphicsItem *item(int index, bool complete=true); + QmlGraphicsItem *item(int index, const QByteArray &, bool complete=true); + ReleaseFlags release(QmlGraphicsItem *item); + void completeItem(); + QVariant evaluate(int index, const QString &expression, QObject *objectContext); + + int indexOf(QmlGraphicsItem *item, QObject *objectContext) const; + + QObject *parts(); + +Q_SIGNALS: + void createdPackage(int index, QmlPackage *package); + void destroyingPackage(QmlPackage *package); + +private Q_SLOTS: + void _q_itemsChanged(int, int, const QList &); + void _q_itemsInserted(int index, int count); + void _q_itemsRemoved(int index, int count); + void _q_itemsMoved(int from, int to, int count); + void _q_rowsInserted(const QModelIndex &,int,int); + void _q_rowsRemoved(const QModelIndex &,int,int); + void _q_dataChanged(const QModelIndex&,const QModelIndex&); + void _q_createdPackage(int index, QmlPackage *package); + void _q_destroyingPackage(QmlPackage *package); + +private: + Q_DISABLE_COPY(QmlGraphicsVisualDataModel) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsVisualModel) +QML_DECLARE_TYPE(QmlGraphicsVisualItemModel) +QML_DECLARE_TYPEINFO(QmlGraphicsVisualItemModel, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QmlGraphicsVisualDataModel) + +QT_END_HEADER + +#endif // QMLGRAPHICSVISUALDATAMODEL_H diff --git a/src/declarative/fx/qmlgraphicswebview.cpp b/src/declarative/fx/qmlgraphicswebview.cpp index d9044cf..a307bc2 100644 --- a/src/declarative/fx/qmlgraphicswebview.cpp +++ b/src/declarative/fx/qmlgraphicswebview.cpp @@ -55,11 +55,11 @@ #include "qml.h" #include "qmlengine.h" -#include "qmlstate.h" -#include "qlistmodelinterface.h" +#include "qmlstate_p.h" +#include "qlistmodelinterface_p.h" -#include "qmlgraphicswebview.h" -#include +#include "qmlgraphicswebview_p.h" +#include QT_BEGIN_NAMESPACE QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,WebView,QmlGraphicsWebView) @@ -1385,4 +1385,4 @@ QWebPage *QmlGraphicsWebPage::createWindow(WebWindowType type) QT_END_NAMESPACE -#include "qfxwebview.moc" +#include "qmlgraphicswebview.moc" diff --git a/src/declarative/fx/qmlgraphicswebview.h b/src/declarative/fx/qmlgraphicswebview.h deleted file mode 100644 index 81f7bcd..0000000 --- a/src/declarative/fx/qmlgraphicswebview.h +++ /dev/null @@ -1,251 +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 QMLGRAPHICSWEBVIEW_H -#define QMLGRAPHICSWEBVIEW_H - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_HEADER - -class QWebHistory; -class QWebSettings; - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlGraphicsWebViewPrivate; -class QNetworkRequest; -class QmlGraphicsWebView; - -class Q_DECLARATIVE_EXPORT QmlGraphicsWebPage : public QWebPage -{ - Q_OBJECT -public: - explicit QmlGraphicsWebPage(QmlGraphicsWebView *parent); - ~QmlGraphicsWebPage(); -protected: - QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); - QWebPage *createWindow(WebWindowType type); - -private: - QmlGraphicsWebView *viewItem(); -}; - - -class QmlGraphicsWebViewAttached; -class QmlGraphicsWebSettings; - -//### TODO: browser plugins - -class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem -{ - Q_OBJECT - - Q_ENUMS(Status) - - Q_PROPERTY(QString title READ title NOTIFY titleChanged) - Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged) - Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false) - Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) - Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) - - Q_PROPERTY(QString html READ html WRITE setHtml) - - Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) - Q_PROPERTY(int webPageWidth READ webPageWidth WRITE setWebPageWidth) - Q_PROPERTY(int pixelCacheSize READ pixelCacheSize WRITE setPixelCacheSize) - Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - - Q_PROPERTY(QAction* reload READ reloadAction CONSTANT) - Q_PROPERTY(QAction* back READ backAction CONSTANT) - Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) - Q_PROPERTY(QAction* stop READ stopAction CONSTANT) - - Q_PROPERTY(QmlGraphicsWebSettings* settings READ settingsObject CONSTANT) - - Q_PROPERTY(QmlList* javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) - - Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent) - Q_PROPERTY(QmlGraphicsItem* newWindowParent READ newWindowParent WRITE setNewWindowParent) - - Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled) - -public: - QmlGraphicsWebView(QmlGraphicsItem *parent=0); - ~QmlGraphicsWebView(); - - QUrl url() const; - void setUrl(const QUrl &); - - QString title() const; - - QPixmap icon() const; - - qreal textSizeMultiplier() const; - void setTextSizeMultiplier(qreal); - - qreal zoomFactor() const; - void setZoomFactor(qreal); - - int preferredWidth() const; - void setPreferredWidth(int); - int webPageWidth() const; - void setWebPageWidth(int); - - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - QString statusText() const; - - QAction *reloadAction() const; - QAction *backAction() const; - QAction *forwardAction() const; - QAction *stopAction() const; - - QWebPage *page() const; - void setPage(QWebPage *page); - - void load(const QNetworkRequest &request, - QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, - const QByteArray &body = QByteArray()); - - QString html() const; - - void setHtml(const QString &html, const QUrl &baseUrl = QUrl()); - void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()); - - QWebHistory *history() const; - QWebSettings *settings() const; - QmlGraphicsWebSettings *settingsObject() const; - - int pixelCacheSize() const; - void setPixelCacheSize(int pixels); - - bool renderingEnabled() const; - void setRenderingEnabled(bool); - - QmlList *javaScriptWindowObjects(); - - static QmlGraphicsWebViewAttached *qmlAttachedProperties(QObject *); - - QmlComponent *newWindowComponent() const; - void setNewWindowComponent(QmlComponent *newWindow); - QmlGraphicsItem *newWindowParent() const; - void setNewWindowParent(QmlGraphicsItem *newWindow); - -Q_SIGNALS: - void preferredWidthChanged(); - void preferredHeightChanged(); - void urlChanged(); - void progressChanged(); - void statusChanged(Status); - void titleChanged(const QString&); - void iconChanged(); - void statusTextChanged(); - void zoomFactorChanged(); - - void loadStarted(); - void loadFinished(); - void loadFailed(); - - void doubleClick(int clickX, int clickY); - - void zooming(qreal zoom, int centerX, int centerY); - -public Q_SLOTS: - QVariant evaluateJavaScript(const QString&); - void heuristicZoom(int clickX, int clickY); - -private Q_SLOTS: - void expandToWebPage(); - void paintPage(const QRect&); - void doLoadStarted(); - void doLoadProgress(int p); - void doLoadFinished(bool ok); - void setStatusText(const QString&); - void windowObjectCleared(); - void pageUrlChanged(); - void contentsSizeChanged(const QSize&); - -protected: - QmlGraphicsWebView(QmlGraphicsWebViewPrivate &dd, QmlGraphicsItem *parent); - - void drawContents(QPainter *, const QRect &); - - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - void hoverMoveEvent (QGraphicsSceneHoverEvent * event); - void keyPressEvent(QKeyEvent* event); - void keyReleaseEvent(QKeyEvent* event); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - virtual void focusChanged(bool); - virtual bool sceneEvent(QEvent *event); - QmlGraphicsWebView *createWindow(QWebPage::WebWindowType type); - QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; - -private: - void init(); - virtual void componentComplete(); - Q_DISABLE_COPY(QmlGraphicsWebView) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsWebView) - friend class QmlGraphicsWebPage; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlGraphicsWebView) -QML_DECLARE_TYPEINFO(QmlGraphicsWebView, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QAction) - -QT_END_HEADER - -#endif diff --git a/src/declarative/fx/qmlgraphicswebview_p.h b/src/declarative/fx/qmlgraphicswebview_p.h new file mode 100644 index 0000000..0398b0d --- /dev/null +++ b/src/declarative/fx/qmlgraphicswebview_p.h @@ -0,0 +1,251 @@ +/**************************************************************************** +** +** 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 QMLGRAPHICSWEBVIEW_H +#define QMLGRAPHICSWEBVIEW_H + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_HEADER + +class QWebHistory; +class QWebSettings; + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlGraphicsWebViewPrivate; +class QNetworkRequest; +class QmlGraphicsWebView; + +class Q_DECLARATIVE_EXPORT QmlGraphicsWebPage : public QWebPage +{ + Q_OBJECT +public: + explicit QmlGraphicsWebPage(QmlGraphicsWebView *parent); + ~QmlGraphicsWebPage(); +protected: + QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); + QWebPage *createWindow(WebWindowType type); + +private: + QmlGraphicsWebView *viewItem(); +}; + + +class QmlGraphicsWebViewAttached; +class QmlGraphicsWebSettings; + +//### TODO: browser plugins + +class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem +{ + Q_OBJECT + + Q_ENUMS(Status) + + Q_PROPERTY(QString title READ title NOTIFY titleChanged) + Q_PROPERTY(QPixmap icon READ icon NOTIFY iconChanged) + Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false) + Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) + Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) + + Q_PROPERTY(QString html READ html WRITE setHtml) + + Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) + Q_PROPERTY(int webPageWidth READ webPageWidth WRITE setWebPageWidth) + Q_PROPERTY(int pixelCacheSize READ pixelCacheSize WRITE setPixelCacheSize) + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) + Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + + Q_PROPERTY(QAction* reload READ reloadAction CONSTANT) + Q_PROPERTY(QAction* back READ backAction CONSTANT) + Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) + Q_PROPERTY(QAction* stop READ stopAction CONSTANT) + + Q_PROPERTY(QmlGraphicsWebSettings* settings READ settingsObject CONSTANT) + + Q_PROPERTY(QmlList* javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) + + Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent) + Q_PROPERTY(QmlGraphicsItem* newWindowParent READ newWindowParent WRITE setNewWindowParent) + + Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled) + +public: + QmlGraphicsWebView(QmlGraphicsItem *parent=0); + ~QmlGraphicsWebView(); + + QUrl url() const; + void setUrl(const QUrl &); + + QString title() const; + + QPixmap icon() const; + + qreal textSizeMultiplier() const; + void setTextSizeMultiplier(qreal); + + qreal zoomFactor() const; + void setZoomFactor(qreal); + + int preferredWidth() const; + void setPreferredWidth(int); + int webPageWidth() const; + void setWebPageWidth(int); + + enum Status { Null, Ready, Loading, Error }; + Status status() const; + qreal progress() const; + QString statusText() const; + + QAction *reloadAction() const; + QAction *backAction() const; + QAction *forwardAction() const; + QAction *stopAction() const; + + QWebPage *page() const; + void setPage(QWebPage *page); + + void load(const QNetworkRequest &request, + QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, + const QByteArray &body = QByteArray()); + + QString html() const; + + void setHtml(const QString &html, const QUrl &baseUrl = QUrl()); + void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()); + + QWebHistory *history() const; + QWebSettings *settings() const; + QmlGraphicsWebSettings *settingsObject() const; + + int pixelCacheSize() const; + void setPixelCacheSize(int pixels); + + bool renderingEnabled() const; + void setRenderingEnabled(bool); + + QmlList *javaScriptWindowObjects(); + + static QmlGraphicsWebViewAttached *qmlAttachedProperties(QObject *); + + QmlComponent *newWindowComponent() const; + void setNewWindowComponent(QmlComponent *newWindow); + QmlGraphicsItem *newWindowParent() const; + void setNewWindowParent(QmlGraphicsItem *newWindow); + +Q_SIGNALS: + void preferredWidthChanged(); + void preferredHeightChanged(); + void urlChanged(); + void progressChanged(); + void statusChanged(Status); + void titleChanged(const QString&); + void iconChanged(); + void statusTextChanged(); + void zoomFactorChanged(); + + void loadStarted(); + void loadFinished(); + void loadFailed(); + + void doubleClick(int clickX, int clickY); + + void zooming(qreal zoom, int centerX, int centerY); + +public Q_SLOTS: + QVariant evaluateJavaScript(const QString&); + void heuristicZoom(int clickX, int clickY); + +private Q_SLOTS: + void expandToWebPage(); + void paintPage(const QRect&); + void doLoadStarted(); + void doLoadProgress(int p); + void doLoadFinished(bool ok); + void setStatusText(const QString&); + void windowObjectCleared(); + void pageUrlChanged(); + void contentsSizeChanged(const QSize&); + +protected: + QmlGraphicsWebView(QmlGraphicsWebViewPrivate &dd, QmlGraphicsItem *parent); + + void drawContents(QPainter *, const QRect &); + + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void hoverMoveEvent (QGraphicsSceneHoverEvent * event); + void keyPressEvent(QKeyEvent* event); + void keyReleaseEvent(QKeyEvent* event); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + virtual void focusChanged(bool); + virtual bool sceneEvent(QEvent *event); + QmlGraphicsWebView *createWindow(QWebPage::WebWindowType type); + QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; + +private: + void init(); + virtual void componentComplete(); + Q_DISABLE_COPY(QmlGraphicsWebView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsWebView) + friend class QmlGraphicsWebPage; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlGraphicsWebView) +QML_DECLARE_TYPEINFO(QmlGraphicsWebView, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QAction) + +QT_END_HEADER + +#endif diff --git a/src/declarative/qml/qmlbasicscript.cpp b/src/declarative/qml/qmlbasicscript.cpp index eba4307..0eb897b 100644 --- a/src/declarative/qml/qmlbasicscript.cpp +++ b/src/declarative/qml/qmlbasicscript.cpp @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index fa971a3..045b45a 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 5d2bd12..f7bd027 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -41,7 +41,7 @@ #include "private/qmlcompiler_p.h" #include "private/qmlcompositetypedata_p.h" -#include +#include #include "qmlparser_p.h" #include "private/qmlscriptparser_p.h" #include diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index c856680..f2268a7 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -48,7 +48,7 @@ #include "qmlvme_p.h" #include "qml.h" #include -#include +#include #include #include #include diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 463bd93..6f60b4f 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -62,7 +62,7 @@ #include #include #include "qml.h" -#include +#include #include #include "private/qmlbasicscript_p.h" #include "qmlengine.h" diff --git a/src/declarative/qml/qmlenginedebug_p.h b/src/declarative/qml/qmlenginedebug_p.h index a8572eb..c381033 100644 --- a/src/declarative/qml/qmlenginedebug_p.h +++ b/src/declarative/qml/qmlenginedebug_p.h @@ -53,7 +53,7 @@ // We mean it. // -#include +#include #include #include diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index edec988..a76c36b 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -43,7 +43,7 @@ #include "qmlmetaproperty_p.h" #include "qmlcompositetypedata_p.h" #include -#include +#include #include #include "qmlbinding.h" #include diff --git a/src/declarative/qml/qmlparser.cpp b/src/declarative/qml/qmlparser.cpp index f9e3c50..dfedae5 100644 --- a/src/declarative/qml/qmlparser.cpp +++ b/src/declarative/qml/qmlparser.cpp @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include "private/qmlcomponent_p.h" #include diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 95dfe5b..2dfda37 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -55,7 +55,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index b986b60..e112f25 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -41,7 +41,7 @@ #include "qmlvme_p.h" #include "qmlcompiler_p.h" -#include +#include #include #include #include "private/qmetaobjectbuilder_p.h" diff --git a/src/declarative/qml/qmlwatcher.cpp b/src/declarative/qml/qmlwatcher.cpp index 8cd51e0..a9d3dad 100644 --- a/src/declarative/qml/qmlwatcher.cpp +++ b/src/declarative/qml/qmlwatcher.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/declarative/util/qfxperf.cpp b/src/declarative/util/qfxperf.cpp index 97f195b..a21f2ed 100644 --- a/src/declarative/util/qfxperf.cpp +++ b/src/declarative/util/qfxperf.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "private/qfxperf_p.h" +#include "private/qfxperf_p_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qfxperf_p.h b/src/declarative/util/qfxperf_p.h deleted file mode 100644 index 37bfc32..0000000 --- a/src/declarative/util/qfxperf_p.h +++ /dev/null @@ -1,90 +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 QFXPERF_H -#define QFXPERF_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/qperformancelog_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -Q_DECLARE_PERFORMANCE_LOG(QmlPerf) { - Q_DECLARE_PERFORMANCE_METRIC(QmlParsing) - - Q_DECLARE_PERFORMANCE_METRIC(Compilation) - Q_DECLARE_PERFORMANCE_METRIC(VMEExecution) - - Q_DECLARE_PERFORMANCE_METRIC(BindInit) - Q_DECLARE_PERFORMANCE_METRIC(BindValue) - Q_DECLARE_PERFORMANCE_METRIC(BindValueSSE) - Q_DECLARE_PERFORMANCE_METRIC(BindValueQt) - Q_DECLARE_PERFORMANCE_METRIC(BindableValueUpdate) - Q_DECLARE_PERFORMANCE_METRIC(PixmapLoad) - Q_DECLARE_PERFORMANCE_METRIC(FontDatabase) - Q_DECLARE_PERFORMANCE_METRIC(QmlGraphicsPathViewPathCache) - Q_DECLARE_PERFORMANCE_METRIC(CreateParticle) - Q_DECLARE_PERFORMANCE_METRIC(ItemComponentComplete) - Q_DECLARE_PERFORMANCE_METRIC(ImageComponentComplete) - Q_DECLARE_PERFORMANCE_METRIC(BaseLayoutComponentComplete) - Q_DECLARE_PERFORMANCE_METRIC(TextComponentComplete) - Q_DECLARE_PERFORMANCE_METRIC(QmlGraphicsText_setText) - Q_DECLARE_PERFORMANCE_METRIC(AddScript) -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QFXPERF_H diff --git a/src/declarative/util/qfxperf_p_p.h b/src/declarative/util/qfxperf_p_p.h new file mode 100644 index 0000000..e4424b0 --- /dev/null +++ b/src/declarative/util/qfxperf_p_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 QFXPERF_H +#define QFXPERF_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/qperformancelog_p_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +Q_DECLARE_PERFORMANCE_LOG(QmlPerf) { + Q_DECLARE_PERFORMANCE_METRIC(QmlParsing) + + Q_DECLARE_PERFORMANCE_METRIC(Compilation) + Q_DECLARE_PERFORMANCE_METRIC(VMEExecution) + + Q_DECLARE_PERFORMANCE_METRIC(BindInit) + Q_DECLARE_PERFORMANCE_METRIC(BindValue) + Q_DECLARE_PERFORMANCE_METRIC(BindValueSSE) + Q_DECLARE_PERFORMANCE_METRIC(BindValueQt) + Q_DECLARE_PERFORMANCE_METRIC(BindableValueUpdate) + Q_DECLARE_PERFORMANCE_METRIC(PixmapLoad) + Q_DECLARE_PERFORMANCE_METRIC(FontDatabase) + Q_DECLARE_PERFORMANCE_METRIC(QmlGraphicsPathViewPathCache) + Q_DECLARE_PERFORMANCE_METRIC(CreateParticle) + Q_DECLARE_PERFORMANCE_METRIC(ItemComponentComplete) + Q_DECLARE_PERFORMANCE_METRIC(ImageComponentComplete) + Q_DECLARE_PERFORMANCE_METRIC(BaseLayoutComponentComplete) + Q_DECLARE_PERFORMANCE_METRIC(TextComponentComplete) + Q_DECLARE_PERFORMANCE_METRIC(QmlGraphicsText_setText) + Q_DECLARE_PERFORMANCE_METRIC(AddScript) +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QFXPERF_H diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index e00a1c8..cc46a9c 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -39,15 +39,15 @@ ** ****************************************************************************/ -#include "qmlanimation.h" +#include "qmlanimation_p.h" #include "qvariant.h" #include "qcolor.h" #include "qfile.h" #include "qmlpropertyvaluesource.h" #include "qml.h" #include "qmlinfo.h" -#include "qmlanimation_p.h" -#include "qmlbehavior.h" +#include "qmlanimation_p_p.h" +#include #include #include #include @@ -55,7 +55,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h deleted file mode 100644 index 4e94aa0..0000000 --- a/src/declarative/util/qmlanimation.h +++ /dev/null @@ -1,407 +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 QMLANIMATION_H -#define QMLANIMATION_H - -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlAbstractAnimationPrivate; -class QmlAnimationGroup; -class Q_AUTOTEST_EXPORT QmlAbstractAnimation : public QObject, public QmlPropertyValueSource, public QmlParserStatus -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlAbstractAnimation) - - Q_INTERFACES(QmlParserStatus) - Q_INTERFACES(QmlPropertyValueSource) - Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) - Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) - Q_PROPERTY(bool alwaysRunToEnd READ alwaysRunToEnd WRITE setAlwaysRunToEnd NOTIFY alwaysRunToEndChanged()) - Q_PROPERTY(bool repeat READ repeat WRITE setRepeat NOTIFY repeatChanged) - Q_CLASSINFO("DefaultMethod", "start()") - Q_INTERFACES(QmlParserStatus) - -public: - QmlAbstractAnimation(QObject *parent=0); - virtual ~QmlAbstractAnimation(); - - bool isRunning() const; - void setRunning(bool); - bool isPaused() const; - void setPaused(bool); - bool alwaysRunToEnd() const; - void setAlwaysRunToEnd(bool); - bool repeat() const; - void setRepeat(bool); - - int currentTime(); - void setCurrentTime(int); - - QmlAnimationGroup *group() const; - void setGroup(QmlAnimationGroup *); - - //### these belong at a lower level in the hierarchy - QObject *target() const; - void setTarget(QObject *); - QString property() const; - void setProperty(const QString &); - - virtual void setTarget(const QmlMetaProperty &); - - void classBegin(); - void componentComplete(); - -Q_SIGNALS: - void started(); - void completed(); - void runningChanged(bool); - void pausedChanged(bool); - void repeatChanged(bool); - void targetChanged(QObject *, const QString &); - void alwaysRunToEndChanged(bool); - -public Q_SLOTS: - void restart(); - void start(); - void pause(); - void resume(); - void stop(); - void complete(); - -protected: - QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObject *parent); - -public: - enum TransitionDirection { Forward, Backward }; - virtual void transition(QmlStateActions &actions, - QmlMetaProperties &modified, - TransitionDirection direction); - virtual void prepare(QmlMetaProperty &); - virtual QAbstractAnimation *qtAnimation() = 0; - -private Q_SLOTS: - void timelineComplete(); -}; - -class QmlPauseAnimationPrivate; -class QmlPauseAnimation : public QmlAbstractAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlPauseAnimation) - - Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) - -public: - QmlPauseAnimation(QObject *parent=0); - virtual ~QmlPauseAnimation(); - - int duration() const; - void setDuration(int); - -Q_SIGNALS: - void durationChanged(int); - -protected: - virtual QAbstractAnimation *qtAnimation(); -}; - -class QmlScriptActionPrivate; -class QmlScriptAction : public QmlAbstractAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlScriptAction) - - Q_PROPERTY(QmlScriptString script READ script WRITE setScript) - Q_PROPERTY(QString stateChangeScriptName READ stateChangeScriptName WRITE setStateChangeScriptName) - -public: - QmlScriptAction(QObject *parent=0); - virtual ~QmlScriptAction(); - - QmlScriptString script() const; - void setScript(const QmlScriptString &); - - QString stateChangeScriptName() const; - void setStateChangeScriptName(const QString &); - -protected: - virtual void transition(QmlStateActions &actions, - QmlMetaProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); -}; - -class QmlPropertyActionPrivate; -class QmlPropertyAction : public QmlAbstractAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlPropertyAction) - - Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) - Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) - Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) - Q_PROPERTY(QList* targets READ targets) - Q_PROPERTY(QList* exclude READ exclude) - Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) - -public: - QmlPropertyAction(QObject *parent=0); - virtual ~QmlPropertyAction(); - - QString properties() const; - void setProperties(const QString &); - - QList *targets(); - QList *exclude(); - - QVariant value() const; - void setValue(const QVariant &); - -Q_SIGNALS: - void valueChanged(const QVariant &); - void propertiesChanged(const QString &); - -protected: - virtual void transition(QmlStateActions &actions, - QmlMetaProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); - virtual void prepare(QmlMetaProperty &); -}; - -class QmlGraphicsItem; -class QmlParentActionPrivate; -class QmlParentAction : public QmlAbstractAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlParentAction) - - Q_PROPERTY(QmlGraphicsItem *target READ object WRITE setObject) - Q_PROPERTY(QmlGraphicsItem *parent READ parent WRITE setParent) - -public: - QmlParentAction(QObject *parent=0); - virtual ~QmlParentAction(); - - QmlGraphicsItem *object() const; - void setObject(QmlGraphicsItem *); - - QmlGraphicsItem *parent() const; - void setParent(QmlGraphicsItem *); - -protected: - virtual void transition(QmlStateActions &actions, - QmlMetaProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); -}; - -class QmlPropertyAnimationPrivate; -class Q_AUTOTEST_EXPORT QmlPropertyAnimation : public QmlAbstractAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlPropertyAnimation) - - Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) - Q_PROPERTY(QVariant from READ from WRITE setFrom NOTIFY fromChanged) - Q_PROPERTY(QVariant to READ to WRITE setTo NOTIFY toChanged) - Q_PROPERTY(QString easing READ easing WRITE setEasing NOTIFY easingChanged) - Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) - Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) - Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) - Q_PROPERTY(QList* targets READ targets) - Q_PROPERTY(QList* exclude READ exclude) - -public: - QmlPropertyAnimation(QObject *parent=0); - virtual ~QmlPropertyAnimation(); - - int duration() const; - void setDuration(int); - - QVariant from() const; - void setFrom(const QVariant &); - - QVariant to() const; - void setTo(const QVariant &); - - QString easing() const; - void setEasing(const QString &); - - QString properties() const; - void setProperties(const QString &); - - QList *targets(); - QList *exclude(); - -protected: - virtual void transition(QmlStateActions &actions, - QmlMetaProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); - virtual void prepare(QmlMetaProperty &); - -Q_SIGNALS: - void durationChanged(int); - void fromChanged(QVariant); - void toChanged(QVariant); - void easingChanged(const QString &); - void propertiesChanged(const QString &); -}; - -class Q_AUTOTEST_EXPORT QmlColorAnimation : public QmlPropertyAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlPropertyAnimation) - Q_PROPERTY(QColor from READ from WRITE setFrom NOTIFY fromChanged) - Q_PROPERTY(QColor to READ to WRITE setTo NOTIFY toChanged) - -public: - QmlColorAnimation(QObject *parent=0); - virtual ~QmlColorAnimation(); - - QColor from() const; - void setFrom(const QColor &); - - QColor to() const; - void setTo(const QColor &); -}; - -class Q_AUTOTEST_EXPORT QmlNumberAnimation : public QmlPropertyAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlPropertyAnimation) - - Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged) - Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged) - -public: - QmlNumberAnimation(QObject *parent=0); - virtual ~QmlNumberAnimation(); - - qreal from() const; - void setFrom(qreal); - - qreal to() const; - void setTo(qreal); -}; - -class QmlAnimationGroupPrivate; -class QmlAnimationGroup : public QmlAbstractAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlAnimationGroup) - - Q_CLASSINFO("DefaultProperty", "animations") - Q_PROPERTY(QmlList *animations READ animations) - -public: - QmlAnimationGroup(QObject *parent); - virtual ~QmlAnimationGroup(); - - QmlList* animations(); - friend class QmlAbstractAnimation; -}; - -class QmlSequentialAnimation : public QmlAnimationGroup -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlAnimationGroup) - -public: - QmlSequentialAnimation(QObject *parent=0); - virtual ~QmlSequentialAnimation(); - -protected: - virtual void transition(QmlStateActions &actions, - QmlMetaProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); - virtual void prepare(QmlMetaProperty &); -}; - -class QmlParallelAnimation : public QmlAnimationGroup -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlAnimationGroup) - -public: - QmlParallelAnimation(QObject *parent=0); - virtual ~QmlParallelAnimation(); - -protected: - virtual void transition(QmlStateActions &actions, - QmlMetaProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); - virtual void prepare(QmlMetaProperty &); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlAbstractAnimation) -QML_DECLARE_TYPE(QmlPauseAnimation) -QML_DECLARE_TYPE(QmlScriptAction) -QML_DECLARE_TYPE(QmlPropertyAction) -QML_DECLARE_TYPE(QmlParentAction) -QML_DECLARE_TYPE(QmlPropertyAnimation) -QML_DECLARE_TYPE(QmlColorAnimation) -QML_DECLARE_TYPE(QmlNumberAnimation) -QML_DECLARE_TYPE(QmlSequentialAnimation) -QML_DECLARE_TYPE(QmlParallelAnimation) - -QT_END_HEADER - -#endif // QMLANIMATION_H diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index 38b92ae..5f9f907 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -39,324 +39,369 @@ ** ****************************************************************************/ -#ifndef QMLANIMATION_P_H -#define QMLANIMATION_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 -#include -#include -#include -#include -#include -#include -#include +#ifndef QMLANIMATION_H +#define QMLANIMATION_H + +#include +#include +#include +#include +#include +#include #include -#include -#include +#include + +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -//interface for classes that provide animation actions for QActionAnimation -class QAbstractAnimationAction -{ -public: - virtual ~QAbstractAnimationAction() {} - virtual void doAction() = 0; -}; +QT_MODULE(Declarative) -//templated animation action -//allows us to specify an action that calls a function of a class. -//(so that class doesn't have to inherit QmlAbstractAnimationAction) -template -class QAnimationActionProxy : public QAbstractAnimationAction +class QmlAbstractAnimationPrivate; +class QmlAnimationGroup; +class Q_AUTOTEST_EXPORT QmlAbstractAnimation : public QObject, public QmlPropertyValueSource, public QmlParserStatus { + Q_OBJECT + Q_DECLARE_PRIVATE(QmlAbstractAnimation) + + Q_INTERFACES(QmlParserStatus) + Q_INTERFACES(QmlPropertyValueSource) + Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) + Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) + Q_PROPERTY(bool alwaysRunToEnd READ alwaysRunToEnd WRITE setAlwaysRunToEnd NOTIFY alwaysRunToEndChanged()) + Q_PROPERTY(bool repeat READ repeat WRITE setRepeat NOTIFY repeatChanged) + Q_CLASSINFO("DefaultMethod", "start()") + Q_INTERFACES(QmlParserStatus) + public: - QAnimationActionProxy(T *p) : m_p(p) {} - virtual void doAction() { (m_p->*method)(); } + QmlAbstractAnimation(QObject *parent=0); + virtual ~QmlAbstractAnimation(); + + bool isRunning() const; + void setRunning(bool); + bool isPaused() const; + void setPaused(bool); + bool alwaysRunToEnd() const; + void setAlwaysRunToEnd(bool); + bool repeat() const; + void setRepeat(bool); + + int currentTime(); + void setCurrentTime(int); + + QmlAnimationGroup *group() const; + void setGroup(QmlAnimationGroup *); + + //### these belong at a lower level in the hierarchy + QObject *target() const; + void setTarget(QObject *); + QString property() const; + void setProperty(const QString &); + + virtual void setTarget(const QmlMetaProperty &); + + void classBegin(); + void componentComplete(); + +Q_SIGNALS: + void started(); + void completed(); + void runningChanged(bool); + void pausedChanged(bool); + void repeatChanged(bool); + void targetChanged(QObject *, const QString &); + void alwaysRunToEndChanged(bool); + +public Q_SLOTS: + void restart(); + void start(); + void pause(); + void resume(); + void stop(); + void complete(); + +protected: + QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObject *parent); -private: - T *m_p; +public: + enum TransitionDirection { Forward, Backward }; + virtual void transition(QmlStateActions &actions, + QmlMetaProperties &modified, + TransitionDirection direction); + virtual void prepare(QmlMetaProperty &); + virtual QAbstractAnimation *qtAnimation() = 0; + +private Q_SLOTS: + void timelineComplete(); }; -//performs an action of type QAbstractAnimationAction -class QActionAnimation : public QAbstractAnimation +class QmlPauseAnimationPrivate; +class QmlPauseAnimation : public QmlAbstractAnimation { Q_OBJECT + Q_DECLARE_PRIVATE(QmlPauseAnimation) + + Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) + public: - QActionAnimation(QObject *parent = 0) : QAbstractAnimation(parent), animAction(0), policy(KeepWhenStopped) {} - QActionAnimation(QAbstractAnimationAction *action, QObject *parent = 0) - : QAbstractAnimation(parent), animAction(action), policy(KeepWhenStopped) {} - virtual int duration() const { return 0; } - void setAnimAction(QAbstractAnimationAction *action, DeletionPolicy p) - { - if (state() == Running) - stop(); - animAction = action; - policy = p; - } + QmlPauseAnimation(QObject *parent=0); + virtual ~QmlPauseAnimation(); + + int duration() const; + void setDuration(int); + +Q_SIGNALS: + void durationChanged(int); + protected: - virtual void updateCurrentTime(int) {} - - virtual void updateState(State /*oldState*/, State newState) - { - if (newState == Running) { - if (animAction) - animAction->doAction(); - } else if (newState == Stopped && policy == DeleteWhenStopped) { - delete animAction; - animAction = 0; - } - } - -private: - QAbstractAnimationAction *animAction; - DeletionPolicy policy; + virtual QAbstractAnimation *qtAnimation(); }; -//animates QmlTimeLineValue (assumes start and end values will be reals or compatible) -class QmlTimeLineValueAnimator : public QVariantAnimation +class QmlScriptActionPrivate; +class QmlScriptAction : public QmlAbstractAnimation { Q_OBJECT + Q_DECLARE_PRIVATE(QmlScriptAction) + + Q_PROPERTY(QmlScriptString script READ script WRITE setScript) + Q_PROPERTY(QString stateChangeScriptName READ stateChangeScriptName WRITE setStateChangeScriptName) + public: - QmlTimeLineValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), fromSourced(0), policy(KeepWhenStopped) {} - void setAnimValue(QmlTimeLineValue *value, DeletionPolicy p) - { - if (state() == Running) - stop(); - animValue = value; - policy = p; - } - void setFromSourcedValue(bool *value) - { - fromSourced = value; - } + QmlScriptAction(QObject *parent=0); + virtual ~QmlScriptAction(); + + QmlScriptString script() const; + void setScript(const QmlScriptString &); + + QString stateChangeScriptName() const; + void setStateChangeScriptName(const QString &); + protected: - virtual void updateCurrentValue(const QVariant &value) - { - if (animValue) - animValue->setValue(value.toDouble()); - } - virtual void updateState(State oldState, State newState) - { - QVariantAnimation::updateState(oldState, newState); - if (newState == Running) { - //check for new from every loop - if (fromSourced) - *fromSourced = false; - } else if (newState == Stopped && policy == DeleteWhenStopped) { - delete animValue; - animValue = 0; - } - } - -private: - QmlTimeLineValue *animValue; - bool *fromSourced; - DeletionPolicy policy; + virtual void transition(QmlStateActions &actions, + QmlMetaProperties &modified, + TransitionDirection direction); + virtual QAbstractAnimation *qtAnimation(); }; -//an animation that just gives a tick -template -class QTickAnimationProxy : public QAbstractAnimation +class QmlPropertyActionPrivate; +class QmlPropertyAction : public QmlAbstractAnimation { - //Q_OBJECT //doesn't work with templating -public: - QTickAnimationProxy(T *p, QObject *parent = 0) : QAbstractAnimation(parent), m_p(p) {} - virtual int duration() const { return -1; } -protected: - virtual void updateCurrentTime(int msec) { (m_p->*method)(msec); } + Q_OBJECT + Q_DECLARE_PRIVATE(QmlPropertyAction) -private: - T *m_p; -}; + Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) + Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) + Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) + Q_PROPERTY(QList* targets READ targets) + Q_PROPERTY(QList* exclude READ exclude) + Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) -class QmlAbstractAnimationPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QmlAbstractAnimation) public: - QmlAbstractAnimationPrivate() - : running(false), paused(false), alwaysRunToEnd(false), repeat(false), - connectedTimeLine(false), componentComplete(true), startOnCompletion(false), - target(0), group(0) {} - - bool running; - bool paused; - bool alwaysRunToEnd; - bool repeat; - bool connectedTimeLine; + QmlPropertyAction(QObject *parent=0); + virtual ~QmlPropertyAction(); - bool componentComplete; - bool startOnCompletion; + QString properties() const; + void setProperties(const QString &); - void commence(); + QList *targets(); + QList *exclude(); - QmlNullableValue userProperty; - QObject *target; - QString propertyName; + QVariant value() const; + void setValue(const QVariant &); - QmlMetaProperty property; - QmlAnimationGroup *group; +Q_SIGNALS: + void valueChanged(const QVariant &); + void propertiesChanged(const QString &); - QmlMetaProperty createProperty(QObject *obj, const QString &str); +protected: + virtual void transition(QmlStateActions &actions, + QmlMetaProperties &modified, + TransitionDirection direction); + virtual QAbstractAnimation *qtAnimation(); + virtual void prepare(QmlMetaProperty &); }; -class QmlPauseAnimationPrivate : public QmlAbstractAnimationPrivate +class QmlGraphicsItem; +class QmlParentActionPrivate; +class QmlParentAction : public QmlAbstractAnimation { - Q_DECLARE_PUBLIC(QmlPauseAnimation) -public: - QmlPauseAnimationPrivate() - : QmlAbstractAnimationPrivate(), pa(0) {} - - void init(); + Q_OBJECT + Q_DECLARE_PRIVATE(QmlParentAction) - QPauseAnimation *pa; -}; + Q_PROPERTY(QmlGraphicsItem *target READ object WRITE setObject) + Q_PROPERTY(QmlGraphicsItem *parent READ parent WRITE setParent) -class QmlScriptActionPrivate : public QmlAbstractAnimationPrivate -{ - Q_DECLARE_PUBLIC(QmlScriptAction) public: - QmlScriptActionPrivate() - : QmlAbstractAnimationPrivate(), hasRunScriptScript(false), proxy(this), rsa(0) {} + QmlParentAction(QObject *parent=0); + virtual ~QmlParentAction(); - void init(); + QmlGraphicsItem *object() const; + void setObject(QmlGraphicsItem *); - QmlScriptString script; - QString name; - QmlScriptString runScriptScript; - bool hasRunScriptScript; + QmlGraphicsItem *parent() const; + void setParent(QmlGraphicsItem *); - void execute(); - - QAnimationActionProxy proxy; - QActionAnimation *rsa; +protected: + virtual void transition(QmlStateActions &actions, + QmlMetaProperties &modified, + TransitionDirection direction); + virtual QAbstractAnimation *qtAnimation(); }; -class QmlPropertyActionPrivate : public QmlAbstractAnimationPrivate +class QmlPropertyAnimationPrivate; +class Q_AUTOTEST_EXPORT QmlPropertyAnimation : public QmlAbstractAnimation { - Q_DECLARE_PUBLIC(QmlPropertyAction) + Q_OBJECT + Q_DECLARE_PRIVATE(QmlPropertyAnimation) + + Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) + Q_PROPERTY(QVariant from READ from WRITE setFrom NOTIFY fromChanged) + Q_PROPERTY(QVariant to READ to WRITE setTo NOTIFY toChanged) + Q_PROPERTY(QString easing READ easing WRITE setEasing NOTIFY easingChanged) + Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) + Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) + Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) + Q_PROPERTY(QList* targets READ targets) + Q_PROPERTY(QList* exclude READ exclude) + public: - QmlPropertyActionPrivate() - : QmlAbstractAnimationPrivate(), proxy(this), spa(0) {} + QmlPropertyAnimation(QObject *parent=0); + virtual ~QmlPropertyAnimation(); - void init(); + int duration() const; + void setDuration(int); - QString properties; - QList targets; - QList exclude; + QVariant from() const; + void setFrom(const QVariant &); - QmlNullableValue value; + QVariant to() const; + void setTo(const QVariant &); - void doAction(); + QString easing() const; + void setEasing(const QString &); - QAnimationActionProxy proxy; - QActionAnimation *spa; + QString properties() const; + void setProperties(const QString &); + + QList *targets(); + QList *exclude(); + +protected: + virtual void transition(QmlStateActions &actions, + QmlMetaProperties &modified, + TransitionDirection direction); + virtual QAbstractAnimation *qtAnimation(); + virtual void prepare(QmlMetaProperty &); + +Q_SIGNALS: + void durationChanged(int); + void fromChanged(QVariant); + void toChanged(QVariant); + void easingChanged(const QString &); + void propertiesChanged(const QString &); }; -class QmlParentActionPrivate : public QmlAbstractAnimationPrivate +class Q_AUTOTEST_EXPORT QmlColorAnimation : public QmlPropertyAnimation { - Q_DECLARE_PUBLIC(QmlParentAction) -public: - QmlParentActionPrivate() - : QmlAbstractAnimationPrivate(), pcTarget(0), pcParent(0) {} + Q_OBJECT + Q_DECLARE_PRIVATE(QmlPropertyAnimation) + Q_PROPERTY(QColor from READ from WRITE setFrom NOTIFY fromChanged) + Q_PROPERTY(QColor to READ to WRITE setTo NOTIFY toChanged) - void init(); +public: + QmlColorAnimation(QObject *parent=0); + virtual ~QmlColorAnimation(); - QmlGraphicsItem *pcTarget; - QmlGraphicsItem *pcParent; + QColor from() const; + void setFrom(const QColor &); - void doAction(); - QActionAnimation *cpa; + QColor to() const; + void setTo(const QColor &); }; -class QmlAnimationGroupPrivate : public QmlAbstractAnimationPrivate +class Q_AUTOTEST_EXPORT QmlNumberAnimation : public QmlPropertyAnimation { - Q_DECLARE_PUBLIC(QmlAnimationGroup) + Q_OBJECT + Q_DECLARE_PRIVATE(QmlPropertyAnimation) + + Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged) + Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged) + public: - QmlAnimationGroupPrivate() - : QmlAbstractAnimationPrivate(), animations(this), ag(0) {} - - struct AnimationList : public QmlConcreteList - { - AnimationList(QmlAnimationGroupPrivate *p) - : anim(p) {} - virtual void append(QmlAbstractAnimation *a) { - QmlConcreteList::append(a); - a->setGroup(anim->q_func()); - } - virtual void clear() - { - for (int i = 0; i < count(); ++i) - at(i)->setGroup(0); - QmlConcreteList::clear(); - } - virtual void removeAt(int i) - { - at(i)->setGroup(0); - QmlConcreteList::removeAt(i); - } - virtual void insert(int i, QmlAbstractAnimation *a) - { - QmlConcreteList::insert(i, a); - a->setGroup(anim->q_func()); - } - - QmlAnimationGroupPrivate *anim; - }; - - AnimationList animations; - QAnimationGroup *ag; + QmlNumberAnimation(QObject *parent=0); + virtual ~QmlNumberAnimation(); + + qreal from() const; + void setFrom(qreal); + + qreal to() const; + void setTo(qreal); }; -class QmlPropertyAnimationPrivate : public QmlAbstractAnimationPrivate +class QmlAnimationGroupPrivate; +class QmlAnimationGroup : public QmlAbstractAnimation { - Q_DECLARE_PUBLIC(QmlPropertyAnimation) -public: - QmlPropertyAnimationPrivate() - : QmlAbstractAnimationPrivate(), fromSourced(false), fromIsDefined(false), toIsDefined(false), - defaultToInterpolatorType(0), interpolatorType(0), interpolator(0), va(0), - value(this, &QmlPropertyAnimationPrivate::valueChanged) {} + Q_OBJECT + Q_DECLARE_PRIVATE(QmlAnimationGroup) - void init(); + Q_CLASSINFO("DefaultProperty", "animations") + Q_PROPERTY(QmlList *animations READ animations) - QVariant from; - QVariant to; +public: + QmlAnimationGroup(QObject *parent); + virtual ~QmlAnimationGroup(); - QString easing; + QmlList* animations(); + friend class QmlAbstractAnimation; +}; - QString properties; - QList targets; - QList exclude; +class QmlSequentialAnimation : public QmlAnimationGroup +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlAnimationGroup) - bool fromSourced; - bool fromIsDefined; - bool toIsDefined; - bool defaultToInterpolatorType; - int interpolatorType; - QVariantAnimation::Interpolator interpolator; +public: + QmlSequentialAnimation(QObject *parent=0); + virtual ~QmlSequentialAnimation(); - QmlTimeLineValueAnimator *va; - virtual void valueChanged(qreal); +protected: + virtual void transition(QmlStateActions &actions, + QmlMetaProperties &modified, + TransitionDirection direction); + virtual QAbstractAnimation *qtAnimation(); + virtual void prepare(QmlMetaProperty &); +}; - QmlTimeLineValueProxy value; +class QmlParallelAnimation : public QmlAnimationGroup +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlAnimationGroup) + +public: + QmlParallelAnimation(QObject *parent=0); + virtual ~QmlParallelAnimation(); - static QVariant interpolateVariant(const QVariant &from, const QVariant &to, qreal progress); - static void convertVariant(QVariant &variant, int type); +protected: + virtual void transition(QmlStateActions &actions, + QmlMetaProperties &modified, + TransitionDirection direction); + virtual QAbstractAnimation *qtAnimation(); + virtual void prepare(QmlMetaProperty &); }; QT_END_NAMESPACE -#endif // QMLANIMATION_P_H +QML_DECLARE_TYPE(QmlAbstractAnimation) +QML_DECLARE_TYPE(QmlPauseAnimation) +QML_DECLARE_TYPE(QmlScriptAction) +QML_DECLARE_TYPE(QmlPropertyAction) +QML_DECLARE_TYPE(QmlParentAction) +QML_DECLARE_TYPE(QmlPropertyAnimation) +QML_DECLARE_TYPE(QmlColorAnimation) +QML_DECLARE_TYPE(QmlNumberAnimation) +QML_DECLARE_TYPE(QmlSequentialAnimation) +QML_DECLARE_TYPE(QmlParallelAnimation) + +QT_END_HEADER + +#endif // QMLANIMATION_H diff --git a/src/declarative/util/qmlanimation_p_p.h b/src/declarative/util/qmlanimation_p_p.h new file mode 100644 index 0000000..1372343 --- /dev/null +++ b/src/declarative/util/qmlanimation_p_p.h @@ -0,0 +1,362 @@ +/**************************************************************************** +** +** 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 QMLANIMATION_P_H +#define QMLANIMATION_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +//interface for classes that provide animation actions for QActionAnimation +class QAbstractAnimationAction +{ +public: + virtual ~QAbstractAnimationAction() {} + virtual void doAction() = 0; +}; + +//templated animation action +//allows us to specify an action that calls a function of a class. +//(so that class doesn't have to inherit QmlAbstractAnimationAction) +template +class QAnimationActionProxy : public QAbstractAnimationAction +{ +public: + QAnimationActionProxy(T *p) : m_p(p) {} + virtual void doAction() { (m_p->*method)(); } + +private: + T *m_p; +}; + +//performs an action of type QAbstractAnimationAction +class QActionAnimation : public QAbstractAnimation +{ + Q_OBJECT +public: + QActionAnimation(QObject *parent = 0) : QAbstractAnimation(parent), animAction(0), policy(KeepWhenStopped) {} + QActionAnimation(QAbstractAnimationAction *action, QObject *parent = 0) + : QAbstractAnimation(parent), animAction(action), policy(KeepWhenStopped) {} + virtual int duration() const { return 0; } + void setAnimAction(QAbstractAnimationAction *action, DeletionPolicy p) + { + if (state() == Running) + stop(); + animAction = action; + policy = p; + } +protected: + virtual void updateCurrentTime(int) {} + + virtual void updateState(State /*oldState*/, State newState) + { + if (newState == Running) { + if (animAction) + animAction->doAction(); + } else if (newState == Stopped && policy == DeleteWhenStopped) { + delete animAction; + animAction = 0; + } + } + +private: + QAbstractAnimationAction *animAction; + DeletionPolicy policy; +}; + +//animates QmlTimeLineValue (assumes start and end values will be reals or compatible) +class QmlTimeLineValueAnimator : public QVariantAnimation +{ + Q_OBJECT +public: + QmlTimeLineValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), fromSourced(0), policy(KeepWhenStopped) {} + void setAnimValue(QmlTimeLineValue *value, DeletionPolicy p) + { + if (state() == Running) + stop(); + animValue = value; + policy = p; + } + void setFromSourcedValue(bool *value) + { + fromSourced = value; + } +protected: + virtual void updateCurrentValue(const QVariant &value) + { + if (animValue) + animValue->setValue(value.toDouble()); + } + virtual void updateState(State oldState, State newState) + { + QVariantAnimation::updateState(oldState, newState); + if (newState == Running) { + //check for new from every loop + if (fromSourced) + *fromSourced = false; + } else if (newState == Stopped && policy == DeleteWhenStopped) { + delete animValue; + animValue = 0; + } + } + +private: + QmlTimeLineValue *animValue; + bool *fromSourced; + DeletionPolicy policy; +}; + +//an animation that just gives a tick +template +class QTickAnimationProxy : public QAbstractAnimation +{ + //Q_OBJECT //doesn't work with templating +public: + QTickAnimationProxy(T *p, QObject *parent = 0) : QAbstractAnimation(parent), m_p(p) {} + virtual int duration() const { return -1; } +protected: + virtual void updateCurrentTime(int msec) { (m_p->*method)(msec); } + +private: + T *m_p; +}; + +class QmlAbstractAnimationPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlAbstractAnimation) +public: + QmlAbstractAnimationPrivate() + : running(false), paused(false), alwaysRunToEnd(false), repeat(false), + connectedTimeLine(false), componentComplete(true), startOnCompletion(false), + target(0), group(0) {} + + bool running; + bool paused; + bool alwaysRunToEnd; + bool repeat; + bool connectedTimeLine; + + bool componentComplete; + bool startOnCompletion; + + void commence(); + + QmlNullableValue userProperty; + QObject *target; + QString propertyName; + + QmlMetaProperty property; + QmlAnimationGroup *group; + + QmlMetaProperty createProperty(QObject *obj, const QString &str); +}; + +class QmlPauseAnimationPrivate : public QmlAbstractAnimationPrivate +{ + Q_DECLARE_PUBLIC(QmlPauseAnimation) +public: + QmlPauseAnimationPrivate() + : QmlAbstractAnimationPrivate(), pa(0) {} + + void init(); + + QPauseAnimation *pa; +}; + +class QmlScriptActionPrivate : public QmlAbstractAnimationPrivate +{ + Q_DECLARE_PUBLIC(QmlScriptAction) +public: + QmlScriptActionPrivate() + : QmlAbstractAnimationPrivate(), hasRunScriptScript(false), proxy(this), rsa(0) {} + + void init(); + + QmlScriptString script; + QString name; + QmlScriptString runScriptScript; + bool hasRunScriptScript; + + void execute(); + + QAnimationActionProxy proxy; + QActionAnimation *rsa; +}; + +class QmlPropertyActionPrivate : public QmlAbstractAnimationPrivate +{ + Q_DECLARE_PUBLIC(QmlPropertyAction) +public: + QmlPropertyActionPrivate() + : QmlAbstractAnimationPrivate(), proxy(this), spa(0) {} + + void init(); + + QString properties; + QList targets; + QList exclude; + + QmlNullableValue value; + + void doAction(); + + QAnimationActionProxy proxy; + QActionAnimation *spa; +}; + +class QmlParentActionPrivate : public QmlAbstractAnimationPrivate +{ + Q_DECLARE_PUBLIC(QmlParentAction) +public: + QmlParentActionPrivate() + : QmlAbstractAnimationPrivate(), pcTarget(0), pcParent(0) {} + + void init(); + + QmlGraphicsItem *pcTarget; + QmlGraphicsItem *pcParent; + + void doAction(); + QActionAnimation *cpa; +}; + +class QmlAnimationGroupPrivate : public QmlAbstractAnimationPrivate +{ + Q_DECLARE_PUBLIC(QmlAnimationGroup) +public: + QmlAnimationGroupPrivate() + : QmlAbstractAnimationPrivate(), animations(this), ag(0) {} + + struct AnimationList : public QmlConcreteList + { + AnimationList(QmlAnimationGroupPrivate *p) + : anim(p) {} + virtual void append(QmlAbstractAnimation *a) { + QmlConcreteList::append(a); + a->setGroup(anim->q_func()); + } + virtual void clear() + { + for (int i = 0; i < count(); ++i) + at(i)->setGroup(0); + QmlConcreteList::clear(); + } + virtual void removeAt(int i) + { + at(i)->setGroup(0); + QmlConcreteList::removeAt(i); + } + virtual void insert(int i, QmlAbstractAnimation *a) + { + QmlConcreteList::insert(i, a); + a->setGroup(anim->q_func()); + } + + QmlAnimationGroupPrivate *anim; + }; + + AnimationList animations; + QAnimationGroup *ag; +}; + +class QmlPropertyAnimationPrivate : public QmlAbstractAnimationPrivate +{ + Q_DECLARE_PUBLIC(QmlPropertyAnimation) +public: + QmlPropertyAnimationPrivate() + : QmlAbstractAnimationPrivate(), fromSourced(false), fromIsDefined(false), toIsDefined(false), + defaultToInterpolatorType(0), interpolatorType(0), interpolator(0), va(0), + value(this, &QmlPropertyAnimationPrivate::valueChanged) {} + + void init(); + + QVariant from; + QVariant to; + + QString easing; + + QString properties; + QList targets; + QList exclude; + + bool fromSourced; + bool fromIsDefined; + bool toIsDefined; + bool defaultToInterpolatorType; + int interpolatorType; + QVariantAnimation::Interpolator interpolator; + + QmlTimeLineValueAnimator *va; + virtual void valueChanged(qreal); + + QmlTimeLineValueProxy value; + + static QVariant interpolateVariant(const QVariant &from, const QVariant &to, qreal progress); + static void convertVariant(QVariant &variant, int type); +}; + +QT_END_NAMESPACE + +#endif // QMLANIMATION_P_H diff --git a/src/declarative/util/qmlbind.cpp b/src/declarative/util/qmlbind.cpp index d18ef47..98ec7cf 100644 --- a/src/declarative/util/qmlbind.cpp +++ b/src/declarative/util/qmlbind.cpp @@ -47,8 +47,8 @@ #include #include #include -#include -#include "qmlbind.h" +#include +#include "qmlbind_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qmlbind.h b/src/declarative/util/qmlbind.h deleted file mode 100644 index 731cdf8..0000000 --- a/src/declarative/util/qmlbind.h +++ /dev/null @@ -1,92 +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 QMLBIND_H -#define QMLBIND_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlBindPrivate; -class Q_DECLARATIVE_EXPORT QmlBind : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlBind) - - Q_PROPERTY(QObject *target READ object WRITE setObject) - Q_PROPERTY(QString property READ property WRITE setProperty) - Q_PROPERTY(QVariant value READ value WRITE setValue) - Q_PROPERTY(bool when READ when WRITE setWhen) - -public: - QmlBind(QObject *parent=0); - ~QmlBind(); - - bool when() const; - void setWhen(bool); - - QObject *object(); - void setObject(QObject *); - - QString property() const; - void setProperty(const QString &); - - QVariant value() const; - void setValue(const QVariant &); - -private: - void eval(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlBind) - -QT_END_HEADER - -#endif diff --git a/src/declarative/util/qmlbind_p.h b/src/declarative/util/qmlbind_p.h new file mode 100644 index 0000000..731cdf8 --- /dev/null +++ b/src/declarative/util/qmlbind_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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 QMLBIND_H +#define QMLBIND_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlBindPrivate; +class Q_DECLARATIVE_EXPORT QmlBind : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlBind) + + Q_PROPERTY(QObject *target READ object WRITE setObject) + Q_PROPERTY(QString property READ property WRITE setProperty) + Q_PROPERTY(QVariant value READ value WRITE setValue) + Q_PROPERTY(bool when READ when WRITE setWhen) + +public: + QmlBind(QObject *parent=0); + ~QmlBind(); + + bool when() const; + void setWhen(bool); + + QObject *object(); + void setObject(QObject *); + + QString property() const; + void setProperty(const QString &); + + QVariant value() const; + void setValue(const QVariant &); + +private: + void eval(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlBind) + +QT_END_HEADER + +#endif diff --git a/src/declarative/util/qmlconnection.cpp b/src/declarative/util/qmlconnection.cpp index 5475fb2..c52732f 100644 --- a/src/declarative/util/qmlconnection.cpp +++ b/src/declarative/util/qmlconnection.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlconnection.h" +#include "qmlconnection_p.h" #include #include "private/qmlboundsignal_p.h" #include "private/qobject_p.h" diff --git a/src/declarative/util/qmlconnection.h b/src/declarative/util/qmlconnection.h deleted file mode 100644 index 3d69c6f..0000000 --- a/src/declarative/util/qmlconnection.h +++ /dev/null @@ -1,92 +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 QMLCONNECTION_H -#define QMLCONNECTION_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlBoundSignal; -class QmlContext; -class QmlConnectionPrivate; -class Q_DECLARATIVE_EXPORT QmlConnection : public QObject, public QmlParserStatus -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlConnection) - - Q_INTERFACES(QmlParserStatus) - Q_PROPERTY(QObject *sender READ signalSender WRITE setSignalSender) - Q_PROPERTY(QmlScriptString script READ script WRITE setScript) - Q_PROPERTY(QString signal READ signal WRITE setSignal) - -public: - QmlConnection(QObject *parent=0); - ~QmlConnection(); - - QObject *signalSender() const; - void setSignalSender(QObject *); - QmlScriptString script() const; - void setScript(const QmlScriptString&); - QString signal() const; - void setSignal(const QString&); - -private: - void disconnectIfValid(); - void connectIfValid(); - void componentComplete(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlConnection) - -QT_END_HEADER - -#endif diff --git a/src/declarative/util/qmlconnection_p.h b/src/declarative/util/qmlconnection_p.h new file mode 100644 index 0000000..3d69c6f --- /dev/null +++ b/src/declarative/util/qmlconnection_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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 QMLCONNECTION_H +#define QMLCONNECTION_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlBoundSignal; +class QmlContext; +class QmlConnectionPrivate; +class Q_DECLARATIVE_EXPORT QmlConnection : public QObject, public QmlParserStatus +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlConnection) + + Q_INTERFACES(QmlParserStatus) + Q_PROPERTY(QObject *sender READ signalSender WRITE setSignalSender) + Q_PROPERTY(QmlScriptString script READ script WRITE setScript) + Q_PROPERTY(QString signal READ signal WRITE setSignal) + +public: + QmlConnection(QObject *parent=0); + ~QmlConnection(); + + QObject *signalSender() const; + void setSignalSender(QObject *); + QmlScriptString script() const; + void setScript(const QmlScriptString&); + QString signal() const; + void setSignal(const QString&); + +private: + void disconnectIfValid(); + void connectIfValid(); + void componentComplete(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlConnection) + +QT_END_HEADER + +#endif diff --git a/src/declarative/util/qmleasefollow.cpp b/src/declarative/util/qmleasefollow.cpp index 9d17d25..96654c6 100644 --- a/src/declarative/util/qmleasefollow.cpp +++ b/src/declarative/util/qmleasefollow.cpp @@ -39,11 +39,11 @@ ** ****************************************************************************/ -#include "qmleasefollow.h" +#include "qmleasefollow_p.h" #include #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qmleasefollow.h b/src/declarative/util/qmleasefollow.h deleted file mode 100644 index a653ea6..0000000 --- a/src/declarative/util/qmleasefollow.h +++ /dev/null @@ -1,113 +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 QMLEASEFOLLOW_H -#define QMLEASEFOLLOW_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlMetaProperty; -class QmlEaseFollowPrivate; -class Q_DECLARATIVE_EXPORT QmlEaseFollow : public QObject, - public QmlPropertyValueSource -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlEaseFollow) - Q_INTERFACES(QmlPropertyValueSource) - Q_ENUMS(ReversingMode) - - Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue NOTIFY sourceChanged) - Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity NOTIFY velocityChanged) - Q_PROPERTY(qreal duration READ duration WRITE setDuration NOTIFY durationChanged) - Q_PROPERTY(ReversingMode reversingMode READ reversingMode WRITE setReversingMode NOTIFY reversingModeChanged) - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(qreal maximumEasingTime READ maximumEasingTime WRITE setMaximumEasingTime NOTIFY maximumEasingTimeChanged) - -public: - enum ReversingMode { Eased, Immediate, Sync }; - - QmlEaseFollow(QObject *parent = 0); - ~QmlEaseFollow(); - - ReversingMode reversingMode() const; - void setReversingMode(ReversingMode); - - qreal sourceValue() const; - void setSourceValue(qreal); - - qreal velocity() const; - void setVelocity(qreal); - - qreal duration() const; - void setDuration(qreal); - - bool enabled() const; - void setEnabled(bool enabled); - - qreal maximumEasingTime() const; - void setMaximumEasingTime(qreal); - - virtual void setTarget(const QmlMetaProperty &); - -signals: - void sourceChanged(); - void velocityChanged(); - void durationChanged(); - void reversingModeChanged(); - void enabledChanged(); - void maximumEasingTimeChanged(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlEaseFollow); - -QT_END_HEADER - -#endif // QMLEASEFOLLOW_H diff --git a/src/declarative/util/qmleasefollow_p.h b/src/declarative/util/qmleasefollow_p.h new file mode 100644 index 0000000..a653ea6 --- /dev/null +++ b/src/declarative/util/qmleasefollow_p.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** 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 QMLEASEFOLLOW_H +#define QMLEASEFOLLOW_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlMetaProperty; +class QmlEaseFollowPrivate; +class Q_DECLARATIVE_EXPORT QmlEaseFollow : public QObject, + public QmlPropertyValueSource +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlEaseFollow) + Q_INTERFACES(QmlPropertyValueSource) + Q_ENUMS(ReversingMode) + + Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue NOTIFY sourceChanged) + Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity NOTIFY velocityChanged) + Q_PROPERTY(qreal duration READ duration WRITE setDuration NOTIFY durationChanged) + Q_PROPERTY(ReversingMode reversingMode READ reversingMode WRITE setReversingMode NOTIFY reversingModeChanged) + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(qreal maximumEasingTime READ maximumEasingTime WRITE setMaximumEasingTime NOTIFY maximumEasingTimeChanged) + +public: + enum ReversingMode { Eased, Immediate, Sync }; + + QmlEaseFollow(QObject *parent = 0); + ~QmlEaseFollow(); + + ReversingMode reversingMode() const; + void setReversingMode(ReversingMode); + + qreal sourceValue() const; + void setSourceValue(qreal); + + qreal velocity() const; + void setVelocity(qreal); + + qreal duration() const; + void setDuration(qreal); + + bool enabled() const; + void setEnabled(bool enabled); + + qreal maximumEasingTime() const; + void setMaximumEasingTime(qreal); + + virtual void setTarget(const QmlMetaProperty &); + +signals: + void sourceChanged(); + void velocityChanged(); + void durationChanged(); + void reversingModeChanged(); + void enabledChanged(); + void maximumEasingTimeChanged(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlEaseFollow); + +QT_END_HEADER + +#endif // QMLEASEFOLLOW_H diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp index 3e4cb64..80709f1 100644 --- a/src/declarative/util/qmllistaccessor.cpp +++ b/src/declarative/util/qmllistaccessor.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmllistaccessor.h" +#include "qmllistaccessor_p.h" #include #include #include diff --git a/src/declarative/util/qmllistaccessor.h b/src/declarative/util/qmllistaccessor.h deleted file mode 100644 index c3ff632..0000000 --- a/src/declarative/util/qmllistaccessor.h +++ /dev/null @@ -1,85 +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 QMLLISTACCESSOR_H -#define QMLLISTACCESSOR_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlEngine; -class Q_DECLARATIVE_EXPORT QmlListAccessor -{ -public: - QmlListAccessor(); - virtual ~QmlListAccessor(); - - QVariant list() const; - void setList(const QVariant &, QmlEngine * = 0); - - bool isValid() const; - - int count() const; - QVariant at(int) const; - - virtual void append(const QVariant &); - virtual void insert(int, const QVariant &); - virtual void removeAt(int); - virtual void clear(); - - enum Type { Invalid, StringList, VariantList, QmlList, QList, Instance, Integer }; - Type type() const { return m_type; } - -private: - Type m_type; - QVariant d; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMLLISTACCESSOR_H diff --git a/src/declarative/util/qmllistaccessor_p.h b/src/declarative/util/qmllistaccessor_p.h new file mode 100644 index 0000000..c3ff632 --- /dev/null +++ b/src/declarative/util/qmllistaccessor_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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 QMLLISTACCESSOR_H +#define QMLLISTACCESSOR_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlEngine; +class Q_DECLARATIVE_EXPORT QmlListAccessor +{ +public: + QmlListAccessor(); + virtual ~QmlListAccessor(); + + QVariant list() const; + void setList(const QVariant &, QmlEngine * = 0); + + bool isValid() const; + + int count() const; + QVariant at(int) const; + + virtual void append(const QVariant &); + virtual void insert(int, const QVariant &); + virtual void removeAt(int); + virtual void clear(); + + enum Type { Invalid, StringList, VariantList, QmlList, QList, Instance, Integer }; + Type type() const { return m_type; } + +private: + Type m_type; + QVariant d; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLLISTACCESSOR_H diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index 9c9fa6a..d5202c5 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -44,9 +44,9 @@ #include #include #include -#include "qmlopenmetaobject.h" +#include "qmlopenmetaobject_p.h" #include -#include "qmllistmodel.h" +#include "qmllistmodel_p.h" #include Q_DECLARE_METATYPE(QListModelInterface *) diff --git a/src/declarative/util/qmllistmodel.h b/src/declarative/util/qmllistmodel.h deleted file mode 100644 index 7bb94cf..0000000 --- a/src/declarative/util/qmllistmodel.h +++ /dev/null @@ -1,103 +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 QMLLISTMODEL_H -#define QMLLISTMODEL_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -struct ModelNode; -class QmlListModel : public QListModelInterface -{ - Q_OBJECT - Q_PROPERTY(int count READ count) - -public: - QmlListModel(QObject *parent=0); - ~QmlListModel(); - - virtual QList roles() const; - virtual QString toString(int role) const; - virtual int count() const; - virtual QHash data(int index, const QList &roles = (QList())) const; - - Q_INVOKABLE void clear(); - Q_INVOKABLE void remove(int index); - Q_INVOKABLE void append(const QScriptValue&); - Q_INVOKABLE void insert(int index, const QScriptValue&); - Q_INVOKABLE void set(int index, const QScriptValue&); - Q_INVOKABLE void set(int index, const QString& property, const QVariant& value); - Q_INVOKABLE void move(int from, int to, int count); - -private: - QVariant valueForNode(ModelNode *) const; - mutable QStringList roleStrings; - friend class QmlListModelParser; - friend struct ModelNode; - - void checkRoles() const; - void addRole(const QString &) const; - mutable bool _rolesOk; - ModelNode *_root; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlListModel) - -QT_END_HEADER - -#endif // QMLLISTMODEL_H diff --git a/src/declarative/util/qmllistmodel_p.h b/src/declarative/util/qmllistmodel_p.h new file mode 100644 index 0000000..b376e59 --- /dev/null +++ b/src/declarative/util/qmllistmodel_p.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** 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 QMLLISTMODEL_H +#define QMLLISTMODEL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +struct ModelNode; +class QmlListModel : public QListModelInterface +{ + Q_OBJECT + Q_PROPERTY(int count READ count) + +public: + QmlListModel(QObject *parent=0); + ~QmlListModel(); + + virtual QList roles() const; + virtual QString toString(int role) const; + virtual int count() const; + virtual QHash data(int index, const QList &roles = (QList())) const; + + Q_INVOKABLE void clear(); + Q_INVOKABLE void remove(int index); + Q_INVOKABLE void append(const QScriptValue&); + Q_INVOKABLE void insert(int index, const QScriptValue&); + Q_INVOKABLE void set(int index, const QScriptValue&); + Q_INVOKABLE void set(int index, const QString& property, const QVariant& value); + Q_INVOKABLE void move(int from, int to, int count); + +private: + QVariant valueForNode(ModelNode *) const; + mutable QStringList roleStrings; + friend class QmlListModelParser; + friend struct ModelNode; + + void checkRoles() const; + void addRole(const QString &) const; + mutable bool _rolesOk; + ModelNode *_root; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlListModel) + +QT_END_HEADER + +#endif // QMLLISTMODEL_H diff --git a/src/declarative/util/qmlnullablevalue_p.h b/src/declarative/util/qmlnullablevalue_p.h deleted file mode 100644 index 6455642..0000000 --- a/src/declarative/util/qmlnullablevalue_p.h +++ /dev/null @@ -1,81 +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 QMLNULLABLEVALUE_P_H -#define QMLNULLABLEVALUE_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. -// - -QT_BEGIN_NAMESPACE - -template -struct QmlNullableValue -{ - QmlNullableValue() - : isNull(true), value(T()) {} - QmlNullableValue(const QmlNullableValue &o) - : isNull(o.isNull), value(o.value) {} - QmlNullableValue(const T &t) - : isNull(false), value(t) {} - QmlNullableValue &operator=(const T &t) - { isNull = false; value = t; return *this; } - QmlNullableValue &operator=(const QmlNullableValue &o) - { isNull = o.isNull; value = o.value; return *this; } - operator T() const { return value; } - - void invalidate() { isNull = true; } - bool isValid() const { return !isNull; } - bool isNull; - T value; -}; - -QT_END_NAMESPACE - -#endif // QMLNULLABLEVALUE_P_H diff --git a/src/declarative/util/qmlnullablevalue_p_p.h b/src/declarative/util/qmlnullablevalue_p_p.h new file mode 100644 index 0000000..6455642 --- /dev/null +++ b/src/declarative/util/qmlnullablevalue_p_p.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 QMLNULLABLEVALUE_P_H +#define QMLNULLABLEVALUE_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. +// + +QT_BEGIN_NAMESPACE + +template +struct QmlNullableValue +{ + QmlNullableValue() + : isNull(true), value(T()) {} + QmlNullableValue(const QmlNullableValue &o) + : isNull(o.isNull), value(o.value) {} + QmlNullableValue(const T &t) + : isNull(false), value(t) {} + QmlNullableValue &operator=(const T &t) + { isNull = false; value = t; return *this; } + QmlNullableValue &operator=(const QmlNullableValue &o) + { isNull = o.isNull; value = o.value; return *this; } + operator T() const { return value; } + + void invalidate() { isNull = true; } + bool isValid() const { return !isNull; } + bool isNull; + T value; +}; + +QT_END_NAMESPACE + +#endif // QMLNULLABLEVALUE_P_H diff --git a/src/declarative/util/qmlopenmetaobject.cpp b/src/declarative/util/qmlopenmetaobject.cpp index 11648f6..c348ced 100644 --- a/src/declarative/util/qmlopenmetaobject.cpp +++ b/src/declarative/util/qmlopenmetaobject.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlopenmetaobject.h" +#include "qmlopenmetaobject_p.h" #include "private/qmetaobjectbuilder_p.h" #include diff --git a/src/declarative/util/qmlopenmetaobject.h b/src/declarative/util/qmlopenmetaobject.h deleted file mode 100644 index be0490d..0000000 --- a/src/declarative/util/qmlopenmetaobject.h +++ /dev/null @@ -1,91 +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 QMLOPENMETAOBJECT_H -#define QMLOPENMETAOBJECT_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlOpenMetaObjectPrivate; -class QMetaPropertyBuilder; -class Q_DECLARATIVE_EXPORT QmlOpenMetaObject : public QAbstractDynamicMetaObject -{ -public: - QmlOpenMetaObject(QObject *, bool = true); - ~QmlOpenMetaObject(); - - QVariant value(const QByteArray &) const; - void setValue(const QByteArray &, const QVariant &); - QVariant value(int) const; - void setValue(int, const QVariant &); - QVariant &operator[](const QByteArray &); - - int count() const; - QByteArray name(int) const; - - QObject *object() const; -protected: - virtual int metaCall(QMetaObject::Call _c, int _id, void **_a); - virtual int createProperty(const char *, const char *); - - virtual void propertyRead(int); - virtual void propertyWrite(int); - virtual QVariant propertyCreated(int, QMetaPropertyBuilder &); - -private: - int doCreateProperty(const char *); - - QmlOpenMetaObjectPrivate *d; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMLOPENMETAOBJECT_H diff --git a/src/declarative/util/qmlopenmetaobject_p.h b/src/declarative/util/qmlopenmetaobject_p.h new file mode 100644 index 0000000..be0490d --- /dev/null +++ b/src/declarative/util/qmlopenmetaobject_p.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** 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 QMLOPENMETAOBJECT_H +#define QMLOPENMETAOBJECT_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlOpenMetaObjectPrivate; +class QMetaPropertyBuilder; +class Q_DECLARATIVE_EXPORT QmlOpenMetaObject : public QAbstractDynamicMetaObject +{ +public: + QmlOpenMetaObject(QObject *, bool = true); + ~QmlOpenMetaObject(); + + QVariant value(const QByteArray &) const; + void setValue(const QByteArray &, const QVariant &); + QVariant value(int) const; + void setValue(int, const QVariant &); + QVariant &operator[](const QByteArray &); + + int count() const; + QByteArray name(int) const; + + QObject *object() const; +protected: + virtual int metaCall(QMetaObject::Call _c, int _id, void **_a); + virtual int createProperty(const char *, const char *); + + virtual void propertyRead(int); + virtual void propertyWrite(int); + virtual QVariant propertyCreated(int, QMetaPropertyBuilder &); + +private: + int doCreateProperty(const char *); + + QmlOpenMetaObjectPrivate *d; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLOPENMETAOBJECT_H diff --git a/src/declarative/util/qmlpackage.cpp b/src/declarative/util/qmlpackage.cpp index 7df8453..05b6cbc 100644 --- a/src/declarative/util/qmlpackage.cpp +++ b/src/declarative/util/qmlpackage.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "private/qobject_p.h" -#include "qmlpackage.h" +#include "qmlpackage_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qmlpackage.h b/src/declarative/util/qmlpackage.h deleted file mode 100644 index 7cceaa7..0000000 --- a/src/declarative/util/qmlpackage.h +++ /dev/null @@ -1,88 +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 QMLPACKAGE_H -#define QMLPACKAGE_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -/***************************************************************************** - ***************************************************************************** - XXX Experimental - ***************************************************************************** -*****************************************************************************/ - -class QmlPackagePrivate; -class QmlPackageAttached; -class QmlPackage : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlPackage) - - Q_CLASSINFO("DefaultProperty", "data") - Q_PROPERTY(QmlList *data READ data SCRIPTABLE false) - -public: - QmlPackage(QObject *parent=0); - virtual ~QmlPackage(); - - QmlList *data(); - - QObject *part(const QString & = QString()); - bool hasPart(const QString &); - - static QmlPackageAttached *qmlAttachedProperties(QObject *); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlPackage) -QML_DECLARE_TYPEINFO(QmlPackage, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER - -#endif // QMLPACKAGE_H diff --git a/src/declarative/util/qmlpackage_p.h b/src/declarative/util/qmlpackage_p.h new file mode 100644 index 0000000..7cceaa7 --- /dev/null +++ b/src/declarative/util/qmlpackage_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 QMLPACKAGE_H +#define QMLPACKAGE_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +/***************************************************************************** + ***************************************************************************** + XXX Experimental + ***************************************************************************** +*****************************************************************************/ + +class QmlPackagePrivate; +class QmlPackageAttached; +class QmlPackage : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlPackage) + + Q_CLASSINFO("DefaultProperty", "data") + Q_PROPERTY(QmlList *data READ data SCRIPTABLE false) + +public: + QmlPackage(QObject *parent=0); + virtual ~QmlPackage(); + + QmlList *data(); + + QObject *part(const QString & = QString()); + bool hasPart(const QString &); + + static QmlPackageAttached *qmlAttachedProperties(QObject *); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlPackage) +QML_DECLARE_TYPEINFO(QmlPackage, QML_HAS_ATTACHED_PROPERTIES) + +QT_END_HEADER + +#endif // QMLPACKAGE_H diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp index 0ac168b..57db897 100644 --- a/src/declarative/util/qmlpropertychanges.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -40,8 +40,8 @@ ****************************************************************************/ #include "private/qobject_p.h" -#include "qmlopenmetaobject.h" -#include "qmlpropertychanges.h" +#include "qmlopenmetaobject_p.h" +#include "qmlpropertychanges_p.h" #include #include #include diff --git a/src/declarative/util/qmlpropertychanges.h b/src/declarative/util/qmlpropertychanges.h deleted file mode 100644 index 2931cdb..0000000 --- a/src/declarative/util/qmlpropertychanges.h +++ /dev/null @@ -1,84 +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 QMLPROPERTYCHANGES_H -#define QMLPROPERTYCHANGES_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlPropertyChangesPrivate; -class Q_DECLARATIVE_EXPORT QmlPropertyChanges : public QmlStateOperation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlPropertyChanges) - - Q_PROPERTY(QObject *target READ object WRITE setObject) - Q_PROPERTY(bool restoreEntryValues READ restoreEntryValues WRITE setRestoreEntryValues) - Q_PROPERTY(bool explicit READ isExplicit WRITE setIsExplicit) -public: - QmlPropertyChanges(); - ~QmlPropertyChanges(); - - QObject *object() const; - void setObject(QObject *); - - bool restoreEntryValues() const; - void setRestoreEntryValues(bool); - - bool isExplicit() const; - void setIsExplicit(bool); - - virtual ActionList actions(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlPropertyChanges) - -QT_END_HEADER - -#endif // QMLPROPERTYCHANGES_H diff --git a/src/declarative/util/qmlpropertychanges_p.h b/src/declarative/util/qmlpropertychanges_p.h new file mode 100644 index 0000000..cb93eb3 --- /dev/null +++ b/src/declarative/util/qmlpropertychanges_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 QMLPROPERTYCHANGES_H +#define QMLPROPERTYCHANGES_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlPropertyChangesPrivate; +class Q_DECLARATIVE_EXPORT QmlPropertyChanges : public QmlStateOperation +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlPropertyChanges) + + Q_PROPERTY(QObject *target READ object WRITE setObject) + Q_PROPERTY(bool restoreEntryValues READ restoreEntryValues WRITE setRestoreEntryValues) + Q_PROPERTY(bool explicit READ isExplicit WRITE setIsExplicit) +public: + QmlPropertyChanges(); + ~QmlPropertyChanges(); + + QObject *object() const; + void setObject(QObject *); + + bool restoreEntryValues() const; + void setRestoreEntryValues(bool); + + bool isExplicit() const; + void setIsExplicit(bool); + + virtual ActionList actions(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlPropertyChanges) + +QT_END_HEADER + +#endif // QMLPROPERTYCHANGES_H diff --git a/src/declarative/util/qmlpropertymap.cpp b/src/declarative/util/qmlpropertymap.cpp index a587af3..c54135c 100644 --- a/src/declarative/util/qmlpropertymap.cpp +++ b/src/declarative/util/qmlpropertymap.cpp @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#include "qmlpropertymap.h" -#include +#include "qmlpropertymap_p.h" +#include #include QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qmlpropertymap.h b/src/declarative/util/qmlpropertymap.h deleted file mode 100644 index 24b4395..0000000 --- a/src/declarative/util/qmlpropertymap.h +++ /dev/null @@ -1,91 +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 QMLPROPERTYMAP_H -#define QMLPROPERTYMAP_H - -#include -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlPropertyMapPrivate; -class Q_DECLARATIVE_EXPORT QmlPropertyMap : public QObject -{ - Q_OBJECT -public: - QmlPropertyMap(QObject *parent = 0); - virtual ~QmlPropertyMap(); - - QVariant value(const QString &key) const; - void insert(const QString &key, const QVariant &value); - void clear(const QString &key); - - Q_INVOKABLE QStringList keys() const; - - int count() const; - int size() const; - bool isEmpty() const; - bool contains(const QString &key) const; - - QVariant &operator[](const QString &key); - const QVariant operator[](const QString &key) const; - -Q_SIGNALS: - void valueChanged(const QString &key); - -private: - Q_DECLARE_PRIVATE(QmlPropertyMap) - Q_DISABLE_COPY(QmlPropertyMap) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/declarative/util/qmlpropertymap_p.h b/src/declarative/util/qmlpropertymap_p.h new file mode 100644 index 0000000..24b4395 --- /dev/null +++ b/src/declarative/util/qmlpropertymap_p.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** 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 QMLPROPERTYMAP_H +#define QMLPROPERTYMAP_H + +#include +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlPropertyMapPrivate; +class Q_DECLARATIVE_EXPORT QmlPropertyMap : public QObject +{ + Q_OBJECT +public: + QmlPropertyMap(QObject *parent = 0); + virtual ~QmlPropertyMap(); + + QVariant value(const QString &key) const; + void insert(const QString &key, const QVariant &value); + void clear(const QString &key); + + Q_INVOKABLE QStringList keys() const; + + int count() const; + int size() const; + bool isEmpty() const; + bool contains(const QString &key) const; + + QVariant &operator[](const QString &key); + const QVariant operator[](const QString &key) const; + +Q_SIGNALS: + void valueChanged(const QString &key); + +private: + Q_DECLARE_PRIVATE(QmlPropertyMap) + Q_DISABLE_COPY(QmlPropertyMap) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/declarative/util/qmlspringfollow.cpp b/src/declarative/util/qmlspringfollow.cpp index 3b2526b..354110e 100644 --- a/src/declarative/util/qmlspringfollow.cpp +++ b/src/declarative/util/qmlspringfollow.cpp @@ -43,8 +43,8 @@ #include #include #include "private/qobject_p.h" -#include "qmlspringfollow.h" -#include "private/qmlanimation_p.h" +#include "qmlspringfollow_p.h" +#include "private/qmlanimation_p_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qmlspringfollow.h b/src/declarative/util/qmlspringfollow.h deleted file mode 100644 index 1b77861..0000000 --- a/src/declarative/util/qmlspringfollow.h +++ /dev/null @@ -1,113 +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 QMLFOLLOW_H -#define QMLFOLLOW_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlSpringFollowPrivate; -class Q_DECLARATIVE_EXPORT QmlSpringFollow : public QObject, - public QmlPropertyValueSource -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlSpringFollow) - Q_INTERFACES(QmlPropertyValueSource) - - Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue) - Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) - Q_PROPERTY(qreal spring READ spring WRITE setSpring) - Q_PROPERTY(qreal damping READ damping WRITE setDamping) - Q_PROPERTY(qreal epsilon READ epsilon WRITE setEpsilon) - Q_PROPERTY(qreal modulus READ modulus WRITE setModulus) - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) - Q_PROPERTY(qreal value READ value NOTIFY valueChanged) - Q_PROPERTY(qreal modulus READ modulus WRITE setModulus NOTIFY modulusChanged) - Q_PROPERTY(qreal mass READ mass WRITE setMass NOTIFY massChanged) - Q_PROPERTY(bool inSync READ inSync NOTIFY syncChanged) - -public: - QmlSpringFollow(QObject *parent=0); - ~QmlSpringFollow(); - - virtual void setTarget(const QmlMetaProperty &); - - qreal sourceValue() const; - void setSourceValue(qreal value); - qreal velocity() const; - void setVelocity(qreal velocity); - qreal spring() const; - void setSpring(qreal spring); - qreal damping() const; - void setDamping(qreal damping); - qreal epsilon() const; - void setEpsilon(qreal epsilon); - qreal mass() const; - void setMass(qreal modulus); - qreal modulus() const; - void setModulus(qreal modulus); - bool enabled() const; - void setEnabled(bool enabled); - bool inSync() const; - - qreal value() const; - -Q_SIGNALS: - void valueChanged(qreal); - void modulusChanged(); - void massChanged(); - void syncChanged(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlSpringFollow) - -QT_END_HEADER - -#endif // QFXFOLLOW_H diff --git a/src/declarative/util/qmlspringfollow_p.h b/src/declarative/util/qmlspringfollow_p.h new file mode 100644 index 0000000..1b77861 --- /dev/null +++ b/src/declarative/util/qmlspringfollow_p.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** 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 QMLFOLLOW_H +#define QMLFOLLOW_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlSpringFollowPrivate; +class Q_DECLARATIVE_EXPORT QmlSpringFollow : public QObject, + public QmlPropertyValueSource +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlSpringFollow) + Q_INTERFACES(QmlPropertyValueSource) + + Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue) + Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) + Q_PROPERTY(qreal spring READ spring WRITE setSpring) + Q_PROPERTY(qreal damping READ damping WRITE setDamping) + Q_PROPERTY(qreal epsilon READ epsilon WRITE setEpsilon) + Q_PROPERTY(qreal modulus READ modulus WRITE setModulus) + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) + Q_PROPERTY(qreal value READ value NOTIFY valueChanged) + Q_PROPERTY(qreal modulus READ modulus WRITE setModulus NOTIFY modulusChanged) + Q_PROPERTY(qreal mass READ mass WRITE setMass NOTIFY massChanged) + Q_PROPERTY(bool inSync READ inSync NOTIFY syncChanged) + +public: + QmlSpringFollow(QObject *parent=0); + ~QmlSpringFollow(); + + virtual void setTarget(const QmlMetaProperty &); + + qreal sourceValue() const; + void setSourceValue(qreal value); + qreal velocity() const; + void setVelocity(qreal velocity); + qreal spring() const; + void setSpring(qreal spring); + qreal damping() const; + void setDamping(qreal damping); + qreal epsilon() const; + void setEpsilon(qreal epsilon); + qreal mass() const; + void setMass(qreal modulus); + qreal modulus() const; + void setModulus(qreal modulus); + bool enabled() const; + void setEnabled(bool enabled); + bool inSync() const; + + qreal value() const; + +Q_SIGNALS: + void valueChanged(qreal); + void modulusChanged(); + void massChanged(); + void syncChanged(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlSpringFollow) + +QT_END_HEADER + +#endif // QFXFOLLOW_H diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index 425480c..6908175 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -39,14 +39,14 @@ ** ****************************************************************************/ -#include "qmltransition.h" -#include "qmlstategroup.h" -#include "qmlstate_p.h" +#include "qmltransition_p.h" +#include "qmlstategroup_p.h" +#include "qmlstate_p_p.h" #include "qmlbinding.h" -#include "qmlstateoperations.h" -#include "qmlanimation.h" +#include "qmlstateoperations_p.h" #include "qmlanimation_p.h" -#include "qmlstate.h" +#include "qmlanimation_p_p.h" +#include "qmlstate_p.h" #include QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h deleted file mode 100644 index 50128c0..0000000 --- a/src/declarative/util/qmlstate.h +++ /dev/null @@ -1,174 +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 QMLSTATE_H -#define QMLSTATE_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class ActionEvent; -class QmlBinding; -class Action -{ -public: - Action(); - Action(QObject *, const QString &, const QVariant &); - - bool restore:1; - bool actionDone:1; - bool reverseEvent:1; - bool deletableToBinding:1; - - QmlMetaProperty property; - QVariant fromValue; - QVariant toValue; - - QmlAbstractBinding *fromBinding; - QmlAbstractBinding *toBinding; - ActionEvent *event; - - //strictly for matching - QObject *specifiedObject; - QString specifiedProperty; - - void deleteFromBinding(); -}; - -class ActionEvent -{ -public: - virtual ~ActionEvent(); - virtual QString typeName() const; - - virtual void execute(); - virtual bool isReversable(); - virtual void reverse(); - virtual void saveOriginals() {} - - //virtual bool hasExtraActions(); - virtual QList extraActions(); - - virtual bool changesBindings(); - virtual void clearForwardBindings(); - virtual void clearReverseBindings(); - virtual bool override(ActionEvent*other); -}; - -//### rename to QmlStateChange? -class QmlStateGroup; -class Q_DECLARATIVE_EXPORT QmlStateOperation : public QObject -{ - Q_OBJECT -public: - QmlStateOperation(QObject *parent = 0) - : QObject(parent) {} - typedef QList ActionList; - - virtual ActionList actions(); - -protected: - QmlStateOperation(QObjectPrivate &dd, QObject *parent = 0); -}; - -typedef QmlStateOperation::ActionList QmlStateActions; - -class QmlTransition; -class QmlStatePrivate; -class Q_DECLARATIVE_EXPORT QmlState : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QmlBinding *when READ when WRITE setWhen) - Q_PROPERTY(QString extend READ extends WRITE setExtends) - Q_PROPERTY(QmlList* changes READ changes) - Q_CLASSINFO("DefaultProperty", "changes") - -public: - QmlState(QObject *parent=0); - virtual ~QmlState(); - - QString name() const; - void setName(const QString &); - - /*'when' is a QmlBinding to limit state changes oscillation - due to the unpredictable order of evaluation of bound expressions*/ - bool isWhenKnown() const; - QmlBinding *when() const; - void setWhen(QmlBinding *); - - QString extends() const; - void setExtends(const QString &); - - QmlList *changes(); - QmlState &operator<<(QmlStateOperation *); - - void apply(QmlStateGroup *, QmlTransition *, QmlState *revert); - void cancel(); - - QmlStateGroup *stateGroup() const; - void setStateGroup(QmlStateGroup *); - -Q_SIGNALS: - void completed(); - -private: - Q_DECLARE_PRIVATE(QmlState) - Q_DISABLE_COPY(QmlState) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlStateOperation) -QML_DECLARE_TYPE(QmlState) - -QT_END_HEADER - -#endif // QMLSTATE_H diff --git a/src/declarative/util/qmlstate_p.h b/src/declarative/util/qmlstate_p.h index 63fc6da..50128c0 100644 --- a/src/declarative/util/qmlstate_p.h +++ b/src/declarative/util/qmlstate_p.h @@ -39,83 +39,136 @@ ** ****************************************************************************/ -#ifndef QMLSTATE_P_H -#define QMLSTATE_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 -#include -#include -#include +#ifndef QMLSTATE_H +#define QMLSTATE_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class SimpleAction +QT_MODULE(Declarative) + +class ActionEvent; +class QmlBinding; +class Action { public: - enum State { StartState, EndState }; - SimpleAction(const Action &a, State state = StartState) - { - property = a.property; - specifiedObject = a.specifiedObject; - specifiedProperty = a.specifiedProperty; - event = a.event; - if (state == StartState) { - value = a.fromValue; - binding = property.binding(); - reverseEvent = true; - } else { - value = a.toValue; - binding = a.toBinding; - reverseEvent = false; - } - } + Action(); + Action(QObject *, const QString &, const QVariant &); + + bool restore:1; + bool actionDone:1; + bool reverseEvent:1; + bool deletableToBinding:1; QmlMetaProperty property; - QVariant value; - QmlAbstractBinding *binding; + QVariant fromValue; + QVariant toValue; + + QmlAbstractBinding *fromBinding; + QmlAbstractBinding *toBinding; + ActionEvent *event; + + //strictly for matching QObject *specifiedObject; QString specifiedProperty; - ActionEvent *event; - bool reverseEvent; + + void deleteFromBinding(); }; -class QmlStatePrivate : public QObjectPrivate +class ActionEvent { - Q_DECLARE_PUBLIC(QmlState) +public: + virtual ~ActionEvent(); + virtual QString typeName() const; + + virtual void execute(); + virtual bool isReversable(); + virtual void reverse(); + virtual void saveOriginals() {} + + //virtual bool hasExtraActions(); + virtual QList extraActions(); + virtual bool changesBindings(); + virtual void clearForwardBindings(); + virtual void clearReverseBindings(); + virtual bool override(ActionEvent*other); +}; + +//### rename to QmlStateChange? +class QmlStateGroup; +class Q_DECLARATIVE_EXPORT QmlStateOperation : public QObject +{ + Q_OBJECT public: - QmlStatePrivate() - : when(0), inState(false), group(0) {} + QmlStateOperation(QObject *parent = 0) + : QObject(parent) {} + typedef QList ActionList; - typedef QList SimpleActionList; + virtual ActionList actions(); - QString name; - QmlBinding *when; - QmlConcreteList operations; +protected: + QmlStateOperation(QObjectPrivate &dd, QObject *parent = 0); +}; + +typedef QmlStateOperation::ActionList QmlStateActions; + +class QmlTransition; +class QmlStatePrivate; +class Q_DECLARATIVE_EXPORT QmlState : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QmlBinding *when READ when WRITE setWhen) + Q_PROPERTY(QString extend READ extends WRITE setExtends) + Q_PROPERTY(QmlList* changes READ changes) + Q_CLASSINFO("DefaultProperty", "changes") + +public: + QmlState(QObject *parent=0); + virtual ~QmlState(); - QmlTransitionManager transitionManager; + QString name() const; + void setName(const QString &); - SimpleActionList revertList; - QList reverting; - QString extends; - mutable bool inState; - QmlStateGroup *group; + /*'when' is a QmlBinding to limit state changes oscillation + due to the unpredictable order of evaluation of bound expressions*/ + bool isWhenKnown() const; + QmlBinding *when() const; + void setWhen(QmlBinding *); - QmlStateOperation::ActionList generateActionList(QmlStateGroup *) const; - void complete(); + QString extends() const; + void setExtends(const QString &); + + QmlList *changes(); + QmlState &operator<<(QmlStateOperation *); + + void apply(QmlStateGroup *, QmlTransition *, QmlState *revert); + void cancel(); + + QmlStateGroup *stateGroup() const; + void setStateGroup(QmlStateGroup *); + +Q_SIGNALS: + void completed(); + +private: + Q_DECLARE_PRIVATE(QmlState) + Q_DISABLE_COPY(QmlState) }; QT_END_NAMESPACE -#endif // QMLSTATE_P_H +QML_DECLARE_TYPE(QmlStateOperation) +QML_DECLARE_TYPE(QmlState) + +QT_END_HEADER + +#endif // QMLSTATE_H diff --git a/src/declarative/util/qmlstate_p_p.h b/src/declarative/util/qmlstate_p_p.h new file mode 100644 index 0000000..2b62213 --- /dev/null +++ b/src/declarative/util/qmlstate_p_p.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** 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 QMLSTATE_P_H +#define QMLSTATE_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 +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class SimpleAction +{ +public: + enum State { StartState, EndState }; + SimpleAction(const Action &a, State state = StartState) + { + property = a.property; + specifiedObject = a.specifiedObject; + specifiedProperty = a.specifiedProperty; + event = a.event; + if (state == StartState) { + value = a.fromValue; + binding = property.binding(); + reverseEvent = true; + } else { + value = a.toValue; + binding = a.toBinding; + reverseEvent = false; + } + } + + QmlMetaProperty property; + QVariant value; + QmlAbstractBinding *binding; + QObject *specifiedObject; + QString specifiedProperty; + ActionEvent *event; + bool reverseEvent; +}; + +class QmlStatePrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlState) + +public: + QmlStatePrivate() + : when(0), inState(false), group(0) {} + + typedef QList SimpleActionList; + + QString name; + QmlBinding *when; + QmlConcreteList operations; + + QmlTransitionManager transitionManager; + + SimpleActionList revertList; + QList reverting; + QString extends; + mutable bool inState; + QmlStateGroup *group; + + QmlStateOperation::ActionList generateActionList(QmlStateGroup *) const; + void complete(); +}; + +QT_END_NAMESPACE + +#endif // QMLSTATE_P_H diff --git a/src/declarative/util/qmlstategroup.cpp b/src/declarative/util/qmlstategroup.cpp index b07def1..6ef8dce 100644 --- a/src/declarative/util/qmlstategroup.cpp +++ b/src/declarative/util/qmlstategroup.cpp @@ -40,8 +40,8 @@ ****************************************************************************/ #include "private/qobject_p.h" -#include "qmlstategroup.h" -#include "qmltransition.h" +#include "qmlstategroup_p.h" +#include "qmltransition_p.h" #include #include diff --git a/src/declarative/util/qmlstategroup.h b/src/declarative/util/qmlstategroup.h deleted file mode 100644 index cf79eb4..0000000 --- a/src/declarative/util/qmlstategroup.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 QMLSTATEGROUP_H -#define QMLSTATEGROUP_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlStateGroupPrivate; -class Q_DECLARATIVE_EXPORT QmlStateGroup : public QObject, public QmlParserStatus -{ - Q_OBJECT - Q_INTERFACES(QmlParserStatus) - Q_DECLARE_PRIVATE(QmlStateGroup) - - Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) - Q_PROPERTY(QmlList* states READ statesProperty DESIGNABLE false) - Q_PROPERTY(QmlList* transitions READ transitionsProperty DESIGNABLE false) - -public: - QmlStateGroup(QObject * = 0); - virtual ~QmlStateGroup(); - - QString state() const; - void setState(const QString &); - - QmlList* statesProperty(); - QList states() const; - - QmlList* transitionsProperty(); - - QmlState *findState(const QString &name) const; - - virtual void classBegin(); - virtual void componentComplete(); -Q_SIGNALS: - void stateChanged(const QString &); - -private: - friend class QmlState; - void updateAutoState(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlStateGroup) - -QT_END_HEADER - -#endif // QMLSTATEGROUP_H diff --git a/src/declarative/util/qmlstategroup_p.h b/src/declarative/util/qmlstategroup_p.h new file mode 100644 index 0000000..3136b1e --- /dev/null +++ b/src/declarative/util/qmlstategroup_p.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 QMLSTATEGROUP_H +#define QMLSTATEGROUP_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlStateGroupPrivate; +class Q_DECLARATIVE_EXPORT QmlStateGroup : public QObject, public QmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QmlParserStatus) + Q_DECLARE_PRIVATE(QmlStateGroup) + + Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) + Q_PROPERTY(QmlList* states READ statesProperty DESIGNABLE false) + Q_PROPERTY(QmlList* transitions READ transitionsProperty DESIGNABLE false) + +public: + QmlStateGroup(QObject * = 0); + virtual ~QmlStateGroup(); + + QString state() const; + void setState(const QString &); + + QmlList* statesProperty(); + QList states() const; + + QmlList* transitionsProperty(); + + QmlState *findState(const QString &name) const; + + virtual void classBegin(); + virtual void componentComplete(); +Q_SIGNALS: + void stateChanged(const QString &); + +private: + friend class QmlState; + void updateAutoState(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlStateGroup) + +QT_END_HEADER + +#endif // QMLSTATEGROUP_H diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 5c328cf..af8ba63 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -43,10 +43,10 @@ #include #include #include -#include "qmlstateoperations.h" +#include "qmlstateoperations_p.h" #include #include -#include +#include #include #include #include @@ -730,8 +730,8 @@ bool QmlAnchorChanges::override(ActionEvent*other) return false; } -QT_END_NAMESPACE - #include "qmlstateoperations.moc" -#include "moc_qmlstateoperations.cpp" +#include "moc_qmlstateoperations_p.cpp" + +QT_END_NAMESPACE diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h deleted file mode 100644 index f2bcd49..0000000 --- a/src/declarative/util/qmlstateoperations.h +++ /dev/null @@ -1,177 +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 QMLSTATEOPERATIONS_H -#define QMLSTATEOPERATIONS_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlParentChangePrivate; -class Q_DECLARATIVE_EXPORT QmlParentChange : public QmlStateOperation, public ActionEvent -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlParentChange) - - Q_PROPERTY(QmlGraphicsItem *target READ object WRITE setObject) - Q_PROPERTY(QmlGraphicsItem *parent READ parent WRITE setParent) -public: - QmlParentChange(QObject *parent=0); - ~QmlParentChange(); - - QmlGraphicsItem *object() const; - void setObject(QmlGraphicsItem *); - - QmlGraphicsItem *parent() const; - void setParent(QmlGraphicsItem *); - - virtual ActionList actions(); - - virtual void saveOriginals(); - virtual void execute(); - virtual bool isReversable(); - virtual void reverse(); - virtual QString typeName() const; - virtual bool override(ActionEvent*other); -}; - -class QmlStateChangeScriptPrivate; -class Q_DECLARATIVE_EXPORT QmlStateChangeScript : public QmlStateOperation, public ActionEvent -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlStateChangeScript) - - Q_PROPERTY(QmlScriptString script READ script WRITE setScript) - Q_PROPERTY(QString name READ name WRITE setName) - -public: - QmlStateChangeScript(QObject *parent=0); - ~QmlStateChangeScript(); - - virtual ActionList actions(); - - QmlScriptString script() const; - void setScript(const QmlScriptString &); - - QString name() const; - void setName(const QString &); - - virtual void execute(); -}; - -class QmlAnchorChangesPrivate; -class Q_DECLARATIVE_EXPORT QmlAnchorChanges : public QmlStateOperation, public ActionEvent -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlAnchorChanges) - - Q_PROPERTY(QmlGraphicsItem *target READ object WRITE setObject) - Q_PROPERTY(QString reset READ reset WRITE setReset) - Q_PROPERTY(QmlGraphicsAnchorLine left READ left WRITE setLeft) - Q_PROPERTY(QmlGraphicsAnchorLine right READ right WRITE setRight) - Q_PROPERTY(QmlGraphicsAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter) - Q_PROPERTY(QmlGraphicsAnchorLine top READ top WRITE setTop) - Q_PROPERTY(QmlGraphicsAnchorLine bottom READ bottom WRITE setBottom) - Q_PROPERTY(QmlGraphicsAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter) - Q_PROPERTY(QmlGraphicsAnchorLine baseline READ baseline WRITE setBaseline) - -public: - QmlAnchorChanges(QObject *parent=0); - ~QmlAnchorChanges(); - - virtual ActionList actions(); - - QmlGraphicsItem *object() const; - void setObject(QmlGraphicsItem *); - - QString reset() const; - void setReset(const QString &); - - QmlGraphicsAnchorLine left() const; - void setLeft(const QmlGraphicsAnchorLine &edge); - - QmlGraphicsAnchorLine right() const; - void setRight(const QmlGraphicsAnchorLine &edge); - - QmlGraphicsAnchorLine horizontalCenter() const; - void setHorizontalCenter(const QmlGraphicsAnchorLine &edge); - - QmlGraphicsAnchorLine top() const; - void setTop(const QmlGraphicsAnchorLine &edge); - - QmlGraphicsAnchorLine bottom() const; - void setBottom(const QmlGraphicsAnchorLine &edge); - - QmlGraphicsAnchorLine verticalCenter() const; - void setVerticalCenter(const QmlGraphicsAnchorLine &edge); - - QmlGraphicsAnchorLine baseline() const; - void setBaseline(const QmlGraphicsAnchorLine &edge); - - virtual void execute(); - virtual bool isReversable(); - virtual void reverse(); - virtual QString typeName() const; - virtual bool override(ActionEvent*other); - virtual QList extraActions(); - virtual bool changesBindings(); - virtual void saveOriginals(); - virtual void clearForwardBindings(); - virtual void clearReverseBindings(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlParentChange) -QML_DECLARE_TYPE(QmlStateChangeScript) -QML_DECLARE_TYPE(QmlAnchorChanges) - -QT_END_HEADER - -#endif // QMLSTATEOPERATIONS_H diff --git a/src/declarative/util/qmlstateoperations_p.h b/src/declarative/util/qmlstateoperations_p.h new file mode 100644 index 0000000..04ea781 --- /dev/null +++ b/src/declarative/util/qmlstateoperations_p.h @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** 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 QMLSTATEOPERATIONS_H +#define QMLSTATEOPERATIONS_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlParentChangePrivate; +class Q_DECLARATIVE_EXPORT QmlParentChange : public QmlStateOperation, public ActionEvent +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlParentChange) + + Q_PROPERTY(QmlGraphicsItem *target READ object WRITE setObject) + Q_PROPERTY(QmlGraphicsItem *parent READ parent WRITE setParent) +public: + QmlParentChange(QObject *parent=0); + ~QmlParentChange(); + + QmlGraphicsItem *object() const; + void setObject(QmlGraphicsItem *); + + QmlGraphicsItem *parent() const; + void setParent(QmlGraphicsItem *); + + virtual ActionList actions(); + + virtual void saveOriginals(); + virtual void execute(); + virtual bool isReversable(); + virtual void reverse(); + virtual QString typeName() const; + virtual bool override(ActionEvent*other); +}; + +class QmlStateChangeScriptPrivate; +class Q_DECLARATIVE_EXPORT QmlStateChangeScript : public QmlStateOperation, public ActionEvent +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlStateChangeScript) + + Q_PROPERTY(QmlScriptString script READ script WRITE setScript) + Q_PROPERTY(QString name READ name WRITE setName) + +public: + QmlStateChangeScript(QObject *parent=0); + ~QmlStateChangeScript(); + + virtual ActionList actions(); + + QmlScriptString script() const; + void setScript(const QmlScriptString &); + + QString name() const; + void setName(const QString &); + + virtual void execute(); +}; + +class QmlAnchorChangesPrivate; +class Q_DECLARATIVE_EXPORT QmlAnchorChanges : public QmlStateOperation, public ActionEvent +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlAnchorChanges) + + Q_PROPERTY(QmlGraphicsItem *target READ object WRITE setObject) + Q_PROPERTY(QString reset READ reset WRITE setReset) + Q_PROPERTY(QmlGraphicsAnchorLine left READ left WRITE setLeft) + Q_PROPERTY(QmlGraphicsAnchorLine right READ right WRITE setRight) + Q_PROPERTY(QmlGraphicsAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter) + Q_PROPERTY(QmlGraphicsAnchorLine top READ top WRITE setTop) + Q_PROPERTY(QmlGraphicsAnchorLine bottom READ bottom WRITE setBottom) + Q_PROPERTY(QmlGraphicsAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter) + Q_PROPERTY(QmlGraphicsAnchorLine baseline READ baseline WRITE setBaseline) + +public: + QmlAnchorChanges(QObject *parent=0); + ~QmlAnchorChanges(); + + virtual ActionList actions(); + + QmlGraphicsItem *object() const; + void setObject(QmlGraphicsItem *); + + QString reset() const; + void setReset(const QString &); + + QmlGraphicsAnchorLine left() const; + void setLeft(const QmlGraphicsAnchorLine &edge); + + QmlGraphicsAnchorLine right() const; + void setRight(const QmlGraphicsAnchorLine &edge); + + QmlGraphicsAnchorLine horizontalCenter() const; + void setHorizontalCenter(const QmlGraphicsAnchorLine &edge); + + QmlGraphicsAnchorLine top() const; + void setTop(const QmlGraphicsAnchorLine &edge); + + QmlGraphicsAnchorLine bottom() const; + void setBottom(const QmlGraphicsAnchorLine &edge); + + QmlGraphicsAnchorLine verticalCenter() const; + void setVerticalCenter(const QmlGraphicsAnchorLine &edge); + + QmlGraphicsAnchorLine baseline() const; + void setBaseline(const QmlGraphicsAnchorLine &edge); + + virtual void execute(); + virtual bool isReversable(); + virtual void reverse(); + virtual QString typeName() const; + virtual bool override(ActionEvent*other); + virtual QList extraActions(); + virtual bool changesBindings(); + virtual void saveOriginals(); + virtual void clearForwardBindings(); + virtual void clearReverseBindings(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlParentChange) +QML_DECLARE_TYPE(QmlStateChangeScript) +QML_DECLARE_TYPE(QmlAnchorChanges) + +QT_END_HEADER + +#endif // QMLSTATEOPERATIONS_H diff --git a/src/declarative/util/qmlsystempalette.cpp b/src/declarative/util/qmlsystempalette.cpp index 014eca8..c5a0986 100644 --- a/src/declarative/util/qmlsystempalette.cpp +++ b/src/declarative/util/qmlsystempalette.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "private/qobject_p.h" -#include "qmlsystempalette.h" +#include "qmlsystempalette_p.h" #include QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qmlsystempalette.h b/src/declarative/util/qmlsystempalette.h deleted file mode 100644 index 6558c7e..0000000 --- a/src/declarative/util/qmlsystempalette.h +++ /dev/null @@ -1,122 +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 QMLSYSTEMPALETTE_H -#define QMLSYSTEMPALETTE_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlSystemPalettePrivate; -class Q_DECLARATIVE_EXPORT QmlSystemPalette : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlSystemPalette) - - Q_PROPERTY(QPalette::ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY paletteChanged) - Q_PROPERTY(QColor window READ window NOTIFY paletteChanged) - Q_PROPERTY(QColor windowText READ windowText NOTIFY paletteChanged) - Q_PROPERTY(QColor base READ base NOTIFY paletteChanged) - Q_PROPERTY(QColor text READ text NOTIFY paletteChanged) - Q_PROPERTY(QColor alternateBase READ alternateBase NOTIFY paletteChanged) - Q_PROPERTY(QColor button READ button NOTIFY paletteChanged) - Q_PROPERTY(QColor buttonText READ buttonText NOTIFY paletteChanged) - Q_PROPERTY(QColor light READ light NOTIFY paletteChanged) - Q_PROPERTY(QColor midlight READ midlight NOTIFY paletteChanged) - Q_PROPERTY(QColor dark READ dark NOTIFY paletteChanged) - Q_PROPERTY(QColor mid READ mid NOTIFY paletteChanged) - Q_PROPERTY(QColor shadow READ shadow NOTIFY paletteChanged) - Q_PROPERTY(QColor highlight READ highlight NOTIFY paletteChanged) - Q_PROPERTY(QColor highlightedText READ highlightedText NOTIFY paletteChanged) - -public: - QmlSystemPalette(QObject *parent=0); - ~QmlSystemPalette(); - - QColor window() const; - QColor windowText() const; - - QColor base() const; - QColor text() const; - QColor alternateBase() const; - - QColor button() const; - QColor buttonText() const; - - QColor light() const; - QColor midlight() const; - QColor dark() const; - QColor mid() const; - QColor shadow() const; - - QColor highlight() const; - QColor highlightedText() const; - - QPalette::ColorGroup colorGroup() const; - void setColorGroup(QPalette::ColorGroup); - - // FIXME: Move to utility class? - Q_INVOKABLE QColor lighter(const QColor&) const; - Q_INVOKABLE QColor darker(const QColor&) const; - -Q_SIGNALS: - void paletteChanged(); - -private: - bool eventFilter(QObject *watched, QEvent *event); - bool event(QEvent *event); - -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlSystemPalette) - -QT_END_HEADER - -#endif // QMLSYSTEMPALETTE_H diff --git a/src/declarative/util/qmlsystempalette_p.h b/src/declarative/util/qmlsystempalette_p.h new file mode 100644 index 0000000..6558c7e --- /dev/null +++ b/src/declarative/util/qmlsystempalette_p.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** 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 QMLSYSTEMPALETTE_H +#define QMLSYSTEMPALETTE_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlSystemPalettePrivate; +class Q_DECLARATIVE_EXPORT QmlSystemPalette : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlSystemPalette) + + Q_PROPERTY(QPalette::ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY paletteChanged) + Q_PROPERTY(QColor window READ window NOTIFY paletteChanged) + Q_PROPERTY(QColor windowText READ windowText NOTIFY paletteChanged) + Q_PROPERTY(QColor base READ base NOTIFY paletteChanged) + Q_PROPERTY(QColor text READ text NOTIFY paletteChanged) + Q_PROPERTY(QColor alternateBase READ alternateBase NOTIFY paletteChanged) + Q_PROPERTY(QColor button READ button NOTIFY paletteChanged) + Q_PROPERTY(QColor buttonText READ buttonText NOTIFY paletteChanged) + Q_PROPERTY(QColor light READ light NOTIFY paletteChanged) + Q_PROPERTY(QColor midlight READ midlight NOTIFY paletteChanged) + Q_PROPERTY(QColor dark READ dark NOTIFY paletteChanged) + Q_PROPERTY(QColor mid READ mid NOTIFY paletteChanged) + Q_PROPERTY(QColor shadow READ shadow NOTIFY paletteChanged) + Q_PROPERTY(QColor highlight READ highlight NOTIFY paletteChanged) + Q_PROPERTY(QColor highlightedText READ highlightedText NOTIFY paletteChanged) + +public: + QmlSystemPalette(QObject *parent=0); + ~QmlSystemPalette(); + + QColor window() const; + QColor windowText() const; + + QColor base() const; + QColor text() const; + QColor alternateBase() const; + + QColor button() const; + QColor buttonText() const; + + QColor light() const; + QColor midlight() const; + QColor dark() const; + QColor mid() const; + QColor shadow() const; + + QColor highlight() const; + QColor highlightedText() const; + + QPalette::ColorGroup colorGroup() const; + void setColorGroup(QPalette::ColorGroup); + + // FIXME: Move to utility class? + Q_INVOKABLE QColor lighter(const QColor&) const; + Q_INVOKABLE QColor darker(const QColor&) const; + +Q_SIGNALS: + void paletteChanged(); + +private: + bool eventFilter(QObject *watched, QEvent *event); + bool event(QEvent *event); + +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlSystemPalette) + +QT_END_HEADER + +#endif // QMLSYSTEMPALETTE_H diff --git a/src/declarative/util/qmltimeline.cpp b/src/declarative/util/qmltimeline.cpp index 5ba310d..55d9490 100644 --- a/src/declarative/util/qmltimeline.cpp +++ b/src/declarative/util/qmltimeline.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmltimeline_p.h" +#include "qmltimeline_p_p.h" #include #include #include diff --git a/src/declarative/util/qmltimeline_p.h b/src/declarative/util/qmltimeline_p.h deleted file mode 100644 index abed80a..0000000 --- a/src/declarative/util/qmltimeline_p.h +++ /dev/null @@ -1,224 +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 QMLTIMELINE_H -#define QMLTIMELINE_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 -#include -#include - -QT_BEGIN_NAMESPACE - -class QEasingCurve; -class QmlTimeLineValue; -class QmlTimeLineEvent; -struct QmlTimeLinePrivate; -class QmlTimeLineObject; -class Q_DECLARATIVE_EXPORT QmlTimeLine : public QAbstractAnimation -{ -Q_OBJECT -public: - QmlTimeLine(QObject *parent = 0); - ~QmlTimeLine(); - - enum SyncMode { LocalSync, GlobalSync }; - SyncMode syncMode() const; - void setSyncMode(SyncMode); - - void pause(QmlTimeLineObject &, int); - void execute(const QmlTimeLineEvent &); - void set(QmlTimeLineValue &, qreal); - - int accel(QmlTimeLineValue &, qreal velocity, qreal accel); - int accel(QmlTimeLineValue &, qreal velocity, qreal accel, qreal maxDistance); - int accelDistance(QmlTimeLineValue &, qreal velocity, qreal distance); - - void move(QmlTimeLineValue &, qreal destination, int time = 500); - void move(QmlTimeLineValue &, qreal destination, const QEasingCurve &, int time = 500); - void moveBy(QmlTimeLineValue &, qreal change, int time = 500); - void moveBy(QmlTimeLineValue &, qreal change, const QEasingCurve &, int time = 500); - - void sync(); - void setSyncPoint(int); - int syncPoint() const; - - void sync(QmlTimeLineValue &); - void sync(QmlTimeLineValue &, QmlTimeLineValue &); - - void reset(QmlTimeLineValue &); - - void complete(); - void clear(); - bool isActive() const; - - int time() const; - - virtual int duration() const; -Q_SIGNALS: - void updated(); - void completed(); - -protected: - virtual void updateCurrentTime(int); - -private: - void remove(QmlTimeLineObject *); - friend class QmlTimeLineObject; - friend struct QmlTimeLinePrivate; - QmlTimeLinePrivate *d; -}; - -class Q_DECLARATIVE_EXPORT QmlTimeLineObject -{ -public: - QmlTimeLineObject(); - virtual ~QmlTimeLineObject(); - -protected: - friend class QmlTimeLine; - friend struct QmlTimeLinePrivate; - QmlTimeLine *_t; -}; - -class Q_DECLARATIVE_EXPORT QmlTimeLineValue : public QmlTimeLineObject -{ -public: - QmlTimeLineValue(qreal v = 0.) : _v(v) {} - - virtual qreal value() const { return _v; } - virtual void setValue(qreal v) { _v = v; } - - QmlTimeLine *timeLine() const { return _t; } - - operator qreal() const { return _v; } - QmlTimeLineValue &operator=(qreal v) { setValue(v); return *this; } -private: - friend class QmlTimeLine; - friend struct QmlTimeLinePrivate; - qreal _v; -}; - -class Q_DECLARATIVE_EXPORT QmlTimeLineEvent -{ -public: - QmlTimeLineEvent(); - QmlTimeLineEvent(const QmlTimeLineEvent &o); - - template - QmlTimeLineEvent(QmlTimeLineObject *b, T *c) - { - d0 = &callFunc; - d1 = (void *)c; - d2 = b; - } - - template - static QmlTimeLineEvent timeLineEvent(QmlTimeLineObject *b, T *c) - { - QmlTimeLineEvent rv; - rv.d0 = &callFunc; - rv.d1 = (void *)c; - rv.d2 = b; - return rv; - } - - QmlTimeLineEvent &operator=(const QmlTimeLineEvent &o); - void execute() const; - QmlTimeLineObject *eventObject() const; - -private: - typedef void (*CallFunc)(void *c); - - template - static void callFunc(void *c) - { - T *cls = (T *)c; - (cls->*method)(); - } - CallFunc d0; - void *d1; - QmlTimeLineObject *d2; -}; - -template -class QmlTimeLineValueProxy : public QmlTimeLineValue -{ -public: - QmlTimeLineValueProxy(T *cls, void (T::*func)(qreal), qreal v = 0.) - : QmlTimeLineValue(v), _class(cls), _setFunctionReal(func), _setFunctionInt(0) - { - Q_ASSERT(_class); - } - - QmlTimeLineValueProxy(T *cls, void (T::*func)(int), qreal v = 0.) - : QmlTimeLineValue(v), _class(cls), _setFunctionReal(0), _setFunctionInt(func) - { - Q_ASSERT(_class); - } - - virtual void setValue(qreal v) - { - QmlTimeLineValue::setValue(v); - if (_setFunctionReal) (_class->*_setFunctionReal)(v); - else if (_setFunctionInt) (_class->*_setFunctionInt)((int)v); - } - -private: - T *_class; - void (T::*_setFunctionReal)(qreal); - void (T::*_setFunctionInt)(int); -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/declarative/util/qmltimeline_p_p.h b/src/declarative/util/qmltimeline_p_p.h new file mode 100644 index 0000000..abed80a --- /dev/null +++ b/src/declarative/util/qmltimeline_p_p.h @@ -0,0 +1,224 @@ +/**************************************************************************** +** +** 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 QMLTIMELINE_H +#define QMLTIMELINE_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 +#include +#include + +QT_BEGIN_NAMESPACE + +class QEasingCurve; +class QmlTimeLineValue; +class QmlTimeLineEvent; +struct QmlTimeLinePrivate; +class QmlTimeLineObject; +class Q_DECLARATIVE_EXPORT QmlTimeLine : public QAbstractAnimation +{ +Q_OBJECT +public: + QmlTimeLine(QObject *parent = 0); + ~QmlTimeLine(); + + enum SyncMode { LocalSync, GlobalSync }; + SyncMode syncMode() const; + void setSyncMode(SyncMode); + + void pause(QmlTimeLineObject &, int); + void execute(const QmlTimeLineEvent &); + void set(QmlTimeLineValue &, qreal); + + int accel(QmlTimeLineValue &, qreal velocity, qreal accel); + int accel(QmlTimeLineValue &, qreal velocity, qreal accel, qreal maxDistance); + int accelDistance(QmlTimeLineValue &, qreal velocity, qreal distance); + + void move(QmlTimeLineValue &, qreal destination, int time = 500); + void move(QmlTimeLineValue &, qreal destination, const QEasingCurve &, int time = 500); + void moveBy(QmlTimeLineValue &, qreal change, int time = 500); + void moveBy(QmlTimeLineValue &, qreal change, const QEasingCurve &, int time = 500); + + void sync(); + void setSyncPoint(int); + int syncPoint() const; + + void sync(QmlTimeLineValue &); + void sync(QmlTimeLineValue &, QmlTimeLineValue &); + + void reset(QmlTimeLineValue &); + + void complete(); + void clear(); + bool isActive() const; + + int time() const; + + virtual int duration() const; +Q_SIGNALS: + void updated(); + void completed(); + +protected: + virtual void updateCurrentTime(int); + +private: + void remove(QmlTimeLineObject *); + friend class QmlTimeLineObject; + friend struct QmlTimeLinePrivate; + QmlTimeLinePrivate *d; +}; + +class Q_DECLARATIVE_EXPORT QmlTimeLineObject +{ +public: + QmlTimeLineObject(); + virtual ~QmlTimeLineObject(); + +protected: + friend class QmlTimeLine; + friend struct QmlTimeLinePrivate; + QmlTimeLine *_t; +}; + +class Q_DECLARATIVE_EXPORT QmlTimeLineValue : public QmlTimeLineObject +{ +public: + QmlTimeLineValue(qreal v = 0.) : _v(v) {} + + virtual qreal value() const { return _v; } + virtual void setValue(qreal v) { _v = v; } + + QmlTimeLine *timeLine() const { return _t; } + + operator qreal() const { return _v; } + QmlTimeLineValue &operator=(qreal v) { setValue(v); return *this; } +private: + friend class QmlTimeLine; + friend struct QmlTimeLinePrivate; + qreal _v; +}; + +class Q_DECLARATIVE_EXPORT QmlTimeLineEvent +{ +public: + QmlTimeLineEvent(); + QmlTimeLineEvent(const QmlTimeLineEvent &o); + + template + QmlTimeLineEvent(QmlTimeLineObject *b, T *c) + { + d0 = &callFunc; + d1 = (void *)c; + d2 = b; + } + + template + static QmlTimeLineEvent timeLineEvent(QmlTimeLineObject *b, T *c) + { + QmlTimeLineEvent rv; + rv.d0 = &callFunc; + rv.d1 = (void *)c; + rv.d2 = b; + return rv; + } + + QmlTimeLineEvent &operator=(const QmlTimeLineEvent &o); + void execute() const; + QmlTimeLineObject *eventObject() const; + +private: + typedef void (*CallFunc)(void *c); + + template + static void callFunc(void *c) + { + T *cls = (T *)c; + (cls->*method)(); + } + CallFunc d0; + void *d1; + QmlTimeLineObject *d2; +}; + +template +class QmlTimeLineValueProxy : public QmlTimeLineValue +{ +public: + QmlTimeLineValueProxy(T *cls, void (T::*func)(qreal), qreal v = 0.) + : QmlTimeLineValue(v), _class(cls), _setFunctionReal(func), _setFunctionInt(0) + { + Q_ASSERT(_class); + } + + QmlTimeLineValueProxy(T *cls, void (T::*func)(int), qreal v = 0.) + : QmlTimeLineValue(v), _class(cls), _setFunctionReal(0), _setFunctionInt(func) + { + Q_ASSERT(_class); + } + + virtual void setValue(qreal v) + { + QmlTimeLineValue::setValue(v); + if (_setFunctionReal) (_class->*_setFunctionReal)(v); + else if (_setFunctionInt) (_class->*_setFunctionInt)((int)v); + } + +private: + T *_class; + void (T::*_setFunctionReal)(qreal); + void (T::*_setFunctionInt)(int); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/declarative/util/qmltimer.cpp b/src/declarative/util/qmltimer.cpp index 1d90051..ff4c912 100644 --- a/src/declarative/util/qmltimer.cpp +++ b/src/declarative/util/qmltimer.cpp @@ -42,7 +42,7 @@ #include "QtCore/qcoreapplication.h" #include "QtCore/qpauseanimation.h" #include "private/qobject_p.h" -#include "qmltimer.h" +#include "qmltimer_p.h" #include "qdebug.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qmltimer.h b/src/declarative/util/qmltimer.h deleted file mode 100644 index 22478cb..0000000 --- a/src/declarative/util/qmltimer.h +++ /dev/null @@ -1,108 +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 QMLTIMER_H -#define QMLTIMER_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlTimerPrivate; -class Q_DECLARATIVE_EXPORT QmlTimer : public QObject, public QmlParserStatus -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlTimer) - Q_INTERFACES(QmlParserStatus) - Q_PROPERTY(int interval READ interval WRITE setInterval) - Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) - Q_PROPERTY(bool repeat READ isRepeating WRITE setRepeating) - Q_PROPERTY(bool triggeredOnStart READ triggeredOnStart WRITE setTriggeredOnStart) - -public: - QmlTimer(QObject *parent=0); - - void setInterval(int interval); - int interval() const; - - bool isRunning() const; - void setRunning(bool running); - - bool isRepeating() const; - void setRepeating(bool repeating); - - bool triggeredOnStart() const; - void setTriggeredOnStart(bool triggeredOnStart); - -protected: - void classBegin(); - void componentComplete(); - -public Q_SLOTS: - void start(); - void stop(); - -Q_SIGNALS: - void triggered(); - void runningChanged(); - -private: - void update(); - -private Q_SLOTS: - void ticked(); - void stateChanged(QAbstractAnimation::State,QAbstractAnimation::State); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlTimer) - -QT_END_HEADER - -#endif diff --git a/src/declarative/util/qmltimer_p.h b/src/declarative/util/qmltimer_p.h new file mode 100644 index 0000000..22478cb --- /dev/null +++ b/src/declarative/util/qmltimer_p.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** 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 QMLTIMER_H +#define QMLTIMER_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlTimerPrivate; +class Q_DECLARATIVE_EXPORT QmlTimer : public QObject, public QmlParserStatus +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlTimer) + Q_INTERFACES(QmlParserStatus) + Q_PROPERTY(int interval READ interval WRITE setInterval) + Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) + Q_PROPERTY(bool repeat READ isRepeating WRITE setRepeating) + Q_PROPERTY(bool triggeredOnStart READ triggeredOnStart WRITE setTriggeredOnStart) + +public: + QmlTimer(QObject *parent=0); + + void setInterval(int interval); + int interval() const; + + bool isRunning() const; + void setRunning(bool running); + + bool isRepeating() const; + void setRepeating(bool repeating); + + bool triggeredOnStart() const; + void setTriggeredOnStart(bool triggeredOnStart); + +protected: + void classBegin(); + void componentComplete(); + +public Q_SLOTS: + void start(); + void stop(); + +Q_SIGNALS: + void triggered(); + void runningChanged(); + +private: + void update(); + +private Q_SLOTS: + void ticked(); + void stateChanged(QAbstractAnimation::State,QAbstractAnimation::State); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlTimer) + +QT_END_HEADER + +#endif diff --git a/src/declarative/util/qmltransition.cpp b/src/declarative/util/qmltransition.cpp index 97a3b74..d752d1b 100644 --- a/src/declarative/util/qmltransition.cpp +++ b/src/declarative/util/qmltransition.cpp @@ -39,13 +39,13 @@ ** ****************************************************************************/ -#include "qmlstate.h" -#include "qmlstategroup.h" #include "qmlstate_p.h" -#include "qmlstateoperations.h" -#include "qmlanimation.h" +#include "qmlstategroup_p.h" +#include "qmlstate_p_p.h" +#include "qmlstateoperations_p.h" #include "qmlanimation_p.h" -#include "qmltransitionmanager_p.h" +#include "qmlanimation_p_p.h" +#include "qmltransitionmanager_p_p.h" #include QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qmltransition.h b/src/declarative/util/qmltransition.h deleted file mode 100644 index b09341d..0000000 --- a/src/declarative/util/qmltransition.h +++ /dev/null @@ -1,99 +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 QMLTRANSITION_H -#define QMLTRANSITION_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlAbstractAnimation; -class QmlTransitionPrivate; -class QmlTransitionManager; -class Q_DECLARATIVE_EXPORT QmlTransition : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlTransition) - - Q_PROPERTY(QString from READ fromState WRITE setFromState) - Q_PROPERTY(QString to READ toState WRITE setToState) - Q_PROPERTY(bool reversible READ reversible WRITE setReversible) - Q_PROPERTY(QmlList* animations READ animations) - Q_CLASSINFO("DefaultProperty", "animations") - -public: - QmlTransition(QObject *parent=0); - ~QmlTransition(); - - QString fromState() const; - void setFromState(const QString &); - - QString toState() const; - void setToState(const QString &); - - bool reversible() const; - void setReversible(bool); - - QmlList* animations(); - - void prepare(QmlStateOperation::ActionList &actions, - QList &after, - QmlTransitionManager *end); - - void setReversed(bool r); - void stop(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlTransition) - -QT_END_HEADER - -#endif // QMLTRANSITION_H diff --git a/src/declarative/util/qmltransition_p.h b/src/declarative/util/qmltransition_p.h new file mode 100644 index 0000000..092cde9 --- /dev/null +++ b/src/declarative/util/qmltransition_p.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** 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 QMLTRANSITION_H +#define QMLTRANSITION_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlAbstractAnimation; +class QmlTransitionPrivate; +class QmlTransitionManager; +class Q_DECLARATIVE_EXPORT QmlTransition : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlTransition) + + Q_PROPERTY(QString from READ fromState WRITE setFromState) + Q_PROPERTY(QString to READ toState WRITE setToState) + Q_PROPERTY(bool reversible READ reversible WRITE setReversible) + Q_PROPERTY(QmlList* animations READ animations) + Q_CLASSINFO("DefaultProperty", "animations") + +public: + QmlTransition(QObject *parent=0); + ~QmlTransition(); + + QString fromState() const; + void setFromState(const QString &); + + QString toState() const; + void setToState(const QString &); + + bool reversible() const; + void setReversible(bool); + + QmlList* animations(); + + void prepare(QmlStateOperation::ActionList &actions, + QList &after, + QmlTransitionManager *end); + + void setReversed(bool r); + void stop(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QmlTransition) + +QT_END_HEADER + +#endif // QMLTRANSITION_H diff --git a/src/declarative/util/qmltransitionmanager.cpp b/src/declarative/util/qmltransitionmanager.cpp index 7eaccac..b33cae3 100644 --- a/src/declarative/util/qmltransitionmanager.cpp +++ b/src/declarative/util/qmltransitionmanager.cpp @@ -40,8 +40,8 @@ ****************************************************************************/ #include -#include -#include +#include +#include QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qmltransitionmanager_p.h b/src/declarative/util/qmltransitionmanager_p.h deleted file mode 100644 index 74a3950..0000000 --- a/src/declarative/util/qmltransitionmanager_p.h +++ /dev/null @@ -1,85 +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 QMLTRANSITIONMANAGER_P_H -#define QMLTRANSITIONMANAGER_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 - -QT_BEGIN_NAMESPACE - -class QmlStatePrivate; -class QmlTransitionManagerPrivate; -class QmlTransitionManager -{ -public: - QmlTransitionManager(); - ~QmlTransitionManager(); - - void transition(const QList &, QmlTransition *transition); - - void cancel(); - -private: - Q_DISABLE_COPY(QmlTransitionManager); - QmlTransitionManagerPrivate *d; - - void complete(); - void setState(QmlState *); - - friend class QmlState; - friend class QmlTransitionPrivate; -}; - -QT_END_NAMESPACE - -#endif // QMLTRANSITIONMANAGER_P_H diff --git a/src/declarative/util/qmltransitionmanager_p_p.h b/src/declarative/util/qmltransitionmanager_p_p.h new file mode 100644 index 0000000..ab435aa --- /dev/null +++ b/src/declarative/util/qmltransitionmanager_p_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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 QMLTRANSITIONMANAGER_P_H +#define QMLTRANSITIONMANAGER_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 + +QT_BEGIN_NAMESPACE + +class QmlStatePrivate; +class QmlTransitionManagerPrivate; +class QmlTransitionManager +{ +public: + QmlTransitionManager(); + ~QmlTransitionManager(); + + void transition(const QList &, QmlTransition *transition); + + void cancel(); + +private: + Q_DISABLE_COPY(QmlTransitionManager); + QmlTransitionManagerPrivate *d; + + void complete(); + void setState(QmlState *); + + friend class QmlState; + friend class QmlTransitionPrivate; +}; + +QT_END_NAMESPACE + +#endif // QMLTRANSITIONMANAGER_P_H diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index 91d443a..f19ac98 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -53,14 +53,14 @@ #include "qml.h" #include "qmlgraphicsitem.h" -#include "private/qperformancelog_p.h" -#include "private/qfxperf_p.h" +#include "private/qperformancelog_p_p.h" +#include "private/qfxperf_p_p.h" #include "qmlview.h" #include #include -#include -#include +#include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qperformancelog.cpp b/src/declarative/util/qperformancelog.cpp index 8e11997..1a9be90 100644 --- a/src/declarative/util/qperformancelog.cpp +++ b/src/declarative/util/qperformancelog.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qperformancelog_p.h" +#include "qperformancelog_p_p.h" #include #include diff --git a/src/declarative/util/qperformancelog_p.h b/src/declarative/util/qperformancelog_p.h deleted file mode 100644 index 6655a8d..0000000 --- a/src/declarative/util/qperformancelog_p.h +++ /dev/null @@ -1,141 +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 QPERFORMANCELOG_H -#define QPERFORMANCELOG_H - -#include - -QT_BEGIN_NAMESPACE - -namespace QPerformanceLog -{ - Q_DECLARATIVE_EXPORT void displayData(); - Q_DECLARATIVE_EXPORT void clear(); - -#ifdef Q_ENABLE_PERFORMANCE_LOG - struct LogData { - LogData(const char *); - QTime timer; - int sumTime; - unsigned int *data; - }; - - struct LogMetric { - LogMetric(LogData *, int, const char *); - }; - - // Internal - void displayData(LogData *); - void clear(LogData *); -#endif -} - -#ifdef Q_ENABLE_PERFORMANCE_LOG - -#define Q_DECLARE_PERFORMANCE_METRIC(name) \ - enum { name = ValueChoice<0, ValueTracker<0, __LINE__>::value, __LINE__>::value }; \ - template \ - struct ValueTracker \ - { \ - enum { value = name }; \ - }; \ - extern QPerformanceLog::LogMetric metric ## name; - -#define Q_DECLARE_PERFORMANCE_LOG(name) \ - namespace name { \ - extern QPerformanceLog::LogData log; \ - inline void displayData() { QPerformanceLog::displayData(&log); } \ - inline void clear() { QPerformanceLog::clear(&log); } \ - } \ - template \ - class name ## Timer { \ - public: \ - name ## Timer() { \ - lastSum = name::log.sumTime + name::log.timer.restart(); \ - name::log.sumTime = 0; \ - } \ - ~ name ## Timer() { \ - name::log.data[2 * N] += name::log.sumTime + name::log.timer.restart(); \ - ++name::log.data[2 * N + 1]; \ - name::log.sumTime = lastSum; \ - } \ - private: \ - int lastSum; \ - }; \ - namespace name { \ - template \ - struct ValueTracker \ - { \ - enum { value = -1 }; \ - }; \ - template \ - struct ValueChoice \ - { \ - enum { value = ValueChoice::value, L>::value }; \ - }; \ - template \ - struct ValueChoice \ - { \ - enum { value = DefNextValue }; \ - }; \ - } \ - namespace name - -#define Q_DEFINE_PERFORMANCE_LOG(name, desc) \ - QPerformanceLog::LogData name::log(desc); \ - namespace name - -#define Q_DEFINE_PERFORMANCE_METRIC(name, desc) \ - QPerformanceLog::LogMetric metrix ## name(&log, name, desc); - -#else // Q_ENABLE_PERFORMANCE_LOG - -#define Q_DECLARE_PERFORMANCE_METRIC(name) -#define Q_DECLARE_PERFORMANCE_LOG(name) namespace name -#define Q_DEFINE_PERFORMANCE_LOG(name, desc) namespace name -#define Q_DEFINE_PERFORMANCE_METRIC(name, desc) - -#endif // Q_ENABLE_PERFORMANCE_LOG - -QT_END_NAMESPACE - -#endif // QPERFORMANCELOG_H diff --git a/src/declarative/util/qperformancelog_p_p.h b/src/declarative/util/qperformancelog_p_p.h new file mode 100644 index 0000000..6655a8d --- /dev/null +++ b/src/declarative/util/qperformancelog_p_p.h @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** 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 QPERFORMANCELOG_H +#define QPERFORMANCELOG_H + +#include + +QT_BEGIN_NAMESPACE + +namespace QPerformanceLog +{ + Q_DECLARATIVE_EXPORT void displayData(); + Q_DECLARATIVE_EXPORT void clear(); + +#ifdef Q_ENABLE_PERFORMANCE_LOG + struct LogData { + LogData(const char *); + QTime timer; + int sumTime; + unsigned int *data; + }; + + struct LogMetric { + LogMetric(LogData *, int, const char *); + }; + + // Internal + void displayData(LogData *); + void clear(LogData *); +#endif +} + +#ifdef Q_ENABLE_PERFORMANCE_LOG + +#define Q_DECLARE_PERFORMANCE_METRIC(name) \ + enum { name = ValueChoice<0, ValueTracker<0, __LINE__>::value, __LINE__>::value }; \ + template \ + struct ValueTracker \ + { \ + enum { value = name }; \ + }; \ + extern QPerformanceLog::LogMetric metric ## name; + +#define Q_DECLARE_PERFORMANCE_LOG(name) \ + namespace name { \ + extern QPerformanceLog::LogData log; \ + inline void displayData() { QPerformanceLog::displayData(&log); } \ + inline void clear() { QPerformanceLog::clear(&log); } \ + } \ + template \ + class name ## Timer { \ + public: \ + name ## Timer() { \ + lastSum = name::log.sumTime + name::log.timer.restart(); \ + name::log.sumTime = 0; \ + } \ + ~ name ## Timer() { \ + name::log.data[2 * N] += name::log.sumTime + name::log.timer.restart(); \ + ++name::log.data[2 * N + 1]; \ + name::log.sumTime = lastSum; \ + } \ + private: \ + int lastSum; \ + }; \ + namespace name { \ + template \ + struct ValueTracker \ + { \ + enum { value = -1 }; \ + }; \ + template \ + struct ValueChoice \ + { \ + enum { value = ValueChoice::value, L>::value }; \ + }; \ + template \ + struct ValueChoice \ + { \ + enum { value = DefNextValue }; \ + }; \ + } \ + namespace name + +#define Q_DEFINE_PERFORMANCE_LOG(name, desc) \ + QPerformanceLog::LogData name::log(desc); \ + namespace name + +#define Q_DEFINE_PERFORMANCE_METRIC(name, desc) \ + QPerformanceLog::LogMetric metrix ## name(&log, name, desc); + +#else // Q_ENABLE_PERFORMANCE_LOG + +#define Q_DECLARE_PERFORMANCE_METRIC(name) +#define Q_DECLARE_PERFORMANCE_LOG(name) namespace name +#define Q_DEFINE_PERFORMANCE_LOG(name, desc) namespace name +#define Q_DEFINE_PERFORMANCE_METRIC(name, desc) + +#endif // Q_ENABLE_PERFORMANCE_LOG + +QT_END_NAMESPACE + +#endif // QPERFORMANCELOG_H diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index 01ad898..a60613e 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -24,28 +24,28 @@ SOURCES += \ HEADERS += \ util/qmlview.h \ - util/qfxperf_p.h \ + util/qfxperf_p_p.h \ util/qfxglobal.h \ - util/qperformancelog_p.h \ - util/qmlconnection.h \ - util/qmlpackage.h \ - util/qmlanimation.h \ + util/qperformancelog_p_p.h \ + util/qmlconnection_p.h \ + util/qmlpackage_p.h \ util/qmlanimation_p.h \ - util/qmlsystempalette.h \ - util/qmlspringfollow.h \ - util/qmleasefollow.h \ - util/qmlstate.h\ - util/qmlstateoperations.h \ - util/qmlpropertychanges.h \ + util/qmlanimation_p_p.h \ + util/qmlsystempalette_p.h \ + util/qmlspringfollow_p.h \ + util/qmleasefollow_p.h \ util/qmlstate_p.h\ - util/qmltransitionmanager_p.h \ - util/qmlstategroup.h \ - util/qmltransition.h \ - util/qmllistmodel.h\ - util/qmllistaccessor.h \ - util/qmlopenmetaobject.h \ - util/qmlnullablevalue_p.h \ - util/qmltimeline_p.h \ - util/qmltimer.h \ - util/qmlbind.h \ - util/qmlpropertymap.h + util/qmlstateoperations_p.h \ + util/qmlpropertychanges_p.h \ + util/qmlstate_p_p.h\ + util/qmltransitionmanager_p_p.h \ + util/qmlstategroup_p.h \ + util/qmltransition_p.h \ + util/qmllistmodel_p.h\ + util/qmllistaccessor_p.h \ + util/qmlopenmetaobject_p.h \ + util/qmlnullablevalue_p_p.h \ + util/qmltimeline_p_p.h \ + util/qmltimer_p.h \ + util/qmlbind_p.h \ + util/qmlpropertymap_p.h diff --git a/src/declarative/widgets/graphicslayouts.cpp b/src/declarative/widgets/graphicslayouts.cpp index 8707b94..e2f5370 100644 --- a/src/declarative/widgets/graphicslayouts.cpp +++ b/src/declarative/widgets/graphicslayouts.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "graphicslayouts.h" +#include "graphicslayouts_p.h" #include #include diff --git a/src/declarative/widgets/graphicslayouts.h b/src/declarative/widgets/graphicslayouts.h deleted file mode 100644 index 45f1439..0000000 --- a/src/declarative/widgets/graphicslayouts.h +++ /dev/null @@ -1,193 +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 GRAPHICSLAYOUTS_H -#define GRAPHICSLAYOUTS_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayoutItem) -public: - QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0); - - virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const; -}; - -//TODO: -// -content margins -// -per-item spacing (does this need to be exposed?) -// -per-item alignment -class LinearLayoutAttached; -class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) - - Q_PROPERTY(QmlList *children READ children) - Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsLinearLayoutObject(QObject * = 0); - ~QGraphicsLinearLayoutObject(); - - QmlList *children() { return &_children; } - - static LinearLayoutAttached *qmlAttachedProperties(QObject *); - -private Q_SLOTS: - void updateStretch(QGraphicsLayoutItem*,int); - void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); - -private: - friend class LinearLayoutAttached; - void clearChildren(); - void insertLayoutItem(int, QGraphicsLayoutItem *); - static QHash attachedProperties; - - class ChildList : public QmlList - { - public: - ChildList(QGraphicsLinearLayoutObject *o) - : obj(o) {} - - virtual void append(QGraphicsLayoutItem *item) - { - insert(-1, item); - } - virtual void clear() { obj->clearChildren(); } - virtual int count() const { return obj->count(); } - virtual void removeAt(int i) { obj->removeAt(i); } - virtual QGraphicsLayoutItem *at(int i) const { return obj->itemAt(i); } - virtual void insert(int i, QGraphicsLayoutItem *item) { obj->insertLayoutItem(i, item); } - - private: - QGraphicsLinearLayoutObject *obj; - }; - - ChildList _children; -}; - -//TODO: -// -content margins -// -column and row specific settings: -// -alignment -// -fixed/min/max/preferred width -// -spacing -// -stretch -class GridLayoutAttached; -class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) - - Q_PROPERTY(QmlList *children READ children) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) - Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing) - Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing) - Q_CLASSINFO("DefaultProperty", "children") -public: - QGraphicsGridLayoutObject(QObject * = 0); - ~QGraphicsGridLayoutObject(); - - QmlList *children() { return &_children; } - - qreal spacing() const; - - static GridLayoutAttached *qmlAttachedProperties(QObject *); - -private: - friend class GraphicsLayoutAttached; - void addWidget(QGraphicsWidget *); - void clearChildren(); - void addLayoutItem(QGraphicsLayoutItem *); - static QHash attachedProperties; - - class ChildList : public QmlList - { - public: - ChildList(QGraphicsGridLayoutObject *o) - : obj(o) {} - - virtual void append(QGraphicsLayoutItem *o) - { - obj->addLayoutItem(o); - } - virtual void clear() { obj->clearChildren(); } - virtual int count() const { return obj->count(); } - virtual void removeAt(int i) { obj->removeAt(i); } - virtual QGraphicsLayoutItem *at(int i) const { return obj->itemAt(i); } - //XXX GridLayout doesn't have an insert, so for now we treat it as an append. - // this is obviously potenitally dangerous -- perhaps should be a concrete - // list with no relation to layout index, etc at all. - virtual void insert(int, QGraphicsLayoutItem *item) { append(item); } - - private: - QGraphicsGridLayoutObject *obj; - }; - - ChildList _children; -}; - -QT_END_NAMESPACE - -QML_DECLARE_INTERFACE(QGraphicsLayoutItem) -QML_DECLARE_INTERFACE(QGraphicsLayout) -QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject) -QML_DECLARE_TYPE(QGraphicsLinearLayoutObject) -QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QGraphicsGridLayoutObject) -QML_DECLARE_TYPEINFO(QGraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER - -#endif // GRAPHICSLAYOUTS_H diff --git a/src/declarative/widgets/graphicslayouts_p.h b/src/declarative/widgets/graphicslayouts_p.h new file mode 100644 index 0000000..9eeac24 --- /dev/null +++ b/src/declarative/widgets/graphicslayouts_p.h @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** 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 GRAPHICSLAYOUTS_H +#define GRAPHICSLAYOUTS_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayoutItem) +public: + QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0); + + virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const; +}; + +//TODO: +// -content margins +// -per-item spacing (does this need to be exposed?) +// -per-item alignment +class LinearLayoutAttached; +class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QmlList *children READ children) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsLinearLayoutObject(QObject * = 0); + ~QGraphicsLinearLayoutObject(); + + QmlList *children() { return &_children; } + + static LinearLayoutAttached *qmlAttachedProperties(QObject *); + +private Q_SLOTS: + void updateStretch(QGraphicsLayoutItem*,int); + void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); + +private: + friend class LinearLayoutAttached; + void clearChildren(); + void insertLayoutItem(int, QGraphicsLayoutItem *); + static QHash attachedProperties; + + class ChildList : public QmlList + { + public: + ChildList(QGraphicsLinearLayoutObject *o) + : obj(o) {} + + virtual void append(QGraphicsLayoutItem *item) + { + insert(-1, item); + } + virtual void clear() { obj->clearChildren(); } + virtual int count() const { return obj->count(); } + virtual void removeAt(int i) { obj->removeAt(i); } + virtual QGraphicsLayoutItem *at(int i) const { return obj->itemAt(i); } + virtual void insert(int i, QGraphicsLayoutItem *item) { obj->insertLayoutItem(i, item); } + + private: + QGraphicsLinearLayoutObject *obj; + }; + + ChildList _children; +}; + +//TODO: +// -content margins +// -column and row specific settings: +// -alignment +// -fixed/min/max/preferred width +// -spacing +// -stretch +class GridLayoutAttached; +class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QmlList *children READ children) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing) + Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsGridLayoutObject(QObject * = 0); + ~QGraphicsGridLayoutObject(); + + QmlList *children() { return &_children; } + + qreal spacing() const; + + static GridLayoutAttached *qmlAttachedProperties(QObject *); + +private: + friend class GraphicsLayoutAttached; + void addWidget(QGraphicsWidget *); + void clearChildren(); + void addLayoutItem(QGraphicsLayoutItem *); + static QHash attachedProperties; + + class ChildList : public QmlList + { + public: + ChildList(QGraphicsGridLayoutObject *o) + : obj(o) {} + + virtual void append(QGraphicsLayoutItem *o) + { + obj->addLayoutItem(o); + } + virtual void clear() { obj->clearChildren(); } + virtual int count() const { return obj->count(); } + virtual void removeAt(int i) { obj->removeAt(i); } + virtual QGraphicsLayoutItem *at(int i) const { return obj->itemAt(i); } + //XXX GridLayout doesn't have an insert, so for now we treat it as an append. + // this is obviously potenitally dangerous -- perhaps should be a concrete + // list with no relation to layout index, etc at all. + virtual void insert(int, QGraphicsLayoutItem *item) { append(item); } + + private: + QGraphicsGridLayoutObject *obj; + }; + + ChildList _children; +}; + +QT_END_NAMESPACE + +QML_DECLARE_INTERFACE(QGraphicsLayoutItem) +QML_DECLARE_INTERFACE(QGraphicsLayout) +QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject) +QML_DECLARE_TYPE(QGraphicsLinearLayoutObject) +QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QGraphicsGridLayoutObject) +QML_DECLARE_TYPEINFO(QGraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES) + +QT_END_HEADER + +#endif // GRAPHICSLAYOUTS_H diff --git a/src/declarative/widgets/graphicswidgets.cpp b/src/declarative/widgets/graphicswidgets.cpp index cfcc87b..b631884 100644 --- a/src/declarative/widgets/graphicswidgets.cpp +++ b/src/declarative/widgets/graphicswidgets.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "graphicswidgets.h" +#include "graphicswidgets_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/widgets/graphicswidgets.h b/src/declarative/widgets/graphicswidgets.h deleted file mode 100644 index 8147400..0000000 --- a/src/declarative/widgets/graphicswidgets.h +++ /dev/null @@ -1,62 +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 GRAPHICSWIDGETS_H -#define GRAPHICSWIDGETS_H - -#include -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_MODULE(Declarative) - -QML_DECLARE_TYPE(QGraphicsView) -QML_DECLARE_TYPE_HASMETATYPE(QGraphicsScene) -QML_DECLARE_TYPE(QGraphicsWidget) -QML_DECLARE_INTERFACE_HASMETATYPE(QGraphicsItem) - -QT_END_HEADER - -#endif // GRAPHICSWIDGETS_H diff --git a/src/declarative/widgets/graphicswidgets_p.h b/src/declarative/widgets/graphicswidgets_p.h new file mode 100644 index 0000000..8147400 --- /dev/null +++ b/src/declarative/widgets/graphicswidgets_p.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 GRAPHICSWIDGETS_H +#define GRAPHICSWIDGETS_H + +#include +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_MODULE(Declarative) + +QML_DECLARE_TYPE(QGraphicsView) +QML_DECLARE_TYPE_HASMETATYPE(QGraphicsScene) +QML_DECLARE_TYPE(QGraphicsWidget) +QML_DECLARE_INTERFACE_HASMETATYPE(QGraphicsItem) + +QT_END_HEADER + +#endif // GRAPHICSWIDGETS_H diff --git a/src/declarative/widgets/widgets.pri b/src/declarative/widgets/widgets.pri index 41c50d8..4a8bc93 100644 --- a/src/declarative/widgets/widgets.pri +++ b/src/declarative/widgets/widgets.pri @@ -3,8 +3,8 @@ SOURCES += \ widgets/graphicslayouts.cpp \ HEADERS += \ - widgets/graphicswidgets.h \ - widgets/graphicslayouts.h \ + widgets/graphicswidgets_p.h \ + widgets/graphicslayouts_p.h \ diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index ec6a951..ed4c61e 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include class tst_anchors : public QObject diff --git a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp index 099daec..bedf97c 100644 --- a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp +++ b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp @@ -2,9 +2,9 @@ #include #include #include -#include -#include -#include "qmlgraphicsanimatedimageitem.h" +#include +#include +#include "qmlgraphicsanimatedimageitem_p.h" class tst_animatedimage : public QObject { diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index eaf4d14..cb535d4 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include class tst_animations : public QObject diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index b225a7d..ef2ce76 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include class tst_behaviors : public QObject diff --git a/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp b/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp index 556912e..8cc14d1 100644 --- a/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp +++ b/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include class tst_datetimeformatter : public QObject diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index 0b9e402..0a97768 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -1,7 +1,7 @@ #include -#include +#include #include -#include +#include #include class tst_QmlGraphicsLayouts : public QObject diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 4e0f6cb..f38e721 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -1,8 +1,8 @@ #include -#include +#include #include -#include -#include +#include +#include #include #include diff --git a/tests/auto/declarative/numberformatter/tst_numberformatter.cpp b/tests/auto/declarative/numberformatter/tst_numberformatter.cpp index 412557f..ce6ec0a 100644 --- a/tests/auto/declarative/numberformatter/tst_numberformatter.cpp +++ b/tests/auto/declarative/numberformatter/tst_numberformatter.cpp @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include class tst_numberformat : public QObject { diff --git a/tests/auto/declarative/pathview/tst_pathview.cpp b/tests/auto/declarative/pathview/tst_pathview.cpp index 013edf5..aa42832 100644 --- a/tests/auto/declarative/pathview/tst_pathview.cpp +++ b/tests/auto/declarative/pathview/tst_pathview.cpp @@ -1,9 +1,9 @@ #include -#include +#include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp index c54c151..4f8b5a0 100644 --- a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp +++ b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include class tst_qfxloader : public QObject diff --git a/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp b/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp index 14f3f19..e9f9a6f 100644 --- a/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp +++ b/tests/auto/declarative/qfxpixmapcache/tst_qfxpixmapcache.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp index 4011851..0014d8d 100644 --- a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp +++ b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include class tst_qfxtext : public QObject diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp index cab8666..94d1f85 100644 --- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp +++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp index eeaef89..a03bd15 100644 --- a/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp +++ b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp @@ -2,7 +2,7 @@ #include "../../../shared/util.h" #include #include -#include +#include #include #include #include diff --git a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp index f5b57ea..7bcd96d 100644 --- a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp +++ b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include class tst_QmlListAccessor : public QObject { diff --git a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp index f3e62ab..0976e84 100644 --- a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp +++ b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp @@ -1,9 +1,9 @@ #include #include #include -#include +#include #include -#include +#include #include class tst_QmlPropertyMap : public QObject diff --git a/tests/auto/declarative/qmltimer/tst_qmltimer.cpp b/tests/auto/declarative/qmltimer/tst_qmltimer.cpp index 15b558f..3602fc7 100644 --- a/tests/auto/declarative/qmltimer/tst_qmltimer.cpp +++ b/tests/auto/declarative/qmltimer/tst_qmltimer.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include class tst_qmltimer : public QObject { diff --git a/tests/auto/declarative/repeater/tst_repeater.cpp b/tests/auto/declarative/repeater/tst_repeater.cpp index 8354005..ca056fa 100644 --- a/tests/auto/declarative/repeater/tst_repeater.cpp +++ b/tests/auto/declarative/repeater/tst_repeater.cpp @@ -1,8 +1,8 @@ #include -#include +#include #include -#include -#include +#include +#include #include class tst_QmlGraphicsRepeater : public QObject diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp index ce73c0c..d398dc1 100644 --- a/tests/auto/declarative/sql/tst_sql.cpp +++ b/tests/auto/declarative/sql/tst_sql.cpp @@ -2,7 +2,7 @@ #include "../../../shared/util.h" #include #include -#include +#include #include #include #include diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index 218baf8..7855889 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include class tst_states : public QObject { diff --git a/tools/qmldebugger/creatorplugin/qmlinspectormode.cpp b/tools/qmldebugger/creatorplugin/qmlinspectormode.cpp index 5881cd1..0d404ab 100644 --- a/tools/qmldebugger/creatorplugin/qmlinspectormode.cpp +++ b/tools/qmldebugger/creatorplugin/qmlinspectormode.cpp @@ -33,8 +33,8 @@ #include #include -#include -#include +#include +#include #include "../standalone/objectpropertiesview.h" #include "../standalone/objecttree.h" diff --git a/tools/qmldebugger/creatorplugin/qmlinspectorplugin.cpp b/tools/qmldebugger/creatorplugin/qmlinspectorplugin.cpp index 5108c35..0520125 100644 --- a/tools/qmldebugger/creatorplugin/qmlinspectorplugin.cpp +++ b/tools/qmldebugger/creatorplugin/qmlinspectorplugin.cpp @@ -14,8 +14,8 @@ #include -#include -#include +#include +#include #include "runcontrol.h" #include "qmlinspector.h" diff --git a/tools/qmldebugger/standalone/canvasframerate.cpp b/tools/qmldebugger/standalone/canvasframerate.cpp index 10c3dbf..f16dedd 100644 --- a/tools/qmldebugger/standalone/canvasframerate.cpp +++ b/tools/qmldebugger/standalone/canvasframerate.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tools/qmldebugger/standalone/canvasframerate.h b/tools/qmldebugger/standalone/canvasframerate.h index 6c1ff9f..4711055 100644 --- a/tools/qmldebugger/standalone/canvasframerate.h +++ b/tools/qmldebugger/standalone/canvasframerate.h @@ -4,7 +4,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/tools/qmldebugger/standalone/engine.cpp b/tools/qmldebugger/standalone/engine.cpp index 92c54eb..61a53eb 100644 --- a/tools/qmldebugger/standalone/engine.cpp +++ b/tools/qmldebugger/standalone/engine.cpp @@ -5,10 +5,10 @@ #include #include -#include +#include #include #include -#include +#include #include "engine.h" #include "objectpropertiesview.h" diff --git a/tools/qmldebugger/standalone/engine.h b/tools/qmldebugger/standalone/engine.h index a3ebe46..d2ea7d8 100644 --- a/tools/qmldebugger/standalone/engine.h +++ b/tools/qmldebugger/standalone/engine.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/tools/qmldebugger/standalone/expressionquerywidget.h b/tools/qmldebugger/standalone/expressionquerywidget.h index 3fe0295..15096e2 100644 --- a/tools/qmldebugger/standalone/expressionquerywidget.h +++ b/tools/qmldebugger/standalone/expressionquerywidget.h @@ -3,7 +3,7 @@ #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/tools/qmldebugger/standalone/objectpropertiesview.cpp b/tools/qmldebugger/standalone/objectpropertiesview.cpp index d6fefa0..1fa6f85 100644 --- a/tools/qmldebugger/standalone/objectpropertiesview.cpp +++ b/tools/qmldebugger/standalone/objectpropertiesview.cpp @@ -4,9 +4,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "objectpropertiesview.h" diff --git a/tools/qmldebugger/standalone/objectpropertiesview.h b/tools/qmldebugger/standalone/objectpropertiesview.h index 306e5b9..fb64837 100644 --- a/tools/qmldebugger/standalone/objectpropertiesview.h +++ b/tools/qmldebugger/standalone/objectpropertiesview.h @@ -1,7 +1,7 @@ #ifndef PROPERTIESTABLEMODEL_H #define PROPERTIESTABLEMODEL_H -#include +#include #include diff --git a/tools/qmldebugger/standalone/objecttree.cpp b/tools/qmldebugger/standalone/objecttree.cpp index 6c132b6..65860c8 100644 --- a/tools/qmldebugger/standalone/objecttree.cpp +++ b/tools/qmldebugger/standalone/objecttree.cpp @@ -4,9 +4,9 @@ #include -#include -#include -#include +#include +#include +#include #include "objecttree.h" diff --git a/tools/qmldebugger/standalone/qmldebugger.h b/tools/qmldebugger/standalone/qmldebugger.h index 9203e33..1c20087 100644 --- a/tools/qmldebugger/standalone/qmldebugger.h +++ b/tools/qmldebugger/standalone/qmldebugger.h @@ -1,7 +1,7 @@ #ifndef QMLDEBUGGER_H #define QMLDEBUGGER_H -#include +#include #include #include diff --git a/tools/qmldebugger/standalone/watchtable.cpp b/tools/qmldebugger/standalone/watchtable.cpp index 19f034e..00d5a69 100644 --- a/tools/qmldebugger/standalone/watchtable.cpp +++ b/tools/qmldebugger/standalone/watchtable.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 93470eb..e32c899 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -18,7 +18,7 @@ #include #include #include "qml.h" -#include +#include #include #include #include "deviceskin.h" -- cgit v0.12 From 9c8774e4aff4e21eb7dc4b98ce525e0b1a8285f6 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 30 Oct 2009 16:21:58 +1000 Subject: Fixup mistakes following renaming files --- tests/auto/declarative/animatedimage/tst_animatedimage.cpp | 2 +- tests/auto/declarative/animations/tst_animations.cpp | 2 +- tests/auto/declarative/behaviors/tst_behaviors.cpp | 2 +- tests/auto/declarative/layouts/tst_layouts.cpp | 4 ++-- tests/auto/declarative/listview/tst_listview.cpp | 6 +++--- tests/auto/declarative/pathview/tst_pathview.cpp | 8 ++++---- tests/auto/declarative/qfxloader/qfxloader.pro | 2 +- tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro | 2 +- tests/auto/declarative/qfxtext/qfxtext.pro | 2 +- tests/auto/declarative/qfxtextedit/qfxtextedit.pro | 2 +- tests/auto/declarative/qfxtextinput/qfxtextinput.pro | 2 +- tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp | 2 +- tests/auto/declarative/repeater/tst_repeater.cpp | 6 +++--- tools/qmlviewer/qmlviewer.h | 2 +- 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp index bedf97c..e2b96d0 100644 --- a/tests/auto/declarative/animatedimage/tst_animatedimage.cpp +++ b/tests/auto/declarative/animatedimage/tst_animatedimage.cpp @@ -4,7 +4,7 @@ #include #include #include -#include "qmlgraphicsanimatedimageitem_p.h" +#include class tst_animatedimage : public QObject { diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index cb535d4..8e3e522 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include class tst_animations : public QObject { diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index ef2ce76..25540a2 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include class tst_behaviors : public QObject { diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp index 0a97768..2d9f7e8 100644 --- a/tests/auto/declarative/layouts/tst_layouts.cpp +++ b/tests/auto/declarative/layouts/tst_layouts.cpp @@ -1,7 +1,7 @@ #include -#include +#include #include -#include +#include #include class tst_QmlGraphicsLayouts : public QObject diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index f38e721..f1077f2 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -1,8 +1,8 @@ #include -#include +#include #include -#include -#include +#include +#include #include #include diff --git a/tests/auto/declarative/pathview/tst_pathview.cpp b/tests/auto/declarative/pathview/tst_pathview.cpp index aa42832..385a42e 100644 --- a/tests/auto/declarative/pathview/tst_pathview.cpp +++ b/tests/auto/declarative/pathview/tst_pathview.cpp @@ -1,9 +1,9 @@ #include -#include +#include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/tests/auto/declarative/qfxloader/qfxloader.pro b/tests/auto/declarative/qfxloader/qfxloader.pro index 8be8cdf..aee52cc 100644 --- a/tests/auto/declarative/qfxloader/qfxloader.pro +++ b/tests/auto/declarative/qfxloader/qfxloader.pro @@ -2,6 +2,6 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle -SOURCES += tst_qmlgraphicsloader.cpp +SOURCES += tst_qfxloader.cpp DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro b/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro index 1df2f4e..218eeff 100644 --- a/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro +++ b/tests/auto/declarative/qfxpixmapcache/qfxpixmapcache.pro @@ -3,7 +3,7 @@ contains(QT_CONFIG,declarative): QT += declarative QT += network macx:CONFIG -= app_bundle -SOURCES += tst_qmlgraphicspixmapcache.cpp +SOURCES += tst_qfxpixmapcache.cpp # QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage # LIBS += -lgcov diff --git a/tests/auto/declarative/qfxtext/qfxtext.pro b/tests/auto/declarative/qfxtext/qfxtext.pro index 1d8c59f..1f3fe37 100644 --- a/tests/auto/declarative/qfxtext/qfxtext.pro +++ b/tests/auto/declarative/qfxtext/qfxtext.pro @@ -2,4 +2,4 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle -SOURCES += tst_qmlgraphicstext.cpp +SOURCES += tst_qfxtext.cpp diff --git a/tests/auto/declarative/qfxtextedit/qfxtextedit.pro b/tests/auto/declarative/qfxtextedit/qfxtextedit.pro index 9e6a71a..b5e0464 100644 --- a/tests/auto/declarative/qfxtextedit/qfxtextedit.pro +++ b/tests/auto/declarative/qfxtextedit/qfxtextedit.pro @@ -2,7 +2,7 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle -SOURCES += tst_qmlgraphicstextedit.cpp +SOURCES += tst_qfxtextedit.cpp # Define SRCDIR equal to test's source directory DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxtextinput/qfxtextinput.pro b/tests/auto/declarative/qfxtextinput/qfxtextinput.pro index fd75fec..fe2e3e3 100644 --- a/tests/auto/declarative/qfxtextinput/qfxtextinput.pro +++ b/tests/auto/declarative/qfxtextinput/qfxtextinput.pro @@ -2,7 +2,7 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle -SOURCES += tst_qmlgraphicstextinput.cpp +SOURCES += tst_qfxtextinput.cpp # Define SRCDIR equal to test's source directory DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp index e4930f6..79868ce 100644 --- a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp +++ b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include class tst_qfxtextinput : public QObject diff --git a/tests/auto/declarative/repeater/tst_repeater.cpp b/tests/auto/declarative/repeater/tst_repeater.cpp index ca056fa..f39c3a3 100644 --- a/tests/auto/declarative/repeater/tst_repeater.cpp +++ b/tests/auto/declarative/repeater/tst_repeater.cpp @@ -1,8 +1,8 @@ #include -#include +#include #include -#include -#include +#include +#include #include class tst_QmlGraphicsRepeater : public QObject diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index bc8fe11..b6c0ad7 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -15,7 +15,7 @@ #define QMLVIEWER_H #include -#include +#include #include #include -- cgit v0.12