1 | /* |
---|---|
2 | SPDX-FileCopyrightText: 2013-2016 Simon St James <kdedevel@etotheipiplusone.com> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #include "matchhighlighter.h" |
8 | |
9 | #include "kateconfig.h" |
10 | #include "katedocument.h" |
11 | #include "katerenderer.h" |
12 | #include "kateview.h" |
13 | |
14 | using namespace KateVi; |
15 | |
16 | MatchHighlighter::MatchHighlighter(KTextEditor::ViewPrivate *view) |
17 | : m_view(view) |
18 | { |
19 | updateMatchHighlightAttrib(); |
20 | m_highlightedMatch = m_view->doc()->newMovingRange(range: KTextEditor::Range::invalid(), insertBehaviors: Kate::TextRange::DoNotExpand); |
21 | m_highlightedMatch->setView(m_view); // Show only in this view. |
22 | m_highlightedMatch->setAttributeOnlyForViews(true); |
23 | // Use z depth defined in moving ranges interface. |
24 | m_highlightedMatch->setZDepth(-10000.0); |
25 | m_highlightedMatch->setAttribute(m_highlightMatchAttribute); |
26 | connect(sender: m_view, signal: &KTextEditor::View::configChanged, context: this, slot: &MatchHighlighter::updateMatchHighlightAttrib); |
27 | } |
28 | |
29 | MatchHighlighter::~MatchHighlighter() |
30 | { |
31 | delete m_highlightedMatch; |
32 | } |
33 | |
34 | void MatchHighlighter::updateMatchHighlight(KTextEditor::Range matchRange) |
35 | { |
36 | // Note that if matchRange is invalid, the highlight will not be shown, so we |
37 | // don't need to check for that explicitly. |
38 | m_highlightedMatch->setRange(matchRange); |
39 | } |
40 | |
41 | void MatchHighlighter::updateMatchHighlightAttrib() |
42 | { |
43 | const QColor &matchColour = m_view->rendererConfig()->searchHighlightColor(); |
44 | if (!m_highlightMatchAttribute) { |
45 | m_highlightMatchAttribute = new KTextEditor::Attribute; |
46 | } |
47 | m_highlightMatchAttribute->setBackground(matchColour); |
48 | KTextEditor::Attribute::Ptr mouseInAttribute(new KTextEditor::Attribute()); |
49 | m_highlightMatchAttribute->setDynamicAttribute(type: KTextEditor::Attribute::ActivateMouseIn, attribute: mouseInAttribute); |
50 | m_highlightMatchAttribute->dynamicAttribute(type: KTextEditor::Attribute::ActivateMouseIn)->setBackground(matchColour); |
51 | } |
52 |