KTextEditor
movingcursor.h
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 * 00003 * Copyright (C) 2010 Christoph Cullmann <cullmann@kde.org> 00004 * 00005 * Based on code of the SmartCursor/Range by: 00006 * Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org> 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_MOVINGCURSOR_H 00025 #define KDELIBS_KTEXTEDITOR_MOVINGCURSOR_H 00026 00027 #include <kdebug.h> 00028 #include <ktexteditor/ktexteditor_export.h> 00029 #include <ktexteditor/cursor.h> 00030 #include <ktexteditor/document.h> 00031 00032 namespace KTextEditor 00033 { 00034 00035 class MovingRange; 00036 00066 class KTEXTEDITOR_EXPORT MovingCursor 00067 { 00068 // 00069 // sub types 00070 // 00071 public: 00076 enum InsertBehavior { 00077 StayOnInsert = 0x0, 00078 MoveOnInsert = 0x1 00079 }; 00080 00084 enum WrapBehavior { 00085 Wrap = 0x0, 00086 NoWrap = 0x1 00087 }; 00088 00089 // 00090 // stuff that needs to be implemented by editor part cusors 00091 // 00092 public: 00097 virtual void setInsertBehavior (InsertBehavior insertBehavior) = 0; 00098 00103 virtual InsertBehavior insertBehavior () const = 0; 00104 00109 virtual Document *document () const = 0; 00110 00115 virtual MovingRange *range () const = 0; 00116 00122 virtual void setPosition (const KTextEditor::Cursor& position) = 0; 00123 00128 virtual int line() const = 0; 00129 00134 virtual int column() const = 0; 00135 00139 virtual ~MovingCursor (); 00140 00141 // 00142 // forbidden stuff 00143 // 00144 protected: 00148 MovingCursor (); 00149 00150 private: 00154 MovingCursor (const MovingCursor &); 00155 00159 MovingCursor &operator= (const MovingCursor &); 00160 00161 // 00162 // convenience API 00163 // 00164 public: 00165 00171 inline bool isValid() const { 00172 return line() >= 0 && column() >= 0; 00173 } 00174 00180 inline bool isValidTextPosition() const { 00181 return isValid() && line() < document()->lines() && column() <= document()->lineLength(line()); 00182 } 00183 00192 void setPosition (int line, int column); 00193 00198 void setLine(int line); 00199 00204 void setColumn(int column); 00205 00211 bool atStartOfLine() const; 00212 00218 bool atEndOfLine() const; 00219 00225 bool atStartOfDocument() const; 00226 00233 bool atEndOfDocument() const; 00234 00242 bool gotoNextLine(); 00243 00251 bool gotoPreviousLine(); 00252 00264 bool move(int chars, WrapBehavior wrapBehavior = Wrap); 00265 00271 const Cursor toCursor () const { return Cursor (line(), column()); } 00272 00278 operator const Cursor () const { return Cursor (line(), column()); } 00279 00280 // 00281 // operators for: MovingCursor <-> MovingCursor 00282 // 00293 inline friend bool operator==(const MovingCursor& c1, const MovingCursor& c2) 00294 { return c1.line() == c2.line() && c1.column() == c2.column(); } 00295 00302 inline friend bool operator!=(const MovingCursor& c1, const MovingCursor& c2) 00303 { return !(c1 == c2); } 00304 00312 inline friend bool operator>(const MovingCursor& c1, const MovingCursor& c2) 00313 { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.column() > c2.column()); } 00314 00322 inline friend bool operator>=(const MovingCursor& c1, const MovingCursor& c2) 00323 { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.column() >= c2.column()); } 00324 00332 inline friend bool operator<(const MovingCursor& c1, const MovingCursor& c2) 00333 { return !(c1 >= c2); } 00334 00342 inline friend bool operator<=(const MovingCursor& c1, const MovingCursor& c2) 00343 { return !(c1 > c2); } 00344 00351 inline friend QDebug operator<< (QDebug s, const MovingCursor *cursor) { 00352 if (cursor) 00353 s.nospace() << "(" << cursor->line() << ", " << cursor->column() << ")"; 00354 else 00355 s.nospace() << "(null cursor)"; 00356 return s.space(); 00357 } 00358 00365 inline friend QDebug operator<< (QDebug s, const MovingCursor &cursor) { 00366 return s << &cursor; 00367 } 00368 }; 00369 00370 } 00371 00372 #endif 00373 00374 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference