summaryrefslogtreecommitdiffstatshomepage
path: root/DocumentItem.h
blob: 236e61c0d4c4e2cda6b625f8312518ff9a715588 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef DOCUMENTITEM_H
#define DOCUMENTITEM_H

#include <QGraphicsObject>
#include <QPair>
class DocumentBuffer;

class DocumentItem : public QGraphicsObject
{
	Q_OBJECT
public:
	DocumentItem(int lineCharacterCount, int lineCount, QGraphicsItem *parent = 0);
	~DocumentItem();
	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
	QRectF boundingRect() const;
	const DocumentBuffer& buffer() const;
	void setBuffer(DocumentBuffer *buffer);
	bool isEditable() const;
	void setEditable(bool on);
	void setText(const QString &text);
	void scroll(int lines);
	QPair<int, int> cursorLocation() const;
	void setCursorLocation(const QPair<int, int> &location);
	int scrollTop() const;
	void setScrollTop(int top);

protected:
	void keyPressEvent(QKeyEvent *event);
	void wheelEvent(QGraphicsSceneWheelEvent *event);

private:
	enum { CHARACTER_WIDTH = 25, CHARACTER_HEIGHT = 40 };
	DocumentBuffer *m_buffer;
	int m_lineCharacterCount;
	int m_lineCount;
	int m_currentRow;
	int m_currentCol;
	int m_scrollTop;
	bool m_editable;
};

#endif // DOCUMENTITEM_H