summary refs log tree commit diff
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-08-09 18:20:17 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-08-09 18:20:17 +0300
commitd4c3dac28f2afb7c8f675729ed91c56494928c43 (patch)
tree234fa17a819dfcc11b1e3bb9e61e603879f71d63
parentAllow user to configure join rules for a room (diff)
downloadnheko-d4c3dac28f2afb7c8f675729ed91c56494928c43.tar.xz
Remove the reserved space gap for the typing notifications
Diffstat (limited to '')
-rw-r--r--src/ChatPage.cpp19
-rw-r--r--src/TextInputWidget.cpp2
-rw-r--r--src/TextInputWidget.h1
-rw-r--r--src/TypingDisplay.cpp21
-rw-r--r--src/TypingDisplay.h11
-rw-r--r--src/timeline/TimelineView.cpp9
6 files changed, 44 insertions, 19 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index 27c4fbe9..71ea0649 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -122,11 +122,14 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
         splitter->addWidget(content_);
         splitter->restoreSizes(parent->width());
 
-        text_input_    = new TextInputWidget(this);
-        typingDisplay_ = new TypingDisplay(this);
-        contentLayout_->addWidget(typingDisplay_);
+        text_input_ = new TextInputWidget(this);
         contentLayout_->addWidget(text_input_);
 
+        typingDisplay_ = new TypingDisplay(content_);
+        typingDisplay_->hide();
+        connect(
+          text_input_, &TextInputWidget::heightChanged, typingDisplay_, &TypingDisplay::setOffset);
+
         typingRefresher_ = new QTimer(this);
         typingRefresher_->setInterval(TYPING_REFRESH_TIMEOUT);
 
@@ -592,8 +595,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
         // Callbacks to update the user info (top left corner of the page).
         connect(this, &ChatPage::setUserAvatar, user_info_widget_, &UserInfoWidget::setAvatar);
         connect(this, &ChatPage::setUserDisplayName, this, [this](const QString &name) {
-                QSettings settings;
-                auto userid = settings.value("auth/user_id").toString();
+                auto userid = utils::localUser();
                 user_info_widget_->setUserId(userid);
                 user_info_widget_->setDisplayName(name);
         });
