File indexing completed on 2024-04-21 03:57:33
0001 /* 0002 SPDX-FileCopyrightText: 2002-2005 Hamish Rodda <rodda@kde.org> 0003 SPDX-FileCopyrightText: 2003 Anakim Border <aborder@sources.sourceforge.net> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef _KATE_LINELAYOUT_H_ 0009 #define _KATE_LINELAYOUT_H_ 0010 0011 #include <QExplicitlySharedDataPointer> 0012 #include <QSharedData> 0013 0014 #include <optional> 0015 0016 #include "katetextline.h" 0017 0018 #include <ktexteditor/cursor.h> 0019 0020 class QTextLayout; 0021 namespace KTextEditor 0022 { 0023 class DocumentPrivate; 0024 } 0025 class KateTextLayout; 0026 class KateRenderer; 0027 0028 class KateLineLayout 0029 { 0030 public: 0031 explicit KateLineLayout(KateRenderer &renderer); 0032 0033 void debugOutput() const; 0034 0035 void clear(); 0036 bool isValid() const; 0037 bool isOutsideDocument() const; 0038 0039 bool isRightToLeft() const; 0040 0041 bool includesCursor(const KTextEditor::Cursor realCursor) const; 0042 0043 friend bool operator>(const KateLineLayout &r, const KTextEditor::Cursor c); 0044 friend bool operator>=(const KateLineLayout &r, const KTextEditor::Cursor c); 0045 friend bool operator<(const KateLineLayout &r, const KTextEditor::Cursor c); 0046 friend bool operator<=(const KateLineLayout &r, const KTextEditor::Cursor c); 0047 0048 const Kate::TextLine &textLine(bool forceReload = false) const; 0049 int length() const; 0050 0051 int line() const; 0052 /** 0053 * Only pass virtualLine if you know it (and thus we shouldn't try to look it up) 0054 */ 0055 void setLine(int line, int virtualLine = -1); 0056 KTextEditor::Cursor start() const; 0057 0058 int virtualLine() const; 0059 void setVirtualLine(int virtualLine); 0060 0061 bool isDirty(int viewLine) const; 0062 bool setDirty(int viewLine, bool dirty = true); 0063 0064 int width() const; 0065 int widthOfLastLine(); 0066 0067 int viewLineCount() const; 0068 KateTextLayout viewLine(int viewLine); 0069 int viewLineForColumn(int column) const; 0070 0071 bool startsInvisibleBlock() const; 0072 0073 QTextLayout *layout() const; 0074 void setLayout(QTextLayout *layout); 0075 void invalidateLayout(); 0076 0077 bool layoutDirty = true; 0078 bool usePlainTextLine = false; 0079 0080 // This variable is used as follows: 0081 // non-dynamic-wrapping mode: unused 0082 // dynamic wrapping mode: 0083 // first viewLine of a line: the X position of the first non-whitespace char 0084 // subsequent viewLines: the X offset from the left of the display. 0085 // 0086 // this is used to provide a dynamic-wrapping-retains-indent feature. 0087 int shiftX = 0; 0088 0089 private: 0090 // Disable copy 0091 KateLineLayout(const KateLineLayout ©); 0092 0093 KateRenderer &m_renderer; 0094 mutable std::optional<Kate::TextLine> m_textLine; 0095 int m_line; 0096 int m_virtualLine; 0097 0098 std::unique_ptr<QTextLayout> m_layout; 0099 QList<bool> m_dirtyList; 0100 }; 0101 0102 #endif