23 #include "PaintingHelpers_p.h" 28 #include "KDChartAbstractDiagram_p.h" 33 #include "KDChartPainterSaver_p.h" 40 namespace PaintingHelpers {
52 return QPointF( point.x() * cos( yrad ) + tdAttributes.
depth() * sin( yrad ),
53 point.y() * cos( xrad ) - tdAttributes.
depth() * sin( xrad ) );
58 ctx->
painter()->setBrush( brush );
60 QPen( pen.color(), pen.width(), pen.style(), Qt::FlatCap, Qt::MiterJoin ) ) );
61 #if QT_VERSION > 0x040299 62 ctx->
painter()->drawPolyline( points );
67 for (
int i = 0; i < points.size()-1; ++i ) {
68 ctx->
painter()->drawLine( points.at( i ), points.at( i + 1 ) );
77 const QPointF topLeft =
project( from, tdAttributes );
78 const QPointF topRight =
project ( to, tdAttributes );
79 const QPolygonF segment = QPolygonF() << from << topLeft << topRight << to;
81 QBrush indexBrush( diagram->
brush( index ) );
82 indexBrush = tdAttributes.
threeDBrush( indexBrush, QRectF(topLeft, topRight) );
84 const PainterSaver painterSaver( ctx->
painter() );
87 ctx->
painter()->setBrush( indexBrush );
90 reverseMapper->
addPolygon( index.row(), index.column(), segment );
91 ctx->
painter()->drawPolygon( segment );
103 gridDimensions.at( 0 ).end :
104 gridDimensions.at( 0 ).start,
106 gridDimensions.at( 1 ).end :
107 gridDimensions.at( 1 ).start ) ) );
110 gridDimensions.at( 0 ).start :
111 gridDimensions.at( 0 ).end,
113 gridDimensions.at( 1 ).start :
114 gridDimensions.at( 1 ).end ) ) );
115 const QPointF markerPoint = at;
119 startPoint = QPointF( bottomLeft.x(), at.y() );
121 startPoint = QPointF( at.x(), topRight.y() );
126 endPoint = QPointF( at.x(), bottomLeft.y() );
128 endPoint = QPointF( topRight.x(), at.y() );
132 const QRectF ellipseMarker = QRectF( at.x() - markerSize.width() / 2,
133 at.y() - markerSize.height() / 2,
134 markerSize.width(), markerSize.height() );
136 QPointF startMarker[3];
138 startMarker[0] = startPoint + QPointF( 0, markerSize.height() / 2 );
139 startMarker[1] = startPoint + QPointF( markerSize.width() / 2, 0 );
140 startMarker[2] = startPoint - QPointF( 0, markerSize.height() / 2 );
142 startMarker[0] = startPoint + QPointF( 0, markerSize.height() / 2 );
143 startMarker[1] = startPoint + QPointF( markerSize.width() / 2, 0 );
144 startMarker[2] = startPoint - QPointF( markerSize.width() / 2, 0 );
147 QPointF endMarker[3];
150 endMarker[0] = endPoint + QPointF( markerSize.width() / 2, 0 );
151 endMarker[1] = endPoint - QPointF( 0, markerSize.height() / 2 );
152 endMarker[2] = endPoint - QPointF( markerSize.width() / 2, 0 );
154 endMarker[0] = endPoint + QPointF( 0, markerSize.width() / 2 );
155 endMarker[1] = endPoint - QPointF( 0, markerSize.height() / 2 );
156 endMarker[2] = endPoint - QPointF( markerSize.width() / 2, 0 );
159 QPointF topLeft = startPoint;
160 QPointF bottomRightOffset = endPoint - topLeft;
161 QSizeF size( bottomRightOffset.x(), bottomRightOffset.y() );
162 QRectF area( topLeft, size );
164 PainterSaver painterSaver( ctx->
painter() );
166 ctx->
painter()->setBrush( QBrush() );
167 ctx->
painter()->drawLine( markerPoint, startPoint );
168 ctx->
painter()->drawLine( markerPoint, endPoint );
174 ctx->
painter()->drawEllipse( ellipseMarker );
178 ctx->
painter()->drawPolygon( startMarker, 3 );
179 ctx->
painter()->drawPolygon( endMarker, 3 );
186 if (
Plotter *plotter = qobject_cast< Plotter* >( diagram ) ) {
187 return plotter->threeDLineAttributes( index );
188 }
else if (
LineDiagram *lineDiagram = qobject_cast< LineDiagram* >( diagram ) ) {
189 return lineDiagram->threeDLineAttributes( index );
197 if (
Plotter *plotter = qobject_cast< Plotter* >( diagram ) ) {
198 return plotter->valueTrackerAttributes( index );
199 }
else if (
LineDiagram *lineDiagram = qobject_cast< LineDiagram* >( diagram ) ) {
200 return lineDiagram->valueTrackerAttributes( index );
207 const LabelPaintCache& lpc,
const LineAttributesInfoList& lineList )
211 const PainterSaver painterSaver( ctx->
painter() );
217 KDAB_FOREACH (
const LineAttributesInfo& lineInfo, lineList ) {
218 const QModelIndex& index = lineInfo.index;
223 lineInfo.nextValue, td, &diagramPrivate->reverseMapper );
225 const QBrush brush( diagram->
brush( index ) );
226 const QPen pen( diagram->
pen( index ) );
232 if (pen.style() != Qt::NoPen)
233 diagramPrivate->reverseMapper.addLine( lineInfo.index.row(), lineInfo.index.column(),
234 lineInfo.value, lineInfo.nextValue );
236 if ( points.count() && points.last() == lineInfo.value && curBrush == brush && curPen == pen ) {
240 if ( points.count() ) {
246 points << lineInfo.value;
248 points << lineInfo.nextValue;
251 if ( points.count() ) {
256 KDAB_FOREACH (
const LineAttributesInfo& lineInfo, lineList ) {
264 diagramPrivate->paintDataValueTextsAndMarkers( ctx, lpc,
true );
272 for (
int i = 0; i < areas.count(); ++i )
274 const QPolygonF& p = areas[ i ];
275 path.addPolygon( p );
276 diagramPrivate->reverseMapper.addPolygon( index.row(), index.column(), p );
281 QBrush trans = diagram->
brush( index );
283 trans = threeDAttrs.
threeDBrush( trans, path.boundingRect() );
285 QColor transColor = trans.color();
286 transColor.setAlpha( opacity );
287 trans.setColor(transColor);
288 QPen indexPen = diagram->
pen(index);
289 indexPen.setBrush( trans );
290 const PainterSaver painterSaver( ctx->
painter() );
294 ctx->
painter()->setBrush( trans );
296 ctx->
painter()->drawPath( path );
bool isVerticalRangeReversed() const
void paintElements(AbstractDiagram::Private *diagramPrivate, PaintContext *ctx, const LabelPaintCache &lpc, const LineAttributesInfoList &lineList)
const QPointF project(const QPointF &point, const ThreeDLineAttributes &tdAttributes)
virtual const QPointF translate(const QPointF &diagramPoint) const =0
Translate the given point in value space coordinates to a position in pixel space.
AbstractCoordinatePlane * coordinatePlane() const
static ValueTrackerAttributes valueTrackerAttributes(AbstractDiagram *diagram, const QModelIndex &index)
QPainter * painter() const
QBrush markerBrush() const
Plotter defines a diagram type plotting two-dimensional data.
AbstractDiagram defines the interface for diagram classes.
QBrush brush() const
Retrieve the brush to be used for painting datapoints globally.
bool isHorizontalRangeReversed() const
The ReverseMapper stores information about objects on a chart and their respective model indexes...
uint lineXRotation() const
void paintAreas(AbstractDiagram::Private *diagramPrivate, PaintContext *ctx, const QModelIndex &index, const QList< QPolygonF > &areas, uint opacity)
LineDiagram defines a common line diagram.
bool antiAliasing() const
Cell-specific attributes regarding value tracking.
Stores information about painting diagrams.
uint lineYRotation() const
Qt::Orientations orientations() const
QPen pen() const
Retrieve the pen to be used for painting datapoints globally.
virtual QBrush threeDBrush(const QBrush &brush, const QRectF &rect) const
DataDimensionsList gridDimensionsList()
Returns the dimensions used for drawing the grid lines.
void addPolygon(int row, int column, const QPolygonF &polygon)
void paintPolyline(PaintContext *ctx, const QBrush &brush, const QPen &pen, const QPolygonF &points)
static QPen scalePen(const QPen &pen)
void paintValueTracker(PaintContext *ctx, const ValueTrackerAttributes &vt, const QPointF &at)
Cartesian coordinate plane.
void paintThreeDLines(PaintContext *ctx, AbstractDiagram *diagram, const QModelIndex &index, const QPointF &from, const QPointF &to, const ThreeDLineAttributes &tdAttributes, ReverseMapper *reverseMapper)
QBrush arrowBrush() const
static ThreeDLineAttributes threeDLineAttributes(AbstractDiagram *diagram, const QModelIndex &index)
QSizeF markerSize() const
A set of 3D line attributes.