OSDN Git Service

add key input event at hexview.cpp
authorsuma <suma@users.sourceforge.jp>
Thu, 21 May 2009 01:52:13 +0000 (10:52 +0900)
committersuma <suma@users.sourceforge.jp>
Thu, 21 May 2009 01:52:13 +0000 (10:52 +0900)
src/control/standard/hexview.cpp
src/control/standard/hexview.h

index e1bc417..9eb173d 100644 (file)
@@ -583,18 +583,28 @@ void HexView::keyPressEvent(QKeyEvent *ev)
                                if (nibble < 0) {
                                        continue;
                                }
-                               if (cursor_->HighNibble) {
-                                       // TODO: insert/rewrite document
-                                       //changeData(m_cursorPosition, (nibble << 4) + (m_data[m_cursorPosition] & 0x0f), true);
-                                       cursor_->HighNibble = false;
-                                       // Clear and redraw caret
-                                       drawView(DRAW_LINE, cursor_->Position / HexConfig::Num - cursor_->Top);
-                                       drawCaret();
-                               } else {
-                                       // TODO: insert/rewrite document
-                                       //changeData(m_cursorPosition, nibble + (m_data[m_cursorPosition] & 0xf0));
+                               //if (cursor_->Insert) {
+                               if (false) {
+                                       // Inserte mode
+                                       quint64 pos = cursor_->Position + (cursor_->HighNibble ? 0 : 1);
                                        cursor_->HighNibble = true;
-                                       cursor_->moveRelativePosition(1, false, false);
+                                       insertData(pos, nibble);
+                               } else if (cursor_->Position < document_->length()) {
+                                       // Ovewrite mode
+                                       uchar currentCharacter;
+                                       document_->get(cursor_->Position, &currentCharacter, 1);
+                                       if (cursor_->HighNibble) {
+                                               changeData(cursor_->Position, (nibble << 4) + (currentCharacter & 0x0f), true);
+                                               cursor_->HighNibble = false;
+                                               // TODO: fix Clear and redraw caret, implment Event
+                                               drawView(DRAW_LINE, cursor_->Position / HexConfig::Num - cursor_->Top);
+                                               drawCaret();
+                                       } else {
+                                               changeData(cursor_->Position, nibble + (currentCharacter & 0xf0));
+                                               cursor_->moveRelativePosition(1, false, false);
+                                       }
+                               } else {
+                                       break;
                                }
                        }
                }
@@ -602,4 +612,21 @@ void HexView::keyPressEvent(QKeyEvent *ev)
        }
 }
 
+void HexView::changeData(quint64 pos, uchar character, bool highNibble)
+{
+       document_->remove(pos, 1);
+       document_->insert(pos, &character, 1);
+       cursor_->HighNibble = !cursor_->HighNibble;
+       // TODO: implement Redraw Event
+}
+
+void HexView::insertData(quint64 pos, uchar character)
+{
+       document_->insert(pos, &character, 1);
+       // TODO: implement Redraw Event
+       drawView(DRAW_AFTER, cursor_->Position / HexConfig::Num);
+       drawCaret();
+}
+
+
 }      // namespace
index b217ff5..524253f 100644 (file)
@@ -169,6 +169,9 @@ namespace Standard {
                void drawCaretBlock(const CaretDrawInfo &);
                void drawCaretUnderbar(const CaretDrawInfo &);
 
+               void changeData(quint64 pos, uchar character, bool highNibble = false);
+               void insertData(quint64 pos, uchar character);
+
        protected:
                // Main components
                HexConfig config_;