PlotZoomer.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
19 #include <QMouseEvent>
20 
21 #include <qwt/qwt_painter.h>
22 #include <qwt/qwt_plot_canvas.h>
23 
25 
27 
28 namespace rqt_multiplot {
29 
30 /*****************************************************************************/
31 /* Constructors and Destructor */
32 /*****************************************************************************/
33 
34 PlotZoomer::PlotZoomer(QwtPlotCanvas* canvas, bool doReplot) :
35  QwtPlotZoomer(canvas, doReplot) {
36  if (canvas)
37  setStateMachine(new PlotZoomerMachine());
38 }
39 
41 }
42 
43 /*****************************************************************************/
44 /* Methods */
45 /*****************************************************************************/
46 
47 void PlotZoomer::drawRubberBand(QPainter* painter) const {
48  if (!isActive())
49  return;
50 
51  if ((stateMachine()->selectionType() == QwtPickerMachine::RectSelection) &&
52  (rubberBand() == RectRubberBand)) {
53  if (pickedPoints().count() < 2)
54  return;
55 
56  QPoint p1 = pickedPoints()[0];
57  QPoint p2 = pickedPoints()[pickedPoints().count()-1];
58 
59  QRect rect = QRect(p1, p2).normalized();
60  rect.adjust(0, 0, -1, -1);
61 
62  QwtPainter::drawRect(painter, rect);
63  }
64  else
65  QwtPlotZoomer::drawRubberBand(painter);
66 }
67 
68 void PlotZoomer::widgetMousePressEvent(QMouseEvent* event) {
69  if (mouseMatch(MouseSelect2, event))
70  position_ = event->pos();
71 
72  QwtPlotZoomer::widgetMousePressEvent(event);
73 }
74 
75 void PlotZoomer::widgetMouseReleaseEvent(QMouseEvent* event) {
76  if (mouseMatch(MouseSelect2, event)) {
77  if (position_ == event->pos())
78  zoom(0);
79  }
80  else
81  QwtPlotZoomer::widgetMouseReleaseEvent(event);
82 }
83 
84 }
void widgetMouseReleaseEvent(QMouseEvent *event)
Definition: PlotZoomer.cpp:75
void drawRubberBand(QPainter *painter) const
Definition: PlotZoomer.cpp:47
PlotZoomer(QwtPlotCanvas *canvas, bool doReplot=true)
Definition: PlotZoomer.cpp:34
void widgetMousePressEvent(QMouseEvent *event)
Definition: PlotZoomer.cpp:68


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44