void HexView::drawView(DrawMode mode, int line_start, int end)
{
- qDebug("refresh event mode:%d line:%d end:%d", mode, line_start, end);
- qDebug(" end:%llu endOld:%llu pos:%llu", cursor->SelEnd, cursor->SelEndOld, cursor->Position);
+ //qDebug("refresh event mode:%d line:%d end:%d", mode, line_start, end);
+ //qDebug(" end:%llu endOld:%llu pos:%llu", cursor->SelEnd, cursor->SelEndOld, cursor->Position);
// FIXME: refactoring refresh event
QPainter painter;
void HexView::mousePressEvent(QMouseEvent *ev)
{
if (ev->button() == Qt::LeftButton) {
- qDebug("mosue press pos:%llu end:%llu endO:%llu el:%llu", cursor->Position, cursor->SelEnd, cursor->SelEndOld, cursor->SelEnd / HexConfig::Num);
+ //qDebug("mosue press pos:%llu end:%llu endO:%llu el:%llu", cursor->Position, cursor->SelEnd, cursor->SelEndOld, cursor->SelEnd / HexConfig::Num);
#if 0
// Draw selected lines
// Start mouse capture
grabMouse();
- qDebug("end PressEvent");
+ //qDebug("end PressEvent");
}
}
return;
}
- qDebug("mouse move");
+ //qDebug("mouse move");
#if 0
// Set moved position to OLD
cursor->SelEndOld = cursor->SelEnd;
return;
}
- qDebug("mouse release");
+ //qDebug("mouse release");
// End mouse capture
releaseMouse();
// TODO: support keyboard remap
if (ev->modifiers() == Qt::NoModifier) {
- qDebug("keypress:[%s]", ev->text().toStdString().c_str());
+ //qDebug("keypress:[%s]", ev->text().toStdString().c_str());
} else {
- qDebug("keypress:[%s] with modifier", ev->text().toStdString().c_str());
+ //qDebug("keypress:[%s] with modifier", ev->text().toStdString().c_str());
}
- quint64 old = cursor->SelEnd;
- quint64 oldT = cursor->Top;
+ bool keepAnchor = ev->modifiers() & Qt::SHIFT ? true : false;
switch (ev->key()) {
case Qt::Key_Home:
- cursor->Home();
+ //cursor->Home();
+ cursor->movePosition(0, keepAnchor, false);
break;
case Qt::Key_End:
cursor->End();
break;
case Qt::Key_Left:
- cursor->Left();
+ cursor->moveRelativePosition(-1, keepAnchor, false);
break;
case Qt::Key_Right:
- cursor->Right();
+ cursor->moveRelativePosition(1, keepAnchor, false);
break;
case Qt::Key_Up:
- cursor->Up();
+ cursor->moveRelativePosition(-16, keepAnchor, false);
break;
case Qt::Key_Down:
- cursor->Down();
+ cursor->moveRelativePosition(16, keepAnchor, false);
break;
case Qt::Key_PageUp:
- cursor->PageUp();
+ cursor->moveRelativePosition(-16 * 15, keepAnchor, false);
break;
case Qt::Key_PageDown:
- cursor->PageDown();
+ cursor->moveRelativePosition(16 * 15, keepAnchor, false);
break;
case Qt::Key_Backspace:
qDebug("key backspace");
default:
return;
}
- cursor->SelEndOld = cursor->SelEnd;
-
- if (ev->modifiers() != Qt::SHIFT) {
- }
-
- // FIXME: refactoring refresh event
- if (cursor->SelEnd != old || cursor->Top != oldT) {
- drawView();
- drawCaret();
- }
if (ev->modifiers() != Qt::NoModifier) {
} else {
#include <algorithm>
+#include <limits>
#include "scursor.h"
#include "../document.h"
#include "hexview.h"
void Cursor::movePosition(quint64 pos, bool sel, bool hold_vpos)
{
- // 移動で選択操作をするとき
- // 1.古い位置のキャレットを消す描画 2.カーソル位置を更新する 3.選択範囲の行のみ再描画 4. キャレット描画 という流れになるようだ。選択じゃないときは少しプロセスが減る。
- // 移動だけのときは
- // 1.カーソル位置移動 2.古いカーソル位置の再描画(必要があれば) 3. キャレット再描画
-
Q_ASSERT(pos <= document->length());
+ // FIXME: replace drawView/drawCaret callings to udpate event
- const quint64 old_top = Top;
-
-
if (!Selection) {
if (sel) {
- // # Begin selection
+ //-- Begin selection --
// Draw selected lines
view->drawSelected(true);
setSelection(true);
} else {
- // normal move
+ //-- Normal move --
// only redrawCaret
+ quint64 top = Top;
+ int vpos_line;
+ if (hold_vpos) {
+ vpos_line = (Top - Position) / HexConfig::Num;
+ }
+
+ const bool goDown = Position < pos;
+
+ if (goDown) {
+ const int count_line = view->getConfig().drawableLines(view->height()) - 1;
+ const quint64 pos_line = pos / HexConfig::Num;
+
+ // if Top + count_line < pos_line then Pos is invisible
+ if (count_line <= pos_line && Top <= pos_line - count_line) {
+ qDebug("Top:%llu, pos_line:%llu, count_line:%d", pos_line, count_line);
+ top = pos_line - count_line + 1;
+ }
+ } else {
+ top = qMin(pos / HexConfig::Num, Top);
+ }
+
+ if (hold_vpos) {
+ //Top;
+ }
+
+ if (Top == top && Position != pos) {
+ qDebug("---- disable caret");
+ const int line = (SelEndOld / HexConfig::Num) - Top;
+ view->drawView(HexView::DRAW_RANGE, line, line + 1);
+ }
+
+ SelEndOld = SelEnd = SelBegin = Position = pos;
+ qDebug("Top:%llu, Pos:%llu, top:%llu", Top, Position, top);
+ if (Top != top) {
+ qDebug("---- draw all");
+ Top = top;
+ view->drawView();
+ }
+
+ view->drawCaret();
}
} else {
if (sel) {
- // # Move selection
+ //-- Move selection
// Set moved position to OLD
SelEndOld = SelEnd;
// Redraw updated lines
view->drawSelected(false);
- //-- Redraw caret if caret selection moved
+ //-- Redraw caret if caret selection moved --
if (view->getConfig().EnableCaret && SelEnd != SelEndOld) {
view->drawCaret();
setHexCaretVisible(false);
}
} else {
- // # End selection
+ //-- End selection --
// Set moved position
SelEnd = Position = pos;
refreshSelected();
}
}
}
- // if !selected
- // drawSelected(true)
- // selEnd = pos = newpos
- // redrawCaret
- // f refresh =>
- // selEnd= Pos = newPos
- // drawSelected(false);
- // drawCaret
-
- if (old_top == Top) {
- if (!sel && Selected) {
- // beginning selection
- //drawSelected(true);
- } else {
- //drawSelected(false);
- }
- }
}
void Cursor::moveRelativePosition(qint64 pos, bool sel, bool hold_vpos)
{
+ quint64 abs = static_cast<quint64>(qAbs(pos));
+ quint64 okPos = 0;
+ if (pos < 0) {
+ if (Position < abs) {
+ okPos = 0;
+ } else {
+ okPos = Position - abs;
+ }
+ } else {
+ okPos = Position + abs;
+ if (okPos < Position || okPos < abs || document->length() < okPos) { // check overed
+ okPos = document->length();
+ }
+ }
+ qDebug("pos:%lld, abs:%llu, okPos: %llu", pos, abs, okPos);
+ movePosition(okPos, sel, hold_vpos);
}
void Cursor::refreshTopByDown()