]>
Commit | Line | Data |
---|---|---|
6fa02541 | 1 | /* |
b3f22de0 | 2 | * This file is part of the PulseView project. |
6fa02541 JH |
3 | * |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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 | |
19 | */ | |
20 | ||
cdf7bea7 JH |
21 | #include "view.h" |
22 | #include "viewport.h" | |
6fa02541 | 23 | |
8d634081 | 24 | #include "signal.h" |
51e77110 | 25 | #include "../sigsession.h" |
e3f65ace | 26 | |
7cd5faf8 | 27 | #include <QMouseEvent> |
e9c41f8c | 28 | |
e3f65ace JH |
29 | #include <boost/foreach.hpp> |
30 | ||
31 | using namespace boost; | |
32 | using namespace std; | |
33 | ||
cdf7bea7 JH |
34 | namespace pv { |
35 | namespace view { | |
e9c41f8c | 36 | |
cdf7bea7 | 37 | Viewport::Viewport(View &parent) : |
64b60583 | 38 | QWidget(&parent), |
adb4b10c | 39 | _view(parent) |
6fa02541 | 40 | { |
d7002724 | 41 | setMouseTracking(true); |
64b60583 JH |
42 | setAutoFillBackground(true); |
43 | setBackgroundRole(QPalette::Base); | |
07204819 JH |
44 | |
45 | connect(&_view, SIGNAL(signals_moved()), | |
46 | this, SLOT(on_signals_moved())); | |
d7002724 JH |
47 | } |
48 | ||
cdf7bea7 | 49 | int Viewport::get_total_height() const |
a429590b | 50 | { |
07204819 | 51 | int h = 0; |
38eeddea JH |
52 | const vector< shared_ptr<Trace> > traces(_view.get_traces()); |
53 | BOOST_FOREACH(const shared_ptr<Trace> t, traces) { | |
54 | assert(t); | |
55 | h = max(t->get_v_offset() + View::SignalHeight, h); | |
adb4b10c JH |
56 | } |
57 | ||
07204819 | 58 | return h; |
a429590b JH |
59 | } |
60 | ||
e314eca4 | 61 | void Viewport::paintEvent(QPaintEvent*) |
d7002724 | 62 | { |
38eeddea | 63 | const vector< shared_ptr<Trace> > traces(_view.get_traces()); |
3e46726a | 64 | |
64b60583 | 65 | QPainter p(this); |
ce6e73a8 | 66 | p.setRenderHint(QPainter::Antialiasing); |
3e46726a | 67 | |
0ba172cf JH |
68 | if (_view.cursors_shown()) |
69 | _view.cursors().draw_viewport_background(p, rect()); | |
f76af637 | 70 | |
3e46726a | 71 | // Plot the signal |
38eeddea | 72 | BOOST_FOREACH(const shared_ptr<Trace> t, traces) |
3e46726a | 73 | { |
38eeddea | 74 | assert(t); |
fe08b6e8 | 75 | t->paint_back(p, 0, width()); |
3e46726a JH |
76 | } |
77 | ||
fe08b6e8 JH |
78 | BOOST_FOREACH(const shared_ptr<Trace> t, traces) |
79 | t->paint_mid(p, 0, width()); | |
80 | ||
81 | BOOST_FOREACH(const shared_ptr<Trace> t, traces) | |
82 | t->paint_fore(p, 0, width()); | |
83 | ||
0ba172cf JH |
84 | if (_view.cursors_shown()) |
85 | _view.cursors().draw_viewport_foreground(p, rect()); | |
f76af637 | 86 | |
64b60583 | 87 | p.end(); |
6fa02541 | 88 | } |
009e1503 | 89 | |
cdf7bea7 | 90 | void Viewport::mousePressEvent(QMouseEvent *event) |
7cd5faf8 JH |
91 | { |
92 | assert(event); | |
1dd95c70 JH |
93 | |
94 | _mouse_down_point = event->pos(); | |
adb4b10c | 95 | _mouse_down_offset = _view.offset(); |
7cd5faf8 JH |
96 | } |
97 | ||
cdf7bea7 | 98 | void Viewport::mouseMoveEvent(QMouseEvent *event) |
7cd5faf8 JH |
99 | { |
100 | assert(event); | |
1dd95c70 | 101 | |
333d5bbc | 102 | if (event->buttons() & Qt::LeftButton) |
1dd95c70 | 103 | { |
adb4b10c JH |
104 | _view.set_scale_offset(_view.scale(), |
105 | _mouse_down_offset + | |
106 | (_mouse_down_point - event->pos()).x() * | |
107 | _view.scale()); | |
1dd95c70 | 108 | } |
7cd5faf8 JH |
109 | } |
110 | ||
cdf7bea7 | 111 | void Viewport::wheelEvent(QWheelEvent *event) |
1dd95c70 JH |
112 | { |
113 | assert(event); | |
ffd5cd20 AG |
114 | |
115 | if (event->orientation() == Qt::Vertical) { | |
116 | // Vertical scrolling is interpreted as zooming in/out | |
117 | _view.zoom(event->delta() / 120, event->x()); | |
23840406 AG |
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() | |
122 | + _view.offset()); | |
ffd5cd20 | 123 | } |
7cd5faf8 JH |
124 | } |
125 | ||
07204819 JH |
126 | void Viewport::on_signals_moved() |
127 | { | |
128 | update(); | |
129 | } | |
130 | ||
cdf7bea7 JH |
131 | } // namespace view |
132 | } // namespace pv |