Skip to content
Permalink
Browse files

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

  • Loading branch information
nirvn committed Apr 17, 2019
1 parent 0362f9d commit 9cb58a86701dfa2d90936121f45efb070085a4f4
Showing with 49 additions and 36 deletions.
  1. +6 −31 src/app/qgisapp.cpp
  2. +0 −5 src/app/qgisapp.h
  3. +27 −0 src/gui/qgsguiutils.cpp
  4. +16 −0 src/gui/qgsguiutils.h
@@ -2047,24 +2047,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;
@@ -3236,10 +3218,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 *>();
@@ -3248,11 +3231,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 );
}
}

@@ -11014,15 +10997,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 )
@@ -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 );

@@ -247,6 +247,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 );
}
}

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

/**

0 comments on commit 9cb58a8

Please sign in to comment.
You can’t perform that action at this time.