• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • part
katearbitraryhighlight.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2003 Hamish Rodda <rodda@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "katearbitraryhighlight.h"
20 #include "katearbitraryhighlight.moc"
21 
22 #include "katesupercursor.h"
23 #include "katedocument.h"
24 
25 #include <kdebug.h>
26 
27 #include <tqfont.h>
28 
29 KateArbitraryHighlightRange::KateArbitraryHighlightRange(KateSuperCursor* start,
30 KateSuperCursor* end, TQObject* parent, const char* name) :
31 KateSuperRange(start, end, parent, name) {
32 }
33 
34 KateArbitraryHighlightRange::KateArbitraryHighlightRange(KateDocument* doc, const KateRange& range, TQObject* parent, const char* name)
35  : KateSuperRange(doc, range, parent, name)
36 {
37 }
38 
39 KateArbitraryHighlightRange::KateArbitraryHighlightRange(KateDocument* doc, const KateTextCursor& start, const KateTextCursor& end, TQObject* parent, const char* name)
40  : KateSuperRange(doc, start, end, parent, name)
41 {
42 }
43 
44 KateArbitraryHighlightRange::~KateArbitraryHighlightRange()
45 {
46 }
47 
48 KateArbitraryHighlight::KateArbitraryHighlight(KateDocument* parent, const char* name)
49  : TQObject(parent, name)
50 {
51 }
52 
53 KateAttribute KateArbitraryHighlightRange::merge(TQPtrList<KateSuperRange> ranges)
54 {
55  ranges.sort();
56 
57  KateAttribute ret;
58 
59  if (ranges.first() && ranges.current()->inherits("KateArbitraryHighlightRange"))
60  ret = *(static_cast<KateArbitraryHighlightRange*>(ranges.current()));
61 
62  KateSuperRange* r;
63  while ((r = ranges.next())) {
64  if (r->inherits("KateArbitraryHighlightRange")) {
65  KateArbitraryHighlightRange* hl = static_cast<KateArbitraryHighlightRange*>(r);
66  ret += *hl;
67  }
68  }
69 
70  return ret;
71 }
72 
73 void KateArbitraryHighlight::addHighlightToDocument(KateSuperRangeList* list)
74 {
75  m_docHLs.append(list);
76  connect(list, TQT_SIGNAL(rangeEliminated(KateSuperRange*)), TQT_SLOT(slotRangeEliminated(KateSuperRange*)));
77  connect(list, TQT_SIGNAL(destroyed(TQObject*)),TQT_SLOT(slotRangeListDeleted(TQObject*)));
78 }
79 
80 void KateArbitraryHighlight::addHighlightToView(KateSuperRangeList* list, KateView* view)
81 {
82  if (!m_viewHLs[view])
83  m_viewHLs.insert(view, new TQPtrList<KateSuperRangeList>());
84 
85  m_viewHLs[view]->append(list);
86 
87  connect(list, TQT_SIGNAL(rangeEliminated(KateSuperRange*)), TQT_SLOT(slotTagRange(KateSuperRange*)));
88  connect(list, TQT_SIGNAL(tagRange(KateSuperRange*)), TQT_SLOT(slotTagRange(KateSuperRange*)));
89  connect(list, TQT_SIGNAL(destroyed(TQObject*)),TQT_SLOT(slotRangeListDeleted(TQObject*)));
90 }
91 
92 void KateArbitraryHighlight::slotRangeListDeleted(TQObject* obj) {
93  int id=m_docHLs.findRef(static_cast<KateSuperRangeList*>(obj));
94  if (id>=0) m_docHLs.take(id);
95 
96  for (TQMap<KateView*, TQPtrList<KateSuperRangeList>* >::Iterator it = m_viewHLs.begin(); it != m_viewHLs.end(); ++it)
97  for (KateSuperRangeList* l = (*it)->first(); l; l = (*it)->next())
98  if (l==obj) {
99  l->take();
100  break; //should we check if one list is stored more than once for a view ?? I don't think adding the same list 2 or more times is sane, but who knows (jowenn)
101  }
102 }
103 
104 KateSuperRangeList& KateArbitraryHighlight::rangesIncluding(uint line, KateView* view)
105 {
106  // OPTIMISE make return value persistent
107 
108  static KateSuperRangeList s_return(false);
109 
110  Q_ASSERT(!s_return.autoDelete());
111  s_return.clear();
112 
113  //--- TEMPORARY OPTIMISATION: return the actual range when there are none or one. ---
114  if (m_docHLs.count() + m_viewHLs.count() == 0)
115  return s_return;
116  else if (m_docHLs.count() + m_viewHLs.count() == 1)
117  if (m_docHLs.count())
118  return *(m_docHLs.first());
119  else
120  if (m_viewHLs.values().first() && m_viewHLs.values().first()->count() == 1)
121  if (m_viewHLs.keys().first() == view && m_viewHLs.values().first())
122  return *(m_viewHLs.values().first()->first());
123  //--- END Temporary optimisation ---
124 
125  if (view) {
126  TQPtrList<KateSuperRangeList>* list = m_viewHLs[view];
127  if (list)
128  for (KateSuperRangeList* l = list->first(); l; l = list->next())
129  if (l->count())
130  s_return.appendList(l->rangesIncluding(line));
131 
132  } else {
133  for (TQMap<KateView*, TQPtrList<KateSuperRangeList>* >::Iterator it = m_viewHLs.begin(); it != m_viewHLs.end(); ++it)
134  for (KateSuperRangeList* l = (*it)->first(); l; l = (*it)->next())
135  if (l->count())
136  s_return.appendList(l->rangesIncluding(line));
137  }
138 
139  for (KateSuperRangeList* l = m_docHLs.first(); l; l = m_docHLs.next())
140  if (l->count())
141  s_return.appendList(l->rangesIncluding(line));
142 
143  return s_return;
144 }
145 
146 void KateArbitraryHighlight::slotTagRange(KateSuperRange* range)
147 {
148  emit tagLines(viewForRange(range), range);
149 }
150 
151 KateView* KateArbitraryHighlight::viewForRange(KateSuperRange* range)
152 {
153  for (TQMap<KateView*, TQPtrList<KateSuperRangeList>* >::Iterator it = m_viewHLs.begin(); it != m_viewHLs.end(); ++it)
154  for (KateSuperRangeList* l = (*it)->first(); l; l = (*it)->next())
155  if (l->contains(range))
156  return it.key();
157 
158  // This must belong to a document-global highlight
159  return 0L;
160 }
KateTextCursor
Simple cursor class with no document pointer.
Definition: katecursor.h:33
KateAttribute
The Attribute class incorporates all text decorations supported by Kate.
Definition: kateattribute.h:32
KateSuperRange
Represents a range of text, from the start() to the end().
Definition: katesupercursor.h:168
KateSuperCursor
Possible additional features:
Definition: katesupercursor.h:45

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kate

Skip menu "kate"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kate by doxygen 1.8.8
This website is maintained by Timothy Pearson.