edbee - Qt Editor Library
textrenderer.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <QCache>
9 #include <QObject>
10 #include <QHash>
11 #include <QRect>
12 
13 
15 
16 class QPainter;
17 class QRect;
18 class QTextLayout;
19 
20 
21 namespace edbee {
22 
23 class AbstractComponent;
24 class TextDocument;
25 class TextEditorConfig;
26 class TextEditorController;
27 class TextEditorWidget;
28 class TextSelection;
29 class TextTheme;
30 class TextThemeStyler;
31 
34 class TextRenderer : public QObject
35 {
36 Q_OBJECT
37 
38 public:
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();
52  int viewHeightInLines();
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 // caching
62  QTextLayout* textLayoutForLine( int line );
63 
64 // rendering
65  void renderBegin(const QRect& rect );
66  void renderEnd( const QRect& rect );
67 
68 // getters / setters
74 
75  void setViewport( const QRect& viewport );
76 
77  void resetCaretTime();
78  bool shouldRenderCaret();
79  bool isCaretVisible();
80  void setCaretVisible(bool visible);
81 
82  QRect viewport() { return viewport_; }
83  int viewportX() { return viewport_.x(); }
84  int viewportY(){ return viewport_.y(); }
85  int viewportWidth() { return viewport_.width(); }
86  int viewportHeight() { return viewport_.height(); }
87 
88 // theme support
89  TextThemeStyler* themeStyler() { return textThemeStyler_; }
90 
91  QString themeName() const;
92  TextTheme* theme();
93  void setThemeByName( const QString& name );
94  void setTheme( TextTheme* theme );
95 
96 
97 // temporary getters only valid while rendering!!
98  const QRect* clipRect() { return clipRectRef_; }
99  int startOffset() { return startOffset_; }
100  int endOffset() { return endOffset_; }
101  int startLine() { return startLine_; }
102  int endLine() { return endLine_; }
103 
104 private:
105  void updateWidthCacheForRange( int offset, int length );
106 
107 protected slots:
108 
109  void textDocumentChanged( edbee::TextDocument* oldDocument, edbee::TextDocument* newDocument );
110  void textChanged( edbee::TextBufferChange change );
111 
112  void lastScopedOffsetChanged( int previousOffset, int newOffset );
113 
114 public slots:
115 
116  void invalidateTextLayoutCaches(int fromLine=0);
117  void invalidateCaches();
118 
119 private:
120 
121  TextEditorController* controllerRef_;
122  qint64 caretTime_;
123  qint64 caretBlinkRate_;
124 
125  QCache<int,QTextLayout> cachedTextLayoutList_;
126 
127  QRect viewport_;
128  int totalWidthCache_;
129 
130  TextThemeStyler* textThemeStyler_;
131 
132  // temporary variables only valid the int the current context
133  const QRect* clipRectRef_;
134  int startOffset_;
135  int endOffset_;
136  int startLine_;
137  int endLine_;
138 
139 };
140 
141 } // edbee
int startLine()
This method is valid only while rendering!
Definition: textrenderer.h:101
This is the base and abstract class of a text document A TextDocument is the model part of the editor...
Definition: textdocument.h:40
virtual void init()
The init method is called if all objects required for editing have been created!
Definition: textrenderer.cpp:57
int viewportY()
Definition: textrenderer.h:84
This clas represents a text buffer change and is used to pass around between events This is a sharedd...
Definition: textbuffer.h:45
A class for rendering the text.
Definition: textrenderer.h:34
void setViewport(const QRect &viewport)
Sets the current viewport of the renderer.
Definition: textrenderer.cpp:380
void setThemeByName(const QString &name)
Selects the active theme name.
Definition: textrenderer.cpp:434
int yPosForLine(int line)
This method returns the y position for the given line.
Definition: textrenderer.cpp:211
int viewportHeight()
Definition: textrenderer.h:86
QTextLayout * textLayoutForLine(int line)
This method returns the textlayout for the given line.
Definition: textrenderer.cpp:227
int lineHeight()
This method returns the (maximum) line-height in pixels.
Definition: textrenderer.cpp:73
int endLine()
This method is valid only while rendering!
Definition: textrenderer.h:102
int viewportX()
Definition: textrenderer.h:83
void invalidateTextLayoutCaches(int fromLine=0)
Invalidates the QTextLayout caches.
Definition: textrenderer.cpp:500
int totalHeight()
This method returns the total height.
Definition: textrenderer.cpp:133
void lastScopedOffsetChanged(int previousOffset, int newOffset)
The scoped to offset has been changed.
Definition: textrenderer.cpp:489
QRect viewport()
Definition: textrenderer.h:82
int lineIndexForYpos(int y)
This method returns a valid line index for the given y-pos If the y-position isn&#39;t on a line it retur...
Definition: textrenderer.cpp:93
This class is used to return the style formats for rendering the texts.
Definition: texttheme.h:157
TextEditorWidget * textWidget()
This method returns the widget.
Definition: textrenderer.cpp:373
TextSelection * textSelection()
This method returns the textselection.
Definition: textrenderer.cpp:352
void renderBegin(const QRect &rect)
This method starts rendering.
Definition: textrenderer.cpp:295
TextEditorController * controller()
returns a reference to the given controller
Definition: textrenderer.cpp:366
int totalWidth()
Returns the total width of the editor. This method is NOT the real with This method takes the maximum...
Definition: textrenderer.cpp:103
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:85
The class textselection is a RangeSet that is used by the view of the document.
Definition: textselection.h:24
void resetCaretTime()
sets the caret time on 0
Definition: textrenderer.cpp:387
bool isCaretVisible()
Returns true if the caret is visible.
Definition: textrenderer.cpp:406
int viewHeightInLines()
This method returns the number of lines.
Definition: textrenderer.cpp:155
void textDocumentChanged(edbee::TextDocument *oldDocument, edbee::TextDocument *newDocument)
The text-document has been changed.
Definition: textrenderer.cpp:451
int xPosForColumn(int line, int column)
This method returns the x position for the given column.
Definition: textrenderer.cpp:183
int xPosForOffset(int offset)
This method returns the x-coordinate for the given offset.
Definition: textrenderer.cpp:196
QString themeName() const
returns the current theme name
Definition: textrenderer.cpp:420
TextEditorConfig * config()
Returns the editor configuration.
Definition: textrenderer.cpp:359
int endOffset()
This method is valid only while rendering!
Definition: textrenderer.h:100
General configuration settings of the text editor.
Definition: texteditorconfig.h:17
Copyright 2011-2013 - Reliable Bits Software by Blommers IT.
Definition: commentcommand.cpp:22
TextThemeStyler * themeStyler()
Definition: textrenderer.h:89
void invalidateCaches()
call this method to invalidate all caches!
Definition: textrenderer.cpp:517
int firstVisibleLine()
This method returns the first visible line.
Definition: textrenderer.cpp:163
const QRect * clipRect()
This method is valid only while rendering!
Definition: textrenderer.h:98
void setTheme(TextTheme *theme)
sets the theme
Definition: textrenderer.cpp:443
virtual void reset()
This method resets all caching information.
Definition: textrenderer.cpp:65
virtual ~TextRenderer()
the destructor
Definition: textrenderer.cpp:48
void renderEnd(const QRect &rect)
This method starts rendering.
Definition: textrenderer.cpp:338
This class defines a single theme.
Definition: texttheme.h:68
The texteditor works via the controller. The controller is the central point/mediater which maps/cont...
Definition: texteditorcontroller.h:37
TextDocument * textDocument()
This method returns the document.
Definition: textrenderer.cpp:345
int viewportWidth()
Definition: textrenderer.h:85
TextTheme * theme()
Returns the active theme.
Definition: textrenderer.cpp:427
int nrWidth()
The M-width isn&#39;t good enough for calculating the width of numbers. Often the M is to wide...
Definition: textrenderer.cpp:148
This is the general edbee widget This core functionality of this widget is divided in several seperat...
Definition: texteditorwidget.h:32
int columnIndexForXpos(int line, int x)
This method returns the (closet) valid column for the given x-position.
Definition: textrenderer.cpp:170
void setCaretVisible(bool visible)
sets the carets to visible or invisible
Definition: textrenderer.cpp:413
int yPosForOffset(int offset)
This method returns the offset position for the given line.
Definition: textrenderer.cpp:218
bool shouldRenderCaret()
this method returnst true if the caret is visible
Definition: textrenderer.cpp:396
void textChanged(edbee::TextBufferChange change)
The text is replaced.
Definition: textrenderer.cpp:466
TextRenderer(TextEditorController *controller)
The default textrenderer constructor.
Definition: textrenderer.cpp:33
int startOffset()
This method is valid only while rendering!
Definition: textrenderer.h:99
int emWidth()
This method returns width of the M cahracter.
Definition: textrenderer.cpp:140