Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add QgsGuiUtils::iconSize to get user-prefered toolbar icon size
  • Loading branch information
nirvn committed Apr 17, 2019
1 parent e5491ee commit c0dd9fe
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 36 deletions.
37 changes: 6 additions & 31 deletions src/app/qgisapp.cpp
Expand Up @@ -2052,24 +2052,6 @@ int QgisApp::chooseReasonableDefaultIconSize() const

}

int QgisApp::dockedToolbarIconSize( int standardToolbarIconSize ) const
{
int dockSize;
if ( standardToolbarIconSize > 32 )
{
dockSize = standardToolbarIconSize - 16;
}
else if ( standardToolbarIconSize == 32 )
{
dockSize = 24;
}
else
{
dockSize = 16;
}
return dockSize;
}

void QgisApp::readSettings()
{
QgsSettings settings;
Expand Down Expand Up @@ -3244,10 +3226,11 @@ void QgisApp::createStatusBar()

void QgisApp::setIconSizes( int size )
{
int dockSize = dockedToolbarIconSize( size );
QSize iconSize = QSize( size, size );
QSize panelIconSize = QgsGuiUtils::panelIconSize( iconSize );

//Set the icon size of for all the toolbars created in the future.
setIconSize( QSize( size, size ) );
setIconSize( iconSize );

//Change all current icon sizes.
QList<QToolBar *> toolbars = findChildren<QToolBar *>();
Expand All @@ -3257,11 +3240,11 @@ void QgisApp::setIconSizes( int size )
QString className = toolbar->parent()->metaObject()->className();
if ( className == QLatin1String( "QgisApp" ) )
{
toolbar->setIconSize( QSize( size, size ) );
toolbar->setIconSize( iconSize );
}
else
{
toolbar->setIconSize( QSize( dockSize, dockSize ) );
toolbar->setIconSize( panelIconSize );
}
}

Expand Down Expand Up @@ -11050,15 +11033,7 @@ QgsMapLayer *QgisApp::activeLayer()

QSize QgisApp::iconSize( bool dockedToolbar ) const
{
QgsSettings s;
int size = s.value( QStringLiteral( "/qgis/iconSize" ), 32 ).toInt();

if ( dockedToolbar )
{
size = dockedToolbarIconSize( size );
}

return QSize( size, size );
return QgsGuiUtils::iconSize( dockedToolbar );
}

bool QgisApp::setActiveLayer( QgsMapLayer *layer )
Expand Down
5 changes: 0 additions & 5 deletions src/app/qgisapp.h
Expand Up @@ -1979,11 +1979,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Attempts to choose a reasonable default icon size based on the window's screen DPI
int chooseReasonableDefaultIconSize() const;

/**
* Returns the size of docked toolbars for a given standard (non-docked) toolbar icon size.
*/
int dockedToolbarIconSize( int standardToolbarIconSize ) 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
27 changes: 27 additions & 0 deletions src/gui/qgsguiutils.cpp
Expand Up @@ -248,6 +248,33 @@ namespace QgsGuiUtils
return static_cast< int >( std::floor( std::max( Qgis::UI_SCALE_FACTOR * fm.height() * scale, static_cast< double >( standardSize ) ) ) );
}

QSize iconSize( bool dockableToolbar )
{
QgsSettings s;
int w = s.value( QStringLiteral( "/qgis/iconSize" ), 32 ).toInt();
QSize size( w, w );

if ( dockableToolbar )
{
size = panelIconSize( size );
}

return size;
}

QSize panelIconSize( QSize size )
{
int adjustedSize = 16;
if ( size.width() > 32 )
{
adjustedSize = size.width() - 16;
}
else if ( size.width() == 32 )
{
adjustedSize = 24;
}
return QSize( adjustedSize, adjustedSize );
}
}

//
Expand Down
16 changes: 16 additions & 0 deletions src/gui/qgsguiutils.h
Expand Up @@ -173,6 +173,22 @@ namespace QgsGuiUtils
* \since QGIS 3.6
*/
int GUI_EXPORT scaleIconSize( int standardSize );

/**
* Returns the user-preferred size of a window's toolbar icons.
* \param dockableToolbar If set to true, the icon size will be returned for dockable window panel's toolbars.
* \returns a QSize object representing an icon's width and height.
* \since QGIS 3.8
*/
QSize GUI_EXPORT iconSize( bool dockableToolbar = false );

/**
* Returns dockable panel toolbar icon width based on the provided window toolbar width.
* \param size Icon size from which the output size will be derived from.
* \returns a QSize object representing an icon's width and height.
* \since QGIS 3.8
*/
QSize GUI_EXPORT panelIconSize( QSize size );
}

/**
Expand Down

0 comments on commit c0dd9fe

Please sign in to comment.