// Set up local keyboard shortcuts
zoom_in_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Plus), this,
- SLOT(on_zoom_in_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
+ SLOT(on_zoom_in_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
zoom_in_shortcut_->setAutoRepeat(false);
zoom_out_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Minus), this,
SLOT(on_scroll_to_end_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
end_shortcut_->setAutoRepeat(false);
+ grab_ruler_left_shortcut_ = new QShortcut(QKeySequence(Qt::Key_1), this,
+ nullptr, nullptr, Qt::WidgetWithChildrenShortcut);
+ connect(grab_ruler_left_shortcut_, &QShortcut::activated,
+ this, [=]{on_grab_ruler(1);});
+ grab_ruler_left_shortcut_->setAutoRepeat(false);
+
+ grab_ruler_right_shortcut_ = new QShortcut(QKeySequence(Qt::Key_2), this,
+ nullptr, nullptr, Qt::WidgetWithChildrenShortcut);
+ connect(grab_ruler_right_shortcut_, &QShortcut::activated,
+ this, [=]{on_grab_ruler(2);});
+ grab_ruler_right_shortcut_->setAutoRepeat(false);
+
+ cancel_grab_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Escape), this,
+ nullptr, nullptr, Qt::WidgetWithChildrenShortcut);
+ connect(cancel_grab_shortcut_, &QShortcut::activated,
+ this, [=]{grabbed_widget_ = nullptr;});
+ cancel_grab_shortcut_->setAutoRepeat(false);
+
// Trigger the initial event manually. The default device has signals
// which were created before this object came into being
signals_changed();
next_flag_text_ = 'A';
trigger_markers_.clear();
hover_widget_ = nullptr;
+ grabbed_widget_ = nullptr;
hover_point_ = QPoint(-1, -1);
scroll_needs_defaults_ = true;
saved_v_offset_ = 0;
{
shared_ptr<Signal> ret_val;
- for (const shared_ptr<Signal> s : signals_)
+ for (const shared_ptr<Signal>& s : signals_)
if (s->base() == base) {
ret_val = s;
break;
return viewport_;
}
+QAbstractScrollArea* View::scrollarea() const
+{
+ return scrollarea_;
+}
+
const Ruler* View::ruler() const
{
return ruler_;
viewport_->update();
}
-void View::centre_cursors()
+void View::center_cursors()
{
assert(cursors_);
update_hover_point();
+ if (grabbed_widget_) {
+ int64_t nearest = get_nearest_level_change(hover_point_);
+ pv::util::Timestamp mouse_time = offset_ + hover_point_.x() * scale_;
+
+ if (nearest == -1) {
+ grabbed_widget_->set_time(mouse_time);
+ } else {
+ grabbed_widget_->set_time(nearest / get_signal_under_mouse_cursor()->base()->get_samplerate());
+ }
+ }
+
} else if (type == QEvent::MouseButtonPress) {
+ grabbed_widget_ = nullptr;
+
const QMouseEvent *const mouse_event = (QMouseEvent*)event;
if ((object == viewport_) && (mouse_event->button() & Qt::LeftButton)) {
// Send event to all trace tree items
viewport_->update();
}
+void View::on_grab_ruler(int ruler_id)
+{
+ if (!cursors_shown()) {
+ center_cursors();
+ show_cursors();
+ }
+
+ // Release the grabbed widget if its trigger hotkey was pressed twice
+ if (ruler_id == 1)
+ grabbed_widget_ = (grabbed_widget_ == cursors_->first().get()) ?
+ nullptr : cursors_->first().get();
+ else
+ grabbed_widget_ = (grabbed_widget_ == cursors_->second().get()) ?
+ nullptr : cursors_->second().get();
+
+ if (grabbed_widget_)
+ grabbed_widget_->set_time(ruler_->get_absolute_time_from_x_pos(
+ mapFromGlobal(QCursor::pos()).x() - header_width()));
+}
+
void View::signals_changed()
{
using sigrok::Channel;