KTextEditor

katerenderer.h
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2007 Mirko Stocker <[email protected]>
4  SPDX-FileCopyrightText: 2003-2005 Hamish Rodda <[email protected]>
5  SPDX-FileCopyrightText: 2001 Christoph Cullmann <[email protected]>
6  SPDX-FileCopyrightText: 2001 Joseph Wenninger <[email protected]>
7  SPDX-FileCopyrightText: 1999 Jochen Wilhelmy <[email protected]>
8 
9  SPDX-License-Identifier: LGPL-2.0-only
10 */
11 
12 #ifndef KATE_RENDERER_H
13 #define KATE_RENDERER_H
14 
15 #include "kateconfig.h"
16 #include "katelinelayout.h"
17 #include "katetextline.h"
18 #include <ktexteditor/attribute.h>
19 
20 #include <QFlags>
21 #include <QFont>
22 #include <QFontMetricsF>
23 #include <QTextLine>
24 
25 namespace KTextEditor
26 {
27 class DocumentPrivate;
28 }
29 namespace KTextEditor
30 {
31 class ViewPrivate;
32 }
33 class KateRendererConfig;
34 class KateRenderRange;
35 namespace Kate
36 {
37 class TextFolding;
38 }
39 
46 {
47 public:
64  enum caretStyles { Line, Block, Underline, Half };
65 
72  explicit KateRenderer(KTextEditor::DocumentPrivate *doc, Kate::TextFolding &folding, KTextEditor::ViewPrivate *view = nullptr);
73 
77  ~KateRenderer();
78 
79  KateRenderer(const KateRenderer &) = delete;
80  KateRenderer &operator=(const KateRenderer &) = delete;
81 
85  KTextEditor::DocumentPrivate *doc() const
86  {
87  return m_doc;
88  }
89 
95  {
96  return m_folding;
97  }
98 
102  KTextEditor::ViewPrivate *view() const
103  {
104  return m_view;
105  }
106 
111  void updateAttributes();
112 
117  inline bool drawCaret() const
118  {
119  return m_drawCaret;
120  }
121 
126  void setDrawCaret(bool drawCaret);
127 
133  {
134  return m_caretStyle;
135  }
136 
141  void setCaretStyle(KateRenderer::caretStyles style);
142 
146  void setCaretOverrideColor(const QColor &color);
147 
153  inline bool showTabs() const
154  {
155  return m_showTabs;
156  }
157 
162  void setShowTabs(bool showTabs);
163 
167  void setShowSpaces(KateDocumentConfig::WhitespaceRendering showSpaces);
168 
172  inline KateDocumentConfig::WhitespaceRendering showSpaces() const
173  {
174  return m_showSpaces;
175  }
176 
180  void updateMarkerSize();
181 
185  inline bool showNonPrintableSpaces() const
186  {
187  return m_showNonPrintableSpaces;
188  }
189 
193  void setShowNonPrintableSpaces(const bool showNonPrintableSpaces);
194 
199  void setTabWidth(int tabWidth);
200 
205  bool showIndentLines() const;
206 
211  void setShowIndentLines(bool showLines);
212 
217  void setIndentWidth(int indentWidth);
218 
223  inline bool showSelections() const
224  {
225  return m_showSelections;
226  }
227 
233  void setShowSelections(bool showSelections);
234 
238  void increaseFontSizes(qreal step = 1.0);
239  void decreaseFontSizes(qreal step = 1.0);
240  void resetFontSizes();
241 
246  const QFont &currentFont() const
247  {
248  return m_font;
249  }
250 
256  {
257  return m_fontMetrics;
258  }
259 
264  bool isPrinterFriendly() const;
265 
271  void setPrinterFriendly(bool printerFriendly);
272 
276  void layoutLine(KateLineLayoutPtr line, int maxwidth = -1, bool cacheLayout = false) const;
277 
288  bool isLineRightToLeft(KateLineLayoutPtr lineLayout) const;
289 
295  QVector<QTextLayout::FormatRange> decorationsForLine(const Kate::TextLine &textLine, int line, bool selectionsOnly = false, bool completionHighlight = false, bool completionSelected = false) const;
296 
297  // Width calculators
298  qreal spaceWidth() const;
299 
303  int cursorToX(const KateTextLayout &range, int col, bool returnPastLine = false) const;
305  int cursorToX(const KateTextLayout &range, const KTextEditor::Cursor &pos, bool returnPastLine = false) const;
306 
312  KTextEditor::Cursor xToCursor(const KateTextLayout &range, int x, bool returnPastLine = false) const;
313 
314  // Font height
315  uint fontHeight() const;
316 
317  // Line height
318  int lineHeight() const;
319 
320  // Document height
321  uint documentHeight() const;
322 
323  // Selection boundaries
324  bool getSelectionBounds(int line, int lineLength, int &start, int &end) const;
325 
333  SkipDrawFirstInvisibleLineUnderlined = 0x1,
334  };
335  Q_DECLARE_FLAGS(PaintTextLineFlags, PaintTextLineFlag)
336 
337 
350  void paintTextLine(QPainter &paint, KateLineLayoutPtr range, int xStart, int xEnd, const KTextEditor::Cursor *cursor = nullptr, PaintTextLineFlags flags = PaintTextLineFlags());
351 
366  void paintTextLineBackground(QPainter &paint, KateLineLayoutPtr layout, int currentViewLine, int xStart, int xEnd);
367 
375  KTextEditor::Attribute::Ptr attribute(uint pos) const;
376  KTextEditor::Attribute::Ptr specificAttribute(int context) const;
377 
378 private:
382  void paintSpace(QPainter &paint, qreal x, qreal y);
386  void paintTabstop(QPainter &paint, qreal x, qreal y);
387 
391  void paintNonBreakSpace(QPainter &paint, qreal x, qreal y);
392 
396  void paintNonPrintableSpaces(QPainter &paint, qreal x, qreal y, const QChar &chr);
397 
399  void paintIndentMarker(QPainter &paint, uint x, uint y);
400 
401  void assignSelectionBrushesFromAttribute(QTextLayout::FormatRange &target, const KTextEditor::Attribute &attribute) const;
402 
403  // update font height
404  void updateFontHeight();
405 
406  KTextEditor::DocumentPrivate *const m_doc;
407  Kate::TextFolding &m_folding;
408  KTextEditor::ViewPrivate *const m_view;
409 
410  // cache of config values
411  int m_tabWidth;
412  int m_indentWidth;
413  int m_fontHeight;
414  float m_fontAscent;
415 
416  // some internal flags
417  KateRenderer::caretStyles m_caretStyle;
418  bool m_drawCaret;
419  bool m_showSelections;
420  bool m_showTabs;
421  KateDocumentConfig::WhitespaceRendering m_showSpaces = KateDocumentConfig::None;
422  float m_markerSize;
423  bool m_showNonPrintableSpaces;
424  bool m_printerFriendly;
425  QColor m_caretOverrideColor;
426 
427  QVector<KTextEditor::Attribute::Ptr> m_attributes;
428 
432 public:
433  inline KateRendererConfig *config() const
434  {
435  return m_config;
436  }
437 
438  void updateConfig();
439 
440 private:
441  KateRendererConfig *const m_config;
442 
446  QFont m_font;
447 
451  QFontMetricsF m_fontMetrics;
452 };
453 
454 #endif
bool drawCaret() const
Determine whether the caret (text cursor) will be drawn.
Definition: katerenderer.h:117
bool showNonPrintableSpaces() const
Definition: katerenderer.h:185
The Cursor represents a position in a Document.
Definition: cursor.h:71
const QFont & currentFont() const
Access currently used font.
Definition: katerenderer.h:246
Handles all of the work of rendering the text (used for the views and printing)
Definition: katerenderer.h:45
KTextEditor::DocumentPrivate * doc() const
Returns the document to which this renderer is bound.
Definition: katerenderer.h:85
bool showSelections() const
Show the view&#39;s selection?
Definition: katerenderer.h:223
bool showTabs() const
Definition: katerenderer.h:153
Class representing the folding information for a TextBuffer.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
KateDocumentConfig * config()
Configuration.
Kate::TextFolding & folding() const
Returns the folding info to which this renderer is bound.
Definition: katerenderer.h:94
PaintTextLineFlag
Flags to customize the paintTextLine function behavior.
Definition: katerenderer.h:329
caretStyles
Style of Caret.
Definition: katerenderer.h:64
KateDocumentConfig::WhitespaceRendering showSpaces() const
Definition: katerenderer.h:172
This class represents one visible line of text; with dynamic wrapping, many KateTextLayouts can be ne...
KTextEditor::ViewPrivate * view() const
Returns the view to which this renderer is bound.
Definition: katerenderer.h:102
KateRenderer::caretStyles caretStyle() const
The style of the caret (text cursor) to be painted.
Definition: katerenderer.h:132
const QFontMetricsF & currentFontMetrics() const
Access currently used font metrics.
Definition: katerenderer.h:255
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Sep 17 2020 22:57:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.