|
22 | 22 | #include "qgscomposeritemwidget.h"
|
23 | 23 | #include "qgscomposition.h"
|
24 | 24 | #include "qgsexpressionbuilderdialog.h"
|
| 25 | +#include "qgssvgcache.h" |
25 | 26 | #include <QDoubleValidator>
|
26 | 27 | #include <QFileDialog>
|
27 | 28 | #include <QFileInfo>
|
@@ -435,6 +436,35 @@ void QgsComposerPictureWidget::setGuiElementValues()
|
435 | 436 | }
|
436 | 437 | }
|
437 | 438 |
|
| 439 | +QIcon QgsComposerPictureWidget::svgToIcon( const QString& filePath ) const |
| 440 | +{ |
| 441 | + QColor fill, outline; |
| 442 | + double outlineWidth, fillOpacity, outlineOpacity; |
| 443 | + bool fillParam, fillOpacityParam, outlineParam, outlineWidthParam, outlineOpacityParam; |
| 444 | + bool hasDefaultFillColor = false, hasDefaultFillOpacity = false, hasDefaultOutlineColor = false, |
| 445 | + hasDefaultOutlineWidth = false, hasDefaultOutlineOpacity = false; |
| 446 | + QgsSvgCache::instance()->containsParams( filePath, fillParam, hasDefaultFillColor, fill, |
| 447 | + fillOpacityParam, hasDefaultFillOpacity, fillOpacity, |
| 448 | + outlineParam, hasDefaultOutlineColor, outline, |
| 449 | + outlineWidthParam, hasDefaultOutlineWidth, outlineWidth, |
| 450 | + outlineOpacityParam, hasDefaultOutlineOpacity, outlineOpacity ); |
| 451 | + |
| 452 | + //if defaults not set in symbol, use these values |
| 453 | + if ( !hasDefaultFillColor ) |
| 454 | + fill = QColor( 200, 200, 200 ); |
| 455 | + fill.setAlphaF( hasDefaultFillOpacity ? fillOpacity : 1.0 ); |
| 456 | + if ( !hasDefaultOutlineColor ) |
| 457 | + outline = Qt::black; |
| 458 | + outline.setAlphaF( hasDefaultOutlineOpacity ? outlineOpacity : 1.0 ); |
| 459 | + if ( !hasDefaultOutlineWidth ) |
| 460 | + outlineWidth = 0.6; |
| 461 | + |
| 462 | + bool fitsInCache; // should always fit in cache at these sizes (i.e. under 559 px ^ 2, or half cache size) |
| 463 | + const QImage& img = QgsSvgCache::instance()->svgAsImage( filePath, 30.0, fill, outline, outlineWidth, 3.5 /*appr. 88 dpi*/, 1.0, fitsInCache ); |
| 464 | + |
| 465 | + return QIcon( QPixmap::fromImage( img ) ); |
| 466 | +} |
| 467 | + |
438 | 468 | int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )
|
439 | 469 | {
|
440 | 470 | //go through all files of a directory
|
@@ -484,7 +514,8 @@ int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )
|
484 | 514 |
|
485 | 515 | if ( fileIsSvg )
|
486 | 516 | {
|
487 |
| - QIcon icon( filePath ); |
| 517 | + // render SVG file |
| 518 | + QIcon icon = svgToIcon( filePath ); |
488 | 519 | listItem->setIcon( icon );
|
489 | 520 | }
|
490 | 521 | else //for pixel formats: create icon from scaled pixmap
|
|
0 commit comments