KTextEditor
cursor.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_CURSOR_H 00025 #define KDELIBS_KTEXTEDITOR_CURSOR_H 00026 00027 #include <ktexteditor/ktexteditor_export.h> 00028 #include <kdebug.h> 00029 00030 namespace KTextEditor 00031 { 00032 class Document; 00033 class Range; 00034 class SmartCursor; 00035 00061 class KTEXTEDITOR_EXPORT Cursor 00062 { 00063 friend class Range; 00064 00065 public: 00069 Cursor(); 00070 00077 Cursor(int line, int column); 00078 00085 Cursor(const Cursor& copy); 00086 00090 //Do not remove! Needed for inheritance. 00091 virtual ~Cursor(); 00092 00100 virtual bool isValid() const; 00101 00105 virtual bool isSmartCursor() const; 00106 00110 virtual SmartCursor* toSmartCursor() const; 00111 00115 static Cursor invalid(); 00116 00120 static Cursor start(); 00121 00135 virtual void setPosition(const Cursor& position); 00136 00145 void setPosition(int line, int column); 00146 00151 virtual int line() const; 00152 00157 virtual void setLine(int line); 00158 00163 int column() const; 00164 00169 virtual void setColumn(int column); 00170 00175 bool atStartOfLine() const; 00176 00181 bool atStartOfDocument() const; 00182 00188 void position (int &line, int &column) const; 00190 00194 Range* range() const; 00195 00202 inline Cursor& operator=(const Cursor& cursor) 00203 { setPosition(cursor); return *this; } 00204 00211 inline friend Cursor operator+(const Cursor& c1, const Cursor& c2) 00212 { return Cursor(c1.line() + c2.line(), c1.column() + c2.column()); } 00213 00220 inline friend Cursor& operator+=(Cursor& c1, const Cursor& c2) 00221 { c1.setPosition(c1.line() + c2.line(), c1.column() + c2.column()); return c1; } 00222 00231 inline friend Cursor operator-(const Cursor& c1, const Cursor& c2) 00232 { return Cursor(c1.line() - c2.line(), c1.column() - c2.column()); } 00233 00240 inline friend Cursor& operator-=(Cursor& c1, const Cursor& c2) 00241 { c1.setPosition(c1.line() - c2.line(), c1.column() - c2.column()); return c1; } 00242 00253 inline friend bool operator==(const Cursor& c1, const Cursor& c2) 00254 { return c1.line() == c2.line() && c1.column() == c2.column(); } 00255 00262 inline friend bool operator!=(const Cursor& c1, const Cursor& c2) 00263 { return !(c1 == c2); } 00264 00272 inline friend bool operator>(const Cursor& c1, const Cursor& c2) 00273 { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.m_column > c2.m_column); } 00274 00282 inline friend bool operator>=(const Cursor& c1, const Cursor& c2) 00283 { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.m_column >= c2.m_column); } 00284 00292 inline friend bool operator<(const Cursor& c1, const Cursor& c2) 00293 { return !(c1 >= c2); } 00294 00302 inline friend bool operator<=(const Cursor& c1, const Cursor& c2) 00303 { return !(c1 > c2); } 00304 00308 inline friend QDebug operator<< (QDebug s, const Cursor& cursor) { 00309 if (&cursor) 00310 s.nospace() << "(" << cursor.line() << ", " << cursor.column() << ")"; 00311 else 00312 s.nospace() << "(null cursor)"; 00313 return s.space(); 00314 } 00315 00316 protected: 00324 virtual void setRange(Range* range); 00325 00331 void cursorChangedDirectly(const Cursor& from); 00332 00338 int m_line; 00339 00345 int m_column; 00346 00352 Range* m_range; 00353 }; 00354 00355 } 00356 00357 #endif 00358 00359 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference