• 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
cursor.h
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
3  Copyright (C) 2001-2005 Christoph Cullmann <cullmann@kde.org>
4  Copyright (C) 2002 Christian Couder <christian@kdevelop.org>
5  Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
6  Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
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_CURSOR_H
25 #define KDELIBS_KTEXTEDITOR_CURSOR_H
26 
27 #include <ktexteditor/ktexteditor_export.h>
28 #include <kdebug.h>
29 
30 namespace KTextEditor
31 {
32 class Document;
33 class Range;
34 class SmartCursor;
35 
55 class KTEXTEDITOR_EXPORT Cursor
56 {
57  friend class Range;
58 
59  public:
63  Cursor();
64 
71  Cursor(int line, int column);
72 
79  Cursor(const Cursor& copy);
80 
84  //TODO: KDE5 make non-virtual for maximum speed
85  virtual ~Cursor();
86 
91  virtual bool isValid() const;
92 
97  virtual bool isSmartCursor() const;
98 
103  virtual SmartCursor* toSmartCursor() const;
104 
110  static Cursor invalid();
111 
115  static Cursor start();
116 
128  virtual void setPosition(const Cursor& position);
129 
138  void setPosition(int line, int column);
139 
144  virtual int line() const;
145 
150  virtual void setLine(int line);
151 
156  int column() const;
157 
162  virtual void setColumn(int column);
163 
168  bool atStartOfLine() const;
169 
174  bool atStartOfDocument() const;
175 
181  void position (int &line, int &column) const;
183 
188  Range* range() const;
189 
196  inline Cursor& operator=(const Cursor& cursor)
197  { setPosition(cursor); return *this; }
198 
205  inline friend Cursor operator+(const Cursor& c1, const Cursor& c2)
206  { return Cursor(c1.line() + c2.line(), c1.column() + c2.column()); }
207 
214  inline friend Cursor& operator+=(Cursor& c1, const Cursor& c2)
215  { c1.setPosition(c1.line() + c2.line(), c1.column() + c2.column()); return c1; }
216 
225  inline friend Cursor operator-(const Cursor& c1, const Cursor& c2)
226  { return Cursor(c1.line() - c2.line(), c1.column() - c2.column()); }
227 
234  inline friend Cursor& operator-=(Cursor& c1, const Cursor& c2)
235  { c1.setPosition(c1.line() - c2.line(), c1.column() - c2.column()); return c1; }
236 
247  inline friend bool operator==(const Cursor& c1, const Cursor& c2)
248  { return c1.line() == c2.line() && c1.column() == c2.column(); }
249 
256  inline friend bool operator!=(const Cursor& c1, const Cursor& c2)
257  { return !(c1 == c2); }
258 
266  inline friend bool operator>(const Cursor& c1, const Cursor& c2)
267  { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.m_column > c2.m_column); }
268 
276  inline friend bool operator>=(const Cursor& c1, const Cursor& c2)
277  { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.m_column >= c2.m_column); }
278 
286  inline friend bool operator<(const Cursor& c1, const Cursor& c2)
287  { return !(c1 >= c2); }
288 
296  inline friend bool operator<=(const Cursor& c1, const Cursor& c2)
297  { return !(c1 > c2); }
298 
302  inline friend QDebug operator<< (QDebug s, const Cursor& cursor) {
303  if (&cursor)
304  s.nospace() << "(" << cursor.line() << ", " << cursor.column() << ")";
305  else
306  s.nospace() << "(null cursor)";
307  return s.space();
308  }
309 
310  protected:
319  virtual void setRange(Range* range);
320 
327  void cursorChangedDirectly(const Cursor& from);
328 
334  int m_line;
335 
341  int m_column;
342 
349  Range* m_range;
350 };
351 
352 }
353 
354 #endif
355 
356 // kate: space-indent on; indent-width 2; replace-tabs on;
KTextEditor::Cursor::operator-=
friend Cursor & operator-=(Cursor &c1, const Cursor &c2)
Subtraction assignment operator.
Definition: cursor.h:234
KTextEditor::Cursor::m_range
Range * m_range
Definition: cursor.h:349
KTextEditor::Cursor::operator+
friend Cursor operator+(const Cursor &c1, const Cursor &c2)
Addition operator.
Definition: cursor.h:205
QDebug::nospace
QDebug & nospace()
KTextEditor::Cursor::m_line
int m_line
Definition: cursor.h:334
KTextEditor::Cursor
An object which represents a position in a Document.
Definition: cursor.h:55
KTextEditor::Cursor::operator==
friend bool operator==(const Cursor &c1, const Cursor &c2)
Equality operator.
Definition: cursor.h:247
ktexteditor_export.h
KTextEditor::SmartCursor
A Cursor which is bound to a specific Document, and maintains its position.
Definition: smartcursor.h:65
KTEXTEDITOR_EXPORT
#define KTEXTEDITOR_EXPORT
Definition: ktexteditor_export.h:35
KTextEditor::Cursor::operator!=
friend bool operator!=(const Cursor &c1, const Cursor &c2)
Inequality operator.
Definition: cursor.h:256
KTextEditor::Cursor::operator+=
friend Cursor & operator+=(Cursor &c1, const Cursor &c2)
Addition assignment operator.
Definition: cursor.h:214
KTextEditor::Range
An object representing a section of text, from one Cursor to another.
Definition: range.h:54
KTextEditor::Cursor::operator-
friend Cursor operator-(const Cursor &c1, const Cursor &c2)
Subtraction operator.
Definition: cursor.h:225
QDebug::space
QDebug & space()
KTextEditor::Cursor::operator<=
friend bool operator<=(const Cursor &c1, const Cursor &c2)
Less than or equal to operator.
Definition: cursor.h:296
QDebug
KTextEditor::Cursor::line
virtual int line() const
Retrieve the line on which this cursor is situated.
Definition: cursor.cpp:62
KTextEditor::Cursor::operator<
friend bool operator<(const Cursor &c1, const Cursor &c2)
Less than operator.
Definition: cursor.h:286
KTextEditor::Cursor::setPosition
virtual void setPosition(const Cursor &position)
Set the current cursor position to position.
Definition: cursor.cpp:96
KTextEditor::Cursor::operator=
Cursor & operator=(const Cursor &cursor)
Assignment operator.
Definition: cursor.h:196
KTextEditor::Cursor::operator>
friend bool operator>(const Cursor &c1, const Cursor &c2)
Greater than operator.
Definition: cursor.h:266
KTextEditor::Cursor::operator>=
friend bool operator>=(const Cursor &c1, const Cursor &c2)
Greater than or equal to operator.
Definition: cursor.h:276
KTextEditor::Cursor::column
int column() const
Retrieve the column on which this cursor is situated.
Definition: cursor.cpp:79
KTextEditor::Cursor::m_column
int m_column
Definition: cursor.h:341
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