Implemented basic viewport scrolling in BasicViewport.
[aesalon.git] / src / artisan / gviewport / BasicViewport.cpp
blob431112fff72305ecdc758234b56ddaf29b8f3a51
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
8 */
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"
18 namespace Artisan {
19 namespace GViewport {
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()));
40 image.merge(m_image);
41 m_image = image;
44 void BasicViewport::acceptRenderedImage(RenderedImage *image) {
45 m_image.merge(*image);
46 delete image;
47 update();
50 void BasicViewport::updateRange(const Rect &range) {
51 RenderedImage image(range, Rect(size()));
52 image.merge(m_image);
53 m_image = image;
55 Renderer *renderer = new Renderer(m_image.dataRange(), m_image.pixelSize(), m_data);
56 connect(renderer, SIGNAL(finishedRendering(RenderedImage *)), this, SLOT(acceptRenderedImage(RenderedImage *)));
57 renderer->enqueue();
60 void BasicViewport::resizeEvent(QResizeEvent *event) {
61 RenderedImage image(m_image.dataRange(), Rect(event->size()));
62 image.merge(m_image);
63 m_image = image;
64 Renderer *renderer = new Renderer(m_image.dataRange(), Rect(event->size()), m_data);
65 connect(renderer, SIGNAL(finishedRendering(RenderedImage *)), this, SLOT(acceptRenderedImage(RenderedImage *)));
66 renderer->enqueue();
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