Skip to content

Commit

Permalink
Fix incorrect icon sizes in Python console
Browse files Browse the repository at this point in the history
Console was not respecting application icon size setting
  • Loading branch information
nyalldawson committed Aug 6, 2017
1 parent 139fe68 commit cad54f2
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 17 deletions.
4 changes: 2 additions & 2 deletions python/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def __init__(self, parent=None):
self.toolBar.setFocusPolicy(Qt.NoFocus)
self.toolBar.setContextMenuPolicy(Qt.DefaultContextMenu)
self.toolBar.setLayoutDirection(Qt.LeftToRight)
self.toolBar.setIconSize(QSize(16, 16))
self.toolBar.setIconSize(iface.iconSize(dockedToolbar=True))
self.toolBar.setMovable(False)
self.toolBar.setFloatable(False)
self.toolBar.addAction(self.clearButton)
Expand All @@ -367,7 +367,7 @@ def __init__(self, parent=None):
self.toolBarEditor.setFocusPolicy(Qt.NoFocus)
self.toolBarEditor.setContextMenuPolicy(Qt.DefaultContextMenu)
self.toolBarEditor.setLayoutDirection(Qt.LeftToRight)
self.toolBarEditor.setIconSize(QSize(16, 16))
self.toolBarEditor.setIconSize(iface.iconSize(dockedToolbar=True))
self.toolBarEditor.setMovable(False)
self.toolBarEditor.setFloatable(False)
self.toolBarEditor.addAction(self.openFileButton)
Expand Down
7 changes: 7 additions & 0 deletions python/gui/qgisinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ Constructor
.. seealso:: createNewMapCanvas()
%End

virtual QSize iconSize( bool dockedToolbar = false ) const = 0;
%Docstring
Returns the toolbar icon size. If ``dockedToolbar`` is true, the icon size
for toolbars contained within docks is returned.
:rtype: QSize
%End

public slots: // TODO: do these functions really need to be slots?


Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/gui/ScriptEditorDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def __init__(self, algType, alg):
self.restoreState(settings.value("/Processing/stateScriptEditor", QByteArray()))
self.restoreGeometry(settings.value("/Processing/geometryScriptEditor", QByteArray()))

iconSize = int(settings.value("IconSize", 24))
self.toolBar.setIconSize(QSize(iconSize, iconSize))
self.toolBar.setIconSize(iface.iconSize())

self.actionOpenScript.setIcon(
QgsApplication.getThemeIcon('/mActionFileOpen.svg'))
Expand Down
2 changes: 2 additions & 0 deletions python/plugins/processing/modeler/ModelerDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
from processing.modeler.ModelerParametersDialog import ModelerParametersDialog
from processing.modeler.ModelerUtils import ModelerUtils
from processing.modeler.ModelerScene import ModelerScene
from qgis.utils import iface

from processing.modeler.WrongModelException import WrongModelException
from qgis.PyQt.QtXml import QDomDocument

Expand Down
45 changes: 32 additions & 13 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,24 @@ 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 @@ -2831,19 +2849,7 @@ void QgisApp::createStatusBar()

void QgisApp::setIconSizes( int size )
{
int dockSize;
if ( size > 32 )
{
dockSize = size - 16;
}
else if ( size == 32 )
{
dockSize = 24;
}
else
{
dockSize = 16;
}
int dockSize = dockedToolbarIconSize( size );

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

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

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

return QSize( size, size );
}

bool QgisApp::setActiveLayer( QgsMapLayer *layer )
{
if ( !layer )
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Returns the active map layer.
QgsMapLayer *activeLayer();

/**
* Returns the toolbar icon size. If \a dockedToolbar is true, the icon size
* for toolbars contained within docks is returned.
*/
QSize iconSize( bool dockedToolbar = false ) const;

public slots:
//! Process the list of URIs that have been dropped in QGIS
void handleDropUriList( const QgsMimeDataUtils::UriList &lst );
Expand Down Expand Up @@ -1715,6 +1721,11 @@ 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;

QgisAppStyleSheet *mStyleSheetBuilder = nullptr;

// actions for menus and toolbars -----------------
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgisappinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ void QgisAppInterface::closeMapCanvas( const QString &name )
qgis->closeMapCanvas( name );
}

QSize QgisAppInterface::iconSize( bool dockedToolbar ) const
{
return qgis->iconSize( dockedToolbar );
}

QgsLayerTreeMapCanvasBridge *QgisAppInterface::layerTreeCanvasBridge()
{
return qgis->layerTreeCanvasBridge();
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisappinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
QgsMapCanvas *createNewMapCanvas( const QString &name ) override;
virtual void closeMapCanvas( const QString &name ) override;

virtual QSize iconSize( bool dockedToolbar = false ) const override;

/**
* Returns a pointer to the layer tree canvas bridge
*
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgisinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ class GUI_EXPORT QgisInterface : public QObject
*/
virtual void closeMapCanvas( const QString &name ) = 0;

/**
* Returns the toolbar icon size. If \a dockedToolbar is true, the icon size
* for toolbars contained within docks is returned.
*/
virtual QSize iconSize( bool dockedToolbar = false ) const = 0;

public slots: // TODO: do these functions really need to be slots?

/* Exposed functions */
Expand Down

0 comments on commit cad54f2

Please sign in to comment.