KTextEditor

view.h
1 /*
2  SPDX-FileCopyrightText: 2001 Christoph Cullmann <[email protected]>
3 
4  Documentation:
5  SPDX-FileCopyrightText: 2005 Dominik Haumann <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #ifndef KTEXTEDITOR_VIEW_H
11 #define KTEXTEDITOR_VIEW_H
12 
13 #include <ktexteditor/attribute.h>
14 #include <ktexteditor/document.h>
15 #include <ktexteditor/range.h>
16 #include <ktexteditor_export.h>
17 
18 // gui merging
19 #include <KXMLGUIClient>
20 
21 // widget
22 #include <QWidget>
23 
24 class QMenu;
25 
26 class KConfigGroup;
27 
28 namespace KTextEditor
29 {
30 class Document;
31 class MainWindow;
32 class ViewPrivate;
33 
143 class KTEXTEDITOR_EXPORT View : public QWidget, public KXMLGUIClient
144 {
145  Q_OBJECT
146 
147 protected:
159  View(ViewPrivate *impl, QWidget *parent);
160 
161 public:
165  virtual ~View();
166 
167  /*
168  * Accessor for the document
169  */
170 public:
176  virtual Document *document() const = 0;
177 
178  /*
179  * General information about this view
180  */
181 public:
186  enum InputMode {
187  NormalInputMode = 0,
188  ViInputMode = 1
189  };
190 
195  enum ViewMode {
196  NormalModeInsert = 0,
197  NormalModeOverwrite = 1,
199  ViModeNormal = 10,
200  ViModeInsert = 11,
201  ViModeVisual = 12,
202  ViModeVisualLine = 13,
203  ViModeVisualBlock = 14,
204  ViModeReplace = 15
205  };
206 
211  enum LineType {
212  RealLine = 0,
213  VisibleLine = 1
214  };
223  virtual ViewMode viewMode() const = 0;
224 
236  virtual QString viewModeHuman() const = 0;
237 
245  void setViewInputMode(InputMode inputMode);
246 
255  virtual InputMode viewInputMode() const = 0;
256 
263  virtual QString viewInputModeHuman() const = 0;
264 
269  virtual KTextEditor::MainWindow *mainWindow() const = 0;
270 
271  /*
272  * SIGNALS
273  * following signals should be emitted by the editor view
274  */
275 Q_SIGNALS:
281  void focusIn(KTextEditor::View *view);
282 
288  void focusOut(KTextEditor::View *view);
289 
296  void viewModeChanged(KTextEditor::View *view, KTextEditor::View::ViewMode mode);
297 
304  void viewInputModeChanged(KTextEditor::View *view, KTextEditor::View::InputMode mode);
305 
314  void textInserted(KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text);
315 
316  /*
317  * Context menu handling
318  */
319 public:
333  virtual void setContextMenu(QMenu *menu) = 0;
334 
343  virtual QMenu *contextMenu() const = 0;
344 
378  virtual QMenu *defaultContextMenu(QMenu *menu = nullptr) const = 0;
379 
380 Q_SIGNALS:
385  void contextMenuAboutToShow(KTextEditor::View *view, QMenu *menu);
386 
387  /*
388  * Cursor handling
389  */
390 public:
398  virtual bool setCursorPosition(Cursor position) = 0;
399 
406  virtual Cursor cursorPosition() const = 0;
407 
418  virtual Cursor cursorPositionVirtual() const = 0;
419 
433  virtual QPoint cursorToCoordinate(const KTextEditor::Cursor &cursor) const = 0;
434 
449  virtual QPoint cursorPositionCoordinates() const = 0;
450 
462  virtual KTextEditor::Cursor coordinatesToCursor(const QPoint &coord) const = 0;
463 
464  /*
465  * SIGNALS
466  * following signals should be emitted by the editor view
467  * if the cursor position changes
468  */
469 Q_SIGNALS:
477  void cursorPositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &newPosition);
478 
484  void verticalScrollPositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &newPos);
485 
490  void horizontalScrollPositionChanged(KTextEditor::View *view);
491  /*
492  * Mouse position
493  */
494 public:
503  virtual bool mouseTrackingEnabled() const = 0;
504 
520  virtual bool setMouseTrackingEnabled(bool enable) = 0;
521 
522 Q_SIGNALS:
534  void mousePositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &newPosition);
535 
536  /*
537  * Selection methods.
538  * This deals with text selection and copy&paste
539  */
540 public:
549  virtual bool setSelection(const Range &range) = 0;
550 
557  virtual bool selection() const = 0;
558 
564  virtual Range selectionRange() const = 0;
565 
571  virtual QString selectionText() const = 0;
572 
579  virtual bool removeSelection() = 0;
580 
586  virtual bool removeSelectionText() = 0;
587 
588  /*
589  * Blockselection stuff
590  */
591 public:
598  virtual bool setBlockSelection(bool on) = 0;
599 
608  virtual bool blockSelection() const = 0;
609 
610  /*
611  * SIGNALS
612  * following signals should be emitted by the editor view for selection
613  * handling.
614  */
615 Q_SIGNALS:
623  void selectionChanged(KTextEditor::View *view);
624 
625 public:
634  virtual bool insertText(const QString &text);
635 
654  bool insertTemplate(const KTextEditor::Cursor &insertPosition, const QString &templateString, const QString &script = QString());
655 
663  void setScrollPosition(KTextEditor::Cursor &cursor);
664 
672  void setHorizontalScrollPosition(int x);
673 
682  KTextEditor::Cursor maxScrollPosition() const;
683 
699  int firstDisplayedLine(LineType lineType = RealLine) const;
700 
716  int lastDisplayedLine(LineType lineType = RealLine) const;
717 
725  QRect textAreaRect() const;
726 
727 public:
733  virtual bool print() = 0;
734 
738  virtual void printPreview() = 0;
739 
745  bool isStatusBarEnabled() const;
746 
753  void setStatusBarEnabled(bool enable);
754 
755 Q_SIGNALS:
761  void statusBarEnabledChanged(KTextEditor::View *view, bool enabled);
762 
763 public:
774  virtual void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) = 0;
775 
784  virtual void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) = 0;
785 
786 public:
792  virtual KTextEditor::Attribute::Ptr defaultStyleAttribute(KTextEditor::DefaultStyle defaultStyle) const = 0;
793 
799  virtual QList<KTextEditor::AttributeBlock> lineAttributes(int line) = 0;
800 
801 private:
805  ViewPrivate *const d;
806 };
807 
808 }
809 
810 #endif
LineType
Possible line types.
Definition: view.h:211
DefaultStyle
The following lists all valid default styles that are used for the syntax highlighting files in the i...
Definition: attribute.h:26
QString mode() const override
Return the name of the currently used mode.
void textInserted(KTextEditor::Document *document, const KTextEditor::Range &range)
The document emits this signal whenever text was inserted.
The Cursor represents a position in a Document.
Definition: cursor.h:71
A KParts derived class representing a text document.
Definition: document.h:185
void readSessionConfig(const KConfigGroup &config, const QSet< QString > &flags=QSet< QString >()) override
Read session settings from the given config.
ViewMode
Possible view modes These correspond to various modes the text editor might be in.
Definition: view.h:195
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
KateDocumentConfig * config()
Configuration.
void writeSessionConfig(KConfigGroup &config, const QSet< QString > &flags=QSet< QString >()) override
Write session settings to the config.
An object representing a section of text, from one Cursor to another.
InputMode
Possible input modes.
Definition: view.h:186
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:143
This class allows the application that embeds the KTextEditor component to allow it to access parts o...
Definition: mainwindow.h:43
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Oct 28 2020 23:02:35 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.