Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Hard-code toolbar icon size (#53077)
With automatic high DPI scaling enabled, the toolbar icon size can be hard-coded.
  • Loading branch information
jbp35 committed May 15, 2023
1 parent 09b53df commit 8d64197
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -310,7 +310,7 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
initializeRegistry();
}
QgsSettings settings;
int size = settings.value( QStringLiteral( "/qgis/iconSize" ), QGIS_ICON_SIZE ).toInt();
int size = settings.value( QStringLiteral( "/qgis/toolbarIconSize" ), QGIS_ICON_SIZE ).toInt();
setIconSize( QSize( size, size ) );
setStyleSheet( QgisApp::instance()->styleSheet() );

Expand Down
4 changes: 2 additions & 2 deletions src/app/options/qgsoptions.cpp
Expand Up @@ -671,7 +671,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
}

// set the default icon size
cmbIconSize->setCurrentIndex( cmbIconSize->findText( mSettings->value( QStringLiteral( "qgis/iconSize" ), QGIS_ICON_SIZE ).toString() ) );
cmbIconSize->setCurrentIndex( cmbIconSize->findText( mSettings->value( QStringLiteral( "/qgis/toolbarIconSize" ), QGIS_ICON_SIZE ).toString() ) );

// set font size and family
spinFontSize->blockSignals( true );
Expand Down Expand Up @@ -1628,7 +1628,7 @@ void QgsOptions::saveOptions()

QgsApplication::setNullRepresentation( leNullValue->text() );
mSettings->setValue( QStringLiteral( "/qgis/style" ), cmbStyle->currentText() );
mSettings->setValue( QStringLiteral( "/qgis/iconSize" ), cmbIconSize->currentText() );
mSettings->setValue( QStringLiteral( "/qgis/toolbarIconSize" ), cmbIconSize->currentText() );

mSettings->setValue( QStringLiteral( "/qgis/messageTimeout" ), mMessageTimeoutSpnBx->value() );

Expand Down
35 changes: 5 additions & 30 deletions src/app/qgisapp.cpp
Expand Up @@ -1664,18 +1664,18 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
endProfile();

// Set icon size of toolbars
if ( settings.contains( QStringLiteral( "/qgis/iconSize" ) ) )
if ( settings.contains( QStringLiteral( "/qgis/toolbarIconSize" ) ) )
{
int size = settings.value( QStringLiteral( "/qgis/iconSize" ) ).toInt();
int size = settings.value( QStringLiteral( "/qgis/toolbarIconSize" ), QGIS_ICON_SIZE ).toInt();
if ( size < 16 )
size = QGIS_ICON_SIZE;
setIconSizes( size );
}
else
{
// first run, guess a good icon size
int size = chooseReasonableDefaultIconSize();
settings.setValue( QStringLiteral( "/qgis/iconSize" ), size );
// first run, set default value
int size = QGIS_ICON_SIZE;
settings.setValue( QStringLiteral( "/qgis/toolbarIconSize" ), size );
setIconSizes( size );
}

Expand Down Expand Up @@ -2765,31 +2765,6 @@ void QgisApp::applyDefaultSettingsToCanvas( QgsMapCanvas *canvas )
canvas->setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType( settings.enumValue( QStringLiteral( "qgis/segmentationToleranceType" ), QgsAbstractGeometry::MaximumAngle ) ) );
}

int QgisApp::chooseReasonableDefaultIconSize() const
{
QScreen *screen = QApplication::screens().at( 0 );
if ( screen->physicalDotsPerInch() < 115 )
{
// no hidpi screen, use default size
return QGIS_ICON_SIZE;
}
else
{
double size = fontMetrics().horizontalAdvance( 'X' ) * 3;
if ( size < 24 )
return 16;
else if ( size < 32 )
return 24;
else if ( size < 48 )
return 32;
else if ( size < 64 )
return 48;
else
return 64;
}

}

void QgisApp::readSettings()
{
QgsSettings settings;
Expand Down
3 changes: 0 additions & 3 deletions src/app/qgisapp.h
Expand Up @@ -2350,9 +2350,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;

//! Attempts to choose a reasonable default icon size based on the window's screen DPI
int chooseReasonableDefaultIconSize() const;

//! Populates project "load from" / "save to" menu based on project storages (when the menu is about to be shown)
void populateProjectStorageMenu( QMenu *menu, bool saving );

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisappstylesheet.cpp
Expand Up @@ -84,7 +84,7 @@ QMap<QString, QVariant> QgisAppStyleSheet::defaultOptions()

settings.endGroup(); // "qgis/stylesheet"

opts.insert( QStringLiteral( "iconSize" ), settings.value( QStringLiteral( "/qgis/iconSize" ), QGIS_ICON_SIZE ) );
opts.insert( QStringLiteral( "iconSize" ), settings.value( QStringLiteral( "/qgis/toolbarIconSize" ), QGIS_ICON_SIZE ) );

return opts;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsattributetabledialog.cpp
Expand Up @@ -172,7 +172,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
layout()->setContentsMargins( 0, 0, 0, 0 );
static_cast< QGridLayout * >( layout() )->setVerticalSpacing( 0 );

int size = settings.value( QStringLiteral( "/qgis/iconSize" ), 16 ).toInt();
int size = settings.value( QStringLiteral( "/qgis/toolbarIconSize" ), 16 ).toInt();
if ( size > 32 )
{
size -= 16;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -363,7 +363,7 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
else
QgisApp::instance()->panelMenu()->addAction( mDock->toggleViewAction() );

int size = mySettings.value( QStringLiteral( "/qgis/iconSize" ), 16 ).toInt();
int size = mySettings.value( QStringLiteral( "/qgis/toolbarIconSize" ), 16 ).toInt();
if ( size > 32 )
{
size -= 16;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsguiutils.cpp
Expand Up @@ -251,7 +251,7 @@ namespace QgsGuiUtils
QSize iconSize( bool dockableToolbar )
{
const QgsSettings s;
const int w = s.value( QStringLiteral( "/qgis/iconSize" ), 32 ).toInt();
const int w = s.value( QStringLiteral( "/qgis/toolbarIconSize" ), 32 ).toInt();
QSize size( w, w );

if ( dockableToolbar )
Expand Down

0 comments on commit 8d64197

Please sign in to comment.