From: Joel Holdsworth Date: Mon, 9 Jul 2012 22:23:47 +0000 (+0100) Subject: Added toolbar zoom buttons X-Git-Tag: pulseview-0.1.0~320 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a429590b40f74cebd13986bb1b4c06a4b47d8815;p=pulseview.git Added toolbar zoom buttons --- diff --git a/mainwindow.cpp b/mainwindow.cpp index 0b6f6e15..5ecc14d1 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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); diff --git a/mainwindow.h b/mainwindow.h index 4633aa0e..6a1e52ca 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -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(); diff --git a/sigview.cpp b/sigview.cpp index c46476a3..5601be57 100644 --- a/sigview.cpp +++ b/sigview.cpp @@ -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(); +} diff --git a/sigview.h b/sigview.h index aae9e67e..3630d17e 100644 --- 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();