mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Text: copy image keys
This commit is contained in:
parent
d21a00e8d5
commit
ed65261e37
|
@ -27,6 +27,7 @@
|
|||
#include <QApplication>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QDesktopServices>
|
||||
#include <QTextFragment>
|
||||
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user