diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-09 01:16:18 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-09 01:16:18 (GMT) |
commit | d131a9f99ebd5d753d2eedfafe0b276410168bc8 (patch) | |
tree | de22a55bdc4282fba1d40287361f582d78d20013 /src | |
parent | b957118a2d2f44cec5f1a0709da26a5c685cc344 (diff) | |
parent | 0a39d054989c0402404c2c3cf2bfe566511ea3da (diff) | |
download | Qt-d131a9f99ebd5d753d2eedfafe0b276410168bc8.zip Qt-d131a9f99ebd5d753d2eedfafe0b276410168bc8.tar.gz Qt-d131a9f99ebd5d753d2eedfafe0b276410168bc8.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui-scriptopt
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/fx/qfxgraphicsobjectcontainer.cpp | 119 | ||||
-rw-r--r-- | src/declarative/fx/qfxgraphicsobjectcontainer.h | 8 | ||||
-rw-r--r-- | src/declarative/fx/qfxgridview.cpp | 15 | ||||
-rw-r--r-- | src/declarative/fx/qfxlistview.cpp | 19 |
4 files changed, 89 insertions, 72 deletions
diff --git a/src/declarative/fx/qfxgraphicsobjectcontainer.cpp b/src/declarative/fx/qfxgraphicsobjectcontainer.cpp index c0cac6c..5a61d12 100644 --- a/src/declarative/fx/qfxgraphicsobjectcontainer.cpp +++ b/src/declarative/fx/qfxgraphicsobjectcontainer.cpp @@ -43,9 +43,42 @@ #include <QGraphicsObject> #include <QGraphicsWidget> #include <QGraphicsSceneResizeEvent> +#include <private/qfxitem_p.h> QT_BEGIN_NAMESPACE +class QFxGraphicsObjectContainerPrivate : public QFxItemPrivate +{ + Q_DECLARE_PUBLIC(QFxGraphicsObjectContainer) + +public: + QFxGraphicsObjectContainerPrivate() : QFxItemPrivate(), graphicsObject(0), syncedResize(false) + { } + + void _q_updateSize(); + + void setFiltering(bool on) + { + Q_Q(QFxGraphicsObjectContainer); + 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 QFxGraphicsObjectContainer \brief The GraphicsObjectContainer element allows you to add QGraphicsObjects into Fluid UI elements. @@ -61,7 +94,7 @@ QML_DEFINE_NOCREATE_TYPE(QGraphicsObject) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GraphicsObjectContainer,QFxGraphicsObjectContainer) QFxGraphicsObjectContainer::QFxGraphicsObjectContainer(QFxItem *parent) -: QFxItem(parent), _graphicsObject(0), _syncedResize(false) +: QFxItem(*new QFxGraphicsObjectContainerPrivate, parent) { } @@ -71,7 +104,8 @@ QFxGraphicsObjectContainer::~QFxGraphicsObjectContainer() QGraphicsObject *QFxGraphicsObjectContainer::graphicsObject() const { - return _graphicsObject; + Q_D(const QFxGraphicsObjectContainer); + return d->graphicsObject; } /*! @@ -80,30 +114,45 @@ QGraphicsObject *QFxGraphicsObjectContainer::graphicsObject() const */ void QFxGraphicsObjectContainer::setGraphicsObject(QGraphicsObject *object) { - if (object == _graphicsObject) + Q_D(QFxGraphicsObjectContainer); + if (object == d->graphicsObject) return; - //### what should we do with previously set object? + //### remove previously set item? + + d->setFiltering(false); + + d->graphicsObject = object; - _graphicsObject = object; + if (d->graphicsObject) { + d->graphicsObject->setParentItem(this); - if (_graphicsObject) { - _graphicsObject->setParentItem(this); + if (d->syncedResize && d->graphicsObject->isWidget()) { + QGraphicsWidget *gw = static_cast<QGraphicsWidget*>(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); - if (_syncedResize && _graphicsObject->isWidget()) { - _graphicsObject->installEventFilter(this); - QSizeF newSize = static_cast<QGraphicsWidget*>(_graphicsObject)->size(); //### use sizeHint? - setImplicitWidth(newSize.width()); - setImplicitHeight(newSize.height()); + gwSize = gw->size(); + setImplicitWidth(gwSize.width()); + setImplicitHeight(gwSize.height()); + + d->setFiltering(true); } } } QVariant QFxGraphicsObjectContainer::itemChange(GraphicsItemChange change, const QVariant &value) { + Q_D(QFxGraphicsObjectContainer); if (change == ItemSceneHasChanged) { - QGraphicsObject *o = _graphicsObject; - _graphicsObject = 0; + QGraphicsObject *o = d->graphicsObject; + d->graphicsObject = 0; setGraphicsObject(o); } return QFxItem::itemChange(change, value); @@ -111,9 +160,10 @@ QVariant QFxGraphicsObjectContainer::itemChange(GraphicsItemChange change, const bool QFxGraphicsObjectContainer::eventFilter(QObject *watched, QEvent *e) { - if (watched == _graphicsObject && e->type() == QEvent::GraphicsSceneResize) { - if (_graphicsObject && _graphicsObject->isWidget() && _syncedResize) { - QSizeF newSize = static_cast<QGraphicsWidget*>(_graphicsObject)->size(); + Q_D(QFxGraphicsObjectContainer); + if (watched == d->graphicsObject && e->type() == QEvent::GraphicsSceneResize) { + if (d->graphicsObject && d->graphicsObject->isWidget() && d->syncedResize) { + QSizeF newSize = static_cast<QGraphicsWidget*>(d->graphicsObject)->size(); setImplicitWidth(newSize.width()); setImplicitHeight(newSize.height()); } @@ -142,40 +192,27 @@ bool QFxGraphicsObjectContainer::eventFilter(QObject *watched, QEvent *e) */ bool QFxGraphicsObjectContainer::synchronizedResizing() const { - return _syncedResize; + Q_D(const QFxGraphicsObjectContainer); + return d->syncedResize; } void QFxGraphicsObjectContainer::setSynchronizedResizing(bool on) { - if (on == _syncedResize) + Q_D(QFxGraphicsObjectContainer); + if (on == d->syncedResize) return; - if (_graphicsObject && _graphicsObject->isWidget()) { - if (!on) { - _graphicsObject->removeEventFilter(this); - disconnect(this, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); - disconnect(this, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); - } - } - - _syncedResize = on; - - if (_graphicsObject && _graphicsObject->isWidget()) { - if (on) { - _graphicsObject->installEventFilter(this); - connect(this, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); - connect(this, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); - } - } + d->syncedResize = on; + d->setFiltering(on); } -void QFxGraphicsObjectContainer::_q_updateSize() +void QFxGraphicsObjectContainerPrivate::_q_updateSize() { - if (!_graphicsObject || !_graphicsObject->isWidget() || !_syncedResize) + if (!graphicsObject || !graphicsObject->isWidget() || !syncedResize) return; - QGraphicsWidget *gw = static_cast<QGraphicsWidget*>(_graphicsObject); - const QSizeF newSize(width(), height()); + QGraphicsWidget *gw = static_cast<QGraphicsWidget*>(graphicsObject); + const QSizeF newSize(width, height); gw->resize(newSize); //### will respecting the widgets min/max ever get us in trouble? (all other items always @@ -189,3 +226,5 @@ void QFxGraphicsObjectContainer::_q_updateSize() } QT_END_NAMESPACE + +#include "moc_qfxgraphicsobjectcontainer.cpp" diff --git a/src/declarative/fx/qfxgraphicsobjectcontainer.h b/src/declarative/fx/qfxgraphicsobjectcontainer.h index a8b7c8c..656a7f8 100644 --- a/src/declarative/fx/qfxgraphicsobjectcontainer.h +++ b/src/declarative/fx/qfxgraphicsobjectcontainer.h @@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QGraphicsObject; +class QFxGraphicsObjectContainerPrivate; class Q_DECLARATIVE_EXPORT QFxGraphicsObjectContainer : public QFxItem { @@ -74,12 +75,9 @@ protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value); bool eventFilter(QObject *watched, QEvent *e); -private Q_SLOTS: - void _q_updateSize(); - private: - QGraphicsObject *_graphicsObject; - bool _syncedResize; + Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxGraphicsObjectContainer) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index a8b27f4..2d25d56 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -149,7 +149,7 @@ class QFxGridViewPrivate : public QFxFlickablePrivate public: QFxGridViewPrivate() - : model(0), currentItem(0), tmpCurrent(0), flow(QFxGridView::LeftToRight) + : model(0), currentItem(0), flow(QFxGridView::LeftToRight) , visiblePos(0), visibleIndex(0) , currentIndex(-1) , cellWidth(100), cellHeight(100), columns(1), requestedIndex(-1) , highlightComponent(0), highlight(0), trackedItem(0) @@ -298,7 +298,6 @@ public: QList<FxGridItem*> visibleItems; QHash<QFxItem*,int> unrequestedItems; FxGridItem *currentItem; - QFxItem *tmpCurrent; QFxGridView::Flow flow; int visiblePos; int visibleIndex; @@ -640,10 +639,6 @@ void QFxGridViewPrivate::updateCurrent(int modelIndex) return; } - if (tmpCurrent) { - delete tmpCurrent; - tmpCurrent = 0; - } FxGridItem *oldCurrentItem = currentItem; currentIndex = modelIndex; currentItem = createItem(modelIndex); @@ -821,12 +816,8 @@ void QFxGridView::setCurrentIndex(int index) QFxItem *QFxGridView::currentItem() { Q_D(QFxGridView); - if (!d->currentItem) { - // Always return something valid - if (!d->tmpCurrent) - d->tmpCurrent = new QFxItem(viewport()); - return d->tmpCurrent; - } + if (!d->currentItem) + return 0; return d->currentItem->item; } diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 1247021..5afd881 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -170,15 +170,15 @@ class QFxListViewPrivate : public QFxFlickablePrivate public: QFxListViewPrivate() - : model(0), currentItem(0), tmpCurrent(0), orient(Qt::Vertical) + : model(0), currentItem(0), orient(Qt::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) , ownModel(false), wrap(false), autoHighlight(true) , haveHighlightRange(false), strictHighlightRange(false) - , highlightMoveSpeed(400), highlightResizeSpeed(400) {} void init(); @@ -371,7 +371,6 @@ public: QList<FxListItem*> visibleItems; QHash<QFxItem*,int> unrequestedItems; FxListItem *currentItem; - QFxItem *tmpCurrent; Qt::Orientation orient; int visiblePos; int visibleIndex; @@ -752,10 +751,6 @@ void QFxListViewPrivate::updateCurrent(int modelIndex) return; } - if (tmpCurrent) { - delete tmpCurrent; - tmpCurrent = 0; - } FxListItem *oldCurrentItem = currentItem; currentIndex = modelIndex; currentItem = createItem(modelIndex); @@ -991,14 +986,8 @@ void QFxListView::setCurrentIndex(int index) QFxItem *QFxListView::currentItem() { Q_D(QFxListView); - if (!d->currentItem) { - // Always return something valid - if (!d->tmpCurrent) { - d->tmpCurrent = new QFxItem; - d->tmpCurrent->setParent(viewport()); - } - return d->tmpCurrent; - } + if (!d->currentItem) + return 0; return d->currentItem->item; } |