/** * Checks if the user is still composing */ void ChatDlg::checkComposing() { if (!isComposing_) { // User stopped composing composingTimer_->deleteLater(); composingTimer_ = 0; emit composing(false); } isComposing_ = false; // Reset composing }
/** * Records that the user is composing */ void ChatDlg::setComposing() { if (!composingTimer_) { /* User (re)starts composing */ composingTimer_ = new QTimer(this); connect(composingTimer_, SIGNAL(timeout()), SLOT(checkComposing())); composingTimer_->start(2000); // FIXME: magic number emit composing(true); } isComposing_ = true; }
bool ChatTextEdit::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = (QKeyEvent *) event; if (keyEvent->key() == Qt::Key_Up) { // Key up QTextCursor cursor = textCursor(); int pos = cursor.position(); bool sel = keyEvent->modifiers() == Qt::ShiftModifier; cursor.movePosition(QTextCursor::Up, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor)); if (pos == cursor.position()) cursor.movePosition(QTextCursor::Start, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor)); setTextCursor(cursor); return true; } else if (keyEvent->key() == Qt::Key_Down) { // Key down QTextCursor cursor = textCursor(); int pos = cursor.position(); bool sel = keyEvent->modifiers() == Qt::ShiftModifier; cursor.movePosition(QTextCursor::Down, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor)); if (pos == cursor.position()) cursor.movePosition(QTextCursor::End, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor)); setTextCursor(cursor); return true; } else if (keyEvent->nativeScanCode() == 36) { // Return pressed if (Client::enterIsSend && !(keyEvent->modifiers() & Qt::ShiftModifier)) { isComposing = false; emit returnPressed(); return true; } } else if (keyEvent->nativeScanCode() == 54 && keyEvent->modifiers() == Qt::ControlModifier) { // Copy QTextCursor cursor = textCursor(); if (cursor.hasSelection()) { QTextDocumentFragment selection = cursor.selection(); QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(Utilities::htmlToWAText(selection.toHtml())); QMaemo5InformationBox::information(this,"Copied"); return true; } } else if (keyEvent->nativeScanCode() == 55 && keyEvent->modifiers() == Qt::ControlModifier) { // Paste event QTextCursor cursor = textCursor(); QClipboard *clipboard = QApplication::clipboard(); cursor.insertHtml(Utilities::WATextToHtml(clipboard->text(),32,false)); return true; } else if (!isComposing) { isComposing = true; emit composing(); } else { lastKeyPressed = QDateTime::currentMSecsSinceEpoch(); composingTimer.start(2000); } } else if (event->type() == QEvent::InputMethod) { QInputMethodEvent *inputEvent = (QInputMethodEvent *) event; //Utilities::logData("Commit String: '" + inputEvent->commitString() + "'"); if (inputEvent->commitString() == "\n" && Client::enterIsSend) { // Let's hide the keyboard if it was shown QTimer::singleShot(0,this,SLOT(closeKB())); isComposing = false; emit returnPressed(); return true; } } return QTextEdit::eventFilter(obj,event); }