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

Kate

katecompletiondelegate.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2007 David Nolden <david.nolden.kdevelop@art-master.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "katecompletiondelegate.h"
00020 
00021 #include <ktexteditor/codecompletionmodel.h>
00022 
00023 #include "katerenderer.h"
00024 #include "katetextline.h"
00025 #include "katedocument.h"
00026 #include "kateview.h"
00027 #include "katehighlight.h"
00028 #include "katerenderrange.h"
00029 #include "katesmartrange.h"
00030 
00031 #include "katecompletionwidget.h"
00032 #include "katecompletionmodel.h"
00033 #include "katecompletiontree.h"
00034 
00035 KateCompletionDelegate::KateCompletionDelegate(ExpandingWidgetModel* model, KateCompletionWidget* parent) :
00036     ExpandingDelegate(model, parent), m_cachedRow(-1)
00037 {
00038 }
00039 
00040 void KateCompletionDelegate::adjustStyle( const QModelIndex& index, QStyleOptionViewItem & option ) const {
00041     if(index.column() == 0) {
00042         //We always want to use the match-color if available, also for highlighted items.
00044         uint color = model()->matchColor(index);
00045         if(color != 0) {
00046             QColor match(color);
00047         
00048             for(int a = 0; a <=2; a++ )
00049             option.palette.setColor( (QPalette::ColorGroup)a, QPalette::Highlight, match );
00050         }
00051     }
00052 }
00053 
00054 
00055 KateRenderer * KateCompletionDelegate::renderer( ) const
00056 {
00057   return widget()->view()->renderer();
00058 }
00059 
00060 KateCompletionWidget * KateCompletionDelegate::widget( ) const
00061 {
00062   return static_cast<KateCompletionWidget*>(const_cast<QObject*>(parent()));
00063 }
00064 
00065 KateDocument * KateCompletionDelegate::document( ) const
00066 {
00067   return widget()->view()->doc();
00068 }
00069 
00070 void KateCompletionDelegate::heightChanged() const {
00071   if(parent())
00072     widget()->updateHeight();
00073 }
00074 
00075 QList<QTextLayout::FormatRange> KateCompletionDelegate::createHighlighting(const QModelIndex& index, QStyleOptionViewItem& option) const {
00076     
00077     QVariant highlight = model()->data(index, KTextEditor::CodeCompletionModel::HighlightingMethod);
00078 
00079     // TODO: config enable specifying no highlight as default
00080     int highlightMethod = KTextEditor::CodeCompletionModel::InternalHighlighting;
00081     if (highlight.canConvert(QVariant::Int))
00082       highlightMethod = highlight.toInt();
00083     
00084     if( index.row() == m_cachedRow && highlightMethod & KTextEditor::CodeCompletionModel::InternalHighlighting ) {
00085         
00086         if( index.column() < m_cachedColumnStarts.size() ) {
00087             m_currentColumnStart = m_cachedColumnStarts[index.column()];
00088         } else {
00089             kWarning() << "Column-count does not match";
00090         }
00091         
00092         return m_cachedHighlights;
00093     }
00094     
00096     m_cachedRow = index.row();
00097     
00098     KTextEditor::Cursor completionStart = widget()->completionRange()->start();
00099 
00100     QString startText = document()->text(KTextEditor::Range(completionStart.line(), 0, completionStart.line(), completionStart.column()));
00101 
00102     KateTextLine::Ptr thisLine(new KateTextLine());
00103     thisLine->insertText(0, startText);
00104 
00105     int len = completionStart.column();
00106     m_cachedColumnStarts.clear();
00107     
00108     if (highlightMethod & KTextEditor::CodeCompletionModel::CustomHighlighting) {
00109         m_currentColumnStart = 0;
00110         return highlightingFromVariantList(model()->data(index, KTextEditor::CodeCompletionModel::CustomHighlight).toList());
00111     }
00112     
00113     for (int i = 0; i < KTextEditor::CodeCompletionModel::ColumnCount; ++i) {
00114       m_cachedColumnStarts.append(len);
00115       QString text = model()->data(model()->index(index.row(), i, index.parent()), Qt::DisplayRole).toString();
00116       thisLine->insertText(thisLine->length(), text);
00117       len += text.length();
00118     }
00119 
00120     //kDebug( 13035 ) << "About to highlight with mode " << highlightMethod << " text [" << thisLine->string() << "]";
00121 
00122     if (highlightMethod & KTextEditor::CodeCompletionModel::InternalHighlighting) {
00123       KateTextLine::Ptr previousLine;
00124       if (completionStart.line())
00125         previousLine = document()->kateTextLine(completionStart.line() - 1);
00126       else
00127         previousLine = new KateTextLine();
00128 
00129       QVector<int> foldingList;
00130       bool ctxChanged = false;
00131       document()->highlight()->doHighlight(previousLine.data(), thisLine.data(), foldingList, ctxChanged);
00132     }
00133 
00134   m_currentColumnStart = m_cachedColumnStarts[index.column()];
00135   
00136   NormalRenderRange rr;
00137   QList<QTextLayout::FormatRange> ret = renderer()->decorationsForLine(thisLine, 0, false, &rr, option.state & QStyle::State_Selected);
00138 
00139   //Remove background-colors
00140   for( QList<QTextLayout::FormatRange>::iterator it = ret.begin(); it != ret.end(); ++it )
00141     (*it).format.clearBackground();
00142   
00143   return ret;
00144 }
00145 
00146 

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
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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