diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-24 07:22:16 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-24 07:22:16 (GMT) |
commit | 83449457780f4321595ec5f15056474cc22061da (patch) | |
tree | 1efc45348916a58188fd1e8dbe0355bec843dd6e /src/declarative | |
parent | 3c2396d4d1e1b398dade04629af2854368b65efb (diff) | |
parent | d0f83cb45f27b2814326344ded548a02c2ebe583 (diff) | |
download | Qt-83449457780f4321595ec5f15056474cc22061da.zip Qt-83449457780f4321595ec5f15056474cc22061da.tar.gz Qt-83449457780f4321595ec5f15056474cc22061da.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/canvas/qsimplecanvas.cpp | 6 | ||||
-rw-r--r-- | src/declarative/extra/qmltimer.cpp | 150 | ||||
-rw-r--r-- | src/declarative/extra/qmltimer.h | 20 | ||||
-rw-r--r-- | src/declarative/fx/qfxflowview.cpp | 9 | ||||
-rw-r--r-- | src/declarative/fx/qfxitem.cpp | 9 | ||||
-rw-r--r-- | src/declarative/fx/qfxpainteditem.cpp | 30 | ||||
-rw-r--r-- | src/declarative/fx/qfxpainteditem.h | 7 | ||||
-rw-r--r-- | src/declarative/fx/qfxpainteditem_p.h | 3 | ||||
-rw-r--r-- | src/declarative/fx/qfxwebview.cpp | 7 | ||||
-rw-r--r-- | src/declarative/fx/qfxwebview.h | 1 | ||||
-rw-r--r-- | src/declarative/util/qmlanimation.cpp | 62 | ||||
-rw-r--r-- | src/declarative/util/qmlanimation.h | 6 | ||||
-rw-r--r-- | src/declarative/util/qmlanimation_p.h | 3 |
13 files changed, 286 insertions, 27 deletions
diff --git a/src/declarative/canvas/qsimplecanvas.cpp b/src/declarative/canvas/qsimplecanvas.cpp index cb46f94..a4998dc 100644 --- a/src/declarative/canvas/qsimplecanvas.cpp +++ b/src/declarative/canvas/qsimplecanvas.cpp @@ -883,9 +883,9 @@ QRect QSimpleCanvasPrivate::resetDirty() dirtyItems.clear(); oldDirty = QRect(); - if (fullUpdate()) + /*if (fullUpdate()) return QRect(); - else + else*/ return r; } else { return QRect(); @@ -934,7 +934,7 @@ bool QSimpleCanvas::event(QEvent *e) QRect r = d->resetDirty(); #if defined(QFX_RENDER_QPAINTER) - if (r.isEmpty() || fullUpdate()) + if (fullUpdate()) repaint(); else repaint(r); diff --git a/src/declarative/extra/qmltimer.cpp b/src/declarative/extra/qmltimer.cpp index 1e1a6de..0c13c4a 100644 --- a/src/declarative/extra/qmltimer.cpp +++ b/src/declarative/extra/qmltimer.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include "QtCore/qcoreapplication.h" #include "QtCore/qpauseanimation.h" #include "private/qobject_p.h" #include "qmltimer.h" @@ -52,27 +53,59 @@ class QmlTimerPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QmlTimer) public: - QmlTimerPrivate() : interval(1000) {} + QmlTimerPrivate() + : interval(1000), running(false), repeating(false), firesOnStart(false) + , componentComplete(false) {} int interval; + bool running; + bool repeating; + bool firesOnStart; QPauseAnimation pause; + bool componentComplete; }; +/*! + \qmlclass Timer QFxTimer + \brief The Timer item triggers a handler at a specified interval. + + A timer can be used to trigger an action either once, or repeatedly + at a given interval. + + \qml + Timer { + interval: 500; running: true; repeat: true + onTriggered: Time.text = Date().toString() + } + Text { + id: Time + } + \endqml + +*/ + QmlTimer::QmlTimer(QObject *parent) : QObject(*(new QmlTimerPrivate), parent) { Q_D(QmlTimer); connect(&d->pause, SIGNAL(currentLoopChanged(int)), this, SLOT(ticked())); - d->pause.setLoopCount(-1); + connect(&d->pause, SIGNAL(finished()), this, SLOT(ticked())); + connect(&d->pause, SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)) + , this, SLOT(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State))); + d->pause.setLoopCount(1); d->pause.setDuration(d->interval); } +/*! + \qmlproperty int Timer::interval + + Sets the \a interval between triggering. +*/ void QmlTimer::setInterval(int interval) { Q_D(QmlTimer); if (interval != d->interval) { d->interval = interval; - d->pause.setDuration(d->interval); - d->pause.start(); + update(); } } @@ -82,16 +115,119 @@ int QmlTimer::interval() const return d->interval; } -void QmlTimer::componentComplete() +/*! + \qmlproperty bool Timer::running + + If set to true, starts the timer; otherwise stops the timer. + For a non-repeating timer, \a running will be set to false after the + timer has been triggered. + + \sa repeat +*/ +bool QmlTimer::isRunning() const +{ + Q_D(const QmlTimer); + return d->running; +} + +void QmlTimer::setRunning(bool running) +{ + Q_D(QmlTimer); + if (d->running != running) { + d->running = running; + emit runningChanged(); + update(); + } +} + +/*! + \qmlproperty bool Timer::repeat + + If \a repeat is true the timer will be triggered repeatedly at the + specified interval; otherwise, the timer will trigger once at the + specified interval and then stop (i.e. running will be set to false). + + \sa running +*/ +bool QmlTimer::isRepeating() const +{ + Q_D(const QmlTimer); + return d->repeating; +} + +void QmlTimer::setRepeating(bool repeating) +{ + Q_D(QmlTimer); + if (repeating != d->repeating) { + d->repeating = repeating; + update(); + } +} + +/*! + \qmlproperty bool Timer::firesOnStart + + If \a firesOnStart is true, the timer will be triggered immediately + when started, and subsequently at the specified interval. + + \sa running +*/ +bool QmlTimer::firesOnStart() const +{ + Q_D(const QmlTimer); + return d->firesOnStart; +} + +void QmlTimer::setFiresOnStart(bool firesOnStart) +{ + Q_D(QmlTimer); + if (d->firesOnStart != firesOnStart) { + d->firesOnStart = firesOnStart; + update(); + } +} + +void QmlTimer::update() { Q_D(QmlTimer); - if (d->pause.state() != QAbstractAnimation::Running) + if (!d->componentComplete) + return; + d->pause.stop(); + if (d->running) { + d->pause.setLoopCount(d->repeating ? -1 : 1); + d->pause.setDuration(d->interval); d->pause.start(); + if (d->firesOnStart) { + QCoreApplication::removePostedEvents(this, QEvent::MetaCall); + QMetaObject::invokeMethod(this, "ticked", Qt::QueuedConnection); + } + } +} + +void QmlTimer::componentComplete() +{ + Q_D(QmlTimer); + d->componentComplete = true; + update(); } +/*! + \qmlsignal Timer::onTriggered + + This handler is called when the Timer is triggered. +*/ void QmlTimer::ticked() { - emit timeout(); + emit triggered(); +} + +void QmlTimer::stateChanged(QAbstractAnimation::State, QAbstractAnimation::State state) +{ + Q_D(QmlTimer); + if (d->running && state != QAbstractAnimation::Running) { + d->running = false; + emit runningChanged(); + } } QT_END_NAMESPACE diff --git a/src/declarative/extra/qmltimer.h b/src/declarative/extra/qmltimer.h index 75603c6..8a94395 100644 --- a/src/declarative/extra/qmltimer.h +++ b/src/declarative/extra/qmltimer.h @@ -44,6 +44,7 @@ #include <QtDeclarative/qfxglobal.h> #include <QtCore/qobject.h> +#include <QtCore/qabstractanimation.h> #include <QtDeclarative/qml.h> QT_BEGIN_HEADER @@ -57,6 +58,9 @@ class Q_DECLARATIVE_EXPORT QmlTimer : public QObject, public QmlParserStatus Q_OBJECT Q_DECLARE_PRIVATE(QmlTimer) 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 firesOnStart READ firesOnStart WRITE setFiresOnStart) public: QmlTimer(QObject *parent=0); @@ -64,14 +68,28 @@ public: void setInterval(int interval); int interval() const; + bool isRunning() const; + void setRunning(bool running); + + bool isRepeating() const; + void setRepeating(bool repeating); + + bool firesOnStart() const; + void setFiresOnStart(bool firesOnStart); + protected: void componentComplete(); Q_SIGNALS: - void timeout(); + void triggered(); + void runningChanged(); + +private: + void update(); private Q_SLOTS: void ticked(); + void stateChanged(QAbstractAnimation::State,QAbstractAnimation::State); }; QML_DECLARE_TYPE(QmlTimer) diff --git a/src/declarative/fx/qfxflowview.cpp b/src/declarative/fx/qfxflowview.cpp index e02e186..77cd6df 100644 --- a/src/declarative/fx/qfxflowview.cpp +++ b/src/declarative/fx/qfxflowview.cpp @@ -128,10 +128,11 @@ void QFxFlowView::refresh() { if (m_model && m_columns >= 1) { for (int ii = 0; ii < m_model->count(); ++ii) { - QFxItem *item = m_model->item(ii); - item->setParent(this); - item->setZ(0); - m_items << item; + if (QFxItem *item = m_model->item(ii)) { + item->setParent(this); + item->setZ(0); + m_items << item; + } } reflow(); diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 0c4d97b..73786a8 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -897,7 +897,16 @@ void QFxItem::qmlLoaded() QmlContext *ctxt = new QmlContext(qmlContext(this)); ctxt->addDefaultObject(this); + if (!d->_qmlcomp->errors().isEmpty()) { + qWarning() << d->_qmlcomp->errors(); + delete d->_qmlcomp; + d->_qmlcomp = 0; + emit qmlChanged(); + return; + } QObject *obj = d->_qmlcomp->create(ctxt); + if (!d->_qmlcomp->errors().isEmpty()) + qWarning() << d->_qmlcomp->errors(); QFxItem *qmlChild = qobject_cast<QFxItem *>(obj); if (qmlChild) { qmlChild->setItemParent(this); diff --git a/src/declarative/fx/qfxpainteditem.cpp b/src/declarative/fx/qfxpainteditem.cpp index 29d11ff..65589f2 100644 --- a/src/declarative/fx/qfxpainteditem.cpp +++ b/src/declarative/fx/qfxpainteditem.cpp @@ -156,7 +156,6 @@ void QFxPaintedItem::setSmooth(bool smooth) Q_D(QFxPaintedItem); if (d->smooth == smooth) return; d->smooth = smooth; - clearCache(); update(); } @@ -304,7 +303,8 @@ void QFxPaintedItem::paintGLContents(GLPainter &p) for (int i = 0; i < rects.count(); ++i) { const QRect &r = rects.at(i); QPixmap img(r.size()); - img.fill(Qt::transparent); + if (d->fillColor.isValid()) + img.fill(d->fillColor); { QPainter qp(&img); qp.translate(-r.x(),-r.y()); @@ -384,4 +384,30 @@ void QFxPaintedItem::setCacheSize(int pixels) d->max_imagecache_size = pixels; } +/*! + \property QFxPaintedItem::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 QFxPaintedItem::setFillColor(const QColor& c) +{ + Q_D(QFxPaintedItem); + if (d->fillColor == c) + return; + d->fillColor = c; + emit fillColorChanged(); + update(); +} + +QColor QFxPaintedItem::fillColor() const +{ + Q_D(const QFxPaintedItem); + return d->fillColor; +} + + QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpainteditem.h b/src/declarative/fx/qfxpainteditem.h index b7db2d9..6cb8fe7 100644 --- a/src/declarative/fx/qfxpainteditem.h +++ b/src/declarative/fx/qfxpainteditem.h @@ -59,6 +59,7 @@ class Q_DECLARATIVE_EXPORT QFxPaintedItem : public QFxItem Q_PROPERTY(QSize contentsSize READ contentsSize WRITE setContentsSize) Q_PROPERTY(bool smooth READ isSmooth WRITE setSmooth) + Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY fillColorChanged) Q_PROPERTY(int cacheSize READ cacheSize WRITE setCacheSize) public: @@ -80,11 +81,17 @@ public: int cacheSize() const; void setCacheSize(int pixels); + QColor fillColor() const; + void setFillColor(const QColor&); + protected: QFxPaintedItem(QFxPaintedItemPrivate &dd, QFxItem *parent); virtual void drawContents(QPainter *p, const QRect &) = 0; +Q_SIGNALS: + void fillColorChanged(); + protected Q_SLOTS: void dirtyCache(const QRect &); void clearCache(); diff --git a/src/declarative/fx/qfxpainteditem_p.h b/src/declarative/fx/qfxpainteditem_p.h index 21ac556..4e953a0 100644 --- a/src/declarative/fx/qfxpainteditem_p.h +++ b/src/declarative/fx/qfxpainteditem_p.h @@ -68,7 +68,7 @@ class QFxPaintedItemPrivate : public QFxItemPrivate public: QFxPaintedItemPrivate() - : max_imagecache_size(100000), smooth(false) + : max_imagecache_size(100000), smooth(false), fillColor(Qt::transparent) { } @@ -89,6 +89,7 @@ public: int max_imagecache_size; bool smooth; QSize contentsSize; + QColor fillColor; }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp index adb33e8..f4a06ce 100644 --- a/src/declarative/fx/qfxwebview.cpp +++ b/src/declarative/fx/qfxwebview.cpp @@ -428,12 +428,6 @@ void QFxWebView::setInteractive(bool i) emit interactiveChanged(); } -void QFxWebView::updateCacheForVisibility() -{ - if (!isVisible()) - clearCache(); -} - void QFxWebView::expandToWebPage() { Q_D(QFxWebView); @@ -845,7 +839,6 @@ void QFxWebView::setPage(QWebPage *page) d->idealheight>0 ? d->idealheight : -1)); d->page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); d->page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); - connect(this,SIGNAL(visibleChanged()),this,SLOT(updateCacheForVisibility())); connect(d->page,SIGNAL(repaintRequested(QRect)),this,SLOT(paintPage(QRect))); connect(d->page->mainFrame(),SIGNAL(urlChanged(QUrl)),this,SIGNAL(urlChanged())); connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h index c9a62cc..0ac1895 100644 --- a/src/declarative/fx/qfxwebview.h +++ b/src/declarative/fx/qfxwebview.h @@ -179,7 +179,6 @@ Q_SIGNALS: void doubleClick(); private Q_SLOTS: - void updateCacheForVisibility(); void expandToWebPage(); void paintPage(const QRect&); void doLoadProgress(int p); diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 7df249e..2a6cad9 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -255,6 +255,44 @@ void QmlAbstractAnimation::setRunning(bool r) emit runningChanged(d->running); } +/*! + \qmlproperty bool Animation::paused + This property holds whether the animation is currently paused. + + The \c paused property can be set to declaratively control whether or not + an animation is paused. + + Animations can also be paused and resumed imperatively from JavaScript + using the \c pause() and \c resume() methods. + + By default, animations are not paused. +*/ +bool QmlAbstractAnimation::isPaused() const +{ + Q_D(const QmlAbstractAnimation); + return d->paused; +} + +void QmlAbstractAnimation::setPaused(bool p) +{ + Q_D(QmlAbstractAnimation); + if (d->paused == p) + return; + + if (d->group) { + qWarning("QmlAbstractAnimation: setPaused() cannot be used on non-root animation nodes"); + return; + } + + d->paused = p; + if (d->paused) + qtAnimation()->pause(); + else + qtAnimation()->resume(); + + emit pausedChanged(d->running); +} + void QmlAbstractAnimation::classBegin() { Q_D(QmlAbstractAnimation); @@ -430,6 +468,30 @@ void QmlAbstractAnimation::start() } /*! + \qmlmethod Animation::pause() + \brief Pauses the animation. + + If the animation is already paused, calling this method has no effect. The + \c paused property will be true following a call to \c pause(). +*/ +void QmlAbstractAnimation::pause() +{ + setPaused(true); +} + +/*! + \qmlmethod Animation::resume() + \brief Resumes a paused animation. + + If the animation is not paused, calling this method has no effect. The + \c paused property will be false following a call to \c resume(). +*/ +void QmlAbstractAnimation::resume() +{ + setPaused(false); +} + +/*! \qmlmethod Animation::stop() \brief Stops the animation. diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h index 5ab9dda..0452159 100644 --- a/src/declarative/util/qmlanimation.h +++ b/src/declarative/util/qmlanimation.h @@ -65,6 +65,7 @@ class QmlAbstractAnimation : public QmlPropertyValueSource, public QmlParserStat Q_INTERFACES(QmlParserStatus) Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) + Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) Q_PROPERTY(bool finishPlaying READ finishPlaying WRITE setFinishPlaying NOTIFY finishPlayingChanged()) Q_PROPERTY(bool repeat READ repeat WRITE setRepeat NOTIFY repeatChanged) Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) @@ -78,6 +79,8 @@ public: bool isRunning() const; void setRunning(bool); + bool isPaused() const; + void setPaused(bool); bool finishPlaying() const; void setFinishPlaying(bool); bool repeat() const; @@ -100,6 +103,7 @@ Q_SIGNALS: void started(); void completed(); void runningChanged(bool); + void pausedChanged(bool); void repeatChanged(bool); void targetChanged(QObject *, const QString &); void finishPlayingChanged(bool); @@ -107,6 +111,8 @@ Q_SIGNALS: public Q_SLOTS: void restart(); void start(); + void pause(); + void resume(); void stop(); void complete(); diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index e5a7384..f09ab88 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -172,11 +172,12 @@ class QmlAbstractAnimationPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QmlAbstractAnimation) public: QmlAbstractAnimationPrivate() - : running(false), finishPlaying(false), repeat(false), + : running(false), paused(false), finishPlaying(false), repeat(false), connectedTimeLine(false), componentComplete(true), startOnCompletion(false), target(0), group(0) {} bool running; + bool paused; bool finishPlaying; bool repeat; bool connectedTimeLine; |