• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Kate

katearbitraryhighlight.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2003 Hamish Rodda <rodda@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "katearbitraryhighlight.h"
00020 #include "katearbitraryhighlight.moc"
00021 
00022 #include "katesupercursor.h"
00023 #include "katedocument.h"
00024 
00025 #include <kdebug.h>
00026 
00027 #include <qfont.h>
00028 
00029 KateArbitraryHighlightRange::KateArbitraryHighlightRange(KateSuperCursor* start,
00030 KateSuperCursor* end, QObject* parent, const char* name)   :
00031 KateSuperRange(start, end, parent, name) {
00032 }
00033 
00034 KateArbitraryHighlightRange::KateArbitraryHighlightRange(KateDocument* doc, const KateRange& range, QObject* parent, const char* name)
00035   : KateSuperRange(doc, range, parent, name)
00036 {
00037 }
00038 
00039 KateArbitraryHighlightRange::KateArbitraryHighlightRange(KateDocument* doc, const KateTextCursor& start, const KateTextCursor& end, QObject* parent, const char* name)
00040   : KateSuperRange(doc, start, end, parent, name)
00041 {
00042 }
00043 
00044 KateArbitraryHighlightRange::~KateArbitraryHighlightRange()
00045 {
00046 }
00047 
00048 KateArbitraryHighlight::KateArbitraryHighlight(KateDocument* parent, const char* name)
00049   : QObject(parent, name)
00050 {
00051 }
00052 
00053 KateAttribute KateArbitraryHighlightRange::merge(QPtrList<KateSuperRange> ranges)
00054 {
00055   ranges.sort();
00056 
00057   KateAttribute ret;
00058 
00059   if (ranges.first() && ranges.current()->inherits("KateArbitraryHighlightRange"))
00060     ret = *(static_cast<KateArbitraryHighlightRange*>(ranges.current()));
00061 
00062   KateSuperRange* r;
00063   while ((r = ranges.next())) {
00064     if (r->inherits("KateArbitraryHighlightRange")) {
00065       KateArbitraryHighlightRange* hl = static_cast<KateArbitraryHighlightRange*>(r);
00066       ret += *hl;
00067     }
00068   }
00069 
00070   return ret;
00071 }
00072 
00073 void KateArbitraryHighlight::addHighlightToDocument(KateSuperRangeList* list)
00074 {
00075   m_docHLs.append(list);
00076   connect(list, SIGNAL(rangeEliminated(KateSuperRange*)), SLOT(slotRangeEliminated(KateSuperRange*)));
00077   connect(list, SIGNAL(destroyed(QObject*)),SLOT(slotRangeListDeleted(QObject*)));
00078 }
00079 
00080 void KateArbitraryHighlight::addHighlightToView(KateSuperRangeList* list, KateView* view)
00081 {
00082   if (!m_viewHLs[view])
00083     m_viewHLs.insert(view, new QPtrList<KateSuperRangeList>());
00084 
00085   m_viewHLs[view]->append(list);
00086 
00087   connect(list, SIGNAL(rangeEliminated(KateSuperRange*)), SLOT(slotTagRange(KateSuperRange*)));
00088   connect(list, SIGNAL(tagRange(KateSuperRange*)), SLOT(slotTagRange(KateSuperRange*)));
00089   connect(list, SIGNAL(destroyed(QObject*)),SLOT(slotRangeListDeleted(QObject*)));
00090 }
00091 
00092 void KateArbitraryHighlight::slotRangeListDeleted(QObject* obj) {
00093    int id=m_docHLs.findRef(static_cast<KateSuperRangeList*>(obj));
00094    if (id>=0) m_docHLs.take(id);
00095    
00096    for (QMap<KateView*, QPtrList<KateSuperRangeList>* >::Iterator it = m_viewHLs.begin(); it != m_viewHLs.end(); ++it)
00097     for (KateSuperRangeList* l = (*it)->first(); l; l = (*it)->next())
00098       if (l==obj) {
00099         l->take();
00100         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)
00101       }
00102 }
00103 
00104 KateSuperRangeList& KateArbitraryHighlight::rangesIncluding(uint line, KateView* view)
00105 {
00106   // OPTIMISE make return value persistent
00107 
00108   static KateSuperRangeList s_return(false);
00109 
00110   Q_ASSERT(!s_return.autoDelete());
00111   s_return.clear();
00112 
00113   //--- TEMPORARY OPTIMISATION: return the actual range when there are none or one. ---
00114   if (m_docHLs.count() + m_viewHLs.count() == 0)
00115     return s_return;
00116   else if (m_docHLs.count() + m_viewHLs.count() == 1)
00117     if (m_docHLs.count())
00118       return *(m_docHLs.first());
00119     else
00120       if (m_viewHLs.values().first() && m_viewHLs.values().first()->count() == 1)
00121         if (m_viewHLs.keys().first() == view && m_viewHLs.values().first())
00122           return *(m_viewHLs.values().first()->first());
00123   //--- END Temporary optimisation ---
00124 
00125   if (view) {
00126     QPtrList<KateSuperRangeList>* list = m_viewHLs[view];
00127     if (list)
00128       for (KateSuperRangeList* l = list->first(); l; l = list->next())
00129         if (l->count())
00130           s_return.appendList(l->rangesIncluding(line));
00131 
00132   } else {
00133     for (QMap<KateView*, QPtrList<KateSuperRangeList>* >::Iterator it = m_viewHLs.begin(); it != m_viewHLs.end(); ++it)
00134       for (KateSuperRangeList* l = (*it)->first(); l; l = (*it)->next())
00135         if (l->count())
00136           s_return.appendList(l->rangesIncluding(line));
00137   }
00138 
00139   for (KateSuperRangeList* l = m_docHLs.first(); l; l = m_docHLs.next())
00140     if (l->count())
00141       s_return.appendList(l->rangesIncluding(line));
00142 
00143   return s_return;
00144 }
00145 
00146 void KateArbitraryHighlight::slotTagRange(KateSuperRange* range)
00147 {
00148   emit tagLines(viewForRange(range), range);
00149 }
00150 
00151 KateView* KateArbitraryHighlight::viewForRange(KateSuperRange* range)
00152 {
00153   for (QMap<KateView*, QPtrList<KateSuperRangeList>* >::Iterator it = m_viewHLs.begin(); it != m_viewHLs.end(); ++it)
00154     for (KateSuperRangeList* l = (*it)->first(); l; l = (*it)->next())
00155       if (l->contains(range))
00156         return it.key();
00157 
00158   // This must belong to a document-global highlight
00159   return 0L;
00160 }
00161 
00162 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

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

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal