Skip to content

Commit

Permalink
Fix more icon sizes on hidpi
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 27, 2019
1 parent 7b739f1 commit 9b2e39c
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 24 deletions.
6 changes: 4 additions & 2 deletions src/app/layout/qgsreportsectionmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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

#ifdef ENABLE_MODELTEST
#include "modeltest.h"
Expand Down Expand Up @@ -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 );
Expand Down
9 changes: 6 additions & 3 deletions src/gui/qgscolorbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgscolorwidgets.h"
#include "qgssettings.h"
#include "qgsproject.h"
#include "qgsguiutils.h"

#include <QPainter>
#include <QTemporaryFile>
Expand Down Expand Up @@ -467,8 +468,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;
Expand All @@ -480,15 +483,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;
}
Expand Down
8 changes: 5 additions & 3 deletions src/gui/qgscolorrampbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down
8 changes: 5 additions & 3 deletions src/gui/qgscolorwidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "qgssymbollayerutils.h"
#include "qgssettings.h"
#include "qgslogger.h"
#include "qgsguiutils.h"

#include <QResizeEvent>
#include <QStyleOptionFrameV3>
Expand Down Expand Up @@ -53,18 +54,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;
}
Expand Down
13 changes: 8 additions & 5 deletions src/gui/qgsfontbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,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 );
}
Expand Down Expand Up @@ -379,7 +380,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;
Expand All @@ -390,7 +392,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;
}
Expand Down Expand Up @@ -596,16 +598,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
{
Expand Down
9 changes: 6 additions & 3 deletions src/gui/qgssymbolbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "qgscolorswatchgrid.h"
#include "qgssymbollayerutils.h"
#include "qgsapplication.h"
#include "qgsguiutils.h"
#include <QMenu>
#include <QClipboard>
#include <QDrag>
Expand Down Expand Up @@ -332,7 +333,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
{
Expand Down Expand Up @@ -513,7 +515,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;
Expand All @@ -524,7 +527,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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/gui/symbology/qgscategorizedsymbolrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "qgsexpression.h"
#include "qgsmapcanvas.h"
#include "qgssettings.h"
#include "qgsguiutils.h"

#include <QKeyEvent>
#include <QMenu>
Expand Down Expand Up @@ -194,7 +195,8 @@ QVariant QgsCategorizedSymbolRendererModel::data( const QModelIndex &index, int
{
if ( 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 ) );
}
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/symbology/qgsgraduatedsymbolrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
4 changes: 3 additions & 1 deletion src/gui/symbology/qgsrulebasedrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "qgspanelwidget.h"
#include "qgsmapcanvas.h"
#include "qgssettings.h"
#include "qgsguiutils.h"

#include <QKeyEvent>
#include <QMenu>
Expand Down Expand Up @@ -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 )
{
Expand Down
7 changes: 5 additions & 2 deletions src/gui/symbology/qgssymbollevelsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgssymbollayer.h"
#include "qgssymbol.h"
#include "qgssettings.h"
#include "qgsguiutils.h"

#include <QTableWidgetItem>
#include <QItemDelegate>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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 );
Expand Down

0 comments on commit 9b2e39c

Please sign in to comment.