edbee - Qt Editor Library v0.11.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
textrenderer.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 <QCache>
9#include <QObject>
10#include <QHash>
11#include <QRect>
12
13
15
16class QPainter;
17class QRect;
18
19namespace edbee {
20
21class AbstractComponent;
22class TextDocument;
26class TextRangeSet;
27class TextSelection;
28class TextTheme;
29class TextThemeStyler;
30class TextLayout;
31
34class EDBEE_EXPORT TextRenderer : public QObject
35{
36Q_OBJECT
37
38public:
40 virtual ~TextRenderer();
41 virtual void init();
42 virtual void reset();
43
44// calculation functions
45 int lineHeight();
46 int rawLineIndexForYpos( int y );
47 int lineIndexForYpos( int y );
48 int totalWidth();
49 int totalHeight();
50 int emWidth();
51 int nrWidth();
53 int firstVisibleLine();
54
55 int columnIndexForXpos( int line, int x );
56 int xPosForColumn( int line, int column );
57 int xPosForOffset( int offset );
58 int yPosForLine( int line );
59 int yPosForOffset( int offset );
60
61// Document access functions (Document vs Placeholder text)
62 int lineCount();
63 QString getLine(int index);
64
65// caching
66 TextLayout* textLayoutForLine( int line );
69
70// rendering
71 void renderBegin(const QRect& rect );
72 void renderEnd( const QRect& rect );
73
74// getters / setters
81
82 void setViewport( const QRect& viewport );
83
84 void resetCaretTime();
85 bool shouldRenderCaret();
86 bool isCaretVisible();
87 void setCaretVisible(bool visible);
88
89 QRect viewport() { return viewport_; }
90 int viewportX() { return viewport_.x(); }
91 int viewportY(){ return viewport_.y(); }
92 int viewportWidth() { return viewport_.width(); }
93 int viewportHeight() { return viewport_.height(); }
94
95// theme support
96 TextThemeStyler* themeStyler() { return textThemeStyler_; }
97
98 QString themeName() const;
99 TextTheme* theme();
100 void setThemeByName( const QString& name );
101 void setTheme( TextTheme* theme );
102
103// temporary getters only valid while rendering!!
104 const QRect* clipRect() { return clipRectRef_; }
105 int startOffset() { return startOffset_; }
106 int endOffset() { return endOffset_; }
107 int startLine() { return startLine_; }
108 int endLine() { return endLine_; }
109
110private:
111 void updateWidthCacheForRange( int offset, int length );
112
113protected slots:
114
115 void textDocumentChanged( edbee::TextDocument* oldDocument, edbee::TextDocument* newDocument );
116 void textChanged( edbee::TextBufferChange change, QString oldText = QString() );
117
118 void lastScopedOffsetChanged( int previousOffset, int newOffset );
119
120public slots:
121
122 void invalidateTextLayoutCaches(int fromLine=0);
123 void invalidateCaches();
124
125signals:
126 void themeChanged( TextTheme* theme );
127
128
129private:
130
131 TextEditorController* controllerRef_;
132 qint64 caretTime_;
133 qint64 caretBlinkRate_;
134
135 QCache<int,TextLayout> cachedTextLayoutList_;
136
137 QRect viewport_;
138 int totalWidthCache_;
139
140 TextThemeStyler* textThemeStyler_;
141
142 // temporary variables only valid the int the current context
143 const QRect* clipRectRef_;
144 int startOffset_;
145 int endOffset_;
146 int startLine_;
147 int endLine_;
148
149 TextDocument* placeHolderDocument_;
150};
151
152} // edbee
This clas represents a text buffer change and is used to pass around between events This is a sharedd...
Definition textbuffer.h:45
This is the base and abstract class of a text document A TextDocument is the model part of the editor...
Definition textdocument.h:42
General configuration settings of the text editor.
Definition texteditorconfig.h:18
The texteditor works via the controller. The controller is the central point/mediator which maps/cont...
Definition texteditorcontroller.h:39
This is the general edbee widget The core functionality of this widget is divided in several separate...
Definition texteditorwidget.h:36
A virtual textlayout.
Definition textlayout.h:28
The basic textrange class. A simple class of textrange with a simple vector implementation.
Definition textrange.h:202
TextRenderer(TextEditorController *controller)
The default textrenderer constructor.
Definition textrenderer.cpp:36
int viewportHeight()
Definition textrenderer.h:93
int viewHeightInLines()
This method returns the number of lines.
Definition textrenderer.cpp:165
void setCaretVisible(bool visible)
sets the carets to visible or invisible
Definition textrenderer.cpp:577
int endLine()
This method is valid only while rendering!
Definition textrenderer.h:108
int viewportY()
Definition textrenderer.h:91
int nrWidth()
The M-width isn't good enough for calculating the width of numbers. Often the M is to wide....
Definition textrenderer.cpp:158
TextThemeStyler * themeStyler()
Definition textrenderer.h:96
int totalHeight()
This method returns the total height.
Definition textrenderer.cpp:143
void resetCaretTime()
sets the caret time on 0
Definition textrenderer.cpp:551
int rawLineIndexForYpos(int y)
This method converts the give y position to a line index Warning this returns a RAW line index,...
Definition textrenderer.cpp:95
void setViewport(const QRect &viewport)
Sets the current viewport of the renderer.
Definition textrenderer.cpp:544
TextLayout * textLayoutForLineNormal(int line)
Definition textrenderer.cpp:338
int endOffset()
This method is valid only while rendering!
Definition textrenderer.h:106
int totalWidth()
Returns the total width of the editor. This method is NOT the real with This method takes the maximum...
Definition textrenderer.cpp:113
int xPosForColumn(int line, int column)
This method returns the x position for the given column.
Definition textrenderer.cpp:192
int yPosForOffset(int offset)
This method returns the offset position for the given line.
Definition textrenderer.cpp:226
int startOffset()
This method is valid only while rendering!
Definition textrenderer.h:105
TextEditorController * controller()
returns a reference to the given controller
Definition textrenderer.cpp:530
void renderEnd(const QRect &rect)
This method starts rendering.
Definition textrenderer.cpp:493
const QRect * clipRect()
This method is valid only while rendering!
Definition textrenderer.h:104
TextDocument * placeholderTextDocument()
Definition textrenderer.cpp:509
void renderBegin(const QRect &rect)
This method starts rendering.
Definition textrenderer.cpp:450
QRect viewport()
Definition textrenderer.h:89
int lineIndexForYpos(int y)
This method returns a valid line index for the given y-pos If the y-position isn't on a line it retur...
Definition textrenderer.cpp:103
TextLayout * textLayoutForLineForPlaceholder(int line)
Definition textrenderer.cpp:282
int firstVisibleLine()
This method returns the first visible line.
Definition textrenderer.cpp:173
TextDocument * textDocument()
This method returns the document.
Definition textrenderer.cpp:500
QString getLine(int index)
int columnIndexForXpos(int line, int x)
This method returns the (closet) valid column for the given x-position.
Definition textrenderer.cpp:180
int viewportX()
Definition textrenderer.h:90
int startLine()
This method is valid only while rendering!
Definition textrenderer.h:107
int lineHeight()
This method returns the (maximum) line-height in pixels.
Definition textrenderer.cpp:83
virtual void reset()
This method resets all caching information.
Definition textrenderer.cpp:75
TextEditorConfig * config()
Returns the editor configuration.
Definition textrenderer.cpp:523
bool shouldRenderCaret()
this method returns true if the caret is visible
Definition textrenderer.cpp:560
virtual void init()
The init method is called if all objects required for editing have been created!
Definition textrenderer.cpp:67
int emWidth()
This method returns width of the M cahracter.
Definition textrenderer.cpp:150
int viewportWidth()
Definition textrenderer.h:92
int xPosForOffset(int offset)
This method returns the x-coordinate for the given offset.
Definition textrenderer.cpp:204
bool isCaretVisible()
Returns true if the caret is visible.
Definition textrenderer.cpp:570
TextLayout * textLayoutForLine(int line)
This method returns the textlayout for the given line.
Definition textrenderer.cpp:233
TextSelection * textSelection()
This method returns the textselection.
Definition textrenderer.cpp:516
int yPosForLine(int line)
This method returns the y position for the given line.
Definition textrenderer.cpp:219
TextEditorWidget * textWidget()
This method returns the widget.
Definition textrenderer.cpp:537
The class textselection is a RangeSet that is used by the view of the document.
Definition textselection.h:25
This class defines a single theme.
Definition texttheme.h:68
This class is used to return the style formats for rendering the texts.
Definition texttheme.h:157
#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