OSDN Git Service

Ver0.26
[gefu/Gefu.git] / textview.h
1 #ifndef TEXTVIEW_H
2 #define TEXTVIEW_H
3
4 #include <QWidget>
5 class QScrollArea;
6
7 class TextView : public QWidget
8 {
9     Q_OBJECT
10 public:
11     explicit TextView(QScrollArea *parent = 0);
12
13     void    setData(const QByteArray &data);
14
15 private:
16     struct ViewPosition {
17         int lineNum;    // 行番号
18         int offset;     // 文字列先頭からのオフセット
19         int x;          // X座標
20         int y;          // Y座標
21
22         ViewPosition() :
23             lineNum(0), offset(0), x(0), y(0)
24         {
25         }
26     };
27
28     QScrollArea*            m_scrollArea;
29     QByteArray              m_source;
30     QString                 m_data;
31     int                     m_charHeight;
32     int                     m_charWidth;
33     int                     m_tabWidth;
34     QVector<ViewPosition>   m_viewPositions;
35     int                     m_selectionBegin;
36     int                     m_selectionEnd;
37     int                     m_selectionInit;
38
39     void    adjust();
40     void    convertFrom(const char *code);
41     int     cursorPos(const QPoint &pos);
42     int     lineNumChars(int lines = -1) const;
43     void    resetSelection(int index);
44     void    setSelection(int index);
45
46 signals:
47     void    copyAvailable(bool);
48     void    statusChanged(const QString &text);
49
50 public slots:
51     void    onConvertFromEUC();
52     void    onConvertFromJIS();
53     void    onConvertFromSJIS();
54     void    onConvertFromUTF8();
55     void    onConvertFromUTF16();
56     void    onConvertFromUTF16BE();
57     void    onConvertFromUTF16LE();
58     void    onCopy();
59     void    onScaleDown();
60     void    onScaleUp();
61     void    onSelectAll();
62
63     // QWidget interface
64 public slots:
65     void setVisible(bool visible);
66
67 protected:
68     void mousePressEvent(QMouseEvent *e);
69     void mouseDoubleClickEvent(QMouseEvent *e);
70     void mouseMoveEvent(QMouseEvent *e);
71     void paintEvent(QPaintEvent *e);
72     void resizeEvent(QResizeEvent *e);
73 };
74
75 #endif // TEXTVIEW_H