Skip to content
Permalink
Browse files

Fix more icon sizes on hidpi

(cherry picked from commit 9b2e39c)
  • Loading branch information
nyalldawson committed Jan 29, 2019
1 parent 2b04248 commit 77fd62d8213db7bc08219f678478a8dac48394fc
@@ -15,6 +15,7 @@

#include "qgsreportsectionmodel.h"
#include "functional"
#include "qgsguiutils.h"

#ifdef ENABLE_MODELTEST
#include "modeltest.h"
@@ -67,10 +68,11 @@ QVariant QgsReportSectionModel::data( const QModelIndex &index, int role ) const

if ( section == mEditedSection )
{
QPixmap pixmap( icon.pixmap( 16, 16 ) );
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
QPixmap pixmap( icon.pixmap( iconSize, iconSize ) );

QPainter painter( &pixmap );
painter.drawPixmap( 0, 0, 16, 16, QgsApplication::getThemePixmap( QStringLiteral( "/mActionToggleEditing.svg" ) ) );
painter.drawPixmap( 0, 0, iconSize, iconSize, QgsApplication::getThemePixmap( QStringLiteral( "/mActionToggleEditing.svg" ) ) );
painter.end();

return QIcon( pixmap );
@@ -415,8 +415,10 @@ void QgsColorButton::setValidTemporaryColor( const QColor &newColor )

QPixmap QgsColorButton::createMenuIcon( const QColor &color, const bool showChecks )
{
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );

//create an icon pixmap
QPixmap pixmap( 16, 16 );
QPixmap pixmap( iconSize, iconSize );
pixmap.fill( Qt::transparent );

QPainter p;
@@ -428,15 +430,15 @@ QPixmap QgsColorButton::createMenuIcon( const QColor &color, const bool showChec
QBrush checkBrush = QBrush( transparentBackground() );
p.setPen( Qt::NoPen );
p.setBrush( checkBrush );
p.drawRect( 0, 0, 15, 15 );
p.drawRect( 0, 0, iconSize - 1, iconSize - 1 );
}

//draw color over pattern
p.setBrush( QBrush( color ) );

//draw border
p.setPen( QColor( 197, 197, 197 ) );
p.drawRect( 0, 0, 15, 15 );
p.drawRect( 0, 0, iconSize - 1, iconSize - 1 );
p.end();
return pixmap;
}
@@ -210,7 +210,8 @@ void QgsColorRampButton::mousePressEvent( QMouseEvent *e )
QPixmap QgsColorRampButton::createMenuIcon( QgsColorRamp *colorramp )
{
//create an icon pixmap
QPixmap pixmap = QgsSymbolLayerUtils::colorRampPreviewPixmap( colorramp, QSize( 16, 16 ) );
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
QPixmap pixmap = QgsSymbolLayerUtils::colorRampPreviewPixmap( colorramp, QSize( iconSize, iconSize ) );
return pixmap;
}

@@ -273,13 +274,14 @@ void QgsColorRampButton::prepareMenu()

QStringList rampNames = mStyle->symbolsOfFavorite( QgsStyle::ColorrampEntity );
rampNames.sort();
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
{
std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( *it ) );

if ( !mShowGradientOnly || ( ramp->type() == QLatin1String( "gradient" ) || ramp->type() == QLatin1String( "cpt-city" ) ) )
{
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( 16, 16 ) );
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( iconSize, iconSize ) );
QAction *ra = new QAction( *it, this );
ra->setIcon( icon );
connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
@@ -299,7 +301,7 @@ void QgsColorRampButton::prepareMenu()

if ( !mShowGradientOnly || ( ramp->type() == QLatin1String( "gradient" ) || ramp->type() == QLatin1String( "cpt-city" ) ) )
{
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( 16, 16 ) );
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( iconSize, iconSize ) );
QAction *ra = new QAction( *it, this );
ra->setIcon( icon );
connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
@@ -18,6 +18,7 @@
#include "qgssymbollayerutils.h"
#include "qgssettings.h"
#include "qgslogger.h"
#include "qgsguiutils.h"

