KTextEditor::View Class

class KTextEditor::View

A text widget with KXMLGUIClient that represents a Document. More...

Header: #include <KTextEditor/View>
CMake: find_package(KF6 REQUIRED COMPONENTS TextEditor)
target_link_libraries(mytarget PRIVATE KF6::TextEditor)
Since: 5.66)
Inherits: QWidget and KXMLGUIClient

Public Types

enum InputMode { NormalInputMode, ViInputMode }
(since 5.33) enum LineType { RealLine, VisibleLine }
enum ViewMode { NormalModeInsert, NormalModeOverwrite, ViModeNormal, ViModeInsert, ViModeVisual, …, ViModeReplace }

Public Functions

virtual ~View() override
virtual void abortCompletion() = 0
(since 6.0) virtual KTextEditor::AbstractAnnotationItemDelegate *annotationItemDelegate() const = 0
virtual KTextEditor::AnnotationModel *annotationModel() const = 0
virtual bool blockSelection() const = 0
virtual QList<KTextEditor::CodeCompletionModel *> codeCompletionModels() const = 0
virtual QStringList configKeys() const = 0
virtual QVariant configValue(const QString &key) = 0
virtual QMenu *contextMenu() const = 0
virtual KTextEditor::Cursor coordinatesToCursor(const QPoint &coord) const = 0
virtual KTextEditor::Cursor cursorPosition() const = 0
virtual QPoint cursorPositionCoordinates() const = 0
virtual KTextEditor::Cursor cursorPositionVirtual() const = 0
(since 5.95) QList<KTextEditor::Cursor> cursorPositions() const
virtual QPoint cursorToCoordinate(KTextEditor::Cursor cursor) const = 0
virtual QMenu *defaultContextMenu(QMenu *menu = nullptr) const = 0
virtual QExplicitlySharedDataPointer<KTextEditor::Attribute> defaultStyleAttribute(KSyntaxHighlighting::Theme::TextStyle defaultStyle) const = 0
virtual KTextEditor::Document *document() const = 0
(since 5.33) int firstDisplayedLine(KTextEditor::View::LineType lineType = RealLine) const
virtual void forceCompletion() = 0
(since 6.0) virtual QScrollBar *horizontalScrollBar() const = 0
bool insertTemplate(KTextEditor::Cursor insertPosition, const QString &templateString, const QString &script = QString())
virtual bool insertText(const QString &text)
virtual bool isAnnotationBorderVisible() const = 0
virtual bool isAutomaticInvocationEnabled() const = 0
virtual bool isCompletionActive() const = 0
bool isStatusBarEnabled() const
(since 5.33) int lastDisplayedLine(KTextEditor::View::LineType lineType = RealLine) const
virtual QList<KTextEditor::AttributeBlock> lineAttributes(int line) = 0
virtual KTextEditor::MainWindow *mainWindow() const = 0
(since 5.33) KTextEditor::Cursor maxScrollPosition() const
virtual bool mouseTrackingEnabled() const = 0
virtual bool print() = 0
virtual void printPreview() = 0
virtual void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) = 0
virtual void registerCompletionModel(KTextEditor::CodeCompletionModel *model) = 0
virtual void registerInlineNoteProvider(KTextEditor::InlineNoteProvider *provider) = 0
virtual void registerTextHintProvider(KTextEditor::TextHintProvider *provider) = 0
virtual bool removeSelection() = 0
virtual bool removeSelectionText() = 0
virtual bool selection() const = 0
virtual KTextEditor::Range selectionRange() const = 0
(since 5.95) QList<KTextEditor::Range> selectionRanges() const
virtual QString selectionText() const = 0
virtual void setAnnotationBorderVisible(bool visible) = 0
(since 6.0) virtual void setAnnotationItemDelegate(KTextEditor::AbstractAnnotationItemDelegate *delegate) = 0
virtual void setAnnotationModel(KTextEditor::AnnotationModel *model) = 0
(since 6.0) virtual void setAnnotationUniformItemSizes(bool uniformItemSizes) = 0
virtual void setAutomaticInvocationEnabled(bool enabled = true) = 0
virtual bool setBlockSelection(bool on) = 0
virtual void setConfigValue(const QString &key, const QVariant &value) = 0
virtual void setContextMenu(QMenu *menu) = 0
virtual bool setCursorPosition(KTextEditor::Cursor position) = 0
(since 5.95) void setCursorPositions(const QList<KTextEditor::Cursor> &positions)
(since 5.33) void setHorizontalScrollPosition(int x)
virtual bool setMouseTrackingEnabled(bool enable) = 0
(since 5.33) void setScrollPosition(KTextEditor::Cursor cursor)
virtual bool setSelection(KTextEditor::Range range) = 0
(since 5.95) void setSelections(const QList<KTextEditor::Range> &ranges)
void setStatusBarEnabled(bool enable)
virtual void setTextHintDelay(int delay) = 0
(since 5.54) virtual void setViewInputMode(KTextEditor::View::InputMode inputMode) = 0
virtual void startCompletion(KTextEditor::Range word, KTextEditor::CodeCompletionModel *model) = 0
virtual void startCompletion(const KTextEditor::Range &word, const QList<KTextEditor::CodeCompletionModel *> &models = QList<CodeCompletionModel *>(), KTextEditor::CodeCompletionModel::InvocationType invocationType = KTextEditor::CodeCompletionModel::ManualInvocation) = 0
(since 5.33) QRect textAreaRect() const
virtual int textHintDelay() const = 0
(since 5.79) KSyntaxHighlighting::Theme theme() const
(since 6.0) virtual bool uniformAnnotationItemSizes() const = 0
virtual void unregisterCompletionModel(KTextEditor::CodeCompletionModel *model) = 0
virtual void unregisterInlineNoteProvider(KTextEditor::InlineNoteProvider *provider) = 0
virtual void unregisterTextHintProvider(KTextEditor::TextHintProvider *provider) = 0
(since 6.0) virtual QScrollBar *verticalScrollBar() const = 0
virtual KTextEditor::View::InputMode viewInputMode() const = 0
virtual QString viewInputModeHuman() const = 0
virtual KTextEditor::View::ViewMode viewMode() const = 0
virtual QString viewModeHuman() const = 0
virtual void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) = 0

