Commit af808028 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add emoticonunicodeproxymodel

parent 17a611c9
......@@ -57,6 +57,7 @@ target_sources(KF5PimTextEdit PRIVATE
emoticon/emoticonunicodeutils.cpp
emoticon/emoticonunicodemodel.cpp
emoticon/emoticonlistview.cpp
emoticon/emoticonunicodeproxymodel.cpp
)
target_sources(KF5PimTextEdit PRIVATE
......
......@@ -11,3 +11,4 @@ endmacro()
emoticontest(emoticontexteditselectortest.cpp)
emoticontest(emoticonlistviewtest.cpp)
emoticontest(emoticonunicodeproxymodeltest.cpp)
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "emoticonunicodeproxymodeltest.h"
#include "emoticon/emoticonunicodeproxymodel.h"
#include <QTest>
QTEST_MAIN(EmoticonUnicodeProxyModelTest)
EmoticonUnicodeProxyModelTest::EmoticonUnicodeProxyModelTest(QObject *parent)
: QObject(parent)
{
}
void EmoticonUnicodeProxyModelTest::shouldHaveDefaultValues()
{
KPIMTextEdit::EmoticonUnicodeProxyModel m;
QVERIFY(m.categories().isEmpty());
}
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include <QObject>
class EmoticonUnicodeProxyModelTest : public QObject
{
Q_OBJECT
public:
explicit EmoticonUnicodeProxyModelTest(QObject *parent = nullptr);
~EmoticonUnicodeProxyModelTest() override = default;
private Q_SLOTS:
void shouldHaveDefaultValues();
};
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "emoticonunicodeproxymodel.h"
#include "emoticonunicodemodel.h"
using namespace KPIMTextEdit;
EmoticonUnicodeProxyModel::EmoticonUnicodeProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
EmoticonUnicodeProxyModel::~EmoticonUnicodeProxyModel()
{
}
bool EmoticonUnicodeProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
if (mCategories.isEmpty()) {
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
}
const QModelIndex sourceIndex = sourceModel()->index(source_row, 0, source_parent);
const QString category = sourceIndex.data(EmoticonUnicodeModel::Category).toString();
if (mCategories.contains(category)) {
return true;
}
return false;
}
const QStringList &EmoticonUnicodeProxyModel::categories() const
{
return mCategories;
}
void EmoticonUnicodeProxyModel::setCategories(const QStringList &newCategories)
{
mCategories = newCategories;
}
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "kpimtextedit_private_export.h"
#include <QSortFilterProxyModel>
namespace KPIMTextEdit
{
class KPIMTEXTEDIT_TESTS_EXPORT EmoticonUnicodeProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit EmoticonUnicodeProxyModel(QObject *parent = nullptr);
~EmoticonUnicodeProxyModel() override;
const QStringList &categories() const;
void setCategories(const QStringList &newCategories);
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
private:
QStringList mCategories;
};
}
......@@ -5,6 +5,7 @@
*/
#include "emoticonunicodetab.h"
#include "emoticonlistview.h"
#include "emoticonlistwidgetselector.h"
#include "emoticonunicodemodel.h"
#include "textutils.h"
......@@ -31,11 +32,9 @@ void EmoticonUnicodeTab::searchUnicode(const QString &str)
// TODO show search page + update proxyfilter + switch to search page
}
void EmoticonUnicodeTab::createFullTab()
void EmoticonUnicodeTab::createSearchTab()
{
auto allEmojisView = new QListView(this);
allEmojisView->setViewMode(QListView::IconMode);
allEmojisView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
auto allEmojisView = new EmoticonListView(this);
// auto emoticonFilterProxyModel = new EmoticonModelFilterProxyModel(this);
// emoticonFilterProxyModel->setSourceModel(account->emoticonModel());
auto m = new EmoticonUnicodeModel(this);
......@@ -49,7 +48,7 @@ void EmoticonUnicodeTab::createFullTab()
void EmoticonUnicodeTab::loadEmoticons()
{
createFullTab();
createSearchTab();
createPlainTextEmoticonTab(i18n("Faces"), EmoticonUnicodeUtils::unicodeFaceEmoji());
createPlainTextEmoticonTab(i18n("Animals"), EmoticonUnicodeUtils::unicodeAnimalsEmoji());
createPlainTextEmoticonTab(i18n("Emotions"), EmoticonUnicodeUtils::unicodeEmotionEmoji());
......
......@@ -32,7 +32,7 @@ Q_SIGNALS:
private:
void createPlainTextEmoticonTab(const QString &str, const QVector<EmoticonUnicodeUtils::EmoticonStruct> &emoticons);
void createFullTab();
void createSearchTab();
};
}
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