• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • render
katetextlayout.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2002-2005 Hamish Rodda <rodda@kde.org>
3  Copyright (C) 2003 Anakim Border <aborder@sources.sourceforge.net>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "katetextlayout.h"
21 
22 #include <kdebug.h>
23 
24 KateTextLayout::KateTextLayout(KateLineLayoutPtr line, int viewLine)
25  : m_lineLayout(line)
26  , m_viewLine(viewLine)
27  , m_startX(m_viewLine ? -1 : 0)
28  , m_invalidDirty(true)
29 {
30  if (isValid())
31  m_textLayout = m_lineLayout->layout()->lineAt(m_viewLine);
32 }
33 
34 bool KateTextLayout::isDirty( ) const
35 {
36  if (!isValid())
37  return m_invalidDirty;
38 
39  return m_lineLayout->isDirty(viewLine());
40 }
41 
42 bool KateTextLayout::setDirty( bool dirty )
43 {
44  if (!isValid())
45  return (m_invalidDirty = dirty);
46 
47  return m_lineLayout->setDirty(viewLine(), dirty);
48 }
49 
50 bool KateTextLayout::includesCursor(const KTextEditor::Cursor& realCursor) const
51 {
52  return realCursor.line() == line() && realCursor.column() >= startCol() && (!wrap() || realCursor.column() < endCol());
53 }
54 
55 int KateTextLayout::xOffset() const
56 {
57  if (!isValid())
58  return 0;
59 
60  return startX() ? m_lineLayout->shiftX() : 0;
61 }
62 
63 void KateTextLayout::debugOutput() const
64 {
65  kDebug( 13033 ) << "KateTextLayout: " << m_lineLayout << " valid " << isValid() << " line " << m_lineLayout->line() << " (" << line() << ") cols [" << startCol() << " -> " << endCol() << "] x [" << startX() << " -> " << endX() << " off " << m_lineLayout->shiftX() << "] wrap " << wrap();
66 }
67 
68 bool operator> (const KateTextLayout& r, const KTextEditor::Cursor& c)
69 {
70  return r.line() > c.line() || r.endCol() > c.column();
71 }
72 
73 bool operator>= (const KateTextLayout& r, const KTextEditor::Cursor& c)
74 {
75  return r.line() > c.line() || r.endCol() >= c.column();
76 }
77 
78 bool operator< (const KateTextLayout& r, const KTextEditor::Cursor& c)
79 {
80  return r.line() < c.line() || r.startCol() < c.column();
81 }
82 
83 bool operator<= (const KateTextLayout& r, const KTextEditor::Cursor& c)
84 {
85  return r.line() < c.line() || r.startCol() <= c.column();
86 }
87 
88 bool KateTextLayout::isValid( ) const
89 {
90  return m_lineLayout && m_lineLayout->isValid() && m_viewLine >= 0 && m_viewLine < m_lineLayout->viewLineCount();
91 }
92 
93 int KateTextLayout::line( ) const
94 {
95  if (!isValid())
96  return -1;
97 
98  return m_lineLayout->line();
99 }
100 
101 int KateTextLayout::virtualLine( ) const
102 {
103  if (!isValid())
104  return -1;
105 
106  return m_lineLayout->virtualLine();
107 }
108 
109 int KateTextLayout::viewLine( ) const
110 {
111  if (!isValid())
112  return 0;
113 
114  return m_viewLine;
115 }
116 
117 const QTextLine & KateTextLayout::lineLayout( ) const
118 {
119  return m_textLayout;
120 }
121 
122 KateLineLayoutPtr KateTextLayout::kateLineLayout( ) const
123 {
124  return m_lineLayout;
125 }
126 
127 int KateTextLayout::startCol( ) const
128 {
129  if (!isValid())
130  return 0;
131 
132  return lineLayout().textStart();
133 }
134 
135 KTextEditor::Cursor KateTextLayout::start( ) const
136 {
137  return KTextEditor::Cursor(line(), startCol());
138 }
139 
140 int KateTextLayout::endCol(bool indicateEOL) const
141 {
142  if (!isValid())
143  return 0;
144 
145  if (indicateEOL)
146  if (viewLine() == kateLineLayout()->viewLineCount() - 1)
147  return -1;
148 
149  return startCol() + m_textLayout.textLength();
150 }
151 
152 KTextEditor::Cursor KateTextLayout::end(bool indicateEOL) const
153 {
154  return KTextEditor::Cursor(line(), endCol(indicateEOL));
155 }
156 
157 int KateTextLayout::length( ) const
158 {
159  if (!isValid())
160  return 0;
161 
162  return m_textLayout.textLength();
163 }
164 
165 bool KateTextLayout::isEmpty( ) const
166 {
167  if (!isValid())
168  return true;
169 
170  return startCol() == 0 && endCol() == 0;
171 }
172 
173 bool KateTextLayout::wrap( ) const
174 {
175  if (!isValid())
176  return false;
177 
178  return viewLine() < m_lineLayout->viewLineCount() - 1;
179 }
180 
181 int KateTextLayout::startX( ) const
182 {
183  if (!isValid())
184  return 0;
185 
186  if (m_startX == -1)
187  // viewLine is already > 0, from the constructor
188  for (int i = 0; i < viewLine(); ++i)
189  m_startX += (int)m_lineLayout->layout()->lineAt(i).naturalTextWidth();
190 
191  return m_startX;
192 }
193 
194 int KateTextLayout::endX( ) const
195 {
196  if (!isValid())
197  return 0;
198 
199  return startX() + (int)m_textLayout.naturalTextWidth();
200 }
201 
202 int KateTextLayout::width( ) const
203 {
204  if (!isValid())
205  return 0;
206 
207  return (int)m_textLayout.naturalTextWidth();
208 }
209 
210 KateTextLayout KateTextLayout::invalid( )
211 {
212  return KateTextLayout();
213 }
214 
215 bool KateTextLayout::isRightToLeft() const
216 {
217  if (m_lineLayout)
218  return m_lineLayout->isRightToLeft();
219 
220  return false;
221 }
operator<
bool operator<(const KateTextLayout &r, const KTextEditor::Cursor &c)
Definition: katetextlayout.cpp:78
KateTextLayout::startCol
int startCol() const
Definition: katetextlayout.cpp:127
KateTextLayout::line
int line() const
Definition: katetextlayout.cpp:93
KateTextLayout::isEmpty
bool isEmpty() const
Definition: katetextlayout.cpp:165
KateTextLayout::isValid
bool isValid() const
Definition: katetextlayout.cpp:88
KateTextLayout::debugOutput
void debugOutput() const
Definition: katetextlayout.cpp:63
KateTextLayout::start
KTextEditor::Cursor start() const
Definition: katetextlayout.cpp:135
operator>=
bool operator>=(const KateTextLayout &r, const KTextEditor::Cursor &c)
Definition: katetextlayout.cpp:73
KateTextLayout::startX
int startX() const
Definition: katetextlayout.cpp:181
KateTextLayout::setDirty
bool setDirty(bool dirty=true)
Definition: katetextlayout.cpp:42
KateTextLayout::length
int length() const
Definition: katetextlayout.cpp:157
KateTextLayout::endCol
int endCol(bool indicateEOL=false) const
Return the end column of this text line.
Definition: katetextlayout.cpp:140
KateTextLayout::xOffset
int xOffset() const
Definition: katetextlayout.cpp:55
KateTextLayout::isRightToLeft
bool isRightToLeft() const
Definition: katetextlayout.cpp:215
KateTextLayout::viewLine
int viewLine() const
Return the index of this visual line inside the document line (KateLineLayout).
Definition: katetextlayout.cpp:109
KateTextLayout::kateLineLayout
KateLineLayoutPtr kateLineLayout() const
Definition: katetextlayout.cpp:122
operator<=
bool operator<=(const KateTextLayout &r, const KTextEditor::Cursor &c)
Definition: katetextlayout.cpp:83
katetextlayout.h
KateTextLayout::includesCursor
bool includesCursor(const KTextEditor::Cursor &realCursor) const
Definition: katetextlayout.cpp:50
KateTextLayout
This class represents one visible line of text; with dynamic wrapping, many KateTextLayouts can be ne...
Definition: katetextlayout.h:38
QTextLine
KateTextLayout::width
int width() const
Definition: katetextlayout.cpp:202
KateTextLayout::virtualLine
int virtualLine() const
Definition: katetextlayout.cpp:101
operator>
bool operator>(const KateTextLayout &r, const KTextEditor::Cursor &c)
Definition: katetextlayout.cpp:68
KateTextLayout::isDirty
bool isDirty() const
Definition: katetextlayout.cpp:34
KateTextLayout::end
KTextEditor::Cursor end(bool indicateEOL=false) const
Return the end position of this text line.
Definition: katetextlayout.cpp:152
KateTextLayout::endX
int endX() const
Definition: katetextlayout.cpp:194
KateTextLayout::lineLayout
const QTextLine & lineLayout() const
Definition: katetextlayout.cpp:117
KateTextLayout::invalid
static KateTextLayout invalid()
Definition: katetextlayout.cpp:210
KateLineLayoutPtr
KSharedPtr< KateLineLayout > KateLineLayoutPtr
Definition: katelinelayout.h:120
KateTextLayout::wrap
bool wrap() const
Definition: katetextlayout.cpp:173
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal