Kate
katelayoutcache.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries and the Kate part. 00002 * 00003 * Copyright (C) 2005 Hamish Rodda <rodda@kde.org> 00004 * Copyright (C) 2008 Dominik Haumann <dhaumann kde org> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef KATELAYOUTCACHE_H 00023 #define KATELAYOUTCACHE_H 00024 00025 #include <QPair> 00026 00027 #include <ktexteditor/range.h> 00028 00029 #include "katetextlayout.h" 00030 00031 class KateRenderer; 00032 00033 namespace KTextEditor { class Document; } 00034 00035 class KateLineLayoutMap 00036 { 00037 public: 00038 KateLineLayoutMap(); 00039 ~KateLineLayoutMap(); 00040 00041 inline void clear(); 00042 00043 inline bool contains(int i) const; 00044 00045 inline void insert(int realLine, const KateLineLayoutPtr& lineLayoutPtr); 00046 00047 inline void viewWidthIncreased(); 00048 inline void viewWidthDecreased(int newWidth); 00049 00050 inline void relayoutLines(int startRealLine, int endRealLine); 00051 00052 inline void slotEditDone(int fromLine, int toLine, int shiftAmount); 00053 00054 KateLineLayoutPtr& operator[](int i); 00055 00056 typedef QPair<int, KateLineLayoutPtr> LineLayoutPair; 00057 private: 00058 typedef QVector<LineLayoutPair> LineLayoutMap; 00059 LineLayoutMap m_lineLayouts; 00060 }; 00061 00079 class KateLayoutCache : public QObject 00080 { 00081 Q_OBJECT 00082 00083 public: 00084 explicit KateLayoutCache(KateRenderer* renderer, QObject* parent); 00085 00086 void clear(); 00087 00088 int viewWidth() const; 00089 void setViewWidth(int width); 00090 00091 bool wrap() const; 00092 void setWrap(bool wrap); 00093 00094 bool acceptDirtyLayouts(); 00095 void setAcceptDirtyLayouts(bool accept); 00096 00097 // BEGIN generic methods to get/set layouts 00110 KateLineLayoutPtr line(int realLine, int virtualLine = -1); 00112 KateLineLayoutPtr line(const KTextEditor::Cursor& realCursor); 00113 00115 KateTextLayout textLayout(const KTextEditor::Cursor& realCursor); 00116 00119 KateTextLayout textLayout(uint realLine, int viewLine); 00120 // END 00121 00122 // BEGIN methods to do with the caching of lines visible within a view 00124 KateTextLayout& viewLine(int viewLine); 00125 00126 // find the view line of the cursor, relative to the display (0 = top line of view, 1 = second line, etc.) 00127 // if limitToVisible is true, only lines which are currently visible will be searched for, and -1 returned if the line is not visible. 00128 int displayViewLine(const KTextEditor::Cursor& virtualCursor, bool limitToVisible = false); 00129 00130 int viewCacheLineCount() const; 00131 KTextEditor::Cursor viewCacheStart() const; 00132 KTextEditor::Cursor viewCacheEnd() const; 00133 void updateViewCache(const KTextEditor::Cursor& startPos, int newViewLineCount = -1, int viewLinesScrolled = 0); 00134 00135 void relayoutLines(int startRealLine, int endRealLine); 00136 00137 // find the index of the last view line for a specific line 00138 int lastViewLine(int realLine); 00139 // find the view line of cursor c (0 = same line, 1 = down one, etc.) 00140 int viewLine(const KTextEditor::Cursor& realCursor); 00141 int viewLineCount(int realLine); 00142 00143 void viewCacheDebugOutput() const; 00144 // END 00145 00146 private Q_SLOTS: 00147 void wrapLine (const KTextEditor::Cursor &position); 00148 void unwrapLine (int line); 00149 void insertText (const KTextEditor::Cursor &position, const QString &text); 00150 void removeText (const KTextEditor::Range &range); 00151 00152 private: 00153 KateRenderer* m_renderer; 00154 00161 mutable KateLineLayoutMap m_lineLayouts; 00162 00163 // Convenience vector for quick direct access to the specific text layout 00164 KTextEditor::Cursor m_startPos; 00165 mutable QVector<KateTextLayout> m_textLayouts; 00166 00167 int m_viewWidth; 00168 bool m_wrap; 00169 bool m_acceptDirtyLayouts; 00170 }; 00171 00172 #endif 00173 00174 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference