void CHexWidget::keyPressed(QKeyEvent *event) { int key = event->key(); if((key >= Qt::Key_0 && key <= Qt::Key_9) || (key >= Qt::Key_A && key <= Qt::Key_F)) { /*if(m_currUndoPoint != m_undoList.begin()) { m_undoList.erase(m_undoList.begin(), m_currUndoPoint); }*/ int byte = m_currentFile.getByte(m_uiCurrentLine, m_uiCurrentByte/2); Modification mod; mod.line = m_uiCurrentLine; mod.byte = m_uiCurrentByte/2; mod.value = byte; m_undoList.insert(m_currUndoPoint, mod); m_currUndoPoint--; if(byte == -1) { QWidget::keyPressEvent(event); return; } if(m_uiCurrentByte % 2 == 0) { // MSB selected byte = (keyToHexValue(key) << 4) + (byte & 0x0F); } else { // LSB selected byte = keyToHexValue(key) + (byte & 0xF0); } byte = byte & 0x00FF; m_currentFile.setByte(m_uiCurrentLine, m_uiCurrentByte/2, byte); moveCursorX(1); } else { switch(key) { case Qt::Key_U: if((event->modifiers() & Qt::ShiftModifier) == 0) undo(); else redo(); break; case Qt::Key_H: case Qt::Key_Left: moveCursorX(-1); break; case Qt::Key_L: case Qt::Key_Right: moveCursorX(1); break; case Qt::Key_K: case Qt::Key_Up: if(m_uiCurrentLine != 0) m_uiCurrentLine -= 1; break; case Qt::Key_J: case Qt::Key_Down: if(m_uiCurrentLine + 1 < m_currentFile.getLineCount()) m_uiCurrentLine += 1; break; default: QWidget::keyPressEvent(event); return; } } m_cursorPosY = lineToYCoord(m_uiCurrentLine); this->update(); }
void readStr(string buffstr, uint32 bufSize) { uint32 i = 0; bool reading = true; while(reading) { //exit the writer program when the Ctrl-Z key is pressed if (progexit && writing) { clearScreen(); updateCursor(); writing = false; progexit = false; print("Q-Kernel> ", 0x08); } if (newCmd && typingCmd) { startCmdX = cursorX; startCmdY = cursorY; newCmd = 0; } //Detect keypress and return string of characters pressed to the buffstr char array if(inportb(0x64) & 0x1) { uint8 value = inportb(0x60); if (deleteStopX > 0) { if ((cursorX == deleteStopX) && (cursorY == startCmdY)) { /* Make sure user cannot press delete anymore */ if (value == 14) continue; } } /* Make sure the user can only press delete */ if (buffOverflow) { if (value == 14) buffOverflow = false; else continue; } bool handled = false; switch(value) { case 29: // Left Ctrl Down ctrl = true; // Toggle On break; case 157: // Left Ctrl Up ctrl = false; // Toggle Off break; case 1: // Esc (Ctrl-z) if (writing) { progexit = true; reading = false; } else { i = pushCtrlChar(i, buffstr, 'Z', bufSize); } break; case 14: // Backspace if (lshift || rshift) { // On of the shifts are activated // Delete until space | non-word | different-cased-word i = backspaceMul(i, buffstr, bufSize); } else { // No shift -> delete one char i = backspaceOne(i, buffstr, bufSize); } break; case 25: if (ctrl) { if (writing) { moveUp(); handled = true; } } break; case 28: //This is the enter key, we need to add more functionality to it with Writer and other commands if (writing) { printch('\n',0x0F); buffstr[i] = '\n'; i++; } else { reading = false; } break; case 30: if (ctrl) { moveCursorX(-cursorX + deleteStopX); handled = true; } break; case 38: if (ctrl) { /* Make sure no clear screen during writer session */ if (!writing) { clearScreen(); // Returns command "skip" which does nothing strcpy(buffstr, "skip"); buffstr[4] = '\0'; /* Set EOL */ handled = true; return; } } break; case 42: //Left shift lshift = true; break; case 44: // z or Ctrl-Z if (ctrl) { if (writing) { progexit = true; reading = false; handled = true; } } break; case 48: if (ctrl) { moveCursorX(-1); handled = true; } break; case 49: if (ctrl) { if (writing) { moveDown(); handled = true; } } break; case 54: // Right shift on rshift = true; // Toggle On break; case 56: // Left/Right alt On alt = true; // Toggle On break; case 58: // Capslock down capslock = !capslock; break; case 72: //Up arrow if (writing) { moveUp(); } break; case 75: //Left Arrow moveCursorX(-1); break; case 77: //Right Arrow moveCursorX(1); break; case 80: //Down Arrow if (writing) { moveDown(); } break; case 170: // Left shift released (http://wiki.osdev.org/PS2_Keyboard) lshift = false; break; case 182: // Right shift released (http://wiki.osdev.org/PS2_Keyboard) rshift = false; // Toggle Off break; case 184: // Left/Right alt Off alt = false; // Toggle Off break; } if(!handled && chars[value]) { i = charKeyPressed(buffstr, value, i, bufSize); } } } buffstr[i] = 0; }