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::acceptRenderedImage(RenderedImage
*image
) {
31 m_image
.merge(*image
);
36 void BasicViewport::translate(const Point
&by
) {
37 RenderedImage
image(Rect(m_image
.dataRange() + by
), m_image
.pixelSize());
42 enqueue(m_image
.dataRange());
45 void BasicViewport::setViewport(const Rect
&range
) {
46 RenderedImage
image(range
, Rect(size()));
51 enqueue(m_image
.dataRange());
54 void BasicViewport::updateRange(const Rect
&range
) {
58 void BasicViewport::resizeEvent(QResizeEvent
*event
) {
59 RenderedImage
image(m_image
.dataRange(), Rect(event
->size()));
63 enqueue(m_image
.dataRange());
66 void BasicViewport::paintEvent(QPaintEvent
*event
) {
67 m_image
.paintOnto(this);
70 void BasicViewport::mouseMoveEvent(QMouseEvent
*event
) {
71 if(event
->buttons() & Qt::LeftButton
) {
72 Point diff
= -(event
->pos() - m_lastPoint
);
74 CoordinateMapper
mapper(m_image
);
75 translate(mapper
.pixelToDataOffset(diff
));
77 m_lastPoint
= event
->pos();
81 void BasicViewport::mousePressEvent(QMouseEvent
*event
) {
82 m_lastPoint
= event
->pos();
85 void BasicViewport::wheelEvent(QWheelEvent
*event
) {
86 double factor
= 1.0 - (event
->delta() / 1200.0);
88 Rect newRange
= m_image
.dataRange();
90 if(event
->modifiers() & Qt::ShiftModifier
) {
91 newRange
.scaleHeight(factor
);
93 else if(event
->modifiers() & Qt::ControlModifier
) {
94 newRange
.scaleWidth(factor
);
97 newRange
.scaleHeight(factor
);
98 newRange
.scaleWidth(factor
);
101 setViewport(newRange
);
104 void BasicViewport::enqueue(const Rect
&rect
) {
105 CoordinateMapper
mapper(m_image
);
106 Renderer
*renderer
= new Renderer(rect
, mapper
.dataToPixel(rect
), m_data
);
108 connect(renderer
, SIGNAL(finishedRendering(RenderedImage
*)),
109 this, SLOT(acceptRenderedImage(RenderedImage
*)),
110 Qt::QueuedConnection
);
114 } // namespace GViewport
115 } // namespace Artisan