Skip to content
Permalink
Browse files

[FEATURE] Choose font family for app

- Define app font family (or Qt default) in app options
- App font choices in options are now temporary unless saved
- Refactor to more general stylesheet methods (for later use)
- Add QgisAppInterface and sip methods for setting app font and family
  • Loading branch information
dakcarto committed Oct 3, 2012
1 parent d8c7c15 commit 48e0a97f407a8810b6d77854307695afde3efbdb
@@ -32,6 +32,18 @@ class QgisInterface : QObject

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

/** Set the app font size
* @param fontSize point size of font
* @note added in 2.0
*/
virtual void setFontSize( int fontSize ) = 0;

/** Set the app font family
* @param fontFamily family of font (not including any style)
* @note added in 2.0
*/
virtual void setFontFamily( QString fontFamily ) = 0;

//! Zoom to full extent of map layers
virtual void zoomFull() = 0;

@@ -83,9 +83,10 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
connect( mButtonBox, SIGNAL( rejected() ), this, SLOT( close() ) );

QSettings settings;
setAppStyleSheet();

int size = settings.value( "/IconSize", QGIS_ICON_SIZE ).toInt();
setIconSize( QSize( size, size ) );
setFontSize( settings.value( "/fontPointSize", QGIS_DEFAULT_FONTSIZE ).toInt() );

QToolButton* orderingToolButton = new QToolButton( this );
orderingToolButton->setPopupMode( QToolButton::InstantPopup );
@@ -372,7 +373,14 @@ void QgsComposer::setIconSizes( int size )

void QgsComposer::setFontSize( int fontSize )
{
setStyleSheet( QString( "font-size: %1pt; " ).arg( fontSize ) );
//Convenience method for backwards compatibility
//Should set directly for QgisApp instead
QgisApp::instance()->setFontSize( fontSize );
}

void QgsComposer::setAppStyleSheet()
{
setStyleSheet( QgisApp::instance()->styleSheet() );
}

void QgsComposer::connectSlots()
@@ -60,6 +60,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

void setIconSizes( int size );
void setFontSize( int size );
//! Set app stylesheet from main app
//! @note added in 2.0
void setAppStyleSheet();

//! Open and show, set defaults if first time
void open();
@@ -457,7 +457,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
qApp->processEvents();

QSettings settings;
setFontSize( settings.value( "/fontPointSize", QGIS_DEFAULT_FONTSIZE ).toInt() );
setAppStyleSheet();

QWidget *centralWidget = this->centralWidget();
QGridLayout *centralLayout = new QGridLayout( centralWidget );
@@ -1147,11 +1147,48 @@ void QgisApp::createActionGroups()

void QgisApp::setFontSize( int fontSize )
{
setStyleSheet( QString( "font-size: %1pt; " ).arg( fontSize ) );
if ( fontSize < 4 || 99 < fontSize ) // defaults for Options spinbox
{
return;
}
QSettings settings;
settings.setValue( "/fontPointSize", fontSize );
setAppStyleSheet();
}

void QgisApp::setFontFamily( const QString& fontFamily )
{
QSettings settings;
settings.setValue( "/fontFamily", fontFamily );
setAppStyleSheet();
}

void QgisApp::setAppStyleSheet()
{
QSettings settings;
int fontSize = settings.value( "/fontPointSize", QGIS_DEFAULT_FONTSIZE ).toInt();

QString fontFamily = settings.value( "/fontFamily", QVariant( "QtDefault" ) ).toString();

QString family = QString( "" ); // use default Qt font family
if ( fontFamily != "QtDefault" )
{
QFont *tempFont = new QFont( fontFamily );
// is exact family match returned from system?
if ( tempFont->family() == fontFamily )
{
family = QString( " \"%1\";" ).arg( fontFamily );
}
delete tempFont;
}

QString stylesheet = QString( "font: %1pt%2\n" ).arg( fontSize ).arg( family );
setStyleSheet( stylesheet );

// cascade styles to any current project composers
foreach ( QgsComposer *c, mPrintComposers )
{
c->setFontSize( fontSize );
c->setAppStyleSheet();
}
}

