• 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
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 
32 // TODO: KDE5, maybe add
33 // - void MoivingRange::setBlockMode(bool enableBlockMode);
34 // - bool MoivingRange::blockMode() const;
35 // This way, arbitrary highlighting would work for colums as well. In fact, if implemented
36 // correctly in the Kate Renderer, drawing block selection mode could use this, too.
37 // The vi in put mode yank highlighting could use it, too: https://bugs.kde.org/show_bug.cgi?id=324695
38 //
39 // A correct implementation needs to take care of MovingRangeFeedback, especially
40 // of mouseEnteredRange(), mouseExitedRange(), caretEnteredRange() and caretEnteredRange()
41 
42 namespace KTextEditor
43 {
44 
45 class Document;
46 class View;
47 class MovingRangeFeedback;
48 
132 class KTEXTEDITOR_EXPORT MovingRange
133 {
134  //
135  // sub types
136  //
137  public:
139  enum InsertBehavior {
141  DoNotExpand = 0x0,
143  ExpandLeft = 0x1,
145  ExpandRight = 0x2
146  };
147  Q_DECLARE_FLAGS(InsertBehaviors, InsertBehavior)
148 
149 
152  enum EmptyBehavior {
153  AllowEmpty = 0x0,
154  InvalidateIfEmpty = 0x1
155  };
156 
157  //
158  // stuff that needs to be implemented by editor part cursors
159  //
160  public:
165  virtual void setInsertBehaviors (InsertBehaviors insertBehaviors) = 0;
166 
171  virtual InsertBehaviors insertBehaviors () const = 0;
172 
177  virtual void setEmptyBehavior (EmptyBehavior emptyBehavior) = 0;
178 
183  virtual EmptyBehavior emptyBehavior () const = 0;
184 
189  virtual Document *document () const = 0;
190 
197  virtual void setRange (const KTextEditor::Range &range) = 0;
198 
203  virtual const MovingCursor &start () const = 0;
204 
209  virtual const MovingCursor &end () const = 0;
210 
216  virtual View *view () const = 0;
217 
226  virtual void setView (View *view) = 0;
227 
233  virtual Attribute::Ptr attribute () const = 0;
234 
242  virtual void setAttribute (Attribute::Ptr attribute) = 0;
243 
249  virtual bool attributeOnlyForViews () const = 0;
250 
255  virtual void setAttributeOnlyForViews (bool onlyForViews) = 0;
256 
262  virtual MovingRangeFeedback *feedback () const = 0;
263 
271  virtual void setFeedback (MovingRangeFeedback *feedback) = 0;
272 
287  virtual qreal zDepth () const = 0;
288 
298  virtual void setZDepth (qreal zDepth) = 0;
299 
303  virtual ~MovingRange ();
304 
305  //
306  // forbidden stuff
307  //
308  protected:
312  MovingRange ();
313 
314  private:
318  MovingRange (const MovingRange &);
319 
323  MovingRange &operator= (const MovingRange &);
324 
325  //
326  // convenience API
327  //
328  public:
337  void setRange (const Cursor &start, const Cursor &end);
338 
343  const Range toRange () const { return Range (start().toCursor(), end().toCursor()); }
344 
349  operator const Range () const { return Range (start().toCursor(), end().toCursor()); }
350 
357  inline friend QDebug operator<< (QDebug s, const MovingRange *range) {
358  if (range)
359  s << "[" << range->start() << " -> " << range->end() << "]";
360  else
361  s << "(null range)";
362  return s.space();
363  }
364 
371  inline friend QDebug operator<< (QDebug s, const MovingRange &range) {
372  return s << &range;
373  }
374 
381  inline bool isEmpty() const {
382  return start() == end();
383  }
384 
385  //BEGIN comparison functions
399  inline bool contains(const Range& range) const {
400  return range.start() >= start() && range.end() <= end();
401  }
402 
410  inline bool contains(const Cursor& cursor) const {
411  return cursor >= start() && cursor < end();
412  }
413 
421  inline bool containsLine(int line) const {
422  return (line > start().line() || (line == start().line() && !start().column())) && line < end().line();
423  }
424 
432  inline bool containsColumn(int column) const {
433  return column >= start().column() && column < end().column();
434  }
435 
443  bool overlaps(const Range& range) const;
444 
452  inline bool overlapsLine(int line) const {
453  return line >= start().line() && line <= end().line();
454  }
455 
466  inline bool overlapsColumn(int column) const {
467  return start().column() <= column && end().column() > column;
468  }
469 
477  inline bool onSingleLine() const {
478  return start().line() == end().line();
479  }
480 
481  //END comparison functions
482 };
483 
484 Q_DECLARE_OPERATORS_FOR_FLAGS(MovingRange::InsertBehaviors)
485 
486 }
487 
488 #endif
489 
490 // kate: space-indent on; indent-width 2; replace-tabs on;
KTextEditor::Range::start
Cursor & start()
Get the start position of this range.
Definition: range.cpp:296
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:410
KTextEditor::MovingRange::EmptyBehavior
EmptyBehavior
Behavior of range if it becomes empty.
Definition: movingrange.h:152
KTextEditor::MovingCursor
A Cursor which is bound to a specific Document, and maintains its position.
Definition: movingcursor.h:66
KTextEditor::MovingRange::toRange
const Range toRange() const
Convert this clever range into a dumb one.
Definition: movingrange.h:343
KTextEditor::MovingRangeFeedback
A class which provides notifications of state changes to a MovingRange.
Definition: movingrangefeedback.h:48
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::MovingRange::contains
bool contains(const Range &range) const
Check whether the this range wholly encompasses range.
Definition: movingrange.h:399
KTextEditor::MovingRange::overlapsLine
bool overlapsLine(int line) const
Check whether the range overlaps at least part of line.
Definition: movingrange.h:452
range.h
attribute.h
KTextEditor::MovingRange::overlapsColumn
bool overlapsColumn(int column) const
Check to see if this range overlaps column; that is, if column is between start().column() and end().column().
Definition: movingrange.h:466
ktexteditor_export.h
KTextEditor::Document
A KParts derived class representing a text document.
Definition: document.h:111
KTextEditor::Attribute::Ptr
KSharedPtr< Attribute > Ptr
Definition: attribute.h:61
KTextEditor::MovingRange::isEmpty
bool isEmpty() const
Returns true if this range contains no characters, ie.
Definition: movingrange.h:381
KTEXTEDITOR_EXPORT
#define KTEXTEDITOR_EXPORT
Definition: ktexteditor_export.h:35
KTextEditor::MovingRange::onSingleLine
bool onSingleLine() const
Check whether the start() and end() cursors of this range are on the same line.
Definition: movingrange.h:477
KTextEditor::Range
An object representing a section of text, from one Cursor to another.
Definition: range.h:54
QDebug::space
QDebug & space()
KTextEditor::MovingRange::containsLine
bool containsLine(int line) const
Returns true if this range wholly encompasses line.
Definition: movingrange.h:421
QDebug
KTextEditor::MovingRange::containsColumn
bool containsColumn(int column) const
Check whether the range contains column.
Definition: movingrange.h:432
KTextEditor::MovingRange::start
virtual const MovingCursor & start() const =0
Retrieve start cursor of this range, read-only.
KTextEditor::MovingRange::InsertBehavior
InsertBehavior
Determine how the range reacts to characters inserted immediately outside the range.
Definition: movingrange.h:139
movingcursor.h
KTextEditor::Range::end
Cursor & end()
Get the end position of this range.
Definition: range.cpp:306
KTextEditor::MovingRange::end
virtual const MovingCursor & end() const =0
Retrieve end cursor of this range, read-only.
KTextEditor::View
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:145
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