Skip to content
Permalink
Browse files

Improve code editor default color scheme to fix dark background issues

(this also backports night mapping code editor color scheme)
  • Loading branch information
nirvn committed Jan 16, 2019
1 parent dafbef1 commit 710d568c402a5bb82cc4990a3a42073a88637833
@@ -0,0 +1,50 @@
[general]
cursorColor=#cfcfcf
caretLineColor=#363636
marginBackgroundColor=#9d9d9d
marginForegroundColor=#000000
selectionBackgroundColor=#d7d7d7
selectionForegroundColor=#000000
matchedBraceColor=#363636
stderrFontColor=#e31a1c
edgeColor=#ff0000
foldColor=#3a3a3a

[python]
paperBackgroundColor=#1f1f1f
defaultFontColor=#f6f3e8
classFontColor=#b3e765
keywordFontColor=#6cbcf7
decoratorFontColor=#6cbcf7
numberFontColor=#ed5d36
methodFontColor=#ed5d36
commentFontColor=#b3e765
commentBlockFontColor=#aeaeae
singleQuoteFontColor=#65b042
doubleQuoteFontColor=#65b042
tripleSingleQuoteFontColor=#65b042
tripleDoubleQuoteFontColor=#65b042

[sql]
paperBackgroundColor=#1f1f1f
defaultFontColor=#f6f3e8
commentFontColor=#b3e765
commentLineFontColor=#aeaeae
numberFontColor=#ed5d36
keywordFontColor=#6cbcf7
singleQuoteFontColor=#65b042
doubleQuoteFontColor=#A0A020
operatorFontColor=#6cbcf7
identifierFontColor=#b3e765
QuotedIdentifierFontColor=#ed5d36
QuotedOperatorFontColor=#ed5d36

[html]
paperBackgroundColor=#1f1f1f
defaultFontColor=#f6f3e8
tagFontColor=#6cbcf7
unknownTagFontColor=#ff2222
numberFontColor=#ed5d36
singleQuoteFontColor=#65b042
doubleQuoteFontColor=#A0A020
commentFontColor=#aeaeae
@@ -14,8 +14,10 @@
* *
***************************************************************************/

#include "qgsapplication.h"
#include "qgscodeeditor.h"
#include "qgssettings.h"
#include "qgssymbollayerutils.h"

#include <QWidget>
#include <QFont>
@@ -90,16 +92,35 @@ void QgsCodeEditor::keyPressEvent( QKeyEvent *event )

