diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,7 @@ add_executable(${PROGRAM_NAME} WIN32 hidabletabwidget.cpp framebuffer.cpp scalepicker.cpp + scalezoomer.cpp ${UI_FILES} misc/windows_icon.rc ) diff --git a/plot.cpp b/plot.cpp --- a/plot.cpp +++ b/plot.cpp @@ -22,7 +22,7 @@ Plot::Plot(QWidget* parent) : QwtPlot(parent), zoomer(this->canvas(), false), - scalePicker(this->axisWidget(QwtPlot::xBottom)) + sZoomer(this, &zoomer) { isAutoScaled = false; diff --git a/plot.h b/plot.h --- a/plot.h +++ b/plot.h @@ -23,7 +23,7 @@ #include #include #include "zoomer.h" -#include "scalepicker.h" +#include "scalezoomer.h" class Plot : public QwtPlot { @@ -37,8 +37,8 @@ private: bool isAutoScaled; double yMin, yMax; Zoomer zoomer; + ScaleZoomer sZoomer; QwtPlotGrid grid; - ScalePicker scalePicker; void resetAxes(); diff --git a/scalepicker.cpp b/scalepicker.cpp --- a/scalepicker.cpp +++ b/scalepicker.cpp @@ -53,7 +53,6 @@ bool ScalePicker::eventFilter(QObject* o { if (started) { - qDebug() << "Picking:" << firstPos << pos; emit picking(firstPos, pos); } } diff --git a/scalezoomer.cpp b/scalezoomer.cpp new file mode 100644 --- /dev/null +++ b/scalezoomer.cpp @@ -0,0 +1,57 @@ +/* + Copyright © 2015 Hasan Yavuz Özderya + + This file is part of serialplot. + + serialplot is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + serialplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with serialplot. If not, see . +*/ + +#include +#include +#include "scalezoomer.h" + +ScaleZoomer::ScaleZoomer(QwtPlot* plot, QwtPlotZoomer* zoomer) : + QObject(plot), + bottomPicker(plot->axisWidget(QwtPlot::xBottom)), + leftPicker(plot->axisWidget(QwtPlot::yLeft)) +{ + _plot = plot; + _zoomer = zoomer; + connect(&bottomPicker, &ScalePicker::picked, this, &ScaleZoomer::bottomPicked); + connect(&leftPicker, &ScalePicker::picked, this, &ScaleZoomer::leftPicked); +} + +void ScaleZoomer::bottomPicked(double firstPos, double lastPos) +{ + QRectF zRect; + if (lastPos > firstPos) + { + zRect.setLeft(firstPos); + zRect.setRight(lastPos); + } + else + { + zRect.setLeft(lastPos); + zRect.setRight(firstPos); + } + + zRect.setBottom(_plot->axisScaleDiv(QwtPlot::yLeft).lowerBound()); + zRect.setTop(_plot->axisScaleDiv(QwtPlot::yLeft).upperBound()); + _zoomer->zoom(zRect); +} + +void ScaleZoomer::leftPicked(double firstPos, double lastPos) +{ + +} diff --git a/scalezoomer.h b/scalezoomer.h new file mode 100644 --- /dev/null +++ b/scalezoomer.h @@ -0,0 +1,48 @@ +/* + Copyright © 2015 Hasan Yavuz Özderya + + This file is part of serialplot. + + serialplot is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + serialplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with serialplot. If not, see . +*/ + +#ifndef SCALEZOOMER_H +#define SCALEZOOMER_H + +#include +#include +#include + +#include "scalepicker.h" + +class ScaleZoomer : public QObject +{ + Q_OBJECT + +public: + ScaleZoomer(QwtPlot*, QwtPlotZoomer*); + +private: + QwtPlot* _plot; + QwtPlotZoomer* _zoomer; + ScalePicker bottomPicker; + ScalePicker leftPicker; + + +private slots: + void bottomPicked(double firstPos, double lastPos); + void leftPicked(double firstPos, double lastPos); +}; + +#endif /* SCALEZOOMER_H */ diff --git a/serialplot.pro b/serialplot.pro --- a/serialplot.pro +++ b/serialplot.pro @@ -40,7 +40,9 @@ SOURCES += main.cpp\ plot.cpp \ zoomer.cpp \ hidabletabwidget.cpp \ - framebuffer.cpp + framebuffer.cpp \ + scalepicker.cpp \ + scalezoomer.cpp HEADERS += mainwindow.h \ utils.h \ @@ -50,7 +52,9 @@ HEADERS += mainwindow.h \ plot.h \ zoomer.h \ hidabletabwidget.h \ - framebuffer.h + framebuffer.h \ + scalepicker.h \ + scalezoomer.h FORMS += mainwindow.ui \ about_dialog.ui \