QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  setFoldingVisible( true );
35 }
36 
38 {
39  QFont font = lexerFont();
41 
42  QsciLexerHTML *lexer = new QsciLexerHTML( this );
43  lexer->setDefaultFont( font );
44  lexer->setDefaultColor( defaultColor );
46  lexer->setFont( font, -1 );
47 
48  font.setItalic( true );
49  lexer->setFont( font, QsciLexerHTML::HTMLComment );
50  lexer->setFont( font, QsciLexerHTML::JavaScriptComment );
51  lexer->setFont( font, QsciLexerHTML::JavaScriptCommentLine );
52 
53  lexer->setColor( defaultColor, QsciLexerHTML::Default );
54  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Tag ), QsciLexerHTML::Tag );
55  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::UnknownTag ), QsciLexerHTML::UnknownTag );
56  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Method ), QsciLexerHTML::Attribute );
57  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Method ), QsciLexerHTML::UnknownAttribute );
58  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Class ), QsciLexerHTML::Entity );
59  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Number ), QsciLexerHTML::HTMLNumber );
60  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Comment ), QsciLexerHTML::HTMLComment );
61  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Comment ), QsciLexerHTML::JavaScriptComment );
62  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::CommentLine ), QsciLexerHTML::JavaScriptCommentLine );
63  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Number ), QsciLexerHTML::JavaScriptNumber );
64  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Keyword ), QsciLexerHTML::JavaScriptKeyword );
65  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QsciLexerHTML::JavaScriptDoubleQuotedString );
66  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::SingleQuote ), QsciLexerHTML::JavaScriptSingleQuotedString );
67  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::SingleQuote ), QsciLexerHTML::HTMLSingleQuotedString );
68  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QsciLexerHTML::HTMLDoubleQuotedString );
69 
70  setLexer( lexer );
72 }
QgsCodeEditor::lexerColor
QColor lexerColor(QgsCodeEditorColorScheme::ColorRole role) const
Returns the color to use in the lexer for the specified role.
Definition: qgscodeeditor.cpp:154
QgsCodeEditorColorScheme::ColorRole::Default
@ Default
Default text color.
QgsCodeEditorColorScheme::ColorRole::CommentLine
@ CommentLine
Line comment color.
qgssymbollayerutils.h
QgsCodeEditor
A text editor based on QScintilla2.
Definition: qgscodeeditor.h:42
QgsCodeEditorColorScheme::ColorRole::Tag
@ Tag
Tag color.
QgsCodeEditorColorScheme::ColorRole::UnknownTag
@ UnknownTag
Unknown tag.
QgsCodeEditorColorScheme::ColorRole::SingleQuote
@ SingleQuote
Single quote color.
QgsCodeEditor::setTitle
void setTitle(const QString &title)
Set the widget title.
Definition: qgscodeeditor.cpp:259
qgsapplication.h
QgsCodeEditorColorScheme::ColorRole::DoubleQuote
@ DoubleQuote
Double quote color.
QgsCodeEditorColorScheme::ColorRole::Method
@ Method
Method color.
QgsCodeEditorColorScheme::ColorRole::Comment
@ Comment
Comment color.
QgsCodeEditor::lexerFont
QFont lexerFont() const
Returns the font to use in the lexer.
Definition: qgscodeeditor.cpp:170
qgscodeeditorhtml.h
QgsCodeEditor::runPostLexerConfigurationTasks
void runPostLexerConfigurationTasks()
Performs tasks which must be run after a lexer has been set for the widget.
Definition: qgscodeeditor.cpp:203
QgsCodeEditorColorScheme::ColorRole::Number
@ Number
Number color.
QgsCodeEditorHTML::QgsCodeEditorHTML
QgsCodeEditorHTML(QWidget *parent=nullptr)
Constructor for QgsCodeEditorHTML.
Definition: qgscodeeditorhtml.cpp:26
QgsCodeEditor::defaultColor
static QColor defaultColor(QgsCodeEditorColorScheme::ColorRole role, const QString &theme=QString())
Returns the default color for the specified role.
Definition: qgscodeeditor.cpp:342
QgsCodeEditorHTML::initializeLexer
void initializeLexer() override
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
Definition: qgscodeeditorhtml.cpp:37
QgsCodeEditorColorScheme::ColorRole::Class
@ Class
Class color.
QgsCodeEditor::setFoldingVisible
void setFoldingVisible(bool folding)
Set whether the folding controls are visible in the editor.
Definition: qgscodeeditor.cpp:309
QgsCodeEditorColorScheme::ColorRole::Background
@ Background
Background color.
QgsCodeEditorColorScheme::ColorRole::Keyword
@ Keyword
Keyword color.