|
|
@ -15,15 +15,28 @@ |
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include "emoji/PickButton.h" |
|
|
|
#include <QDebug> |
|
|
|
|
|
|
|
|
|
|
|
#include "emoji/Panel.h" |
|
|
|
#include "emoji/Panel.h" |
|
|
|
|
|
|
|
#include "emoji/PickButton.h" |
|
|
|
|
|
|
|
|
|
|
|
using namespace emoji; |
|
|
|
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) |
|
|
|
PickButton::PickButton(QWidget *parent) |
|
|
|
: FlatButton(parent) |
|
|
|
: FlatButton(parent) |
|
|
|
, panel_{nullptr} |
|
|
|
, panel_{nullptr} |
|
|
|
{} |
|
|
|
{ |
|
|
|
|
|
|
|
connect(&hideTimer_, &QTimer::timeout, this, [this]() { |
|
|
|
|
|
|
|
if (panel_ && !panel_->underMouse()) { |
|
|
|
|
|
|
|
hideTimer_.stop(); |
|
|
|
|
|
|
|
panel_->hide(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
PickButton::enterEvent(QEvent *e) |
|
|
|
PickButton::enterEvent(QEvent *e) |
|
|
@ -33,8 +46,12 @@ PickButton::enterEvent(QEvent *e) |
|
|
|
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); |
|
|
|
|
|
|
|
connect(panel_.data(), &Panel::leaving, this, [this]() { panel_->hide(); }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (panel_->isVisible()) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
QPoint pos(rect().x(), rect().y()); |
|
|
|
QPoint pos(rect().x(), rect().y()); |
|
|
|
pos = this->mapToGlobal(pos); |
|
|
|
pos = this->mapToGlobal(pos); |
|
|
|
|
|
|
|
|
|
|
@ -46,3 +63,10 @@ PickButton::enterEvent(QEvent *e) |
|
|
|
panel_->move(x, y); |
|
|
|
panel_->move(x, y); |
|
|
|
panel_->show(); |
|
|
|
panel_->show(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
PickButton::leaveEvent(QEvent *e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
hideTimer_.start(TimeoutDuration); |
|
|
|
|
|
|
|
FlatButton::leaveEvent(e); |
|
|
|
|
|
|
|
} |
|
|
|