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

KTextEditor

  • interfaces
  • ktexteditor
movingrange.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_MOVINGRANGE_H
25#define KDELIBS_KTEXTEDITOR_MOVINGRANGE_H
26
27#include <ktexteditor/ktexteditor_export.h>
28#include <ktexteditor/attribute.h>
29#include <ktexteditor/range.h>
30#include <ktexteditor/movingcursor.h>
31
32namespace KTextEditor
33{
34
35class Document;
36class View;
37class MovingRangeFeedback;
38
122class KTEXTEDITOR_EXPORT MovingRange
123{
124 //
125 // sub types
126 //
127 public:
129 enum InsertBehavior {
131 DoNotExpand = 0x0,
133 ExpandLeft = 0x1,
135 ExpandRight = 0x2
136 };
137 Q_DECLARE_FLAGS(InsertBehaviors, InsertBehavior)
138
139
142 enum EmptyBehavior {
143 AllowEmpty = 0x0,
144 InvalidateIfEmpty = 0x1
145 };
146
147 //
148 // stuff that needs to be implemented by editor part cursors
149 //
150 public:
155 virtual void setInsertBehaviors (InsertBehaviors insertBehaviors) = 0;
156
161 virtual InsertBehaviors insertBehaviors () const = 0;
162
167 virtual void setEmptyBehavior (EmptyBehavior emptyBehavior) = 0;
168
173 virtual EmptyBehavior emptyBehavior () const = 0;
174
179 virtual Document *document () const = 0;
180
187 virtual void setRange (const KTextEditor::Range &range) = 0;
188
193 virtual const MovingCursor &start () const = 0;
194
199 virtual const MovingCursor &end () const = 0;
200
206 virtual View *view () const = 0;
207
216 virtual void setView (View *view) = 0;
217
223 virtual Attribute::Ptr attribute () const = 0;
224
232 virtual void setAttribute (Attribute::Ptr attribute) = 0;
233
239 virtual bool attributeOnlyForViews () const = 0;
240
245 virtual void setAttributeOnlyForViews (bool onlyForViews) = 0;
246
252 virtual MovingRangeFeedback *feedback () const = 0;
253
261 virtual void setFeedback (MovingRangeFeedback *feedback) = 0;
262
277 virtual qreal zDepth () const = 0;
278
288 virtual void setZDepth (qreal zDepth) = 0;
289
293 virtual ~MovingRange ();
294
295 //
296 // forbidden stuff
297 //
298 protected:
302 MovingRange ();
303
304 private:
308 MovingRange (const MovingRange &);
309
313 MovingRange &operator= (const MovingRange &);
314
315 //
316 // convenience API
317 //
318 public:
327 void setRange (const Cursor &start, const Cursor &end);
328
333 const Range toRange () const { return Range (start().toCursor(), end().toCursor()); }
334
339 operator const Range () const { return Range (start().toCursor(), end().toCursor()); }
340
347 inline friend QDebug operator<< (QDebug s, const MovingRange *range) {
348 if (range)
349 s << "[" << range->start() << " -> " << range->end() << "]";
350 else
351 s << "(null range)";
352 return s.space();
353 }
354
361 inline friend QDebug operator<< (QDebug s, const MovingRange &range) {
362 return s << &range;
363 }
364
371 inline bool isEmpty() const {
372 return start() == end();
373 }
374
375 //BEGIN comparison functions
389 inline bool contains(const Range& range) const {
390 return range.start() >= start() && range.end() <= end();
391 }
392
400 inline bool contains(const Cursor& cursor) const {
401 return cursor >= start() && cursor < end();
402 }
403
411 inline bool containsLine(int line) const {
412 return (line > start().line() || (line == start().line() && !start().column())) && line < end().line();
413 }
414
422 inline bool containsColumn(int column) const {
423 return column >= start().column() && column < end().column();
424 }
425
433 bool overlaps(const Range& range) const;
434
442 inline bool overlapsLine(int line) const {
443 return line >= start().line() && line <= end().line();
444 }
445
456 inline bool overlapsColumn(int column) const {
457 return start().column() <= column && end().column() > column;
458 }
459
467 inline bool onSingleLine() const {
468 return start().line() == end().line();
469 }
470
471 //END comparison functions
472};
473
474Q_DECLARE_OPERATORS_FOR_FLAGS(MovingRange::InsertBehaviors)
475
476}
477
478#endif
479
480// kate: space-indent on; indent-width 2; replace-tabs on;
attribute.h
KSharedPtr< Attribute >
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::MovingRangeFeedback
A class which provides notifications of state changes to a MovingRange.
Definition: movingrangefeedback.h:49
KTextEditor::MovingRange
A range that is bound to a specific Document, and maintains its position.
Definition: movingrange.h:123
KTextEditor::MovingRange::emptyBehavior
virtual EmptyBehavior emptyBehavior() const =0
Will this range invalidate itself if it becomes empty?
KTextEditor::MovingRange::containsColumn
bool containsColumn(int column) const
Check whether the range contains column.
Definition: movingrange.h:422
KTextEditor::MovingRange::setAttribute
virtual void setAttribute(Attribute::Ptr attribute)=0
Sets the currently active attribute for this range.
KTextEditor::MovingRange::start
virtual const MovingCursor & start() const =0
Retrieve start cursor of this range, read-only.
KTextEditor::MovingRange::setAttributeOnlyForViews
virtual void setAttributeOnlyForViews(bool onlyForViews)=0
Set if this range's attribute is only visible in views, not for example prints.
KTextEditor::MovingRange::isEmpty
bool isEmpty() const
Returns true if this range contains no characters, ie.
Definition: movingrange.h:371
KTextEditor::MovingRange::setInsertBehaviors
virtual void setInsertBehaviors(InsertBehaviors insertBehaviors)=0
Set insert behaviors.
KTextEditor::MovingRange::overlapsColumn
bool overlapsColumn(int column) const
Check to see if this range overlaps column; that is, if column is between start()....
Definition: movingrange.h:456
KTextEditor::MovingRange::setView
virtual void setView(View *view)=0
Sets the currently active view for this range.
KTextEditor::MovingRange::contains
bool contains(const Cursor &cursor) const
Check to see if cursor is contained within this range, ie >= start() and < end().
Definition: movingrange.h:400
KTextEditor::MovingRange::containsLine
bool containsLine(int line) const
Returns true if this range wholly encompasses line.
Definition: movingrange.h:411
KTextEditor::MovingRange::end
virtual const MovingCursor & end() const =0
Retrieve end cursor of this range, read-only.
KTextEditor::MovingRange::feedback
virtual MovingRangeFeedback * feedback() const =0
Gets the active MovingRangeFeedback for this range.
KTextEditor::MovingRange::overlapsLine
bool overlapsLine(int line) const
Check whether the range overlaps at least part of line.
Definition: movingrange.h:442
KTextEditor::MovingRange::EmptyBehavior
EmptyBehavior
Behavior of range if it becomes empty.
Definition: movingrange.h:142
KTextEditor::MovingRange::attribute
virtual Attribute::Ptr attribute() const =0
Gets the active Attribute for this range.
KTextEditor::MovingRange::toRange
const Range toRange() const
Convert this clever range into a dumb one.
Definition: movingrange.h:333
KTextEditor::MovingRange::setRange
virtual void setRange(const KTextEditor::Range &range)=0
Set the range of this range.
KTextEditor::MovingRange::setFeedback
virtual void setFeedback(MovingRangeFeedback *feedback)=0
Sets the currently active MovingRangeFeedback for this range.
KTextEditor::MovingRange::setZDepth
virtual void setZDepth(qreal zDepth)=0
Set the current Z-depth of this range.
KTextEditor::MovingRange::document
virtual Document * document() const =0
Gets the document to which this range is bound.
KTextEditor::MovingRange::contains
bool contains(const Range &range) const
Check whether the this range wholly encompasses range.
Definition: movingrange.h:389
KTextEditor::MovingRange::attributeOnlyForViews
virtual bool attributeOnlyForViews() const =0
Is this range's attribute only visible in views, not for example prints? Default is false.
KTextEditor::MovingRange::setEmptyBehavior
virtual void setEmptyBehavior(EmptyBehavior emptyBehavior)=0
Set if this range will invalidate itself if it becomes empty.
KTextEditor::MovingRange::view
virtual View * view() const =0
Gets the active view for this range.
KTextEditor::MovingRange::zDepth
virtual qreal zDepth() const =0
Gets the current Z-depth of this range.
KTextEditor::MovingRange::insertBehaviors
virtual InsertBehaviors insertBehaviors() const =0
Get current insert behaviors.
KTextEditor::MovingRange::onSingleLine
bool onSingleLine() const
Check whether the start() and end() cursors of this range are on the same line.
Definition: movingrange.h:467
KTextEditor::MovingRange::InsertBehavior
InsertBehavior
Determine how the range reacts to characters inserted immediately outside the range.
Definition: movingrange.h:129
KTextEditor::Range
An object representing a section of text, from one Cursor to another.
Definition: range.h:55
KTextEditor::Range::start
Cursor & start()
Get the start position of this range.
Definition: range.cpp:296
KTextEditor::Range::end
Cursor & end()
Get the end position of this range.
Definition: range.cpp:306
KTextEditor::View
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:146
ktexteditor_export.h
movingcursor.h
end
const KShortcut & end()
KTextEditor
Namespace for the KDE Text Editor Interfaces.
Definition: annotationinterface.h:31
range.h
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