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

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • 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_viRelLineNumbersOn( false )
1259  , m_updateViRelLineNumbers ( false )
1260  , m_foldingMarkersOn( false )
1261  , m_dynWrapIndicatorsOn( false )
1262  , m_annotationBorderOn( false )
1263  , m_dynWrapIndicators( 0 )
1264  , m_cachedLNWidth( 0 )
1265  , m_maxCharWidth( 0.0 )
1266  , iconPaneWidth (16)
1267  , m_annotationBorderWidth (6)
1268  , m_foldingRange(0)
1269  , m_nextHighlightBlock(-2)
1270  , m_currentBlockLine(-1)
1271 {
1272  setAttribute( Qt::WA_StaticContents );
1273  setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum );
1274  setMouseTracking(true);
1275  m_doc->setMarkDescription( MarkInterface::markType01, i18n("Bookmark") );
1276  m_doc->setMarkPixmap( MarkInterface::markType01, KIcon("bookmarks").pixmap(16, 16) );
1277 
1278  updateFont();
1279 
1280  m_delayFoldingHlTimer.setSingleShot(true);
1281  m_delayFoldingHlTimer.setInterval(150);
1282  connect(&m_delayFoldingHlTimer, SIGNAL(timeout()), this, SLOT(showBlock()));
1283 }
1284 
1285 KateIconBorder::~KateIconBorder()
1286 {
1287  delete m_foldingRange;
1288  m_foldingRange = 0;
1289 }
1290 
1291 void KateIconBorder::setIconBorderOn( bool enable )
1292 {
1293  if( enable == m_iconBorderOn )
1294  return;
1295 
1296  m_iconBorderOn = enable;
1297 
1298  updateGeometry();
1299 
1300  QTimer::singleShot( 0, this, SLOT(update()) );
1301 }
1302 
1303 void KateIconBorder::setAnnotationBorderOn( bool enable )
1304 {
1305  if( enable == m_annotationBorderOn )
1306  return;
1307 
1308  m_annotationBorderOn = enable;
1309 
1310  emit m_view->annotationBorderVisibilityChanged(m_view, enable);
1311 
1312  updateGeometry();
1313 
1314  QTimer::singleShot( 0, this, SLOT(update()) );
1315 }
1316 
1317 void KateIconBorder::removeAnnotationHovering()
1318 {
1319  // remove hovering if it's still there
1320  if (m_annotationBorderOn && !m_hoveredAnnotationGroupIdentifier.isEmpty())
1321  {
1322  m_hoveredAnnotationGroupIdentifier.clear();
1323  hideAnnotationTooltip();
1324  QTimer::singleShot( 0, this, SLOT(update()) );
1325  }
1326 }
1327 
1328 void KateIconBorder::setLineNumbersOn( bool enable )
1329 {
1330  if( enable == m_lineNumbersOn )
1331  return;
1332 
1333  m_lineNumbersOn = enable;
1334  m_dynWrapIndicatorsOn = (m_dynWrapIndicators == 1) ? enable : m_dynWrapIndicators;
1335 
1336  updateGeometry();
1337 
1338  QTimer::singleShot( 0, this, SLOT(update()) );
1339 }
1340 
1341 void KateIconBorder::setViRelLineNumbersOn(bool enable)
1342 {
1343  if( enable == m_viRelLineNumbersOn )
1344  return;
1345 
1346  m_viRelLineNumbersOn = enable;
1347  /*
1348  * We don't have to touch the m_dynWrapIndicatorsOn because
1349  * we already got it right from the m_lineNumbersOn
1350  */
1351  updateGeometry();
1352 
1353  QTimer::singleShot( 0, this, SLOT(update()) );
1354 }
1355 
1356 void KateIconBorder::updateViRelLineNumbers()
1357 {
1358  if (m_viRelLineNumbersOn) {
1359  m_updateViRelLineNumbers = true;
1360  update();
1361  }
1362 }
1363 
1364 void KateIconBorder::setDynWrapIndicators( int state )
1365 {
1366  if (state == m_dynWrapIndicators )
1367  return;
1368 
1369  m_dynWrapIndicators = state;
1370  m_dynWrapIndicatorsOn = (state == 1) ? m_lineNumbersOn : state;
1371 
1372  updateGeometry ();
1373 
1374  QTimer::singleShot( 0, this, SLOT(update()) );
1375 }
1376 
1377 void KateIconBorder::setFoldingMarkersOn( bool enable )
1378 {
1379  if( enable == m_foldingMarkersOn )
1380  return;
1381 
1382  m_foldingMarkersOn = enable;
1383 
1384  updateGeometry();
1385 
1386  QTimer::singleShot( 0, this, SLOT(update()) );
1387 }
1388 
1389 QSize KateIconBorder::sizeHint() const
1390 {
1391  int w = 0;
1392 
1393  if (m_iconBorderOn)
1394  w += iconPaneWidth + 2;
1395 
1396  if (m_annotationBorderOn)
1397  {
1398  w += m_annotationBorderWidth + 2;
1399  }
1400 
1401  if (m_lineNumbersOn || (m_view->dynWordWrap() && m_dynWrapIndicatorsOn)) {
1402  w += lineNumberWidth() + 2;
1403  }
1404 
1405  if (m_foldingMarkersOn)
1406  w += iconPaneWidth;
1407 
1408  // space for the line modification system border
1409  if (m_view->config()->lineModification()) {
1410  w += 3;
1411  }
1412 
1413  // two pixel space
1414  w += 2;
1415 
1416  return QSize( w, 0 );
1417 }
1418 
1419 // This function (re)calculates the maximum width of any of the digit characters (0 -> 9)
1420 // for graceful handling of variable-width fonts as the linenumber font.
1421 void KateIconBorder::updateFont()
1422 {
1423  const QFontMetricsF &fm = m_view->renderer()->config()->fontMetrics();
1424  m_maxCharWidth = 0.0;
1425  // Loop to determine the widest numeric character in the current font.
1426  // 48 is ascii '0'
1427  for (int i = 48; i < 58; i++) {
1428  const qreal charWidth = ceil(fm.width( QChar(i) ));
1429  m_maxCharWidth = qMax(m_maxCharWidth, charWidth);
1430  }
1431 
1432  // the icon pane scales with the font...
1433  iconPaneWidth = fm.height();
1434 
1435  updateGeometry();
1436 
1437  QTimer::singleShot( 0, this, SLOT(update()) );
1438 }
1439 
1440 int KateIconBorder::lineNumberWidth() const
1441 {
1442  // width = (number of digits + 1) * char width
1443  const int digits = (int) ceil(log10((double)(m_view->doc()->lines() + 1)));
1444  int width = m_lineNumbersOn ? (int)ceil((digits + 1) * m_maxCharWidth) : 0;
1445 
1446  if (m_view->dynWordWrap() && m_dynWrapIndicatorsOn) {
1447  // HACK: 16 == style().scrollBarExtent().width()
1448  width = qMax(16 + 4, width);
1449 
1450  if (m_cachedLNWidth != width || m_oldBackgroundColor != m_view->renderer()->config()->iconBarColor()) {
1451  int w = 16;// HACK: 16 == style().scrollBarExtent().width() style().scrollBarExtent().width();
1452  int h = m_view->renderer()->lineHeight();
1453 
1454  QSize newSize(w, h);
1455  if ((m_arrow.size() != newSize || m_oldBackgroundColor != m_view->renderer()->config()->iconBarColor()) && !newSize.isEmpty()) {
1456  m_arrow = QPixmap(newSize);
1457 
1458  QPainter p(&m_arrow);
1459  p.fillRect( 0, 0, w, h, m_view->renderer()->config()->iconBarColor() );
1460 
1461  h = m_view->renderer()->config()->fontMetrics().ascent();
1462 
1463  p.setPen(m_view->renderer()->config()->lineNumberColor());
1464 
1465  QPainterPath path;
1466  path.moveTo(w/2, h/2);
1467  path.lineTo(w/2, 0);
1468  path.lineTo(w/4, h/4);
1469  path.lineTo(0, 0);
1470  path.lineTo(0, h/2);
1471  path.lineTo(w/2, h-1);
1472  path.lineTo(w*3/4, h-1);
1473  path.lineTo(w-1, h*3/4);
1474  path.lineTo(w*3/4, h/2);
1475  path.lineTo(0, h/2);
1476  p.drawPath(path);
1477  }
1478  }
1479  }
1480 
1481  return width;
1482 }
1483 
1484 void KateIconBorder::paintEvent(QPaintEvent* e)
1485 {
1486  paintBorder(e->rect().x(), e->rect().y(), e->rect().width(), e->rect().height());
1487 }
1488 
1489 static void paintTriangle (QPainter &painter, QColor c, int xOffset, int yOffset, int width, int height, bool open)
1490 {
1491  painter.setRenderHint(QPainter::Antialiasing);
1492 
1493  qreal size = qMin (width, height);
1494 
1495  if ( KColorUtils::luma( c ) > 0.25 )
1496  c = KColorUtils::darken( c );
1497  else
1498  c = KColorUtils::shade( c, 0.1 );
1499 
1500  QPen pen;
1501  pen.setJoinStyle (Qt::RoundJoin);
1502  pen.setColor (c);
1503  pen.setWidthF (1.5);
1504  painter.setPen ( pen );
1505 
1506  painter.setBrush (c);
1507 
1508  // let some border, if possible
1509  size *= 0.6;
1510 
1511  qreal halfSize = size / 2;
1512  qreal halfSizeP = halfSize * 0.6;
1513  QPointF middle (xOffset + (qreal)width / 2, yOffset + (qreal)height / 2);
1514 
1515  if (open)
1516  {
1517  QPointF points[3] = { middle+QPointF(-halfSize, -halfSizeP), middle+QPointF(halfSize, -halfSizeP), middle+QPointF(0, halfSizeP) };
1518  painter.drawConvexPolygon(points, 3);
1519  }
1520  else
1521  {
1522  QPointF points[3] = { middle+QPointF(-halfSizeP, -halfSize), middle+QPointF(-halfSizeP, halfSize), middle+QPointF(halfSizeP, 0) };
1523  painter.drawConvexPolygon(points, 3);
1524  }
1525 
1526  painter.setRenderHint(QPainter::Antialiasing, false);
1527 }
1528 
1529 void KateIconBorder::paintBorder (int /*x*/, int y, int /*width*/, int height)
1530 {
1531  uint h = m_view->renderer()->lineHeight();
1532  uint startz = (y / h);
1533  uint endz = startz + 1 + (height / h);
1534  uint lineRangesSize = m_viewInternal->cache()->viewCacheLineCount();
1535  uint currentLine = m_view->cursorPosition().line();
1536 
1537  // center the folding boxes
1538  int m_px = (h - 11) / 2;
1539  if (m_px < 0)
1540  m_px = 0;
1541 
1542  int lnWidth( 0 );
1543  if ( m_lineNumbersOn || (m_view->dynWordWrap() && m_dynWrapIndicatorsOn) ) // avoid calculating unless needed ;-)
1544  {
1545  lnWidth = lineNumberWidth();
1546  if ( lnWidth != m_cachedLNWidth || m_oldBackgroundColor != m_view->renderer()->config()->iconBarColor() )
1547  {
1548  // we went from n0 ->n9 lines or vice verca
1549  // this causes an extra updateGeometry() first time the line numbers
1550  // are displayed, but sizeHint() is supposed to be const so we can't set
1551  // the cached value there.
1552  m_cachedLNWidth = lnWidth;
1553  m_oldBackgroundColor = m_view->renderer()->config()->iconBarColor();
1554  updateGeometry();
1555  update ();
1556  return;
1557  }
1558  }
1559 
1560  int w( this->width() ); // sane value/calc only once
1561 
1562  QPainter p ( this );
1563  p.setRenderHints (QPainter::TextAntialiasing);
1564  p.setFont ( m_view->renderer()->config()->font() ); // for line numbers
1565 
1566  KTextEditor::AnnotationModel *model = m_view->annotationModel() ?
1567  m_view->annotationModel() : m_doc->annotationModel();
1568 
1569  for (uint z=startz; z <= endz; z++)
1570  {
1571  int y = h * z;
1572  int realLine = -1;
1573 
1574  if (z < lineRangesSize)
1575  realLine = m_viewInternal->cache()->viewLine(z).line();
1576 
1577  int lnX = 0;
1578 
1579  p.fillRect( 0, y, w-5, h, m_view->renderer()->config()->iconBarColor() );
1580  p.fillRect( w-5, y, 5, h, m_view->renderer()->config()->backgroundColor() );
1581 
1582  // icon pane
1583  if( m_iconBorderOn )
1584  {
1585  p.setPen ( m_view->renderer()->config()->separatorColor() );
1586  p.setBrush ( m_view->renderer()->config()->separatorColor() );
1587  p.drawLine(lnX+iconPaneWidth+1, y, lnX+iconPaneWidth+1, y+h);
1588 
1589  if( (realLine > -1) && (m_viewInternal->cache()->viewLine(z).startCol() == 0) )
1590  {
1591  uint mrk ( m_doc->mark( realLine ) ); // call only once
1592 
1593  if ( mrk )
1594  {
1595  for( uint bit = 0; bit < 32; bit++ )
1596  {
1597  MarkInterface::MarkTypes markType = (MarkInterface::MarkTypes)(1<<bit);
1598  if( mrk & markType )
1599  {
1600  QPixmap px_mark (m_doc->markPixmap( markType ));
1601 
1602  if (!px_mark.isNull() && h > 0 && iconPaneWidth > 0)
1603  {
1604  if (iconPaneWidth < px_mark.width() || h < (uint)px_mark.height())
1605  px_mark = px_mark.scaled (iconPaneWidth, h, Qt::KeepAspectRatio);
1606 
1607  // center the mark pixmap
1608  int x_px = (iconPaneWidth - px_mark.width()) / 2;
1609  if (x_px < 0)
1610  x_px = 0;
1611 
1612  int y_px = (h - px_mark.height()) / 2;
1613  if (y_px < 0)
1614  y_px = 0;
1615 
1616  p.drawPixmap( lnX+x_px, y+y_px, px_mark);
1617  }
1618  }
1619  }
1620  }
1621  }
1622 
1623  lnX += iconPaneWidth + 2;
1624  }
1625 
1626  // annotation information
1627  if( m_annotationBorderOn )
1628  {
1629  // Draw a border line between annotations and the line numbers
1630  p.setPen ( m_view->renderer()->config()->lineNumberColor() );
1631  p.setBrush ( m_view->renderer()->config()->lineNumberColor() );
1632 
1633  int borderWidth = m_annotationBorderWidth;
1634  p.drawLine(lnX+borderWidth+1, y, lnX+borderWidth+1, y+h);
1635 
1636  if( (realLine > -1) && model )
1637  {
1638  // Fetch data from the model
1639  QVariant text = model->data( realLine, Qt::DisplayRole );
1640  QVariant foreground = model->data( realLine, Qt::ForegroundRole );
1641  QVariant background = model->data( realLine, Qt::BackgroundRole );
1642  // Fill the background
1643  if( background.isValid() )
1644  {
1645  p.fillRect( lnX, y, borderWidth + 1, h, background.value<QBrush>() );
1646  }
1647  // Set the pen for drawing the foreground
1648  if( foreground.isValid() )
1649  {
1650  p.setPen( foreground.value<QPen>() );
1651  }
1652 
1653  // Draw a border around all adjacent entries that have the same text as the currently hovered one
1654  const QVariant identifier = model->data( realLine, (Qt::ItemDataRole) KTextEditor::AnnotationModel::GroupIdentifierRole );
1655  if( m_hoveredAnnotationGroupIdentifier == identifier.toString() )
1656  {
1657  p.drawLine( lnX, y, lnX, y+h );
1658  p.drawLine( lnX+borderWidth, y, lnX+borderWidth, y+h );
1659 
1660  QVariant beforeText = model->data( realLine-1, Qt::DisplayRole );
1661  QVariant afterText = model->data( realLine+1, Qt::DisplayRole );
1662  if( ((beforeText.isValid() && beforeText.canConvert<QString>()
1663  && text.isValid() && text.canConvert<QString>()
1664  && beforeText.toString() != text.toString()) || realLine == 0)
1665  && m_viewInternal->cache()->viewLine(z).viewLine() == 0)
1666  {
1667  p.drawLine( lnX+1, y, lnX+borderWidth, y );
1668  }
1669 
1670  if( ((afterText.isValid() && afterText.canConvert<QString>()
1671  && text.isValid() && text.canConvert<QString>()
1672  && afterText.toString() != text.toString())
1673  || realLine == m_view->doc()->lines() - 1)
1674  && m_viewInternal->cache()->viewLine(z).viewLine() == m_viewInternal->cache()->viewLineCount(realLine)-1)
1675  {
1676  p.drawLine( lnX+1, y+h-1, lnX+borderWidth, y+h-1 );
1677  }
1678  }
1679  if( foreground.isValid() )
1680  {
1681  QPen pen = p.pen();
1682  pen.setWidth( 1 );
1683  p.setPen( pen );
1684  }
1685 
1686  // Now draw the normal text
1687  if( text.isValid() && text.canConvert<QString>() && (m_viewInternal->cache()->viewLine(z).startCol() == 0) )
1688  {
1689  p.drawText( lnX+3, y, borderWidth-3, h, Qt::AlignLeft|Qt::AlignVCenter, text.toString() );
1690  }
1691  }
1692 
1693  // adjust current X position and reset the pen and brush
1694  lnX += borderWidth + 2;
1695  }
1696 
1697  // line number
1698  if( m_lineNumbersOn || (m_view->dynWordWrap() && m_dynWrapIndicatorsOn) )
1699  {
1700  p.setPen ( m_view->renderer()->config()->lineNumberColor() );
1701  p.setBrush ( m_view->renderer()->config()->lineNumberColor() );
1702 
1703  if (realLine > -1) {
1704  if (m_viewInternal->cache()->viewLine(z).startCol() == 0) {
1705  if (m_viRelLineNumbersOn && m_view->viInputMode()) {
1706  int diff = abs(realLine - currentLine);
1707  if (diff > 0) {
1708  p.drawText( lnX + m_maxCharWidth / 2, y, lnWidth - m_maxCharWidth, h,
1709  Qt::TextDontClip|Qt::AlignRight|Qt::AlignVCenter, QString("%1").arg(diff) );
1710  } else {
1711  p.drawText( lnX + m_maxCharWidth / 2, y, lnWidth - m_maxCharWidth, h,
1712  Qt::TextDontClip|Qt::AlignLeft|Qt::AlignVCenter, QString("%1").arg(realLine + 1) );
1713  }
1714  if (m_updateViRelLineNumbers) {
1715  m_updateViRelLineNumbers = false;
1716  update();
1717  }
1718  } else if (m_lineNumbersOn) {
1719  p.drawText( lnX + m_maxCharWidth / 2, y, lnWidth - m_maxCharWidth, h,
1720  Qt::TextDontClip|Qt::AlignRight|Qt::AlignVCenter, QString("%1").arg( realLine + 1 ) );
1721  }
1722  } else if (m_view->dynWordWrap() && m_dynWrapIndicatorsOn) {
1723  p.drawPixmap(lnX + lnWidth - m_arrow.width() - 2, y, m_arrow);
1724  }
1725  }
1726 
1727  lnX += lnWidth + 2;
1728  }
1729 
1730  // folding markers
1731  if( m_foldingMarkersOn)
1732  {
1733  // first icon border background
1734  p.fillRect(lnX, y, iconPaneWidth, h, m_view->renderer()->config()->iconBarColor());
1735 
1736  // possible additional folding highlighting
1737  if ((realLine >= 0) && m_foldingRange && m_foldingRange->overlapsLine (realLine)) {
1738  p.save();
1739 
1740  // use linear gradient as brush
1741  QLinearGradient g(lnX, y, lnX + iconPaneWidth, y);
1742  const QColor foldingColor(m_view->renderer()->config()->foldingColor());
1743  g.setColorAt(0, foldingColor);
1744  g.setColorAt(0.3, foldingColor.lighter(110));
1745  g.setColorAt(1, foldingColor);
1746  p.setBrush(g);
1747  p.setPen(foldingColor);
1748 
1749  p.setClipRect(lnX, y, iconPaneWidth, h);
1750  p.setRenderHint(QPainter::Antialiasing);
1751 
1752  const qreal r = 4.0;
1753  if (m_foldingRange->start().line() == realLine &&
1754  m_viewInternal->cache()->viewLine(z).viewLine() == 0)
1755  {
1756  p.drawRect(lnX, y, iconPaneWidth, h + r);
1757  } else if (m_foldingRange->end().line() == realLine &&
1758  m_viewInternal->cache()->viewLine(z).viewLine() == m_viewInternal->cache()->viewLineCount(realLine)-1)
1759  {
1760  p.drawRect(lnX, y-r, iconPaneWidth, h + r);
1761  } else {
1762  p.drawRect(lnX, y-r, iconPaneWidth, h+2*r);
1763  }
1764  p.restore();
1765  }
1766 
1767  if ((realLine >= 0) && (m_viewInternal->cache()->viewLine(z).startCol() == 0))
1768  {
1769  QVector<QPair<qint64, Kate::TextFolding::FoldingRangeFlags> > startingRanges = m_view->textFolding().foldingRangesStartingOnLine (realLine);
1770  bool anyFolded = false;
1771  for (int i = 0; i < startingRanges.size(); ++i)
1772  if (startingRanges[i].second & Kate::TextFolding::Folded)
1773  anyFolded = true;
1774 
1775  Kate::TextLine tl = m_doc->kateTextLine(realLine);
1776 
1777  if (!startingRanges.isEmpty() || tl->markedAsFoldingStart())
1778  {
1779  if (anyFolded)
1780  {
1781  paintTriangle (p, m_view->renderer()->config()->foldingColor(), lnX, y, iconPaneWidth, h, false);
1782  }
1783  else
1784  {
1785  paintTriangle (p, m_view->renderer()->config()->foldingColor(), lnX, y, iconPaneWidth, h, true);
1786  }
1787  }
1788  }
1789 
1790  lnX += iconPaneWidth;
1791  }
1792 
1793  // modified line system
1794  if (m_view->config()->lineModification() &&
1795  realLine > -1 && !m_doc->url().isEmpty())
1796  {
1797  // one pixel space
1798  ++lnX;
1799 
1800  Kate::TextLine tl = m_doc->plainKateTextLine(realLine);
1801  if (tl->markedAsModified()) {
1802  p.fillRect(lnX, y, 3, h, m_view->renderer()->config()->modifiedLineColor());
1803  }
1804  if (tl->markedAsSavedOnDisk()) {
1805  p.fillRect(lnX, y, 3, h, m_view->renderer()->config()->savedLineColor());
1806  }
1807  }
1808  }
1809 }
1810 
1811 KateIconBorder::BorderArea KateIconBorder::positionToArea( const QPoint& p ) const
1812 {
1813  // see KateIconBorder::sizeHint() for pixel spacings
1814  int x = 0;
1815  if( m_iconBorderOn ) {
1816  x += iconPaneWidth;
1817  if( p.x() <= x )
1818  return IconBorder;
1819  x += 2;
1820  }
1821  if( this->m_annotationBorderOn ) {
1822  x += m_annotationBorderWidth;
1823  if( p.x() <= x )
1824  return AnnotationBorder;
1825  x += 2;
1826  }
1827  if( m_lineNumbersOn || m_dynWrapIndicators ) {
1828  x += lineNumberWidth();
1829  if( p.x() <= x )
1830  return LineNumbers;
1831  x += 2;
1832  }
1833  if( m_foldingMarkersOn ) {
1834  x += iconPaneWidth;
1835  if( p.x() <= x )
1836  return FoldingMarkers;
1837  }
1838  if (m_view->config()->lineModification()) {
1839  x += 3 + 2;
1840  if( p.x() <= x )
1841  return ModificationBorder;
1842  }
1843  return None;
1844 }
1845 
1846 void KateIconBorder::mousePressEvent( QMouseEvent* e )
1847 {
1848  const KateTextLayout& t = m_viewInternal->yToKateTextLayout(e->y());
1849  if (t.isValid()) {
1850  m_lastClickedLine = t.line();
1851  if ( positionToArea( e->pos() ) != IconBorder && positionToArea( e->pos() ) != AnnotationBorder )
1852  {
1853  QMouseEvent forward( QEvent::MouseButtonPress,
1854  QPoint( 0, e->y() ), e->button(), e->buttons(),e->modifiers() );
1855  m_viewInternal->mousePressEvent( &forward );
1856  }
1857  return e->accept();
1858  }
1859 
1860  QWidget::mousePressEvent(e);
1861 }
1862 
1863 void KateIconBorder::showDelayedBlock(int line)
1864 {
1865  // save the line over which the mouse hovers
1866  // either we start the timer for delay, or we show the block immediately
1867  // if the moving range already exists
1868  m_nextHighlightBlock = line;
1869  if (!m_foldingRange) {
1870  if (!m_delayFoldingHlTimer.isActive()) {
1871  m_delayFoldingHlTimer.start();
1872  }
1873  } else {
1874  showBlock();
1875  }
1876 }
1877 
1878 void KateIconBorder::showBlock()
1879 {
1880  if (m_nextHighlightBlock == m_currentBlockLine) return;
1881  m_currentBlockLine = m_nextHighlightBlock;
1882 
1887  KTextEditor::Range newRange = KTextEditor::Range::invalid();
1888  for (int line = m_currentBlockLine; line >= qMax(0, m_currentBlockLine-1024); --line) {
1892  KTextEditor::Range foldingRange = m_doc->buffer().computeFoldingRangeForStartLine (line);
1893  if (!foldingRange.isValid())
1894  continue;
1895 
1899  if (foldingRange.overlapsLine (m_currentBlockLine)) {
1900  newRange = foldingRange;
1901  break;
1902  }
1903  }
1904 
1905  if (newRange.isValid() && m_foldingRange && *m_foldingRange == newRange) {
1906  // new range equals the old one, nothing to do.
1907  return;
1908  } else { // the ranges differ, delete the old, if it exists
1909  delete m_foldingRange;
1910  m_foldingRange = 0;
1911  }
1912 
1913  if (newRange.isValid()) {
1914  kDebug(13025) << "new folding hl-range:" << newRange;
1915  m_foldingRange = m_doc->newMovingRange(newRange, KTextEditor::MovingRange::ExpandRight);
1916  KTextEditor::Attribute::Ptr attr(new KTextEditor::Attribute());
1917 
1921  QColor result = m_view->renderer()->config()->foldingColor();
1922  result.setAlphaF (0.5);
1923  attr->setBackground(QBrush( result ));
1924 
1925  m_foldingRange->setView (m_view);
1926  // use z depth defined in moving ranges interface
1927  m_foldingRange->setZDepth (-100.0);
1928  m_foldingRange->setAttribute(attr);
1929  }
1930 
1934  repaint ();
1935 }
1936 
1937 void KateIconBorder::hideBlock()
1938 {
1939  if (m_delayFoldingHlTimer.isActive()) {
1940  m_delayFoldingHlTimer.stop();
1941  }
1942 
1943  m_nextHighlightBlock = -2;
1944  m_currentBlockLine = -1;
1945  delete m_foldingRange;
1946  m_foldingRange = 0;
1947 }
1948 
1949 void KateIconBorder::leaveEvent(QEvent *event)
1950 {
1951  hideBlock();
1952  removeAnnotationHovering();
1953 
1954  QWidget::leaveEvent(event);
1955 }
1956 
1957 void KateIconBorder::mouseMoveEvent( QMouseEvent* e )
1958 {
1959  const KateTextLayout& t = m_viewInternal->yToKateTextLayout(e->y());
1960  if (t.isValid()) {
1961  if ( positionToArea( e->pos() ) == FoldingMarkers) showDelayedBlock(t.line());
1962  else hideBlock();
1963  if ( positionToArea( e->pos() ) == AnnotationBorder )
1964  {
1965  KTextEditor::AnnotationModel *model = m_view->annotationModel() ?
1966  m_view->annotationModel() : m_doc->annotationModel();
1967  if (model)
1968  {
1969  m_hoveredAnnotationGroupIdentifier = model->data( t.line(),
1970  (Qt::ItemDataRole) KTextEditor::AnnotationModel::GroupIdentifierRole ).toString();
1971  showAnnotationTooltip( t.line(), e->globalPos() );
1972  QTimer::singleShot( 0, this, SLOT(update()) );
1973  }
1974  }
1975  else
1976  {
1977  if( positionToArea( e->pos() ) == IconBorder )
1978  m_doc->requestMarkTooltip( t.line(), e->globalPos() );
1979 
1980  m_hoveredAnnotationGroupIdentifier.clear();
1981  hideAnnotationTooltip();
1982  QTimer::singleShot( 0, this, SLOT(update()) );
1983  }
1984  if ( positionToArea( e->pos() ) != IconBorder )
1985  {
1986  QPoint p = m_viewInternal->mapFromGlobal( e->globalPos() );
1987  QMouseEvent forward( QEvent::MouseMove, p, e->button(), e->buttons(), e->modifiers() );
1988  m_viewInternal->mouseMoveEvent( &forward );
1989  }
1990  }
1991  else
1992  {
1993  // remove hovering if it's still there
1994  removeAnnotationHovering();
1995  }
1996 
1997  QWidget::mouseMoveEvent(e);
1998 }
1999 
2000 void KateIconBorder::mouseReleaseEvent( QMouseEvent* e )
2001 {
2002  int cursorOnLine = m_viewInternal->yToKateTextLayout(e->y()).line();
2003 
2004  if (cursorOnLine == m_lastClickedLine &&
2005  cursorOnLine <= m_doc->lastLine() )
2006  {
2007  BorderArea area = positionToArea( e->pos() );
2008  if( area == IconBorder) {
2009  if (e->button() == Qt::LeftButton) {
2010  if( !m_doc->handleMarkClick(cursorOnLine) ) {
2011  KateViewConfig *config = m_view->config();
2012  if( m_doc->editableMarks() & config->defaultMarkType() ) {
2013  if( m_doc->mark( cursorOnLine ) & config->defaultMarkType() )
2014  m_doc->removeMark( cursorOnLine, config->defaultMarkType() );
2015  else
2016  m_doc->addMark( cursorOnLine, config->defaultMarkType() );
2017  } else if (config->allowMarkMenu()) {
2018  showMarkMenu( cursorOnLine, QCursor::pos() );
2019  }
2020  }
2021  }
2022  else
2023  if (e->button() == Qt::RightButton) {
2024  showMarkMenu( cursorOnLine, QCursor::pos() );
2025  }
2026  }
2027 
2028  if ( area == FoldingMarkers) {
2029  // ask the folding info for this line, if any folds are around!
2030  QVector<QPair<qint64, Kate::TextFolding::FoldingRangeFlags> > startingRanges = m_view->textFolding().foldingRangesStartingOnLine (cursorOnLine);
2031  bool anyFolded = false;
2032  for (int i = 0; i < startingRanges.size(); ++i)
2033  if (startingRanges[i].second & Kate::TextFolding::Folded)
2034  anyFolded = true;
2035 
2036  // fold or unfold all ranges, remember if any action happened!
2037  bool actionDone = false;
2038  for (int i = 0; i < startingRanges.size(); ++i)
2039  actionDone = (anyFolded ? m_view->textFolding().unfoldRange (startingRanges[i].first) : m_view->textFolding().foldRange (startingRanges[i].first)) || actionDone;
2040 
2041  // if no action done, try to fold it, create non-persistent folded range, if possible!
2042  if (!actionDone) {
2043  // either use the fold for this line or the range that is highlighted ATM if any!
2044  KTextEditor::Range foldingRange = m_view->doc()->buffer().computeFoldingRangeForStartLine (cursorOnLine);
2045  if (!foldingRange.isValid() && m_foldingRange)
2046  foldingRange = m_foldingRange->toRange ();
2047  m_view->textFolding().newFoldingRange (foldingRange, Kate::TextFolding::Folded);
2048  }
2049  }
2050 
2051  if ( area == AnnotationBorder ) {
2052  if( e->button() == Qt::LeftButton && KGlobalSettings::singleClick() ) {
2053  emit m_view->annotationActivated( m_view, cursorOnLine );
2054  } else if ( e->button() == Qt::RightButton ) {
2055  showAnnotationMenu( cursorOnLine, e->globalPos() );
2056  }
2057  }
2058  }
2059 
2060  QMouseEvent forward( QEvent::MouseButtonRelease,
2061  QPoint( 0, e->y() ), e->button(), e->buttons(),e->modifiers() );
2062  m_viewInternal->mouseReleaseEvent( &forward );
2063 }
2064 
2065 void KateIconBorder::mouseDoubleClickEvent( QMouseEvent* e )
2066 {
2067  int cursorOnLine = m_viewInternal->yToKateTextLayout(e->y()).line();
2068 
2069  if (cursorOnLine == m_lastClickedLine &&
2070  cursorOnLine <= m_doc->lastLine() )
2071  {
2072  BorderArea area = positionToArea( e->pos() );
2073  if( area == AnnotationBorder && !KGlobalSettings::singleClick() ) {
2074  emit m_view->annotationActivated( m_view, cursorOnLine );
2075  }
2076  }
2077  QMouseEvent forward( QEvent::MouseButtonDblClick,
2078  QPoint( 0, e->y() ), e->button(), e->buttons(),e->modifiers() );
2079  m_viewInternal->mouseDoubleClickEvent( &forward );
2080 }
2081 
2082 void KateIconBorder::wheelEvent(QWheelEvent *e)
2083 {
2084  QCoreApplication::sendEvent(m_viewInternal, e);
2085 }
2086 
2087 void KateIconBorder::showMarkMenu( uint line, const QPoint& pos )
2088 {
2089  if( m_doc->handleMarkContextMenu( line, pos ) )
2090  return;
2091 
2092  if( !m_view->config()->allowMarkMenu() )
2093  return;
2094 
2095  KMenu markMenu;
2096  KMenu selectDefaultMark;
2097 
2098  QVector<int> vec( 33 );
2099  int i=1;
2100 
2101  for( uint bit = 0; bit < 32; bit++ ) {
2102  MarkInterface::MarkTypes markType = (MarkInterface::MarkTypes)(1<<bit);
2103  if( !(m_doc->editableMarks() & markType) )
2104  continue;
2105 
2106  QAction *mA;
2107  QAction *dMA;
2108  if( !m_doc->markDescription( markType ).isEmpty() ) {
2109  mA=markMenu.addAction( m_doc->markDescription( markType ));
2110  dMA=selectDefaultMark.addAction( m_doc->markDescription( markType ));
2111  } else {
2112  mA=markMenu.addAction( i18n("Mark Type %1", bit + 1 ));
2113  dMA=selectDefaultMark.addAction( i18n("Mark Type %1", bit + 1 ));
2114  }
2115  mA->setData(i);
2116  mA->setCheckable(true);
2117  dMA->setData(i+100);
2118  dMA->setCheckable(true);
2119  if( m_doc->mark( line ) & markType )
2120  mA->setChecked(true );
2121 
2122  if( markType & KateViewConfig::global()->defaultMarkType() )
2123  dMA->setChecked(true );
2124 
2125  vec[i++] = markType;
2126  }
2127 
2128  if( markMenu.actions().count() == 0 )
2129  return;
2130 
2131  if( markMenu.actions().count() > 1 )
2132  markMenu.addAction( i18n("Set Default Mark Type" ))->setMenu(&selectDefaultMark);
2133 
2134  QAction *rA = markMenu.exec( pos );
2135  if( !rA )
2136  return;
2137  int result=rA->data().toInt();
2138  if ( result > 100)
2139  {
2140  KateViewConfig::global()->setDefaultMarkType (vec[result-100]);
2141  // flush config, otherwise it isn't necessarily done
2142  KConfigGroup cg(KGlobal::config(), "Kate View Defaults");
2143  KateViewConfig::global()->writeConfig(cg);
2144  }
2145  else
2146  {
2147  MarkInterface::MarkTypes markType = (MarkInterface::MarkTypes) vec[result];
2148  if( m_doc->mark( line ) & markType ) {
2149  m_doc->removeMark( line, markType );
2150  } else {
2151  m_doc->addMark( line, markType );
2152  }
2153  }
2154 }
2155 
2156 void KateIconBorder::showAnnotationTooltip( int line, const QPoint& pos )
2157 {
2158  KTextEditor::AnnotationModel *model = m_view->annotationModel() ?
2159  m_view->annotationModel() : m_doc->annotationModel();
2160 
2161  if( model )
2162  {
2163  QVariant data = model->data( line, Qt::ToolTipRole );
2164  QString tip = data.toString();
2165  if (!tip.isEmpty())
2166  QToolTip::showText( pos, data.toString(), this );
2167  }
2168 }
2169 
2170 
2171 int KateIconBorder::annotationLineWidth( int line )
2172 {
2173  KTextEditor::AnnotationModel *model = m_view->annotationModel() ?
2174  m_view->annotationModel() : m_doc->annotationModel();
2175 
2176  if( model )
2177  {
2178  QVariant data = model->data( line, Qt::DisplayRole );
2179  return data.toString().length() * m_maxCharWidth + 8;
2180  }
2181  return 8;
2182 }
2183 
2184 void KateIconBorder::updateAnnotationLine( int line )
2185 {
2186  if( annotationLineWidth(line) > m_annotationBorderWidth )
2187  {
2188  m_annotationBorderWidth = annotationLineWidth(line);
2189  updateGeometry();
2190 
2191  QTimer::singleShot( 0, this, SLOT(update()) );
2192  }
2193 }
2194 
2195 void KateIconBorder::showAnnotationMenu( int line, const QPoint& pos)
2196 {
2197  KMenu menu;
2198  QAction a(i18n("Disable Annotation Bar"), &menu);
2199  a.setIcon(KIcon("dialog-close"));
2200  menu.addAction(&a);
2201  emit m_view->annotationContextMenuAboutToShow( m_view, &menu, line );
2202  if (menu.exec(pos) == &a)
2203  m_view->setAnnotationBorderVisible(false);
2204 }
2205 
2206 void KateIconBorder::hideAnnotationTooltip()
2207 {
2208  QToolTip::hideText();
2209 }
2210 
2211 void KateIconBorder::updateAnnotationBorderWidth( )
2212 {
2213  m_annotationBorderWidth = 6;
2214  KTextEditor::AnnotationModel *model = m_view->annotationModel() ?
2215  m_view->annotationModel() : m_doc->annotationModel();
2216 
2217  if( model ) {
2218  for( int i = 0; i < m_view->doc()->lines(); i++ ) {
2219  int curwidth = annotationLineWidth( i );
2220  if( curwidth > m_annotationBorderWidth )
2221  m_annotationBorderWidth = curwidth;
2222  }
2223  }
2224 
2225  updateGeometry();
2226 
2227  QTimer::singleShot( 0, this, SLOT(update()) );
2228 }
2229 
2230 
2231 
2232 void KateIconBorder::annotationModelChanged( KTextEditor::AnnotationModel * oldmodel, KTextEditor::AnnotationModel * newmodel )
2233 {
2234  if( oldmodel )
2235  {
2236  oldmodel->disconnect( this );
2237  }
2238  if( newmodel )
2239  {
2240  connect( newmodel, SIGNAL(reset()), this, SLOT(updateAnnotationBorderWidth()) );
2241  connect( newmodel, SIGNAL(lineChanged(int)), this, SLOT(updateAnnotationLine(int)) );
2242  }
2243  updateAnnotationBorderWidth();
2244 }
2245 
2246 //END KateIconBorder
2247 
2248 //BEGIN KateViewEncodingAction
2249 // Acording to http://www.iana.org/assignments/ianacharset-mib
2250 // the default/unknown mib value is 2.
2251 #define MIB_DEFAULT 2
2252 
2253 class KateViewEncodingAction::Private
2254 {
2255  public:
2256  Private(KateViewEncodingAction *parent)
2257  : q(parent),
2258  currentSubAction(0)
2259  {
2260  }
2261 
2262  void init();
2263 
2264  void _k_subActionTriggered(QAction*);
2265 
2266  KateViewEncodingAction *q;
2267  QAction *currentSubAction;
2268 };
2269 
2270 bool lessThanAction(KSelectAction *a, KSelectAction *b)
2271 {
2272  return a->text() < b->text();
2273 }
2274 
2275 void KateViewEncodingAction::Private::init()
2276 {
2277  QList<KSelectAction *> actions;
2278 
2279  q->setToolBarMode(MenuMode);
2280 
2281  int i;
2282  foreach(const QStringList &encodingsForScript, KGlobal::charsets()->encodingsByScript())
2283  {
2284  KSelectAction* tmp = new KSelectAction(encodingsForScript.at(0),q);
2285 
2286  for (i=1; i<encodingsForScript.size(); ++i)
2287  {
2288  tmp->addAction(encodingsForScript.at(i));
2289  }
2290  q->connect(tmp,SIGNAL(triggered(QAction*)),q,SLOT(_k_subActionTriggered(QAction*)));
2291  //tmp->setCheckable(true);
2292  actions << tmp;
2293  }
2294  qSort(actions.begin(), actions.end(), lessThanAction);
2295  foreach (KSelectAction *action, actions)
2296  q->addAction(action);
2297 }
2298 
2299 void KateViewEncodingAction::Private::_k_subActionTriggered(QAction *action)
2300 {
2301  if (currentSubAction==action)
2302  return;
2303  currentSubAction=action;
2304  bool ok = false;
2305  int mib = q->mibForName(action->text(), &ok);
2306  if (ok)
2307  {
2308  emit q->KSelectAction::triggered(action->text());
2309  emit q->triggered(q->codecForMib(mib));
2310  }
2311 }
2312 
2313 KateViewEncodingAction::KateViewEncodingAction(KateDocument *_doc, KateView *_view, const QString& text, QObject *parent)
2314 : KSelectAction(text, parent), doc(_doc), view (_view), d(new Private(this))
2315 {
2316  d->init();
2317 
2318  connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow()));
2319  connect(this,SIGNAL(triggered(QString)),this,SLOT(setEncoding(QString)));
2320 }
2321 
2322 KateViewEncodingAction::~KateViewEncodingAction()
2323 {
2324  delete d;
2325 }
2326 
2327 void KateViewEncodingAction::slotAboutToShow()
2328 {
2329  setCurrentCodec(doc->config()->encoding());
2330 }
2331 
2332 void KateViewEncodingAction::setEncoding (const QString &e)
2333 {
2334  doc->userSetEncodingForNextReload ();
2335  doc->setEncoding(e);
2336  view->reloadFile();
2337 }
2338 
2339 int KateViewEncodingAction::mibForName(const QString &codecName, bool *ok) const
2340 {
2341  // FIXME logic is good but code is ugly
2342 
2343  bool success = false;
2344  int mib = MIB_DEFAULT;
2345  KCharsets *charsets = KGlobal::charsets();
2346 
2347  QTextCodec *codec = charsets->codecForName(codecName, success);
2348  if (!success)
2349  {
2350  // Maybe we got a description name instead
2351  codec = charsets->codecForName(charsets->encodingForName(codecName), success);
2352  }
2353 
2354  if (codec)
2355  mib = codec->mibEnum();
2356 
2357  if (ok)
2358  *ok = success;
2359 
2360  if (success)
2361  return mib;
2362 
2363  kWarning() << "Invalid codec name: " << codecName;
2364  return MIB_DEFAULT;
2365 }
2366 
2367 QTextCodec *KateViewEncodingAction::codecForMib(int mib) const
2368 {
2369  if (mib == MIB_DEFAULT)
2370  {
2371  // FIXME offer to change the default codec
2372  return QTextCodec::codecForLocale();
2373  }
2374  else
2375  return QTextCodec::codecForMib(mib);
2376 }
2377 
2378 QTextCodec *KateViewEncodingAction::currentCodec() const
2379 {
2380  return codecForMib(currentCodecMib());
2381 }
2382 
2383 bool KateViewEncodingAction::setCurrentCodec( QTextCodec *codec )
2384 {
2385  disconnect(this,SIGNAL(triggered(QString)),this,SLOT(setEncoding(QString)));
2386 
2387  int i,j;
2388  for (i=0;i<actions().size();++i)
2389  {
2390  if (actions().at(i)->menu())
2391  {
2392  for (j=0;j<actions().at(i)->menu()->actions().size();++j)
2393  {
2394  if (!j && !actions().at(i)->menu()->actions().at(j)->data().isNull())
2395  continue;
2396  if (actions().at(i)->menu()->actions().at(j)->isSeparator())
2397  continue;
2398 
2399  if (codec==KGlobal::charsets()->codecForName(actions().at(i)->menu()->actions().at(j)->text()))
2400  {
2401  d->currentSubAction=actions().at(i)->menu()->actions().at(j);
2402  d->currentSubAction->setChecked(true);
2403  }
2404  else
2405  actions().at(i)->menu()->actions().at(j)->setChecked (false);
2406  }
2407  }
2408  }
2409 
2410  connect(this,SIGNAL(triggered(QString)),this,SLOT(setEncoding(QString)));
2411  return true;
2412 }
2413 
2414 QString KateViewEncodingAction::currentCodecName() const
2415 {
2416  return d->currentSubAction->text();
2417 }
2418 
2419 bool KateViewEncodingAction::setCurrentCodec( const QString &codecName )
2420 {
2421  return setCurrentCodec(KGlobal::charsets()->codecForName(codecName));
2422 }
2423 
2424 int KateViewEncodingAction::currentCodecMib() const
2425 {
2426  return mibForName(currentCodecName());
2427 }
2428 
2429 bool KateViewEncodingAction::setCurrentCodec( int mib )
2430 {
2431  return setCurrentCodec(codecForMib(mib));
2432 }
2433 //END KateViewEncodingAction
2434 
2435 //BEGIN KateViewBar related classes
2436 
2437 KateViewBarWidget::KateViewBarWidget (bool addCloseButton, QWidget *parent)
2438  : QWidget (parent)
2439  , m_viewBar(0)
2440 {
2441  QHBoxLayout *layout = new QHBoxLayout (this);
2442 
2443  // NOTE: Here be cosmetics.
2444  layout->setMargin(0);
2445 
2446  // hide button
2447  if (addCloseButton) {
2448  QToolButton *hideButton = new QToolButton(this);
2449  hideButton->setAutoRaise(true);
2450  hideButton->setIcon(KIcon("dialog-close"));
2451  connect(hideButton, SIGNAL(clicked()), SIGNAL(hideMe()));
2452  layout->addWidget(hideButton);
2453  layout->setAlignment( hideButton, Qt::AlignLeft|Qt::AlignTop );
2454  }
2455 
2456  // widget to be used as parent for the real content
2457  m_centralWidget = new QWidget (this);
2458  layout->addWidget(m_centralWidget);
2459 
2460  setLayout(layout);
2461  setFocusProxy(m_centralWidget);
2462 }
2463 
2464 
2465 KateViewBar::KateViewBar (bool external,KTextEditor::ViewBarContainer::Position pos,QWidget *parent, KateView *view)
2466  : QWidget (parent), m_external(external), m_pos(pos),m_view (view), m_permanentBarWidget(0)
2467 
2468 {
2469  m_layout = new QVBoxLayout(this);
2470  m_stack = new QStackedWidget(this);
2471  m_layout->addWidget(m_stack);
2472  m_layout->setMargin(0);
2473 
2474  m_stack->hide();
2475  hide ();
2476 }
2477 
2478 void KateViewBar::addBarWidget (KateViewBarWidget *newBarWidget)
2479 {
2480  if (hasBarWidget(newBarWidget)) {
2481  kDebug(13025) << "this bar widget is already added";
2482  return;
2483  }
2484  // add new widget, invisible...
2485  newBarWidget->hide();
2486  m_stack->addWidget (newBarWidget);
2487  newBarWidget->setAssociatedViewBar(this);
2488  connect(newBarWidget, SIGNAL(hideMe()), SLOT(hideCurrentBarWidget()));
2489 
2490  kDebug(13025)<<"add barwidget " << newBarWidget;
2491 }
2492 
2493 void KateViewBar::removeBarWidget (KateViewBarWidget *barWidget)
2494 {
2495  if (hasBarWidget(barWidget)) {
2496  m_stack->removeWidget(barWidget);
2497  barWidget->setAssociatedViewBar(0);
2498  barWidget->hide();
2499  disconnect(barWidget, 0, this, 0);
2500  }
2501 }
2502 
2503 void KateViewBar::addPermanentBarWidget (KateViewBarWidget *barWidget)
2504 {
2505  // remove old widget from layout (if any)
2506  if (m_permanentBarWidget) {
2507  m_permanentBarWidget->hide();
2508  m_layout->removeWidget(m_permanentBarWidget);
2509  }
2510 
2511  m_layout->addWidget(barWidget, 0, Qt::AlignBottom);
2512  m_permanentBarWidget = barWidget;
2513  m_permanentBarWidget->show();
2514 
2515  setViewBarVisible(true);
2516 }
2517 
2518 void KateViewBar::removePermanentBarWidget (KateViewBarWidget *barWidget)
2519 {
2520  if (m_permanentBarWidget != barWidget) {
2521  kDebug(13025) << "no such permanent widget exists in bar";
2522  return;
2523  }
2524 
2525  if (!m_permanentBarWidget)
2526  return;
2527 
2528  m_permanentBarWidget->hide();
2529  m_layout->removeWidget(m_permanentBarWidget);
2530  m_permanentBarWidget = 0;
2531 
2532  if (!m_stack->isVisible()) {
2533  setViewBarVisible(false);
2534  }
2535 }
2536 
2537 bool KateViewBar::hasPermanentWidget (KateViewBarWidget *barWidget ) const
2538 {
2539  return (m_permanentBarWidget == barWidget);
2540 }
2541 
2542 void KateViewBar::showBarWidget (KateViewBarWidget *barWidget)
2543 {
2544  Q_ASSERT(barWidget != 0);
2545 
2546  if (barWidget != qobject_cast<KateViewBarWidget*>(m_stack->currentWidget())) {
2547  hideCurrentBarWidget();
2548  }
2549 
2550  // raise correct widget
2551  m_stack->setCurrentWidget (barWidget);
2552  barWidget->show();
2553  barWidget->setFocus(Qt::ShortcutFocusReason);
2554  m_stack->show();
2555 
2556  // if we have any permanent widget, bar is always visible,
2557  // no need to show it
2558  if (!m_permanentBarWidget) {
2559  setViewBarVisible(true);
2560  }
2561 }
2562 
2563 bool KateViewBar::hasBarWidget(KateViewBarWidget* barWidget) const
2564 {
2565  return m_stack->indexOf(barWidget) != -1;
2566 }
2567 
2568 void KateViewBar::hideCurrentBarWidget ()
2569 {
2570  KateViewBarWidget *current=qobject_cast<KateViewBarWidget*>(m_stack->currentWidget());
2571  if (current) {
2572  current->closed();
2573  }
2574  m_stack->hide();
2575 
2576  // if we have any permanent widget, bar is always visible,
2577  // no need to hide it
2578  if (!m_permanentBarWidget) {
2579  setViewBarVisible(false);
2580  }
2581 
2582  m_view->setFocus();
2583  kDebug(13025)<<"hide barwidget";
2584 }
2585 
2586 void KateViewBar::setViewBarVisible (bool visible)
2587 {
2588  if (m_external) {
2589  KTextEditor::ViewBarContainer *viewBarContainer=qobject_cast<KTextEditor::ViewBarContainer*>( KateGlobal::self()->container() );
2590  if (viewBarContainer) {
2591  if (visible) {
2592  viewBarContainer->showViewBarForView(m_view,m_pos);
2593  } else {
2594  viewBarContainer->hideViewBarForView(m_view,m_pos);
2595  }
2596  }
2597  } else {
2598  setVisible (visible);
2599  }
2600 }
2601 
2602 void KateViewBar::keyPressEvent(QKeyEvent* event)
2603 {
2604  if (event->key() == Qt::Key_Escape) {
2605  hideCurrentBarWidget();
2606  return;
2607  }
2608  QWidget::keyPressEvent(event);
2609 
2610 }
2611 
2612 void KateViewBar::hideEvent(QHideEvent* event)
2613 {
2614  Q_UNUSED(event);
2615 // if (!event->spontaneous())
2616 // m_view->setFocus();
2617 }
2618 
2619 //END KateViewBar related classes
2620 
2621 KatePasteMenu::KatePasteMenu (const QString& text, KateView *view)
2622  : KActionMenu(text, view)
2623  , m_view (view)
2624 {
2625  connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow()));
2626 }
2627 
2628 void KatePasteMenu::slotAboutToShow()
2629 {
2630  menu()->clear ();
2631 
2635  int i = 0;
2636  Q_FOREACH (const QString &text, KateGlobal::self()->clipboardHistory()) {
2640  QString leftPart = (text.size() > 48) ? (text.left(48) + "...") : text;
2641  QAction *a=menu()->addAction (leftPart.replace ("\n", " "), this, SLOT(paste()));
2642  a->setData(i++);
2643  }
2644 }
2645 
2646 void KatePasteMenu::paste ()
2647 {
2648  if (!sender())
2649  return;
2650 
2651  QAction *action = qobject_cast<QAction*>(sender());
2652  if (!action)
2653  return;
2654 
2655  // get index
2656  int i = action->data().toInt();
2657  if (i >= KateGlobal::self()->clipboardHistory().size())
2658  return;
2659 
2660  // paste
2661  m_view->paste (&KateGlobal::self()->clipboardHistory()[i]);
2662 }
2663 
2664 
2665 #include "kateviewhelpers.moc"
2666 
2667 // kate: space-indent on; indent-width 2; replace-tabs on;
2668 
QWidget::layout
QLayout * layout() const
QHideEvent
KateDocument::line
virtual QString line(int line) const
Definition: katedocument.cpp:447
QAction::text
text
KateView::annotationActivated
void annotationActivated(KTextEditor::View *view, int line)
QVariant::canConvert
bool canConvert(Type t) const
QTimer::setInterval
void setInterval(int msec)
KateDocument::buffer
KateBuffer & buffer()
Get access to buffer of this document.
Definition: katedocument.h:946
KateIconBorder::None
Definition: kateviewhelpers.h:182
QWhatsThis::showText
void showText(const QPoint &pos, const QString &text, QWidget *w)
KateDocument::config
KateDocumentConfig * config()
Configuration.
Definition: katedocument.h:1009
QEvent
QPixmap::size
QSize size() const
QResizeEvent
KateCmd::historyLength
uint historyLength() const
Definition: katecmd.h:50
QWidget
QAction::triggered
void triggered(bool checked)
QKeyEvent::modifiers
Qt::KeyboardModifiers modifiers() const
QRegExp::cap
QString cap(int nth) const
kateview.h
QScrollBar::sizeHint
virtual QSize sizeHint() const
KateTextLayout::startCol
int startCol() const
Definition: katetextlayout.cpp:127
QEvent::type
Type type() const
Kate::Script::i18n
QScriptValue i18n(QScriptContext *context, QScriptEngine *engine)
i18n("text", arguments [optional])
Definition: katescripthelpers.cpp:186
QWidget::palette
const QPalette & palette() const
QHash::insert
iterator insert(const Key &key, const T &value)
KateIconBorder::updateFont
void updateFont()
Definition: kateviewhelpers.cpp:1421
KateViewBar::addBarWidget
void addBarWidget(KateViewBarWidget *newBarWidget)
Adds a widget to this viewbar.
Definition: kateviewhelpers.cpp:2478
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:4741
KateViewInternal::startPos
KTextEditor::Cursor startPos() const
Definition: kateviewinternal.h:125
QPixmap::width
int width() const
KateViewEncodingAction::KateViewEncodingAction
KateViewEncodingAction(KateDocument *_doc, KateView *_view, const QString &text, QObject *parent)
Definition: kateviewhelpers.cpp:2313
QPainter::fillRect
void fillRect(const QRectF &rectangle, const QBrush &brush)
KateView::renderer
KateRenderer * renderer()
Definition: kateview.cpp:1664
katerenderer.h
KateGlobal::container
QObject * container()
Get the currently associated Container object.
Definition: kateglobal.cpp:519
KateTextLayout::line
int line() const
Definition: katetextlayout.cpp:93
QPainter::setRenderHint
void setRenderHint(RenderHint hint, bool on)
QStackedWidget::currentWidget
QWidget * currentWidget() const
KateBuffer::ensureHighlighted
void ensureHighlighted(int line, int lookAhead=64)
Update highlighting of given line line, if needed.
Definition: katebuffer.cpp:284
QWidget::updateGeometry
void updateGeometry()
KateViewInternal::mouseDoubleClickEvent
virtual void mouseDoubleClickEvent(QMouseEvent *)
Definition: kateviewinternal.cpp:2641
KateWildcardMatcher::exactMatch
bool exactMatch(const QString &candidate, const QString &wildcard, int candidatePosFromRight, int wildcardPosFromRight, bool caseSensitive=true)
Definition: katewildcardmatcher.cpp:29
QPixmap::fill
void fill(const QColor &color)
lessThanAction
bool lessThanAction(KSelectAction *a, KSelectAction *b)
Definition: kateviewhelpers.cpp:2270
KateIconBorder::setAnnotationBorderOn
void setAnnotationBorderOn(bool enable)
Definition: kateviewhelpers.cpp:1303
QHashIterator::key
const Key & key() const
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:244
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
Kate::Script::i18nc
QScriptValue i18nc(QScriptContext *context, QScriptEngine *engine)
i18nc("context", "text", arguments [optional])
Definition: katescripthelpers.cpp:210
QScrollBar::initStyleOption
void initStyleOption(QStyleOptionSlider *option) const
QSize::isEmpty
bool isEmpty() const
KateDocument::handleMarkClick
bool handleMarkClick(int line)
Returns true if the click on the mark should not be further processed.
Definition: katedocument.cpp:1762
QChar
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
KateViewConfig::lineModification
bool lineModification() const
Definition: kateconfig.cpp:1636
QAction::setChecked
void setChecked(bool)
QColor::value
int value() const
QHashIterator::hasNext
bool hasNext() const
QAction::data
QVariant data() const
QWidget::style
QStyle * style() const
QStyle::pixelMetric
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const =0
KateCommandLineBar::setText
void setText(const QString &text, bool selected=true)
Definition: kateviewhelpers.cpp:839
QHash::size
int size() const
QMouseEvent::y
int y() const
KateIconBorder::IconBorder
Definition: kateviewhelpers.h:182
KateViewBar::KateViewBar
KateViewBar(bool external, KTextEditor::ViewBarContainer::Position pos, QWidget *parent, KateView *view)
Definition: kateviewhelpers.cpp:2465
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
QPalette::color
const QColor & color(ColorGroup group, ColorRole role) const
QList::at
const T & at(int i) const
KateRenderer::attribute
KTextEditor::Attribute::Ptr attribute(uint pos) const
This takes an in index, and returns all the attributes for it.
Definition: katerenderer.cpp:79
KateTextLayout::isValid
bool isValid() const
Definition: katetextlayout.cpp:88
QString::size
int size() const
QWheelEvent
katedocument.h
KateViewBar::removePermanentBarWidget
void removePermanentBarWidget(KateViewBarWidget *barWidget)
Removes permanent bar widget from viewbar.
Definition: kateviewhelpers.cpp:2518
QWidget::y
int y() const
KateViewInternal::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *)
Definition: kateviewinternal.cpp:2736
QWidget::isVisible
bool isVisible() const
KateViewBar::hideEvent
virtual void hideEvent(QHideEvent *event)
Definition: kateviewhelpers.cpp:2612
KateRendererConfig::iconBarColor
const QColor & iconBarColor() const
Definition: kateconfig.cpp:2508
QScrollBar::mousePressEvent
virtual void mousePressEvent(QMouseEvent *e)
KateDocument::defaultStyle
virtual KTextEditor::Attribute::Ptr defaultStyle(const KTextEditor::HighlightInterface::DefaultStyle ds) const
Definition: katedocument.cpp:5348
KateDocument::annotationModel
virtual KTextEditor::AnnotationModel * annotationModel() const
Definition: katedocument.cpp:4799
QHBoxLayout
QScrollBar
QWidget::setAttribute
void setAttribute(Qt::WidgetAttribute attribute, bool on)
QVariant::value
T value() const
QWidget::visibleRect
QRect visibleRect() const
KatePasteMenu::KatePasteMenu
KatePasteMenu(const QString &text, KateView *view)
Definition: kateviewhelpers.cpp:2621
KateViewEncodingAction::mibForName
int mibForName(const QString &codecName, bool *ok=0) const
Definition: kateviewhelpers.cpp:2339
QPen::setJoinStyle
void setJoinStyle(Qt::PenJoinStyle style)
QColor::setAlpha
void setAlpha(int alpha)
QPainterPath::moveTo
void moveTo(const QPointF &point)
QRect::height
int height() const
QBrush
KateIconBorder::lineNumberWidth
int lineNumberWidth() const
Definition: kateviewhelpers.cpp:1440
KateCmdLineEdit::KateCmdLineEdit
KateCmdLineEdit(KateCommandLineBar *bar, KateView *view)
Definition: kateviewhelpers.cpp:852
QRect::x
int x() const
QRect::y
int y() const
QStyle::subControlRect
virtual QRect subControlRect(ComplexControl control, const QStyleOptionComplex *option, SubControl subControl, const QWidget *widget) const =0
QAbstractSlider::pageStep
int pageStep() const
s_linePixelIncLimit
static const int s_linePixelIncLimit
Definition: kateviewhelpers.cpp:85
KateGlobal::self
static KateGlobal * self()
Kate Part Internal stuff ;)
Definition: kateglobal.cpp:465
QPoint
KateDocument::userSetEncodingForNextReload
void userSetEncodingForNextReload()
User did set encoding for next reload => enforce it!
Definition: katedocument.h:960
QMouseEvent
QStringList::join
QString join(const QString &separator) const
QMouseEvent::buttons
Qt::MouseButtons buttons() const
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:2529
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:3068
QLinearGradient
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
s_pixelMargin
static const int s_pixelMargin
Definition: kateviewhelpers.cpp:84
QToolTip::showText
void showText(const QPoint &pos, const QString &text, QWidget *w)
KateDocument::plainKateTextLine
Kate::TextLine plainKateTextLine(uint i)
Definition: katedocument.cpp:4712
QColor::hue
int hue() const
QAbstractButton::setIcon
void setIcon(const QIcon &icon)
QScrollBar::paintEvent
virtual void paintEvent(QPaintEvent *)
QScrollBar::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *e)
QFontMetricsF::width
qreal width(const QString &text) const
QColor::getHsl
void getHsl(int *h, int *s, int *l, int *a) const
QWidget::update
void update()
QTextCodec::codecForLocale
QTextCodec * codecForLocale()
QPoint::x
int x() const
QPoint::y
int y() const
KateView::getViInputModeManager
KateViInputModeManager * getViInputModeManager()
Definition: kateview.cpp:1587
Kate::TextFolding::foldRange
bool foldRange(qint64 id)
Fold the given range.
Definition: katetextfolding.cpp:168
QList::size
int size() const
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
QString::isNull
bool isNull() const
kateviewhelpers.h
katebuffer.h
Kate::TextFolding::unfoldRange
bool unfoldRange(qint64 id, bool remove=false)
Unfold the given range.
Definition: katetextfolding.cpp:191
QPointF
KateRendererConfig::lineNumberColor
const QColor & lineNumberColor() const
Definition: kateconfig.cpp:2582
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
QColor::lightness
int lightness() const
QString::clear
void clear()
KateViewInternal::yToKateTextLayout
KateTextLayout yToKateTextLayout(int y) const
Definition: kateviewinternal.cpp:312
KateViewBarWidget::KateViewBarWidget
KateViewBarWidget(bool addCloseButton, QWidget *parent=0)
Definition: kateviewhelpers.cpp:2437
QWidget::width
int width() const
KSelectAction
KateView::selectionRange
virtual const KTextEditor::Range & selectionRange() const
Definition: kateview.cpp:2815
KateRendererConfig::modifiedLineColor
const QColor & modifiedLineColor() const
Definition: kateconfig.cpp:2645
QPaintEvent::rect
const QRect & rect() const
KateViewBarWidget
Definition: kateviewhelpers.h:294
QRegExp::indexIn
int indexIn(const QString &str, int offset, CaretMode caretMode) const
QPainter::drawRect
void drawRect(const QRectF &rectangle)
QRegExp
QLayout::removeWidget
void removeWidget(QWidget *widget)
KateScrollBar::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: kateviewhelpers.cpp:696
KateViewBar::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
Definition: kateviewhelpers.cpp:2602
KateIconBorder::updateAnnotationLine
void updateAnnotationLine(int line)
Definition: kateviewhelpers.cpp:2184
QRect
KateIconBorder::setIconBorderOn
void setIconBorderOn(bool enable)
Definition: kateviewhelpers.cpp:1291
KateIconBorder::setFoldingMarkersOn
void setFoldingMarkersOn(bool enable)
Definition: kateviewhelpers.cpp:1377
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
KateViewBarWidget::centralWidget
QWidget * centralWidget()
Definition: kateviewhelpers.h:311
QMouseEvent::globalPos
const QPoint & globalPos() const
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:2493
KateCmd::fromHistory
const QString fromHistory(int i) const
Definition: katecmd.cpp:129
QPainter::drawPoint
void drawPoint(const QPointF &position)
paintTriangle
static void paintTriangle(QPainter &painter, QColor c, int xOffset, int yOffset, int width, int height, bool open)
Definition: kateviewhelpers.cpp:1489
QStackedWidget::setCurrentWidget
void setCurrentWidget(QWidget *widget)
KateViewInternal::mousePressEvent
virtual void mousePressEvent(QMouseEvent *)
Definition: kateviewinternal.cpp:2517
QWidget::setLayout
void setLayout(QLayout *layout)
QHash::constEnd
const_iterator constEnd() const
QTimer
QAbstractSlider::orientation
Qt::Orientation orientation() const
KateTextLayout::viewLine
int viewLine() const
Return the index of this visual line inside the document line (KateLineLayout).
Definition: katetextlayout.cpp:109
QWidget::mousePressEvent
virtual void mousePressEvent(QMouseEvent *event)
QVariant::toInt
int toInt(bool *ok) const
QWidget::x
int x() const
KateRenderer::config
KateRendererConfig * config() const
Configuration.
Definition: katerenderer.h:362
QSharedPointer
QAbstractSlider::sliderPosition
int sliderPosition() const
QHash< int, KTextEditor::Mark * >
KateScrollBar::sliderChange
virtual void sliderChange(SliderChange change)
Definition: kateviewhelpers.cpp:711
QRect::top
int top() const
QObject
QStyle
QPainter::setPen
void setPen(const QColor &color)
KateScrollBar::marksChanged
void marksChanged()
Definition: kateviewhelpers.cpp:732
QWidget::setFocus
void setFocus()
QPainterPath::lineTo
void lineTo(const QPointF &endPoint)
katelayoutcache.h
KateCommandLineBar::showHelpPage
void showHelpPage()
Definition: kateviewhelpers.cpp:829
KateIconBorder::setDynWrapIndicators
void setDynWrapIndicators(int state)
Definition: kateviewhelpers.cpp:1364
QRect::left
int left() const
kateglobal.h
QMouseEvent::button
Qt::MouseButton button() const
KateViewInternal::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *)
Definition: kateviewinternal.cpp:2813
QPainter
QHashIterator
KateViewInternal
Definition: kateviewinternal.h:58
QWidget::setFocusProxy
void setFocusProxy(QWidget *w)
QWidget::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *event)
QString::isEmpty
bool isEmpty() const
QCoreApplication::sendEvent
bool sendEvent(QObject *receiver, QEvent *event)
KateIconBorder::setViRelLineNumbersOn
void setViRelLineNumbersOn(bool enable)
Definition: kateviewhelpers.cpp:1341
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
KateViewBarWidget::hideMe
void hideMe()
QKeyEvent::text
QString text() const
KateDocument::lines
virtual int lines() const
Definition: katedocument.cpp:753
QPen::setWidthF
void setWidthF(qreal width)
KateDocument::editableMarks
virtual uint editableMarks() const
Definition: katedocument.cpp:1841
QPainter::setBrush
void setBrush(const QBrush &brush)
QVBoxLayout
KateScrollBar::mousePressEvent
virtual void mousePressEvent(QMouseEvent *e)
Definition: kateviewhelpers.cpp:188
MIB_DEFAULT
#define MIB_DEFAULT
Definition: kateviewhelpers.cpp:2251
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:2563
KateCmdLineEdit::event
virtual bool event(QEvent *e)
Definition: kateviewhelpers.cpp:929
KateRendererConfig::global
static KateRendererConfig * global()
Definition: kateconfig.h:640
KateViewEncodingAction::setCurrentCodec
bool setCurrentCodec(QTextCodec *codec)
Definition: kateviewhelpers.cpp:2383
Kate::TextFolding::Folded
Range is folded away.
Definition: katetextfolding.h:69
KateCmdLineEdit::hideEvent
void hideEvent(QHideEvent *e)
Definition: kateviewhelpers.cpp:878
QStackedWidget
katecmd.h
KateScrollBar::updatePixmap
void updatePixmap()
Definition: kateviewhelpers.cpp:323
QPixmap::scaled
QPixmap scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const
QString
QList< QTextLayout::FormatRange >
QWidget::hide
void hide()
KateViewConfig::setDefaultMarkType
void setDefaultMarkType(uint type)
Definition: kateconfig.cpp:1754
QAbstractSlider::minimum
int minimum() const
QColor
QChar::unicode
ushort unicode() const
QTextCodec
QPen::setColor
void setColor(const QColor &color)
QRect::moveTop
void moveTop(int y)
QToolButton::setAutoRaise
void setAutoRaise(bool enable)
QLayout::setMargin
void setMargin(int margin)
KateDocument::markPixmap
virtual QPixmap markPixmap(MarkInterface::MarkTypes) const
Definition: katedocument.cpp:1816
QWidget::setSizePolicy
void setSizePolicy(QSizePolicy)
Kate::Mark
Mark
Definition: katedefaultcolors.h:55
KateDocumentConfig::encoding
const QString & encoding() const
Definition: kateconfig.cpp:829
QStringList
QWidget::rect
QRect rect() const
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:2232
KateView
Definition: kateview.h:77
KateIconBorder::setLineNumbersOn
void setLineNumbersOn(bool enable)
Definition: kateviewhelpers.cpp:1328
QPixmap
KateViewBarWidget::closed
virtual void closed()
Definition: kateviewhelpers.h:302
KateView::annotationContextMenuAboutToShow
void annotationContextMenuAboutToShow(KTextEditor::View *view, QMenu *menu, int line)
QInputEvent::modifiers
Qt::KeyboardModifiers modifiers() const
QChar::isNull
bool isNull() const
QAction::setData
void setData(const QVariant &userData)
QHash::clear
void clear()
Kate::TextFolding::lineToVisibleLine
int lineToVisibleLine(int line) const
Convert a text buffer line to a visible line number.
Definition: katetextfolding.cpp:366
QList::end
iterator end()
QToolButton
QKeyEvent::key
int key() const
KateViewEncodingAction::currentCodecName
QString currentCodecName() const
Definition: kateviewhelpers.cpp:2414
QEvent::accept
void accept()
KateViewBar::addPermanentBarWidget
void addPermanentBarWidget(KateViewBarWidget *barWidget)
Adds widget that will be always shown in the viewbar.
Definition: kateviewhelpers.cpp:2503
KateScrollBar::sizeHint
QSize sizeHint() const
Definition: kateviewhelpers.cpp:150
KateDocument
Definition: katedocument.h:74
QHashIterator::next
Item next()
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QSize
KateIconBorder::FoldingMarkers
Definition: kateviewhelpers.h:182
KateDocument::requestMarkTooltip
void requestMarkTooltip(int line, QPoint position)
Definition: katedocument.cpp:1752
QPixmap::height
int height() const
KateViewConfig::writeConfig
void writeConfig(KConfigGroup &config)
Write config to object.
Definition: kateconfig.cpp:1327
KateViewConfig::allowMarkMenu
bool allowMarkMenu() const
Definition: kateconfig.cpp:1767
QAbstractSlider::value
int value() const
QStackedWidget::removeWidget
void removeWidget(QWidget *widget)
KateScrollBar::paintEvent
virtual void paintEvent(QPaintEvent *e)
Definition: kateviewhelpers.cpp:260
QTextCodec::mibEnum
virtual int mibEnum() const =0
QColor::lighter
QColor lighter(int factor) const
QTimer::stop
void stop()
QToolTip::hideText
void hideText()
KateScrollBar::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *e)
Definition: kateviewhelpers.cpp:237
QAction::setCheckable
void setCheckable(bool)
KateIconBorder::BorderArea
BorderArea
Definition: kateviewhelpers.h:182
KateCommandLineBar
Definition: kateviewhelpers.h:414
KateViewEncodingAction::codecForMib
QTextCodec * codecForMib(int mib) const
Definition: kateviewhelpers.cpp:2367
KateDocument::kateTextLine
Kate::TextLine kateTextLine(uint i)
Definition: katedocument.cpp:4706
KateViewEncodingAction::triggered
void triggered(QTextCodec *codec)
Specific (proper) codec was selected.
KateIconBorder::AnnotationBorder
Definition: kateviewhelpers.h:182
KateView::reloadFile
void reloadFile()
Definition: kateview.cpp:1219
KateCommandLineBar::KateCommandLineBar
KateCommandLineBar(KateView *view, QWidget *parent=0)
Definition: kateviewhelpers.cpp:810
QWidget::repaint
void repaint()
katetextlayout.h
KateView::cursorPosition
KTextEditor::Cursor cursorPosition() const
Definition: kateview.cpp:2423
QLayout::setAlignment
bool setAlignment(QWidget *w, QFlags< Qt::AlignmentFlag > alignment)
QString::replace
QString & replace(int position, int n, QChar after)
QKeyEvent
KateViewConfig::autoCenterLines
int autoCenterLines() const
Definition: kateconfig.cpp:1678
KateIconBorder::updateAnnotationBorderWidth
void updateAnnotationBorderWidth()
Definition: kateviewhelpers.cpp:2211
KateViewEncodingAction::currentCodecMib
int currentCodecMib() const
Definition: kateviewhelpers.cpp:2424
QHash::constBegin
const_iterator constBegin() const
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:2603
KActionMenu
KLineEdit
KateViewBar::hideCurrentBarWidget
void hideCurrentBarWidget()
Hides currently shown bar widget.
Definition: kateviewhelpers.cpp:2568
KateLayoutCache::viewLineCount
int viewLineCount(int realLine)
Definition: katelayoutcache.cpp:475
QPainterPath
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
KateCmd::commandList
QStringList commandList() const
Definition: katecmd.cpp:107
QRect::width
int width() const
QString::mid
QString mid(int position, int n) const
QCursor::pos
QPoint pos()
QPainter::drawPath
void drawPath(const QPainterPath &path)
KateDocument::setEncoding
virtual bool setEncoding(const QString &e)
Definition: katedocument.cpp:3954
QVector< Kate::TextLineData::Attribute >
KateIconBorder::positionToArea
BorderArea positionToArea(const QPoint &) const
Definition: kateviewhelpers.cpp:1811
KateView::viInputMode
bool viInputMode() const
Definition: kateview.cpp:1530
halfIPW
const int halfIPW
Definition: kateviewhelpers.cpp:1249
KateViewEncodingAction::~KateViewEncodingAction
~KateViewEncodingAction()
Definition: kateviewhelpers.cpp:2322
KateRendererConfig::font
const QFont & font() const
Definition: kateconfig.cpp:2276
QPen::setWidth
void setWidth(int width)
QAbstractSlider::singleStep
int singleStep() const
KateViewBar::showBarWidget
void showBarWidget(KateViewBarWidget *barWidget)
Shows barWidget that was previously added with addBarWidget.
Definition: kateviewhelpers.cpp:2542
KateView::setAnnotationBorderVisible
void setAnnotationBorderVisible(bool visible)
Definition: kateview.cpp:3073
QFontMetricsF::ascent
qreal ascent() const
QLatin1String
QStackedWidget::indexOf
int indexOf(QWidget *widget) const
KateViewInternal::endPos
KTextEditor::Cursor endPos() const
Definition: kateviewinternal.cpp:285
QVector::isEmpty
bool isEmpty() const
KateViewEncodingAction::currentCodec
QTextCodec * currentCodec() const
Definition: kateviewhelpers.cpp:2378
QRect::setHeight
void setHeight(int height)
KateDocument::removeMark
virtual void removeMark(int line, uint markType)
Definition: katedocument.cpp:1714
QPainter::drawConvexPolygon
void drawConvexPolygon(const QPointF *points, int pointCount)
KateCmdLineEdit
Definition: kateviewhelpers.h:432
KateIconBorder::ModificationBorder
Definition: kateviewhelpers.h:182
QWidget::mapFromGlobal
QPoint mapFromGlobal(const QPoint &pos) const
QAction
QTextCodec::codecForName
QTextCodec * codecForName(const QByteArray &name)
KateRendererConfig::savedLineColor
const QColor & savedLineColor() const
Definition: kateconfig.cpp:2666
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
KateScrollBar::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *e)
Definition: kateviewhelpers.cpp:213
KateViInputModeManager::reset
void reset()
Definition: kateviinputmodemanager.cpp:663
QTextCodec::codecForMib
QTextCodec * codecForMib(int mib)
KateViewConfig::scrollPastEnd
bool scrollPastEnd() const
Definition: kateconfig.cpp:1997
QRect::adjust
void adjust(int dx1, int dy1, int dx2, int dy2)
QWidget::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
QRect::bottom
int bottom() const
QString::length
int length() const
KateIconBorder::~KateIconBorder
virtual ~KateIconBorder()
Definition: kateviewhelpers.cpp:1285
KateRenderer::lineHeight
int lineHeight() const
Definition: katerenderer.cpp:825
KateRendererConfig::backgroundColor
const QColor & backgroundColor() const
Definition: kateconfig.cpp:2327
QAbstractSlider::valueChanged
void valueChanged(int value)
QWidget::setMouseTracking
void setMouseTracking(bool enable)
KateDocument::setMarkDescription
virtual void setMarkDescription(MarkInterface::MarkTypes, const QString &)
Definition: katedocument.cpp:1811
QStyleOption::init
void init(const QWidget *widget)
QColor::setHsl
void setHsl(int h, int s, int l, int a)
QColor::setHsv
void setHsv(int h, int s, int v, int a)
QString::left
QString left(int n) const
KateIconBorder::sizeHint
virtual QSize sizeHint() const
Definition: kateviewhelpers.cpp:1389
KateDocument::marks
virtual const QHash< int, KTextEditor::Mark * > & marks()
Definition: katedocument.cpp:1747
QPen
Kate::TextFolding::newFoldingRange
qint64 newFoldingRange(const KTextEditor::Range &range, FoldingRangeFlags flags=FoldingRangeFlags())
Create a new folding range.
Definition: katetextfolding.cpp:99
QTimer::start
void start(int msec)
QColor::setAlphaF
void setAlphaF(qreal alpha)
QVariant::isValid
bool isValid() const
KateScrollBar::setShowMiniMap
void setShowMiniMap(bool b)
Definition: kateviewhelpers.cpp:131
KateViewEncodingAction::codecName
QString codecName
Definition: kateviewhelpers.h:254
KateView::doc
KateDocument * doc()
accessor to katedocument pointer
Definition: kateview.h:553
KateViewConfig::defaultMarkType
uint defaultMarkType() const
Definition: kateconfig.cpp:1746
QWidget::show
void show()
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:2284
QMouseEvent::pos
const QPoint & pos() const
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:250
QPaintEvent
QWidget::resizeEvent
virtual void resizeEvent(QResizeEvent *event)
QHashIterator::value
const T & value() const
QTextLayout::FormatRange
QStackedWidget::addWidget
int addWidget(QWidget *widget)
QTimer::isActive
bool isActive() const
QAbstractSlider::maximum
int maximum() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KateLayoutCache::viewCacheLineCount
int viewCacheLineCount() const
Definition: katelayoutcache.cpp:364
QVector::size
int size() const
KateView::config
KateViewConfig * config()
Configuration.
Definition: kateview.h:653
QPainter::begin
bool begin(QPaintDevice *device)
QWidget::leaveEvent
virtual void leaveEvent(QEvent *event)
Kate::TextFolding::visibleLines
int visibleLines() const
Query number of visible lines.
Definition: katetextfolding.cpp:340
kateviglobal.h
KateIconBorder::updateViRelLineNumbers
void updateViRelLineNumbers()
Definition: kateviewhelpers.cpp:1356
KateScrollBar::sliderMMBMoved
void sliderMMBMoved(int value)
kateconfig.h
QString::data
QChar * data()
QRegExp::exactMatch
bool exactMatch(const QString &str) const
KateViewBar::hasPermanentWidget
bool hasPermanentWidget(KateViewBarWidget *barWidget) const
Definition: kateviewhelpers.cpp:2537
QVariant::toString
QString toString() const
QFocusEvent
QList::begin
iterator begin()
KateDocument::setMarkPixmap
virtual void setMarkPixmap(MarkInterface::MarkTypes, const QPixmap &)
Definition: katedocument.cpp:1806
KateCommandLineBar::execute
void execute(const QString &text)
Definition: kateviewhelpers.cpp:847
QWidget::height
int height() const
QScrollBar::sliderChange
virtual void sliderChange(SliderChange change)
QFontMetricsF::height
qreal height() const
QStyleOptionSlider
QScrollBar::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *e)
KateView::paste
void paste(const QString *textToPaste=0)
Definition: kateview.cpp:2399
QChar::isLetterOrNumber
bool isLetterOrNumber() const
KateViewConfig::global
static KateViewConfig * global()
Definition: kateconfig.h:402
KateIconBorder::LineNumbers
Definition: kateviewhelpers.h:182
QTimer::setSingleShot
void setSingleShot(bool singleShot)
QVariant
QFontMetricsF
KateDocument::markDescription
virtual QString markDescription(MarkInterface::MarkTypes) const
Definition: katedocument.cpp:1831
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

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

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal