• Skip to content
  • Skip to link menu
KDE 4.3 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    Copyright (C) 2008 David Nolden <david.nolden.kdevelop@art-master.de>
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 #ifndef KDELIBS_KTEXTEDITOR_SMARTRANGE_H
00021 #define KDELIBS_KTEXTEDITOR_SMARTRANGE_H
00022 
00023 #include <ktexteditor/ktexteditor_export.h>
00024 #include <ktexteditor/range.h>
00025 #include <ktexteditor/smartcursor.h>
00026 #include <ktexteditor/attribute.h>
00027 
00028 #include <QtCore/QList>
00029 
00030 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00031 template <class T> class QStack;
00032 #endif
00033 
00034 class KAction;
00035 
00036 namespace KTextEditor
00037 {
00038 class SmartRangeNotifier;
00039 class SmartRangeWatcher;
00040 
00094 class KTEXTEDITOR_EXPORT SmartRange : public Range
00095 {
00096   friend class SmartCursor;
00097 
00098   public:
00100     enum InsertBehavior {
00102       DoNotExpand = 0,
00104       ExpandLeft = 0x1,
00106       ExpandRight = 0x2
00107     };
00108     Q_DECLARE_FLAGS(InsertBehaviors, InsertBehavior)
00109 
00110     virtual ~SmartRange();
00111 
00115     virtual bool isSmartRange() const;
00116 
00120     virtual SmartRange* toSmartRange() const;
00121 
00134     virtual void setRange(const Range& range);
00135 
00143     inline SmartCursor& smartStart()
00144       { return *static_cast<SmartCursor*>(m_start); }
00145 
00153     inline const SmartCursor& smartStart() const
00154       { return *static_cast<const SmartCursor*>(m_start); }
00155 
00163     inline SmartCursor& smartEnd()
00164       { return *static_cast<SmartCursor*>(m_end); }
00165 
00173     inline const SmartCursor& smartEnd() const
00174       { return *static_cast<const SmartCursor*>(m_end); }
00175 
00180     virtual bool confineToRange(const Range& range);
00181 
00186     virtual bool expandToRange(const Range& range);
00187 
00188     //BEGIN Functionality present from having this range associated with a Document
00203     Document* document() const;
00204 
00211     virtual QStringList text(bool block = false) const;
00212 
00220     virtual bool replaceText(const QStringList &text, bool block = false);
00221 
00229     virtual bool removeText(bool block = false);
00230     //END
00231 
00232     //BEGIN Behavior
00246     InsertBehaviors insertBehavior() const;
00247 
00258     void setInsertBehavior(InsertBehaviors behavior);
00259     //END
00260 
00261     //BEGIN Relationships to other ranges
00277     inline SmartRange* parentRange() const
00278       { return m_parentRange; }
00279 
00294     virtual void setParentRange(SmartRange* r);
00295 
00303     bool hasParent(SmartRange* parent) const;
00304 
00310     inline int depth() const
00311       { return m_parentRange ? m_parentRange->depth() + 1 : 0; }
00312 
00318     inline SmartRange* topParentRange() const
00319       { return parentRange() ? parentRange()->topParentRange() : const_cast<SmartRange*>(this); }
00320 
00328     const QList<SmartRange*>& childRanges() const;
00329 
00336     void clearChildRanges();
00337 
00342     void deleteChildRanges();
00343 
00348     void clearAndDeleteChildRanges();
00349 
00358     SmartRange* childBefore( const SmartRange * range ) const;
00359 
00368     SmartRange* childAfter( const SmartRange * range ) const;
00369 
00381     SmartRange* mostSpecificRange(const Range& input) const;
00382 
00391     SmartRange* firstRangeContaining(const Cursor& pos) const;
00392 
00412     SmartRange* deepestRangeContaining(const Cursor& pos,
00413                                        QStack<SmartRange*>* rangesEntered = 0L,
00414                                        QStack<SmartRange*>* rangesExited = 0L) const;
00415 
00416     QList<SmartRange*> deepestRangesContaining(const Cursor& pos) const;
00417     
00422     int overlapCount() const;
00423     //END
00424 
00425     //BEGIN Arbitrary highlighting
00439     Attribute::Ptr attribute() const;
00440 
00450     void setAttribute(Attribute::Ptr attribute);
00451     //END
00452 
00453     //BEGIN Action binding
00472     void associateAction(KAction* action);
00473 
00480     void dissociateAction(KAction* action);
00481 
00487     const QList<KAction*>& associatedActions() const
00488       { return m_associatedActions; }
00489 
00493     void clearAssociatedActions();
00494     //END
00495 
00496     //BEGIN Notification methods
00514     SmartRangeNotifier* primaryNotifier();
00515 
00520     const QList<SmartRangeNotifier*> notifiers() const;
00521 
00527     void addNotifier(SmartRangeNotifier* notifier);
00528 
00534     void removeNotifier(SmartRangeNotifier* notifier);
00535 
00545     void deletePrimaryNotifier();
00546 
00554     const QList<SmartRangeWatcher*>& watchers() const;
00555 
00563     void addWatcher(SmartRangeWatcher* watcher);
00564 
00570     void removeWatcher(SmartRangeWatcher* watcher);
00572     //END
00573 
00587     inline SmartRange& operator=(const SmartRange& rhs)
00588       { setRange(rhs); return *this; }
00589 
00599     inline SmartRange& operator=(const Range& rhs)
00600       { setRange(rhs); return *this; }
00601 
00602   protected:
00618     SmartRange(SmartCursor* start, SmartCursor* end, SmartRange* parent = 0L, InsertBehaviors insertBehavior = DoNotExpand);
00619 
00628     virtual void rangeChanged(Cursor* cursor, const Range& from);
00629 
00635     virtual void checkFeedback();
00636 
00642     virtual SmartRangeNotifier* createNotifier() = 0;
00643 
00648     void rebuildChildStructure();
00649     
00650   private:
00655     SmartRange(const SmartRange&);
00656 
00661     SmartRange* deepestRangeContainingInternal(const Cursor& pos,
00662                                                QStack<SmartRange*>* rangesEntered,
00663                                                QStack<SmartRange*>* rangesExited,
00664                                                bool first = false) const;
00665 
00671     void insertChildRange(SmartRange* newChild);
00672 
00678     void removeChildRange(SmartRange* newChild);
00679 
00685     Attribute::Ptr m_attribute;
00686 
00687     SmartRange* m_parentRange;
00688 
00694     QList<SmartRange*> m_childRanges;
00695 
00701     QList<KAction*> m_associatedActions;
00702 
00708     QList<SmartRangeNotifier*> m_notifiers;
00709 
00715     QList<SmartRangeWatcher*> m_watchers;
00716 
00722     bool m_ownsAttribute :1;
00729     uchar m_overlapCount:6;
00730 };
00731 
00732 Q_DECLARE_OPERATORS_FOR_FLAGS(SmartRange::InsertBehaviors)
00733 
00734 }
00735 
00736 #endif
00737 
00738 // 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
  • 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