8#include "emoticontexteditselector.h"
9#include "emoticoncategorybuttons.h"
10#include "emoticonlistview.h"
12#include <KLocalizedString>
15#include <TextEmoticonsCore/EmojiModel>
16#include <TextEmoticonsCore/EmojiModelManager>
17#include <TextEmoticonsCore/EmojiProxyModel>
18#include <TextEmoticonsCore/EmoticonUnicodeUtils>
19#include <TextEmoticonsCore/UnicodeEmoticonManager>
21using namespace TextEmoticonsWidgets;
23class EmoticonTextEditSelector::EmoticonTextEditSelectorPrivate
26 EmoticonTextEditSelectorPrivate(EmoticonTextEditSelector *q)
27 : mSearchUnicodeLineEdit(new QLineEdit(q))
28 , mCategoryButtons(new EmoticonCategoryButtons(q))
29 , mEmoticonListView(new EmoticonListView(q))
30 , mEmojiProxyModel(new TextEmoticonsCore::EmojiProxyModel(q))
34 void slotUsedIdentifierChanged(
const QStringList &lst)
36 mEmojiProxyModel->setRecentEmoticons(lst);
38 void slotCategorySelected(
const QString &category)
40 mSearchUnicodeLineEdit->setText({});
41 mEmojiProxyModel->setCategory(category);
42 mEmoticonListView->setIsRecentView(category == TextEmoticonsCore::EmoticonUnicodeUtils::recentIdentifier());
45 void slotSearchUnicode(
const QString &str)
47 mEmojiProxyModel->setSearchIdentifier(str);
50 void slotItemSelected(
const QString &str,
const QString &identifier)
52 TextEmoticonsCore::EmojiModelManager::self()->addIdentifier(identifier);
53 Q_EMIT qq->insertEmoji(str);
54 Q_EMIT qq->insertEmojiIdentifier(identifier);
55 if (qq->isVisible() && qq->parentWidget() && qq->parentWidget()->inherits(
"QMenu")) {
56 qq->parentWidget()->close();
59 QLineEdit *
const mSearchUnicodeLineEdit;
60 EmoticonCategoryButtons *
const mCategoryButtons;
61 EmoticonListView *
const mEmoticonListView;
62 TextEmoticonsCore::EmojiProxyModel *
const mEmojiProxyModel;
63 bool mCustomEmojiSupport =
false;
64 EmoticonTextEditSelector *
const qq;
67EmoticonTextEditSelector::EmoticonTextEditSelector(
QWidget *parent)
69 , d(new EmoticonTextEditSelectorPrivate(this))
71 const int defaultFontSize{22};
74 f.
setFamily(TextEmoticonsCore::EmoticonUnicodeUtils::emojiFontName());
75 d->mEmoticonListView->setFontSize(defaultFontSize);
76 d->mCategoryButtons->setFont(f);
78 mainLayout->setObjectName(QStringLiteral(
"mainLayout"));
79 mainLayout->setSpacing(0);
80 mainLayout->setContentsMargins({});
81 d->mSearchUnicodeLineEdit->setObjectName(QStringLiteral(
"mSearchUnicodeLineEdit"));
82 d->mSearchUnicodeLineEdit->setClearButtonEnabled(
true);
83 d->mSearchUnicodeLineEdit->setPlaceholderText(
i18nc(
"@info:placeholder",
"Search Emoticon…"));
84 mainLayout->addWidget(d->mSearchUnicodeLineEdit);
86 d->mCategoryButtons->setObjectName(QStringLiteral(
"mCategoryButtons"));
87 mainLayout->addWidget(d->mCategoryButtons);
88 d->mEmoticonListView->setObjectName(QStringLiteral(
"mEmoticonListView"));
89 mainLayout->addWidget(d->mEmoticonListView);
91 d->mEmojiProxyModel->setObjectName(QStringLiteral(
"mEmoticonProxyModel"));
92 d->mEmoticonListView->setModel(d->mEmojiProxyModel);
93 connect(d->mEmoticonListView, &EmoticonListView::fontSizeChanged, d->mEmoticonListView, &EmoticonListView::setFontSize);
94 connect(d->mEmoticonListView, &EmoticonListView::emojiItemSelected,
this, [
this](
const QString &str,
const QString &identifier) {
95 d->slotItemSelected(str, identifier);
97 connect(d->mCategoryButtons, &EmoticonCategoryButtons::categorySelected,
this, [
this](
const QString &category) {
98 d->slotCategorySelected(category);
101 d->slotSearchUnicode(str);
103 connect(TextEmoticonsCore::EmojiModelManager::self(), &TextEmoticonsCore::EmojiModelManager::usedIdentifierChanged,
this, [
this](
const QStringList &lst) {
104 d->slotUsedIdentifierChanged(lst);
107 connect(d->mEmoticonListView, &EmoticonListView::clearHistory,
this, []() {
108 TextEmoticonsCore::EmojiModelManager::self()->setRecentIdentifier(QStringList());
112 setMinimumSize(popupMenuSize);
117 d->mSearchUnicodeLineEdit->setFocus();
120EmoticonTextEditSelector::~EmoticonTextEditSelector() =
default;
124 if (!d->mCategoryButtons->wasLoaded()) {
126 d->mEmojiProxyModel->setSourceModel(TextEmoticonsCore::EmojiModelManager::self()->emojiModel());
128 d->mCategoryButtons->setCategories(categories, d->mCustomEmojiSupport);
129 d->mEmojiProxyModel->setRecentEmoticons(TextEmoticonsCore::EmojiModelManager::self()->recentIdentifier());
135 d->mCustomEmojiSupport = b;
140 return d->mCustomEmojiSupport;
143#include "moc_emoticontexteditselector.cpp"
The UnicodeEmoticonManager class.
void forceLineEditFocus()
Focus the line edit for search.
bool customEmojiSupport() const
Return whether the custom emoji category is enabled.
void loadEmoticons()
Do all the magic of creating an TextEmoticonsCore::UnicodeEmoticonManager and loading the categories ...
void setCustomEmojiSupport(bool b)
Set whether the custom emoji category should be shown.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setFamily(const QString &family)
void setPointSize(int pointSize)
void textChanged(const QString &text)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)