@@ -175,7 +175,13 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
void setTheme( QString themeName = "default" );

void setIconSizes( int size );
void setFontSize( int size );
void setFontSize( int fontSize );
//! Set app font family
//! @note added in 2.0
void setFontFamily( const QString& fontFamily );
//! Set app stylesheet from settings
//! @note added in 2.0
void setAppStyleSheet();

//! Setup the toolbar popup menus for a given theme
void setupToolbarPopups( QString themeName );
@@ -67,6 +67,16 @@ QgsLegendInterface* QgisAppInterface::legendInterface()
return &legendIface;
}

void QgisAppInterface::setFontSize( int fontSize )
{
qgis->setFontSize( fontSize );
}

void QgisAppInterface::setFontFamily( QString fontFamily )
{
qgis->setFontFamily( fontFamily );
}

void QgisAppInterface::zoomFull()
{
qgis->zoomFull();
@@ -50,6 +50,18 @@ class QgisAppInterface : public QgisInterface
QgsLegendInterface* legendInterface();

/* Exposed functions */
/** Set the app font size
* @param fontSize point size of font
* @note added in 2.0
*/
void setFontSize( int fontSize );

/** Set the app font family
* @param fontFamily family of font (not including any style)
* @note added in 2.0
*/
void setFontFamily( QString fontFamily );

//! Zoom map to full extent
void zoomFull();
//! Zoom map to previous extent
@@ -32,6 +32,7 @@
#include "qgsrasterformatsaveoptionswidget.h"
#include "qgsrasterpyramidsoptionswidget.h"
#include "qgsdialog.h"
#include "qgscomposer.h"

#include <QInputDialog>
#include <QFileDialog>
@@ -76,7 +77,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
connect( cmbIconSize, SIGNAL( highlighted( const QString& ) ), this, SLOT( iconSizeChanged( const QString& ) ) );
connect( cmbIconSize, SIGNAL( textChanged( const QString& ) ), this, SLOT( iconSizeChanged( const QString& ) ) );

connect( spinFontSize, SIGNAL( valueChanged( const QString& ) ), this, SLOT( fontSizeChanged( const QString& ) ) );
connect( spinFontSize, SIGNAL( valueChanged( const QString& ) ), this, SLOT( updateAppStyleSheet() ) );
connect( mFontFamilyRadioQt, SIGNAL( released() ), this, SLOT( updateAppStyleSheet() ) );
connect( mFontFamilyRadioCustom, SIGNAL( released() ), this, SLOT( updateAppStyleSheet() ) );
connect( mFontFamilyComboBox, SIGNAL( currentFontChanged( const QFont& ) ), this, SLOT( updateAppStyleSheet() ) );

connect( cmbEllipsoid, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updateEllipsoidUI( int ) ) );

@@ -85,6 +89,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
#endif

connect( this, SIGNAL( accepted() ), this, SLOT( saveOptions() ) );
connect( this, SIGNAL( rejected() ), this, SLOT( rejectOptions() ) );

QStringList styles = QStyleFactory::keys();
foreach ( QString style, styles )
@@ -373,7 +378,26 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
// set the theme combo
cmbTheme->setCurrentIndex( cmbTheme->findText( settings.value( "/Themes", "default" ).toString() ) );
cmbIconSize->setCurrentIndex( cmbIconSize->findText( settings.value( "/IconSize", QGIS_ICON_SIZE ).toString() ) );

