KTextEditor
range.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) 2001-2005 Christoph Cullmann <cullmann@kde.org> 00004 * Copyright (C) 2002 Christian Couder <christian@kdevelop.org> 00005 * Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> 00006 * Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de> 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_RANGE_H 00025 #define KDELIBS_KTEXTEDITOR_RANGE_H 00026 00027 #include <ktexteditor/ktexteditor_export.h> 00028 #include <ktexteditor/cursor.h> 00029 00030 00031 namespace KTextEditor 00032 { 00033 class SmartRange; 00034 00054 class KTEXTEDITOR_EXPORT Range 00055 { 00056 friend class Cursor; 00057 00058 public: 00063 Range(); 00064 00072 Range(const Cursor& start, const Cursor& end); 00073 00081 Range(const Cursor& start, int width); 00082 00090 Range(const Cursor& start, int endLine, int endColumn); 00091 00100 Range(int startLine, int startColumn, int endLine, int endColumn); 00101 00107 Range(const Range& copy); 00108 00112 //Do not remove! Needed for inheritance. 00113 virtual ~Range(); 00114 00118 virtual bool isValid() const; 00119 00123 static Range invalid(); 00124 00128 virtual bool isSmartRange() const; 00129 00133 virtual SmartRange* toSmartRange() const; 00134 00158 Cursor& start(); 00159 00167 const Cursor& start() const; 00168 00188 Cursor& end(); 00189 00197 const Cursor& end() const; 00198 00204 void setBothLines(int line); 00205 00211 void setBothColumns(int column); 00212 00218 virtual void setRange(const Range& range); 00219 00230 void setRange(const Cursor& start, const Cursor& end); 00231 00239 virtual bool expandToRange(const Range& range); 00240 00248 virtual bool confineToRange(const Range& range); 00249 00257 bool onSingleLine() const; 00258 00265 int numberOfLines() const; 00266 00273 int columnWidth() const; 00274 00281 bool isEmpty() const; 00282 00283 //BEGIN comparison functions 00300 bool contains(const Range& range) const; 00301 00309 bool contains(const Cursor& cursor) const; 00310 00318 bool containsLine(int line) const; 00319 00327 bool containsColumn(int column) const; 00328 00336 bool overlaps(const Range& range) const; 00337 00345 bool overlapsLine(int line) const; 00346 00357 bool overlapsColumn(int column) const; 00358 00372 int positionRelativeToCursor(const Cursor& cursor) const; 00373 00386 int positionRelativeToLine(int line) const; 00387 00397 bool boundaryAtCursor(const Cursor& cursor) const; 00398 00408 bool boundaryOnLine(int line) const; 00409 00419 bool boundaryOnColumn(int column) const; 00421 //END 00422 00431 Range intersect(const Range& range) const; 00432 00441 Range encompass(const Range& range) const; 00442 00452 inline Range& operator=(const Range& rhs) 00453 { setRange(rhs); return *this; } 00454 00463 inline friend Range operator+(const Range& r1, const Range& r2) 00464 { return Range(r1.start() + r2.start(), r1.end() + r2.end()); } 00465 00474 inline friend Range& operator+=(Range& r1, const Range& r2) 00475 { r1.setRange(r1.start() + r2.start(), r1.end() + r2.end()); return r1; } 00476 00486 inline friend Range operator-(const Range& r1, const Range& r2) 00487 { return Range(r1.start() - r2.start(), r1.end() - r2.end()); } 00488 00497 inline friend Range& operator-=(Range& r1, const Range& r2) 00498 { r1.setRange(r1.start() - r2.start(), r1.end() - r2.end()); return r1; } 00499 00508 inline friend Range operator&(const Range& r1, const Range& r2) 00509 { return r1.intersect(r2); } 00510 00519 inline friend Range& operator&=(Range& r1, const Range& r2) 00520 { r1.setRange(r1.intersect(r2)); return r1; } 00521 00530 inline friend bool operator==(const Range& r1, const Range& r2) 00531 { return r1.start() == r2.start() && r1.end() == r2.end(); } 00532 00541 inline friend bool operator!=(const Range& r1, const Range& r2) 00542 { return r1.start() != r2.start() || r1.end() != r2.end(); } 00543 00553 inline friend bool operator>(const Range& r1, const Range& r2) 00554 { return r1.start() > r2.end(); } 00555 00565 inline friend bool operator<(const Range& r1, const Range& r2) 00566 { return r1.end() < r2.start(); } 00567 00571 inline friend QDebug operator<< (QDebug s, const Range& range) { 00572 if (&range) 00573 s << "[" << range.start() << " -> " << range.end() << "]"; 00574 else 00575 s << "(null range)"; 00576 return s; 00577 } 00578 00579 protected: 00588 Range(Cursor* start, Cursor* end); 00589 00598 virtual void rangeChanged(Cursor* cursor, const Range& from); 00599 00605 Cursor* m_start; 00606 00612 Cursor* m_end; 00613 }; 00614 00615 } 00616 00617 #endif 00618 00619 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference