From 7c21b977b85783fc7d3521c936c6ebb1c7571c0e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 29 Aug 2023 16:03:07 +0300 Subject: [PATCH 3/3] Qt6: Fix chatline UTF8 handling See osdn #48557 Signed-off-by: Marko Lindqvist --- client/gui-qt/chatline.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/client/gui-qt/chatline.cpp b/client/gui-qt/chatline.cpp index 7dbdb0535f..3960bf87f5 100644 --- a/client/gui-qt/chatline.cpp +++ b/client/gui-qt/chatline.cpp @@ -34,7 +34,7 @@ // client #include "audio.h" #include "climap.h" -#include "climisc.h" /* for write_chatline_content */ +#include "climisc.h" // For write_chatline_content() #include "connectdlg_common.h" #include "control.h" #include "game.h" @@ -373,12 +373,14 @@ void chatwdg::anchor_clicked(const QUrl &link) QStringList sl; int id; enum text_link_type type; + struct tile *ptile = nullptr; + sl = link.toString().split(","); n = sl.at(0).toInt(); id = sl.at(1).toInt(); type = static_cast(n); - struct tile *ptile = NULL; + switch (type) { case TLT_CITY: { struct city *pcity = game_city_by_number(id); @@ -409,7 +411,7 @@ void chatwdg::anchor_clicked(const QUrl &link) } break; } - if (ptile) { + if (ptile != nullptr) { center_tile_mapcanvas(ptile); link_mark_restore(type, id); } @@ -418,7 +420,7 @@ void chatwdg::anchor_clicked(const QUrl &link) /***********************************************************************//** Adds news string to chatwdg (from chat_listener interface) ***************************************************************************/ -void chatwdg::chat_message_received(const QString& message, +void chatwdg::chat_message_received(const QString &message, const struct text_tag_list *tags) { QColor col = chat_output->palette().color(QPalette::Text); @@ -476,6 +478,7 @@ bool chatwdg::eventFilter(QObject *obj, QEvent *event) event->setAccepted(true); } } + return QObject::eventFilter(obj, event); } @@ -548,7 +551,6 @@ void chatwdg::make_link(struct tile *ptile) chat_line->setFocus(); } - /***********************************************************************//** Applies tags to text ***************************************************************************/ @@ -564,10 +566,10 @@ QString apply_tags(QString str, const struct text_tag_list *tags, QMultiMap mm; QByteArray str_bytes; - if (tags == NULL) { + if (tags == nullptr) { return str; } - str_bytes = str.toLocal8Bit(); + str_bytes = str.toUtf8(); qba = str_bytes.data(); text_tag_list_iterate(tags, ptag) { @@ -623,7 +625,7 @@ QString apply_tags(QString str, const struct text_tag_list *tags, } break; case TTT_LINK: { - struct color *pcolor = NULL; + struct color *pcolor = nullptr; switch (text_tag_link_type(ptag)) { case TLT_CITY: @@ -637,8 +639,8 @@ QString apply_tags(QString str, const struct text_tag_list *tags, break; } - if (!pcolor) { - break; /* Not a valid link type case. */ + if (pcolor == nullptr) { + break; // Not a valid link type case. } color = pcolor->qcolor.name(QColor::HexRgb); str_col = QString("").arg(color); @@ -732,7 +734,7 @@ static bool is_plain_public_message(QString s) } /***********************************************************************//** - Appends the string to the chat output window. The string should be + Appends the string to the chat output window. The string should be inserted on its own line, although it will have no newline. ***************************************************************************/ void qtg_real_output_window_append(const char *astring, -- 2.40.1