Skip to content
Permalink
Browse files

[maptips] fix font not respecting user settings

(this is important for non-Latin users out there)
  • Loading branch information
nirvn committed Jul 18, 2018
1 parent 62347b6 commit 2f0c36c3de39bb5dfe9ed6d2088028cc6cc09240
Showing with 36 additions and 1 deletion.
  1. +5 −0 python/gui/auto_generated/qgsmaptip.sip.in
  2. +5 −0 src/app/qgisapp.cpp
  3. +2 −0 src/app/qgsoptions.cpp
  4. +16 −1 src/gui/qgsmaptip.cpp
  5. +8 −0 src/gui/qgsmaptip.h
@@ -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

};
@@ -2335,6 +2335,11 @@ void QgisApp::setAppStyleSheet( const QString &stylesheet )
{
d->setStyleSheet( stylesheet );
}

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

int QgisApp::messageTimeout()
@@ -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();
@@ -19,6 +19,7 @@
#include "qgsvectorlayer.h"
#include "qgsexpression.h"
#include "qgslogger.h"
#include "qgssettings.h"
#include "qgswebview.h"
#include "qgswebframe.h"

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

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

void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
@@ -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;"
@@ -131,6 +136,8 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
"</body>"
"</html>" ).arg( bodyStyle, containerStyle, tipText );

QgsDebugMsg( tipHtml );

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

@@ -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 )
{
@@ -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();
@@ -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 2f0c36c

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