PlotZoomer.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include <QMouseEvent>
00020 
00021 #include <qwt/qwt_painter.h>
00022 #include <qwt/qwt_plot_canvas.h>
00023 
00024 #include <rqt_multiplot/PlotZoomerMachine.h>
00025 
00026 #include "rqt_multiplot/PlotZoomer.h"
00027 
00028 namespace rqt_multiplot {
00029 
00030 /*****************************************************************************/
00031 /* Constructors and Destructor                                               */
00032 /*****************************************************************************/
00033 
00034 PlotZoomer::PlotZoomer(QwtPlotCanvas* canvas, bool doReplot) :
00035   QwtPlotZoomer(canvas, doReplot) {
00036   if (canvas)
00037     setStateMachine(new PlotZoomerMachine());
00038 }
00039 
00040 PlotZoomer::~PlotZoomer() {
00041 }
00042 
00043 /*****************************************************************************/
00044 /* Methods                                                                   */
00045 /*****************************************************************************/
00046 
00047 void PlotZoomer::drawRubberBand(QPainter* painter) const {
00048   if (!isActive())
00049     return;
00050 
00051   if ((stateMachine()->selectionType() == QwtPickerMachine::RectSelection) &&
00052       (rubberBand() == RectRubberBand)) {
00053     if (pickedPoints().count() < 2)
00054       return;
00055 
00056     QPoint p1 = pickedPoints()[0];
00057     QPoint p2 = pickedPoints()[pickedPoints().count()-1];
00058 
00059     QRect rect = QRect(p1, p2).normalized();
00060     rect.adjust(0, 0, -1, -1);
00061 
00062     QwtPainter::drawRect(painter, rect);
00063   }
00064   else
00065     QwtPlotZoomer::drawRubberBand(painter);
00066 }
00067 
00068 void PlotZoomer::widgetMousePressEvent(QMouseEvent* event) {
00069   if (mouseMatch(MouseSelect2, event))
00070     position_ = event->pos();
00071 
00072   QwtPlotZoomer::widgetMousePressEvent(event);
00073 }
00074 
00075 void PlotZoomer::widgetMouseReleaseEvent(QMouseEvent* event) {
00076   if (mouseMatch(MouseSelect2, event)) {
00077     if (position_ == event->pos())
00078       zoom(0);
00079   }
00080   else
00081     QwtPlotZoomer::widgetMouseReleaseEvent(event);
00082 }
00083 
00084 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Tue May 9 2017 02:16:02