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;
00239
00245 KTextEditor::Cursor xToCursor(const KateTextLayout& range, int x, bool returnPastLine = false) const;
00246
00247
00248 uint fontHeight();
00249
00250
00251 uint documentHeight();
00252
00253
00254 bool getSelectionBounds(int line, int lineLength, int &start, int &end) const;
00255
00268 void paintTextLine(QPainter& paint, KateLineLayoutPtr range, int xStart, int xEnd, const KTextEditor::Cursor* cursor = 0L);
00269
00284 void paintTextLineBackground(QPainter& paint, KateLineLayoutPtr layout, int currentViewLine, int xStart, int xEnd);
00285
00293 KTextEditor::Attribute::Ptr attribute(uint pos) const;
00294 KTextEditor::Attribute::Ptr specificAttribute(int context) const;
00295
00296 private:
00300 void paintTrailingSpace(QPainter &paint, qreal x, qreal y);
00304 void paintTabstop(QPainter &paint, qreal x, qreal y);
00305
00307 void paintIndentMarker(QPainter &paint, uint x, uint y);
00308
00309 void assignSelectionBrushesFromAttribute(QTextLayout::FormatRange& target, const KTextEditor::Attribute& attribute) const;
00310
00311 KateDocument* m_doc;
00312 KateView *m_view;
00313
00314
00315 int m_tabWidth;
00316 int m_indentWidth;
00317
00318
00319 KateRenderer::caretStyles m_caretStyle;
00320 bool m_drawCaret;
00321 bool m_showSelections;
00322 bool m_showTabs;
00323 bool m_showSpaces;
00324 bool m_printerFriendly;
00325 QColor m_caretOverrideColor;
00326
00327 QList<KTextEditor::Attribute::Ptr> m_attributes;
00328
00332 public:
00333 inline KateRendererConfig *config () const { return m_config; }
00334
00335 void updateConfig ();
00336
00337 private:
00338 KateRendererConfig *m_config;
00339
00340 KateSmartRegion m_dynamicRegion;
00341 };
00342
00343 #endif