QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsmaskpaintdevice.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaskpaintdevice.h
3 --------------------------------------
4 Date : February 2022
5 Copyright : (C) 2022 by Julien Cabieces
6 Email : julien dot cabieces at oslandia dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgsmaskpaintdevice.h"
17
18
19Q_GUI_EXPORT extern int qt_defaultDpiX();
20Q_GUI_EXPORT extern int qt_defaultDpiY();
21
23
24QgsMaskPaintEngine::QgsMaskPaintEngine( bool usePathStroker )
25 : QPaintEngine( QPaintEngine::AllFeatures )
26 , mUsePathStroker( usePathStroker )
27{
28}
29
30QPainterPath QgsMaskPaintEngine::maskPainterPath() const
31{
32 return mMaskPainterPath;
33}
34
35void QgsMaskPaintEngine::drawPath( const QPainterPath &path )
36{
37 QPainterPath realPath = path;
38 if ( mUsePathStroker )
39 {
40 QPen pen = painter()->pen();
41 QPainterPathStroker stroker( pen );
42 QPainterPath strokedPath = stroker.createStroke( path );
43 realPath = strokedPath;
44 }
45
46 const QTransform transform = painter()->combinedTransform();
47 mMaskPainterPath.addPath( transform.map( realPath ) );
48}
49
50void QgsMaskPaintEngine::drawPolygon( const QPointF *points, int numPoints, QPaintEngine::PolygonDrawMode mode )
51{
52 Q_UNUSED( mode );
53
54 QPolygonF polygon;
55 polygon.reserve( numPoints );
56 for ( int i = 0; i < numPoints; ++i )
57 polygon << points[i];
58
59 const QTransform transform = painter()->transform();
60 mMaskPainterPath.addPolygon( transform.map( polygon ) );
61}
62
64
66{
67 mPaintEngine = std::make_unique<QgsMaskPaintEngine>( usePathStroker );
68}
69
71{
72 return mPaintEngine.get();
73}
74
75int QgsMaskPaintDevice::metric( PaintDeviceMetric m ) const
76{
77 // copy/paste from qpicture.cpp
78 int val;
79 QRectF brect = mPaintEngine->maskPainterPath().boundingRect();
80 switch ( m )
81 {
82 case PdmWidth:
83 val = brect.width();
84 break;
85 case PdmHeight:
86 val = brect.height();
87 break;
88 case PdmWidthMM:
89 val = int( 25.4 / qt_defaultDpiX() * brect.width() );
90 break;
91 case PdmHeightMM:
92 val = int( 25.4 / qt_defaultDpiY() * brect.height() );
93 break;
94 case PdmDpiX:
95 case PdmPhysicalDpiX:
96 val = qt_defaultDpiX();
97 break;
98 case PdmDpiY:
99 case PdmPhysicalDpiY:
100 val = qt_defaultDpiY();
101 break;
102 case PdmNumColors:
103 val = 16777216;
104 break;
105 case PdmDepth:
106 val = 24;
107 break;
108 case PdmDevicePixelRatio:
109 val = 1;
110 break;
111 case PdmDevicePixelRatioScaled:
112 val = 1 * QPaintDevice::devicePixelRatioFScale();
113 break;
114 default:
115 val = 0;
116 qWarning( "QPicture::metric: Invalid metric command" );
117 }
118 return val;
119}
120
122{
123 return mPaintEngine->maskPainterPath();
124}
QgsMaskPaintDevice(bool usePathStroker=false)
QPainterPath maskPainterPath() const
Returns the mask painter path painted on this paint device.
int metric(PaintDeviceMetric metric) const override
QPaintEngine * paintEngine() const override
Q_GUI_EXPORT int qt_defaultDpiX()
Q_GUI_EXPORT int qt_defaultDpiX()
Q_GUI_EXPORT int qt_defaultDpiY()