]>
Commit | Line | Data |
---|---|---|
adb4b10c | 1 | /* |
b3f22de0 | 2 | * This file is part of the PulseView project. |
adb4b10c 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 | ||
269528f5 | 21 | #ifdef ENABLE_DECODE |
4e5a4405 | 22 | #include <libsigrokdecode/libsigrokdecode.h> |
269528f5 | 23 | #endif |
4e5a4405 | 24 | |
361c560e JH |
25 | #include <extdef.h> |
26 | ||
c3a740dd JH |
27 | #include <cassert> |
28 | #include <climits> | |
29 | #include <cmath> | |
30 | #include <mutex> | |
7ff0145f | 31 | #include <unordered_set> |
adb4b10c | 32 | |
361c560e | 33 | #include <QApplication> |
adb4b10c | 34 | #include <QEvent> |
361c560e | 35 | #include <QFontMetrics> |
cbd80f64 | 36 | #include <QMouseEvent> |
adb4b10c JH |
37 | #include <QScrollBar> |
38 | ||
448a72cf JH |
39 | #include <libsigrok/libsigrok.hpp> |
40 | ||
2acdb232 JH |
41 | #include "cursorheader.hpp" |
42 | #include "decodetrace.hpp" | |
43 | #include "header.hpp" | |
44 | #include "logicsignal.hpp" | |
45 | #include "ruler.hpp" | |
46 | #include "signal.hpp" | |
47 | #include "tracegroup.hpp" | |
48 | #include "view.hpp" | |
49 | #include "viewport.hpp" | |
adb4b10c | 50 | |
f65cd27b | 51 | #include "pv/session.hpp" |
2acdb232 JH |
52 | #include "pv/data/logic.hpp" |
53 | #include "pv/data/logicsnapshot.hpp" | |
361c560e | 54 | #include "pv/util.hpp" |
adb4b10c | 55 | |
aca64cac JH |
56 | using boost::shared_lock; |
57 | using boost::shared_mutex; | |
361c560e | 58 | |
1bc6525b | 59 | using pv::data::SignalData; |
361c560e JH |
60 | using pv::util::format_time; |
61 | ||
a2321722 | 62 | using std::back_inserter; |
819f4c25 | 63 | using std::deque; |
448a72cf | 64 | using std::dynamic_pointer_cast; |
819f4c25 | 65 | using std::list; |
c3a740dd | 66 | using std::lock_guard; |
819f4c25 | 67 | using std::max; |
1bc6525b | 68 | using std::make_pair; |
819f4c25 | 69 | using std::min; |
1bc6525b | 70 | using std::pair; |
819f4c25 | 71 | using std::set; |
f9abf97e | 72 | using std::shared_ptr; |
448a72cf | 73 | using std::unordered_map; |
7ff0145f | 74 | using std::unordered_set; |
819f4c25 | 75 | using std::vector; |
f9abf97e | 76 | using std::weak_ptr; |
adb4b10c | 77 | |
cdf7bea7 JH |
78 | namespace pv { |
79 | namespace view { | |
adb4b10c | 80 | |
cdf7bea7 JH |
81 | const double View::MaxScale = 1e9; |
82 | const double View::MinScale = 1e-15; | |
adb4b10c | 83 | |
f25770e2 JH |
84 | const int View::MaxScrollValue = INT_MAX / 2; |
85 | ||
361c560e JH |
86 | const int View::ScaleUnits[3] = {1, 2, 5}; |
87 | ||
f76af637 JH |
88 | const QColor View::CursorAreaColour(220, 231, 243); |
89 | ||
2e04f9bd JH |
90 | const QSizeF View::LabelPadding(4, 0); |
91 | ||
2b81ae46 | 92 | View::View(Session &session, QWidget *parent) : |
adb4b10c | 93 | QAbstractScrollArea(parent), |
8dbbc7f0 JH |
94 | session_(session), |
95 | viewport_(new Viewport(*this)), | |
96 | ruler_(new Ruler(*this)), | |
97 | cursorheader_(new CursorHeader(*this)), | |
98 | header_(new Header(*this)), | |
99 | scale_(1e-6), | |
100 | offset_(0), | |
101 | v_offset_(0), | |
102 | updating_scroll_(false), | |
361c560e JH |
103 | tick_period_(0.0), |
104 | tick_prefix_(0), | |
8dbbc7f0 JH |
105 | show_cursors_(false), |
106 | cursors_(*this), | |
107 | hover_point_(-1, -1) | |
adb4b10c | 108 | { |
b16907d3 JH |
109 | connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), |
110 | this, SLOT(h_scroll_value_changed(int))); | |
adb4b10c JH |
111 | connect(verticalScrollBar(), SIGNAL(valueChanged(int)), |
112 | this, SLOT(v_scroll_value_changed(int))); | |
69dd2b03 | 113 | |
8dbbc7f0 | 114 | connect(&session_, SIGNAL(signals_changed()), |
69dd2b03 | 115 | this, SLOT(signals_changed())); |
8dbbc7f0 | 116 | connect(&session_, SIGNAL(capture_state_changed(int)), |
50f97924 | 117 | this, SLOT(data_updated())); |
8dbbc7f0 | 118 | connect(&session_, SIGNAL(data_received()), |
1f374035 | 119 | this, SLOT(data_updated())); |
8dbbc7f0 | 120 | connect(&session_, SIGNAL(frame_ended()), |
adb4b10c | 121 | this, SLOT(data_updated())); |
1d8dca91 | 122 | |
8dbbc7f0 | 123 | connect(cursors_.first().get(), SIGNAL(time_changed()), |
ca4ec3ea | 124 | this, SLOT(marker_time_changed())); |
8dbbc7f0 | 125 | connect(cursors_.second().get(), SIGNAL(time_changed()), |
ca4ec3ea JH |
126 | this, SLOT(marker_time_changed())); |
127 | ||
8dbbc7f0 | 128 | connect(header_, SIGNAL(signals_moved()), |
07204819 | 129 | this, SLOT(on_signals_moved())); |
54401bbb | 130 | |
8dbbc7f0 JH |
131 | connect(header_, SIGNAL(selection_changed()), |
132 | cursorheader_, SLOT(clear_selection())); | |
133 | connect(cursorheader_, SIGNAL(selection_changed()), | |
134 | header_, SLOT(clear_selection())); | |
17348f85 | 135 | |
8dbbc7f0 | 136 | connect(header_, SIGNAL(selection_changed()), |
8b454527 | 137 | this, SIGNAL(selection_changed())); |
8dbbc7f0 | 138 | connect(cursorheader_, SIGNAL(selection_changed()), |
8b454527 JH |
139 | this, SIGNAL(selection_changed())); |
140 | ||
33c62f44 JH |
141 | connect(this, SIGNAL(hover_point_changed()), |
142 | this, SLOT(on_hover_point_changed())); | |
143 | ||
8dbbc7f0 | 144 | connect(&lazy_event_handler_, SIGNAL(timeout()), |
32218d3e | 145 | this, SLOT(process_sticky_events())); |
8dbbc7f0 | 146 | lazy_event_handler_.setSingleShot(true); |
32218d3e | 147 | |
8dbbc7f0 | 148 | setViewport(viewport_); |
cbd80f64 | 149 | |
8dbbc7f0 JH |
150 | viewport_->installEventFilter(this); |
151 | ruler_->installEventFilter(this); | |
152 | cursorheader_->installEventFilter(this); | |
153 | header_->installEventFilter(this); | |
d873f4d6 | 154 | |
9f46d905 JH |
155 | // Trigger the initial event manually. The default device has signals |
156 | // which were created before this object came into being | |
d873f4d6 | 157 | signals_changed(); |
84a0d458 | 158 | |
512bfc56 | 159 | // make sure the transparent widgets are on the top |
8dbbc7f0 JH |
160 | cursorheader_->raise(); |
161 | header_->raise(); | |
361c560e JH |
162 | |
163 | // Update the zoom state | |
164 | calculate_tick_spacing(); | |
adb4b10c JH |
165 | } |
166 | ||
2b81ae46 | 167 | Session& View::session() |
1d19ef83 | 168 | { |
8dbbc7f0 | 169 | return session_; |
1d19ef83 JH |
170 | } |
171 | ||
2b81ae46 | 172 | const Session& View::session() const |
38eeddea | 173 | { |
8dbbc7f0 | 174 | return session_; |
38eeddea JH |
175 | } |
176 | ||
eae6e30a JH |
177 | View* View::view() |
178 | { | |
179 | return this; | |
180 | } | |
181 | ||
182 | const View* View::view() const | |
183 | { | |
184 | return this; | |
185 | } | |
186 | ||
2ae445ba SA |
187 | Viewport* View::viewport() |
188 | { | |
8dbbc7f0 | 189 | return viewport_; |
2ae445ba SA |
190 | } |
191 | ||
192 | const Viewport* View::viewport() const | |
193 | { | |
8dbbc7f0 | 194 | return viewport_; |
2ae445ba SA |
195 | } |
196 | ||
cdf7bea7 | 197 | double View::scale() const |
adb4b10c | 198 | { |
8dbbc7f0 | 199 | return scale_; |
adb4b10c JH |
200 | } |
201 | ||
cdf7bea7 | 202 | double View::offset() const |
adb4b10c | 203 | { |
8dbbc7f0 | 204 | return offset_; |
adb4b10c JH |
205 | } |
206 | ||
7ff0145f | 207 | int View::owner_visual_v_offset() const |
adb4b10c | 208 | { |
8dbbc7f0 | 209 | return -v_offset_; |
adb4b10c JH |
210 | } |
211 | ||
3e769a37 JH |
212 | unsigned int View::depth() const |
213 | { | |
214 | return 0; | |
215 | } | |
216 | ||
361c560e JH |
217 | unsigned int View::tick_prefix() const |
218 | { | |
219 | return tick_prefix_; | |
220 | } | |
221 | ||
222 | double View::tick_period() const | |
223 | { | |
224 | return tick_period_; | |
225 | } | |
226 | ||
cdf7bea7 | 227 | void View::zoom(double steps) |
adb4b10c | 228 | { |
8dbbc7f0 | 229 | zoom(steps, viewport_->width() / 2); |
adb4b10c JH |
230 | } |
231 | ||
17c0f398 JH |
232 | void View::zoom(double steps, int offset) |
233 | { | |
8dbbc7f0 | 234 | set_zoom(scale_ * pow(3.0/2.0, -steps), offset); |
17c0f398 JH |
235 | } |
236 | ||
ca46b534 JH |
237 | void View::zoom_fit() |
238 | { | |
1bc6525b JH |
239 | const pair<double, double> extents = get_time_extents(); |
240 | const double delta = extents.second - extents.first; | |
241 | if (delta < 1e-12) | |
ca46b534 JH |
242 | return; |
243 | ||
8dbbc7f0 JH |
244 | assert(viewport_); |
245 | const int w = viewport_->width(); | |
ca46b534 JH |
246 | if (w <= 0) |
247 | return; | |
248 | ||
78311127 JH |
249 | const double scale = max(min(delta / w, MaxScale), MinScale); |
250 | set_scale_offset(scale, extents.first); | |
ca46b534 JH |
251 | } |
252 | ||
d1e7d82c JH |
253 | void View::zoom_one_to_one() |
254 | { | |
255 | using pv::data::SignalData; | |
256 | ||
d1e7d82c | 257 | // Make a set of all the visible data objects |
0fc664a9 | 258 | set< shared_ptr<SignalData> > visible_data = get_visible_data(); |
d1e7d82c JH |
259 | if (visible_data.empty()) |
260 | return; | |
261 | ||
262 | double samplerate = 0.0; | |
d9aecf1f | 263 | for (const shared_ptr<SignalData> d : visible_data) { |
d1e7d82c JH |
264 | assert(d); |
265 | samplerate = max(samplerate, d->samplerate()); | |
266 | } | |
267 | ||
268 | if (samplerate == 0.0) | |
269 | return; | |
270 | ||
8dbbc7f0 JH |
271 | assert(viewport_); |
272 | const int w = viewport_->width(); | |
d1e7d82c JH |
273 | if (w <= 0) |
274 | return; | |
275 | ||
276 | set_zoom(1.0 / samplerate, w / 2); | |
277 | } | |
278 | ||
cdf7bea7 | 279 | void View::set_scale_offset(double scale, double offset) |
adb4b10c | 280 | { |
8dbbc7f0 JH |
281 | scale_ = scale; |
282 | offset_ = offset; | |
ccdd3ef5 | 283 | |
361c560e JH |
284 | calculate_tick_spacing(); |
285 | ||
adb4b10c | 286 | update_scroll(); |
8dbbc7f0 JH |
287 | ruler_->update(); |
288 | cursorheader_->update(); | |
289 | viewport_->update(); | |
e0fc5810 | 290 | scale_offset_changed(); |
adb4b10c JH |
291 | } |
292 | ||
1bc6525b JH |
293 | set< shared_ptr<SignalData> > View::get_visible_data() const |
294 | { | |
aca64cac | 295 | shared_lock<shared_mutex> lock(session().signals_mutex()); |
c3a740dd | 296 | const vector< shared_ptr<Signal> > &sigs(session().signals()); |
1bc6525b JH |
297 | |
298 | // Make a set of all the visible data objects | |
299 | set< shared_ptr<SignalData> > visible_data; | |
d9aecf1f | 300 | for (const shared_ptr<Signal> sig : sigs) |
1bc6525b JH |
301 | if (sig->enabled()) |
302 | visible_data.insert(sig->data()); | |
303 | ||
304 | return visible_data; | |
305 | } | |
306 | ||
307 | pair<double, double> View::get_time_extents() const | |
308 | { | |
309 | const set< shared_ptr<SignalData> > visible_data = get_visible_data(); | |
310 | if (visible_data.empty()) | |
311 | return make_pair(0.0, 0.0); | |
312 | ||
313 | double left_time = DBL_MAX, right_time = DBL_MIN; | |
d9aecf1f | 314 | for (const shared_ptr<SignalData> d : visible_data) |
1bc6525b JH |
315 | { |
316 | const double start_time = d->get_start_time(); | |
a472a884 JH |
317 | double samplerate = d->samplerate(); |
318 | samplerate = (samplerate <= 0.0) ? 1.0 : samplerate; | |
319 | ||
1bc6525b JH |
320 | left_time = min(left_time, start_time); |
321 | right_time = max(right_time, start_time + | |
a472a884 | 322 | d->get_max_sample_count() / samplerate); |
1bc6525b JH |
323 | } |
324 | ||
325 | assert(left_time < right_time); | |
326 | return make_pair(left_time, right_time); | |
327 | } | |
328 | ||
f76af637 JH |
329 | bool View::cursors_shown() const |
330 | { | |
8dbbc7f0 | 331 | return show_cursors_; |
f76af637 JH |
332 | } |
333 | ||
334 | void View::show_cursors(bool show) | |
335 | { | |
8dbbc7f0 JH |
336 | show_cursors_ = show; |
337 | cursorheader_->update(); | |
338 | viewport_->update(); | |
f76af637 JH |
339 | } |
340 | ||
b4d91e56 JH |
341 | void View::centre_cursors() |
342 | { | |
8dbbc7f0 JH |
343 | const double time_width = scale_ * viewport_->width(); |
344 | cursors_.first()->set_time(offset_ + time_width * 0.4); | |
345 | cursors_.second()->set_time(offset_ + time_width * 0.6); | |
346 | cursorheader_->update(); | |
347 | viewport_->update(); | |
b4d91e56 JH |
348 | } |
349 | ||
b42d25c4 | 350 | CursorPair& View::cursors() |
f76af637 | 351 | { |
8dbbc7f0 | 352 | return cursors_; |
f76af637 JH |
353 | } |
354 | ||
58864c5c JH |
355 | const CursorPair& View::cursors() const |
356 | { | |
8dbbc7f0 | 357 | return cursors_; |
58864c5c JH |
358 | } |
359 | ||
cbd80f64 JH |
360 | const QPoint& View::hover_point() const |
361 | { | |
8dbbc7f0 | 362 | return hover_point_; |
cbd80f64 JH |
363 | } |
364 | ||
9cef9567 JH |
365 | void View::update_viewport() |
366 | { | |
8dbbc7f0 JH |
367 | assert(viewport_); |
368 | viewport_->update(); | |
369 | header_->update(); | |
7ff0145f JH |
370 | } |
371 | ||
372 | void View::restack_all_row_items() | |
373 | { | |
374 | // Make a set of owners | |
375 | unordered_set< RowItemOwner* > owners; | |
376 | for (const auto &r : *this) | |
377 | owners.insert(r->owner()); | |
378 | ||
379 | // Make a list that is sorted from deepest first | |
380 | vector< RowItemOwner* > sorted_owners(owners.begin(), owners.end()); | |
381 | sort(sorted_owners.begin(), sorted_owners.end(), | |
382 | [](const RowItemOwner* a, const RowItemOwner *b) { | |
383 | return a->depth() > b->depth(); }); | |
384 | ||
385 | // Restack the items recursively | |
386 | for (auto &o : sorted_owners) | |
387 | o->restack_items(); | |
388 | ||
389 | // Animate the items to their destination | |
390 | for (const auto &r : *this) | |
391 | r->animate_to_layout_v_offset(); | |
9cef9567 JH |
392 | } |
393 | ||
f25770e2 JH |
394 | void View::get_scroll_layout(double &length, double &offset) const |
395 | { | |
1bc6525b | 396 | const pair<double, double> extents = get_time_extents(); |
8dbbc7f0 JH |
397 | length = (extents.second - extents.first) / scale_; |
398 | offset = offset_ / scale_; | |
f25770e2 JH |
399 | } |
400 | ||
d1e7d82c JH |
401 | void View::set_zoom(double scale, int offset) |
402 | { | |
8dbbc7f0 | 403 | const double cursor_offset = offset_ + scale_ * offset; |
d1e7d82c JH |
404 | const double new_scale = max(min(scale, MaxScale), MinScale); |
405 | const double new_offset = cursor_offset - new_scale * offset; | |
406 | set_scale_offset(new_scale, new_offset); | |
407 | } | |
408 | ||
361c560e JH |
409 | void View::calculate_tick_spacing() |
410 | { | |
411 | const double SpacingIncrement = 32.0f; | |
412 | const double MinValueSpacing = 32.0f; | |
413 | ||
414 | double min_width = SpacingIncrement, typical_width; | |
415 | ||
416 | QFontMetrics m(QApplication::font()); | |
417 | ||
418 | do { | |
419 | const double min_period = scale_ * min_width; | |
420 | ||
421 | const int order = (int)floorf(log10f(min_period)); | |
422 | const double order_decimal = pow(10.0, order); | |
423 | ||
424 | unsigned int unit = 0; | |
425 | ||
426 | do { | |
427 | tick_period_ = order_decimal * ScaleUnits[unit++]; | |
428 | } while (tick_period_ < min_period && | |
429 | unit < countof(ScaleUnits)); | |
430 | ||
431 | tick_prefix_ = (order - pv::util::FirstSIPrefixPower) / 3; | |
432 | ||
433 | typical_width = m.boundingRect(0, 0, INT_MAX, INT_MAX, | |
434 | Qt::AlignLeft | Qt::AlignTop, | |
435 | format_time(offset_, tick_prefix_)).width() + | |
436 | MinValueSpacing; | |
437 | ||
438 | min_width += SpacingIncrement; | |
439 | ||
440 | } while(typical_width > tick_period_ / scale_); | |
441 | } | |
442 | ||
cdf7bea7 | 443 | void View::update_scroll() |
adb4b10c | 444 | { |
8dbbc7f0 | 445 | assert(viewport_); |
adb4b10c | 446 | |
8dbbc7f0 | 447 | const QSize areaSize = viewport_->size(); |
adb4b10c JH |
448 | |
449 | // Set the horizontal scroll bar | |
450 | double length = 0, offset = 0; | |
f25770e2 JH |
451 | get_scroll_layout(length, offset); |
452 | length = max(length - areaSize.width(), 0.0); | |
adb4b10c | 453 | |
b4ef7f2a | 454 | horizontalScrollBar()->setPageStep(areaSize.width() / 2); |
f25770e2 | 455 | |
8dbbc7f0 | 456 | updating_scroll_ = true; |
528bd8a1 | 457 | |
333d5bbc | 458 | if (length < MaxScrollValue) { |
f25770e2 JH |
459 | horizontalScrollBar()->setRange(0, length); |
460 | horizontalScrollBar()->setSliderPosition(offset); | |
461 | } else { | |
462 | horizontalScrollBar()->setRange(0, MaxScrollValue); | |
463 | horizontalScrollBar()->setSliderPosition( | |
8dbbc7f0 | 464 | offset_ * MaxScrollValue / (scale_ * length)); |
f25770e2 | 465 | } |
adb4b10c | 466 | |
8dbbc7f0 | 467 | updating_scroll_ = false; |
528bd8a1 | 468 | |
adb4b10c JH |
469 | // Set the vertical scrollbar |
470 | verticalScrollBar()->setPageStep(areaSize.height()); | |
a5d93c27 JH |
471 | |
472 | const pair<int, int> extents = v_extents(); | |
473 | const int extra_scroll_height = (extents.second - extents.first) / 4; | |
474 | verticalScrollBar()->setRange(extents.first - extra_scroll_height, | |
475 | extents.first + extra_scroll_height); | |
adb4b10c JH |
476 | } |
477 | ||
d7c0ca4a JH |
478 | void View::update_layout() |
479 | { | |
512bfc56 | 480 | setViewportMargins( |
8dbbc7f0 JH |
481 | header_->sizeHint().width() - pv::view::Header::BaselineOffset, |
482 | ruler_->sizeHint().height(), 0, 0); | |
483 | ruler_->setGeometry(viewport_->x(), 0, | |
484 | viewport_->width(), viewport_->y()); | |
485 | cursorheader_->setGeometry( | |
486 | viewport_->x(), | |
487 | ruler_->sizeHint().height() - cursorheader_->sizeHint().height() / 2, | |
488 | viewport_->width(), cursorheader_->sizeHint().height()); | |
489 | header_->setGeometry(0, viewport_->y(), | |
490 | header_->sizeHint().width(), viewport_->height()); | |
d7c0ca4a JH |
491 | update_scroll(); |
492 | } | |
493 | ||
eae6e30a JH |
494 | void View::paint_label(QPainter &p, int right, bool hover) |
495 | { | |
496 | (void)p; | |
497 | (void)right; | |
498 | (void)hover; | |
499 | } | |
500 | ||
501 | QRectF View::label_rect(int right) | |
502 | { | |
503 | (void)right; | |
504 | return QRectF(); | |
505 | } | |
506 | ||
448a72cf JH |
507 | bool View::add_channels_to_owner( |
508 | const vector< shared_ptr<sigrok::Channel> > &channels, | |
509 | RowItemOwner *owner, int &offset, | |
510 | unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> > | |
511 | &signal_map, | |
512 | std::function<bool (shared_ptr<RowItem>)> filter_func) | |
513 | { | |
514 | bool any_added = false; | |
515 | ||
516 | assert(owner); | |
517 | ||
518 | for (const auto &channel : channels) | |
519 | { | |
520 | const auto iter = signal_map.find(channel); | |
521 | if (iter == signal_map.end() || | |
522 | (filter_func && !filter_func((*iter).second))) | |
523 | continue; | |
524 | ||
525 | shared_ptr<RowItem> row_item = (*iter).second; | |
526 | owner->add_child_item(row_item); | |
527 | apply_offset(row_item, offset); | |
528 | signal_map.erase(iter); | |
529 | ||
530 | any_added = true; | |
531 | } | |
532 | ||
533 | return any_added; | |
534 | } | |
535 | ||
536 | void View::apply_offset(shared_ptr<RowItem> row_item, int &offset) { | |
537 | assert(row_item); | |
538 | const pair<int, int> extents = row_item->v_extents(); | |
539 | if (row_item->enabled()) | |
540 | offset += -extents.first; | |
541 | row_item->force_to_v_offset(offset); | |
542 | if (row_item->enabled()) | |
543 | offset += extents.second; | |
544 | } | |
545 | ||
cbd80f64 JH |
546 | bool View::eventFilter(QObject *object, QEvent *event) |
547 | { | |
548 | const QEvent::Type type = event->type(); | |
333d5bbc | 549 | if (type == QEvent::MouseMove) { |
cbd80f64 JH |
550 | |
551 | const QMouseEvent *const mouse_event = (QMouseEvent*)event; | |
8dbbc7f0 JH |
552 | if (object == viewport_) |
553 | hover_point_ = mouse_event->pos(); | |
554 | else if (object == ruler_ || object == cursorheader_) | |
555 | hover_point_ = QPoint(mouse_event->x(), 0); | |
556 | else if (object == header_) | |
557 | hover_point_ = QPoint(0, mouse_event->y()); | |
cbd80f64 | 558 | else |
8dbbc7f0 | 559 | hover_point_ = QPoint(-1, -1); |
cbd80f64 JH |
560 | |
561 | hover_point_changed(); | |
562 | ||
333d5bbc | 563 | } else if (type == QEvent::Leave) { |
8dbbc7f0 | 564 | hover_point_ = QPoint(-1, -1); |
cbd80f64 JH |
565 | hover_point_changed(); |
566 | } | |
567 | ||
568 | return QObject::eventFilter(object, event); | |
569 | } | |
570 | ||
cdf7bea7 | 571 | bool View::viewportEvent(QEvent *e) |
adb4b10c JH |
572 | { |
573 | switch(e->type()) { | |
574 | case QEvent::Paint: | |
575 | case QEvent::MouseButtonPress: | |
576 | case QEvent::MouseButtonRelease: | |
577 | case QEvent::MouseButtonDblClick: | |
578 | case QEvent::MouseMove: | |
579 | case QEvent::Wheel: | |
4b4f1c0d MC |
580 | case QEvent::TouchBegin: |
581 | case QEvent::TouchUpdate: | |
582 | case QEvent::TouchEnd: | |
adb4b10c JH |
583 | return false; |
584 | ||
585 | default: | |
586 | return QAbstractScrollArea::viewportEvent(e); | |
587 | } | |
588 | } | |
589 | ||
e314eca4 | 590 | void View::resizeEvent(QResizeEvent*) |
adb4b10c | 591 | { |
d7c0ca4a | 592 | update_layout(); |
adb4b10c JH |
593 | } |
594 | ||
32218d3e JH |
595 | void View::appearance_changed(bool label, bool content) |
596 | { | |
597 | if (label) | |
8dbbc7f0 | 598 | header_->update(); |
32218d3e | 599 | if (content) |
8dbbc7f0 | 600 | viewport_->update(); |
32218d3e JH |
601 | } |
602 | ||
603 | void View::extents_changed(bool horz, bool vert) | |
604 | { | |
8dbbc7f0 | 605 | sticky_events_ |= |
32218d3e JH |
606 | (horz ? SelectableItemHExtentsChanged : 0) | |
607 | (vert ? SelectableItemVExtentsChanged : 0); | |
8dbbc7f0 | 608 | lazy_event_handler_.start(); |
32218d3e JH |
609 | } |
610 | ||
b16907d3 | 611 | void View::h_scroll_value_changed(int value) |
adb4b10c | 612 | { |
8dbbc7f0 | 613 | if (updating_scroll_) |
528bd8a1 JH |
614 | return; |
615 | ||
f25770e2 | 616 | const int range = horizontalScrollBar()->maximum(); |
333d5bbc | 617 | if (range < MaxScrollValue) |
8dbbc7f0 | 618 | offset_ = scale_ * value; |
f25770e2 JH |
619 | else { |
620 | double length = 0, offset; | |
621 | get_scroll_layout(length, offset); | |
8dbbc7f0 | 622 | offset_ = scale_ * length * value / MaxScrollValue; |
f25770e2 JH |
623 | } |
624 | ||
8dbbc7f0 JH |
625 | ruler_->update(); |
626 | cursorheader_->update(); | |
627 | viewport_->update(); | |
adb4b10c JH |
628 | } |
629 | ||
cdf7bea7 | 630 | void View::v_scroll_value_changed(int value) |
adb4b10c | 631 | { |
8dbbc7f0 JH |
632 | v_offset_ = value; |
633 | header_->update(); | |
634 | viewport_->update(); | |
adb4b10c JH |
635 | } |
636 | ||
69dd2b03 JH |
637 | void View::signals_changed() |
638 | { | |
448a72cf JH |
639 | int offset = 0; |
640 | ||
68b21a71 JH |
641 | // Populate the traces |
642 | clear_child_items(); | |
643 | ||
8dbbc7f0 | 644 | shared_ptr<sigrok::Device> device = session_.device(); |
448a72cf JH |
645 | assert(device); |
646 | ||
647 | // Collect a set of signals | |
648 | unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> > | |
649 | signal_map; | |
650 | ||
8dbbc7f0 JH |
651 | shared_lock<shared_mutex> lock(session_.signals_mutex()); |
652 | const vector< shared_ptr<Signal> > &sigs(session_.signals()); | |
448a72cf JH |
653 | |
654 | for (const shared_ptr<Signal> &sig : sigs) | |
655 | signal_map[sig->channel()] = sig; | |
656 | ||
657 | // Populate channel groups | |
658 | for (auto entry : device->channel_groups()) | |
659 | { | |
660 | const shared_ptr<sigrok::ChannelGroup> &group = entry.second; | |
661 | ||
662 | if (group->channels().size() <= 1) | |
663 | continue; | |
664 | ||
665 | shared_ptr<TraceGroup> trace_group(new TraceGroup()); | |
666 | int child_offset = 0; | |
667 | if (add_channels_to_owner(group->channels(), | |
668 | trace_group.get(), child_offset, signal_map)) | |
669 | { | |
670 | add_child_item(trace_group); | |
671 | apply_offset(trace_group, offset); | |
672 | } | |
673 | } | |
674 | ||
675 | // Add the remaining logic channels | |
676 | shared_ptr<TraceGroup> logic_trace_group(new TraceGroup()); | |
677 | int child_offset = 0; | |
678 | ||
679 | if (add_channels_to_owner(device->channels(), | |
680 | logic_trace_group.get(), child_offset, signal_map, | |
681 | [](shared_ptr<RowItem> r) -> bool { | |
682 | return dynamic_pointer_cast<LogicSignal>(r) != nullptr; | |
683 | })) | |
68b21a71 | 684 | |
448a72cf JH |
685 | { |
686 | add_child_item(logic_trace_group); | |
687 | apply_offset(logic_trace_group, offset); | |
688 | } | |
689 | ||
690 | // Add the remaining channels | |
691 | add_channels_to_owner(device->channels(), this, offset, signal_map); | |
692 | assert(signal_map.empty()); | |
693 | ||
694 | // Add decode signals | |
68b21a71 JH |
695 | #ifdef ENABLE_DECODE |
696 | const vector< shared_ptr<DecodeTrace> > decode_sigs( | |
697 | session().get_decode_signals()); | |
448a72cf | 698 | for (auto s : decode_sigs) { |
68b21a71 | 699 | add_child_item(s); |
448a72cf | 700 | apply_offset(s, offset); |
ef8311a4 | 701 | } |
448a72cf | 702 | #endif |
ef8311a4 | 703 | |
a6c1726e | 704 | update_layout(); |
69dd2b03 JH |
705 | } |
706 | ||
cdf7bea7 | 707 | void View::data_updated() |
adb4b10c | 708 | { |
adb4b10c JH |
709 | // Update the scroll bars |
710 | update_scroll(); | |
711 | ||
712 | // Repaint the view | |
8dbbc7f0 | 713 | viewport_->update(); |
adb4b10c | 714 | } |
cdf7bea7 | 715 | |
ca4ec3ea JH |
716 | void View::marker_time_changed() |
717 | { | |
8dbbc7f0 JH |
718 | cursorheader_->update(); |
719 | viewport_->update(); | |
ca4ec3ea JH |
720 | } |
721 | ||
07204819 | 722 | void View::on_signals_moved() |
54401bbb | 723 | { |
07204819 JH |
724 | update_scroll(); |
725 | signals_moved(); | |
54401bbb JH |
726 | } |
727 | ||
32218d3e | 728 | void View::process_sticky_events() |
d7c0ca4a | 729 | { |
8dbbc7f0 | 730 | if (sticky_events_ & SelectableItemHExtentsChanged) |
32218d3e | 731 | update_layout(); |
8dbbc7f0 | 732 | if (sticky_events_ & SelectableItemVExtentsChanged) |
7ff0145f | 733 | restack_all_row_items(); |
32218d3e JH |
734 | |
735 | // Clear the sticky events | |
8dbbc7f0 | 736 | sticky_events_ = 0; |
d7c0ca4a JH |
737 | } |
738 | ||
33c62f44 JH |
739 | void View::on_hover_point_changed() |
740 | { | |
aa59d5c2 | 741 | for (shared_ptr<RowItem> r : *this) |
eae6e30a | 742 | r->hover_point_changed(); |
33c62f44 JH |
743 | } |
744 | ||
cdf7bea7 JH |
745 | } // namespace view |
746 | } // namespace pv |