##// END OF EJS Templates
Change background gradient to use ObjectBoundingMode...
Michal Klocek -
r122:a77b38c0fb20
parent child
Show More
@@ -36,7 +36,12 int main(int argc, char *argv[])
36 chartView->setTitle("Custom color line chart example");
36 chartView->setTitle("Custom color line chart example");
37 chartView->addSeries(series0);
37 chartView->addSeries(series0);
38 chartView->addSeries(series1);
38 chartView->addSeries(series1);
39 chartView->setBackground(Qt::blue,Qt::yellow,QChart::HorizonatlGradientOrientation);
39
40 QLinearGradient backgroundGradient;
41 backgroundGradient.setColorAt(0.0, Qt::blue);
42 backgroundGradient.setColorAt(1.0, Qt::yellow);
43 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
44 chartView->setChartBackgroundBrush(backgroundGradient);
40
45
41 window.setCentralWidget(chartView);
46 window.setCentralWidget(chartView);
42 window.resize(400, 300);
47 window.resize(400, 300);
@@ -71,7 +71,7 void QChart::addSeries(QChartSeries* series)
71 domain.m_maxY = qMax(domain.m_maxY,y);
71 domain.m_maxY = qMax(domain.m_maxY,y);
72 }
72 }
73
73
74 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
74 XYLineChartItem* item = new XYLineChartItem(xyseries,0,this);
75
75
76 m_chartItems << item;
76 m_chartItems << item;
77 // TODO:
77 // TODO:
@@ -240,12 +240,12 void QChart::setBackground(const QColor& startColor, const QColor& endColor, Gra
240 m_bacgroundOrinetation = orientation;
240 m_bacgroundOrinetation = orientation;
241 m_backgroundGradient.setColorAt(0.0, startColor);
241 m_backgroundGradient.setColorAt(0.0, startColor);
242 m_backgroundGradient.setColorAt(1.0, endColor);
242 m_backgroundGradient.setColorAt(1.0, endColor);
243 m_backgroundGradient.setStart(0,0);
243 m_backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
244
244
245 if(orientation == VerticalGradientOrientation){
245 if(orientation == VerticalGradientOrientation){
246 m_backgroundGradient.setFinalStop(0,m_rect.height());
246 m_backgroundGradient.setFinalStop(0,1);
247 }else{
247 }else{
248 m_backgroundGradient.setFinalStop(m_rect.width(),0);
248 m_backgroundGradient.setFinalStop(1,0);
249 }
249 }
250
250
251 m_backgroundItem->setBrush(m_backgroundGradient);
251 m_backgroundItem->setBrush(m_backgroundGradient);
@@ -253,6 +253,30 void QChart::setBackground(const QColor& startColor, const QColor& endColor, Gra
253 m_backgroundItem->update();
253 m_backgroundItem->update();
254 }
254 }
255
255
256 void QChart::setChartBackgroundBrush(const QBrush& brush)
257 {
258
259 if(!m_backgroundItem){
260 m_backgroundItem = new QGraphicsRectItem(this);
261 m_backgroundItem->setZValue(-1);
262 }
263
264 m_backgroundItem->setBrush(brush);
265 m_backgroundItem->update();
266 }
267
268 void QChart::setChartBackgroundPen(const QPen& pen)
269 {
270
271 if(!m_backgroundItem){
272 m_backgroundItem = new QGraphicsRectItem(this);
273 m_backgroundItem->setZValue(-1);
274 }
275
276 m_backgroundItem->setPen(pen);
277 m_backgroundItem->update();
278 }
279
256 void QChart::setTitle(const QString& title,const QFont& font)
280 void QChart::setTitle(const QString& title,const QFont& font)
257 {
281 {
258 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
282 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
@@ -390,11 +414,6 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
390 //recalculate background gradient
414 //recalculate background gradient
391 if (m_backgroundItem) {
415 if (m_backgroundItem) {
392 m_backgroundItem->setRect(rect);
416 m_backgroundItem->setRect(rect);
393 if (m_bacgroundOrinetation == HorizonatlGradientOrientation)
394 m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(), 0);
395 else
396 m_backgroundGradient.setFinalStop(0, m_backgroundItem->rect().height());
397 m_backgroundItem->setBrush(m_backgroundGradient);
398 }
417 }
399
418
400 // resize and reposition childs
419 // resize and reposition childs
@@ -63,6 +63,9 public:
63 void setTitle(const QString& title,const QFont& font = QFont());
63 void setTitle(const QString& title,const QFont& font = QFont());
64 void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, GradientOrientation orientation = VerticalGradientOrientation);
64 void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, GradientOrientation orientation = VerticalGradientOrientation);
65
65
66 void setChartBackgroundBrush(const QBrush& brush);
67 void setChartBackgroundPen(const QPen& pen);
68
66 void zoomInToRect(const QRectF& rectangle);
69 void zoomInToRect(const QRectF& rectangle);
67 void zoomIn();
70 void zoomIn();
68 void zoomOut();
71 void zoomOut();
@@ -74,4 +74,12 void QChartView::setBackground(const QColor& startColor, const QColor& endColor,
74 m_chart->setBackground(startColor,endColor,orientation);
74 m_chart->setBackground(startColor,endColor,orientation);
75 }
75 }
76
76
77 void QChartView::setChartBackgroundBrush(const QBrush& brush)
78 {
79 m_chart->setChartBackgroundBrush(brush);
80 }
81 void QChartView::setChartBackgroundPen(const QPen& pen)
82 {
83 m_chart->setChartBackgroundPen(pen);
84 }
77 QTCOMMERCIALCHART_END_NAMESPACE
85 QTCOMMERCIALCHART_END_NAMESPACE
@@ -27,7 +27,14 public:
27
27
28 int margin() const;
28 int margin() const;
29 void setTitle(const QString& title);
29 void setTitle(const QString& title);
30
31 //Obsolete
30 void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, QChart::GradientOrientation orientation = QChart::VerticalGradientOrientation);
32 void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, QChart::GradientOrientation orientation = QChart::VerticalGradientOrientation);
33
34
35 void setChartBackgroundBrush(const QBrush& brush);
36 void setChartBackgroundPen(const QPen& pen);
37
31 void zoomInToRect(const QRect& rectangle);
38 void zoomInToRect(const QRect& rectangle);
32 void zoomIn();
39 void zoomIn();
33 void zoomOut();
40 void zoomOut();
General Comments 0
You need to be logged in to leave comments. Login now