summary refs log tree commit diff
path: root/src/TextInputWidget.cc
diff options
context:
space:
mode:
authorThomas Herzog <thomas.herzog@mail.com>2017-10-31 19:11:49 +0100
committermujx <mujx@users.noreply.github.com>2017-10-31 20:11:49 +0200
commit287b5aa4c0d52e1ac80a0785ab136aa0f98b3e9f (patch)
tree8535d6ec3717ba551b17fc70f0cc80306273e82c /src/TextInputWidget.cc
parentAdd missing headers (diff)
downloadnheko-287b5aa4c0d52e1ac80a0785ab136aa0f98b3e9f.tar.xz
Implemented sending of typing notifications (#105)
Diffstat (limited to 'src/TextInputWidget.cc')
-rw-r--r--src/TextInputWidget.cc36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/TextInputWidget.cc b/src/TextInputWidget.cc
index 0d5e1102..7ebef6b1 100644
--- a/src/TextInputWidget.cc
+++ b/src/TextInputWidget.cc
@@ -29,15 +29,37 @@ FilteredTextEdit::FilteredTextEdit(QWidget *parent)
   : QTextEdit(parent)
 {
         setAcceptRichText(false);
+
+        typingTimer_ = new QTimer(this);
+        typingTimer_->setInterval(1000);
+        typingTimer_->setSingleShot(true);
+
+        connect(typingTimer_, &QTimer::timeout, this, &FilteredTextEdit::stopTyping);
 }
 
 void
 FilteredTextEdit::keyPressEvent(QKeyEvent *event)
 {
-        if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
+        if (!typingTimer_->isActive()) {
+                emit startedTyping();
+        }
+
+        typingTimer_->start();
+
+        if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
+                stopTyping();
+
                 emit enterPressed();
-        else
+        } else {
                 QTextEdit::keyPressEvent(event);
+        }
+}
+
+void
+FilteredTextEdit::stopTyping()
+{
+        typingTimer_->stop();
+        emit stoppedTyping();
 }
 
 TextInputWidget::TextInputWidget(QWidget *parent)
@@ -104,6 +126,10 @@ TextInputWidget::TextInputWidget(QWidget *parent)
                 SIGNAL(emojiSelected(const QString &)),
                 this,
                 SLOT(addSelectedEmoji(const QString &)));
+
+        connect(input_, &FilteredTextEdit::startedTyping, this, &TextInputWidget::startedTyping);
+
+        connect(input_, &FilteredTextEdit::stoppedTyping, this, &TextInputWidget::stoppedTyping);
 }
 
 void
@@ -227,3 +253,9 @@ TextInputWidget::hideUploadSpinner()
 }
 
 TextInputWidget::~TextInputWidget() {}
+
+void
+TextInputWidget::stopTyping()
+{
+        input_->stopTyping();
+}