@@ -46,9 +46,9 @@ QgsAppScreenShots::QgsAppScreenShots( const QString &saveDirectory )
46
46
<< mPolygonLayer );
47
47
}
48
48
49
- QPixmap QgsAppScreenShots::takeScreenshot ( QWidget *widget, GrabMode mode )
49
+ QPixmap QgsAppScreenShots::takeScreenshot ( QWidget *widget, GrabMode mode, QRect crop, bool gradient )
50
50
{
51
- QPixmap pix ;
51
+ QPixmap pixmap ;
52
52
QRect geom;
53
53
54
54
QScreen *scr = screen ( widget );
@@ -57,7 +57,7 @@ QPixmap QgsAppScreenShots::takeScreenshot( QWidget *widget, GrabMode mode )
57
57
widget->raise ();
58
58
if ( mode == GrabWidget )
59
59
{
60
- pix = widget->grab ();
60
+ pixmap = widget->grab ();
61
61
}
62
62
else if ( mode == GrabWidgetAndFrame )
63
63
{
@@ -67,27 +67,17 @@ QPixmap QgsAppScreenShots::takeScreenshot( QWidget *widget, GrabMode mode )
67
67
if ( !widget || mode != GrabWidget )
68
68
{
69
69
WId wid = widget ? widget->winId () : 0 ;
70
- pix = scr->grabWindow ( wid );
70
+ pixmap = scr->grabWindow ( wid );
71
71
if ( !geom.isEmpty () )
72
72
{
73
73
qreal dpr = scr->devicePixelRatio ();
74
- pix = pix .copy ( static_cast <int >( geom.x () * dpr ),
75
- static_cast <int >( geom.y () * dpr ),
76
- static_cast <int >( geom.width () * dpr ),
77
- static_cast <int >( geom.height () * dpr ) );
74
+ pixmap = pixmap .copy ( static_cast <int >( geom.x () * dpr ),
75
+ static_cast <int >( geom.y () * dpr ),
76
+ static_cast <int >( geom.width () * dpr ),
77
+ static_cast <int >( geom.height () * dpr ) );
78
78
}
79
79
}
80
- return pix;
81
- }
82
80
83
- void QgsAppScreenShots::takeScreenshot ( const QString &name, QWidget *widget, QgsAppScreenShots::GrabMode mode )
84
- {
85
- QPixmap pixmap = takeScreenshot ( widget, mode );
86
- saveScreenshot ( pixmap, name );
87
- }
88
-
89
- void QgsAppScreenShots::saveScreenshot ( QPixmap &pixmap, const QString &name, QRect crop, bool gradient )
90
- {
91
81
if ( !crop.isNull () )
92
82
{
93
83
if ( crop.height () == 0 )
@@ -96,13 +86,20 @@ void QgsAppScreenShots::saveScreenshot( QPixmap &pixmap, const QString &name, QR
96
86
crop.setWidth ( pixmap.width () );
97
87
}
98
88
if ( !crop.isEmpty () )
89
+ {
90
+ qreal dpr = scr->devicePixelRatio ();
91
+ crop = QRect ( static_cast <int >( crop.x () * dpr ),
92
+ static_cast <int >( crop.y () * dpr ),
93
+ static_cast <int >( crop.width () * dpr ),
94
+ static_cast <int >( crop.height () * dpr ) );
99
95
pixmap = pixmap.copy ( crop );
96
+ }
100
97
101
98
102
99
if ( gradient )
103
100
{
104
101
QImage img = pixmap.toImage ();
105
- QLinearGradient linearGrad ( QPointF ( 0 , pixmap.height () - 200 ), QPointF ( 0 , pixmap.height () - 20 ) );
102
+ QLinearGradient linearGrad ( QPointF ( 0 , pixmap.height () - mGradientSize ), QPointF ( 0 , pixmap.height () - mGradientSize / 10 ) );
106
103
linearGrad.setColorAt ( 0 , Qt::transparent );
107
104
linearGrad.setColorAt ( 1 , Qt::white );
108
105
@@ -113,6 +110,17 @@ void QgsAppScreenShots::saveScreenshot( QPixmap &pixmap, const QString &name, QR
113
110
pixmap = QPixmap::fromImage ( img );
114
111
}
115
112
113
+ return pixmap;
114
+ }
115
+
116
+ void QgsAppScreenShots::takeScreenshot ( const QString &name, QWidget *widget, QgsAppScreenShots::GrabMode mode )
117
+ {
118
+ QPixmap pixmap = takeScreenshot ( widget, mode );
119
+ saveScreenshot ( pixmap, name );
120
+ }
121
+
122
+ void QgsAppScreenShots::saveScreenshot ( QPixmap &pixmap, const QString &name )
123
+ {
116
124
const QString &fileName = mSaveDirectory + " /" + name + " .png" ;
117
125
pixmap.save ( fileName );
118
126
QgsMessageLog::logMessage ( QString ( " Screenshot saved: %1" ).arg ( fileName ) );
@@ -168,6 +176,11 @@ void QgsAppScreenShots::takePicturesOf( Categories categories )
168
176
takeVectorLayerProperties ();
169
177
}
170
178
179
+ void QgsAppScreenShots::setGradientSize ( int size )
180
+ {
181
+ mGradientSize = size;
182
+ }
183
+
171
184
172
185
// ----------------------
173
186
// !!!!! SCREENSHOTS !!!!
@@ -224,8 +237,9 @@ void QgsAppScreenShots::take25dSymbol()
224
237
QCoreApplication::processEvents ();
225
238
dlg->adjustSize ();
226
239
QCoreApplication::processEvents ();
227
- QPixmap pixmap = takeScreenshot ( dlg );
228
- saveScreenshot ( pixmap, rootName + QLatin1String ( " 25dsymbol" ), QRect ( 0 , 0 , 0 , 800 ), true );
240
+ int cropHeight = w->mAdvancedConfigurationBox ->mapTo ( dlg, w->mAdvancedConfigurationBox ->frameGeometry ().bottomLeft () ).y ();
241
+ QPixmap pixmap = takeScreenshot ( dlg, GrabWidgetAndFrame, QRect ( 0 , 0 , 0 , cropHeight ), true );
242
+ saveScreenshot ( pixmap, rootName + QLatin1String ( " 25dsymbol" ) );
229
243
230
244
// exit properly
231
245
dlg->close ();
0 commit comments