#include <QApplication>
#include <QBrush>
+#include <QMenu>
#include <QPainter>
#include <QPointF>
#include <QRect>
return QRectF(x - label_size.width(), top, label_size.width(), height);
}
+QMenu *Cursor::create_header_context_menu(QWidget *parent)
+{
+ QMenu *const menu = new QMenu(parent);
+
+ QAction *const snap_disable = new QAction(tr("Disable snapping"), this);
+ snap_disable->setCheckable(true);
+ snap_disable->setChecked(snapping_disabled_);
+ connect(snap_disable, &QAction::toggled, this, [=](bool checked){snapping_disabled_ = checked;});
+ menu->addAction(snap_disable);
+
+ return menu;
+}
+
shared_ptr<Cursor> Cursor::get_other_cursor() const
{
const shared_ptr<CursorPair> cursors(view_.cursors());
*/
QRectF label_rect(const QRectF &rect) const;
+ virtual QMenu* create_header_context_menu(QWidget *parent) override;
+
private:
shared_ptr<Cursor> get_other_cursor() const;
};
connect(del, SIGNAL(triggered()), this, SLOT(on_delete()));
menu->addAction(del);
+ QAction *const snap_disable = new QAction(tr("Disable snapping"), this);
+ snap_disable->setCheckable(true);
+ snap_disable->setChecked(snapping_disabled_);
+ connect(snap_disable, &QAction::toggled, this, [=](bool checked){snapping_disabled_ = checked;});
+ menu->addAction(snap_disable);
+
return menu;
}
void TimeItem::drag_by(const QPoint &delta)
{
- int64_t sample_num = view_.get_nearest_level_change(drag_point_ + delta);
-
- if (sample_num > -1)
- set_time(sample_num / view_.get_signal_under_mouse_cursor()->base()->get_samplerate());
- else
+ if (snapping_disabled_) {
set_time(view_.offset() + (drag_point_.x() + delta.x() - 0.5) *
view_.scale());
+ } else {
+ int64_t sample_num = view_.get_nearest_level_change(drag_point_ + delta);
+
+ if (sample_num > -1)
+ set_time(sample_num / view_.get_signal_under_mouse_cursor()->base()->get_samplerate());
+ else
+ set_time(view_.offset() + (drag_point_.x() + delta.x() - 0.5) * view_.scale());
+ }
}
const pv::util::Timestamp TimeItem::delta(const pv::util::Timestamp& other) const
return other - time();
}
+
+bool TimeItem::is_snapping_disabled() const
+{
+ return snapping_disabled_;
+}
+
} // namespace trace
} // namespace views
} // namespace pv
*/
TimeItem(View &view);
+ bool snapping_disabled_ = false;
+
public:
/**
* Sets the time of the marker.
*/
void drag_by(const QPoint &delta);
+ bool is_snapping_disabled() const;
+
protected:
View &view_;
};