From 5125433552eb905fe228febc4961bca404f6bae2 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sun, 8 Apr 2018 15:49:53 +0300 Subject: Hide emoji panel if it's not under the mouse cursor fixes #254 fixes #246 --- src/emoji/Panel.cc | 8 +------- src/emoji/PickButton.cc | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/emoji/Panel.cc b/src/emoji/Panel.cc index 064dd6d5..89c3f823 100644 --- a/src/emoji/Panel.cc +++ b/src/emoji/Panel.cc @@ -39,7 +39,7 @@ Panel::Panel(QWidget *parent) "QScrollBar::handle:vertical { min-height: 30px; }"); setAttribute(Qt::WA_ShowWithoutActivating, true); - setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint); + setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint); auto mainWidget = new QWidget(this); mainWidget->setMaximumSize(width_, height_); @@ -213,12 +213,6 @@ Panel::showCategory(const Category *category) this->scrollArea_->ensureVisible(0, posToGo, 0, 0); } -void -Panel::leaveEvent(QEvent *) -{ - hide(); -} - void Panel::paintEvent(QPaintEvent *event) { diff --git a/src/emoji/PickButton.cc b/src/emoji/PickButton.cc index 530c951b..d2b4e9fd 100644 --- a/src/emoji/PickButton.cc +++ b/src/emoji/PickButton.cc @@ -15,15 +15,28 @@ * along with this program. If not, see . */ -#include "emoji/PickButton.h" +#include + #include "emoji/Panel.h" +#include "emoji/PickButton.h" 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; + PickButton::PickButton(QWidget *parent) : FlatButton(parent) , panel_{nullptr} -{} +{ + connect(&hideTimer_, &QTimer::timeout, this, [this]() { + if (panel_ && !panel_->underMouse()) { + hideTimer_.stop(); + panel_->hide(); + } + }); +} void PickButton::enterEvent(QEvent *e) @@ -33,8 +46,12 @@ PickButton::enterEvent(QEvent *e) if (panel_.isNull()) { panel_ = QSharedPointer(new Panel(this)); connect(panel_.data(), &Panel::emojiSelected, this, &PickButton::emojiSelected); + connect(panel_.data(), &Panel::leaving, this, [this]() { panel_->hide(); }); } + if (panel_->isVisible()) + return; + QPoint pos(rect().x(), rect().y()); pos = this->mapToGlobal(pos); @@ -46,3 +63,10 @@ PickButton::enterEvent(QEvent *e) panel_->move(x, y); panel_->show(); } + +void +PickButton::leaveEvent(QEvent *e) +{ + hideTimer_.start(TimeoutDuration); + FlatButton::leaveEvent(e); +} -- cgit 1.5.1