edbee - Qt Editor Library v0.11.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
texteditorcontroller.h
Go to the documentation of this file.
1// edbee - Copyright (c) 2012-2025 by Rick Blommers and contributors
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include "edbee/exports.h"
7
8#include <QObject>
9#include <QIcon>
10
13
14class QAction;
15
16namespace edbee {
17
18class ChangeGroup;
21class TextCaretCache;
22class TextCommand;
23class TextDocument;
29class TextRenderer;
30class TextRangeSet;
31class TextSearcher;
32class TextSelection;
33class UndoableTextCommand;
34
35
38class EDBEE_EXPORT TextEditorController : public QObject
39{
40 Q_OBJECT
41public:
42
48
49
50 explicit TextEditorController( TextEditorWidget* widget = nullptr, QObject *parent = nullptr );
51 explicit TextEditorController( TextDocument* document, TextEditorWidget* widget = nullptr, QObject *parent = nullptr );
52 virtual ~TextEditorController();
53
54// public method
55 void notifyStateChange();
56
57 void giveTextDocument( TextDocument* doc );
58 void setTextDocument( TextDocument* doc );
59
60 void setAutoScrollToCaret( AutoScrollToCaret autoScroll );
61 virtual AutoScrollToCaret autoScrollToCaret() const;
62
63 bool hasFocus();
64 QAction* createUnconnectedAction(const QString& command, const QString& text, const QIcon& icon=QIcon(), QObject* owner=0 );
65 QAction* createAction(const QString& command, const QString& text , const QIcon& icon=QIcon(), QObject* owner=0 );
66
67
68// getters
69// TextBuffer* textBuffer() const;
70 TextDocument* textDocument() const;
71 TextSelection* textSelection() const;
72 TextRenderer* textRenderer() const;
73 TextRangeSet* borderedTextRanges() const;
74
75 void setKeyMap( TextEditorKeyMap* keyMap );
76 void giveKeyMap( TextEditorKeyMap* keyMap );
77 TextEditorKeyMap* keyMap() const;
78 void setCommandMap( TextEditorCommandMap* commandMap );
79 void giveCommandMap( TextEditorCommandMap* commandMap );
80 TextEditorCommandMap* commandMap() const;
81 TextEditorWidget* widget() const;
82 TextCaretCache* textCaretCache() const;
83 void giveTextSearcher( TextSearcher* searcher );
84 TextSearcher* textSearcher();
85 DynamicVariables* dynamicVariables() const;
86
87signals:
88
90 void updateStatusTextSignal( const QString& text );
91
93 void textDocumentChanged( edbee::TextDocument* oldDocument, edbee::TextDocument* newDocument );
94
96 void commandToBeExecuted( edbee::TextEditorCommand* command );
97 void commandExecuted( edbee::TextEditorCommand* command );
98
99 void backspacePressed();
100
101public slots:
102
103 void onTextChanged( edbee::TextBufferChange change, QString oldText = QString() );
104 void onSelectionChanged( edbee::TextRangeSet *oldRangeSet );
105 void onLineDataChanged( int line, int length, int newLength );
106
107 void updateAfterConfigChange();
108
109public slots:
110
111 // updates the status text
112 virtual void updateStatusText( const QString& extraText=QString() );
113
114 virtual void update();
115
116 // scrolling
117 virtual void scrollPositionVisible( int xPos, int yPos );
118 virtual void scrollOffsetVisible( int offset );
119 virtual void scrollCaretVisible();
120
121 virtual void storeSelection( int coalesceId=0 );
122
123 // replace the given selection
124 virtual void replace( int offset, int length, const QString& text, int coalesceId, bool stickySelection=false);
125 virtual void replaceSelection(const QString& text, int coalesceId=0, bool stickySelection=false);
126 virtual void replaceSelection(const QStringList& texts, int coalesceId=0, bool stickySelection=false);
127 virtual void replaceRangeSet(edbee::TextRangeSet& rangeSet, const QString& text, int coalesceId=0, bool stickySelection=false);
128 virtual void replaceRangeSet(edbee::TextRangeSet& rangeSet, const QStringList& texts, int coalesceId=0, bool stickySelection=false);
129
130 // caret movements
131 virtual void moveCaretTo( int line, int col, bool keepAnchors, int rangeIndex=-1 );
132 virtual void moveCaretToOffset( int offset, bool keepAnchors, int rangeIndex=-1 );
133 virtual void moveCaretAndAnchorToOffset(int caret, int anchor, int rangeIndex= -1 );
134 virtual void addCaretAt( int line, int col);
135 virtual void addCaretAtOffset( int offset );
136 virtual void changeAndGiveTextSelection(edbee::TextRangeSet* rangeSet , int coalesceId = 0);
137
138 // perform an undo
139 virtual void undo(bool soft=false);
140 virtual void redo(bool soft=false);
141
142 // command execution
143 virtual void beginUndoGroup( edbee::ChangeGroup* group=0 );
144 virtual void endUndoGroup(int coalesceId=0, bool flatten=false);
145
146 // low level command execution
147 virtual void executeCommand( edbee::TextEditorCommand* textCommand );
148 virtual void executeCommand( const QString& name=QString() );
149
150 public:
151
152 // returns the readonly state
153 virtual bool readonly() const;
154 virtual void setReadonly(bool value);
155
156
157private:
158
159 TextEditorWidget* widgetRef_;
160 TextDocument* textDocument_;
161 TextDocument* textDocumentRef_;
162
163 TextSelection* textSelection_;
164
165 TextEditorKeyMap* keyMap_;
166 TextEditorKeyMap* keyMapRef_;
167 TextEditorCommandMap* commandMap_;
168 TextEditorCommandMap* commandMapRef_;
169 TextRenderer* textRenderer_;
170 TextCaretCache* textCaretCache_;
171
172 TextSearcher* textSearcher_;
173
174 AutoScrollToCaret autoScrollToCaret_;
175
176
177 // extra highlight text
178 TextRangeSet* borderedTextRanges_;
179};
180
181} // edbee
An undoable-command-group.
Definition change.h:84
This class is used for remembering/managing dynamic variables This are a kind of environment variable...
Definition dynamicvariables.h:64
This clas represents a text buffer change and is used to pass around between events This is a sharedd...
Definition textbuffer.h:45
A special cache. For remembering the x-coordinates of the carets.
Definition textcaretcache.h:19
This is the base and abstract class of a text document A TextDocument is the model part of the editor...
Definition textdocument.h:42
This is the abstract base class for a textcommand.
Definition texteditorcommand.h:50
This is a texteditor map. This is used to map Command-Names to commands This class is the owner of th...
Definition texteditorcommandmap.h:20
This is the main texteditor-component (which is the true editor) This is the QWidget that recieves th...
Definition texteditorcomponent.h:29
The texteditor works via the controller. The controller is the central point/mediator which maps/cont...
Definition texteditorcontroller.h:39
AutoScrollToCaret
Definition texteditorcontroller.h:43
@ AutoScrollWhenFocus
Definition texteditorcontroller.h:45
@ AutoScrollAlways
Definition texteditorcontroller.h:44
@ AutoScrollNever
Definition texteditorcontroller.h:46
TextEditorController(TextEditorWidget *widget=nullptr, QObject *parent=nullptr)
The constructor.
Definition texteditorcontroller.cpp:44
A text editor key map This key map, maps key-sequences to action-names.
Definition texteditorkeymap.h:39
This is the general edbee widget The core functionality of this widget is divided in several separate...
Definition texteditorwidget.h:36
The basic textrange class. A simple class of textrange with a simple vector implementation.
Definition textrange.h:202
A class for rendering the text.
Definition textrenderer.h:35
The text searcher is a class to remember the current search operation It remembers the current search...
Definition textsearcher.h:24
The class textselection is a RangeSet that is used by the view of the document.
Definition textselection.h:25
#define EDBEE_EXPORT
Definition exports.h:15
QT Acessibility has an issue with reporting blank lines between elements lines. defining 'WINDOWS_EMP...
Definition commentcommand.cpp:20