summary refs log tree commit diff
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-08-08 13:15:19 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-08-08 13:15:19 +0300
commit43a4676282841e169ec0f0f505c386c11b9a2a72 (patch)
tree0195b3c6b8e2c7c2c6576f942745fac9ed26787d
parentAdd tooltips for the message indicators (#377) (diff)
downloadnheko-43a4676282841e169ec0f0f505c386c11b9a2a72.tar.xz
Remove hover event from emoji picker
fixes #398
-rw-r--r--src/TextInputWidget.cpp1
-rw-r--r--src/emoji/PickButton.cpp26
-rw-r--r--src/emoji/PickButton.h4
3 files changed, 22 insertions, 9 deletions
diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp
index f3b0f4be..9a58ed59 100644
--- a/src/TextInputWidget.cpp
+++ b/src/TextInputWidget.cpp
@@ -501,6 +501,7 @@ TextInputWidget::TextInputWidget(QWidget *parent)
         sendMessageBtn_->setIconSize(QSize(ButtonHeight, ButtonHeight));
 
         emojiBtn_ = new emoji::PickButton(this);
+        emojiBtn_->setToolTip(tr("Emoji"));
 
         QIcon emoji_icon;
         emoji_icon.addFile(":/icons/icons/ui/smile.png");
diff --git a/src/emoji/PickButton.cpp b/src/emoji/PickButton.cpp
index d2b4e9fd..608b4fa2 100644
--- a/src/emoji/PickButton.cpp
+++ b/src/emoji/PickButton.cpp
@@ -24,25 +24,35 @@ using namespace emoji;
 
 // Number of milliseconds after which the panel will be hidden
 // if the mouse cursor is not on top of the widget.
-constexpr int TimeoutDuration = 300;
+constexpr int HIDE_TIMEOUT = 300;
 
 PickButton::PickButton(QWidget *parent)
   : FlatButton(parent)
   , panel_{nullptr}
 {
-        connect(&hideTimer_, &QTimer::timeout, this, [this]() {
-                if (panel_ && !panel_->underMouse()) {
-                        hideTimer_.stop();
-                        panel_->hide();
+        connect(&hideTimer_, &QTimer::timeout, this, &PickButton::hidePanel);
+        connect(this, &QPushButton::clicked, this, [this]() {
+                if (panel_ && panel_->isVisible()) {
+                        hidePanel();
+                        return;
                 }
+
+                showPanel();
         });
 }
 
 void
-PickButton::enterEvent(QEvent *e)
+PickButton::hidePanel()
 {
-        Q_UNUSED(e);
+        if (panel_ && !panel_->underMouse()) {
+                hideTimer_.stop();
+                panel_->hide();
+        }
+}
 
+void
+PickButton::showPanel()
+{
         if (panel_.isNull()) {
                 panel_ = QSharedPointer<Panel>(new Panel(this));
                 connect(panel_.data(), &Panel::emojiSelected, this, &PickButton::emojiSelected);
@@ -67,6 +77,6 @@ PickButton::enterEvent(QEvent *e)
 void
 PickButton::leaveEvent(QEvent *e)
 {
-        hideTimer_.start(TimeoutDuration);
+        hideTimer_.start(HIDE_TIMEOUT);
         FlatButton::leaveEvent(e);
 }
diff --git a/src/emoji/PickButton.h b/src/emoji/PickButton.h
index d14067c6..97ed8c37 100644
--- a/src/emoji/PickButton.h
+++ b/src/emoji/PickButton.h
@@ -37,10 +37,12 @@ signals:
         void emojiSelected(const QString &emoji);
 
 protected:
-        void enterEvent(QEvent *e) override;
         void leaveEvent(QEvent *e) override;
 
 private:
+        void showPanel();
+        void hidePanel();
+
         // Vertical distance from panel's bottom.
         int vertical_distance_ = 10;