From 6492541df306e20d16e3a64d9df174c99c847945 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 18 Jun 2019 16:08:06 +0200 Subject: Support copy-pasting foreground images within same document When using a texture for foreground color in text and copy-pasting the text inside the same QTextEdit, the formatting would disappear. Fixing this in a general way would require implementing some other carrier format in the mime data than HTML, such as e.g ODF, but it can quite easily be fixed for the case where the data is pasted in the same document, or even different documents as long as they have a reference to the image in the formats. [ChangeLog][QtWidgets][QTextEdit] Added support for copy-pasting foreground brushes with textures within same document. Task-number: QTBUG-75931 Change-Id: I8b39dce289c64eea39e25cb8eb207e2534bcd2eb Reviewed-by: Eirik Aavitsland --- .../widgets/widgets/qtextedit/tst_qtextedit.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp') diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp index 3669935823..81682dc027 100644 --- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp @@ -160,6 +160,7 @@ private slots: void selectionChanged(); #ifndef QT_NO_CLIPBOARD void copyPasteBackgroundImage(); + void copyPasteForegroundImage(); #endif void setText(); void cursorRect(); @@ -1904,6 +1905,36 @@ void tst_QTextEdit::copyPasteBackgroundImage() ba.texture().cacheKey() == bb.texture().cacheKey()); QFile::remove(QLatin1String("foo.png")); } + +void tst_QTextEdit::copyPasteForegroundImage() +{ + ed->clear(); + + QPixmap pix(20, 20); + pix.fill(Qt::blue); + + QTextCharFormat fmt; + { + QBrush textureBrush; + { + textureBrush.setTexture(pix); + } + textureBrush.setStyle(Qt::TexturePattern); + fmt.setForeground(textureBrush); + } + ed->textCursor().insertText("Foobar", fmt); + + ed->moveCursor(QTextCursor::Start); + ed->moveCursor(QTextCursor::End, QTextCursor::KeepAnchor); + + ed->copy(); + ed->clear(); + ed->paste(); + + QBrush brush = ed->textCursor().charFormat().foreground(); + QCOMPARE(brush.style(), Qt::TexturePattern); + QCOMPARE(brush.texture().cacheKey(), pix.cacheKey()); +} #endif void tst_QTextEdit::setText() -- cgit v1.2.3