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

Kate

katerenderrange.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2003-2006 Hamish Rodda <rodda@kde.org>
00003    Copyright (C) 2007 Mirko Stocker <me@misto.ch>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "katerenderrange.h"
00021 
00022 #include <limits.h>
00023 
00024 #include "katesmartrange.h"
00025 #include "katedynamicanimation.h"
00026 
00027 SmartRenderRange::SmartRenderRange(KateSmartRange* range, bool useDynamic, KateView* view)
00028   : m_currentRange(0L)
00029   , m_view(view)
00030   , m_useDynamic(useDynamic)
00031 {
00032   Q_ASSERT(range);
00033   if (range) {
00034     addTo(range);
00035     m_currentPos = range->start();
00036   }
00037 }
00038 
00039 KTextEditor::Cursor SmartRenderRange::nextBoundary() const
00040 {
00041   if (!m_currentRange)
00042     return KTextEditor::Cursor(INT_MAX,INT_MAX);
00043 
00044   KTextEditor::SmartRange* r = m_currentRange->deepestRangeContaining(m_currentPos);
00045   
00046   if(!r) {
00047     if(m_currentPos < m_currentRange->start()) {
00048       return m_currentRange->start();
00049     }
00050     return KTextEditor::Cursor(INT_MAX, INT_MAX);
00051   }
00052   
00053   foreach (KTextEditor::SmartRange* child, r->childRanges()) {
00054     if (child->start() > m_currentPos)
00055       return child->start();
00056   }
00057   return m_currentRange->end();
00058 }
00059 
00060 bool SmartRenderRange::advanceTo(const KTextEditor::Cursor& pos) const
00061 {
00062   m_currentPos = pos;
00063 
00064   if (!m_currentRange)
00065     return false;
00066 
00067   bool ret = false;
00068 
00069   while (m_currentRange && !m_currentRange->contains(pos) && m_currentRange->parentRange()) {
00070     m_attribs.pop();
00071     m_currentRange = m_currentRange->parentRange();
00072     ret = true;
00073   }
00074 
00075   if (!m_currentRange)
00076     return ret;
00077 
00078   KTextEditor::SmartRange* r = m_currentRange->deepestRangeContaining(pos);
00079   if (r != m_currentRange)
00080     ret = true;
00081 
00082   if (r)
00083     addTo(r);
00084 
00085   return ret;
00086 }
00087 
00088 KTextEditor::Attribute::Ptr SmartRenderRange::currentAttribute() const
00089 {
00090   if (m_attribs.count() && m_currentRange->contains(m_currentPos))
00091     return m_attribs.top();
00092   return KTextEditor::Attribute::Ptr();
00093 }
00094 
00095 void SmartRenderRange::addTo(KTextEditor::SmartRange* range) const
00096 {
00097   KTextEditor::SmartRange* r = range;
00098   QStack<KTextEditor::SmartRange*> reverseStack;
00099   while (r != m_currentRange) {
00100     reverseStack.push(r);
00101     r = r->parentRange();
00102   }
00103 
00104   while (reverseStack.count()) {
00105     KTextEditor::Attribute::Ptr a(new KTextEditor::Attribute());
00106     if (!m_attribs.isEmpty())
00107       *a = *m_attribs.top();
00108 
00109     KateSmartRange* r2 = static_cast<KateSmartRange*>(reverseStack.pop());
00110     if (KTextEditor::Attribute::Ptr a2 = r2->attribute())
00111       *a += *a2;
00112 
00113     if (m_useDynamic && r2->hasDynamic())
00114       foreach (KateDynamicAnimation* anim, r2->dynamicAnimations())
00115         anim->mergeToAttribute(a);
00116 
00117     m_attribs.push(a);
00118   }
00119 
00120   m_currentRange = range;
00121 }
00122 
00123 NormalRenderRange::NormalRenderRange()
00124   : m_currentRange(0)
00125 {
00126 }
00127 
00128 NormalRenderRange::~NormalRenderRange()
00129 {
00130   QListIterator<pairRA> it = m_ranges;
00131   while (it.hasNext())
00132     delete it.next().first;
00133 }
00134 
00135 void NormalRenderRange::addRange(KTextEditor::Range* range, KTextEditor::Attribute::Ptr attribute)
00136 {
00137   m_ranges.append(pairRA(range, attribute));
00138 }
00139 
00140 KTextEditor::Cursor NormalRenderRange::nextBoundary() const
00141 {
00142   int index = m_currentRange;
00143   while (index < m_ranges.count()) {
00144     if (m_ranges.at(index).first->start() > m_currentPos)
00145       return m_ranges.at(index).first->start();
00146 
00147     else if (m_ranges.at(index).first->end() > m_currentPos)
00148       return m_ranges.at(index).first->end();
00149 
00150     ++index;
00151 
00152   }
00153 
00154   return KTextEditor::Cursor(INT_MAX, INT_MAX);
00155 }
00156 
00157 bool NormalRenderRange::advanceTo(const KTextEditor::Cursor& pos) const
00158 {
00159   m_currentPos = pos;
00160 
00161   int index = m_currentRange;
00162   while (index < m_ranges.count()) {
00163     if (m_ranges.at(index).first->end() <= pos) {
00164       ++index;
00165 
00166     } else {
00167       bool ret = index != m_currentRange;
00168       m_currentRange = index;
00169       return ret;
00170     }
00171   }
00172 
00173   return false;
00174 }
00175 
00176 KTextEditor::Attribute::Ptr NormalRenderRange::currentAttribute() const
00177 {
00178   if (m_currentRange < m_ranges.count() && m_ranges[m_currentRange].first->contains(m_currentPos))
00179     return m_ranges[m_currentRange].second;
00180 
00181   return KTextEditor::Attribute::Ptr();
00182 }
00183 
00184 void RenderRangeList::appendRanges(const QList<KTextEditor::SmartRange*>& startingRanges, bool useDynamic, KateView* view)
00185 {
00186   foreach (KTextEditor::SmartRange* range, startingRanges)
00187     append(new SmartRenderRange(static_cast<KateSmartRange*>(range), useDynamic, view));
00188 }
00189 
00190 KTextEditor::Cursor RenderRangeList::nextBoundary() const
00191 {
00192   KTextEditor::Cursor ret = m_currentPos;
00193   bool first = true;
00194   foreach (KateRenderRange* r, *this) {
00195     if (first) {
00196       ret = r->nextBoundary();
00197       first = false;
00198 
00199     } else {
00200       KTextEditor::Cursor nb = r->nextBoundary();
00201       if (ret > nb)
00202         ret = nb;
00203     }
00204   }
00205   return ret;
00206 }
00207 
00208 bool RenderRangeList::advanceTo(const KTextEditor::Cursor& pos) const
00209 {
00210   bool ret = false;
00211 
00212   foreach (KateRenderRange* r, *this)
00213     ret |= r->advanceTo(pos);
00214 
00215   return ret;
00216 }
00217 
00218 bool RenderRangeList::hasAttribute() const
00219 {
00220   foreach (KateRenderRange* r, *this)
00221     if (r->currentAttribute())
00222       return true;
00223 
00224   return false;
00225 }
00226 
00227 KTextEditor::Attribute RenderRangeList::generateAttribute() const
00228 {
00229   KTextEditor::Attribute a;
00230 
00231   foreach (KateRenderRange* r, *this)
00232     if (KTextEditor::Attribute::Ptr a2 = r->currentAttribute())
00233       a += *a2;
00234 
00235   return a;
00236 }
00237 

Kate

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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