Commit ad0eff18 authored by hjk's avatar hjk
Browse files

bineditor: code cosmetics

parent 82422c46
......@@ -49,8 +49,6 @@
#include <QtGui/QToolTip>
#include <QtGui/QWheelEvent>
using namespace BINEditor;
// QByteArray::toLower() is broken, it stops at the first \0
static void lower(QByteArray &ba)
{
......@@ -81,6 +79,8 @@ static QByteArray calculateHexPattern(const QByteArray &pattern)
return result;
}
namespace BINEditor {
BinEditor::BinEditor(QWidget *parent)
: QAbstractScrollArea(parent)
{
......@@ -299,10 +299,13 @@ void BinEditor::timerEvent(QTimerEvent *e)
QPoint pos;
const QPoint globalPos = QCursor::pos();
pos = viewport()->mapFromGlobal(globalPos);
QMouseEvent ev(QEvent::MouseMove, pos, globalPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QMouseEvent ev(QEvent::MouseMove, pos, globalPos,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
mouseMoveEvent(&ev);
int deltaY = qMax(pos.y() - visible.top(), visible.bottom() - pos.y()) - visible.height();
int deltaX = qMax(pos.x() - visible.left(), visible.right() - pos.x()) - visible.width();
int deltaY = qMax(pos.y() - visible.top(),
visible.bottom() - pos.y()) - visible.height();
int deltaX = qMax(pos.x() - visible.left(),
visible.right() - pos.x()) - visible.width();
int delta = qMax(deltaX, deltaY);
if (delta >= 0) {
if (delta < 7)
......@@ -509,9 +512,10 @@ QRect BinEditor::cursorRect() const
int y = (line - topLine) * m_lineHeight;
int xoffset = horizontalScrollBar()->value();
int column = m_cursorPosition % 16;
int x = m_hexCursor ?
(-xoffset + m_margin + m_labelWidth + column * m_columnWidth)
: (-xoffset + m_margin + m_labelWidth + 16 * m_columnWidth + m_charWidth + column * m_charWidth);
int x = m_hexCursor
? (-xoffset + m_margin + m_labelWidth + column * m_columnWidth)
: (-xoffset + m_margin + m_labelWidth + 16 * m_columnWidth
+ m_charWidth + column * m_charWidth);
int w = m_hexCursor ? m_columnWidth : m_charWidth;
return QRect(x, y, w, m_lineHeight);
}
......@@ -675,12 +679,15 @@ int BinEditor::find(const QByteArray &pattern_arg, int from,
return pos;
}
int BinEditor::findPattern(const QByteArray &data, const QByteArray &dataHex, int from, int offset, int *match)
int BinEditor::findPattern(const QByteArray &data, const QByteArray &dataHex,
int from, int offset, int *match)
{
if (m_searchPattern.isEmpty())
return -1;
int normal = m_searchPattern.isEmpty()? -1 : data.indexOf(m_searchPattern, from - offset);
int hex = m_searchPatternHex.isEmpty()? -1 : dataHex.indexOf(m_searchPatternHex, from - offset);
int normal = m_searchPattern.isEmpty()
? -1 : data.indexOf(m_searchPattern, from - offset);
int hex = m_searchPatternHex.isEmpty()
? -1 : dataHex.indexOf(m_searchPatternHex, from - offset);
if (normal >= 0 && (hex < 0 || normal < hex)) {
if (match)
......@@ -799,7 +806,7 @@ void BinEditor::paintEvent(QPaintEvent *e)
painter.drawText(-xoffset, i * m_lineHeight + m_ascent,
addressString(m_baseAddr + ((uint) line) * 16));
addressString(m_baseAddr + uint(line) * 16));
int cursor = -1;
if (line * 16 <= m_cursorPosition && m_cursorPosition < line * 16 + 16)
......@@ -1499,3 +1506,4 @@ void BinEditor::asIntegers(int offset, int count, quint64 &beValue,
}
}
} // namespace BINEditor
......@@ -57,8 +57,8 @@ class BinEditor : public QAbstractScrollArea
Q_OBJECT
Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE false)
public:
public:
BinEditor(QWidget *parent = 0);
~BinEditor();
......@@ -121,7 +121,8 @@ public:
public Q_SLOTS:
void setFontSettings(const TextEditor::FontSettings &fs);
void highlightSearchResults(const QByteArray &pattern, QTextDocument::FindFlags findFlags = 0);
void highlightSearchResults(const QByteArray &pattern,
QTextDocument::FindFlags findFlags = 0);
void copy(bool raw = false);
Q_SIGNALS:
......@@ -155,10 +156,10 @@ protected:
private:
bool m_inLazyMode;
QByteArray m_data;
QMap <int, QByteArray> m_lazyData;
QMap <int, QByteArray> m_oldLazyData;
QMap<int, QByteArray> m_lazyData;
QMap<int, QByteArray> m_oldLazyData;
int m_blockSize;
QMap <int, QByteArray> m_modifiedData;
QMap<int, QByteArray> m_modifiedData;
mutable QSet<int> m_lazyRequests;
QByteArray m_emptyBlock;
QByteArray m_lowerBlock;
......@@ -218,7 +219,8 @@ private:
void changeData(int position, uchar character, bool highNibble = false);
int findPattern(const QByteArray &data, const QByteArray &dataHex, int from, int offset, int *match);
int findPattern(const QByteArray &data, const QByteArray &dataHex,
int from, int offset, int *match);
void drawItems(QPainter *painter, int x, int y, const QString &itemString);
void drawChanges(QPainter *painter, int x, int y, const char *changes);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment