diff --git a/doc/api_break.dox b/doc/api_break.dox index 0394a62b113..190f1b947fc 100644 --- a/doc/api_break.dox +++ b/doc/api_break.dox @@ -1423,6 +1423,7 @@ QgsSymbolLayerUtils (renamed from QgsSymbolLayerUtilsV2) {#qgis_api_break - encodeOutputUnit() and decodeOutputUnit() were removed. QgsUnitTypes::encodeUnit() and QgsUnitTypes::decodeRenderUnit() should be used instead. - The signatures for wellKnownMarkerToSld() and wellKnownMarkerFromSld() were changed. +- The symbolPreviewPixmap() customContext is now the fourth parameter QgsSymbolSelectorWidget {#qgis_api_break_3_0_QgsSymbolSelectorWidget} diff --git a/python/core/symbology-ng/qgssymbollayerutils.sip b/python/core/symbology-ng/qgssymbollayerutils.sip index f43c206dde8..12f432519dd 100644 --- a/python/core/symbology-ng/qgssymbollayerutils.sip +++ b/python/core/symbology-ng/qgssymbollayerutils.sip @@ -95,7 +95,23 @@ class QgsSymbolLayerUtils static QPainter::CompositionMode decodeBlendMode( const QString& s ); - static QIcon symbolPreviewIcon( QgsSymbol* symbol, QSize size ); + /** Returns an icon preview for a color ramp. + * @param symbol symbol + * @param size target pixmap size + * @param padding space between icon edge and symbol + * @see symbolPreviewPixmap() + */ + static QIcon symbolPreviewIcon( QgsSymbol* symbol, QSize size, int padding = 0 ); + + /** Returns a pixmap preview for a color ramp. + * @param symbol symbol + * @param size target pixmap size + * @param padding space between icon edge and symbol + * @param customContext render context to use when rendering symbol + * @note customContext parameter added in 2.6 + * @see symbolPreviewIcon() + */ + static QPixmap symbolPreviewPixmap( QgsSymbol* symbol, QSize size, int padding = 0, QgsRenderContext* customContext = 0 ); /** Draws a symbol layer preview to a QPicture * @param layer symbol layer to draw @@ -118,14 +134,23 @@ class QgsSymbolLayerUtils */ static QIcon symbolLayerPreviewIcon( QgsSymbolLayer* layer, QgsUnitTypes::RenderUnit u, QSize size, const QgsMapUnitScale& scale = QgsMapUnitScale() ); - static QIcon colorRampPreviewIcon( QgsColorRamp* ramp, QSize size ); + /** Returns a icon preview for a color ramp. + * @param ramp color ramp + * @param size target icon size + * @param padding space between icon edge and symbol + * @see colorRampPreviewPixmap() + */ + static QIcon colorRampPreviewIcon( QgsColorRamp* ramp, QSize size, int padding = 0 ); + /** Returns a pixmap preview for a color ramp. + * @param ramp color ramp + * @param size target pixmap size + * @param padding space between icon edge and symbol + * @see colorRampPreviewIcon() + */ + static QPixmap colorRampPreviewPixmap( QgsColorRamp* ramp, QSize size, int padding = 0 ); static void drawStippledBackground( QPainter* painter, QRect rect ); - //! @note customContext parameter added in 2.6 - static QPixmap symbolPreviewPixmap( QgsSymbol* symbol, QSize size, QgsRenderContext* customContext = 0 ); - static QPixmap colorRampPreviewPixmap( QgsColorRamp* ramp, QSize size ); - /** Returns the maximum estimated bleed for the symbol */ static double estimateMaxSymbolBleed( QgsSymbol* symbol ); diff --git a/src/core/layertree/qgslayertreemodellegendnode.cpp b/src/core/layertree/qgslayertreemodellegendnode.cpp index 93ca467c667..4dada79f818 100644 --- a/src/core/layertree/qgslayertreemodellegendnode.cpp +++ b/src/core/layertree/qgslayertreemodellegendnode.cpp @@ -168,7 +168,7 @@ QSize QgsSymbolLegendNode::minimumIconSize( QgsRenderContext* context ) const if ( mItem.symbol() && mItem.symbol()->type() == QgsSymbol::Marker ) { minSz = QgsImageOperation::nonTransparentImageRect( - QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), QSize( 512, 512 ), + QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), QSize( 512, 512 ), 0, context ).toImage(), minSz, true ).size(); @@ -176,7 +176,7 @@ QSize QgsSymbolLegendNode::minimumIconSize( QgsRenderContext* context ) const else if ( mItem.symbol() && mItem.symbol()->type() == QgsSymbol::Line ) { minSz = QgsImageOperation::nonTransparentImageRect( - QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), QSize( minSz.width(), 512 ), + QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), QSize( minSz.width(), 512 ), 0, context ).toImage(), minSz, true ).size(); @@ -273,7 +273,7 @@ QVariant QgsSymbolLegendNode::data( int role ) const if ( mItem.symbol() ) { QScopedPointer context( createTemporaryRenderContext() ); - pix = QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), mIconSize, context.data() ); + pix = QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), mIconSize, 0, context.data() ); } else { diff --git a/src/core/symbology-ng/qgssymbollayerutils.cpp b/src/core/symbology-ng/qgssymbollayerutils.cpp index 2f901a38745..c9428d75b48 100644 --- a/src/core/symbology-ng/qgssymbollayerutils.cpp +++ b/src/core/symbology-ng/qgssymbollayerutils.cpp @@ -574,12 +574,12 @@ QPainter::CompositionMode QgsSymbolLayerUtils::decodeBlendMode( const QString &s return QPainter::CompositionMode_SourceOver; // "Normal" } -QIcon QgsSymbolLayerUtils::symbolPreviewIcon( QgsSymbol* symbol, QSize size ) +QIcon QgsSymbolLayerUtils::symbolPreviewIcon( QgsSymbol* symbol, QSize size, int padding ) { - return QIcon( symbolPreviewPixmap( symbol, size ) ); + return QIcon( symbolPreviewPixmap( symbol, size, padding ) ); } -QPixmap QgsSymbolLayerUtils::symbolPreviewPixmap( QgsSymbol* symbol, QSize size, QgsRenderContext* customContext ) +QPixmap QgsSymbolLayerUtils::symbolPreviewPixmap( QgsSymbol* symbol, QSize size, int padding, QgsRenderContext* customContext ) { Q_ASSERT( symbol ); @@ -588,9 +588,21 @@ QPixmap QgsSymbolLayerUtils::symbolPreviewPixmap( QgsSymbol* symbol, QSize size, QPainter painter; painter.begin( &pixmap ); painter.setRenderHint( QPainter::Antialiasing ); + if ( customContext ) + { customContext->setPainter( &painter ); + } + + if ( padding > 0 ) + { + size.setWidth( size.rwidth() - ( padding * 2 ) ); + size.setHeight( size.rheight() - ( padding * 2 ) ); + painter.translate( padding, padding ); + } + symbol->drawPreviewIcon( &painter, size, customContext ); + painter.end(); return pixmap; } @@ -636,12 +648,12 @@ QIcon QgsSymbolLayerUtils::symbolLayerPreviewIcon( QgsSymbolLayer* layer, QgsUni return QIcon( pixmap ); } -QIcon QgsSymbolLayerUtils::colorRampPreviewIcon( QgsColorRamp* ramp, QSize size ) +QIcon QgsSymbolLayerUtils::colorRampPreviewIcon( QgsColorRamp* ramp, QSize size, int padding ) { - return QIcon( colorRampPreviewPixmap( ramp, size ) ); + return QIcon( colorRampPreviewPixmap( ramp, size, padding ) ); } -QPixmap QgsSymbolLayerUtils::colorRampPreviewPixmap( QgsColorRamp* ramp, QSize size ) +QPixmap QgsSymbolLayerUtils::colorRampPreviewPixmap( QgsColorRamp* ramp, QSize size, int padding ) { QPixmap pixmap( size ); pixmap.fill( Qt::transparent ); @@ -650,7 +662,7 @@ QPixmap QgsSymbolLayerUtils::colorRampPreviewPixmap( QgsColorRamp* ramp, QSize s painter.begin( &pixmap ); //draw stippled background, for transparent images - drawStippledBackground( &painter, QRect( 0, 0, size.width(), size.height() ) ); + drawStippledBackground( &painter, QRect( padding, padding, size.width() - padding * 2, size.height() - padding * 2 ) ); // antialising makes the colors duller, and no point in antialiasing a color ramp // painter.setRenderHint( QPainter::Antialiasing ); @@ -658,7 +670,7 @@ QPixmap QgsSymbolLayerUtils::colorRampPreviewPixmap( QgsColorRamp* ramp, QSize s { QPen pen( ramp->color( static_cast< double >( i ) / size.width() ) ); painter.setPen( pen ); - painter.drawLine( i, 0, i, size.height() - 1 ); + painter.drawLine( i, 0 + padding, i, size.height() - 1 - padding ); } painter.end(); return pixmap; diff --git a/src/core/symbology-ng/qgssymbollayerutils.h b/src/core/symbology-ng/qgssymbollayerutils.h index 7387770c0bd..495344ff95d 100644 --- a/src/core/symbology-ng/qgssymbollayerutils.h +++ b/src/core/symbology-ng/qgssymbollayerutils.h @@ -138,7 +138,23 @@ class CORE_EXPORT QgsSymbolLayerUtils static QPainter::CompositionMode decodeBlendMode( const QString& s ); - static QIcon symbolPreviewIcon( QgsSymbol* symbol, QSize size ); + /** Returns an icon preview for a color ramp. + * @param symbol symbol + * @param size target pixmap size + * @param padding space between icon edge and symbol + * @see symbolPreviewPixmap() + */ + static QIcon symbolPreviewIcon( QgsSymbol* symbol, QSize size, int padding = 0 ); + + /** Returns a pixmap preview for a color ramp. + * @param symbol symbol + * @param size target pixmap size + * @param padding space between icon edge and symbol + * @param customContext render context to use when rendering symbol + * @note customContext parameter added in 2.6 + * @see symbolPreviewIcon() + */ + static QPixmap symbolPreviewPixmap( QgsSymbol* symbol, QSize size, int padding = 0, QgsRenderContext* customContext = nullptr ); /** Draws a symbol layer preview to a QPicture * @param layer symbol layer to draw @@ -161,25 +177,24 @@ class CORE_EXPORT QgsSymbolLayerUtils */ static QIcon symbolLayerPreviewIcon( QgsSymbolLayer* layer, QgsUnitTypes::RenderUnit u, QSize size, const QgsMapUnitScale& scale = QgsMapUnitScale() ); - /** Returns a icon preview for a color ramp. + /** Returns an icon preview for a color ramp. * @param ramp color ramp * @param size target icon size + * @param padding space between icon edge and color ramp * @see colorRampPreviewPixmap() */ - static QIcon colorRampPreviewIcon( QgsColorRamp* ramp, QSize size ); + static QIcon colorRampPreviewIcon( QgsColorRamp* ramp, QSize size, int padding = 0 ); /** Returns a pixmap preview for a color ramp. * @param ramp color ramp * @param size target pixmap size + * @param padding space between icon edge and color ramp * @see colorRampPreviewIcon() */ - static QPixmap colorRampPreviewPixmap( QgsColorRamp* ramp, QSize size ); + static QPixmap colorRampPreviewPixmap( QgsColorRamp* ramp, QSize size, int padding = 0 ); static void drawStippledBackground( QPainter* painter, QRect rect ); - //! @note customContext parameter added in 2.6 - static QPixmap symbolPreviewPixmap( QgsSymbol* symbol, QSize size, QgsRenderContext* customContext = nullptr ); - //! Returns the maximum estimated bleed for the symbol static double estimateMaxSymbolBleed( QgsSymbol* symbol ); diff --git a/src/gui/symbology-ng/qgsstylemanagerdialog.cpp b/src/gui/symbology-ng/qgsstylemanagerdialog.cpp index ecb8be3d62d..f53f1996177 100644 --- a/src/gui/symbology-ng/qgsstylemanagerdialog.cpp +++ b/src/gui/symbology-ng/qgsstylemanagerdialog.cpp @@ -236,17 +236,8 @@ void QgsStyleManagerDialog::on_tabItemType_currentChanged( int ) actnExportAsPNG->setVisible( flag ); actnExportAsSVG->setVisible( flag ); - // set icon and grid size, depending on type - if ( currentItemType() == 1 || currentItemType() == 3 ) - { - listItems->setIconSize( QSize( 75, 50 ) ); - listItems->setGridSize( QSize( 100, 80 ) ); - } - else - { - listItems->setIconSize( QSize( 50, 50 ) ); - listItems->setGridSize( QSize( 75, 80 ) ); - } + listItems->setIconSize( QSize( 100, 90 ) ); + listItems->setGridSize( QSize( 120, 110 ) ); populateList(); } @@ -275,7 +266,7 @@ void QgsStyleManagerDialog::populateSymbols( const QStringList& symbolNames, boo if ( symbol && symbol->type() == type ) { QStandardItem* item = new QStandardItem( name ); - QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( symbol, listItems->iconSize() ); + QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( symbol, listItems->iconSize(), 18 ); item->setIcon( icon ); item->setData( name ); // used to find out original name when user edited the name item->setCheckable( check ); @@ -301,7 +292,7 @@ void QgsStyleManagerDialog::populateColorRamps( const QStringList& colorRamps, b QScopedPointer< QgsColorRamp > ramp( mStyle->colorRamp( name ) ); QStandardItem* item = new QStandardItem( name ); - QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), listItems->iconSize() ); + QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), listItems->iconSize(), 18 ); item->setIcon( icon ); item->setData( name ); // used to find out original name when user edited the name item->setCheckable( check ); diff --git a/src/gui/symbology-ng/qgssymbolslistwidget.cpp b/src/gui/symbology-ng/qgssymbolslistwidget.cpp index 08548a86c7b..0257cc20192 100644 --- a/src/gui/symbology-ng/qgssymbolslistwidget.cpp +++ b/src/gui/symbology-ng/qgssymbolslistwidget.cpp @@ -243,7 +243,7 @@ void QgsSymbolsListWidget::populateSymbols( const QStringList& names ) itemFont.setPointSize( 10 ); item->setFont( itemFont ); // create preview icon - QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( s, previewSize ); + QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( s, previewSize, 15 ); item->setIcon( icon ); // add to model model->appendRow( item ); diff --git a/src/ui/symbollayer/widget_symbolslist.ui b/src/ui/symbollayer/widget_symbolslist.ui index 31e73bbdf3c..ef29f779d5f 100644 --- a/src/ui/symbollayer/widget_symbolslist.ui +++ b/src/ui/symbollayer/widget_symbolslist.ui @@ -37,8 +37,8 @@ - 48 - 48 + 77 + 70