@@ -890,9 +892,7 @@ QStringList
 ChatPage::generateTypingUsers(const QString &room_id, const std::vector<std::string> &typing_users)
 {
         QStringList users;
-
-        QSettings settings;
-        QString local_user = settings.value("auth/user_id").toString();
+        auto local_user = utils::localUser();
 
         for (const auto &uid : typing_users) {
                 const auto remote_user = QString::fromStdString(uid);
@@ -1262,8 +1262,7 @@ ChatPage::ensureOneTimeKeyCount(const std::map<std::string, uint16_t> &counts)
 void
 ChatPage::getProfileInfo()
 {
-        QSettings settings;
-        const auto userid = settings.value("auth/user_id").toString().toStdString();
+        const auto userid = utils::localUser().toStdString();
 
         http::client()->get_profile(
           userid, [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) {
diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp
index 9a58ed59..74ca072b 100644
--- a/src/TextInputWidget.cpp
+++ b/src/TextInputWidget.cpp
@@ -477,6 +477,8 @@ TextInputWidget::TextInputWidget(QWidget *parent)
 
                 setFixedHeight(widgetHeight);
                 input_->setFixedHeight(textInputHeight);
+
+                emit heightChanged(widgetHeight);
         });
         connect(input_, &FilteredTextEdit::showSuggestions, this, [this](const QString &q) {
                 if (q.isEmpty() || !cache::client())
diff --git a/src/TextInputWidget.h b/src/TextInputWidget.h
index 37d73fbb..8f634f6b 100644
--- a/src/TextInputWidget.h
+++ b/src/TextInputWidget.h
@@ -166,6 +166,7 @@ private slots:
 signals:
         void sendTextMessage(QString msg);
         void sendEmoteMessage(QString msg);
+        void heightChanged(int height);
 
         void uploadImage(const QSharedPointer<QIODevice> data, const QString &filename);
         void uploadFile(const QSharedPointer<QIODevice> data, const QString &filename);
diff --git a/src/TypingDisplay.cpp b/src/TypingDisplay.cpp
index 08214a63..cd405a7a 100644
--- a/src/TypingDisplay.cpp
+++ b/src/TypingDisplay.cpp
@@ -1,5 +1,7 @@
+#include <QDebug>
 #include <QPainter>
 #include <QPoint>
+#include <QShowEvent>
 
 #include "Config.h"
 #include "TypingDisplay.h"
@@ -8,21 +10,33 @@
 constexpr int LEFT_PADDING = 24;
 
 TypingDisplay::TypingDisplay(QWidget *parent)
-  : QWidget(parent)
+  : OverlayWidget(parent)
+  , offset_{conf::textInput::height}
 {
         QFont f;
         f.setPixelSize(conf::typingNotificationFontSize);
-
         setFont(f);
 
         setFixedHeight(QFontMetrics(font()).height() + 2);
+        setAttribute(Qt::WA_TransparentForMouseEvents);
+}
+
+void
+TypingDisplay::setOffset(int margin)
+{
+        offset_ = margin;
+        move(0, parentWidget()->height() - offset_ - height());
 }
 
 void
 TypingDisplay::setUsers(const QStringList &uid)
 {
+        move(0, parentWidget()->height() - offset_ - height());
+
+        text_.clear();
+
         if (uid.isEmpty()) {
-                text_.clear();
+                hide();
                 update();
 
                 return;
@@ -35,6 +49,7 @@ TypingDisplay::setUsers(const QStringList &uid)
         else if (uid.size() > 1)
                 text_ += tr(" are typing");
 
+        show();
         update();
 }
 
diff --git a/src/TypingDisplay.h b/src/TypingDisplay.h
index d5e2f29c..c4e6c357 100644
--- a/src/TypingDisplay.h
+++ b/src/TypingDisplay.h
@@ -1,9 +1,10 @@
 #pragma once
 
-#include <QPaintEvent>
-#include <QWidget>
+#include "ui/OverlayWidget.h"
 
-class TypingDisplay : public QWidget
+class QPaintEvent;
+
+class TypingDisplay : public OverlayWidget
 {
         Q_OBJECT
 
@@ -17,10 +18,14 @@ public:
         void setTextColor(const QColor &color) { textColor_ = color; };
         QColor textColor() const { return textColor_; };
 
+public slots:
+        void setOffset(int margin);
+
 protected:
         void paintEvent(QPaintEvent *event) override;
 
 private:
+        int offset_;
         QColor textColor_;
         QString text_;
 };
diff --git a/src/timeline/TimelineView.cpp b/src/timeline/TimelineView.cpp
index 3a4193a0..3d0a1026 100644
--- a/src/timeline/TimelineView.cpp
+++ b/src/timeline/TimelineView.cpp
@@ -490,8 +490,6 @@ TimelineView::init()
         QIcon icon;
         icon.addFile(":/icons/icons/ui/angle-arrow-down.png");
         scrollDownBtn_ = new FloatingButton(icon, this);
-        scrollDownBtn_->setBackgroundColor(QColor("#F5F5F5"));
-        scrollDownBtn_->setForegroundColor(QColor("black"));
         scrollDownBtn_->hide();
 
         connect(scrollDownBtn_, &QPushButton::clicked, this, [this]() {
@@ -509,8 +507,13 @@ TimelineView::init()
         scroll_widget_ = new QWidget(this);
         scroll_widget_->setObjectName("scroll_widget");
 
+        // Height of the typing display.
+        QFont f;
+        f.setPixelSize(conf::typingNotificationFontSize);
+        const int bottomMargin = QFontMetrics(f).height() + 6;
+
         scroll_layout_ = new QVBoxLayout(scroll_widget_);
-        scroll_layout_->setContentsMargins(4, 0, 15, 15);
+        scroll_layout_->setContentsMargins(4, 0, 15, bottomMargin);
         scroll_layout_->setSpacing(0);
         scroll_layout_->setObjectName("timelinescrollarea");