// set font size and family
blockSignals( true );
spinFontSize->setValue( settings.value( "/fontPointSize", QGIS_DEFAULT_FONTSIZE ).toInt() );
QString fontFamily = settings.value( "/fontFamily", QVariant( "QtDefault" ) ).toString();
bool isQtDefault = ( fontFamily == QString( "QtDefault" ) );
mFontFamilyRadioQt->setChecked( isQtDefault );
mFontFamilyRadioCustom->setChecked( !isQtDefault );
if ( !isQtDefault )
{
QFont *tempFont = new QFont( fontFamily );
// is exact family match returned from system?
if ( tempFont->family() == fontFamily )
{
mFontFamilyComboBox->setCurrentFont( *tempFont );
}
delete tempFont;
}
blockSignals( false );

QString name = QApplication::style()->objectName();
cmbStyle->setCurrentIndex( cmbStyle->findText( name, Qt::MatchFixedString ) );
//set the state of the checkboxes
@@ -741,9 +765,23 @@ void QgsOptions::iconSizeChanged( const QString &iconSize )
QgisApp::instance()->setIconSizes( iconSize.toInt() );
}

void QgsOptions::fontSizeChanged( const QString &fontSize )
void QgsOptions::updateAppStyleSheet()
{
QgisApp::instance()->setFontSize( fontSize.toInt() );
int fontSize = spinFontSize->value();

QString family = QString( "" ); // use default Qt font family
if ( mFontFamilyRadioCustom->isChecked() )
{
family = QString( " \"%1\";" ).arg( mFontFamilyComboBox->currentFont().family() );
}

QString stylesheet = QString( "font: %1pt%2" ).arg( fontSize ).arg( family );
QgisApp::instance()->setStyleSheet( stylesheet );

foreach ( QgsComposer* c, QgisApp::instance()->printComposers() )
{
c->setAppStyleSheet();
}
}

void QgsOptions::toggleEnableBackbuffer( int state )
@@ -910,7 +948,16 @@ void QgsOptions::saveOptions()
}

settings.setValue( "/IconSize", cmbIconSize->currentText() );

// application stylesheet settings
settings.setValue( "/fontPointSize", spinFontSize->value() );
QString fontFamily = QString( "QtDefault" );
if ( mFontFamilyRadioCustom->isChecked() )
{
fontFamily = mFontFamilyComboBox->currentFont().family();
}
settings.setValue( "/fontFamily", fontFamily );
QgisApp::instance()->setAppStyleSheet();

// rasters settings
settings.setValue( "/Raster/defaultRedBand", spnRed->value() );
@@ -1086,6 +1133,10 @@ void QgsOptions::saveOptions()
saveGdalDriverList();
}

void QgsOptions::rejectOptions()
{
QgisApp::instance()->setAppStyleSheet();
}

void QgsOptions::on_pbnSelectProjection_clicked()
{
@@ -65,13 +65,21 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
void on_pbnEditPyramidsOptions_pressed();
void editGdalDriver( const QString& driverName );
void saveOptions();
/*!
* Slot to reset any temporarily applied options on dialog close/cancel
* @note added in QGIS 2.0
*/
void rejectOptions();
//! Slot to change the theme this is handled when the user
// activates or highlights a theme name in the drop-down list
void themeChanged( const QString & );

void iconSizeChanged( const QString &iconSize );

void fontSizeChanged( const QString &fontSize );
/*!
* Slot to temporarily apply settings to app stylesheet
* @note added in QGIS 2.0
*/
void updateAppStyleSheet();

//! Slot to change backbuffering. This is handled when the user changes
// the value of the checkbox
@@ -76,6 +76,19 @@ class GUI_EXPORT QgisInterface : public QObject

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

/* Exposed functions */
/** Set the app font size
* @param fontSize point size of font
* @note added in 2.0
*/
virtual void setFontSize( int fontSize ) = 0;

/** Set the app font family
* @param fontFamily family of font (not including any style)
* @note added in 2.0
*/
virtual void setFontFamily( QString fontFamily ) = 0;

//! Zoom to full extent of map layers
virtual void zoomFull() = 0;

0 comments on commit 48e0a97

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