Skip to content

Commit

Permalink
Merge pull request #4989 from nyalldawson/icon_size
Browse files Browse the repository at this point in the history
Fix various icon size issues
  • Loading branch information
nyalldawson authored Aug 6, 2017
2 parents 5b9d7cf + 2d88a4d commit c5f6af7
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 22 deletions.
6 changes: 4 additions & 2 deletions python/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def __init__(self, parent=None):
# Hide search widget on start up
self.widgetFind.hide()

icon_size = iface.iconSize(dockedToolbar=True) if iface else QSize(16, 16)

sizes = self.splitter.sizes()
self.splitter.setSizes(sizes)

Expand Down Expand Up @@ -351,7 +353,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(icon_size)
self.toolBar.setMovable(False)
self.toolBar.setFloatable(False)
self.toolBar.addAction(self.clearButton)
Expand All @@ -367,7 +369,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(icon_size)
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
35 changes: 30 additions & 5 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 Expand Up @@ -79,6 +81,34 @@ def __init__(self, model=None):
except:
pass

self.mToolbar.setIconSize(iface.iconSize())
self.mActionOpen.setIcon(
QgsApplication.getThemeIcon('/mActionFileOpen.svg'))
self.mActionSave.setIcon(
QgsApplication.getThemeIcon('/mActionFileSave.svg'))
self.mActionSaveAs.setIcon(
QgsApplication.getThemeIcon('/mActionFileSaveAs.svg'))
self.mActionZoomActual.setIcon(
QgsApplication.getThemeIcon('/mActionZoomActual.svg'))
self.mActionZoomIn.setIcon(
QgsApplication.getThemeIcon('/mActionZoomIn.svg'))
self.mActionZoomOut.setIcon(
QgsApplication.getThemeIcon('/mActionZoomOut.svg'))
self.mActionExportImage.setIcon(
QgsApplication.getThemeIcon('/mActionSaveMapAsImage.svg'))
self.mActionZoomToItems.setIcon(
QgsApplication.getThemeIcon('/mActionZoomFullExtent.svg'))
self.mActionExportPdf.setIcon(
QgsApplication.getThemeIcon('/mActionSaveAsPDF.svg'))
self.mActionExportSvg.setIcon(
QgsApplication.getThemeIcon('/mActionSaveAsSVG.svg'))
self.mActionExportPython.setIcon(
QgsApplication.getThemeIcon('/mActionSaveAsPython.svg'))
self.mActionEditHelp.setIcon(
QgsApplication.getThemeIcon('/mActionEditHelpContent.svg'))
self.mActionRun.setIcon(
QgsApplication.getThemeIcon('/mActionStart.svg'))

self.addDockWidget(Qt.LeftDockWidgetArea, self.propertiesDock)
self.addDockWidget(Qt.LeftDockWidgetArea, self.inputsDock)
self.addDockWidget(Qt.LeftDockWidgetArea, self.algorithmsDock)
Expand Down Expand Up @@ -217,11 +247,6 @@ def _mimeDataAlgorithm(items):
ctrlEquals = QShortcut(QKeySequence("Ctrl+="), self)
ctrlEquals.activated.connect(self.zoomIn)

try:
iconSize = int(settings.value("IconSize", 24))
except:
iconSize = 24
self.mToolbar.setIconSize(QSize(iconSize, iconSize))
self.mActionOpen.triggered.connect(self.openModel)
self.mActionSave.triggered.connect(self.save)
self.mActionSaveAs.triggered.connect(self.saveAs)
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 c5f6af7

Please sign in to comment.