summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-08-22 12:52:59 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-08-23 17:30:18 +0200
commit86d338383e62189cbf46239c2866d3c59092add4 (patch)
treecfd34010de3cc32507b5145da6f93e08a0528ded /src/plugins/platforms/cocoa
parent7d45f2d0b94e3a6ab5041e7271097c83d3cfed44 (diff)
macOS: Highlight selected part of preedit using platform theme palette
QInputMethodEvent::Selection unfortunately doesn't apply to the preedit text, and QInputMethodEvent::Cursor which does, doesn't support setting a selection. Until we've introduced attributes that allow us to propagate the preedit selection semantically we resort to styling the selection via the TextFormat attribute, so that the preedit selection is visible to the user. This allows us to remove the fallback we had for thick and double underline styles, where we mapped those to the wiggly underline style. This was needed to distinguish the selected cluster when composing CJK, but looked out of place. One disadvantage of faking the selection via text format is that we will not update the selection color on theme change, e.g. when switching from light to dark mode, but this is a minor issue that we can live with until we've introduced a proper QInputMethodEvent attribute for the preedit selection. Pick-to: 6.2 Change-Id: I1c45c310107697962e328a4db908d29d2358f756 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qnsview_complextext.mm22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview_complextext.mm b/src/plugins/platforms/cocoa/qnsview_complextext.mm
index 0d1027d705..987e3548af 100644
--- a/src/plugins/platforms/cocoa/qnsview_complextext.mm
+++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm
@@ -133,6 +133,22 @@
preeditAttributes << QInputMethodEvent::Attribute(
QInputMethodEvent::Cursor, selectedRange.location + selectedRange.length, true);
+
+ // QInputMethodEvent::Selection unfortunately doesn't apply to the
+ // preedit text, and QInputMethodEvent::Cursor which does, doesn't
+ // support setting a selection. Until we've introduced attributes
+ // that allow us to propagate the preedit selection semantically
+ // we resort to styling the selection via the TextFormat attribute,
+ // so that the preedit selection is visible to the user.
+ QTextCharFormat selectionFormat;
+ auto *platformTheme = QGuiApplicationPrivate::platformTheme();
+ auto *systemPalette = platformTheme->palette();
+ selectionFormat.setBackground(systemPalette->color(QPalette::Highlight));
+ preeditAttributes << QInputMethodEvent::Attribute(
+ QInputMethodEvent::TextFormat,
+ selectedRange.location, selectedRange.length,
+ selectionFormat);
+
int index = 0;
int composingLength = preeditString.length();
while (index < composingLength) {
@@ -166,11 +182,7 @@
// 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);
+ // input methods to highlight the selected clause segments.
}
if (NSColor *underlineColor = attributes[NSUnderlineColorAttributeName])
format.setUnderlineColor(qt_mac_toQColor(underlineColor));