From 88550e1210efb92ff4a5dfc22890e63f604a909d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 19 Aug 2021 16:56:53 +0200 Subject: [PATCH] macOS: Clean up code style in [QNSView setMarkedText:] Pick-to: 6.2 Change-Id: I8a901ac81b64e6fc9bd7fe9ea4e3eaa6257118ce Reviewed-by: Volker Hilsheimer --- .../platforms/cocoa/qnsview_complextext.mm | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/plugins/platforms/cocoa/qnsview_complextext.mm b/src/plugins/platforms/cocoa/qnsview_complextext.mm index 040f65250a..f329a32758 100644 --- a/src/plugins/platforms/cocoa/qnsview_complextext.mm +++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm @@ -129,41 +129,41 @@ const bool isAttributedString = [text isKindOfClass:NSAttributedString.class]; QString preeditString = QString::fromNSString(isAttributedString ? [text string] : text); - QList attrs; - attrs< preeditAttributes; + preeditAttributes << QInputMethodEvent::Attribute( + QInputMethodEvent::Cursor, selectedRange.location + selectedRange.length, true); if (isAttributedString) { - int composingLength = preeditString.length(); - int index = 0; // Create attributes for individual sections of preedit text + int index = 0; + int composingLength = preeditString.length(); while (index < composingLength) { NSRange effectiveRange; - NSRange range = NSMakeRange(index, composingLength-index); + NSRange range = NSMakeRange(index, composingLength - index); NSDictionary *attributes = [text attributesAtIndex:index - longestEffectiveRange:&effectiveRange - inRange:range]; - NSNumber *underlineStyle = [attributes objectForKey:NSUnderlineStyleAttributeName]; - if (underlineStyle) { - QColor clr (Qt::black); - NSColor *color = [attributes objectForKey:NSUnderlineColorAttributeName]; - if (color) { - clr = qt_mac_toQColor(color); - } + longestEffectiveRange:&effectiveRange inRange:range]; + + if (NSNumber *underlineStyle = attributes[NSUnderlineStyleAttributeName]) { + QColor underlineColor(Qt::black); + if (NSColor *color = attributes[NSUnderlineColorAttributeName]) + underlineColor = qt_mac_toQColor(color); + QTextCharFormat format; format.setFontUnderline(true); - format.setUnderlineColor(clr); - attrs<window()->focusObject()) { m_composingFocusObject = focusObject; if (queryInputMethod(focusObject)) { - QInputMethodEvent e(preeditString, attrs); - QCoreApplication::sendEvent(focusObject, &e); + QInputMethodEvent event(preeditString, preeditAttributes); + QCoreApplication::sendEvent(focusObject, &event); // prevent handleKeyEvent from sending a key event m_sendKeyEvent = false; }