fixed word wrapping
This commit is contained in:
@@ -129,10 +129,12 @@ void TextElement::addToContainer(MessageLayoutContainer &container, MessageEleme
|
|||||||
singletons::ThemeManager &themeManager = singletons::ThemeManager::ThemeManager::getInstance();
|
singletons::ThemeManager &themeManager = singletons::ThemeManager::ThemeManager::getInstance();
|
||||||
|
|
||||||
for (Word &word : this->words) {
|
for (Word &word : this->words) {
|
||||||
auto getTextLayoutElement = [&](QString text, int width) {
|
auto getTextLayoutElement = [&](QString text, int width, bool trailingSpace) {
|
||||||
return new TextLayoutElement(*this, text, QSize(width, metrics.height()),
|
auto e = new TextLayoutElement(*this, text, QSize(width, metrics.height()),
|
||||||
this->color.getColor(themeManager), this->style,
|
this->color.getColor(themeManager), this->style,
|
||||||
container.scale);
|
container.scale);
|
||||||
|
e->setTrailingSpace(trailingSpace);
|
||||||
|
return e;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (word.width == -1) {
|
if (word.width == -1) {
|
||||||
@@ -141,7 +143,8 @@ void TextElement::addToContainer(MessageLayoutContainer &container, MessageEleme
|
|||||||
|
|
||||||
// see if the text fits in the current line
|
// see if the text fits in the current line
|
||||||
if (container.fitsInLine(word.width)) {
|
if (container.fitsInLine(word.width)) {
|
||||||
container.addElementNoLineBreak(getTextLayoutElement(word.text, word.width));
|
container.addElementNoLineBreak(
|
||||||
|
getTextLayoutElement(word.text, word.width, this->hasTrailingSpace()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +153,8 @@ void TextElement::addToContainer(MessageLayoutContainer &container, MessageEleme
|
|||||||
container.breakLine();
|
container.breakLine();
|
||||||
|
|
||||||
if (container.fitsInLine(word.width)) {
|
if (container.fitsInLine(word.width)) {
|
||||||
container.addElementNoLineBreak(getTextLayoutElement(word.text, word.width));
|
container.addElementNoLineBreak(
|
||||||
|
getTextLayoutElement(word.text, word.width, this->hasTrailingSpace()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,22 +167,29 @@ void TextElement::addToContainer(MessageLayoutContainer &container, MessageEleme
|
|||||||
int lastWidth = 0;
|
int lastWidth = 0;
|
||||||
|
|
||||||
for (int i = 1; i < textLength; i++) {
|
for (int i = 1; i < textLength; i++) {
|
||||||
int chatWidth = metrics.width(text[i]);
|
int charWidth = metrics.width(text[i]);
|
||||||
|
|
||||||
if (!container.fitsInLine(width + chatWidth)) {
|
if (!container.fitsInLine(width + charWidth)) {
|
||||||
container.addElementNoLineBreak(
|
container.addElementNoLineBreak(getTextLayoutElement(
|
||||||
getTextLayoutElement(text.mid(wordStart, i - wordStart), width - lastWidth));
|
text.mid(wordStart, i - wordStart), width - lastWidth, false));
|
||||||
container.breakLine();
|
container.breakLine();
|
||||||
|
|
||||||
i += 2;
|
|
||||||
wordStart = i;
|
wordStart = i;
|
||||||
lastWidth = width;
|
lastWidth = width;
|
||||||
width += chatWidth;
|
width = 0;
|
||||||
|
if (textLength > i + 2) {
|
||||||
|
width += metrics.width(text[i]);
|
||||||
|
width += metrics.width(text[i + 1]);
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
width += charWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
container.addElement(getTextLayoutElement(text.mid(wordStart), word.width - lastWidth));
|
container.addElement(getTextLayoutElement(text.mid(wordStart), word.width - lastWidth,
|
||||||
|
this->hasTrailingSpace()));
|
||||||
|
container.breakLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user