Kate
katerenderer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __KATE_RENDERER_H__
00024 #define __KATE_RENDERER_H__
00025
00026 #include "katecursor.h"
00027 #include <ktexteditor/attribute.h>
00028 #include "katetextline.h"
00029 #include "katelinelayout.h"
00030 #include "katesmartregion.h"
00031
00032 #include <QtGui/QFont>
00033 #include <QtGui/QFontMetrics>
00034 #include <QtCore/QList>
00035 #include <QtGui/QTextLine>
00036
00037 class KateDocument;
00038 class KateView;
00039 class KateRendererConfig;
00040 class KateRenderRange;
00041 namespace KTextEditor { class Range; }
00042
00043 class KateLineLayout;
00044 typedef KSharedPtr<KateLineLayout> KateLineLayoutPtr;
00045
00051 class KateRenderer
00052 {
00053 public:
00057 enum caretStyles {
00058 Line,
00059 Block
00060 };
00061
00067 explicit KateRenderer(KateDocument* doc, KateView *view = 0);
00068
00072 ~KateRenderer();
00073
00077 KateDocument* doc() const { return m_doc; }
00078
00082 KateView* view() const { return m_view; }
00083
00088 void updateAttributes ();
00089
00094 inline bool drawCaret() const { return m_drawCaret; }
00095
00100 void setDrawCaret(bool drawCaret);
00101
00106 inline KateRenderer::caretStyles caretStyle() const { return m_caretStyle; }
00107
00112 void setCaretStyle(KateRenderer::caretStyles style);
00113
00117 void setCaretOverrideColor(const QColor& color);
00118
00124 inline bool showTabs() const { return m_showTabs; }
00125
00130 void setShowTabs(bool showTabs);
00131
00135 inline bool showTrailingSpaces() const { return m_showSpaces; }
00136
00140 void setShowTrailingSpaces(bool showSpaces);
00141
00146 void setTabWidth(int tabWidth);
00147
00152 bool showIndentLines() const;
00153
00158 void setShowIndentLines(bool showLines);
00159
00164 void setIndentWidth(int indentWidth);
00165
00170 inline bool showSelections() const { return m_showSelections; }
00171
00177 void setShowSelections(bool showSelections);
00178
00182 void increaseFontSizes();
00183 void decreaseFontSizes();
00184 const QFont& currentFont() const;
00185 const QFontMetrics& currentFontMetrics() const;
00186
00191 bool isPrinterFriendly() const;
00192
00198 void setPrinterFriendly(bool printerFriendly);
00199
00203 void layoutLine(KateLineLayoutPtr line, int maxwidth = -1, bool cacheLayout = false) const;
00204
00215 bool isLineRightToLeft( KateLineLayoutPtr lineLayout ) const;
00216
00223 QList<QTextLayout::FormatRange> decorationsForLine(const KateTextLine::Ptr& textLine, int line, bool selectionsOnly = false, KateRenderRange* completionHighlight = 0L, bool completionSelected = false) const;
00224
00225 KateSmartRegion& dynamicRegion() { return m_dynamicRegion; }
00226
00227
00228 uint spaceWidth() const;
00229 KDE_DEPRECATED uint textWidth(const KateTextLine::Ptr &, int cursorCol);
00230 KDE_DEPRECATED uint textWidth(const KateTextLine::Ptr &textLine, uint startcol, uint maxwidth, bool *needWrap, int *endX = 0);
00231 KDE_DEPRECATED uint textWidth(const KTextEditor::Cursor& cursor);
00232
00236 int cursorToX(const KateTextLayout& range, int col) const;
00238 int cursorToX(const KateTextLayout& range, const KTextEditor::Cursor& pos) const;
00240 int cursorToX(const KateTextLayout& range, const KTextEditor::Cursor& pos, bool returnPastLine) const;
00241
00247 KTextEditor::Cursor xToCursor(const KateTextLayout& range, int x, bool returnPastLine = false) const;
00248
00249
00250 uint fontHeight();
00251
00252
00253 uint documentHeight();
00254
00255
00256 bool getSelectionBounds(int line, int lineLength, int &start, int &end) const;
00257
00270 void paintTextLine(QPainter& paint, KateLineLayoutPtr range, int xStart, int xEnd, const KTextEditor::Cursor* cursor = 0L);
00271
00286 void paintTextLineBackground(QPainter& paint, KateLineLayoutPtr layout, int currentViewLine, int xStart, int xEnd);
00287
00295 KTextEditor::Attribute::Ptr attribute(uint pos) const;
00296 KTextEditor::Attribute::Ptr specificAttribute(int context) const;
00297
00298 private:
00302 void paintTrailingSpace(QPainter &paint, qreal x, qreal y);
00306 void paintTabstop(QPainter &paint, qreal x, qreal y);
00307
00309 void paintIndentMarker(QPainter &paint, uint x, uint y);
00310
00311 void assignSelectionBrushesFromAttribute(QTextLayout::FormatRange& target, const KTextEditor::Attribute& attribute) const;
00312
00313 KateDocument* m_doc;
00314 KateView *m_view;
00315
00316
00317 int m_tabWidth;
00318 int m_indentWidth;
00319
00320
00321 KateRenderer::caretStyles m_caretStyle;
00322 bool m_drawCaret;
00323 bool m_showSelections;
00324 bool m_showTabs;
00325 bool m_showSpaces;
00326 bool m_printerFriendly;
00327 QColor m_caretOverrideColor;
00328
00329 QList<KTextEditor::Attribute::Ptr> m_attributes;
00330
00334 public:
00335 inline KateRendererConfig *config () const { return m_config; }
00336
00337 void updateConfig ();
00338
00339 private:
00340 KateRendererConfig *m_config;
00341
00342 KateSmartRegion m_dynamicRegion;
00343 };
00344
00345 #endif