1/* This file is part of the KDE libraries
2 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
3 Copyright (C) 2005 Dominik Haumann (dhdev@gmx.de) (documentation)
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef KTEXTEDITOR_VIEW_H
22#define KTEXTEDITOR_VIEW_H
23
24#include <ktexteditor_export.h>
25#include <ktexteditor/attribute.h>
26#include <ktexteditor/document.h>
27#include <ktexteditor/range.h>
28
29// gui merging
30#include <KXMLGUIClient>
31
32// widget
33#include <QWidget>
34
35class QMenu;
36
37class KConfigGroup;
38
39namespace KTextEditor
40{
41
42class Document;
43class MainWindow;
44class ViewPrivate;
45
46/**
47 * \brief A text widget with KXMLGUIClient that represents a Document.
48 *
49 * Topics:
50 * - \ref view_intro
51 * - \ref view_hook_into_gui
52 * - \ref view_selection
53 * - \ref view_cursors
54 * - \ref view_mouse_tracking
55 * - \ref view_modes
56 * - \ref view_extensions
57 *
58 * \section view_intro Introduction
59 *
60 * The View class represents a single view of a KTextEditor::Document,
61 * get the document on which the view operates with document().
62 * A view provides both the graphical representation of the text and the
63 * KXMLGUIClient for the actions. The view itself does not provide
64 * text manipulation, use the methods from the Document instead. The only
65 * method to insert text is insertText(), which inserts the given text
66 * at the current cursor position and emits the signal textInserted().
67 *
68 * Usually a view is created by using Document::createView().
69 * Furthermore a view can have a context menu. Set it with setContextMenu()
70 * and get it with contextMenu().
71 *
72 * \section view_hook_into_gui Merging the View's GUI
73 *
74 * A View is derived from the class KXMLGUIClient, so its GUI elements (like
75 * menu entries and toolbar items) can be merged into the application's GUI
76 * (or into a KXMLGUIFactory) by calling
77 * \code
78 * // view is of type KTextEditor::View*
79 * mainWindow()->guiFactory()->addClient( view );
80 * \endcode
81 * You can add only one view as client, so if you have several views, you first
82 * have to remove the current view, and then add the new one, like this
83 * \code
84 * mainWindow()->guiFactory()->removeClient( currentView );
85 * mainWindow()->guiFactory()->addClient( newView );
86 * \endcode
87 *
88 * \section view_selection Text Selection
89 *
90 * As the view is a graphical text editor it provides \e normal and \e block
91 * text selection. You can check with selection() whether a selection exists.
92 * removeSelection() will remove the selection without removing the text,
93 * whereas removeSelectionText() also removes both, the selection and the
94 * selected text. Use selectionText() to get the selected text and
95 * setSelection() to specify the selected text range. The signal
96 * selectionChanged() is emitted whenever the selection changed.
97 *
98 * \section view_cursors Cursor Positions
99 *
100 * A view has one Cursor which represents a line/column tuple. Two different
101 * kinds of cursor positions are supported: first is the \e real cursor
102 * position where a \e tab character only counts one character. Second is the
103 * \e virtual cursor position, where a \e tab character counts as many
104 * spaces as defined. Get the real position with cursorPosition() and the
105 * virtual position with cursorPositionVirtual(). Set the real cursor
106 * position with setCursorPosition(). The signal cursorPositionChanged() is
107 * emitted whenever the cursor position changed.
108 *
109 * Screen coordinates of the current text cursor position in pixels are obtained
110 * through cursorPositionCoordinates(). Further conversion of screen pixel
111 * coordinates and text cursor positions are provided by cursorToCoordinate()
112 * and coordinatesToCursor().
113 *
114 * \section view_mouse_tracking Mouse Tracking
115 *
116 * It is possible to get notified via the signal mousePositionChanged() for
117 * mouse move events, if mouseTrackingEnabled() returns \e true. Mouse tracking
118 * can be turned on/off by calling setMouseTrackingEnabled(). If an editor
119 * implementation does not support mouse tracking, mouseTrackingEnabled() will
120 * always return \e false.
121 *
122 * \section view_modes Input/View Modes
123 *
124 * A view supports several input modes. Common input modes are
125 * \e NormalInputMode and \e ViInputMode. Which input modes the editor supports depends on the
126 * implementation. The getter viewInputMode() returns enum \InputMode representing the current mode.
127 *
128 * Input modes can have their own view modes. In case of default \e NormalInputMode those are
129 * \e NormalModeInsert and \e NormalModeOverwrite. You can use viewMode() getter to obtain those.
130 *
131 * For viewMode() and viewInputMode() there are also variants with \e Human suffix, which
132 * returns the human readable representation (i18n) usable for displaying in user interface.
133 *
134 * Whenever the input/view mode changes the signals
135 * viewInputModeChanged()/viewModeChanged() are emitted.
136 *
137 * \section view_extensions View Extension Interfaces
138 *
139 * A simple view represents the text of a Document and provides a text cursor,
140 * text selection, edit modes etc.
141 * Advanced concepts like code completion and text hints are defined in the
142 * extension interfaces. An KTextEditor implementation does not need to
143 * support all the extensions. To implement the interfaces multiple
144 * inheritance is used.
145 *
146 * More information about interfaces for the view can be found in
147 * \ref kte_group_view_extensions.
148 *
149 * \see KTextEditor::Document, KTextEditor::CodeCompletionInterface,
150 * KXMLGUIClient
151 * \author Christoph Cullmann \<cullmann@kde.org\>
152 */
153class KTEXTEDITOR_EXPORT View : public QWidget, public KXMLGUIClient
154{
155 Q_OBJECT
156
157protected:
158 /**
159 * Constructor.
160 *
161 * Create a view attached to the widget \p parent.
162 *
163 * Pass it the internal implementation to store a d-pointer.
164 *
165 * \param impl d-pointer to use
166 * \param parent parent widget
167 * \see Document::createView()
168 */
169 View(ViewPrivate *impl, QWidget *parent);
170
171public:
172 /**
173 * Virtual destructor.
174 */
175 virtual ~View();
176
177 /*
178 * Accessor for the document
179 */
180public:
181 /**
182 * Get the view's \e document, that means the view is a view of the
183 * returned document.
184 * \return the view's document
185 */
186 virtual Document *document() const = 0;
187
188 /*
189 * General information about this view
190 */
191public:
192 /**
193 * Possible input modes.
194 * These correspond to various modes the text editor might be in.
195 */
196 enum InputMode {
197 NormalInputMode = 0, /**< Normal Mode. */
198 ViInputMode = 1 /**< Vi mode. The view will behave like the editor vi(m) */
199 };
200
201 /**
202 * Possible view modes
203 * These correspond to various modes the text editor might be in.
204 */
205 enum ViewMode {
206 NormalModeInsert = 0, /**< Insert mode. Characters will be added. */
207 NormalModeOverwrite = 1, /**< Overwrite mode. Characters will be replaced. */
208
209 ViModeNormal = 10,
210 ViModeInsert = 11,
211 ViModeVisual = 12,
212 ViModeVisualLine = 13,
213 ViModeVisualBlock = 14,
214 ViModeReplace = 15
215 };
216
217 /**
218 * Possible line types
219 * \since 5.33
220 */
221 enum LineType {
222 RealLine = 0, /**< Real line */
223 VisibleLine = 1 /**< Visible line. Line that is not folded. */
224 };
225 /**
226 * Get the current view mode/state.
227 * This can be used to detect the view's current mode. For
228 * example \NormalInputMode, \ViInputMode or whatever other input modes are
229 * supported. \see viewModeHuman() for translated version.
230 * \return current view mode/state
231 * \see viewModeChanged()
232 */
233 virtual ViewMode viewMode() const = 0;
234
235 /**
236 * Get the current view mode state.
237 * This can be used to visually indicate the view's current mode, for
238 * example \e INSERT mode, \e OVERWRITE mode or \e COMMAND mode - or
239 * whatever other edit modes are supported. The string should be
240 * translated (i18n), as this is a user aimed representation of the view
241 * state, which should be shown in the GUI, for example in the status bar.
242 * This string may be rich-text.
243 * \return Human-readable version of the view mode state
244 * \see viewModeChanged()
245 */
246 virtual QString viewModeHuman() const = 0;
247
248 /**
249 * Set the view's new input mode.
250 * \param inputMode new InputMode value
251 * \see viewInputMode()
252 * @since 5.54
253 * KF6: make virtual
254 */
255 void setViewInputMode(InputMode inputMode);
256
257 /**
258 * Get the view's current input mode.
259 * The current mode can be \NormalInputMode and \ViInputMode.
260 * For human translated version \see viewInputModeHuman.
261 *
262 * \return the current input mode of this view
263 * \see viewInputModeChanged()
264 */
265 virtual InputMode viewInputMode() const = 0;
266
267 /**
268 * Get the view's current input mode in human readable form.
269 * The string should be translated (i18n). For id like version \see viewInputMode
270 *
271 * \return the current input mode of this view in human readable form
272 */
273 virtual QString viewInputModeHuman() const = 0;
274
275 /**
276 * Get the view's main window, if any
277 * \return the view's main window, will always return at least some non-nullptr dummy interface
278 */
279 virtual KTextEditor::MainWindow *mainWindow() const = 0;
280
281 /*
282 * SIGNALS
283 * following signals should be emitted by the editor view
284 */
285Q_SIGNALS:
286 /**
287 * This signal is emitted whenever the \p view gets the focus.
288 * \param view view which gets focus
289 * \see focusOut()
290 */
291 void focusIn(KTextEditor::View *view);
292
293 /**
294 * This signal is emitted whenever the \p view loses the focus.
295 * \param view view which lost focus
296 * \see focusIn()
297 */
298 void focusOut(KTextEditor::View *view);
299
300 /**
301 * This signal is emitted whenever the view mode of \p view changes.
302 * \param view the view which changed its mode
303 * \param mode new view mode
304 * \see viewMode()
305 */
306 void viewModeChanged(KTextEditor::View *view, KTextEditor::View::ViewMode mode);
307
308 /**
309 * This signal is emitted whenever the \p view's input \p mode changes.
310 * \param view view which changed its input mode
311 * \param mode new input mode
312 * \see viewInputMode()
313 */
314 void viewInputModeChanged(KTextEditor::View *view, KTextEditor::View::InputMode mode);
315
316 /**
317 * This signal is emitted from \p view whenever the users inserts \p text
318 * at \p position, that means the user typed/pasted text.
319 * \param view view in which the text was inserted
320 * \param position position where the text was inserted
321 * \param text the text the user has typed into the editor
322 * \see insertText()
323 */
324 void textInserted(KTextEditor::View *view,
325 const KTextEditor::Cursor &position,
326 const QString &text);
327
328 /*
329 * Context menu handling
330 */
331public:
332 /**
333 * Set a context menu for this view to \p menu.
334 *
335 * \note any previously assigned menu is not deleted. If you are finished
336 * with the previous menu, you may delete it.
337 *
338 * \warning Use this with care! Plugin xml gui clients are not merged
339 * into this menu!
340 * \warning !!!!!! DON'T USE THIS FUNCTION, UNLESS YOU ARE SURE YOU DON'T WANT PLUGINS TO WORK !!!!!!
341 *
342 * \param menu new context menu object for this view
343 * \see contextMenu()
344 */
345 virtual void setContextMenu(QMenu *menu) = 0;
346
347 /**
348 * Get the context menu for this view. The return value can be NULL
349 * if no context menu object was set and kxmlgui is not initialized yet.
350 * If there is no user set menu, the kxmlgui menu is returned. Do not delete this menu, if
351 * if it is the xmlgui menu.
352 * \return context menu object
353 * \see setContextMenu()
354 */
355 virtual QMenu *contextMenu() const = 0;
356
357 /**
358 * Populate \a menu with default text editor actions. If \a menu is
359 * null, a menu will be created with the view as its parent.
360 *
361 * \note to use this menu, you will next need to call setContextMenu(),
362 * as this does not assign the new context menu.
363 *
364 * \warning This contains only basic options from the editor component
365 * (katepart). Plugins are \p not merged/integrated into it!
366 * If you want to be a better citizen and take full advantage
367 * of KTextEditor plugins do something like:
368 * \code
369 * KXMLGUIClient* client = view;
370 * // search parent XmlGuiClient
371 * while (client->parentClient()) {
372 * client = client->parentClient();
373 * }
374 *
375 * if (client->factory()) {
376 * QList<QWidget*> conts = client->factory()->containers("menu");
377 * foreach (QWidget *w, conts) {
378 * if (w->objectName() == "ktexteditor_popup") {
379 * // do something with the menu (ie adding an onshow handler)
380 * break;
381 * }
382 * }
383 * }
384 * \endcode
385 * \warning or simply use the aboutToShow, aboutToHide signals !!!!!
386 *
387 * \param menu the menu to be populated, or null to create a new menu.
388 * \return the menu, whether created or passed initially
389 */
390 virtual QMenu *defaultContextMenu(QMenu *menu = nullptr) const = 0;
391
392Q_SIGNALS:
393 /**
394 * Signal which is emitted immediately prior to showing the current
395 * context \a menu.
396 */
397 void contextMenuAboutToShow(KTextEditor::View *view, QMenu *menu);
398
399 /*
400 * Cursor handling
401 */
402public:
403 /**
404 * Set the view's new cursor to \p position. A \e TAB character
405 * is handeled as only on character.
406 * \param position new cursor position
407 * \return \e true on success, otherwise \e false
408 * \see cursorPosition()
409 */
410 virtual bool setCursorPosition(Cursor position) = 0;
411
412 /**
413 * Get the view's current cursor position. A \e TAB character is
414 * handeled as only one character.
415 * \return current cursor position
416 * \see setCursorPosition()
417 */
418 virtual Cursor cursorPosition() const = 0;
419
420 /**
421 * Get the current \e virtual cursor position, \e virtual means the
422 * tabulator character (TAB) counts \e multiple characters, as configured
423 * by the user (e.g. one TAB is 8 spaces). The virtual cursor
424 * position provides access to the user visible values of the current
425 * cursor position.
426 *
427 * \return virtual cursor position
428 * \see cursorPosition()
429 */
430 virtual Cursor cursorPositionVirtual() const = 0;
431
432 /**
433 * Get the screen coordinates (x, y) of the supplied \a cursor relative
434 * to the view widget in pixels. Thus, (0, 0) represents the top left hand
435 * of the view widget.
436 *
437 * To map pixel coordinates to a Cursor position (the reverse transformation)
438 * use coordinatesToCursor().
439 *
440 * \param cursor cursor to determine coordinate for.
441 * \return cursor screen coordinates relative to the view widget
442 *
443 * \see cursorPositionCoordinates(), coordinatesToCursor()
444 */
445 virtual QPoint cursorToCoordinate(const KTextEditor::Cursor &cursor) const = 0;
446
447 /**
448 * Get the screen coordinates (x, y) of the cursor position in pixels.
449 * The returned coordinates are relative to the View such that (0, 0)
450 * represents tht top-left corner of the View.
451 *
452 * If global screen coordinates are required, e.g. for showing a QToolTip,
453 * convert the view coordinates to global screen coordinates as follows:
454 * \code
455 * QPoint viewCoordinates = view->cursorPositionCoordinates();
456 * QPoint globalCoorinates = view->mapToGlobal(viewCoordinates);
457 * \endcode
458 * \return cursor screen coordinates
459 * \see cursorToCoordinate(), coordinatesToCursor()
460 */
461 virtual QPoint cursorPositionCoordinates() const = 0;
462
463 /**
464 * Get the text-cursor in the document from the screen coordinates,
465 * relative to the view widget.
466 *
467 * To map a cursor to pixel coordinates (the reverse transformation)
468 * use cursorToCoordinate().
469 *
470 * \param coord coordinates relative to the view widget
471 * \return cursor in the View, that points onto the character under
472 * the given coordinate. May be KTextEditor::Cursor::invalid().
473 */
474 virtual KTextEditor::Cursor coordinatesToCursor(const QPoint &coord) const = 0;
475
476 /*
477 * SIGNALS
478 * following signals should be emitted by the editor view
479 * if the cursor position changes
480 */
481Q_SIGNALS:
482 /**
483 * This signal is emitted whenever the \p view's cursor position changed.
484 * \param view view which emitted the signal
485 * \param newPosition new position of the cursor (Kate will pass the real
486 * cursor position, not the virtual)
487 * \see cursorPosition(), cursorPositionVirtual()
488 */
489 void cursorPositionChanged(KTextEditor::View *view,
490 const KTextEditor::Cursor &newPosition);
491
492 /**
493 * This signal should be emitted whenever the \p view is scrolled vertically.
494 * \param view view which emitted the signal
495 * \param newPos the new scroll position
496 */
497 void verticalScrollPositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &newPos);
498
499 /**
500 * This signal should be emitted whenever the \p view is scrolled horizontally.
501 * \param view view which emitted the signal
502 */
503 void horizontalScrollPositionChanged(KTextEditor::View *view);
504 /*
505 * Mouse position
506 */
507public:
508 /**
509 * Check, whether mouse tracking is enabled.
510 *
511 * Mouse tracking is required to have the signal mousePositionChanged()
512 * emitted.
513 * \return \e true, if mouse tracking is enabled, otherwise \e false
514 * \see setMouseTrackingEnabled(), mousePositionChanged()
515 */
516 virtual bool mouseTrackingEnabled() const = 0;
517
518 /**
519 * Try to enable or disable mouse tracking according to \p enable.
520 * The return value contains the state of mouse tracking \e after the
521 * request. Mouse tracking is required to have the mousePositionChanged()
522 * signal emitted.
523 *
524 * \note Implementation Notes: An implementation is not forced to support
525 * this, and should always return \e false if it does not have
526 * support.
527 *
528 * \param enable if \e true, try to enable mouse tracking, otherwise disable
529 * it.
530 * \return the current state of mouse tracking
531 * \see mouseTrackingEnabled(), mousePositionChanged()
532 */
533 virtual bool setMouseTrackingEnabled(bool enable) = 0;
534
535Q_SIGNALS:
536 /**
537 * This signal is emitted whenever the position of the mouse changes over
538 * this \a view. If the mouse moves off the view, an invalid cursor position
539 * should be emitted, i.e. Cursor::invalid().
540 * \note If mouseTrackingEnabled() returns \e false, this signal is never
541 * emitted.
542 * \param view view which emitted the signal
543 * \param newPosition new position of the mouse or Cursor::invalid(), if the
544 * mouse moved out of the \p view.
545 * \see mouseTrackingEnabled()
546 */
547 void mousePositionChanged(KTextEditor::View *view,
548 const KTextEditor::Cursor &newPosition);
549
550 /*
551 * Selection methods.
552 * This deals with text selection and copy&paste
553 */
554public:
555 /**
556 * Set the view's selection to the range \p selection.
557 * The old selection will be discarded.
558 * \param range the range of the new selection
559 * \return \e true on success, otherwise \e false (e.g. when the cursor
560 * range is invalid)
561 * \see selectionRange(), selection()
562 */
563 virtual bool setSelection(const Range &range) = 0;
564
565 /**
566 * Query the view whether it has selected text, i.e. whether a selection
567 * exists.
568 * \return \e true if a text selection exists, otherwise \e false
569 * \see setSelection(), selectionRange()
570 */
571 virtual bool selection() const = 0;
572
573 /**
574 * Get the range occupied by the current selection.
575 * \return selection range, valid only if a selection currently exists.
576 * \see setSelection()
577 */
578 virtual Range selectionRange() const = 0;
579
580 /**
581 * Get the view's selected text.
582 * \return the selected text
583 * \see setSelection()
584 */
585 virtual QString selectionText() const = 0;
586
587 /**
588 * Remove the view's current selection, \e without deleting the selected
589 * text.
590 * \return \e true on success, otherwise \e false
591 * \see removeSelectionText()
592 */
593 virtual bool removeSelection() = 0;
594
595 /**
596 * Remove the view's current selection \e including the selected text.
597 * \return \e true on success, otherwise \e false
598 * \see removeSelection()
599 */
600 virtual bool removeSelectionText() = 0;
601
602 /*
603 * Blockselection stuff
604 */
605public:
606 /**
607 * Set block selection mode to state \p on.
608 * \param on if \e true, block selection mode is turned on, otherwise off
609 * \return \e true on success, otherwise \e false
610 * \see blockSelection()
611 */
612 virtual bool setBlockSelection(bool on) = 0;
613
614 /**
615 * Get the status of the selection mode. \e true indicates that block
616 * selection mode is on. If this is \e true, selections applied via the
617 * SelectionInterface are handled as block selections and the Copy&Paste
618 * functions work on rectangular blocks of text rather than normal.
619 * \return \e true, if block selection mode is enabled, otherwise \e false
620 * \see setBlockSelection()
621 */
622 virtual bool blockSelection() const = 0;
623
624 /*
625 * SIGNALS
626 * following signals should be emitted by the editor view for selection
627 * handling.
628 */
629Q_SIGNALS:
630 /**
631 * This signal is emitted whenever the \p view's selection changes.
632 * \note If the mode switches from block selection to normal selection
633 * or vice versa this signal should also be emitted.
634 * \param view view in which the selection changed
635 * \see selection(), selectionRange(), selectionText()
636 */
637 void selectionChanged(KTextEditor::View *view);
638
639public:
640 /**
641 * This is a convenience function which inserts \p text at the view's
642 * current cursor position. You do not necessarily need to reimplement
643 * it, except you want to do some special things.
644 * \param text Text to be inserted
645 * \return \e true on success of insertion, otherwise \e false
646 * \see textInserted()
647 */
648 virtual bool insertText(const QString &text);
649
650 /**
651 * Insert a template into the document. The template can have editable fields
652 * which can be filled by the user. You can create editable fields
653 * with ${fieldname}; multiple fields with the same name will have their
654 * contents synchronized automatically, and only the first one is editable
655 * in this case.
656 * Fields can have a default value specified by writing ${fieldname=default}.
657 * Note that `default' is a JavaScript expression and strings need to be quoted.
658 * You can also provide a piece of JavaScript for more complex logic.
659 * To create a field which provides text based on a JS function call and the values
660 * of the other, editable fields, use the ${func()} syntax. func() must be a callable
661 * object defined in @p script. You can pass arguments to the function by just
662 * writing any constant expression or a field name.
663 * \param insertPosition where to insert the template
664 * \param templateString template to insert using the above syntax
665 * \param script script with functions which can be used in @p templateScript
666 * \return true on success, false if insertion failed (e.g. read-only mode)
667 */
668 bool insertTemplate(const KTextEditor::Cursor& insertPosition,
669 const QString& templateString,
670 const QString& script = QString());
671
672
673 /**
674 * Scroll view to cursor.
675 *
676 * \param cursor the cursor position to scroll to.
677 *
678 * \since 5.33
679 */
680 void setScrollPosition(KTextEditor::Cursor &cursor);
681
682 /**
683 * Horizontally scroll view to position.
684 *
685 * \param x the pixel position to scroll to.
686 *
687 * \since 5.33
688 */
689 void setHorizontalScrollPosition(int x);
690
691 /**
692 * Get the cursor corresponding to the maximum position
693 * the view can vertically scroll to.
694 *
695 * \return cursor position of the maximum vertical scroll position.
696 *
697 * \since 5.33
698 */
699 KTextEditor::Cursor maxScrollPosition() const;
700
701 /**
702 * Get the first displayed line in the view.
703 *
704 * \note If code is folded, many hundred lines can be
705 * between firstDisplayedLine() and lastDisplayedLine().
706 *
707 * \param lineType if RealLine (the default), it returns the real line number
708 * accounting for folded regions. In that case it walks over all folded
709 * regions
710 * O(n) for n == number of folded ranges
711 * \return the first displayed line
712 *
713 * \see lastDisplayedLine()
714 * \since 5.33
715 */
716 int firstDisplayedLine(LineType lineType = RealLine) const;
717
718 /**
719 * Get the last displayed line in the view.
720 *
721 * \note If code is folded, many hundred lines can be
722 * between firstDisplayedLine() and lastDisplayedLine().
723 *
724 * \param lineType if RealLine (the default), it returns the real line number
725 * accounting for folded regions. In that case it walks over all folded
726 * regions
727 * O(n) for n == number of folded ranges
728 * \return the last displayed line
729 *
730 * \see firstDisplayedLine()
731 * \since 5.33
732 */
733 int lastDisplayedLine(LineType lineType = RealLine) const;
734
735 /**
736 * Get the view's text area rectangle excluding border, scrollbars, etc.
737 *
738 * \return the view's text area rectangle
739 *
740 * \since 5.33
741 */
742 QRect textAreaRect() const;
743
744public:
745 /**
746 * Print the document. This should result in showing the print dialog.
747 *
748 * @returns true if document was printed
749 */
750 virtual bool print() = 0;
751
752 /**
753 * Shows the print preview dialog/
754 */
755 virtual void printPreview() = 0;
756
757 /**
758 * Is the status bar enabled?
759 *
760 * @return status bar enabled?
761 */
762 bool isStatusBarEnabled() const;
763
764 /**
765 * Show/hide the status bar of the view.
766 * Per default, the status bar is enabled.
767 *
768 * @param enable should the status bar be enabled?
769 */
770 void setStatusBarEnabled(bool enable);
771
772Q_SIGNALS:
773 /**
774 * This signal is emitted whenever the status bar of \p view is toggled.
775 *
776 * @param enabled Whether the status bar is currently enabled or not
777 */
778 void statusBarEnabledChanged(KTextEditor::View *view, bool enabled);
779
780public:
781 /**
782 * Read session settings from the given \p config.
783 *
784 * Known flags:
785 * none atm
786 *
787 * \param config read the session settings from this KConfigGroup
788 * \param flags additional flags
789 * \see writeSessionConfig()
790 */
791 virtual void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) = 0;
792
793 /**
794 * Write session settings to the \p config.
795 * See readSessionConfig() for more details.
796 *
797 * \param config write the session settings to this KConfigGroup
798 * \param flags additional flags
799 * \see readSessionConfig()
800 */
801 virtual void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) = 0;
802
803public:
804 /**
805 * Returns the attribute for the default style \p defaultStyle.
806 * @param defaultStyle default style to get the attribute for
807 * @see KTextEditor::Attribute
808 */
809 virtual KTextEditor::Attribute::Ptr defaultStyleAttribute(KTextEditor::DefaultStyle defaultStyle) const = 0;
810
811 /**
812 * Get the list of AttributeBlocks for a given \p line in the document.
813 *
814 * \return list of AttributeBlocks for given \p line.
815 */
816 virtual QList<KTextEditor::AttributeBlock> lineAttributes(int line) = 0;
817
818private:
819 /**
820 * private d-pointer, pointing to the internal implementation
821 */
822 ViewPrivate *const d;
823};
824
825}
826
827#endif
828
829