Blame SOURCES/0037-Update-the-preedit-styling-mapping.patch

93bb3c
From 3ddd4dcb1790920ce2598ebdbe14c95bdba55005 Mon Sep 17 00:00:00 2001
93bb3c
From: Weng Xuetian <wengxt@gmail.com>
93bb3c
Date: Wed, 22 Dec 2021 10:42:38 -0800
93bb3c
Subject: [PATCH 37/40] Update the preedit styling mapping
93bb3c
93bb3c
- None mapping to no style.
93bb3c
- Default/Underline mapping to underline.
93bb3c
- Highlight/Selection mapping to background color/text color with highlight/highlight
93bb3c
text with underline.
93bb3c
- Active/Inactive mapping to bold text with underline.
93bb3c
- Incorrect mapping to red wave underline.
93bb3c
93bb3c
Pick-to: 5.15 6.2 6.3
93bb3c
Change-Id: Iab51d671b8f83aece8596f7f7610de19343fcceb
93bb3c
Reviewed-by: Aleix Pol Gonzalez <aleixpol@kde.org>
93bb3c
(cherry picked from commit f1fb5d9e568a24e213ee41e82a1142cef56f1098)
93bb3c
---
93bb3c
 .../qwaylandinputmethodeventbuilder.cpp       | 31 ++++++++++++-------
93bb3c
 1 file changed, 20 insertions(+), 11 deletions(-)
93bb3c
93bb3c
diff --git a/src/shared/qwaylandinputmethodeventbuilder.cpp b/src/shared/qwaylandinputmethodeventbuilder.cpp
93bb3c
index 458d818e..f50ccf30 100644
93bb3c
--- a/src/shared/qwaylandinputmethodeventbuilder.cpp
93bb3c
+++ b/src/shared/qwaylandinputmethodeventbuilder.cpp
93bb3c
@@ -39,7 +39,10 @@
93bb3c
 
93bb3c
 #include "qwaylandinputmethodeventbuilder_p.h"
93bb3c
 
93bb3c
+#include <QBrush>
93bb3c
+#include <QGuiApplication>
93bb3c
 #include <QInputMethod>
93bb3c
+#include <QPalette>
93bb3c
 #include <QTextCharFormat>
93bb3c
 
93bb3c
 #ifdef QT_BUILD_WAYLANDCOMPOSITOR_LIB
93bb3c
@@ -81,32 +84,38 @@ void QWaylandInputMethodEventBuilder::addPreeditStyling(uint32_t index, uint32_t
93bb3c
     QTextCharFormat format;
93bb3c
 
93bb3c
     switch (style) {
93bb3c
-    case 0:
93bb3c
-    case 1:
93bb3c
+    case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_NONE:
93bb3c
+        break;
93bb3c
+    case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_DEFAULT:
93bb3c
+    case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_UNDERLINE:
93bb3c
         format.setFontUnderline(true);
93bb3c
         format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
93bb3c
         m_preeditStyles.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, index, length, format));
93bb3c
         break;
93bb3c
-    case 2:
93bb3c
-    case 3:
93bb3c
+    case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_ACTIVE:
93bb3c
+    case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_INACTIVE:
93bb3c
         format.setFontWeight(QFont::Bold);
93bb3c
         format.setFontUnderline(true);
93bb3c
         format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
93bb3c
         m_preeditStyles.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, index, length, format));
93bb3c
         break;
93bb3c
-    case 4:
93bb3c
-        format.setFontUnderline(true);
93bb3c
-        format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
93bb3c
-        m_preeditStyles.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, index, length, format));
93bb3c
+    case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_HIGHLIGHT:
93bb3c
+    case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_SELECTION:
93bb3c
+        {
93bb3c
+            format.setFontUnderline(true);
93bb3c
+            format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
93bb3c
+            QPalette palette = qApp->palette();
93bb3c
+            format.setBackground(QBrush(palette.color(QPalette::Active, QPalette::Highlight)));
93bb3c
+            format.setForeground(QBrush(palette.color(QPalette::Active, QPalette::HighlightedText)));
93bb3c
+            m_preeditStyles.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, index, length, format));
93bb3c
+        }
93bb3c
         break;
93bb3c
-    case 5:
93bb3c
+    case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_INCORRECT:
93bb3c
         format.setFontUnderline(true);
93bb3c
         format.setUnderlineStyle(QTextCharFormat::WaveUnderline);
93bb3c
         format.setUnderlineColor(QColor(Qt::red));
93bb3c
         m_preeditStyles.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, index, length, format));
93bb3c
         break;
93bb3c
-//    case QtWayland::wl_text_input::preedit_style_selection:
93bb3c
-//    case QtWayland::wl_text_input::preedit_style_none:
93bb3c
     default:
93bb3c
         break;
93bb3c
     }
93bb3c
-- 
93bb3c
2.35.1
93bb3c