7#include "emoticoncategorybuttons.h"
8#include "emoticoncategorybutton.h"
9#include "emoticonunicodeutils.h"
10#include <KLocalizedString>
11#include <QButtonGroup>
15#include <TextEmoticonsCore/EmoticonCategory>
16#include <TextEmoticonsCore/EmoticonUnicodeUtils>
18using namespace TextEmoticonsWidgets;
19EmoticonCategoryButtons::EmoticonCategoryButtons(
QWidget *parent)
25 mMainLayout->setContentsMargins({});
26 mButtonGroup->setObjectName(QStringLiteral(
"mButtonGroup"));
29EmoticonCategoryButtons::~EmoticonCategoryButtons() =
default;
31void EmoticonCategoryButtons::wheelEvent(
QWheelEvent *event)
33 auto button = mButtonGroup->checkedButton();
35 const int index = mButtonGroup->buttons().indexOf(button);
37 QAbstractButton *nextButton =
nullptr;
38 if (
event->angleDelta().y() > 0) {
40 nextButton = mButtonGroup->buttons().at(index - 1);
42 nextButton = mButtonGroup->buttons().constLast();
44 }
else if (
event->angleDelta().y() < 0) {
45 if (index == (mButtonGroup->buttons().count() - 1)) {
46 nextButton = mButtonGroup->buttons().constFirst();
48 nextButton = mButtonGroup->buttons().at(index + 1);
61void EmoticonCategoryButtons::addButton(
const QString &name,
const QString &category,
const QString &toolTip)
63 auto button =
new EmoticonCategoryButton(
this);
64 button->setText(name);
66 mMainLayout->addWidget(button);
67 mButtonGroup->addButton(button);
70 Q_EMIT categorySelected(category);
75bool EmoticonCategoryButtons::wasLoaded()
const
80void EmoticonCategoryButtons::setCategories(
const QList<TextEmoticonsCore::EmoticonCategory> &categories,
bool hasCustomSupport)
82 addButton(TextEmoticonsCore::EmoticonUnicodeUtils::recentName(),
83 TextEmoticonsCore::EmoticonUnicodeUtils::recentIdentifier(),
84 i18nc(
"Previously used emojis",
"History"));
85 if (hasCustomSupport) {
86 addButton(TextEmoticonsCore::EmoticonUnicodeUtils::customName(),
87 TextEmoticonsCore::EmoticonUnicodeUtils::customIdentifier(),
88 i18nc(
"'Custom' is a category of emoji",
"Custom"));
90 for (
const auto &cat : categories) {
91 addButton(cat.name(), cat.category(), cat.i18nName());
94 auto button = mButtonGroup->buttons().constFirst();
95 button->setChecked(
true);
96 Q_EMIT categorySelected(TextEmoticonsCore::EmoticonUnicodeUtils::recentIdentifier());
100#include "moc_emoticoncategorybuttons.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual bool event(QEvent *e)
void setObjectName(QAnyStringView name)