|
|
|
@ -150,33 +150,31 @@ QRectF Text::boundingRect() const
@@ -150,33 +150,31 @@ QRectF Text::boundingRect() const
|
|
|
|
|
|
|
|
|
|
void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) |
|
|
|
|
{ |
|
|
|
|
if (doc) |
|
|
|
|
{ |
|
|
|
|
painter->setClipRect(boundingRect()); |
|
|
|
|
|
|
|
|
|
// draw selection
|
|
|
|
|
QAbstractTextDocumentLayout::PaintContext ctx; |
|
|
|
|
QAbstractTextDocumentLayout::Selection sel; |
|
|
|
|
if (!doc) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (hasSelection()) |
|
|
|
|
{ |
|
|
|
|
sel.cursor = QTextCursor(doc); |
|
|
|
|
sel.cursor.setPosition(getSelectionStart()); |
|
|
|
|
sel.cursor.setPosition(getSelectionEnd(), QTextCursor::KeepAnchor); |
|
|
|
|
} |
|
|
|
|
painter->setClipRect(boundingRect()); |
|
|
|
|
|
|
|
|
|
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 selection
|
|
|
|
|
QAbstractTextDocumentLayout::PaintContext ctx; |
|
|
|
|
QAbstractTextDocumentLayout::Selection sel; |
|
|
|
|
|
|
|
|
|
// draw text
|
|
|
|
|
doc->documentLayout()->draw(painter, ctx); |
|
|
|
|
if (hasSelection()) |
|
|
|
|
{ |
|
|
|
|
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) |
|
|
|
|