• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KTextEditor

  • interfaces
  • 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
30namespace KTextEditor
31{
32class Document;
33class Range;
34class SmartCursor;
35
61class KTEXTEDITOR_EXPORT Cursor
62{
63 friend class Range;
64
65 public:
69 Cursor();
70
77 Cursor(int line, int column);
78
85 Cursor(const Cursor& copy);
86
90 //Do not remove! Needed for inheritance.
91 virtual ~Cursor();
92
100 virtual bool isValid() const;
101
105 virtual bool isSmartCursor() const;
106
110 virtual SmartCursor* toSmartCursor() const;
111
115 static Cursor invalid();
116
120 static Cursor start();
121
135 virtual void setPosition(const Cursor& position);
136
145 void setPosition(int line, int column);
146
151 virtual int line() const;
152
157 virtual void setLine(int line);
158
163 int column() const;
164
169 virtual void setColumn(int column);
170
175 bool atStartOfLine() const;
176
181 bool atStartOfDocument() const;
182
188 void position (int &line, int &column) const;
190
194 Range* range() const;
195
202 inline Cursor& operator=(const Cursor& cursor)
203 { setPosition(cursor); return *this; }
204
211 inline friend Cursor operator+(const Cursor& c1, const Cursor& c2)
212 { return Cursor(c1.line() + c2.line(), c1.column() + c2.column()); }
213
220 inline friend Cursor& operator+=(Cursor& c1, const Cursor& c2)
221 { c1.setPosition(c1.line() + c2.line(), c1.column() + c2.column()); return c1; }
222
231 inline friend Cursor operator-(const Cursor& c1, const Cursor& c2)
232 { return Cursor(c1.line() - c2.line(), c1.column() - c2.column()); }
233
240 inline friend Cursor& operator-=(Cursor& c1, const Cursor& c2)
241 { c1.setPosition(c1.line() - c2.line(), c1.column() - c2.column()); return c1; }
242
253 inline friend bool operator==(const Cursor& c1, const Cursor& c2)
254 { return c1.line() == c2.line() && c1.column() == c2.column(); }
255
262 inline friend bool operator!=(const Cursor& c1, const Cursor& c2)
263 { return !(c1 == c2); }
264
272 inline friend bool operator>(const Cursor& c1, const Cursor& c2)
273 { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.m_column > c2.m_column); }
274
282 inline friend bool operator>=(const Cursor& c1, const Cursor& c2)
283 { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.m_column >= c2.m_column); }
284
292 inline friend bool operator<(const Cursor& c1, const Cursor& c2)
293 { return !(c1 >= c2); }
294
302 inline friend bool operator<=(const Cursor& c1, const Cursor& c2)
303 { return !(c1 > c2); }
304
308 inline friend QDebug operator<< (QDebug s, const Cursor& cursor) {
309 if (&cursor)
310 s.nospace() << "(" << cursor.line() << ", " << cursor.column() << ")";
311 else
312 s.nospace() << "(null cursor)";
313 return s.space();
314 }
315
316 protected:
324 virtual void setRange(Range* range);
325
331 void cursorChangedDirectly(const Cursor& from);
332
338 int m_line;
339
345 int m_column;
346
352 Range* m_range;
353};
354
355}
356
357#endif
358
359// kate: space-indent on; indent-width 2; replace-tabs on;
KTextEditor::Cursor
An object which represents a position in a Document.
Definition: cursor.h:62
KTextEditor::Cursor::column
int column() const
Retrieve the column on which this cursor is situated.
Definition: cursor.cpp:79
KTextEditor::Cursor::operator<
friend bool operator<(const Cursor &c1, const Cursor &c2)
Less than operator.
Definition: cursor.h:292
KTextEditor::Cursor::operator+
friend Cursor operator+(const Cursor &c1, const Cursor &c2)
Addition operator.
Definition: cursor.h:211
KTextEditor::Cursor::operator<=
friend bool operator<=(const Cursor &c1, const Cursor &c2)
Less than or equal to operator.
Definition: cursor.h:302
KTextEditor::Cursor::operator==
friend bool operator==(const Cursor &c1, const Cursor &c2)
Equality operator.
Definition: cursor.h:253
KTextEditor::Cursor::operator>=
friend bool operator>=(const Cursor &c1, const Cursor &c2)
Greater than or equal to operator.
Definition: cursor.h:282
KTextEditor::Cursor::operator-=
friend Cursor & operator-=(Cursor &c1, const Cursor &c2)
Subtraction assignment operator.
Definition: cursor.h:240
KTextEditor::Cursor::setPosition
virtual void setPosition(const Cursor &position)
Set the current cursor position to position.
Definition: cursor.cpp:96
KTextEditor::Cursor::m_line
int m_line
Definition: cursor.h:338
KTextEditor::Cursor::operator!=
friend bool operator!=(const Cursor &c1, const Cursor &c2)
Inequality operator.
Definition: cursor.h:262
KTextEditor::Cursor::operator>
friend bool operator>(const Cursor &c1, const Cursor &c2)
Greater than operator.
Definition: cursor.h:272
KTextEditor::Cursor::line
virtual int line() const
Retrieve the line on which this cursor is situated.
Definition: cursor.cpp:62
KTextEditor::Cursor::operator=
Cursor & operator=(const Cursor &cursor)
Assignment operator.
Definition: cursor.h:202
KTextEditor::Cursor::operator+=
friend Cursor & operator+=(Cursor &c1, const Cursor &c2)
Addition assignment operator.
Definition: cursor.h:220
KTextEditor::Cursor::operator-
friend Cursor operator-(const Cursor &c1, const Cursor &c2)
Subtraction operator.
Definition: cursor.h:231
KTextEditor::Cursor::m_column
int m_column
Definition: cursor.h:345
KTextEditor::Cursor::m_range
Range * m_range
Definition: cursor.h:352
KTextEditor::Range
An object representing a section of text, from one Cursor to another.
Definition: range.h:55
KTextEditor::SmartCursor
A Cursor which is bound to a specific Document, and maintains its position.
Definition: smartcursor.h:66
kdebug.h
ktexteditor_export.h
KTextEditor
Namespace for the KDE Text Editor Interfaces.
Definition: annotationinterface.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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