void HexView::resizeEvent(QResizeEvent *rs)
{
- QSize size(min(rs->size().width(), config.maxWidth()), rs->size().height());
+ QSize size(qMin(rs->size().width(), config.maxWidth()), rs->size().height());
QResizeEvent resize(size, rs->oldSize());
View::resizeEvent(&resize);
pix_.fill(config.Colors[Color::Background]);
case DRAW_AFTER:
y_top += config.byteHeight() * line_start;
y += config.byteHeight() * line_start;
- max_y = max(y + config.byteHeight(), height());
+ max_y = qMax(y + config.byteHeight(), height());
count_line = config.drawableLines(max_y - y);
break;
case DRAW_RANGE:
y_top += config.byteHeight() * line_start;
y += config.byteHeight() * line_start;
- max_y = min(y + config.byteHeight() * end, height());
+ max_y = qMin(y + config.byteHeight() * end, height());
count_line = config.drawableLines(max_y - y);
break;
}
// Get top position of view
const quint64 top = (cursor->Top + line_start) * HexConfig::Num;
- const uint size = min(document->length() - top, (quint64)HexConfig::Num * count_line);
+ const uint size = qMin(document->length() - top, (quint64)HexConfig::Num * count_line);
if (size == 0) {
return;
}
// Draw empty area(after end line)
if (type == DRAW_ALL || type == DRAW_AFTER) {
QBrush brush(config.Colors[Color::Background]);
- const int y_start = y_top + max(0, count_line - 1) * config.byteHeight();
+ const int y_start = y_top + qMax(0, count_line - 1) * config.byteHeight();
painter.fillRect(0, y_start, width(), height(), brush);
}
drawLines(painter, dcolors_, y_top, 0, x_count_max);
// Update screen buffer
- const int draw_width = min(width(), config.maxWidth());
+ const int draw_width = qMin(width(), config.maxWidth());
const int draw_height = count_line * config.byteHeight();
painter.end();
update(0, y_top, draw_width, draw_height);
return;
}
- sel_begin = min(cursor->SelBegin, cursor->SelEnd);
- sel_end = max(cursor->SelBegin, cursor->SelEnd);
+ sel_begin = qMin(cursor->SelBegin, cursor->SelEnd);
+ sel_end = qMax(cursor->SelBegin, cursor->SelEnd);
- if (top <= sel_end && sel_begin <= max(top + (HexConfig::Num * count_line), top + size)) {
+ if (top <= sel_end && sel_begin <= qMax(top + (HexConfig::Num * count_line), top + size)) {
selected = true;
} else {
selected = false;
inline bool HexView::isSelected(quint64 pos)
{
- const quint64 sel_begin = min(cursor->SelBegin, cursor->SelEnd);
- const quint64 sel_end = max(cursor->SelBegin, cursor->SelEnd);
+ const quint64 sel_begin = qMin(cursor->SelBegin, cursor->SelEnd);
+ const quint64 sel_end = qMax(cursor->SelBegin, cursor->SelEnd);
return sel_begin <= pos && pos < sel_end;
}
// Set begin position
cursor->SelEndOld = cursor->Position;
- cursor->SelBegin = cursor->SelEnd = moveByMouse(ev->pos().x(), ev->pos().y());
+ cursor->SelBegin = cursor->SelEnd = cursor->Position = posAt(ev->pos());
// Set caret visible
cursor->Toggle = true;
}
// Set moved position
- cursor->SelEnd = moveByMouse(ev->pos().x(), ev->pos().y());
+ cursor->SelEnd = cursor->Position = posAt(ev->pos());
// Refresh flag
cursor->refreshSelected();
releaseMouse();
// Set moved position
- cursor->SelEnd = moveByMouse(ev->pos().x(), ev->pos().y());
+ cursor->SelEnd = cursor->Position = posAt(ev->pos());
cursor->refreshSelected();
// Set caret invisible
}
}
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-quint64 HexView::moveByMouse(int xx, int yy)
+quint64 HexView::posAt(const QPoint &pos)
{
- int x = config.XToPos(xx);
- int y = config.YToLine(yy);
+ int x = config.XToPos(pos.x());
+ int y = config.YToLine(pos.y());
if (x < 0) {
x = 0;
x = y = 0;
}
- cursor->Position = MIN((cursor->Top + y) * HexConfig::Num + x, document->length());
- return cursor->Position;
+ return qMin((cursor->Top + y) * HexConfig::Num + x, document->length());
}
-#undef MIN
void HexView::drawSelected(bool reset)
{
if (reset && cursor->Selected) {
//-- Reset selected lines
// Get selected lines
- begin = min(min(cursor->SelBegin, cursor->SelEnd), cursor->SelEndOld);
- end = max(max(cursor->SelBegin, cursor->SelEnd), cursor->SelEndOld);
+ begin = qMin(qMin(cursor->SelBegin, cursor->SelEnd), cursor->SelEndOld);
+ end = qMax(qMax(cursor->SelBegin, cursor->SelEnd), cursor->SelEndOld);
const int begin_line = begin / HexConfig::Num - cursor->Top;
const int end_line = end / HexConfig::Num - cursor->Top + 1;
cursor->Selected = false;
if ((cursor->SelBegin < cursor->SelEndOld && cursor->SelBegin >= cursor->SelEnd ||
cursor->SelBegin >= cursor->SelEndOld && cursor->SelBegin < cursor->SelEnd)) {
// Crossing between begin and end
- begin = min(min(cursor->SelBegin, cursor->SelEnd), cursor->SelEndOld);
- end = max(max(cursor->SelBegin, cursor->SelEnd), cursor->SelEndOld);
+ begin = qMin(qMin(cursor->SelBegin, cursor->SelEnd), cursor->SelEndOld);
+ end = qMax(qMax(cursor->SelBegin, cursor->SelEnd), cursor->SelEndOld);
} else {
// Minimum range
- begin = min(cursor->SelEnd, cursor->SelEndOld);
- end = max(cursor->SelEnd, cursor->SelEndOld);
+ begin = qMin(cursor->SelEnd, cursor->SelEndOld);
+ end = qMax(cursor->SelEnd, cursor->SelEndOld);
}
// Get redrawing lines
};
protected:
-
- void drawView();
- void drawView(int type, int = 0, int = 0);
- void drawLines(QPainter &painter, DCIList &dcolors, int y, int x_begin = 0, int x_end = HexConfig::Num); // x: [)
- void drawText(QPainter &painter, const QString &hex, int x, int y);
-
void resizeEvent(QResizeEvent *);
void mousePressEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
void timerEvent(QTimerEvent *);
-
void keyPressEvent(QKeyEvent *);
+ protected:
+
+ void drawView();
+ void drawView(int type, int = 0, int = 0);
+ void drawLines(QPainter &painter, DCIList &dcolors, int y, int x_begin = 0, int x_end = HexConfig::Num); // x: [)
+ void drawText(QPainter &painter, const QString &hex, int x, int y);
+
+
void isSelected(bool &selected, quint64 &sb, quint64 &se, quint64 top, int yCount, uint size);
bool isSelected(quint64 pos);
void drawSelected(bool reset = false);
void drawCaretBlock(CaretDrawInfo &);
void byteToHex(uchar c, QString &h);
- quint64 moveByMouse(int x, int y);
+ quint64 posAt(const QPoint &pos);
- public slots:
void drawCaret(bool visible = true);
void drawCaret(bool visible, quint64 pos);