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
66
67
68
69
70
71
72
73
74
75
|
/*
* Copyright (c) 2016-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtEmojisSelector.h>
#include <QScrollArea>
#include <QSettings>
#include <QString>
#include <QWidget>
#include <SwifTools/EmojiMapper.h>
#include <Swift/QtUI/QtEmojisGrid.h>
#include <Swift/QtUI/QtEmojisScroll.h>
#include <Swift/QtUI/QtRecentEmojisGrid.h>
#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
QtEmojisSelector::QtEmojisSelector(QSettings* settings, QWidget* parent) : QTabWidget(parent), settings_(settings) {
recentEmojisGrid_ = addRecentTab();
connect(recentEmojisGrid_, SIGNAL(onEmojiSelected(QString)), this, SLOT(emojiClickedSlot(QString)));
for (const auto& category : EmojiMapper::getCategories()) {
if (category != "modifier") {
QtEmojisGrid* grid = addTab(P2QSTRING(category));
connect(grid, SIGNAL(onEmojiSelected(QString)), this, SLOT(emojiClickedSlot(QString)));
}
}
loadSettings();
}
QtEmojisSelector::~QtEmojisSelector() {
writeSettings();
}
QtRecentEmojisGrid* QtEmojisSelector::addRecentTab() {
QtRecentEmojisGrid* recent = new QtRecentEmojisGrid(settings_);
QtEmojisScroll* scroll = new QtEmojisScroll(recent);
QTabWidget::addTab(scroll, QString::fromStdString(EmojiMapper::categoryToFlagshipUnicodeEmoji("recent")));
setTabToolTip(count()-1, tr("Recent"));
return recent;
}
QtEmojisGrid* QtEmojisSelector::addTab(QString categoryName) {
QtEmojisGrid* grid = new QtEmojisGrid(categoryName);
QtEmojisScroll* scroll = new QtEmojisScroll(grid);
QTabWidget::addTab(scroll, QString::fromStdString(EmojiMapper::categoryToFlagshipUnicodeEmoji(Q2PSTRING(categoryName))));
setTabToolTip(count()-1, categoryName.replace(0, 1, categoryName[0].toUpper()));
return grid;
}
void QtEmojisSelector::loadSettings() {
if (settings_->contains("currentEmojiTab")) {
setCurrentIndex(settings_->value("currentEmojiTab").toInt());
} else {
setCurrentIndex(1); //index of people category
}
}
void QtEmojisSelector::writeSettings() {
settings_->setValue("currentEmojiTab", currentIndex());
}
void QtEmojisSelector::emojiClickedSlot(QString emoji) {
recentEmojisGrid_->handleEmojiClicked(emoji);
emit emojiClicked(emoji);
}
}
|