PulseView  unreleased development snapshot
A Qt-based sigrok GUI
timeitem.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2014 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, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "signal.hpp"
21 #include "timeitem.hpp"
22 #include "view.hpp"
23 
24 namespace pv {
25 namespace views {
26 namespace trace {
27 
29  view_(view) {
30 }
31 
32 void TimeItem::drag_by(const QPoint &delta)
33 {
34  if (snapping_disabled_) {
35  set_time(view_.offset() + (drag_point_.x() + delta.x() - 0.5) *
36  view_.scale());
37  } else {
38  int64_t sample_num = view_.get_nearest_level_change(drag_point_ + delta);
39 
40  if (sample_num > -1)
41  set_time(sample_num / view_.get_signal_under_mouse_cursor()->base()->get_samplerate());
42  else
43  set_time(view_.offset() + (drag_point_.x() + delta.x() - 0.5) * view_.scale());
44  }
45 }
46 
48 {
49  return other - time();
50 }
51 
52 
54 {
55  return snapping_disabled_;
56 }
57 
58 } // namespace trace
59 } // namespace views
60 } // namespace pv
void drag_by(const QPoint &delta)
Definition: timeitem.cpp:32
const pv::util::Timestamp & offset() const
Definition: view.cpp:605
virtual const pv::util::Timestamp time() const =0
bool is_snapping_disabled() const
Definition: timeitem.cpp:53
virtual void set_time(const pv::util::Timestamp &time)=0
shared_ptr< Signal > get_signal_under_mouse_cursor() const
Definition: view.cpp:461
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 24 >, boost::multiprecision::et_off > Timestamp
Timestamp type providing yoctosecond resolution.
Definition: util.hpp:67
virtual const pv::util::Timestamp delta(const pv::util::Timestamp &other) const
Definition: timeitem.cpp:47
int64_t get_nearest_level_change(const QPoint &p)
Definition: view.cpp:1052
double scale() const
Definition: view.cpp:577