KTextEditor
cursor.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_CURSOR_H
00024 #define KDELIBS_KTEXTEDITOR_CURSOR_H
00025
00026 #include <ktexteditor/ktexteditor_export.h>
00027 #include <kdebug.h>
00028
00029 namespace KTextEditor
00030 {
00031 class Document;
00032 class Range;
00033 class SmartCursor;
00034
00060 class KTEXTEDITOR_EXPORT Cursor
00061 {
00062 friend class Range;
00063
00064 public:
00068 Cursor();
00069
00076 Cursor(int line, int column);
00077
00084 Cursor(const Cursor& copy);
00085
00089
00090 virtual ~Cursor();
00091
00099 virtual bool isValid() const;
00100
00104 virtual bool isSmartCursor() const;
00105
00109 virtual SmartCursor* toSmartCursor() const;
00110
00114 static Cursor invalid();
00115
00119 static Cursor start();
00120
00134 virtual void setPosition(const Cursor& position);
00135
00144 void setPosition(int line, int column);
00145
00150 virtual int line() const;
00151
00156 virtual void setLine(int line);
00157
00162 int column() const;
00163
00168 virtual void setColumn(int column);
00169
00174 bool atStartOfLine() const;
00175
00180 bool atStartOfDocument() const;
00181
00187 void position (int &line, int &column) const;
00189
00193 Range* range() const;
00194
00201 inline Cursor& operator=(const Cursor& cursor)
00202 { setPosition(cursor); return *this; }
00203
00210 inline friend Cursor operator+(const Cursor& c1, const Cursor& c2)
00211 { return Cursor(c1.line() + c2.line(), c1.column() + c2.column()); }
00212
00219 inline friend Cursor& operator+=(Cursor& c1, const Cursor& c2)
00220 { c1.setPosition(c1.line() + c2.line(), c1.column() + c2.column()); return c1; }
00221
00230 inline friend Cursor operator-(const Cursor& c1, const Cursor& c2)
00231 { return Cursor(c1.line() - c2.line(), c1.column() - c2.column()); }
00232
00239 inline friend Cursor& operator-=(Cursor& c1, const Cursor& c2)
00240 { c1.setPosition(c1.line() - c2.line(), c1.column() - c2.column()); return c1; }
00241
00252 inline friend bool operator==(const Cursor& c1, const Cursor& c2)
00253 { return c1.line() == c2.line() && c1.column() == c2.column(); }
00254
00261 inline friend bool operator!=(const Cursor& c1, const Cursor& c2)
00262 { return !(c1 == c2); }
00263
00271 inline friend bool operator>(const Cursor& c1, const Cursor& c2)
00272 { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.m_column > c2.m_column); }
00273
00281 inline friend bool operator>=(const Cursor& c1, const Cursor& c2)
00282 { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.m_column >= c2.m_column); }
00283
00291 inline friend bool operator<(const Cursor& c1, const Cursor& c2)
00292 { return !(c1 >= c2); }
00293
00301 inline friend bool operator<=(const Cursor& c1, const Cursor& c2)
00302 { return !(c1 > c2); }
00303
00307 inline friend QDebug operator<< (QDebug s, const Cursor& cursor) {
00308 if (&cursor)
00309 s.nospace() << "(" << cursor.line() << ", " << cursor.column() << ")";
00310 else
00311 s.nospace() << "(null cursor)";
00312 return s.space();
00313 }
00314
00315 protected:
00323 virtual void setRange(Range* range);
00324
00330 void cursorChangedDirectly(const Cursor& from);
00331
00337 int m_line;
00338
00344 int m_column;
00345
00351 Range* m_range;
00352 };
00353
00354 }
00355
00356 #endif
00357
00358