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