1 /***************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Qt Software Information (qt-info@nokia.com)
10 ** Non-Open Source Usage
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.
17 ** GNU General Public License Usage
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:
25 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
26 ** http://www.gnu.org/copyleft/gpl.html.
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.
32 ***************************************************************************/
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>
47 namespace TextEditor {
53 class BinEditor : public QAbstractScrollArea
56 Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
59 BinEditor(QWidget *parent = 0);
62 void setData(const QByteArray &data);
63 QByteArray data() const;
65 void zoomIn(int range = 1);
66 void zoomOut(int range = 1);
73 int cursorPosition() const;
74 void setCursorPosition(int pos, MoveMode moveMode = MoveAnchor);
76 void setModified(bool);
77 bool isModified() const;
79 int find(const QByteArray &pattern, int from = 0, QTextDocument::FindFlags findFlags = 0);
87 Core::IEditor *editorInterface() const { return m_ieditor; }
88 void setEditorInterface(Core::IEditor *ieditor) { m_ieditor = ieditor; }
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); }
96 bool isUndoAvailable() const { return m_undoStack.size(); }
97 bool isRedoAvailable() const { return m_redoStack.size(); }
99 QString addressString(uint address);
103 void setFontSettings(const TextEditor::FontSettings &fs);
104 void highlightSearchResults(const QByteArray &pattern, QTextDocument::FindFlags findFlags = 0);
108 void modificationChanged(bool modified);
109 void undoAvailable(bool);
110 void redoAvailable(bool);
111 void copyAvailable(bool);
112 void cursorPositionChanged(int position);
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 *);
130 int m_unmodifiedState;
140 int m_numVisibleLines;
143 bool m_cursorVisible;
144 int m_cursorPosition;
145 int m_anchorPosition;
148 bool m_isMonospacedFont;
150 QByteArray m_searchPattern;
151 QByteArray m_searchPatternHex;
153 QBasicTimer m_cursorBlinkTimer;
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);
163 void changeData(int position, uchar character, bool highNibble = false);
165 int findPattern(const QByteArray &data, int from, int offset, int *match);
166 void drawItems(QPainter *painter, int x, int y, const QString &itemString);
168 struct BinEditorEditCommand {
173 QStack<BinEditorEditCommand> m_undoStack, m_redoStack;
175 QBasicTimer m_autoScrollTimer;
176 Core::IEditor *m_ieditor;
177 QString m_addressString;
180 } // namespace BINEditor
182 #endif // BINEDITOR_H