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

Kate

  • sources
  • kde-4.12
  • applications
  • kate
  • part
  • view
kateviewhelpers.h
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
3  Copyright (C) 2001 Anders Lund <anders@alweb.dk>
4  Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef __KATE_VIEW_HELPERS_H__
22 #define __KATE_VIEW_HELPERS_H__
23 
24 #include <kselectaction.h>
25 #include <klineedit.h>
26 #include <KActionMenu>
27 
28 #include <QtGui/QPixmap>
29 #include <QtGui/QColor>
30 #include <QtGui/QScrollBar>
31 #include <QtCore/QHash>
32 #include <QtGui/QStackedWidget>
33 #include <QtCore/QMap>
34 #include <QtCore/QTimer>
35 #include <QtGui/QTextLayout>
36 
37 #include <ktexteditor/containerinterface.h>
38 #include <ktexteditor/cursor.h>
39 #include "katepartprivate_export.h"
40 #include "katetextline.h"
41 
42 class KateDocument;
43 class KateView;
44 class KateViewInternal;
45 
46 #define MAXFOLDINGCOLORS 16
47 
48 class KateLineInfo;
49 
50 namespace KTextEditor {
51  class Command;
52  class AnnotationModel;
53  class MovingRange;
54 }
55 
56 class QTimer;
57 class QVBoxLayout;
58 
66 class KateScrollBar : public QScrollBar
67 {
68  Q_OBJECT
69 
70  public:
71  KateScrollBar(Qt::Orientation orientation, class KateViewInternal *parent);
72  QSize sizeHint() const;
73 
74  inline bool showMarks() { return m_showMarks; }
75  inline void setShowMarks(bool b) { m_showMarks = b; update(); }
76 
77  inline bool showMiniMap() { return m_showMiniMap; }
78  void setShowMiniMap(bool b);
79 
80  inline bool miniMapAll() { return m_miniMapAll; }
81  inline void setMiniMapAll(bool b) { m_miniMapAll = b; updateGeometry(); update(); }
82 
83  inline bool miniMapWidth() { return m_miniMapWidth; }
84  inline void setMiniMapWidth(int width) { m_miniMapWidth = width; updateGeometry(); update(); }
85 
86  inline void queuePixmapUpdate() { m_updateTimer.start(); }
87 
88 Q_SIGNALS:
89  void sliderMMBMoved(int value);
90 
91  protected:
92  virtual void mousePressEvent(QMouseEvent* e);
93  virtual void mouseReleaseEvent(QMouseEvent* e);
94  virtual void mouseMoveEvent (QMouseEvent* e);
95  virtual void paintEvent(QPaintEvent *e);
96  virtual void resizeEvent(QResizeEvent *);
97  virtual void styleChange(QStyle &oldStyle);
98  virtual void sliderChange ( SliderChange change );
99 
100  protected Q_SLOTS:
101  void sliderMaybeMoved(int value);
102  void marksChanged();
103 
104  public Q_SLOTS:
105  void updatePixmap();
106 
107  private:
108  void redrawMarks();
109  void recomputeMarksPositions();
110 
111  void miniMapPaintEvent(QPaintEvent *e);
112  void normalPaintEvent(QPaintEvent *e);
113 
114  int minimapYToStdY(int y);
115 
116  const QColor charColor(const QVector<Kate::TextLineData::Attribute> &attributes, int &attributeIndex,
117  const QList<QTextLayout::FormatRange> &decorations,
118  const QColor &defaultColor, int x, QChar ch);
119 
120  bool m_middleMouseDown;
121  bool m_leftMouseDown;
122 
123  KateView *m_view;
124  KateDocument *m_doc;
125  class KateViewInternal *m_viewInternal;
126 
127  QHash<int, QColor> m_lines;
128 
129  bool m_showMarks;
130  bool m_showMiniMap;
131  bool m_miniMapAll;
132  int m_miniMapWidth;
133 
134  QPixmap m_pixmap;
135  int m_grooveHeight;
136  QRect m_stdGroveRect;
137  QRect m_mapGroveRect;
138  QRect m_stdSliderRect;
139  QRect m_mapSliderRect;
140  QTimer m_updateTimer;
141  QPoint m_toolTipPos;
142 
143  // lists of lines added/removed recently to avoid scrollbar flickering
144  QHash<int, int> m_linesAdded;
145  int m_linesModified;
146 
147  static unsigned char characterOpacity[256];
148 };
149 
150 class KateIconBorder : public QWidget
151 {
152  Q_OBJECT
153 
154  public:
155  KateIconBorder( KateViewInternal* internalView, QWidget *parent );
156  virtual ~KateIconBorder();
157  // VERY IMPORTANT ;)
158  virtual QSize sizeHint() const;
159 
160  void updateFont();
161  int lineNumberWidth() const;
162 
163  void setIconBorderOn( bool enable );
164  void setLineNumbersOn( bool enable );
165  void setAnnotationBorderOn( bool enable );
166  void setDynWrapIndicators(int state );
167  int dynWrapIndicators() const { return m_dynWrapIndicators; }
168  bool dynWrapIndicatorsOn() const { return m_dynWrapIndicatorsOn; }
169  void setFoldingMarkersOn( bool enable );
170  void toggleIconBorder() { setIconBorderOn( !iconBorderOn() ); }
171  void toggleLineNumbers() { setLineNumbersOn( !lineNumbersOn() ); }
172  void toggleFoldingMarkers() { setFoldingMarkersOn( !foldingMarkersOn() ); }
173  inline bool iconBorderOn() const { return m_iconBorderOn; }
174  inline bool lineNumbersOn() const { return m_lineNumbersOn; }
175  inline bool foldingMarkersOn() const { return m_foldingMarkersOn; }
176  inline bool annotationBorderOn() const { return m_annotationBorderOn; }
177 
178  enum BorderArea { None, LineNumbers, IconBorder, FoldingMarkers, AnnotationBorder, ModificationBorder };
179  BorderArea positionToArea( const QPoint& ) const;
180 
181  public Q_SLOTS:
182  void updateAnnotationBorderWidth();
183  void updateAnnotationLine( int line );
184  void annotationModelChanged( KTextEditor::AnnotationModel* oldmodel, KTextEditor::AnnotationModel* newmodel );
185 
186  private:
187  void paintEvent( QPaintEvent* );
188  void paintBorder (int x, int y, int width, int height);
189 
190  void mousePressEvent( QMouseEvent* );
191  void mouseMoveEvent( QMouseEvent* );
192  void mouseReleaseEvent( QMouseEvent* );
193  void mouseDoubleClickEvent( QMouseEvent* );
194  void leaveEvent(QEvent *event);
195  void wheelEvent(QWheelEvent *e);
196 
197  void showMarkMenu( uint line, const QPoint& pos );
198 
199  void showAnnotationTooltip( int line, const QPoint& pos );
200  void hideAnnotationTooltip();
201  void removeAnnotationHovering();
202  void showAnnotationMenu( int line, const QPoint& pos);
203  int annotationLineWidth( int line );
204 
205  KateView *m_view;
206  KateDocument *m_doc;
207  KateViewInternal *m_viewInternal;
208 
209  bool m_iconBorderOn:1;
210  bool m_lineNumbersOn:1;
211  bool m_foldingMarkersOn:1;
212  bool m_dynWrapIndicatorsOn:1;
213  bool m_annotationBorderOn:1;
214  int m_dynWrapIndicators;
215 
216  int m_lastClickedLine;
217 
218  int m_cachedLNWidth;
219 
220  qreal m_maxCharWidth;
221  int iconPaneWidth;
222  int m_annotationBorderWidth;
223 
224  mutable QPixmap m_arrow;
225  mutable QColor m_oldBackgroundColor;
226 
227 
228  KTextEditor::MovingRange *m_foldingRange;
229  int m_nextHighlightBlock;
230  int m_currentBlockLine;
231  QTimer m_delayFoldingHlTimer;
232  void showDelayedBlock(int line);
233  void hideBlock();
234 
235  private Q_SLOTS:
236  void showBlock();
237 
238  private:
239  QString m_hoveredAnnotationText;
240 
241  void initializeFoldingColors();
242 };
243 
244 class KateViewEncodingAction: public KSelectAction
245 {
246  Q_OBJECT
247 
248  Q_PROPERTY(QString codecName READ currentCodecName WRITE setCurrentCodec)
249  Q_PROPERTY(int codecMib READ currentCodecMib)
250 
251  public:
252  KateViewEncodingAction(KateDocument *_doc, KateView *_view, const QString& text, QObject *parent);
253 
254  ~KateViewEncodingAction();
255 
256  int mibForName(const QString &codecName, bool *ok = 0) const;
257  QTextCodec *codecForMib(int mib) const;
258 
259  QTextCodec *currentCodec() const;
260  bool setCurrentCodec(QTextCodec *codec);
261 
262  QString currentCodecName() const;
263  bool setCurrentCodec(const QString &codecName);
264 
265  int currentCodecMib() const;
266  bool setCurrentCodec(int mib);
267 
268  Q_SIGNALS:
272  void triggered(QTextCodec *codec);
273 
274  private:
275  KateDocument* doc;
276  KateView *view;
277  class Private;
278  Private* const d;
279  Q_PRIVATE_SLOT( d, void _k_subActionTriggered(QAction*) )
280 
281  private Q_SLOTS:
282  void setEncoding (const QString &e);
283  void slotAboutToShow();
284 };
285 
286 class KateViewBar;
287 
288 class KateViewBarWidget : public QWidget
289 {
290  Q_OBJECT
291  friend class KateViewBar;
292 
293  public:
294  explicit KateViewBarWidget (bool addCloseButton, QWidget* parent = 0);
295 
296  virtual void closed() {}
297 
299  KateViewBar* viewBar() { return m_viewBar; }
300 
301  protected:
305  QWidget *centralWidget() { return m_centralWidget; }
306 
307  signals:
308  void hideMe();
309 
310  // for friend class KateViewBar
311  private:
312  void setAssociatedViewBar(KateViewBar* bar) { m_viewBar = bar;}
313 
314  private:
315  QWidget *m_centralWidget;
316  KateViewBar* m_viewBar; // 0-pointer, if not added to a view bar
317 };
318 
319 class KateViewBar : public QWidget
320 {
321  Q_OBJECT
322 
323  public:
324  KateViewBar (bool external,
325  KTextEditor::ViewBarContainer::Position pos,
326  QWidget *parent,
327  KateView *view);
328 
329 
335  void addBarWidget (KateViewBarWidget *newBarWidget);
336 
343  void removeBarWidget (KateViewBarWidget *barWidget);
344 
348  bool hasBarWidget(KateViewBarWidget* barWidget) const;
349 
354  void showBarWidget (KateViewBarWidget *barWidget);
355 
367  void addPermanentBarWidget (KateViewBarWidget *barWidget);
368 
375  void removePermanentBarWidget (KateViewBarWidget *barWidget);
376 
380  bool hasPermanentWidget (KateViewBarWidget *barWidget) const;
381 
382  public Q_SLOTS:
386  void hideCurrentBarWidget();
387 
388  protected:
389  virtual void keyPressEvent(QKeyEvent* event);
390  virtual void hideEvent(QHideEvent* event);
391 
392  private:
396  void setViewBarVisible(bool visible);
397 
398  bool m_external;
399  KTextEditor::ViewBarContainer::Position m_pos;
400 
401  private:
402  KateView *m_view;
403  QStackedWidget *m_stack;
404  KateViewBarWidget *m_permanentBarWidget;
405  QVBoxLayout *m_layout;
406 };
407 
408 class KATEPART_TESTS_EXPORT KateCommandLineBar : public KateViewBarWidget
409 {
410  Q_OBJECT
411 
412  public:
413  explicit KateCommandLineBar(KateView *view, QWidget *parent = 0);
414  ~KateCommandLineBar();
415 
416  void setText(const QString &text, bool selected = true);
417  void execute(const QString &text);
418 
419  public Q_SLOTS:
420  void showHelpPage();
421 
422  private:
423  class KateCmdLineEdit *m_lineEdit;
424 };
425 
426 class KateCmdLineEdit : public KLineEdit
427 {
428  Q_OBJECT
429 
430  public:
431  KateCmdLineEdit (KateCommandLineBar *bar, KateView *view);
432  virtual bool event(QEvent *e);
433 
434  void hideEvent (QHideEvent *e);
435 
436  signals:
437  void hideRequested();
438 
439  public Q_SLOTS:
440  void slotReturnPressed ( const QString& cmd );
441 
442  private Q_SLOTS:
443  void hideLineEdit();
444 
445  protected:
446  void focusInEvent ( QFocusEvent *ev );
447  void keyPressEvent( QKeyEvent *ev );
448 
449  private:
460  int calculatePosition( QString string );
461  void fromHistory( bool up );
462  QString helptext( const QPoint & ) const;
463 
464  KateView *m_view;
465  KateCommandLineBar *m_bar;
466  bool m_msgMode;
467  QString m_oldText;
468  uint m_histpos;
469  uint m_cmdend;
470  KTextEditor::Command *m_command;
471  class KateCmdLnWhatsThis *m_help;
472 
473  QTimer *m_hideTimer;
474 };
475 
476 class KatePasteMenu : public KActionMenu
477 {
478  Q_OBJECT
479 
480  public:
481  KatePasteMenu (const QString& text, KateView *view);
482 
483  private:
484  KateView *m_view;
485 
486  private Q_SLOTS:
487  void slotAboutToShow();
488  void paste ();
489 };
490 
491 #endif
492 
493 // kate: space-indent on; indent-width 2; replace-tabs on;
QColor
KateIconBorder::None
Definition: kateviewhelpers.h:178
KateScrollBar::showMiniMap
bool showMiniMap()
Definition: kateviewhelpers.h:77
KAction::event
bool event(QEvent *)
KateViewBarWidget::viewBar
KateViewBar * viewBar()
returns the currently associated KateViewBar and 0, if it is not associated
Definition: kateviewhelpers.h:299
katetextline.h
KateIconBorder::updateFont
void updateFont()
Definition: kateviewhelpers.cpp:1396
KateScrollBar::queuePixmapUpdate
void queuePixmapUpdate()
Definition: kateviewhelpers.h:86
KateScrollBar::showMarks
bool showMarks()
Definition: kateviewhelpers.h:74
KateIconBorder::setAnnotationBorderOn
void setAnnotationBorderOn(bool enable)
Definition: kateviewhelpers.cpp:1301
KateIconBorder::IconBorder
Definition: kateviewhelpers.h:178
cursor.h
KateIconBorder
Definition: kateviewhelpers.h:150
QWidget
Command
Command
KateViewEncodingAction::mibForName
int mibForName(const QString &codecName, bool *ok=0) const
Definition: kateviewhelpers.cpp:2298
KATEPART_TESTS_EXPORT
#define KATEPART_TESTS_EXPORT
Definition: katepartprivate_export.h:36
KateIconBorder::lineNumberWidth
int lineNumberWidth() const
Definition: kateviewhelpers.cpp:1415
KTextEditor::MovingRange
QString
QHash< int, QColor >
KateIconBorder::lineNumbersOn
bool lineNumbersOn() const
Definition: kateviewhelpers.h:174
KateIconBorder::foldingMarkersOn
bool foldingMarkersOn() const
Definition: kateviewhelpers.h:175
QObject
paste
KAction * paste(const QObject *recvr, const char *slot, QObject *parent)
KateScrollBar
This class is required because QScrollBar's sliderMoved() signal is really supposed to be a sliderDra...
Definition: kateviewhelpers.h:66
KateScrollBar::styleChange
virtual void styleChange(QStyle &oldStyle)
Definition: kateviewhelpers.cpp:704
KSelectAction
KateViewBarWidget
Definition: kateviewhelpers.h:288
KateScrollBar::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: kateviewhelpers.cpp:696
KateIconBorder::updateAnnotationLine
void updateAnnotationLine(int line)
Definition: kateviewhelpers.cpp:2143
KateIconBorder::setIconBorderOn
void setIconBorderOn(bool enable)
Definition: kateviewhelpers.cpp:1289
QScrollBar
KateIconBorder::setFoldingMarkersOn
void setFoldingMarkersOn(bool enable)
Definition: kateviewhelpers.cpp:1352
KateViewBarWidget::centralWidget
QWidget * centralWidget()
Definition: kateviewhelpers.h:305
KateScrollBar::sliderChange
virtual void sliderChange(SliderChange change)
Definition: kateviewhelpers.cpp:711
KateScrollBar::marksChanged
void marksChanged()
Definition: kateviewhelpers.cpp:732
KateIconBorder::setDynWrapIndicators
void setDynWrapIndicators(int state)
Definition: kateviewhelpers.cpp:1339
katepartprivate_export.h
KTextEditor::ViewBarContainer::Position
Position
KateViewInternal
Definition: kateviewinternal.h:57
KateIconBorder::iconBorderOn
bool iconBorderOn() const
Definition: kateviewhelpers.h:173
up
KAction * up(const QObject *recvr, const char *slot, QObject *parent)
KateIconBorder::dynWrapIndicatorsOn
bool dynWrapIndicatorsOn() const
Definition: kateviewhelpers.h:168
KateScrollBar::mousePressEvent
virtual void mousePressEvent(QMouseEvent *e)
Definition: kateviewhelpers.cpp:188
KateScrollBar::KateScrollBar
KateScrollBar(Qt::Orientation orientation, class KateViewInternal *parent)
Definition: kateviewhelpers.cpp:107
KateViewEncodingAction::setCurrentCodec
bool setCurrentCodec(QTextCodec *codec)
Definition: kateviewhelpers.cpp:2342
KateScrollBar::updatePixmap
void updatePixmap()
Definition: kateviewhelpers.cpp:323
KateScrollBar::setMiniMapAll
void setMiniMapAll(bool b)
Definition: kateviewhelpers.h:81
KTextEditor::AnnotationModel
KateIconBorder::annotationModelChanged
void annotationModelChanged(KTextEditor::AnnotationModel *oldmodel, KTextEditor::AnnotationModel *newmodel)
Definition: kateviewhelpers.cpp:2191
KateView
Definition: kateview.h:78
KateIconBorder::setLineNumbersOn
void setLineNumbersOn(bool enable)
Definition: kateviewhelpers.cpp:1326
KateViewBarWidget::closed
virtual void closed()
Definition: kateviewhelpers.h:296
KTextEditor::Command
KateViewEncodingAction::currentCodecName
QString currentCodecName() const
Definition: kateviewhelpers.cpp:2373
KateScrollBar::sizeHint
QSize sizeHint() const
Definition: kateviewhelpers.cpp:150
KateDocument
Definition: katedocument.h:74
KateIconBorder::FoldingMarkers
Definition: kateviewhelpers.h:178
KateScrollBar::paintEvent
virtual void paintEvent(QPaintEvent *e)
Definition: kateviewhelpers.cpp:260
KateScrollBar::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *e)
Definition: kateviewhelpers.cpp:237
KateIconBorder::annotationBorderOn
bool annotationBorderOn() const
Definition: kateviewhelpers.h:176
KateIconBorder::BorderArea
BorderArea
Definition: kateviewhelpers.h:178
KateCommandLineBar
Definition: kateviewhelpers.h:408
KateViewEncodingAction::codecForMib
QTextCodec * codecForMib(int mib) const
Definition: kateviewhelpers.cpp:2326
KateScrollBar::miniMapAll
bool miniMapAll()
Definition: kateviewhelpers.h:80
KateViewEncodingAction::triggered
void triggered(QTextCodec *codec)
Specific (proper) codec was selected.
KateIconBorder::AnnotationBorder
Definition: kateviewhelpers.h:178
containerinterface.h
KateIconBorder::updateAnnotationBorderWidth
void updateAnnotationBorderWidth()
Definition: kateviewhelpers.cpp:2170
KateViewEncodingAction::currentCodecMib
int currentCodecMib() const
Definition: kateviewhelpers.cpp:2383
KActionMenu
KLineEdit
KateIconBorder::dynWrapIndicators
int dynWrapIndicators() const
Definition: kateviewhelpers.h:167
KateScrollBar::sliderMaybeMoved
void sliderMaybeMoved(int value)
Definition: kateviewhelpers.cpp:778
KateViewEncodingAction::codecMib
int codecMib
Definition: kateviewhelpers.h:249
KateIconBorder::positionToArea
BorderArea positionToArea(const QPoint &) const
Definition: kateviewhelpers.cpp:1771
QPoint
KateScrollBar::miniMapWidth
bool miniMapWidth()
Definition: kateviewhelpers.h:83
KateViewEncodingAction::currentCodec
QTextCodec * currentCodec() const
Definition: kateviewhelpers.cpp:2337
kselectaction.h
QRect
KateCmdLineEdit
Definition: kateviewhelpers.h:426
KateIconBorder::ModificationBorder
Definition: kateviewhelpers.h:178
KateScrollBar::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *e)
Definition: kateviewhelpers.cpp:213
KateIconBorder::toggleLineNumbers
void toggleLineNumbers()
Definition: kateviewhelpers.h:171
KatePasteMenu
Definition: kateviewhelpers.h:476
KateIconBorder::~KateIconBorder
virtual ~KateIconBorder()
Definition: kateviewhelpers.cpp:1283
KateIconBorder::sizeHint
virtual QSize sizeHint() const
Definition: kateviewhelpers.cpp:1364
KateScrollBar::setMiniMapWidth
void setMiniMapWidth(int width)
Definition: kateviewhelpers.h:84
QSize
KateScrollBar::setShowMiniMap
void setShowMiniMap(bool b)
Definition: kateviewhelpers.cpp:131
KateScrollBar::setShowMarks
void setShowMarks(bool b)
Definition: kateviewhelpers.h:75
KateViewEncodingAction::codecName
QString codecName
Definition: kateviewhelpers.h:248
klineedit.h
KateIconBorder::KateIconBorder
KateIconBorder(KateViewInternal *internalView, QWidget *parent)
Definition: kateviewhelpers.cpp:1251
KateIconBorder::toggleIconBorder
void toggleIconBorder()
Definition: kateviewhelpers.h:170
KateViewEncodingAction
Definition: kateviewhelpers.h:244
KateViewBar
Definition: kateviewhelpers.h:319
QEvent
KateScrollBar::sliderMMBMoved
void sliderMMBMoved(int value)
QAction
KateIconBorder::toggleFoldingMarkers
void toggleFoldingMarkers()
Definition: kateviewhelpers.h:172
QList< QTextLayout::FormatRange >
KateIconBorder::LineNumbers
Definition: kateviewhelpers.h:178
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

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

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Applications
  •   Libraries
  •     libkonq
  • Konsole

Search



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

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