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(); }
void QKeyPushButton::mouseReleaseEvent(QMouseEvent * /* event */) { widgetKeyBoard *tmpKeyBoard = (widgetKeyBoard *) this->m_parent; bool pressedEcho = IS_PASSWORD(this->text()) == true || IS_PASSWORD_EMB(this->text()) == true; if (IS_CAPS(this->text()) == false && pressedEcho == false) { if (tmpKeyBoard->isEmbeddedKeyboard() == true && tmpKeyBoard->isZoomFacilityEnable() && NO_SPECIAL_KEY(this->text()) && this->text().trimmed().length() != 0) { tmpKeyBoard->setCursor(Qt::ArrowCursor); if (this->m_oldYKey != 0) this->setGeometry(this->x() + 10, this->m_oldYKey, KEY_WIDTH_EMBEDDED, KEY_HEIGHT_EMBEDDED); else this->setGeometry(this->x() + 10, this->y() + HEIGHT_ZOOM_KEY + KEY_HEIGHT_EMBEDDED, KEY_WIDTH_EMBEDDED, KEY_HEIGHT_EMBEDDED); this->m_oldYKey = 0; QCoreApplication::processEvents(); } this->setStyleSheet(QString(DEFAULT_STYLE_BUTTON) + QString(DEFAULT_BACKGROUND_BUTTON) + this->style_embedded); } else if (pressedEcho == true && tmpKeyBoard->isEnabledSwitchingEcho() == false && tmpKeyBoard->currentTextBox()->echoMode() == QLineEdit::Normal) this->setStyleSheet(QString(DEFAULT_STYLE_BUTTON) + QString(DEFAULT_BACKGROUND_BUTTON) + this->style_embedded); tmpKeyBoard->soundClick(); }
void QKeyPushButton::mousePressEvent(QMouseEvent * /*event */) { static bool m_capsActive = true; widgetKeyBoard *tmpKeyBoard = (widgetKeyBoard *) this->m_parent; static int yMarginKeyboard = tmpKeyBoard->rect().y(); QString text = this->text(); short adjustZoomedKey = HEIGHT_ZOOM_KEY; QString defaultStyleButton = QString(DEFAULT_STYLE_BUTTON); QString changedColorButton = QString(CHANGED_BACKGROUND_BUTTON); // // se si tratta del maiuscolo: if (IS_CAPS(text) == true) { if (m_capsActive == false) m_capsActive = true; else { changedColorButton = QString(DEFAULT_BACKGROUND_BUTTON); m_capsActive = false; } this->setStyleSheet(defaultStyleButton + changedColorButton + this->style_embedded); this->repaint(); QCoreApplication::processEvents(); } else if (tmpKeyBoard->isEnabledSwitchingEcho() == true && (IS_PASSWORD(text) == true || IS_PASSWORD_EMB(text) == true)) tmpKeyBoard->switchKeyEchoMode(tmpKeyBoard->currentTextBox()); else { this->setStyleSheet(defaultStyleButton + changedColorButton + this->style_embedded); this->repaint(); QCoreApplication::processEvents(); emit pressedKey(m_capsActive); } this->m_oldYKey = 0; if (tmpKeyBoard->isEmbeddedKeyboard() == true && tmpKeyBoard->isZoomFacilityEnable() && NO_SPECIAL_KEY(text) && text.trimmed().length() != 0) { tmpKeyBoard->setCursor(Qt::BlankCursor); if (this->y() - adjustZoomedKey - KEY_HEIGHT_EMBEDDED < yMarginKeyboard) this->m_oldYKey = this->y(); else adjustZoomedKey = -HEIGHT_ZOOM_KEY; this->setGeometry(this->x() - 10, this->y() + adjustZoomedKey - KEY_HEIGHT_EMBEDDED, KEY_WIDTH_EMBEDDED + WIDTH_ZOOM_KEY, KEY_HEIGHT_EMBEDDED + HEIGHT_ZOOM_KEY); this->setStyleSheet(changedColorButton + defaultStyleButton); 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); } }