Skip to content
Permalink
Browse files

Fix fold icon colors in code editors -- allow these to be set so that

they can match the editor theme
  • Loading branch information
nyalldawson committed Oct 7, 2020
1 parent 8273483 commit c9fb3620db8676ffa6785d7541b160b4cb90c1a3
@@ -149,6 +149,13 @@ Returns the color to use in the lexer for the specified ``role``.
%Docstring
Returns the font to use in the lexer.

.. versionadded:: 3.16
%End

void runPostLexerConfigurationTasks();
%Docstring
Performs tasks which must be run after a lexer has been set for the widget.

.. versionadded:: 3.16
%End

@@ -54,6 +54,8 @@ Defines a color scheme for use in QgsCodeEditor widgets.
Edge,
Fold,
Error,
FoldIconForeground,
FoldIconHalo,
};

QgsCodeEditorColorScheme( const QString &id = QString(), const QString &name = QString() );
@@ -66,6 +66,8 @@ QgsCodeEditorOptionsWidget::QgsCodeEditorOptionsWidget( QWidget *parent )
{QgsCodeEditorColorScheme::ColorRole::Edge, mColorEdge },
{QgsCodeEditorColorScheme::ColorRole::Fold, mColorFold },
{QgsCodeEditorColorScheme::ColorRole::Error, mColorError },
{QgsCodeEditorColorScheme::ColorRole::FoldIconForeground, mColorFoldIcon },
{QgsCodeEditorColorScheme::ColorRole::FoldIconHalo, mColorFoldIconHalo },
};

for ( auto it = mColorButtonMap.constBegin(); it != mColorButtonMap.constEnd(); ++it )
@@ -61,6 +61,8 @@ QMap< QgsCodeEditorColorScheme::ColorRole, QString > QgsCodeEditor::sColorRoleTo
{QgsCodeEditorColorScheme::ColorRole::Edge, QStringLiteral( "edgeColor" ) },
{QgsCodeEditorColorScheme::ColorRole::Fold, QStringLiteral( "foldColor" ) },
{QgsCodeEditorColorScheme::ColorRole::Error, QStringLiteral( "stderrFontColor" ) },
{QgsCodeEditorColorScheme::ColorRole::FoldIconForeground, QStringLiteral( "foldIconForeground" ) },
{QgsCodeEditorColorScheme::ColorRole::FoldIconHalo, QStringLiteral( "foldIconHalo" ) },
};


@@ -190,6 +192,17 @@ QFont QgsCodeEditor::lexerFont() const
return font;
}

void QgsCodeEditor::runPostLexerConfigurationTasks()
{
setMatchedBraceForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceForeground ) );
setMatchedBraceBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceBackground ) );

SendScintilla( SCI_MARKERSETFORE, SC_MARKNUM_FOLDEROPEN, lexerColor( QgsCodeEditorColorScheme::ColorRole::FoldIconHalo ) );
SendScintilla( SCI_MARKERSETBACK, SC_MARKNUM_FOLDEROPEN, lexerColor( QgsCodeEditorColorScheme::ColorRole::FoldIconForeground ) );
SendScintilla( SCI_MARKERSETFORE, SC_MARKNUM_FOLDER, lexerColor( QgsCodeEditorColorScheme::ColorRole::FoldIconHalo ) );
SendScintilla( SCI_MARKERSETBACK, SC_MARKNUM_FOLDER, lexerColor( QgsCodeEditorColorScheme::ColorRole::FoldIconForeground ) );
}

void QgsCodeEditor::setSciWidget()
{
QFont font = lexerFont();
@@ -336,6 +349,8 @@ QColor QgsCodeEditor::defaultColor( QgsCodeEditorColorScheme::ColorRole role, co
{QgsCodeEditorColorScheme::ColorRole::Edge, QStringLiteral( "edgeColor" ) },
{QgsCodeEditorColorScheme::ColorRole::Fold, QStringLiteral( "foldColor" ) },
{QgsCodeEditorColorScheme::ColorRole::Error, QStringLiteral( "stderrFontColor" ) },
{QgsCodeEditorColorScheme::ColorRole::FoldIconForeground, QStringLiteral( "foldIconForeground" ) },
{QgsCodeEditorColorScheme::ColorRole::FoldIconHalo, QStringLiteral( "foldIconHalo" ) },
};

const QgsCodeEditorColorScheme defaultScheme = QgsGui::codeEditorColorSchemeRegistry()->scheme( QStringLiteral( "default" ) );
@@ -165,6 +165,13 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
*/
QFont lexerFont() const;

/**
* Performs tasks which must be run after a lexer has been set for the widget.
*
* \since QGIS 3.16
*/
void runPostLexerConfigurationTasks();

private:

void setSciWidget();
@@ -67,6 +67,8 @@ class GUI_EXPORT QgsCodeEditorColorScheme
Edge, //!< Edge color
Fold, //!< Fold color
Error, //!< Error color
FoldIconForeground, //!< Fold icon foreground color
FoldIconHalo, //!< Fold icon halo color
};

