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

KTextEditor

smartrange.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2003-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 #ifndef KDELIBS_KTEXTEDITOR_SMARTRANGE_H
00020 #define KDELIBS_KTEXTEDITOR_SMARTRANGE_H
00021 
00022 #include <ktexteditor/ktexteditor_export.h>
00023 #include <ktexteditor/range.h>
00024 #include <ktexteditor/smartcursor.h>
00025 #include <ktexteditor/attribute.h>
00026 
00027 #include <QtCore/QList>
00028 
00029 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00030 template <class T> class QStack;
00031 #endif
00032 
00033 class KAction;
00034 
00035 namespace KTextEditor
00036 {
00037 class SmartRangeNotifier;
00038 class SmartRangeWatcher;
00039 
00081 class KTEXTEDITOR_EXPORT SmartRange : public Range
00082 {
00083   friend class SmartCursor;
00084 
00085   public:
00087     enum InsertBehavior {
00089       DoNotExpand = 0,
00091       ExpandLeft = 0x1,
00093       ExpandRight = 0x2
00094     };
00095     Q_DECLARE_FLAGS(InsertBehaviors, InsertBehavior)
00096 
00097     virtual ~SmartRange();
00098 
00102     virtual bool isSmartRange() const;
00103 
00107     virtual SmartRange* toSmartRange() const;
00108 
00121     virtual void setRange(const Range& range);
00122 
00130     inline SmartCursor& smartStart()
00131       { return *static_cast<SmartCursor*>(m_start); }
00132 
00140     inline const SmartCursor& smartStart() const
00141       { return *static_cast<const SmartCursor*>(m_start); }
00142 
00150     inline SmartCursor& smartEnd()
00151       { return *static_cast<SmartCursor*>(m_end); }
00152 
00160     inline const SmartCursor& smartEnd() const
00161       { return *static_cast<const SmartCursor*>(m_end); }
00162 
00167     virtual bool confineToRange(const Range& range);
00168 
00173     virtual bool expandToRange(const Range& range);
00174 
00175     //BEGIN Functionality present from having this range associated with a Document
00190     Document* document() const;
00191 
00198     virtual QStringList text(bool block = false) const;
00199 
00207     virtual bool replaceText(const QStringList &text, bool block = false);
00208 
00216     virtual bool removeText(bool block = false);
00217     //END
00218 
00219     //BEGIN Behavior
00233     InsertBehaviors insertBehavior() const;
00234 
00245     void setInsertBehavior(InsertBehaviors behavior);
00246     //END
00247 
00248     //BEGIN Relationships to other ranges
00264     inline SmartRange* parentRange() const
00265       { return m_parentRange; }
00266 
00281     virtual void setParentRange(SmartRange* r);
00282 
00290     bool hasParent(SmartRange* parent) const;
00291 
00297     inline int depth() const
00298       { return m_parentRange ? m_parentRange->depth() + 1 : 0; }
00299 
00305     inline SmartRange* topParentRange() const
00306       { return parentRange() ? parentRange()->topParentRange() : const_cast<SmartRange*>(this); }
00307 
00315     const QList<SmartRange*>& childRanges() const;
00316 
00323     void clearChildRanges();
00324 
00329     void deleteChildRanges();
00330 
00335     void clearAndDeleteChildRanges();
00336 
00344     SmartRange* childBefore( const SmartRange * range ) const;
00345 
00353     SmartRange* childAfter( const SmartRange * range ) const;
00354 
00363     SmartRange* mostSpecificRange(const Range& input) const;
00364 
00373     SmartRange* firstRangeContaining(const Cursor& pos) const;
00374 
00391     SmartRange* deepestRangeContaining(const Cursor& pos,
00392                                        QStack<SmartRange*>* rangesEntered = 0L,
00393                                        QStack<SmartRange*>* rangesExited = 0L) const;
00394     //END
00395 
00396     //BEGIN Arbitrary highlighting
00410     Attribute::Ptr attribute() const;
00411 
00418     void setAttribute(Attribute::Ptr attribute);
00419     //END
00420 
00421     //BEGIN Action binding
00440     void associateAction(KAction* action);
00441 
00448     void dissociateAction(KAction* action);
00449 
00455     const QList<KAction*>& associatedActions() const
00456       { return m_associatedActions; }
00457 
00461     void clearAssociatedActions();
00462     //END
00463 
00464     //BEGIN Notification methods
00482     SmartRangeNotifier* primaryNotifier();
00483 
00488     const QList<SmartRangeNotifier*> notifiers() const;
00489 
00495     void addNotifier(SmartRangeNotifier* notifier);
00496 
00502     void removeNotifier(SmartRangeNotifier* notifier);
00503 
00513     void deletePrimaryNotifier();
00514 
00522     const QList<SmartRangeWatcher*>& watchers() const;
00523 
00531     void addWatcher(SmartRangeWatcher* watcher);
00532 
00538     void removeWatcher(SmartRangeWatcher* watcher);
00540     //END
00541 
00555     inline SmartRange& operator=(const SmartRange& rhs)
00556       { setRange(rhs); return *this; }
00557 
00567     inline SmartRange& operator=(const Range& rhs)
00568       { setRange(rhs); return *this; }
00569 
00570   protected:
00585     SmartRange(SmartCursor* start, SmartCursor* end, SmartRange* parent = 0L, InsertBehaviors insertBehavior = DoNotExpand);
00586 
00595     virtual void rangeChanged(Cursor* cursor, const Range& from);
00596 
00602     virtual void checkFeedback();
00603 
00609     virtual SmartRangeNotifier* createNotifier() = 0;
00610 
00611   private:
00616     SmartRange(const SmartRange&);
00617 
00622     SmartRange* deepestRangeContainingInternal(const Cursor& pos,
00623                                                QStack<SmartRange*>* rangesEntered,
00624                                                QStack<SmartRange*>* rangesExited,
00625                                                bool first = false) const;
00626 
00632     void insertChildRange(SmartRange* newChild);
00633 
00639     void removeChildRange(SmartRange* newChild);
00640 
00646     Attribute::Ptr m_attribute;
00647 
00653     SmartRange* m_parentRange;
00654 
00660     QList<SmartRange*> m_childRanges;
00661 
00667     QList<KAction*> m_associatedActions;
00668 
00674     QList<SmartRangeNotifier*> m_notifiers;
00675 
00681     QList<SmartRangeWatcher*> m_watchers;
00682 
00688     bool m_ownsAttribute :1;
00689 };
00690 
00691 Q_DECLARE_OPERATORS_FOR_FLAGS(SmartRange::InsertBehaviors)
00692 
00693 }
00694 
00695 #endif
00696 
00697 // kate: space-indent on; indent-width 2; replace-tabs on;

KTextEditor

Skip menu "KTextEditor"
  • Main Page
  • Modules
  • 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