diff options
author | Jens Bache-Wiig <jbache@trolltech.com> | 2010-09-28 22:41:05 +0200 |
---|---|---|
committer | Jens Bache-Wiig <jbache@trolltech.com> | 2010-09-28 22:41:05 +0200 |
commit | 2d3aa1c2c272ab4e1050daa666c41f5f9e09c5ad (patch) | |
tree | e5132af37ac8277ebcdd413e2f34c933c6c19cc1 /src | |
parent | 347ae0c6b819473f790db3be960afc6e734eb92d (diff) |
Fix a problem with anchors.
Canvas was not forwarding oncompleted to the parent class.
This caused some issues with anchoring.
Diffstat (limited to 'src')
-rw-r--r-- | src/canvas.cpp | 17 | ||||
-rw-r--r-- | src/canvas.h | 3 | ||||
-rw-r--r-- | src/context2d.cpp | 9 |
3 files changed, 20 insertions, 9 deletions
diff --git a/src/canvas.cpp b/src/canvas.cpp index e5c6bf8..73adff3 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -46,11 +46,11 @@ Canvas::Canvas(QDeclarativeItem *parent) : QDeclarativeItem(parent), - m_context(new Context2D(this)), - m_canvasWidth(0), - m_canvasHeight(0), - m_fillMode(Canvas::Stretch), - m_color(Qt::white) + m_context(new Context2D(this)), + m_canvasWidth(0), + m_canvasHeight(0), + m_fillMode(Canvas::Stretch), + m_color(Qt::white) { setFlag(QGraphicsItem::ItemHasNoContents, false); setCacheMode(QGraphicsItem::DeviceCoordinateCache); @@ -66,6 +66,7 @@ void Canvas::componentComplete() connect(m_context, SIGNAL(changed()), this, SLOT(requestPaint())); emit init(); + QDeclarativeItem::componentComplete(); } void Canvas::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) @@ -163,12 +164,13 @@ void Canvas::requestPaint() update(); } -void Canvas::geometryChanged(const QRectF &newGeometry, const QRectF &) +void Canvas::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { if (m_canvasWidth == 0 && m_canvasHeight == 0 - && newGeometry.width() > 0 && newGeometry.height() > 0) { + && newGeometry.width() > 0 && newGeometry.height() > 0) { m_context->setSize(width(), height()); } + QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); } void Canvas::setCanvasWidth(int newWidth) @@ -248,3 +250,4 @@ void Canvas::clearInterval(const QScriptValue &handler) { CanvasTimer::removeTimer(handler); } + diff --git a/src/canvas.h b/src/canvas.h index a4c0094..99e67fb 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -58,9 +58,9 @@ public: Canvas(QDeclarativeItem *parent = 0); enum FillMode { Stretch, PreserveAspectFit, PreserveAspectCrop, Tile, TileVertically, TileHorizontally }; + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); - void setCanvasWidth(int newWidth); int canvasWidth() {return m_canvasWidth;} @@ -69,6 +69,7 @@ public: void componentComplete(); + public Q_SLOTS: Context2D *getContext(const QString & = QString("2d")); void requestPaint(); diff --git a/src/context2d.cpp b/src/context2d.cpp index 6dfc025..bc3c77b 100644 --- a/src/context2d.cpp +++ b/src/context2d.cpp @@ -462,6 +462,10 @@ void Context2D::setShadowOffsetY(qreal y) void Context2D::setShadowBlur(qreal b) { + if (m_shadowbuffer.isNull() || m_shadowbuffer.width() != m_width || m_shadowbuffer.height() != m_height) { + m_shadowbuffer = QImage(m_width, m_height, QImage::Format_ARGB32); + } + if (m_painter.device() == &m_shadowbuffer && m_state.shadowBlur>0) endPainting(); m_state.shadowBlur = b; @@ -919,7 +923,7 @@ void Context2D::beginPainting() if (m_state.shadowBlur > 0) { if (m_shadowbuffer.width() != m_width || m_shadowbuffer.height() != m_height) { - m_shadowbuffer = QImage(m_width, m_height, QImage::Format_ARGB32); + m_shadowbuffer = QImage(m_width, m_height, QImage::Format_ARGB32_Premultiplied); } } @@ -947,6 +951,8 @@ void Context2D::beginPainting() } else { if (m_state.shadowBlur > 0 && m_painter.device() != &m_shadowbuffer) { m_painter.end(); + + m_shadowbuffer.fill(Qt::transparent); m_painter.begin(&m_shadowbuffer); } @@ -959,6 +965,7 @@ void Context2D::endPainting() { if (m_state.shadowBlur > 0) { QImage alphaChannel = m_shadowbuffer.alphaChannel(); + qt_blurImage(alphaChannel, m_state.shadowBlur, false, 1); QRect imageRect = m_shadowbuffer.rect(); |