• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

katelinelayout.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2002-2005 Hamish Rodda <rodda@kde.org>
00003    Copyright (C) 2003      Anakim Border <aborder@sources.sourceforge.net>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "katelinelayout.h"
00021 #include "katetextlayout.h"
00022 
00023 #include <QtGui/QTextLine>
00024 
00025 #include <kdebug.h>
00026 
00027 #include "katedocument.h"
00028 
00029 KateLineLayout::KateLineLayout(KateDocument* doc)
00030   : m_doc(doc)
00031   , m_textLine(0L)
00032   , m_line(-1)
00033   , m_virtualLine(-1)
00034   , m_shiftX(0)
00035   , m_layout(0L)
00036   , m_layoutDirty(true)
00037   , m_usePlainTextLine(false)
00038 {
00039   Q_ASSERT(doc);
00040 }
00041 
00042 KateLineLayout::~KateLineLayout()
00043 {
00044   delete m_layout;
00045 }
00046 
00047 void KateLineLayout::clear()
00048 {
00049   m_textLine = 0L;
00050   m_line = -1;
00051   m_virtualLine = -1;
00052   m_shiftX = 0;
00053   // not touching dirty
00054   delete m_layout;
00055   m_layout = 0L;
00056   // not touching layout dirty
00057 }
00058 
00059 bool KateLineLayout::includesCursor(const KTextEditor::Cursor& realCursor) const
00060 {
00061   return realCursor.line() == line();
00062 }
00063 
00064 const KateTextLine::Ptr& KateLineLayout::textLine(bool reloadForce) const
00065 {
00066   if (reloadForce || !m_textLine)
00067     m_textLine = usePlainTextLine() ? m_doc->plainKateTextLine (line()) : m_doc->kateTextLine(line());
00068 
00069   Q_ASSERT(m_textLine);
00070 
00071   return m_textLine;
00072 }
00073 
00074 int KateLineLayout::line( ) const
00075 {
00076   return m_line;
00077 }
00078 
00079 void KateLineLayout::setLine( int line, int virtualLine )
00080 {
00081   m_line = line;
00082   m_virtualLine = (virtualLine == -1) ? m_doc->getVirtualLine(line) : virtualLine;
00083   m_textLine = 0L;
00084 }
00085 
00086 int KateLineLayout::virtualLine( ) const
00087 {
00088   return m_virtualLine;
00089 }
00090 
00091 void KateLineLayout::setVirtualLine( int virtualLine )
00092 {
00093   m_virtualLine = virtualLine;
00094 }
00095 
00096 bool KateLineLayout::startsInvisibleBlock() const
00097 {
00098   if (!isValid())
00099     return false;
00100 
00101   return (virtualLine() + 1) != (int)m_doc->getVirtualLine(line() + 1);
00102 }
00103 
00104 int KateLineLayout::shiftX() const
00105 {
00106   return m_shiftX;
00107 }
00108 
00109 void KateLineLayout::setShiftX(int shiftX)
00110 {
00111   m_shiftX = shiftX;
00112 }
00113 
00114 KateDocument* KateLineLayout::doc() const
00115 {
00116   return m_doc;
00117 }
00118 
00119 bool KateLineLayout::isValid( ) const
00120 {
00121   return line() != -1 && layout() && textLine();
00122 }
00123 
00124 QTextLayout* KateLineLayout::layout() const
00125 {
00126   return m_layout;
00127 }
00128 
00129 void KateLineLayout::setLayout(QTextLayout* layout)
00130 {
00131   if (m_layout != layout) {
00132     delete m_layout;
00133     m_layout = layout;
00134   }
00135 
00136   m_layoutDirty = !m_layout;
00137   m_dirtyList.clear();
00138   if (m_layout)
00139     for (int i = 0; i < qMax(1, m_layout->lineCount()); ++i)
00140       m_dirtyList.append(true);
00141 }
00142 
00143 void KateLineLayout::invalidateLayout( )
00144 {
00145   setLayout(0L);
00146 }
00147 
00148 bool KateLineLayout::isDirty( int viewLine ) const
00149 {
00150   Q_ASSERT(isValid() && viewLine >= 0 && viewLine < viewLineCount());
00151   return m_dirtyList[viewLine];
00152 }
00153 
00154 bool KateLineLayout::setDirty( int viewLine, bool dirty )
00155 {
00156   Q_ASSERT(isValid() && viewLine >= 0 && viewLine < viewLineCount());
00157   m_dirtyList[viewLine] = dirty;
00158   return dirty;
00159 }
00160 
00161 KTextEditor::Cursor KateLineLayout::start( ) const
00162 {
00163   return KTextEditor::Cursor(line(), 0);
00164 }
00165 
00166 int KateLineLayout::length( ) const
00167 {
00168   return textLine()->length();
00169 }
00170 
00171 int KateLineLayout::viewLineCount( ) const
00172 {
00173   return m_layout->lineCount();
00174 }
00175 
00176 KateTextLayout KateLineLayout::viewLine( int viewLine ) const
00177 {
00178   if (viewLine < 0)
00179     viewLine += viewLineCount();
00180   Q_ASSERT(isValid());
00181   Q_ASSERT(viewLine >= 0 && viewLine < viewLineCount());
00182   return KateTextLayout(KateLineLayoutPtr(const_cast<KateLineLayout*>(this)), viewLine);
00183 }
00184 
00185 int KateLineLayout::width( ) const
00186 {
00187   int width = 0;
00188 
00189   for (int i = 0; i < m_layout->lineCount(); ++i)
00190     width = qMax((int)m_layout->lineAt(i).naturalTextWidth(), width);
00191 
00192   return width;
00193 }
00194 
00195 int KateLineLayout::widthOfLastLine( ) const
00196 {
00197   const KateTextLayout& lastLine = viewLine(viewLineCount() - 1);
00198   return lastLine.endX();
00199 }
00200 
00201 bool KateLineLayout::isOutsideDocument( ) const
00202 {
00203   return line() < 0 || line() >= m_doc->lines();
00204 }
00205 
00206 void KateLineLayout::debugOutput() const
00207 {
00208   kDebug( 13033 ) << "KateLineLayout: " << this << " valid " << isValid() << " line " << line() << " length " << length() << " width " << width() << " viewLineCount " << viewLineCount();
00209 }
00210 
00211 int KateLineLayout::viewLineForColumn( int column ) const
00212 {
00213   int len = 0;
00214   int i = 0;
00215   for (; i < m_layout->lineCount() - 1; ++i) {
00216     len += m_layout->lineAt(i).textLength();
00217     if (column < len)
00218       return i;
00219   }
00220   return i;
00221 }
00222 
00223 bool KateLineLayout::isLayoutDirty( ) const
00224 {
00225   return m_layoutDirty;
00226 }
00227 
00228 void KateLineLayout::setLayoutDirty( bool dirty )
00229 {
00230   m_layoutDirty = dirty;
00231 }
00232 
00233 bool KateLineLayout::usePlainTextLine () const
00234 {
00235   return m_usePlainTextLine;
00236 }
00237 
00238 void KateLineLayout::setUsePlainTextLine (bool plain)
00239 {
00240   m_usePlainTextLine = plain;
00241 }
00242 
00243 bool KateLineLayout::isRightToLeft() const
00244 {
00245   if (!m_layout)
00246     return false;
00247 
00248   return m_layout->textOption().textDirection() == Qt::RightToLeft;
00249 }
00250 
00251 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal