From ed65261e374e1701b819bb9e3808d6188fc91bc0 Mon Sep 17 00:00:00 2001 From: krepa098 Date: Fri, 9 Jan 2015 15:50:13 +0100 Subject: [PATCH] Text: copy image keys --- src/chatlog/content/text.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index 67dc1e070..0a591b27a 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -27,6 +27,7 @@ #include #include #include +#include Text::Text(const QString& txt, QFont font, bool enableElide, const QString &rwText) : rawText(rwText) @@ -83,7 +84,38 @@ void Text::selectionMouseMove(QPointF scenePos) if(cur >= 0) { cursor.setPosition(cur, QTextCursor::KeepAnchor); - selectedText = cursor.selectedText(); + selectedText.clear(); + + QTextBlock block = cursor.block(); + for(QTextBlock::Iterator itr = block.begin(); itr!=block.end(); ++itr) + { + int pos = itr.fragment().position(); //fragment position -> position of the first character in the fragment + + if(itr.fragment().charFormat().isImageFormat()) + { + QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat(); + QString key = imgFmt.name(); //img key (eg. key::D for :D) + QString rune = key.mid(4); + + if(pos >= cursor.selectionStart() && pos < cursor.selectionEnd()) + { + selectedText += rune; + pos++; + } + } + else + { + text = itr.fragment().text(); + + for(QChar c : text) + { + if(pos >= cursor.selectionStart() && pos < cursor.selectionEnd()) + selectedText += c; + + pos++; + } + } + } } update();