From 5c9f8288cf642a51bdce46f2833b37e4f94d43d9 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 31 Jul 2009 13:33:24 +1000 Subject: Add baselineOffset to anchors. --- src/declarative/fx/qfxanchors.cpp | 18 +++++++++++++++++- src/declarative/fx/qfxanchors.h | 5 +++++ src/declarative/fx/qfxanchors_p.h | 3 ++- src/declarative/fx/qfxitem.cpp | 3 ++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp index a22aeb3..1595f57 100644 --- a/src/declarative/fx/qfxanchors.cpp +++ b/src/declarative/fx/qfxanchors.cpp @@ -468,7 +468,7 @@ void QFxAnchorsPrivate::updateVerticalAnchors() } else if (usedAnchors & QFxAnchors::HasBaselineAnchor) { //Handle baseline if (baseline.item->parentItem() == item->parentItem()) { - setItemY(position(baseline.item, baseline.anchorLine) - item->baselineOffset()); + setItemY(position(baseline.item, baseline.anchorLine) - item->baselineOffset() + baselineOffset); } } --updatingVerticalAnchor; @@ -872,6 +872,22 @@ void QFxAnchors::setVerticalCenterOffset(qreal offset) emit verticalCenterOffsetChanged(); } +qreal QFxAnchors::baselineOffset() const +{ + Q_D(const QFxAnchors); + return d->baselineOffset; +} + +void QFxAnchors::setBaselineOffset(qreal offset) +{ + Q_D(QFxAnchors); + if (d->baselineOffset == offset) + return; + d->baselineOffset = offset; + d->updateVerticalAnchors(); + emit baselineOffsetChanged(); +} + QFxAnchors::UsedAnchors QFxAnchors::usedAnchors() const { Q_D(const QFxAnchors); diff --git a/src/declarative/fx/qfxanchors.h b/src/declarative/fx/qfxanchors.h index 7ff4c35..70217d6 100644 --- a/src/declarative/fx/qfxanchors.h +++ b/src/declarative/fx/qfxanchors.h @@ -71,6 +71,7 @@ class Q_DECLARATIVE_EXPORT QFxAnchors : public QObject Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged()) + Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged()) Q_PROPERTY(QFxItem *fill READ fill WRITE setFill) Q_PROPERTY(QFxItem *centerIn READ centerIn WRITE setCenterIn) @@ -137,6 +138,9 @@ public: qreal verticalCenterOffset() const; void setVerticalCenterOffset(qreal); + qreal baselineOffset() const; + void setBaselineOffset(qreal); + QFxItem *fill() const; void setFill(QFxItem *); @@ -157,6 +161,7 @@ Q_SIGNALS: void bottomMarginChanged(); void verticalCenterOffsetChanged(); void horizontalCenterOffsetChanged(); + void baselineOffsetChanged(); private: friend class QFxItem; diff --git a/src/declarative/fx/qfxanchors_p.h b/src/declarative/fx/qfxanchors_p.h index 1827324..ca42966 100644 --- a/src/declarative/fx/qfxanchors_p.h +++ b/src/declarative/fx/qfxanchors_p.h @@ -66,7 +66,7 @@ public: : updatingMe(false), updatingHorizontalAnchor(0), updatingVerticalAnchor(0), item(0), usedAnchors(0), fill(0), centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), - bottomMargin(0), vCenterOffset(0), hCenterOffset(0), + bottomMargin(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0), componentComplete(true) { } @@ -126,6 +126,7 @@ public: qreal bottomMargin; qreal vCenterOffset; qreal hCenterOffset; + qreal baselineOffset; bool componentComplete; }; diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 617e479..71d4ce2 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -1087,13 +1087,14 @@ QFxAnchorLine QFxItem::baseline() const \qmlproperty real Item::anchors.rightMargin \qmlproperty real Item::anchors.horizontalCenterOffset \qmlproperty real Item::anchors.verticalCenterOffset + \qmlproperty real Item::anchors.baselineOffset Anchors provide a way to position an item by specifying its relationship with other items. Margins apply to top, bottom, left, right, and fill anchors. - Offsets apply for horizontal and vertical center anchors. + Offsets apply for horizontal center, vertical center, and baseline anchors. \table \row -- cgit v0.12 From fa75cbdd3e1ae7b7d10d582498ae7e1d535f82ec Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 31 Jul 2009 13:59:29 +1000 Subject: Remove paintContents. --- doc/src/declarative/cppitem.qdoc | 2 ++ src/declarative/extra/qfxparticles.cpp | 10 +++---- src/declarative/extra/qfxparticles.h | 2 +- src/declarative/fx/qfximage.cpp | 48 +++++++++++++++++----------------- src/declarative/fx/qfximage.h | 2 +- src/declarative/fx/qfxitem.cpp | 5 ---- src/declarative/fx/qfxitem.h | 3 +-- src/declarative/fx/qfxpainteditem.cpp | 20 +++++++------- src/declarative/fx/qfxpainteditem.h | 4 +-- src/declarative/fx/qfxrect.cpp | 6 ++--- src/declarative/fx/qfxrect.h | 2 +- src/declarative/fx/qfxtext.cpp | 20 +++++++------- src/declarative/fx/qfxtext.h | 2 +- 13 files changed, 61 insertions(+), 65 deletions(-) diff --git a/doc/src/declarative/cppitem.qdoc b/doc/src/declarative/cppitem.qdoc index 97aae67..794f67a 100644 --- a/doc/src/declarative/cppitem.qdoc +++ b/doc/src/declarative/cppitem.qdoc @@ -99,6 +99,8 @@ a simple cached-image painting model. \section2 Reimplementing paint functions +\warning This section is out of date. Use the normal QGraphicsItem::paint function. + Two alternative painters are available, offering different levels of performance and functionality: QPainter, GLPainter. diff --git a/src/declarative/extra/qfxparticles.cpp b/src/declarative/extra/qfxparticles.cpp index 0f22165..6d41434 100644 --- a/src/declarative/extra/qfxparticles.cpp +++ b/src/declarative/extra/qfxparticles.cpp @@ -347,7 +347,7 @@ public: maxX = minX = maxY = minY = 0; } - void paintContents(QPainter &p); + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); void updateSize(); @@ -1067,13 +1067,13 @@ void QFxParticlesPainter::updateSize() setY(myY); } -void QFxParticles::paintContents(QPainter &p) +void QFxParticles::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_UNUSED(p); //painting is done by the ParticlesPainter, so it can have the right size } -void QFxParticlesPainter::paintContents(QPainter &p) +void QFxParticlesPainter::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { if (d->image.isNull()) return; @@ -1083,8 +1083,8 @@ void QFxParticlesPainter::paintContents(QPainter &p) for (int i = 0; i < d->particles.count(); ++i) { const QFxParticle &particle = d->particles.at(i); - p.setOpacity(particle.opacity); - p.drawPixmap(particle.x - myX, particle.y - myY, d->image); + p->setOpacity(particle.opacity); + p->drawPixmap(particle.x - myX, particle.y - myY, d->image); } } diff --git a/src/declarative/extra/qfxparticles.h b/src/declarative/extra/qfxparticles.h index 2574f7f..bde6ec6 100644 --- a/src/declarative/extra/qfxparticles.h +++ b/src/declarative/extra/qfxparticles.h @@ -203,7 +203,7 @@ public: QFxParticleMotion *motion() const; void setMotion(QFxParticleMotion *); - void paintContents(QPainter &p); + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); protected: virtual void componentComplete(); diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index f1be4a4..15dc620 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -270,22 +270,22 @@ void QFxImage::setSmoothTransform(bool s) update(); } -void QFxImage::paintContents(QPainter &p) +void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_D(QFxImage); if (d->pix.isNull()) return; - bool oldAA = p.testRenderHint(QPainter::Antialiasing); - bool oldSmooth = p.testRenderHint(QPainter::SmoothPixmapTransform); + bool oldAA = p->testRenderHint(QPainter::Antialiasing); + bool oldSmooth = p->testRenderHint(QPainter::SmoothPixmapTransform); if (d->smooth) - p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); + p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); QPixmap pix = d->pix; if (d->tiled) { - p.save(); - p.setClipRect(0, 0, width(), height(), Qt::IntersectClip); + p->save(); + p->setClipRect(0, 0, width(), height(), Qt::IntersectClip); QRect me = QRect(0, 0, width(), height()); int pw = pix.width(); @@ -295,13 +295,13 @@ void QFxImage::paintContents(QPainter &p) while(yy < height()) { int xx = 0; while(xx < width()) { - p.drawPixmap(xx, yy, pix); + p->drawPixmap(xx, yy, pix); xx += pw; } yy += ph; } - p.restore(); + p->restore(); } else if (!d->scaleGrid || d->scaleGrid->isNull()) { if (width() != pix.width() || height() != pix.height()) { qreal widthScale = width() / qreal(pix.width()); @@ -320,12 +320,12 @@ void QFxImage::paintContents(QPainter &p) } scale.scale(widthScale, heightScale); - QTransform old = p.transform(); - p.setWorldTransform(scale * old); - p.drawPixmap(0, 0, pix); - p.setWorldTransform(old); + QTransform old = p->transform(); + p->setWorldTransform(scale * old); + p->drawPixmap(0, 0, pix); + p->setWorldTransform(old); } else { - p.drawPixmap(0, 0, pix); + p->drawPixmap(0, 0, pix); } } else { int sgl = d->scaleGrid->left(); @@ -345,46 +345,46 @@ void QFxImage::paintContents(QPainter &p) // Upper left if (sgt && sgl) - p.drawPixmap(QRect(0, 0, sgl, sgt), pix, QRect(0, 0, sgl, sgt)); + 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, + 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, + 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, + 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), + 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, + 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, + 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, + 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, + p->drawPixmap(QPoint(w-sgr, h - sgb), pix, QRect(pix.width()-sgr, pix.height() - sgb, sgr, sgb)); } if (d->smooth) { - p.setRenderHint(QPainter::Antialiasing, oldAA); - p.setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); + p->setRenderHint(QPainter::Antialiasing, oldAA); + p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); } } diff --git a/src/declarative/fx/qfximage.h b/src/declarative/fx/qfximage.h index 4b6e700..633289f 100644 --- a/src/declarative/fx/qfximage.h +++ b/src/declarative/fx/qfximage.h @@ -92,7 +92,7 @@ public: QUrl source() const; virtual void setSource(const QUrl &url); - void paintContents(QPainter &painter); + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); Q_SIGNALS: void sourceChanged(const QUrl &); diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 71d4ce2..a9c406d 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -1672,10 +1672,6 @@ QRectF QFxItem::boundingRect() const return QRectF(0, 0, d->width, d->height); } -void QFxItem::paintContents(QPainter &) -{ -} - /*! \enum QFxItem::TransformOrigin @@ -1906,7 +1902,6 @@ void QFxItem::setOptions(Options options, bool set) void QFxItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { - paintContents(*p); } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index 2050ab9..d33c07e 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -206,7 +206,7 @@ public: void setTransformOrigin(TransformOrigin); QRectF boundingRect() const; - virtual void paintContents(QPainter &); + virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); virtual bool hasFocus() const; void setFocus(bool); @@ -227,7 +227,6 @@ Q_SIGNALS: protected: bool isComponentComplete() const; - virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); virtual void childrenChanged(); virtual bool sceneEventFilter(QGraphicsItem *, QEvent *); virtual bool sceneEvent(QEvent *); diff --git a/src/declarative/fx/qfxpainteditem.cpp b/src/declarative/fx/qfxpainteditem.cpp index a4055eb..2bd17bc 100644 --- a/src/declarative/fx/qfxpainteditem.cpp +++ b/src/declarative/fx/qfxpainteditem.cpp @@ -209,20 +209,20 @@ void QFxPaintedItem::init() /*! \reimp */ -void QFxPaintedItem::paintContents(QPainter &p) +void QFxPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_D(QFxPaintedItem); const QRect content(QPoint(0,0),d->contentsSize); if (content.width() <= 0 || content.height() <= 0) return; - bool oldAntiAliasing = p.testRenderHint(QPainter::Antialiasing); - bool oldSmoothPixmap = p.testRenderHint(QPainter::SmoothPixmapTransform); + bool oldAntiAliasing = p->testRenderHint(QPainter::Antialiasing); + bool oldSmoothPixmap = p->testRenderHint(QPainter::SmoothPixmapTransform); if (oldAntiAliasing) - p.setRenderHints(QPainter::Antialiasing, false); // cannot stitch properly otherwise + p->setRenderHints(QPainter::Antialiasing, false); // cannot stitch properly otherwise if (d->smooth) - p.setRenderHints(QPainter::SmoothPixmapTransform, true); - QRectF clipf = p.clipRegion().boundingRect(); + p->setRenderHints(QPainter::SmoothPixmapTransform, true); + QRectF clipf = p->clipRegion().boundingRect(); if (clipf.isEmpty()) clipf = mapToScene(content).boundingRect(); // ### Inefficient: Maps toScene and then fromScene else @@ -239,7 +239,7 @@ void QFxPaintedItem::paintContents(QPainter &p) QRect area = d->imagecache[i]->area; if (topaint.contains(area)) { QRectF target(area.x(), area.y(), area.width(), area.height()); - p.drawPixmap(target.toRect(), d->imagecache[i]->image); + p->drawPixmap(target.toRect(), d->imagecache[i]->image); topaint -= area; d->imagecache[i]->age=0; } else { @@ -284,14 +284,14 @@ void QFxPaintedItem::paintContents(QPainter &p) newitem->image = img; d->imagecache.append(newitem); QRectF target(r.x(), r.y(), r.width(), r.height()); - p.drawPixmap(target.toRect(), newitem->image); + p->drawPixmap(target.toRect(), newitem->image); } } if (oldAntiAliasing) - p.setRenderHints(QPainter::Antialiasing, oldAntiAliasing); + p->setRenderHints(QPainter::Antialiasing, oldAntiAliasing); if (d->smooth) - p.setRenderHints(QPainter::SmoothPixmapTransform, oldSmoothPixmap); + p->setRenderHints(QPainter::SmoothPixmapTransform, oldSmoothPixmap); } /*! diff --git a/src/declarative/fx/qfxpainteditem.h b/src/declarative/fx/qfxpainteditem.h index e74ead0..51e155e 100644 --- a/src/declarative/fx/qfxpainteditem.h +++ b/src/declarative/fx/qfxpainteditem.h @@ -66,8 +66,6 @@ public: QFxPaintedItem(QFxItem *parent=0); ~QFxPaintedItem(); - void paintContents(QPainter &painter); - bool isSmooth() const; QSize contentsSize() const; @@ -80,6 +78,8 @@ public: QColor fillColor() const; void setFillColor(const QColor&); + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + protected: QFxPaintedItem(QFxPaintedItemPrivate &dd, QFxItem *parent); diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp index 955eb61..0722d26 100644 --- a/src/declarative/fx/qfxrect.cpp +++ b/src/declarative/fx/qfxrect.cpp @@ -471,14 +471,14 @@ void QFxRect::generateBorderedRect() } } -void QFxRect::paintContents(QPainter &p) +void QFxRect::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_D(QFxRect); if (d->radius > 0 || (d->pen && d->pen->isValid()) || (d->gradient && d->gradient->gradient()) ) - drawRect(p); + drawRect(*p); else - p.fillRect(QRect(0, 0, width(), height()), d->getColor()); + p->fillRect(QRect(0, 0, width(), height()), d->getColor()); } void QFxRect::drawRect(QPainter &p) diff --git a/src/declarative/fx/qfxrect.h b/src/declarative/fx/qfxrect.h index 98f5e67..fb96217 100644 --- a/src/declarative/fx/qfxrect.h +++ b/src/declarative/fx/qfxrect.h @@ -159,7 +159,7 @@ public: QRectF boundingRect() const; - void paintContents(QPainter &painter); + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); private Q_SLOTS: void doUpdate(); diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index cb8af40..1313dca 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -765,17 +765,17 @@ void QFxText::setSmoothTransform(bool s) update(); } -void QFxText::paintContents(QPainter &p) +void QFxText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_D(QFxText); d->checkImgCache(); if (d->imgCache.isNull()) return; - bool oldAA = p.testRenderHint(QPainter::Antialiasing); - bool oldSmooth = p.testRenderHint(QPainter::SmoothPixmapTransform); + bool oldAA = p->testRenderHint(QPainter::Antialiasing); + bool oldSmooth = p->testRenderHint(QPainter::SmoothPixmapTransform); if (d->smooth) - p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); + p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); int w = width(); int h = height(); @@ -811,16 +811,16 @@ void QFxText::paintContents(QPainter &p) d->imgCache.height() > height()); if (needClip) { - p.save(); - p.setClipRect(boundingRect()); + p->save(); + p->setClipRect(boundingRect()); } - p.drawPixmap(x, y, d->imgCache); + p->drawPixmap(x, y, d->imgCache); if (needClip) - p.restore(); + p->restore(); if (d->smooth) { - p.setRenderHint(QPainter::Antialiasing, oldAA); - p.setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); + p->setRenderHint(QPainter::Antialiasing, oldAA); + p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); } } diff --git a/src/declarative/fx/qfxtext.h b/src/declarative/fx/qfxtext.h index a02b76b..41362ae 100644 --- a/src/declarative/fx/qfxtext.h +++ b/src/declarative/fx/qfxtext.h @@ -125,7 +125,7 @@ public: bool smoothTransform() const; void setSmoothTransform(bool); - void paintContents(QPainter &p); + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); virtual void componentComplete(); -- cgit v0.12 From c3c67a1081f992525cca03430b7cba78915409b3 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Fri, 31 Jul 2009 05:23:36 +0200 Subject: Remove unused include. Reviewed-by: TrustMe --- src/gui/graphicsview/qgraphicsitem.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index c9a581c..6ceca56 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -48,7 +48,6 @@ #include #include #include -#include class tst_QGraphicsItem; -- cgit v0.12 From e5e13c7b3e609006579331b01caf99d680b9f552 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Fri, 31 Jul 2009 06:36:07 +0200 Subject: Fix compile breakage in 638fd43 by using QGraphicsItem::focusProxy(). Turned out this functionality was in used after all, although calling "git grep" didn't reveal its usage. Reviewed-by: Michael Brasser --- src/declarative/fx/qfxkeyproxy.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/declarative/fx/qfxkeyproxy.cpp b/src/declarative/fx/qfxkeyproxy.cpp index 85ecc39..b22d686 100644 --- a/src/declarative/fx/qfxkeyproxy.cpp +++ b/src/declarative/fx/qfxkeyproxy.cpp @@ -85,12 +85,20 @@ public: QFxKeyProxyPrivate() : inPress(false), inRelease(false), inIM(false), imeItem(0) {} QList targets; + QGraphicsItem *finalFocusProxy(QGraphicsItem *item) + { + QGraphicsItem *fp; + while ((fp = item->focusProxy())) + item = fp; + return item; + } + //loop detection bool inPress:1; bool inRelease:1; bool inIM:1; - QFxItem *imeItem; + QGraphicsItem *imeItem; }; QFxKeyProxy::QFxKeyProxy(QFxItem *parent) @@ -125,7 +133,7 @@ void QFxKeyProxy::keyPressEvent(QKeyEvent *e) if (!d->inPress) { d->inPress = true; for (int ii = 0; ii < d->targets.count(); ++ii) { - QFxItem *i = qobject_cast(scene()->focusItem(d->targets.at(ii))); + QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); if (i) { scene()->sendEvent(i, e); if (e->isAccepted()) { @@ -145,7 +153,7 @@ void QFxKeyProxy::keyReleaseEvent(QKeyEvent *e) if (!d->inRelease) { d->inRelease = true; for (int ii = 0; ii < d->targets.count(); ++ii) { - QFxItem *i = qobject_cast(scene()->focusItem(d->targets.at(ii))); + QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); if (i) { scene()->sendEvent(i, e); if (e->isAccepted()) { @@ -165,7 +173,7 @@ void QFxKeyProxy::inputMethodEvent(QInputMethodEvent *e) if (!d->inIM) { d->inIM = true; for (int ii = 0; ii < d->targets.count(); ++ii) { - QFxItem *i = qobject_cast(scene()->focusItem(d->targets.at(ii))); + QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); if (i && (i->flags() & ItemAcceptsInputMethod)) { scene()->sendEvent(i, e); if (e->isAccepted()) { @@ -179,20 +187,20 @@ void QFxKeyProxy::inputMethodEvent(QInputMethodEvent *e) } } -class QFxItemAccessor : public QFxItem +class QFxItemAccessor : public QGraphicsItem { public: QVariant doInputMethodQuery(Qt::InputMethodQuery query) const { - return QFxItem::inputMethodQuery(query); + return QGraphicsItem::inputMethodQuery(query); } }; QVariant QFxKeyProxy::inputMethodQuery(Qt::InputMethodQuery query) const { for (int ii = 0; ii < d->targets.count(); ++ii) { - QFxItem *i = qobject_cast(scene()->focusItem(d->targets.at(ii))); + QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii)); if (i && (i->flags() & ItemAcceptsInputMethod) && i == d->imeItem) { //### how robust is i == d->imeItem check? - QVariant v = static_cast(i)->doInputMethodQuery(query); + QVariant v = static_cast(i)->doInputMethodQuery(query); if (v.type() == QVariant::RectF) v = mapRectFromItem(i, v.toRectF()); //### cost? return v; -- cgit v0.12