void HistoryLineEdit::returnPressed( ) { m_history->append( text( ) ); m_pos = m_history->size( ); emit lineEntered( text( ) ); clear( ); }
void ApplicationConsole::keyPressEvent(QKeyEvent *keyEvent) { int cursorPos = this->textCursor().position(); if( cursorPos < m_userInputStartPosition) { this->moveCursor(QTextCursor::End); } int key = keyEvent->key(); // only delete the previous char if the cursor is ahead the start of the modifiable text if(key == Qt::Key_Backspace && m_userInputStartPosition >= cursorPos) { keyEvent->ignore(); return; } QPlainTextEdit::keyPressEvent(keyEvent); keyEvent->accept(); if(key == Qt::Key_Enter || key == Qt::Key_Return) { // read the written text and emit a signal QString line; QTextCursor tmp = this->textCursor(); tmp.setPosition(m_userInputStartPosition); tmp.setPosition(this->toPlainText().count(), QTextCursor::KeepAnchor); line = tmp.selectedText(); emit lineEntered(line); m_userInputStartPosition = this->toPlainText().count(); } }