void QgsCodeEditor::setSciWidget()
{
QHash< QString, QColor > colors;
if ( QgsApplication::instance()->themeName() != QStringLiteral( "default" ) )
{
QSettings ini( QgsApplication::instance()->uiThemes().value( QgsApplication::instance()->themeName() ) + "/qscintilla.ini", QSettings::IniFormat );
for ( const auto &key : ini.allKeys() )
{
colors.insert( key, QgsSymbolLayerUtils::decodeColor( ini.value( key ).toString() ) );
}
}

setUtf8( true );
setCaretLineVisible( true );
setCaretLineBackgroundColor( QColor( 252, 243, 237 ) );
setCaretLineBackgroundColor( colors.value( QStringLiteral( "caretLineColor" ), QColor( 252, 243, 237 ) ) );
setCaretForegroundColor( colors.value( QStringLiteral( "cursorColor" ), QColor( 51, 51, 51 ) ) );
setSelectionForegroundColor( colors.value( QStringLiteral( "selectionForegroundColorEditor" ), QColor( 48, 48, 48 ) ) );
setSelectionBackgroundColor( colors.value( QStringLiteral( "selectionBackgroundColor" ), QColor( 251, 251, 251 ) ) );

setBraceMatching( QsciScintilla::SloppyBraceMatch );
setMatchedBraceBackgroundColor( QColor( 183, 249, 7 ) );
setMatchedBraceBackgroundColor( colors.value( QStringLiteral( "matchedBraceColor" ), QColor( 183, 249, 7 ) ) );
// whether margin will be shown
setMarginVisible( mMargin );
setMarginsForegroundColor( colors.value( QStringLiteral( "marginForegroundColor" ), QColor( 62, 62, 227 ) ) );
setMarginsBackgroundColor( colors.value( QStringLiteral( "marginBackgroundColor" ), QColor( 249, 249, 249 ) ) );
setIndentationGuidesForegroundColor( colors.value( QStringLiteral( "marginForegroundColor" ), QColor( 62, 62, 227 ) ) );
setIndentationGuidesBackgroundColor( colors.value( QStringLiteral( "marginBackgroundColor" ), QColor( 249, 249, 249 ) ) );
// whether margin will be shown
setFoldingVisible( mFolding );
QColor foldColor = colors.value( QStringLiteral( "foldColor" ), QColor( 244, 244, 244 ) );
setFoldMarginColors( foldColor, foldColor );
// indentation
setAutoIndent( true );
setIndentationWidth( 4 );
@@ -125,8 +146,6 @@ void QgsCodeEditor::setMarginVisible( bool margin )
setMarginLineNumbers( 1, true );
setMarginsFont( marginFont );
setMarginWidth( 1, QStringLiteral( "00000" ) );
setMarginsForegroundColor( QColor( 62, 62, 227 ) );
setMarginsBackgroundColor( QColor( 249, 249, 249 ) );
}
else
{
@@ -142,7 +161,6 @@ void QgsCodeEditor::setFoldingVisible( bool folding )
if ( folding )
{
setFolding( QsciScintilla::PlainFoldStyle );
setFoldMarginColors( QColor( 244, 244, 244 ), QColor( 244, 244, 244 ) );
}
else
{
@@ -15,6 +15,7 @@

#include "qgsapplication.h"
#include "qgscodeeditorexpression.h"
#include "qgssymbollayerutils.h"

#include <QString>
#include <QFont>
@@ -101,18 +102,45 @@ void QgsCodeEditorExpression::setFields( const QgsFields &fields )

void QgsCodeEditorExpression::initializeLexer()
{
QHash< QString, QColor > colors;
if ( QgsApplication::instance()->themeName() != QStringLiteral( "default" ) )
{
QSettings ini( QgsApplication::instance()->uiThemes().value( QgsApplication::instance()->themeName() ) + "/qscintilla.ini", QSettings::IniFormat );
for ( const auto &key : ini.allKeys() )
{
colors.insert( key, QgsSymbolLayerUtils::decodeColor( ini.value( key ).toString() ) );
}
}

QFont font = getMonospaceFont();
#ifdef Q_OS_MAC
// The font size gotten from getMonospaceFont() is too small on Mac
font.setPointSize( QLabel().font().pointSize() );
#endif
QColor defaultColor = colors.value( QStringLiteral( "sql/defaultFontColor" ), Qt::black );

mSqlLexer = new QgsLexerExpression( this );
mSqlLexer->setDefaultFont( font );
mSqlLexer->setDefaultColor( defaultColor );
mSqlLexer->setDefaultPaper( colors.value( QStringLiteral( "sql/paperBackgroundColor" ), Qt::white ) );
mSqlLexer->setFont( font, -1 );
font.setBold( true );
mSqlLexer->setFont( font, QsciLexerSQL::Keyword );

mSqlLexer->setColor( Qt::darkYellow, QsciLexerSQL::DoubleQuotedString ); // fields

mSqlLexer->setColor( defaultColor, QsciLexerSQL::Default );
mSqlLexer->setColor( colors.value( QStringLiteral( "sql/commentFontColor" ), QColor( 142, 144, 140 ) ), QsciLexerSQL::Comment );
mSqlLexer->setColor( colors.value( QStringLiteral( "sql/commentLineFontColor" ), QColor( 142, 144, 140 ) ), QsciLexerSQL::CommentLine );
mSqlLexer->setColor( colors.value( QStringLiteral( "sql/numberFontColor" ), QColor( 200, 40, 41 ) ), QsciLexerSQL::Number );
mSqlLexer->setColor( colors.value( QStringLiteral( "sql/keywordFontColor" ), QColor( 137, 89, 168 ) ), QsciLexerSQL::Keyword );
mSqlLexer->setColor( colors.value( QStringLiteral( "sql/singleQuoteFontColor" ), QColor( 113, 140, 0 ) ), QsciLexerSQL::SingleQuotedString );
mSqlLexer->setColor( colors.value( QStringLiteral( "sql/doubleQuoteFontColor" ), QColor( 234, 183, 0 ) ), QsciLexerSQL::DoubleQuotedString );
mSqlLexer->setColor( colors.value( QStringLiteral( "sql/operatorFontColor" ), QColor( 66, 113, 174 ) ), QsciLexerSQL::Operator );
mSqlLexer->setColor( colors.value( QStringLiteral( "sql/identifierFontColor" ), QColor( 62, 153, 159 ) ), QsciLexerSQL::Identifier );
mSqlLexer->setColor( colors.value( QStringLiteral( "sql/QuotedIdentifierFontColor" ), Qt::black ), QsciLexerSQL::QuotedIdentifier );
mSqlLexer->setColor( colors.value( QStringLiteral( "sql/QuotedOperatorFontColor" ), Qt::black ), QsciLexerSQL::QuotedOperator );

setLexer( mSqlLexer );
}

@@ -15,6 +15,7 @@

#include "qgsapplication.h"
#include "qgscodeeditorhtml.h"
#include "qgssymbollayerutils.h"

#include <QWidget>
#include <QString>
@@ -37,14 +38,36 @@ QgsCodeEditorHTML::QgsCodeEditorHTML( QWidget *parent )

void QgsCodeEditorHTML::setSciLexerHTML()
{
QHash< QString, QColor > colors;
if ( QgsApplication::instance()->themeName() != QStringLiteral( "default" ) )
{
QSettings ini( QgsApplication::instance()->uiThemes().value( QgsApplication::instance()->themeName() ) + "/qscintilla.ini", QSettings::IniFormat );
for ( const auto &key : ini.allKeys() )
{
colors.insert( key, QgsSymbolLayerUtils::decodeColor( ini.value( key ).toString() ) );
}
}

QFont font = getMonospaceFont();
#ifdef Q_OS_MAC
// The font size gotten from getMonospaceFont() is too small on Mac
font.setPointSize( QLabel().font().pointSize() );
#endif
QColor defaultColor = colors.value( QStringLiteral( "html/defaultFontColor" ), Qt::black );

QsciLexerHTML *lexer = new QsciLexerHTML( this );
lexer->setDefaultFont( font );
lexer->setDefaultColor( defaultColor );
lexer->setDefaultPaper( colors.value( QStringLiteral( "html/paperBackgroundColor" ), Qt::white ) );
lexer->setFont( font, -1 );

lexer->setColor( defaultColor, QsciLexerHTML::Default );
lexer->setColor( colors.value( QStringLiteral( "html/tagFontColor" ), QColor( 66, 113, 174 ) ), QsciLexerHTML::Tag );
lexer->setColor( colors.value( QStringLiteral( "html/unknownTagFontColor" ), QColor( 255, 0, 0 ) ), QsciLexerHTML::UnknownTag );
lexer->setColor( colors.value( QStringLiteral( "html/numberFontColor" ), QColor( 200, 40, 41 ) ), QsciLexerHTML::HTMLNumber );
lexer->setColor( colors.value( QStringLiteral( "html/commentFontColor" ), QColor( 142, 144, 140 ) ), QsciLexerHTML::HTMLComment );
lexer->setColor( colors.value( QStringLiteral( "html/singleQuoteFontColor" ), QColor( 113, 140, 0 ) ), QsciLexerHTML::HTMLSingleQuotedString );
lexer->setColor( colors.value( QStringLiteral( "html/doubleQuoteFontColor" ), QColor( 113, 140, 0 ) ), QsciLexerHTML::HTMLDoubleQuotedString );

setLexer( lexer );
}
@@ -16,6 +16,7 @@
#include "qgsapplication.h"
#include "qgscodeeditorpython.h"
#include "qgslogger.h"
#include "qgssymbollayerutils.h"

#include <QWidget>
#include <QString>
@@ -38,23 +39,44 @@ QgsCodeEditorPython::QgsCodeEditorPython( QWidget *parent, const QList<QString>

void QgsCodeEditorPython::setSciLexerPython()
{
QHash< QString, QColor > colors;
if ( QgsApplication::instance()->themeName() != QStringLiteral( "default" ) )
{
QSettings ini( QgsApplication::instance()->uiThemes().value( QgsApplication::instance()->themeName() ) + "/qscintilla.ini", QSettings::IniFormat );
for ( const auto &key : ini.allKeys() )
{
colors.insert( key, QgsSymbolLayerUtils::decodeColor( ini.value( key ).toString() ) );
}
}

// current line
setCaretWidth( 2 );

setEdgeMode( QsciScintilla::EdgeLine );
setEdgeColumn( 80 );
setEdgeColor( QColor( 255, 0, 0 ) );
setEdgeColor( colors.value( QStringLiteral( "edgeColor" ), QColor( 255, 0, 0 ) ) );

setWhitespaceVisibility( QsciScintilla::WsVisibleAfterIndent );

QFont font = getMonospaceFont();
QColor defaultColor = colors.value( QStringLiteral( "python/defaultFontColor" ), Qt::black );

QsciLexerPython *pyLexer = new QsciLexerPython( this );
pyLexer->setDefaultFont( font );
pyLexer->setDefaultColor( defaultColor );
pyLexer->setDefaultPaper( colors.value( QStringLiteral( "python/paperBackgroundColor" ), Qt::white ) );
pyLexer->setFont( font, -1 );
pyLexer->setColor( Qt::red, QsciLexerPython::Comment );
pyLexer->setColor( Qt::darkGreen, QsciLexerPython::Keyword );
pyLexer->setColor( Qt::darkBlue, QsciLexerPython::Decorator );
pyLexer->setColor( defaultColor, QsciLexerPython::Default );
pyLexer->setColor( colors.value( QStringLiteral( "python/classFontColor" ), QColor( 66, 113, 174 ) ), QsciLexerPython::ClassName );
pyLexer->setColor( colors.value( QStringLiteral( "python/numberFontColor" ), QColor( 200, 40, 41 ) ), QsciLexerPython::Number );
pyLexer->setColor( colors.value( QStringLiteral( "python/commentFontColor" ), QColor( 142, 144, 140 ) ), QsciLexerPython::Comment );
pyLexer->setColor( colors.value( QStringLiteral( "python/commentBlockFontColor" ), QColor( 142, 144, 140 ) ), QsciLexerPython::CommentBlock );
pyLexer->setColor( colors.value( QStringLiteral( "python/keywordFontColor" ), QColor( 137, 89, 168 ) ), QsciLexerPython::Keyword );
pyLexer->setColor( colors.value( QStringLiteral( "python/decoratorFontColor" ), QColor( 62, 153, 159 ) ), QsciLexerPython::Decorator );
pyLexer->setColor( colors.value( QStringLiteral( "python/singleQuoteFontColor" ), QColor( 113, 140, 0 ) ), QsciLexerPython::SingleQuotedString );
pyLexer->setColor( colors.value( QStringLiteral( "python/doubleQuoteFontColor" ), QColor( 113, 140, 0 ) ), QsciLexerPython::DoubleQuotedString );
pyLexer->setColor( colors.value( QStringLiteral( "python/tripleSingleQuoteFontColor" ), QColor( 234, 183, 0 ) ), QsciLexerPython::TripleSingleQuotedString );
pyLexer->setColor( colors.value( QStringLiteral( "python/tripleDoubleQuoteFontColor" ), QColor( 234, 183, 0 ) ), QsciLexerPython::TripleDoubleQuotedString );

QsciAPIs *apis = new QsciAPIs( pyLexer );

@@ -15,6 +15,7 @@

#include "qgsapplication.h"
#include "qgscodeeditorsql.h"
#include "qgssymbollayerutils.h"

#include <QWidget>
#include <QString>
@@ -38,17 +39,42 @@ QgsCodeEditorSQL::QgsCodeEditorSQL( QWidget *parent )

void QgsCodeEditorSQL::setSciLexerSQL()
{
QHash< QString, QColor > colors;
if ( QgsApplication::instance()->themeName() != QStringLiteral( "default" ) )
{
QSettings ini( QgsApplication::instance()->uiThemes().value( QgsApplication::instance()->themeName() ) + "/qscintilla.ini", QSettings::IniFormat );
for ( const auto &key : ini.allKeys() )
{
colors.insert( key, QgsSymbolLayerUtils::decodeColor( ini.value( key ).toString() ) );
}
}

QFont font = getMonospaceFont();
#ifdef Q_OS_MAC
// The font size gotten from getMonospaceFont() is too small on Mac
font.setPointSize( QLabel().font().pointSize() );
#endif
QColor defaultColor = colors.value( QStringLiteral( "sql/defaultFontColor" ), Qt::black );

QsciLexerSQL *sqlLexer = new QgsCaseInsensitiveLexerSQL( this );
sqlLexer->setDefaultFont( font );
sqlLexer->setDefaultColor( defaultColor );
sqlLexer->setDefaultPaper( colors.value( QStringLiteral( "sql/paperBackgroundColor" ), Qt::white ) );
sqlLexer->setFont( font, -1 );
font.setBold( true );
sqlLexer->setFont( font, QsciLexerSQL::Keyword );
sqlLexer->setColor( Qt::darkYellow, QsciLexerSQL::DoubleQuotedString ); // fields

sqlLexer->setColor( defaultColor, QsciLexerSQL::Default );
sqlLexer->setColor( colors.value( QStringLiteral( "sql/commentFontColor" ), QColor( 142, 144, 140 ) ), QsciLexerSQL::Comment );
sqlLexer->setColor( colors.value( QStringLiteral( "sql/commentLineFontColor" ), QColor( 142, 144, 140 ) ), QsciLexerSQL::CommentLine );
sqlLexer->setColor( colors.value( QStringLiteral( "sql/numberFontColor" ), QColor( 200, 40, 41 ) ), QsciLexerSQL::Number );
sqlLexer->setColor( colors.value( QStringLiteral( "sql/keywordFontColor" ), QColor( 137, 89, 168 ) ), QsciLexerSQL::Keyword );
sqlLexer->setColor( colors.value( QStringLiteral( "sql/singleQuoteFontColor" ), QColor( 113, 140, 0 ) ), QsciLexerSQL::SingleQuotedString );
sqlLexer->setColor( colors.value( QStringLiteral( "sql/doubleQuoteFontColor" ), QColor( 234, 183, 0 ) ), QsciLexerSQL::DoubleQuotedString );
sqlLexer->setColor( colors.value( QStringLiteral( "sql/operatorFontColor" ), QColor( 66, 113, 174 ) ), QsciLexerSQL::Operator );
sqlLexer->setColor( colors.value( QStringLiteral( "sql/identifierFontColor" ), QColor( 62, 153, 159 ) ), QsciLexerSQL::Identifier );
sqlLexer->setColor( colors.value( QStringLiteral( "sql/QuotedIdentifierFontColor" ), Qt::black ), QsciLexerSQL::QuotedIdentifier );
sqlLexer->setColor( colors.value( QStringLiteral( "sql/QuotedOperatorFontColor" ), Qt::black ), QsciLexerSQL::QuotedOperator );

setLexer( sqlLexer );
}

0 comments on commit 710d568

Please sign in to comment.
You can’t perform that action at this time.