aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWang Chuan <ouchuanm@outlook.com>2020-06-02 22:35:34 +0800
committerWang Chuan <ouchuanm@outlook.com>2020-06-05 08:25:04 +0800
commitbf8b45e33af960c03c7dccf56e90e76eda1f510e (patch)
tree2b7e624daea3443eb7240abb799180ce9f21d246
parent69126c7bb1eed2afd06fd70d364c8e4e2ba4a21a (diff)
QQuickTextNodeEngine: prevent renderring transparent selection color
It is not necessary to render selection color which is transparent. Pick-to: 5.15 Fixes: QTBUG-83819 Change-Id: I45c086652e194192619aad025121e6064ab37a58 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--src/quick/items/qquicktextnodeengine.cpp4
-rw-r--r--tests/auto/quick/qquicktextedit/data/transparentSelectionColor.qml17
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp27
3 files changed, 46 insertions, 2 deletions
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp
index ccdf2c9fa5..5acd3c9bf6 100644
--- a/src/quick/items/qquicktextnodeengine.cpp
+++ b/src/quick/items/qquicktextnodeengine.cpp
@@ -801,8 +801,8 @@ void QQuickTextNodeEngine::addToSceneGraph(QQuickTextNode *parentNode,
// Then, prepend all selection rectangles to the tree
for (int i = 0; i < m_selectionRects.size(); ++i) {
const QRectF &rect = m_selectionRects.at(i);
-
- parentNode->addRectangleNode(rect, m_selectionColor);
+ if (m_selectionColor.alpha() != 0)
+ parentNode->addRectangleNode(rect, m_selectionColor);
}
// Add decorations for each node to the tree.
diff --git a/tests/auto/quick/qquicktextedit/data/transparentSelectionColor.qml b/tests/auto/quick/qquicktextedit/data/transparentSelectionColor.qml
new file mode 100644
index 0000000000..185d66a1ed
--- /dev/null
+++ b/tests/auto/quick/qquicktextedit/data/transparentSelectionColor.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.10
+
+Rectangle {
+ width: 640
+ height: 480
+ color: "red"
+ TextEdit {
+ id: textEdit
+ anchors.top: parent.top
+ anchors.left: parent.left
+ width: contentWidth
+ height: contentHeight
+ font.pixelSize: 50
+ text: " "
+ selectionColor: "transparent"
+ }
+}
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index 4891bb327c..d0ba99f42d 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -221,6 +221,7 @@ private slots:
void QTBUG_51115_readOnlyResetsSelection();
void keys_shortcutoverride();
+ void transparentSelectionColor();
private:
void simulateKeys(QWindow *window, const QList<Key> &keys);
#if QT_CONFIG(shortcut)
@@ -5835,6 +5836,32 @@ void tst_qquicktextedit::keys_shortcutoverride()
QCOMPARE(root->property("who").value<QString>(), QLatin1String("TextEdit"));
}
+void tst_qquicktextedit::transparentSelectionColor()
+{
+ if ((QGuiApplication::platformName() == QLatin1String("offscreen"))
+ || (QGuiApplication::platformName() == QLatin1String("minimal")))
+ QSKIP("Skipping due to grabToImage not functional on offscreen/minimal platforms");
+
+ QQuickView view;
+ view.setSource(testFileUrl("transparentSelectionColor.qml"));
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ QObject *root = view.rootObject();
+ QVERIFY(root);
+
+ QQuickTextEdit *textEdit = root->findChild<QQuickTextEdit *>();
+ QVERIFY(textEdit);
+ textEdit->selectAll();
+
+ QImage img = view.grabWindow();
+ QCOMPARE(img.isNull(), false);
+
+ QColor color = img.pixelColor(int(textEdit->width() / 2), int(textEdit->height()) / 2);
+ QVERIFY(color.red() > 250);
+ QVERIFY(color.blue() < 10);
+ QVERIFY(color.green() < 10);
+}
+
QTEST_MAIN(tst_qquicktextedit)
#include "tst_qquicktextedit.moc"