/**
@@ -52,6 +52,8 @@ QgsCodeEditorColorSchemeRegistry::QgsCodeEditorColorSchemeRegistry()
{QgsCodeEditorColorScheme::ColorRole::Edge, QColor( "#efefef" ) },
{QgsCodeEditorColorScheme::ColorRole::Fold, QColor( "#efefef" ) },
{QgsCodeEditorColorScheme::ColorRole::Error, QColor( "#e31a1c" ) },
{QgsCodeEditorColorScheme::ColorRole::FoldIconForeground, QColor( "#ffffff" ) },
{QgsCodeEditorColorScheme::ColorRole::FoldIconHalo, QColor( "#000000" ) },
} );
addColorScheme( defaultScheme );

@@ -89,6 +91,8 @@ QgsCodeEditorColorSchemeRegistry::QgsCodeEditorColorSchemeRegistry()
{QgsCodeEditorColorScheme::ColorRole::Edge, QColor( "#EEE8D5" ) },
{QgsCodeEditorColorScheme::ColorRole::Fold, QColor( "#EEE8D5" ) },
{QgsCodeEditorColorScheme::ColorRole::Error, QColor( "#DC322F" ) },
{QgsCodeEditorColorScheme::ColorRole::FoldIconForeground, QColor( "#ffffff" ) },
{QgsCodeEditorColorScheme::ColorRole::FoldIconHalo, QColor( "#93a1a1" ) },
} );
addColorScheme( solarizedLight );

@@ -126,6 +130,8 @@ QgsCodeEditorColorSchemeRegistry::QgsCodeEditorColorSchemeRegistry()
{QgsCodeEditorColorScheme::ColorRole::Edge, QColor( "#586E75" ) },
{QgsCodeEditorColorScheme::ColorRole::Fold, QColor( "#073642" ) },
{QgsCodeEditorColorScheme::ColorRole::Error, QColor( "#DC322F" ) },
{QgsCodeEditorColorScheme::ColorRole::FoldIconForeground, QColor( "#586e75" ) },
{QgsCodeEditorColorScheme::ColorRole::FoldIconHalo, QColor( "#839496" ) },
} );
addColorScheme( solarizedDark );
}
@@ -71,8 +71,7 @@ void QgsCodeEditorCSS::initializeLexer()

setLexer( lexer );

setMatchedBraceForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceForeground ) );
setMatchedBraceBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceBackground ) );
runPostLexerConfigurationTasks();
}

//
@@ -131,9 +131,7 @@ void QgsCodeEditorExpression::initializeLexer()
mSqlLexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::QuotedOperator ), QsciLexerSQL::QuotedOperator );

setLexer( mSqlLexer );

setMatchedBraceForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceForeground ) );
setMatchedBraceBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceBackground ) );
runPostLexerConfigurationTasks();
}

void QgsCodeEditorExpression::updateApis()
@@ -69,7 +69,5 @@ void QgsCodeEditorHTML::initializeLexer()
lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QsciLexerHTML::HTMLDoubleQuotedString );

setLexer( lexer );

setMatchedBraceForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceForeground ) );
setMatchedBraceBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceBackground ) );
runPostLexerConfigurationTasks();
}
@@ -61,7 +61,5 @@ void QgsCodeEditorJavascript::initializeLexer()
lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Identifier ), QsciLexerJavaScript::Identifier );

setLexer( lexer );

setMatchedBraceForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceForeground ) );
setMatchedBraceBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceBackground ) );
runPostLexerConfigurationTasks();
}
@@ -175,12 +175,12 @@ void QgsCodeEditorPython::initializeLexer()
setMarginsForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginForeground ) );
setMarginsBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MarginBackground ) );

setMatchedBraceForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceForeground ) );
setMatchedBraceBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceBackground ) );

setFoldingVisible( true );
setIndentationsUseTabs( false );
setIndentationGuides( true );


runPostLexerConfigurationTasks();
}

void QgsCodeEditorPython::autoComplete()
@@ -67,8 +67,7 @@ void QgsCodeEditorSQL::initializeLexer()

setLexer( mSqlLexer );

setMatchedBraceForegroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceForeground ) );
setMatchedBraceBackgroundColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::MatchedBraceBackground ) );
runPostLexerConfigurationTasks();
}

void QgsCodeEditorSQL::setFields( const QgsFields &fields )

0 comments on commit c9fb362

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