PulseView  unreleased development snapshot
A Qt-based sigrok GUI
ruler.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the PulseView project.
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, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef PULSEVIEW_PV_VIEWS_TRACE_RULER_HPP
21 #define PULSEVIEW_PV_VIEWS_TRACE_RULER_HPP
22 
23 #include <functional>
24 #include <memory>
25 
26 #include <boost/optional.hpp>
27 
28 #include "marginwidget.hpp"
29 #include <pv/util.hpp>
30 
31 using std::function;
32 using std::pair;
33 using std::shared_ptr;
34 using std::vector;
35 
36 namespace RulerTest {
37 struct tick_position_test_0;
38 struct tick_position_test_1;
39 struct tick_position_test_2;
40 }
41 
42 namespace pv {
43 namespace views {
44 namespace trace {
45 
46 class TimeItem;
47 class ViewItem;
48 
50 {
51  vector<pair<double, QString>> major;
52  vector<double> minor;
53 };
54 
60 class Ruler : public MarginWidget
61 {
62  Q_OBJECT
63 
64  friend struct RulerTest::tick_position_test_0;
65  friend struct RulerTest::tick_position_test_1;
66  friend struct RulerTest::tick_position_test_2;
67 
68 private:
70  static const float RulerHeight;
71 
73  static const float HoverArrowSize;
74 
75 public:
76  Ruler(View &parent);
77 
78  QSize sizeHint() const override;
79 
85  QSize extended_size_hint() const override;
86 
112  static QString format_time_with_distance(
113  const pv::util::Timestamp& distance,
114  const pv::util::Timestamp& t,
117  unsigned precision = 0,
118  bool sign = true);
119 
120  pv::util::Timestamp get_absolute_time_from_x_pos(uint32_t x) const;
121  pv::util::Timestamp get_ruler_time_from_x_pos(uint32_t x) const;
122 
123  pv::util::Timestamp get_ruler_time_from_absolute_time(const pv::util::Timestamp& abs_time) const;
124  pv::util::Timestamp get_absolute_time_from_ruler_time(const pv::util::Timestamp& ruler_time) const;
125 
126  shared_ptr<TimeItem> get_reference_item() const;
127 
128 protected:
129  virtual void contextMenuEvent(QContextMenuEvent *event) override;
130  void resizeEvent(QResizeEvent*) override;
131  virtual void item_hover(const shared_ptr<ViewItem> &item, QPoint pos) override;
132 
133 private:
137  vector< shared_ptr<ViewItem> > items() override;
138 
145  shared_ptr<ViewItem> get_mouse_over_item(const QPoint &pt) override;
146 
147  void mouseDoubleClickEvent(QMouseEvent *event) override;
148 
149  void paintEvent(QPaintEvent *event) override;
150 
156  void draw_hover_mark(QPainter &p, int text_height);
157 
158  int calculate_text_height() const;
159 
172  static TickPositions calculate_tick_positions(
173  const pv::util::Timestamp& major_period,
174  const pv::util::Timestamp& offset,
175  const double scale,
176  const int width,
177  const unsigned int minor_tick_count,
178  function<QString(const pv::util::Timestamp&)> format_function);
179 
180 private Q_SLOTS:
181  void on_hover_point_changed(const QWidget* widget, const QPoint &hp);
182 
183  void invalidate_tick_position_cache();
184 
185  void on_createMarker();
186  void on_setZeroPosition();
187  void on_resetZeroPosition();
188  void on_toggleHoverMarker();
189 
190 private:
195  boost::optional<TickPositions> tick_position_cache_;
196 
197  shared_ptr<TimeItem> hover_item_;
198 
200 };
201 
202 } // namespace trace
203 } // namespace views
204 } // namespace pv
205 
206 #endif // PULSEVIEW_PV_VIEWS_TRACE_RULER_HPP
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t t(t+t)") define_sfop3(16
static const float RulerHeight
Height of the ruler in multipes of the text height.
Definition: ruler.hpp:70
SIPrefix
Definition: util.hpp:50
uint32_t context_menu_x_pos_
Definition: ruler.hpp:199
shared_ptr< TimeItem > hover_item_
Definition: ruler.hpp:197
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)
vector< pair< double, QString > > major
Definition: ruler.hpp:51
TimeUnit
Definition: util.hpp:44
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 24 >, boost::multiprecision::et_off > Timestamp
Timestamp type providing yoctosecond resolution.
Definition: util.hpp:67
static const float HoverArrowSize
Height of the hover arrow in multiples of the text height.
Definition: ruler.hpp:73
boost::optional< TickPositions > tick_position_cache_
Definition: ruler.hpp:195
vector< double > minor
Definition: ruler.hpp:52