File indexing completed on 2024-04-28 15:30:35

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 "katetextline.h"
0015 
0016 #include <ktexteditor/cursor.h>
0017 
0018 class QTextLayout;
0019 namespace KTextEditor
0020 {
0021 class DocumentPrivate;
0022 }
0023 class KateTextLayout;
0024 class KateRenderer;
0025 
0026 class KateLineLayout final : public QSharedData
0027 {
0028 public:
0029     explicit KateLineLayout(KateRenderer &renderer);
0030 
0031     KTextEditor::DocumentPrivate *doc() const;
0032     void debugOutput() const;
0033 
0034     void clear();
0035     bool isValid() const;
0036     bool isOutsideDocument() const;
0037 
0038     bool isRightToLeft() const;
0039 
0040     bool includesCursor(const KTextEditor::Cursor realCursor) const;
0041 
0042     friend bool operator>(const KateLineLayout &r, const KTextEditor::Cursor c);
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 
0047     const Kate::TextLine &textLine(bool forceReload = false) const;
0048     int length() const;
0049 
0050     int line() const;
0051     /**
0052      * Only pass virtualLine if you know it (and thus we shouldn't try to look it up)
0053      */
0054     void setLine(int line, int virtualLine = -1);
0055     KTextEditor::Cursor start() const;
0056 
0057     int virtualLine() const;
0058     void setVirtualLine(int virtualLine);
0059 
0060     bool isDirty(int viewLine) const;
0061     bool setDirty(int viewLine, bool dirty = true);
0062 
0063     int width() const;
0064     int widthOfLastLine() const;
0065 
0066     int viewLineCount() const;
0067     KateTextLayout viewLine(int viewLine) const;
0068     int viewLineForColumn(int column) const;
0069 
0070     bool startsInvisibleBlock() const;
0071 
0072     // This variable is used as follows:
0073     // non-dynamic-wrapping mode: unused
0074     // dynamic wrapping mode:
0075     //   first viewLine of a line: the X position of the first non-whitespace char
0076     //   subsequent viewLines: the X offset from the left of the display.
0077     //
0078     // this is used to provide a dynamic-wrapping-retains-indent feature.
0079     int shiftX() const;
0080     void setShiftX(int shiftX);
0081 
0082     QTextLayout *layout() const;
0083     void setLayout(QTextLayout *layout);
0084     void invalidateLayout();
0085 
0086     bool isLayoutDirty() const;
0087     void setLayoutDirty(bool dirty = true);
0088 
0089     bool usePlainTextLine() const;
0090     void setUsePlainTextLine(bool plain = true);
0091 
0092 private:
0093     // Disable copy
0094     KateLineLayout(const KateLineLayout &copy);
0095 
0096     KateRenderer &m_renderer;
0097     mutable Kate::TextLine m_textLine;
0098     int m_line;
0099     int m_virtualLine;
0100     int m_shiftX;
0101 
0102     std::unique_ptr<QTextLayout> m_layout;
0103     QList<bool> m_dirtyList;
0104 
0105     bool m_layoutDirty;
0106     bool m_usePlainTextLine;
0107 };
0108 
0109 typedef QExplicitlySharedDataPointer<KateLineLayout> KateLineLayoutPtr;
0110 
0111 #endif