-
Notifications
You must be signed in to change notification settings - Fork 88
/
chooseemojiwidget.cpp
49 lines (42 loc) · 1004 Bytes
/
chooseemojiwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "chooseemojiwidget.h"
#include <QMouseEvent>
#include "emoji.h"
ChooseEmojiWidget::ChooseEmojiWidget(QWidget* parent)
:QLabel(parent), mIndex(-1)
{
setMouseTracking(true);
}
void ChooseEmojiWidget::mousePressEvent(QMouseEvent *event)
{
mIndex = getIndex(event->x(), event->y());
}
void ChooseEmojiWidget::mouseMoveEvent(QMouseEvent *event)
{
auto index = getIndex(event->x(), event->y());
if (index >= 0 && index < EMOJI_LEN)
{
emit hesitate(index);
}
else
{
emit hesitate(-1);
}
}
void ChooseEmojiWidget::mouseReleaseEvent(QMouseEvent *event)
{
auto index = getIndex(event->x(), event->y());
if (mIndex == index && mIndex >= 0 && mIndex < EMOJI_LEN)
{
emit choose(mIndex);
}
mIndex = -1;
}
int ChooseEmojiWidget::getIndex(int x, int y)
{
int col = x/25;
int row = y/25;
auto index = row * EMOJI_BMP_COL + col;
if (index >= 0 && index < EMOJI_LEN)
return index;
return -1;
}