OSDN Git Service

fixed selection drawing bugs
authorsuma <suma@users.sourceforge.jp>
Tue, 10 Mar 2009 04:34:13 +0000 (13:34 +0900)
committersuma <suma@users.sourceforge.jp>
Tue, 10 Mar 2009 04:34:13 +0000 (13:34 +0900)
src/control/standard/hexview.cpp
src/control/standard/hexview.h
src/control/standard/scursor.cpp
src/control/standard/scursor.h

index dad4cfc..fb77864 100644 (file)
@@ -435,7 +435,6 @@ void HexView::byteToHex(uchar c, QString &h)
 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);
 
                cursor->movePosition(posAt(ev->pos()), false, false);
 
@@ -453,13 +452,12 @@ void HexView::mouseMoveEvent(QMouseEvent *ev)
        cursor->movePosition(posAt(ev->pos()), true, false);
 }
 
-void HexView::mouseReleaseEvent(QMouseEvent *ev)
+void HexView::mouseReleaseEvent(QMouseEvent *)
 {
        //qDebug("mouse release");
 
        // End mouse capture
        releaseMouse();
-       //cursor->movePosition(posAt(ev->pos()), true, false);
 }
 
 quint64 HexView::posAt(const QPoint &pos)
@@ -477,46 +475,6 @@ quint64 HexView::posAt(const QPoint &pos)
        return qMin((cursor->Top + y) * HexConfig::Num + x, document->length());
 }
 
-void HexView::drawSelected(bool reset)
-{
-       /*
-       const quint64 SelBegin = cursor->SelBegin;
-       const quint64 SelEnd = cursor->SelEnd;
-       const quint64 SelEndOld = cursor->SelEndOld;
-       quint64 begin, end;
-       if (reset && cursor->Selected) {
-               //-- Reset selected lines
-               // Get selected lines
-               begin = qMin(qMin(SelBegin, SelEnd), SelEndOld);
-               end   = qMax(qMax(SelBegin, SelEnd), SelEndOld);
-               const int begin_line = begin / HexConfig::Num - cursor->Top;
-               const int end_line   = end   / HexConfig::Num - cursor->Top + 1;
-               cursor->Selected = false;
-
-               // Redraw lines
-               drawView(DRAW_RANGE, begin_line, end_line);
-       } else if (cursor->selMoved()) {
-               // Selected range is changing
-               if ((SelBegin < SelEndOld && SelBegin >= SelEnd ||
-                       SelBegin >= SelEndOld && SelBegin < SelEnd)) {
-                       // Crossing between begin and end
-                       begin = qMin(qMin(SelBegin, SelEnd), SelEndOld);
-                       end   = qMax(qMax(SelBegin, SelEnd), SelEndOld);
-               } else {
-                       // Minimum range
-                       begin = qMin(SelEnd, SelEndOld);
-                       end   = qMax(SelEnd, SelEndOld);
-               }
-
-               // Get redrawing lines
-               const int begin_line = begin / HexConfig::Num - cursor->Top;
-               const int end_line   = end   / HexConfig::Num - cursor->Top + 1;
-               // Redraw lines
-               drawView(DRAW_RANGE, begin_line, end_line);
-       }
-       */
-}
-
 // Enable caret blink
 void HexView::setCaretBlink(bool enable)
 {
index 3025943..27b127e 100644 (file)
@@ -144,7 +144,9 @@ namespace Standard {
 
 
        public:
+               // TODO change signal
                void drawView(DrawMode mode = DRAW_ALL, int = 0, int = 0);
+
        protected:
                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);
@@ -152,8 +154,6 @@ namespace Standard {
 
                void isSelected(bool &selected, quint64 &sb, quint64 &se, quint64 top, int yCount, uint size);
                bool isSelected(quint64 pos);
-       public:
-               void drawSelected(bool reset = false);
        protected:
 
                void byteToHex(uchar c, QString &h);
index d9c3869..8e502d9 100644 (file)
@@ -73,22 +73,37 @@ void Cursor::movePosition(quint64 pos, bool sel, bool hold_vpos)
                }
        }
 
-       if (!sel) {
-               PositionAnchor = pos;
-       }
        Position = pos;
