QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgscodeeditorcss.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscodeeditorcss.cpp - A CSS editor based on QScintilla
3  --------------------------------------
4  Date : 27-Jul-2014
5  Copyright : (C) 2014 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 "qgscodeeditorcss.h"
18 
19 #include <QWidget>
20 #include <QString>
21 #include <QFont>
22 #include <Qsci/qscilexercss.h>
23 
24 
26  : QgsCodeEditor( parent )
27 {
28  if ( !parent )
29  {
30  setTitle( tr( "CSS Editor" ) );
31  }
32  setFoldingVisible( true );
34 }
35 
37 {
38  QsciLexerCSS *lexer = new QgsQsciLexerCSS( this );
39 
40  QFont font = lexerFont();
41  lexer->setDefaultFont( font );
42  lexer->setFont( font, -1 );
43 
44  font.setItalic( true );
45  lexer->setFont( font, QsciLexerCSS::Comment );
46 
47  font.setItalic( false );
48  font.setBold( true );
49  lexer->setFont( font, QsciLexerCSS::SingleQuotedString );
50  lexer->setFont( font, QsciLexerCSS::DoubleQuotedString );
51 
52  lexer->setDefaultColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Default ) );
55 
56  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Tag ), QsciLexerCSS::Tag );
57  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Class ), QsciLexerCSS::ClassSelector );
58  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Keyword ), QsciLexerCSS::Attribute );
59  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Method ), QsciLexerCSS::PseudoClass );
60  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Method ), QsciLexerCSS::UnknownPseudoClass );
61  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Operator ), QsciLexerCSS::Operator );
62  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Number ), QsciLexerCSS::Value );
63  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Comment ), QsciLexerCSS::Comment );
64  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QsciLexerCSS::DoubleQuotedString );
65  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::SingleQuote ), QsciLexerCSS::SingleQuotedString );
66  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Identifier ), QsciLexerCSS::CSS1Property );
67  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Identifier ), QsciLexerCSS::UnknownProperty );
68  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Identifier ), QsciLexerCSS::CSS2Property );
69  lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Identifier ), QsciLexerCSS::CSS3Property );
70 
71  setLexer( lexer );
72 
74 }
75 
76 //
77 // QgsQsciLexerCSS
78 //
79 QgsQsciLexerCSS::QgsQsciLexerCSS( QObject *parent )
80  : QsciLexerCSS( parent )
81 {
82 
83 }
84 
85 QString QgsQsciLexerCSS::description( int style ) const
86 {
87  // see https://www.riverbankcomputing.com/pipermail/qscintilla/2019-July/001415.html
88  if ( style == QsciLexerCSS::Comment )
89  return QStringLiteral( "Comment" );
90 
91  return QsciLexerCSS::description( style );
92 }
QgsCodeEditor::lexerColor
QColor lexerColor(QgsCodeEditorColorScheme::ColorRole role) const
Returns the color to use in the lexer for the specified role.
Definition: qgscodeeditor.cpp:154
QgsCodeEditorCSS::QgsCodeEditorCSS
QgsCodeEditorCSS(QWidget *parent=nullptr)
Constructor for QgsCodeEditorCSS.
Definition: qgscodeeditorcss.cpp:25
QgsCodeEditorColorScheme::ColorRole::Default
@ Default
Default text color.
QgsCodeEditor
A text editor based on QScintilla2.
Definition: qgscodeeditor.h:42
QgsCodeEditorColorScheme::ColorRole::Operator
@ Operator
Operator color.
QgsCodeEditorColorScheme::ColorRole::Tag
@ Tag
Tag color.
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
qgscodeeditorcss.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.
QgsCodeEditorColorScheme::ColorRole::Identifier
@ Identifier
Identifier color.
QgsCodeEditorCSS::initializeLexer
void initializeLexer() override
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
Definition: qgscodeeditorcss.cpp:36
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.