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

Kate

katesmartrange.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2003,2004,2005 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 "katesmartrange.h"
00020 
00021 #include "katedocument.h"
00022 #include "kateview.h"
00023 #include <ktexteditor/attribute.h>
00024 #include "katesmartmanager.h"
00025 #include "katedynamicanimation.h"
00026 
00027 #include <kdebug.h>
00028 
00029 KateSmartRange::KateSmartRange(const KTextEditor::Range& range, KateDocument* doc, KTextEditor::SmartRange* parent, KTextEditor::SmartRange::InsertBehaviors insertBehavior)
00030   : KTextEditor::SmartRange(new KateSmartCursor(range.start(), doc), new KateSmartCursor(range.end(), doc), parent, insertBehavior)
00031 //  , m_feedbackLevel(NoFeedback)
00032   , m_dynamicDoc(0L)
00033   , m_mouseOver(false)
00034   , m_caretOver(false)
00035   , m_isInternal(false)
00036 {
00037 }
00038 
00039 KateSmartRange::KateSmartRange(KateDocument* doc, KTextEditor::SmartRange* parent)
00040   : KTextEditor::SmartRange(new KateSmartCursor(doc), new KateSmartCursor(doc), parent)
00041 //  , m_feedbackLevel(NoFeedback)
00042   , m_dynamicDoc(0L)
00043   , m_mouseOver(false)
00044   , m_caretOver(false)
00045   , m_isInternal(false)
00046 {
00047 }
00048 
00049 KateSmartRange::KateSmartRange( KateSmartCursor * start, KateSmartCursor * end, KTextEditor::SmartRange * parent, KTextEditor::SmartRange::InsertBehaviors insertBehavior )
00050   : KTextEditor::SmartRange(start, end, parent, insertBehavior)
00051 //  , m_feedbackLevel(NoFeedback)
00052   , m_dynamicDoc(0L)
00053   , m_mouseOver(false)
00054   , m_caretOver(false)
00055   , m_isInternal(false)
00056 {
00057 }
00058 
00059 KateSmartRange::~KateSmartRange()
00060 {
00061   foreach (KTextEditor::SmartRangeNotifier* n, notifiers()) {
00062     emit static_cast<KateSmartRangeNotifier*>(n)->rangeDeleted(this);
00063     // FIXME delete the notifier
00064   }
00065 
00066   foreach (KTextEditor::SmartRangeWatcher* w, watchers())
00067     w->rangeDeleted(this);
00068 
00069   if (m_start)
00070     kateDocument()->smartManager()->rangeDeleted(this);
00071 
00072   foreach (KateSmartRangePtr* ptr, m_pointers)
00073     ptr->deleted();
00074 }
00075 
00076 KateDocument * KateSmartRange::kateDocument( ) const
00077 {
00078   return static_cast<KateDocument*>(document());
00079 }
00080 
00081 KateSmartRangeNotifier::KateSmartRangeNotifier(KateSmartRange* owner)
00082   : m_owner(owner)
00083 {
00084 }
00085 
00086 void KateSmartRangeNotifier::connectNotify(const char* signal)
00087 {
00088   if (receivers(signal) == 1)
00089     // which signal has been turned on?
00090     if (QMetaObject::normalizedSignature(SIGNAL(positionChanged(SmartRange*))) == signal)
00091       m_owner->checkFeedback();
00092 }
00093 
00094 void KateSmartRangeNotifier::disconnectNotify(const char* signal)
00095 {
00096   if (receivers(signal) == 0)
00097     // which signal has been turned off?
00098     if (QMetaObject::normalizedSignature(SIGNAL(positionChanged(SmartRange*))) == signal)
00099       m_owner->checkFeedback();
00100 }
00101 
00102 KTextEditor::SmartRangeNotifier* KateSmartRange::createNotifier()
00103 {
00104   return new KateSmartRangeNotifier(this);
00105 }
00106 
00107 void KateSmartRange::shifted( )
00108 {
00109   if (kStart().lastPosition() != kStart() || kEnd().lastPosition() != kEnd()) {
00110     // position changed
00111     foreach (KTextEditor::SmartRangeNotifier* n, notifiers())
00112       emit static_cast<KateSmartRangeNotifier*>(n)->rangePositionChanged(this);
00113     foreach (KTextEditor::SmartRangeWatcher* w, watchers())
00114       w->rangePositionChanged(this);
00115   }
00116 
00117   kStart().resetLastPosition();
00118   kEnd().resetLastPosition();
00119 }
00120 
00121 void KateSmartRange::translated(const KateEditInfo& edit)
00122 {
00123   Q_ASSERT(end() >= edit.start());
00124   if (end() < edit.start()) {
00125     kStart().resetLastPosition();
00126     kEnd().resetLastPosition();
00127     return;
00128   }
00129 
00130   // position changed
00131   if (kStart().lastPosition() != kStart() || kEnd().lastPosition() != kEnd()) {
00132     foreach (KTextEditor::SmartRangeNotifier* n, notifiers())
00133       emit static_cast<KateSmartRangeNotifier*>(n)->rangePositionChanged(this);
00134     foreach (KTextEditor::SmartRangeWatcher* w, watchers())
00135       w->rangePositionChanged(this);
00136   }
00137 
00138   // contents changed
00139   foreach (KTextEditor::SmartRangeNotifier* n, notifiers())
00140     emit static_cast<KateSmartRangeNotifier*>(n)->rangeContentsChanged(this);
00141   foreach (KTextEditor::SmartRangeWatcher* w, watchers())
00142     w->rangeContentsChanged(this);
00143 
00144   if (start() == end() && kStart().lastPosition() != kEnd().lastPosition()) {
00145     // range eliminated
00146     foreach (KTextEditor::SmartRangeNotifier* n, notifiers())
00147       emit static_cast<KateSmartRangeNotifier*>(n)->rangeEliminated(this);
00148     foreach (KTextEditor::SmartRangeWatcher* w, watchers())
00149       w->rangeEliminated(this);
00150   }
00151 
00152   kStart().resetLastPosition();
00153   kEnd().resetLastPosition();
00154 }
00155 
00156 void KateSmartRange::feedbackMostSpecific( KateSmartRange * mostSpecific )
00157 {
00158   // most specific range feedback
00159   foreach (KTextEditor::SmartRangeNotifier* n, notifiers())
00160     emit static_cast<KateSmartRangeNotifier*>(n)->rangeContentsChanged(this, mostSpecific);
00161   foreach (KTextEditor::SmartRangeWatcher* w, watchers())
00162     w->rangeContentsChanged(this, mostSpecific);
00163 }
00164 
00165 void KateSmartRange::feedbackMouseCaretChange(KTextEditor::View* view, bool mouse, bool entered)
00166 {
00167   if (mouse) {
00168     if (entered) {
00169       foreach (KTextEditor::SmartRangeNotifier* n, notifiers())
00170         emit static_cast<KateSmartRangeNotifier*>(n)->mouseEnteredRange(this, view);
00171       foreach (KTextEditor::SmartRangeWatcher* w, watchers())
00172         w->mouseEnteredRange(this, view);
00173 
00174     } else {
00175       foreach (KTextEditor::SmartRangeNotifier* n, notifiers())
00176         emit static_cast<KateSmartRangeNotifier*>(n)->mouseExitedRange(this, view);
00177       foreach (KTextEditor::SmartRangeWatcher* w, watchers())
00178         w->mouseExitedRange(this, view);
00179     }
00180 
00181   } else {
00182     if (entered) {
00183       foreach (KTextEditor::SmartRangeNotifier* n, notifiers())
00184         emit static_cast<KateSmartRangeNotifier*>(n)->caretEnteredRange(this, view);
00185       foreach (KTextEditor::SmartRangeWatcher* w, watchers())
00186         w->caretEnteredRange(this, view);
00187 
00188     } else {
00189       foreach (KTextEditor::SmartRangeNotifier* n, notifiers())
00190         emit static_cast<KateSmartRangeNotifier*>(n)->caretExitedRange(this, view);
00191       foreach (KTextEditor::SmartRangeWatcher* w, watchers())
00192         w->caretExitedRange(this, view);
00193     }
00194   }
00195 }
00196 
00197 void KateSmartRange::setParentRange( SmartRange * r )
00198 {
00199   bool gotParent = false;
00200   bool lostParent = false;
00201   if (!parentRange() && r)
00202     gotParent = true;
00203   else if (parentRange() && !r)
00204     lostParent = true;
00205 
00206   SmartRange::setParentRange(r);
00207 
00208   if (gotParent)
00209     kateDocument()->smartManager()->rangeGotParent(this);
00210   else if (lostParent)
00211     kateDocument()->smartManager()->rangeLostParent(this);
00212 }
00213 
00214 void KateSmartRange::unbindAndDelete( )
00215 {
00216   kateDocument()->smartManager()->rangeDeleted(this);
00217   kStart().unbindFromRange();
00218   kEnd().unbindFromRange();
00219   m_start = 0L;
00220   m_end = 0L;
00221   delete this;
00222 }
00223 
00224 void KateSmartRange::setInternal( )
00225 {
00226   m_isInternal = true;
00227   kStart().setInternal();
00228   kEnd().setInternal();
00229 }
00230 
00231 /*KateDynamicAnimation * KateSmartRange::dynamicForView( const KateView * const view) const
00232 {
00233   foreach (KateDynamicAnimation* anim, m_dynamic)
00234     if (anim->view() == view)
00235       return anim;
00236 
00237   return 0L;
00238 }*/
00239 
00240 void KateSmartRange::addDynamic( KateDynamicAnimation * anim )
00241 {
00242   m_dynamic.append(anim);
00243 }
00244 
00245 void KateSmartRange::removeDynamic( KateDynamicAnimation * anim )
00246 {
00247   m_dynamic.removeAll(anim);
00248 }
00249 
00250 const QList<KateDynamicAnimation*> & KateSmartRange::dynamicAnimations( ) const
00251 {
00252   return m_dynamic;
00253 }
00254 
00255 void KateSmartRange::registerPointer( KateSmartRangePtr * ptr )
00256 {
00257   m_pointers.append(ptr);
00258 }
00259 
00260 void KateSmartRange::deregisterPointer( KateSmartRangePtr * ptr )
00261 {
00262   m_pointers.removeAll(ptr);
00263 }
00264 
00265 void KateSmartRange::checkFeedback()
00266 {
00267   kStart().checkFeedback();
00268   kEnd().checkFeedback();
00269 }
00270 
00271 // kate: space-indent on; indent-width 2; replace-tabs on;
00272 
00273 #include "katesmartrange.moc"

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