Newer
Older
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_symbol.h"
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "qwt_painter.h"
#include "qwt_graphic.h"
#include <qapplication.h>
#include <qpainter.h>
#include <qpainterpath.h>
#include <qpixmap.h>
#include <qpaintengine.h>
#include <qmath.h>
#ifndef QWT_NO_SVG
#include <qsvgrenderer.h>
#endif
namespace QwtTriangle
{
enum Type
{
Left,
Right,
Up,
Down
};
}
static QwtGraphic qwtPathGraphic( const QPainterPath &path,
const QPen &pen, const QBrush& brush )
{
QwtGraphic graphic;
graphic.setRenderHint( QwtGraphic::RenderPensUnscaled );
QPainter painter( &graphic );
painter.setPen( pen );
painter.setBrush( brush );
painter.drawPath( path );
painter.end();
return graphic;
}
static inline QRectF qwtScaledBoundingRect(
const QwtGraphic &graphic, const QSizeF size )
{
QSizeF scaledSize = size;
if ( scaledSize.isEmpty() )
scaledSize = graphic.defaultSize();
const QSizeF sz = graphic.controlPointRect().size();
double sx = 1.0;
if ( sz.width() > 0.0 )
sx = scaledSize.width() / sz.width();
double sy = 1.0;
if ( sz.height() > 0.0 )
sy = scaledSize.height() / sz.height();
return graphic.scaledBoundingRect( sx, sy );
}
static inline void qwtDrawPixmapSymbols( QPainter *painter,
const QPointF *points, int numPoints, const QwtSymbol &symbol )
{
QSize size = symbol.size();
if ( size.isEmpty() )
size = symbol.pixmap().size();
const QTransform transform = painter->transform();
if ( transform.isScaling() )
{
const QRect r( 0, 0, size.width(), size.height() );
size = transform.mapRect( r ).size();
}
QPixmap pm = symbol.pixmap();
if ( pm.size() != size )
pm = pm.scaled( size );
QPointF pinPoint( 0.5 * size.width(), 0.5 * size.height() );
if ( symbol.isPinPointEnabled() )
pinPoint = symbol.pinPoint();
painter->resetTransform();
for ( int i = 0; i < numPoints; i++ )
{
const QPointF pos = transform.map( points[i] ) - pinPoint;
QwtPainter::drawPixmap( painter,
QRect( pos.toPoint(), pm.size() ), pm );
}
}
#ifndef QWT_NO_SVG
static inline void qwtDrawSvgSymbols( QPainter *painter,
const QPointF *points, int numPoints,
QSvgRenderer *renderer, const QwtSymbol &symbol )
{
if ( renderer == NULL || !renderer->isValid() )
return;
const QRectF viewBox = renderer->viewBoxF();
if ( viewBox.isEmpty() )
return;
QSizeF sz = symbol.size();
if ( !sz.isValid() )
sz = viewBox.size();
const double sx = sz.width() / viewBox.width();
const double sy = sz.height() / viewBox.height();
QPointF pinPoint = viewBox.center();
if ( symbol.isPinPointEnabled() )
pinPoint = symbol.pinPoint();
const double dx = sx * ( pinPoint.x() - viewBox.left() );
const double dy = sy * ( pinPoint.y() - viewBox.top() );
for ( int i = 0; i < numPoints; i++ )
{
const double x = points[i].x() - dx;
const double y = points[i].y() - dy;
renderer->render( painter,
QRectF( x, y, sz.width(), sz.height() ) );
}
}
#endif
static inline void qwtDrawGraphicSymbols( QPainter *painter,
const QPointF *points, int numPoints, const QwtGraphic &graphic,
const QwtSymbol &symbol )
{
const QRectF pointRect = graphic.controlPointRect();
if ( pointRect.isEmpty() )
return;
double sx = 1.0;
double sy = 1.0;
const QSize sz = symbol.size();
if ( sz.isValid() )
{
sx = sz.width() / pointRect.width();
sy = sz.height() / pointRect.height();
}
QPointF pinPoint = pointRect.center();
if ( symbol.isPinPointEnabled() )
pinPoint = symbol.pinPoint();
const QTransform transform = painter->transform();
for ( int i = 0; i < numPoints; i++ )
{
QTransform tr = transform;
tr.translate( points[i].x(), points[i].y() );
tr.scale( sx, sy );
tr.translate( -pinPoint.x(), -pinPoint.y() );
painter->setTransform( tr );
graphic.render( painter );
}
painter->setTransform( transform );
}
static inline void qwtDrawEllipseSymbols( QPainter *painter,
const QPointF *points, int numPoints, const QwtSymbol &symbol )
{
painter->setBrush( symbol.brush() );
painter->setPen( symbol.pen() );
const QSize size = symbol.size();
if ( QwtPainter::roundingAlignment( painter ) )
{
const int sw = size.width();
const int sh = size.height();
const int sw2 = size.width() / 2;
const int sh2 = size.height() / 2;
for ( int i = 0; i < numPoints; i++ )
{
const int x = qRound( points[i].x() );
const int y = qRound( points[i].y() );
const QRectF r( x - sw2, y - sh2, sw, sh );
Loading
Loading full blame...