From c8512fa98461a54f3febc076fa1d7f99eae1d593 Mon Sep 17 00:00:00 2001 From: Diadlo Date: Wed, 14 Sep 2016 13:02:59 +0300 Subject: [PATCH 1/2] fix(text): Change idealSize calculation Ideal size of doc can not be used because in the case of using it for boundingRect (which uses 0,0 as the upper-left corner) leads to the clipping right side of RTL languages. Fixed #1887. --- src/chatlog/content/text.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index 41a485f36..7e3e0c851 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -293,7 +293,7 @@ void Text::freeResources() QSizeF Text::idealSize() { if (doc) - return QSizeF(qMin(doc->idealWidth(), width), doc->size().height()); + return doc->size(); return size; } From c3bf4b7085f97424baaffa626edd6560d427672d Mon Sep 17 00:00:00 2001 From: Diadlo Date: Wed, 14 Sep 2016 13:04:49 +0300 Subject: [PATCH 2/2] refactor(text): Add early break --- src/chatlog/content/text.cpp | 46 +++++++++++++++++------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index 7e3e0c851..4da82836c 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -150,33 +150,31 @@ QRectF Text::boundingRect() const void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { - if (doc) + + if (!doc) + return; + + painter->setClipRect(boundingRect()); + + // draw selection + QAbstractTextDocumentLayout::PaintContext ctx; + QAbstractTextDocumentLayout::Selection sel; + + if (hasSelection()) { - painter->setClipRect(boundingRect()); - - // draw selection - QAbstractTextDocumentLayout::PaintContext ctx; - QAbstractTextDocumentLayout::Selection sel; - - if (hasSelection()) - { - sel.cursor = QTextCursor(doc); - sel.cursor.setPosition(getSelectionStart()); - sel.cursor.setPosition(getSelectionEnd(), QTextCursor::KeepAnchor); - } - - const QColor selectionColor = QColor::fromRgbF(0.23, 0.68, 0.91); - sel.format.setBackground(selectionColor.lighter(selectionHasFocus ? 100 : 160)); - sel.format.setForeground(selectionHasFocus ? Qt::white : Qt::black); - ctx.selections.append(sel); - ctx.palette.setColor(QPalette::Text, color); - - // draw text - doc->documentLayout()->draw(painter, ctx); + sel.cursor = QTextCursor(doc); + sel.cursor.setPosition(getSelectionStart()); + sel.cursor.setPosition(getSelectionEnd(), QTextCursor::KeepAnchor); } - Q_UNUSED(option) - Q_UNUSED(widget) + const QColor selectionColor = QColor::fromRgbF(0.23, 0.68, 0.91); + sel.format.setBackground(selectionColor.lighter(selectionHasFocus ? 100 : 160)); + sel.format.setForeground(selectionHasFocus ? Qt::white : Qt::black); + ctx.selections.append(sel); + ctx.palette.setColor(QPalette::Text, color); + + // draw text + doc->documentLayout()->draw(painter, ctx); } void Text::visibilityChanged(bool visible)