From b963888b1c7ff01f0815752c4212808ee8ecf244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 20 Aug 2021 12:59:40 +0200 Subject: [PATCH] macOS: Handle more NSUnderlineStyles during text composition Pick-to: 6.2 Change-Id: I2a6cf612506d19736eab007f687a03f6d6595b62 Reviewed-by: Volker Hilsheimer --- .../platforms/cocoa/qnsview_complextext.mm | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/cocoa/qnsview_complextext.mm b/src/plugins/platforms/cocoa/qnsview_complextext.mm index a22d19d0ed..0d1027d705 100644 --- a/src/plugins/platforms/cocoa/qnsview_complextext.mm +++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm @@ -150,8 +150,28 @@ qCDebug(lcQpaKeys) << "Decorating range" << range << "based on" << attributes; QTextCharFormat format; - if (NSNumber *underlineStyle = attributes[NSUnderlineStyleAttributeName]) - format.setFontUnderline(true); // FIXME: Support all NSUnderlineStyles + if (NSNumber *underlineStyle = attributes[NSUnderlineStyleAttributeName]) { + format.setFontUnderline(true); + NSUnderlineStyle style = underlineStyle.integerValue; + if (style & NSUnderlineStylePatternDot) + format.setUnderlineStyle(QTextCharFormat::DotLine); + else if (style & NSUnderlineStylePatternDash) + format.setUnderlineStyle(QTextCharFormat::DashUnderline); + else if (style & NSUnderlineStylePatternDashDot) + format.setUnderlineStyle(QTextCharFormat::DashDotLine); + if (style & NSUnderlineStylePatternDashDotDot) + format.setUnderlineStyle(QTextCharFormat::DashDotDotLine); + else + format.setUnderlineStyle(QTextCharFormat::SingleUnderline); + + // Unfortunately QTextCharFormat::UnderlineStyle does not distinguish + // between NSUnderlineStyle{Single,Thick,Double}, which is used by CJK + // input methods to highlight the selected clause segments, so we fake + // it using QTextCharFormat::WaveUnderline. + if ((style & NSUnderlineStyleThick) == NSUnderlineStyleThick + || (style & NSUnderlineStyleDouble) == NSUnderlineStyleDouble) + format.setUnderlineStyle(QTextCharFormat::WaveUnderline); + } if (NSColor *underlineColor = attributes[NSUnderlineColorAttributeName]) format.setUnderlineColor(qt_mac_toQColor(underlineColor)); if (NSColor *foregroundColor = attributes[NSForegroundColorAttributeName])