mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(text): Add early break
This commit is contained in:
parent
c8512fa984
commit
c3bf4b7085
|
@ -150,33 +150,31 @@ QRectF Text::boundingRect() const
|
||||||
|
|
||||||
void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
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());
|
sel.cursor = QTextCursor(doc);
|
||||||
|
sel.cursor.setPosition(getSelectionStart());
|
||||||
// draw selection
|
sel.cursor.setPosition(getSelectionEnd(), QTextCursor::KeepAnchor);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_UNUSED(option)
|
const QColor selectionColor = QColor::fromRgbF(0.23, 0.68, 0.91);
|
||||||
Q_UNUSED(widget)
|
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)
|
void Text::visibilityChanged(bool visible)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user