• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • sources
  • kde-4.12
  • applications
  • kate
  • part
  • view
kateviewhelpers.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2008, 2009 Matthew Woehlke <mw_triad@users.sourceforge.net>
3  Copyright (C) 2007 Mirko Stocker <me@misto.ch>
4  Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
5  Copyright (C) 2001 Anders Lund <anders@alweb.dk>
6  Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
7  Copyright (C) 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com>
8  Copyright (C) 2012 Kåre Särs <kare.sars@iki.fi> (Minimap)
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Library General Public
12  License version 2 as published by the Free Software Foundation.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Library General Public License for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with this library; see the file COPYING.LIB. If not, write to
21  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  Boston, MA 02110-1301, USA.
23 */
24 
25 #include "kateviewhelpers.h"
26 
27 #include "katecmd.h"
28 #include <ktexteditor/attribute.h>
29 #include <ktexteditor/annotationinterface.h>
30 #include <ktexteditor/movingrange.h>
31 #include <ktexteditor/containerinterface.h>
32 #include <ktexteditor/highlightinterface.h>
33 #include "kateconfig.h"
34 #include "katedocument.h"
35 #include <katebuffer.h>
36 #include "katerenderer.h"
37 #include "kateview.h"
38 #include "kateviewinternal.h"
39 #include "katelayoutcache.h"
40 #include "katetextlayout.h"
41 #include "kateglobal.h"
42 #include "kateviglobal.h"
43 #include <katevicommandrangeexpressionparser.h>
44 
45 #include <kapplication.h>
46 #include <kcharsets.h>
47 #include <kcolorscheme.h>
48 #include <kcolorutils.h>
49 #include <kdebug.h>
50 #include <kglobalsettings.h>
51 #include <klocale.h>
52 #include <knotification.h>
53 #include <kglobal.h>
54 #include <kmenu.h>
55 #include <kiconloader.h>
56 #include <kconfiggroup.h>
57 #include "ktoolinvocation.h"
58 
59 #include <QtAlgorithms>
60 #include <QVariant>
61 #include <QtGui/QCursor>
62 #include <QtGui/QMenu>
63 #include <QtGui/QPainter>
64 #include <QtGui/QStyle>
65 #include <QtCore/QTimer>
66 #include <QtCore/QRegExp>
67 #include <QtCore/QTextCodec>
68 #include <QtGui/QKeyEvent>
69 #include <QtGui/QPainterPath>
70 #include <QtGui/QStyleOption>
71 #include <QtGui/QPalette>
72 #include <QtGui/QPen>
73 #include <QtGui/QBoxLayout>
74 #include <QtGui/QToolButton>
75 #include <QtGui/QToolTip>
76 #include <QtGui/QAction>
77 #include <QtGui/QWhatsThis>
78 #include <QtGui/QLinearGradient>
79 
80 #include <math.h>
81 
82 //BEGIN KateScrollBar
83 static const int s_lineWidth = 100;
84 static const int s_pixelMargin = 8;
85 static const int s_linePixelIncLimit = 6;
86 
87 unsigned char KateScrollBar::characterOpacity[256] = {
88  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // <- 15
89  0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 0, 0, 0, 0, // <- 31
90  0, 125, 41, 221, 138, 195, 218, 21, 142, 142, 137, 137, 97, 87, 87, 140, // <- 47
91  223, 164, 183, 190, 191, 193, 214, 158, 227, 216, 103, 113, 146, 140, 146, 149, // <- 63
92  248, 204, 240, 174, 217, 197, 178, 205, 209, 176, 168, 211, 160, 246, 238, 218, // <- 79
93  195, 229, 227, 196, 167, 212, 188, 238, 197, 169, 189, 158, 21, 151, 115, 90, // <- 95
94  15, 192, 209, 153, 208, 187, 162, 221, 183, 149, 161, 191, 146, 203, 167, 182, // <- 111
95  208, 203, 139, 166, 158, 167, 157, 189, 164, 179, 156, 167, 145, 166, 109, 0, // <- 127
96  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // <- 143
97  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // <- 159
98  0, 125, 184, 187, 146, 201, 127, 203, 89, 194, 156, 141, 117, 87, 202, 88, // <- 175
99  115, 165, 118, 121, 85, 190, 236, 87, 88, 111, 151, 140, 194, 191, 203, 148, // <- 191
100  215, 215, 222, 224, 223, 234, 230, 192, 208, 208, 216, 217, 187, 187, 194, 195, // <- 207
101  228, 255, 228, 228, 235, 239, 237, 150, 255, 222, 222, 229, 232, 180, 197, 225, // <- 223
102  208, 208, 216, 217, 212, 230, 218, 170, 202, 202, 211, 204, 156, 156, 165, 159, // <- 239
103  214, 194, 197, 197, 206, 206, 201, 132, 214, 183, 183, 192, 187, 195, 227, 198
104 };
105 
106 
107 KateScrollBar::KateScrollBar (Qt::Orientation orientation, KateViewInternal* parent)
108  : QScrollBar (orientation, parent->m_view)
109  , m_middleMouseDown (false)
110  , m_leftMouseDown (false)
111  , m_view(parent->m_view)
112  , m_doc(parent->doc())
113  , m_viewInternal(parent)
114  , m_showMarks(false)
115  , m_showMiniMap(false)
116  , m_miniMapAll(true)
117  , m_miniMapWidth(40)
118  , m_grooveHeight(height())
119  , m_linesModified(0)
120 {
121  connect(this, SIGNAL(valueChanged(int)), this, SLOT(sliderMaybeMoved(int)));
122  connect(m_doc, SIGNAL(marksChanged(KTextEditor::Document*)), this, SLOT(marksChanged()));
123 
124  styleChange(*style());
125 
126  m_updateTimer.setInterval(300);
127  m_updateTimer.setSingleShot(true);
128  QTimer::singleShot(10, this, SLOT(updatePixmap()));
129 }
130 
131 void KateScrollBar::setShowMiniMap(bool b)
132 {
133  if (b && !m_showMiniMap) {
134  connect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), &m_updateTimer, SLOT(start()), Qt::UniqueConnection);
135  connect(m_doc, SIGNAL(textChanged(KTextEditor::Document*)), &m_updateTimer, SLOT(start()), Qt::UniqueConnection);
136  connect(m_view, SIGNAL(delayedUpdateOfView()), &m_updateTimer, SLOT(start()), Qt::UniqueConnection);
137  connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updatePixmap()), Qt::UniqueConnection);
138  connect(&(m_view->textFolding()), SIGNAL(foldingRangesChanged()), &m_updateTimer, SLOT(start()), Qt::UniqueConnection);
139  }
140  else if (!b) {
141  disconnect(&m_updateTimer);
142  }
143 
144  m_showMiniMap = b;
145 
146  updateGeometry();
147  update();
148 }
149 
150 QSize KateScrollBar::sizeHint() const
151 {
152  if (m_showMiniMap) {
153  return QSize(m_miniMapWidth, QScrollBar::sizeHint().height());
154  }
155  return QScrollBar::sizeHint();
156 }
157 
158 int KateScrollBar::minimapYToStdY(int y)
159 {
160  // Check if the minimap fills the whole scrollbar
161  if (m_stdGroveRect.height() == m_mapGroveRect.height()){
162  return y;
163  }
164 
165  // check if y is on the step up/down
166  if ((y < m_stdGroveRect.top()) || (y > m_stdGroveRect.bottom())) {
167  return y;
168  }
169 
170  if (y < m_mapGroveRect.top()) {
171  return m_stdGroveRect.top() + 1;
172  }
173 
174  if (y > m_mapGroveRect.bottom()) {
175  return m_stdGroveRect.bottom() - 1;
176  }
177 
178  // check for div/0
179  if (m_mapGroveRect.height() == 0) {
180  return y;
181  }
182 
183  int newY = (y - m_mapGroveRect.top()) * m_stdGroveRect.height() / m_mapGroveRect.height();
184  newY += m_stdGroveRect.top();
185  return newY;
186 }
187 
188 void KateScrollBar::mousePressEvent(QMouseEvent* e)
189 {
190  if (m_showMiniMap) {
191  QMouseEvent eMod(QEvent::MouseButtonPress,
192  QPoint(6, minimapYToStdY(e->pos().y())),
193  e->button(), e->buttons(), e->modifiers());
194  QScrollBar::mousePressEvent(&eMod);
195  }
196  else {
197  QScrollBar::mousePressEvent(e);
198  }
199 
200  if (e->button() == Qt::MidButton)
201  m_middleMouseDown = true;
202  else if (e->button() == Qt::LeftButton)
203  m_leftMouseDown = true;
204 
205  m_toolTipPos = e->globalPos() - QPoint(e->pos().x(), 0);
206  const int fromLine = m_viewInternal->toRealCursor(m_viewInternal->startPos()).line() + 1;
207  const int lastLine = m_viewInternal->toRealCursor(m_viewInternal->endPos()).line() + 1;
208  QToolTip::showText(m_toolTipPos, i18nc("from line - to line", "<center>%1<br/>&#x2014;<br/>%2</center>", fromLine, lastLine), this);
209 
210  redrawMarks();
211 }
212 
213 void KateScrollBar::mouseReleaseEvent(QMouseEvent* e)
214 {
215  if (e->button() == Qt::MidButton)
216  m_middleMouseDown = false;
217  else if (e->button() == Qt::LeftButton)
218  m_leftMouseDown = false;
219 
220  redrawMarks();
221 
222  if (m_leftMouseDown || m_middleMouseDown) {
223  QToolTip::hideText();
224  }
225 
226  if (m_showMiniMap) {
227  QMouseEvent eMod(QEvent::MouseButtonRelease,
228  QPoint(e->pos().x(), minimapYToStdY(e->pos().y())),
229  e->button(), e->buttons(), e->modifiers());
230  QScrollBar::mouseReleaseEvent(&eMod);
231  }
232  else {
233  QScrollBar::mouseReleaseEvent(e);
234  }
235 }
236 
237 void KateScrollBar::mouseMoveEvent(QMouseEvent* e)
238 {
239  if (m_showMiniMap) {
240  QMouseEvent eMod(QEvent::MouseMove,
241  QPoint(e->pos().x(), minimapYToStdY(e->pos().y())),
242  e->button(), e->buttons(), e->modifiers());
243  QScrollBar::mouseMoveEvent(&eMod);
244  }
245  else {
246  QScrollBar::mouseMoveEvent(e);
247  }
248 
249  if (e->buttons() & (Qt::LeftButton | Qt::MidButton)) {
250  redrawMarks();
251 
252  // current line tool tip
253  m_toolTipPos = e->globalPos() - QPoint(e->pos().x(), 0);
254  const int fromLine = m_viewInternal->toRealCursor(m_viewInternal->startPos()).line() + 1;
255  const int lastLine = m_viewInternal->toRealCursor(m_viewInternal->endPos()).line() + 1;
256  QToolTip::showText(m_toolTipPos, i18nc("from line - to line", "<center>%1<br/>&#x2014;<br/>%2</center>", fromLine, lastLine), this);
257  }
258 }
259 
260 void KateScrollBar::paintEvent(QPaintEvent *e)
261 {
262  if (m_doc->marks().size() != m_lines.size()) {
263  recomputeMarksPositions();
264  }
265  if (m_showMiniMap) {
266  miniMapPaintEvent(e);
267  }
268  else {
269  normalPaintEvent(e);
270  }
271 }
272 
273 // This function is optimized for bing called in sequence.
274 const QColor KateScrollBar::charColor(const QVector<Kate::TextLineData::Attribute> &attributes, int &attributeIndex,
275  const QList<QTextLayout::FormatRange> &decorations,
276  const QColor &defaultColor, int x, QChar ch)
277 {
278  QColor color = defaultColor;
279 
280  bool styleFound = false;
281 
282  // Query the decorations, that is, things like search highlighting, or the
283  // KDevelop DUChain highlighting, for a color to use
284  foreach (const QTextLayout::FormatRange& range, decorations) {
285  if (range.start <= x && range.start + range.length > x) {
286  // If there's a different background color set (search markers, ...)
287  // use that, otherwise use the foreground color.
288  if ( range.format.hasProperty(QTextFormat::BackgroundBrush) ) {
289  color = range.format.background().color();
290  }
291  else {
292  color = range.format.foreground().color();
293  }
294  styleFound = true;
295  break;
296  }
297  }
298 
299  // If there's no decoration set for the current character (this will mostly be the case for
300  // plain Kate), query the styles, that is, the default kate syntax highlighting.
301  if (!styleFound) {
302  // go to the block containing x
303  while ((attributeIndex < attributes.size()) &&
304  ((attributes[attributeIndex].offset + attributes[attributeIndex].length) < x))
305  {
306  ++attributeIndex;
307  }
308  if ((attributeIndex < attributes.size()) && (x < attributes[attributeIndex].offset + attributes[attributeIndex].length)) {
309  color = m_view->renderer()->attribute(attributes[attributeIndex].attributeValue)->foreground().color();
310  }
311  }
312 
313  // Query how much "blackness" the character has.
314  // This causes for example a dot or a dash to appear less intense
315  // than an A or similar.
316  // This gives the pixels created a bit of structure, which makes it look more
317  // like real text.
318  color.setAlpha((ch.unicode() < 256) ? characterOpacity[ch.unicode()] : 1.0);
319 
320  return color;
321 }
322 
323 void KateScrollBar::updatePixmap()
324 {
325  //QTime time;
326  //time.start();
327 
328  if (!m_showMiniMap) {
329  // make sure no time is wasted if the option is disabled
330  return;
331  }
332 
333  // For performance reason, only every n-th line will be drawn if the widget is
334  // sufficiently small compared to the amount of lines in the document.
335  int docLineCount = m_view->textFolding().visibleLines();
336  int pixmapLineCount = docLineCount;
337  if (m_view->config()->scrollPastEnd()) {
338  pixmapLineCount += pageStep();
339  }
340  int pixmapLinesUnscaled = pixmapLineCount;
341  if (m_grooveHeight < 5) m_grooveHeight = 5;
342  int lineDivisor = pixmapLinesUnscaled/m_grooveHeight;
343  if (lineDivisor < 1) lineDivisor = 1;
344  int charIncrement = 1;
345  int lineIncrement = 1;
346  if ( (m_grooveHeight > 10) && (pixmapLineCount >= m_grooveHeight*2) ) {
347  charIncrement = pixmapLineCount / m_grooveHeight;
348  while (charIncrement > s_linePixelIncLimit) {
349  lineIncrement++;
350  pixmapLineCount = pixmapLinesUnscaled/lineIncrement;
351  charIncrement = pixmapLineCount / m_grooveHeight;
352  }
353  pixmapLineCount /= charIncrement;
354  }
355 
356  int pixmapLineWidth = s_pixelMargin + s_lineWidth/charIncrement;
357 
358  //kDebug(13040) << "l" << lineIncrement << "c" << charIncrement << "d" << lineDivisor;
359  //kDebug(13040) << "pixmap" << pixmapLineCount << pixmapLineWidth << "docLines" << m_view->textFolding().visibleLines() << "height" << m_grooveHeight;
360 
361  QColor backgroundColor;
362  QColor defaultTextColor;
363  if (m_doc->defaultStyle(KTextEditor::HighlightInterface::dsNormal)) {
364  backgroundColor = m_doc->defaultStyle(KTextEditor::HighlightInterface::dsNormal)->background().color();
365  defaultTextColor = m_doc->defaultStyle(KTextEditor::HighlightInterface::dsNormal)->foreground().color();
366  }
367  else {
368  backgroundColor = palette().color(QPalette::Base);
369  defaultTextColor = palette().color(QPalette::Text);
370  }
371  QColor modifiedLineColor = m_view->renderer()->config()->modifiedLineColor();
372  QColor savedLineColor = m_view->renderer()->config()->savedLineColor();
373  // move the modified line color away from the background color
374  modifiedLineColor.setHsv(modifiedLineColor.hue(), 255, 255 - backgroundColor.value()/3);
375  savedLineColor.setHsv(savedLineColor.hue(), 100, 255 - backgroundColor.value()/3);
376 
377  m_pixmap = QPixmap(pixmapLineWidth, pixmapLineCount);
378  m_pixmap.fill(QColor("transparent"));
379 
380  // The text currently selected in the document, to be drawn later.
381  const Range& selection = m_view->selectionRange();
382 
383  QPainter painter;
384  if ( painter.begin(&m_pixmap) ) {
385  // Do not force updates of the highlighting if the document is very large
386  bool simpleMode = m_doc->lines() > 7500;
387 
388  int pixelY = 0;
389  int drawnLines = 0;
390 
391  // Iterate over all visible lines, drawing them.
392  for (int virtualLine=0; virtualLine < docLineCount; virtualLine += lineIncrement) {
393 
394  int realLineNumber = m_view->textFolding().visibleLineToLine(virtualLine);
395  QString lineText = m_doc->line(realLineNumber);
396 
397  // use this to control the offset of the text from the left
398  int pixelX = s_pixelMargin;
399 
400  if (!simpleMode) {
401  m_doc->buffer().ensureHighlighted(realLineNumber);
402  }
403  const Kate::TextLine& kateline = m_doc->plainKateTextLine(realLineNumber);
404 
405  const QVector<Kate::TextLineData::Attribute> &attributes = kateline->attributesList();
406  QList< QTextLayout::FormatRange > decorations = m_view->renderer()->decorationsForLine(kateline, realLineNumber);
407  int attributeIndex = 0;
408 
409  // The color to draw the currently selected text in; change the alpha value to make it
410  // more or less intense
411  QColor selectionColor = palette().color(QPalette::HighlightedText);
412  selectionColor.setAlpha(180);
413 
414  painter.setPen(defaultTextColor);
415  // Iterate over all the characters in the current line
416  for (int x = 0; (x < lineText.size() && x < s_lineWidth); x += charIncrement) {
417  if (pixelX >= s_lineWidth + s_pixelMargin) {
418  break;
419  }
420 
421  // draw the pixels
422  if (lineText[x] == ' ') {
423  pixelX++;
424  }
425  else if (lineText[x] == '\t') {
426  pixelX += qMax(4/charIncrement, 1); // FIXME: tab width...
427  }
428  else {
429  painter.setPen(charColor(attributes, attributeIndex, decorations, defaultTextColor, x, lineText[x]));
430 
431  // Actually draw the pixel with the color queried from the renderer.
432  painter.drawPoint(pixelX, pixelY);
433 
434  pixelX++;
435  }
436 
437  // Query the selection and draw it above the character with an alpha channel
438  if (selection.contains(Cursor(realLineNumber, x))) {
439  painter.setPen(selectionColor);
440  painter.drawPoint(s_pixelMargin, pixelY);
441  // fill the line up in case the selection extends beyond it
442  if (lineText.size() - 1 == x) {
443  for (int xFill = s_pixelMargin; xFill < s_lineWidth; xFill++) {
444  painter.drawPoint(xFill, pixelY);
445  }
446  }
447  }
448  }
449  drawnLines++;
450  if (((drawnLines) % charIncrement) == 0) {
451  pixelY++;
452  }
453 
454  }
455  //kDebug(13040) << drawnLines;
456  // Draw line modification marker map.
457  // Disable this if the document is really huge,
458  // since it requires querying every line.
459  if ( m_doc->lines() < 50000 ) {
460  for ( int lineno = 0; lineno < docLineCount; lineno++ ) {
461  int realLineNo = m_view->textFolding().visibleLineToLine(lineno);
462  const Kate::TextLine& line = m_doc->plainKateTextLine(realLineNo);
463  if ( line->markedAsModified() ) {
464  painter.setPen(modifiedLineColor);
465  }
466  else if ( line->markedAsSavedOnDisk() ) {
467  painter.setPen(savedLineColor);
468  }
469  else {
470  continue;
471  }
472  painter.drawRect(2, lineno/lineDivisor, 3, 1);
473  }
474  }
475  }
476  //kDebug(13040) << time.elapsed();
477  // Redraw the scrollbar widget with the updated pixmap.
478  update();
479 }
480 
481 void KateScrollBar::miniMapPaintEvent(QPaintEvent *e)
482 {
483  QScrollBar::paintEvent(e);
484 
485  QPainter painter(this);
486 
487  QStyleOptionSlider opt;
488  opt.init(this);
489  opt.subControls = QStyle::SC_None;
490  opt.activeSubControls = QStyle::SC_None;
491  opt.orientation = orientation();
492  opt.minimum = minimum();
493  opt.maximum = maximum();
494  opt.sliderPosition = sliderPosition();
495  opt.sliderValue = value();
496  opt.singleStep = singleStep();
497  opt.pageStep = pageStep();
498 
499  int docXMargin = 1;
500  QRect grooveRect = style()->subControlRect(QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarGroove, this);
501  m_stdGroveRect = grooveRect;
502  if (style()->subControlRect(QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarSubLine, this).height() == 0) {
503  int alignMargin = style()->pixelMetric(QStyle::PM_FocusFrameVMargin, &opt, this);
504  grooveRect.moveTop(alignMargin);
505  grooveRect.setHeight(grooveRect.height() - alignMargin);
506  }
507  if (style()->subControlRect(QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarAddLine, this).height() == 0) {
508  int alignMargin = style()->pixelMetric(QStyle::PM_FocusFrameVMargin, &opt, this);
509  grooveRect.setHeight(grooveRect.height() - alignMargin);
510  }
511  m_grooveHeight = grooveRect.height();
512 
513  QRect sliderRect = style()->subControlRect(QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarSlider, this);
514  m_stdSliderRect = sliderRect;
515  sliderRect.adjust(docXMargin+1, 1, -(docXMargin+1), -1);
516 
517  //style()->drawControl(QStyle::CE_ScrollBarAddLine, &opt, &painter, this);
518  //style()->drawControl(QStyle::CE_ScrollBarSubLine, &opt, &painter, this);
519 
520  // calculate the document size and position
521  int docHeight = qMin(grooveRect.height(), m_pixmap.height()*2) - 2*docXMargin;
522  int yoffset = 1; // top-aligned in stead of center-aligned (grooveRect.height() - docHeight) / 2;
523  QRect docRect(QPoint(grooveRect.left()+docXMargin, yoffset+grooveRect.top()), QSize(grooveRect.width()-2*docXMargin, docHeight));
524  m_mapGroveRect = docRect;
525 
526  // calculate the visible area
527  int max = qMax(maximum()+1, 1);
528  int visibleStart = value()*docHeight/(max+pageStep()) + docRect.top();
529  int visibleEnd = (value()+pageStep())*docHeight/(max+pageStep()) + docRect.top();
530  QRect visibleRect = docRect;
531  visibleRect.moveTop(visibleStart);
532  visibleRect.setHeight(visibleEnd-visibleStart);
533  m_mapSliderRect = visibleRect;
534 
535  // calculate colors
536  QColor backgroundColor;
537  QColor foregroundColor;
538  // TODO KDE5: If HighlightInterface is a View interface, use HighlightInterface::defaultStyle() again.
539  if (m_doc->defaultStyle(KTextEditor::HighlightInterface::dsNormal)) {
540  backgroundColor = m_doc->defaultStyle(KTextEditor::HighlightInterface::dsNormal)->background().color();
541  foregroundColor = m_doc->defaultStyle(KTextEditor::HighlightInterface::dsNormal)->foreground().color();
542  }
543  else {
544  backgroundColor = palette().color(QPalette::Base);
545  foregroundColor = palette().color(QPalette::Text);
546  }
547  int backgroundLightness = backgroundColor.lightness();
548  int foregroundLightness = foregroundColor.lightness();
549  int lighnessDiff = (foregroundLightness - backgroundLightness);
550 
551  // get a color suited for the color theme
552  QColor darkShieldColor = palette().color(QPalette::Mid);
553  int hue, sat, light;
554  darkShieldColor.getHsl(&hue, &sat, &light);
555  // apply suitable lightness
556  darkShieldColor.setHsl(hue, sat, backgroundLightness + lighnessDiff * 0.35);
557  // gradient for nicer results
558  QLinearGradient gradient(0, 0, width(), 0);
559  gradient.setColorAt(0, darkShieldColor);
560  gradient.setColorAt(0.3, darkShieldColor.lighter(115));
561  gradient.setColorAt(1, darkShieldColor);
562 
563  QColor lightShieldColor;
564  lightShieldColor.setHsl(hue, sat, backgroundLightness + lighnessDiff * 0.15);
565 
566  QColor outlineColor;
567  outlineColor.setHsl(hue, sat, backgroundLightness + lighnessDiff * 0.5);
568 
569  // draw the grove background in case the document is small
570  painter.setPen(QPen(QColor("transparent"),0));
571  painter.setBrush(palette().brush(QPalette::Dark));
572  painter.drawRect(grooveRect);
573 
574  // dark "shield" of non-slider parts
575  painter.setBrush(gradient);
576  painter.drawRect(docRect);
577 
578 
579  // light "shield" non-visible parts
580  if ((docHeight+2*docXMargin >= grooveRect.height()) && (sliderRect.height() > visibleRect.height()+2)) {
581  // slider
582  painter.setPen(QPen(QColor("transparent"),0));
583  painter.setBrush(lightShieldColor);
584  sliderRect.adjust(1,0,-1,0);
585  painter.drawRect(sliderRect);
586 
587  // visible area
588  visibleRect.adjust(2,0,-3,0);
589  painter.setPen(QPen(backgroundColor,1));
590  painter.setBrush(backgroundColor);
591  painter.drawRect(visibleRect);
592 
593  // slider outline
594  painter.setRenderHint(QPainter::Antialiasing);
595  painter.setPen(QPen(outlineColor, 2));
596  painter.setBrush(QColor("transparent"));
597  sliderRect.adjust(-1,0,1,0);
598  painter.drawRoundedRect(sliderRect, 4, 4);
599  painter.setRenderHint(QPainter::Antialiasing, false);
600  }
601  else {
602  // visible area with outline
603  painter.setRenderHint(QPainter::Antialiasing);
604  painter.setPen(QPen(outlineColor, 2));
605  painter.setBrush(backgroundColor);
606  visibleRect.adjust(1,0,-1,2);
607  painter.drawRoundedRect(visibleRect, 4, 4);
608  painter.setRenderHint(QPainter::Antialiasing, false);
609  }
610 
611  // Smooth transform only when squeezing
612  if (grooveRect.height() < m_pixmap.height()) {
613  painter.setRenderHint(QPainter::SmoothPixmapTransform);
614  }
615 
616  // draw the modified lines margin
617  QRect pixmapMarginRect(QPoint(0, 0), QSize(s_pixelMargin, m_pixmap.height()));
618  QRect docPixmapMarginRect(QPoint(0, docRect.top()), QSize(s_pixelMargin, docRect.height()));
619  painter.drawPixmap(docPixmapMarginRect, m_pixmap, pixmapMarginRect);
620 
621  // calculate the stretch and draw the stretched lines
622  QRect pixmapRect(QPoint(s_pixelMargin, 0), QSize(m_pixmap.width() - s_pixelMargin, m_pixmap.height()));
623  QRect docPixmapRect(QPoint(s_pixelMargin, docRect.top()), QSize(docRect.width()-s_pixelMargin, docRect.height()));
624  painter.drawPixmap(docPixmapRect, m_pixmap, pixmapRect);
625 
626  if (!m_showMarks) return;
627 
628  QHashIterator<int, QColor> it = m_lines;
629  QPen penBg;
630  penBg.setWidth(4);
631  lightShieldColor.setAlpha(180);
632  penBg.setColor(lightShieldColor);
633  painter.setPen(penBg);
634  while (it.hasNext())
635  {
636  it.next();
637  int y = (it.key()-grooveRect.top()) * docHeight/grooveRect.height() + docRect.top();;
638  painter.drawLine(6, y, width()-6, y);
639  }
640 
641  it = m_lines;
642  QPen pen;
643  pen.setWidth(2);
644  while (it.hasNext())
645  {
646  it.next();
647  pen.setColor(it.value());
648  painter.setPen(pen);
649  int y = (it.key()-grooveRect.top()) * docHeight/grooveRect.height() + docRect.top();;
650  painter.drawLine(6, y, width()-6, y);
651  }
652 }
653 
654 void KateScrollBar::normalPaintEvent(QPaintEvent *e)
655 {
656  QScrollBar::paintEvent(e);
657 
658  if (!m_showMarks) return;
659 
660  QPainter painter(this);
661 
662  QStyleOptionSlider opt;
663  opt.init(this);
664  opt.subControls = QStyle::SC_None;
665  opt.activeSubControls = QStyle::SC_None;
666  opt.orientation = orientation();
667  opt.minimum = minimum();
668  opt.maximum = maximum();
669  opt.sliderPosition = sliderPosition();
670  opt.sliderValue = value();
671  opt.singleStep = singleStep();
672  opt.pageStep = pageStep();
673 
674  QRect rect = style()->subControlRect(QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarSlider, this);
675  int sideMargin = width() - rect.width();
676  if (sideMargin < 4) sideMargin = 4;
677  sideMargin /= 2;
678 
679  QHashIterator<int, QColor> it = m_lines;
680  while (it.hasNext())
681  {
682  it.next();
683  painter.setPen(it.value());
684  if (it.key() < rect.top() || it.key() > rect.bottom())
685  {
686  painter.drawLine(0, it.key(), width(), it.key());
687  }
688  else
689  {
690  painter.drawLine(0, it.key(), sideMargin, it.key());
691  painter.drawLine(width()-sideMargin, it.key(), width(), it.key());
692  }
693  }
694 }
695 
696 void KateScrollBar::resizeEvent(QResizeEvent *e)
697 {
698  QScrollBar::resizeEvent(e);
699  m_updateTimer.start();
700  m_lines.clear();
701  update();
702 }
703 
704 void KateScrollBar::styleChange(QStyle &s)
705 {
706  QScrollBar::styleChange(s);
707  m_lines.clear();
708  update();
709 }
710 
711 void KateScrollBar::sliderChange ( SliderChange change )
712 {
713  // call parents implementation
714  QScrollBar::sliderChange (change);
715 
716  if (change == QAbstractSlider::SliderValueChange)
717  {
718  redrawMarks();
719  }
720  else if (change == QAbstractSlider::SliderRangeChange)
721  {
722  marksChanged();
723  }
724 
725  if (m_leftMouseDown || m_middleMouseDown) {
726  const int fromLine = m_viewInternal->toRealCursor(m_viewInternal->startPos()).line() + 1;
727  const int lastLine = m_viewInternal->toRealCursor(m_viewInternal->endPos()).line() + 1;
728  QToolTip::showText(m_toolTipPos, i18nc("from line - to line", "<center>%1<br/>&#x2014;<br/>%2</center>", fromLine, lastLine), this);
729  }
730 }
731 
732 void KateScrollBar::marksChanged()
733 {
734  m_lines.clear();
735  update();
736 }
737 
738 void KateScrollBar::redrawMarks()
739 {
740  if (!m_showMarks) return;
741  update();
742 }
743 
744 void KateScrollBar::recomputeMarksPositions()
745 {
746  // get the style options to compute the scrollbar pixels
747  QStyleOptionSlider opt;
748  initStyleOption(&opt);
749  QRect grooveRect = style()->subControlRect(QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarGroove, this);
750 
751  // cache top margin and groove height
752  const int top = grooveRect.top();
753  const int h = grooveRect.height() - 1;
754 
755  // make sure we have a sane height
756  if (h <= 0) return;
757 
758  // get total visible (=without folded) lines in the document
759  int visibleLines = m_view->textFolding().visibleLines() - 1;
760  if (m_view->config()->scrollPastEnd()) {
761  visibleLines += m_viewInternal->linesDisplayed() - 1;
762  visibleLines -= m_view->config()->autoCenterLines();
763  }
764 
765  // now repopulate the scrollbar lines list
766  m_lines.clear();
767  const QHash<int, KTextEditor::Mark*> &marks = m_doc->marks();
768  for (QHash<int, KTextEditor::Mark*>::const_iterator i = marks.constBegin(); i != marks.constEnd(); ++i)
769  {
770  KTextEditor::Mark *mark = i.value();
771  const int line = m_view->textFolding().lineToVisibleLine(mark->line);
772  const double ratio = static_cast<double>(line) / visibleLines;
773  m_lines.insert(top + (int)(h * ratio),
774  KateRendererConfig::global()->lineMarkerColor((KTextEditor::MarkInterface::MarkTypes)mark->type));
775  }
776 }
777 
778 void KateScrollBar::sliderMaybeMoved(int value)
779 {
780  if (m_middleMouseDown) {
781  // we only need to emit this signal once, as for the following slider
782  // movements the signal sliderMoved() is already emitted.
783  // Thus, set m_middleMouseDown to false right away.
784  m_middleMouseDown = false;
785  emit sliderMMBMoved(value);
786  }
787 }
788 //END
789 
790 
791 //BEGIN KateCmdLineEditFlagCompletion
796 class KateCmdLineEditFlagCompletion : public KCompletion
797 {
798  public:
799  KateCmdLineEditFlagCompletion() {;}
800 
801  QString makeCompletion( const QString & /*s*/ )
802  {
803  return QString();
804  }
805 
806 };
807 //END KateCmdLineEditFlagCompletion
808 
809 //BEGIN KateCmdLineEdit
810 KateCommandLineBar::KateCommandLineBar (KateView *view, QWidget *parent)
811  : KateViewBarWidget (true, parent)
812 {
813  QHBoxLayout *topLayout = new QHBoxLayout ();
814  centralWidget()->setLayout(topLayout);
815  topLayout->setMargin(0);
816  m_lineEdit = new KateCmdLineEdit (this, view);
817  connect(m_lineEdit, SIGNAL(hideRequested()), SIGNAL(hideMe()));
818  topLayout->addWidget (m_lineEdit);
819 
820  QToolButton *helpButton = new QToolButton(this);
821  helpButton->setAutoRaise(true);
822  helpButton->setIcon(KIcon(KIcon ("help-contextual")));
823  topLayout->addWidget(helpButton);
824  connect (helpButton,SIGNAL(clicked()),this,SLOT(showHelpPage()));
825 
826  setFocusProxy (m_lineEdit);
827 }
828 
829 void KateCommandLineBar::showHelpPage() {
830  KToolInvocation::invokeHelp("advanced-editing-tools-commandline","kate");
831 }
832 
833 KateCommandLineBar::~KateCommandLineBar()
834 {
835 }
836 
837 // inserts the given string in the command line edit and (if selected = true) selects it so the user
838 // can type over it if they want to
839 void KateCommandLineBar::setText(const QString &text, bool selected)
840 {
841  m_lineEdit->setText(text);
842  if (selected) {
843  m_lineEdit->selectAll();
844  }
845 }
846 
847 void KateCommandLineBar::execute(const QString &text)
848 {
849  m_lineEdit->slotReturnPressed(text);
850 }
851 
852 KateCmdLineEdit::KateCmdLineEdit (KateCommandLineBar *bar, KateView *view)
853  : KLineEdit ()
854  , m_view (view)
855  , m_bar (bar)
856  , m_msgMode (false)
857  , m_histpos( 0 )
858  , m_cmdend( 0 )
859  , m_command( 0L )
860 {
861  connect (this, SIGNAL(returnPressed(QString)),
862  this, SLOT(slotReturnPressed(QString)));
863 
864  setCompletionObject(KateCmd::self()->commandCompletionObject());
865  setAutoDeleteCompletionObject( false );
866 
867  m_hideTimer = new QTimer(this);
868  m_hideTimer->setSingleShot(true);
869  connect(m_hideTimer, SIGNAL(timeout()), this, SLOT(hideLineEdit()));
870 
871  // make sure the timer is stopped when the user switches views. if not, focus will be given to the
872  // wrong view when KateViewBar::hideCurrentBarWidget() is called after 4 seconds. (the timer is
873  // used for showing things like "Success" for four seconds after the user has used the kate
874  // command line)
875  connect(m_view, SIGNAL(focusOut(KTextEditor::View*)), m_hideTimer, SLOT(stop()));
876 }
877 
878 void KateCmdLineEdit::hideEvent(QHideEvent *e)
879 {
880  Q_UNUSED(e);
881 }
882 
883 
884 QString KateCmdLineEdit::helptext( const QPoint & ) const
885 {
886  QString beg = "<qt background=\"white\"><div><table width=\"100%\"><tr><td bgcolor=\"brown\"><font color=\"white\"><b>Help: <big>";
887  QString mid = "</big></b></font></td></tr><tr><td>";
888  QString end = "</td></tr></table></div><qt>";
889 
890  QString t = text();
891  QRegExp re( "\\s*help\\s+(.*)" );
892  if ( re.indexIn( t ) > -1 )
893  {
894  QString s;
895  // get help for command
896  QString name = re.cap( 1 );
897  if ( name == "list" )
898  {
899  return beg + i18n("Available Commands") + mid
900  + KateCmd::self()->commandList().join(" ")
901  + i18n("<p>For help on individual commands, do <code>'help &lt;command&gt;'</code></p>")
902  + end;
903  }
904  else if ( ! name.isEmpty() )
905  {
906  KTextEditor::Command *cmd = KateCmd::self()->queryCommand( name );
907  if ( cmd )
908  {
909  if ( cmd->help( m_view, name, s ) )
910  return beg + name + mid + s + end;
911  else
912  return beg + name + mid + i18n("No help for '%1'", name ) + end;
913  }
914  else
915  return beg + mid + i18n("No such command <b>%1</b>", name) + end;
916  }
917  }
918 
919  return beg + mid + i18n(
920  "<p>This is the Katepart <b>command line</b>.<br />"
921  "Syntax: <code><b>command [ arguments ]</b></code><br />"
922  "For a list of available commands, enter <code><b>help list</b></code><br />"
923  "For help for individual commands, enter <code><b>help &lt;command&gt;</b></code></p>")
924  + end;
925 }
926 
927 
928 
929 bool KateCmdLineEdit::event(QEvent *e) {
930  if (e->type() == QEvent::QueryWhatsThis) {
931  setWhatsThis(helptext(QPoint()));
932  e->accept();
933  return true;
934  }
935  return KLineEdit::event(e);
936 }
937 
938 
964 void KateCmdLineEdit::slotReturnPressed ( const QString& text )
965 {
966  if (text.isEmpty()) return;
967  // silently ignore leading space characters and colon characters (for vi-heads)
968  uint n = 0;
969  const uint textlen=text.length();
970  while( (n<textlen) && ( text[n].isSpace() || text[n] == ':' ) )
971  n++;
972 
973  if (n>=textlen) return;
974 
975  QString cmd = text.mid( n );
976 
977  // Parse any leading range expression, and strip it (and maybe do some other transforms on the command).
978  QString leadingRangeExpression;
979  KTextEditor::Range range = CommandRangeExpressionParser::parseRangeExpression(cmd, m_view, leadingRangeExpression, cmd);
980 
981  // Built in help: if the command starts with "help", [try to] show some help
982  if ( cmd.startsWith( QLatin1String("help") ) )
983  {
984  QWhatsThis::showText(mapToGlobal(QPoint(0,0)), helptext( QPoint() ) );
985  clear();
986  KateCmd::self()->appendHistory( cmd );
987  m_histpos = KateCmd::self()->historyLength();
988  m_oldText.clear();
989  return;
990  }
991 
992  if (cmd.length () > 0)
993  {
994  KTextEditor::Command *p = KateCmd::self()->queryCommand (cmd);
995  KTextEditor::RangeCommand *ce = dynamic_cast<KTextEditor::RangeCommand*>(p);
996 
997  m_oldText = leadingRangeExpression + cmd;
998  m_msgMode = true;
999 
1000  // the following commands changes the focus themselves, so bar should be hidden before execution.
1001  if (QRegExp("buffer|b|new|vnew|bp|bprev|bn|bnext|bf|bfirst|bl|blast|edit|e").exactMatch(cmd.split(" ").at(0))) {
1002  emit hideRequested();
1003  }
1004 
1005  // we got a range and a valid command, but the command does not inherit the RangeCommand
1006  // extension. bail out.
1007  if ( ( !ce && range.isValid() && p ) || ( range.isValid() && ce && !ce->supportsRange(cmd) ) ) {
1008  setText (i18n ("Error: No range allowed for command \"%1\".", cmd));
1009  } else {
1010 
1011  if (p)
1012  {
1013  QString msg;
1014 
1015  if ((ce && range.isValid() && ce->exec(m_view, cmd, msg, range)) ||
1016  (p->exec(m_view, cmd, msg)))
1017  {
1018 
1019  // append command along with range (will be empty if none given) to history
1020  KateCmd::self()->appendHistory( leadingRangeExpression + cmd );
1021  m_histpos = KateCmd::self()->historyLength();
1022  m_oldText.clear();
1023 
1024  if (msg.length() > 0) {
1025  setText (i18n ("Success: ") + msg);
1026  } else if (isVisible()) {
1027  // always hide on success without message
1028  emit hideRequested();
1029  }
1030  }
1031  else
1032  {
1033  if (msg.length() > 0) {
1034  if (msg.contains('\n')) {
1035  // multiline error, use widget with more space
1036  QWhatsThis::showText(mapToGlobal(QPoint(0,0)), msg);
1037  } else {
1038  setText(msg);
1039  }
1040  } else {
1041  setText (i18n ("Command \"%1\" failed.", cmd));
1042  }
1043  KNotification::beep();
1044  }
1045  }
1046  else
1047  {
1048  setText (i18n ("No such command: \"%1\"", cmd));
1049  KNotification::beep();
1050  }
1051  }
1052  }
1053 
1054  // clean up
1055  if (completionObject() != KateCmd::self()->commandCompletionObject())
1056  {
1057  KCompletion *c = completionObject();
1058  setCompletionObject(KateCmd::self()->commandCompletionObject());
1059  delete c;
1060  }
1061  m_command = 0;
1062  m_cmdend = 0;
1063 
1064  // the following commands change the focus themselves
1065  if (!QRegExp("buffer|b|new|vnew|bp|bprev|bn|bnext|bf|bfirst|bl|blast|edit|e").exactMatch(cmd.split(" ").at(0))) {
1066  m_view->setFocus ();
1067  }
1068 
1069  if (isVisible()) {
1070  m_hideTimer->start(4000);
1071  }
1072 
1073  if (m_view->viInputMode()) {
1074  m_view->getViInputModeManager()->reset();
1075  }
1076 }
1077 
1078 void KateCmdLineEdit::hideLineEdit () // unless i have focus ;)
1079 {
1080  if ( ! hasFocus() ) {
1081  emit hideRequested();
1082  }
1083 }
1084 
1085 void KateCmdLineEdit::focusInEvent ( QFocusEvent *ev )
1086 {
1087  if (m_msgMode)
1088  {
1089  m_msgMode = false;
1090  setText (m_oldText);
1091  selectAll();
1092  }
1093 
1094  KLineEdit::focusInEvent (ev);
1095 }
1096 
1097 void KateCmdLineEdit::keyPressEvent( QKeyEvent *ev )
1098 {
1099  if (ev->key() == Qt::Key_Escape ||
1100  (ev->key() == Qt::Key_BracketLeft && ev->modifiers() == Qt::ControlModifier))
1101  {
1102  m_view->setFocus ();
1103  hideLineEdit();
1104  if (m_view->viInputMode()) {
1105  m_view->getViInputModeManager()->reset();
1106  }
1107  clear();
1108  }
1109  else if ( ev->key() == Qt::Key_Up )
1110  fromHistory( true );
1111  else if ( ev->key() == Qt::Key_Down )
1112  fromHistory( false );
1113 
1114  uint cursorpos = cursorPosition();
1115  KLineEdit::keyPressEvent (ev);
1116 
1117  // during typing, let us see if we have a valid command
1118  if ( ! m_cmdend || cursorpos <= m_cmdend )
1119  {
1120  QChar c;
1121  if ( ! ev->text().isEmpty() )
1122  c = ev->text()[0];
1123 
1124  if ( ! m_cmdend && ! c.isNull() ) // we have no command, so lets see if we got one
1125  {
1126  if ( ! c.isLetterOrNumber() && c != '-' && c != '_' )
1127  {
1128  m_command = KateCmd::self()->queryCommand( text().trimmed() );
1129  if ( m_command )
1130  {
1131  //kDebug(13025)<<"keypress in commandline: We have a command! "<<m_command<<". text is '"<<text()<<"'";
1132  // if the typed character is ":",
1133  // we try if the command has flag completions
1134  m_cmdend = cursorpos;
1135  //kDebug(13025)<<"keypress in commandline: Set m_cmdend to "<<m_cmdend;
1136  }
1137  else
1138  m_cmdend = 0;
1139  }
1140  }
1141  else // since cursor is inside the command name, we reconsider it
1142  {
1143  kDebug(13025)<<"keypress in commandline: \\W -- text is "<<text();
1144  m_command = KateCmd::self()->queryCommand( text().trimmed() );
1145  if ( m_command )
1146  {
1147  //kDebug(13025)<<"keypress in commandline: We have a command! "<<m_command;
1148  QString t = text();
1149  m_cmdend = 0;
1150  bool b = false;
1151  for ( ; (int)m_cmdend < t.length(); m_cmdend++ )
1152  {
1153  if ( t[m_cmdend].isLetter() )
1154  b = true;
1155  if ( b && ( ! t[m_cmdend].isLetterOrNumber() && t[m_cmdend] != '-' && t[m_cmdend] != '_' ) )
1156  break;
1157  }
1158 
1159  if ( c == ':' && cursorpos == m_cmdend )
1160  {
1161  // check if this command wants to complete flags
1162  //kDebug(13025)<<"keypress in commandline: Checking if flag completion is desired!";
1163  }
1164  }
1165  else
1166  {
1167  // clean up if needed
1168  if (completionObject() != KateCmd::self()->commandCompletionObject())
1169  {
1170  KCompletion *c = completionObject();
1171  setCompletionObject(KateCmd::self()->commandCompletionObject());
1172  delete c;
1173  }
1174 
1175  m_cmdend = 0;
1176  }
1177  }
1178 
1179  // if we got a command, check if it wants to do something.
1180  if ( m_command )
1181  {
1182  //kDebug(13025)<<"Checking for CommandExtension..";
1183  KTextEditor::CommandExtension *ce = dynamic_cast<KTextEditor::CommandExtension*>(m_command);
1184  if ( ce )
1185  {
1186  KCompletion *cmpl = ce->completionObject( m_view, text().left( m_cmdend ).trimmed() );
1187  if ( cmpl )
1188  {
1189  // We need to prepend the current command name + flag string
1190  // when completion is done
1191  //kDebug(13025)<<"keypress in commandline: Setting completion object!";
1192 
1193  setCompletionObject( cmpl );
1194  }
1195  }
1196  }
1197  }
1198  else if ( m_command )// check if we should call the commands processText()
1199  {
1200  KTextEditor::CommandExtension *ce = dynamic_cast<KTextEditor::CommandExtension*>( m_command );
1201  if ( ce && ce->wantsToProcessText( text().left( m_cmdend ).trimmed() )
1202  && ! ( ev->text().isNull() || ev->text().isEmpty() ) )
1203  ce->processText( m_view, text() );
1204  }
1205 }
1206 
1207 void KateCmdLineEdit::fromHistory( bool up )
1208 {
1209  if ( ! KateCmd::self()->historyLength() )
1210  return;
1211 
1212  QString s;
1213 
1214  if ( up )
1215  {
1216  if ( m_histpos > 0 )
1217  {
1218  m_histpos--;
1219  s = KateCmd::self()->fromHistory( m_histpos );
1220  }
1221  }
1222  else
1223  {
1224  if ( m_histpos < ( KateCmd::self()->historyLength() - 1 ) )
1225  {
1226  m_histpos++;
1227  s = KateCmd::self()->fromHistory( m_histpos );
1228  }
1229  else
1230  {
1231  m_histpos = KateCmd::self()->historyLength();
1232  setText( m_oldText );
1233  }
1234  }
1235  if ( ! s.isEmpty() )
1236  {
1237  // Select the argument part of the command, so that it is easy to overwrite
1238  setText( s );
1239  static QRegExp reCmd = QRegExp(".*[\\w\\-]+(?:[^a-zA-Z0-9_-]|:\\w+)(.*)");
1240  if ( reCmd.indexIn( text() ) == 0 )
1241  setSelection( text().length() - reCmd.cap(1).length(), reCmd.cap(1).length() );
1242  }
1243 }
1244 //END KateCmdLineEdit
1245 
1246 //BEGIN KateIconBorder
1247 using namespace KTextEditor;
1248 
1249 const int halfIPW = 8;
1250 
1251 KateIconBorder::KateIconBorder ( KateViewInternal* internalView, QWidget *parent )
1252  : QWidget(parent)
1253  , m_view( internalView->m_view )
1254  , m_doc( internalView->doc() )
1255  , m_viewInternal( internalView )
1256  , m_iconBorderOn( false )
1257  , m_lineNumbersOn( false )
1258  , m_foldingMarkersOn( false )
1259  , m_dynWrapIndicatorsOn( false )
1260  , m_annotationBorderOn( false )
1261  , m_dynWrapIndicators( 0 )
1262  , m_cachedLNWidth( 0 )
1263  , m_maxCharWidth( 0.0 )
1264  , iconPaneWidth (16)
1265  , m_annotationBorderWidth (6)
1266  , m_foldingRange(0)
1267  , m_nextHighlightBlock(-2)
1268  , m_currentBlockLine(-1)
1269 {
1270  setAttribute( Qt::WA_StaticContents );
1271  setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum );
1272  setMouseTracking(true);
1273  m_doc->setMarkDescription( MarkInterface::markType01, i18n("Bookmark") );
1274  m_doc->setMarkPixmap( MarkInterface::markType01, KIcon("bookmarks").pixmap(16, 16) );
1275 
1276  updateFont();
1277 
1278  m_delayFoldingHlTimer.setSingleShot(true);
1279  m_delayFoldingHlTimer.setInterval(150);
1280  connect(&m_delayFoldingHlTimer, SIGNAL(timeout()), this, SLOT(showBlock()));
1281 }
1282 
1283 KateIconBorder::~KateIconBorder()
1284 {
1285  delete m_foldingRange;
1286  m_foldingRange = 0;
1287 }
1288 
1289 void KateIconBorder::setIconBorderOn( bool enable )
1290 {
1291  if( enable == m_iconBorderOn )
1292  return;
1293 
1294  m_iconBorderOn = enable;
1295 
1296  updateGeometry();
1297 
1298  QTimer::singleShot( 0, this, SLOT(update()) );
1299 }
1300 
1301 void KateIconBorder::setAnnotationBorderOn( bool enable )
1302 {
1303  if( enable == m_annotationBorderOn )
1304  return;
1305 
1306  m_annotationBorderOn = enable;
1307 
1308  emit m_view->annotationBorderVisibilityChanged(m_view, enable);
1309 
1310  updateGeometry();
1311 
1312  QTimer::singleShot( 0, this, SLOT(update()) );
1313 }
1314 
1315 void KateIconBorder::removeAnnotationHovering()
1316 {
1317  // remove hovering if it's still there
1318  if (m_annotationBorderOn && !m_hoveredAnnotationText.isEmpty())
1319  {
1320  m_hoveredAnnotationText.clear();
1321  hideAnnotationTooltip();
1322  QTimer::singleShot( 0, this, SLOT(update()) );
1323  }
1324 }
1325 
1326 void KateIconBorder::setLineNumbersOn( bool enable )
1327 {
1328  if( enable == m_lineNumbersOn )
1329  return;
1330 
1331  m_lineNumbersOn = enable;
1332  m_dynWrapIndicatorsOn = (m_dynWrapIndicators == 1) ? enable : m_dynWrapIndicators;
1333 
1334  updateGeometry();
1335 
1336  QTimer::singleShot( 0, this, SLOT(update()) );
1337 }
1338 
1339 void KateIconBorder::setDynWrapIndicators( int state )
1340 {
1341  if (state == m_dynWrapIndicators )
1342  return;
1343 
1344  m_dynWrapIndicators = state;
1345  m_dynWrapIndicatorsOn = (state == 1) ? m_lineNumbersOn : state;
1346 
1347  updateGeometry ();
1348 
1349  QTimer::singleShot( 0, this, SLOT(update()) );
1350 }
1351 
1352 void KateIconBorder::setFoldingMarkersOn( bool enable )
1353 {
1354  if( enable == m_foldingMarkersOn )
1355  return;
1356 
1357  m_foldingMarkersOn = enable;
1358 
1359  updateGeometry();
1360 
1361  QTimer::singleShot( 0, this, SLOT(update()) );
1362 }
1363 
1364 QSize KateIconBorder::sizeHint() const
1365 {
1366  int w = 0;
1367 
1368  if (m_iconBorderOn)
1369  w += iconPaneWidth + 2;
1370 
1371  if (m_annotationBorderOn)
1372  {
1373  w += m_annotationBorderWidth + 2;
1374  }
1375 
1376  if (m_lineNumbersOn || (m_view->dynWordWrap() && m_dynWrapIndicatorsOn)) {
1377  w += lineNumberWidth() + 2;
1378  }
1379 
1380  if (m_foldingMarkersOn)
1381  w += iconPaneWidth;
1382 
1383  // space for the line modification system border
1384  if (m_view->config()->lineModification()) {
1385  w += 3;
1386  }
1387 
1388  // two pixel space
1389  w += 2;
1390 
1391  return QSize( w, 0 );
1392 }
1393 
1394 // This function (re)calculates the maximum width of any of the digit characters (0 -> 9)
1395 // for graceful handling of variable-width fonts as the linenumber font.
1396 void KateIconBorder::updateFont()
1397 {
1398  const QFontMetricsF &fm = m_view->renderer()->config()->fontMetrics();
1399  m_maxCharWidth = 0.0;
1400  // Loop to determine the widest numeric character in the current font.
1401  // 48 is ascii '0'
1402  for (int i = 48; i < 58; i++) {
1403  const qreal charWidth = ceil(fm.width( QChar(i) ));
1404  m_maxCharWidth = qMax(m_maxCharWidth, charWidth);
1405  }
1406 
1407  // the icon pane scales with the font...
1408  iconPaneWidth = fm.height();
1409 
1410  updateGeometry();
1411 
1412  QTimer::singleShot( 0, this, SLOT(update()) );
1413 }
1414 
1415 int KateIconBorder::lineNumberWidth() const
1416 {
1417  // width = (number of digits + 1) * char width
1418  const int digits = (int) ceil(log10((double)(m_view->doc()->lines() + 1)));
1419  int width = m_lineNumbersOn ? (int)ceil((digits + 1) * m_maxCharWidth) : 0;
1420 
1421  if (m_view->dynWordWrap() && m_dynWrapIndicatorsOn) {
1422  // HACK: 16 == style().scrollBarExtent().width()
1423  width = qMax(16 + 4, width);
1424 
1425  if (m_cachedLNWidth != width || m_oldBackgroundColor != m_view->renderer()->config()->iconBarColor()) {
1426  int w = 16;// HACK: 16 == style().scrollBarExtent().width() style().scrollBarExtent().width();
1427  int h = m_view->renderer()->lineHeight();
1428 
1429  QSize newSize(w, h);
1430  if ((m_arrow.size() != newSize || m_oldBackgroundColor != m_view->renderer()->config()->iconBarColor()) && !newSize.isEmpty()) {
1431  m_arrow = QPixmap(newSize);
1432 
1433  QPainter p(&m_arrow);
1434  p.fillRect( 0, 0, w, h, m_view->renderer()->config()->iconBarColor() );
1435 
1436  h = m_view->renderer()->config()->fontMetrics().ascent();
1437 
1438  p.setPen(m_view->renderer()->config()->lineNumberColor());
1439 
1440  QPainterPath path;
1441  path.moveTo(w/2, h/2);
1442  path.lineTo(w/2, 0);
1443  path.lineTo(w/4, h/4);
1444  path.lineTo(0, 0);
1445  path.lineTo(0, h/2);
1446  path.lineTo(w/2, h-1);
1447  path.lineTo(w*3/4, h-1);
1448  path.lineTo(w-1, h*3/4);
1449  path.lineTo(w*3/4, h/2);
1450  path.lineTo(0, h/2);
1451  p.drawPath(path);
1452  }
1453  }
1454  }
1455 
1456  return width;
1457 }
1458 
1459 void KateIconBorder::paintEvent(QPaintEvent* e)
1460 {
1461  paintBorder(e->rect().x(), e->rect().y(), e->rect().width(), e->rect().height());
1462 }
1463 
1464 static void paintTriangle (QPainter &painter, QColor c, int xOffset, int yOffset, int width, int height, bool open)
1465 {
1466  painter.setRenderHint(QPainter::Antialiasing);
1467 
1468  qreal size = qMin (width, height);
1469 
1470  if ( KColorUtils::luma( c ) > 0.25 )
1471  c = KColorUtils::darken( c );
1472  else
1473  c = KColorUtils::shade( c, 0.1 );
1474 
1475  QPen pen;
1476  pen.setJoinStyle (Qt::RoundJoin);
1477  pen.setColor (c);
1478  pen.setWidthF (1.5);
1479  painter.setPen ( pen );
1480 
1481  painter.setBrush (c);
1482 
1483  // let some border, if possible
1484  size *= 0.6;
1485 
1486  qreal halfSize = size / 2;
1487  qreal halfSizeP = halfSize * 0.6;
1488  QPointF middle (xOffset + (qreal)width / 2, yOffset + (qreal)height / 2);
1489 
1490  if (open)
1491  {
1492  QPointF points[3] = { middle+QPointF(-halfSize, -halfSizeP), middle+QPointF(halfSize, -halfSizeP), middle+QPointF(0, halfSizeP) };
1493  painter.drawConvexPolygon(points, 3);
1494  }
1495  else
1496  {
1497  QPointF points[3] = { middle+QPointF(-halfSizeP, -halfSize), middle+QPointF(-halfSizeP, halfSize), middle+QPointF(halfSizeP, 0) };
1498  painter.drawConvexPolygon(points, 3);
1499  }
1500 
1501  painter.setRenderHint(QPainter::Antialiasing, false);
1502 }
1503 
1504 void KateIconBorder::paintBorder (int /*x*/, int y, int /*width*/, int height)
1505 {
1506  uint h = m_view->renderer()->lineHeight();
1507  uint startz = (y / h);
1508  uint endz = startz + 1 + (height / h);
1509  uint lineRangesSize = m_viewInternal->cache()->viewCacheLineCount();
1510 
1511  // center the folding boxes
1512  int m_px = (h - 11) / 2;
1513  if (m_px < 0)
1514  m_px = 0;
1515 
1516  int lnWidth( 0 );
1517  if ( m_lineNumbersOn || (m_view->dynWordWrap() && m_dynWrapIndicatorsOn) ) // avoid calculating unless needed ;-)
1518  {
1519  lnWidth = lineNumberWidth();
1520  if ( lnWidth != m_cachedLNWidth || m_oldBackgroundColor != m_view->renderer()->config()->iconBarColor() )
1521  {
1522  // we went from n0 ->n9 lines or vice verca
1523  // this causes an extra updateGeometry() first time the line numbers
1524  // are displayed, but sizeHint() is supposed to be const so we can't set
1525  // the cached value there.
1526  m_cachedLNWidth = lnWidth;
1527  m_oldBackgroundColor = m_view->renderer()->config()->iconBarColor();
1528  updateGeometry();
1529  update ();
1530  return;
1531  }
1532  }
1533 
1534  int w( this->width() ); // sane value/calc only once
1535 
1536  QPainter p ( this );
1537  p.setRenderHints (QPainter::TextAntialiasing);
1538  p.setFont ( m_view->renderer()->config()->font() ); // for line numbers
1539 
1540  KTextEditor::AnnotationModel *model = m_view->annotationModel() ?
1541  m_view->annotationModel() : m_doc->annotationModel();
1542 
1543  for (uint z=startz; z <= endz; z++)
1544  {
1545  int y = h * z;
1546  int realLine = -1;
1547 
1548  if (z < lineRangesSize)
1549  realLine = m_viewInternal->cache()->viewLine(z).line();
1550 
1551  int lnX = 0;
1552 
1553  p.fillRect( 0, y, w-5, h, m_view->renderer()->config()->iconBarColor() );
1554  p.fillRect( w-5, y, 5, h, m_view->renderer()->config()->backgroundColor() );
1555 
1556  // icon pane
1557  if( m_iconBorderOn )
1558  {
1559  p.setPen ( m_view->renderer()->config()->separatorColor() );
1560  p.setBrush ( m_view->renderer()->config()->separatorColor() );
1561  p.drawLine(lnX+iconPaneWidth+1, y, lnX+iconPaneWidth+1, y+h);
1562 
1563  if( (realLine > -1) && (m_viewInternal->cache()->viewLine(z).startCol() == 0) )
1564  {
1565  uint mrk ( m_doc->mark( realLine ) ); // call only once
1566 
1567  if ( mrk )
1568  {
1569  for( uint bit = 0; bit < 32; bit++ )
1570  {
1571  MarkInterface::MarkTypes markType = (MarkInterface::MarkTypes)(1<<bit);
1572  if( mrk & markType )
1573  {
1574  QPixmap px_mark (m_doc->markPixmap( markType ));
1575 
1576  if (!px_mark.isNull() && h > 0 && iconPaneWidth > 0)
1577  {
1578  if (iconPaneWidth < px_mark.width() || h < (uint)px_mark.height())
1579  px_mark = px_mark.scaled (iconPaneWidth, h, Qt::KeepAspectRatio);
1580 
1581  // center the mark pixmap
1582  int x_px = (iconPaneWidth - px_mark.width()) / 2;
1583  if (x_px < 0)
1584  x_px = 0;
1585 
1586  int y_px = (h - px_mark.height()) / 2;
1587  if (y_px < 0)
1588  y_px = 0;
1589 
1590  p.drawPixmap( lnX+x_px, y+y_px, px_mark);
1591  }
1592  }
1593  }
1594  }
1595  }
1596 
1597  lnX += iconPaneWidth + 2;
1598  }
1599 
1600  // annotation information
1601  if( m_annotationBorderOn )
1602  {
1603  // Draw a border line between annotations and the line numbers
1604  p.setPen ( m_view->renderer()->config()->lineNumberColor() );
1605  p.setBrush ( m_view->renderer()->config()->lineNumberColor() );
1606 
1607  int borderWidth = m_annotationBorderWidth;
1608  p.drawLine(lnX+borderWidth+1, y, lnX+borderWidth+1, y+h);
1609 
1610  if( (realLine > -1) && model )
1611  {
1612  // Fetch data from the model
1613  QVariant text = model->data( realLine, Qt::DisplayRole );
1614  QVariant foreground = model->data( realLine, Qt::ForegroundRole );
1615  QVariant background = model->data( realLine, Qt::BackgroundRole );
1616  // Fill the background
1617  if( background.isValid() )
1618  {
1619  p.fillRect( lnX, y, borderWidth + 1, h, background.value<QBrush>() );
1620  }
1621  // Set the pen for drawing the foreground
1622  if( foreground.isValid() )
1623  {
1624  p.setBrush( foreground.value<QBrush>() );
1625  }
1626 
1627  // Draw a border around all adjacent entries that have the same text as the currently hovered one
1628  if( m_hoveredAnnotationText == text.toString() )
1629  {
1630  p.drawLine( lnX, y, lnX, y+h );
1631  p.drawLine( lnX+borderWidth, y, lnX+borderWidth, y+h );
1632 
1633  QVariant beforeText = model->data( realLine-1, Qt::DisplayRole );
1634  QVariant afterText = model->data( realLine+1, Qt::DisplayRole );
1635  if( ((beforeText.isValid() && beforeText.canConvert<QString>()
1636  && text.isValid() && text.canConvert<QString>()
1637  && beforeText.toString() != text.toString()) || realLine == 0)
1638  && m_viewInternal->cache()->viewLine(z).viewLine() == 0)
1639  {
1640  p.drawLine( lnX+1, y, lnX+borderWidth, y );
1641  }
1642 
1643  if( ((afterText.isValid() && afterText.canConvert<QString>()
1644  && text.isValid() && text.canConvert<QString>()
1645  && afterText.toString() != text.toString())
1646  || realLine == m_view->doc()->lines() - 1)
1647  && m_viewInternal->cache()->viewLine(z).viewLine() == m_viewInternal->cache()->viewLineCount(realLine)-1)
1648  {
1649  p.drawLine( lnX+1, y+h-1, lnX+borderWidth, y+h-1 );
1650  }
1651  }
1652  if( foreground.isValid() )
1653  {
1654  QPen pen = p.pen();
1655  pen.setWidth( 1 );
1656  p.setPen( pen );
1657  }
1658 
1659  // Now draw the normal text
1660  if( text.isValid() && text.canConvert<QString>() && (m_viewInternal->cache()->viewLine(z).startCol() == 0) )
1661  {
1662  p.drawText( lnX+3, y, borderWidth-3, h, Qt::AlignLeft|Qt::AlignVCenter, text.toString() );
1663  }
1664  }
1665 
1666  // adjust current X position and reset the pen and brush
1667  lnX += borderWidth + 2;
1668  }
1669 
1670  // line number
1671  if( m_lineNumbersOn || (m_view->dynWordWrap() && m_dynWrapIndicatorsOn) )
1672  {
1673  p.setPen ( m_view->renderer()->config()->lineNumberColor() );
1674  p.setBrush ( m_view->renderer()->config()->lineNumberColor() );
1675 
1676  if (realLine > -1) {
1677  if (m_viewInternal->cache()->viewLine(z).startCol() == 0) {
1678  if (m_lineNumbersOn) {
1679  p.drawText( lnX + m_maxCharWidth / 2, y, lnWidth - m_maxCharWidth, h,
1680  Qt::TextDontClip|Qt::AlignRight|Qt::AlignVCenter, QString("%1").arg( realLine + 1 ) );
1681  }
1682  } else if (m_view->dynWordWrap() && m_dynWrapIndicatorsOn) {
1683  p.drawPixmap(lnX + lnWidth - m_arrow.width() - 2, y, m_arrow);
1684  }
1685  }
1686 
1687  lnX += lnWidth + 2;
1688  }
1689 
1690  // folding markers
1691  if( m_foldingMarkersOn)
1692  {
1693  // first icon border background
1694  p.fillRect(lnX, y, iconPaneWidth, h, m_view->renderer()->config()->iconBarColor());
1695 
1696  // possible additional folding highlighting
1697  if ((realLine >= 0) && m_foldingRange && m_foldingRange->overlapsLine (realLine)) {
1698  p.save();
1699 
1700  // use linear gradient as brush
1701  QLinearGradient g(lnX, y, lnX + iconPaneWidth, y);
1702  const QColor foldingColor(m_view->renderer()->config()->foldingColor());
1703  g.setColorAt(0, foldingColor);
1704  g.setColorAt(0.3, foldingColor.lighter(110));
1705  g.setColorAt(1, foldingColor);
1706  p.setBrush(g);
1707  p.setPen(foldingColor);
1708 
1709  p.setClipRect(lnX, y, iconPaneWidth, h);
1710  p.setRenderHint(QPainter::Antialiasing);
1711 
1712  const qreal r = 4.0;
1713  if (m_foldingRange->start().line() == realLine &&
1714  m_viewInternal->cache()->viewLine(z).viewLine() == 0)
1715  {
1716  p.drawRect(lnX, y, iconPaneWidth, h + r);
1717  } else if (m_foldingRange->end().line() == realLine &&
1718  m_viewInternal->cache()->viewLine(z).viewLine() == m_viewInternal->cache()->viewLineCount(realLine)-1)
1719  {
1720  p.drawRect(lnX, y-r, iconPaneWidth, h + r);
1721  } else {
1722  p.drawRect(lnX, y-r, iconPaneWidth, h+2*r);
1723  }
1724  p.restore();
1725  }
1726 
1727  if ((realLine >= 0) && (m_viewInternal->cache()->viewLine(z).startCol() == 0))
1728  {
1729  QVector<QPair<qint64, Kate::TextFolding::FoldingRangeFlags> > startingRanges = m_view->textFolding().foldingRangesStartingOnLine (realLine);
1730  bool anyFolded = false;
1731  for (int i = 0; i < startingRanges.size(); ++i)
1732  if (startingRanges[i].second & Kate::TextFolding::Folded)
1733  anyFolded = true;
1734 
1735  Kate::TextLine tl = m_doc->kateTextLine(realLine);
1736 
1737  if (!startingRanges.isEmpty() || tl->markedAsFoldingStart())
1738  {
1739  if (anyFolded)
1740  {
1741  paintTriangle (p, m_view->renderer()->config()->foldingColor(), lnX, y, iconPaneWidth, h, false);
1742  }
1743  else
1744  {
1745  paintTriangle (p, m_view->renderer()->config()->foldingColor(), lnX, y, iconPaneWidth, h, true);
1746  }
1747  }
1748  }
1749 
1750  lnX += iconPaneWidth;
1751  }
1752 
1753  // modified line system
1754  if (m_view->config()->lineModification() &&
1755  realLine > -1 && !m_doc->url().isEmpty())
1756  {
1757  // one pixel space
1758  ++lnX;
1759 
1760  Kate::TextLine tl = m_doc->plainKateTextLine(realLine);
1761  if (tl->markedAsModified()) {
1762  p.fillRect(lnX, y, 3, h, m_view->renderer()->config()->modifiedLineColor());
1763  }
1764  if (tl->markedAsSavedOnDisk()) {
1765  p.fillRect(lnX, y, 3, h, m_view->renderer()->config()->savedLineColor());
1766  }
1767  }
1768  }
1769 }
1770 
1771 KateIconBorder::BorderArea KateIconBorder::positionToArea( const QPoint& p ) const
1772 {
1773  // see KateIconBorder::sizeHint() for pixel spacings
1774  int x = 0;
1775  if( m_iconBorderOn ) {
1776  x += iconPaneWidth;
1777  if( p.x() <= x )
1778  return IconBorder;
1779  x += 2;
1780  }
1781  if( this->m_annotationBorderOn ) {
1782  x += m_annotationBorderWidth;
1783  if( p.x() <= x )
1784  return AnnotationBorder;
1785  x += 2;
1786  }
1787  if( m_lineNumbersOn || m_dynWrapIndicators ) {
1788  x += lineNumberWidth();
1789  if( p.x() <= x )
1790  return LineNumbers;
1791  x += 2;
1792  }
1793  if( m_foldingMarkersOn ) {
1794  x += iconPaneWidth;
1795  if( p.x() <= x )
1796  return FoldingMarkers;
1797  }
1798  if (m_view->config()->lineModification()) {
1799  x += 3 + 2;
1800  if( p.x() <= x )
1801  return ModificationBorder;
1802  }
1803  return None;
1804 }
1805 
1806 void KateIconBorder::mousePressEvent( QMouseEvent* e )
1807 {
1808  const KateTextLayout& t = m_viewInternal->yToKateTextLayout(e->y());
1809  if (t.isValid()) {
1810  m_lastClickedLine = t.line();
1811  if ( positionToArea( e->pos() ) != IconBorder && positionToArea( e->pos() ) != AnnotationBorder )
1812  {
1813  QMouseEvent forward( QEvent::MouseButtonPress,
1814  QPoint( 0, e->y() ), e->button(), e->buttons(),e->modifiers() );
1815  m_viewInternal->mousePressEvent( &forward );
1816  }
1817  return e->accept();
1818  }
1819 
1820  QWidget::mousePressEvent(e);
1821 }
1822 
1823 void KateIconBorder::showDelayedBlock(int line)
1824 {
1825  // save the line over which the mouse hovers
1826  // either we start the timer for delay, or we show the block immediately
1827  // if the moving range already exists
1828  m_nextHighlightBlock = line;
1829  if (!m_foldingRange) {
1830  if (!m_delayFoldingHlTimer.isActive()) {
1831  m_delayFoldingHlTimer.start();
1832  }
1833  } else {
1834  showBlock();
1835  }
1836 }
1837 
1838 void KateIconBorder::showBlock()
1839 {
1840  if (m_nextHighlightBlock == m_currentBlockLine) return;
1841  m_currentBlockLine = m_nextHighlightBlock;
1842 
1847  KTextEditor::Range newRange = KTextEditor::Range::invalid();
1848  for (int line = m_currentBlockLine; line >= qMax(0, m_currentBlockLine-1024); --line) {
1852  KTextEditor::Range foldingRange = m_doc->buffer().computeFoldingRangeForStartLine (line);
1853  if (!foldingRange.isValid())
1854  continue;
1855 
1859  if (foldingRange.overlapsLine (m_currentBlockLine)) {
1860  newRange = foldingRange;
1861  break;
1862  }
1863  }
1864 
1865  if (newRange.isValid() && m_foldingRange && *m_foldingRange == newRange) {
1866  // new range equals the old one, nothing to do.
1867  return;
1868  } else { // the ranges differ, delete the old, if it exists
1869  delete m_foldingRange;
1870  m_foldingRange = 0;
1871  }
1872 
1873  if (newRange.isValid()) {
1874  kDebug(13025) << "new folding hl-range:" << newRange;
1875  m_foldingRange = m_doc->newMovingRange(newRange, KTextEditor::MovingRange::ExpandRight);
1876  KTextEditor::Attribute::Ptr attr(new KTextEditor::Attribute());
1877 
1881  QColor result = m_view->renderer()->config()->foldingColor();
1882  result.setAlphaF (0.5);
1883  attr->setBackground(QBrush( result ));
1884 
1885  m_foldingRange->setView (m_view);
1886  // use z depth defined in moving ranges interface
1887  m_foldingRange->setZDepth (-100.0);
1888  m_foldingRange->setAttribute(attr);
1889  }
1890 
1894  repaint ();
1895 }
1896 
1897 void KateIconBorder::hideBlock()
1898 {
1899  if (m_delayFoldingHlTimer.isActive()) {
1900  m_delayFoldingHlTimer.stop();
1901  }
1902 
1903  m_nextHighlightBlock = -2;
1904  m_currentBlockLine = -1;
1905  delete m_foldingRange;
1906  m_foldingRange = 0;
1907 }
1908 
1909 void KateIconBorder::leaveEvent(QEvent *event)
1910 {
1911  hideBlock();
1912  removeAnnotationHovering();
1913 
1914  QWidget::leaveEvent(event);
1915 }
1916 
1917 void KateIconBorder::mouseMoveEvent( QMouseEvent* e )
1918 {
1919  const KateTextLayout& t = m_viewInternal->yToKateTextLayout(e->y());
1920  if (t.isValid()) {
1921  if ( positionToArea( e->pos() ) == FoldingMarkers) showDelayedBlock(t.line());
1922  else hideBlock();
1923  if ( positionToArea( e->pos() ) == AnnotationBorder )
1924  {
1925  KTextEditor::AnnotationModel *model = m_view->annotationModel() ?
1926  m_view->annotationModel() : m_doc->annotationModel();
1927  if (model)
1928  {
1929  m_hoveredAnnotationText = model->data( t.line(), Qt::DisplayRole ).toString();
1930  showAnnotationTooltip( t.line(), e->globalPos() );
1931  QTimer::singleShot( 0, this, SLOT(update()) );
1932  }
1933  }
1934  else
1935  {
1936  if( positionToArea( e->pos() ) == IconBorder )
1937  m_doc->requestMarkTooltip( t.line(), e->globalPos() );
1938 
1939  m_hoveredAnnotationText.clear();
1940  hideAnnotationTooltip();
1941  QTimer::singleShot( 0, this, SLOT(update()) );
1942  }
1943  if ( positionToArea( e->pos() ) != IconBorder )
1944  {
1945  QPoint p = m_viewInternal->mapFromGlobal( e->globalPos() );
1946  QMouseEvent forward( QEvent::MouseMove, p, e->button(), e->buttons(), e->modifiers() );
1947  m_viewInternal->mouseMoveEvent( &forward );
1948  }
1949  }
1950  else
1951  {
1952  // remove hovering if it's still there
1953  removeAnnotationHovering();
1954  }
1955 
1956  QWidget::mouseMoveEvent(e);
1957 }
1958 
1959 void KateIconBorder::mouseReleaseEvent( QMouseEvent* e )
1960 {
1961  int cursorOnLine = m_viewInternal->yToKateTextLayout(e->y()).line();
1962 
1963  if (cursorOnLine == m_lastClickedLine &&
1964  cursorOnLine <= m_doc->lastLine() )
1965  {
1966  BorderArea area = positionToArea( e->pos() );
1967  if( area == IconBorder) {
1968  if (e->button() == Qt::LeftButton) {
1969  if( !m_doc->handleMarkClick(cursorOnLine) ) {
1970  KateViewConfig *config = m_view->config();
1971  if( m_doc->editableMarks() & config->defaultMarkType() ) {
1972  if( m_doc->mark( cursorOnLine ) & config->defaultMarkType() )
1973  m_doc->removeMark( cursorOnLine, config->defaultMarkType() );
1974  else
1975  m_doc->addMark( cursorOnLine, config->defaultMarkType() );
1976  } else if (config->allowMarkMenu()) {
1977  showMarkMenu( cursorOnLine, QCursor::pos() );
1978  }
1979  }
1980  }
1981  else
1982  if (e->button() == Qt::RightButton) {
1983  showMarkMenu( cursorOnLine, QCursor::pos() );
1984  }
1985  }
1986 
1987  if ( area == FoldingMarkers) {
1988  // ask the folding info for this line, if any folds are around!
1989  QVector<QPair<qint64, Kate::TextFolding::FoldingRangeFlags> > startingRanges = m_view->textFolding().foldingRangesStartingOnLine (cursorOnLine);
1990  bool anyFolded = false;
1991  for (int i = 0; i < startingRanges.size(); ++i)
1992  if (startingRanges[i].second & Kate::TextFolding::Folded)
1993  anyFolded = true;
1994 
1995  // fold or unfold all ranges, remember if any action happened!
1996  bool actionDone = false;
1997  for (int i = 0; i < startingRanges.size(); ++i)
1998  actionDone = (anyFolded ? m_view->textFolding().unfoldRange (startingRanges[i].first) : m_view->textFolding().foldRange (startingRanges[i].first)) || actionDone;
1999 
2000  // if no action done, try to fold it, create non-persistent folded range, if possible!
2001  if (!actionDone) {
2002  // either use the fold for this line or the range that is highlighted ATM if any!
2003  KTextEditor::Range foldingRange = m_view->doc()->buffer().computeFoldingRangeForStartLine (cursorOnLine);
2004  if (!foldingRange.isValid() && m_foldingRange)
2005  foldingRange = m_foldingRange->toRange ();
2006  m_view->textFolding().newFoldingRange (foldingRange, Kate::TextFolding::Folded);
2007  }
2008  }
2009 
2010  if ( area == AnnotationBorder ) {
2011  if( e->button() == Qt::LeftButton && KGlobalSettings::singleClick() ) {
2012  emit m_view->annotationActivated( m_view, cursorOnLine );
2013  } else if ( e->button() == Qt::RightButton ) {
2014  showAnnotationMenu( cursorOnLine, e->globalPos() );
2015  }
2016  }
2017  }
2018 
2019  QMouseEvent forward( QEvent::MouseButtonRelease,
2020  QPoint( 0, e->y() ), e->button(), e->buttons(),e->modifiers() );
2021  m_viewInternal->mouseReleaseEvent( &forward );
2022 }
2023 
2024 void KateIconBorder::mouseDoubleClickEvent( QMouseEvent* e )
2025 {
2026  int cursorOnLine = m_viewInternal->yToKateTextLayout(e->y()).line();
2027 
2028  if (cursorOnLine == m_lastClickedLine &&
2029  cursorOnLine <= m_doc->lastLine() )
2030  {
2031  BorderArea area = positionToArea( e->pos() );
2032  if( area == AnnotationBorder && !KGlobalSettings::singleClick() ) {
2033  emit m_view->annotationActivated( m_view, cursorOnLine );
2034  }
2035  }
2036  QMouseEvent forward( QEvent::MouseButtonDblClick,
2037  QPoint( 0, e->y() ), e->button(), e->buttons(),e->modifiers() );
2038  m_viewInternal->mouseDoubleClickEvent( &forward );
2039 }
2040 
2041 void KateIconBorder::wheelEvent(QWheelEvent *e)
2042 {
2043  QCoreApplication::sendEvent(m_viewInternal, e);
2044 }
2045 
2046 void KateIconBorder::showMarkMenu( uint line, const QPoint& pos )
2047 {
2048  if( m_doc->handleMarkContextMenu( line, pos ) )
2049  return;
2050 
2051  if( !m_view->config()->allowMarkMenu() )
2052  return;
2053 
2054  KMenu markMenu;
2055  KMenu selectDefaultMark;
2056 
2057  QVector<int> vec( 33 );
2058  int i=1;
2059 
2060  for( uint bit = 0; bit < 32; bit++ ) {
2061  MarkInterface::MarkTypes markType = (MarkInterface::MarkTypes)(1<<bit);
2062  if( !(m_doc->editableMarks() & markType) )
2063  continue;
2064 
2065  QAction *mA;
2066  QAction *dMA;
2067  if( !m_doc->markDescription( markType ).isEmpty() ) {
2068  mA=markMenu.addAction( m_doc->markDescription( markType ));
2069  dMA=selectDefaultMark.addAction( m_doc->markDescription( markType ));
2070  } else {
2071  mA=markMenu.addAction( i18n("Mark Type %1", bit + 1 ));
2072  dMA=selectDefaultMark.addAction( i18n("Mark Type %1", bit + 1 ));
2073  }
2074  mA->setData(i);
2075  mA->setCheckable(true);
2076  dMA->setData(i+100);
2077  dMA->setCheckable(true);
2078  if( m_doc->mark( line ) & markType )
2079  mA->setChecked(true );
2080 
2081  if( markType & KateViewConfig::global()->defaultMarkType() )
2082  dMA->setChecked(true );
2083 
2084  vec[i++] = markType;
2085  }
2086 
2087  if( markMenu.actions().count() == 0 )
2088  return;
2089 
2090  if( markMenu.actions().count() > 1 )
2091  markMenu.addAction( i18n("Set Default Mark Type" ))->setMenu(&selectDefaultMark);
2092 
2093  QAction *rA = markMenu.exec( pos );
2094  if( !rA )
2095  return;
2096  int result=rA->data().toInt();
2097  if ( result > 100)
2098  {
2099  KateViewConfig::global()->setDefaultMarkType (vec[result-100]);
2100  // flush config, otherwise it isn't necessarily done
2101  KConfigGroup cg(KGlobal::config(), "Kate View Defaults");
2102  KateViewConfig::global()->writeConfig(cg);
2103  }
2104  else
2105  {
2106  MarkInterface::MarkTypes markType = (MarkInterface::MarkTypes) vec[result];
2107  if( m_doc->mark( line ) & markType ) {
2108  m_doc->removeMark( line, markType );
2109  } else {
2110  m_doc->addMark( line, markType );
2111  }
2112  }
2113 }
2114 
2115 void KateIconBorder::showAnnotationTooltip( int line, const QPoint& pos )
2116 {
2117  KTextEditor::AnnotationModel *model = m_view->annotationModel() ?
2118  m_view->annotationModel() : m_doc->annotationModel();
2119 
2120  if( model )
2121  {
2122  QVariant data = model->data( line, Qt::ToolTipRole );
2123  QString tip = data.toString();
2124  if (!tip.isEmpty())
2125  QToolTip::showText( pos, data.toString(), this );
2126  }
2127 }
2128 
2129 
2130 int KateIconBorder::annotationLineWidth( int line )
2131 {
2132  KTextEditor::AnnotationModel *model = m_view->annotationModel() ?
2133  m_view->annotationModel() : m_doc->annotationModel();
2134 
2135  if( model )
2136  {
2137  QVariant data = model->data( line, Qt::DisplayRole );
2138  return data.toString().length() * m_maxCharWidth + 8;
2139  }
2140  return 8;
2141 }
2142 
2143 void KateIconBorder::updateAnnotationLine( int line )
2144 {
2145  if( annotationLineWidth(line) > m_annotationBorderWidth )
2146  {
2147  m_annotationBorderWidth = annotationLineWidth(line);
2148  updateGeometry();
2149 
2150  QTimer::singleShot( 0, this, SLOT(update()) );
2151  }
2152 }
2153 
2154 void KateIconBorder::showAnnotationMenu( int line, const QPoint& pos)
2155 {
2156  KMenu menu;
2157  QAction a(i18n("Disable Annotation Bar"), &menu);
2158  a.setIcon(KIcon("dialog-close"));
2159  menu.addAction(&a);
2160  emit m_view->annotationContextMenuAboutToShow( m_view, &menu, line );
2161  if (menu.exec(pos) == &a)
2162  m_view->setAnnotationBorderVisible(false);
2163 }
2164 
2165 void KateIconBorder::hideAnnotationTooltip()
2166 {
2167  QToolTip::hideText();
2168 }
2169 
2170 void KateIconBorder::updateAnnotationBorderWidth( )
2171 {
2172  m_annotationBorderWidth = 6;
2173  KTextEditor::AnnotationModel *model = m_view->annotationModel() ?
2174  m_view->annotationModel() : m_doc->annotationModel();
2175 
2176  if( model ) {
2177  for( int i = 0; i < m_view->doc()->lines(); i++ ) {
2178  int curwidth = annotationLineWidth( i );
2179  if( curwidth > m_annotationBorderWidth )
2180  m_annotationBorderWidth = curwidth;
2181  }
2182  }
2183 
2184  updateGeometry();
2185 
2186  QTimer::singleShot( 0, this, SLOT(update()) );
2187 }
2188 
2189 
2190 
2191 void KateIconBorder::annotationModelChanged( KTextEditor::AnnotationModel * oldmodel, KTextEditor::AnnotationModel * newmodel )
2192 {
2193  if( oldmodel )
2194  {
2195  oldmodel->disconnect( this );
2196  }
2197  if( newmodel )
2198  {
2199  connect( newmodel, SIGNAL(reset()), this, SLOT(updateAnnotationBorderWidth()) );
2200  connect( newmodel, SIGNAL(lineChanged(int)), this, SLOT(updateAnnotationLine(int)) );
2201  }
2202  updateAnnotationBorderWidth();
2203 }
2204 
2205 //END KateIconBorder
2206 
2207 //BEGIN KateViewEncodingAction
2208 // Acording to http://www.iana.org/assignments/ianacharset-mib
2209 // the default/unknown mib value is 2.
2210 #define MIB_DEFAULT 2
2211 
2212 class KateViewEncodingAction::Private
2213 {
2214  public:
2215  Private(KateViewEncodingAction *parent)
2216  : q(parent),
2217  currentSubAction(0)
2218  {
2219  }
2220 
2221  void init();
2222 
2223  void _k_subActionTriggered(QAction*);
2224 
2225  KateViewEncodingAction *q;
2226  QAction *currentSubAction;
2227 };
2228 
2229 bool lessThanAction(KSelectAction *a, KSelectAction *b)
2230 {
2231  return a->text() < b->text();
2232 }
2233 
2234 void KateViewEncodingAction::Private::init()
2235 {
2236  QList<KSelectAction *> actions;
2237 
2238  q->setToolBarMode(MenuMode);
2239 
2240  int i;
2241  foreach(const QStringList &encodingsForScript, KGlobal::charsets()->encodingsByScript())
2242  {
2243  KSelectAction* tmp = new KSelectAction(encodingsForScript.at(0),q);
2244 
2245  for (i=1; i<encodingsForScript.size(); ++i)
2246  {
2247  tmp->addAction(encodingsForScript.at(i));
2248  }
2249  q->connect(tmp,SIGNAL(triggered(QAction*)),q,SLOT(_k_subActionTriggered(QAction*)));
2250  //tmp->setCheckable(true);
2251  actions << tmp;
2252  }
2253  qSort(actions.begin(), actions.end(), lessThanAction);
2254  foreach (KSelectAction *action, actions)
2255  q->addAction(action);
2256 }
2257 
2258 void KateViewEncodingAction::Private::_k_subActionTriggered(QAction *action)
2259 {
2260  if (currentSubAction==action)
2261  return;
2262  currentSubAction=action;
2263  bool ok = false;
2264  int mib = q->mibForName(action->text(), &ok);
2265  if (ok)
2266  {
2267  emit q->KSelectAction::triggered(action->text());
2268  emit q->triggered(q->codecForMib(mib));
2269  }
2270 }
2271 
2272 KateViewEncodingAction::KateViewEncodingAction(KateDocument *_doc, KateView *_view, const QString& text, QObject *parent)
2273 : KSelectAction(text, parent), doc(_doc), view (_view), d(new Private(this))
2274 {
2275  d->init();
2276 
2277  connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow()));
2278  connect(this,SIGNAL(triggered(QString)),this,SLOT(setEncoding(QString)));
2279 }
2280 
2281 KateViewEncodingAction::~KateViewEncodingAction()
2282 {
2283  delete d;
2284 }
2285 
2286 void KateViewEncodingAction::slotAboutToShow()
2287 {
2288  setCurrentCodec(doc->config()->encoding());
2289 }
2290 
2291 void KateViewEncodingAction::setEncoding (const QString &e)
2292 {
2293  doc->userSetEncodingForNextReload ();
2294  doc->setEncoding(e);
2295  view->reloadFile();
2296 }
2297 
2298 int KateViewEncodingAction::mibForName(const QString &codecName, bool *ok) const
2299 {
2300  // FIXME logic is good but code is ugly
2301 
2302  bool success = false;
2303  int mib = MIB_DEFAULT;
2304  KCharsets *charsets = KGlobal::charsets();
2305 
2306  QTextCodec *codec = charsets->codecForName(codecName, success);
2307  if (!success)
2308  {
2309  // Maybe we got a description name instead
2310  codec = charsets->codecForName(charsets->encodingForName(codecName), success);
2311  }
2312 
2313  if (codec)
2314  mib = codec->mibEnum();
2315 
2316  if (ok)
2317  *ok = success;
2318 
2319  if (success)
2320  return mib;
2321 
2322  kWarning() << "Invalid codec name: " << codecName;
2323  return MIB_DEFAULT;
2324 }
2325 
2326 QTextCodec *KateViewEncodingAction::codecForMib(int mib) const
2327 {
2328  if (mib == MIB_DEFAULT)
2329  {
2330  // FIXME offer to change the default codec
2331  return QTextCodec::codecForLocale();
2332  }
2333  else
2334  return QTextCodec::codecForMib(mib);
2335 }
2336 
2337 QTextCodec *KateViewEncodingAction::currentCodec() const
2338 {
2339  return codecForMib(currentCodecMib());
2340 }
2341 
2342 bool KateViewEncodingAction::setCurrentCodec( QTextCodec *codec )
2343 {
2344  disconnect(this,SIGNAL(triggered(QString)),this,SLOT(setEncoding(QString)));
2345 
2346  int i,j;
2347  for (i=0;i<actions().size();++i)
2348  {
2349  if (actions().at(i)->menu())
2350  {
2351  for (j=0;j<actions().at(i)->menu()->actions().size();++j)
2352  {
2353  if (!j && !actions().at(i)->menu()->actions().at(j)->data().isNull())
2354  continue;
2355  if (actions().at(i)->menu()->actions().at(j)->isSeparator())
2356  continue;
2357 
2358  if (codec==KGlobal::charsets()->codecForName(actions().at(i)->menu()->actions().at(j)->text()))
2359  {
2360  d->currentSubAction=actions().at(i)->menu()->actions().at(j);
2361  d->currentSubAction->setChecked(true);
2362  }
2363  else
2364  actions().at(i)->menu()->actions().at(j)->setChecked (false);
2365  }
2366  }
2367  }
2368 
2369  connect(this,SIGNAL(triggered(QString)),this,SLOT(setEncoding(QString)));
2370  return true;
2371 }
2372 
2373 QString KateViewEncodingAction::currentCodecName() const
2374 {
2375  return d->currentSubAction->text();
2376 }
2377 
2378 bool KateViewEncodingAction::setCurrentCodec( const QString &codecName )
2379 {
2380  return setCurrentCodec(KGlobal::charsets()->codecForName(codecName));
2381 }
2382 
2383 int KateViewEncodingAction::currentCodecMib() const
2384 {
2385  return mibForName(currentCodecName());
2386 }
2387 
2388 bool KateViewEncodingAction::setCurrentCodec( int mib )
2389 {
2390  return setCurrentCodec(codecForMib(mib));
2391 }
2392 //END KateViewEncodingAction
2393 
2394 //BEGIN KateViewBar related classes
2395 
2396 KateViewBarWidget::KateViewBarWidget (bool addCloseButton, QWidget *parent)
2397  : QWidget (parent)
2398  , m_viewBar(0)
2399 {
2400  QHBoxLayout *layout = new QHBoxLayout (this);
2401 
2402  // NOTE: Here be cosmetics.
2403  layout->setMargin(0);
2404 
2405  // hide button
2406  if (addCloseButton) {
2407  QToolButton *hideButton = new QToolButton(this);
2408  hideButton->setAutoRaise(true);
2409  hideButton->setIcon(KIcon("dialog-close"));
2410  connect(hideButton, SIGNAL(clicked()), SIGNAL(hideMe()));
2411  layout->addWidget(hideButton);
2412  layout->setAlignment( hideButton, Qt::AlignLeft|Qt::AlignTop );
2413  }
2414 
2415  // widget to be used as parent for the real content
2416  m_centralWidget = new QWidget (this);
2417  layout->addWidget(m_centralWidget);
2418 
2419  setLayout(layout);
2420  setFocusProxy(m_centralWidget);
2421 }
2422 
2423 
2424 KateViewBar::KateViewBar (bool external,KTextEditor::ViewBarContainer::Position pos,QWidget *parent, KateView *view)
2425  : QWidget (parent), m_external(external), m_pos(pos),m_view (view), m_permanentBarWidget(0)
2426 
2427 {
2428  m_layout = new QVBoxLayout(this);
2429  m_stack = new QStackedWidget(this);
2430  m_layout->addWidget(m_stack);
2431  m_layout->setMargin(0);
2432 
2433  m_stack->hide();
2434  hide ();
2435 }
2436 
2437 void KateViewBar::addBarWidget (KateViewBarWidget *newBarWidget)
2438 {
2439  if (hasBarWidget(newBarWidget)) {
2440  kDebug(13025) << "this bar widget is already added";
2441  return;
2442  }
2443  // add new widget, invisible...
2444  newBarWidget->hide();
2445  m_stack->addWidget (newBarWidget);
2446  newBarWidget->setAssociatedViewBar(this);
2447  connect(newBarWidget, SIGNAL(hideMe()), SLOT(hideCurrentBarWidget()));
2448 
2449  kDebug(13025)<<"add barwidget " << newBarWidget;
2450 }
2451 
2452 void KateViewBar::removeBarWidget (KateViewBarWidget *barWidget)
2453 {
2454  if (hasBarWidget(barWidget)) {
2455  m_stack->removeWidget(barWidget);
2456  barWidget->setAssociatedViewBar(0);
2457  barWidget->hide();
2458  disconnect(barWidget, 0, this, 0);
2459  }
2460 }
2461 
2462 void KateViewBar::addPermanentBarWidget (KateViewBarWidget *barWidget)
2463 {
2464  // remove old widget from layout (if any)
2465  if (m_permanentBarWidget) {
2466  m_permanentBarWidget->hide();
2467  m_layout->removeWidget(m_permanentBarWidget);
2468  }
2469 
2470  m_layout->addWidget(barWidget, 0, Qt::AlignBottom);
2471  m_permanentBarWidget = barWidget;
2472  m_permanentBarWidget->show();
2473 
2474  setViewBarVisible(true);
2475 }
2476 
2477 void KateViewBar::removePermanentBarWidget (KateViewBarWidget *barWidget)
2478 {
2479  if (m_permanentBarWidget != barWidget) {
2480  kDebug(13025) << "no such permanent widget exists in bar";
2481  return;
2482  }
2483 
2484  if (!m_permanentBarWidget)
2485  return;
2486 
2487  m_permanentBarWidget->hide();
2488  m_layout->removeWidget(m_permanentBarWidget);
2489  m_permanentBarWidget = 0;
2490 
2491  if (!m_stack->isVisible()) {
2492  setViewBarVisible(false);
2493  }
2494 }
2495 
2496 bool KateViewBar::hasPermanentWidget (KateViewBarWidget *barWidget ) const
2497 {
2498  return (m_permanentBarWidget == barWidget);
2499 }
2500 
2501 void KateViewBar::showBarWidget (KateViewBarWidget *barWidget)
2502 {
2503  Q_ASSERT(barWidget != 0);
2504 
2505  if (barWidget != qobject_cast<KateViewBarWidget*>(m_stack->currentWidget())) {
2506  hideCurrentBarWidget();
2507  }
2508 
2509  // raise correct widget
2510  m_stack->setCurrentWidget (barWidget);
2511  barWidget->show();
2512  barWidget->setFocus(Qt::ShortcutFocusReason);
2513  m_stack->show();
2514 
2515  // if we have any permanent widget, bar is always visible,
2516  // no need to show it
2517  if (!m_permanentBarWidget) {
2518  setViewBarVisible(true);
2519  }
2520 }
2521 
2522 bool KateViewBar::hasBarWidget(KateViewBarWidget* barWidget) const
2523 {
2524  return m_stack->indexOf(barWidget) != -1;
2525 }
2526 
2527 void KateViewBar::hideCurrentBarWidget ()
2528 {
2529  KateViewBarWidget *current=qobject_cast<KateViewBarWidget*>(m_stack->currentWidget());
2530  if (current) {
2531  current->closed();
2532  }
2533  m_stack->hide();
2534 
2535  // if we have any permanent widget, bar is always visible,
2536  // no need to hide it
2537  if (!m_permanentBarWidget) {
2538  setViewBarVisible(false);
2539  }
2540 
2541  m_view->setFocus();
2542  kDebug(13025)<<"hide barwidget";
2543 }
2544 
2545 void KateViewBar::setViewBarVisible (bool visible)
2546 {
2547  if (m_external) {
2548  KTextEditor::ViewBarContainer *viewBarContainer=qobject_cast<KTextEditor::ViewBarContainer*>( KateGlobal::self()->container() );
2549  if (viewBarContainer) {
2550  if (visible) {
2551  viewBarContainer->showViewBarForView(m_view,m_pos);
2552  } else {
2553  viewBarContainer->hideViewBarForView(m_view,m_pos);
2554  }
2555  }
2556  } else {
2557  setVisible (visible);
2558  }
2559 }
2560 
2561 void KateViewBar::keyPressEvent(QKeyEvent* event)
2562 {
2563  if (event->key() == Qt::Key_Escape) {
2564  hideCurrentBarWidget();
2565  return;
2566  }
2567  QWidget::keyPressEvent(event);
2568 
2569 }
2570 
2571 void KateViewBar::hideEvent(QHideEvent* event)
2572 {
2573  Q_UNUSED(event);
2574 // if (!event->spontaneous())
2575 // m_view->setFocus();
2576 }
2577 
2578 //END KateViewBar related classes
2579 
2580 KatePasteMenu::KatePasteMenu (const QString& text, KateView *view)
2581  : KActionMenu(text, view)
2582  , m_view (view)
2583 {
2584  connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow()));
2585 }
2586 
2587 void KatePasteMenu::slotAboutToShow()
2588 {
2589  menu()->clear ();
2590 
2594  int i = 0;
2595  Q_FOREACH (const QString &text, KateGlobal::self()->clipboardHistory()) {
2599  QString leftPart = (text.size() > 48) ? (text.left(48) + "...") : text;
2600  QAction *a=menu()->addAction (leftPart.replace ("\n", " "), this, SLOT(paste()));
2601  a->setData(i++);
2602  }
2603 }
2604 
2605 void KatePasteMenu::paste ()
2606 {
2607  if (!sender())
2608  return;
2609 
2610  QAction *action = qobject_cast<QAction*>(sender());
2611  if (!action)
2612  return;
2613 
2614  // get index
2615  int i = action->data().toInt();
2616  if (i >= KateGlobal::self()->clipboardHistory().size())
2617  return;
2618 
2619  // paste
2620  m_view->paste (&KateGlobal::self()->clipboardHistory()[i]);
2621 }
2622 
2623 
2624 #include "kateviewhelpers.moc"
2625 
2626 // kate: space-indent on; indent-width 2; replace-tabs on;
2627 
QVariant
KateDocument::line
virtual QString line(int line) const
Definition: katedocument.cpp:447
KateView::annotationActivated
void annotationActivated(KTextEditor::View *view, int line)
KateDocument::buffer
KateBuffer & buffer()
Get access to buffer of this document.
Definition: katedocument.h:946
QColor
KateIconBorder::None
Definition: kateviewhelpers.h:178
KCharsets::codecForName
QTextCodec * codecForName(const QString &name) const
KateDocument::config
KateDocumentConfig * config()
Configuration.
Definition: katedocument.h:1009
KTextEditor::Mark::type
uint type
KSharedPtr< Attribute >
KateCmd::historyLength
uint historyLength() const
Definition: katecmd.h:50
kateview.h
KateTextLayout::startCol
int startCol() const
Definition: katetextlayout.cpp:127
Kate::Script::i18n
QScriptValue i18n(QScriptContext *context, QScriptEngine *engine)
i18n("text", arguments [optional])
Definition: katescripthelpers.cpp:186
kcharsets.h
KColorUtils::darken
QColor darken(const QColor &, qreal amount=0.5, qreal chromaGain=1.0)
KateIconBorder::updateFont
void updateFont()
Definition: kateviewhelpers.cpp:1396
KTextEditor::Command::exec
virtual bool exec(KTextEditor::View *view, const QString &cmd, QString &msg)=0
KateViewBar::addBarWidget
void addBarWidget(KateViewBarWidget *newBarWidget)
Adds a widget to this viewbar.
Definition: kateviewhelpers.cpp:2437
KateCmdLineEdit::hideRequested
void hideRequested()
KateDocument::addMark
virtual void addMark(int line, uint markType)
Definition: katedocument.cpp:1677
KateDocument::newMovingRange
virtual KTextEditor::MovingRange * newMovingRange(const KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors=KTextEditor::MovingRange::DoNotExpand, KTextEditor::MovingRange::EmptyBehavior emptyBehavior=KTextEditor::MovingRange::AllowEmpty)
Create a new moving range for this document.
Definition: katedocument.cpp:4742
KateViewInternal::startPos
KTextEditor::Cursor startPos() const
Definition: kateviewinternal.h:124
KateViewEncodingAction::KateViewEncodingAction
KateViewEncodingAction(KateDocument *_doc, KateView *_view, const QString &text, QObject *parent)
Definition: kateviewhelpers.cpp:2272
KTextEditor::Command::help
virtual bool help(KTextEditor::View *view, const QString &cmd, QString &msg)=0
kdebug.h
KateView::renderer
KateRenderer * renderer()
Definition: kateview.cpp:1653
katerenderer.h
KateGlobal::container
QObject * container()
Get the currently associated Container object.
Definition: kateglobal.cpp:516
KateTextLayout::line
int line() const
Definition: katetextlayout.cpp:93
KCharsets
KTextEditor::Attribute
kapplication.h
KateBuffer::ensureHighlighted
void ensureHighlighted(int line, int lookAhead=64)
Update highlighting of given line line, if needed.
Definition: katebuffer.cpp:284
KateViewInternal::mouseDoubleClickEvent
virtual void mouseDoubleClickEvent(QMouseEvent *)
Definition: kateviewinternal.cpp:2586
KateWildcardMatcher::exactMatch
bool exactMatch(const QString &candidate, const QString &wildcard, int candidatePosFromRight, int wildcardPosFromRight, bool caseSensitive=true)
Definition: katewildcardmatcher.cpp:29
KTextEditor::Range::isValid
virtual bool isValid() const
lessThanAction
bool lessThanAction(KSelectAction *a, KSelectAction *b)
Definition: kateviewhelpers.cpp:2229
KateIconBorder::setAnnotationBorderOn
void setAnnotationBorderOn(bool enable)
Definition: kateviewhelpers.cpp:1301
KateCmdLineEdit::slotReturnPressed
void slotReturnPressed(const QString &cmd)
Parse the text as a command.
Definition: kateviewhelpers.cpp:964
KateView::dynWordWrap
bool dynWordWrap() const
Definition: kateview.h:245
KateBuffer::computeFoldingRangeForStartLine
KTextEditor::Range computeFoldingRangeForStartLine(int startLine)
For a given line, compute the folding range that starts there to be used to fold e.g.
Definition: katebuffer.cpp:522
kglobalsettings.h
Kate::Script::i18nc
QScriptValue i18nc(QScriptContext *context, QScriptEngine *engine)
i18nc("context", "text", arguments [optional])
Definition: katescripthelpers.cpp:210
KGlobalSettings::singleClick
static bool singleClick()
KateDocument::handleMarkClick
bool handleMarkClick(int line)
Returns true if the click on the mark should not be further processed.
Definition: katedocument.cpp:1762
KateViewConfig::lineModification
bool lineModification() const
Definition: kateconfig.cpp:1528
timeout
int timeout
KMenu
KateCommandLineBar::setText
void setText(const QString &text, bool selected=true)
Definition: kateviewhelpers.cpp:839
kcolorutils.h
KLineEdit::setCompletionObject
virtual void setCompletionObject(KCompletion *, bool hsig=true)
KateIconBorder::IconBorder
Definition: kateviewhelpers.h:178
KateViewBar::KateViewBar
KateViewBar(bool external, KTextEditor::ViewBarContainer::Position pos, QWidget *parent, KateView *view)
Definition: kateviewhelpers.cpp:2424
katevicommandrangeexpressionparser.h
KateCmd::self
static KateCmd * self()
Definition: katecmd.cpp:112
Kate::TextFolding::visibleLineToLine
int visibleLineToLine(int visibleLine) const
Convert a visible line number to a line number in the text buffer.
Definition: katetextfolding.cpp:422
QWidget
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
KTextEditor::CommandExtension::processText
virtual void processText(KTextEditor::View *view, const QString &text)=0
katedocument.h
KateViewBar::removePermanentBarWidget
void removePermanentBarWidget(KateViewBarWidget *barWidget)
Removes permanent bar widget from viewbar.
Definition: kateviewhelpers.cpp:2477
KateViewInternal::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *)
Definition: kateviewinternal.cpp:2681
KateViewBar::hideEvent
virtual void hideEvent(QHideEvent *event)
Definition: kateviewhelpers.cpp:2571
name
const char * name(StandardAction id)
KateRendererConfig::iconBarColor
const QColor & iconBarColor() const
Definition: kateconfig.cpp:2359
KateDocument::defaultStyle
virtual KTextEditor::Attribute::Ptr defaultStyle(const KTextEditor::HighlightInterface::DefaultStyle ds) const
Definition: katedocument.cpp:5354
movingrange.h
KateDocument::annotationModel
virtual KTextEditor::AnnotationModel * annotationModel() const
Definition: katedocument.cpp:4800
KatePasteMenu::KatePasteMenu
KatePasteMenu(const QString &text, KateView *view)
Definition: kateviewhelpers.cpp:2580
KateViewEncodingAction::mibForName
int mibForName(const QString &codecName, bool *ok=0) const
Definition: kateviewhelpers.cpp:2298
KateIconBorder::lineNumberWidth
int lineNumberWidth() const
Definition: kateviewhelpers.cpp:1415
KateCmdLineEdit::KateCmdLineEdit
KateCmdLineEdit(KateCommandLineBar *bar, KateView *view)
Definition: kateviewhelpers.cpp:852
kiconloader.h
s_linePixelIncLimit
static const int s_linePixelIncLimit
Definition: kateviewhelpers.cpp:85
KateGlobal::self
static KateGlobal * self()
Kate Part Internal stuff ;)
Definition: kateglobal.cpp:462
KateDocument::userSetEncodingForNextReload
void userSetEncodingForNextReload()
User did set encoding for next reload => enforce it!
Definition: katedocument.h:960
QString
QHash< int, KTextEditor::Mark * >
KTextEditor::HighlightInterface::dsNormal
KTextEditor::Mark::line
int line
s_lineWidth
static const int s_lineWidth
Definition: kateviewhelpers.cpp:83
KateView::textFolding
Kate::TextFolding & textFolding()
Folding handler for this view.
Definition: kateview.h:574
KateRendererConfig::foldingColor
const QColor & foldingColor() const
Definition: kateconfig.cpp:2380
KateCmd::appendHistory
void appendHistory(const QString &cmd)
Definition: katecmd.cpp:117
KateCommandLineBar::~KateCommandLineBar
~KateCommandLineBar()
Definition: kateviewhelpers.cpp:833
KateView::annotationModel
KTextEditor::AnnotationModel * annotationModel() const
Definition: kateview.cpp:3006
ktoolinvocation.h
QObject
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KTextEditor::Cursor
klocale.h
s_pixelMargin
static const int s_pixelMargin
Definition: kateviewhelpers.cpp:84
KateDocument::plainKateTextLine
Kate::TextLine plainKateTextLine(uint i)
Definition: katedocument.cpp:4713
KParts::ReadOnlyPart::url
KUrl url
KToolInvocation::invokeHelp
static void invokeHelp(const QString &anchor=QString(), const QString &appname=QString(), const QByteArray &startup_id=QByteArray())
KateView::getViInputModeManager
KateViInputModeManager * getViInputModeManager()
Definition: kateview.cpp:1567
KLineEdit::clear
virtual void clear()
Kate::TextFolding::foldRange
bool foldRange(qint64 id)
Fold the given range.
Definition: katetextfolding.cpp:168
KLineEdit::keyPressEvent
virtual void keyPressEvent(QKeyEvent *)
config
KSharedConfigPtr config()
CommandRangeExpressionParser::parseRangeExpression
static KTextEditor::Range parseRangeExpression(const QString &command, KateView *view, QString &destRangeExpression, QString &destTransformedCommand)
Attempt to parse any leading range expression (e.g.
Definition: katevicommandrangeexpressionparser.cpp:68
kateviewhelpers.h
katebuffer.h
Kate::TextFolding::unfoldRange
bool unfoldRange(qint64 id, bool remove=false)
Unfold the given range.
Definition: katetextfolding.cpp:191
KateRendererConfig::lineNumberColor
const QColor & lineNumberColor() const
Definition: kateconfig.cpp:2433
KateScrollBar::styleChange
virtual void styleChange(QStyle &oldStyle)
Definition: kateviewhelpers.cpp:704
KateCmdLineEdit::keyPressEvent
void keyPressEvent(QKeyEvent *ev)
Definition: kateviewhelpers.cpp:1097
KateDocument::mark
virtual uint mark(int line)
Definition: katedocument.cpp:1646
KateViewInternal::yToKateTextLayout
KateTextLayout yToKateTextLayout(int y) const
Definition: kateviewinternal.cpp:306
KateViewBarWidget::KateViewBarWidget
KateViewBarWidget(bool addCloseButton, QWidget *parent=0)
Definition: kateviewhelpers.cpp:2396
knotification.h
KSelectAction
KateView::selectionRange
virtual const KTextEditor::Range & selectionRange() const
Definition: kateview.cpp:2760
KateRendererConfig::modifiedLineColor
const QColor & modifiedLineColor() const
Definition: kateconfig.cpp:2496
KColorUtils::luma
qreal luma(const QColor &)
KateViewBarWidget
Definition: kateviewhelpers.h:288
KateScrollBar::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: kateviewhelpers.cpp:696
KateViewBar::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
Definition: kateviewhelpers.cpp:2561
KateIconBorder::updateAnnotationLine
void updateAnnotationLine(int line)
Definition: kateviewhelpers.cpp:2143
KateIconBorder::setIconBorderOn
void setIconBorderOn(bool enable)
Definition: kateviewhelpers.cpp:1289
kglobal.h
QScrollBar
KateIconBorder::setFoldingMarkersOn
void setFoldingMarkersOn(bool enable)
Definition: kateviewhelpers.cpp:1352
KTextEditor::MovingRange::overlapsLine
bool overlapsLine(int line) const
KateViewBarWidget::centralWidget
QWidget * centralWidget()
Definition: kateviewhelpers.h:305
Kate::TextFolding::foldingRangesStartingOnLine
QVector< QPair< qint64, FoldingRangeFlags > > foldingRangesStartingOnLine(int line) const
Queries which folding ranges start at the given line and returns the id + flags for all of them...
Definition: katetextfolding.cpp:476
KateViewBar::removeBarWidget
void removeBarWidget(KateViewBarWidget *barWidget)
Removes a widget from this viewbar.
Definition: kateviewhelpers.cpp:2452
KateCmd::fromHistory
const QString fromHistory(int i) const
Definition: katecmd.cpp:129
paintTriangle
static void paintTriangle(QPainter &painter, QColor c, int xOffset, int yOffset, int width, int height, bool open)
Definition: kateviewhelpers.cpp:1464
KateViewInternal::mousePressEvent
virtual void mousePressEvent(QMouseEvent *)
Definition: kateviewinternal.cpp:2462
KTextEditor::RangeCommand::exec
virtual bool exec(KTextEditor::View *view, const QString &cmd, QString &msg, const KTextEditor::Range &range)=0
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
attribute.h
KTextEditor::ViewBarContainer::hideViewBarForView
virtual void hideViewBarForView(View *view, enum Position position)=0
KateScrollBar::sliderChange
virtual void sliderChange(SliderChange change)
Definition: kateviewhelpers.cpp:711
kmenu.h
KTextEditor::Document
KateScrollBar::marksChanged
void marksChanged()
Definition: kateviewhelpers.cpp:732
katelayoutcache.h
KateCommandLineBar::showHelpPage
void showHelpPage()
Definition: kateviewhelpers.cpp:829
KateIconBorder::setDynWrapIndicators
void setDynWrapIndicators(int state)
Definition: kateviewhelpers.cpp:1339
kateglobal.h
KateViewInternal::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *)
Definition: kateviewinternal.cpp:2752
KTextEditor::ViewBarContainer::Position
Position
KTextEditor::RangeCommand::supportsRange
virtual bool supportsRange(const QString &cmd)=0
QStringList
KTextEditor::AnnotationModel::data
virtual QVariant data(int line, Qt::ItemDataRole role) const =0
KateViewInternal
Definition: kateviewinternal.h:57
KTextEditor::Range::invalid
static Range invalid()
KCompletion
KTextEditor::CommandExtension::completionObject
virtual KCompletion * completionObject(KTextEditor::View *view, const QString &cmdname)=0
KateViewBarWidget::hideMe
void hideMe()
KateDocument::lines
virtual int lines() const
Definition: katedocument.cpp:753
KTextEditor::Mark
KIcon
KNotification::beep
static void beep(const QString &reason=QString(), QWidget *widget=0L)
KateDocument::editableMarks
virtual uint editableMarks() const
Definition: katedocument.cpp:1841
KGlobal::charsets
KCharsets * charsets()
KateScrollBar::mousePressEvent
virtual void mousePressEvent(QMouseEvent *e)
Definition: kateviewhelpers.cpp:188
KCharsets::encodingForName
QString encodingForName(const QString &descriptiveName) const
MIB_DEFAULT
#define MIB_DEFAULT
Definition: kateviewhelpers.cpp:2210
kateviewinternal.h
KateScrollBar::KateScrollBar
KateScrollBar(Qt::Orientation orientation, class KateViewInternal *parent)
Definition: kateviewhelpers.cpp:107
KateViewBar::hasBarWidget
bool hasBarWidget(KateViewBarWidget *barWidget) const
Definition: kateviewhelpers.cpp:2522
KateCmdLineEdit::event
virtual bool event(QEvent *e)
Definition: kateviewhelpers.cpp:929
KateRendererConfig::global
static KateRendererConfig * global()
Definition: kateconfig.h:613
KateViewEncodingAction::setCurrentCodec
bool setCurrentCodec(QTextCodec *codec)
Definition: kateviewhelpers.cpp:2342
Kate::TextFolding::Folded
Range is folded away.
Definition: katetextfolding.h:69
KateCmdLineEdit::hideEvent
void hideEvent(QHideEvent *e)
Definition: kateviewhelpers.cpp:878
katecmd.h
KateScrollBar::updatePixmap
void updatePixmap()
Definition: kateviewhelpers.cpp:323
KTextEditor::ViewBarContainer::showViewBarForView
virtual void showViewBarForView(View *view, enum Position position)=0
KateViewConfig::setDefaultMarkType
void setDefaultMarkType(uint type)
Definition: kateconfig.cpp:1646
KColorUtils::shade
QColor shade(const QColor &, qreal lumaAmount, qreal chromaAmount=0.0)
KTextEditor::AnnotationModel
KateDocument::markPixmap
virtual QPixmap markPixmap(MarkInterface::MarkTypes) const
Definition: katedocument.cpp:1816
KateDocumentConfig::encoding
const QString & encoding() const
Definition: kateconfig.cpp:788
KActionMenu::menu
KMenu * menu()
KateLayoutCache::viewLine
KateTextLayout & viewLine(int viewLine)
Returns the layout of the corresponding line in the view.
Definition: katelayoutcache.cpp:358
KateDocument::handleMarkContextMenu
bool handleMarkContextMenu(int line, QPoint position)
Returns true if the context-menu event should not further be processed.
Definition: katedocument.cpp:1774
KateCmdLineEdit::focusInEvent
void focusInEvent(QFocusEvent *ev)
Definition: kateviewhelpers.cpp:1085
KateIconBorder::annotationModelChanged
void annotationModelChanged(KTextEditor::AnnotationModel *oldmodel, KTextEditor::AnnotationModel *newmodel)
Definition: kateviewhelpers.cpp:2191
KateView
Definition: kateview.h:78
KateIconBorder::setLineNumbersOn
void setLineNumbersOn(bool enable)
Definition: kateviewhelpers.cpp:1326
KateViewBarWidget::closed
virtual void closed()
Definition: kateviewhelpers.h:296
KateView::annotationContextMenuAboutToShow
void annotationContextMenuAboutToShow(KTextEditor::View *view, QMenu *menu, int line)
KTextEditor::Range
KTextEditor::Command
Kate::TextFolding::lineToVisibleLine
int lineToVisibleLine(int line) const
Convert a text buffer line to a visible line number.
Definition: katetextfolding.cpp:366
KateViewEncodingAction::currentCodecName
QString currentCodecName() const
Definition: kateviewhelpers.cpp:2373
KateViewBar::addPermanentBarWidget
void addPermanentBarWidget(KateViewBarWidget *barWidget)
Adds widget that will be always shown in the viewbar.
Definition: kateviewhelpers.cpp:2462
KateScrollBar::sizeHint
QSize sizeHint() const
Definition: kateviewhelpers.cpp:150
KateDocument
Definition: katedocument.h:74
KateIconBorder::FoldingMarkers
Definition: kateviewhelpers.h:178
KateDocument::requestMarkTooltip
void requestMarkTooltip(int line, QPoint position)
Definition: katedocument.cpp:1752
forward
KAction * forward(const QObject *recvr, const char *slot, QObject *parent)
KTextEditor::RangeCommand
KateViewConfig::writeConfig
void writeConfig(KConfigGroup &config)
Write config to object.
Definition: kateconfig.cpp:1243
KateViewConfig::allowMarkMenu
bool allowMarkMenu() const
Definition: kateconfig.cpp:1659
KateScrollBar::paintEvent
virtual void paintEvent(QPaintEvent *e)
Definition: kateviewhelpers.cpp:260
KateScrollBar::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *e)
Definition: kateviewhelpers.cpp:237
KTextEditor::Range::overlapsLine
bool overlapsLine(int line) const
KateIconBorder::BorderArea
BorderArea
Definition: kateviewhelpers.h:178
KateCommandLineBar
Definition: kateviewhelpers.h:408
ok
KGuiItem ok()
KateViewEncodingAction::codecForMib
QTextCodec * codecForMib(int mib) const
Definition: kateviewhelpers.cpp:2326
KateDocument::kateTextLine
Kate::TextLine kateTextLine(uint i)
Definition: katedocument.cpp:4707
KateViewEncodingAction::triggered
void triggered(QTextCodec *codec)
Specific (proper) codec was selected.
KateIconBorder::AnnotationBorder
Definition: kateviewhelpers.h:178
KateView::reloadFile
void reloadFile()
Definition: kateview.cpp:1204
KateCommandLineBar::KateCommandLineBar
KateCommandLineBar(KateView *view, QWidget *parent=0)
Definition: kateviewhelpers.cpp:810
containerinterface.h
KTextEditor::MovingRange::ExpandRight
katetextlayout.h
KConfigGroup
KTextEditor::MarkInterface::MarkTypes
MarkTypes
KateViewConfig::autoCenterLines
int autoCenterLines() const
Definition: kateconfig.cpp:1570
KLineEdit::focusInEvent
virtual void focusInEvent(QFocusEvent *ev)
KateIconBorder::updateAnnotationBorderWidth
void updateAnnotationBorderWidth()
Definition: kateviewhelpers.cpp:2170
KateViewEncodingAction::currentCodecMib
int currentCodecMib() const
Definition: kateviewhelpers.cpp:2383
KateCmd::queryCommand
KTextEditor::Command * queryCommand(const QString &cmd) const
Definition: katecmd.cpp:78
KateCmd::commandCompletionObject
KCompletion * commandCompletionObject()
Definition: katecmd.cpp:136
KateRendererConfig::separatorColor
const QColor & separatorColor() const
Definition: kateconfig.cpp:2454
KCompletion::makeCompletion
virtual QString makeCompletion(const QString &string)
KActionMenu
KLineEdit
KateViewBar::hideCurrentBarWidget
void hideCurrentBarWidget()
Hides currently shown bar widget.
Definition: kateviewhelpers.cpp:2527
KateLayoutCache::viewLineCount
int viewLineCount(int realLine)
Definition: katelayoutcache.cpp:471
KTextEditor::MovingRange::start
virtual const MovingCursor & start() const =0
KateScrollBar::sliderMaybeMoved
void sliderMaybeMoved(int value)
Definition: kateviewhelpers.cpp:778
KateTextLayout
This class represents one visible line of text; with dynamic wrapping, many KateTextLayouts can be ne...
Definition: katetextlayout.h:38
KTextEditor::MovingCursor::line
virtual int line() const =0
KateCmd::commandList
QStringList commandList() const
Definition: katecmd.cpp:107
KateDocument::setEncoding
virtual bool setEncoding(const QString &e)
Definition: katedocument.cpp:3953
KateIconBorder::positionToArea
BorderArea positionToArea(const QPoint &) const
Definition: kateviewhelpers.cpp:1771
KateView::viInputMode
bool viInputMode() const
Definition: kateview.cpp:1515
halfIPW
const int halfIPW
Definition: kateviewhelpers.cpp:1249
KateViewEncodingAction::~KateViewEncodingAction
~KateViewEncodingAction()
Definition: kateviewhelpers.cpp:2281
KateRendererConfig::font
const QFont & font() const
Definition: kateconfig.cpp:2127
KateViewBar::showBarWidget
void showBarWidget(KateViewBarWidget *barWidget)
Shows barWidget that was previously added with addBarWidget.
Definition: kateviewhelpers.cpp:2501
KateView::setAnnotationBorderVisible
void setAnnotationBorderVisible(bool visible)
Definition: kateview.cpp:3011
QPoint
KateViewInternal::endPos
KTextEditor::Cursor endPos() const
Definition: kateviewinternal.cpp:279
KateViewEncodingAction::currentCodec
QTextCodec * currentCodec() const
Definition: kateviewhelpers.cpp:2337
KateDocument::removeMark
virtual void removeMark(int line, uint markType)
Definition: katedocument.cpp:1714
stop
KGuiItem stop()
annotationinterface.h
QRect
KateCmdLineEdit
Definition: kateviewhelpers.h:426
KateIconBorder::ModificationBorder
Definition: kateviewhelpers.h:178
KTextEditor::CommandExtension::wantsToProcessText
virtual bool wantsToProcessText(const QString &cmdname)=0
KateRendererConfig::savedLineColor
const QColor & savedLineColor() const
Definition: kateconfig.cpp:2517
Kate::TextLine
QSharedPointer< TextLineData > TextLine
The normal world only accesses the text lines with shared pointers.
Definition: katetextline.h:443
KateScrollBar::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *e)
Definition: kateviewhelpers.cpp:213
KateViInputModeManager::reset
void reset()
Definition: kateviinputmodemanager.cpp:651
KateViewConfig::scrollPastEnd
bool scrollPastEnd() const
Definition: kateconfig.cpp:1854
KLineEdit::event
virtual bool event(QEvent *)
KateIconBorder::~KateIconBorder
virtual ~KateIconBorder()
Definition: kateviewhelpers.cpp:1283
KateRenderer::lineHeight
int lineHeight() const
Definition: katerenderer.cpp:825
KateRendererConfig::backgroundColor
const QColor & backgroundColor() const
Definition: kateconfig.cpp:2178
selectAll
KAction * selectAll(const QObject *recvr, const char *slot, QObject *parent)
KateDocument::setMarkDescription
virtual void setMarkDescription(MarkInterface::MarkTypes, const QString &)
Definition: katedocument.cpp:1811
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KateIconBorder::sizeHint
virtual QSize sizeHint() const
Definition: kateviewhelpers.cpp:1364
KateDocument::marks
virtual const QHash< int, KTextEditor::Mark * > & marks()
Definition: katedocument.cpp:1747
Kate::TextFolding::newFoldingRange
qint64 newFoldingRange(const KTextEditor::Range &range, FoldingRangeFlags flags=FoldingRangeFlags())
Create a new folding range.
Definition: katetextfolding.cpp:99
QSize
KateScrollBar::setShowMiniMap
void setShowMiniMap(bool b)
Definition: kateviewhelpers.cpp:131
KTextEditor::CommandExtension
KateViewEncodingAction::codecName
QString codecName
Definition: kateviewhelpers.h:248
KateView::doc
KateDocument * doc()
accessor to katedocument pointer
Definition: kateview.h:552
KTextEditor::ViewBarContainer
KateViewConfig::defaultMarkType
uint defaultMarkType() const
Definition: kateconfig.cpp:1638
KTextEditor::Range::contains
bool contains(const Range &range) const
KTextEditor::MovingRange::end
virtual const MovingCursor & end() const =0
KateView::annotationBorderVisibilityChanged
void annotationBorderVisibilityChanged(View *view, bool visible)
KateIconBorder::KateIconBorder
KateIconBorder(KateViewInternal *internalView, QWidget *parent)
Definition: kateviewhelpers.cpp:1251
KateViewConfig
Definition: kateconfig.h:381
KateRendererConfig::fontMetrics
const QFontMetricsF & fontMetrics() const
Definition: kateconfig.cpp:2135
reset
KGuiItem reset()
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
KateViewEncodingAction
Definition: kateviewhelpers.h:244
QToolButton
highlightinterface.h
KTextEditor::View
KLineEdit::returnPressed
void returnPressed(const QString &)
KateLayoutCache::viewCacheLineCount
int viewCacheLineCount() const
Definition: katelayoutcache.cpp:364
KLineEdit::setText
virtual void setText(const QString &)
KateView::config
KateViewConfig * config()
Configuration.
Definition: kateview.h:654
QEvent
Kate::TextFolding::visibleLines
int visibleLines() const
Query number of visible lines.
Definition: katetextfolding.cpp:340
kateviglobal.h
end
const KShortcut & end()
KateScrollBar::sliderMMBMoved
void sliderMMBMoved(int value)
kateconfig.h
KateViewBar::hasPermanentWidget
bool hasPermanentWidget(KateViewBarWidget *barWidget) const
Definition: kateviewhelpers.cpp:2496
kcolorscheme.h
KateDocument::setMarkPixmap
virtual void setMarkPixmap(MarkInterface::MarkTypes, const QPixmap &)
Definition: katedocument.cpp:1806
KateCommandLineBar::execute
void execute(const QString &text)
Definition: kateviewhelpers.cpp:847
QAction
kconfiggroup.h
KateView::paste
void paste(const QString *textToPaste=0)
Definition: kateview.cpp:2374
QList< QTextLayout::FormatRange >
KateViewConfig::global
static KateViewConfig * global()
Definition: kateconfig.h:402
KateIconBorder::LineNumbers
Definition: kateviewhelpers.h:178
KateDocument::markDescription
virtual QString markDescription(MarkInterface::MarkTypes) const
Definition: katedocument.cpp:1831
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:53 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
  • Applications
  •   Libraries
  •     libkonq
  • 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