mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
commit
d1ec8cc989
@ -337,32 +337,39 @@ QString Text::extractSanitizedText(int from, int to) const
|
|||||||
return "";
|
return "";
|
||||||
|
|
||||||
QString txt;
|
QString txt;
|
||||||
QTextBlock block = doc->firstBlock();
|
|
||||||
|
|
||||||
for (QTextBlock::Iterator itr = block.begin(); itr != block.end(); ++itr) {
|
QTextBlock begin = doc->findBlock(from);
|
||||||
int pos =
|
QTextBlock end = doc->findBlock(to);
|
||||||
itr.fragment()
|
for (QTextBlock block = begin; block != end.next() && block.isValid(); block = block.next()) {
|
||||||
.position(); // fragment position -> position of the first character in the fragment
|
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()) {
|
if (itr.fragment().charFormat().isImageFormat()) {
|
||||||
QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat();
|
QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat();
|
||||||
QString key = imgFmt.name(); // img key (eg. key::D for :D)
|
QString key = imgFmt.name(); // img key (eg. key::D for :D)
|
||||||
QString rune = key.mid(4);
|
QString rune = key.mid(4);
|
||||||
|
|
||||||
if (pos >= from && pos < to) {
|
if (pos >= from && pos < to) {
|
||||||
txt += rune;
|
txt += rune;
|
||||||
++pos;
|
++pos;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (QChar c : itr.fragment().text()) {
|
for (QChar c : itr.fragment().text()) {
|
||||||
if (pos >= from && pos < to)
|
if (pos >= from && pos < to)
|
||||||
txt += c;
|
txt += c;
|
||||||
|
|
||||||
++pos;
|
++pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
txt += '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
txt.chop(1);
|
||||||
|
|
||||||
return txt;
|
return txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user