MCPcopy Create free account
hub / github.com/IENT/YUView / convertPixelPosToPlotPos

Method convertPixelPosToPlotPos

YUViewLib/src/ui/views/PlotViewWidget.cpp:989–1024  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

987}
988
989QPointF PlotViewWidget::convertPixelPosToPlotPos(const QPointF & pixelPos,
990 std::optional<double> zoomFactor) const
991{
992 if (!zoomFactor)
993 zoomFactor = this->zoomFactor;
994
995 Range<double> yRange = {0, 100};
996 if (this->model)
997 yRange = this->model->getYRange();
998 const auto rangeY = double(yRange.max - yRange.min);
999
1000 const auto valueX =
1001 ((pixelPos.x() - this->propertiesAxis[0].line.p1().x() - this->moveOffset.x()) /
1002 (*zoomFactor)) /
1003 this->zoomToPixelsPerValueX;
1004
1005 // line.p1 maps to the maximum y value and line.p2 to the lowest value
1006 if (this->fixYAxis)
1007 {
1008 const auto lineLength =
1009 this->propertiesAxis[1].line.p1().y() - this->propertiesAxis[1].line.p2().y();
1010 const double relativePos = (this->propertiesAxis[1].line.p1().y() - pixelPos.y()) / lineLength;
1011 const auto valueY = yRange.min + relativePos * rangeY;
1012 return {valueX, valueY};
1013 }
1014 else
1015 {
1016 const auto zoomToPixelsPerValueY =
1017 (this->propertiesAxis[1].line.p1().y() - this->propertiesAxis[1].line.p2().y()) / rangeY;
1018 const auto valueY =
1019 ((-pixelPos.y() + this->propertiesAxis[1].line.p1().y() + this->moveOffset.y()) /
1020 (*zoomFactor)) /
1021 zoomToPixelsPerValueY;
1022 return {valueX, valueY};
1023 }
1024}
1025
1026void PlotViewWidget::onZoomRectUpdateOffsetAndZoom(QRectF zoomRect, double additionalZoomFactor)
1027{

Callers 5

zoomToFitInternalMethod · 0.95
mouseMoveEventMethod · 0.95
drawLimitsMethod · 0.95
drawPlotMethod · 0.95
getAxisRangeMethod · 0.95

Calls 1

getYRangeMethod · 0.45

Tested by

no test coverage detected