Kate
katearbitraryhighlight.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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;
00101 }
00102 }
00103
00104 KateSuperRangeList& KateArbitraryHighlight::rangesIncluding(uint line, KateView* view)
00105 {
00106
00107
00108 static KateSuperRangeList s_return(false);
00109
00110 Q_ASSERT(!s_return.autoDelete());
00111 s_return.clear();
00112
00113
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
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
00159 return 0L;
00160 }
00161
00162