From fcf207f30c3f26fae324a21934af44c3cad4d9c0 2012-04-04 10:16:43 From: Michal Klocek Date: 2012-04-04 10:16:43 Subject: [PATCH] Increses margins prescision --- diff --git a/src/chartpresenter_p.h b/src/chartpresenter_p.h index 7e0637a..187a524 100644 --- a/src/chartpresenter_p.h +++ b/src/chartpresenter_p.h @@ -84,7 +84,7 @@ public: //TODO: fix me void resetAllElements(); void createChartBackgroundItem(); void createChartTitleItem(); - QRect margins() const { return m_chartMargins;} + QRectF margins() const { return m_chartMargins;} public Q_SLOTS: void handleSeriesAdded(QSeries* series,Domain* domain); @@ -116,8 +116,8 @@ public: //TODO: fixme int m_marginBig; int m_marginSmall; int m_marginTiny; - QRect m_chartMargins; - QRect m_legendMargins; + QRectF m_chartMargins; + QRectF m_legendMargins; }; diff --git a/src/qchart.cpp b/src/qchart.cpp index b94dc4c..aed22d4 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -275,7 +275,7 @@ QLegend* QChart::legend() const return d_ptr->m_legend; } -QRect QChart::margins() const +QRectF QChart::margins() const { return d_ptr->m_presenter->margins(); } diff --git a/src/qchart.h b/src/qchart.h index 1172055..9ca4bc1 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -76,6 +76,7 @@ public: QFont titleFont() const; void setTitleBrush(const QBrush &brush); QBrush titleBrush() const; + void setBackgroundBrush(const QBrush &brush); QBrush backgroundBrush() const; void setBackgroundPen(const QPen &pen); @@ -99,7 +100,7 @@ public: QChartAxis* axisY() const; QLegend* legend() const; - QRect margins() const; + QRectF margins() const; protected: void resizeEvent(QGraphicsSceneResizeEvent *event); diff --git a/src/qchartview.cpp b/src/qchartview.cpp index c07ec45..cc19d6f 100644 --- a/src/qchartview.cpp +++ b/src/qchartview.cpp @@ -138,8 +138,9 @@ void QChartView::mousePressEvent(QMouseEvent *event) void QChartView::mouseMoveEvent(QMouseEvent *event) { if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { - int padding = d_ptr->m_chart->margins().top(); - QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); + QRectF margins = d_ptr->m_chart->margins(); + QRectF geometry = d_ptr->m_chart->geometry(); + QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom()); int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { diff --git a/test/auto/qchartview/tst_qchartview.cpp b/test/auto/qchartview/tst_qchartview.cpp index 682ff71..3edcd3d 100644 --- a/test/auto/qchartview/tst_qchartview.cpp +++ b/test/auto/qchartview/tst_qchartview.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include QTCOMMERCIALCHART_USE_NAMESPACE @@ -68,6 +69,7 @@ void tst_QChartView::cleanupTestCase() void tst_QChartView::init() { m_view = new QChartView(new QChart()); + m_view->chart()->legend()->setVisible(false); } void tst_QChartView::cleanup() @@ -131,7 +133,7 @@ void tst_QChartView::rubberBand() QFETCH(int, maxY); m_view->setRubberBand(rubberBand); - QRect padding = m_view->chart()->margins(); + QRectF padding = m_view->chart()->margins(); QCOMPARE(m_view->rubberBand(), rubberBand); QLineSeries* line = new QLineSeries(); @@ -150,10 +152,11 @@ void tst_QChartView::rubberBand() QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal))); QTest::qWaitForWindowShown(m_view); - QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft()); - QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft()); - QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft()); - QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft()); + QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint()); + QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint()); + QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); + QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); + QCOMPARE(spy0.count(), Xcount); QCOMPARE(spy1.count(), Ycount); @@ -186,7 +189,7 @@ void tst_QChartView::keys() QFETCH(int, Xcount); QFETCH(int, Ycount); - QRect padding = m_view->chart()->margins(); + QRectF padding = m_view->chart()->margins(); QLineSeries* line = new QLineSeries(); *line << QPointF(0, 0) << QPointF(100, 100);