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/BasicViewport.cpp
10 #include <QResizeEvent>
11 #include <QPaintEvent>
12 #include <QMouseEvent>
14 #include "artisan/gviewport/BasicViewport.h"
15 #include "artisan/gviewport/Renderer.h"
16 #include "artisan/gviewport/CoordinateMapper.h"
21 BasicViewport::BasicViewport(Data
*data
) : m_data(data
) {
22 setMinimumSize(120, 120);
23 setMouseTracking(true);
26 BasicViewport::~BasicViewport() {
30 void BasicViewport::translate(const Point
&upperLeft
) {
34 void BasicViewport::scale(double factor
) {
38 void BasicViewport::setViewport(const Rect
&range
) {
39 RenderedImage
image(range
, Rect(size()));
44 void BasicViewport::acceptRenderedImage(RenderedImage
*image
) {
45 m_image
.merge(*image
);
50 void BasicViewport::updateRange(const Rect
&range
) {
51 RenderedImage
image(range
, Rect(size()));
55 Renderer
*renderer
= new Renderer(m_image
.dataRange(), m_image
.pixelSize(), m_data
);
56 connect(renderer
, SIGNAL(finishedRendering(RenderedImage
*)), this, SLOT(acceptRenderedImage(RenderedImage
*)));
60 void BasicViewport::resizeEvent(QResizeEvent
*event
) {
61 RenderedImage
image(m_image
.dataRange(), Rect(event
->size()));
64 Renderer
*renderer
= new Renderer(m_image
.dataRange(), Rect(event
->size()), m_data
);
65 connect(renderer
, SIGNAL(finishedRendering(RenderedImage
*)), this, SLOT(acceptRenderedImage(RenderedImage
*)));
69 void BasicViewport::paintEvent(QPaintEvent
*event
) {
70 m_image
.paintOnto(this);
73 void BasicViewport::mouseMoveEvent(QMouseEvent
*event
) {
74 if(event
->buttons() & Qt::LeftButton
) {
75 Point diff
= -(event
->pos() - m_lastPoint
);
77 CoordinateMapper
mapper(m_image
);
78 updateRange(m_image
.dataRange() + mapper
.pixelToDataOffset(diff
));
80 m_lastPoint
= event
->pos();
84 void BasicViewport::mousePressEvent(QMouseEvent
*event
) {
85 m_lastPoint
= event
->pos();
88 } // namespace GViewport
89 } // namespace Artisan