KTextEditor

view.h
1 /* SPDX-License-Identifier: LGPL-2.0-or-later
2 
3  Copyright (C) 2001 Christoph Cullmann <[email protected]>
4  Copyright (C) 2005 Dominik Haumann ([email protected]) (documentation)
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #ifndef KTEXTEDITOR_VIEW_H
23 #define KTEXTEDITOR_VIEW_H
24 
25 #include <ktexteditor/attribute.h>
26 #include <ktexteditor/document.h>
27 #include <ktexteditor/range.h>
28 #include <ktexteditor_export.h>
29 
30 // gui merging
31 #include <KXMLGUIClient>
32 
33 // widget
34 #include <QWidget>
35 
36 class QMenu;
37 
38 class KConfigGroup;
39 
40 namespace KTextEditor
41 {
42 class Document;
43 class MainWindow;
44 class ViewPrivate;
45 
155 class KTEXTEDITOR_EXPORT View : public QWidget, public KXMLGUIClient
156 {
157  Q_OBJECT
158 
159 protected:
171  View(ViewPrivate *impl, QWidget *parent);
172 
173 public:
177  virtual ~View();
178 
179  /*
180  * Accessor for the document
181  */
182 public:
188  virtual Document *document() const = 0;
189 
190  /*
191  * General information about this view
192  */
193 public:
198  enum InputMode {
199  NormalInputMode = 0,
200  ViInputMode = 1
201  };
202 
207  enum ViewMode {
208  NormalModeInsert = 0,
209  NormalModeOverwrite = 1,
211  ViModeNormal = 10,
212  ViModeInsert = 11,
213  ViModeVisual = 12,
214  ViModeVisualLine = 13,
215  ViModeVisualBlock = 14,
216  ViModeReplace = 15
217  };
218 
223  enum LineType {
224  RealLine = 0,
225  VisibleLine = 1
226  };
235  virtual ViewMode viewMode() const = 0;
236 
248  virtual QString viewModeHuman() const = 0;
249 
257  void setViewInputMode(InputMode inputMode);
258 
267  virtual InputMode viewInputMode() const = 0;
268 
275  virtual QString viewInputModeHuman() const = 0;
276 
281  virtual KTextEditor::MainWindow *mainWindow() const = 0;
282 
283  /*
284  * SIGNALS
285  * following signals should be emitted by the editor view
286  */
287 Q_SIGNALS:
293  void focusIn(KTextEditor::View *view);
294 
300  void focusOut(KTextEditor::View *view);
301 
308  void viewModeChanged(KTextEditor::View *view, KTextEditor::View::ViewMode mode);
309 
316  void viewInputModeChanged(KTextEditor::View *view, KTextEditor::View::InputMode mode);
317 
326  void textInserted(KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text);
327 
328  /*
329  * Context menu handling
330  */
331 public:
345  virtual void setContextMenu(QMenu *menu) = 0;
346 
355  virtual QMenu *contextMenu() const = 0;
356 
390  virtual QMenu *defaultContextMenu(QMenu *menu = nullptr) const = 0;
391 
392 Q_SIGNALS:
397  void contextMenuAboutToShow(KTextEditor::View *view, QMenu *menu);
398 
399  /*
400  * Cursor handling
401  */
402 public:
410  virtual bool setCursorPosition(Cursor position) = 0;
411 
418  virtual Cursor cursorPosition() const = 0;
419 
430  virtual Cursor cursorPositionVirtual() const = 0;
431 
445  virtual QPoint cursorToCoordinate(const KTextEditor::Cursor &cursor) const = 0;
446 
461  virtual QPoint cursorPositionCoordinates() const = 0;
462 
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  */
481 Q_SIGNALS:
489  void cursorPositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &newPosition);
490 
496  void verticalScrollPositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &newPos);
497 
502  void horizontalScrollPositionChanged(KTextEditor::View *view);
503  /*
504  * Mouse position
505  */
506 public:
515  virtual bool mouseTrackingEnabled() const = 0;
516 
532  virtual bool setMouseTrackingEnabled(bool enable) = 0;
533 
534 Q_SIGNALS:
546  void mousePositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &newPosition);
547 
548  /*
549  * Selection methods.
550  * This deals with text selection and copy&paste
551  */
552 public:
561  virtual bool setSelection(const Range &range) = 0;
562 
569  virtual bool selection() const = 0;
570 
576  virtual Range selectionRange() const = 0;
577 
583  virtual QString selectionText() const = 0;
584 
591  virtual bool removeSelection() = 0;
592 
598  virtual bool removeSelectionText() = 0;
599 
600  /*
601  * Blockselection stuff
602  */
603 public:
610  virtual bool setBlockSelection(bool on) = 0;
611 
620  virtual bool blockSelection() const = 0;
621 
622  /*
623  * SIGNALS
624  * following signals should be emitted by the editor view for selection
625  * handling.
626  */
627 Q_SIGNALS:
635  void selectionChanged(KTextEditor::View *view);
636 
637 public:
646  virtual bool insertText(const QString &text);
647 
666  bool insertTemplate(const KTextEditor::Cursor &insertPosition, const QString &templateString, const QString &script = QString());
667 
675  void setScrollPosition(KTextEditor::Cursor &cursor);
676 
684  void setHorizontalScrollPosition(int x);
685 
694  KTextEditor::Cursor maxScrollPosition() const;
695 
711  int firstDisplayedLine(LineType lineType = RealLine) const;
712 
728  int lastDisplayedLine(LineType lineType = RealLine) const;
729 
737  QRect textAreaRect() const;
738 
739 public:
745  virtual bool print() = 0;
746 
750  virtual void printPreview() = 0;
751 
757  bool isStatusBarEnabled() const;
758 
765  void setStatusBarEnabled(bool enable);
766 
767 Q_SIGNALS:
773  void statusBarEnabledChanged(KTextEditor::View *view, bool enabled);
774 
775 public:
786  virtual void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) = 0;
787 
796  virtual void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) = 0;
797 
798 public:
804  virtual KTextEditor::Attribute::Ptr defaultStyleAttribute(KTextEditor::DefaultStyle defaultStyle) const = 0;
805 
811  virtual QList<KTextEditor::AttributeBlock> lineAttributes(int line) = 0;
812 
813 private:
817  ViewPrivate *const d;
818 };
819 
820 }
821 
822 #endif
LineType
Possible line types.
Definition: view.h:223
DefaultStyle
The following lists all valid default styles that are used for the syntax highlighting files in the i...
Definition: attribute.h:40
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:85
A KParts derived class representing a text document.
Definition: document.h:199
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:207
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:198
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:155
This class allows the application that embeds the KTextEditor component to allow it to access parts o...
Definition: mainwindow.h:57
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 11 2020 22:57:12 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.