#include <QResizeEvent>
#include <QStyleOptionFrameV3>
@@ -55,18 +56,19 @@ int QgsColorWidget::componentValue() const
QPixmap QgsColorWidget::createDragIcon( const QColor &color )
{
//craft a pixmap for the drag icon
QPixmap pixmap( 50, 50 );
const int iconSize = QgsGuiUtils::scaleIconSize( 50 );
QPixmap pixmap( iconSize, iconSize );
pixmap.fill( Qt::transparent );
QPainter painter;
painter.begin( &pixmap );
//start with a light gray background
painter.fillRect( QRect( 0, 0, 50, 50 ), QBrush( QColor( 200, 200, 200 ) ) );
painter.fillRect( QRect( 0, 0, iconSize, iconSize ), QBrush( QColor( 200, 200, 200 ) ) );
//draw rect with white border, filled with current color
QColor pixmapColor = color;
pixmapColor.setAlpha( 255 );
painter.setBrush( QBrush( pixmapColor ) );
painter.setPen( QPen( Qt::white ) );
painter.drawRect( QRect( 1, 1, 47, 47 ) );
painter.drawRect( QRect( 1, 1, iconSize - 2, iconSize - 2 ) );
painter.end();
return pixmap;
}
@@ -236,7 +236,8 @@ void QgsFontButton::mouseMoveEvent( QMouseEvent *e )
drag->setMimeData( QgsFontUtils::toMimeData( mFont ) );
break;
}
drag->setPixmap( createDragIcon() );
const int iconSize = QgsGuiUtils::scaleIconSize( 50 );
drag->setPixmap( createDragIcon( QSize( iconSize, iconSize ) ) );
drag->exec( Qt::CopyAction );
setDown( false );
}
@@ -378,7 +379,8 @@ void QgsFontButton::wheelEvent( QWheelEvent *event )
QPixmap QgsFontButton::createColorIcon( const QColor &color ) const
{
//create an icon pixmap
QPixmap pixmap( 16, 16 );
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
QPixmap pixmap( iconSize, iconSize );
pixmap.fill( Qt::transparent );

QPainter p;
@@ -389,7 +391,7 @@ QPixmap QgsFontButton::createColorIcon( const QColor &color ) const

//draw border
p.setPen( QColor( 197, 197, 197 ) );
p.drawRect( 0, 0, 15, 15 );
p.drawRect( 0, 0, iconSize - 1, iconSize - 1 );
p.end();
return pixmap;
}
@@ -595,16 +597,17 @@ void QgsFontButton::prepareMenu()
//action, even if it's disabled, to give hint to the user that pasting colors is possible
QgsTextFormat tempFormat;
QFont tempFont;
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
if ( mMode == ModeTextRenderer && formatFromMimeData( QApplication::clipboard()->mimeData(), tempFormat ) )
{
tempFormat.setSizeUnit( QgsUnitTypes::RenderPixels );
tempFormat.setSize( 14 );
pasteFormatAction->setIcon( createDragIcon( QSize( 16, 16 ), &tempFormat ) );
pasteFormatAction->setIcon( createDragIcon( QSize( iconSize, iconSize ), &tempFormat ) );
}
else if ( mMode == ModeQFont && fontFromMimeData( QApplication::clipboard()->mimeData(), tempFont ) )
{
tempFont.setPointSize( 8 );
pasteFormatAction->setIcon( createDragIcon( QSize( 16, 16 ), nullptr, &tempFont ) );
pasteFormatAction->setIcon( createDragIcon( QSize( iconSize, iconSize ), nullptr, &tempFont ) );
}
else
{
@@ -24,6 +24,7 @@
#include "qgscolorschemeregistry.h"
#include "qgscolorswatchgrid.h"
#include "qgssymbollayerutils.h"
#include "qgsguiutils.h"
#include <QMenu>
#include <QClipboard>
#include <QDrag>
@@ -320,7 +321,8 @@ void QgsSymbolButton::prepareMenu()
std::unique_ptr< QgsSymbol > tempSymbol( QgsSymbolLayerUtils::symbolFromMimeData( QApplication::clipboard()->mimeData() ) );
if ( tempSymbol && tempSymbol->type() == mType )
{
pasteSymbolAction->setIcon( QgsSymbolLayerUtils::symbolPreviewIcon( tempSymbol.get(), QSize( 16, 16 ), 1 ) );
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
pasteSymbolAction->setIcon( QgsSymbolLayerUtils::symbolPreviewIcon( tempSymbol.get(), QSize( iconSize, iconSize ), 1 ) );
}
else
{
@@ -501,7 +503,8 @@ bool QgsSymbolButton::colorFromMimeData( const QMimeData *mimeData, QColor &resu
QPixmap QgsSymbolButton::createColorIcon( const QColor &color ) const
{
//create an icon pixmap
QPixmap pixmap( 16, 16 );
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
QPixmap pixmap( iconSize, iconSize );
pixmap.fill( Qt::transparent );

QPainter p;
@@ -512,7 +515,7 @@ QPixmap QgsSymbolButton::createColorIcon( const QColor &color ) const

//draw border
p.setPen( QColor( 197, 197, 197 ) );
p.drawRect( 0, 0, 15, 15 );
p.drawRect( 0, 0, iconSize - 1, iconSize - 1 );
p.end();
return pixmap;
}
@@ -37,6 +37,7 @@
#include "qgsexpression.h"
#include "qgsmapcanvas.h"
#include "qgssettings.h"
#include "qgsguiutils.h"

#include <QKeyEvent>
#include <QMenu>
@@ -143,7 +144,8 @@ QVariant QgsCategorizedSymbolRendererModel::data( const QModelIndex &index, int
}
else if ( role == Qt::DecorationRole && index.column() == 0 && category.symbol() )
{
return QgsSymbolLayerUtils::symbolPreviewIcon( category.symbol(), QSize( 16, 16 ) );
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
return QgsSymbolLayerUtils::symbolPreviewIcon( category.symbol(), QSize( iconSize, iconSize ) );
}
else if ( role == Qt::TextAlignmentRole )
{
@@ -162,7 +162,8 @@ QVariant QgsGraduatedSymbolRendererModel::data( const QModelIndex &index, int ro
}
else if ( role == Qt::DecorationRole && index.column() == 0 && range.symbol() )
{
return QgsSymbolLayerUtils::symbolPreviewIcon( range.symbol(), QSize( 16, 16 ) );
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
return QgsSymbolLayerUtils::symbolPreviewIcon( range.symbol(), QSize( iconSize, iconSize ) );
}
else if ( role == Qt::TextAlignmentRole )
{
@@ -30,6 +30,7 @@
#include "qgspanelwidget.h"
#include "qgsmapcanvas.h"
#include "qgssettings.h"
#include "qgsguiutils.h"

#include <QKeyEvent>
#include <QMenu>
@@ -919,7 +920,8 @@ QVariant QgsRuleBasedRendererModel::data( const QModelIndex &index, int role ) c
}
else if ( role == Qt::DecorationRole && index.column() == 0 && rule->symbol() )
{
return QgsSymbolLayerUtils::symbolPreviewIcon( rule->symbol(), QSize( 16, 16 ) );
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
return QgsSymbolLayerUtils::symbolPreviewIcon( rule->symbol(), QSize( iconSize, iconSize ) );
}
else if ( role == Qt::TextAlignmentRole )
{
@@ -19,6 +19,7 @@
#include "qgssymbollayer.h"
#include "qgssymbol.h"
#include "qgssettings.h"
#include "qgsguiutils.h"

#include <QTableWidgetItem>
#include <QItemDelegate>
@@ -51,14 +52,15 @@ QgsSymbolLevelsWidget::QgsSymbolLevelsWidget( QgsFeatureRenderer *renderer, bool
}
}

const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
int maxLayers = 0;
tableLevels->setRowCount( mList.count() );
for ( int i = 0; i < mList.count(); i++ )
{
QgsSymbol *sym = mList.at( i ).symbol();

// set icons for the rows
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( sym, QSize( 16, 16 ) );
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( sym, QSize( iconSize, iconSize ) );
tableLevels->setVerticalHeaderItem( i, new QTableWidgetItem( icon, QString() ) );

// find out max. number of layers per symbol
@@ -89,6 +91,7 @@ QgsSymbolLevelsWidget::QgsSymbolLevelsWidget( QgsFeatureRenderer *renderer, bool

void QgsSymbolLevelsWidget::populateTable()
{
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
for ( int row = 0; row < mList.count(); row++ )
{
QgsSymbol *sym = mList.at( row ).symbol();
@@ -107,7 +110,7 @@ void QgsSymbolLevelsWidget::populateTable()
else
{
QgsSymbolLayer *sl = sym->symbolLayer( layer );
QIcon icon = QgsSymbolLayerUtils::symbolLayerPreviewIcon( sl, QgsUnitTypes::RenderMillimeters, QSize( 16, 16 ) );
QIcon icon = QgsSymbolLayerUtils::symbolLayerPreviewIcon( sl, QgsUnitTypes::RenderMillimeters, QSize( iconSize, iconSize ) );
item = new QTableWidgetItem( icon, QString::number( sl->renderingPass() ) );
}
tableLevels->setItem( row, layer + 1, item );

0 comments on commit 77fd62d

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