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_plot_canvas.h"
#include "qwt_painter.h"
#include "qwt_null_paintdevice.h"
#include "qwt_math.h"
#include "qwt_plot.h"
#include <qpainter.h>
#include <qstyle.h>
#include <qstyleoption.h>
#include <qpaintengine.h>
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 <qevent.h>
class QwtStyleSheetRecorder: public QwtNullPaintDevice
{
public:
QwtStyleSheetRecorder( const QSize &size ):
d_size( size )
{
}
virtual void updateState( const QPaintEngineState &state )
{
if ( state.state() & QPaintEngine::DirtyPen )
{
d_pen = state.pen();
}
if ( state.state() & QPaintEngine::DirtyBrush )
{
d_brush = state.brush();
}
if ( state.state() & QPaintEngine::DirtyBrushOrigin )
{
d_origin = state.brushOrigin();
}
}
virtual void drawRects(const QRectF *rects, int count )
{
for ( int i = 0; i < count; i++ )
border.rectList += rects[i];
}
virtual void drawPath( const QPainterPath &path )
{
const QRectF rect( QPointF( 0.0, 0.0 ), d_size );
if ( path.controlPointRect().contains( rect.center() ) )
{
setCornerRects( path );
alignCornerRects( rect );
background.path = path;
background.brush = d_brush;
background.origin = d_origin;
}
else
{
border.pathList += path;
}
}
void setCornerRects( const QPainterPath &path )
{
QPointF pos( 0.0, 0.0 );
for ( int i = 0; i < path.elementCount(); i++ )
{
QPainterPath::Element el = path.elementAt(i);
switch( el.type )
{
case QPainterPath::MoveToElement:
case QPainterPath::LineToElement:
{
pos.setX( el.x );
pos.setY( el.y );
break;
}
case QPainterPath::CurveToElement:
{
QRectF r( pos, QPointF( el.x, el.y ) );
clipRects += r.normalized();
pos.setX( el.x );
pos.setY( el.y );
break;
}
case QPainterPath::CurveToDataElement:
{
if ( clipRects.size() > 0 )
{
QRectF r = clipRects.last();
r.setCoords(
qMin( r.left(), el.x ),
qMin( r.top(), el.y ),
qMax( r.right(), el.x ),
qMax( r.bottom(), el.y )
);
clipRects.last() = r.normalized();
}
break;
}
}
}
}
protected:
virtual QSize sizeMetrics() const
{
return d_size;
}
private:
void alignCornerRects( const QRectF &rect )
{
for ( int i = 0; i < clipRects.size(); i++ )
{
QRectF &r = clipRects[i];
if ( r.center().x() < rect.center().x() )
r.setLeft( rect.left() );
else
r.setRight( rect.right() );
if ( r.center().y() < rect.center().y() )
r.setTop( rect.top() );
else
r.setBottom( rect.bottom() );
}
}
public:
QVector<QRectF> clipRects;
struct Border
{
QList<QPainterPath> pathList;
QList<QRectF> rectList;
QRegion clipRegion;
} border;
struct Background
{
QPainterPath path;
QBrush brush;
QPointF origin;
} background;
private:
const QSize d_size;
QPen d_pen;
QBrush d_brush;
QPointF d_origin;
};
static void qwtDrawBackground( QPainter *painter, QwtPlotCanvas *canvas )
{
painter->save();
const QPainterPath borderClip = canvas->borderPath( canvas->rect() );
if ( !borderClip.isEmpty() )
painter->setClipPath( borderClip, Qt::IntersectClip );
const QBrush &brush =
canvas->palette().brush( canvas->backgroundRole() );
if ( brush.style() == Qt::TexturePattern )
{
QPixmap pm( canvas->size() );
QwtPainter::fillPixmap( canvas, pm );
painter->drawPixmap( 0, 0, pm );
}
else if ( brush.gradient() )
{
QVector<QRect> rects;
if ( brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode )
{
rects += canvas->rect();
}
else
{
rects = painter->clipRegion().rects();
}
#if 1
bool useRaster = false;
if ( painter->paintEngine()->type() == QPaintEngine::X11 )
{
// Qt 4.7.1: gradients on X11 are broken ( subrects +
// QGradient::StretchToDeviceMode ) and horrible slow.
Loading
Loading full blame...