Signals

void annotationActivated(KTextEditor::View *view, int line)
void annotationBorderVisibilityChanged(KTextEditor::View *view, bool visible)
void annotationContextMenuAboutToShow(KTextEditor::View *view, QMenu *menu, int line)
(since 5.79) void configChanged(KTextEditor::View *view)
void contextMenuAboutToShow(KTextEditor::View *view, QMenu *menu)
void cursorPositionChanged(KTextEditor::View *view, KTextEditor::Cursor newPosition)
void focusIn(KTextEditor::View *view)
void focusOut(KTextEditor::View *view)
void horizontalScrollPositionChanged(KTextEditor::View *view)
void mousePositionChanged(KTextEditor::View *view, KTextEditor::Cursor newPosition)
void selectionChanged(KTextEditor::View *view)
void statusBarEnabledChanged(KTextEditor::View *view, bool enabled)
void textInserted(KTextEditor::View *view, KTextEditor::Cursor position, const QString &text)
void verticalScrollPositionChanged(KTextEditor::View *view, KTextEditor::Cursor newPos)
void viewInputModeChanged(KTextEditor::View *view, KTextEditor::View::InputMode mode)
void viewModeChanged(KTextEditor::View *view, KTextEditor::View::ViewMode mode)

Protected Functions

View(KTextEditor::ViewPrivate *impl, QWidget *parent)

Detailed Description

Introduction

The View class represents a single view of a KTextEditor::Document, get the document on which the view operates with document(). A view provides both the graphical representation of the text and the KXMLGUIClient for the actions. The view itself does not provide text manipulation, use the methods from the Document instead. The only method to insert text is insertText(), which inserts the given text at the current cursor position and emits the signal textInserted().

Usually a view is created by using Document::createView(). Furthermore a view can have a context menu. Set it with setContextMenu() and get it with contextMenu().

Merging the View's GUI

A View is derived from the class KXMLGUIClient, so its GUI elements (like menu entries and toolbar items) can be merged into the application's GUI (or into a KXMLGUIFactory) by calling

// view is of type KTextEditor::View*
mainWindow()->guiFactory()->addClient( view );

You can add only one view as client, so if you have several views, you first have to remove the current view, and then add the new one, like this

mainWindow()->guiFactory()->removeClient( currentView );
mainWindow()->guiFactory()->addClient( newView );

Text Selection

As the view is a graphical text editor it provides normal and block text selection. You can check with selection() whether a selection exists. removeSelection() will remove the selection without removing the text, whereas removeSelectionText() also removes both, the selection and the selected text. Use selectionText() to get the selected text and setSelection() to specify the selected text range. The signal selectionChanged() is emitted whenever the selection changed.

Cursor Positions

A view has one Cursor which represents a line/column tuple. Two different kinds of cursor positions are supported: first is the real cursor position where a tab character only counts one character. Second is the virtual cursor position, where a tab character counts as many spaces as defined. Get the real position with cursorPosition() and the virtual position with cursorPositionVirtual(). Set the real cursor position with setCursorPosition(). The signal cursorPositionChanged() is emitted whenever the cursor position changed.

Screen coordinates of the current text cursor position in pixels are obtained through cursorPositionCoordinates(). Further conversion of screen pixel coordinates and text cursor positions are provided by cursorToCoordinate() and coordinatesToCursor().

Mouse Tracking

It is possible to get notified via the signal mousePositionChanged() for mouse move events, if mouseTrackingEnabled() returns true. Mouse tracking can be turned on/off by calling setMouseTrackingEnabled(). If an editor implementation does not support mouse tracking, mouseTrackingEnabled() will always return false.

Input/View Modes

