@@ -298,6 +298,11 @@ void QgsSimpleLineSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer )
298
298
mCustomCheckBox ->setCheckState ( useCustomDashPattern ? Qt::Checked : Qt::Unchecked );
299
299
mCustomCheckBox ->blockSignals ( false );
300
300
301
+ // make sure height of custom dash button looks good under different platforms
302
+ QSize size = mChangePatternButton ->minimumSizeHint ();
303
+ int fontHeight = static_cast < int >( Qgis::UI_SCALE_FACTOR * fontMetrics ().height () * 1.4 );
304
+ mChangePatternButton ->setMinimumSize ( QSize ( size.width (), std::max ( size.height (), fontHeight ) ) );
305
+
301
306
// draw inside polygon?
302
307
const bool drawInsidePolygon = mLayer ->drawInsidePolygon ();
303
308
whileBlocking ( mDrawInsideCheckBox )->setCheckState ( drawInsidePolygon ? Qt::Checked : Qt::Unchecked );
@@ -332,7 +337,6 @@ void QgsSimpleLineSymbolLayerWidget::penWidthChanged()
332
337
void QgsSimpleLineSymbolLayerWidget::colorChanged ( const QColor &color )
333
338
{
334
339
mLayer ->setColor ( color );
335
- updatePatternIcon ();
336
340
emit changed ();
337
341
}
338
342
@@ -341,6 +345,7 @@ void QgsSimpleLineSymbolLayerWidget::penStyleChanged()
341
345
mLayer ->setPenStyle ( cboPenStyle->penStyle () );
342
346
mLayer ->setPenJoinStyle ( cboJoinStyle->penJoinStyle () );
343
347
mLayer ->setPenCapStyle ( cboCapStyle->penCapStyle () );
348
+ updatePatternIcon ();
344
349
emit changed ();
345
350
}
346
351
@@ -396,6 +401,7 @@ void QgsSimpleLineSymbolLayerWidget::mPenWidthUnitWidget_changed()
396
401
{
397
402
mLayer ->setWidthUnit ( mPenWidthUnitWidget ->unit () );
398
403
mLayer ->setWidthMapUnitScale ( mPenWidthUnitWidget ->getMapUnitScale () );
404
+ updatePatternIcon ();
399
405
emit changed ();
400
406
}
401
407
}
@@ -416,6 +422,7 @@ void QgsSimpleLineSymbolLayerWidget::mDashPatternUnitWidget_changed()
416
422
{
417
423
mLayer ->setCustomDashPatternUnit ( mDashPatternUnitWidget ->unit () );
418
424
mLayer ->setCustomDashPatternMapUnitScale ( mDashPatternUnitWidget ->getMapUnitScale () );
425
+ updatePatternIcon ();
419
426
emit changed ();
420
427
}
421
428
}
@@ -434,17 +441,53 @@ void QgsSimpleLineSymbolLayerWidget::updatePatternIcon()
434
441
{
435
442
return ;
436
443
}
437
- QgsSimpleLineSymbolLayer * layerCopy = mLayer ->clone ();
444
+ std::unique_ptr< QgsSimpleLineSymbolLayer > layerCopy ( mLayer ->clone () );
438
445
if ( !layerCopy )
439
446
{
440
447
return ;
441
448
}
442
449
QColor color = qApp->palette ().color ( QPalette::WindowText );
443
450
layerCopy->setColor ( color );
451
+ // reset offset, we don't want to show that in the preview
452
+ layerCopy->setOffset ( 0 );
444
453
layerCopy->setUseCustomDashPattern ( true );
445
- QIcon buttonIcon = QgsSymbolLayerUtils::symbolLayerPreviewIcon ( layerCopy, QgsUnitTypes::RenderMillimeters, mChangePatternButton ->iconSize () );
446
- mChangePatternButton ->setIcon ( buttonIcon );
447
- delete layerCopy;
454
+
455
+ QSize currentIconSize;
456
+ // icon size is button size with a small margin
457
+ #ifdef Q_OS_WIN
458
+ currentIconSize = QSize ( mChangePatternButton ->width () - 10 , mChangePatternButton ->height () - 6 );
459
+ #else
460
+ currentIconSize = QSize ( mChangePatternButton ->width () - 10 , mChangePatternButton ->height () - 12 );
461
+ #endif
462
+
463
+ if ( !currentIconSize.isValid () || currentIconSize.width () <= 0 || currentIconSize.height () <= 0 )
464
+ {
465
+ return ;
466
+ }
467
+
468
+ // create an icon pixmap
469
+ std::unique_ptr< QgsLineSymbol > previewSymbol = qgis::make_unique< QgsLineSymbol >( QgsSymbolLayerList () << layerCopy.release () );
470
+ const QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon ( previewSymbol.get (), currentIconSize );
471
+ mChangePatternButton ->setIconSize ( currentIconSize );
472
+ mChangePatternButton ->setIcon ( icon );
473
+
474
+ // set tooltip
475
+ // create very large preview image
476
+ int width = static_cast < int >( Qgis::UI_SCALE_FACTOR * fontMetrics ().width ( ' X' ) * 23 );
477
+ int height = static_cast < int >( width / 1.61803398875 ); // golden ratio
478
+
479
+ QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap ( previewSymbol.get (), QSize ( width, height ), height / 20 );
480
+ QByteArray data;
481
+ QBuffer buffer ( &data );
482
+ pm.save ( &buffer, " PNG" , 100 );
483
+ mChangePatternButton ->setToolTip ( QStringLiteral ( " <img src='data:image/png;base64, %3'>" ).arg ( QString ( data.toBase64 () ) ) );
484
+ }
485
+
486
+ void QgsSimpleLineSymbolLayerWidget::resizeEvent ( QResizeEvent *event )
487
+ {
488
+ QgsSymbolLayerWidget::resizeEvent ( event );
489
+ // redraw custom dash pattern icon -- the button size has changed
490
+ updatePatternIcon ();
448
491
}
449
492
450
493
0 commit comments