Add QgsGuiUtils::iconSize to get user-prefered toolbar icon size

This commit is contained in:
nirvn 2019-04-16 12:08:58 +07:00 committed by Mathieu Pellerin
parent e5491ee610
commit c0dd9fef68
4 changed files with 49 additions and 36 deletions

View File

@ -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;
@ -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 *>();
@ -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 );
}
}
@ -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 )

View File

@ -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 );

View File

@ -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 );
}
}
//

View File

@ -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 );
}
/**