Bug 406821 - Dark UI color theme breaks default LightTheme
Summary: Dark UI color theme breaks default LightTheme
Status: RESOLVED FIXED
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: theme (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
: 406404 406745 410934 415624 417809 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-04-23 16:32 UTC by Friedrich W. H. Kossebau
Modified: 2021-06-03 09:39 UTC (History)
8 users (show)

See Also:
Latest Commit:
Version Fixed In: 20.04


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Friedrich W. H. Kossebau 2019-04-23 16:32:03 UTC
SUMMARY
When using a dark UI color theme, with the default syntax highligting theme for LightTheme those text regions which would be rendered using "Normal" textstyle appear invisible against bright backgrounds.

STEPS TO REPRODUCE
1. Use Plasma, switch to dark color theme "Breeze Dark"
2. In Dolphin, enable preview of "Text Files" (needs KA 19.04)
3. Navigate to folder with text files, e.g. a dir with C++ sources
4. Enable "Preview" for folder, also trigger tooltips & info docker

OBSERVED RESULT
Rendered text misses out large parts of text to render.

EXPECTED RESULT
All text is properly rendered in some sane colors against the bright background.


Additionally strange is that QColor(highlightingTheme.textColor(KSyntaxHighlighting::Theme::Normal)) is always QColor(ARGB 1, 0.121569, 0.109804, 0.105882). Matching the "text-color" : "#1f1c1b" entry in default.theme.

Is there potentially a chance that instead of applying the "Normal" style for such text regions, that the regions stay unformatted in the QTextDocument, and thus Qt's rendering falls back to UI colors?
Comment 1 Nate Graham 2019-04-24 02:18:51 UTC
*** Bug 406745 has been marked as a duplicate of this bug. ***
Comment 2 Nate Graham 2019-04-24 02:18:55 UTC
*** Bug 406404 has been marked as a duplicate of this bug. ***
Comment 3 Dominik Haumann 2019-05-19 17:09:41 UTC
The issue is that QTextDocument uses the application palette by default.

Indeed, looking at the codeeditor code (https://github.com/KDE/syntax-highlighting/blob/master/examples/codeeditor.cpp#L198), we can see that the widget palette is changed whenever the theme is changed:

void CodeEditor::setTheme(const KSyntaxHighlighting::Theme &theme)
{
    auto pal = qApp->palette();
    if (theme.isValid()) {
        pal.setColor(QPalette::Base, theme.editorColor(KSyntaxHighlighting::Theme::BackgroundColor));
        pal.setColor(QPalette::Text, theme.textColor(KSyntaxHighlighting::Theme::Normal));
        pal.setColor(QPalette::Highlight, theme.editorColor(KSyntaxHighlighting::Theme::TextSelection));
    }
    setPalette(pal);

    m_highlighter->setTheme(theme);
    m_highlighter->rehighlight();
    highlightCurrentLine();
}

This part is missing in thumbnail/textcreator.cpp. One fix is to do the following:

const QPalette appPalette = qApp->palette();
QPalette pal = appPalette;
    if (theme.isValid()) {
        pal.setColor(QPalette::Base, theme.editorColor(KSyntaxHighlighting::Theme::BackgroundColor));
        pal.setColor(QPalette::Text, theme.textColor(KSyntaxHighlighting::Theme::Normal));
        pal.setColor(QPalette::Highlight, theme.editorColor(KSyntaxHighlighting::Theme::TextSelection));
    }
    qApp->setPalette(pal);
    // ... do the painting
    qApp->setPalette(appPalette);

@Friedrich: Can you check whether this works? If this is being run in a separate process, then you can even drop reverting to the old palette.

Another solution would be to change the SyntaxHighlighter implementation in SyntaxHighligher::applyFormat(), see https://github.com/KDE/syntax-highlighting/blob/master/src/lib/syntaxhighlighter.cpp#L159
There, the part "format.isDefaultTextStyle(theme()) || " needs to be removed, this should work as well.
Comment 4 Dominik Haumann 2019-05-19 17:10:39 UTC
For reference: The preview was implemented in https://phabricator.kde.org/D19432.
Comment 5 Dominik Haumann 2019-05-22 20:09:21 UTC
Git commit bbc465981bd55ca5449f5d22e972fccbe994e24f by Dominik Haumann.
Committed on 22/05/2019 at 20:09.
Pushed by dhaumann into branch 'master'.

SyntaxHighlighter: Fix foreground color for text without special highlighting

Summary:
QTextDocument seems to use the widget palette (or application
palette) when drawing text. That is, by default the palette's
foreground color is used when no special QTextCharFormat is
specified.

This patch changes applyFormat() such that the foreground color
is always set to avoid the fallback to the QPalette's foreground
color.
Related: bug 406816
FIXED-IN: 5.59

Test Plan: make && make test + manual testing with the codeeditor example

Reviewers: vkrause, cullmann, kossebau

Reviewed By: cullmann

Subscribers: kwrite-devel, kde-frameworks-devel

Tags: #kate, #frameworks

Differential Revision: https://phabricator.kde.org/D21295

M  +0    -1    examples/codeeditor/codeeditor.cpp
M  +4    -4    src/lib/syntaxhighlighter.cpp

https://commits.kde.org/syntax-highlighting/bbc465981bd55ca5449f5d22e972fccbe994e24f
Comment 6 Ilia Kats 2019-12-11 20:13:12 UTC
Git commit 4ec12a850e258de49d2ed7103f82b468939164c1 by Ilia Kats.
Committed on 11/12/2019 at 20:08.
Pushed by iliakats into branch 'master'.

fix preview of plain text files when using dark theme
Related: bug 409380
Differential Revision: https://phabricator.kde.org/D25891

M  +3    -1    thumbnail/textcreator.cpp

https://commits.kde.org/kio-extras/4ec12a850e258de49d2ed7103f82b468939164c1
Comment 7 Nate Graham 2019-12-27 23:29:44 UTC
*** Bug 415624 has been marked as a duplicate of this bug. ***
Comment 8 Nate Graham 2020-02-18 03:49:34 UTC
*** Bug 417809 has been marked as a duplicate of this bug. ***
Comment 9 Frank 2020-02-18 10:50:22 UTC
Hello,

Regarding the test plan and seeing the VERSION FIXED IN = 20.04, is it fair to say if one upgrades/installs right now Kubuntu 20.04 from daily build this bug would be fixed?

I tested 20.04 daily build 2 days ago and the behavior was not fixed, but I do not know for sure if the updated code was part of that daily build or not.

Thanks
Comment 10 Nate Graham 2020-02-18 15:03:21 UTC
It will be fixed in the 20.04 version of KDE applications, not necessarily the 20.04 release of Kubuntu. IIRC they are planning to ship the 19.04 version of KDE applications.
Comment 11 Nate Graham 2020-02-18 15:03:31 UTC
You could ask them to backport this fix though.
Comment 12 Frank 2020-02-18 15:12:02 UTC
Thanks Nate, that's what I thought after posting, the version is related to KDE not Kubuntu, since this is the KDE bugs site. :)

I thought I have KDE 19.12.2 applications but I must have been looking at the wrong place for the version I run.

I will definately keep an eye on this one, install dev versions of applications if available or ask to backport yes.


Thank you for your precise comment.
Comment 13 maxmustermann1884 2020-02-18 21:21:50 UTC
happy to see this fixed. I guess, this won't enable dark (source colorscheme is hardcoded&binary?) text file previews?
Comment 14 Geekley 2020-10-24 22:38:06 UTC
Still getting this bug on updated Kubuntu 20.04.
Plain text is white on white, while syntax colored text is displayed as normal.

Dolphin 19.12.3
Linux (x86_64) release 5.4.0-52-generic
Qt 5.12.8
KDE Plasma 5.18.5, KDE Frameworks 5.68.0
Plasma Color Scheme: Breeze Dark
Comment 15 Frank 2020-10-24 23:48:16 UTC
You have to upgrade to KDE Applications 20.04 or above. 19.12 will not fix it.

If you upgrade to Kubuntu 20.10 the issue will be fixed as it uses KDE Apps 20.08.
Comment 16 Geekley 2020-10-25 18:45:31 UTC
Thanks! I asked for a backport on launchpad (is that the right place for this? do I need to provide more info?)
https://bugs.launchpad.net/ubuntu/+source/dolphin/+bug/1901431
Comment 17 Geekley 2021-05-26 23:54:15 UTC
(In reply to Frank from comment #15)
> You have to upgrade to KDE Applications 20.04 or above. 19.12 will not fix
> it.
> 
> If you upgrade to Kubuntu 20.10 the issue will be fixed as it uses KDE Apps
> 20.08.

I've just upgraded to Kubuntu 20.10, but the issue persists... :(

$ apt list --installed dolphin*
dolphin/groovy,now 4:20.08.2-0ubuntu1 amd64 [installed,automatic]

$ apt list --installed kde*
kde-cli-tools-data/groovy,groovy,now 4:5.19.5-0ubuntu1 all [installed,automatic]
kde-cli-tools/groovy,now 4:5.19.5-0ubuntu1 amd64 [installed,automatic]
kde-config-gtk-style-preview/groovy,now 4:5.19.5-0ubuntu1 amd64 [installed,automatic]
kde-config-gtk-style/groovy,now 4:5.19.5-0ubuntu1 amd64 [installed,automatic]
kde-config-screenlocker/groovy,now 5.19.5-0ubuntu1 amd64 [installed,automatic]
kde-config-sddm/groovy,now 4:5.19.5-0ubuntu1 amd64 [installed,automatic]
kde-config-tablet/groovy,now 3.2.0-3build1 amd64 [installed,automatic]
kde-config-whoopsie/groovy,now 15.10ubuntu2 amd64 [installed,automatic]
kde-spectacle/groovy,now 20.08.2-0ubuntu1 amd64 [installed,automatic]
kde-style-breeze/groovy,now 4:5.19.5-0ubuntu1 amd64 [installed,automatic]
kde-style-oxygen-qt5/groovy,now 4:5.19.5-0ubuntu1 amd64 [installed,automatic]
kdeconnect/groovy,now 20.08.2-0ubuntu1 amd64 [installed,automatic]
kded5/groovy,now 5.74.0-0ubuntu1 amd64 [installed,automatic]
kdegraphics-thumbnailers/groovy,now 4:20.08.1-0ubuntu1 amd64 [installed,automatic]
kdenetwork-filesharing/groovy,now 4:20.08.1-0ubuntu1 amd64 [installed,automatic]
kdeplasma-addons-data/groovy,groovy,now 4:5.19.5-0ubuntu1 all [installed,automatic]
Comment 18 Frank 2021-05-27 00:35:04 UTC
That's interesting.

I run the following:

KDE Plasma 5.21.5
KDE Framework 5.82.0
QT 5.15.2
Dolphin 21.04.1

I do not have the issue anymore even when I was on older versions of all 4 above.

Maybe there is something specific to Kubuntu?
Or maybe the fix was pushed forward into a newer version that you don't have yet. I am not actually sure which of the above 4 really fixes the issue. :( I would need someone with more expertise to clarify this.
Comment 19 Patrick Silva 2021-06-03 09:39:54 UTC
*** Bug 410934 has been marked as a duplicate of this bug. ***