OSDN Git Service

more cosmetic changes
[qt-creator-jp/qt-creator-jp.git] / src / plugins / bineditor / bineditor.h
1 /***************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact:  Qt Software Information (qt-info@nokia.com)
8 **
9 ** 
10 ** Non-Open Source Usage  
11 ** 
12 ** Licensees may use this file in accordance with the Qt Beta Version
13 ** License Agreement, Agreement version 2.2 provided with the Software or,
14 ** alternatively, in accordance with the terms contained in a written
15 ** agreement between you and Nokia.  
16 ** 
17 ** GNU General Public License Usage 
18 ** 
19 ** Alternatively, this file may be used under the terms of the GNU General
20 ** Public License versions 2.0 or 3.0 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.GPL included in the packaging
22 ** of this file.  Please review the following information to ensure GNU
23 ** General Public Licensing requirements will be met:
24 **
25 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
26 ** http://www.gnu.org/copyleft/gpl.html.
27 **
28 ** In addition, as a special exception, Nokia gives you certain additional
29 ** rights. These rights are described in the Nokia Qt GPL Exception version
30 ** 1.2, included in the file GPL_EXCEPTION.txt in this package.  
31 ** 
32 ***************************************************************************/
33
34 #ifndef BINEDITOR_H
35 #define BINEDITOR_H
36
37 #include <QtGui/qabstractscrollarea.h>
38 #include <QtCore/qbasictimer.h>
39 #include <QtCore/qstack.h>
40 #include <QtGui/qtextdocument.h>
41 #include <QtGui/qtextformat.h>
42
43 namespace Core {
44 class IEditor;
45 }
46
47 namespace TextEditor {
48 class FontSettings;
49 }
50
51 namespace BINEditor {
52
53 class BinEditor : public QAbstractScrollArea
54 {
55     Q_OBJECT
56     Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
57 public:
58
59     BinEditor(QWidget *parent = 0);
60     ~BinEditor();
61
62     void setData(const QByteArray &data);
63     QByteArray data() const;
64
65     void zoomIn(int range = 1);
66     void zoomOut(int range = 1);
67
68     enum MoveMode {
69         MoveAnchor,
70         KeepAnchor
71     };
72
73     int cursorPosition() const;
74     void setCursorPosition(int pos, MoveMode moveMode = MoveAnchor);
75
76     void setModified(bool);
77     bool isModified() const;
78
79     int find(const QByteArray &pattern, int from = 0, QTextDocument::FindFlags findFlags = 0);
80
81     void selectAll();
82     void clear();
83
84     void undo();
85     void redo();
86
87     Core::IEditor *editorInterface() const { return m_ieditor; }
88     void setEditorInterface(Core::IEditor *ieditor) { m_ieditor = ieditor; }
89
90     bool hasSelection() const { return m_cursorPosition != m_anchorPosition; }
91     int selectionStart() const { return qMin(m_anchorPosition, m_cursorPosition); }
92     int selectionEnd() const { return qMax(m_anchorPosition, m_cursorPosition); }
93
94     bool event(QEvent*);
95
96     bool isUndoAvailable() const { return m_undoStack.size(); }
97     bool isRedoAvailable() const { return m_redoStack.size(); }
98
99     QString addressString(uint address);
100
101
102 public Q_SLOTS:
103     void setFontSettings(const TextEditor::FontSettings &fs);
104     void highlightSearchResults(const QByteArray &pattern, QTextDocument::FindFlags findFlags = 0);
105     void copy();
106
107 Q_SIGNALS:
108     void modificationChanged(bool modified);
109     void undoAvailable(bool);
110     void redoAvailable(bool);
111     void copyAvailable(bool);
112     void cursorPositionChanged(int position);
113
114 protected:
115     void scrollContentsBy(int dx, int dy);
116     void paintEvent(QPaintEvent *e);
117     void resizeEvent(QResizeEvent *);
118     void changeEvent(QEvent *);
119     void wheelEvent(QWheelEvent *e);
120     void mousePressEvent(QMouseEvent *e);
121     void mouseMoveEvent(QMouseEvent *e);
122     void mouseReleaseEvent(QMouseEvent *e);
123     void keyPressEvent(QKeyEvent *e);
124     void focusInEvent(QFocusEvent *);
125     void focusOutEvent(QFocusEvent *);
126     void timerEvent(QTimerEvent *);
127
128 private:
129     QByteArray m_data;
130     int m_unmodifiedState;
131     int m_margin;
132     int m_descent;
133     int m_ascent;
134     int m_lineHeight;
135     int m_charWidth;
136     int m_labelWidth;
137     int m_textWidth;
138     int m_columnWidth;
139     int m_numLines;
140     int m_numVisibleLines;
141
142
143     bool m_cursorVisible;
144     int m_cursorPosition;
145     int m_anchorPosition;
146     bool m_hexCursor;
147     bool m_lowNibble;
148     bool m_isMonospacedFont;
149
150     QByteArray m_searchPattern;
151     QByteArray m_searchPatternHex;
152
153     QBasicTimer m_cursorBlinkTimer;
154
155     void init();
156     int posAt(const QPoint &pos) const;
157     bool inTextArea(const QPoint &pos) const;
158     QRect cursorRect() const;
159     void updateLines(int fromPosition = -1, int toPosition = -1);
160     void ensureCursorVisible();
161     void setBlinkingCursorEnabled(bool enable);
162
163     void changeData(int position, uchar character, bool highNibble = false);
164
165     int findPattern(const QByteArray &data, int from, int offset, int *match);
166     void drawItems(QPainter *painter, int x, int y, const QString &itemString);
167
168     struct BinEditorEditCommand {
169         int position;
170         uchar character;
171         bool highNibble;
172     };
173     QStack<BinEditorEditCommand> m_undoStack, m_redoStack;
174
175     QBasicTimer m_autoScrollTimer;
176     Core::IEditor *m_ieditor;
177     QString m_addressString;
178 };
179
180 } // namespace BINEditor
181
182 #endif // BINEDITOR_H