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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
* Copyright (c) 2016-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtEmojiCell.h>
#include <Swiften/Base/Platform.h>
#include <QFont>
#include <QFontMetrics>
#include <QPushButton>
#include <QString>
#include <SwifTools/EmojiMapper.h>
namespace Swift {
QtEmojiCell::QtEmojiCell(QString shortname, QString text, QWidget* parent) : QPushButton(parent) {
setText(text);
QFont font = this->font();
#ifdef SWIFTEN_PLATFORM_WINDOWS
//Windows emoji font miscalculates the bounding rectangular that surrounds the emoji. We set a multiplier value to make it look consistent with linux & Mac
const float sizeMultiplier = 1.3;
font.setPointSize(18);
#else
font.setPointSize(22);
const float sizeMultiplier = 1;
#endif
font.setBold(true);
setFont(font);
const auto boundingRect = fontMetrics().boundingRect("\xF0\x9F\x98\x83");
setFixedWidth(qMax(sizeMultiplier*boundingRect.width(), sizeMultiplier*boundingRect.height()));
setFixedHeight(qMax(sizeMultiplier*boundingRect.width(), sizeMultiplier*boundingRect.height()));
setFlat(true);
setToolTip(shortname);
connect(this, SIGNAL(clicked()), this, SLOT(handleEmojiClicked()));
}
QtEmojiCell::QtEmojiCell(QIcon icon, QString text, QWidget* parent) : QPushButton(parent), text_(text) {
setIcon(icon);
setFlat(true);
connect(this, SIGNAL(clicked()), this, SLOT(handleEmojiClicked()));
setFixedSize(icon.availableSizes()[0] * 1.5);
}
QtEmojiCell::QtEmojiCell(const QtEmojiCell& b) : QtEmojiCell(b.toolTip(), b.text()) {
}
QtEmojiCell::~QtEmojiCell() {
}
void QtEmojiCell::handleEmojiClicked () {
if (text_.isEmpty()) {
emit emojiClicked(text());
}
else {
emit emojiClicked(text_);
}
}
}
|