• 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
katerenderer.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2007 Mirko Stocker <me@misto.ch>
3  Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
4  Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
5  Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
6  Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
7  Copyright (C) 2013 Andrey Matveyakin <a.matveyakin@gmail.com>
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Library General Public
11  License version 2 as published by the Free Software Foundation.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #include "katerenderer.h"
25 
26 #include "katedocument.h"
27 #include "kateconfig.h"
28 #include "katehighlight.h"
29 #include "kateview.h"
30 #include "katerenderrange.h"
31 #include "katetextlayout.h"
32 #include "katebuffer.h"
33 
34 #include <limits.h>
35 
36 #include <kdebug.h>
37 
38 #include <QtGui/QPainter>
39 #include <QtGui/QTextLine>
40 #include <QtCore/QStack>
41 #include <QtGui/QBrush>
42 
43 #include <ktexteditor/highlightinterface.h>
44 
45 static const QChar tabChar('\t');
46 static const QChar spaceChar(' ');
47 static const QChar nbSpaceChar(0xa0); // non-breaking space
48 
49 KateRenderer::KateRenderer(KateDocument* doc, Kate::TextFolding &folding, KateView *view)
50  : m_doc(doc)
51  , m_folding (folding)
52  , m_view (view)
53  , m_tabWidth(m_doc->config()->tabWidth())
54  , m_indentWidth(m_doc->config()->indentationWidth())
55  , m_caretStyle(KateRenderer::Line)
56  , m_drawCaret(true)
57  , m_showSelections(true)
58  , m_showTabs(true)
59  , m_showSpaces(true)
60  , m_printerFriendly(false)
61  , m_config(new KateRendererConfig(this))
62 {
63  updateAttributes ();
64 
65  // initialize with a sane font height
66  updateFontHeight ();
67 }
68 
69 KateRenderer::~KateRenderer()
70 {
71  delete m_config;
72 }
73 
74 void KateRenderer::updateAttributes ()
75 {
76  m_attributes = m_doc->highlight()->attributes (config()->schema ());
77 }
78 
79 KTextEditor::Attribute::Ptr KateRenderer::attribute(uint pos) const
80 {
81  if (pos < (uint)m_attributes.count())
82  return m_attributes[pos];
83 
84  return m_attributes[0];
85 }
86 
87 KTextEditor::Attribute::Ptr KateRenderer::specificAttribute( int context ) const
88 {
89  if (context >= 0 && context < m_attributes.count())
90  return m_attributes[context];
91 
92  return m_attributes[0];
93 }
94 
95 void KateRenderer::setDrawCaret(bool drawCaret)
96 {
97  m_drawCaret = drawCaret;
98 }
99 
100 void KateRenderer::setCaretStyle(KateRenderer::caretStyles style)
101 {
102  m_caretStyle = style;
103 }
104 
105 void KateRenderer::setShowTabs(bool showTabs)
106 {
107  m_showTabs = showTabs;
108 }
109 
110 void KateRenderer::setShowTrailingSpaces(bool showSpaces)
111 {
112  m_showSpaces = showSpaces;
113 }
114 
115 void KateRenderer::setTabWidth(int tabWidth)
116 {
117  m_tabWidth = tabWidth;
118 }
119 
120 bool KateRenderer::showIndentLines() const
121 {
122  return m_config->showIndentationLines();
123 }
124 
125 void KateRenderer::setShowIndentLines(bool showIndentLines)
126 {
127  m_config->setShowIndentationLines(showIndentLines);
128 }
129 
130 void KateRenderer::setIndentWidth(int indentWidth)
131 {
132  m_indentWidth = indentWidth;
133 }
134 
135 void KateRenderer::setShowSelections(bool showSelections)
136 {
137  m_showSelections = showSelections;
138 }
139 
140 void KateRenderer::increaseFontSizes()
141 {
142  QFont f ( config()->font () );
143  f.setPointSize (f.pointSize ()+1);
144 
145  config()->setFont (f);
146 }
147 
148 void KateRenderer::decreaseFontSizes()
149 {
150  QFont f ( config()->font () );
151 
152  if ((f.pointSize ()-1) > 0)
153  f.setPointSize (f.pointSize ()-1);
154 
155  config()->setFont (f);
156 }
157 
158 bool KateRenderer::isPrinterFriendly() const
159 {
160  return m_printerFriendly;
161 }
162 
163 void KateRenderer::setPrinterFriendly(bool printerFriendly)
164 {
165  m_printerFriendly = printerFriendly;
166  setShowTabs(false);
167  setShowTrailingSpaces(false);
168  setShowSelections(false);
169  setDrawCaret(false);
170 }
171 
172 void KateRenderer::paintTextLineBackground(QPainter& paint, KateLineLayoutPtr layout, int currentViewLine, int xStart, int xEnd)
173 {
174  if (isPrinterFriendly())
175  return;
176 
177  // Normal background color
178  QColor backgroundColor( config()->backgroundColor() );
179 
180  // paint the current line background if we're on the current line
181  QColor currentLineColor = config()->highlightedLineColor();
182 
183  // Check for mark background
184  int markRed = 0, markGreen = 0, markBlue = 0, markCount = 0;
185 
186  // Retrieve marks for this line
187  uint mrk = m_doc->mark( layout->line() );
188  if (mrk)
189  {
190  for (uint bit = 0; bit < 32; bit++)
191  {
192  KTextEditor::MarkInterface::MarkTypes markType = (KTextEditor::MarkInterface::MarkTypes)(1<<bit);
193  if (mrk & markType)
194  {
195  QColor markColor = config()->lineMarkerColor(markType);
196 
197  if (markColor.isValid()) {
198  markCount++;
199  markRed += markColor.red();
200  markGreen += markColor.green();
201  markBlue += markColor.blue();
202  }
203  }
204  } // for
205  } // Marks
206 
207  if (markCount) {
208  markRed /= markCount;
209  markGreen /= markCount;
210  markBlue /= markCount;
211  backgroundColor.setRgb(
212  int((backgroundColor.red() * 0.9) + (markRed * 0.1)),
213  int((backgroundColor.green() * 0.9) + (markGreen * 0.1)),
214  int((backgroundColor.blue() * 0.9) + (markBlue * 0.1))
215  );
216  }
217 
218  // Draw line background
219  paint.fillRect(0, 0, xEnd - xStart, lineHeight() * layout->viewLineCount(), backgroundColor);
220 
221  // paint the current line background if we're on the current line
222  if (currentViewLine != -1) {
223  if (markCount) {
224  markRed /= markCount;
225  markGreen /= markCount;
226  markBlue /= markCount;
227  currentLineColor.setRgb(
228  int((currentLineColor.red() * 0.9) + (markRed * 0.1)),
229  int((currentLineColor.green() * 0.9) + (markGreen * 0.1)),
230  int((currentLineColor.blue() * 0.9) + (markBlue * 0.1))
231  );
232  }
233 
234  paint.fillRect(0, lineHeight() * currentViewLine, xEnd - xStart, lineHeight(), currentLineColor);
235  }
236 }
237 
238 void KateRenderer::paintTabstop(QPainter &paint, qreal x, qreal y)
239 {
240  QPen penBackup( paint.pen() );
241  QPen pen( config()->tabMarkerColor() );
242  pen.setWidthF(qMax(1.0, spaceWidth() / 10.0));
243  paint.setPen( pen );
244  paint.setRenderHint(QPainter::Antialiasing, false);
245 
246  int dist = spaceWidth() * 0.3;
247  QPoint points[8];
248  points[0] = QPoint(x - dist, y - dist);
249  points[1] = QPoint(x, y);
250  points[2] = QPoint(x, y);
251  points[3] = QPoint(x - dist, y + dist);
252  x += spaceWidth() / 3.0;
253  points[4] = QPoint(x - dist, y - dist);
254  points[5] = QPoint(x, y);
255  points[6] = QPoint(x, y);
256  points[7] = QPoint(x - dist, y + dist);
257  paint.drawLines(points, 4);
258  paint.setPen( penBackup );
259 }
260 
261 void KateRenderer::paintTrailingSpace(QPainter &paint, qreal x, qreal y)
262 {
263  QPen penBackup( paint.pen() );
264  QPen pen( config()->tabMarkerColor() );
265  pen.setWidthF(spaceWidth() / 3.5);
266  pen.setCapStyle(Qt::RoundCap);
267  paint.setPen( pen );
268  paint.setRenderHint(QPainter::Antialiasing, true);
269 
270  paint.drawPoint( QPointF(x, y) );
271  paint.setPen( penBackup );
272 }
273 
274 void KateRenderer::paintNonBreakSpace(QPainter &paint, qreal x, qreal y)
275 {
276  QPen penBackup( paint.pen() );
277  QPen pen( config()->tabMarkerColor() );
278  pen.setWidthF(qMax(1.0, spaceWidth() / 10.0));
279  paint.setPen( pen );
280  paint.setRenderHint(QPainter::Antialiasing, false);
281 
282  const int height = fontHeight();
283  const int width = spaceWidth();
284 
285  QPoint points[6];
286  points[0] = QPoint(x+width/10, y+height/4);
287  points[1] = QPoint(x+width/10, y+height/3);
288  points[2] = QPoint(x+width/10, y+height/3);
289  points[3] = QPoint(x+width-width/10, y+height/3);
290  points[4] = QPoint(x+width-width/10, y+height/3);
291  points[5] = QPoint(x+width-width/10, y+height/4);
292  paint.drawLines(points, 3);
293  paint.setPen( penBackup );
294 }
295 
296 void KateRenderer::paintIndentMarker(QPainter &paint, uint x, uint y /*row*/)
297 {
298  QPen penBackup( paint.pen() );
299  QPen myPen(config()->indentationLineColor());
300  static const QVector<qreal> dashPattern = QVector<qreal>() << 1 << 1;
301  myPen.setDashPattern(dashPattern);
302  if (y % 2)
303  myPen.setDashOffset(1);
304  paint.setPen(myPen);
305 
306  const int height = fontHeight();
307  const int top = 0;
308  const int bottom = height-1;
309 
310  QPainter::RenderHints renderHints = paint.renderHints();
311  paint.setRenderHints(renderHints, false);
312 
313  paint.drawLine(x + 2, top, x + 2, bottom);
314 
315  paint.setRenderHints(renderHints, true);
316 
317  paint.setPen( penBackup );
318 }
319 
320 static bool rangeLessThanForRenderer (const Kate::TextRange *a, const Kate::TextRange *b)
321 {
322  // compare Z-Depth first
323  // smaller Z-Depths should win!
324  if (a->zDepth() > b->zDepth())
325  return true;
326  else if (a->zDepth() < b->zDepth())
327  return false;
328 
329  // end of a > end of b?
330  if (a->end().toCursor() > b->end().toCursor())
331  return true;
332 
333  // if ends are equal, start of a < start of b?
334  if (a->end().toCursor() == b->end().toCursor())
335  return a->start().toCursor() < b->start().toCursor();
336 
337  return false;
338 }
339 
340 QList<QTextLayout::FormatRange> KateRenderer::decorationsForLine( const Kate::TextLine& textLine, int line, bool selectionsOnly, KateRenderRange* completionHighlight, bool completionSelected ) const
341 {
342  QList<QTextLayout::FormatRange> newHighlight;
343 
344  // Don't compute the highlighting if there isn't going to be any highlighting
345  QList<Kate::TextRange *> rangesWithAttributes = m_doc->buffer().rangesForLine (line, m_printerFriendly ? 0 : m_view, true);
346  if (selectionsOnly || textLine->attributesList().count() || rangesWithAttributes.count()) {
347  RenderRangeList renderRanges;
348 
349  // Add the inbuilt highlighting to the list
350  NormalRenderRange* inbuiltHighlight = new NormalRenderRange();
351  const QVector<Kate::TextLineData::Attribute> &al = textLine->attributesList();
352  for (int i = 0; i < al.count(); ++i)
353  if (al[i].length > 0 && al[i].attributeValue > 0)
354  inbuiltHighlight->addRange(new KTextEditor::Range(KTextEditor::Cursor(line, al[i].offset), al[i].length), specificAttribute(al[i].attributeValue));
355  renderRanges.append(inbuiltHighlight);
356 
357  if (!completionHighlight) {
358  // check for dynamic hl stuff
359  const QSet<Kate::TextRange *> *rangesMouseIn = m_view ? m_view->rangesMouseIn () : 0;
360  const QSet<Kate::TextRange *> *rangesCaretIn = m_view ? m_view->rangesCaretIn () : 0;
361  bool anyDynamicHlsActive = m_view && (!rangesMouseIn->empty() || !rangesCaretIn->empty());
362 
363  // sort all ranges, we want that the most specific ranges win during rendering, multiple equal ranges are kind of random, still better than old smart rangs behavior ;)
364  qSort (rangesWithAttributes.begin(), rangesWithAttributes.end(), rangeLessThanForRenderer);
365 
366  // loop over all ranges
367  for (int i = 0; i < rangesWithAttributes.size(); ++i) {
368  // real range
369  Kate::TextRange *kateRange = rangesWithAttributes[i];
370 
371  // calculate attribute, default: normal attribute
372  KTextEditor::Attribute::Ptr attribute = kateRange->attribute();
373  if (anyDynamicHlsActive) {
374  // check mouse in
375  if (KTextEditor::Attribute::Ptr attributeMouseIn = attribute->dynamicAttribute (KTextEditor::Attribute::ActivateMouseIn)) {
376  if (rangesMouseIn->contains (kateRange))
377  attribute = attributeMouseIn;
378  }
379 
380  // check caret in
381  if (KTextEditor::Attribute::Ptr attributeCaretIn = attribute->dynamicAttribute (KTextEditor::Attribute::ActivateCaretIn)) {
382  if (rangesCaretIn->contains (kateRange))
383  attribute = attributeCaretIn;
384  }
385  }
386 
387  // span range
388  NormalRenderRange *additionaHl = new NormalRenderRange();
389  additionaHl->addRange(new KTextEditor::Range (*kateRange), attribute);
390  renderRanges.append(additionaHl);
391  }
392  } else {
393  // Add the code completion arbitrary highlight to the list
394  renderRanges.append(completionHighlight);
395  }
396 
397  // Add selection highlighting if we're creating the selection decorations
398  if ((selectionsOnly && showSelections() && m_view->selection()) || (completionHighlight && completionSelected) || m_view->blockSelection()) {
399  NormalRenderRange* selectionHighlight = new NormalRenderRange();
400 
401  // Set up the selection background attribute TODO: move this elsewhere, eg. into the config?
402  static KTextEditor::Attribute::Ptr backgroundAttribute;
403  if (!backgroundAttribute)
404  backgroundAttribute = KTextEditor::Attribute::Ptr(new KTextEditor::Attribute());
405 
406  backgroundAttribute->setBackground(config()->selectionColor());
407  backgroundAttribute->setForeground(attribute(KTextEditor::HighlightInterface::dsNormal)->selectedForeground().color());
408 
409  // Create a range for the current selection
410  if (completionHighlight && completionSelected)
411  selectionHighlight->addRange(new KTextEditor::Range(line, 0, line + 1, 0), backgroundAttribute);
412  else
413  if(m_view->blockSelection() && m_view->selectionRange().overlapsLine(line))
414  selectionHighlight->addRange(new KTextEditor::Range(m_doc->rangeOnLine(m_view->selectionRange(), line)), backgroundAttribute);
415  else {
416  selectionHighlight->addRange(new KTextEditor::Range(m_view->selectionRange()), backgroundAttribute);
417  }
418 
419  renderRanges.append(selectionHighlight);
420  // highlighting for the vi visual modes
421  }
422 
423  KTextEditor::Cursor currentPosition, endPosition;
424 
425  // Calculate the range which we need to iterate in order to get the highlighting for just this line
426  if (selectionsOnly) {
427  if(m_view->blockSelection()) {
428  KTextEditor::Range subRange = m_doc->rangeOnLine(m_view->selectionRange(), line);
429  currentPosition = subRange.start();
430  endPosition = subRange.end();
431  } else {
432  KTextEditor::Range rangeNeeded = m_view->selectionRange() & KTextEditor::Range(line, 0, line + 1, 0);
433 
434  currentPosition = qMax(KTextEditor::Cursor(line, 0), rangeNeeded.start());
435  endPosition = qMin(KTextEditor::Cursor(line + 1, 0), rangeNeeded.end());
436  }
437  } else {
438  currentPosition = KTextEditor::Cursor(line, 0);
439  endPosition = KTextEditor::Cursor(line + 1, 0);
440  }
441 
442  // Main iterative loop. This walks through each set of highlighting ranges, and stops each
443  // time the highlighting changes. It then creates the corresponding QTextLayout::FormatRanges.
444  while (currentPosition < endPosition) {
445  renderRanges.advanceTo(currentPosition);
446 
447  if (!renderRanges.hasAttribute()) {
448  // No attribute, don't need to create a FormatRange for this text range
449  currentPosition = renderRanges.nextBoundary();
450  continue;
451  }
452 
453  KTextEditor::Cursor nextPosition = renderRanges.nextBoundary();
454 
455  // Create the format range and populate with the correct start, length and format info
456  QTextLayout::FormatRange fr;
457  fr.start = currentPosition.column();
458 
459  if (nextPosition < endPosition || endPosition.line() <= line) {
460  fr.length = nextPosition.column() - currentPosition.column();
461 
462  } else {
463  // +1 to force background drawing at the end of the line when it's warranted
464  fr.length = textLine->length() - currentPosition.column() + 1;
465  }
466 
467  KTextEditor::Attribute::Ptr a = renderRanges.generateAttribute();
468  if (a) {
469  fr.format = *a;
470 
471  if(selectionsOnly) {
472  assignSelectionBrushesFromAttribute(fr, *a);
473  }
474  }
475 
476  newHighlight.append(fr);
477 
478  currentPosition = nextPosition;
479  }
480 
481  if (completionHighlight)
482  // Don't delete external completion render range
483  renderRanges.removeAll(completionHighlight);
484 
485  qDeleteAll(renderRanges);
486  }
487 
488  return newHighlight;
489 }
490 
491 void KateRenderer::assignSelectionBrushesFromAttribute(QTextLayout::FormatRange& target, const KTextEditor::Attribute& attribute) const
492 {
493  if(attribute.hasProperty(KTextEditor::Attribute::SelectedForeground)) {
494  target.format.setForeground(attribute.selectedForeground());
495  }
496  if(attribute.hasProperty(KTextEditor::Attribute::SelectedBackground)) {
497  target.format.setBackground(attribute.selectedBackground());
498  }
499 }
500 
501 /*
502 The ultimate line painting function.
503 Currently missing features:
504 - draw indent lines
505 */
506 void KateRenderer::paintTextLine(QPainter& paint, KateLineLayoutPtr range, int xStart, int xEnd, const KTextEditor::Cursor* cursor)
507 {
508  Q_ASSERT(range->isValid());
509 
510 // kDebug( 13033 )<<"KateRenderer::paintTextLine";
511 
512  // font data
513  const QFontMetricsF &fm = config()->fontMetrics();
514 
515  int currentViewLine = -1;
516  if (cursor && cursor->line() == range->line())
517  currentViewLine = range->viewLineForColumn(cursor->column());
518 
519  paintTextLineBackground(paint, range, currentViewLine, xStart, xEnd);
520 
521  if (range->layout()) {
522  bool drawSelection = m_view->selection() && showSelections() && m_view->selectionRange().overlapsLine(range->line());
523  // Draw selection in block selecton mode. We need 2 kinds of selections that QTextLayout::draw can't render:
524  // - past-end-of-line selection and
525  // - 0-column-wide selection (used to indicate where text will be typed)
526  if (drawSelection && m_view->blockSelection()) {
527  int selectionStartColumn = m_doc->fromVirtualColumn(range->line(), m_doc->toVirtualColumn(m_view->selectionRange().start()));
528  int selectionEndColumn = m_doc->fromVirtualColumn(range->line(), m_doc->toVirtualColumn(m_view->selectionRange().end()));
529  QBrush selectionBrush = config()->selectionColor();
530  if (selectionStartColumn != selectionEndColumn) {
531  KateTextLayout lastLine = range->viewLine(range->viewLineCount() - 1);
532  if (selectionEndColumn > lastLine.startCol()) {
533  int selectionStartX = (selectionStartColumn > lastLine.startCol()) ? cursorToX(lastLine, selectionStartColumn, true) : 0;
534  int selectionEndX = cursorToX(lastLine, selectionEndColumn, true);
535  paint.fillRect(QRect(selectionStartX - xStart, (int)lastLine.lineLayout().y(), selectionEndX - selectionStartX, lineHeight()), selectionBrush);
536  }
537  } else {
538  const int selectStickWidth = 2;
539  KateTextLayout selectionLine = range->viewLine(range->viewLineForColumn(selectionStartColumn));
540  int selectionX = cursorToX(selectionLine, selectionStartColumn, true);
541  paint.fillRect(QRect(selectionX - xStart, (int)selectionLine.lineLayout().y(), selectStickWidth, lineHeight()), selectionBrush);
542  }
543  }
544 
545  QVector<QTextLayout::FormatRange> additionalFormats;
546  if (range->length() > 0) {
547  // We may have changed the pen, be absolutely sure it gets set back to
548  // normal foreground color before drawing text for text that does not
549  // set the pen color
550  paint.setPen(attribute(KTextEditor::HighlightInterface::dsNormal)->foreground().color());
551  // Draw the text :)
552  if (drawSelection) {
553  // FIXME toVector() may be a performance issue
554  additionalFormats = decorationsForLine(range->textLine(), range->line(), true).toVector();
555  range->layout()->draw(&paint, QPoint(-xStart,0), additionalFormats);
556 
557  } else {
558  range->layout()->draw(&paint, QPoint(-xStart,0));
559  }
560  }
561 
562  QBrush backgroundBrush;
563  bool backgroundBrushSet = false;
564 
565  // Loop each individual line for additional text decoration etc.
566  QListIterator<QTextLayout::FormatRange> it = range->layout()->additionalFormats();
567  QVectorIterator<QTextLayout::FormatRange> it2 = additionalFormats;
568  for (int i = 0; i < range->viewLineCount(); ++i) {
569  KateTextLayout line = range->viewLine(i);
570 
571  // Determine the background to use, if any, for the end of this view line
572  backgroundBrushSet = false;
573  while (it2.hasNext()) {
574  const QTextLayout::FormatRange& fr = it2.peekNext();
575  if (fr.start > line.endCol())
576  break;
577 
578  if (fr.start + fr.length > line.endCol()) {
579  if (fr.format.hasProperty(QTextFormat::BackgroundBrush)) {
580  backgroundBrushSet = true;
581  backgroundBrush = fr.format.background();
582  }
583 
584  goto backgroundDetermined;
585  }
586 
587  it2.next();
588  }
589 
590  while (it.hasNext()) {
591  const QTextLayout::FormatRange& fr = it.peekNext();
592  if (fr.start > line.endCol())
593  break;
594 
595  if (fr.start + fr.length > line.endCol()) {
596  if (fr.format.hasProperty(QTextFormat::BackgroundBrush)) {
597  backgroundBrushSet = true;
598  backgroundBrush = fr.format.background();
599  }
600 
601  break;
602  }
603 
604  it.next();
605  }
606 
607  backgroundDetermined:
608 
609  // Draw selection or background color outside of areas where text is rendered
610  if (!m_printerFriendly ) {
611  bool draw = false;
612  QBrush drawBrush;
613  if (m_view->selection() && !m_view->blockSelection() && m_view->lineEndSelected(line.end(true))) {
614  draw = true;
615  drawBrush = config()->selectionColor();
616  } else if (backgroundBrushSet && !m_view->blockSelection()) {
617  draw = true;
618  drawBrush = backgroundBrush;
619  }
620 
621  if (draw) {
622  int fillStartX = line.endX() - line.startX() + line.xOffset() - xStart;
623  int fillStartY = lineHeight() * i;
624  int width= xEnd - xStart - fillStartX;
625  int height= lineHeight();
626 
627  // reverse X for right-aligned lines
628  if (range->layout()->textOption().alignment() == Qt::AlignRight)
629  fillStartX = 0;
630 
631  if (width > 0) {
632  QRect area(fillStartX, fillStartY, width, height);
633  paint.fillRect(area, drawBrush);
634  }
635  }
636  }
637  // Draw indent lines
638  if (showIndentLines() && i == 0)
639  {
640  const qreal w = spaceWidth();
641  const int lastIndentColumn = range->textLine()->indentDepth(m_tabWidth);
642 
643  for (int x = m_indentWidth; x < lastIndentColumn; x += m_indentWidth)
644  {
645  paintIndentMarker(paint, x * w + 1 - xStart, range->line());
646  }
647  }
648 
649  // draw an open box to mark non-breaking spaces
650  const QString& text = range->textLine()->string();
651  int y = lineHeight() * i + fm.ascent() - fm.strikeOutPos();
652  int nbSpaceIndex = text.indexOf(nbSpaceChar, line.lineLayout().xToCursor(xStart));
653 
654  while (nbSpaceIndex != -1 && nbSpaceIndex < line.endCol()) {
655  int x = line.lineLayout().cursorToX(nbSpaceIndex);
656  if (x > xEnd)
657  break;
658  paintNonBreakSpace(paint, x - xStart, y);
659  nbSpaceIndex = text.indexOf(nbSpaceChar, nbSpaceIndex + 1);
660  }
661 
662  // draw tab stop indicators
663  if (showTabs()) {
664  int tabIndex = text.indexOf(tabChar, line.lineLayout().xToCursor(xStart));
665  while (tabIndex != -1 && tabIndex < line.endCol()) {
666  int x = line.lineLayout().cursorToX(tabIndex);
667  if (x > xEnd)
668  break;
669  paintTabstop(paint, x - xStart + spaceWidth()/2.0, y);
670  tabIndex = text.indexOf(tabChar, tabIndex + 1);
671  }
672  }
673 
674  // draw trailing spaces
675  if (showTrailingSpaces()) {
676  int spaceIndex = line.endCol() - 1;
677  int trailingPos = range->textLine()->lastChar();
678  if (trailingPos < 0)
679  trailingPos = 0;
680  if (spaceIndex >= trailingPos) {
681  while (spaceIndex >= line.startCol() && text.at(spaceIndex).isSpace()) {
682  if (text.at(spaceIndex) != '\t' || !showTabs())
683  paintTrailingSpace(paint, line.lineLayout().cursorToX(spaceIndex) - xStart + spaceWidth()/2.0, y);
684  --spaceIndex;
685  }
686  }
687  }
688  }
689 
690  // draw word-wrap-honor-indent filling
691  if ( (range->viewLineCount() > 1) && range->shiftX() && (range->shiftX() > xStart) )
692  {
693  if (backgroundBrushSet)
694  paint.fillRect(0, lineHeight(), range->shiftX() - xStart, lineHeight() * (range->viewLineCount() - 1),
695  backgroundBrush);
696  paint.fillRect(0, lineHeight(), range->shiftX() - xStart, lineHeight() * (range->viewLineCount() - 1),
697  QBrush(config()->wordWrapMarkerColor(), Qt::Dense4Pattern));
698  }
699 
700  // Draw caret
701  if (drawCaret() && cursor && range->includesCursor(*cursor)) {
702  int caretWidth, lineWidth = 2;
703  QColor color;
704  QTextLine line = range->layout()->lineForTextPosition(qMin(cursor->column(), range->length()));
705 
706  // Determine the caret's style
707  caretStyles style = caretStyle();
708 
709  // Make the caret the desired width
710  if (style == Line) {
711  caretWidth = lineWidth;
712  } else if (line.isValid() && cursor->column() < range->length()) {
713  caretWidth = int(line.cursorToX(cursor->column() + 1) - line.cursorToX(cursor->column()));
714  if (caretWidth < 0) {
715  caretWidth = -caretWidth;
716  }
717  } else {
718  caretWidth = spaceWidth();
719  }
720 
721  // Determine the color
722  if (m_caretOverrideColor.isValid()) {
723  // Could actually use the real highlighting system for this...
724  // would be slower, but more accurate for corner cases
725  color = m_caretOverrideColor;
726  } else {
727  // search for the FormatRange that includes the cursor
728  foreach (const QTextLayout::FormatRange &r, range->layout()->additionalFormats()) {
729  if ((r.start <= cursor->column() ) && ( (r.start + r.length) > cursor->column())) {
730  // check for Qt::NoBrush, as the returned color is black() and no invalid QColor
731  QBrush foregroundBrush = r.format.foreground();
732  if (foregroundBrush != Qt::NoBrush) {
733  color = r.format.foreground().color();
734  }
735  break;
736  }
737  }
738  // still no color found, fall back to default style
739  if (!color.isValid())
740  color = attribute(KTextEditor::HighlightInterface::dsNormal)->foreground().color();
741  }
742 
743  // Clip the caret - Qt's caret has a habit of intruding onto other lines.
744  paint.save();
745  paint.setClipRect(0, line.lineNumber() * lineHeight(), xEnd - xStart, lineHeight());
746  switch(style) {
747  case Line :
748  paint.setPen(QPen(color, caretWidth));
749  break;
750  case Block :
751  // use a gray caret so it's possible to see the character
752  color.setAlpha(128);
753  paint.setPen(QPen(color, caretWidth));
754  break;
755  case Underline :
756  paint.setClipRect(0, lineHeight() - lineWidth, xEnd - xStart, lineWidth);
757  break;
758  case Half :
759  color.setAlpha(128);
760  paint.setPen(QPen(color, caretWidth));
761  paint.setClipRect(0, lineHeight() / 2, xEnd - xStart, lineHeight() / 2);
762  break;
763  }
764 
765  if (cursor->column() <= range->length()) {
766  range->layout()->drawCursor(&paint, QPoint(-xStart,0), cursor->column(), caretWidth);
767  } else {
768  // Off the end of the line... must be block mode. Draw the caret ourselves.
769  const KateTextLayout& lastLine = range->viewLine(range->viewLineCount() - 1);
770  int x = cursorToX(lastLine, KTextEditor::Cursor(range->line(), cursor->column()), true);
771  if ((x >= xStart) && (x <= xEnd)) {
772  paint.fillRect(x - xStart, (int)lastLine.lineLayout().y(), caretWidth, lineHeight(), color);
773  }
774  }
775 
776  paint.restore();
777  }
778  }
779 
780  // Draws the dashed underline at the start of a folded block of text.
781  if (range->startsInvisibleBlock()) {
782  const QPainter::RenderHints backupRenderHints = paint.renderHints();
783  paint.setRenderHint(QPainter::Antialiasing, false);
784  QPen pen(config()->wordWrapMarkerColor());
785  pen.setCosmetic(true);
786  pen.setStyle(Qt::DashLine);
787  pen.setDashOffset(xStart);
788  paint.setPen(pen);
789  paint.drawLine(0, (lineHeight() * range->viewLineCount()) - 1, xEnd - xStart, (lineHeight() * range->viewLineCount()) - 1);
790  paint.setRenderHints(backupRenderHints);
791  }
792 
793  // show word wrap marker if desirable
794  if ((!isPrinterFriendly()) && config()->wordWrapMarker() && QFontInfo(config()->font()).fixedPitch())
795  {
796  const QPainter::RenderHints backupRenderHints = paint.renderHints();
797  paint.setRenderHint(QPainter::Antialiasing, false);
798  paint.setPen( config()->wordWrapMarkerColor() );
799  int _x = qreal(m_doc->config()->wordWrapAt()) * fm.width('x') - xStart;
800  paint.drawLine( _x,0,_x,lineHeight() );
801  paint.setRenderHints(backupRenderHints);
802  }
803 }
804 
805 const QFont& KateRenderer::currentFont() const
806 {
807  return config()->font();
808 }
809 
810 const QFontMetricsF& KateRenderer::currentFontMetrics() const
811 {
812  return config()->fontMetrics();
813 }
814 
815 uint KateRenderer::fontHeight() const
816 {
817  return m_fontHeight;
818 }
819 
820 uint KateRenderer::documentHeight() const
821 {
822  return m_doc->lines() * lineHeight();
823 }
824 
825 int KateRenderer::lineHeight() const
826 {
827  return fontHeight();
828 }
829 
830 bool KateRenderer::getSelectionBounds(int line, int lineLength, int &start, int &end) const
831 {
832  bool hasSel = false;
833 
834  if (m_view->selection() && !m_view->blockSelection())
835  {
836  if (m_view->lineIsSelection(line))
837  {
838  start = m_view->selectionRange().start().column();
839  end = m_view->selectionRange().end().column();
840  hasSel = true;
841  }
842  else if (line == m_view->selectionRange().start().line())
843  {
844  start = m_view->selectionRange().start().column();
845  end = lineLength;
846  hasSel = true;
847  }
848  else if (m_view->selectionRange().containsLine(line))
849  {
850  start = 0;
851  end = lineLength;
852  hasSel = true;
853  }
854  else if (line == m_view->selectionRange().end().line())
855  {
856  start = 0;
857  end = m_view->selectionRange().end().column();
858  hasSel = true;
859  }
860  }
861  else if (m_view->lineHasSelected(line))
862  {
863  start = m_view->selectionRange().start().column();
864  end = m_view->selectionRange().end().column();
865  hasSel = true;
866  }
867 
868  if (start > end) {
869  int temp = end;
870  end = start;
871  start = temp;
872  }
873 
874  return hasSel;
875 }
876 
877 void KateRenderer::updateConfig ()
878 {
879  // update the attibute list pointer
880  updateAttributes ();
881 
882  if (m_view)
883  m_view->updateRendererConfig();
884 
885  // update font height
886  updateFontHeight ();
887 }
888 
889 void KateRenderer::updateFontHeight ()
890 {
891  // first: get normal line spacing
892  m_fontHeight = config()->fontMetrics().height();
893 
894  // Sometimes the height of italic fonts is larger than for the non-italic
895  // font. Since all our lines are of same/fixed height, use the maximum of
896  // both heights (bug #302748)
897  QFont italicFont = config()->font();
898  italicFont.setItalic(true);
899  m_fontHeight = qMax (m_fontHeight, QFontMetrics(italicFont).height());
900 
901  // same for bold font
902  QFont boldFont = config()->font();
903  boldFont.setBold (true);
904  m_fontHeight = qMax (m_fontHeight, QFontMetrics(boldFont).height());
905 }
906 
907 qreal KateRenderer::spaceWidth() const
908 {
909  return config()->fontMetrics().width(spaceChar);
910 }
911 
912 void KateRenderer::layoutLine(KateLineLayoutPtr lineLayout, int maxwidth, bool cacheLayout) const
913 {
914  // if maxwidth == -1 we have no wrap
915 
916  Kate::TextLine textLine = lineLayout->textLine();
917  Q_ASSERT(textLine);
918 
919  QTextLayout* l = lineLayout->layout();
920  if (!l) {
921  l = new QTextLayout(textLine->string(), config()->font());
922  } else {
923  l->setText(textLine->string());
924  l->setFont(config()->font());
925  }
926 
927  l->setCacheEnabled(cacheLayout);
928 
929  // Initial setup of the QTextLayout.
930 
931  // Tab width
932  QTextOption opt;
933  opt.setFlags(QTextOption::IncludeTrailingSpaces);
934  opt.setTabStop(m_tabWidth * config()->fontMetrics().width(spaceChar));
935  opt.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
936 
937  // Find the first strong character in the string.
938  // If it is an RTL character, set the base layout direction of the string to RTL.
939  //
940  // See http://www.unicode.org/reports/tr9/#The_Paragraph_Level (Sections P2 & P3).
941  // Qt's text renderer ("scribe") version 4.2 assumes a "higher-level protocol"
942  // (such as KatePart) will specify the paragraph level, so it does not apply P2 & P3
943  // by itself. If this ever change in Qt, the next code block could be removed.
944  if (isLineRightToLeft(lineLayout)) {
945  opt.setAlignment( Qt::AlignRight );
946  opt.setTextDirection( Qt::RightToLeft );
947  }
948  else {
949  opt.setAlignment( Qt::AlignLeft );
950  opt.setTextDirection( Qt::LeftToRight );
951  }
952 
953  l->setTextOption(opt);
954 
955  // Syntax highlighting, inbuilt and arbitrary
956  l->setAdditionalFormats(decorationsForLine(textLine, lineLayout->line()));
957 
958  // Begin layouting
959  l->beginLayout();
960 
961  int height = 0;
962  int shiftX = 0;
963 
964  bool needShiftX = (maxwidth != -1)
965  && (m_view->config()->dynWordWrapAlignIndent() > 0);
966 
967  forever {
968  QTextLine line = l->createLine();
969  if (!line.isValid())
970  break;
971 
972  if (maxwidth > 0)
973  line.setLineWidth(maxwidth);
974 
975  line.setPosition(QPoint(line.lineNumber() ? shiftX : 0, height));
976 
977  if (needShiftX && line.width() > 0) {
978  needShiftX = false;
979  // Determine x offset for subsequent-lines-of-paragraph indenting
980  int pos = textLine->nextNonSpaceChar(0);
981 
982  if (pos > 0) {
983  shiftX = (int)line.cursorToX(pos);
984  }
985 
986  // check for too deep shift value and limit if necessary
987  if (shiftX > ((double)maxwidth / 100 * m_view->config()->dynWordWrapAlignIndent()))
988  shiftX = 0;
989 
990  // if shiftX > 0, the maxwidth has to adapted
991  maxwidth -= shiftX;
992 
993  lineLayout->setShiftX(shiftX);
994  }
995 
996  height += lineHeight();
997  }
998 
999  l->endLayout();
1000 
1001  lineLayout->setLayout(l);
1002 }
1003 
1004 
1005 // 1) QString::isRightToLeft() sux
1006 // 2) QString::isRightToLeft() is marked as internal (WTF?)
1007 // 3) QString::isRightToLeft() does not seem to work on my setup
1008 // 4) isStringRightToLeft() should behave much better than QString::isRightToLeft() therefore:
1009 // 5) isStringRightToLeft() kicks ass
1010 bool KateRenderer::isLineRightToLeft( KateLineLayoutPtr lineLayout ) const
1011 {
1012  QString s = lineLayout->textLine()->string();
1013  int i = 0;
1014 
1015  // borrowed from QString::updateProperties()
1016  while( i != s.length() )
1017  {
1018  QChar c = s.at(i);
1019 
1020  switch(c.direction()) {
1021  case QChar::DirL:
1022  case QChar::DirLRO:
1023  case QChar::DirLRE:
1024  return false;
1025 
1026  case QChar::DirR:
1027  case QChar::DirAL:
1028  case QChar::DirRLO:
1029  case QChar::DirRLE:
1030  return true;
1031 
1032  default:
1033  break;
1034  }
1035  i ++;
1036  }
1037 
1038  return false;
1039 #if 0
1040  // or should we use the direction of the widget?
1041  QWidget* display = qobject_cast<QWidget*>(view()->parent());
1042  if (!display)
1043  return false;
1044  return display->layoutDirection() == Qt::RightToLeft;
1045 #endif
1046 }
1047 
1048 int KateRenderer::cursorToX(const KateTextLayout& range, int col, bool returnPastLine) const
1049 {
1050  return cursorToX(range, KTextEditor::Cursor(range.line(), col), returnPastLine);
1051 }
1052 
1053 int KateRenderer::cursorToX(const KateTextLayout& range, const KTextEditor::Cursor & pos, bool returnPastLine) const
1054 {
1055  Q_ASSERT(range.isValid());
1056 
1057  int x;
1058  if (range.lineLayout().width() > 0) {
1059  x = (int)range.lineLayout().cursorToX(pos.column());
1060  } else {
1061  x = 0;
1062  }
1063 
1064  int over = pos.column() - range.endCol();
1065  if (returnPastLine && over > 0)
1066  x += over * spaceWidth();
1067 
1068  return x;
1069 }
1070 
1071 KTextEditor::Cursor KateRenderer::xToCursor(const KateTextLayout & range, int x, bool returnPastLine ) const
1072 {
1073  Q_ASSERT(range.isValid());
1074  KTextEditor::Cursor ret(range.line(), range.lineLayout().xToCursor(x));
1075 
1076  // TODO wrong for RTL lines?
1077  if (returnPastLine && range.endCol(true) == -1 && x > range.width() + range.xOffset())
1078  ret.setColumn(ret.column() + ((x - (range.width() + range.xOffset())) / spaceWidth()));
1079 
1080  return ret;
1081 }
1082 
1083 void KateRenderer::setCaretOverrideColor(const QColor& color)
1084 {
1085  m_caretOverrideColor = color;
1086 }
1087 
1088 // kate: space-indent on; indent-width 2; replace-tabs on;
KateDocument::buffer
KateBuffer & buffer()
Get access to buffer of this document.
Definition: katedocument.h:946
QTextLine::width
qreal width() const
KateDocument::config
KateDocumentConfig * config()
Configuration.
Definition: katedocument.h:1009
KateRenderer::cursorToX
int cursorToX(const KateTextLayout &range, int col, bool returnPastLine=false) const
Returns the x position of cursor col on the line range.
Definition: katerenderer.cpp:1048
KateRenderer::setShowSelections
void setShowSelections(bool showSelections)
Set whether the view's selections should be shown.
Definition: katerenderer.cpp:135
KateRenderer::drawCaret
bool drawCaret() const
Determine whether the caret (text cursor) will be drawn.
Definition: katerenderer.h:115
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QWidget
KateRenderer::showTrailingSpaces
bool showTrailingSpaces() const
Definition: katerenderer.h:156
NormalRenderRange::addRange
void addRange(KTextEditor::Range *range, KTextEditor::Attribute::Ptr attribute)
Definition: katerenderrange.cpp:96
katehighlight.h
QFont::setPointSize
void setPointSize(int pointSize)
KateRenderer::updateConfig
void updateConfig()
Definition: katerenderer.cpp:877
kateview.h
QPen::setStyle
void setStyle(Qt::PenStyle style)
KateRendererConfig::selectionColor
const QColor & selectionColor() const
Definition: kateconfig.cpp:2348
KateTextLayout::startCol
int startCol() const
Definition: katetextlayout.cpp:127
KateRenderer::Block
Definition: katerenderer.h:71
KateRenderer::paintTextLineBackground
void paintTextLineBackground(QPainter &paint, KateLineLayoutPtr layout, int currentViewLine, int xStart, int xEnd)
Paint the background of a line.
Definition: katerenderer.cpp:172
QTextLine::xToCursor
int xToCursor(qreal x, CursorPosition cpos) const
RenderRangeList::advanceTo
void advanceTo(const KTextEditor::Cursor &pos)
Definition: katerenderrange.cpp:165
KateRenderer::currentFont
const QFont & currentFont() const
Definition: katerenderer.cpp:805
QTextLayout::setFont
void setFont(const QFont &font)
Kate::TextRange::start
const KTextEditor::MovingCursor & start() const
Retrieve start cursor of this range, read-only.
Definition: katetextrange.h:119
QPainter::RenderHints
typedef RenderHints
QPainter::fillRect
void fillRect(const QRectF &rectangle, const QBrush &brush)
KateRenderer::spaceWidth
qreal spaceWidth() const
Definition: katerenderer.cpp:907
katerenderer.h
QListIterator::next
const T & next()
KateTextLayout::line
int line() const
Definition: katetextlayout.cpp:93
QPainter::setRenderHint
void setRenderHint(RenderHint hint, bool on)
KateRendererConfig::lineMarkerColor
const QColor & lineMarkerColor(KTextEditor::MarkInterface::MarkTypes type=KTextEditor::MarkInterface::markType01) const
Definition: kateconfig.cpp:2390
KateDocument::highlight
KateHighlighting * highlight() const
Definition: katedocument.cpp:4701
QPainter::renderHints
RenderHints renderHints() const
KateRenderer::fontHeight
uint fontHeight() const
Definition: katerenderer.cpp:815
KateRenderer::setCaretOverrideColor
void setCaretOverrideColor(const QColor &color)
Set a brush with which to override drawing of the caret.
Definition: katerenderer.cpp:1083
QChar
KateRenderer::KateRenderer
KateRenderer(KateDocument *doc, Kate::TextFolding &folding, KateView *view=0)
Constructor.
Definition: katerenderer.cpp:49
QFont
KateRenderer::currentFontMetrics
const QFontMetricsF & currentFontMetrics() const
Definition: katerenderer.cpp:810
KateRenderer::documentHeight
uint documentHeight() const
Definition: katerenderer.cpp:820
QListIterator::peekNext
const T & peekNext() const
KateRenderer::attribute
KTextEditor::Attribute::Ptr attribute(uint pos) const
This takes an in index, and returns all the attributes for it.
Definition: katerenderer.cpp:79
KateTextLayout::isValid
bool isValid() const
Definition: katetextlayout.cpp:88
QTextLine::lineNumber
int lineNumber() const
katedocument.h
QPainter::save
void save()
QPainter::drawLines
void drawLines(const QLineF *lines, int lineCount)
QVectorIterator::peekNext
const T & peekNext() const
RenderRangeList
Definition: katerenderrange.h:66
KateDocumentConfig::wordWrapAt
int wordWrapAt() const
Definition: kateconfig.cpp:553
QColor::setAlpha
void setAlpha(int alpha)
KateRenderer::increaseFontSizes
void increaseFontSizes()
Change to a different font (soon to be font set?)
Definition: katerenderer.cpp:140
QBrush
nbSpaceChar
static const QChar nbSpaceChar(0xa0)
KateRendererConfig::setFont
void setFont(const QFont &font)
Definition: kateconfig.cpp:2292
QPoint
QFontMetrics
KateRendererConfig::wordWrapMarkerColor
const QColor & wordWrapMarkerColor() const
Definition: kateconfig.cpp:2445
KateRenderer::layoutLine
void layoutLine(KateLineLayoutPtr line, int maxwidth=-1, bool cacheLayout=false) const
Text width & height calculation functions...
Definition: katerenderer.cpp:912
KateTextLayout::startX
int startX() const
Definition: katetextlayout.cpp:181
QPainter::drawLine
void drawLine(const QLineF &line)
QColor::setRgb
void setRgb(int r, int g, int b, int a)
QFontMetricsF::width
qreal width(const QString &text) const
KateDocument::fromVirtualColumn
int fromVirtualColumn(int line, int column) const
Definition: katedocument.cpp:2580
KateTextLayout::endCol
int endCol(bool indicateEOL=false) const
Return the end column of this text line.
Definition: katetextlayout.cpp:140
KateRenderer::xToCursor
KTextEditor::Cursor xToCursor(const KateTextLayout &range, int x, bool returnPastLine=false) const
Returns the real cursor which is occupied by the specified x value, or that closest to it...
Definition: katerenderer.cpp:1071
QTextLayout::beginLayout
void beginLayout()
QList::size
int size() const
tabChar
static const QChar tabChar('\t')
katebuffer.h
QPointF
KateRenderer::setShowTrailingSpaces
void setShowTrailingSpaces(bool showSpaces)
Set whether a mark should be painted for trailing spaces.
Definition: katerenderer.cpp:110
QTextLine::setLineWidth
void setLineWidth(qreal width)
KateDocument::mark
virtual uint mark(int line)
Definition: katedocument.cpp:1646
QFont::setBold
void setBold(bool enable)
KateView::selectionRange
virtual const KTextEditor::Range & selectionRange() const
Definition: kateview.cpp:2815
KateViewConfig::dynWordWrapAlignIndent
int dynWordWrapAlignIndent() const
Definition: kateconfig.cpp:1447
KateRenderer
Handles all of the work of rendering the text (used for the views and printing)
Definition: katerenderer.h:50
QTextOption::setWrapMode
void setWrapMode(WrapMode mode)
QRect
KateTextLayout::xOffset
int xOffset() const
Definition: katetextlayout.cpp:55
KateRenderer::setShowTabs
void setShowTabs(bool showTabs)
Set whether a mark should be painted to help identifying tabs.
Definition: katerenderer.cpp:105
QList::count
int count(const T &value) const
KateView::updateRendererConfig
void updateRendererConfig()
Definition: kateview.cpp:1795
QList::append
void append(const T &value)
QChar::isSpace
bool isSpace() const
KateRenderer::setPrinterFriendly
void setPrinterFriendly(bool printerFriendly)
Configure this renderer to paint in a printer-friendly fashion.
Definition: katerenderer.cpp:163
QPainter::drawPoint
void drawPoint(const QPointF &position)
QTextLine::setPosition
void setPosition(const QPointF &pos)
KateRenderer::Underline
Definition: katerenderer.h:72
KateTextLayout::viewLine
int viewLine() const
Return the index of this visual line inside the document line (KateLineLayout).
Definition: katetextlayout.cpp:109
KateRenderer::config
KateRendererConfig * config() const
Configuration.
Definition: katerenderer.h:362
QSharedPointer
QWidget::layoutDirection
layoutDirection
KateRenderer::decreaseFontSizes
void decreaseFontSizes()
Definition: katerenderer.cpp:148
KateRenderer::Half
Definition: katerenderer.h:73
KateRenderer::showIndentLines
bool showIndentLines() const
Definition: katerenderer.cpp:120
KateView::lineIsSelection
bool lineIsSelection(int line)
Definition: kateview.cpp:2113
QColor::red
int red() const
QPainter::setPen
void setPen(const QColor &color)
QTextLayout::createLine
QTextLine createLine()
KateRenderer::getSelectionBounds
bool getSelectionBounds(int line, int lineLength, int &start, int &end) const
Definition: katerenderer.cpp:830
KateHighlighting::attributes
QList< KTextEditor::Attribute::Ptr > attributes(const QString &schema)
Definition: katehighlight.cpp:2172
KateRenderer::view
KateView * view() const
Returns the view to which this renderer is bound.
Definition: katerenderer.h:103
QPainter
NormalRenderRange
Definition: katerenderrange.h:47
QList::removeAll
int removeAll(const T &value)
QPen::setCosmetic
void setCosmetic(bool cosmetic)
QTextLayout
KateDocument::lines
virtual int lines() const
Definition: katedocument.cpp:753
QTextLine::cursorToX
qreal cursorToX(int *cursorPos, Edge edge) const
KateRenderer::showSelections
bool showSelections() const
Show the view's selection?
Definition: katerenderer.h:191
KateDocument::rangeOnLine
KTextEditor::Range rangeOnLine(KTextEditor::Range range, int line) const
Definition: katedocument.cpp:319
KateRenderer::showTabs
bool showTabs() const
Definition: katerenderer.h:145
QSet< Kate::TextRange * >
QTextLayout::setCacheEnabled
void setCacheEnabled(bool enable)
spaceChar
static const QChar spaceChar(' ')
KateView::blockSelection
virtual bool blockSelection() const
Definition: kateview.cpp:2221
Kate::TextFolding
Class representing the folding information for a TextBuffer.
Definition: katetextfolding.h:42
QString
QList< QTextLayout::FormatRange >
KateRenderer::Line
Definition: katerenderer.h:70
QColor
QChar::direction
Direction direction() const
QVectorIterator::hasNext
bool hasNext() const
QTextOption::setFlags
void setFlags(QFlags< QTextOption::Flag > flags)
katerenderrange.h
KateRendererConfig::setShowIndentationLines
void setShowIndentationLines(bool on)
Definition: kateconfig.cpp:2738
KateView::selection
virtual bool selection() const
Definition: kateview.cpp:2033
QTextOption
KateView
Definition: kateview.h:77
QFontInfo
KateRenderer::setIndentWidth
void setIndentWidth(int indentWidth)
Sets the width of the tab.
Definition: katerenderer.cpp:130
QColor::green
int green() const
KateRenderer::~KateRenderer
~KateRenderer()
Destructor.
Definition: katerenderer.cpp:69
QList::end
iterator end()
KateRendererConfig::highlightedLineColor
const QColor & highlightedLineColor() const
Definition: kateconfig.cpp:2369
KateDocument
Definition: katedocument.h:74
KateRenderer::updateAttributes
void updateAttributes()
update the highlighting attributes (for example after an hl change or after hl config changed) ...
Definition: katerenderer.cpp:74
KateRenderer::setTabWidth
void setTabWidth(int tabWidth)
Sets the width of the tab.
Definition: katerenderer.cpp:115
RenderRangeList::hasAttribute
bool hasAttribute() const
Definition: katerenderrange.cpp:180
KateRenderer::specificAttribute
KTextEditor::Attribute::Ptr specificAttribute(int context) const
Definition: katerenderer.cpp:87
QFont::setItalic
void setItalic(bool enable)
QSet::contains
bool contains(const T &value) const
KateRenderer::caretStyles
caretStyles
Style of Caret.
Definition: katerenderer.h:69
Kate::TextRange::zDepth
qreal zDepth() const
Gets the current Z-depth of this range.
Definition: katetextrange.h:226
QVectorIterator
QPainter::setRenderHints
void setRenderHints(QFlags< QPainter::RenderHint > hints, bool on)
QPainter::restore
void restore()
katetextlayout.h
QColor::blue
int blue() const
QSet::empty
bool empty() const
Kate::TextBuffer::rangesForLine
QList< TextRange * > rangesForLine(int line, KTextEditor::View *view, bool rangesWithAttributeOnly) const
Return the ranges which affect the given line.
Definition: katetextbuffer.cpp:872
Kate::TextRange::end
const KTextEditor::MovingCursor & end() const
Retrieve end cursor of this range, read-only.
Definition: katetextrange.h:131
KateRendererConfig
Definition: kateconfig.h:618
KateTextLayout
This class represents one visible line of text; with dynamic wrapping, many KateTextLayouts can be ne...
Definition: katetextlayout.h:38
QPainter::setClipRect
void setClipRect(const QRectF &rectangle, Qt::ClipOperation operation)
QVector
QTextLine
KateTextLayout::width
int width() const
Definition: katetextlayout.cpp:202
KateRenderer::caretStyle
KateRenderer::caretStyles caretStyle() const
The style of the caret (text cursor) to be painted.
Definition: katerenderer.h:127
KateRenderer::isPrinterFriendly
bool isPrinterFriendly() const
Definition: katerenderer.cpp:158
KateRendererConfig::font
const QFont & font() const
Definition: kateconfig.cpp:2276
QTextLine::y
qreal y() const
rangeLessThanForRenderer
static bool rangeLessThanForRenderer(const Kate::TextRange *a, const Kate::TextRange *b)
Definition: katerenderer.cpp:320
KateRenderer::setCaretStyle
void setCaretStyle(KateRenderer::caretStyles style)
Set the style of caret to be painted.
Definition: katerenderer.cpp:100
QTextOption::setTextDirection
void setTextDirection(Qt::LayoutDirection direction)
QString::at
const QChar at(int position) const
KateRenderer::paintTextLine
void paintTextLine(QPainter &paint, KateLineLayoutPtr range, int xStart, int xEnd, const KTextEditor::Cursor *cursor=0L)
This is the ultimate function to perform painting of a text line.
Definition: katerenderer.cpp:506
RenderRangeList::generateAttribute
KTextEditor::Attribute::Ptr generateAttribute() const
Definition: katerenderrange.cpp:189
QVector::count
int count(const T &value) const
KateTextLayout::end
KTextEditor::Cursor end(bool indicateEOL=false) const
Return the end position of this text line.
Definition: katetextlayout.cpp:152
QString::length
int length() const
KateRenderer::lineHeight
int lineHeight() const
Definition: katerenderer.cpp:825
KateTextLayout::endX
int endX() const
Definition: katetextlayout.cpp:194
QTextLayout::setTextOption
void setTextOption(const QTextOption &option)
QPen
KateView::lineHasSelected
bool lineHasSelected(int line)
Definition: kateview.cpp:2108
KateRendererConfig::showIndentationLines
bool showIndentationLines() const
Definition: kateconfig.cpp:2730
KateTextLayout::lineLayout
const QTextLine & lineLayout() const
Definition: katetextlayout.cpp:117
QTextLine::isValid
bool isValid() const
KateDocument::toVirtualColumn
int toVirtualColumn(int line, int column) const
Definition: katedocument.cpp:2565
QListIterator
KateRendererConfig::fontMetrics
const QFontMetricsF & fontMetrics() const
Definition: kateconfig.cpp:2284
Kate::TextRange::attribute
KTextEditor::Attribute::Ptr attribute() const
Gets the active Attribute for this range.
Definition: katetextrange.h:173
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
KateView::lineEndSelected
bool lineEndSelected(const KTextEditor::Cursor &lineEndPos)
Definition: kateview.cpp:2101
QTextLayout::setText
void setText(const QString &string)
RenderRangeList::nextBoundary
KTextEditor::Cursor nextBoundary() const
Definition: katerenderrange.cpp:143
QTextLayout::FormatRange
KateRenderer::setShowIndentLines
void setShowIndentLines(bool showLines)
Set whether a guide should be painted to help identifying indent lines.
Definition: katerenderer.cpp:125
QTextLayout::setAdditionalFormats
void setAdditionalFormats(const QList< FormatRange > &formatList)
KateView::config
KateViewConfig * config()
Configuration.
Definition: kateview.h:653
KateRenderer::setDrawCaret
void setDrawCaret(bool drawCaret)
Set whether the caret (text cursor) will be drawn.
Definition: katerenderer.cpp:95
QTextOption::setAlignment
void setAlignment(QFlags< Qt::AlignmentFlag > alignment)
QPainter::pen
const QPen & pen() const
kateconfig.h
KateLineLayoutPtr
KSharedPtr< KateLineLayout > KateLineLayoutPtr
Definition: katelinelayout.h:120
Kate::TextRange
Class representing a 'clever' text range.
Definition: katetextrange.h:46
QVectorIterator::next
const T & next()
QList::begin
iterator begin()
KateRenderRange
Definition: katerenderrange.h:35
QTextOption::setTabStop
void setTabStop(qreal tabStop)
KateRenderer::isLineRightToLeft
bool isLineRightToLeft(KateLineLayoutPtr lineLayout) const
This is a smaller QString::isRightToLeft().
Definition: katerenderer.cpp:1010
QFont::pointSize
int pointSize() const
QTextLayout::endLayout
void endLayout()
QFontMetricsF::height
qreal height() const
QColor::isValid
bool isValid() const
QPen::setDashOffset
void setDashOffset(qreal offset)
QFontMetricsF
QListIterator::hasNext
bool hasNext() const
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