QGIS API Documentation 3.39.0-Master (47f7b3a4989)
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 switch ( m )
80 {
81 case PdmWidth:
82 val = static_cast< int >( mPaintEngine->maskPainterPath().boundingRect().width() );
83 break;
84 case PdmHeight:
85 val = static_cast< int >( mPaintEngine->maskPainterPath().boundingRect().height() );
86 break;
87 case PdmWidthMM:
88 val = static_cast< int >( 25.4 / qt_defaultDpiX() * mPaintEngine->maskPainterPath().boundingRect().width() );
89 break;
90 case PdmHeightMM:
91 val = static_cast< int >( 25.4 / qt_defaultDpiY() * mPaintEngine->maskPainterPath().boundingRect().height() );
92 break;
93 case PdmDpiX:
94 case PdmPhysicalDpiX:
95 val = qt_defaultDpiX();
96 break;
97 case PdmDpiY:
98 case PdmPhysicalDpiY:
99 val = qt_defaultDpiY();
100 break;
101 case PdmNumColors:
102 val = 16777216;
103 break;
104 case PdmDepth:
105 val = 24;
106 break;
107 case PdmDevicePixelRatio:
108 val = 1;
109 break;
110 case PdmDevicePixelRatioScaled:
111 val = static_cast< int >( 1 * QPaintDevice::devicePixelRatioFScale() );
112 break;
113 default:
114 val = 0;
115 qWarning( "QPicture::metric: Invalid metric command" );
116 }
117 return val;
118}
119
121{
122 return mPaintEngine->maskPainterPath();
123}
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
Q_GUI_EXPORT int qt_defaultDpiX()
Q_GUI_EXPORT int qt_defaultDpiX()
Q_GUI_EXPORT int qt_defaultDpiY()
Q_GUI_EXPORT int qt_defaultDpiY()