QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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 "qgscodeeditorhtml.h"
17
18#include <QWidget>
19#include <QString>
20#include <QFont>
21#include <Qsci/qscilexerhtml.h>
22
23
25 : QgsCodeEditor( parent,
26 QString(),
27 false,
28 false,
29 QgsCodeEditor::Flag::CodeFolding )
30{
31 if ( !parent )
32 {
33 setTitle( tr( "HTML Editor" ) );
34 }
36}
37
39{
41}
42
44{
45 QFont font = lexerFont();
47
48 QsciLexerHTML *lexer = new QsciLexerHTML( this );
49 lexer->setDefaultFont( font );
50 lexer->setDefaultColor( defaultColor );
52 lexer->setFont( font, -1 );
53
54 font.setItalic( true );
55 lexer->setFont( font, QsciLexerHTML::HTMLComment );
56 lexer->setFont( font, QsciLexerHTML::JavaScriptComment );
57 lexer->setFont( font, QsciLexerHTML::JavaScriptCommentLine );
58
59 lexer->setColor( defaultColor, QsciLexerHTML::Default );
60 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Tag ), QsciLexerHTML::Tag );
61 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::UnknownTag ), QsciLexerHTML::UnknownTag );
62 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Method ), QsciLexerHTML::Attribute );
63 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Method ), QsciLexerHTML::UnknownAttribute );
64 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Class ), QsciLexerHTML::Entity );
65 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Number ), QsciLexerHTML::HTMLNumber );
66 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Comment ), QsciLexerHTML::HTMLComment );
67 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Comment ), QsciLexerHTML::JavaScriptComment );
68 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::CommentLine ), QsciLexerHTML::JavaScriptCommentLine );
69 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Number ), QsciLexerHTML::JavaScriptNumber );
70 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Keyword ), QsciLexerHTML::JavaScriptKeyword );
71 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QsciLexerHTML::JavaScriptDoubleQuotedString );
72 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::SingleQuote ), QsciLexerHTML::JavaScriptSingleQuotedString );
73 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::SingleQuote ), QsciLexerHTML::HTMLSingleQuotedString );
74 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QsciLexerHTML::HTMLDoubleQuotedString );
75
76 setLexer( lexer );
78}
ScriptLanguage
Scripting languages.
Definition: qgis.h:2715
@ DoubleQuote
Double quote color.
@ CommentLine
Line comment color.
@ SingleQuote
Single quote color.
Qgis::ScriptLanguage language() const override
Returns the associated scripting language.
void initializeLexer() override
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
QgsCodeEditorHTML(QWidget *parent=nullptr)
Constructor for QgsCodeEditorHTML.
A text editor based on QScintilla2.
Definition: qgscodeeditor.h:93
void runPostLexerConfigurationTasks()
Performs tasks which must be run after a lexer has been set for the widget.
void setTitle(const QString &title)
Set the widget title.
Flag
Flags controlling behavior of code editor.
QFont lexerFont() const
Returns the font to use in the lexer.
QColor lexerColor(QgsCodeEditorColorScheme::ColorRole role) const
Returns the color to use in the lexer for the specified role.
static QColor defaultColor(QgsCodeEditorColorScheme::ColorRole role, const QString &theme=QString())
Returns the default color for the specified role.