Skip to content

Commit

Permalink
Cleanup style handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 21, 2021
1 parent 5bae3a2 commit 1404a79
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions src/gui/qgsrichtexteditor.cpp
Expand Up @@ -31,6 +31,7 @@
#include "qgsrichtexteditor.h"
#include "qgsguiutils.h"
#include "qgscolorbutton.h"
#include "qgscodeeditor.h"

#include <QMimeData>
#include <QApplication>
Expand Down Expand Up @@ -362,41 +363,44 @@ void QgsRichTextEditor::textStyle( int )
mTextEdit->setCurrentCharFormat( format );

ParagraphItems style = static_cast< ParagraphItems >( mParagraphStyleCombo->currentData().toInt() );
if ( style == ParagraphHeading1
|| style == ParagraphHeading2
|| style == ParagraphHeading3
|| style == ParagraphHeading4 )

switch ( style )
{
if ( style == ParagraphHeading1 )
{
case QgsRichTextEditor::ParagraphStandard:
break;

case QgsRichTextEditor::ParagraphHeading1:
format.setFontPointSize( mFontSizeH1 );
}
if ( style == ParagraphHeading2 )
{
format.setFontWeight( QFont::Bold );
break;

case QgsRichTextEditor::ParagraphHeading2:
format.setFontPointSize( mFontSizeH2 );
}
if ( style == ParagraphHeading3 )
{
format.setFontWeight( QFont::Bold );
format.setFontItalic( true );
break;

case QgsRichTextEditor::ParagraphHeading3:
format.setFontPointSize( mFontSizeH3 );
}
if ( style == ParagraphHeading4 )
{
format.setFontWeight( QFont::Bold );
break;

case QgsRichTextEditor::ParagraphHeading4:
format.setFontPointSize( mFontSizeH4 );
}
if ( style == ParagraphHeading2 || style == ParagraphHeading4 )
{
format.setFontWeight( QFont::Bold );
format.setFontItalic( true );
}
break;

format.setFontWeight( QFont::Bold );
}
if ( style == ParagraphMonospace )
{
format = cursor.charFormat();
format.setFontFamily( QStringLiteral( "Monospace" ) );
format.setFontStyleHint( QFont::Monospace );
format.setFontFixedPitch( true );
case QgsRichTextEditor::ParagraphMonospace:
{
format = cursor.charFormat();
format.setFontFamily( QgsCodeEditor::getMonospaceFont().family() );
format.setFontStyleHint( QFont::Monospace );
format.setFontFixedPitch( true );
break;
}
}

cursor.setCharFormat( format );
mTextEdit->setCurrentCharFormat( format );

Expand Down

0 comments on commit 1404a79

Please sign in to comment.