From 54d3d066141dfc3ffecb84cf177e80b2878d230b Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
Date: Wed, 2 Dec 2009 13:24:53 +0100
Subject: [PATCH] use new selection type for find scopes, draw shadow in
 overlay (not underlay)

---
 src/plugins/texteditor/basetexteditor.cpp    | 27 +++++++++++++++-----
 src/plugins/texteditor/texteditoroverlay.cpp | 17 ++++++++----
 2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 3f2d1ef9850..55f6a2459f8 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -2092,10 +2092,12 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
     QAbstractTextDocumentLayout::PaintContext context = getPaintContext();
 
     if (!d->m_findScope.isNull()) {
-        QAbstractTextDocumentLayout::Selection selection;
-        selection.format.setBackground(d->m_searchScopeFormat.background());
-        selection.cursor = d->m_findScope;
-        context.selections.prepend(selection);
+
+        TextEditorOverlay *overlay = new TextEditorOverlay(this);
+        overlay->addOverlaySelection(d->m_findScope, d->m_searchScopeFormat.background().color().darker(120),
+                                     d->m_searchScopeFormat.background().color());
+        overlay->paint(&painter, e->rect());
+        delete overlay;
     }
 
     BlockSelectionData *blockSelection = 0;
@@ -2146,6 +2148,7 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
 
     } // end first pass
 
+
     d->m_searchResultOverlay->fill(&painter,
                                    d->m_searchResultFormat.background().color(),
                                    e->rect());
@@ -2978,13 +2981,25 @@ void BaseTextEditor::slotUpdateBlockNotify(const QTextBlock &block)
         /* an overlay might draw outside the block bounderies, force
            complete viewport update */
         viewport()->update();
-    } else if (block.previous().isValid() && block.userState() != block.previous().userState()) {
+    } else {
+        if (block.previous().isValid() && block.userState() != block.previous().userState()) {
         /* The syntax highlighting state changes. This opens up for
            the possibility that the paragraph has braces that support
            code folding. In this case, do the save thing and also
            update the previous block, which might contain a collapse
            box which now is invalid.*/
-        emit requestBlockUpdate(block.previous());
+            emit requestBlockUpdate(block.previous());
+        }
+        if (!d->m_findScope.isNull()) {
+            if (block.position() < d->m_findScope.selectionEnd()
+                && block.position()+block.length() >= d->m_findScope.selectionStart() ) {
+                QTextBlock b = block.document()->findBlock(d->m_findScope.selectionStart());
+                do {
+                    emit requestBlockUpdate(b);
+                    b = b.next();
+                } while (b.isValid() && b.position() < d->m_findScope.selectionEnd());
+            }
+        }
     }
     blockRecursion = false;
 }
diff --git a/src/plugins/texteditor/texteditoroverlay.cpp b/src/plugins/texteditor/texteditoroverlay.cpp
index e2ea55a4cc1..183db1140d2 100644
--- a/src/plugins/texteditor/texteditoroverlay.cpp
+++ b/src/plugins/texteditor/texteditoroverlay.cpp
@@ -308,6 +308,18 @@ void TextEditorOverlay::paintSelection(QPainter *painter,
     }
 
     painter->setRenderHint(QPainter::Antialiasing);
+
+    if (selection.m_dropShadow) {
+        painter->save();
+        painter->translate(m_dropShadowWidth, m_dropShadowWidth);
+
+        QPainterPath clip = path;
+        clip.translate(-m_dropShadowWidth, -m_dropShadowWidth);
+        painter->setClipPath(clip.intersected(path));
+        painter->fillPath(path, QColor(0, 0, 0, 100));
+        painter->restore();
+    }
+
     pen.setJoinStyle(Qt::RoundJoin);
     painter->setPen(pen);
     painter->drawPath(path);
@@ -328,11 +340,6 @@ void TextEditorOverlay::fillSelection(QPainter *painter,
     painter->save();
     painter->translate(-.5, -.5);
     painter->setRenderHint(QPainter::Antialiasing);
-    if (selection.m_dropShadow) {
-        painter->translate(m_dropShadowWidth, m_dropShadowWidth);
-        painter->fillPath(path, QColor(0, 0, 0, 100));
-        painter->translate(-m_dropShadowWidth, -m_dropShadowWidth);
-    }
     painter->fillPath(path, color);
     painter->restore();
 }
-- 
GitLab