QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 }
bool addColorScheme(const QgsCodeEditorColorScheme &scheme)
Adds a color scheme to the registry.
bool removeColorScheme(const QString &id)
Removes the color scheme with matching id from the registry.
QgsCodeEditorColorScheme scheme(const QString &id) const
Returns the color scheme with matching id.
QStringList schemes() const
Returns a list of the QgsCodeEditorColorScheme::id() values for all registered color schemes.
QgsCodeEditorColorSchemeRegistry()
Constructor for a color scheme registry.
Defines a color scheme for use in QgsCodeEditor widgets.
@ TripleSingleQuote
Triple single quote color.
@ CommentBlock
Comment block color.
@ QuotedOperator
Quoted operator color.
@ DoubleQuote
Double quote color.
@ QuotedIdentifier
Quoted identifier color.
@ SelectionForeground
Selection foreground color.
@ CommentLine
Line comment color.
@ FoldIconForeground
Fold icon foreground color.
@ MarginForeground
Margin foreground color.
@ ErrorBackground
Error background color.
@ MatchedBraceBackground
Matched brace background color.
@ IndentationGuide
Indentation guide line.
@ SingleQuote
Single quote color.
@ MarginBackground
Margin background color.
@ SelectionBackground
Selection background color.
@ MatchedBraceForeground
Matched brace foreground color.
@ TripleDoubleQuote
Triple double quote color.
@ FoldIconHalo
Fold icon halo color.
QString id() const
Returns the ID of the color scheme, which is a unique, non-translated identifier for the scheme.
void setColors(const QMap< ColorRole, QColor > &colors)
Sets all colors for the scheme.