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
00518 inline friend Range& operator&=(Range& r1, const Range& r2)
00519 { r1.setRange(r1.intersect(r2)); return r1; }
00520
00529 inline friend bool operator==(const Range& r1, const Range& r2)
00530 { return r1.start() == r2.start() && r1.end() == r2.end(); }
00531
00540 inline friend bool operator!=(const Range& r1, const Range& r2)
00541 { return r1.start() != r2.start() || r1.end() != r2.end(); }
00542
00552 inline friend bool operator>(const Range& r1, const Range& r2)
00553 { return r1.start() > r2.end(); }
00554
00564 inline friend bool operator<(const Range& r1, const Range& r2)
00565 { return r1.end() < r2.start(); }
00566
00570 inline friend QDebug operator<< (QDebug s, const Range& range) {
00571 if (&range)
00572 s << "[" << range.start() << " -> " << range.end() << "]";
00573 else
00574 s << "(null range)";
00575 return s;
00576 }
00577
00578 protected:
00587 Range(Cursor* start, Cursor* end);
00588
00597 virtual void rangeChanged(Cursor* cursor, const Range& from);
00598
00604 Cursor* m_start;
00605
00611 Cursor* m_end;
00612 };
00613
00614 }
00615
00616 #endif
00617
00618