int handle_cntrl_char (int c, char *cmd) { if(IS_BACK_SPACE(c)) { if(cmd[0] == '\0') return 0; write (gfd,"\b \b",sizeof("\b \b")); cmd[strlen(cmd) - 1] = '\0'; return 0; } else if(c == 0x1b ) { c = read_input(); c = read_input(); if(c == 65) { return 0; } else if(c == 66) { } return 0; } else if(IS_HELP_CHAR(c)) { write_input_on_screen (c); is_help = 1; handle_help(cmd, 0); is_help = 0; goto cmd_print; } else if(IS_TAB(c)) { handle_tab (cmd); goto cmd_print; } else { return 1; } cmd_print: print_prompt (); write_string (cmd); return 0; }
void QKeyPushButton::getKeyPress(bool capsStatus) { int keyCode = 0; QKeyEvent *key = NULL; QString text = this->text(); // // per tutti i car speciali tranne il CAPS (RETURN, ALT, SHIFT, ecc...) inoltra al componente widgetKeyBoard: if (NO_SPECIAL_KEY(text) == false && (IS_BACK(text) == true || IS_BACK_EMB(text) == true || IS_TAB(text) == true || IS_RETURN(text) == true || IS_CTRL_LEFT(text) == true || IS_ALT(text) == true || IS_CANC(text) == true || IS_CUT_LEFT(text) == true || IS_PASSWORD(text) || IS_PASSWORD_EMB(text) || IS_PASTE(text) || IS_COPY(text))) key = new QKeyEvent(QEvent::KeyPress, keyCode, Qt::NoModifier, text); else { // trattasi di caratteri stampabili keyCode = text.toAscii()[0]; // prende il valore numerico (sempre maiuscolo) if (capsStatus == false) { // se deve prendere minuscolo, controlla se il carattere รจ alfabetico if (keyCode >= tr("A")[0] && keyCode <= tr("Z")[0]) { keyCode += 32; // carattere piccolo text = (char ) keyCode; // carattere piccolo } key = new QKeyEvent(QEvent::KeyPress, keyCode, Qt::NoModifier, text); } else key = new QKeyEvent(QEvent::KeyPress, keyCode, Qt::ShiftModifier, text); } ((widgetKeyBoard *) this->m_parent)->receiptChildKey(key, NULL); QCoreApplication::processEvents(); }
// // riceve i caratteri che sono stati digitati: void widgetKeyBoard::receiptChildKey(QKeyEvent *event, QLineEdit *focusThisControl, bool reset) { static QLineEdit *nextInput = NULL; if (reset == true) { // reinizializza il controllo nextInput = this->getNextTextbox(focusThisControl, true); return; } if (nextInput == NULL) return; // // inizia l'analisi del carattere ricevuto: QString newKey = event->text(); QString tmpReceiptString = nextInput->text(); int tmpPos = nextInput->cursorPosition(); if (NO_SPECIAL_KEY(newKey) == false) { if (IS_RETURN(newKey) == true || IS_TAB(newKey) == true) { // trattasi di TAB, si sposta alla text successiva nextInput = this->setDefaultTextStyle(nextInput); nextInput->deselect(); nextInput = this->getNextTextbox(); this->controlKeyEcho(nextInput); // status of key echo here if (nextInput != NULL) { nextInput->setCursorPosition(nextInput->text().length()); // comment this line if you want caret position at current char inserted nextInput->setFocus(Qt::TabFocusReason); } } else if (IS_BACK(newKey) == true || IS_BACK_EMB(newKey) == true) { // trattasi di CANCELLARE carattere, elimina il carattere a sinistra if (tmpPos-1 >= 0) { tmpReceiptString = tmpReceiptString.remove(tmpPos-1, 1); nextInput->setText(tmpReceiptString); nextInput->setCursorPosition(tmpPos-1); nextInput->setSelection(tmpPos-2, 1); } } else if (IS_CANC(newKey) == true) { // trattasi di CANC carattere, elimina il carattere a destra tmpReceiptString = tmpReceiptString.remove(tmpPos, 1); nextInput->setText(tmpReceiptString); nextInput->setCursorPosition(tmpPos); nextInput->setSelection(tmpPos-1, 1); } else if (IS_COPY(newKey) == true || IS_CUT_LEFT(newKey) == true) { QPushButton *button = this->findChild<QPushButton *>(KEY_PASTE); if (button != NULL) { if (nextInput->text().length() != 0) { this->m_clipboard->setText(nextInput->text()); if (IS_CUT_LEFT(newKey) == true) nextInput->setText(""); button->setEnabled(true); } else button->setEnabled(false); } } else if (IS_PASTE(newKey) == true) nextInput->setText(this->m_clipboard->text()); else if (IS_ALT(newKey) == true || IS_CTRL_LEFT(newKey) == true) ; // non esegue nessuna operazione } else { // si tratta di un carattere da visualizzare nella casella di testo corrente tmpReceiptString = tmpReceiptString.insert(tmpPos, newKey); nextInput->setText(tmpReceiptString); nextInput->setCursorPosition(tmpPos+1); nextInput->setSelection(tmpPos, 1); } }