Skip to content

Commit

Permalink
On first run, try to guess a good default icon size based on screen DPI
Browse files Browse the repository at this point in the history
Otherwise icons are miniscule when loading QGIS on hidpi screens, and
users must know that they need to manually change the icon size
to make it usable...
  • Loading branch information
nyalldawson committed Jul 18, 2017
1 parent dbd50b4 commit 71b9ce2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -50,6 +50,7 @@
#include <QProgressDialog>
#include <QRegExp>
#include <QRegExpValidator>
#include <QScreen>
#include <QShortcut>
#include <QSpinBox>
#include <QSplashScreen>
Expand Down Expand Up @@ -1033,8 +1034,20 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
}

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

mSplash->showMessage( tr( "Initializing file filters" ), Qt::AlignHCenter | Qt::AlignBottom );
qApp->processEvents();
Expand Down Expand Up @@ -1729,6 +1742,31 @@ QgsCoordinateReferenceSystem QgisApp::defaultCrsForNewLayers() const
return defaultCrs;
}

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().width( QStringLiteral( "XXX" ) );
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: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1688,6 +1688,9 @@ 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;

QgisAppStyleSheet *mStyleSheetBuilder = nullptr;

// actions for menus and toolbars -----------------
Expand Down

2 comments on commit 71b9ce2

@m-kuhn
Copy link
Member

@m-kuhn m-kuhn commented on 71b9ce2 Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea to set the icon size based on fontMetrics.
Do you know if that takes system default font sizes into account? If yes, wouldn't it make sense to always use this logic (also for low res displays) so people with visual impairment and increased font size also get bigger icons by default?

@nyalldawson
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable to me. Let me test on some low res displays tomorrow and confirm.

Please sign in to comment.