Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zoom reset option to context menus #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading