Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[maptips] fix font not respecting user settings
(this is important for non-Latin users out there)
  • Loading branch information
nirvn committed Jul 19, 2018
1 parent 1c9b65d commit 68290a2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions python/gui/auto_generated/qgsmaptip.sip.in
Expand Up @@ -61,6 +61,11 @@ Show a maptip at a given point on the map canvas
Clear the current maptip if it exists

:param mpMapCanvas: the canvas from which the tip should be cleared.
%End

void applyFontSettings();
%Docstring
Apply font family and size to match user settings
%End

};
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -2339,6 +2339,11 @@ void QgisApp::setAppStyleSheet( const QString &stylesheet )
{
d->setStyleSheet( stylesheet );
}

if ( mpMaptip )
{
mpMaptip->applyFontSettings();
}
}

int QgisApp::messageTimeout()
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -1634,6 +1634,8 @@ void QgsOptions::saveOptions()
if ( mStyleSheetNewOpts != mStyleSheetOldOpts )
{
mStyleSheetBuilder->saveToSettings( mStyleSheetNewOpts );
// trigger an extra style sheet build to propagate saved settings
mStyleSheetBuilder->buildStyleSheet( mStyleSheetNewOpts );
}

mDefaultDatumTransformTableWidget->transformContext().writeSettings();
Expand Down
17 changes: 16 additions & 1 deletion src/gui/qgsmaptip.cpp
Expand Up @@ -19,6 +19,7 @@
#include "qgsvectorlayer.h"
#include "qgsexpression.h"
#include "qgslogger.h"
#include "qgssettings.h"
#include "qgswebview.h"
#include "qgswebframe.h"

Expand All @@ -40,6 +41,9 @@ QgsMapTip::QgsMapTip()
{
// Init the visible flag
mMapTipVisible = false;

// Init font-related values
applyFontSettings();
}

void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
Expand Down Expand Up @@ -118,7 +122,8 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
bodyStyle = QString(
"background-color: %1;"
"margin: 0;"
"white-space: nowrap;" ).arg( backgroundColor );
"white-space: nowrap;"
"font: %2pt \"%3\";" ).arg( backgroundColor ).arg( mFontSize ).arg( mFontFamily );

containerStyle = QString(
"display: inline-block;"
Expand All @@ -131,6 +136,8 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
"</body>"
"</html>" ).arg( bodyStyle, containerStyle, tipText );

QgsDebugMsg( tipHtml );

mWidget->move( pixelPosition.x(),
pixelPosition.y() );

Expand Down Expand Up @@ -216,6 +223,14 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPointXY &mapPosition, Qg
return tipString;
}

void QgsMapTip::applyFontSettings()
{
QgsSettings settings;
QFont defaultFont = qApp->font();
mFontSize = settings.value( QStringLiteral( "/qgis/stylesheet/fontPointSize" ), defaultFont.pointSize() ).toInt();
mFontFamily = settings.value( QStringLiteral( "/qgis/stylesheet/fontFamily" ), defaultFont.family() ).toString();
}

// This slot handles all clicks
void QgsMapTip::onLinkClicked( const QUrl &url )
{
Expand Down
8 changes: 8 additions & 0 deletions src/gui/qgsmaptip.h
Expand Up @@ -79,6 +79,11 @@ class GUI_EXPORT QgsMapTip : public QWidget
*/
void clear( QgsMapCanvas *mpMapCanvas = nullptr );

/**
* Apply font family and size to match user settings
*/
void applyFontSettings();

private slots:
void onLinkClicked( const QUrl &url );
void resizeContent();
Expand All @@ -99,6 +104,9 @@ class GUI_EXPORT QgsMapTip : public QWidget
QWidget *mWidget = nullptr;
QgsWebView *mWebView = nullptr;

QString mFontFamily;
int mFontSize = 8;

const int MARGIN_VALUE = 5;
};
#endif // QGSMAPTIP_H

0 comments on commit 68290a2

Please sign in to comment.