QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgscodeeditorcolorschemeregistry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscodeeditorcolorschemeregistry.cpp
3  --------------------------------------
4  Date : October 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  ***************************************************************************/
16 
17 #include <QObject>
18 
20 {
21  QgsCodeEditorColorScheme defaultScheme( QStringLiteral( "default" ), QObject::tr( "Default" ) );
22  defaultScheme.setColors(
23  {
24  {QgsCodeEditorColorScheme::ColorRole::Default, QColor( "#4d4d4c" ) },
25  {QgsCodeEditorColorScheme::ColorRole::Keyword, QColor( "#8959a8" ) },
26  {QgsCodeEditorColorScheme::ColorRole::Class, QColor( "#4271ae" ) },
27  {QgsCodeEditorColorScheme::ColorRole::Method, QColor( "#4271ae" ) },
29  {QgsCodeEditorColorScheme::ColorRole::Number, QColor( "#c82829" ) },
30  {QgsCodeEditorColorScheme::ColorRole::Comment, QColor( "#8e908c" ) },
34  {QgsCodeEditorColorScheme::ColorRole::Operator, QColor( "#8959a8" ) },
38  {QgsCodeEditorColorScheme::ColorRole::Tag, QColor( "#4271ae" ) },
40  {QgsCodeEditorColorScheme::ColorRole::Cursor, QColor( "#636363" ) },
41  {QgsCodeEditorColorScheme::ColorRole::CaretLine, QColor( "#efefef" ) },
52  {QgsCodeEditorColorScheme::ColorRole::Edge, QColor( "#efefef" ) },
53  {QgsCodeEditorColorScheme::ColorRole::Fold, QColor( "#efefef" ) },
54  {QgsCodeEditorColorScheme::ColorRole::Error, QColor( "#e31a1c" ) },
59  } );
60  addColorScheme( defaultScheme );
61 
62  QgsCodeEditorColorScheme solarizedLight( QStringLiteral( "solarized" ), QObject::tr( "Solarized (Light)" ) );
63  solarizedLight.setColors(
64  {
65  {QgsCodeEditorColorScheme::ColorRole::Default, QColor( "#586E75" ) },
66  {QgsCodeEditorColorScheme::ColorRole::Keyword, QColor( "#859900" ) },
67  {QgsCodeEditorColorScheme::ColorRole::Class, QColor( "#268BD2" ) },
68  {QgsCodeEditorColorScheme::ColorRole::Method, QColor( "#268BD2" ) },
70  {QgsCodeEditorColorScheme::ColorRole::Number, QColor( "#2AA198" ) },
71  {QgsCodeEditorColorScheme::ColorRole::Comment, QColor( "#93A1A1" ) },
75  {QgsCodeEditorColorScheme::ColorRole::Cursor, QColor( "#DC322F" ) },
76  {QgsCodeEditorColorScheme::ColorRole::CaretLine, QColor( "#EEE8D5" ) },
77  {QgsCodeEditorColorScheme::ColorRole::Operator, QColor( "#586E75" ) },
81  {QgsCodeEditorColorScheme::ColorRole::Tag, QColor( "#2AA198" ) },
93  {QgsCodeEditorColorScheme::ColorRole::Edge, QColor( "#EEE8D5" ) },
94  {QgsCodeEditorColorScheme::ColorRole::Fold, QColor( "#EEE8D5" ) },
95  {QgsCodeEditorColorScheme::ColorRole::Error, QColor( "#DC322F" ) },
100  } );
101  addColorScheme( solarizedLight );
102 
103  QgsCodeEditorColorScheme solarizedDark( QStringLiteral( "solarized_dark" ), QObject::tr( "Solarized (Dark)" ) );
104  solarizedDark.setColors(
105  {
106  {QgsCodeEditorColorScheme::ColorRole::Default, QColor( "#839496" ) },
107  {QgsCodeEditorColorScheme::ColorRole::Keyword, QColor( "#859900" ) },
108  {QgsCodeEditorColorScheme::ColorRole::Class, QColor( "#268BD2" ) },
109  {QgsCodeEditorColorScheme::ColorRole::Method, QColor( "#268BD2" ) },
110  {QgsCodeEditorColorScheme::ColorRole::Decoration, QColor( "#94558D" ) },
111  {QgsCodeEditorColorScheme::ColorRole::Number, QColor( "#2AA198" ) },
112  {QgsCodeEditorColorScheme::ColorRole::Comment, QColor( "#2AA198" ) },
113  {QgsCodeEditorColorScheme::ColorRole::CommentLine, QColor( "#2AA198" ) },
115  {QgsCodeEditorColorScheme::ColorRole::Background, QColor( "#002B36" ) },
116  {QgsCodeEditorColorScheme::ColorRole::Cursor, QColor( "#DC322F" ) },
117  {QgsCodeEditorColorScheme::ColorRole::CaretLine, QColor( "#073642" ) },
118  {QgsCodeEditorColorScheme::ColorRole::Operator, QColor( "#839496" ) },
120  {QgsCodeEditorColorScheme::ColorRole::Identifier, QColor( "#839496" ) },
122  {QgsCodeEditorColorScheme::ColorRole::Tag, QColor( "#268BD2" ) },
123  {QgsCodeEditorColorScheme::ColorRole::UnknownTag, QColor( "#268BD2" ) },
124  {QgsCodeEditorColorScheme::ColorRole::SingleQuote, QColor( "#3D8080" ) },
125  {QgsCodeEditorColorScheme::ColorRole::DoubleQuote, QColor( "#3D8080" ) },
134  {QgsCodeEditorColorScheme::ColorRole::Edge, QColor( "#586E75" ) },
135  {QgsCodeEditorColorScheme::ColorRole::Fold, QColor( "#073642" ) },
136  {QgsCodeEditorColorScheme::ColorRole::Error, QColor( "#DC322F" ) },
141  } );
142  addColorScheme( solarizedDark );
143 }
144 
146 {
147  if ( mColorSchemes.contains( scheme.id() ) )
148  return false;
149 
150  mColorSchemes.insert( scheme.id(), scheme );
151  return true;
152 }
153 
155 {
156  if ( !mColorSchemes.contains( id ) )
157  return false;
158 
159  mColorSchemes.remove( id );
160  return true;
161 }
162 
164 {
165  return mColorSchemes.keys();
166 }
167 
169 {
170  if ( !mColorSchemes.contains( id ) )
171  return mColorSchemes.value( QStringLiteral( "default" ) );
172 
173  return mColorSchemes.value( id );
174 }
QgsCodeEditorColorScheme::ColorRole::SelectionForeground
@ SelectionForeground
Selection foreground color.
QgsCodeEditorColorScheme::ColorRole::Edge
@ Edge
Edge color.
QgsCodeEditorColorScheme::ColorRole::MarginForeground
@ MarginForeground
Margin foreground color.
QgsCodeEditorColorScheme::ColorRole::CaretLine
@ CaretLine
Caret line color.
QgsCodeEditorColorScheme::ColorRole::Default
@ Default
Default text color.
QgsCodeEditorColorScheme::ColorRole::FoldIconForeground
@ FoldIconForeground
Fold icon foreground color.
QgsCodeEditorColorScheme::ColorRole::CommentLine
@ CommentLine
Line comment color.
QgsCodeEditorColorSchemeRegistry::scheme
QgsCodeEditorColorScheme scheme(const QString &id) const
Returns the color scheme with matching id.
Definition: qgscodeeditorcolorschemeregistry.cpp:168
QgsCodeEditorColorScheme
Defines a color scheme for use in QgsCodeEditor widgets.
Definition: qgscodeeditorcolorscheme.h:31
QgsCodeEditorColorScheme::ColorRole::Operator
@ Operator
Operator color.
QgsCodeEditorColorScheme::ColorRole::Error
@ Error
Error color.
QgsCodeEditorColorSchemeRegistry::QgsCodeEditorColorSchemeRegistry
QgsCodeEditorColorSchemeRegistry()
Constructor for a color scheme registry.
Definition: qgscodeeditorcolorschemeregistry.cpp:19
QgsCodeEditorColorScheme::ColorRole::Tag
@ Tag
Tag color.
QgsCodeEditorColorScheme::ColorRole::UnknownTag
@ UnknownTag
Unknown tag.
QgsCodeEditorColorScheme::ColorRole::SingleQuote
@ SingleQuote
Single quote color.
QgsCodeEditorColorScheme::ColorRole::SelectionBackground
@ SelectionBackground
Selection background color.
QgsCodeEditorColorScheme::ColorRole::DoubleQuote
@ DoubleQuote
Double quote color.
QgsCodeEditorColorScheme::ColorRole::MarginBackground
@ MarginBackground
Margin background color.
QgsCodeEditorColorSchemeRegistry::schemes
QStringList schemes() const
Returns a list of the QgsCodeEditorColorScheme::id() values for all registered color schemes.
Definition: qgscodeeditorcolorschemeregistry.cpp:163
QgsCodeEditorColorScheme::ColorRole::Method
@ Method
Method color.
QgsCodeEditorColorScheme::ColorRole::Comment
@ Comment
Comment color.
QgsCodeEditorColorSchemeRegistry::addColorScheme
bool addColorScheme(const QgsCodeEditorColorScheme &scheme)
Adds a color scheme to the registry.
Definition: qgscodeeditorcolorschemeregistry.cpp:145
QgsCodeEditorColorScheme::id
QString id() const
Returns the ID of the color scheme, which is a unique, non-translated identifier for the scheme.
Definition: qgscodeeditorcolorscheme.h:89
QgsCodeEditorColorScheme::ColorRole::MatchedBraceBackground
@ MatchedBraceBackground
Matched brace background color.
QgsCodeEditorColorScheme::ColorRole::Decoration
@ Decoration
Decoration color.
QgsCodeEditorColorScheme::ColorRole::CommentBlock
@ CommentBlock
Comment block color.
QgsCodeEditorColorScheme::ColorRole::IndentationGuide
@ IndentationGuide
Indentation guide line.
QgsCodeEditorColorSchemeRegistry::removeColorScheme
bool removeColorScheme(const QString &id)
Removes the color scheme with matching id from the registry.
Definition: qgscodeeditorcolorschemeregistry.cpp:154
QgsCodeEditorColorScheme::ColorRole::TripleSingleQuote
@ TripleSingleQuote
Triple single quote color.
QgsCodeEditorColorScheme::ColorRole::Number
@ Number
Number color.
QgsCodeEditorColorScheme::ColorRole::Identifier
@ Identifier
Identifier color.
QgsCodeEditorColorScheme::ColorRole::TripleDoubleQuote
@ TripleDoubleQuote
Triple double quote color.
QgsCodeEditorColorScheme::ColorRole::QuotedOperator
@ QuotedOperator
Quoted operator color.
QgsCodeEditorColorScheme::ColorRole::Cursor
@ Cursor
Cursor color.
QgsCodeEditorColorScheme::ColorRole::Fold
@ Fold
Fold color.
QgsCodeEditorColorScheme::ColorRole::MatchedBraceForeground
@ MatchedBraceForeground
Matched brace foreground color.
QgsCodeEditorColorScheme::ColorRole::QuotedIdentifier
@ QuotedIdentifier
Quoted identifier color.
QgsCodeEditorColorScheme::ColorRole::Class
@ Class
Class color.
QgsCodeEditorColorScheme::setColors
void setColors(const QMap< ColorRole, QColor > &colors)
Sets all colors for the scheme.
Definition: qgscodeeditorcolorscheme.cpp:35
qgscodeeditorcolorschemeregistry.h
QgsCodeEditorColorScheme::ColorRole::Background
@ Background
Background color.
QgsCodeEditorColorScheme::ColorRole::Keyword
@ Keyword
Keyword color.
QgsCodeEditorColorScheme::ColorRole::ErrorBackground
@ ErrorBackground
Error background color.
QgsCodeEditorColorScheme::ColorRole::FoldIconHalo
@ FoldIconHalo
Fold icon halo color.