source: ntrip/trunk/BNC/qwt/qwt_graphic.h@ 9274

Last change on this file since 9274 was 8127, checked in by stoecker, 8 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 5.6 KB
RevLine 
[8127]1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#ifndef QWT_GRAPHIC_H
11#define QWT_GRAPHIC_H
12
13#include "qwt_global.h"
14#include "qwt_null_paintdevice.h"
15#include <qmetatype.h>
16#include <qimage.h>
17#include <qpixmap.h>
18
19class QwtPainterCommand;
20
21/*!
22 \brief A paint device for scalable graphics
23
24 QwtGraphic is the representation of a graphic that is tailored for
25 scalability. Like QPicture it will be initialized by QPainter
26 operations and can be replayed later to any target paint device.
27
28 While the usual image representations QImage and QPixmap are not
29 scalable Qt offers two paint devices, that might be candidates
30 for representing a vector graphic:
31
32 - QPicture\n
33 Unfortunately QPicture had been forgotten, when Qt4
34 introduced floating point based render engines. Its API
35 is still on integers, what make it unusable for proper scaling.
36
37 - QSvgRenderer/QSvgGenerator\n
38 Unfortunately QSvgRenderer hides to much information about
39 its nodes in internal APIs, that are necessary for proper
40 layout calculations. Also it is derived from QObject and
41 can't be copied like QImage/QPixmap.
42
43 QwtGraphic maps all scalable drawing primitives to a QPainterPath
44 and stores them together with the painter state changes
45 ( pen, brush, transformation ... ) in a list of QwtPaintCommands.
46 For being a complete QPaintDevice it also stores pixmaps or images,
47 what is somehow against the idea of the class, because these objects
48 can't be scaled without a loss in quality.
49
50 The main issue about scaling a QwtGraphic object are the pens used for
51 drawing the outlines of the painter paths. While non cosmetic pens
52 ( QPen::isCosmetic() ) are scaled with the same ratio as the path,
53 cosmetic pens have a fixed width. A graphic might have paths with
54 different pens - cosmetic and non-cosmetic.
55
56 QwtGraphic caches 2 different rectangles:
57
58 - control point rectangle\n
59 The control point rectangle is the bounding rectangle of all
60 control point rectangles of the painter paths, or the target
61 rectangle of the pixmaps/images.
62
63 - bounding rectangle\n
64 The bounding rectangle extends the control point rectangle by
65 what is needed for rendering the outline with an unscaled pen.
66
67 Because the offset for drawing the outline depends on the shape
68 of the painter path ( the peak of a triangle is different than the flat side )
69 scaling with a fixed aspect ratio always needs to be calculated from the
70 control point rectangle.
71
72 \sa QwtPainterCommand
73 */
74class QWT_EXPORT QwtGraphic: public QwtNullPaintDevice
75{
76public:
77 /*!
78 Hint how to render a graphic
79 \sa setRenderHint(), testRenderHint()
80 */
81 enum RenderHint
82 {
83 /*!
84 When rendering a QwtGraphic a specific scaling between
85 the controlPointRect() and the coordinates of the target rectangle
86 is set up internally in render().
87
88 When RenderPensUnscaled is set this specific scaling is applied
89 for the control points only, but not for the pens.
90 All other painter transformations ( set up by application code )
91 are supposed to work like usual.
92
93 \sa render();
94 */
95 RenderPensUnscaled = 0x1
96 };
97
98 /*!
99 \brief Render hints
100
101 The default setting is to disable all hints
102 */
103 typedef QFlags<RenderHint> RenderHints;
104
105 QwtGraphic();
106 QwtGraphic( const QwtGraphic & );
107
108 virtual ~QwtGraphic();
109
110 QwtGraphic& operator=( const QwtGraphic & );
111
112 void reset();
113
114 bool isNull() const;
115 bool isEmpty() const;
116
117 void render( QPainter * ) const;
118
119 void render( QPainter *, const QSizeF &,
120 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
121
122 void render( QPainter *, const QRectF &,
123 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
124
125 void render( QPainter *, const QPointF &,
126 Qt::Alignment = Qt::AlignTop | Qt::AlignLeft ) const;
127
128 QPixmap toPixmap() const;
129 QPixmap toPixmap( const QSize &,
130 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
131
132 QImage toImage() const;
133 QImage toImage( const QSize &,
134 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
135
136 QRectF scaledBoundingRect( double sx, double sy ) const;
137
138 QRectF boundingRect() const;
139 QRectF controlPointRect() const;
140
141 const QVector< QwtPainterCommand > &commands() const;
142 void setCommands( QVector< QwtPainterCommand > & );
143
144 void setDefaultSize( const QSizeF & );
145 QSizeF defaultSize() const;
146
147 void setRenderHint( RenderHint, bool on = true );
148 bool testRenderHint( RenderHint ) const;
149
150protected:
151 virtual QSize sizeMetrics() const;
152
153 virtual void drawPath( const QPainterPath & );
154
155 virtual void drawPixmap( const QRectF &,
156 const QPixmap &, const QRectF & );
157
158 virtual void drawImage( const QRectF &,
159 const QImage &, const QRectF &, Qt::ImageConversionFlags );
160
161 virtual void updateState( const QPaintEngineState &state );
162
163private:
164 void updateBoundingRect( const QRectF & );
165 void updateControlPointRect( const QRectF & );
166
167 class PathInfo;
168
169 class PrivateData;
170 PrivateData *d_data;
171};
172
173Q_DECLARE_OPERATORS_FOR_FLAGS( QwtGraphic::RenderHints )
174Q_DECLARE_METATYPE( QwtGraphic )
175
176#endif
Note: See TracBrowser for help on using the repository browser.