diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-23 00:56:28 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-23 01:35:07 (GMT) |
commit | 5d5ead94bc79a5364d8685707711673f5dc1a35a (patch) | |
tree | 7887203ad5d3b717129b6794e3e0795b2834ed4c /src/declarative | |
parent | 0b59aed42d27584ef3493305c565dd47f66d179d (diff) | |
download | Qt-5d5ead94bc79a5364d8685707711673f5dc1a35a.zip Qt-5d5ead94bc79a5364d8685707711673f5dc1a35a.tar.gz Qt-5d5ead94bc79a5364d8685707711673f5dc1a35a.tar.bz2 |
Make QSimpleCanvasItem inherit QGraphicsObject
Diffstat (limited to 'src/declarative')
35 files changed, 260 insertions, 1446 deletions
diff --git a/src/declarative/canvas/canvas.pri b/src/declarative/canvas/canvas.pri index 28cab9b..e7cbb9d 100644 --- a/src/declarative/canvas/canvas.pri +++ b/src/declarative/canvas/canvas.pri @@ -1,9 +1,7 @@ SOURCES += \ canvas/qsimplecanvas.cpp \ canvas/qsimplecanvasitem.cpp \ - canvas/qsimplecanvasdebugplugin.cpp \ - canvas/qsimplecanvas_software.cpp \ - canvas/qsimplecanvas_graphicsview.cpp + canvas/qsimplecanvasdebugplugin.cpp HEADERS += \ canvas/qsimplecanvas.h \ diff --git a/src/declarative/canvas/qsimplecanvas.cpp b/src/declarative/canvas/qsimplecanvas.cpp index cbbc26d..327d10a 100644 --- a/src/declarative/canvas/qsimplecanvas.cpp +++ b/src/declarative/canvas/qsimplecanvas.cpp @@ -114,12 +114,10 @@ private: void QSimpleCanvasRootLayer::addDirty(QSimpleCanvasItem *i) { - _canvas->addDirty(i); } void QSimpleCanvasRootLayer::remDirty(QSimpleCanvasItem *i) { - _canvas->remDirty(i); } void QSimpleCanvasPrivate::clearFocusPanel(QSimpleCanvasItem *panel) @@ -558,6 +556,7 @@ QSimpleCanvas::QSimpleCanvas(QWidget *parent) void QSimpleCanvasPrivate::init(QSimpleCanvas::CanvasMode mode) { + mode = QSimpleCanvas::GraphicsView; this->mode = mode; if (mode == QSimpleCanvas::SimpleCanvas) @@ -590,8 +589,7 @@ void QSimpleCanvasPrivate::init(QSimpleCanvas::CanvasMode mode) view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setFrameStyle(0); - static_cast<QSimpleCanvasItemPrivate*>(root->d_ptr)->convertToGraphicsItem(); - view->scene()->addItem(static_cast<QSimpleCanvasItemPrivate*>(root->d_ptr)->graphicsItem); + view->scene()->addItem(root); // These seem to give the best performance view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); @@ -606,24 +604,6 @@ QSimpleCanvas::~QSimpleCanvas() delete d; } -void QSimpleCanvasPrivate::paint(QPainter &p) -{ -#if defined(QFX_RENDER_QPAINTER) - if (!isSetup) { - ++paintVersion; - root->d_func()->setupPainting(0, q->rect()); - } - - lrpTimer.start(); - - root->d_func()->paint(p); - - lrpTime = lrpTimer.elapsed(); -#else - Q_UNUSED(p); -#endif -} - QSimpleCanvas::CanvasMode QSimpleCanvas::canvasMode() const { return d->mode; @@ -798,12 +778,6 @@ void QSimpleCanvas::resizeEvent(QResizeEvent *e) QWidget::resizeEvent(e); } - -void QSimpleCanvas::remDirty(QSimpleCanvasItem *c) -{ - d->dirtyItems.removeAll(c); -} - void QSimpleCanvas::queueUpdate() { if (!d->timer) { @@ -812,44 +786,6 @@ void QSimpleCanvas::queueUpdate() } } -void QSimpleCanvas::addDirty(QSimpleCanvasItem *c) -{ - Q_ASSERT(d->isSimpleCanvas()); - queueUpdate(); - d->oldDirty |= c->d_func()->data()->lastPaintRect; - d->dirtyItems.append(c); -} - -QRect QSimpleCanvasPrivate::dirtyItemClip() const -{ - QRect rv; - if (isSimpleCanvas()) { - for (int ii = 0; ii < dirtyItems.count(); ++ii) - rv |= dirtyItems.at(ii)->d_func()->data()->lastPaintRect; - } - return rv; -} - -QRect QSimpleCanvasPrivate::resetDirty() -{ - if (isSimpleCanvas()) { - QRect r = oldDirty | dirtyItemClip(); - if (!r.isEmpty()) - r.adjust(-1,-1,2,2); //make sure we get everything (since we rounded from floats to ints) - for (int ii = 0; ii < dirtyItems.count(); ++ii) - static_cast<QSimpleCanvasItemPrivate*>(dirtyItems.at(ii)->d_ptr)->data()->dirty = false; - dirtyItems.clear(); - oldDirty = QRect(); - - if (fullUpdate()) - return QRect(); - else - return r; - } else { - return QRect(); - } -} - QSimpleCanvasItem *QSimpleCanvas::focusItem() const { return d->focusItem; @@ -872,33 +808,6 @@ QSimpleCanvasItem *QSimpleCanvas::focusItem(QSimpleCanvasItem *item) const bool QSimpleCanvas::event(QEvent *e) { - if (e->type() == QEvent::User && d->isSimpleCanvas()) { - int tbf = d->frameTimer.restart(); - d->timer = 0; - d->isSetup = true; - ++d->paintVersion; - d->root->d_func()->setupPainting(0, rect()); - - QRect r = d->resetDirty(); - - if (r.isEmpty() || fullUpdate()) - repaint(); - else - repaint(r); - emit framePainted(); - d->isSetup = false; - - int frametimer = d->frameTimer.elapsed(); - gfxCanvasTiming.append(QSimpleCanvasTiming(r, frametimer, d->lrpTime, tbf)); - if (d->debugPlugin) - d->debugPlugin->addTiming(d->lrpTime, frametimer, tbf); - d->lrpTime = 0; - if (continuousUpdate()) - queueUpdate(); - - return true; - } - if (e->type() == QEvent::ShortcutOverride) { if (QSimpleCanvasItem *focus = focusItem()) return focus->event(e); @@ -907,16 +816,6 @@ bool QSimpleCanvas::event(QEvent *e) return QWidget::event(e); } -void QSimpleCanvas::paintEvent(QPaintEvent *) -{ -#if defined(QFX_RENDER_QPAINTER) - if (d->mode == SimpleCanvas) { - QPainter p(this); - d->paint(p); - } -#endif -} - void QSimpleCanvas::dumpTiming() { for (int ii = 0; ii < gfxCanvasTiming.size(); ++ii) { @@ -952,16 +851,9 @@ void QSimpleCanvas::checkState() */ QImage QSimpleCanvas::asImage() const { - if (d->isSimpleCanvas()) { - QImage img(width(),height(),QImage::Format_RGB32); - QPainter p(&img); - const_cast<QSimpleCanvas*>(this)->d->paint(p); - return img; - } else { - QImage img(width(),height(),QImage::Format_RGB32); - QPainter p(&img); - d->view->render(&p); - return img; - } + QImage img(width(),height(),QImage::Format_RGB32); + QPainter p(&img); + d->view->render(&p); + return img; } QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvas.h b/src/declarative/canvas/qsimplecanvas.h index b9f8ddb..b260017 100644 --- a/src/declarative/canvas/qsimplecanvas.h +++ b/src/declarative/canvas/qsimplecanvas.h @@ -57,18 +57,6 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -namespace QSimpleCanvasConfig -{ - enum ImageType { Opaque, Translucent }; - - typedef QTransform Matrix; - - inline Matrix transformToMatrix(const QTransform &t) - { return t; } - inline QTransform matrixToTransform(const Matrix &t) - { return t; } -} - class QSimpleCanvas; class QSimpleCanvasLayer; @@ -79,8 +67,6 @@ class Q_DECLARATIVE_EXPORT QSimpleCanvas : public QWidget { Q_OBJECT public: - typedef QSimpleCanvasConfig::Matrix Matrix; - enum CanvasMode { GraphicsView, SimpleCanvas }; QSimpleCanvas(QWidget *parent = 0); @@ -107,7 +93,6 @@ Q_SIGNALS: protected: virtual bool event(QEvent *); - virtual void paintEvent(QPaintEvent *); virtual void keyPressEvent(QKeyEvent *); virtual void keyReleaseEvent(QKeyEvent *); virtual void mousePressEvent(QMouseEvent *); @@ -129,12 +114,9 @@ private: friend class QSimpleCanvasPrivate; friend class QSimpleCanvasItem; friend class QSimpleCanvasItemPrivate; - friend class QSimpleGraphicsItem; void queueUpdate(); QSimpleCanvasPrivate *d; - void addDirty(QSimpleCanvasItem *); - void remDirty(QSimpleCanvasItem *); }; diff --git a/src/declarative/canvas/qsimplecanvas_graphicsview.cpp b/src/declarative/canvas/qsimplecanvas_graphicsview.cpp deleted file mode 100644 index dd4012b..0000000 --- a/src/declarative/canvas/qsimplecanvas_graphicsview.cpp +++ /dev/null @@ -1,213 +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 "qsimplecanvas.h" -#include "qsimplecanvas_p.h" -#include "qsimplecanvasitem.h" -#include "qsimplecanvasitem_p.h" -#include <QGraphicsItem> -#include <QGraphicsSceneMouseEvent> - - -QT_BEGIN_NAMESPACE -static QHash<QGraphicsScene*,QSimpleCanvas*> sceneMap; - -QSimpleCanvasGraphicsView::QSimpleCanvasGraphicsView(QSimpleCanvasPrivate *parent) -: QGraphicsView(parent->q), canvas(parent) -{ - setScene(&_scene); - sceneMap[&_scene] = parent->q; - setFrameShape(QFrame::NoFrame); - viewport()->setAttribute(Qt::WA_OpaquePaintEvent); -} - -QSimpleCanvasGraphicsView::~QSimpleCanvasGraphicsView() -{ - sceneMap.remove(&_scene); -} - -QSimpleGraphicsItem::QSimpleGraphicsItem(QSimpleCanvasItem *canvasItem) -: /*scene(0),*/ owner(canvasItem) -{ - setAcceptedMouseButtons(Qt::NoButton); -} - -QSimpleGraphicsItem::~QSimpleGraphicsItem() -{ - owner->d_func()->graphicsItem = 0; -} - -void QSimpleGraphicsItem::paint(QPainter *painter, - const QStyleOptionGraphicsItem *, QWidget *) -{ - owner->paintContents(*painter); -} - -QRectF QSimpleGraphicsItem::boundingRect() const -{ - return owner->boundingRect(); -} - -void QSimpleGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - QSimpleCanvasItem *p = owner->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(event)) - return; - } - p = p->parent(); - } - owner->mousePressEvent(event); -} - -void QSimpleGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - QSimpleCanvasItem *p = owner->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(event)) - return; - } - p = p->parent(); - } - owner->mouseReleaseEvent(event); - ungrabMouse(); -} - -void QSimpleGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ - QSimpleCanvasItem *p = owner->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(event)) - return; - } - p = p->parent(); - } - owner->mouseDoubleClickEvent(event); -} - -void QSimpleGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - QSimpleCanvasItem *p = owner->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(event)) - return; - } - p = p->parent(); - } - owner->mouseMoveEvent(event); -} - -bool QSimpleGraphicsItem::sceneEvent(QEvent *event) -{ - bool rv = QGraphicsItem::sceneEvent(event); - if (event->type() == QEvent::UngrabMouse) - owner->mouseUngrabEvent(); - return rv; -} - -QVariant QSimpleGraphicsItem::itemChange(GraphicsItemChange change, const QVariant &value) -{ - if (change == ItemSceneHasChanged) { - QSimpleCanvasItemPrivate *owner_d = static_cast<QSimpleCanvasItemPrivate*>(owner->d_ptr); - QSimpleCanvas *oldCanvas = owner_d->canvas; - owner_d->canvas = sceneMap[scene()]; - if (owner_d->canvas){ - if (owner->hasFocus()) - owner->canvas()->d->setFocusItem(owner, Qt::OtherFocusReason); - if (owner->options() & QSimpleCanvasItem::IsFocusPanel) { - if (owner_d->wantsActiveFocusPanelPendingCanvas) { - owner_d->hasBeenActiveFocusPanel = true; - owner->canvas()->d->setActiveFocusPanel(owner); - owner_d->wantsActiveFocusPanelPendingCanvas = false; - } - } - } - if (owner->options() & QSimpleCanvasItem::MouseFilter) - owner_d->gvRemoveMouseFilter(); - - if (oldCanvas != owner_d->canvas) - owner->canvasChanged(); - - if (owner->options() & QSimpleCanvasItem::MouseFilter) - owner_d->gvAddMouseFilter(); - } - - return QGraphicsItem::itemChange(change, value); -} - -void QSimpleGraphicsItem::keyPressEvent(QKeyEvent *event) -{ - owner->keyPressEvent(event); - QGraphicsItem::keyPressEvent(event); -} - -void QSimpleGraphicsItem::keyReleaseEvent(QKeyEvent *event) -{ - owner->keyReleaseEvent(event); - QGraphicsItem::keyReleaseEvent(event); -} - -void QSimpleGraphicsItem::focusInEvent(QFocusEvent *) -{ - if (!owner->hasFocus()) - owner->setFocus(true); -} - -void QSimpleCanvasItemPrivate::gvRemoveMouseFilter() -{ - QGraphicsScene *scene = graphicsItem->scene(); - if (!scene) return; - - scene->removeEventFilter(q_ptr); -} - -void QSimpleCanvasItemPrivate::gvAddMouseFilter() -{ - QGraphicsScene *scene = graphicsItem->scene(); - if (!scene) return; - - scene->installEventFilter(q_ptr); -} -QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvas_p.h b/src/declarative/canvas/qsimplecanvas_p.h index cd76b22..33c889f 100644 --- a/src/declarative/canvas/qsimplecanvas_p.h +++ b/src/declarative/canvas/qsimplecanvas_p.h @@ -84,8 +84,6 @@ public: bool isGraphicsView() const { return mode == QSimpleCanvas::GraphicsView; } QRect oldDirty; - QRect resetDirty(); - void paint(QPainter &p); QSimpleCanvasItem *opaqueList; diff --git a/src/declarative/canvas/qsimplecanvas_software.cpp b/src/declarative/canvas/qsimplecanvas_software.cpp deleted file mode 100644 index dd5e201..0000000 --- a/src/declarative/canvas/qsimplecanvas_software.cpp +++ /dev/null @@ -1,232 +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 "qsimplecanvas.h" -#include "qsimplecanvasitem_p.h" -#include "qsimplecanvas_p.h" - - -QT_BEGIN_NAMESPACE -QRect QSimpleCanvasItemPrivate::setupPainting(int version, const QRect &bounding) -{ - Q_Q(QSimpleCanvasItem); - - bool hasContents = options & QSimpleCanvasItem::HasContents; - - QRect rv; - - if (hasContents || q->clip()) { - QRectF boundingRectActive = q->boundingRect(); - rv = data()->transformActive.mapRect(boundingRectActive).toAlignedRect() & bounding; - } - - data()->doNotPaint = rv.isEmpty(); - data()->doNotPaintChildren = data()->doNotPaint && q->clip(); - QRect myBounding = bounding; - if (q->clip()) - myBounding &= rv; - - if (!data()->doNotPaintChildren) { - for (int ii = 0; ii < children.count(); ++ii) { - QSimpleCanvasItem *child = children.at(ii); - - int childVersion = version; - if (!child->d_func()->data()->transformValid) - childVersion = canvas->d->paintVersion; - - bool recalcNeeded = - (childVersion > child->d_func()->data()->transformVersion); - - if (recalcNeeded) { - qreal visible = child->visible(); - child->d_func()->data()->activeOpacity = data()->activeOpacity; - if (visible != 1) - child->d_func()->data()->activeOpacity *= visible; - } - - if (child->d_func()->data()->activeOpacity != 0) { - if (recalcNeeded) { - // Calculate child's transform - qreal x = child->x(); - qreal y = child->y(); - qreal scale = child->scale(); - QSimpleCanvasItem::Flip flip = child->flip(); - - QSimpleCanvas::Matrix &am = - child->d_func()->data()->transformActive; - am = data()->transformActive; - if (x != 0 || y != 0) - am.translate(x, y); - if (scale != 1) { - QPointF to = child->d_func()->transformOrigin(); - if (to.x() != 0. || to.y() != 0.) - am.translate(to.x(), to.y()); - am.scale(scale, scale); - if (to.x() != 0. || to.y() != 0.) - am.translate(-to.x(), -to.y()); - } - - if (child->d_func()->data()->transformUser) - am = *child->d_func()->data()->transformUser * am; - - if (flip) { - QRectF br = child->boundingRect(); - am.translate(br.width() / 2., br.height() / 2); - am.scale((flip & QSimpleCanvasItem::HorizontalFlip)?-1:1, - (flip & QSimpleCanvasItem::VerticalFlip)?-1:1); - am.translate(-br.width() / 2., -br.height() / 2); - } - child->d_func()->data()->transformValid = true; - child->d_func()->data()->transformVersion = childVersion; - } - rv |= child->d_func()->setupPainting(child->d_func()->data()->transformVersion, myBounding); - } - } - } - - data()->lastPaintRect = rv; - if (!data()->doNotPaintChildren) { - if (!bounding.intersects(rv)) { - data()->doNotPaintChildren = true; - data()->doNotPaint = true; - } - } - - return rv; -} - -void QSimpleCanvasItemPrivate::paint(QPainter &p) -{ - Q_Q(QSimpleCanvasItem); - - QRect oldUcr; - if (clip) { - - p.save(); - QRectF boundingRectActive = q->boundingRect(); - - QRect cr; - switch(clip) { - case QSimpleCanvasItem::ClipToHeight: - { - qWarning("QSimpleCanvasItem: ClipToHeight not implemented"); - QRect r = p.clipRegion().boundingRect(); - cr = QRect(r.x(), 0, r.width(), - boundingRectActive.height()); - } - break; - case QSimpleCanvasItem::ClipToWidth: - { - qWarning("QSimpleCanvasItem: ClipToWidth not implemented"); - QRect r = p.clipRegion().boundingRect(); - cr = QRect(0, r.y(), boundingRectActive.width(), - r.height()); - } - break; - case QSimpleCanvasItem::ClipToRect: - cr = boundingRectActive.toAlignedRect(); - break; - default: - break; - } - - p.setWorldTransform(data()->transformActive); - if (p.clipRegion().isEmpty()) { - p.setClipRect(cr); - } else { - p.setClipRect(cr, Qt::IntersectClip); - } - - if (p.clipRegion().isEmpty()) { - p.restore(); - return; - } - } - - zOrderChildren(); - - int upto = 0; - if (!data()->doNotPaintChildren) { - for (upto = 0; upto < children.count(); ++upto) { - QSimpleCanvasItem *c = children.at(upto); - if (c->z() < 0) { - paintChild(p, c); - } else { - break; - } - } - } - - if (!data()->doNotPaint) { - p.setWorldTransform(data()->transformActive); - q->paintContents(p); - } - - if (!data()->doNotPaintChildren) { - for (; upto < children.count(); ++upto) { - QSimpleCanvasItem *c = children.at(upto); - paintChild(p, c); - } - } - - if (clip) - p.restore(); - - if (debuggerStatus && debuggerStatus->selected) { - p.setWorldTransform(data()->transformActive); - p.fillRect(q->boundingRect(), QColor(255, 0, 0, 80)); - } -} - -void QSimpleCanvasItemPrivate::paintChild(QPainter &p, QSimpleCanvasItem *c) -{ - if (c->d_func()->data()->activeOpacity != 0) { - - qreal op = p.opacity(); - p.setOpacity(c->d_func()->data()->activeOpacity); - - c->d_func()->paint(p); - - p.setOpacity(op); - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvasdebugplugin.cpp b/src/declarative/canvas/qsimplecanvasdebugplugin.cpp index 91ef7dc..81bfbfa 100644 --- a/src/declarative/canvas/qsimplecanvasdebugplugin.cpp +++ b/src/declarative/canvas/qsimplecanvasdebugplugin.cpp @@ -122,7 +122,7 @@ void QSimpleCanvasSceneDebugPlugin::refresh(QDataStream &ds, { ds << QmlDebugServerPlugin::objectToString(item) << item->x() << item->y() << item->z() << item->width() << item->height() - << (int)item->transformOrigin() << item->scale() << (int)item->flip() + << (int)item->transformOrigin() << item->scale() << (int)0 << item->transform() << item->hasActiveFocus() << (int)item->options(); diff --git a/src/declarative/canvas/qsimplecanvasitem.cpp b/src/declarative/canvas/qsimplecanvasitem.cpp index f53ae72..65c0a45 100644 --- a/src/declarative/canvas/qsimplecanvasitem.cpp +++ b/src/declarative/canvas/qsimplecanvasitem.cpp @@ -48,20 +48,24 @@ QT_BEGIN_NAMESPACE -QSimpleCanvasItemData::QSimpleCanvasItemData() -: buttons(Qt::NoButton), flip(QSimpleCanvasItem::NoFlip), - dirty(false), transformValid(true), doNotPaint(false), - doNotPaintChildren(false), x(0), y(0), z(0), - visible(1), transformUser(0), transformVersion(0), activeOpacity(1) + +static QHash<QGraphicsScene*,QSimpleCanvas*> sceneMap; + +QSimpleCanvasGraphicsView::QSimpleCanvasGraphicsView(QSimpleCanvasPrivate *parent) +: QGraphicsView(parent->q), canvas(parent) { + setScene(&_scene); + sceneMap[&_scene] = parent->q; + setFrameShape(QFrame::NoFrame); + viewport()->setAttribute(Qt::WA_OpaquePaintEvent); } -QSimpleCanvasItemData::~QSimpleCanvasItemData() +QSimpleCanvasGraphicsView::~QSimpleCanvasGraphicsView() { - if (transformUser) - delete transformUser; + sceneMap.remove(&_scene); } + /*! \internal \class QSimpleCanvasItem @@ -105,23 +109,106 @@ bool QSimpleCanvasItem::mouseFilter(QGraphicsSceneMouseEvent *) return false; } +bool QSimpleCanvasItem::sceneEvent(QEvent *event) +{ + bool rv = QGraphicsItem::sceneEvent(event); + if (event->type() == QEvent::UngrabMouse) + mouseUngrabEvent(); + return rv; +} + +QVariant QSimpleCanvasItem::itemChange(GraphicsItemChange change, + const QVariant &value) +{ + Q_D(QSimpleCanvasItem); + if (change == ItemSceneHasChanged) { + QSimpleCanvas *oldCanvas = d->canvas; + d->canvas = sceneMap[scene()]; + if (d->canvas){ + if (hasFocus()) + canvas()->d->setFocusItem(this, Qt::OtherFocusReason); + if (options() & QSimpleCanvasItem::IsFocusPanel) { + if (d->wantsActiveFocusPanelPendingCanvas) { + d->hasBeenActiveFocusPanel = true; + canvas()->d->setActiveFocusPanel(this); + d->wantsActiveFocusPanelPendingCanvas = false; + } + } + } + if (options() & QSimpleCanvasItem::MouseFilter) + d->gvRemoveMouseFilter(); + + if (oldCanvas != d->canvas) + canvasChanged(); + + if (options() & QSimpleCanvasItem::MouseFilter) + d->gvAddMouseFilter(); + } + + return QGraphicsItem::itemChange(change, value); +} + + void QSimpleCanvasItem::mousePressEvent(QGraphicsSceneMouseEvent *e) { +#if 0 + QSimpleCanvasItem *p = owner->parent(); + while(p) { + if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { + if (p->mouseFilter(event)) + return; + } + p = p->parent(); + } + owner->mousePressEvent(event); +#endif e->ignore(); } void QSimpleCanvasItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { +#if 0 + QSimpleCanvasItem *p = owner->parent(); + while(p) { + if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { + if (p->mouseFilter(event)) + return; + } + p = p->parent(); + } + owner->mouseReleaseEvent(event); + ungrabMouse(); +#endif e->ignore(); } void QSimpleCanvasItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) { +#if 0 + QSimpleCanvasItem *p = owner->parent(); + while(p) { + if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { + if (p->mouseFilter(event)) + return; + } + p = p->parent(); + } +#endif e->ignore(); } void QSimpleCanvasItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { +#if 0 + QSimpleCanvasItem *p = owner->parent(); + while(p) { + if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { + if (p->mouseFilter(event)) + return; + } + p = p->parent(); + } +#endif e->ignore(); } @@ -156,6 +243,8 @@ void QSimpleCanvasItem::focusOutEvent(QFocusEvent *e) void QSimpleCanvasItem::focusInEvent(QFocusEvent *e) { + if (!hasFocus()) + setFocus(true); e->ignore(); } @@ -292,36 +381,6 @@ QSimpleCanvasItem *QSimpleCanvasItem::parent() const return d->parent; } -void QSimpleCanvasItemPrivate::zOrderChildren() -{ - if (!needsZOrder || children.count() <= 1) - return; - - needsZOrder = false; - // This is a bubble sort for a reason - it is the fastest sort for a mostly - // ordered list. We only expect z ordering to change infrequently. - bool swap = true; - int c = 0; - while(swap) { - ++c; - swap = false; - QSimpleCanvasItem *item = children.first(); - qreal z = item->z(); - for (int ii = 1; ii < children.count(); ++ii) { - QSimpleCanvasItem *i2 = children.at(ii); - qreal z2 = i2->z(); - if (z2 < z) { - swap = true; - children[ii] = item; - children[ii - 1] = i2; - } else { - item = i2; - z = z2; - } - } - } -} - void QSimpleCanvasItemPrivate::canvasChanged(QSimpleCanvas *newCanvas, QSimpleCanvas *oldCanvas) { Q_Q(QSimpleCanvasItem); @@ -363,37 +422,10 @@ void QSimpleCanvasItem::setFocus(bool focus) } } -qreal QSimpleCanvasItem::x() const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return d->graphicsItem->x(); - else if (d->data_ptr) - return d->data()->x; - else - return 0; -} - -qreal QSimpleCanvasItem::y() const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return d->graphicsItem->y(); - else if (d->data_ptr) - return d->data()->y; - else - return 0; -} - qreal QSimpleCanvasItem::z() const { Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return d->graphicsItem->zValue(); - else if (d->data_ptr) - return d->data()->z; - else - return 0; + return zValue(); } void QSimpleCanvasItem::setX(qreal x) @@ -404,12 +436,7 @@ void QSimpleCanvasItem::setX(qreal x) qreal oldX = this->x(); - if (d->graphicsItem) { - d->graphicsItem->setPos(x, y()); - } else { - d->data()->x = x; - update(); - } + QGraphicsItem::setPos(x, y()); geometryChanged(QRectF(this->x(), y(), width(), height()), QRectF(oldX, y(), width(), height())); @@ -417,18 +444,12 @@ void QSimpleCanvasItem::setX(qreal x) void QSimpleCanvasItem::setY(qreal y) { - Q_D(QSimpleCanvasItem); if (y == this->y()) return; qreal oldY = this->y(); - if (d->graphicsItem) { - d->graphicsItem->setPos(x(), y); - } else { - d->data()->y = y; - update(); - } + QGraphicsItem::setPos(x(), y); geometryChanged(QRectF(x(), this->y(), width(), height()), QRectF(x(), oldY, width(), height())); @@ -436,30 +457,15 @@ void QSimpleCanvasItem::setY(qreal y) void QSimpleCanvasItem::setZ(qreal z) { - Q_D(QSimpleCanvasItem); if (z == this->z()) return; - if (d->graphicsItem) { - - if (z < 0) - d->graphicsItem->setFlag(QGraphicsItem::ItemStacksBehindParent, - true); - else - d->graphicsItem->setFlag(QGraphicsItem::ItemStacksBehindParent, - false); - - d->graphicsItem->setZValue(z); - - } else { - if (d->data()->z == z) - return; + if (z < 0) + setFlag(QGraphicsItem::ItemStacksBehindParent, true); + else + setFlag(QGraphicsItem::ItemStacksBehindParent, false); - d->data()->z = z; - if (parent()) - static_cast<QSimpleCanvasItemPrivate*>(parent()->d_ptr)->needsZOrder = true; - update(); - } + setZValue(z); } qreal QSimpleCanvasItem::width() const @@ -550,17 +556,10 @@ bool QSimpleCanvasItem::heightValid() const void QSimpleCanvasItem::setPos(const QPointF &point) { - Q_D(QSimpleCanvasItem); qreal oldX = x(); qreal oldY = y(); - if (d->graphicsItem) { - d->graphicsItem->setPos(point); - } else { - d->data()->x = point.x(); - d->data()->y = point.y(); - update(); - } + QGraphicsItem::setPos(point); geometryChanged(QRectF(x(), y(), width(), height()), QRectF(oldX, oldY, width(), height())); @@ -576,18 +575,14 @@ void QSimpleCanvasItem::setScale(qreal s) { Q_D(QSimpleCanvasItem); d->scale = s; - if (d->graphicsItem) { - QTransform t; - QPointF to = transformOriginPoint(); - if (to.x() != 0. || to.y() != 0.) - t.translate(to.x(), to.y()); - t.scale(s, s); - if (to.x() != 0. || to.y() != 0.) - t.translate(-to.x(), -to.y()); - d->graphicsItem->setTransform(t * d->graphicsItem->transform); - } else { - update(); - } + QTransform t; + QPointF to = transformOriginPoint(); + if (to.x() != 0. || to.y() != 0.) + t.translate(to.x(), to.y()); + t.scale(s, s); + if (to.x() != 0. || to.y() != 0.) + t.translate(-to.x(), -to.y()); + setTransform(t * d->transform); } bool QSimpleCanvasItem::isVisible() const @@ -602,39 +597,18 @@ bool QSimpleCanvasItem::isVisible() const qreal QSimpleCanvasItem::visible() const { - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return d->graphicsItem->opacity(); - else if (d->data_ptr) - return d->data()->visible; - else - return 1; + return opacity(); } void QSimpleCanvasItem::setVisible(qreal v) { - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - d->graphicsItem->setOpacity(v); - } else { - if (v == visible()) - return; - if (v == 0) - update(); - - d->data()->visible = v; - - if (v != 0) - update(); - } + setOpacity(v); } void QSimpleCanvasItem::addChild(QSimpleCanvasItem *c) { Q_D(QSimpleCanvasItem); d->children.append(c); - if (!d->graphicsItem) - d->needsZOrder = true; childrenChanged(); } @@ -665,28 +639,6 @@ QSimpleCanvasLayer *QSimpleCanvasItem::layer() return 0; } -void QSimpleCanvasItem::update() -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - d->graphicsItem->update(); - } else { - if (!parent()) - return; - - if (d->data()->dirty || 0. == d->data()->visible) return; - - QSimpleCanvasLayer *l = layer(); - if (l == this && parent()) - l = parent()->layer(); - if (l) { - l->addDirty(this); - d->data()->dirty = true; - d->data()->transformValid = false; - } - } -} - bool QSimpleCanvasItem::clip() const { Q_D(const QSimpleCanvasItem); @@ -717,240 +669,57 @@ void QSimpleCanvasItem::setClipType(ClipType c) { Q_D(QSimpleCanvasItem); d->clip = c; - if (d->graphicsItem) - d->graphicsItem->setFlag(QGraphicsItem::ItemClipsChildrenToShape, bool(c)); - else - update(); -} - -Qt::MouseButtons QSimpleCanvasItem::acceptedMouseButtons() const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return d->graphicsItem->acceptedMouseButtons(); - else if (d->data_ptr) - return (Qt::MouseButtons)d->data()->buttons; - else - return Qt::NoButton; + setFlag(QGraphicsItem::ItemClipsChildrenToShape, bool(c)); } -void QSimpleCanvasItem::setAcceptedMouseButtons(Qt::MouseButtons buttons) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) - d->graphicsItem->setAcceptedMouseButtons(buttons); - else - d->data()->buttons = buttons; -} - - QRect QSimpleCanvasItem::itemBoundingRect() { return boundingRect().toAlignedRect(); } -QPointF QSimpleCanvasItemPrivate::adjustFrom(const QPointF &p) const -{ - return p; -} - -QRectF QSimpleCanvasItemPrivate::adjustFrom(const QRectF &r) const -{ - return r; -} - -QPointF QSimpleCanvasItemPrivate::adjustTo(const QPointF &p) const -{ - return p; -} - -QRectF QSimpleCanvasItemPrivate::adjustTo(const QRectF &r) const -{ - return r; -} - QPointF QSimpleCanvasItem::mapFromScene(const QPointF &p) const { - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) { - return d->graphicsItem->mapFromScene(p); - } else { - QPointF mp = d->adjustFrom(p); - d->freshenTransforms(); - return d->data()->transformActive.inverted().map(mp); - } + return QGraphicsItem::mapFromScene(p); } QRectF QSimpleCanvasItem::mapFromScene(const QRectF &r) const { - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) { - return d->graphicsItem->mapFromScene(r).boundingRect(); - } else { - QRectF mr = d->adjustFrom(r); - d->freshenTransforms(); - return d->data()->transformActive.inverted().mapRect(mr); - } + return QGraphicsItem::mapFromScene(r).boundingRect(); } QPointF QSimpleCanvasItem::mapToScene(const QPointF &p) const { - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) { - return d->graphicsItem->mapToScene(p); - } else { - d->freshenTransforms(); - QPointF rp = d->data()->transformActive.map(p); - return d->adjustTo(rp); - } + return QGraphicsItem::mapToScene(p); } QRectF QSimpleCanvasItem::mapToScene(const QRectF &r) const { - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) { - return d->graphicsItem->mapToScene(r).boundingRect(); - } else { - d->freshenTransforms(); - QRectF rr = d->data()->transformActive.mapRect(r); - return d->adjustTo(rr); - } -} - -void QSimpleCanvasItemPrivate::freshenTransforms() const -{ - if (freshenNeeded()) - doFreshenTransforms(); + return QGraphicsItem::mapToScene(r).boundingRect(); } -bool QSimpleCanvasItemPrivate::freshenNeeded() const -{ -#if 0 - return parent && - (data()->transformVersion == -1 || - data()->parentTransformVersion == -1 || - parent->d_func()->data()->transformVersion != data()->parentTransformVersion); -#else - const QSimpleCanvasItemPrivate *me = this; - while(me) { - if (me->data_ptr && !me->data_ptr->transformValid) - return true; - if (me->parent) - me = me->parent->d_func(); - else - me = 0; - } - return false; -#endif -} - -void QSimpleCanvasItemPrivate::doFreshenTransforms() const -{ - Q_Q(const QSimpleCanvasItem); - if (parent) - parent->d_func()->doFreshenTransforms(); - - if (freshenNeeded()) { - if (parent) - data()->transformActive = parent->d_func()->data()->transformActive; - else - data()->transformActive = QSimpleCanvas::Matrix(); - data()->transformActive.translate(q->x(), q->y()); - if (scale != 1.) { - QPointF to = transformOrigin(); - if (to.x() != 0. || to.y() != 0.) - data()->transformActive.translate(to.x(), to.y()); - data()->transformActive.scale(scale, scale); - if (to.x() != 0. || to.y() != 0.) - data()->transformActive.translate(-to.x(), -to.y()); - } - - Q_Q(const QSimpleCanvasItem); - - if (data()->flip) { - QRectF br = q->boundingRect(); - data()->transformActive.translate(br.width() / 2., br.height() / 2); - data()->transformActive.scale((data()->flip & QSimpleCanvasItem::HorizontalFlip)?-1:1, - (data()->flip & QSimpleCanvasItem::VerticalFlip)?-1:1); - data()->transformActive.translate(-br.width() / 2., -br.height() / 2); - } - } -} - -QSimpleCanvas::Matrix QSimpleCanvasItem::transform() const +QTransform QSimpleCanvasItem::transform() const { Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return QSimpleCanvasConfig::transformToMatrix(d->graphicsItem->transform); - else if (d->data()->transformUser) - return *d->data()->transformUser; - else - return QSimpleCanvas::Matrix(); + return d->transform; } -void QSimpleCanvasItem::setTransform(const QSimpleCanvas::Matrix &m) +void QSimpleCanvasItem::setTransform(const QTransform &m) { Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - d->graphicsItem->transform = QSimpleCanvasConfig::matrixToTransform(m); - d->graphicsItem->setTransform(QTransform::fromScale(d->scale, d->scale) * d->graphicsItem->transform); - } else { - if (!d->data()->transformUser) - d->data()->transformUser = new QSimpleCanvas::Matrix; - *d->data()->transformUser = m; - update(); - } + d->transform = m; + QGraphicsItem::setTransform(QTransform::fromScale(d->scale, d->scale) * d->transform); } QSimpleCanvasItem *QSimpleCanvasItem::mouseGrabberItem() const { - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) { - QGraphicsScene *s = d->graphicsItem->scene(); - if (s) { - QGraphicsItem *item = s->mouseGrabberItem(); - QSimpleGraphicsItem *dgi = static_cast<QSimpleGraphicsItem *>(item); - return dgi?static_cast<QSimpleCanvasItem*>(dgi->owner):0; - } - } else { - QSimpleCanvas *c = canvas(); - if (c) - return c->d->lastMouseItem; + QGraphicsScene *s = scene(); + if (s) { + QGraphicsItem *item = s->mouseGrabberItem(); + return static_cast<QSimpleCanvasItem*>(item); // ### } return 0; } -void QSimpleCanvasItem::ungrabMouse() -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - d->graphicsItem->ungrabMouse(); - } else { - QSimpleCanvas *c = canvas(); - if (c && c->d->lastMouseItem == this) { - c->d->lastMouseItem->mouseUngrabEvent(); - c->d->lastMouseItem = 0; - } - } -} - -void QSimpleCanvasItem::grabMouse() -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - d->graphicsItem->grabMouse(); - } else { - QSimpleCanvas *c = canvas(); - if (c) { - if (c->d->lastMouseItem != this) { - if (c->d->lastMouseItem) - c->d->lastMouseItem->mouseUngrabEvent(); - c->d->lastMouseItem = this; - } - } - } -} - bool QSimpleCanvasItem::isFocusable() const { Q_D(const QSimpleCanvasItem); @@ -976,159 +745,32 @@ void QSimpleCanvasItemPrivate::setFocus(bool f) void QSimpleCanvasItemPrivate::setActiveFocus(bool f) { + Q_Q(QSimpleCanvasItem); hasActiveFocus = f; - if (graphicsItem) { - if (f) { - if (!(graphicsItem->flags() & QGraphicsItem::ItemIsFocusable)) - graphicsItem->setFlag(QGraphicsItem::ItemIsFocusable); - graphicsItem->setFocus(); - } else { - graphicsItem->clearFocus(); - if ((graphicsItem->flags() & QGraphicsItem::ItemIsFocusable) && !focusable) - graphicsItem->setFlag(QGraphicsItem::ItemIsFocusable, false); - } - + if (f) { + if (!(q->flags() & QGraphicsItem::ItemIsFocusable)) + q->setFlag(QGraphicsItem::ItemIsFocusable); + q->QGraphicsItem::setFocus(); + } else { + q->clearFocus(); + if ((q->flags() & QGraphicsItem::ItemIsFocusable) && !focusable) + q->setFlag(QGraphicsItem::ItemIsFocusable, false); } } -QSimpleCanvasItem::Flip QSimpleCanvasItem::flip() const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return NoFlip; - else if (d->data_ptr) - return d->data()->flip; - else - return NoFlip; -} - -void QSimpleCanvasItem::setFlip(Flip f) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) - return; - - if (d->data()->flip == f) - return; - - d->data()->flip = f; - update(); -} - -/*! - Places the item under \a item in the parent item's stack. - - The item itself and \a item must be siblings, or this method has no effect. - - \sa stackOver(), stackAt() - */ -void QSimpleCanvasItem::stackUnder(QSimpleCanvasItem *item) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) - return; // XXX - - QSimpleCanvasItem *p = parent(); - if (!p || !item || item == this) return; - - QSimpleCanvasItemPrivate *parent_d_ptr = static_cast<QSimpleCanvasItemPrivate*>(p->d_ptr); - int idx = parent_d_ptr->children.indexOf(item); - if (idx == -1) return; - - parent_d_ptr->children.removeAll(this); - idx = parent_d_ptr->children.indexOf(item); - parent_d_ptr->children.insert(idx + 1, this); - parent_d_ptr->needsZOrder = true; - - p->childrenChanged(); -} - -/*! - Places the item over \a item in the parent item's stack. - - The item itself and \a item must be siblings, or this method has no effect. - - \sa stackUnder(), stackAt() - */ -void QSimpleCanvasItem::stackOver(QSimpleCanvasItem *item) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) - return; // XXX - - QSimpleCanvasItem *p = parent(); - if (!p || !item || item == this) return; - - QSimpleCanvasItemPrivate *parent_d_ptr = static_cast<QSimpleCanvasItemPrivate*>(p->d_ptr); - int idx = parent_d_ptr->children.indexOf(item); - if (idx == -1) return; - - parent_d_ptr->children.removeAll(this); - idx = parent_d_ptr->children.indexOf(item); - parent_d_ptr->children.insert(idx, this); - parent_d_ptr->needsZOrder = true; - - p->childrenChanged(); -} - -/*! - Places the item at position \a index in the parent item's stack. - - If index is zero or less, the item is placed at the beginning of the - stack. If the index is greater than the number of items in the stack, the - item is placed at the end. - - \sa stackOver(), stackUnder() - */ -void QSimpleCanvasItem::stackAt(int index) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) - return; // XXX - - QSimpleCanvasItem *p = parent(); - if (!p) return; - - QSimpleCanvasItemPrivate *parent_d_ptr = static_cast<QSimpleCanvasItemPrivate*>(p->d_ptr); - parent_d_ptr->children.removeAll(this); - - if (index < 0) index = 0; - if (index > parent_d_ptr->children.size()) index = parent_d_ptr->children.size(); - - parent_d_ptr->children.insert(index, this); - parent_d_ptr->needsZOrder = true; - p->childrenChanged(); -} - -/*! - Returns the current stacking index for the child \a item. - - If \a item is not a child, -1 is returned. - - \sa stackAt() - */ -int QSimpleCanvasItem::indexForChild(QSimpleCanvasItem *item) -{ - Q_D(QSimpleCanvasItem); - return d->children.indexOf(item); -} - bool QSimpleCanvasItem::eventFilter(QObject *o, QEvent *e) { - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - switch(e->type()) { - case QEvent::GraphicsSceneMouseDoubleClick: - case QEvent::GraphicsSceneMouseMove: - case QEvent::GraphicsSceneMousePress: - case QEvent::GraphicsSceneMouseRelease: - if (mouseFilter(static_cast<QGraphicsSceneMouseEvent *>(e))) - return true; - break; - default: - break; - } + switch(e->type()) { + case QEvent::GraphicsSceneMouseDoubleClick: + case QEvent::GraphicsSceneMouseMove: + case QEvent::GraphicsSceneMousePress: + case QEvent::GraphicsSceneMouseRelease: + if (mouseFilter(static_cast<QGraphicsSceneMouseEvent *>(e))) + return true; + break; + default: + break; } return QObject::eventFilter(o, e); @@ -1166,102 +808,49 @@ void QSimpleCanvasItem::setOptions(Options options, bool set) d->options &= ~IsFocusRealm; } - if (d->graphicsItem) - d->graphicsItem->setFlag(QGraphicsItem::ItemHasNoContents, !(d->options & HasContents)); + setFlag(QGraphicsItem::ItemHasNoContents, !(d->options & HasContents)); if ((old & MouseFilter) != (d->options & MouseFilter)) { - if (d->graphicsItem) { - if (d->options & MouseFilter) - d->gvAddMouseFilter(); - else - d->gvRemoveMouseFilter(); - - } else { - QSimpleCanvas *c = canvas(); - if (c) { - if (d->options & MouseFilter) - c->d->installMouseFilter(this); - else - c->d->removeMouseFilter(this); - } - } + if (d->options & MouseFilter) + d->gvAddMouseFilter(); + else + d->gvRemoveMouseFilter(); } } QSimpleCanvasItem::QSimpleCanvasItem(QSimpleCanvasItemPrivate &dd, QSimpleCanvasItem *parent) -: QObject(dd, parent) +: QGraphicsObject(dd, parent, 0) { + setFlag(QGraphicsItem::ItemHasNoContents, true); } QSimpleCanvasItem::QSimpleCanvasItem(QSimpleCanvasItem *p) -: QObject(*(new QSimpleCanvasItemPrivate), p) +: QGraphicsObject(*(new QSimpleCanvasItemPrivate), p, 0) { + setFlag(QGraphicsItem::ItemHasNoContents, true); } QSimpleCanvasItem::~QSimpleCanvasItem() { Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - if ((d->options & (IsFocusPanel|IsFocusRealm)) && d->canvas) - d->canvas->d->focusPanelData.remove(this); - if (d->hasFocus && d->canvas) { - QSimpleCanvasItem *prnt = parent(); - while (prnt && !(prnt->options() & (IsFocusPanel|IsFocusRealm))) - prnt = prnt->parent(); - if (prnt && d->canvas->d->focusPanelData.value(prnt) == this) - d->canvas->d->focusPanelData.remove(prnt); - } - - qDeleteAll(children()); - if (parent()) - parent()->remChild(this); - delete d->graphicsItem; - } else { - update(); - setOptions(MouseFilter, false); - - if (d->canvas){ - if (d->canvas->focusItem() == this) - d->canvas->d->focusItem = 0; - if (d->canvas->d->lastFocusItem == this) - d->canvas->d->lastFocusItem = 0; - if (d->hasBeenActiveFocusPanel) - d->canvas->d->clearFocusPanel(this); - if (d->hasFocus) - d->canvas->d->clearFocusItem(this); - } - - while(!d->children.isEmpty()) { - QSimpleCanvasItem *child = d->children.takeFirst(); - delete child; - } - - if (parent() && d->data_ptr && d->data()->dirty) { - QSimpleCanvasLayer *l = parent()->layer(); - if (l) { - l->remDirty(this); - } - } - if (d->parent) - d->parent->remChild(this); - - - if (d->data_ptr) - delete d->data_ptr; + if ((d->options & (IsFocusPanel|IsFocusRealm)) && d->canvas) + d->canvas->d->focusPanelData.remove(this); + if (d->hasFocus && d->canvas) { + QSimpleCanvasItem *prnt = parent(); + while (prnt && !(prnt->options() & (IsFocusPanel|IsFocusRealm))) + prnt = prnt->parent(); + if (prnt && d->canvas->d->focusPanelData.value(prnt) == this) + d->canvas->d->focusPanelData.remove(prnt); } + + qDeleteAll(children()); + if (parent()) + parent()->remChild(this); } QSimpleCanvasItem::operator QGraphicsItem *() { - Q_D(QSimpleCanvasItem); - if (!d->graphicsItem) { - if (parent()) { - qWarning("QSimpleCanvasItem: Only the root item can be converted into a QGraphicsItem"); - return 0; - } - d->convertToGraphicsItem(); - } - return d->graphicsItem; + return this; } QSimpleCanvasItem::operator QmlDebuggerStatus *() @@ -1305,82 +894,14 @@ void QSimpleCanvasItemPrivate::setParentInternal(QSimpleCanvasItem *p) { Q_Q(QSimpleCanvasItem); QSimpleCanvasItem *oldParent = parent; - if (graphicsItem) { - if (oldParent) - oldParent->remChild(q); - - parent = p; - graphicsItem->setParentItem(p->d_func()->graphicsItem); + if (oldParent) + oldParent->remChild(q); - if (parent) - p->addChild(q); + parent = p; + q->setParentItem(p); - } else { - bool canvasChange = false; - if (p) - canvasChange = (p->d_func()->canvas != canvas); - QSimpleCanvas *old = canvas; - - QSimpleCanvasLayer *o = q->layer(); - if (q->parent()) { - q->update(); - q->parent()->remChild(q); - } - parent = p; - QSimpleCanvasLayer *n = 0; - if (q->parent()) { - q->parent()->addChild(q); - n = q->layer(); - } - - if (o != n) { - data()->dirty = false; - data()->transformValid = false; - if (o) o->remDirty(q); - if (n) n->addDirty(q); - } - - if (canvasChange) - canvasChanged(p->d_func()->canvas, old); - - q->update(); - } -} - -void QSimpleCanvasItemPrivate::convertToGraphicsItem(QGraphicsItem *parent) -{ - Q_Q(QSimpleCanvasItem); - Q_ASSERT(!graphicsItem); - graphicsItem = new QSimpleGraphicsItem(q); - graphicsItem->setFlag(QGraphicsItem::ItemHasNoContents, !(q->options() & QSimpleCanvasItem::HasContents)); if (parent) - graphicsItem->setParentItem(parent); - - QSimpleCanvasItemData *old = data_ptr; - data_ptr = 0; - - if (old) { - q->QSimpleCanvasItem::setX(old->x); - q->QSimpleCanvasItem::setY(old->y); - q->QSimpleCanvasItem::setZ(old->z); - q->QSimpleCanvasItem::setVisible(old->visible); - if (old->transformUser) - q->QSimpleCanvasItem::setTransform(*old->transformUser); - q->QSimpleCanvasItem::setFlip(old->flip); - q->QSimpleCanvasItem::setAcceptedMouseButtons((Qt::MouseButtons)old->buttons); - delete old; - } - - if (scale != 1) { - qreal s = scale; - scale = 1; - q->QSimpleCanvasItem::setScale(s); - } - - q->setClipType(clip); - - for (int ii = 0; ii < children.count(); ++ii) - static_cast<QSimpleCanvasItemPrivate*>(children.at(ii)->d_ptr)->convertToGraphicsItem(graphicsItem); + p->addChild(q); } /*! @@ -1395,14 +916,6 @@ void QSimpleCanvasItem::setParent(QSimpleCanvasItem *p) QObject::setParent(p); - if (d->graphicsItem && !static_cast<QSimpleCanvasItemPrivate*>(p->d_ptr)->graphicsItem) - qWarning("QSimpleCanvasItem: Cannot reparent a QGraphicsView item to a QSimpleCanvas item"); - - if (static_cast<QSimpleCanvasItemPrivate*>(p->d_ptr)->graphicsItem && !d->graphicsItem) { - d->setParentInternal(0); - d->convertToGraphicsItem(); - } - QSimpleCanvasItem *oldParent = d->parent; d->setParentInternal(p); parentChanged(p, oldParent); @@ -1462,7 +975,7 @@ int QSimpleCanvasItemPrivate::dump(int indent) QFxItem *i = qobject_cast<QFxItem *>(q); if (i) name = i->id().toLatin1(); - qWarning().nospace() << ba.constData() << state.constData() << " " << children.count() << " " << q << " " << name.constData(); + qWarning().nospace() << ba.constData() << state.constData() << " " << children.count() << " " << " " << name.constData(); int rv = 0; @@ -1731,8 +1244,31 @@ QPixmap QSimpleCanvasItem::string(const QString &str, const QColor &c, const QFo return img; } +void QSimpleCanvasItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + paintContents(*p); +} + void QSimpleCanvasItem::geometryChanged(const QRectF &, const QRectF &) { } +void QSimpleCanvasItemPrivate::gvRemoveMouseFilter() +{ + Q_Q(QSimpleCanvasItem); + QGraphicsScene *scene = q->scene(); + if (!scene) return; + + scene->removeEventFilter(q); +} + +void QSimpleCanvasItemPrivate::gvAddMouseFilter() +{ + Q_Q(QSimpleCanvasItem); + QGraphicsScene *scene = q->scene(); + if (!scene) return; + + scene->installEventFilter(q); +} + QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvasitem.h b/src/declarative/canvas/qsimplecanvasitem.h index 74841ea..eb7bcea 100644 --- a/src/declarative/canvas/qsimplecanvasitem.h +++ b/src/declarative/canvas/qsimplecanvasitem.h @@ -64,12 +64,12 @@ class QPointF; class QRectF; class QGraphicsSceneHoverEvent; -class Q_DECLARATIVE_EXPORT QSimpleCanvasItem : public QObject +class Q_DECLARATIVE_EXPORT QSimpleCanvasItem : public QGraphicsObject { Q_OBJECT Q_CAST_INTERFACES(QGraphicsItem) Q_CAST_INTERFACES(QmlDebuggerStatus) - Q_DECLARE_PRIVATE(QSimpleCanvasItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QSimpleCanvasItem) Q_ENUMS(TransformOrigin) Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin) @@ -104,11 +104,6 @@ public: Options options() const; void setOptions(Options, bool set = true); - Qt::MouseButtons acceptedMouseButtons() const; - void setAcceptedMouseButtons(Qt::MouseButtons buttons); - - qreal x() const; - qreal y() const; qreal z() const; QPointF pos() const; void setX(qreal); @@ -140,13 +135,6 @@ public: qreal scale() const; virtual void setScale(qreal); - enum Flip { NoFlip = 0, - VerticalFlip = 0x01, - HorizontalFlip = 0x02, - VerticalAndHorizontalFlip = 0x03 }; - Flip flip() const; - void setFlip(Flip); - qreal visible() const; virtual void setVisible(qreal); bool isVisible() const; @@ -155,10 +143,6 @@ public: QSimpleCanvasItem *parent() const; void setParent(QSimpleCanvasItem *); - void stackUnder(QSimpleCanvasItem *); - void stackOver(QSimpleCanvasItem *); - void stackAt(int idx); - int indexForChild(QSimpleCanvasItem *); QRect itemBoundingRect(); @@ -166,8 +150,6 @@ public: QRectF boundingRect() const; virtual void paintContents(QPainter &); - void update(); - virtual QSimpleCanvasLayer *layer(); bool hasChildren() const; @@ -178,12 +160,10 @@ public: QPointF mapToScene(const QPointF &) const; QRectF mapToScene(const QRectF &) const; - QSimpleCanvas::Matrix transform() const; - void setTransform(const QSimpleCanvas::Matrix &); + QTransform transform() const; + void setTransform(const QTransform &); QSimpleCanvasItem *mouseGrabberItem() const; - void ungrabMouse(); - void grabMouse(); virtual bool isFocusable() const; void setFocusable(bool); @@ -202,6 +182,7 @@ public: static QPixmap string(const QString &, const QColor & = Qt::black, const QFont & = QFont()); protected: + virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); virtual void addChild(QSimpleCanvasItem *); @@ -215,6 +196,8 @@ protected: public: // Events + virtual bool sceneEvent(QEvent *); + virtual QVariant itemChange(GraphicsItemChange, const QVariant &); virtual bool mouseFilter(QGraphicsSceneMouseEvent *); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); @@ -241,6 +224,7 @@ private: public: QSimpleCanvasItem(QSimpleCanvasItemPrivate &dd, QSimpleCanvasItem *parent); + }; Q_DECLARE_OPERATORS_FOR_FLAGS(QSimpleCanvasItem::Options) diff --git a/src/declarative/canvas/qsimplecanvasitem_p.h b/src/declarative/canvas/qsimplecanvasitem_p.h index a062054..39a1c48 100644 --- a/src/declarative/canvas/qsimplecanvasitem_p.h +++ b/src/declarative/canvas/qsimplecanvasitem_p.h @@ -43,6 +43,7 @@ #define QSIMPLECANVASITEM_P_H #include "private/qobject_p.h" +#include "private/qgraphicsitem_p.h" #include "qsimplecanvas.h" #include "qsimplecanvasitem.h" @@ -50,60 +51,6 @@ QT_BEGIN_NAMESPACE -class QSimpleGraphicsItem : public QGraphicsItem -{ -public: - QSimpleGraphicsItem(QSimpleCanvasItem *); - virtual ~QSimpleGraphicsItem(); - - virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - virtual QRectF boundingRect() const; - - QTransform transform; -protected: - virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - virtual bool sceneEvent(QEvent *); - virtual QVariant itemChange(GraphicsItemChange, const QVariant &); - virtual void keyPressEvent(QKeyEvent *event); - virtual void keyReleaseEvent(QKeyEvent *event); - virtual void focusInEvent(QFocusEvent *event); - -private: - friend class QSimpleCanvasItem; - QSimpleCanvasItem *owner; -}; - -class QSimpleCanvasItemData -{ -public: - QSimpleCanvasItemData(); - ~QSimpleCanvasItemData(); - - // 5 bits is all that's needed to store Qt::MouseButtons - int buttons:5; - QSimpleCanvasItem::Flip flip:2; - bool dirty:1; - bool transformValid:1; - bool doNotPaint:1; - bool doNotPaintChildren:1; - - qreal x; - qreal y; - qreal z; - float visible; - - QSimpleCanvas::Matrix *transformUser; - QSimpleCanvas::Matrix transformActive; - int transformVersion; - - float activeOpacity; - - QRect lastPaintRect; -}; - class QSimpleCanvasItemDebuggerStatus : public QmlDebuggerStatus { public: @@ -121,7 +68,7 @@ public: }; class QGraphicsQSimpleCanvasItem; -class QSimpleCanvasItemPrivate : public QObjectPrivate +class QSimpleCanvasItemPrivate : public QGraphicsItemPrivate { Q_DECLARE_PUBLIC(QSimpleCanvasItem) public: @@ -131,9 +78,8 @@ public: origin(QSimpleCanvasItem::TopLeft), options(QSimpleCanvasItem::NoOption), focusable(false), wantsActiveFocusPanelPendingCanvas(false), hasBeenActiveFocusPanel(false), - hasFocus(false), hasActiveFocus(false), needsZOrder(false), - widthValid(false), heightValid(false), width(0), height(0), paintmargin(0), scale(1), - graphicsItem(0), data_ptr(0) + hasFocus(false), hasActiveFocus(false), + widthValid(false), heightValid(false), width(0), height(0), paintmargin(0), scale(1) { } @@ -156,7 +102,6 @@ public: bool hasBeenActiveFocusPanel:1; bool hasFocus:1; bool hasActiveFocus:1; - bool needsZOrder:1; bool widthValid:1; bool heightValid:1; @@ -168,39 +113,16 @@ public: qreal paintmargin; qreal scale; - QSimpleGraphicsItem *graphicsItem; - inline QSimpleCanvasItemData *data() const { - if (!data_ptr) data_ptr = new QSimpleCanvasItemData; - return data_ptr; - } - mutable QSimpleCanvasItemData *data_ptr; + QTransform transform; void gvRemoveMouseFilter(); void gvAddMouseFilter(); void canvasChanged(QSimpleCanvas *newCanvas, QSimpleCanvas *oldCanvas); - void freshenTransforms() const; - - QPointF adjustFrom(const QPointF &) const; - QRectF adjustFrom(const QRectF &) const; - QPointF adjustTo(const QPointF &) const; - QRectF adjustTo(const QRectF &) const; - QPointF transformOrigin() const; void setParentInternal(QSimpleCanvasItem *); - void convertToGraphicsItem(QGraphicsItem * = 0); - - void paint(QPainter &); - void paintChild(QPainter &, QSimpleCanvasItem *); - QRect setupPainting(int version, const QRect &bounding); - - QSimpleCanvasItem *nextOpaque; - - void zOrderChildren(); - bool freshenNeeded() const; - void doFreshenTransforms() const; // Debugging int dump(int); diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp index 09d6178..d25b679 100644 --- a/src/declarative/fx/qfxanchors.cpp +++ b/src/declarative/fx/qfxanchors.cpp @@ -223,7 +223,7 @@ void QFxAnchorsPrivate::addDepend(QFxItem *item) if (!item) return; QFxItemPrivate *p = - static_cast<QFxItemPrivate *>(QObjectPrivate::get(item)); + static_cast<QFxItemPrivate *>(QGraphicsItemPrivate::get(item)); p->dependantAnchors.append(q); } @@ -233,7 +233,7 @@ void QFxAnchorsPrivate::remDepend(QFxItem *item) if (!item) return; QFxItemPrivate *p = - static_cast<QFxItemPrivate *>(QObjectPrivate::get(item)); + static_cast<QFxItemPrivate *>(QGraphicsItemPrivate::get(item)); p->dependantAnchors.removeAll(q); } diff --git a/src/declarative/fx/qfxanimatedimageitem.h b/src/declarative/fx/qfxanimatedimageitem.h index 5d115d7..8ef2b1c 100644 --- a/src/declarative/fx/qfxanimatedimageitem.h +++ b/src/declarative/fx/qfxanimatedimageitem.h @@ -88,7 +88,7 @@ protected: private: Q_DISABLE_COPY(QFxAnimatedImageItem) - Q_DECLARE_PRIVATE(QFxAnimatedImageItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxAnimatedImageItem) }; QML_DECLARE_TYPE(QFxAnimatedImageItem) diff --git a/src/declarative/fx/qfxcomponentinstance.h b/src/declarative/fx/qfxcomponentinstance.h index e749272..97b8b7b 100644 --- a/src/declarative/fx/qfxcomponentinstance.h +++ b/src/declarative/fx/qfxcomponentinstance.h @@ -78,7 +78,7 @@ protected: QFxComponentInstance(QFxComponentInstancePrivate &dd, QFxItem *parent); private: - Q_DECLARE_PRIVATE(QFxComponentInstance) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxComponentInstance) }; QML_DECLARE_TYPE(QFxComponentInstance) diff --git a/src/declarative/fx/qfxcontentwrapper.h b/src/declarative/fx/qfxcontentwrapper.h index d8fe0b8..f1678d0 100644 --- a/src/declarative/fx/qfxcontentwrapper.h +++ b/src/declarative/fx/qfxcontentwrapper.h @@ -71,7 +71,7 @@ protected: QFxContentWrapper(QFxContentWrapperPrivate &dd, QFxItem *parent); private: - Q_DECLARE_PRIVATE(QFxContentWrapper) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxContentWrapper) }; QML_DECLARE_TYPE(QFxContentWrapper) diff --git a/src/declarative/fx/qfxflickable.h b/src/declarative/fx/qfxflickable.h index 77aaf50..71e409e 100644 --- a/src/declarative/fx/qfxflickable.h +++ b/src/declarative/fx/qfxflickable.h @@ -184,7 +184,7 @@ protected: private: Q_DISABLE_COPY(QFxFlickable) - Q_DECLARE_PRIVATE(QFxFlickable) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxFlickable) }; QML_DECLARE_TYPE(QFxFlickable) diff --git a/src/declarative/fx/qfxflipable.cpp b/src/declarative/fx/qfxflipable.cpp index 0957c2f..d6222f3 100644 --- a/src/declarative/fx/qfxflipable.cpp +++ b/src/declarative/fx/qfxflipable.cpp @@ -219,7 +219,7 @@ void QFxFlipablePrivate::setBackTransform() p3 = axisRotation.transform().map(p3); axisRotation.setAngle(rotation); - QSimpleCanvas::Matrix mat; + QTransform mat; mat.translate(back->width()/2,back->height()/2); if (back->width() && p1.x() >= p2.x()) mat.rotate(180, Qt::YAxis); @@ -284,7 +284,7 @@ QFxFlipable::Side QFxFlipable::side() const //in some cases the user may want to specify a more complex transformation. //in that case, we still allow the generic use of transform. //(the logic here should be kept in sync with setBackTransform and setRotation) -void QFxFlipable::transformChanged(const QSimpleCanvas::Matrix &trans) +void QFxFlipable::transformChanged(const QTransform &trans) { Q_D(QFxFlipable); QPointF p1(0, 0); @@ -308,7 +308,7 @@ void QFxFlipable::transformChanged(const QSimpleCanvas::Matrix &trans) if (newSide != d->current) { d->current = newSide; if (d->current==Back) { - QSimpleCanvas::Matrix mat; + QTransform mat; mat.translate(d->back->width()/2,d->back->height()/2); if (d->back->width() && p1.x() >= p2.x()) mat.rotate(180, Qt::YAxis); diff --git a/src/declarative/fx/qfxflipable.h b/src/declarative/fx/qfxflipable.h index f00e023..5a6271b 100644 --- a/src/declarative/fx/qfxflipable.h +++ b/src/declarative/fx/qfxflipable.h @@ -84,7 +84,7 @@ public: Side side() const; protected: - virtual void transformChanged(const QSimpleCanvas::Matrix &); + virtual void transformChanged(const QTransform &); Q_SIGNALS: void sideChanged(); @@ -92,7 +92,7 @@ Q_SIGNALS: private: Q_PRIVATE_SLOT(d_func(), void _q_updateAxis()) Q_DISABLE_COPY(QFxFlipable) - Q_DECLARE_PRIVATE(QFxFlipable) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxFlipable) }; QML_DECLARE_TYPE(QFxFlipable) diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h index 1514451..954f4eb 100644 --- a/src/declarative/fx/qfxgridview.h +++ b/src/declarative/fx/qfxgridview.h @@ -54,7 +54,7 @@ class QFxGridViewPrivate; class Q_DECLARATIVE_EXPORT QFxGridView : public QFxFlickable { Q_OBJECT - Q_DECLARE_PRIVATE(QFxGridView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxGridView) Q_PROPERTY(QVariant model READ model WRITE setModel) Q_CLASSINFO("DefaultProperty", "delegate") diff --git a/src/declarative/fx/qfximage.h b/src/declarative/fx/qfximage.h index 039334a..e2205e5 100644 --- a/src/declarative/fx/qfximage.h +++ b/src/declarative/fx/qfximage.h @@ -111,7 +111,7 @@ private Q_SLOTS: private: Q_DISABLE_COPY(QFxImage) - Q_DECLARE_PRIVATE(QFxImage) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxImage) void setGridScaledImage(const QFxGridScaledImage& sci); }; QML_DECLARE_TYPE(QFxImage) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index b4de109..7938c63 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -1070,52 +1070,6 @@ void QFxItem::geometryChanged(const QRectF &newGeometry, } } -/*! - \qmlproperty bool Item::flipVertically - \qmlproperty bool Item::flipHorizontally - - When set, the item will be displayed flipped horizontally or vertically - about its center. - */ - -/*! - \property QFxItem::flipVertically - - When set, the item will be displayed flipped horizontally or vertically - about its center. - */ -bool QFxItem::flipVertically() const -{ - return flip() & VerticalFlip; -} - -void QFxItem::setFlipVertically(bool v) -{ - if (v) - setFlip((QSimpleCanvasItem::Flip)(flip() | VerticalFlip)); - else - setFlip((QSimpleCanvasItem::Flip)(flip() & ~VerticalFlip)); -} - -/*! - \property QFxItem::flipHorizontally - - When set, the item will be displayed flipped horizontally or vertically - about its center. - */ -bool QFxItem::flipHorizontally() const -{ - return flip() & HorizontalFlip; -} - -void QFxItem::setFlipHorizontally(bool v) -{ - if (v) - setFlip((QSimpleCanvasItem::Flip)(flip() | HorizontalFlip)); - else - setFlip((QSimpleCanvasItem::Flip)(flip() & ~HorizontalFlip)); -} - /*! \fn void QFxItem::keyPress(QFxKeyEvent *event) This signal is emitted by keyPressEvent() for the \a event. */ @@ -2035,7 +1989,7 @@ void QFxItem::reparentItems() void QFxItem::updateTransform() { Q_D(QFxItem); - QSimpleCanvas::Matrix trans; + QTransform trans; for (int ii = d->_transform.count() - 1; ii >= 0; --ii) { QFxTransform *a = d->_transform.at(ii); if (!a->isIdentity()) @@ -2049,7 +2003,7 @@ void QFxItem::updateTransform() /*! \internal */ -void QFxItem::transformChanged(const QSimpleCanvas::Matrix &) +void QFxItem::transformChanged(const QTransform &) { } diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index 3188516..ef69fd3 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -117,8 +117,6 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QSimpleCanvasItem, public QmlParserS Q_PROPERTY(qreal y READ y WRITE setY NOTIFY topChanged) Q_PROPERTY(qreal z READ z WRITE setZ) Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged) - Q_PROPERTY(bool flipVertically READ flipVertically WRITE setFlipVertically) - Q_PROPERTY(bool flipHorizontally READ flipHorizontally WRITE setFlipHorizontally) Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) Q_PROPERTY(int baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged) Q_PROPERTY(QFxAnchorLine left READ left) @@ -173,11 +171,6 @@ public: QUrl qml() const; void setQml(const QUrl &); - bool flipVertically() const; - void setFlipVertically(bool); - bool flipHorizontally() const; - void setFlipHorizontally(bool); - int baselineOffset() const; void setBaselineOffset(int); @@ -231,7 +224,7 @@ Q_SIGNALS: void newChildCreated(const QString &url, QScriptValue); protected: - virtual void transformChanged(const QSimpleCanvas::Matrix &); + virtual void transformChanged(const QTransform &); virtual void classBegin(); virtual void classComplete(); virtual void componentComplete(); @@ -264,7 +257,7 @@ private: friend class QmlStatePrivate; friend class QFxAnchors; Q_DISABLE_COPY(QFxItem) - Q_DECLARE_PRIVATE(QFxItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxItem) }; QML_DECLARE_TYPE(QFxItem) diff --git a/src/declarative/fx/qfxlayouts.h b/src/declarative/fx/qfxlayouts.h index b119d6f..abf4bb2 100644 --- a/src/declarative/fx/qfxlayouts.h +++ b/src/declarative/fx/qfxlayouts.h @@ -115,7 +115,7 @@ private: void applyTransition(const QList<QPair<QString, QVariant> >& changes, QFxItem* target, QmlTransition* transition); Q_DISABLE_COPY(QFxBaseLayout) - Q_DECLARE_PRIVATE(QFxBaseLayout) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxBaseLayout) }; class Q_DECLARATIVE_EXPORT QFxVerticalLayout : public QFxBaseLayout diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index 5dfb0e4..7fa2050 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -55,7 +55,7 @@ class QFxListViewPrivate; class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable { Q_OBJECT - Q_DECLARE_PRIVATE(QFxListView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxListView) Q_ENUMS(CurrentItemPositioning) Q_PROPERTY(QVariant model READ model WRITE setModel) diff --git a/src/declarative/fx/qfxmouseregion.h b/src/declarative/fx/qfxmouseregion.h index d7db1dc..d8586e9 100644 --- a/src/declarative/fx/qfxmouseregion.h +++ b/src/declarative/fx/qfxmouseregion.h @@ -152,7 +152,7 @@ protected: private: Q_DISABLE_COPY(QFxMouseRegion) - Q_DECLARE_PRIVATE(QFxMouseRegion) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxMouseRegion) }; QML_DECLARE_TYPE(QFxMouseRegion) diff --git a/src/declarative/fx/qfxpainteditem.h b/src/declarative/fx/qfxpainteditem.h index ed254ce..35f8f89 100644 --- a/src/declarative/fx/qfxpainteditem.h +++ b/src/declarative/fx/qfxpainteditem.h @@ -82,7 +82,7 @@ protected Q_SLOTS: private: void init(); Q_DISABLE_COPY(QFxPaintedItem) - Q_DECLARE_PRIVATE(QFxPaintedItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxPaintedItem) }; QML_DECLARE_TYPE(QFxPaintedItem) diff --git a/src/declarative/fx/qfxparticles.h b/src/declarative/fx/qfxparticles.h index a0373d7..bb84df2 100644 --- a/src/declarative/fx/qfxparticles.h +++ b/src/declarative/fx/qfxparticles.h @@ -221,7 +221,7 @@ private Q_SLOTS: private: Q_DISABLE_COPY(QFxParticles) - Q_DECLARE_PRIVATE(QFxParticles) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxParticles) }; QML_DECLARE_TYPE(QFxParticles) diff --git a/src/declarative/fx/qfxpathview.h b/src/declarative/fx/qfxpathview.h index cbdafa8..a40f1f2 100644 --- a/src/declarative/fx/qfxpathview.h +++ b/src/declarative/fx/qfxpathview.h @@ -125,7 +125,7 @@ private: friend class QFxPathViewAttached; static QHash<QObject*, QObject*> attachedProperties; Q_DISABLE_COPY(QFxPathView) - Q_DECLARE_PRIVATE(QFxPathView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxPathView) }; QML_DECLARE_TYPE(QFxPathView) diff --git a/src/declarative/fx/qfxrect.h b/src/declarative/fx/qfxrect.h index d232328..eee1f86 100644 --- a/src/declarative/fx/qfxrect.h +++ b/src/declarative/fx/qfxrect.h @@ -176,7 +176,7 @@ protected: private: Q_DISABLE_COPY(QFxRect) - Q_DECLARE_PRIVATE(QFxRect) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxRect) }; QML_DECLARE_TYPE(QFxRect) diff --git a/src/declarative/fx/qfxrepeater.cpp b/src/declarative/fx/qfxrepeater.cpp index 0211ebb..a6d68cb 100644 --- a/src/declarative/fx/qfxrepeater.cpp +++ b/src/declarative/fx/qfxrepeater.cpp @@ -62,7 +62,7 @@ QFxItem *QFxRepeaterPrivate::addItem(QmlContext *ctxt, QFxItem *lastItem) QFxItem *item = qobject_cast<QFxItem *>(nobj); if (item) { item->setParent(q->itemParent()); - item->stackUnder(lastItem); +// item->stackUnder(lastItem); deletables << nobj; } else { delete nobj; diff --git a/src/declarative/fx/qfxrepeater.h b/src/declarative/fx/qfxrepeater.h index c1b194a..17ffa57 100644 --- a/src/declarative/fx/qfxrepeater.h +++ b/src/declarative/fx/qfxrepeater.h @@ -78,7 +78,7 @@ protected: private: Q_DISABLE_COPY(QFxRepeater) - Q_DECLARE_PRIVATE(QFxRepeater) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxRepeater) }; QML_DECLARE_TYPE(QFxRepeater) diff --git a/src/declarative/fx/qfxtext.h b/src/declarative/fx/qfxtext.h index 35e8b03..83e7299 100644 --- a/src/declarative/fx/qfxtext.h +++ b/src/declarative/fx/qfxtext.h @@ -138,7 +138,7 @@ protected: private: Q_DISABLE_COPY(QFxText) - Q_DECLARE_PRIVATE(QFxText) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxText) }; QML_DECLARE_TYPE(QFxText) diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h index b761a1b..920bd04 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -200,7 +200,7 @@ private: friend class QmlFont; Q_DISABLE_COPY(QFxTextEdit) - Q_DECLARE_PRIVATE(QFxTextEdit) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxTextEdit) }; QML_DECLARE_TYPE(QFxTextEdit) diff --git a/src/declarative/fx/qfxtransform.cpp b/src/declarative/fx/qfxtransform.cpp index 8d9084f..8973295 100644 --- a/src/declarative/fx/qfxtransform.cpp +++ b/src/declarative/fx/qfxtransform.cpp @@ -71,9 +71,9 @@ bool QFxTransform::isIdentity() const return true; } -QSimpleCanvas::Matrix QFxTransform::transform() const +QTransform QFxTransform::transform() const { - return QSimpleCanvas::Matrix(); + return QTransform(); } void QFxTransform::update() diff --git a/src/declarative/fx/qfxtransform.h b/src/declarative/fx/qfxtransform.h index 0a17917..a549b30 100644 --- a/src/declarative/fx/qfxtransform.h +++ b/src/declarative/fx/qfxtransform.h @@ -62,7 +62,7 @@ public: void update(); virtual bool isIdentity() const; - virtual QSimpleCanvas::Matrix transform() const; + virtual QTransform transform() const; }; QML_DECLARE_TYPE(QFxTransform) @@ -127,7 +127,7 @@ public: void setAngle(qreal); virtual bool isIdentity() const; - virtual QSimpleCanvas::Matrix transform() const; + virtual QTransform transform() const; Q_SIGNALS: void angleChanged(); @@ -140,7 +140,7 @@ private: qreal _angle; mutable bool _dirty; - mutable QSimpleCanvas::Matrix _transform; + mutable QTransform _transform; }; QML_DECLARE_TYPE(QFxRotation) @@ -160,7 +160,7 @@ public: void setAngle(qreal); virtual bool isIdentity() const; - virtual QSimpleCanvas::Matrix transform() const; + virtual QTransform transform() const; private Q_SLOTS: void update(); @@ -169,7 +169,7 @@ private: qreal _angle; mutable bool _dirty; - mutable QSimpleCanvas::Matrix _transform; + mutable QTransform _transform; }; QML_DECLARE_TYPE(QFxRotation3D) @@ -189,7 +189,7 @@ public: void setDistance(qreal); virtual bool isIdentity() const; - virtual QSimpleCanvas::Matrix transform() const; + virtual QTransform transform() const; private Q_SLOTS: void update(); @@ -198,7 +198,7 @@ private: qreal _distance; mutable bool _dirty; - mutable QSimpleCanvas::Matrix _transform; + mutable QTransform _transform; }; QML_DECLARE_TYPE(QFxTranslation3D) @@ -296,7 +296,7 @@ public: void setbottomRight_x(qreal); virtual bool isIdentity() const; - virtual QSimpleCanvas::Matrix transform() const; + virtual QTransform transform() const; private: QPointF p; diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h index f30fd0d..115bddc 100644 --- a/src/declarative/fx/qfxwebview.h +++ b/src/declarative/fx/qfxwebview.h @@ -205,7 +205,7 @@ private: void init(); virtual void componentComplete(); Q_DISABLE_COPY(QFxWebView) - Q_DECLARE_PRIVATE(QFxWebView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxWebView) }; QML_DECLARE_TYPE(QFxWebView) |