<file>icons/trigger-low.svg</file>
<file>icons/trigger-none.svg</file>
<file>icons/trigger-rising.svg</file>
+ <file>icons/zoom-fit.png</file>
<file>icons/zoom-in.png</file>
<file>icons/zoom-out.png</file>
</qresource>
QString::fromUtf8("actionViewZoomOut"));
menu_view->addAction(action_view_zoom_out);
+ QAction *const action_view_zoom_fit = new QAction(this);
+ action_view_zoom_fit->setText(QApplication::translate(
+ "MainWindow", "Zoom to &Fit", 0, QApplication::UnicodeUTF8));
+ action_view_zoom_fit->setIcon(QIcon::fromTheme("zoom-fit",
+ QIcon(":/icons/zoom-fit.png")));
+ action_view_zoom_fit->setShortcut(QKeySequence(Qt::Key_F));
+ action_view_zoom_fit->setObjectName(
+ QString::fromUtf8("actionViewZoomFit"));
+ menu_view->addAction(action_view_zoom_fit);
+
menu_view->addSeparator();
QAction *action_view_show_cursors = new QAction(this);
toolbar->addSeparator();
toolbar->addAction(action_view_zoom_in);
toolbar->addAction(action_view_zoom_out);
+ toolbar->addAction(action_view_zoom_fit);
addToolBar(toolbar);
// Setup the sampling bar
_view->zoom(-1);
}
+void MainWindow::on_actionViewZoomFit_triggered()
+{
+ _view->zoom_fit();
+}
+
void MainWindow::on_actionViewShowCursors_triggered()
{
assert(_view);
void on_actionViewZoomOut_triggered();
+ void on_actionViewZoomFit_triggered();
+
void on_actionViewShowCursors_triggered();
void on_actionAbout_triggered();
#include <limits.h>
#include <math.h>
+#include <set>
+
#include <boost/foreach.hpp>
#include <QEvent>
set_scale_offset(new_scale, new_offset);
}
+void View::zoom_fit()
+{
+ using pv::data::SignalData;
+
+ const vector< shared_ptr<Signal> > sigs(
+ session().get_signals());
+
+ // Make a set of all the visible data objects
+ set< shared_ptr<SignalData> > visible_data;
+ BOOST_FOREACH(const shared_ptr<Signal> sig, sigs)
+ if (sig->enabled())
+ visible_data.insert(sig->data());
+
+ if (visible_data.empty())
+ return;
+
+ double left_time = DBL_MAX, right_time = DBL_MIN;
+ BOOST_FOREACH(const shared_ptr<SignalData> d, visible_data)
+ {
+ const double start_time = d->get_start_time();
+ left_time = min(left_time, start_time);
+ right_time = max(right_time, start_time +
+ d->get_max_sample_count() / d->get_samplerate());
+ }
+
+ assert(left_time < right_time);
+ if (right_time - left_time < 1e-12)
+ return;
+
+ assert(_viewport);
+ const int w = _viewport->width();
+ if (w <= 0)
+ return;
+
+ set_scale_offset((right_time - left_time) / w, left_time);
+}
+
void View::set_scale_offset(double scale, double offset)
{
_scale = scale;
void zoom(double steps);
void zoom(double steps, int offset);
+ void zoom_fit();
+
/**
* Sets the scale and offset.
* @param scale The new view scale in seconds per pixel.