void SingleCellViewGraphPanelPlotWidget::mouseReleaseEvent(QMouseEvent *pEvent) { // Default handling of the event QwtPlot::mouseReleaseEvent(pEvent); // Check that interaction is allowed if (!mInteractive) return; // Check whether we need to carry out an action if (mAction == None) return; // Keep track of the action to carry out // Note: this is so that we can reset mAction while still being able to // finish carrying out the action... Action action = mAction; // We are done carrying out an action, so... mAction = None; // Finish carrying out the action switch (action) { case ShowCoordinates: // Remove the coordinates by replotting ourselves replotNow(); break; case ZoomRegion: { // Zoom our region QRectF zoomRegionRect = zoomRegion(); setLocalAxes(zoomRegionRect.left(), zoomRegionRect.right(), zoomRegionRect.bottom(), zoomRegionRect.top()); break; } default: // Another action which needs nothing more to be done ; } }
void SingleCellViewGraphPanelPlotWidget::drawCanvas(QPainter *pPainter) { foreach (SingleCellViewGraphPanelPlotCurve *curve, mCurves) static_cast<SingleCellViewQwtCurveDataAdaptor*>(curve->data())->updateSize(); switch (mAction) { case ShowCoordinates: { // We are showing some coordinates, so start by drawing our pixmap pPainter->drawPixmap(0, 0, mCanvasPixmap); // Draw the two dashed lines that show the coordinates, using a dark // cyan pen QPen pen = pPainter->pen(); QColor backgroundColor = Qt::darkCyan; backgroundColor.setAlphaF(0.69); pen.setColor(backgroundColor); pen.setStyle(Qt::DashLine); pPainter->setPen(pen); QPointF coordinates = QPointF(canvasMap(QwtPlot::xBottom).transform(mOriginPoint.x()), canvasMap(QwtPlot::yLeft).transform(mOriginPoint.y())); pPainter->drawLine(0.0, coordinates.y(), plotLayout()->canvasRect().width(), coordinates.y()); pPainter->drawLine(coordinates.x(), 0.0, coordinates.x(), plotLayout()->canvasRect().height()); // Draw the coordinates drawCoordinates(pPainter, mOriginPoint, backgroundColor, Qt::white); break; } case ZoomRegion: { // We are zooming a region, so start by drawing our pixmap pPainter->drawPixmap(0, 0, mCanvasPixmap); // Retrieve the coordinates of the region to be zoomed QRectF zoomRegionRect = zoomRegion(); // Now, draw the region to be zoomed QColor penColor = Qt::darkRed; QColor brushColor = Qt::yellow; penColor.setAlphaF(0.69); brushColor.setAlphaF(0.19); pPainter->setPen(penColor); QwtScaleMap canvasMapX = canvasMap(QwtPlot::xBottom); QwtScaleMap canvasMapY = canvasMap(QwtPlot::yLeft); double left = canvasMapX.transform(zoomRegionRect.left()); double top = canvasMapY.transform(zoomRegionRect.top()); QRectF unmappedZoomRegionRect = QRectF(left, top, canvasMapX.transform(zoomRegionRect.right())-left, canvasMapY.transform(zoomRegionRect.bottom())-top); pPainter->fillRect(unmappedZoomRegionRect, brushColor); pPainter->drawRect(unmappedZoomRegionRect); // Draw the two sets of coordinates drawCoordinates(pPainter, zoomRegionRect.topLeft(), penColor, Qt::white, BottomRight, false); drawCoordinates(pPainter, zoomRegionRect.bottomRight(), penColor, Qt::white, TopLeft, false); break; } default: // We aren't doing anything special, so just draw our canvas normally QwtPlot::drawCanvas(pPainter); } }
void ImageView::mouseReleaseEvent(QMouseEvent *event) { switch (m_mouseMode) { case MM_ZOOM: m_rubberBand->hide(); if (m_rubberBand->geometry().isNull()) { /* Zoom step. */ int newCenterX, newCenterY; int x = event->x(); int y = event->y(); if (event->modifiers() & Qt::ControlModifier) { this->zoomOut(); if (m_zoomLevel != 1) { newCenterX = (int)(x * (this->m_zoomLevel - 1.0) / this->m_zoomLevel); newCenterY = (int)(y * (this->m_zoomLevel - 1.0) / this->m_zoomLevel); emit viewCenterChanged(newCenterX, newCenterY); if (visibleRegion().contains(event->pos())) { this->canvasToImage(x, y); emit mousePosChanged(x, y); } else { emit mousePosChanged(-1, -1); } } } else if (event->modifiers() == Qt::ShiftModifier) { this->setZoomLevel(1.0f); } else { this->zoomIn(); newCenterX = (int)(x * (this->m_zoomLevel + 1.0) / this->m_zoomLevel); newCenterY = (int)(y * (this->m_zoomLevel + 1.0) / this->m_zoomLevel); emit viewCenterChanged(newCenterX, newCenterY); if (visibleRegion().contains(event->pos())) { this->canvasToImage(x, y); emit mousePosChanged(x, y); } else { emit mousePosChanged(-1, -1); } } } else { /* Lasso zoom. */ if (!(event->modifiers() & Qt::ControlModifier)) { zoomRegion(m_rubberBand->geometry()); } } break; case MM_MINMAX: { QRect selRect = this->m_minMaxLens->geometry(); //QRect visRect = this->visibleRegion().boundingRect(); selRect.moveLeft(selRect.left() / this->m_zoomLevel); selRect.moveTop(selRect.top() / this->m_zoomLevel); selRect.setWidth(::ceilf(static_cast<float>(selRect.width()) / this->m_zoomLevel)); selRect.setHeight(::ceilf(static_cast<float>(selRect.height()) / this->m_zoomLevel)); emit minMaxAreaChanged(selRect); this->m_minMaxLens->setVisible(false); if (event->modifiers() & Qt::ControlModifier) { emit setMappingBounds(); } } break; default: break; } }