A view supports several input modes. Common input modes are NormalInputMode and ViInputMode. Which input modes the editor supports depends on the implementation. The getter viewInputMode() returns enum InputMode representing the current mode.

Input modes can have their own view modes. In case of default NormalInputMode those are NormalModeInsert and NormalModeOverwrite. You can use viewMode() getter to obtain those.

For viewMode() and viewInputMode() there are also variants with Human suffix, which returns the human readable representation (i18n) usable for displaying in user interface.

Whenever the input/view mode changes the signals viewInputModeChanged()/viewModeChanged() are emitted.

View Config

Config provides methods to access and modify the low level config information for a given View KTextEditor::View has support for the following keys:

KeyTypeDescription
line-numbers[bool]show/hide line numbers
icon-bar[bool]show/hide icon bar
folding-bar[bool]show/hide the folding bar
folding-preview[bool]enable/disable folding preview when mouse hovers on folded region
dynamic-word-wrap[bool]enable/disable dynamic word wrap
background-color[QColor]read/set the default background color
selection-color[QColor]read/set the default color for selections
search-highlight-color[QColor]read/set the background color for search
replace-highlight-color[QColor]read/set the background color for replaces
default-mark-type[uint]read/set the default mark type
allow-mark-menu[bool]enable/disable the menu shown when right clicking on the left gutter. When disabled, click on the gutter will always set or clear the mark of default type.
icon-border-color[QColor]read/set the icon border color (on the left with the line numbers)
folding-marker-color[QColor]read/set folding marker colors (in the icon border)
line-number-color[QColor]read/set line number colors (in the icon border)
current-line-number-color[QColor]read/set current line number color (in the icon border)
modification-markers[bool]read/set whether the modification markers are shown
word-count[bool]enable/disable the counting of words and characters in the statusbar
line-count[bool]show/hide the total number of lines in the status bar (
scrollbar-minimap[bool]enable/disable scrollbar minimap
scrollbar-preview[bool]enable/disable scrollbar text preview on hover
font[QFont]change the font
theme[QString]change the theme
word-completion-minimal-word-length[int]minimal word length to trigger word completion
enter-to-insert-completion[bool]enable/disable whether pressing enter inserts completion

You can retrieve the value of a config key using configValue() and set the value for a config key using setConfigValue().

Annotation Interface

The Annotation Interface allows to do these things:

  1. show/hide the annotation border along with the possibility to add actions into its context menu.
  2. set a separate AnnotationModel for the View: Note that this interface inherits the AnnotationInterface.
  3. set a custom AbstractAnnotationItemDelegate for the View.

For a more detailed explanation about whether you want to set a custom delegate for rendering the annotations, read the detailed documentation about the AbstractAnnotationItemDelegate.

Inline Notes

The inline notes interface provides a way to render arbitrary things in the text. The text layout of the line is adapted to create space for the note. Possible applications include showing a name of a function parameter in a function call or rendering a square with a color preview next to CSS color property.

"Inline note showing a CSS color preview"

To register as inline note provider, call registerInlineNoteProvider() with an instance that inherits InlineNoteProvider. Finally, make sure you remove your inline note provider by calling unregisterInlineNoteProvider().

Text Hints

The text hint interface provides a way to show tool tips for text located under the mouse. Possible applications include showing a value of a variable when debugging an application, or showing a complete path of an include directive.

"Text hint showing the contents of a variable"

To register as text hint provider, call registerTextHintProvider() with an instance that inherits TextHintProvider. Finally, make sure you remove your text hint provider by calling unregisterTextHintProvider().

Text hints are shown after the user hovers with the mouse for a delay of textHintDelay() milliseconds over the same word. To change the delay, call setTextHintDelay().

Completion Interface

The Completion Interface is designed to provide code completion functionality for a KTextEditor::View. This interface provides the basic mechanisms to display a list of completions, update this list according to user input, and allow the user to select a completion.

Essentially, this provides an item view for the available completions. In order to use this interface, you will need to implement a CodeCompletionModel that generates the relevant completions given the current input.

More information about interfaces for the view can be found in: kte_group_view_extensions.

See also KTextEditor::Document and KXMLGUIClient.

Member Type Documentation

enum View::InputMode

Possible input modes. These correspond to various modes the text editor might be in.

ConstantValueDescription
KTextEditor::View::NormalInputMode0Normal mode.
KTextEditor::View::ViInputMode1Vi mode. The view will behave like the editor vi(m).

[since 5.33] enum View::LineType

Possible line types.

ConstantValueDescription
KTextEditor::View::RealLine0A real line.
KTextEditor::View::VisibleLine1A visible line. Line that is not folded.

This enum was introduced in 5.33.

enum View::ViewMode

Possible view modes the text editor might be in.

ConstantValueDescription
KTextEditor::View::NormalModeInsert0Insert mode. Characters will be added.
KTextEditor::View::NormalModeOverwrite1Overwrite mode. Characters will be replaced.
KTextEditor::View::ViModeNormal10 
KTextEditor::View::ViModeInsert11 
KTextEditor::View::ViModeVisual12 
KTextEditor::View::ViModeVisualLine13 
KTextEditor::View::ViModeVisualBlock14 
KTextEditor::View::ViModeReplace15 

Member Function Documentation

[protected] View::View(KTextEditor::ViewPrivate *impl, QWidget *parent)

Constructor.

Create a view attached to the widget parent.

Pass it the internal implementation to store a d-pointer.

impl is the d-pointer to use

parent is the parent widget

See also Document::createView().

[override virtual noexcept] View::~View()

Virtual destructor.

[pure virtual] void View::abortCompletion()

Abort the currently displayed code completion without executing any currently selected completion. This is safe, even when the completion box is not currently active.

See also isCompletionActive().

[signal] void View::annotationActivated(KTextEditor::View *view, int line)

This signal is emitted when an entry on the annotation border was activated, for example by clicking or double-clicking it. This follows the KDE wide setting for activation via click or double-clcik

view is the view to which the activated border belongs to

line is the document line that the activated position belongs to

[signal] void View::annotationBorderVisibilityChanged(KTextEditor::View *view, bool visible)

This signal is emitted when the annotation border is shown or hidden.

view is the view to which the border belongs to

visible is the current visibility state

[signal] void View::annotationContextMenuAboutToShow(KTextEditor::View *view, QMenu *menu, int line)

This signal is emitted before a context menu is shown on the annotation border for the given line and view.

Note: Kate Part implementation detail: In Kate Part, the menu has an entry to hide the annotation border.

view is the view that the annotation border belongs to

menu is the context menu that will be shown

line is the annotated line for which the context menu is shown

[pure virtual, since 6.0] KTextEditor::AbstractAnnotationItemDelegate *View::annotationItemDelegate() const

Returns the currently used AbstractAnnotationItemDelegate

Returns the current AbstractAnnotationItemDelegate

This function was introduced in 6.0.

See also setAnnotationItemDelegate().

[pure virtual] KTextEditor::AnnotationModel *View::annotationModel() const

Returns the currently set AnnotationModel or 0 if there's none set

See also setAnnotationModel().

[pure virtual] bool View::blockSelection() const

Get the status of the selection mode. true indicates that block selection mode is on. If this is true, selections applied via the SelectionInterface are handled as block selections and the Copy&Paste functions work on rectangular blocks of text rather than normal.

Returns true, if block selection mode is enabled, otherwise false

See also setBlockSelection().

[pure virtual] QList<KTextEditor::CodeCompletionModel *> View::codeCompletionModels() const

Obtain the list of registered code completion models.

Returns a list of a models that are currently registered

See also registerCompletionModel(CodeCompletionModel*).

[signal, since 5.79] void View::configChanged(KTextEditor::View *view)

This signal is emitted whenever the current view configuration is changed.

view is the view whose config has changed

This function was introduced in 5.79.

[pure virtual] QStringList View::configKeys() const

Get a list of all available keys.

[pure virtual] QVariant View::configValue(const QString &key)

Get a value for the key.

See also setConfigValue().

[pure virtual] QMenu *View::contextMenu() const

Get the context menu for this view. The return value can be NULL if no context menu object was set and kxmlgui is not initialized yet. If there is no user set menu, the kxmlgui menu is returned. Do not delete this menu, if if it is the xmlgui menu.

Returns context menu object

See also setContextMenu().

[signal] void View::contextMenuAboutToShow(KTextEditor::View *view, QMenu *menu)

Signal which is emitted immediately prior to showing the current context menu.

view is the related view

[pure virtual] KTextEditor::Cursor View::coordinatesToCursor(const QPoint &coord) const

Get the text-cursor in the document from the screen coordinates, relative to the view widget.

To map a cursor to pixel coordinates (the reverse transformation) use cursorToCoordinate().

coord is the coordinates relative to the view widget

Returns cursor in the View, that points onto the character under the given coordinate. May be KTextEditor::Cursor::invalid().

[pure virtual] KTextEditor::Cursor View::cursorPosition() const

Get the view's current cursor position. A TAB character is handled as only one character.

Returns current cursor position

See also setCursorPosition().

[signal] void View::cursorPositionChanged(KTextEditor::View *view, KTextEditor::Cursor newPosition)

This signal is emitted whenever the view's cursor position changed.

view is the view which emitted the signal

newPosition is the new position of the cursor (Kate will pass the real cursor position, not the virtual)

See also cursorPosition() and cursorPositionVirtual().

[pure virtual] QPoint View::cursorPositionCoordinates() const

Get the screen coordinates (x, y) of the cursor position in pixels. The returned coordinates are relative to the View such that (0, 0) represents tht top-left corner of the View.

If global screen coordinates are required, e.g. for showing a QToolTip, convert the view coordinates to global screen coordinates as follows:

QPoint viewCoordinates = view->cursorPositionCoordinates();
QPoint globalCoorinates = view->mapToGlobal(viewCoordinates);

Returns cursor screen coordinates

See also cursorToCoordinate() and coordinatesToCursor().

[pure virtual] KTextEditor::Cursor View::cursorPositionVirtual() const

Get the current virtual cursor position, virtual means the tabulator character (TAB) counts multiple characters, as configured by the user (e.g. one TAB is 8 spaces). The virtual cursor position provides access to the user visible values of the current cursor position.

Returns virtual cursor position

See also cursorPosition().

[since 5.95] QList<KTextEditor::Cursor> View::cursorPositions() const

Get the view's current cursor positions. A TAB character is handled as only one character.

The returned vector contains the primary cursor as first element.

Returns all currently existing cursors

This function was introduced in 5.95.

See also setCursorPositions().

[pure virtual] QPoint View::cursorToCoordinate(KTextEditor::Cursor cursor) const

Get the screen coordinates (x, y) of the supplied cursor relative to the view widget in pixels. Thus, (0, 0) represents the top left hand of the view widget.

To map pixel coordinates to a Cursor position (the reverse transformation) use coordinatesToCursor().

cursor is the cursor to determine coordinate for.

Returns cursor screen coordinates relative to the view widget

See also cursorPositionCoordinates() and coordinatesToCursor().

[pure virtual] QMenu *View::defaultContextMenu(QMenu *menu = nullptr) const

Populate menu with default text editor actions. If menu is null, a menu will be created with the view as its parent.

Note: to use this menu, you will next need to call setContextMenu(), as this does not assign the new context menu.

Warning: This contains only basic options from the editor component (katepart). Plugins are not merged/integrated into it! If you want to be a better citizen and take full advantage of KTextEditor plugins do something like:

KXMLGUIClient* client = view;
// search parent XmlGuiClient
while (client->parentClient()) {
  client = client->parentClient();
}

if (client->factory()) {
  const QList<QWidget*> menuContainers = client->factory()->containers("menu");
  for (QWidget *w : menuContainers) {
    if (w->objectName() == "ktexteditor_popup") {
      // do something with the menu (ie adding an onshow handler)
      break;
    }
  }
}

Warning: or simply use the aboutToShow, aboutToHide signals !!!!!

menu is the menu to be populated, or null to create a new menu.

Returns the menu, whether created or passed initially

[pure virtual] QExplicitlySharedDataPointer<KTextEditor::Attribute> View::defaultStyleAttribute(KSyntaxHighlighting::Theme::TextStyle defaultStyle) const

Returns the attribute for the default style defaultStyle.

defaultStyle default style to get the attribute for

See also KTextEditor::Attribute.

[pure virtual] KTextEditor::Document *View::document() const

Get the view's document, that means the view is a view of the returned document. Returns the view's document

[since 5.33] int View::firstDisplayedLine(KTextEditor::View::LineType lineType = RealLine) const

Get the first displayed line in the view.

Note: If code is folded, many hundred lines can be between firstDisplayedLine() and lastDisplayedLine().

lineType if RealLine (the default), it returns the real line number accounting for folded regions. In that case it walks over all folded regions O(n) for n == number of folded ranges

Returns the first displayed line

This function was introduced in 5.33.

See also lastDisplayedLine().

[signal] void View::focusIn(KTextEditor::View *view)

This signal is emitted whenever the view gets the focus.

view is the view which gets focus

See also focusOut().

[signal] void View::focusOut(KTextEditor::View *view)

This signal is emitted whenever the view loses the focus.

view is view which lost focus

See also focusIn().

[pure virtual] void View::forceCompletion()

Force execution of the currently selected completion, and hide the code completion box.

[pure virtual, since 6.0] QScrollBar *View::horizontalScrollBar() const

Returns The horizontal scrollbar of this view

This function was introduced in 6.0.

[signal] void View::horizontalScrollPositionChanged(KTextEditor::View *view)

This signal should be emitted whenever the view is scrolled horizontally.

view is the view which emitted the signal

bool View::insertTemplate(KTextEditor::Cursor insertPosition, const QString &templateString, const QString &script = QString())

Insert a template into the document. The template can have editable fields which can be filled by the user. You can create editable fields with ${fieldname}; multiple fields with the same name will have their contents synchronized automatically, and only the first one is editable in this case. Fields can have a default value specified by writing ${fieldname=default}. Note that `default' is a JavaScript expression and strings need to be quoted. You can also provide a piece of JavaScript for more complex logic. To create a field which provides text based on a JS function call and the values of the other, editable fields, use the ${func()} syntax. func() must be a callable object defined in script. You can pass arguments to the function by just writing any constant expression or a field name.

insertPosition is where to insert the template

templateString is the template to insert using the above syntax

script is a script with functions which can be used in templateString

Returns true on success, false if insertion failed (e.g. read-only mode)

[virtual] bool View::insertText(const QString &text)

This is a convenience function which inserts text at the view's current cursor position. You do not necessarily need to reimplement it, except you want to do some special things.

text is the text to be inserted

Returns true on success of insertion, otherwise false

See also textInserted().

[pure virtual] bool View::isAnnotationBorderVisible() const

Returns true if he View's annotation border is visible.

[pure virtual] bool View::isAutomaticInvocationEnabled() const

Returns true if automatic code completion invocation is enabled.

[pure virtual] bool View::isCompletionActive() const

Returns true if the code completion box is currently displayed.

bool View::isStatusBarEnabled() const

Is the status bar enabled?

Returns status bar enabled?

[since 5.33] int View::lastDisplayedLine(KTextEditor::View::LineType lineType = RealLine) const

Get the last displayed line in the view.

Note: If code is folded, many hundred lines can be between firstDisplayedLine() and lastDisplayedLine().

lineType is if RealLine (the default), it returns the real line number accounting for folded regions. In that case it walks over all folded regions. O(n) for n == number of folded ranges

Returns the last displayed line

This function was introduced in 5.33.

See also firstDisplayedLine().

[pure virtual] QList<KTextEditor::AttributeBlock> View::lineAttributes(int line)

Get the list of AttributeBlocks for a given line in the document.

Returns list of AttributeBlocks for given line.

[pure virtual] KTextEditor::MainWindow *View::mainWindow() const

Get the view's main window, if any

Returns the view's main window, will always return at least some non-nullptr dummy interface

[since 5.33] KTextEditor::Cursor View::maxScrollPosition() const

Get the cursor corresponding to the maximum position the view can vertically scroll to.

Returns cursor position of the maximum vertical scroll position.

This function was introduced in 5.33.

[signal] void View::mousePositionChanged(KTextEditor::View *view, KTextEditor::Cursor newPosition)

This signal is emitted whenever the position of the mouse changes over this view. If the mouse moves off the view, an invalid cursor position should be emitted, i.e. Cursor::invalid().

Note: If mouseTrackingEnabled() returns false, this signal is never emitted.

view is the view which emitted the signal

newPosition is the new position of the mouse or Cursor::invalid(), if the mouse moved out of the view.

See also mouseTrackingEnabled().

[pure virtual] bool View::mouseTrackingEnabled() const

Check, whether mouse tracking is enabled.

Mouse tracking is required to have the signal mousePositionChanged() emitted.

Returns true, if mouse tracking is enabled, otherwise false

See also setMouseTrackingEnabled() and mousePositionChanged().

[pure virtual] bool View::print()

Print the document. This should result in showing the print dialog.

Returns true if document was printed

[pure virtual] void View::printPreview()

Shows the print preview dialog/

[pure virtual] void View::readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>())

Read session settings from the given config.

Known flags: none atm

config is the KConfigGroup to read the session settings from

flags is additional flags

See also writeSessionConfig().

[pure virtual] void View::registerCompletionModel(KTextEditor::CodeCompletionModel *model)

Register a new code completion model.

model is new completion model

See also unregisterCompletionModel().

[pure virtual] void View::registerInlineNoteProvider(KTextEditor::InlineNoteProvider *provider)

Register the inline note provider provider.

Whenever a line is painted, the provider will be queried for notes that should be painted in it. When the provider is about to be destroyed, make sure to call unregisterInlineNoteProvider() to avoid a dangling pointer.

provider inline note provider

See also unregisterInlineNoteProvider() and KTextEditor::InlineNoteProvider.

[pure virtual] void View::registerTextHintProvider(KTextEditor::TextHintProvider *provider)

Register the text hint provider provider.

Whenever the user hovers over text, provider will be asked for a text hint. When the provider is about to be destroyed, make sure to call unregisterTextHintProvider() to avoid a dangling pointer.

provider text hint provider

See also unregisterTextHintProvider() and KTextEditor::TextHintProvider.

[pure virtual] bool View::removeSelection()

Remove the view's current selection, without deleting the selected text.

Returns true on success, otherwise false

See also removeSelectionText().

[pure virtual] bool View::removeSelectionText()

Remove the view's current selection including the selected text.

Returns true on success, otherwise false

See also removeSelection().

[pure virtual] bool View::selection() const

Query the view whether it has selected text, i.e. whether a selection exists.

Returns true if a text selection exists, otherwise false

See also setSelection() and selectionRange().

[signal] void View::selectionChanged(KTextEditor::View *view)

This signal is emitted whenever the view's selection changes.

Note: If the mode switches from block selection to normal selection or vice versa this signal should also be emitted.

view is the view in which the selection changed

See also selection(), selectionRange(), and selectionText().

[pure virtual] KTextEditor::Range View::selectionRange() const

Get the range occupied by the current selection.

Returns selection range, valid only if a selection currently exists.

See also setSelection().

[since 5.95] QList<KTextEditor::Range> View::selectionRanges() const

Get the ranges occupied by the current selections.

Returns selection ranges, valid only if a selection currently exists.

This function was introduced in 5.95.

See also setSelections().

[pure virtual] QString View::selectionText() const

Get the view's selected text.

Returns the selected text

See also setSelection().

[pure virtual] void View::setAnnotationBorderVisible(bool visible)

This function can be used to show or hide the annotation border The annotation border is hidden by default.

visible if true the annotation border is shown, otherwise hidden

See also isAnnotationBorderVisible().

[pure virtual, since 6.0] void View::setAnnotationItemDelegate(KTextEditor::AbstractAnnotationItemDelegate *delegate)

Sets the AbstractAnnotationItemDelegate for this view and the model to provide custom rendering of annotation information for each line. Ownership is not transferred.

delegate is the new AbstractAnnotationItemDelegate, or nullptr to reset to the default delegate

This function was introduced in 6.0.

See also annotationItemDelegate().

[pure virtual] void View::setAnnotationModel(KTextEditor::AnnotationModel *model)

Sets a new AnnotationModel for this document to provide annotation information for each line.

model is the new AnnotationModel

See also annotationModel().

[pure virtual, since 6.0] void View::setAnnotationUniformItemSizes(bool uniformItemSizes)

This function can be used to declare whether it is known that the annotation items rendered by the set delegate all have the same size. This enables the view to do some optimizations for performance purposes.

By default the value of this property is false .

uniformItemSizes if true the annotation items are considered to all have the same size

This function was introduced in 6.0.

[pure virtual] void View::setAutomaticInvocationEnabled(bool enabled = true)

Enable (if enabled is true) or disable automatic code completion invocation.

See also isAutomaticInvocationEnabled().

[pure virtual] bool View::setBlockSelection(bool on)

Set block selection mode to state on.

on if true, block selection mode is turned on, otherwise off

Returns true on success, otherwise false

See also blockSelection().

[pure virtual] void View::setConfigValue(const QString &key, const QVariant &value)

Set a the key's value to value.

See also configValue().

[pure virtual] void View::setContextMenu(QMenu *menu)

Set a context menu for this view to menu.

Note: any previously assigned menu is not deleted. If you are finished with the previous menu, you may delete it.

Warning: Use this with care! Plugin xml gui clients are not merged into this menu!

Warning: !!!!!! DON'T USE THIS FUNCTION, UNLESS YOU ARE SURE YOU DON'T WANT PLUGINS TO WORK !!!!!!

menu is the new context menu object for this view

See also contextMenu().

[pure virtual] bool View::setCursorPosition(KTextEditor::Cursor position)

Set the view's new cursor to position. A TAB character is handled as only on character.

position is the new cursor position

Returns true on success, otherwise false

See also cursorPosition().

[since 5.95] void View::setCursorPositions(const QList<KTextEditor::Cursor> &positions)

Set the view's new cursors to positions. A TAB character is handled as only on character.

This allows to create multiple cursors in this view.

The first passed position will be used for the primary cursor just like if you would call setCursorPosition().

positions is the new cursor positions

This function was introduced in 5.95.

See also cursorPositions().

[since 5.33] void View::setHorizontalScrollPosition(int x)

Horizontally scroll view to position.

x is the pixel position to scroll to.

This function was introduced in 5.33.

[pure virtual] bool View::setMouseTrackingEnabled(bool enable)

Try to enable or disable mouse tracking according to enable. The return value contains the state of mouse tracking after the request. Mouse tracking is required to have the mousePositionChanged() signal emitted.

Note: Implementation Notes: An implementation is not forced to support this, and should always return false if it does not have support.

enable if true, try to enable mouse tracking, otherwise disable it.

Returns the current state of mouse tracking

See also mouseTrackingEnabled() and mousePositionChanged().

[since 5.33] void View::setScrollPosition(KTextEditor::Cursor cursor)

Scroll view to cursor.

cursor is the cursor position to scroll to.

This function was introduced in 5.33.

[pure virtual] bool View::setSelection(KTextEditor::Range range)

Set the view's selection to the range selection. The old selection will be discarded.

range is the range of the new selection

Returns true on success, otherwise false (e.g. when the cursor range is invalid)

See also selectionRange() and selection().

[since 5.95] void View::setSelections(const QList<KTextEditor::Range> &ranges)

Set the view's selections to the ranges selection. The old selection will be discarded.

ranges is the ranges of the new selections

This function was introduced in 5.95.

See also selectionRanges() and selection().

void View::setStatusBarEnabled(bool enable)

Show/hide the status bar of the view. Per default, the status bar is enabled.

enable should the status bar be enabled?

See also isStatusBarEnabled().

[pure virtual] void View::setTextHintDelay(int delay)

Set the text hint delay to delay milliseconds.

The delay specifies the time the user needs to hover over the text before the tool tip is shown. Therefore, delay should not be too large, a value of 500 milliseconds is recommended and set by default.

If delay is <= 0, the default delay will be set.

delay is the tool tip delay in milliseconds

See also textHintDelay().

[pure virtual, since 5.54] void View::setViewInputMode(KTextEditor::View::InputMode inputMode)

Set the view's new input mode.

inputMode is new InputMode value

This function was introduced in 5.54.

See also viewInputMode().

[pure virtual] void View::startCompletion(KTextEditor::Range word, KTextEditor::CodeCompletionModel *model)

Invoke code completion over a given range word with a specific model.

[pure virtual] void View::startCompletion(const KTextEditor::Range &word, const QList<KTextEditor::CodeCompletionModel *> &models = QList<CodeCompletionModel *>(), KTextEditor::CodeCompletionModel::InvocationType invocationType = KTextEditor::CodeCompletionModel::ManualInvocation)

Invoke code completion over a given range, with specific models and invocation type.

models is the list of models to start. If this is an empty list, all registered models are started.

[signal] void View::statusBarEnabledChanged(KTextEditor::View *view, bool enabled)

This signal is emitted whenever the status bar of view is toggled.

enabled Whether the status bar is currently enabled or not

[since 5.33] QRect View::textAreaRect() const

Get the view's text area rectangle excluding border, scrollbars, etc.

Returns the view's text area rectangle

This function was introduced in 5.33.

[pure virtual] int View::textHintDelay() const

Get the text hint delay in milliseconds. By default, the text hint delay is set to 500 milliseconds. It can be changed by calling setTextHintDelay().

See also setTextHintDelay().

[signal] void View::textInserted(KTextEditor::View *view, KTextEditor::Cursor position, const QString &text)

This signal is emitted from view whenever the users inserts text at position, that means the user typed/pasted text.

view is the view in which the text was inserted

position is the position where the text was inserted

text is the inserted text

See also insertText().

[since 5.79] KSyntaxHighlighting::Theme View::theme() const

Get the current active theme of this view. Might change during runtime, configChanged() will be emitted in that cases.

Returns current active theme

This function was introduced in 5.79.

[pure virtual, since 6.0] bool View::uniformAnnotationItemSizes() const

Returns true if the annotation items all have the same size.

This function was introduced in 6.0.

[pure virtual] void View::unregisterCompletionModel(KTextEditor::CodeCompletionModel *model)

Unregister a code completion model.

model is the model that should be unregistered

See also registerCompletionModel().

[pure virtual] void View::unregisterInlineNoteProvider(KTextEditor::InlineNoteProvider *provider)

Unregister the inline note provider provider.

provider inline note provider to unregister

See also registerInlineNoteProvider() and KTextEditor::InlineNoteProvider.

[pure virtual] void View::unregisterTextHintProvider(KTextEditor::TextHintProvider *provider)

Unregister the text hint provider provider.

provider text hint provider to unregister

See also registerTextHintProvider() and KTextEditor::TextHintProvider.

[pure virtual, since 6.0] QScrollBar *View::verticalScrollBar() const

Returns The vertical scrollbar of this view

This function was introduced in 6.0.

[signal] void View::verticalScrollPositionChanged(KTextEditor::View *view, KTextEditor::Cursor newPos)

This signal should be emitted whenever the view is scrolled vertically.

view is the view which emitted the signal

newPos is the new scroll position

[pure virtual] KTextEditor::View::InputMode View::viewInputMode() const

Get the view's current input mode. The current mode can be NormalInputMode and ViInputMode. For human translated version

Returns the current input mode of this view

See also setViewInputMode(), viewInputModeHuman, and viewInputModeChanged().

[signal] void View::viewInputModeChanged(KTextEditor::View *view, KTextEditor::View::InputMode mode)

This signal is emitted whenever the view's input mode changes.

view is the view which changed its input mode

mode is the new input mode

See also viewInputMode().

[pure virtual] QString View::viewInputModeHuman() const

Get the view's current input mode in human readable form. The string should be translated (i18n). For id like version

Returns the current input mode of this view in human readable form

See also viewInputMode.

[pure virtual] KTextEditor::View::ViewMode View::viewMode() const

Get the current view mode/state. This can be used to detect the view's current mode. For example NormalInputMode, ViInputMode or whatever other input modes are supported.

Returns current view mode/state

See also viewModeChanged() and viewModeHuman().

[signal] void View::viewModeChanged(KTextEditor::View *view, KTextEditor::View::ViewMode mode)

This signal is emitted whenever the view mode of view changes.

view is the view which changed its mode

mode is the new view mode

See also viewMode().

[pure virtual] QString View::viewModeHuman() const

Get the current view mode state.

This can be used to visually indicate the view's current mode, for example INSERT mode, OVERWRITE mode or COMMAND mode - or whatever other edit modes are supported. The string should be translated (i18n), as this is a user aimed representation of the view state, which should be shown in the GUI, for example in the status bar. This string may be rich-text.

Returns Human-readable version of the view mode state

See also viewModeChanged().

[pure virtual] void View::writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>())

Write session settings to the config. See readSessionConfig() for more details.

config is the KConfigGroup to write the session settings to

flags is additional flags (see the known flags listed in readSessionConfig())

See also readSessionConfig().