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 int lineHeight();
00254
00255
00256 uint documentHeight();
00257
00258
00259 bool getSelectionBounds(int line, int lineLength, int &start, int &end) const;
00260
00273 void paintTextLine(QPainter& paint, KateLineLayoutPtr range, int xStart, int xEnd, const KTextEditor::Cursor* cursor = 0L);
00274
00289 void paintTextLineBackground(QPainter& paint, KateLineLayoutPtr layout, int currentViewLine, int xStart, int xEnd);
00290
00298 KTextEditor::Attribute::Ptr attribute(uint pos) const;
00299 KTextEditor::Attribute::Ptr specificAttribute(int context) const;
00300
00301 private:
00305 void paintTrailingSpace(QPainter &paint, qreal x, qreal y);
00309 void paintTabstop(QPainter &paint, qreal x, qreal y);
00310
00312 void paintIndentMarker(QPainter &paint, uint x, uint y);
00313
00314 void assignSelectionBrushesFromAttribute(QTextLayout::FormatRange& target, const KTextEditor::Attribute& attribute) const;
00315
00316 KateDocument* m_doc;
00317 KateView *m_view;
00318
00319
00320 int m_tabWidth;
00321 int m_indentWidth;
00322
00323
00324 KateRenderer::caretStyles m_caretStyle;
00325 bool m_drawCaret;
00326 bool m_showSelections;
00327 bool m_showTabs;
00328 bool m_showSpaces;
00329 bool m_printerFriendly;
00330 QColor m_caretOverrideColor;
00331
00332 QList<KTextEditor::Attribute::Ptr> m_attributes;
00333
00337 public:
00338 inline KateRendererConfig *config () const { return m_config; }
00339
00340 void updateConfig ();
00341
00342 private:
00343 KateRendererConfig *m_config;
00344
00345 KateSmartRegion m_dynamicRegion;
00346 };
00347
00348 #endif