forked from qt-creator/qt-creator
Fix painting of current line in generic and python editors
The generic highlighter and the python editor explicitly map some tokens to the format C_TEXT. Unfortunately this format is special, because it's foreground and background colors are handled by setting the editor's palette, and should not be used for setting the format on characters. If the format is explicitly set on characters, their background will be oblique and overpaint e.g. the highlight for the current line, which looks pretty ugly. Handle this directly in SyntaxHighlighter::formatForCategory for all syntax highlighters, by returning an empty QTextCharFormat for C_TEXT. Change-Id: Ifaeb556754ca8106ad6e55d7062b13b45457a809 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -23,17 +23,19 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "highlighter.h"
|
|
||||||
#include "highlightdefinition.h"
|
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "rule.h"
|
#include "highlightdefinition.h"
|
||||||
#include "itemdata.h"
|
#include "highlighter.h"
|
||||||
#include "highlighterexception.h"
|
#include "highlighterexception.h"
|
||||||
|
#include "itemdata.h"
|
||||||
#include "progressdata.h"
|
#include "progressdata.h"
|
||||||
#include "reuse.h"
|
#include "reuse.h"
|
||||||
|
#include "rule.h"
|
||||||
#include "tabsettings.h"
|
#include "tabsettings.h"
|
||||||
|
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
|
#include <texteditor/fontsettings.h>
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
@@ -567,7 +569,7 @@ void Highlighter::applyFormat(int offset,
|
|||||||
// think this approach would fit better. If there are other ideas...
|
// think this approach would fit better. If there are other ideas...
|
||||||
QBrush bg = format.background();
|
QBrush bg = format.background();
|
||||||
if (bg.style() == Qt::NoBrush)
|
if (bg.style() == Qt::NoBrush)
|
||||||
bg = formatForCategory(C_TEXT).background();
|
bg = TextEditorSettings::fontSettings().toTextCharFormat(C_TEXT).background();
|
||||||
if (itemData->color().isValid() && isReadableOn(bg.color(), itemData->color()))
|
if (itemData->color().isValid() && isReadableOn(bg.color(), itemData->color()))
|
||||||
format.setForeground(itemData->color());
|
format.setForeground(itemData->color());
|
||||||
if (itemData->isItalicSpecified())
|
if (itemData->isItalicSpecified())
|
||||||
|
@@ -836,8 +836,12 @@ void SyntaxHighlighter::highlightBlock(const QString &text)
|
|||||||
|
|
||||||
void SyntaxHighlighterPrivate::updateFormats(const FontSettings &fontSettings)
|
void SyntaxHighlighterPrivate::updateFormats(const FontSettings &fontSettings)
|
||||||
{
|
{
|
||||||
for (const auto &pair : qAsConst(formatCategories))
|
// C_TEXT is handled by text editor's foreground and background color,
|
||||||
formats[pair.first] = fontSettings.toTextCharFormat(pair.second);
|
// so use empty format for that
|
||||||
|
for (const auto &pair : qAsConst(formatCategories)) {
|
||||||
|
formats[pair.first] = pair.second == C_TEXT ? QTextCharFormat()
|
||||||
|
: fontSettings.toTextCharFormat(pair.second);
|
||||||
|
}
|
||||||
whitespaceFormat = fontSettings.toTextCharFormat(C_VISUAL_WHITESPACE);
|
whitespaceFormat = fontSettings.toTextCharFormat(C_VISUAL_WHITESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
QTC_PLUGIN_DEPENDS += coreplugin
|
QTC_PLUGIN_DEPENDS += coreplugin texteditor
|
||||||
include(../../qttest.pri)
|
include(../../qttest.pri)
|
||||||
QT += gui
|
QT += gui
|
||||||
PLUGINSDIR = $$IDE_SOURCE_TREE/src/plugins
|
PLUGINSDIR = $$IDE_SOURCE_TREE/src/plugins
|
||||||
|
@@ -4,6 +4,7 @@ QtcAutotest {
|
|||||||
name: "Highlighter engine autotest"
|
name: "Highlighter engine autotest"
|
||||||
Depends { name: "Core" }
|
Depends { name: "Core" }
|
||||||
Depends { name: "Utils" }
|
Depends { name: "Utils" }
|
||||||
|
Depends { name: "TextEditor" }
|
||||||
Depends { name: "Qt.widgets" }
|
Depends { name: "Qt.widgets" }
|
||||||
Group {
|
Group {
|
||||||
name: "Sources from TextEditor plugin"
|
name: "Sources from TextEditor plugin"
|
||||||
|
Reference in New Issue
Block a user