diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-08-07 06:41:35 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-08-07 06:41:35 (GMT) |
commit | b1f10dc22091f80fba651e32e824175f25956313 (patch) | |
tree | 788f291f88e8bd2985ae1b18fe618aedc64a2c14 | |
parent | 76dccb8afe640ec6e22ba8a6e5843c47fd2bd832 (diff) | |
parent | c285afe618837229aee32150216fc853fdeac38d (diff) | |
download | Qt-b1f10dc22091f80fba651e32e824175f25956313.zip Qt-b1f10dc22091f80fba651e32e824175f25956313.tar.gz Qt-b1f10dc22091f80fba651e32e824175f25956313.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
25 files changed, 535 insertions, 188 deletions
diff --git a/demos/declarative/flickr/content/Progress.qml b/demos/declarative/flickr/content/Progress.qml index ae6bb18..4268963 100644 --- a/demos/declarative/flickr/content/Progress.qml +++ b/demos/declarative/flickr/content/Progress.qml @@ -6,7 +6,7 @@ Item { property var progress: 0 Rect { - id: Container; anchors.fill: parent + id: Container; anchors.fill: parent; smooth: true border.color: "white"; border.width: 0; radius: height/2 - 2 gradient: Gradient { GradientStop { position: 0; color: "#66343434" } @@ -18,7 +18,7 @@ Item { id: Fill y: 2; height: parent.height-4; x: 2; width: Math.max(parent.width * progress - 4, 0); - opacity: width < 1 ? 0 : 1 + opacity: width < 1 ? 0 : 1; smooth: true gradient: Gradient { GradientStop { position: 0; color: "lightsteelblue" } GradientStop { position: 1.0; color: "steelblue" } diff --git a/demos/declarative/flickr/content/Slider.qml b/demos/declarative/flickr/content/Slider.qml index 0c15ec6..51385bc 100644 --- a/demos/declarative/flickr/content/Slider.qml +++ b/demos/declarative/flickr/content/Slider.qml @@ -16,16 +16,16 @@ Item { gradient: Gradient { GradientStop { position: 0.0; color: "#66343434" } GradientStop { position: 1.0; color: "#66000000" } - } + } } Rect { - id: Handle + id: Handle; smooth: true x: Slider.width / 2 - Handle.width / 2; y: 2; width: 30; height: Slider.height-4; radius: 6 gradient: Gradient { GradientStop { position: 0.0; color: "lightgray" } GradientStop { position: 1.0; color: "gray" } - } + } MouseRegion { anchors.fill: parent; drag.target: parent diff --git a/examples/declarative/border-image/BorderImage.qml b/examples/declarative/border-image/BorderImage.qml new file mode 100644 index 0000000..a809d5d --- /dev/null +++ b/examples/declarative/border-image/BorderImage.qml @@ -0,0 +1,36 @@ +import Qt 4.6 + +Item { + property var horizontalMode : "Stretch" + property var verticalMode : "Stretch" + property string source + property int minWidth + property int minHeight + property int maxWidth + property int maxHeight + property int margin + + id: Container + width: 240; height: 240 + Image { + x: Container.width / 2 - width / 2 + y: Container.height / 2 - height / 2 + width: SequentialAnimation { + running: true; repeat: true + NumberAnimation { from: Container.minWidth; to: Container.maxWidth; duration: 2000; easing: "easeInOutQuad"} + NumberAnimation { from: Container.maxWidth; to: Container.minWidth; duration: 2000; easing: "easeInOutQuad" } + } + height: SequentialAnimation { + running: true; repeat: true + NumberAnimation { from: Container.minHeight; to: Container.maxHeight; duration: 2000; easing: "easeInOutQuad"} + NumberAnimation { from: Container.maxHeight; to: Container.minHeight; duration: 2000; easing: "easeInOutQuad" } + } + source: Container.source + scaleGrid.horizontalTileRule: Container.horizontalMode + scaleGrid.verticalTileRule: Container.verticalMode + scaleGrid.top: Container.margin + scaleGrid.left: Container.margin + scaleGrid.bottom: Container.margin + scaleGrid.right: Container.margin + } +} diff --git a/examples/declarative/border-image/animated.qml b/examples/declarative/border-image/animated.qml new file mode 100644 index 0000000..58eb44c --- /dev/null +++ b/examples/declarative/border-image/animated.qml @@ -0,0 +1,54 @@ +import Qt 4.6 + +Rect { + id: Page + color: "white" + width: 1030; height: 540 + + BorderImage { + x: 20; y: 20; minWidth: 120; maxWidth: 240 + minHeight: 120; maxHeight: 240 + source: "colors.png"; margin: 30 + } + BorderImage { + x: 270; y: 20; minWidth: 120; maxWidth: 240 + minHeight: 120; maxHeight: 240 + source: "colors.png"; margin: 30 + horizontalMode: "Repeat"; verticalMode: "Repeat" + } + BorderImage { + x: 520; y: 20; minWidth: 120; maxWidth: 240 + minHeight: 120; maxHeight: 240 + source: "colors.png"; margin: 30 + horizontalMode: "Stretch"; verticalMode: "Repeat" + } + BorderImage { + x: 770; y: 20; minWidth: 120; maxWidth: 240 + minHeight: 120; maxHeight: 240 + source: "colors.png"; margin: 30 + horizontalMode: "Round"; verticalMode: "Round" + } + BorderImage { + x: 20; y: 280; minWidth: 60; maxWidth: 200 + minHeight: 40; maxHeight: 200 + source: "bw.png"; margin: 10 + } + BorderImage { + x: 270; y: 280; minWidth: 60; maxWidth: 200 + minHeight: 40; maxHeight: 200 + source: "bw.png"; margin: 10 + horizontalMode: "Repeat"; verticalMode: "Repeat" + } + BorderImage { + x: 520; y: 280; minWidth: 60; maxWidth: 200 + minHeight: 40; maxHeight: 200 + source: "bw.png"; margin: 10 + horizontalMode: "Stretch"; verticalMode: "Repeat" + } + BorderImage { + x: 770; y: 280; minWidth: 60; maxWidth: 200 + minHeight: 40; maxHeight: 200 + source: "bw.png"; margin: 10 + horizontalMode: "Round"; verticalMode: "Round" + } +} diff --git a/examples/declarative/border-image/borders.qml b/examples/declarative/border-image/borders.qml new file mode 100644 index 0000000..a4a329b --- /dev/null +++ b/examples/declarative/border-image/borders.qml @@ -0,0 +1,18 @@ +import Qt 4.6 + +Rect { + id: Page + color: "white" + width: 520; height: 280 + + Image { + x: 20; y: 20; width: 230; height: 240 + smooth: true + source: "colors-stretch.sci" + } + Image { + x: 270; y: 20; width: 230; height: 240 + smooth: true + source: "colors-round.sci" + } +} diff --git a/examples/declarative/border-image/bw.png b/examples/declarative/border-image/bw.png Binary files differnew file mode 100644 index 0000000..486eaae --- /dev/null +++ b/examples/declarative/border-image/bw.png diff --git a/examples/declarative/border-image/colors-round.sci b/examples/declarative/border-image/colors-round.sci new file mode 100644 index 0000000..3784e10 --- /dev/null +++ b/examples/declarative/border-image/colors-round.sci @@ -0,0 +1,7 @@ +gridLeft:30 +gridTop:30 +gridRight:30 +gridBottom:30 +horizontalTileRule:Round +verticalTileRule:Round +imageFile:colors.png diff --git a/examples/declarative/border-image/colors-stretch.sci b/examples/declarative/border-image/colors-stretch.sci new file mode 100644 index 0000000..c693599 --- /dev/null +++ b/examples/declarative/border-image/colors-stretch.sci @@ -0,0 +1,5 @@ +gridLeft:30 +gridTop:30 +gridRight:30 +gridBottom:30 +imageFile:colors.png diff --git a/examples/declarative/border-image/colors.png b/examples/declarative/border-image/colors.png Binary files differnew file mode 100644 index 0000000..c0e137c --- /dev/null +++ b/examples/declarative/border-image/colors.png diff --git a/src/declarative/extra/qfxparticles.cpp b/src/declarative/extra/qfxparticles.cpp index 6d41434..f05f233 100644 --- a/src/declarative/extra/qfxparticles.cpp +++ b/src/declarative/extra/qfxparticles.cpp @@ -53,6 +53,7 @@ #include <qfxpixmap.h> #include <private/qfxperf_p.h> #include <private/qmlanimation_p.h> +#include <QNetworkReply> #include "qfxparticles.h" #include <QPainter> @@ -404,6 +405,7 @@ public: bool emitting; QFxParticleMotion *motion; QFxParticlesPainter *paintItem; + QPointer<QNetworkReply> reply; QList<QFxParticle> particles; QTickAnimationProxy<QFxParticlesPrivate, &QFxParticlesPrivate::tick> clock; @@ -636,7 +638,7 @@ QUrl QFxParticles::source() const void QFxParticles::imageLoaded() { Q_D(QFxParticles); - d->image = QFxPixmap(d->url); + QFxPixmap::find(d->url, &d->image); d->paintItem->updateSize(); d->paintItem->update(); } @@ -645,7 +647,7 @@ void QFxParticles::setSource(const QUrl &name) { Q_D(QFxParticles); - if (name == d->url) + if ((d->url.isEmpty() == name.isEmpty()) && name == d->url) return; if (!d->url.isEmpty()) @@ -658,7 +660,14 @@ void QFxParticles::setSource(const QUrl &name) } else { d->url = name; Q_ASSERT(!name.isRelative()); - QFxPixmap::get(qmlEngine(this), d->url, this, SLOT(imageLoaded())); + d->reply = QFxPixmap::get(qmlEngine(this), d->url, &d->image); + if (d->reply) + connect(d->reply, SIGNAL(finished()), this, SLOT(imageLoaded())); + else { + //### unify with imageLoaded + d->paintItem->updateSize(); + d->paintItem->update(); + } } } @@ -680,17 +689,18 @@ int QFxParticles::count() const void QFxParticles::setCount(int cnt) { Q_D(QFxParticles); - if (cnt != d->count) { - int oldCount = d->count; - d->count = cnt; - d->addParticleTime = 0; - d->addParticleCount = d->particles.count(); - if (!oldCount && d->clock.state() != QAbstractAnimation::Running) { - d->clock.start(); - } - d->paintItem->updateSize(); - d->paintItem->update(); + 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(); } /*! @@ -1043,6 +1053,9 @@ void QFxParticles::setMotion(QFxParticleMotion *motion) void QFxParticlesPainter::updateSize() { + if (!isComponentComplete()) + return; + const int parentX = parentItem()->x(); const int parentY = parentItem()->y(); for (int i = 0; i < d->particles.count(); ++i) { diff --git a/src/declarative/extra/qmlbehaviour.cpp b/src/declarative/extra/qmlbehaviour.cpp index 0e70bdc..052225a 100644 --- a/src/declarative/extra/qmlbehaviour.cpp +++ b/src/declarative/extra/qmlbehaviour.cpp @@ -125,7 +125,8 @@ QmlBehaviour::QmlBehaviour(QObject *parent) : QmlPropertyValueSource(*(new QmlBehaviourPrivate), parent) { Q_D(QmlBehaviour); - d->group = new QParallelAnimationGroup(this); + d->group = new QParallelAnimationGroup; + QFx_setParent_noEvent(d->group, this); } /*! diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index bbb09fb..a6c5281 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -42,6 +42,7 @@ HEADERS += \ fx/qfxvisualitemmodel.h \ fx/qfxlistview.h \ fx/qfxgraphicsobjectcontainer.h \ + fx/qfxlayoutitem.h \ SOURCES += \ fx/qfxanchors.cpp \ @@ -71,6 +72,7 @@ SOURCES += \ fx/qfxvisualitemmodel.cpp \ fx/qfxlistview.cpp \ fx/qfxgraphicsobjectcontainer.cpp \ + fx/qfxlayoutitem.cpp \ contains(QT_CONFIG, webkit) { QT+=webkit diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index ec3053c..26e2727 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -348,60 +348,10 @@ void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) p->drawPixmap(0, 0, pix); } } else { - if (d->fillMode != Stretch) - qWarning("Only fillmode:Stretch supported for scale grid images"); - int sgl = d->scaleGrid->left(); - int sgr = d->scaleGrid->right(); - int sgt = d->scaleGrid->top(); - int sgb = d->scaleGrid->bottom(); - - int w = width(); - int h = height(); - if (sgt + sgb > h) - sgt = sgb = h/2; - if (sgl + sgr > w) - sgl = sgr = w/2; - - const int xSide = sgl + sgr; - const int ySide = sgt + sgb; - - // Upper left - if (sgt && sgl) - p->drawPixmap(QRect(0, 0, sgl, sgt), pix, QRect(0, 0, sgl, sgt)); - // Upper middle - if (pix.width() - xSide && sgt) - p->drawPixmap(QRect(sgl, 0, w - xSide, sgt), pix, - QRect(sgl, 0, pix.width() - xSide, sgt)); - // Upper right - if (sgt && pix.width() - sgr) - p->drawPixmap(QPoint(w-sgr, 0), pix, - QRect(pix.width()-sgr, 0, sgr, sgt)); - // Middle left - if (sgl && pix.height() - ySide) - p->drawPixmap(QRect(0, sgt, sgl, h - ySide), pix, - QRect(0, sgt, sgl, pix.height() - ySide)); - - // Middle - if (pix.width() - xSide && pix.height() - ySide) - p->drawPixmap(QRect(sgl, sgt, w - xSide, h - ySide), - pix, - QRect(sgl, sgt, pix.width() - xSide, pix.height() - ySide)); - // Middle right - if (sgr && pix.height() - ySide) - p->drawPixmap(QRect(w-sgr, sgt, sgr, h - ySide), pix, - QRect(pix.width()-sgr, sgt, sgr, pix.height() - ySide)); - // Lower left - if (sgl && sgr) - p->drawPixmap(QPoint(0, h - sgb), pix, - QRect(0, pix.height() - sgb, sgl, sgb)); - // Lower Middle - if (pix.width() - xSide && sgb) - p->drawPixmap(QRect(sgl, h - sgb, w - xSide, sgb), pix, - QRect(sgl, pix.height() - sgb, pix.width() - xSide, sgb)); - // Lower Right - if (sgr && sgb) - p->drawPixmap(QPoint(w-sgr, h - sgb), pix, - QRect(pix.width()-sgr, pix.height() - sgb, sgr, sgb)); + QMargins margins(d->scaleGrid->top(), d->scaleGrid->left(), d->scaleGrid->bottom(), d->scaleGrid->right()); + QTileRules rules((Qt::TileRule)d->scaleGrid->horizontalTileRule(), + (Qt::TileRule)d->scaleGrid->verticalTileRule()); + qDrawBorderPixmap(p, QRect(0, 0, (int)d->width, (int)d->height), margins, pix, pix.rect(), margins, rules); } if (d->smooth) { @@ -487,7 +437,8 @@ void QFxImage::setSource(const QUrl &url) QFxPerfTimer<QFxPerf::PixmapLoad> perf; #endif Q_D(QFxImage); - if (url == d->url) + //equality is fairly expensive, so we bypass for simple, common case + if ((d->url.isEmpty() == url.isEmpty()) && url == d->url) return; if (d->sciReply) { @@ -535,13 +486,23 @@ void QFxImage::setSource(const QUrl &url) this, SLOT(sciRequestFinished())); } } else { - d->reply = QFxPixmap::get(qmlEngine(this), d->url, this, SLOT(requestFinished())); + d->reply = QFxPixmap::get(qmlEngine(this), d->url, &d->pix); if (d->reply) { + connect(d->reply, SIGNAL(finished()), this, SLOT(requestFinished())); connect(d->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 progressChanged(d->progress); + emit statusChanged(d->status); + emit sourceChanged(d->url); + emit progressChanged(1.0); + update(); } } } @@ -553,15 +514,16 @@ void QFxImage::requestFinished() { Q_D(QFxImage); if (d->url.path().endsWith(QLatin1String(".sci"))) { - d->pix = QFxPixmap(d->sciurl); + QFxPixmap::find(d->sciurl, &d->pix); } else { if (d->reply) { + //###disconnect really needed? disconnect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(requestProgress(qint64,qint64))); if (d->reply->error() != QNetworkReply::NoError) d->status = Error; } - d->pix = QFxPixmap(d->url); + QFxPixmap::find(d->url, &d->pix); } setImplicitWidth(d->pix.width()); setImplicitHeight(d->pix.height()); @@ -612,15 +574,27 @@ void QFxImage::setGridScaledImage(const QFxGridScaledImage& sci) sg->setBottom(sci.gridBottom()); sg->setLeft(sci.gridLeft()); sg->setRight(sci.gridRight()); + sg->setHorizontalTileRule(sci.horizontalTileRule()); + sg->setVerticalTileRule(sci.verticalTileRule()); d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); - d->reply = QFxPixmap::get(qmlEngine(this), d->sciurl, this, SLOT(requestFinished())); + d->reply = QFxPixmap::get(qmlEngine(this), d->sciurl, &d->pix); if (d->reply) { + connect(d->reply, SIGNAL(finished()), this, SLOT(requestFinished())); connect(d->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 progressChanged(d->progress); + emit statusChanged(d->status); + emit sourceChanged(d->url); + emit progressChanged(1.0); + update(); } } } diff --git a/src/declarative/fx/qfxlayoutitem.cpp b/src/declarative/fx/qfxlayoutitem.cpp new file mode 100644 index 0000000..1f814e8 --- /dev/null +++ b/src/declarative/fx/qfxlayoutitem.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 "qfxlayoutitem.h" +#include <QDebug> +#include <limits.h> + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,LayoutItem,QFxLayoutItem) + +/*! + \qmlclass LayoutItem QFxLayoutItem + \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. +*/ + + +/*! + \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 +*/ + +QFxLayoutItem::QFxLayoutItem(QFxItem* parent) + : QFxItem(parent), m_maximumSize(INT_MAX,INT_MAX), m_minimumSize(0,0), m_preferredSize(100,100) +{ + setGraphicsItem(this); +} + +void QFxLayoutItem::setGeometry(const QRectF & rect) +{ + setX(rect.x()); + setY(rect.y()); + setWidth(rect.width()); + setHeight(rect.height()); +} + +QSizeF QFxLayoutItem::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 new file mode 100644 index 0000000..7150554 --- /dev/null +++ b/src/declarative/fx/qfxlayoutitem.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 QFXGRAPHICSLAYOUTITEM_H +#define QFXGRAPHICSLAYOUTITEM_H +#include <QGraphicsLayoutItem> +#include <QFxItem> +#include <QSizeF> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QFxLayoutItem : public QFxItem, 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: + QFxLayoutItem(QFxItem* 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(QFxLayoutItem) + +QT_END_HEADER +#endif diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp index 6dcfcd1..45ff51c 100644 --- a/src/declarative/fx/qfxpathview.cpp +++ b/src/declarative/fx/qfxpathview.cpp @@ -241,10 +241,12 @@ void QFxPathView::setCurrentIndex(int idx) idx = qAbs(idx % d->model->count()); if (d->model && idx != d->currentIndex) { d->currentIndex = idx; - d->snapToCurrent(); - int itemIndex = (idx - d->firstIndex + d->model->count()) % d->model->count(); - if (itemIndex < d->items.count()) - d->items.at(itemIndex)->setFocus(true); + 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(); } } @@ -565,9 +567,34 @@ bool QFxPathView::sceneEventFilter(QGraphicsItem *i, QEvent *e) return QFxItem::sceneEventFilter(i, e); } +void QFxPathView::componentComplete() +{ + Q_D(QFxPathView); + QFxItem::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 QFxPathViewPrivate::regenerate() { Q_Q(QFxPathView); + if (!q->isComponentComplete()) + return; + for (int i=0; i<items.count(); i++){ QFxItem *p = items[i]; releaseItem(p); @@ -612,7 +639,7 @@ void QFxPathViewPrivate::updateItem(QFxItem *item, qreal percent) void QFxPathView::refill() { Q_D(QFxPathView); - if (!d->isValid()) + if (!d->isValid() || !isComponentComplete()) return; QList<qreal> positions; @@ -688,7 +715,7 @@ void QFxPathView::itemsInserted(int modelIndex, int count) { //XXX support animated insertion Q_D(QFxPathView); - if (!d->isValid()) + if (!d->isValid() || !isComponentComplete()) return; if (d->pathItems == -1) { for (int i = 0; i < count; ++i) { @@ -718,7 +745,7 @@ void QFxPathView::itemsRemoved(int modelIndex, int count) { //XXX support animated removal Q_D(QFxPathView); - if (!d->isValid()) + if (!d->isValid() || !isComponentComplete()) return; if (d->pathItems == -1) { for (int i = 0; i < count; ++i) { diff --git a/src/declarative/fx/qfxpathview.h b/src/declarative/fx/qfxpathview.h index 4b8f12d..9cc8adb 100644 --- a/src/declarative/fx/qfxpathview.h +++ b/src/declarative/fx/qfxpathview.h @@ -109,6 +109,7 @@ protected: void mouseReleaseEvent(QGraphicsSceneMouseEvent *); bool sendMouseEvent(QGraphicsSceneMouseEvent *event); bool sceneEventFilter(QGraphicsItem *, QEvent *); + void componentComplete(); private Q_SLOTS: void refill(); diff --git a/src/declarative/fx/qfxpathview_p.h b/src/declarative/fx/qfxpathview_p.h index 801bdb8..a69f75f 100644 --- a/src/declarative/fx/qfxpathview_p.h +++ b/src/declarative/fx/qfxpathview_p.h @@ -86,7 +86,7 @@ public: { Q_Q(QFxPathView); _offset = 0; - q->setAcceptedMouseButtons(Qt::NoButton); + q->setAcceptedMouseButtons(Qt::LeftButton); q->setFlag(QGraphicsItem::ItemAutoDetectsFocusProxy); q->setFiltersChildEvents(true); q->connect(&tl, SIGNAL(updated()), q, SLOT(ticked())); diff --git a/src/declarative/fx/qfxpixmap.cpp b/src/declarative/fx/qfxpixmap.cpp index 6647b21..99b8128 100644 --- a/src/declarative/fx/qfxpixmap.cpp +++ b/src/declarative/fx/qfxpixmap.cpp @@ -81,14 +81,7 @@ public: } }; -class QFxPixmapPrivate -{ -public: - QFxPixmapPrivate() {} - - QPixmap pixmap; - - bool readImage(QIODevice *dev) +static bool readImage(QIODevice *dev, QPixmap *pixmap) { QImageReader imgio(dev); @@ -114,13 +107,12 @@ public: if (!sz.isValid()) img = img.scaled(limit,Qt::KeepAspectRatio); #endif - pixmap = QPixmap::fromImage(img); + *pixmap = QPixmap::fromImage(img); return true; } else { return false; } } -}; /*! \internal @@ -131,25 +123,26 @@ public: This class is NOT reentrant. The pixmap cache will grow indefinately. */ -QFxPixmap::QFxPixmap() -: d(new QFxPixmapPrivate) -{ -} -QFxPixmap::QFxPixmap(const QUrl &url) -: d(new QFxPixmapPrivate) + +bool QFxPixmap::find(const QUrl& url, QPixmap *pixmap) { #ifdef Q_ENABLE_PERFORMANCE_LOG QFxPerfTimer<QFxPerf::PixmapLoad> perf; #endif + QString key = url.toString(); - if (!QPixmapCache::find(key,&d->pixmap)) { + if (!QPixmapCache::find(key,pixmap)) { #ifndef QT_NO_LOCALFILE_OPTIMIZED_QML if (url.scheme()==QLatin1String("file")) { QFile f(url.toLocalFile()); - if (f.open(QIODevice::ReadOnly)) - if (!d->readImage(&f)) + if (f.open(QIODevice::ReadOnly)) { + if (!readImage(&f, pixmap)) { qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + } + } else + *pixmap = QPixmap(); } else #endif { @@ -158,55 +151,21 @@ QFxPixmap::QFxPixmap(const QUrl &url) // API usage error qWarning() << "QFxPixmap: URL not loaded" << url; } else { - if ((*iter)->reply->error()) + if ((*iter)->reply->error()) { qWarning() << "Network error loading" << url << (*iter)->reply->errorString(); - else - if (!d->readImage((*iter)->reply)) + *pixmap = QPixmap(); + } else + if (!readImage((*iter)->reply, pixmap)) { qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + } (*iter)->release(); } } - QPixmapCache::insert(key, d->pixmap); + QPixmapCache::insert(key, *pixmap); } } -QFxPixmap::QFxPixmap(const QFxPixmap &o) -: d(new QFxPixmapPrivate) -{ - d->pixmap = o.d->pixmap; -} - -QFxPixmap::~QFxPixmap() -{ - delete d; -} - -QFxPixmap &QFxPixmap::operator=(const QFxPixmap &o) -{ - d->pixmap = o.d->pixmap; - return *this; -} - -bool QFxPixmap::isNull() const -{ - return d->pixmap.isNull(); -} - -int QFxPixmap::width() const -{ - return d->pixmap.width(); -} - -int QFxPixmap::height() const -{ - return d->pixmap.height(); -} - -QFxPixmap::operator const QPixmap &() const -{ - return d->pixmap; -} - /*! Starts a network request to load \a url. When the URL is loaded, the given slot is invoked. Note that if the image is already cached, @@ -215,20 +174,28 @@ QFxPixmap::operator const QPixmap &() const Returns a QNetworkReply if the image is not immediately available, otherwise returns 0. The QNetworkReply must not be stored - it may be destroyed at any time. */ -QNetworkReply *QFxPixmap::get(QmlEngine *engine, const QUrl& url, QObject* obj, const char* slot) +QNetworkReply *QFxPixmap::get(QmlEngine *engine, const QUrl& url, QPixmap *pixmap) { #ifndef QT_NO_LOCALFILE_OPTIMIZED_QML if (url.scheme()==QLatin1String("file")) { - QObject dummy; - QObject::connect(&dummy, SIGNAL(destroyed()), obj, slot); + QString key = url.toString(); + if (!QPixmapCache::find(key,pixmap)) { + QFile f(url.toLocalFile()); + 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,0)) { - QObject dummy; - QObject::connect(&dummy, SIGNAL(destroyed()), obj, slot); + if (QPixmapCache::find(key,pixmap)) { return 0; } @@ -242,7 +209,6 @@ QNetworkReply *QFxPixmap::get(QmlEngine *engine, const QUrl& url, QObject* obj, (*iter)->addRef(); } - QObject::connect((*iter)->reply, SIGNAL(finished()), obj, slot); return (*iter)->reply; } diff --git a/src/declarative/fx/qfxpixmap.h b/src/declarative/fx/qfxpixmap.h index f63299b..ec8d2be 100644 --- a/src/declarative/fx/qfxpixmap.h +++ b/src/declarative/fx/qfxpixmap.h @@ -54,29 +54,13 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QmlEngine; class QNetworkReply; -class QFxPixmapPrivate; -class Q_DECLARATIVE_EXPORT QFxPixmap +class Q_DECLARATIVE_EXPORT QFxPixmap //### rename QFxPixmapCache { public: - QFxPixmap(); - QFxPixmap(const QUrl& url); // url must have been passed to QFxPixmap::get, and finished. - QFxPixmap(const QFxPixmap &); - virtual ~QFxPixmap(); - - QFxPixmap &operator=(const QFxPixmap &); - - static QNetworkReply *get(QmlEngine *, const QUrl& url, QObject*, const char* slot); + static QNetworkReply *get(QmlEngine *, const QUrl& url, QPixmap *pixmap); static void cancelGet(const QUrl& url, QObject* obj); - bool isNull() const; - - int width() const; - int height() const; - - operator const QPixmap &() const; - -private: - QFxPixmapPrivate *d; + static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QFxPixmap::get, and finished. Or must be a local file. }; diff --git a/src/declarative/fx/qfxscalegrid.cpp b/src/declarative/fx/qfxscalegrid.cpp index 74ef0a1..8eb9890 100644 --- a/src/declarative/fx/qfxscalegrid.cpp +++ b/src/declarative/fx/qfxscalegrid.cpp @@ -41,6 +41,7 @@ #include <QBuffer> #include <qml.h> +#include <QDebug> #include "qfxscalegrid_p.h" @@ -73,7 +74,8 @@ QT_BEGIN_NAMESPACE */ QML_DEFINE_NOCREATE_TYPE(QFxScaleGrid) -QFxScaleGrid::QFxScaleGrid() : QObject(), _left(0), _top(0), _right(0), _bottom(0) +QFxScaleGrid::QFxScaleGrid() : QObject(), _left(0), _top(0), _right(0), _bottom(0), + _horizontalTileRule(Stretch), _verticalTileRule(Stretch) { } @@ -122,13 +124,25 @@ void QFxScaleGrid::setBottom(int pos) _bottom = pos; } +void QFxScaleGrid::setHorizontalTileRule(TileRule r) +{ + _horizontalTileRule = r; +} + +void QFxScaleGrid::setVerticalTileRule(TileRule r) +{ + _verticalTileRule = r; +} + + QFxGridScaledImage::QFxGridScaledImage() -: _l(-1), _r(-1), _t(-1), _b(-1) +: _l(-1), _r(-1), _t(-1), _b(-1), + _h(QFxScaleGrid::Stretch), _v(QFxScaleGrid::Stretch) { } QFxGridScaledImage::QFxGridScaledImage(const QFxGridScaledImage &o) -: _l(o._l), _r(o._r), _t(o._t), _b(o._b), _pix(o._pix) +: _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix) { } @@ -138,22 +152,24 @@ QFxGridScaledImage &QFxGridScaledImage::operator=(const QFxGridScaledImage &o) _r = o._r; _t = o._t; _b = o._b; + _h = o._h; + _v = o._v; _pix = o._pix; return *this; } QFxGridScaledImage::QFxGridScaledImage(QIODevice *data) -: _l(-1), _r(-1), _t(-1), _b(-1) +: _l(-1), _r(-1), _t(-1), _b(-1), _h(QFxScaleGrid::Stretch), _v(QFxScaleGrid::Stretch) { int l = -1; - int r = -1; - int t = -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("#"))) + if (line.isEmpty() || line.startsWith(QLatin1String("#"))) continue; QStringList list = line.split(QLatin1Char(':')); @@ -173,6 +189,10 @@ QFxGridScaledImage::QFxGridScaledImage(QIODevice *data) b = list[1].toInt(); else if (list[0] == QLatin1String("imageFile")) 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()) @@ -183,6 +203,19 @@ QFxGridScaledImage::QFxGridScaledImage(QIODevice *data) _pix = imgFile; } +QFxScaleGrid::TileRule QFxGridScaledImage::stringToRule(const QString &s) +{ + if (s == QLatin1String("Stretch")) + return QFxScaleGrid::Stretch; + if (s == QLatin1String("Repeat")) + return QFxScaleGrid::Repeat; + if (s == QLatin1String("Round")) + return QFxScaleGrid::Round; + + qWarning() << "Unknown tile rule specified. Using Stretch"; + return QFxScaleGrid::Stretch; +} + bool QFxGridScaledImage::isValid() const { return _l >= 0; diff --git a/src/declarative/fx/qfxscalegrid_p.h b/src/declarative/fx/qfxscalegrid_p.h index 986bcda..483ade1 100644 --- a/src/declarative/fx/qfxscalegrid_p.h +++ b/src/declarative/fx/qfxscalegrid_p.h @@ -57,11 +57,15 @@ QT_MODULE(Declarative) class Q_DECLARATIVE_EXPORT QFxScaleGrid : public QObject { Q_OBJECT + Q_ENUMS(TileRule) Q_PROPERTY(int left READ left WRITE setLeft) Q_PROPERTY(int top READ top WRITE setTop) Q_PROPERTY(int right READ right WRITE setRight) Q_PROPERTY(int bottom READ bottom WRITE setBottom) + Q_PROPERTY(TileRule horizontalTileRule READ horizontalTileRule WRITE setHorizontalTileRule) + Q_PROPERTY(TileRule verticalTileRule READ verticalTileRule WRITE setVerticalTileRule) + public: QFxScaleGrid(); ~QFxScaleGrid(); @@ -80,11 +84,21 @@ public: int bottom() const { return _bottom; } void setBottom(int); + enum TileRule { Stretch = Qt::Stretch, Repeat = Qt::Repeat, Round = Qt::Round }; + + TileRule horizontalTileRule() const { return _horizontalTileRule; } + void setHorizontalTileRule(TileRule); + + TileRule verticalTileRule() const { return _verticalTileRule; } + void setVerticalTileRule(TileRule); + private: int _left; int _top; int _right; int _bottom; + TileRule _horizontalTileRule; + TileRule _verticalTileRule; }; class Q_DECLARATIVE_EXPORT QFxGridScaledImage @@ -99,14 +113,21 @@ public: int gridRight() const; int gridTop() const; int gridBottom() const; + QFxScaleGrid::TileRule horizontalTileRule() const { return _h; } + QFxScaleGrid::TileRule verticalTileRule() const { return _v; } QString pixmapUrl() const; private: + static QFxScaleGrid::TileRule stringToRule(const QString &); + +private: int _l; int _r; int _t; int _b; + QFxScaleGrid::TileRule _h; + QFxScaleGrid::TileRule _v; QString _pix; }; diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 3240360..224f668 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -654,7 +654,8 @@ QmlPauseAnimation::~QmlPauseAnimation() void QmlPauseAnimationPrivate::init() { Q_Q(QmlPauseAnimation); - pa = new QPauseAnimation(q); + pa = new QPauseAnimation; + QFx_setParent_noEvent(pa, q); } /*! @@ -799,7 +800,8 @@ QmlRunScriptAction::~QmlRunScriptAction() void QmlRunScriptActionPrivate::init() { Q_Q(QmlRunScriptAction); - rsa = new QActionAnimation(&proxy, q); + rsa = new QActionAnimation(&proxy); + QFx_setParent_noEvent(rsa, q); } /*! @@ -906,7 +908,8 @@ QmlSetPropertyAction::~QmlSetPropertyAction() void QmlSetPropertyActionPrivate::init() { Q_Q(QmlSetPropertyAction); - spa = new QActionAnimation(q); + spa = new QActionAnimation; + QFx_setParent_noEvent(spa, q); } /*! @@ -1096,7 +1099,8 @@ QmlParentChangeAction::~QmlParentChangeAction() void QmlParentChangeActionPrivate::init() { Q_Q(QmlParentChangeAction); - cpa = new QActionAnimation(q); + cpa = new QActionAnimation; + QFx_setParent_noEvent(cpa, q); } void QmlParentChangeActionPrivate::doAction() @@ -1494,7 +1498,9 @@ QmlPropertyAnimation::~QmlPropertyAnimation() void QmlPropertyAnimationPrivate::init() { Q_Q(QmlPropertyAnimation); - va = new QmlTimeLineValueAnimator(q); + va = new QmlTimeLineValueAnimator; + QFx_setParent_noEvent(va, q); + va->setStartValue(QVariant(0.0f)); va->setEndValue(QVariant(1.0f)); } diff --git a/src/declarative/util/qmlstategroup.cpp b/src/declarative/util/qmlstategroup.cpp index 3a07fbe..bb40a8b 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(q); } + if (!nullState) { nullState = new QmlState; QFx_setParent_noEvent(nullState, q); } if (!oldState) oldState = nullState; if (!newState) newState = nullState; } diff --git a/src/declarative/util/qmltransitionmanager.cpp b/src/declarative/util/qmltransitionmanager.cpp index be082f8..f04a821 100644 --- a/src/declarative/util/qmltransitionmanager.cpp +++ b/src/declarative/util/qmltransitionmanager.cpp @@ -242,7 +242,7 @@ void QmlTransitionManager::transition(const QList<Action> &list, d->applyBindings(); } -#include <QDebug> + void QmlTransitionManager::cancel() { if (d->transition) { |