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 // theme support
22 #include <KSyntaxHighlighting/Theme>
23 
24 // widget
25 #include <QWidget>
26 
27 class QMenu;
28 
29 class KConfigGroup;
30 
31 namespace KTextEditor
32 {
33 class Document;
34 class MainWindow;
35 class ViewPrivate;
36 
146 class KTEXTEDITOR_EXPORT View : public QWidget, public KXMLGUIClient
147 {
148  Q_OBJECT
149 
150 protected:
162  View(ViewPrivate *impl, QWidget *parent);
163 
164 public:
168  virtual ~View();
169 
170  /*
171  * Accessor for the document
172  */
173 public:
179  virtual Document *document() const = 0;
180 
181  /*
182  * General information about this view
183  */
184 public:
189  enum InputMode {
190  NormalInputMode = 0,
191  ViInputMode = 1
192  };
193 
198  enum ViewMode {
199  NormalModeInsert = 0,
200  NormalModeOverwrite = 1,
202  ViModeNormal = 10,
203  ViModeInsert = 11,
204  ViModeVisual = 12,
205  ViModeVisualLine = 13,
206  ViModeVisualBlock = 14,
207  ViModeReplace = 15
208  };
209 
214  enum LineType {
215  RealLine = 0,
216  VisibleLine = 1
217  };
226  virtual ViewMode viewMode() const = 0;
227 
239  virtual QString viewModeHuman() const = 0;
240 
248  void setViewInputMode(InputMode inputMode);
249 
258  virtual InputMode viewInputMode() const = 0;
259 
266  virtual QString viewInputModeHuman() const = 0;
267 
272  virtual KTextEditor::MainWindow *mainWindow() const = 0;
273 
274  /*
275  * SIGNALS
276  * following signals should be emitted by the editor view
277  */
278 Q_SIGNALS:
284  void focusIn(KTextEditor::View *view);
285 
291  void focusOut(KTextEditor::View *view);
292 
299  void viewModeChanged(KTextEditor::View *view, KTextEditor::View::ViewMode mode);
300 
307  void viewInputModeChanged(KTextEditor::View *view, KTextEditor::View::InputMode mode);
308 
317  void textInserted(KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text);
318 
319  /*
320  * Context menu handling
321  */
322 public:
336  virtual void setContextMenu(QMenu *menu) = 0;
337 
346  virtual QMenu *contextMenu() const = 0;
347 
381  virtual QMenu *defaultContextMenu(QMenu *menu = nullptr) const = 0;
382 
383 Q_SIGNALS:
388  void contextMenuAboutToShow(KTextEditor::View *view, QMenu *menu);
389 
390  /*
391  * Cursor handling
392  */
393 public:
401  virtual bool setCursorPosition(Cursor position) = 0;
402 
409  virtual Cursor cursorPosition() const = 0;
410 
421  virtual Cursor cursorPositionVirtual() const = 0;
422 
436  virtual QPoint cursorToCoordinate(const KTextEditor::Cursor &cursor) const = 0;
437 
452  virtual QPoint cursorPositionCoordinates() const = 0;
453 
465  virtual KTextEditor::Cursor coordinatesToCursor(const QPoint &coord) const = 0;
466 
467  /*
468  * SIGNALS
469  * following signals should be emitted by the editor view
470  * if the cursor position changes
471  */
472 Q_SIGNALS:
480  void cursorPositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &newPosition);
481 
487  void verticalScrollPositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &newPos);
488 
493  void horizontalScrollPositionChanged(KTextEditor::View *view);
494  /*
495  * Mouse position
496  */
497 public:
506  virtual bool mouseTrackingEnabled() const = 0;
507 
523  virtual bool setMouseTrackingEnabled(bool enable) = 0;
524 
525 Q_SIGNALS:
537  void mousePositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &newPosition);
538 
539  /*
540  * Selection methods.
541  * This deals with text selection and copy&paste
542  */
543 public:
552  virtual bool setSelection(const Range &range) = 0;
553 
560  virtual bool selection() const = 0;
561 
567  virtual Range selectionRange() const = 0;
568 
574  virtual QString selectionText() const = 0;
575 
582  virtual bool removeSelection() = 0;
583 
589  virtual bool removeSelectionText() = 0;
590 
591  /*
592  * Blockselection stuff
593  */
594 public:
601  virtual bool setBlockSelection(bool on) = 0;
602 
611  virtual bool blockSelection() const = 0;
612 
613  /*
614  * SIGNALS
615  * following signals should be emitted by the editor view for selection
616  * handling.
617  */
618 Q_SIGNALS:
626  void selectionChanged(KTextEditor::View *view);
627 
628 public:
637  virtual bool insertText(const QString &text);
638 
657  bool insertTemplate(const KTextEditor::Cursor &insertPosition, const QString &templateString, const QString &script = QString());
658 
666  void setScrollPosition(KTextEditor::Cursor &cursor);
667 
675  void setHorizontalScrollPosition(int x);
676 
685  KTextEditor::Cursor maxScrollPosition() const;
686 
702  int firstDisplayedLine(LineType lineType = RealLine) const;
703 
719  int lastDisplayedLine(LineType lineType = RealLine) const;
720 
728  QRect textAreaRect() const;
729 
730 public:
736  virtual bool print() = 0;
737 
741  virtual void printPreview() = 0;
742 
748  bool isStatusBarEnabled() const;
749 
756  void setStatusBarEnabled(bool enable);
757 
758 Q_SIGNALS:
764  void statusBarEnabledChanged(KTextEditor::View *view, bool enabled);
765 
766 public:
777  virtual void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) = 0;
778 
787  virtual void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) = 0;
788 
789 public:
795  virtual KTextEditor::Attribute::Ptr defaultStyleAttribute(KTextEditor::DefaultStyle defaultStyle) const = 0;
796 
802  virtual QList<KTextEditor::AttributeBlock> lineAttributes(int line) = 0;
803 
804 Q_SIGNALS:
812  void configChanged(KTextEditor::View *view);
813 
814 public:
823  KSyntaxHighlighting::Theme theme() const;
824 
825 private:
829  ViewPrivate *const d;
830 };
831 
832 }
833 
834 #endif
LineType
Possible line types.
Definition: view.h:214
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:198
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
Definition: katetextblock.h:21
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:189
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:146
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-2021 The KDE developers.
Generated on Wed Jan 20 2021 23:01:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.