14 #include <qpaintengine.h> 17 #include <qpainterpath.h> 22 const QPen pen = painter->pen();
24 bool scalablePen =
false;
26 if ( pen.style() != Qt::NoPen && pen.brush().style() != Qt::NoBrush )
28 scalablePen = !pen.isCosmetic();
29 if ( !scalablePen && pen.widthF() == 0.0 )
31 const QPainter::RenderHints hints = painter->renderHints();
32 if ( hints.testFlag( QPainter::NonCosmeticDefaultPen ) )
41 const QPainter *painter,
const QPainterPath &path )
43 QPainterPathStroker stroker;
44 stroker.setWidth( painter->pen().widthF() );
45 stroker.setCapStyle( painter->pen().capStyle() );
46 stroker.setJoinStyle( painter->pen().joinStyle() );
47 stroker.setMiterLimit( painter->pen().miterLimit() );
52 QPainterPath stroke = stroker.createStroke(path);
53 rect = painter->transform().map(stroke).boundingRect();
57 QPainterPath mappedPath = painter->transform().map(path);
58 mappedPath = stroker.createStroke( mappedPath );
60 rect = mappedPath.boundingRect();
69 const QTransform &transform,
70 const QTransform *initialTransform )
79 && painter->transform().isScaling() )
81 bool isCosmetic = painter->pen().isCosmetic();
82 if ( isCosmetic && painter->pen().widthF() == 0.0 )
84 QPainter::RenderHints hints = painter->renderHints();
85 if ( hints.testFlag( QPainter::NonCosmeticDefaultPen ) )
94 const QTransform tr = painter->transform();
96 painter->resetTransform();
98 QPainterPath
path = tr.map( *cmd.
path() );
99 if ( initialTransform )
101 painter->setTransform( *initialTransform );
102 path = initialTransform->inverted().map( path );
105 painter->drawPath( path );
107 painter->setTransform( tr );
111 painter->drawPath( *cmd.
path() );
124 painter->drawImage( data->
rect, data->
image,
132 if ( data->
flags & QPaintEngine::DirtyPen )
133 painter->setPen( data->
pen );
135 if ( data->
flags & QPaintEngine::DirtyBrush )
136 painter->setBrush( data->
brush );
138 if ( data->
flags & QPaintEngine::DirtyBrushOrigin )
141 if ( data->
flags & QPaintEngine::DirtyFont )
142 painter->setFont( data->
font );
144 if ( data->
flags & QPaintEngine::DirtyBackground )
150 if ( data->
flags & QPaintEngine::DirtyTransform )
152 painter->setTransform( data->
transform * transform );
155 if ( data->
flags & QPaintEngine::DirtyClipEnabled )
158 if ( data->
flags & QPaintEngine::DirtyClipRegion)
164 if ( data->
flags & QPaintEngine::DirtyClipPath )
169 if ( data->
flags & QPaintEngine::DirtyHints)
171 const QPainter::RenderHints hints = data->
renderHints;
173 painter->setRenderHint( QPainter::Antialiasing,
174 hints.testFlag( QPainter::Antialiasing ) );
176 painter->setRenderHint( QPainter::TextAntialiasing,
177 hints.testFlag( QPainter::TextAntialiasing ) );
179 painter->setRenderHint( QPainter::SmoothPixmapTransform,
180 hints.testFlag( QPainter::SmoothPixmapTransform ) );
182 painter->setRenderHint( QPainter::HighQualityAntialiasing,
183 hints.testFlag( QPainter::HighQualityAntialiasing ) );
185 painter->setRenderHint( QPainter::NonCosmeticDefaultPen,
186 hints.testFlag( QPainter::NonCosmeticDefaultPen ) );
189 if ( data->
flags & QPaintEngine::DirtyCompositionMode)
192 if ( data->
flags & QPaintEngine::DirtyOpacity)
193 painter->setOpacity( data->
opacity );
221 bool scalePens )
const 223 if ( sx == 1.0 && sy == 1.0 )
226 QTransform transform;
227 transform.scale( sx, sy );
243 rect.adjust( -l, -t, r, b );
250 const QRectF &targetRect,
bool scalePens )
const 252 if ( pathRect.width() <= 0.0 )
257 const double l = qAbs( pathRect.left() - p0.x() );
258 const double r = qAbs( pathRect.right() - p0.x() );
260 const double w = 2.0 * qMin( l, r )
261 * targetRect.width() / pathRect.width();
270 const double pw = qMax(
281 const QRectF &targetRect,
bool scalePens )
const 283 if ( pathRect.height() <= 0.0 )
288 const double t = qAbs( pathRect.top() - p0.y() );
289 const double b = qAbs( pathRect.bottom() - p0.y() );
291 const double h = 2.0 * qMin( t, b )
292 * targetRect.height() / pathRect.height();
322 pointRect( 0.0, 0.0, -1.0, -1.0 ),
323 initialTransform( NULL )
492 if ( sx == 1.0 && sy == 1.0 )
495 QTransform transform;
496 transform.scale( sx, sy );
513 return QSize( qCeil( sz.width() ), qCeil( sz.height() ) );
532 const double w = qMax( qreal( 0.0 ), size.width() );
533 const double h = qMax( qreal( 0.0 ), size.height() );
571 const QTransform transform = painter->transform();
575 for (
int i = 0;
i < numCommands;
i++ )
595 Qt::AspectRatioMode aspectRatioMode )
const 597 const QRectF r( 0.0, 0.0, size.width(), size.height() );
598 render( painter, r, aspectRatioMode );
611 Qt::AspectRatioMode aspectRatioMode )
const 613 if (
isEmpty() || rect.isEmpty() )
625 const bool scalePens =
636 sx = qMin( sx, ssx );
642 sy = qMin( sy, ssy );
645 if ( aspectRatioMode == Qt::KeepAspectRatio )
647 const double s = qMin( sx, sy );
651 else if ( aspectRatioMode == Qt::KeepAspectRatioByExpanding )
653 const double s = qMax( sx, sy );
659 tr.translate( rect.center().x() - 0.5 * sx *
d_data->
pointRect.width(),
664 const QTransform transform = painter->transform();
665 if ( !scalePens && transform.isScaling() )
675 painter->setTransform( tr,
true );
678 painter->setTransform( transform );
696 const QPointF &pos, Qt::Alignment alignment )
const 700 if ( alignment & Qt::AlignLeft )
702 r.moveLeft( pos.x() );
704 else if ( alignment & Qt::AlignHCenter )
706 r.moveCenter( QPointF( pos.x(), r.center().y() ) );
708 else if ( alignment & Qt::AlignRight )
710 r.moveRight( pos.x() );
713 if ( alignment & Qt::AlignTop )
715 r.moveTop( pos.y() );
717 else if ( alignment & Qt::AlignVCenter )
719 r.moveCenter( QPointF( r.center().x(), pos.y() ) );
721 else if ( alignment & Qt::AlignBottom )
723 r.moveBottom( pos.y() );
748 const int w = qCeil( sz.width() );
749 const int h = qCeil( sz.height() );
751 QPixmap pixmap( w, h );
752 pixmap.fill( Qt::transparent );
754 const QRectF r( 0.0, 0.0, sz.width(), sz.height() );
756 QPainter painter( &pixmap );
757 render( &painter, r, Qt::KeepAspectRatio );
776 Qt::AspectRatioMode aspectRatioMode )
const 778 QPixmap pixmap( size );
779 pixmap.fill( Qt::transparent );
781 const QRect r( 0, 0, size.width(), size.height() );
783 QPainter painter( &pixmap );
784 render( &painter, r, aspectRatioMode );
805 Qt::AspectRatioMode aspectRatioMode )
const 807 QImage image( size, QImage::Format_ARGB32_Premultiplied );
810 const QRect r( 0, 0, size.width(), size.height() );
812 QPainter painter( &image );
813 render( &painter, r, aspectRatioMode );
840 const int w = qCeil( sz.width() );
841 const int h = qCeil( sz.height() );
843 QImage image( w, h, QImage::Format_ARGB32 );
846 const QRect r( 0, 0, sz.width(), sz.height() );
848 QPainter painter( &image );
849 render( &painter, r, Qt::KeepAspectRatio );
863 const QPainter *painter =
paintEngine()->painter();
864 if ( painter == NULL )
869 if ( !path.isEmpty() )
871 const QPainterPath scaledPath = painter->transform().map( path );
873 QRectF pointRect = scaledPath.boundingRect();
876 if ( painter->pen().style() != Qt::NoPen
877 && painter->pen().brush().style() != Qt::NoBrush )
900 const QPixmap &pixmap,
const QRectF &subRect )
902 const QPainter *painter =
paintEngine()->painter();
903 if ( painter == NULL )
908 const QRectF r = painter->transform().mapRect( rect );
924 const QRectF &subRect, Qt::ImageConversionFlags flags)
926 const QPainter *painter =
paintEngine()->painter();
927 if ( painter == NULL )
932 const QRectF r = painter->transform().mapRect( rect );
953 const QPainter *painter =
paintEngine()->painter();
954 if ( painter && painter->hasClipping() )
956 QRectF cr = painter->clipRegion().boundingRect();
957 cr = painter->transform().mapRect( cr );
995 const int numCommands = commands.size();
996 if ( numCommands <= 0 )
1004 QPainter painter(
this );
1005 for (
int i = 0;
i < numCommands;
i++ )
QwtGraphic & operator=(const QwtGraphic &)
Assignment operator.
QVector< QwtGraphic::PathInfo > pathInfos
virtual void drawPath(const QPainterPath &)
void render(QPainter *) const
Replay all recorded painter commands.
Qt::ImageConversionFlags flags
double scaleFactorX(const QRectF &pathRect, const QRectF &targetRect, bool scalePens) const
QTransform * initialTransform
QImage toImage() const
Convert the graphic to a QImage.
Attributes how to paint a QPixmap.
QPixmap toPixmap() const
Convert the graphic to a QPixmap.
PathInfo(const QRectF &pointRect, const QRectF &boundingRect, bool scalablePen)
virtual QPaintEngine * paintEngine() const
See QPaintDevice::paintEngine()
A null paint device doing nothing.
QSizeF defaultSize() const
Default size.
QRectF boundingRect() const
virtual QSize sizeMetrics() const
QFlags< RenderHint > RenderHints
Render hints.
void setCommands(QVector< QwtPainterCommand > &)
Append paint commands.
void setRenderHint(RenderHint, bool on=true)
QRectF controlPointRect() const
static void qwtExecCommand(QPainter *painter, const QwtPainterCommand &cmd, QwtGraphic::RenderHints renderHints, const QTransform &transform, const QTransform *initialTransform)
void setDefaultSize(const QSizeF &)
Set a default size.
Qt::BGMode backgroundMode
virtual ~QwtGraphic()
Destructor.
QPainter::CompositionMode compositionMode
GraphId path[kMaxDeadlockPathLen]
QPainter::RenderHints renderHints
PixmapData * pixmapData()
void reset()
Clear all stored commands.
A paint device for scalable graphics.
Qt::ClipOperation clipOperation
void updateControlPointRect(const QRectF &)
Attributes of a state change.
QPaintEngine::DirtyFlags flags
double scaleFactorY(const QRectF &pathRect, const QRectF &targetRect, bool scalePens) const
TFSIMD_FORCE_INLINE const tfScalar & w() const
static QRectF qwtStrokedPathRect(const QPainter *painter, const QPainterPath &path)
virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &)
Store a pixmap command in the command list.
QRectF scaledBoundingRect(double sx, double sy, bool scalePens) const
virtual void drawImage(const QRectF &, const QImage &, const QRectF &, Qt::ImageConversionFlags)
Store a image command in the command list.
Attributes how to paint a QImage.
QVector< QwtPainterCommand > commands
bool testRenderHint(RenderHint) const
static bool qwtHasScalablePen(const QPainter *painter)
const QVector< QwtPainterCommand > & commands() const
QwtGraphic::RenderHints renderHints
QRectF scaledBoundingRect(double sx, double sy) const
Calculate the target rectangle for scaling the graphic.
void updateBoundingRect(const QRectF &)
empty_struct data[sizeof(T)/sizeof(empty_struct)]
virtual void updateState(const QPaintEngineState &state)
Store a state command in the command list.