Skip to content

Commit

Permalink
Fix tiny marker and ellipse symbol preview icons on HIDPI screens
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 3, 2017
1 parent 820e342 commit 9752746
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
19 changes: 14 additions & 5 deletions src/gui/symbology-ng/qgsellipsesymbollayerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
13 changes: 10 additions & 3 deletions src/gui/symbology-ng/qgssymbollayerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 9752746

Please sign in to comment.