Commit 17a611c9 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add emoticonunicodemodel

parent 40386499
......@@ -55,6 +55,8 @@ target_sources(KF5PimTextEdit PRIVATE
emoticon/emoticonunicodetab.cpp
emoticon/emoticonlistwidgetselector.cpp
emoticon/emoticonunicodeutils.cpp
emoticon/emoticonunicodemodel.cpp
emoticon/emoticonlistview.cpp
)
target_sources(KF5PimTextEdit PRIVATE
......
......@@ -10,3 +10,4 @@ macro( emoticontest _source )
endmacro()
emoticontest(emoticontexteditselectortest.cpp)
emoticontest(emoticonlistviewtest.cpp)
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "emoticonlistviewtest.h"
#include "emoticon/emoticonlistview.h"
#include <QTest>
QTEST_MAIN(EmoticonListViewTest)
EmoticonListViewTest::EmoticonListViewTest(QObject *parent)
: QObject(parent)
{
}
void EmoticonListViewTest::shouldHaveDefaultValues()
{
KPIMTextEdit::EmoticonListView w;
QCOMPARE(w.viewMode(), QListView::IconMode);
QCOMPARE(w.horizontalScrollBarPolicy(), Qt::ScrollBarAlwaysOff);
}
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include <QObject>
class EmoticonListViewTest : public QObject
{
Q_OBJECT
public:
explicit EmoticonListViewTest(QObject *parent = nullptr);
~EmoticonListViewTest() override = default;
private Q_SLOTS:
void shouldHaveDefaultValues();
};
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "emoticonlistview.h"
using namespace KPIMTextEdit;
EmoticonListView::EmoticonListView(QWidget *parent)
: QListView(parent)
{
setViewMode(QListView::IconMode);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
EmoticonListView::~EmoticonListView()
{
}
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "kpimtextedit_private_export.h"
#include <QListView>
namespace KPIMTextEdit
{
class KPIMTEXTEDIT_TESTS_EXPORT EmoticonListView : public QListView
{
Q_OBJECT
public:
explicit EmoticonListView(QWidget *parent = nullptr);
~EmoticonListView() override;
};
}
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "emoticonunicodemodel.h"
#include <KLocalizedString>
using namespace KPIMTextEdit;
EmoticonUnicodeModel::EmoticonUnicodeModel(QObject *parent)
: QAbstractListModel(parent)
{
}
EmoticonUnicodeModel::~EmoticonUnicodeModel()
{
}
int EmoticonUnicodeModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid()) {
return 0; // flat model
}
return mEmoticonList.count();
}
QVariant EmoticonUnicodeModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= mEmoticonList.count()) {
return {};
}
const auto &unicodeEmoti = mEmoticonList.at(index.row());
switch (role) {
case UnicodeEmoji:
return unicodeEmoti.emoticonName;
case Category:
return unicodeEmoti.emoticonCategory;
case Identifier:
case Qt::DisplayRole:
return unicodeEmoti.emoticonCode;
}
return {};
}
const QVector<EmoticonUnicodeUtils::EmoticonStruct> &EmoticonUnicodeModel::emoticonList() const
{
return mEmoticonList;
}
void EmoticonUnicodeModel::setEmoticonList(const QVector<EmoticonUnicodeUtils::EmoticonStruct> &newEmoticonList)
{
beginResetModel();
mEmoticonList = newEmoticonList;
endResetModel();
}
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "emoticonunicodeutils.h"
#include "kpimtextedit_private_export.h"
#include <QAbstractListModel>
namespace KPIMTextEdit
{
class KPIMTEXTEDIT_TESTS_EXPORT EmoticonUnicodeModel : public QAbstractListModel
{
Q_OBJECT
public:
enum EmoticonsRoles { UnicodeEmoji = Qt::UserRole + 1, Identifier, Category };
Q_ENUM(EmoticonsRoles)
explicit EmoticonUnicodeModel(QObject *parent = nullptr);
~EmoticonUnicodeModel() override;
Q_REQUIRED_RESULT int rowCount(const QModelIndex &parent = QModelIndex()) const override;
Q_REQUIRED_RESULT QVariant data(const QModelIndex &index, int role) const override;
const QVector<EmoticonUnicodeUtils::EmoticonStruct> &emoticonList() const;
void setEmoticonList(const QVector<EmoticonUnicodeUtils::EmoticonStruct> &newEmoticonList);
private:
Q_DISABLE_COPY(EmoticonUnicodeModel)
QVector<EmoticonUnicodeUtils::EmoticonStruct> mEmoticonList;
};
}
......@@ -6,6 +6,7 @@
#include "emoticonunicodetab.h"
#include "emoticonlistwidgetselector.h"
#include "emoticonunicodemodel.h"
#include "textutils.h"
#include <KLocalizedString>
......@@ -30,8 +31,25 @@ void EmoticonUnicodeTab::searchUnicode(const QString &str)
// TODO show search page + update proxyfilter + switch to search page
}
void EmoticonUnicodeTab::createFullTab()
{
auto allEmojisView = new QListView(this);
allEmojisView->setViewMode(QListView::IconMode);
allEmojisView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// auto emoticonFilterProxyModel = new EmoticonModelFilterProxyModel(this);
// emoticonFilterProxyModel->setSourceModel(account->emoticonModel());
auto m = new EmoticonUnicodeModel(this);
m->setEmoticonList(EmoticonUnicodeUtils::unicodeFaceEmoji() + EmoticonUnicodeUtils::unicodeAnimalsEmoji());
allEmojisView->setModel(m);
const int index = addTab(allEmojisView, i18n("full"));
// if (!str.isEmpty()) {
// setTabToolTip(index, str);
// }
}
void EmoticonUnicodeTab::loadEmoticons()
{
createFullTab();
createPlainTextEmoticonTab(i18n("Faces"), EmoticonUnicodeUtils::unicodeFaceEmoji());
createPlainTextEmoticonTab(i18n("Animals"), EmoticonUnicodeUtils::unicodeAnimalsEmoji());
createPlainTextEmoticonTab(i18n("Emotions"), EmoticonUnicodeUtils::unicodeEmotionEmoji());
......
......@@ -32,6 +32,7 @@ Q_SIGNALS:
private:
void createPlainTextEmoticonTab(const QString &str, const QVector<EmoticonUnicodeUtils::EmoticonStruct> &emoticons);
void createFullTab();
};
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -14,14 +14,16 @@ namespace KPIMTextEdit
namespace EmoticonUnicodeUtils
{
struct EmoticonStruct {
EmoticonStruct(const QString &name, const QString &code)
EmoticonStruct(const QString &name, const QString &code, const QString &category)
: emoticonName(name)
, emoticonCode(code)
, emoticonCategory(category)
{
}
QString emoticonName;
QString emoticonCode;
QString emoticonCategory;
};
KPIMTEXTEDIT_EXPORT Q_REQUIRED_RESULT QVector<EmoticonStruct> unicodeFlagsEmoji();
KPIMTEXTEDIT_EXPORT Q_REQUIRED_RESULT QVector<EmoticonStruct> unicodeFaceEmoji();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment