Skip to content

Commit cad54f2

Browse files
committedAug 6, 2017
Fix incorrect icon sizes in Python console
Console was not respecting application icon size setting
1 parent 139fe68 commit cad54f2

File tree

9 files changed

+68
-17
lines changed

9 files changed

+68
-17
lines changed
 

‎python/console/console.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def __init__(self, parent=None):
351351
self.toolBar.setFocusPolicy(Qt.NoFocus)
352352
self.toolBar.setContextMenuPolicy(Qt.DefaultContextMenu)
353353
self.toolBar.setLayoutDirection(Qt.LeftToRight)
354-
self.toolBar.setIconSize(QSize(16, 16))
354+
self.toolBar.setIconSize(iface.iconSize(dockedToolbar=True))
355355
self.toolBar.setMovable(False)
356356
self.toolBar.setFloatable(False)
357357
self.toolBar.addAction(self.clearButton)
@@ -367,7 +367,7 @@ def __init__(self, parent=None):
367367
self.toolBarEditor.setFocusPolicy(Qt.NoFocus)
368368
self.toolBarEditor.setContextMenuPolicy(Qt.DefaultContextMenu)
369369
self.toolBarEditor.setLayoutDirection(Qt.LeftToRight)
370-
self.toolBarEditor.setIconSize(QSize(16, 16))
370+
self.toolBarEditor.setIconSize(iface.iconSize(dockedToolbar=True))
371371
self.toolBarEditor.setMovable(False)
372372
self.toolBarEditor.setFloatable(False)
373373
self.toolBarEditor.addAction(self.openFileButton)

‎python/gui/qgisinterface.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ Constructor
9999
.. seealso:: createNewMapCanvas()
100100
%End
101101

102+
virtual QSize iconSize( bool dockedToolbar = false ) const = 0;
103+
%Docstring
104+
Returns the toolbar icon size. If ``dockedToolbar`` is true, the icon size
105+
for toolbars contained within docks is returned.
106+
:rtype: QSize
107+
%End
108+
102109
public slots: // TODO: do these functions really need to be slots?
103110

104111

‎python/plugins/processing/gui/ScriptEditorDialog.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def __init__(self, algType, alg):
6868
self.restoreState(settings.value("/Processing/stateScriptEditor", QByteArray()))
6969
self.restoreGeometry(settings.value("/Processing/geometryScriptEditor", QByteArray()))
7070

71-
iconSize = int(settings.value("IconSize", 24))
72-
self.toolBar.setIconSize(QSize(iconSize, iconSize))
71+
self.toolBar.setIconSize(iface.iconSize())
7372

7473
self.actionOpenScript.setIcon(
7574
QgsApplication.getThemeIcon('/mActionFileOpen.svg'))

‎python/plugins/processing/modeler/ModelerDialog.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
from processing.modeler.ModelerParametersDialog import ModelerParametersDialog
5353
from processing.modeler.ModelerUtils import ModelerUtils
5454
from processing.modeler.ModelerScene import ModelerScene
55+
from qgis.utils import iface
56+
5557
from processing.modeler.WrongModelException import WrongModelException
5658
from qgis.PyQt.QtXml import QDomDocument
5759

‎src/app/qgisapp.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,24 @@ int QgisApp::chooseReasonableDefaultIconSize() const
17861786

17871787
}
17881788

