From 25b2e1c316cb9e71b320a1f6c0c757608ba908f1 2013-02-07 12:43:04 From: Miikka Heikkinen Date: 2013-02-07 12:43:04 Subject: [PATCH] Fix zooming when presenter dimensions are not integers If presenter width (or height) is not an integer, zooming using vertical (or horizontal) rubberband will cause the fixed dimension to change, because rubberband uses QRect instead of QRectF. Fixed by forcing the corresponding plotArea dimension for the fixed rubberband dimension when calling zoomIn() in mouseReleaseEvent. Task-number: QTRD-1905 Reviewed-by: Mika Salmela --- diff --git a/src/qchartview.cpp b/src/qchartview.cpp index 52d7d26..82d6b1d 100644 --- a/src/qchartview.cpp +++ b/src/qchartview.cpp @@ -180,7 +180,17 @@ void QChartView::mouseReleaseEvent(QMouseEvent *event) if (d_ptr->m_rubberBand) { if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { d_ptr->m_rubberBand->hide(); - QRect rect = d_ptr->m_rubberBand->geometry(); + QRectF rect = d_ptr->m_rubberBand->geometry(); + // Since plotArea uses QRectF and rubberband uses QRect, we can't just blindly use + // rubberband's dimensions for vertical and horizontal rubberbands, where one + // dimension must match the corresponding plotArea dimension exactly. + if (d_ptr->m_rubberBandFlags == VerticalRubberBand) { + rect.setX(d_ptr->m_chart->plotArea().x()); + rect.setWidth(d_ptr->m_chart->plotArea().width()); + } else if (d_ptr->m_rubberBandFlags == HorizonalRubberBand) { + rect.setY(d_ptr->m_chart->plotArea().y()); + rect.setHeight(d_ptr->m_chart->plotArea().height()); + } d_ptr->m_chart->zoomIn(rect); event->accept(); }