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

KTextEditor

  • interfaces
  • 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
32namespace KTextEditor
33{
34
35class MovingRange;
36
66class 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 inline bool isValidTextPosition() const {
181 return isValid() && line() < document()->lines() && column() <= document()->lineLength(line());
182 }
183
192 void setPosition (int line, int column);
193
198 void setLine(int line);
199
204 void setColumn(int column);
205
211 bool atStartOfLine() const;
212
218 bool atEndOfLine() const;
219
225 bool atStartOfDocument() const;
226
233 bool atEndOfDocument() const;
234
242 bool gotoNextLine();
243
251 bool gotoPreviousLine();
252
264 bool move(int chars, WrapBehavior wrapBehavior = Wrap);
265
271 const Cursor toCursor () const { return Cursor (line(), column()); }
272
278 operator const Cursor () const { return Cursor (line(), column()); }
279
280//
281// operators for: MovingCursor <-> MovingCursor
282//
293 inline friend bool operator==(const MovingCursor& c1, const MovingCursor& c2)
294 { return c1.line() == c2.line() && c1.column() == c2.column(); }
295
302 inline friend bool operator!=(const MovingCursor& c1, const MovingCursor& c2)
303 { return !(c1 == c2); }
304
312 inline friend bool operator>(const MovingCursor& c1, const MovingCursor& c2)
313 { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.column() > c2.column()); }
314
322 inline friend bool operator>=(const MovingCursor& c1, const MovingCursor& c2)
323 { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.column() >= c2.column()); }
324
332 inline friend bool operator<(const MovingCursor& c1, const MovingCursor& c2)
333 { return !(c1 >= c2); }
334
342 inline friend bool operator<=(const MovingCursor& c1, const MovingCursor& c2)
343 { return !(c1 > c2); }
344
351 inline friend QDebug operator<< (QDebug s, const MovingCursor *cursor) {
352 if (cursor)
353 s.nospace() << "(" << cursor->line() << ", " << cursor->column() << ")";
354 else
355 s.nospace() << "(null cursor)";
356 return s.space();
357 }
358
365 inline friend QDebug operator<< (QDebug s, const MovingCursor &cursor) {
366 return s << &cursor;
367 }
368};
369
370}
371
372#endif
373
374// 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::Document
A KParts derived class representing a text document.
Definition: document.h:112
KTextEditor::MovingCursor
A Cursor which is bound to a specific Document, and maintains its position.
Definition: movingcursor.h:67
KTextEditor::MovingCursor::toCursor
const Cursor toCursor() const
Convert this clever cursor into a dumb one.
Definition: movingcursor.h:271
KTextEditor::MovingCursor::operator>
friend bool operator>(const MovingCursor &c1, const MovingCursor &c2)
Greater than operator.
Definition: movingcursor.h:312
KTextEditor::MovingCursor::isValid
bool isValid() const
Returns whether the current position of this cursor is a valid position, i.e.
Definition: movingcursor.h:171
KTextEditor::MovingCursor::operator!=
friend bool operator!=(const MovingCursor &c1, const MovingCursor &c2)
Inequality operator.
Definition: movingcursor.h:302
KTextEditor::MovingCursor::WrapBehavior
WrapBehavior
Wrap behavior for end of line treatement used in move().
Definition: movingcursor.h:84
KTextEditor::MovingCursor::document
virtual Document * document() const =0
Gets the document to which this cursor is bound.
KTextEditor::MovingCursor::setInsertBehavior
virtual void setInsertBehavior(InsertBehavior insertBehavior)=0
Set insert behavior.
KTextEditor::MovingCursor::setPosition
virtual void setPosition(const KTextEditor::Cursor &position)=0
Set the current cursor position to position.
KTextEditor::MovingCursor::operator<
friend bool operator<(const MovingCursor &c1, const MovingCursor &c2)
Less than operator.
Definition: movingcursor.h:332
KTextEditor::MovingCursor::operator==
friend bool operator==(const MovingCursor &c1, const MovingCursor &c2)
Equality operator.
Definition: movingcursor.h:293
KTextEditor::MovingCursor::range
virtual MovingRange * range() const =0
Get range this cursor belongs to, if any.
KTextEditor::MovingCursor::isValidTextPosition
bool isValidTextPosition() const
Check whether the current position of this cursor is a valid text position.
Definition: movingcursor.h:180
KTextEditor::MovingCursor::column
virtual int column() const =0
Retrieve the column on which this cursor is situated.
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::MovingCursor::operator>=
friend bool operator>=(const MovingCursor &c1, const MovingCursor &c2)
Greater than or equal to operator.
Definition: movingcursor.h:322
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)
Less than or equal to operator.
Definition: movingcursor.h:342
KTextEditor::MovingCursor::insertBehavior
virtual InsertBehavior insertBehavior() const =0
Get current insert behavior.
KTextEditor::MovingRange
A range that is bound to a specific Document, and maintains its position.
Definition: movingrange.h:123
cursor.h
document.h
kdebug.h
ktexteditor_export.h
move
CopyJob * move(const KUrl &src, const KUrl &dest, JobFlags flags=DefaultFlags)
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