1789+
int QgisApp::dockedToolbarIconSize( int standardToolbarIconSize ) const
1790+
{
1791+
int dockSize;
1792+
if ( standardToolbarIconSize > 32 )
1793+
{
1794+
dockSize = standardToolbarIconSize - 16;
1795+
}
1796+
else if ( standardToolbarIconSize == 32 )
1797+
{
1798+
dockSize = 24;
1799+
}
1800+
else
1801+
{
1802+
dockSize = 16;
1803+
}
1804+
return dockSize;
1805+
}
1806+
17891807
void QgisApp::readSettings()
17901808
{
17911809
QgsSettings settings;
@@ -2831,19 +2849,7 @@ void QgisApp::createStatusBar()
28312849

28322850
void QgisApp::setIconSizes( int size )
28332851
{
2834-
int dockSize;
2835-
if ( size > 32 )
2836-
{
2837-
dockSize = size - 16;
2838-
}
2839-
else if ( size == 32 )
2840-
{
2841-
dockSize = 24;
2842-
}
2843-
else
2844-
{
2845-
dockSize = 16;
2846-
}
2852+
int dockSize = dockedToolbarIconSize( size );
28472853

28482854
//Set the icon size of for all the toolbars created in the future.
28492855
setIconSize( QSize( size, size ) );
@@ -9736,6 +9742,19 @@ QgsMapLayer *QgisApp::activeLayer()
97369742
return mLayerTreeView ? mLayerTreeView->currentLayer() : nullptr;
97379743
}
97389744

9745+
QSize QgisApp::iconSize( bool dockedToolbar ) const
9746+
{
9747+
QgsSettings s;
9748+
int size = s.value( QStringLiteral( "/IconSize" ), 32 ).toInt();
9749+
9750+
if ( dockedToolbar )
9751+
{
9752+
size = dockedToolbarIconSize( size );
9753+
}
9754+
9755+
return QSize( size, size );
9756+
}
9757+
97399758
bool QgisApp::setActiveLayer( QgsMapLayer *layer )
97409759
{
97419760
if ( !layer )

‎src/app/qgisapp.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
621621
//! Returns the active map layer.
622622
QgsMapLayer *activeLayer();
623623

624+
/**
625+
* Returns the toolbar icon size. If \a dockedToolbar is true, the icon size
626+
* for toolbars contained within docks is returned.
627+
*/
628+
QSize iconSize( bool dockedToolbar = false ) const;
629+
624630
public slots:
625631
//! Process the list of URIs that have been dropped in QGIS
626632
void handleDropUriList( const QgsMimeDataUtils::UriList &lst );
@@ -1715,6 +1721,11 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
17151721
//! Attempts to choose a reasonable default icon size based on the window's screen DPI
17161722
int chooseReasonableDefaultIconSize() const;
17171723

1724+
/**
1725+
* Returns the size of docked toolbars for a given standard (non-docked) toolbar icon size.
1726+
*/
1727+
int dockedToolbarIconSize( int standardToolbarIconSize ) const;
1728+
17181729
QgisAppStyleSheet *mStyleSheetBuilder = nullptr;
17191730

17201731
// actions for menus and toolbars -----------------

‎src/app/qgisappinterface.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,11 @@ void QgisAppInterface::closeMapCanvas( const QString &name )
352352
qgis->closeMapCanvas( name );
353353
}
354354

355+
QSize QgisAppInterface::iconSize( bool dockedToolbar ) const
356+
{
357+
return qgis->iconSize( dockedToolbar );
358+
}
359+
355360
QgsLayerTreeMapCanvasBridge *QgisAppInterface::layerTreeCanvasBridge()
356361
{
357362
return qgis->layerTreeCanvasBridge();

‎src/app/qgisappinterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
183183
QgsMapCanvas *createNewMapCanvas( const QString &name ) override;
184184
virtual void closeMapCanvas( const QString &name ) override;
185185

186+
virtual QSize iconSize( bool dockedToolbar = false ) const override;
187+
186188
/**
187189
* Returns a pointer to the layer tree canvas bridge
188190
*

‎src/gui/qgisinterface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ class GUI_EXPORT QgisInterface : public QObject
128128
*/
129129
virtual void closeMapCanvas( const QString &name ) = 0;
130130

131+
/**
132+
* Returns the toolbar icon size. If \a dockedToolbar is true, the icon size
133+
* for toolbars contained within docks is returned.
134+
*/
135+
virtual QSize iconSize( bool dockedToolbar = false ) const = 0;
136+
131137
public slots: // TODO: do these functions really need to be slots?
132138

133139
/* Exposed functions */

0 commit comments

Comments
 (0)
Please sign in to comment.