KTextEditor

matchhighlighter.cpp
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
14using namespace KateVi;
15
16MatchHighlighter::MatchHighlighter(KTextEditor::ViewPrivate *view)
17 : m_view(view)
18{
19 updateMatchHighlightAttrib();
20 m_highlightedMatch = m_view->doc()->newMovingRange(KTextEditor::Range::invalid(), 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(m_view, &KTextEditor::View::configChanged, this, &MatchHighlighter::updateMatchHighlightAttrib);
27}
28
29MatchHighlighter::~MatchHighlighter()
30{
31 delete m_highlightedMatch;
32}
33
34void 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
41void 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);
49 m_highlightMatchAttribute->setDynamicAttribute(KTextEditor::Attribute::ActivateMouseIn, mouseInAttribute);
50 m_highlightMatchAttribute->dynamicAttribute(KTextEditor::Attribute::ActivateMouseIn)->setBackground(matchColour);
51}
A class which provides customized text decorations.
Definition attribute.h:51
@ ActivateMouseIn
Activate attribute on mouse in.
Definition attribute.h:246
virtual void setRange(KTextEditor::Range range)=0
Set the range of this range.
@ DoNotExpand
Don't expand to encapsulate new characters in either direction. This is the default.
An object representing a section of text, from one Cursor to another.
static constexpr Range invalid() noexcept
Returns an invalid range.
void configChanged(KTextEditor::View *view)
This signal is emitted whenever the current view configuration is changed.
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 12 2024 11:53:31 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.