mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 17:40:47 +03:00
parent
3fb57ac049
commit
43a4676282
3 changed files with 22 additions and 9 deletions
|
@ -501,6 +501,7 @@ TextInputWidget::TextInputWidget(QWidget *parent)
|
||||||
sendMessageBtn_->setIconSize(QSize(ButtonHeight, ButtonHeight));
|
sendMessageBtn_->setIconSize(QSize(ButtonHeight, ButtonHeight));
|
||||||
|
|
||||||
emojiBtn_ = new emoji::PickButton(this);
|
emojiBtn_ = new emoji::PickButton(this);
|
||||||
|
emojiBtn_->setToolTip(tr("Emoji"));
|
||||||
|
|
||||||
QIcon emoji_icon;
|
QIcon emoji_icon;
|
||||||
emoji_icon.addFile(":/icons/icons/ui/smile.png");
|
emoji_icon.addFile(":/icons/icons/ui/smile.png");
|
||||||
|
|
|
@ -24,25 +24,35 @@ using namespace emoji;
|
||||||
|
|
||||||
// Number of milliseconds after which the panel will be hidden
|
// Number of milliseconds after which the panel will be hidden
|
||||||
// if the mouse cursor is not on top of the widget.
|
// if the mouse cursor is not on top of the widget.
|
||||||
constexpr int TimeoutDuration = 300;
|
constexpr int HIDE_TIMEOUT = 300;
|
||||||
|
|
||||||
PickButton::PickButton(QWidget *parent)
|
PickButton::PickButton(QWidget *parent)
|
||||||
: FlatButton(parent)
|
: FlatButton(parent)
|
||||||
, panel_{nullptr}
|
, panel_{nullptr}
|
||||||
{
|
{
|
||||||
connect(&hideTimer_, &QTimer::timeout, this, [this]() {
|
connect(&hideTimer_, &QTimer::timeout, this, &PickButton::hidePanel);
|
||||||
if (panel_ && !panel_->underMouse()) {
|
connect(this, &QPushButton::clicked, this, [this]() {
|
||||||
hideTimer_.stop();
|
if (panel_ && panel_->isVisible()) {
|
||||||
panel_->hide();
|
hidePanel();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showPanel();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PickButton::enterEvent(QEvent *e)
|
PickButton::hidePanel()
|
||||||
{
|
{
|
||||||
Q_UNUSED(e);
|
if (panel_ && !panel_->underMouse()) {
|
||||||
|
hideTimer_.stop();
|
||||||
|
panel_->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PickButton::showPanel()
|
||||||
|
{
|
||||||
if (panel_.isNull()) {
|
if (panel_.isNull()) {
|
||||||
panel_ = QSharedPointer<Panel>(new Panel(this));
|
panel_ = QSharedPointer<Panel>(new Panel(this));
|
||||||
connect(panel_.data(), &Panel::emojiSelected, this, &PickButton::emojiSelected);
|
connect(panel_.data(), &Panel::emojiSelected, this, &PickButton::emojiSelected);
|
||||||
|
@ -67,6 +77,6 @@ PickButton::enterEvent(QEvent *e)
|
||||||
void
|
void
|
||||||
PickButton::leaveEvent(QEvent *e)
|
PickButton::leaveEvent(QEvent *e)
|
||||||
{
|
{
|
||||||
hideTimer_.start(TimeoutDuration);
|
hideTimer_.start(HIDE_TIMEOUT);
|
||||||
FlatButton::leaveEvent(e);
|
FlatButton::leaveEvent(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,12 @@ signals:
|
||||||
void emojiSelected(const QString &emoji);
|
void emojiSelected(const QString &emoji);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void enterEvent(QEvent *e) override;
|
|
||||||
void leaveEvent(QEvent *e) override;
|
void leaveEvent(QEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void showPanel();
|
||||||
|
void hidePanel();
|
||||||
|
|
||||||
// Vertical distance from panel's bottom.
|
// Vertical distance from panel's bottom.
|
||||||
int vertical_distance_ = 10;
|
int vertical_distance_ = 10;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue