edbee - Qt Editor Library
textmargincomponent.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <QWidget>
9 
10 class QEvent;
11 class QFont;
12 class QLinearGradient;
13 class QMouseEvent;
14 class QPainter;
15 
16 namespace edbee {
17 
18 class TextEditorWidget;
19 class TextMarginComponent;
20 class TextRenderer;
21 
25 {
26 public:
29 
30  virtual QString lineText( int line );
31 
32  virtual int widthBeforeLineNumber();
33  virtual void renderBefore( QPainter* painter, int startLine, int endLine, int width );
34  virtual void renderAfter( QPainter* painter, int startLine, int endLine, int width );
35 
36  virtual bool requiresMouseTracking();
37  virtual void mouseMoveEvent( int line, QMouseEvent* event );
38  virtual void mousePressEvent( int line, QMouseEvent* event );
39  virtual void leaveEvent( QEvent* event );
40 
41  TextMarginComponent* marginComponent() { return marginComponentRef_; }
42  void setMarginCompenent( TextMarginComponent* comp ) { marginComponentRef_ = comp; }
43 
44 private:
45  TextMarginComponent* marginComponentRef_;
46 };
47 
48 
51 class TextMarginComponent : public QWidget
52 {
53  Q_OBJECT
54 
55 public:
56  TextMarginComponent( TextEditorWidget* editorWidget, QWidget* parent);
57  virtual ~TextMarginComponent();
58 
59  void init();
60 
61  int widthHint() const;
62  virtual QSize sizeHint() const;
63  bool isGeometryChangeRequired();
64 
65  void fullUpdate();
66  TextEditorWidget* editorWidget() const { return editorRef_;}
67  TextRenderer* renderer() const;
68 
69  TextMarginComponentDelegate* delegate() const { return delegateRef_; }
70  void setDelegate( TextMarginComponentDelegate* delegate );
71  void giveDelegate( TextMarginComponentDelegate* delegate );
72 
73 protected:
74 
75  virtual void paintEvent( QPaintEvent* event );
76  virtual void renderCaretMarkers( QPainter* painter, int startLine, int endLine, int width );
77  virtual void renderLineNumber( QPainter* painter, int startLine, int endLine, int width );
78 
79  virtual void mouseMoveEvent(QMouseEvent* event);
80  virtual void mousePressEvent(QMouseEvent* event);
81  virtual void mouseDoubleClickEvent(QMouseEvent *);
82  virtual void leaveEvent(QEvent* event);
83  virtual void wheelEvent(QWheelEvent* event);
84 
85 public:
86  virtual void updateLineAtOffset(int offset);
87  virtual void updateLine(int line, int length);
88 
89 protected slots:
90 
91  virtual void topChanged(int value);
92  virtual void connectScrollBar();
93 
94 private:
95 
96 
98  int top_;
99  mutable int width_;
100  mutable int lastLineCount_;
101  QFont* marginFont_;
102  TextEditorWidget* editorRef_;
103  TextMarginComponentDelegate* delegate_;
104  TextMarginComponentDelegate* delegateRef_;
105 };
106 
107 } // edbee
The textmargin component delegate You can override the methods in the class for adding functionality ...
Definition: textmargincomponent.h:24
A class for rendering the text.
Definition: textrenderer.h:34
virtual void renderBefore(QPainter *painter, int startLine, int endLine, int width)
Custom rendering before the line-numbers etc are drawn.
Definition: textmargincomponent.cpp:50
TextMarginComponent * marginComponent()
Definition: textmargincomponent.h:41
virtual void leaveEvent(QEvent *event)
Definition: textmargincomponent.cpp:97
TextEditorWidget * editorWidget() const
Definition: textmargincomponent.h:66
virtual ~TextMarginComponentDelegate()
Definition: textmargincomponent.h:28
TextMarginComponentDelegate * delegate() const
Definition: textmargincomponent.h:69
void setMarginCompenent(TextMarginComponent *comp)
Definition: textmargincomponent.h:42
virtual bool requiresMouseTracking()
Make this method return true to enable mouse tracking.
Definition: textmargincomponent.cpp:68
virtual void mousePressEvent(int line, QMouseEvent *event)
Definition: textmargincomponent.cpp:87
The margin/line-number component This class is used for rendering line-numbers etc.
Definition: textmargincomponent.h:51
Copyright 2011-2013 - Reliable Bits Software by Blommers IT.
Definition: commentcommand.cpp:22
virtual void mouseMoveEvent(int line, QMouseEvent *event)
This method is called when the mouse is moved over a certain line To use it you MUST manually call se...
Definition: textmargincomponent.cpp:75
virtual int widthBeforeLineNumber()
The extra space required before the line-number The default implemenation returns 0...
Definition: textmargincomponent.cpp:44
TextMarginComponentDelegate()
The default constructor.
Definition: textmargincomponent.cpp:31
This is the general edbee widget This core functionality of this widget is divided in several seperat...
Definition: texteditorwidget.h:32
virtual void renderAfter(QPainter *painter, int startLine, int endLine, int width)
The delegate can berform custom rendering on a given line.
Definition: textmargincomponent.cpp:59
virtual QString lineText(int line)
The default text (of course) is the line-number.
Definition: textmargincomponent.cpp:37