• 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
  • completion
katecompletiondelegate.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries and the Kate part.
2  *
3  * Copyright (C) 2007 David Nolden <david.nolden.kdevelop@art-master.de>
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 as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "katecompletiondelegate.h"
22 
23 #include <ktexteditor/codecompletionmodel.h>
24 
25 #include "katerenderer.h"
26 #include "katetextline.h"
27 #include "katedocument.h"
28 #include "kateview.h"
29 #include "katehighlight.h"
30 #include "katerenderrange.h"
31 
32 #include "katecompletionwidget.h"
33 #include "katecompletionmodel.h"
34 #include "katecompletiontree.h"
35 
36 //Currently disable because it doesn't work
37 #define DISABLE_INTERNAL_HIGHLIGHTING
38 
39 KateCompletionDelegate::KateCompletionDelegate(ExpandingWidgetModel* model, KateCompletionWidget* parent) :
40  ExpandingDelegate(model, parent), m_cachedRow(-1)
41 {
42 }
43 
44 void KateCompletionDelegate::adjustStyle( const QModelIndex& index, QStyleOptionViewItem & option ) const {
45  if(index.column() == 0) {
46  //We always want to use the match-color if available, also for highlighted items.
48  uint color = model()->matchColor(index);
49  if(color != 0) {
50  QColor match(color);
51 
52  for(int a = 0; a <=2; a++ )
53  option.palette.setColor( (QPalette::ColorGroup)a, QPalette::Highlight, match );
54  }
55  }
56 }
57 
58 
59 KateRenderer * KateCompletionDelegate::renderer( ) const
60 {
61  return widget()->view()->renderer();
62 }
63 
64 KateCompletionWidget * KateCompletionDelegate::widget( ) const
65 {
66  return static_cast<KateCompletionWidget*>(const_cast<QObject*>(parent()));
67 }
68 
69 KateDocument * KateCompletionDelegate::document( ) const
70 {
71  return widget()->view()->doc();
72 }
73 
74 void KateCompletionDelegate::heightChanged() const {
75  if(parent())
76  widget()->updateHeight();
77 }
78 
79 QList<QTextLayout::FormatRange> KateCompletionDelegate::createHighlighting(const QModelIndex& index, QStyleOptionViewItem& option) const {
80 
81  QVariant highlight = model()->data(index, KTextEditor::CodeCompletionModel::HighlightingMethod);
82 
83  // TODO: config enable specifying no highlight as default
84  int highlightMethod = KTextEditor::CodeCompletionModel::InternalHighlighting;
85  if (highlight.canConvert(QVariant::Int))
86  highlightMethod = highlight.toInt();
87 
88  if (highlightMethod & KTextEditor::CodeCompletionModel::CustomHighlighting) {
89  m_currentColumnStart = 0;
90  return highlightingFromVariantList(model()->data(index, KTextEditor::CodeCompletionModel::CustomHighlight).toList());
91  }
92 
93 #ifdef DISABLE_INTERNAL_HIGHLIGHTING
94  return QList<QTextLayout::FormatRange>();
95 #endif
96 
97  if( index.row() == m_cachedRow && highlightMethod & KTextEditor::CodeCompletionModel::InternalHighlighting ) {
98 
99  if( index.column() < m_cachedColumnStarts.size() ) {
100  m_currentColumnStart = m_cachedColumnStarts[index.column()];
101  } else {
102  kWarning() << "Column-count does not match";
103  }
104 
105  return m_cachedHighlights;
106  }
107 
109  m_cachedRow = index.row();
110 
111  KTextEditor::Cursor completionStart = widget()->completionRange()->start();
112 
113  QString startText = document()->text(KTextEditor::Range(completionStart.line(), 0, completionStart.line(), completionStart.column()));
114 
115  QString lineContent = startText;
116 
117  int len = completionStart.column();
118  m_cachedColumnStarts.clear();
119 
120  for (int i = 0; i < KTextEditor::CodeCompletionModel::ColumnCount; ++i) {
121  m_cachedColumnStarts.append(len);
122  QString text = model()->data(model()->index(index.row(), i, index.parent()), Qt::DisplayRole).toString();
123  lineContent += text;
124  len += text.length();
125  }
126 
127  Kate::TextLine thisLine = Kate::TextLine (new Kate::TextLineData(lineContent));
128 
129  //kDebug( 13035 ) << "About to highlight with mode " << highlightMethod << " text [" << thisLine->string() << "]";
130 
131  if (highlightMethod & KTextEditor::CodeCompletionModel::InternalHighlighting) {
132  Kate::TextLine previousLine;
133  if (completionStart.line())
134  previousLine = document()->kateTextLine(completionStart.line() - 1);
135  else
136  previousLine = Kate::TextLine (new Kate::TextLineData());
137 
138  Kate::TextLine nextLine;
139  if ((completionStart.line() + 1) < document()->lines())
140  nextLine = document()->kateTextLine(completionStart.line() + 1);
141  else
142  nextLine = Kate::TextLine (new Kate::TextLineData());
143 
144  bool ctxChanged = false;
145  document()->highlight()->doHighlight(previousLine.data(), thisLine.data(), nextLine.data(), ctxChanged);
146  }
147 
148  m_currentColumnStart = m_cachedColumnStarts[index.column()];
149 
150  NormalRenderRange rr;
151  QList<QTextLayout::FormatRange> ret = renderer()->decorationsForLine(thisLine, 0, false, &rr, option.state & QStyle::State_Selected);
152 
153  //Remove background-colors
154  for( QList<QTextLayout::FormatRange>::iterator it = ret.begin(); it != ret.end(); ++it )
155  (*it).format.clearBackground();
156 
157  return ret;
158 }
159 
160 
QVariant::canConvert
bool canConvert(Type t) const
QList::clear
void clear()
QModelIndex
katehighlight.h
katetextline.h
kateview.h
KateCompletionDelegate::adjustStyle
virtual void adjustStyle(const QModelIndex &index, QStyleOptionViewItem &option) const
Definition: katecompletiondelegate.cpp:44
KateView::renderer
KateRenderer * renderer()
Definition: kateview.cpp:1664
katerenderer.h
KateDocument::highlight
KateHighlighting * highlight() const
Definition: katedocument.cpp:4701
katecompletiontree.h
katecompletiondelegate.h
katedocument.h
KateCompletionDelegate::document
KateDocument * document() const
Definition: katecompletiondelegate.cpp:69
KateCompletionDelegate::widget
KateCompletionWidget * widget() const
Definition: katecompletiondelegate.cpp:64
QSharedPointer::data
T * data() const
Kate::TextLineData
Class representing a single text line.
Definition: katetextline.h:37
QList::size
int size() const
KateCompletionDelegate::KateCompletionDelegate
KateCompletionDelegate(ExpandingWidgetModel *model, KateCompletionWidget *parent)
Definition: katecompletiondelegate.cpp:39
KateRenderer
Handles all of the work of rendering the text (used for the views and printing)
Definition: katerenderer.h:50
QList::append
void append(const T &value)
KateCompletionWidget
This is the code completion's main widget, and also contains the core interface logic.
Definition: katecompletionwidget.h:55
ExpandingWidgetModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Does not request data from index, this only returns local data like highlighting for expanded rows an...
Definition: expandingwidgetmodel.cpp:88
QVariant::toInt
int toInt(bool *ok) const
QSharedPointer
KateCompletionDelegate::createHighlighting
QList< QTextLayout::FormatRange > createHighlighting(const QModelIndex &index, QStyleOptionViewItem &option) const
Definition: katecompletiondelegate.cpp:79
QStyleOptionViewItem
QObject
KateCompletionWidget::view
KateView * view() const
Definition: katecompletionwidget.cpp:271
NormalRenderRange
Definition: katerenderrange.h:47
katecompletionmodel.h
QModelIndex::row
int row() const
KateDocument::lines
virtual int lines() const
Definition: katedocument.cpp:753
ExpandingWidgetModel::matchColor
uint matchColor(const QModelIndex &index) const
Returns the match-color for the given index, or zero if match-quality could not be computed...
Definition: expandingwidgetmodel.cpp:58
ExpandingDelegate::model
ExpandingWidgetModel * model() const
Definition: expandingdelegate.cpp:292
katecompletionwidget.h
KateCompletionDelegate::m_cachedRow
int m_cachedRow
Definition: katecompletiondelegate.h:35
QString
QList< QTextLayout::FormatRange >
QColor
QModelIndex::parent
QModelIndex parent() const
katerenderrange.h
KateCompletionDelegate::renderer
KateRenderer * renderer() const
Definition: katecompletiondelegate.cpp:59
ExpandingDelegate::highlightingFromVariantList
QList< QTextLayout::FormatRange > highlightingFromVariantList(const QList< QVariant > &customHighlights) const
Creates a list of FormatRanges as should be returned by createHighlighting from a list of QVariants a...
Definition: expandingdelegate.cpp:315
QList::end
iterator end()
ExpandingDelegate::m_currentColumnStart
int m_currentColumnStart
Definition: expandingdelegate.h:81
KateDocument
Definition: katedocument.h:74
KateCompletionWidget::updateHeight
void updateHeight()
Called by KateViewInternal, because we need the specific information from the event.
Definition: katecompletionwidget.cpp:554
KateDocument::kateTextLine
Kate::TextLine kateTextLine(uint i)
Definition: katedocument.cpp:4706
KateCompletionDelegate::m_cachedColumnStarts
QList< int > m_cachedColumnStarts
Definition: katecompletiondelegate.h:36
ExpandingDelegate
This is a delegate that cares, together with ExpandingWidgetModel, about embedded widgets in tree-vie...
Definition: expandingdelegate.h:42
Kate::TextLine
QSharedPointer< TextLineData > TextLine
The normal world only accesses the text lines with shared pointers.
Definition: katetextline.h:443
KateCompletionDelegate::heightChanged
virtual void heightChanged() const
Definition: katecompletiondelegate.cpp:74
QModelIndex::column
int column() const
QString::length
int length() const
KateDocument::text
virtual QString text(const KTextEditor::Range &range, bool blockwise=false) const
Definition: katedocument.cpp:337
ExpandingDelegate::m_cachedHighlights
QList< QTextLayout::FormatRange > m_cachedHighlights
Definition: expandingdelegate.h:83
KateView::doc
KateDocument * doc()
accessor to katedocument pointer
Definition: kateview.h:553
KateRenderer::decorationsForLine
QList< QTextLayout::FormatRange > decorationsForLine(const Kate::TextLine &textLine, int line, bool selectionsOnly=false, KateRenderRange *completionHighlight=0L, bool completionSelected=false) const
The ultimate decoration creation function.
Definition: katerenderer.cpp:340
QObject::parent
QObject * parent() const
QVariant::toString
QString toString() const
KateHighlighting::doHighlight
void doHighlight(const Kate::TextLineData *prevLine, Kate::TextLineData *textLine, const Kate::TextLineData *nextLine, bool &ctxChanged, int tabWidth=0, QVector< ContextChange > *contextChanges=0)
Parse the text and fill in the context array and folding list array.
Definition: katehighlight.cpp:279
QList::begin
iterator begin()
KateCompletionWidget::completionRange
KTextEditor::MovingRange * completionRange(KTextEditor::CodeCompletionModel *model=0) const
Definition: katecompletionwidget.cpp:877
QVariant
ExpandingWidgetModel
Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate.
Definition: expandingwidgetmodel.h:36
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