+       PositionAnchor = sel ? PositionAnchor : Position;
 
        if (Top == oldTop) {
-               int line_pos, line_anchor;
-               if (Position != oldPos) {
-                       view->drawView(HexView::DRAW_LINE, oldPos / HexConfig::Num - oldTop);
-               }
-               if (oldSelection) {
-                       redrawSelection(qMin(oldPos, oldPosAnchor), qMax(oldPos, oldPosAnchor), oldTop);
-               }
-               if (hasSelection()) {
-                       redrawSelection(qMin(Position, PositionAnchor), qMax(Position, PositionAnchor), Top);
+               if (!sel && oldSelection) {
+                       //qDebug("A");
+                       redrawSelection(qMin(oldPos, oldPosAnchor), qMax(oldPos, oldPosAnchor));
+               } else if (oldSelection && Position != oldPos) {
+                       quint64 begin, end;
+                       if (PositionAnchor < oldPos && PositionAnchor >= Position ||
+                               PositionAnchor >=oldPos && PositionAnchor < Position) {
+                               // Crossing between begin and end
+                               begin = qMin(qMin(Position, PositionAnchor), oldPos);
+                               end   = qMax(qMax(Position, PositionAnchor), oldPos);
+                               //qDebug("B - crossing %llu, %llu", begin/16, end/16);
+                       } else {
+                               // Minimum range
+                               if (Position < oldPos) {
+                                       begin = qMin(Position, oldPos);
+                                       end   = qMax(qMax(Position, oldPos), PositionAnchor);
+                               } else {
+                                       begin = qMin(qMin(Position, oldPos), PositionAnchor);
+                                       end   = qMax(Position, oldPos);
+                               }
+                               //qDebug("C - Pos:%llu, oldPos:%llu Anch:%llu oldAnch:%llu", Position/16, oldPos/16, PositionAnchor/15, oldPosAnchor/16);
+                               //qDebug("C - minimum %llu, %llu", begin, end);
+                       }
+                       redrawSelection(begin, end);
                }
+               // 
+               view->drawView(HexView::DRAW_LINE, oldPos / HexConfig::Num - Top);
        } else {
                view->drawView();
        }
@@ -99,37 +114,36 @@ void Cursor::movePosition(quint64 pos, bool sel, bool hold_vpos)
 
 void Cursor::moveRelativePosition(qint64 pos, bool sel, bool hold_vpos)
 {
-       quint64 abs = static_cast<quint64>(qAbs(pos));
+       quint64 diff = static_cast<quint64>(qAbs(pos));
        quint64 okPos = 0;
        if (pos < 0) {
-               if (Position < abs) {
+               if (Position < diff) {
                        okPos = 0;
                } else {
-                       okPos = Position - abs;
+                       okPos = Position - diff;
                }
        } else {
-               if (Position < numeric_limits<quint64>::max() - abs && Position + abs <= document->length()) {
-                       okPos = Position + abs;
+               if (Position < numeric_limits<quint64>::max() - diff && Position + diff <= document->length()) {
+                       okPos = Position + diff;
                } else {
                        okPos = document->length();
                }
        }
-       //qDebug("pos:%lld, abs:%llu, okPos: %llu", pos, abs, okPos);
+       //qDebug("pos:%lld, diff:%llu, okPos: %llu", pos, diff, okPos);
        movePosition(okPos, sel, hold_vpos);
 }
 
-void Cursor::redrawSelection(quint64 begin, quint64 end, quint64 top)
+void Cursor::redrawSelection(quint64 begin, quint64 end)
 {
-       qDebug("redrawSelection %llu, %llu, Top:%llu", begin, end, top);
+       //qDebug("redrawSelection %llu, %llu, Top:%llu", begin, end, Top);
        int beginLine, endLine;
        begin /= HexConfig::Num;
        end   /= HexConfig::Num;
 
-       Q_ASSERT(end > top);
-
-       beginLine = qMax(begin, top) - top;
-       endLine   = end - top;
+       beginLine = qMax(begin, Top) - Top;
+       endLine   = qMax(end, Top) - Top;
 
+       //qDebug("redrawSelection %d, %d, Top:%llu", beginLine, endLine, Top);
        view->drawView(HexView::DRAW_RANGE, beginLine, endLine + 1);
 }
 
index 8ae410d..3277fd9 100644 (file)
@@ -81,7 +81,7 @@ namespace Standard {
                void moveRelativePosition(qint64 pos, bool sel, bool hold_vpos);
 
        private:
-               void redrawSelection(quint64, quint64, quint64 top);
+               void redrawSelection(quint64, quint64);
 
        };