Skip to content

Commit

Permalink
Add zoom reset option to context menus
Browse files Browse the repository at this point in the history
  • Loading branch information
matomarss committed Jun 28, 2022
1 parent 7e5c839 commit fcc3c20
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pv/views/trace/ruler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ void Ruler::contextMenuEvent(QContextMenuEvent *event)

QMenu *const menu = new QMenu(this);

if(view_.scale() != 1e-3) {
QAction *const reset_zoom = new QAction(tr("Reset zoom"), this);
connect(reset_zoom, SIGNAL(triggered()), this, SLOT(on_zoom_reset()));
menu->addAction(reset_zoom);
}

QAction *const create_marker = new QAction(tr("Create marker here"), this);
connect(create_marker, SIGNAL(triggered()), this, SLOT(on_createMarker()));
menu->addAction(create_marker);
Expand Down Expand Up @@ -415,6 +421,11 @@ void Ruler::on_toggleHoverMarker()
settings.setValue(GlobalSettings::Key_View_ShowHoverMarker, !state);
}

void Ruler::on_zoom_reset()
{
view_.reset_zoom();
}

} // namespace trace
} // namespace views
} // namespace pv
1 change: 1 addition & 0 deletions pv/views/trace/ruler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ private Q_SLOTS:
void on_setZeroPosition();
void on_resetZeroPosition();
void on_toggleHoverMarker();
void on_zoom_reset();

private:
/**
Expand Down
25 changes: 25 additions & 0 deletions pv/views/trace/tracetreeitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include <cassert>
#include <QMenu>

#include "view.hpp"

Expand Down Expand Up @@ -138,6 +139,30 @@ QPoint TraceTreeItem::drag_point(const QRect &rect) const
return QPoint(rect.right(), get_visual_y());
}

QMenu* TraceTreeItem::create_view_context_menu(QWidget *parent, QPoint &click_pos)
{
(void)click_pos;

QMenu *const menu = new QMenu(parent);

View *view = owner_->view();

if(view->scale() != 1e-3) {
QAction *const reset_zoom = new QAction(tr("Reset zoom"), this);
connect(reset_zoom, SIGNAL(triggered()), this, SLOT(on_zoom_reset()));
menu->addAction(reset_zoom);
}

return menu;
}

void TraceTreeItem::on_zoom_reset()
{
View *view = owner_->view();
assert(view);
view->reset_zoom();
}

} // namespace trace
} // namespace views
} // namespace pv
5 changes: 5 additions & 0 deletions pv/views/trace/tracetreeitem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ class TraceTreeItem : public ViewItem,
*/
virtual pair<int, int> v_extents() const = 0;

virtual QMenu* create_view_context_menu(QWidget *parent, QPoint &click_pos);

private Q_SLOTS:
void on_zoom_reset();

protected:
TraceTreeItemOwner *owner_;

Expand Down
5 changes: 5 additions & 0 deletions pv/views/trace/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,11 @@ void View::set_offset(const pv::util::Timestamp& offset, bool force_update)
}
}

void View::reset_zoom()
{
set_zoom(1e-3, 0);
}

const Timestamp& View::offset() const
{
return offset_;
Expand Down
2 changes: 2 additions & 0 deletions pv/views/trace/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ class View : public ViewBase, public TraceTreeItemOwner, public GlobalSettingsIn

void reset_zero_position();

void reset_zoom();

pv::util::Timestamp zero_offset() const;

/**
Expand Down

0 comments on commit fcc3c20

Please sign in to comment.