KTextEditor
movingrange.h
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 * 00003 * Copyright (C) 2010 Christoph Cullmann <cullmann@kde.org> 00004 * 00005 * Based on code of the SmartCursor/Range by: 00006 * Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org> 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Library General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Library General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Library General Public License 00019 * along with this library; see the file COPYING.LIB. If not, write to 00020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 * Boston, MA 02110-1301, USA. 00022 */ 00023 00024 #ifndef KDELIBS_KTEXTEDITOR_MOVINGRANGE_H 00025 #define KDELIBS_KTEXTEDITOR_MOVINGRANGE_H 00026 00027 #include <ktexteditor/ktexteditor_export.h> 00028 #include <ktexteditor/attribute.h> 00029 #include <ktexteditor/range.h> 00030 #include <ktexteditor/movingcursor.h> 00031 00032 namespace KTextEditor 00033 { 00034 00035 class Document; 00036 class View; 00037 class MovingRangeFeedback; 00038 00068 class KTEXTEDITOR_EXPORT MovingRange 00069 { 00070 // 00071 // sub types 00072 // 00073 public: 00075 enum InsertBehavior { 00077 DoNotExpand = 0x0, 00079 ExpandLeft = 0x1, 00081 ExpandRight = 0x2 00082 }; 00083 Q_DECLARE_FLAGS(InsertBehaviors, InsertBehavior) 00084 00085 00088 enum EmptyBehavior { 00089 AllowEmpty = 0x0, 00090 InvalidateIfEmpty = 0x1 00091 }; 00092 00093 // 00094 // stuff that needs to be implemented by editor part cusors 00095 // 00096 public: 00101 virtual void setInsertBehaviors (InsertBehaviors insertBehaviors) = 0; 00102 00107 virtual InsertBehaviors insertBehaviors () const = 0; 00108 00113 virtual void setEmptyBehavior (EmptyBehavior emptyBehavior) = 0; 00114 00119 virtual EmptyBehavior emptyBehavior () const = 0; 00120 00125 virtual Document *document () const = 0; 00126 00133 virtual void setRange (const KTextEditor::Range &range) = 0; 00134 00139 virtual const MovingCursor &start () const = 0; 00140 00145 virtual const MovingCursor &end () const = 0; 00146 00152 virtual View *view () const = 0; 00153 00162 virtual void setView (View *view) = 0; 00163 00169 virtual Attribute::Ptr attribute () const = 0; 00170 00178 virtual void setAttribute (Attribute::Ptr attribute) = 0; 00179 00185 virtual bool attributeOnlyForViews () const = 0; 00186 00191 virtual void setAttributeOnlyForViews (bool onlyForViews) = 0; 00192 00198 virtual MovingRangeFeedback *feedback () const = 0; 00199 00207 virtual void setFeedback (MovingRangeFeedback *feedback) = 0; 00208 00223 virtual qreal zDepth () const = 0; 00224 00234 virtual void setZDepth (qreal zDepth) = 0; 00235 00239 virtual ~MovingRange (); 00240 00241 // 00242 // forbidden stuff 00243 // 00244 protected: 00248 MovingRange (); 00249 00250 private: 00254 MovingRange (const MovingRange &); 00255 00259 MovingRange &operator= (const MovingRange &); 00260 00261 // 00262 // convenience API 00263 // 00264 public: 00273 void setRange (const Cursor &start, const Cursor &end); 00274 00279 const Range toRange () const { return Range (start().toCursor(), end().toCursor()); } 00280 00285 operator const Range () const { return Range (start().toCursor(), end().toCursor()); } 00286 00293 inline friend QDebug operator<< (QDebug s, const MovingRange *range) { 00294 if (range) 00295 s << "[" << range->start() << " -> " << range->end() << "]"; 00296 else 00297 s << "(null range)"; 00298 return s.space(); 00299 } 00300 00307 inline friend QDebug operator<< (QDebug s, const MovingRange &range) { 00308 return s << ⦥ 00309 } 00310 00317 inline bool isEmpty() const { 00318 return start() == end(); 00319 } 00320 00321 //BEGIN comparison functions 00335 inline bool contains(const Range& range) const { 00336 return range.start() >= start() && range.end() <= end(); 00337 } 00338 00346 inline bool contains(const Cursor& cursor) const { 00347 return cursor >= start() && cursor < end(); 00348 } 00349 00357 inline bool containsLine(int line) const { 00358 return (line > start().line() || (line == start().line() && !start().column())) && line < end().line(); 00359 } 00360 00368 inline bool containsColumn(int column) const { 00369 return column >= start().column() && column < end().column(); 00370 } 00371 00379 bool overlaps(const Range& range) const; 00380 00388 inline bool overlapsLine(int line) const { 00389 return line >= start().line() && line <= end().line(); 00390 } 00391 00402 inline bool overlapsColumn(int column) const { 00403 return start().column() <= column && end().column() > column; 00404 } 00405 00413 inline bool onSingleLine() const { 00414 return start().line() == end().line(); 00415 } 00416 00417 //END comparison functions 00418 }; 00419 00420 Q_DECLARE_OPERATORS_FOR_FLAGS(MovingRange::InsertBehaviors) 00421 00422 } 00423 00424 #endif 00425 00426 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference