Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <QEvent>
00020 #include <QMouseEvent>
00021
00022 #include <qwt/qwt_plot.h>
00023 #include <qwt/qwt_plot_canvas.h>
00024 #include <qwt/qwt_scale_div.h>
00025
00026 #include <ros/package.h>
00027
00028 #include "rqt_multiplot/PlotPanner.h"
00029
00030 namespace rqt_multiplot {
00031
00032
00033
00034
00035
00036 PlotPanner::PlotPanner(QwtPlotCanvas* canvas) :
00037 QObject(canvas),
00038 canvas_(canvas),
00039 panning_(false) {
00040 cursor_ = QCursor(QPixmap(QString::fromStdString(ros::package::getPath(
00041 "rqt_multiplot").append("/resource/23x23/move.png"))), 11, 11);
00042
00043 if (canvas)
00044 canvas->installEventFilter(this);
00045 }
00046
00047 PlotPanner::~PlotPanner() {
00048 }
00049
00050
00051
00052
00053
00054 bool PlotPanner::eventFilter(QObject* object, QEvent* event) {
00055 if (object == canvas_) {
00056 if (!panning_ && (event->type() == QEvent::MouseButtonPress)) {
00057 QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
00058
00059 if (mouseEvent->button() == Qt::LeftButton) {
00060 position_ = mouseEvent->pos();
00061
00062 xMap_ = canvas_->plot()->canvasMap(QwtPlot::xBottom);
00063 yMap_ = canvas_->plot()->canvasMap(QwtPlot::yLeft);
00064
00065 #if QWT_VERSION >= 0x060100
00066 QPointF minimum(
00067 canvas_->plot()->axisScaleDiv(QwtPlot::xBottom).lowerBound(),
00068 canvas_->plot()->axisScaleDiv(QwtPlot::yLeft).lowerBound());
00069 QPointF maximum(
00070 canvas_->plot()->axisScaleDiv(QwtPlot::xBottom).upperBound(),
00071 canvas_->plot()->axisScaleDiv(QwtPlot::yLeft).upperBound());
00072 #else
00073 QPointF minimum(
00074 canvas_->plot()->axisScaleDiv(QwtPlot::xBottom)->lowerBound(),
00075 canvas_->plot()->axisScaleDiv(QwtPlot::yLeft)->lowerBound());
00076 QPointF maximum(
00077 canvas_->plot()->axisScaleDiv(QwtPlot::xBottom)->upperBound(),
00078 canvas_->plot()->axisScaleDiv(QwtPlot::yLeft)->upperBound());
00079 #endif
00080
00081 bounds_.setMinimum(minimum);
00082 bounds_.setMaximum(maximum);
00083
00084 canvasCursor_ = canvas_->cursor();
00085 canvas_->setCursor(cursor_);
00086
00087 panning_ = true;
00088 }
00089 }
00090 else if (panning_ && (event->type() == QEvent::MouseMove)) {
00091 QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
00092
00093 double dx = mouseEvent->pos().x()-position_.x();
00094 double dy = mouseEvent->pos().y()-position_.y();
00095
00096 QPointF minimum(
00097 xMap_.invTransform(xMap_.transform(bounds_.getMinimum().x())-dx),
00098 yMap_.invTransform(yMap_.transform(bounds_.getMinimum().y())-dy));
00099 QPointF maximum(
00100 xMap_.invTransform(xMap_.transform(bounds_.getMaximum().x())-dx),
00101 yMap_.invTransform(yMap_.transform(bounds_.getMaximum().y())-dy));
00102
00103 bool autoReplot = canvas_->plot()->autoReplot();
00104 canvas_->plot()->setAutoReplot(false);
00105
00106 canvas_->plot()->setAxisScale(QwtPlot::xBottom, minimum.x(),
00107 maximum.x());
00108 canvas_->plot()->setAxisScale(QwtPlot::yLeft, minimum.y(),
00109 maximum.y());
00110
00111 canvas_->plot()->setAutoReplot(autoReplot);
00112 canvas_->plot()->replot();
00113 }
00114 else if (panning_ && (event->type() == QEvent::MouseButtonRelease)) {
00115 canvas_->setCursor(canvasCursor_);
00116
00117 panning_ = false;
00118 }
00119 }
00120
00121 return false;
00122 }
00123
00124 }