QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgscodeeditorhtml.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscodeeditorhtml.cpp - A HTML editor based on QScintilla
3  --------------------------------------
4  Date : 20-Jul-2014
5  Copyright : (C) 2014 by Nathan Woodrow
6  Email : woodrow.nathan (at) gmail (dot) com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsapplication.h"
17 #include "qgscodeeditorhtml.h"
18 #include "qgssymbollayerutils.h"
19 
20 #include <QWidget>
21 #include <QString>
22 #include <QFont>
23 #include <Qsci/qscilexerhtml.h>
24 
25 
27  : QgsCodeEditor( parent )
28 {
29  if ( !parent )
30  {
31  setTitle( tr( "HTML Editor" ) );
32  }
33  setMarginVisible( false );
34  setFoldingVisible( true );
35  setSciLexerHTML();
36 }
37 
38 void QgsCodeEditorHTML::setSciLexerHTML()
39 {
40  QHash< QString, QColor > colors;
41  if ( QgsApplication::instance()->themeName() != QStringLiteral( "default" ) )
42  {
43  QSettings ini( QgsApplication::instance()->uiThemes().value( QgsApplication::instance()->themeName() ) + "/qscintilla.ini", QSettings::IniFormat );
44  for ( const auto &key : ini.allKeys() )
45  {
46  colors.insert( key, QgsSymbolLayerUtils::decodeColor( ini.value( key ).toString() ) );
47  }
48  }
49 
50  QFont font = getMonospaceFont();
51  QColor defaultColor = colors.value( QStringLiteral( "html/defaultFontColor" ), Qt::black );
52 
53  QsciLexerHTML *lexer = new QsciLexerHTML( this );
54  lexer->setDefaultFont( font );
55  lexer->setDefaultColor( defaultColor );
56  lexer->setDefaultPaper( colors.value( QStringLiteral( "html/paperBackgroundColor" ), Qt::white ) );
57  lexer->setFont( font, -1 );
58 
59  lexer->setColor( defaultColor, QsciLexerHTML::Default );
60  lexer->setColor( colors.value( QStringLiteral( "html/tagFontColor" ), QColor( 66, 113, 174 ) ), QsciLexerHTML::Tag );
61  lexer->setColor( colors.value( QStringLiteral( "html/unknownTagFontColor" ), QColor( 255, 0, 0 ) ), QsciLexerHTML::UnknownTag );
62  lexer->setColor( colors.value( QStringLiteral( "html/numberFontColor" ), QColor( 200, 40, 41 ) ), QsciLexerHTML::HTMLNumber );
63  lexer->setColor( colors.value( QStringLiteral( "html/commentFontColor" ), QColor( 142, 144, 140 ) ), QsciLexerHTML::HTMLComment );
64  lexer->setColor( colors.value( QStringLiteral( "html/singleQuoteFontColor" ), QColor( 113, 140, 0 ) ), QsciLexerHTML::HTMLSingleQuotedString );
65  lexer->setColor( colors.value( QStringLiteral( "html/doubleQuoteFontColor" ), QColor( 113, 140, 0 ) ), QsciLexerHTML::HTMLDoubleQuotedString );
66 
67  setLexer( lexer );
68 }
qgssymbollayerutils.h
QgsCodeEditor::setMarginVisible
void setMarginVisible(bool margin)
Set margin visible state.
Definition: qgscodeeditor.cpp:146
QgsCodeEditor
Definition: qgscodeeditor.h:38
QgsApplication::instance
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
Definition: qgsapplication.cpp:390
QgsSymbolLayerUtils::decodeColor
static QColor decodeColor(const QString &str)
Definition: qgssymbollayerutils.cpp:57
QgsCodeEditor::setTitle
void setTitle(const QString &title)
Set the widget title.
Definition: qgscodeeditor.cpp:141
qgsapplication.h
qgscodeeditorhtml.h
QgsCodeEditorHTML::QgsCodeEditorHTML
QgsCodeEditorHTML(QWidget *parent=nullptr)
Constructor for QgsCodeEditorHTML.
Definition: qgscodeeditorhtml.cpp:26
QgsCodeEditor::setFoldingVisible
void setFoldingVisible(bool folding)
Set folding visible state.
Definition: qgscodeeditor.cpp:164
QgsCodeEditor::getMonospaceFont
QFont getMonospaceFont()
Definition: qgscodeeditor.cpp:199