QGIS API Documentation 3.99.0-Master (26c88405ac0)
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#include "qgspainting.h"
19
21
22QgsMaskPaintEngine::QgsMaskPaintEngine( bool usePathStroker )
23 : QPaintEngine( QPaintEngine::AllFeatures )
24 , mUsePathStroker( usePathStroker )
25{
26}
27
28QPainterPath QgsMaskPaintEngine::maskPainterPath() const
29{
30 return mMaskPainterPath;
31}
32
33void QgsMaskPaintEngine::drawPath( const QPainterPath &path )
34{
35 QPainterPath realPath = path;
36 if ( mUsePathStroker )
37 {
38 QPen pen = painter()->pen();
39 QPainterPathStroker stroker( pen );
40 QPainterPath strokedPath = stroker.createStroke( path );
41 realPath = strokedPath;
42 }
43
44 const QTransform transform = painter()->combinedTransform();
45 mMaskPainterPath.addPath( transform.map( realPath ) );
46}
47
48void QgsMaskPaintEngine::drawPolygon( const QPointF *points, int numPoints, QPaintEngine::PolygonDrawMode mode )
49{
50 Q_UNUSED( mode );
51
52 QPolygonF polygon;
53 polygon.reserve( numPoints );
54 for ( int i = 0; i < numPoints; ++i )
55 polygon << points[i];
56
57 const QTransform transform = painter()->transform();
58 mMaskPainterPath.addPolygon( transform.map( polygon ) );
59}
60
62
64{
65 mPaintEngine = std::make_unique<QgsMaskPaintEngine>( usePathStroker );
66}
67
69{
70 return mPaintEngine.get();
71}
72
73int QgsMaskPaintDevice::metric( PaintDeviceMetric m ) const
74{
75 // copy/paste from qpicture.cpp
76 int val;
77 switch ( m )
78 {
79 case PdmWidth:
80 val = static_cast< int >( mPaintEngine->maskPainterPath().boundingRect().width() );
81 break;
82 case PdmHeight:
83 val = static_cast< int >( mPaintEngine->maskPainterPath().boundingRect().height() );
84 break;
85 case PdmWidthMM:
86 val = static_cast< int >( 25.4 / QgsPainting::qtDefaultDpiX() * mPaintEngine->maskPainterPath().boundingRect().width() );
87 break;
88 case PdmHeightMM:
89 val = static_cast< int >( 25.4 / QgsPainting::qtDefaultDpiY() * mPaintEngine->maskPainterPath().boundingRect().height() );
90 break;
91 case PdmDpiX:
92 case PdmPhysicalDpiX:
94 break;
95 case PdmDpiY:
96 case PdmPhysicalDpiY:
98 break;
99 case PdmNumColors:
100 val = 16777216;
101 break;
102 case PdmDepth:
103 val = 24;
104 break;
105 case PdmDevicePixelRatio:
106 val = 1;
107 break;
108 case PdmDevicePixelRatioScaled:
109 val = static_cast< int >( 1 * QPaintDevice::devicePixelRatioFScale() );
110 break;
111 default:
112 val = 0;
113 qWarning( "QPicture::metric: Invalid metric command" );
114 }
115 return val;
116}
117
119{
120 return mPaintEngine->maskPainterPath();
121}
Q_DECL_DEPRECATED QgsMaskPaintDevice(bool usePathStroker=false)
Q_DECL_DEPRECATED QPainterPath maskPainterPath() const
Returns the mask painter path painted on this paint device.
int metric(PaintDeviceMetric metric) const override
QPaintEngine * paintEngine() const override
static int qtDefaultDpiY()
Returns the default Qt vertical DPI.
static int qtDefaultDpiX()
Returns the default Qt horizontal DPI.