ui: Improved QtCodeView to annotate code

Added some features to QTCodeSnippet:
* Code is now annotated using information from TokenLocationFile
* Start of line numbering can be set
* Clicking on an annotation in the code gives the corresponding Token Id

fortune cookie message = Your kindness will be repaid.
This commit is contained in:
Eberhard Graether
2014-07-03 10:35:30 +02:00
parent e63106b13b
commit 4c7bbbe28e
8 changed files with 316 additions and 15 deletions
+71
View File
@@ -0,0 +1,71 @@
#ifndef QT_CODE_SNIPPET_H
#define QT_CODE_SNIPPET_H
#include <vector>
#include <QPlainTextEdit>
#include <QObject>
#include "utility/types.h"
class QPaintEvent;
class QResizeEvent;
class QSize;
class QtCodeView;
class QWidget;
class TokenLocationFile;
class QtCodeSnippet: public QPlainTextEdit
{
Q_OBJECT
public:
class LineNumberArea: public QWidget
{
public:
LineNumberArea(QtCodeSnippet *codeSnippet);
virtual ~LineNumberArea();
QSize sizeHint() const;
protected:
void paintEvent(QPaintEvent *event);
private:
QtCodeSnippet *m_codeSnippet;
};
QtCodeSnippet(QtCodeView* parentView, int startLineNumber, QWidget *parent = 0);
virtual ~QtCodeSnippet();
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
void annotateText(const TokenLocationFile& locationFile);
protected:
void resizeEvent(QResizeEvent *event);
private slots:
void updateLineNumberAreaWidth(int newBlockCount);
void updateLineNumberArea(const QRect &, int);
void clickTokenLocation();
private:
struct Annotation
{
int start;
int end;
Id tokenId;
};
int toTextEditPosition(int lineNumber, int columnNumber) const;
QWidget *m_lineNumberArea;
QtCodeView* m_parentView;
const int m_startLineNumber;
std::vector<Annotation> m_annotations;
};
#endif // QT_CODE_SNIPPET_H