Skip to content
Permalink
Browse files

Merge pull request #4989 from nyalldawson/icon_size

Fix various icon size issues
  • Loading branch information
nyalldawson committed Aug 6, 2017
2 parents 5b9d7cf + 2d88a4d commit c5f6af750879e6b0a45f9044eee9f9b5d53a5c74
@@ -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)

@@ -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)
@@ -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)
@@ -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?


@@ -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'))
@@ -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

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

0 comments on commit c5f6af7

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