diff options
author | Jens Bache-Wiig <jbache@trolltech.com> | 2010-09-20 18:35:58 +0200 |
---|---|---|
committer | Jens Bache-Wiig <jbache@trolltech.com> | 2010-09-20 18:35:58 +0200 |
commit | d9e5871377f87ced422c1d1763671e07175ccab9 (patch) | |
tree | 5775968db0f760892e9e2b00704f5a31848e86a7 | |
parent | 645b4b7ad0e69ae9063f56c33108209349317c08 (diff) |
Simply allow canvas as a paint source
Kill toImage
-rw-r--r-- | examples/painting/painting.qml | 2 | ||||
-rw-r--r-- | src/canvas.h | 7 | ||||
-rw-r--r-- | src/context2d.cpp | 23 |
3 files changed, 20 insertions, 12 deletions
diff --git a/examples/painting/painting.qml b/examples/painting/painting.qml index 22ef041..7b77912 100644 --- a/examples/painting/painting.qml +++ b/examples/painting/painting.qml @@ -107,7 +107,7 @@ Rectangle { MouseArea { anchors.fill:parent onClicked: { - model.append({image:canvas.toImage()}); + model.append({image:canvas}); view.currentIndex = model.count-1 } } diff --git a/src/canvas.h b/src/canvas.h index 718e3df..a4c0094 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -82,9 +82,6 @@ public Q_SLOTS: // Save current canvas to disk bool save(const QString& filename) const; - // Return canvas contents as a drawable image - CanvasImage *toImage() const; - // Timers void setInterval(const QScriptValue &handler, long timeout); void setTimeout(const QScriptValue &handler, long timeout); @@ -100,11 +97,15 @@ Q_SIGNALS: void paint(); private: + // Return canvas contents as a drawable image + CanvasImage *toImage() const; Context2D *m_context; int m_canvasWidth; int m_canvasHeight; FillMode m_fillMode; QColor m_color; + + friend class Context2D; }; #endif //CANVAS_H diff --git a/src/context2d.cpp b/src/context2d.cpp index 726fa4e..ec7b034 100644 --- a/src/context2d.cpp +++ b/src/context2d.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "context2d.h" +#include "canvas.h" #include <qdebug.h> #include <math.h> static const double Q_PI = 3.14159265358979323846; // pi @@ -1019,14 +1020,20 @@ void Context2D::drawImage(const QVariant &var, qreal sx, qreal sy, qreal sw = 0, qreal sh = 0) { CanvasImage *image = qobject_cast<CanvasImage*>(var.value<QObject*>()); - if (!image) - return; - beginPainting(); - if (sw == sh && sh == 0) - m_painter.drawPixmap(QPointF(sx, sy), image->value()); - else - m_painter.drawPixmap(QRect(sx, sy, sw, sh), image->value()); - scheduleChange(); + if (!image) { + Canvas *canvas = qobject_cast<Canvas*>(var.value<QObject*>()); + if (canvas) + image = canvas->toImage(); + } + if (image) { + beginPainting(); + if (sw == sh && sh == 0) + m_painter.drawPixmap(QPointF(sx, sy), image->value()); + else + m_painter.drawPixmap(QRect(sx, sy, sw, sh), image->value()); + + scheduleChange(); + } } void Context2D::setSize(int width, int height) |