QKeyPushButton * widgetKeyBoard::createNewKey(QString keyValue) { QKeyPushButton *tmp = new QKeyPushButton(this); QString style = QString(DEFAULT_STYLE_BUTTON) + QString(DEFAULT_BACKGROUND_BUTTON); QSize imageDim; int width = 0, height = 0; if (this->isEmbeddedKeyboard() == true) { imageDim.setWidth(16); imageDim.setHeight(16); } else { imageDim.setWidth(32); imageDim.setHeight(32); } if (IS_PASSWORD(keyValue) == true || IS_PASSWORD_EMB(keyValue) == true) { tmp->setIconSize(imageDim); tmp->setIcon(QPixmap(":/TastieraVirtuale/normalEcho")); } else if (IS_PASTE(keyValue) == true) { tmp->setIconSize(imageDim); tmp->setEnabled(false); tmp->setIcon(QPixmap(":/TastieraVirtuale/paste")); } else if (IS_COPY(keyValue) == true) { tmp->setIconSize(imageDim); tmp->setIcon(QPixmap(":/TastieraVirtuale/copy")); } else if (IS_CUT_LEFT(keyValue) == true) { tmp->setIconSize(imageDim); tmp->setIcon(QPixmap(":/TastieraVirtuale/cut")); } tmp->setText(keyValue); if (this->isEmbeddedKeyboard() == true) { width = KEY_WIDTH_EMBEDDED; height = KEY_HEIGHT_EMBEDDED; style += QString(EMBEDDED_KEYBOARD); } else { width = 54; height = 40; } tmp->setObjectName(keyValue); tmp->setMinimumSize(width, height); tmp->setMaximumSize(width, height); tmp->setStyleSheet(style); tmp->setVisible(true); return (tmp); }
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); } }