]> sigrok.org Git - pulseview.git/commitdiff
Added toolbar zoom buttons
authorJoel Holdsworth <redacted>
Mon, 9 Jul 2012 22:23:47 +0000 (23:23 +0100)
committerJoel Holdsworth <redacted>
Mon, 3 Sep 2012 12:59:06 +0000 (13:59 +0100)
mainwindow.cpp
mainwindow.h
sigview.cpp
sigview.h

index 0b6f6e1567672e07ea066eac1c04018549cb106f..5ecc14d11c995990ecde6325c6aa2ecb903e352d 100644 (file)
@@ -68,6 +68,15 @@ void MainWindow::setup_ui()
        // Setup the UI actions
        _action_about = new QAction(this);
        _action_about->setObjectName(QString::fromUtf8("actionAbout"));
+
+       _action_view_zoom_in = new QAction(this);
+       _action_view_zoom_in->setIcon(QIcon::fromTheme("zoom-in"));
+       _action_view_zoom_in->setObjectName(QString::fromUtf8("actionViewZoomIn"));
+
+       _action_view_zoom_out = new QAction(this);
+       _action_view_zoom_out->setIcon(QIcon::fromTheme("zoom-out"));
+       _action_view_zoom_out->setObjectName(QString::fromUtf8("actionViewZoomOut"));
+
        _action_open = new QAction(this);
        _action_open->setIcon(QIcon::fromTheme("document-open"));
        _action_open->setObjectName(QString::fromUtf8("actionOpen"));
@@ -79,10 +88,15 @@ void MainWindow::setup_ui()
        _menu_file = new QMenu(_menu_bar);
        _menu_file->addAction(_action_open);
 
+       _menu_view = new QMenu(_menu_bar);
+       _menu_view->addAction(_action_view_zoom_in);
+       _menu_view->addAction(_action_view_zoom_out);
+
        _menu_help = new QMenu(_menu_bar);
        _menu_help->addAction(_action_about);
 
        _menu_bar->addAction(_menu_file->menuAction());
+       _menu_bar->addAction(_menu_view->menuAction());
        _menu_bar->addAction(_menu_help->menuAction());
 
        setMenuBar(_menu_bar);
@@ -91,6 +105,9 @@ void MainWindow::setup_ui()
        // Setup the toolbars
        _toolbar = new QToolBar(this);
        _toolbar->addAction(_action_open);
+       _toolbar->addSeparator();
+       _toolbar->addAction(_action_view_zoom_in);
+       _toolbar->addAction(_action_view_zoom_out);
        addToolBar(_toolbar);
 
        _sampling_bar = new SamplingBar(this);
@@ -111,8 +128,12 @@ void MainWindow::setup_ui()
 
        setWindowTitle(QApplication::translate("MainWindow", "sigrok-qt2", 0, QApplication::UnicodeUTF8));
        _action_open->setText(QApplication::translate("MainWindow", "&Open...", 0, QApplication::UnicodeUTF8));
+       _action_view_zoom_in->setText(QApplication::translate("MainWindow", "Zoom &In", 0, QApplication::UnicodeUTF8));
+       _action_view_zoom_out->setText(QApplication::translate("MainWindow", "Zoom &Out", 0, QApplication::UnicodeUTF8));
        _action_about->setText(QApplication::translate("MainWindow", "&About...", 0, QApplication::UnicodeUTF8));
+
        _menu_file->setTitle(QApplication::translate("MainWindow", "&File", 0, QApplication::UnicodeUTF8));
+       _menu_view->setTitle(QApplication::translate("MainWindow", "&View", 0, QApplication::UnicodeUTF8));
        _menu_help->setTitle(QApplication::translate("MainWindow", "&Help", 0, QApplication::UnicodeUTF8));
 
        _view = new SigView(_session, this);
@@ -127,6 +148,16 @@ void MainWindow::on_actionOpen_triggered()
        _session.load_file(file_name.toStdString());
 }
 
+void MainWindow::on_actionViewZoomIn_triggered()
+{
+       _view->zoom(1);
+}
+
+void MainWindow::on_actionViewZoomOut_triggered()
+{
+       _view->zoom(-1);
+}
+
 void MainWindow::on_actionAbout_triggered()
 {
        About dlg(this);
index 4633aa0e245426b6c0a72a6b1ec4582c544cc418..6a1e52ca2d8ddd3a5e3264f3bd37f842a5081cb3 100644 (file)
@@ -52,15 +52,17 @@ private:
 
 private:
 
-
        SigSession _session;
        SigView *_view;
 
        QAction *_action_open;
+       QAction *_action_view_zoom_in;
+       QAction *_action_view_zoom_out;
        QAction *_action_about;
 
        QMenuBar *_menu_bar;
        QMenu *_menu_file;
+       QMenu *_menu_view;
        QMenu *_menu_help;
 
        QWidget *_central_widget;
@@ -74,6 +76,10 @@ private slots:
 
        void on_actionOpen_triggered();
 
+       void on_actionViewZoomIn_triggered();
+
+       void on_actionViewZoomOut_triggered();
+
        void on_actionAbout_triggered();
 
        void run_stop();
index c46476a30f386920b799e68580b1c31f4c0b2cf2..5601be575d722df78302897fa19965fe3280464e 100644 (file)
@@ -62,6 +62,11 @@ SigView::SigView(SigSession &session, QWidget *parent) :
        setAutoFillBackground(false);
 }
 
+void SigView::zoom(double steps)
+{
+       zoom(steps, (width() - LabelMarginWidth) / 2);
+}
+
 void SigView::initializeGL()
 {
 }
@@ -164,13 +169,7 @@ void SigView::mouseReleaseEvent(QMouseEvent *event)
 void SigView::wheelEvent(QWheelEvent *event)
 {
        assert(event);
-
-       const double x = event->x() - LabelMarginWidth;
-       const double cursor_offset = _offset + _scale * x;
-       _scale *= powf(3.0/2.0, -event->delta() / 120);
-       _scale = max(min(_scale, MaxScale), MinScale);
-       _offset = cursor_offset - _scale * x;
-       update();
+       zoom(event->delta() / 120, event->x() - LabelMarginWidth);
 }
 
 void SigView::setup_viewport(int width, int height)
@@ -243,3 +242,12 @@ void SigView::paint_ruler(QPainter &p)
                division++;
        }
 }
+
+void SigView::zoom(double steps, int offset)
+{
+       const double cursor_offset = _offset + _scale * offset;
+       _scale *= pow(3.0/2.0, -steps);
+       _scale = max(min(_scale, MaxScale), MinScale);
+       _offset = cursor_offset - _scale * offset;
+       update();
+}
index aae9e67e37c7d4fb4b837989df63ade658f62709..3630d17e572cfe074a893d7463370d0af4148a3e 100644 (file)
--- a/sigview.h
+++ b/sigview.h
@@ -49,6 +49,8 @@ private:
 public:
        explicit SigView(SigSession &session, QWidget *parent = 0);
 
+       void zoom(double steps);
+
 protected:
 
        void initializeGL();
@@ -68,6 +70,8 @@ private:
 
        void paint_ruler(QPainter &p);
 
+       void zoom(double steps, int offset);
+
 private slots:
        void data_updated();