Skip to content
Permalink
Browse files

Fix tiny marker and ellipse symbol preview icons on HIDPI screens

  • Loading branch information
nyalldawson committed Aug 3, 2017
1 parent 820e342 commit 97527466ab0bf7d8adc252eb923840178843f3e9
@@ -49,22 +49,31 @@ QgsEllipseSymbolLayerWidget::QgsEllipseSymbolLayerWidget( const QgsVectorLayer *

QStringList names;
names << QStringLiteral( "circle" ) << QStringLiteral( "rectangle" ) << QStringLiteral( "diamond" ) << QStringLiteral( "cross" ) << QStringLiteral( "triangle" ) << QStringLiteral( "right_half_triangle" ) << QStringLiteral( "left_half_triangle" ) << QStringLiteral( "semi_circle" );
QSize iconSize = mShapeListWidget->iconSize();

int size = mShapeListWidget->iconSize().width();
size = qMax( 30, qRound( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXX" ) ) ) );
mShapeListWidget->setGridSize( QSize( size * 1.2, size * 1.2 ) );
mShapeListWidget->setIconSize( QSize( size, size ) );

double markerSize = size * 0.8;
Q_FOREACH ( const QString &name, names )
{
QgsEllipseSymbolLayer *lyr = new QgsEllipseSymbolLayer();
lyr->setSymbolWidthUnit( QgsUnitTypes::RenderPixels );
lyr->setSymbolHeightUnit( QgsUnitTypes::RenderPixels );
lyr->setSymbolName( name );
lyr->setStrokeColor( QColor( 0, 0, 0 ) );
lyr->setFillColor( QColor( 200, 200, 200 ) );
lyr->setSymbolWidth( 4 );
lyr->setSymbolHeight( 2 );
QIcon icon = QgsSymbolLayerUtils::symbolLayerPreviewIcon( lyr, QgsUnitTypes::RenderMillimeters, iconSize );
QListWidgetItem *item = new QListWidgetItem( icon, QLatin1String( "" ), mShapeListWidget );
lyr->setSymbolWidth( markerSize );
lyr->setSymbolHeight( markerSize * 0.75 );
QIcon icon = QgsSymbolLayerUtils::symbolLayerPreviewIcon( lyr, QgsUnitTypes::RenderPixels, QSize( size, size ) );
QListWidgetItem *item = new QListWidgetItem( icon, QString(), mShapeListWidget );
item->setToolTip( name );
item->setData( Qt::UserRole, name );
delete lyr;
}
// show at least 2 rows (only 1 row is required, but looks too cramped)
mShapeListWidget->setMinimumHeight( mShapeListWidget->gridSize().height() * 2.1 );

connect( spinOffsetX, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::setOffset );
connect( spinOffsetY, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::setOffset );
@@ -399,19 +399,26 @@ QgsSimpleMarkerSymbolLayerWidget::QgsSimpleMarkerSymbolLayerWidget( const QgsVec
if ( vectorLayer() )
mSizeDDBtn->setSymbol( mAssistantPreviewSymbol );

QSize size = lstNames->iconSize();
double markerSize = DEFAULT_POINT_SIZE * 2;
int size = lstNames->iconSize().width();
size = qMax( 30, qRound( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXX" ) ) ) );
lstNames->setGridSize( QSize( size * 1.2, size * 1.2 ) );
lstNames->setIconSize( QSize( size, size ) );

double markerSize = size * 0.8;
Q_FOREACH ( QgsSimpleMarkerSymbolLayerBase::Shape shape, QgsSimpleMarkerSymbolLayerBase::availableShapes() )
{
QgsSimpleMarkerSymbolLayer *lyr = new QgsSimpleMarkerSymbolLayer( shape, markerSize );
lyr->setSizeUnit( QgsUnitTypes::RenderPixels );
lyr->setColor( QColor( 200, 200, 200 ) );
lyr->setStrokeColor( QColor( 0, 0, 0 ) );
QIcon icon = QgsSymbolLayerUtils::symbolLayerPreviewIcon( lyr, QgsUnitTypes::RenderMillimeters, size );
QIcon icon = QgsSymbolLayerUtils::symbolLayerPreviewIcon( lyr, QgsUnitTypes::RenderPixels, QSize( size, size ) );
QListWidgetItem *item = new QListWidgetItem( icon, QString(), lstNames );
item->setData( Qt::UserRole, static_cast< int >( shape ) );
item->setToolTip( QgsSimpleMarkerSymbolLayerBase::encodeShape( shape ) );
delete lyr;
}
// show at least 3 rows

This comment has been minimized.

Copy link
@nirvn

nirvn Aug 4, 2017

Contributor

Nice one.

lstNames->setMinimumHeight( lstNames->gridSize().height() * 3.1 );

connect( lstNames, &QListWidget::currentRowChanged, this, &QgsSimpleMarkerSymbolLayerWidget::setShape );
connect( btnChangeColorStroke, &QgsColorButton::colorChanged, this, &QgsSimpleMarkerSymbolLayerWidget::setColorStroke );

0 comments on commit 9752746

Please sign in to comment.
You can’t perform that action at this time.