2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "../sigsession.h"
27 #include <QMouseEvent>
29 #include <boost/foreach.hpp>
31 using namespace boost;
37 Viewport::Viewport(View &parent) :
41 setMouseTracking(true);
42 setAutoFillBackground(true);
43 setBackgroundRole(QPalette::Base);
45 connect(&_view, SIGNAL(signals_moved()),
46 this, SLOT(on_signals_moved()));
49 int Viewport::get_total_height() const
52 const vector< shared_ptr<Trace> > traces(_view.get_traces());
53 BOOST_FOREACH(const shared_ptr<Trace> t, traces) {
55 h = max(t->get_v_offset() + View::SignalHeight, h);
61 void Viewport::paintEvent(QPaintEvent*)
63 const vector< shared_ptr<Trace> > traces(_view.get_traces());
66 p.setRenderHint(QPainter::Antialiasing);
68 if (_view.cursors_shown())
69 _view.cursors().draw_viewport_background(p, rect());
72 BOOST_FOREACH(const shared_ptr<Trace> t, traces)
75 t->paint_back(p, 0, width());
78 BOOST_FOREACH(const shared_ptr<Trace> t, traces)
79 t->paint_mid(p, 0, width());
81 BOOST_FOREACH(const shared_ptr<Trace> t, traces)
82 t->paint_fore(p, 0, width());
84 if (_view.cursors_shown())
85 _view.cursors().draw_viewport_foreground(p, rect());
90 void Viewport::mousePressEvent(QMouseEvent *event)
94 _mouse_down_point = event->pos();
95 _mouse_down_offset = _view.offset();
98 void Viewport::mouseMoveEvent(QMouseEvent *event)
102 if (event->buttons() & Qt::LeftButton)
104 _view.set_scale_offset(_view.scale(),
106 (_mouse_down_point - event->pos()).x() *
111 void Viewport::wheelEvent(QWheelEvent *event)
115 if (event->orientation() == Qt::Vertical) {
116 // Vertical scrolling is interpreted as zooming in/out
117 _view.zoom(event->delta() / 120, event->x());
118 } else if (event->orientation() == Qt::Horizontal) {
119 // Horizontal scrolling is interpreted as moving left/right
120 _view.set_scale_offset(_view.scale(),
121 event->delta() * _view.scale()
126 void Viewport::on_signals_moved()