QGIS API Documentation 3.99.0-Master (e9821da5c6b)
Loading...
Searching...
No Matches
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 "qgscodeeditorcss.h"
17
18#include <QFont>
19#include <QString>
20#include <QWidget>
21#include <Qsci/qscilexercss.h>
22
23#include "moc_qgscodeeditorcss.cpp"
24
25using namespace Qt::StringLiterals;
26
28 : QgsCodeEditor( parent, QString(), false, false, QgsCodeEditor::Flag::CodeFolding )
29{
30 if ( !parent )
31 {
32 setTitle( tr( "CSS Editor" ) );
33 }
35}
36
41
43{
44 QsciLexerCSS *lexer = new QgsQsciLexerCSS( this );
45
46 QFont font = lexerFont();
47 lexer->setDefaultFont( font );
48 lexer->setFont( font, -1 );
49
50 font.setItalic( true );
51 lexer->setFont( font, QsciLexerCSS::Comment );
52
53 font.setItalic( false );
54 font.setBold( true );
55 lexer->setFont( font, QsciLexerCSS::SingleQuotedString );
56 lexer->setFont( font, QsciLexerCSS::DoubleQuotedString );
57
61
62 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Tag ), QsciLexerCSS::Tag );
63 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Class ), QsciLexerCSS::ClassSelector );
64 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Keyword ), QsciLexerCSS::Attribute );
65 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Method ), QsciLexerCSS::PseudoClass );
66 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Method ), QsciLexerCSS::UnknownPseudoClass );
67 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Operator ), QsciLexerCSS::Operator );
68 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Number ), QsciLexerCSS::Value );
69 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Comment ), QsciLexerCSS::Comment );
70 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QsciLexerCSS::DoubleQuotedString );
71 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::SingleQuote ), QsciLexerCSS::SingleQuotedString );
72 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Identifier ), QsciLexerCSS::CSS1Property );
73 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Identifier ), QsciLexerCSS::UnknownProperty );
74 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Identifier ), QsciLexerCSS::CSS2Property );
75 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Identifier ), QsciLexerCSS::CSS3Property );
76
77 setLexer( lexer );
78
80}
81
83//
84// QgsQsciLexerCSS
85//
86QgsQsciLexerCSS::QgsQsciLexerCSS( QObject *parent )
87 : QsciLexerCSS( parent )
88{
89}
90
91QString QgsQsciLexerCSS::description( int style ) const
92{
93 // see https://www.riverbankcomputing.com/pipermail/qscintilla/2019-July/001415.html
94 if ( style == QsciLexerCSS::Comment )
95 return u"Comment"_s;
96
97 return QsciLexerCSS::description( style );
98}
ScriptLanguage
Scripting languages.
Definition qgis.h:4561
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).
QgsCodeEditorCSS(QWidget *parent=nullptr)
Constructor for QgsCodeEditorCSS.
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.
QgsCodeEditor(QWidget *parent=nullptr, const QString &title=QString(), bool folding=false, bool margin=false, QgsCodeEditor::Flags flags=QgsCodeEditor::Flags(), QgsCodeEditor::Mode mode=QgsCodeEditor::Mode::ScriptEditor)
Construct a new code editor.
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.