diff --git a/thumbnail/textcreator.cpp b/thumbnail/textcreator.cpp --- a/thumbnail/textcreator.cpp +++ b/thumbnail/textcreator.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -140,9 +141,6 @@ } } - QColor bgColor = QColor ( 245, 245, 245 ); // light-grey background - m_pixmap.fill( bgColor ); - QPainter painter( &m_pixmap ); QTextDocument textDocument(text); @@ -167,6 +165,16 @@ const auto highlightingTheme = m_highlightingRepository.defaultTheme(KSyntaxHighlighting::Repository::LightTheme); syntaxHighlighter.setTheme(highlightingTheme); + // apply background color from theme + m_pixmap.fill(highlightingTheme.editorColor(KSyntaxHighlighting::Theme::EditorColorRole::BackgroundColor)); + + if (!syntaxHighlighter.definition().isValid() || + (syntaxHighlighter.definition().includedDefinitions().isEmpty() && syntaxHighlighter.definition().formats().isEmpty())) { + // when no definition is found for the file, force syntax re-highlighting + // KSyntaxHighlighter does not highlight files with invalid definition by default (SyntaxHighlighter::setDefinition) + syntaxHighlighter.rehighlight(); + } + // draw page-in-page, with clipping as needed painter.translate(xborder, yborder); textDocument.drawContents(&painter, QRectF(QPointF(0, 0), canvasSize));