Minor changes here and there.
[aesalon.git] / src / artisan / gviewport / RenderedImage.cpp
blob98f3219c4e43f5994805129fba0d3374a467e48c
1 /** Aesalon, a tool to visualize program behaviour in real time.
2 Copyright (C) 2009-2011, Aesalon development team.
4 Aesalon is distributed under the terms of the GNU GPLv3. See
5 the included file LICENSE for more information.
7 @file src/artisan/gviewport/RenderedImage.cpp
8 */
10 #include <QPaintDevice>
11 #include <QRect>
13 #include "artisan/gviewport/RenderedImage.h"
14 #include "artisan/gviewport/CoordinateMapper.h"
16 #include "util/MessageSystem.h"
18 namespace Artisan {
19 namespace GViewport {
21 RenderedImage::RenderedImage(const Rect &dataRange, const Rect &pixelSize)
22 : m_dataRange(dataRange), m_pixelSize(pixelSize) {
24 m_image = QImage(m_pixelSize.width(), m_pixelSize.height(), QImage::Format_ARGB32);
26 m_image.fill(qRgb(qrand()%256, qrand()%256, qrand()%256));
28 m_painter = new QPainter();
31 RenderedImage::~RenderedImage() {
32 delete m_painter;
35 void RenderedImage::merge(RenderedImage &other) {
36 CoordinateMapper mapper(*this);
37 Rect local = mapper.dataToPixel(other.dataRange());
38 startPainting();
40 m_painter->drawImage(local.toQRect(), other.m_image);
42 stopPainting();
45 void RenderedImage::startPainting() {
46 m_painter->begin(&m_image);
49 void RenderedImage::stopPainting() {
50 m_painter->end();
53 void RenderedImage::paintOnto(QPaintDevice *device) {
54 QPainter painter(device);
55 painter.drawImage(QRect(0, 0, device->width(), device->height()), m_image, m_image.rect());
58 RenderedImage &RenderedImage::operator=(const RenderedImage &other) {
59 m_dataRange = other.m_dataRange;
60 m_pixelSize = other.m_pixelSize;
61 m_image = other.m_image;
62 return *this;
65 } // namespace GViewport
66 } // namespace Artisan