Kate
katelayoutcache.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 #ifndef KATELAYOUTCACHE_H
00021 #define KATELAYOUTCACHE_H
00022
00023 #include <QThreadStorage>
00024 #include <QPair>
00025 #include <QMutex>
00026
00027 #include <ktexteditor/range.h>
00028
00029 #include "katetextlayout.h"
00030
00031 class KateRenderer;
00032 class KateEditInfo;
00033
00034 namespace KTextEditor { class Document; }
00035
00036 class KateLineLayoutMap
00037 {
00038 public:
00039 KateLineLayoutMap();
00040 ~KateLineLayoutMap();
00041
00042 inline void clear();
00043
00044 inline bool contains(int i) const;
00045
00046 inline void insert(int realLine, const KateLineLayoutPtr& lineLayoutPtr);
00047
00048 inline void viewWidthIncreased();
00049 inline void viewWidthDecreased(int newWidth);
00050
00051 inline void relayoutLines(int startRealLine, int endRealLine);
00052
00053 inline void slotEditDone(int fromLine, int toLine, int shiftAmount);
00054
00055 KateLineLayoutPtr& operator[](int i);
00056
00057 typedef QPair<int, KateLineLayoutPtr> LineLayoutPair;
00058 private:
00059 typedef QVector<LineLayoutPair> LineLayoutMap;
00060 LineLayoutMap m_lineLayouts;
00061 };
00062
00064 class QAssertMutexLocker {
00065 public:
00066 QAssertMutexLocker(QMutex& mutex) : m_mutex(mutex) {
00067 wait.lock();
00068 if(!m_mutex.tryLock()) {
00069
00070
00071 Q_ASSERT(0);
00072 m_mutex.lock();
00073 }
00074 wait.unlock();
00075 }
00076
00077 ~QAssertMutexLocker() {
00078 wait.lock();
00079 m_mutex.unlock();
00080 wait.unlock();
00081 }
00082
00083 private:
00084 QMutex& m_mutex;
00085 static QMutex wait;
00086 };
00087
00105 class KateLayoutCache : public QObject
00106 {
00107 Q_OBJECT
00108
00109 public:
00110 explicit KateLayoutCache(KateRenderer* renderer, QObject* parent);
00111
00112 void clear();
00113
00114 int viewWidth() const;
00115 void setViewWidth(int width);
00116
00117 bool wrap() const;
00118 void setWrap(bool wrap);
00119
00120 bool acceptDirtyLayouts() const;
00121 void setAcceptDirtyLayouts(bool accept);
00122
00123
00136 KateLineLayoutPtr line(int realLine, int virtualLine = -1) const;
00138 KateLineLayoutPtr line(const KTextEditor::Cursor& realCursor) const;
00139
00141 KateTextLayout textLayout(const KTextEditor::Cursor& realCursor) const;
00142
00145 KateTextLayout textLayout(uint realLine, int viewLine) const;
00146
00147
00148
00150 KateTextLayout& viewLine(int viewLine) const;
00151
00152
00153
00154 int displayViewLine(const KTextEditor::Cursor& virtualCursor, bool limitToVisible = false) const;
00155
00156 int viewCacheLineCount() const;
00157 KTextEditor::Cursor viewCacheStart() const;
00158 KTextEditor::Cursor viewCacheEnd() const;
00159 void updateViewCache(const KTextEditor::Cursor& startPos, int newViewLineCount = -1, int viewLinesScrolled = 0);
00160
00161 void relayoutLines(int startRealLine, int endRealLine);
00162
00163
00164 int lastViewLine(int realLine) const;
00165
00166 int viewLine(const KTextEditor::Cursor& realCursor) const;
00167 int viewLineCount(int realLine) const;
00168
00169 void viewCacheDebugOutput() const;
00170
00171
00172 private Q_SLOTS:
00173 void slotEditDone(KateEditInfo* edit);
00174
00175 private:
00176
00177 KateRenderer* m_renderer;
00178
00185 mutable KateLineLayoutMap m_lineLayouts;
00186
00187
00188 KTextEditor::Cursor m_startPos;
00189 mutable QVector<KateTextLayout> m_textLayouts;
00190
00191 int m_viewWidth;
00192 bool m_wrap;
00193
00194 QThreadStorage<bool*> m_acceptDirtyLayouts;
00195
00196 mutable QMutex m_debugMutex;
00197 };
00198
00199 #endif
00200
00201