KTextEditor
range.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef KDELIBS_KTEXTEDITOR_RANGE_H
00024 #define KDELIBS_KTEXTEDITOR_RANGE_H
00025
00026 #include <ktexteditor/ktexteditor_export.h>
00027 #include <ktexteditor/cursor.h>
00028
00029
00030 namespace KTextEditor
00031 {
00032 class SmartRange;
00033
00053 class KTEXTEDITOR_EXPORT Range
00054 {
00055 friend class Cursor;
00056
00057 public:
00062 Range();
00063
00071 Range(const Cursor& start, const Cursor& end);
00072
00080 Range(const Cursor& start, int width);
00081
00089 Range(const Cursor& start, int endLine, int endColumn);
00090
00099 Range(int startLine, int startColumn, int endLine, int endColumn);
00100
00106 Range(const Range& copy);
00107
00111
00112 virtual ~Range();
00113
00117 virtual bool isValid() const;
00118
00122 static Range invalid();
00123
00127 virtual bool isSmartRange() const;
00128
00132 virtual SmartRange* toSmartRange() const;
00133
00157 Cursor& start();
00158
00166 const Cursor& start() const;
00167
00187 Cursor& end();
00188
00196 const Cursor& end() const;
00197
00203 void setBothLines(int line);
00204
00210 void setBothColumns(int column);
00211
00217 virtual void setRange(const Range& range);
00218
00229 void setRange(const Cursor& start, const Cursor& end);
00230
00238 virtual bool expandToRange(const Range& range);
00239
00247 virtual bool confineToRange(const Range& range);
00248
00256 bool onSingleLine() const;
00257
00264 int numberOfLines() const;
00265
00272 int columnWidth() const;
00273
00280 bool isEmpty() const;
00281
00282
00299 bool contains(const Range& range) const;
00300
00308 bool contains(const Cursor& cursor) const;
00309
00317 bool containsLine(int line) const;
00318
00326 bool containsColumn(int column) const;
00327
00335 bool overlaps(const Range& range) const;
00336
00344 bool overlapsLine(int line) const;
00345
00356 bool overlapsColumn(int column) const;
00357
00371 int positionRelativeToCursor(const Cursor& cursor) const;
00372
00385 int positionRelativeToLine(int line) const;
00386
00396 bool boundaryAtCursor(const Cursor& cursor) const;
00397
00407 bool boundaryOnLine(int line) const;
00408
00418 bool boundaryOnColumn(int column) const;
00420
00421
00430 Range intersect(const Range& range) const;
00431
00440 Range encompass(const Range& range) const;
00441
00451 inline Range& operator=(const Range& rhs)
00452 { setRange(rhs); return *this; }
00453
00462 inline friend Range operator+(const Range& r1, const Range& r2)
00463 { return Range(r1.start() + r2.start(), r1.end() + r2.end()); }
00464
00473 inline friend Range& operator+=(Range& r1, const Range& r2)
00474 { r1.setRange(r1.start() + r2.start(), r1.end() + r2.end()); return r1; }
00475
00485 inline friend Range operator-(const Range& r1, const Range& r2)
00486 { return Range(r1.start() - r2.start(), r1.end() - r2.end()); }
00487
00496 inline friend Range& operator-=(Range& r1, const Range& r2)
00497 { r1.setRange(r1.start() - r2.start(), r1.end() - r2.end()); return r1; }
00498
00507 inline friend Range operator&(const Range& r1, const Range& r2)
00508 { return r1.intersect(r2); }
00509
00517 inline friend Range& operator&=(Range& r1, const Range& r2)
00518 { r1.setRange(r1.intersect(r2)); return r1; }
00519
00528 inline friend bool operator==(const Range& r1, const Range& r2)
00529 { return r1.start() == r2.start() && r1.end() == r2.end(); }
00530
00539 inline friend bool operator!=(const Range& r1, const Range& r2)
00540 { return r1.start() != r2.start() || r1.end() != r2.end(); }
00541
00551 inline friend bool operator>(const Range& r1, const Range& r2)
00552 { return r1.start() > r2.end(); }
00553
00563 inline friend bool operator<(const Range& r1, const Range& r2)
00564 { return r1.end() < r2.start(); }
00565
00569 inline friend QDebug operator<< (QDebug s, const Range& range) {
00570 if (&range)
00571 s << "[" << range.start() << " -> " << range.end() << "]";
00572 else
00573 s << "(null range)";
00574 return s;
00575 }
00576
00577 protected:
00586 Range(Cursor* start, Cursor* end);
00587
00596 virtual void rangeChanged(Cursor* cursor, const Range& from);
00597
00603 Cursor* m_start;
00604
00610 Cursor* m_end;
00611 };
00612
00613 }
00614
00615 #endif
00616
00617