Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
don't set parent of QFontDialog to avoid the stylesheet font (fixes #…
  • Loading branch information
jef-n committed Feb 21, 2015
1 parent dbcbddb commit 57ba28c
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 123 deletions.
35 changes: 9 additions & 26 deletions src/app/composer/qgscomposerattributetablewidget.cpp
Expand Up @@ -28,8 +28,7 @@
#include "qgsexpressionbuilderdialog.h"
#include "qgsproject.h"
#include "qgsrelationmanager.h"
#include <QColorDialog>
#include <QFontDialog>
#include "qgisgui.h"

QgsComposerAttributeTableWidget::QgsComposerAttributeTableWidget( QgsComposerAttributeTableV2* table, QgsComposerFrame* frame )
: QgsComposerItemBaseWidget( 0, table )
Expand Down Expand Up @@ -283,29 +282,20 @@ void QgsComposerAttributeTableWidget::on_mMarginSpinBox_valueChanged( double d )
void QgsComposerAttributeTableWidget::on_mHeaderFontPushButton_clicked()
{
if ( !mComposerTable )
{
return;
}

bool ok;
#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont newFont = QFontDialog::getFont( &ok, mComposerTable->headerFont(), this, tr( "Select Font" ), QFontDialog::DontUseNativeDialog );
#else
QFont newFont = QFontDialog::getFont( &ok, mComposerTable->headerFont(), this, tr( "Select Font" ) );
#endif
if ( ok )
QFont newFont = QgisGui::getFont( ok, mComposerTable->headerFont(), tr( "Select Font" ) );
if ( !ok )
{
QgsComposition* composition = mComposerTable->composition();
QgsComposition *composition = mComposerTable->composition();
if ( composition )
{
composition->beginMultiFrameCommand( mComposerTable, tr( "Table header font" ) );
}

mComposerTable->setHeaderFont( newFont );

if ( composition )
{
composition->endMultiFrameCommand();
}
}
}

Expand Down Expand Up @@ -336,24 +326,17 @@ void QgsComposerAttributeTableWidget::on_mContentFontPushButton_clicked()
}

bool ok;
#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont newFont = QFontDialog::getFont( &ok, mComposerTable->contentFont(), this, tr( "Select Font" ), QFontDialog::DontUseNativeDialog );
#else
QFont newFont = QFontDialog::getFont( &ok, mComposerTable->contentFont(), this, tr( "Select Font" ) );
#endif
QFont newFont = QgisGui::getFont( ok, mComposerTable->contentFont(), tr( "Select Font" ) );
if ( ok )
{
QgsComposition* composition = mComposerTable->composition();
if ( composition )
{
composition->beginMultiFrameCommand( mComposerTable, tr( "Table content font" ) );
}

mComposerTable->setContentFont( newFont );

if ( composition )
{
composition->endMultiFrameCommand();
}
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/app/composer/qgscomposerlabelwidget.cpp
Expand Up @@ -91,12 +91,7 @@ void QgsComposerLabelWidget::on_mFontButton_clicked()
if ( mComposerLabel )
{
bool ok;
#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont newFont = QFontDialog::getFont( &ok, mComposerLabel->font(), this, QString(), QFontDialog::DontUseNativeDialog );
#else
QFont newFont = QFontDialog::getFont( &ok, mComposerLabel->font(), this );
#endif
QFont newFont = QgisGui::getFont( ok, mComposerLabel->font() );
if ( ok )
{
mComposerLabel->beginCommand( tr( "Label font changed" ) );
Expand Down
33 changes: 6 additions & 27 deletions src/app/composer/qgscomposerlegendwidget.cpp
Expand Up @@ -23,9 +23,7 @@
#include "qgscomposeritemwidget.h"
#include "qgscomposermap.h"
#include "qgscomposition.h"
#include <QFontDialog>
#include <QColorDialog>
#include <QInputDialog>
#include "qgisgui.h"

#include "qgisapp.h"
#include "qgsapplication.h"
Expand All @@ -41,6 +39,7 @@
#include "qgsvectorlayer.h"

#include <QMessageBox>
#include <QInputDialog>



Expand Down Expand Up @@ -369,12 +368,7 @@ void QgsComposerLegendWidget::on_mTitleFontButton_clicked()
if ( mLegend )
{
bool ok;
#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::Title ).font(), this, QString(), QFontDialog::DontUseNativeDialog );
#else
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::Title ).font(), this );
#endif
QFont newFont = QgisGui::getFont( ok, mLegend->style( QgsComposerLegendStyle::Title ).font() );
if ( ok )
{
mLegend->beginCommand( tr( "Title font changed" ) );
Expand All @@ -391,12 +385,7 @@ void QgsComposerLegendWidget::on_mGroupFontButton_clicked()
if ( mLegend )
{
bool ok;
#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::Group ).font(), this, QString(), QFontDialog::DontUseNativeDialog );
#else
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::Group ).font(), this );
#endif
QFont newFont = QgisGui::getFont( ok, mLegend->style( QgsComposerLegendStyle::Group ).font() );
if ( ok )
{
mLegend->beginCommand( tr( "Legend group font changed" ) );
Expand All @@ -413,12 +402,7 @@ void QgsComposerLegendWidget::on_mLayerFontButton_clicked()
if ( mLegend )
{
bool ok;
#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::Subgroup ).font(), this, QString(), QFontDialog::DontUseNativeDialog );
#else
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::Subgroup ).font(), this );
#endif
QFont newFont = QgisGui::getFont( ok, mLegend->style( QgsComposerLegendStyle::Subgroup ).font() );
if ( ok )
{
mLegend->beginCommand( tr( "Legend layer font changed" ) );
Expand All @@ -435,12 +419,7 @@ void QgsComposerLegendWidget::on_mItemFontButton_clicked()
if ( mLegend )
{
bool ok;
#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::SymbolLabel ).font(), this, QString(), QFontDialog::DontUseNativeDialog );
#else
QFont newFont = QFontDialog::getFont( &ok, mLegend->style( QgsComposerLegendStyle::SymbolLabel ).font(), this );
#endif
QFont newFont = QgisGui::getFont( ok, mLegend->style( QgsComposerLegendStyle::SymbolLabel ).font() );
if ( ok )
{
mLegend->beginCommand( tr( "Legend item font changed" ) );
Expand Down
12 changes: 3 additions & 9 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -27,7 +27,6 @@
#include "qgsmaprenderer.h"
#include "qgsstylev2.h"
#include "qgssymbolv2.h"
//#include "qgssymbolv2propertiesdialog.h"
#include "qgssymbolv2selectordialog.h"
#include "qgssymbollayerv2utils.h"
#include "qgsvectorlayer.h"
Expand All @@ -39,8 +38,8 @@
#include "qgsgenericprojectionselector.h"
#include "qgsproject.h"
#include "qgsvisibilitypresets.h"
#include <QColorDialog>
#include <QFontDialog>
#include "qgisgui.h"

#include <QMessageBox>

QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap )
Expand Down Expand Up @@ -2086,12 +2085,7 @@ void QgsComposerMapWidget::on_mAnnotationFontButton_clicked()
}

bool ok;
#if defined(Q_OS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont newFont = QFontDialog::getFont( &ok, grid->annotationFont(), this, QString(), QFontDialog::DontUseNativeDialog );
#else
QFont newFont = QFontDialog::getFont( &ok, grid->annotationFont(), this );
#endif
QFont newFont = QgisGui::getFont( ok, grid->annotationFont() );
if ( ok )
{
mComposerMap->beginCommand( tr( "Annotation font changed" ) );
Expand Down
8 changes: 1 addition & 7 deletions src/app/composer/qgscomposerscalebarwidget.cpp
Expand Up @@ -310,13 +310,7 @@ void QgsComposerScaleBarWidget::on_mFontButton_clicked()
}

bool dialogAccepted;
QFont oldFont = mComposerScaleBar->font();
#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont newFont = QFontDialog::getFont( &dialogAccepted, oldFont, this, QString(), QFontDialog::DontUseNativeDialog );
#else
QFont newFont = QFontDialog::getFont( &dialogAccepted, oldFont, this );
#endif
QFont newFont = QgisGui::getFont( dialogAccepted, mComposerScaleBar->font() );
if ( dialogAccepted )
{
mComposerScaleBar->beginCommand( tr( "Scalebar font changed" ) );
Expand Down
17 changes: 3 additions & 14 deletions src/app/composer/qgscomposertablewidget.cpp
Expand Up @@ -24,8 +24,7 @@
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
#include "qgsexpressionbuilderdialog.h"
#include <QColorDialog>
#include <QFontDialog>
#include "qgisgui.h"

QgsComposerTableWidget::QgsComposerTableWidget( QgsComposerAttributeTable* table ): QgsComposerItemBaseWidget( 0, table ), mComposerTable( table )
{
Expand Down Expand Up @@ -215,12 +214,7 @@ void QgsComposerTableWidget::on_mHeaderFontPushButton_clicked()
}

bool ok;
#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont newFont = QFontDialog::getFont( &ok, mComposerTable->headerFont(), this, tr( "Select Font" ), QFontDialog::DontUseNativeDialog );
#else
QFont newFont = QFontDialog::getFont( &ok, mComposerTable->headerFont(), this, tr( "Select Font" ) );
#endif
QFont newFont = QgisGui::getFont( ok, mComposerTable->headerFont(), tr( "Select Font" ) );
if ( ok )
{
mComposerTable->beginCommand( tr( "Table header font" ) );
Expand Down Expand Up @@ -250,12 +244,7 @@ void QgsComposerTableWidget::on_mContentFontPushButton_clicked()
}

bool ok;
#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont newFont = QFontDialog::getFont( &ok, mComposerTable->contentFont(), this, tr( "Select Font" ), QFontDialog::DontUseNativeDialog );
#else
QFont newFont = QFontDialog::getFont( &ok, mComposerTable->contentFont(), this, tr( "Select Font" ) );
#endif
QFont newFont = QgisGui::getFont( ok, mComposerTable->contentFont(), tr( "Select Font" ) );
if ( ok )
{
mComposerTable->beginCommand( tr( "Table content font" ) );
Expand Down
10 changes: 2 additions & 8 deletions src/app/qgsdecorationgriddialog.cpp
Expand Up @@ -25,9 +25,8 @@
#include "qgssymbolv2.h"
#include "qgssymbolv2selectordialog.h"
#include "qgisapp.h"
#include "qgisgui.h"

#include <QFontDialog>
#include <QColorDialog>
#include <QSettings>

QgsDecorationGridDialog::QgsDecorationGridDialog( QgsDecorationGrid& deco, QWidget* parent )
Expand Down Expand Up @@ -275,12 +274,7 @@ void QgsDecorationGridDialog::on_mPbtnUpdateFromLayer_clicked()
void QgsDecorationGridDialog::on_mAnnotationFontButton_clicked()
{
bool ok;
#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
QFont newFont = QFontDialog::getFont( &ok, mDeco.gridAnnotationFont(), 0, QString(), QFontDialog::DontUseNativeDialog );
#else
QFont newFont = QFontDialog::getFont( &ok, mDeco.gridAnnotationFont() );
#endif
QFont newFont = QgisGui::getFont( ok, mDeco.gridAnnotationFont() );
if ( ok )
{
mDeco.setGridAnnotationFont( newFont );
Expand Down
5 changes: 2 additions & 3 deletions src/app/qgsdiagramproperties.cpp
Expand Up @@ -30,9 +30,8 @@
#include "qgsvectordataprovider.h"
#include "qgsfeatureiterator.h"
#include "qgscolordialog.h"
#include "qgisgui.h"

#include <QColorDialog>
#include <QFontDialog>
#include <QList>
#include <QMessageBox>
#include <QSettings>
Expand Down Expand Up @@ -494,7 +493,7 @@ void QgsDiagramProperties::on_mDisplayDiagramsGroupBox_toggled( bool checked )
void QgsDiagramProperties::on_mDiagramFontButton_clicked()
{
bool ok;
mDiagramFont = QFontDialog::getFont( &ok, mDiagramFont );
mDiagramFont = QgisGui::getFont( ok, mDiagramFont );
}


Expand Down
9 changes: 2 additions & 7 deletions src/app/qgslabeldialog.cpp
Expand Up @@ -21,9 +21,9 @@
#include "qgslabel.h"
#include "qgslabelattributes.h"
#include "qgslogger.h"
#include "qgisgui.h"

#include <QColorDialog>
#include <QFontDialog>
#include <QTabWidget>
#include <QDoubleValidator>

Expand Down Expand Up @@ -277,12 +277,7 @@ void QgsLabelDialog::changeFont( void )

qreal fontSize = mFont.pointSizeF();
bool resultFlag;
#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
mFont = QFontDialog::getFont( &resultFlag, mFont, 0, QString(), QFontDialog::DontUseNativeDialog );
#else
mFont = QFontDialog::getFont( &resultFlag, mFont );
#endif
QFont newFont = QgisGui::getFont( resultFlag, mFont );
if ( !resultFlag )
return;

Expand Down
6 changes: 0 additions & 6 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -36,12 +36,6 @@
#include "qgssvgselectorwidget.h"

#include <QCheckBox>
#include <QColorDialog>
#include <QFileDialog>
#include <QFontDialog>
#include <QTextEdit>
#include <QApplication>
#include <QMessageBox>
#include <QSettings>


Expand Down
17 changes: 15 additions & 2 deletions src/gui/qgisgui.cpp
Expand Up @@ -15,11 +15,11 @@
#include "qgisgui.h"

#include <QSettings>
#include <QObject> //for tr
#include <QImageWriter>
#include "qgsencodingfiledialog.h"
#include "qgslogger.h"
#include <memory> //for auto_ptr

#include <QFontDialog>


namespace QgisGui
Expand Down Expand Up @@ -188,4 +188,17 @@ namespace QgisGui
return createFileFilter_( longName, glob );
}

QFont getFont( bool &ok, const QFont &initial, const QString &title )
{
// parent is intentionally not set to 'this' as
// that would make it follow the style sheet font
// see also #12233 and #4937

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Feb 22, 2015

Collaborator

@jef-n what causes this? is it a Qt bug?

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Feb 22, 2015

Collaborator

Actually I'm guessing it's https://bugreports.qt.io/plugins/servlet/mobile#issue/QTBUG-41513 - fixed in 5.4. I wonder if we should allow a parent for this method, and ignore it for qt < 5.4...?

#if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)
// Native Mac dialog works only for Qt Carbon
return QFontDialog::getFont( &ok, initial, 0, title, QFontDialog::DontUseNativeDialog );
#else
return QFontDialog::getFont( &ok, initial, 0, title );
#endif
}

} // end of QgisGui namespace
10 changes: 10 additions & 0 deletions src/gui/qgisgui.h
Expand Up @@ -19,6 +19,8 @@
#include <QPair>
#include <QStringList>

class QFont;

/** \ingroup gui
* /namespace QgisGui
* The QgisGui namespace contains constants and helper functions used throughout the QGIS GUI.
Expand Down Expand Up @@ -100,6 +102,14 @@ namespace QgisGui
*/
QString GUI_EXPORT createFileFilter_( QString const &format );

/**
* Show font selection dialog
* @param ok true on ok, false on cancel
* @param initial initial font
* @param title optional dialog title
* @return QFont the selected fon
*/
QFont GUI_EXPORT getFont( bool &ok, const QFont &initial, const QString &title = QString() );
}

#endif

0 comments on commit 57ba28c

Please sign in to comment.