diff --git a/autotests/theme_test.cpp b/autotests/theme_test.cpp --- a/autotests/theme_test.cpp +++ b/autotests/theme_test.cpp @@ -92,27 +92,31 @@ // normal text auto f = collector.formatMap.value(QLatin1String("Normal Text")); QVERIFY(f.isValid()); + QVERIFY(f.textStyle() == Theme::Normal); QVERIFY(f.isDefaultTextStyle(t)); QVERIFY(!f.hasTextColor(t)); QVERIFY(!f.hasBackgroundColor(t)); QVERIFY(f.id() > 0); // visually identical to normal text f = collector.formatMap.value(QLatin1String("Symbol")); QVERIFY(f.isValid()); + QCOMPARE(f.textStyle(), Theme::Operator); QVERIFY(f.isDefaultTextStyle(t)); QVERIFY(!f.hasTextColor(t)); QVERIFY(f.id() > 0); // visually different to normal text f = collector.formatMap.value(QLatin1String("Keywords")); QVERIFY(f.isValid()); + QCOMPARE(f.textStyle(), Theme::Keyword); QVERIFY(!f.isDefaultTextStyle(t)); QVERIFY(f.isBold(t)); QVERIFY(f.id() > 0); f = collector.formatMap.value(QLatin1String("Float")); QVERIFY(f.isValid()); + QCOMPARE(f.textStyle(), Theme::Float); QVERIFY(!f.isDefaultTextStyle(t)); QVERIFY(f.hasTextColor(t)); QVERIFY(f.id() > 0); diff --git a/src/lib/format.h b/src/lib/format.h --- a/src/lib/format.h +++ b/src/lib/format.h @@ -19,19 +19,20 @@ #define KSYNTAXHIGHLIGHTING_FORMAT_H #include "ksyntaxhighlighting_export.h" +#include "theme.h" #include #include + class QColor; class QString; class QXmlStreamReader; namespace KSyntaxHighlighting { class DefinitionRef; class FormatPrivate; -class Theme; /** Describes the format to be used for a specific text fragment. * The actual format used for displaying is merged from the format information @@ -66,6 +67,15 @@ */ quint16 id() const; + /** Returns the underlying TextStyle of this Format. + * Every Theme::TextStyle is visually defined by a Theme. A Format uses one + * of the Theme::TextStyle%s and on top allows modifications such as setting + * a different foreground color etc. + * @see Theme::TextStyle + * @since 5.49 + */ + Theme::TextStyle textStyle() const; + /** Returns @c true if the combination of this format and the theme @p theme * do not change the default text format in any way. * This is useful for output formats where changing formatting implies cost, diff --git a/src/lib/format.cpp b/src/lib/format.cpp --- a/src/lib/format.cpp +++ b/src/lib/format.cpp @@ -20,7 +20,6 @@ #include "definition.h" #include "definitionref_p.h" #include "textstyledata_p.h" -#include "theme.h" #include "themedata_p.h" #include "xml_p.h" @@ -101,6 +100,11 @@ return d->id; } +Theme::TextStyle Format::textStyle() const +{ + return d->defaultStyle; +} + bool Format::isDefaultTextStyle(const Theme &theme) const { return (!hasTextColor(theme))