Skip to content

Commit c0dd9fe

Browse files
committedApr 17, 2019
Add QgsGuiUtils::iconSize to get user-prefered toolbar icon size
1 parent e5491ee commit c0dd9fe

File tree

4 files changed

+49
-36
lines changed

4 files changed

+49
-36
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,24 +2052,6 @@ int QgisApp::chooseReasonableDefaultIconSize() const
20522052

20532053
}
20542054

2055-
int QgisApp::dockedToolbarIconSize( int standardToolbarIconSize ) const
2056-
{
2057-
int dockSize;
2058-
if ( standardToolbarIconSize > 32 )
2059-
{
2060-
dockSize = standardToolbarIconSize - 16;
2061-
}
2062-
else if ( standardToolbarIconSize == 32 )
2063-
{
2064-
dockSize = 24;
2065-
}
2066-
else
2067-
{
2068-
dockSize = 16;
2069-
}
2070-
return dockSize;
2071-
}
2072-
20732055
void QgisApp::readSettings()
20742056
{
20752057
QgsSettings settings;
@@ -3244,10 +3226,11 @@ void QgisApp::createStatusBar()
32443226

32453227
void QgisApp::setIconSizes( int size )
32463228
{
3247-
int dockSize = dockedToolbarIconSize( size );
3229+
QSize iconSize = QSize( size, size );
3230+
QSize panelIconSize = QgsGuiUtils::panelIconSize( iconSize );
32483231

32493232
//Set the icon size of for all the toolbars created in the future.
3250-
setIconSize( QSize( size, size ) );
3233+
setIconSize( iconSize );
32513234

32523235
//Change all current icon sizes.
32533236
QList<QToolBar *> toolbars = findChildren<QToolBar *>();
@@ -3257,11 +3240,11 @@ void QgisApp::setIconSizes( int size )
32573240
QString className = toolbar->parent()->metaObject()->className();
32583241
if ( className == QLatin1String( "QgisApp" ) )
32593242
{
3260-
toolbar->setIconSize( QSize( size, size ) );
3243+
toolbar->setIconSize( iconSize );
32613244
}
32623245
else
32633246
{
3264-
toolbar->setIconSize( QSize( dockSize, dockSize ) );
3247+
toolbar->setIconSize( panelIconSize );
32653248
}
32663249
}
32673250

@@ -11050,15 +11033,7 @@ QgsMapLayer *QgisApp::activeLayer()
1105011033

1105111034
QSize QgisApp::iconSize( bool dockedToolbar ) const
1105211035
{
11053-
QgsSettings s;
11054-
int size = s.value( QStringLiteral( "/qgis/iconSize" ), 32 ).toInt();
11055-
11056-
if ( dockedToolbar )
11057-
{
11058-
size = dockedToolbarIconSize( size );
11059-
}
11060-
11061-
return QSize( size, size );
11036+
return QgsGuiUtils::iconSize( dockedToolbar );
1106211037
}
1106311038

1106411039
bool QgisApp::setActiveLayer( QgsMapLayer *layer )

‎src/app/qgisapp.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,11 +1979,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
19791979
//! Attempts to choose a reasonable default icon size based on the window's screen DPI
19801980
int chooseReasonableDefaultIconSize() const;
19811981

1982-
/**
1983-
* Returns the size of docked toolbars for a given standard (non-docked) toolbar icon size.
1984-
*/
1985-
int dockedToolbarIconSize( int standardToolbarIconSize ) const;
1986-
19871982
//! Populates project "load from" / "save to" menu based on project storages (when the menu is about to be shown)
19881983
void populateProjectStorageMenu( QMenu *menu, bool saving );
19891984

‎src/gui/qgsguiutils.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,33 @@ namespace QgsGuiUtils
248248
return static_cast< int >( std::floor( std::max( Qgis::UI_SCALE_FACTOR * fm.height() * scale, static_cast< double >( standardSize ) ) ) );
249249
}
250250

251+
QSize iconSize( bool dockableToolbar )
252+
{
253+
QgsSettings s;
254+
int w = s.value( QStringLiteral( "/qgis/iconSize" ), 32 ).toInt();
255+
QSize size( w, w );
256+
257+
if ( dockableToolbar )
258+
{
259+
size = panelIconSize( size );
260+
}
261+
262+
return size;
263+
}
264+
265+
QSize panelIconSize( QSize size )
266+
{
267+
int adjustedSize = 16;
268+
if ( size.width() > 32 )
269+
{
270+
adjustedSize = size.width() - 16;
271+
}
272+
else if ( size.width() == 32 )
273+
{
274+
adjustedSize = 24;
275+
}
276+
return QSize( adjustedSize, adjustedSize );
277+
}
251278
}
252279

253280
//

‎src/gui/qgsguiutils.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,22 @@ namespace QgsGuiUtils
173173
* \since QGIS 3.6
174174
*/
175175
int GUI_EXPORT scaleIconSize( int standardSize );
176+
177+
/**
178+
* Returns the user-preferred size of a window's toolbar icons.
179+
* \param dockableToolbar If set to true, the icon size will be returned for dockable window panel's toolbars.
180+
* \returns a QSize object representing an icon's width and height.
181+
* \since QGIS 3.8
182+
*/
183+
QSize GUI_EXPORT iconSize( bool dockableToolbar = false );
184+
185+
/**
186+
* Returns dockable panel toolbar icon width based on the provided window toolbar width.
187+
* \param size Icon size from which the output size will be derived from.
188+
* \returns a QSize object representing an icon's width and height.
189+
* \since QGIS 3.8
190+
*/
191+
QSize GUI_EXPORT panelIconSize( QSize size );
176192
}
177193

178194
/**

0 commit comments

Comments
 (0)
Please sign in to comment.