##// END OF EJS Templates
Fix ChartView rotations for non-90 degree steps....
Miikka Heikkinen -
r2507:470a55f27ca3
parent child
Show More
@@ -23,7 +23,6
23 #include "qchart_p.h"
23 #include "qchart_p.h"
24 #include <QGraphicsScene>
24 #include <QGraphicsScene>
25 #include <QRubberBand>
25 #include <QRubberBand>
26 #include <qmath.h>
27
26
28 /*!
27 /*!
29 \enum QChartView::RubberBand
28 \enum QChartView::RubberBand
@@ -258,18 +257,22 void QChartViewPrivate::setChart(QChart *chart)
258 resize();
257 resize();
259 }
258 }
260
259
261 const qreal rad2deg(57.2957795);
262
263 void QChartViewPrivate::resize()
260 void QChartViewPrivate::resize()
264 {
261 {
265 // Flip chart width and height if the view has been rotated
262 // Fit the chart into view if it has been rotated
266 // more than 45 degrees from the horizontal so it fits better into the view.
263 qreal sinA = qAbs(q_ptr->transform().m21());
267 qreal angle = qAcos(q_ptr->transform().m11()) * rad2deg;
264 qreal cosA = qAbs(q_ptr->transform().m11());
268 QSize chartSize = q_ptr->size();
265 QSize chartSize = q_ptr->size();
269
266
270 if (angle > 45.0 && angle < 135.0) {
267 if (sinA == 1.0) {
271 chartSize.setHeight(q_ptr->size().width());
268 chartSize.setHeight(q_ptr->size().width());
272 chartSize.setWidth(q_ptr->size().height());
269 chartSize.setWidth(q_ptr->size().height());
270 } else if (sinA != 0.0) {
271 // Non-90 degree rotation, find largest square chart that can fit into the view.
272 qreal minDimension = qMin(q_ptr->size().width(), q_ptr->size().height());
273 qreal h = (minDimension - (minDimension / ((sinA / cosA) + 1.0))) / sinA;
274 chartSize.setHeight(h);
275 chartSize.setWidth(h);
273 }
276 }
274
277
275 m_chart->resize(chartSize);
278 m_chart->resize(chartSize);
General Comments 0
You need to be logged in to leave comments. Login now