##// END OF EJS Templates
Increses margins prescision
Michal Klocek -
r874:fcf207f30c3f
parent child
Show More
@@ -84,7 +84,7 public: //TODO: fix me
84 void resetAllElements();
84 void resetAllElements();
85 void createChartBackgroundItem();
85 void createChartBackgroundItem();
86 void createChartTitleItem();
86 void createChartTitleItem();
87 QRect margins() const { return m_chartMargins;}
87 QRectF margins() const { return m_chartMargins;}
88
88
89 public Q_SLOTS:
89 public Q_SLOTS:
90 void handleSeriesAdded(QSeries* series,Domain* domain);
90 void handleSeriesAdded(QSeries* series,Domain* domain);
@@ -116,8 +116,8 public: //TODO: fixme
116 int m_marginBig;
116 int m_marginBig;
117 int m_marginSmall;
117 int m_marginSmall;
118 int m_marginTiny;
118 int m_marginTiny;
119 QRect m_chartMargins;
119 QRectF m_chartMargins;
120 QRect m_legendMargins;
120 QRectF m_legendMargins;
121
121
122 };
122 };
123
123
@@ -275,7 +275,7 QLegend* QChart::legend() const
275 return d_ptr->m_legend;
275 return d_ptr->m_legend;
276 }
276 }
277
277
278 QRect QChart::margins() const
278 QRectF QChart::margins() const
279 {
279 {
280 return d_ptr->m_presenter->margins();
280 return d_ptr->m_presenter->margins();
281 }
281 }
@@ -76,6 +76,7 public:
76 QFont titleFont() const;
76 QFont titleFont() const;
77 void setTitleBrush(const QBrush &brush);
77 void setTitleBrush(const QBrush &brush);
78 QBrush titleBrush() const;
78 QBrush titleBrush() const;
79
79 void setBackgroundBrush(const QBrush &brush);
80 void setBackgroundBrush(const QBrush &brush);
80 QBrush backgroundBrush() const;
81 QBrush backgroundBrush() const;
81 void setBackgroundPen(const QPen &pen);
82 void setBackgroundPen(const QPen &pen);
@@ -99,7 +100,7 public:
99 QChartAxis* axisY() const;
100 QChartAxis* axisY() const;
100
101
101 QLegend* legend() const;
102 QLegend* legend() const;
102 QRect margins() const;
103 QRectF margins() const;
103
104
104 protected:
105 protected:
105 void resizeEvent(QGraphicsSceneResizeEvent *event);
106 void resizeEvent(QGraphicsSceneResizeEvent *event);
@@ -138,8 +138,9 void QChartView::mousePressEvent(QMouseEvent *event)
138 void QChartView::mouseMoveEvent(QMouseEvent *event)
138 void QChartView::mouseMoveEvent(QMouseEvent *event)
139 {
139 {
140 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
140 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
141 int padding = d_ptr->m_chart->margins().top();
141 QRectF margins = d_ptr->m_chart->margins();
142 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
142 QRectF geometry = d_ptr->m_chart->geometry();
143 QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom());
143 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
144 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
144 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
145 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
145 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
146 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
@@ -22,6 +22,7
22 #include <QtTest/QtTest>
22 #include <QtTest/QtTest>
23 #include <qchartview.h>
23 #include <qchartview.h>
24 #include <qlineseries.h>
24 #include <qlineseries.h>
25 #include <qlegend.h>
25 #include <cmath>
26 #include <cmath>
26
27
27 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
@@ -68,6 +69,7 void tst_QChartView::cleanupTestCase()
68 void tst_QChartView::init()
69 void tst_QChartView::init()
69 {
70 {
70 m_view = new QChartView(new QChart());
71 m_view = new QChartView(new QChart());
72 m_view->chart()->legend()->setVisible(false);
71 }
73 }
72
74
73 void tst_QChartView::cleanup()
75 void tst_QChartView::cleanup()
@@ -131,7 +133,7 void tst_QChartView::rubberBand()
131 QFETCH(int, maxY);
133 QFETCH(int, maxY);
132
134
133 m_view->setRubberBand(rubberBand);
135 m_view->setRubberBand(rubberBand);
134 QRect padding = m_view->chart()->margins();
136 QRectF padding = m_view->chart()->margins();
135 QCOMPARE(m_view->rubberBand(), rubberBand);
137 QCOMPARE(m_view->rubberBand(), rubberBand);
136
138
137 QLineSeries* line = new QLineSeries();
139 QLineSeries* line = new QLineSeries();
@@ -150,10 +152,11 void tst_QChartView::rubberBand()
150 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
152 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
151
153
152 QTest::qWaitForWindowShown(m_view);
154 QTest::qWaitForWindowShown(m_view);
153 QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft());
155 QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint());
154 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft());
156 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint());
155 QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft());
157 QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint());
156 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft());
158 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint());
159
157
160
158 QCOMPARE(spy0.count(), Xcount);
161 QCOMPARE(spy0.count(), Xcount);
159 QCOMPARE(spy1.count(), Ycount);
162 QCOMPARE(spy1.count(), Ycount);
@@ -186,7 +189,7 void tst_QChartView::keys()
186 QFETCH(int, Xcount);
189 QFETCH(int, Xcount);
187 QFETCH(int, Ycount);
190 QFETCH(int, Ycount);
188
191
189 QRect padding = m_view->chart()->margins();
192 QRectF padding = m_view->chart()->margins();
190
193
191 QLineSeries* line = new QLineSeries();
194 QLineSeries* line = new QLineSeries();
192 *line << QPointF(0, 0) << QPointF(100, 100);
195 *line << QPointF(0, 0) << QPointF(100, 100);
General Comments 0
You need to be logged in to leave comments. Login now