##// END OF EJS Templates
Fixes mouse handling in base class of chartseries
Michal Klocek -
r1747:19ac79b0cec7
parent child
Show More
@@ -1,150 +1,151
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "areachartitem_p.h"
22 22 #include "qareaseries.h"
23 23 #include "qareaseries_p.h"
24 24 #include "qlineseries.h"
25 25 #include "chartpresenter_p.h"
26 26 #include "domain_p.h"
27 27 #include <QPainter>
28 28 #include <QGraphicsSceneMouseEvent>
29 29 #include <QDebug>
30 30
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 //TODO: optimize : remove points which are not visible
35 35
36 36 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, ChartPresenter *presenter)
37 37 : ChartItem(presenter),
38 38 m_series(areaSeries),
39 39 m_upper(0),
40 40 m_lower(0),
41 41 m_pointsVisible(false)
42 42 {
43 43 setZValue(ChartPresenter::LineChartZValue);
44 44 m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter);
45 45 if (m_series->lowerSeries()){
46 46 m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter);
47 47 }
48 48
49 49 QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated()));
50 50 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
51 51 QObject::connect(this,SIGNAL(clicked(QPointF)),areaSeries,SIGNAL(clicked(QPointF)));
52 52
53 53 handleUpdated();
54 54 }
55 55
56 56 AreaChartItem::~AreaChartItem()
57 57 {
58 58 delete m_upper;
59 59 delete m_lower;
60 60 }
61 61
62 62 QRectF AreaChartItem::boundingRect() const
63 63 {
64 64 return m_rect;
65 65 }
66 66
67 67 QPainterPath AreaChartItem::shape() const
68 68 {
69 69 return m_path;
70 70 }
71 71
72 72 void AreaChartItem::updatePath()
73 73 {
74 74 QPainterPath path;
75 75
76 76 path = m_upper->shape();
77 77
78 78 if (m_lower) {
79 79 path.connectPath(m_lower->shape().toReversed());
80 80 } else {
81 81 QPointF first = path.pointAtPercent(0);
82 82 QPointF last = path.pointAtPercent(1);
83 83 path.lineTo(last.x(),m_clipRect.bottom());
84 84 path.lineTo(first.x(),m_clipRect.bottom());
85 85 }
86 86 path.closeSubpath();
87 87 prepareGeometryChange();
88 88 m_path = path;
89 89 m_rect = path.boundingRect();
90 90 update();
91 91 }
92 92
93 93 void AreaChartItem::handleUpdated()
94 94 {
95 95 setVisible(m_series->isVisible());
96 96 m_pointsVisible = m_series->pointsVisible();
97 97 m_linePen = m_series->pen();
98 98 m_brush = m_series->brush();
99 99 m_pointPen = m_series->pen();
100 100 m_pointPen.setWidthF(2 * m_pointPen.width());
101 101
102 102 update();
103 103 }
104 104
105 105 void AreaChartItem::handleDomainUpdated()
106 106 {
107 107 m_upper->setDomain(domain());
108 108 m_upper->handleDomainUpdated();
109 109 if (m_lower){
110 110 m_lower->setDomain(domain());
111 111 m_lower->handleDomainUpdated();
112 112 }
113 113 }
114 114
115 115 void AreaChartItem::handleGeometryChanged(const QRectF &rect)
116 116 {
117 117 m_clipRect=rect.translated(-rect.topLeft());
118 118 setPos(rect.topLeft());
119 119 m_upper->handleGeometryChanged(rect);
120 120 if (m_lower)
121 121 m_lower->handleGeometryChanged(rect);
122 122 }
123 123
124 124 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
125 125 {
126 126 Q_UNUSED(widget)
127 127 Q_UNUSED(option)
128 128
129 129 painter->save();
130 130 painter->setPen(m_linePen);
131 131 painter->setBrush(m_brush);
132 132 painter->setClipRect(m_clipRect);
133 133 painter->drawPath(m_path);
134 134 if (m_pointsVisible) {
135 135 painter->setPen(m_pointPen);
136 136 painter->drawPoints(m_upper->geometryPoints());
137 137 if (m_lower)
138 138 painter->drawPoints(m_lower->geometryPoints());
139 139 }
140 140 painter->restore();
141 141 }
142 142
143 143 void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
144 144 {
145 145 emit clicked(m_upper->calculateDomainPoint(event->pos()));
146 ChartItem::mousePressEvent(event);
146 147 }
147 148
148 149 #include "moc_areachartitem_p.cpp"
149 150
150 151 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,66 +1,68
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "bar_p.h"
22 22 #include <QPainter>
23 23 #include <QGraphicsSceneEvent>
24 24
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 26
27 27 Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent),
28 28 m_index(index),
29 29 m_barset(barset),
30 30 m_hovering(false)
31 31 {
32 32 setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
33 33 setAcceptHoverEvents(true);
34 34 }
35 35
36 36 Bar::~Bar()
37 37 {
38 38 // End hover event, if bar is deleted during it
39 39 if (m_hovering) {
40 40 emit hovered(false, m_barset);
41 41 }
42 42 }
43 43
44 44 void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
45 45 {
46 46 Q_UNUSED(event)
47 47 emit clicked(m_index, m_barset);
48 QGraphicsItem::mousePressEvent(event);
48 49 }
49 50
50 51 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
51 52 {
52 53 Q_UNUSED(event)
53 54 m_hovering = true;
54 55 emit hovered(true, m_barset);
56
55 57 }
56 58
57 59 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
58 60 {
59 61 Q_UNUSED(event)
60 62 m_hovering = false;
61 63 emit hovered(false, m_barset);
62 64 }
63 65
64 66 #include "moc_bar_p.cpp"
65 67
66 68 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,174 +1,176
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef CHARTPRESENTER_H
31 31 #define CHARTPRESENTER_H
32 32
33 33 #include "qchartglobal.h"
34 34 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
35 35 #include <QRectF>
36 36
37 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 38
39 39 class ChartElement;
40 40 class QAbstractSeries;
41 41 class ChartDataSet;
42 42 class Domain;
43 43 class ChartAxis;
44 44 class ChartTheme;
45 45 class ChartAnimator;
46 46 class ChartBackground;
47 47 class ChartAnimation;
48 48 class ChartLayout;
49 49
50 50 class ChartPresenter: public QObject
51 51 {
52 52 Q_OBJECT
53 53 public:
54 54 enum ZValues {
55 55 BackgroundZValue = -1,
56 ShadesZValue,
56 ShadesZValue ,
57 57 GridZValue,
58 58 SeriesZValue,
59 59 LineChartZValue = SeriesZValue,
60 SplineChartZValue = SeriesZValue,
60 61 BarSeriesZValue = SeriesZValue,
61 62 ScatterSeriesZValue = SeriesZValue,
62 63 PieSeriesZValue = SeriesZValue,
63 64 AxisZValue,
64 LegendZValue
65 LegendZValue,
66 TopMostZValue
65 67 };
66 68
67 69 enum State {
68 70 ShowState,
69 71 ScrollUpState,
70 72 ScrollDownState,
71 73 ScrollLeftState,
72 74 ScrollRightState,
73 75 ZoomInState,
74 76 ZoomOutState
75 77 };
76 78
77 79 ChartPresenter(QChart* chart,ChartDataSet *dataset);
78 80 virtual ~ChartPresenter();
79 81
80 82 ChartTheme *chartTheme() const { return m_chartTheme; }
81 83 ChartDataSet *dataSet() const { return m_dataset; }
82 84 QGraphicsItem* rootItem() const { return m_chart; }
83 85 QGraphicsRectItem* backgroundItem();
84 86 QGraphicsItem* titleItem();
85 87 QList<ChartAxis*> axisItems() const;
86 88
87 89 QLegend* legend();
88 90
89 91 void setBackgroundBrush(const QBrush& brush);
90 92 QBrush backgroundBrush() const;
91 93
92 94 void setBackgroundPen(const QPen& pen);
93 95 QPen backgroundPen() const;
94 96
95 97 void setTitle(const QString& title);
96 98 QString title() const;
97 99
98 100 void setTitleFont(const QFont& font);
99 101 QFont titleFont() const;
100 102
101 103 void setTitleBrush(const QBrush &brush);
102 104 QBrush titleBrush() const;
103 105
104 106 void setBackgroundVisible(bool visible);
105 107 bool isBackgroundVisible() const;
106 108
107 109 void setBackgroundDropShadowEnabled(bool enabled);
108 110 bool isBackgroundDropShadowEnabled() const;
109 111
110 112 void setVisible(bool visible);
111 113
112 114 void setTheme(QChart::ChartTheme theme,bool force = true);
113 115 QChart::ChartTheme theme();
114 116
115 117 void setAnimationOptions(QChart::AnimationOptions options);
116 118 QChart::AnimationOptions animationOptions() const;
117 119
118 120 void zoomIn(qreal factor);
119 121 void zoomIn(const QRectF& rect);
120 122 void zoomOut(qreal factor);
121 123 void scroll(qreal dx,qreal dy);
122 124
123 125 void setGeometry(const QRectF& rect);
124 126 QRectF geometry() { return m_rect; }
125 127
126 128 void startAnimation(ChartAnimation* animation);
127 129 State state() const { return m_state; }
128 130 QPointF statePoint() const { return m_statePoint; }
129 131
130 132 void resetAllElements();
131 133
132 134 void setMarginsMinimum(const QRectF& margins);
133 135 QRectF margins() const;
134 136 QGraphicsLayout* layout();
135 137
136 138 private:
137 139 void createBackgroundItem();
138 140 void createTitleItem();
139 141 void selectVisibleAxis();
140 142
141 143 public Q_SLOTS:
142 144 void handleSeriesAdded(QAbstractSeries* series,Domain* domain);
143 145 void handleSeriesRemoved(QAbstractSeries* series);
144 146 void handleAxisAdded(QAbstractAxis* axis,Domain* domain);
145 147 void handleAxisRemoved(QAbstractAxis* axis);
146 148 void handleAxisVisibleChanged(bool visible);
147 149
148 150 private Q_SLOTS:
149 151 void handleAnimationFinished();
150 152
151 153 Q_SIGNALS:
152 154 void geometryChanged(const QRectF& rect);
153 155 void animationsFinished();
154 156 void marginsChanged(QRectF margins);
155 157
156 158 private:
157 159 QChart* m_chart;
158 160 ChartDataSet* m_dataset;
159 161 ChartTheme *m_chartTheme;
160 162 QMap<QAbstractSeries*, ChartElement*> m_chartItems;
161 163 QMap<QAbstractAxis*, ChartAxis*> m_axisItems;
162 164 QRectF m_rect;
163 165 QChart::AnimationOptions m_options;
164 166 State m_state;
165 167 QPointF m_statePoint;
166 168 QList<ChartAnimation*> m_animations;
167 169 ChartLayout* m_layout;
168 170 ChartBackground* m_backgroundItem;
169 171 QGraphicsSimpleTextItem* m_titleItem;
170 172 };
171 173
172 174 QTCOMMERCIALCHART_END_NAMESPACE
173 175
174 176 #endif /* CHARTPRESENTER_H_ */
@@ -1,114 +1,115
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "linechartitem_p.h"
22 22 #include "qlineseries.h"
23 23 #include "qlineseries_p.h"
24 24 #include "chartpresenter_p.h"
25 25 #include <QPainter>
26 26 #include <QGraphicsSceneMouseEvent>
27 27
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 //TODO: optimize : remove points which are not visible
32 32
33 33 LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter):
34 34 XYChart(series, presenter),
35 35 QGraphicsItem(presenter ? presenter->rootItem() : 0),
36 36 m_series(series),
37 37 m_pointsVisible(false)
38 38 {
39 39 setZValue(ChartPresenter::LineChartZValue);
40 40 QObject::connect(series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated()));
41 41 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
42 42 handleUpdated();
43 43 }
44 44
45 45 QRectF LineChartItem::boundingRect() const
46 46 {
47 47 return m_rect;
48 48 }
49 49
50 50 QPainterPath LineChartItem::shape() const
51 51 {
52 52 return m_path;
53 53 }
54 54
55 55 void LineChartItem::updateGeometry()
56 56 {
57 57 const QVector<QPointF>& points = geometryPoints();
58 58
59 59 if(points.size()==0)
60 60 {
61 61 prepareGeometryChange();
62 62 m_path = QPainterPath();
63 63 m_rect = QRect();
64 64 return;
65 65 }
66 66
67 67 QPainterPath linePath(points.at(0));
68 68
69 69 for(int i=1; i< points.size();i++) {
70 70 linePath.lineTo(points.at(i));
71 71 }
72 72
73 73 prepareGeometryChange();
74 74 m_path = linePath;
75 75 m_rect = linePath.boundingRect();
76 76 setPos(origin());
77 77 }
78 78
79 79 void LineChartItem::handleUpdated()
80 80 {
81 81 setVisible(m_series->isVisible());
82 82 m_pointsVisible = m_series->pointsVisible();
83 83 m_linePen = m_series->pen();
84 84 m_pointPen = m_series->pen();
85 85 m_pointPen.setWidthF(2*m_pointPen.width());
86 86 update();
87 87 }
88 88
89 89 //painter
90 90
91 91 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
92 92 {
93 93 Q_UNUSED(widget)
94 94 Q_UNUSED(option)
95 95
96 96 painter->save();
97 97 painter->setPen(m_linePen);
98 98 painter->setClipRect(clipRect());
99 99 painter->drawPath(m_path);
100 100 if (m_pointsVisible){
101 101 painter->setPen(m_pointPen);
102 102 painter->drawPoints(geometryPoints());
103 103 }
104 104 painter->restore();
105 105 }
106 106
107 107 void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
108 108 {
109 109 emit XYChart::clicked(calculateDomainPoint(event->pos()));
110 QGraphicsItem::mousePressEvent(event);
110 111 }
111 112
112 113 #include "moc_linechartitem_p.cpp"
113 114
114 115 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,274 +1,275
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "piesliceitem_p.h"
22 22 #include "piechartitem_p.h"
23 23 #include "qpieseries.h"
24 24 #include "qpieslice.h"
25 25 #include "chartpresenter_p.h"
26 26 #include <QPainter>
27 27 #include <qmath.h>
28 28 #include <QGraphicsSceneEvent>
29 29 #include <QTime>
30 30 #include <QDebug>
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 QPointF offset(qreal angle, qreal length)
35 35 {
36 36 qreal dx = qSin(angle*(M_PI/180)) * length;
37 37 qreal dy = qCos(angle*(M_PI/180)) * length;
38 38 return QPointF(dx, -dy);
39 39 }
40 40
41 41 PieSliceItem::PieSliceItem(QGraphicsItem* parent)
42 42 :QGraphicsObject(parent),
43 43 m_hovered(false)
44 44 {
45 45 setAcceptHoverEvents(true);
46 46 setAcceptedMouseButtons(Qt::MouseButtonMask);
47 47 setZValue(ChartPresenter::PieSeriesZValue);
48 48 }
49 49
50 50 PieSliceItem::~PieSliceItem()
51 51 {
52 52 // If user is hovering over the slice and it gets destroyed we do
53 53 // not get a hover leave event. So we must emit the signal here.
54 54 if (m_hovered)
55 55 emit hovered(false);
56 56 }
57 57
58 58 QRectF PieSliceItem::boundingRect() const
59 59 {
60 60 return m_boundingRect;
61 61 }
62 62
63 63 QPainterPath PieSliceItem::shape() const
64 64 {
65 65 // Don't include the label and label arm.
66 66 // This is used to detect a mouse clicks. We do not want clicks from label.
67 67 return m_slicePath;
68 68 }
69 69
70 70 void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
71 71 {
72 72 painter->save();
73 73 painter->setClipRect(parentItem()->boundingRect());
74 74 painter->setPen(m_data.m_slicePen);
75 75 painter->setBrush(m_data.m_sliceBrush);
76 76 painter->drawPath(m_slicePath);
77 77 painter->restore();
78 78
79 79 if (m_data.m_isLabelVisible) {
80 80 painter->save();
81 81
82 82 // Pen for label arm not defined in the QPieSeries api, let's use brush's color instead
83 83 // Also, the drawText actually uses the pen color for the text color (unlike QGraphicsSimpleTextItem)
84 84 painter->setPen(m_data.m_labelBrush.color());
85 85 painter->setBrush(m_data.m_labelBrush);
86 86 painter->setFont(m_data.m_labelFont);
87 87
88 88 switch (m_data.m_labelPosition)
89 89 {
90 90 case QPieSlice::LabelOutside:
91 91 painter->setClipRect(parentItem()->boundingRect());
92 92 painter->strokePath(m_labelArmPath, m_data.m_labelBrush.color());
93 93 painter->drawText(m_labelTextRect, Qt::AlignCenter, m_data.m_labelText);
94 94 break;
95 95 case QPieSlice::LabelInside:
96 96 painter->setClipPath(m_slicePath);
97 97 painter->drawText(m_labelTextRect, Qt::AlignCenter, m_data.m_labelText);
98 98 break;
99 99 case QPieSlice::LabelInsideTangential:
100 100 painter->setClipPath(m_slicePath);
101 101 painter->translate(m_labelTextRect.center());
102 102 painter->rotate(m_data.m_startAngle + m_data.m_angleSpan / 2);
103 103 painter->drawText(-m_labelTextRect.width() / 2, -m_labelTextRect.height() / 2, m_labelTextRect.width(), m_labelTextRect.height(), Qt::AlignCenter, m_data.m_labelText);
104 104 break;
105 105 case QPieSlice::LabelInsideNormal:
106 106 painter->setClipPath(m_slicePath);
107 107 painter->translate(m_labelTextRect.center());
108 108 if (m_data.m_startAngle + m_data.m_angleSpan / 2 < 180)
109 109 painter->rotate(m_data.m_startAngle + m_data.m_angleSpan / 2 - 90);
110 110 else
111 111 painter->rotate(m_data.m_startAngle + m_data.m_angleSpan / 2 + 90);
112 112 painter->drawText(-m_labelTextRect.width() / 2, -m_labelTextRect.height() / 2, m_labelTextRect.width(), m_labelTextRect.height(), Qt::AlignCenter, m_data.m_labelText);
113 113 break;
114 114 }
115 115
116 116 painter->restore();
117 117 }
118 118 }
119 119
120 120 void PieSliceItem::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/)
121 121 {
122 122 m_hovered = true;
123 123 emit hovered(true);
124 124 }
125 125
126 126 void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
127 127 {
128 128 m_hovered = false;
129 129 emit hovered(false);
130 130 }
131 131
132 132 void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
133 133 {
134 134 emit clicked(event->buttons());
135 QGraphicsItem::mousePressEvent(event);
135 136 }
136 137
137 138 void PieSliceItem::setLayout(const PieSliceData &sliceData)
138 139 {
139 140 m_data = sliceData;
140 141 updateGeometry();
141 142 update();
142 143 }
143 144
144 145 void PieSliceItem::updateGeometry()
145 146 {
146 147 if (m_data.m_radius <= 0)
147 148 return;
148 149
149 150 prepareGeometryChange();
150 151
151 152 // slice path
152 153 qreal centerAngle;
153 154 QPointF armStart;
154 155 m_slicePath = slicePath(m_data.m_center, m_data.m_radius, m_data.m_startAngle, m_data.m_angleSpan, &centerAngle, &armStart);
155 156
156 157 // text rect
157 158 QFontMetricsF fm(m_data.m_labelFont);
158 159 m_labelTextRect = QRectF(0, 0, fm.width(m_data.m_labelText), fm.height());
159 160
160 161 // label arm path
161 162 QPointF labelTextStart;
162 163 m_labelArmPath = labelArmPath(armStart, centerAngle, m_data.m_radius * m_data.m_labelArmLengthFactor, m_labelTextRect.width(), &labelTextStart);
163 164
164 165 // text position
165 166 switch (m_data.m_labelPosition)
166 167 {
167 168 case QPieSlice::LabelOutside:
168 169 m_labelTextRect.moveBottomLeft(labelTextStart);
169 170 break;
170 171 case QPieSlice::LabelInside:
171 172 case QPieSlice::LabelInsideTangential:
172 173 case QPieSlice::LabelInsideNormal:{
173 174 QPointF textCenter;
174 175 if (m_data.m_donut)
175 176 textCenter = m_data.m_center + offset(centerAngle, m_data.m_innerRadius + (m_data.m_radius - m_data.m_innerRadius) / 2);
176 177 else
177 178 textCenter = m_data.m_center + offset(centerAngle, m_data.m_radius / 2);
178 179 m_labelTextRect.moveCenter(textCenter);
179 180 break;
180 181 }
181 182 }
182 183
183 184 // bounding rect
184 185 if (m_data.m_isLabelVisible)
185 186 m_boundingRect = m_slicePath.boundingRect().united(m_labelArmPath.boundingRect()).united(m_labelTextRect);
186 187 else
187 188 m_boundingRect = m_slicePath.boundingRect();
188 189 }
189 190
190 191 QPointF PieSliceItem::sliceCenter(QPointF point, qreal radius, QPieSlice *slice)
191 192 {
192 193 if (slice->isExploded()) {
193 194 qreal centerAngle = slice->startAngle() + (slice->angleSpan()/2);
194 195 qreal len = radius * slice->explodeDistanceFactor();
195 196 point += offset(centerAngle, len);
196 197 }
197 198 return point;
198 199 }
199 200
200 201 QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal *centerAngle, QPointF* armStart)
201 202 {
202 203 // calculate center angle
203 204 *centerAngle = startAngle + (angleSpan/2);
204 205
205 206 // calculate slice rectangle
206 207 QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2);
207 208
208 209 // slice path
209 210 QPainterPath path;
210 211 if (m_data.m_donut) {
211 212 QRectF insideRect(center.x() - m_data.m_innerRadius, center.y()-m_data.m_innerRadius, m_data.m_innerRadius*2, m_data.m_innerRadius*2);
212 213 path.arcMoveTo(rect, -startAngle + 90);
213 214 path.arcTo(rect, -startAngle + 90, -angleSpan);
214 215 path.arcTo(insideRect, -startAngle + 90 - angleSpan, angleSpan);
215 216 path.closeSubpath();
216 217 } else {
217 218 path.moveTo(rect.center());
218 219 path.arcTo(rect, -startAngle + 90, -angleSpan);
219 220 path.closeSubpath();
220 221 }
221 222
222 223 // calculate label arm start point
223 224 *armStart = center;
224 225 *armStart += offset(*centerAngle, radius + PIESLICE_LABEL_GAP);
225 226
226 227 return path;
227 228 }
228 229
229 230 QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF *textStart)
230 231 {
231 232 // Normalize the angle to 0-360 range
232 233 // NOTE: We are using int here on purpose. Depenging on platform and hardware
233 234 // qreal can be a double, float or something the user gives to the Qt configure
234 235 // (QT_COORD_TYPE). Compilers do not seem to support modulo for double or float
235 236 // but there are fmod() and fmodf() functions for that. So instead of some #ifdef
236 237 // that might break we just use int. Precision for this is just fine for our needs.
237 238 int normalized = angle * 10.0;
238 239 normalized = normalized % 3600;
239 240 if (normalized < 0)
240 241 normalized += 3600;
241 242 angle = (qreal) normalized / 10.0;
242 243
243 244 // prevent label arm pointing straight down because it will look bad
244 245 if (angle < 180 && angle > 170)
245 246 angle = 170;
246 247 if (angle > 180 && angle < 190)
247 248 angle = 190;
248 249
249 250 // line from slice to label
250 251 QPointF parm1 = start + offset(angle, length);
251 252
252 253 // line to underline the label
253 254 QPointF parm2 = parm1;
254 255 if (angle < 180) { // arm swings the other way on the left side
255 256 parm2 += QPointF(textWidth, 0);
256 257 *textStart = parm1;
257 258 }
258 259 else {
259 260 parm2 += QPointF(-textWidth,0);
260 261 *textStart = parm2;
261 262 }
262 263
263 264 QPainterPath path;
264 265 path.moveTo(start);
265 266 path.lineTo(parm1);
266 267 path.lineTo(parm2);
267 268
268 269 return path;
269 270 }
270 271
271 272 #include "moc_piesliceitem_p.cpp"
272 273
273 274 QTCOMMERCIALCHART_END_NAMESPACE
274 275
@@ -1,205 +1,206
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "scatterchartitem_p.h"
22 22 #include "qscatterseries.h"
23 23 #include "qscatterseries_p.h"
24 24 #include "chartpresenter_p.h"
25 25 #include <QPainter>
26 26 #include <QGraphicsScene>
27 27 #include <QDebug>
28 28 #include <QGraphicsSceneMouseEvent>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) :
33 33 XYChart(series,presenter),
34 34 QGraphicsItem(presenter ? presenter->rootItem() : 0),
35 35 m_series(series),
36 36 m_items(this),
37 37 m_visible(true),
38 38 m_shape(QScatterSeries::MarkerShapeRectangle),
39 39 m_size(15)
40 40 {
41 41 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated()));
42 42 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
43 43
44 44 setZValue(ChartPresenter::ScatterSeriesZValue);
45 45 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
46 46
47 47 handleUpdated();
48 48
49 49 m_items.setHandlesChildEvents(false);
50 50
51 51 // TODO: how to draw a drop shadow?
52 52 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
53 53 // dropShadow->setOffset(2.0);
54 54 // dropShadow->setBlurRadius(2.0);
55 55 // setGraphicsEffect(dropShadow);
56 56 }
57 57
58 58 QRectF ScatterChartItem::boundingRect() const
59 59 {
60 60 return m_rect;
61 61 }
62 62
63 63 void ScatterChartItem::createPoints(int count)
64 64 {
65 65 for (int i = 0; i < count; ++i) {
66 66
67 67 QGraphicsItem *item = 0;
68 68
69 69 switch (m_shape) {
70 70 case QScatterSeries::MarkerShapeCircle: {
71 QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size);
71 QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size,this);
72 72 const QRectF& rect = i->boundingRect();
73 73 i->setPos(-rect.width()/2,-rect.height()/2);
74 74 item = new Marker(i,this);
75 75 break;
76 76 }
77 77 case QScatterSeries::MarkerShapeRectangle: {
78 QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size);
78 QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size,this);
79 79 i->setPos(-m_size/2,-m_size/2);
80 80 item = new Marker(i,this);
81 81 break;
82 82 }
83 83 default:
84 84 qWarning()<<"Unsupported marker type";
85 85 break;
86 86
87 87 }
88 88 m_items.addToGroup(item);
89 89 }
90 90 }
91 91
92 92 void ScatterChartItem::deletePoints(int count)
93 93 {
94 94 QList<QGraphicsItem *> items = m_items.childItems();
95 95
96 96 for (int i = 0; i < count; ++i) {
97 97 delete(items.takeLast());
98 98 }
99 99 }
100 100
101 101 void ScatterChartItem::markerSelected(Marker *marker)
102 102 {
103 103 emit XYChart::clicked(calculateDomainPoint(marker->point()));
104 104 }
105 105
106 106 void ScatterChartItem::updateGeometry()
107 107 {
108 108
109 109 const QVector<QPointF>& points = geometryPoints();
110 110
111 111 if(points.size()==0)
112 112 {
113 113 deletePoints(m_items.childItems().count());
114 114 return;
115 115 }
116 116
117 117 int diff = m_items.childItems().size() - points.size();
118 118
119 119 if(diff>0) {
120 120 deletePoints(diff);
121 121 }
122 122 else if(diff<0) {
123 123 createPoints(-diff);
124 124 }
125 125
126 126 if(diff!=0) handleUpdated();
127 127
128 128 QList<QGraphicsItem*> items = m_items.childItems();
129 129
130 130 for (int i = 0; i < points.size(); i++) {
131 131 Marker* item = static_cast<Marker*>(items.at(i));
132 132 const QPointF& point = points.at(i);
133 133 const QRectF& rect = item->boundingRect();
134 134 item->setPoint(point);
135 135 item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2);
136 136 if(!m_visible || !clipRect().contains(point)) {
137 137 item->setVisible(false);
138 138 }
139 139 else {
140 140 item->setVisible(true);
141 141 }
142 142 }
143 143
144 144 prepareGeometryChange();
145 145 m_rect = clipRect();
146 146 setPos(origin());
147 147 }
148 148
149 149 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
150 150 {
151 151 Q_UNUSED(painter)
152 152 Q_UNUSED(option)
153 153 Q_UNUSED(widget)
154 154 }
155 155
156 156 void ScatterChartItem::setPen(const QPen& pen)
157 157 {
158 158 foreach(QGraphicsItem* item , m_items.childItems()) {
159 159 static_cast<Marker*>(item)->setPen(pen);
160 160 }
161 161 }
162 162
163 163 void ScatterChartItem::setBrush(const QBrush& brush)
164 164 {
165 165 foreach(QGraphicsItem* item , m_items.childItems()) {
166 166 static_cast<Marker*>(item)->setBrush(brush);
167 167 }
168 168 }
169 169
170 170 void ScatterChartItem::handleUpdated()
171 171 {
172 172 int count = m_items.childItems().count();
173 173
174 174 if(count==0) return;
175 175
176 176 bool recreate = m_visible != m_series->isVisible()
177 177 || m_size != m_series->markerSize()
178 178 || m_shape != m_series->markerShape();
179 179
180 180 m_visible = m_series->isVisible();
181 181 m_size = m_series->markerSize();
182 182 m_shape = m_series->markerShape();
183 183
184 184 if(recreate) {
185 185 // TODO: optimize handleUpdate to recreate points only in case shape changed
186 186 deletePoints(count);
187 187 createPoints(count);
188 188
189 189 // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points
190 190 updateGeometry();
191 191 }
192 192
193 193 setPen(m_series->pen());
194 194 setBrush(m_series->brush());
195 195 update();
196 196 }
197 197
198 198 void ScatterChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
199 199 {
200 200 emit XYChart::clicked(calculateDomainPoint(event->pos()));
201 QGraphicsItem::mousePressEvent(event);
201 202 }
202 203
203 204 #include "moc_scatterchartitem_p.cpp"
204 205
205 206 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,151 +1,152
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef SCATTERCHARTITEM_H
31 31 #define SCATTERCHARTITEM_H
32 32
33 33 #include "qchartglobal.h"
34 34 #include "xychart_p.h"
35 35 #include <QGraphicsEllipseItem>
36 36 #include <QPen>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39
40 40 class QScatterSeries;
41 41 class Marker;
42 42
43 43 class ScatterChartItem : public XYChart, public QGraphicsItem
44 44 {
45 45 Q_OBJECT
46 46 Q_INTERFACES(QGraphicsItem)
47 47 public:
48 48 explicit ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter);
49 49
50 50 public:
51 51 //from QGraphicsItem
52 52 QRectF boundingRect() const;
53 53 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
54 54
55 55 void setPen(const QPen &pen);
56 56 void setBrush(const QBrush &brush);
57 57
58 58 void markerSelected(Marker *item);
59 59
60 60 public Q_SLOTS:
61 61 void handleUpdated();
62 62
63 63 private:
64 64 void createPoints(int count);
65 65 void deletePoints(int count);
66 66
67 67 protected:
68 68 void updateGeometry();
69 69 void mousePressEvent(QGraphicsSceneMouseEvent *event);
70 70
71 71 private:
72 72 QScatterSeries *m_series;
73 73 QGraphicsItemGroup m_items;
74 74 bool m_visible;
75 75 int m_shape;
76 76 int m_size;
77 77 QRectF m_rect;
78 78 };
79 79
80 80
81 81 class Marker: public QAbstractGraphicsShapeItem
82 82 {
83 83
84 84 public:
85 85
86 86 Marker(QAbstractGraphicsShapeItem *item , ScatterChartItem *parent) : QAbstractGraphicsShapeItem(0) ,m_item(item), m_parent(parent)
87 87 {
88 88 }
89 89
90 90 ~Marker()
91 91 {
92 92 delete m_item;
93 93 }
94 94
95 95 void setPoint(const QPointF& point)
96 96 {
97 97 m_point=point;
98 98 }
99 99
100 100 QPointF point() const
101 101 {
102 102 return m_point;
103 103 }
104 104
105 105 QPainterPath shape() const
106 106 {
107 107 return m_item->shape();
108 108 }
109 109
110 110 QRectF boundingRect() const
111 111 {
112 112 return m_item->boundingRect();
113 113 }
114 114
115 115 bool contains(const QPointF &point) const
116 116 {
117 117 return m_item->contains(point);
118 118 }
119 119
120 120 void setPen(const QPen &pen)
121 121 {
122 122 m_item->setPen(pen);
123 123 }
124 124
125 125 void setBrush(const QBrush &brush)
126 126 {
127 127 m_item->setBrush(brush);
128 128 }
129 129
130 130 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
131 131 {
132 132 m_item->paint(painter,option,widget);
133 133 }
134 134
135 135 protected:
136 136
137 137 void mousePressEvent(QGraphicsSceneMouseEvent *event)
138 138 {
139 139 Q_UNUSED(event)
140 140 m_parent->markerSelected(this);
141 QAbstractGraphicsShapeItem::mousePressEvent(event);
141 142 }
142 143
143 144 private:
144 145 QAbstractGraphicsShapeItem* m_item;
145 146 ScatterChartItem* m_parent;
146 147 QPointF m_point;
147 148 };
148 149
149 150 QTCOMMERCIALCHART_END_NAMESPACE
150 151
151 152 #endif // SCATTERPRESENTER_H
@@ -1,176 +1,177
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "splinechartitem_p.h"
22 22 #include "qsplineseries_p.h"
23 23 #include "chartpresenter_p.h"
24 24 #include "splineanimation_p.h"
25 25 #include <QPainter>
26 26 #include <QGraphicsSceneMouseEvent>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 SplineChartItem::SplineChartItem(QSplineSeries *series, ChartPresenter *presenter) :
31 31 XYChart(series, presenter),
32 32 QGraphicsItem(presenter ? presenter->rootItem() : 0),
33 33 m_series(series),
34 34 m_pointsVisible(false),
35 35 m_animation(0)
36 36 {
37 setZValue(ChartPresenter::LineChartZValue);
37 setZValue(ChartPresenter::SplineChartZValue);
38 38 QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated()));
39 39 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
40 40 handleUpdated();
41 41 }
42 42
43 43 QRectF SplineChartItem::boundingRect() const
44 44 {
45 45 return m_rect;
46 46 }
47 47
48 48 QPainterPath SplineChartItem::shape() const
49 49 {
50 50 return m_path;
51 51 }
52 52
53 53 void SplineChartItem::setAnimation(SplineAnimation* animation)
54 54 {
55 55 m_animation=animation;
56 56 XYChart::setAnimation(animation);
57 57 }
58 58
59 59 ChartAnimation* SplineChartItem::animation() const
60 60 {
61 61 return m_animation;
62 62 }
63 63
64 64 void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points)
65 65 {
66 66 m_controlPoints=points;
67 67 }
68 68
69 69 QVector<QPointF> SplineChartItem::controlGeometryPoints() const
70 70 {
71 71 return m_controlPoints;
72 72 }
73 73
74 74 void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
75 75 {
76 76 QVector<QPointF> controlPoints;
77 77
78 78 if(newPoints.count()>=2) {
79 79 controlPoints.resize(newPoints.count()*2-2);
80 80 }
81 81
82 82 for (int i = 0; i < newPoints.size() - 1; i++) {
83 83 controlPoints[2*i] = calculateGeometryControlPoint(2 * i);
84 84 controlPoints[2 * i + 1] = calculateGeometryControlPoint(2 * i + 1);
85 85 }
86 86
87 87 if (controlPoints.count()<2) {
88 88 setGeometryPoints(newPoints);
89 89 setControlGeometryPoints(controlPoints);
90 90 updateGeometry();
91 91 return;
92 92 }
93 93
94 94 if (m_animation) {
95 95 m_animation->setup(oldPoints,newPoints,m_controlPoints,controlPoints,index);
96 96 setGeometryPoints(newPoints);
97 97 setDirty(false);
98 98 presenter()->startAnimation(m_animation);
99 99 }
100 100 else {
101 101 setGeometryPoints(newPoints);
102 102 setControlGeometryPoints(controlPoints);
103 103 updateGeometry();
104 104 }
105 105 }
106 106
107 107 QPointF SplineChartItem::calculateGeometryControlPoint(int index) const
108 108 {
109 109 return XYChart::calculateGeometryPoint(m_series->d_func()->controlPoint(index));
110 110 }
111 111
112 112 void SplineChartItem::updateGeometry()
113 113 {
114 114 const QVector<QPointF> &points = geometryPoints();
115 115 const QVector<QPointF> &controlPoints = controlGeometryPoints();
116 116
117 117 if ((points.size()<2) || (controlPoints.size()<2)) {
118 118 prepareGeometryChange();
119 119 m_path = QPainterPath();
120 120 m_rect = QRect();
121 121 return;
122 122 }
123 123
124 124 Q_ASSERT(points.count()*2-2 == controlPoints.count());
125 125
126 126 QPainterPath splinePath(points.at(0));
127 127
128 128 for (int i = 0; i < points.size() - 1; i++) {
129 129 const QPointF& point = points.at(i + 1);
130 130 splinePath.cubicTo(controlPoints[2*i],controlPoints[2 * i + 1],point);
131 131 }
132 132
133 133 prepareGeometryChange();
134 134 m_path = splinePath;
135 135 m_rect = splinePath.boundingRect();
136 136 setPos(origin());
137 137 }
138 138
139 139 //handlers
140 140
141 141 void SplineChartItem::handleUpdated()
142 142 {
143 143 setVisible(m_series->isVisible());
144 144 m_pointsVisible = m_series->pointsVisible();
145 145 m_linePen = m_series->pen();
146 146 m_pointPen = m_series->pen();
147 147 m_pointPen.setWidthF(2*m_pointPen.width());
148 148 update();
149 149 }
150 150
151 151 //painter
152 152
153 153 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
154 154 {
155 155 Q_UNUSED(widget)
156 156 Q_UNUSED(option)
157 157
158 158 painter->save();
159 159 painter->setClipRect(clipRect());
160 160 painter->setPen(m_linePen);
161 161 painter->drawPath(m_path);
162 162 if (m_pointsVisible) {
163 163 painter->setPen(m_pointPen);
164 164 painter->drawPoints(geometryPoints());
165 165 }
166 166 painter->restore();
167 167 }
168 168
169 169 void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
170 170 {
171 171 emit XYChart::clicked(calculateDomainPoint(event->pos()));
172 QGraphicsItem::mousePressEvent(event);
172 173 }
173 174
174 175 #include "moc_splinechartitem_p.cpp"
175 176
176 177 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now