QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgscodeeditorjs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscodeeditorjs.cpp - A Javascript editor based on QScintilla
3  --------------------------------------
4  Date : June 2020
5  Copyright : (C) 2020 by Nyall Dawson
6  Email : nyall dot dawson 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 "qgscodeeditorjs.h"
18 
19 #include <QWidget>
20 #include <QString>
21 #include <QFont>
22 #include <Qsci/qscilexerjavascript.h>
23 
24 
26  : QgsCodeEditor( parent )
27 {
28  if ( !parent )
29  {
30  setTitle( tr( "JavaScript Editor" ) );
31  }
32  setFoldingVisible( true );
34 }
35 
37 {
38  QsciLexerJavaScript *lexer = new QsciLexerJavaScript( this );
39 
40  QFont font = lexerFont();
41  lexer->setDefaultFont( font );
42  lexer->setFont( font, -1 );
43 
44  font.setItalic( true );
45  lexer->setFont( font, QsciLexerJavaScript::Comment );
46  lexer->setFont( font, QsciLexerJavaScript::CommentLine );
47 
48  lexer->setDefaultColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Default ) );
51 
52  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Class ), QsciLexerJavaScript::GlobalClass );
53  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Keyword ), QsciLexerJavaScript::Keyword );
54  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Operator ), QsciLexerJavaScript::Operator );
55  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Number ), QsciLexerJavaScript::Number );
56  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Comment ), QsciLexerJavaScript::Comment );
57  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::CommentLine ), QsciLexerJavaScript::CommentLine );
58  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QsciLexerJavaScript::DoubleQuotedString );
59  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::SingleQuote ), QsciLexerJavaScript::SingleQuotedString );
60  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Identifier ), QsciLexerJavaScript::Identifier );
61 
62  setLexer( lexer );
63  setLineNumbersVisible( true );
65 }
@ DoubleQuote
Double quote color.
@ CommentLine
Line comment color.
@ SingleQuote
Single quote color.
QgsCodeEditorJavascript(QWidget *parent=nullptr)
Constructor for QgsCodeEditorJavascript.
void initializeLexer() override
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
A text editor based on QScintilla2.
Definition: qgscodeeditor.h:42
void setFoldingVisible(bool folding)
Set whether the folding controls are visible in the editor.
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.
void setLineNumbersVisible(bool visible)
Sets whether line numbers should be visible in the 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.