void LineProfileTool::addLineMarker(const QPoint &start, const QPoint &end) { ArrowMarker *mrk = new ArrowMarker(); mrk->attach(d_graph->plotWidget()); mrk->setStartPoint(start); mrk->setEndPoint(end); mrk->setColor(Qt::red); mrk->setWidth(1); mrk->setStyle(Qt::SolidLine); mrk->drawEndArrow(false); mrk->drawStartArrow(false); d_graph->addArrow(mrk); mrk->detach(); d_graph->replot(); }
bool CanvasPicker::selectMarker(const QMouseEvent *e) { Graph *g = plot(); const QPoint point = e->pos(); QList<QwtPlotMarker *> lines = g->linesList(); foreach(QwtPlotMarker *i, lines){ ArrowMarker* mrkL = (ArrowMarker*)i; int d = qRound(mrkL->width() + floor(mrkL->headLength()*tan(M_PI*mrkL->headAngle()/180.0)+0.5)); double dist = mrkL->dist(point.x(), point.y()); if (dist <= d){ disableEditing(); if (e->modifiers() & Qt::ShiftModifier) { plot()->setSelectedMarker(i, true); return true; } else if (e->button() == Qt::RightButton) { mrkL->setEditable(false); g->setSelectedMarker(i, true); return true; } g->deselectMarker(); mrkL->setEditable(true); g->setSelectedMarker(i, false); d_editing_marker = mrkL; return true; } }
bool CanvasPicker::eventFilter(QObject *object, QEvent *e) { QVector<int> images = plot()->imageMarkerKeys(); QVector<int> lines = plot()->lineMarkerKeys(); if (object != (QObject *)plot()->plotWidget()->canvas()) return false; switch(e->type()) { case QEvent::MouseButtonPress: { plot()->deselect(); emit selectPlot(); const QMouseEvent *me = (const QMouseEvent *)e; bool allAxisDisabled = true; for (int i=0; i < QwtPlot::axisCnt; i++){ if (plotWidget->axisEnabled(i)){ allAxisDisabled = false; break; } } int dist, point; plotWidget->closestCurve(me->pos().x(), me->pos().y(), dist, point); if (me->button() == Qt::LeftButton && (plot()->drawLineActive())){ startLinePoint = me->pos(); return true; } if (me->button() == Qt::LeftButton && plot()->drawTextActive()){ drawTextMarker(me->pos()); return true; } if (!plot()->zoomOn() && selectMarker(me)){ if (me->button() == Qt::RightButton) emit showMarkerPopupMenu(); return true; } return !(me->modifiers() & Qt::ShiftModifier); } break; case QEvent::MouseButtonDblClick: { if (d_editing_marker) { return d_editing_marker->eventFilter(plotWidget->canvas(), e); } else if (plot()->selectedMarkerKey() >= 0) { if (lines.contains(plot()->selectedMarkerKey())){ emit viewLineDialog(); return true; } else if (images.contains(plot()->selectedMarkerKey())){ emit viewImageDialog(); return true; } } else if (plot()->isPiePlot()){ emit showPlotDialog(plot()->curveKey(0)); return true; } else { const QMouseEvent *me = (const QMouseEvent *)e; int dist, point; int curveKey = plotWidget->closestCurve(me->pos().x(), me->pos().y(), dist, point); if (dist < 10) emit showPlotDialog(curveKey); else emit showPlotDialog(-1); return true; } } break; case QEvent::MouseMove: { const QMouseEvent *me = (const QMouseEvent *)e; if (me->state() != Qt::LeftButton) return true; QPoint pos = me->pos(); DataCurve *c = plot()->selectedCurveLabels(); if (c){ c->moveLabels(pos); return true; } if (plot()->drawLineActive()) { drawLineMarker(pos, plot()->drawArrow()); return true; } return false; } break; case QEvent::MouseButtonRelease: { const QMouseEvent *me = (const QMouseEvent *)e; Graph *g = plot(); if (g->drawLineActive()) { ApplicationWindow *app = g->multiLayer()->applicationWindow(); if (!app) return true; ArrowMarker mrk; mrk.attach(g->plotWidget()); mrk.setStartPoint(startLinePoint); mrk.setEndPoint(QPoint(me->x(), me->y())); mrk.setColor(app->defaultArrowColor); mrk.setWidth(app->defaultArrowLineWidth); mrk.setStyle(app->defaultArrowLineStyle); mrk.setHeadLength(app->defaultArrowHeadLength); mrk.setHeadAngle(app->defaultArrowHeadAngle); mrk.fillArrowHead(app->defaultArrowHeadFill); mrk.drawEndArrow(g->drawArrow()); mrk.drawStartArrow(false); g->addArrow(&mrk); g->drawLine(false); mrk.detach(); plotWidget->replot(); return true; } /*if(plot()->zoomOn()) { //fix for colormap changing on releasing the mouse button after zooming Graph * gr=plot(); if(!gr) return NULL; Spectrogram * spectrogram=gr->getSpectrogram(); if(spectrogram) spectrogram->setupColorBarScaling(); }*/ return false; } break; case QEvent::KeyPress: { int key=((const QKeyEvent *)e)->key(); int selectedMarker = plot()->selectedMarkerKey(); if (lines.contains(selectedMarker) && (key==Qt::Key_Enter || key==Qt::Key_Return)) { emit viewLineDialog(); return true; } if (images.contains(selectedMarker) && (key==Qt::Key_Enter || key==Qt::Key_Return)) { emit viewImageDialog(); return true; } } break; default: break; } return QObject::eventFilter(object, e); }
void CanvasPicker::drawLineMarker(const QPoint& point, bool endArrow) { plot()->plotWidget()->canvas()->repaint(); ArrowMarker mrk; mrk.attach(plotWidget); int clw = plotWidget->canvas()->lineWidth(); mrk.setStartPoint(QPoint(startLinePoint.x() + clw, startLinePoint.y() + clw)); mrk.setEndPoint(QPoint(point.x() + clw,point.y() + clw)); mrk.setWidth(1); mrk.setStyle(Qt::SolidLine); mrk.drawEndArrow(endArrow); mrk.drawStartArrow(false); if (plot()->drawLineActive()) mrk.setColor(Qt::black); else mrk.setColor(Qt::red); plotWidget->replot(); mrk.detach(); }
bool CanvasPicker::eventFilter(QObject *object, QEvent *e) { if (object != (QObject *)plot()->canvas()) return false; Graph *g = plot(); QList<QwtPlotMarker *> lines = g->linesList(); switch(e->type()) { case QEvent::MouseButtonPress: { const QMouseEvent *me = (const QMouseEvent *)e; if (!(me->modifiers() & Qt::ShiftModifier)) g->deselect(); emit selectPlot(); bool allAxisDisabled = true; for (int i=0; i < QwtPlot::axisCnt; i++){ if (g->axisEnabled(i)){ allAxisDisabled = false; break; } } int dist, point; g->closestCurve(me->pos().x(), me->pos().y(), dist, point); if (me->button() == Qt::LeftButton && (g->drawLineActive())){ startLinePoint = me->pos(); return true; } if (!g->zoomOn() && selectMarker(me)){ if (me->button() == Qt::RightButton) emit showMarkerPopupMenu(); return true; } return !(me->modifiers() & Qt::ShiftModifier); } break; case QEvent::MouseButtonDblClick: { if (d_editing_marker) { return d_editing_marker->eventFilter(g->canvas(), e); } else if (g->selectedMarker()) { if (lines.contains(g->selectedMarker())){ emit viewLineDialog(); return true; } } else if (g->isPiePlot()){ emit showPlotDialog(0); return true; } else { const QMouseEvent *me = (const QMouseEvent *)e; int dist, point; QwtPlotCurve *c = g->closestCurve(me->pos().x(), me->pos().y(), dist, point); if (c && dist < 10) emit showPlotDialog(g->curveIndex(c)); else emit showPlotDialog(-1); return true; } } break; case QEvent::MouseMove: { const QMouseEvent *me = (const QMouseEvent *)e; if (me->state() != Qt::LeftButton) return true; QPoint pos = me->pos(); DataCurve *c = g->selectedCurveLabels(); if (c){ c->moveLabels(pos); return true; } if (plot()->drawLineActive()) { drawLineMarker(pos, g->drawArrow()); return true; } return false; } break; case QEvent::MouseButtonRelease: { const QMouseEvent *me = (const QMouseEvent *)e; if (g->drawLineActive()) { ApplicationWindow *app = g->multiLayer()->applicationWindow(); if (!app) return true; ArrowMarker mrk; mrk.attach(g); mrk.setStartPoint(startLinePoint); mrk.setEndPoint(QPoint(me->x(), me->y())); mrk.setColor(app->defaultArrowColor); mrk.setWidth(app->defaultArrowLineWidth); mrk.setStyle(app->defaultArrowLineStyle); mrk.setHeadLength(app->defaultArrowHeadLength); mrk.setHeadAngle(app->defaultArrowHeadAngle); mrk.fillArrowHead(app->defaultArrowHeadFill); mrk.drawEndArrow(g->drawArrow()); mrk.drawStartArrow(false); g->addArrow(&mrk); g->drawLine(false); mrk.detach(); g->replot(); return true; } return false; } break; case QEvent::KeyPress: { int key = ((const QKeyEvent *)e)->key(); QwtPlotMarker *selectedMarker = g->selectedMarker(); if (lines.contains(selectedMarker) && (key == Qt::Key_Enter || key == Qt::Key_Return)){ emit viewLineDialog(); return true; } } break; default: break; } return QObject::eventFilter(object, e); }