Kate
katetextlayout.cpp
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 #include "katetextlayout.h"
00021
00022 #include <kdebug.h>
00023
00024 KateTextLayout::KateTextLayout(KateLineLayoutPtr line, int viewLine)
00025 : m_lineLayout(line)
00026 , m_viewLine(viewLine)
00027 , m_startX(m_viewLine ? -1 : 0)
00028 , m_invalidDirty(true)
00029 {
00030 if (isValid())
00031 m_textLayout = m_lineLayout->layout()->lineAt(m_viewLine);
00032 }
00033
00034 bool KateTextLayout::isDirty( ) const
00035 {
00036 if (!isValid())
00037 return m_invalidDirty;
00038
00039 return m_lineLayout->isDirty(viewLine());
00040 }
00041
00042 bool KateTextLayout::setDirty( bool dirty )
00043 {
00044 if (!isValid())
00045 return (m_invalidDirty = dirty);
00046
00047 return m_lineLayout->setDirty(viewLine(), dirty);
00048 }
00049
00050 bool KateTextLayout::includesCursor(const KTextEditor::Cursor& realCursor) const
00051 {
00052 return realCursor.line() == line() && realCursor.column() >= startCol() && (!wrap() || realCursor.column() < endCol());
00053 }
00054
00055 int KateTextLayout::xOffset() const
00056 {
00057 if (!isValid())
00058 return 0;
00059
00060 return startX() ? m_lineLayout->shiftX() : 0;
00061 }
00062
00063 void KateTextLayout::debugOutput() const
00064 {
00065 kDebug( 13033 ) << "KateTextLayout: " << m_lineLayout << " valid " << isValid() << " line " << m_lineLayout->line() << " (" << line() << ") cols [" << startCol() << " -> " << endCol() << "] x [" << startX() << " -> " << endX() << " off " << m_lineLayout->shiftX() << "] wrap " << wrap();
00066 }
00067
00068 bool operator> (const KateTextLayout& r, const KTextEditor::Cursor& c)
00069 {
00070 return r.line() > c.line() || r.endCol() > c.column();
00071 }
00072
00073 bool operator>= (const KateTextLayout& r, const KTextEditor::Cursor& c)
00074 {
00075 return r.line() > c.line() || r.endCol() >= c.column();
00076 }
00077
00078 bool operator< (const KateTextLayout& r, const KTextEditor::Cursor& c)
00079 {
00080 return r.line() < c.line() || r.startCol() < c.column();
00081 }
00082
00083 bool operator<= (const KateTextLayout& r, const KTextEditor::Cursor& c)
00084 {
00085 return r.line() < c.line() || r.startCol() <= c.column();
00086 }
00087
00088 bool KateTextLayout::isValid( ) const
00089 {
00090 return m_lineLayout && m_lineLayout->isValid() && m_viewLine >= 0 && m_viewLine < m_lineLayout->viewLineCount();
00091 }
00092
00093 int KateTextLayout::line( ) const
00094 {
00095 if (!isValid())
00096 return -1;
00097
00098 return m_lineLayout->line();
00099 }
00100
00101 int KateTextLayout::virtualLine( ) const
00102 {
00103 if (!isValid())
00104 return -1;
00105
00106 return m_lineLayout->virtualLine();
00107 }
00108
00109 int KateTextLayout::viewLine( ) const
00110 {
00111 if (!isValid())
00112 return 0;
00113
00114 return m_viewLine;
00115 }
00116
00117 const QTextLine & KateTextLayout::lineLayout( ) const
00118 {
00119 return m_textLayout;
00120 }
00121
00122 KateLineLayoutPtr KateTextLayout::kateLineLayout( ) const
00123 {
00124 return m_lineLayout;
00125 }
00126
00127 int KateTextLayout::startCol( ) const
00128 {
00129 if (!isValid())
00130 return 0;
00131
00132 return lineLayout().textStart();
00133 }
00134
00135 KTextEditor::Cursor KateTextLayout::start( ) const
00136 {
00137 return KTextEditor::Cursor(line(), startCol());
00138 }
00139
00140 int KateTextLayout::endCol(bool indicateEOL) const
00141 {
00142 if (!isValid())
00143 return 0;
00144
00145 if (indicateEOL)
00146 if (viewLine() == kateLineLayout()->viewLineCount() - 1)
00147 return -1;
00148
00149 return startCol() + m_textLayout.textLength();
00150 }
00151
00152 KTextEditor::Cursor KateTextLayout::end(bool indicateEOL) const
00153 {
00154 return KTextEditor::Cursor(line(), endCol(indicateEOL));
00155 }
00156
00157 int KateTextLayout::length( ) const
00158 {
00159 if (!isValid())
00160 return 0;
00161
00162 return m_textLayout.textLength();
00163 }
00164
00165 bool KateTextLayout::isEmpty( ) const
00166 {
00167 if (!isValid())
00168 return true;
00169
00170 return startCol() == 0 && endCol() == 0;
00171 }
00172
00173 bool KateTextLayout::wrap( ) const
00174 {
00175 if (!isValid())
00176 return false;
00177
00178 return viewLine() < m_lineLayout->viewLineCount() - 1;
00179 }
00180
00181 int KateTextLayout::startX( ) const
00182 {
00183 if (!isValid())
00184 return 0;
00185
00186 if (m_startX == -1)
00187
00188 for (int i = 0; i < viewLine(); ++i)
00189 m_startX += (int)m_lineLayout->layout()->lineAt(i).naturalTextWidth();
00190
00191 return m_startX;
00192 }
00193
00194 int KateTextLayout::endX( ) const
00195 {
00196 if (!isValid())
00197 return 0;
00198
00199 return startX() + (int)m_textLayout.naturalTextWidth();
00200 }
00201
00202 int KateTextLayout::width( ) const
00203 {
00204 if (!isValid())
00205 return 0;
00206
00207 return (int)m_textLayout.naturalTextWidth();
00208 }
00209
00210 KateTextLayout KateTextLayout::invalid( )
00211 {
00212 return KateTextLayout();
00213 }