QString ScriptingWidget::getCommandText() const { QString strCommand; QString strText = toPlainText(); if (strText.isEmpty() == false) { strCommand = strText.mid(getCommandPosition()); } return strCommand; }
string getDataRepresentation(const void *data, uInt dtaLenght, const uint8_t *cmmTag, const uInt &cmmLength, const DataRepresentation dtaRep, uInt stringSize) { uInt cmmPosition = getCommandPosition(data, dtaLenght, cmmTag, cmmLength); if (cmmPosition != 0) { const uint8_t *castData = reinterpret_cast<const uint8_t *>(data); int sizeOffset = 0; if (stringSize <= 0) { stringSize = castData[cmmPosition + cmmLength]; sizeOffset = 1; } switch (dtaRep) { //Translates the binary information into an ASCII reaable string case STRING_REPRESENTATION: { string aStr(reinterpret_cast<const char*>(&(castData[cmmPosition + cmmLength + sizeOffset])), stringSize); return aStr; break; } //Translates the binary information into a decimal (0-9) reaable string case DECIMAL_REPRESENTATION: { std::stringstream ss; for (int k = 0; k < stringSize; k++) { ss << std::hex << setfill('0') << setw(2) << static_cast<unsigned int>( castData[cmmPosition + cmmLength + sizeOffset + k]); } return ss.str(); break; } case HEX_REPRESENTATION: { string aStr(reinterpret_cast<const char*>((int)&(castData[cmmPosition + cmmLength + sizeOffset])), stringSize); return aStr; break; } default: break; } } return "\0"; }
void ScriptingWidget::keyPressEvent(QKeyEvent* e) { if (e != NULL) { QTextCursor currentSelection = textCursor(); int iStartSelection = currentSelection.selectionStart(); int iEndSelection = currentSelection.selectionEnd(); int iCommandStart = getCommandPosition(); if ((e->key() == Qt::Key_Backspace) || (e->key() == Qt::Key_Left)) { // Do not move the cursor past the current command if (iStartSelection <= iCommandStart) { return; } } else if ((e->key() == Qt::Key_Up) || (e->key() == Qt::Key_Down)) { if (mCommandStack.empty() == false) { // Remove the current command text currentSelection.setPosition(iCommandStart); currentSelection.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, toPlainText().size() - iCommandStart); currentSelection.removeSelectedText(); // Get the next command in the stack if (e->key() == Qt::Key_Up) { if (mCommandIndex > 0) { mCommandIndex--; } } else if (e->key() == Qt::Key_Down) { // Let user go one past the end of the stack to clear command line. if (mCommandIndex < mCommandStack.count()) { mCommandIndex++; } } QString strCommand; if (mCommandIndex >= 0 && mCommandIndex < mCommandStack.count()) { strCommand = mCommandStack[mCommandIndex]; } else { // One past the end of the command stack, so clear the command text strCommand.clear(); } // Add the new command text currentSelection.insertText(strCommand); currentSelection.setPosition(currentSelection.selectionEnd()); setTextCursor(currentSelection); } return; } else if ((e->key() == Qt::Key_Return) || (e->key() == Qt::Key_Enter)) { executeCommand(); clipToMaxParagraphs(); return; } else { // Do not overwrite selected text from previous entries if (iStartSelection < iCommandStart) { // Set the cursor to the start of the current command currentSelection.setPosition(iCommandStart); // Select the portion of the command that was previously selected if (iEndSelection >= iCommandStart) { currentSelection.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, iEndSelection - iCommandStart); } } setTextCursor(currentSelection); // Set the command font as the current font setCurrentFont(mCommandFont); } } QTextEdit::keyPressEvent(e); }