File indexing completed on 2024-04-14 03:55:15

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_TEXTLAYOUT_H_
0009 #define _KATE_TEXTLAYOUT_H_
0010 
0011 #include <QTextLine>
0012 
0013 #include "katelinelayout.h"
0014 
0015 /**
0016  * This class represents one visible line of text; with dynamic wrapping,
0017  * many KateTextLayouts can be needed to represent one actual line of text
0018  * (ie. one KateLineLayout)
0019  */
0020 class KateTextLayout
0021 {
0022     friend class KateLineLayout;
0023     friend class KateLayoutCache;
0024 
0025 public:
0026     bool isValid() const;
0027     static KateTextLayout invalid();
0028 
0029     int line() const;
0030     int virtualLine() const;
0031     /** Return the index of this visual line inside the document line
0032         (KateLineLayout).  */
0033     int viewLine() const;
0034 
0035     const QTextLine &lineLayout() const;
0036     KateLineLayout *kateLineLayout() const;
0037 
0038     int startCol() const;
0039     KTextEditor::Cursor start() const;
0040 
0041     /**
0042      * Return the end column of this text line.
0043      *
0044      * \param indicateEOL set to true to return -1 if this layout is the
0045      *        end of the line, otherwise false to return the end column number
0046      */
0047     int endCol(bool indicateEOL = false) const;
0048 
0049     /**
0050      * Return the end position of this text line.
0051      *
0052      * \param indicateEOL set to true to return -1 if this layout is the
0053      *        end of the line, otherwise false to return the end column number
0054      */
0055     KTextEditor::Cursor end(bool indicateEOL = false) const;
0056 
0057     int length() const;
0058     bool isEmpty() const;
0059 
0060     bool wrap() const;
0061 
0062     bool isDirty() const;
0063     bool setDirty(bool dirty = true);
0064 
0065     int startX() const;
0066     int endX() const;
0067     int width() const;
0068 
0069     int xOffset() const;
0070 
0071     bool isRightToLeft() const;
0072 
0073     bool includesCursor(const KTextEditor::Cursor realCursor) const;
0074 
0075     friend bool operator>(const KateLineLayout &r, const KTextEditor::Cursor c);
0076     friend bool operator>=(const KateLineLayout &r, const KTextEditor::Cursor c);
0077     friend bool operator<(const KateLineLayout &r, const KTextEditor::Cursor c);
0078     friend bool operator<=(const KateLineLayout &r, const KTextEditor::Cursor c);
0079 
0080     void debugOutput() const;
0081 
0082     explicit KateTextLayout(KateLineLayout *line = nullptr, int viewLine = 0);
0083 
0084 private:
0085     KateLineLayout *m_lineLayout;
0086     QTextLine m_textLayout;
0087 
0088     int m_viewLine;
0089     mutable int m_startX;
0090     bool m_invalidDirty = true;
0091 };
0092 
0093 #endif