22 #include <QFontMetrics> 24 #include <QMouseEvent> 36 using std::shared_ptr;
43 const float Ruler::RulerHeight = 2.5f;
45 const float Ruler::HoverArrowSize = 0.5f;
47 Ruler::Ruler(
View &parent) :
50 setMouseTracking(
true);
52 connect(&
view_, SIGNAL(hover_point_changed(
const QWidget*, QPoint)),
54 connect(&
view_, SIGNAL(offset_changed()),
56 connect(&
view_, SIGNAL(scale_changed()),
58 connect(&
view_, SIGNAL(tick_prefix_changed()),
60 connect(&
view_, SIGNAL(tick_precision_changed()),
62 connect(&
view_, SIGNAL(tick_period_changed()),
64 connect(&
view_, SIGNAL(time_unit_changed()),
79 max_rect = max_rect.united(i->label_rect(QRect()));
80 return QSize(0,
sizeHint().height() - max_rect.top() / 2 +
92 const unsigned limit = 60;
108 if ((precision == 0) && (distance >= limit))
146 if (event->isAccepted())
151 QMenu *
const menu =
new QMenu(
this);
153 QAction *
const create_marker =
new QAction(tr(
"Create marker here"),
this);
154 connect(create_marker, SIGNAL(triggered()),
this, SLOT(
on_createMarker()));
155 menu->addAction(create_marker);
157 QAction *
const set_zero_position =
new QAction(tr(
"Set as zero point"),
this);
159 menu->addAction(set_zero_position);
162 QAction *
const reset_zero_position =
new QAction(tr(
"Reset zero point"),
this);
164 menu->addAction(reset_zero_position);
167 QAction *
const toggle_hover_marker =
new QAction(
this);
169 menu->addAction(toggle_hover_marker);
172 const bool hover_marker_shown =
174 toggle_hover_marker->setText(hover_marker_shown ?
175 tr(
"Disable mouse hover marker") : tr(
"Enable mouse hover marker"));
177 event->setAccepted(
true);
178 menu->popup(event->globalPos());
190 return vector< shared_ptr<ViewItem> >(
191 time_items.begin(), time_items.end());
211 shared_ptr<TimeItem> ref_item;
214 for (
auto i =
items.rbegin(); i !=
items.rend(); i++) {
215 if ((*i)->enabled() && (*i)->selected()) {
226 if (ref_item && (ref_item->time() == 0))
236 for (
auto i =
items.rbegin(); i !=
items.rend(); i++)
237 if ((*i)->enabled() && (*i)->label_rect(rect()).contains(pt))
245 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 273 const int ValueMargin = 3;
276 const int ruler_height =
RulerHeight * text_height;
277 const int major_tick_y1 = text_height + ValueMargin * 2;
278 const int minor_tick_y1 = (major_tick_y1 + ruler_height) / 2;
283 p.setPen(palette().color(foregroundRole()));
286 const int leftedge = 0;
287 const int rightedge = width();
288 const int x_tick = tick.first;
289 if ((x_tick > leftedge) && (x_tick < rightedge)) {
290 const int x_left_bound =
util::text_width(QFontMetrics(font()), tick.second) / 2;
291 const int x_right_bound = rightedge - x_left_bound;
292 const int x_legend =
min(
max(x_tick, x_left_bound), x_right_bound);
293 p.drawText(x_legend, ValueMargin, 0, text_height,
294 AlignCenter | AlignTop | TextDontClip, tick.second);
295 p.drawLine(QPointF(x_tick, major_tick_y1),
296 QPointF(tick.first, ruler_height));
301 p.drawLine(QPointF(tick, minor_tick_y1),
302 QPointF(tick, ruler_height));
308 p.setRenderHint(QPainter::Antialiasing);
317 for (
auto &i :
items) {
320 i->paint_label(p, r, highlight);
331 p.setPen(QPen(Qt::NoPen));
332 p.setBrush(QBrush(palette().color(foregroundRole())));
336 const QPointF points[] = {
338 QPointF(x - hover_arrow_size, b - hover_arrow_size),
339 QPointF(x + hover_arrow_size, b - hover_arrow_size)
341 p.drawPolygon(points,
countof(points));
346 return QFontMetrics(font()).ascent();
354 const unsigned int minor_tick_count,
364 int division = (round(first_minor_division -
365 first_major_division * minor_tick_count)).convert_to<int>() - 1;
371 x = ((t - offset) / scale).convert_to<
double>();
373 if (division % minor_tick_count == 0) {
375 t = t0 + division / minor_tick_count * major_period;
376 tp.
major.emplace_back(x, format_function(t));
378 tp.
minor.emplace_back(x);
void on_hover_point_changed(const QWidget *widget, const QPoint &hp)
shared_ptr< TimeItem > get_reference_item() const
pv::util::Timestamp get_absolute_time_from_ruler_time(const pv::util::Timestamp &ruler_time) const
util::TimeUnit time_unit() const
QSize extended_size_hint() const override
pv::util::SIPrefix tick_prefix() const
void paintEvent(QPaintEvent *event) override
void on_toggleHoverMarker()
static const int HighlightRadius
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.
const pv::util::Timestamp & offset() const
pv::util::Timestamp get_ruler_time_from_absolute_time(const pv::util::Timestamp &abs_time) const
pv::util::Timestamp get_ruler_time_from_x_pos(uint32_t x) const
void draw_hover_mark(QPainter &p, int text_height)
std::streamsize text_width(const QFontMetrics &metric, const QString &string)
QSize sizeHint() const override
virtual void item_hover(const shared_ptr< ViewItem > &item, QPoint pos) override
QString format_time_si_adjusted(const Timestamp &t, SIPrefix prefix, unsigned precision, QString unit, bool sign)
void reset_zero_position()
void invalidate_tick_position_cache()
T max(const T v0, const T v1)
vector< shared_ptr< TimeItem > > time_items() const
pv::util::Timestamp zero_offset() const
static TickPositions calculate_tick_positions(const pv::util::Timestamp &major_period, const pv::util::Timestamp &offset, const double scale, const int width, const unsigned int minor_tick_count, function< QString(const pv::util::Timestamp &)> format_function)
virtual void contextMenuEvent(QContextMenuEvent *event) override
shared_ptr< ViewItem > get_mouse_over_item(const QPoint &pt) override
unsigned int minor_tick_count() const
int calculate_text_height() const
void setValue(const QString &key, const QVariant &value)
T min(const T v0, const T v1)
uint32_t context_menu_x_pos_
QString format_time_minutes(const Timestamp &t, signed precision, bool sign)
shared_ptr< TimeItem > hover_item_
void mouseDoubleClickEvent(QMouseEvent *event) override
static const QString Key_View_ShowHoverMarker
void on_resetZeroPosition()
static QString format_time_with_distance(const pv::util::Timestamp &distance, const pv::util::Timestamp &t, pv::util::SIPrefix prefix=pv::util::SIPrefix::unspecified, pv::util::TimeUnit unit=pv::util::TimeUnit::Time, unsigned precision=0, bool sign=true)
const QPoint & hover_point() const
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
pv::util::Timestamp get_absolute_time_from_x_pos(uint32_t x) const
const pv::util::Timestamp & tick_period() const
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 24 >, boost::multiprecision::et_off > Timestamp
Timestamp type providing yoctosecond resolution.
static const float HoverArrowSize
Height of the hover arrow in multiples of the text height.
const pv::util::Timestamp & ruler_offset() const
boost::optional< TickPositions > tick_position_cache_
vector< shared_ptr< ViewItem > > items() override
void set_zero_position(const pv::util::Timestamp &position)
unsigned int tick_precision() const
void on_setZeroPosition()
shared_ptr< Flag > add_flag(const pv::util::Timestamp &time)
void resizeEvent(QResizeEvent *) override