inline void HexView::drawCaret(bool visible)
{
- drawCaret(visible, config_.top(), height());
+ drawCaret(visible, cur_->Position, config_.top(), height());
}
-void HexView::drawCaret(bool visible, int ytop, int ymax)
+inline void HexView::drawCaret(bool visible, quint64 pos)
{
- qDebug("drawCaret visible:%d ytop:%d ymax:%d sel:%llu top:%llu", visible, ytop, ymax, cur_->Position, cur_->Top);
+ drawCaret(visible, pos, config_.top(), height());
+}
+
+void HexView::drawCaret(bool visible, quint64 position, int ytop, int ymax)
+{
+ qDebug("drawCaret visible:%d ytop:%d ymax:%d sel:%llu top:%llu", visible, ytop, ymax, position, cur_->Top);
- int line = cur_->Position / HexConfig::Num - cur_->Top;
- const int x = cur_->Position % HexConfig::Num;
+ int line = position / HexConfig::Num - cur_->Top;
+ const int x = position % HexConfig::Num;
const int yt = ytop + line * config_.byteHeight();
const int y = yt + config_.ByteMargin.top();
qDebug("caret (line:%d x:%d)", line, x);
QPainter painter(&pix_);
painter.setFont(config_.Font);
- qDebug("draw caret (%llu) => (%d, %d)", cur_->Position, x, y);
+ qDebug("draw caret (%llu) => (%d, %d)", position, x, y);
// TODO: caching data/dcolors
// Compute selectead area
- if (doc_->length() <= cur_->Position) {
+ if (doc_->length() <= position) {
QBrush br(config_.Colors[Color::Background]);
painter.fillRect(config_.x(x), yt, config_.charWidth(2), config_.byteHeight(), br);
} else {
bool selected = false;
quint64 sb = 0, se = 0;
- isSelected(selected, sb, se, cur_->Position, 1, 1);
- ::DrawInfo di(ytop, cur_->Position, sb, se, 1, selected);
+ isSelected(selected, sb, se, position, 1, 1);
+ ::DrawInfo di(ytop, position, sb, se, 1, selected);
DCIList dlist;
getDrawColors(di, dlist, config_.Colors);
QString hex;
hex.resize(2);
- doc_->get(cur_->Position, &buff_[0], 1);
+ doc_->get(position, &buff_[0], 1);
byteToHex(buff_[0], hex);
painter.drawText(config_.x(x), y, config_.charWidth(2), config_.charHeight(), Qt::AlignCenter, hex);
}
if (visible) {
QBrush br(config_.Colors[Color::SelText]);
- painter.fillRect(config_.x(x), yt, config_.charWidth(1), config_.byteHeight(), br);
+ painter.fillRect(config_.x(x), yt, config_.caretWidth(), config_.caretHeight(), br);
}
update(config_.x(x), yt, config_.byteWidth(), config_.byteHeight());
}
if (ev->button() == Qt::LeftButton) {
grabMouse();
drawSelected(true);
- if (cur_->HexTimerId) {
- drawCaret(false);
- }
- cur_->SelBegin = cur_->SelEnd = cur_->SelEndO = moveByMouse(ev->pos().x(), ev->pos().y());
+ cur_->SelEndO = cur_->Position;
+ cur_->SelBegin = cur_->SelEnd = moveByMouse(ev->pos().x(), ev->pos().y());
cur_->Toggle = true;
- if (cur_->HexTimerId) {
+
+ if (cur_->HexTimerId && cur_->SelEnd != cur_->SelEndO) {
+ drawCaret(false, cur_->SelEndO);
drawCaret(true);
}
qDebug("press - begin:%lld", cur_->SelBegin);
if (cur_->Toggle) {
cur_->SelEndO = cur_->SelEnd;
- if (cur_->HexTimerId) {
- cur_->Position = cur_->SelEnd;
- drawCaret(false);
- }
-
cur_->SelEnd = moveByMouse(ev->pos().x(), ev->pos().y());
cur_->refreshSelected();
drawSelected();
- if (cur_->HexTimerId) {
- cur_->Position = cur_->SelEnd;
+ if (cur_->HexTimerId && cur_->SelEnd != cur_->SelEndO) {
+ drawCaret(false, cur_->SelEndO);
drawCaret(true);
}
}
qDebug("mouse release - begin:%lld end:%lld", cur_->SelBegin, cur_->SelEnd);
drawSelected();
+
+ if (cur_->HexTimerId && cur_->SelEnd != cur_->SelEndO) {
+ drawCaret(false, cur_->SelEndO);
+ drawCaret(true);
+ }
}
}
Q_ASSERT(0 <= i && i < Num);
return X_[i];
}
+ inline int caretWidth() const
+ {
+ return charWidth();
+ }
+ inline int caretHeight() const
+ {
+ return charHeight();
+ }
int drawableLines(int height) const;
int drawableLinesN(int height) const;
int XToPos(int x) const; // -1, 0..15, 16 => 18 patterns
void isSelected(bool &selected, quint64 &sb, quint64 &se, quint64 top, int yCount, uint size);
void drawSelected(bool reset = false);
void drawCaret(bool visible);
- void drawCaret(bool visible, int ytop, int ymax);
+ void drawCaret(bool visible, quint64 pos);
+ void drawCaret(bool visible, quint64 pos, int ytop, int ymax);
void byteToHex(uchar c, QString &h);
quint64 moveByMouse(int x, int y);