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 00122 class KTEXTEDITOR_EXPORT MovingRange 00123 { 00124 // 00125 // sub types 00126 // 00127 public: 00129 enum InsertBehavior { 00131 DoNotExpand = 0x0, 00133 ExpandLeft = 0x1, 00135 ExpandRight = 0x2 00136 }; 00137 Q_DECLARE_FLAGS(InsertBehaviors, InsertBehavior) 00138 00139 00142 enum EmptyBehavior { 00143 AllowEmpty = 0x0, 00144 InvalidateIfEmpty = 0x1 00145 }; 00146 00147 // 00148 // stuff that needs to be implemented by editor part cursors 00149 // 00150 public: 00155 virtual void setInsertBehaviors (InsertBehaviors insertBehaviors) = 0; 00156 00161 virtual InsertBehaviors insertBehaviors () const = 0; 00162 00167 virtual void setEmptyBehavior (EmptyBehavior emptyBehavior) = 0; 00168 00173 virtual EmptyBehavior emptyBehavior () const = 0; 00174 00179 virtual Document *document () const = 0; 00180 00187 virtual void setRange (const KTextEditor::Range &range) = 0; 00188 00193 virtual const MovingCursor &start () const = 0; 00194 00199 virtual const MovingCursor &end () const = 0; 00200 00206 virtual View *view () const = 0; 00207 00216 virtual void setView (View *view) = 0; 00217 00223 virtual Attribute::Ptr attribute () const = 0; 00224 00232 virtual void setAttribute (Attribute::Ptr attribute) = 0; 00233 00239 virtual bool attributeOnlyForViews () const = 0; 00240 00245 virtual void setAttributeOnlyForViews (bool onlyForViews) = 0; 00246 00252 virtual MovingRangeFeedback *feedback () const = 0; 00253 00261 virtual void setFeedback (MovingRangeFeedback *feedback) = 0; 00262 00277 virtual qreal zDepth () const = 0; 00278 00288 virtual void setZDepth (qreal zDepth) = 0; 00289 00293 virtual ~MovingRange (); 00294 00295 // 00296 // forbidden stuff 00297 // 00298 protected: 00302 MovingRange (); 00303 00304 private: 00308 MovingRange (const MovingRange &); 00309 00313 MovingRange &operator= (const MovingRange &); 00314 00315 // 00316 // convenience API 00317 // 00318 public: 00327 void setRange (const Cursor &start, const Cursor &end); 00328 00333 const Range toRange () const { return Range (start().toCursor(), end().toCursor()); } 00334 00339 operator const Range () const { return Range (start().toCursor(), end().toCursor()); } 00340 00347 inline friend QDebug operator<< (QDebug s, const MovingRange *range) { 00348 if (range) 00349 s << "[" << range->start() << " -> " << range->end() << "]"; 00350 else 00351 s << "(null range)"; 00352 return s.space(); 00353 } 00354 00361 inline friend QDebug operator<< (QDebug s, const MovingRange &range) { 00362 return s << ⦥ 00363 } 00364 00371 inline bool isEmpty() const { 00372 return start() == end(); 00373 } 00374 00375 //BEGIN comparison functions 00389 inline bool contains(const Range& range) const { 00390 return range.start() >= start() && range.end() <= end(); 00391 } 00392 00400 inline bool contains(const Cursor& cursor) const { 00401 return cursor >= start() && cursor < end(); 00402 } 00403 00411 inline bool containsLine(int line) const { 00412 return (line > start().line() || (line == start().line() && !start().column())) && line < end().line(); 00413 } 00414 00422 inline bool containsColumn(int column) const { 00423 return column >= start().column() && column < end().column(); 00424 } 00425 00433 bool overlaps(const Range& range) const; 00434 00442 inline bool overlapsLine(int line) const { 00443 return line >= start().line() && line <= end().line(); 00444 } 00445 00456 inline bool overlapsColumn(int column) const { 00457 return start().column() <= column && end().column() > column; 00458 } 00459 00467 inline bool onSingleLine() const { 00468 return start().line() == end().line(); 00469 } 00470 00471 //END comparison functions 00472 }; 00473 00474 Q_DECLARE_OPERATORS_FOR_FLAGS(MovingRange::InsertBehaviors) 00475 00476 } 00477 00478 #endif 00479 00480 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.7 API Reference