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
00211 bool isLineRightToLeft( KateLineLayoutPtr lineLayout ) const;
00212
00219 QList<QTextLayout::FormatRange> decorationsForLine(const KateTextLine::Ptr& textLine, int line, bool selectionsOnly = false, KateRenderRange* completionHighlight = 0L, bool completionSelected = false) const;
00220
00221 KateSmartRegion& dynamicRegion() { return m_dynamicRegion; }
00222
00223
00224 uint spaceWidth() const;
00225 KDE_DEPRECATED uint textWidth(const KateTextLine::Ptr &, int cursorCol);
00226 KDE_DEPRECATED uint textWidth(const KateTextLine::Ptr &textLine, uint startcol, uint maxwidth, bool *needWrap, int *endX = 0);
00227 KDE_DEPRECATED uint textWidth(const KTextEditor::Cursor& cursor);
00228
00232 int cursorToX(const KateTextLayout& range, int col) const;
00234 int cursorToX(const KateTextLayout& range, const KTextEditor::Cursor& pos) const;
00235
00241 KTextEditor::Cursor xToCursor(const KateTextLayout& range, int x, bool returnPastLine = false) const;
00242
00243
00244 uint fontHeight();
00245
00246
00247 uint documentHeight();
00248
00249
00250 bool getSelectionBounds(int line, int lineLength, int &start, int &end) const;
00251
00264 void paintTextLine(QPainter& paint, KateLineLayoutPtr range, int xStart, int xEnd, const KTextEditor::Cursor* cursor = 0L);
00265
00280 void paintTextLineBackground(QPainter& paint, KateLineLayoutPtr layout, int currentViewLine, int xStart, int xEnd);
00281
00289 KTextEditor::Attribute::Ptr attribute(uint pos) const;
00290 KTextEditor::Attribute::Ptr specificAttribute(int context) const;
00291
00292 private:
00296 void paintTrailingSpace(QPainter &paint, qreal x, qreal y);
00300 void paintTabstop(QPainter &paint, qreal x, qreal y);
00301
00303 void paintIndentMarker(QPainter &paint, uint x, uint y);
00304
00305 void assignSelectionBrushesFromAttribute(QTextLayout::FormatRange& target, const KTextEditor::Attribute& attribute) const;
00306
00307 KateDocument* m_doc;
00308 KateView *m_view;
00309
00310
00311 int m_tabWidth;
00312 int m_indentWidth;
00313
00314
00315 KateRenderer::caretStyles m_caretStyle;
00316 bool m_drawCaret;
00317 bool m_showSelections;
00318 bool m_showTabs;
00319 bool m_showSpaces;
00320 bool m_printerFriendly;
00321 QColor m_caretOverrideColor;
00322
00323 QList<KTextEditor::Attribute::Ptr> m_attributes;
00324
00328 public:
00329 inline KateRendererConfig *config () const { return m_config; }
00330
00331 void updateConfig ();
00332
00333 private:
00334 KateRendererConfig *m_config;
00335
00336 KateSmartRegion m_dynamicRegion;
00337 };
00338
00339 #endif