]>
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 | |
51e77110 JH |
24 | #include "../sigsession.h" |
25 | #include "../signal.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); | |
d7002724 JH |
44 | } |
45 | ||
cdf7bea7 | 46 | int Viewport::get_total_height() const |
a429590b | 47 | { |
adb4b10c JH |
48 | int height = 0; |
49 | BOOST_FOREACH(const shared_ptr<Signal> s, | |
1d19ef83 | 50 | _view.session().get_signals()) { |
adb4b10c | 51 | assert(s); |
1d8dca91 | 52 | height += View::SignalHeight; |
adb4b10c JH |
53 | } |
54 | ||
55 | return height; | |
a429590b JH |
56 | } |
57 | ||
cdf7bea7 | 58 | void Viewport::paintEvent(QPaintEvent *event) |
d7002724 | 59 | { |
e3f65ace | 60 | const vector< shared_ptr<Signal> > &sigs = |
1d19ef83 | 61 | _view.session().get_signals(); |
3e46726a | 62 | |
64b60583 | 63 | QPainter p(this); |
ce6e73a8 | 64 | p.setRenderHint(QPainter::Antialiasing); |
3e46726a JH |
65 | |
66 | // Plot the signal | |
64b60583 | 67 | int offset = -_view.v_offset(); |
3e46726a JH |
68 | BOOST_FOREACH(const shared_ptr<Signal> s, sigs) |
69 | { | |
70 | assert(s); | |
71 | ||
1d8dca91 JH |
72 | const QRect signal_rect(0, offset, |
73 | width(), View::SignalHeight); | |
3e46726a | 74 | |
64b60583 | 75 | s->paint(p, signal_rect, _view.scale(), _view.offset()); |
3e46726a | 76 | |
1d8dca91 | 77 | offset += View::SignalHeight; |
3e46726a JH |
78 | } |
79 | ||
64b60583 | 80 | p.end(); |
6fa02541 | 81 | } |
009e1503 | 82 | |
cdf7bea7 | 83 | void Viewport::mousePressEvent(QMouseEvent *event) |
7cd5faf8 JH |
84 | { |
85 | assert(event); | |
1dd95c70 JH |
86 | |
87 | _mouse_down_point = event->pos(); | |
adb4b10c | 88 | _mouse_down_offset = _view.offset(); |
7cd5faf8 JH |
89 | } |
90 | ||
cdf7bea7 | 91 | void Viewport::mouseMoveEvent(QMouseEvent *event) |
7cd5faf8 JH |
92 | { |
93 | assert(event); | |
1dd95c70 JH |
94 | |
95 | if(event->buttons() & Qt::LeftButton) | |
96 | { | |
adb4b10c JH |
97 | _view.set_scale_offset(_view.scale(), |
98 | _mouse_down_offset + | |
99 | (_mouse_down_point - event->pos()).x() * | |
100 | _view.scale()); | |
1dd95c70 | 101 | } |
7cd5faf8 JH |
102 | } |
103 | ||
cdf7bea7 | 104 | void Viewport::mouseReleaseEvent(QMouseEvent *event) |
7cd5faf8 JH |
105 | { |
106 | assert(event); | |
1dd95c70 | 107 | } |
7cd5faf8 | 108 | |
cdf7bea7 | 109 | void Viewport::wheelEvent(QWheelEvent *event) |
1dd95c70 JH |
110 | { |
111 | assert(event); | |
1d8dca91 | 112 | _view.zoom(event->delta() / 120, event->x()); |
7cd5faf8 JH |
113 | } |
114 | ||
cdf7bea7 JH |
115 | } // namespace view |
116 | } // namespace pv |