From f8aaf8b5fc37587b3c4c263a3057e87e1ed9cd01 2013-05-08 08:59:08 From: Miikka Heikkinen Date: 2013-05-08 08:59:08 Subject: [PATCH] Fix chart resize for rotated QChartViews. This only actually produces a nice result for even 90 degree rotations, anything else will have some part of the chart offscreen. Task-number: QTRD-1860 Change-Id: I1b17fb9c30665c736965614531b1985d91e87339 Reviewed-by: Tomi Korpipää Reviewed-by: Mika Salmela --- diff --git a/src/qchartview.cpp b/src/qchartview.cpp index 535f204..56de254 100644 --- a/src/qchartview.cpp +++ b/src/qchartview.cpp @@ -257,9 +257,21 @@ void QChartViewPrivate::setChart(QChart *chart) resize(); } +const qreal rad2deg(57.2957795); + void QChartViewPrivate::resize() { - m_chart->resize(q_ptr->size()); + // Flip chart width and height if the view has been rotated + // more than 45 degrees from the horizontal so it fits better into the view. + qreal angle = acos(q_ptr->transform().m11()) * rad2deg; + QSize chartSize = q_ptr->size(); + + if (angle > 45.0 && angle < 135.0) { + chartSize.setHeight(q_ptr->size().width()); + chartSize.setWidth(q_ptr->size().height()); + } + + m_chart->resize(chartSize); q_ptr->setMinimumSize(m_chart->minimumSize().toSize()); q_ptr->setSceneRect(m_chart->geometry()); }