• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

KTextEditor

  • kde-4.14
  • applications
  • kate
  • ktexteditor
movingcursor.h
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2010 Christoph Cullmann <cullmann@kde.org>
4  *
5  * Based on code of the SmartCursor/Range by:
6  * Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #ifndef KDELIBS_KTEXTEDITOR_MOVINGCURSOR_H
25 #define KDELIBS_KTEXTEDITOR_MOVINGCURSOR_H
26 
27 #include <kdebug.h>
28 #include <ktexteditor/ktexteditor_export.h>
29 #include <ktexteditor/cursor.h>
30 #include <ktexteditor/document.h>
31 
32 namespace KTextEditor
33 {
34 
35 class MovingRange;
36 
66 class KTEXTEDITOR_EXPORT MovingCursor
67 {
68  //
69  // sub types
70  //
71  public:
76  enum InsertBehavior {
77  StayOnInsert = 0x0,
78  MoveOnInsert = 0x1
79  };
80 
84  enum WrapBehavior {
85  Wrap = 0x0,
86  NoWrap = 0x1
87  };
88 
89  //
90  // stuff that needs to be implemented by editor part cusors
91  //
92  public:
97  virtual void setInsertBehavior (InsertBehavior insertBehavior) = 0;
98 
103  virtual InsertBehavior insertBehavior () const = 0;
104 
109  virtual Document *document () const = 0;
110 
115  virtual MovingRange *range () const = 0;
116 
122  virtual void setPosition (const KTextEditor::Cursor& position) = 0;
123 
128  virtual int line() const = 0;
129 
134  virtual int column() const = 0;
135 
139  virtual ~MovingCursor ();
140 
141  //
142  // forbidden stuff
143  //
144  protected:
148  MovingCursor ();
149 
150  private:
154  MovingCursor (const MovingCursor &);
155 
159  MovingCursor &operator= (const MovingCursor &);
160 
161  //
162  // convenience API
163  //
164  public:
165 
171  inline bool isValid() const {
172  return line() >= 0 && column() >= 0;
173  }
174 
180  // TODO KDE5: use KTE::Document::isValidTextPosition()
181  inline bool isValidTextPosition() const {
182  return isValid() && line() < document()->lines() && column() <= document()->lineLength(line());
183  }
184 
193  void setPosition (int line, int column);
194 
199  void setLine(int line);
200 
205  void setColumn(int column);
206 
212  bool atStartOfLine() const;
213 
219  bool atEndOfLine() const;
220 
226  bool atStartOfDocument() const;
227 
234  bool atEndOfDocument() const;
235 
243  bool gotoNextLine();
244 
252  bool gotoPreviousLine();
253 
265  bool move(int chars, WrapBehavior wrapBehavior = Wrap);
266 
272  const Cursor toCursor () const { return Cursor (line(), column()); }
273 
279  operator const Cursor () const { return Cursor (line(), column()); }
280 
281 //
282 // operators for: MovingCursor <-> MovingCursor
283 //
294  inline friend bool operator==(const MovingCursor& c1, const MovingCursor& c2)
295  { return c1.line() == c2.line() && c1.column() == c2.column(); }
296 
303  inline friend bool operator!=(const MovingCursor& c1, const MovingCursor& c2)
304  { return !(c1 == c2); }
305 
313  inline friend bool operator>(const MovingCursor& c1, const MovingCursor& c2)
314  { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.column() > c2.column()); }
315 
323  inline friend bool operator>=(const MovingCursor& c1, const MovingCursor& c2)
324  { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.column() >= c2.column()); }
325 
333  inline friend bool operator<(const MovingCursor& c1, const MovingCursor& c2)
334  { return !(c1 >= c2); }
335 
343  inline friend bool operator<=(const MovingCursor& c1, const MovingCursor& c2)
344  { return !(c1 > c2); }
345 
352  inline friend QDebug operator<< (QDebug s, const MovingCursor *cursor) {
353  if (cursor)
354  s.nospace() << "(" << cursor->line() << ", " << cursor->column() << ")";
355  else
356  s.nospace() << "(null cursor)";
357  return s.space();
358  }
359 
366  inline friend QDebug operator<< (QDebug s, const MovingCursor &cursor) {
367  return s << &cursor;
368  }
369 };
370 
371 }
372 
373 #endif
374 
375 // kate: space-indent on; indent-width 2; replace-tabs on;
KTextEditor::MovingCursor::column
virtual int column() const =0
Retrieve the column on which this cursor is situated.
KTextEditor::MovingCursor::operator<=
friend bool operator<=(const MovingCursor &c1, const MovingCursor &c2)
Less than or equal to operator.
Definition: movingcursor.h:343
KTextEditor::MovingCursor::operator<
friend bool operator<(const MovingCursor &c1, const MovingCursor &c2)
Less than operator.
Definition: movingcursor.h:333
cursor.h
KTextEditor::MovingCursor
A Cursor which is bound to a specific Document, and maintains its position.
Definition: movingcursor.h:66
QDebug::nospace
QDebug & nospace()
KTextEditor::MovingRange
A range that is bound to a specific Document, and maintains its position.
Definition: movingrange.h:132
KTextEditor::Cursor
An object which represents a position in a Document.
Definition: cursor.h:55
KTextEditor::MovingCursor::InsertBehavior
InsertBehavior
Insert behavior of this cursor, should it stay if text is insert at its position or should it move...
Definition: movingcursor.h:76
ktexteditor_export.h
KTextEditor::Document
A KParts derived class representing a text document.
Definition: document.h:111
KTextEditor::MovingCursor::isValidTextPosition
bool isValidTextPosition() const
Check whether the current position of this cursor is a valid text position.
Definition: movingcursor.h:181
KTEXTEDITOR_EXPORT
#define KTEXTEDITOR_EXPORT
Definition: ktexteditor_export.h:35
document.h
KTextEditor::MovingCursor::toCursor
const Cursor toCursor() const
Convert this clever cursor into a dumb one.
Definition: movingcursor.h:272
KTextEditor::MovingCursor::WrapBehavior
WrapBehavior
Wrap behavior for end of line treatement used in move().
Definition: movingcursor.h:84
QDebug::space
QDebug & space()
KTextEditor::MovingCursor::isValid
bool isValid() const
Returns whether the current position of this cursor is a valid position, i.e.
Definition: movingcursor.h:171
QDebug
KTextEditor::MovingCursor::line
virtual int line() const =0
Retrieve the line on which this cursor is situated.
KTextEditor::MovingCursor::operator!=
friend bool operator!=(const MovingCursor &c1, const MovingCursor &c2)
Inequality operator.
Definition: movingcursor.h:303
KTextEditor::MovingCursor::operator>
friend bool operator>(const MovingCursor &c1, const MovingCursor &c2)
Greater than operator.
Definition: movingcursor.h:313
KTextEditor::MovingCursor::operator>=
friend bool operator>=(const MovingCursor &c1, const MovingCursor &c2)
Greater than or equal to operator.
Definition: movingcursor.h:323
KTextEditor::MovingCursor::operator==
friend bool operator==(const MovingCursor &c1, const MovingCursor &c2)
Equality operator.
Definition: movingcursor.h:294
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KTextEditor

Skip menu "KTextEditor"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal