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

Add special emoticonrecentlistview

parent efe95ca4
......@@ -58,6 +58,8 @@ target_sources(KF5PimTextEdit PRIVATE
emoticon/emoticonlistview.cpp
emoticon/emoticonunicodeproxymodel.cpp
emoticon/emoticonunicodemodelmanager.cpp
emoticon/emoticonrecentusedfilterproxymodel.cpp
emoticon/emoticonrecentlistview.cpp
)
target_sources(KF5PimTextEdit PRIVATE
......
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "emoticonrecentlistview.h"
using namespace KPIMTextEdit;
EmoticonRecentListView::EmoticonRecentListView(QWidget *parent)
: EmoticonListView(parent)
{
}
EmoticonRecentListView::~EmoticonRecentListView()
{
}
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "emoticonlistview.h"
#include "kpimtextedit_private_export.h"
namespace KPIMTextEdit
{
class KPIMTEXTEDIT_TESTS_EXPORT EmoticonRecentListView : public EmoticonListView
{
Q_OBJECT
public:
explicit EmoticonRecentListView(QWidget *parent = nullptr);
~EmoticonRecentListView() override;
};
}
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "emoticonrecentusedfilterproxymodel.h"
#include "emoticonunicodemodel.h"
#include <KConfig>
#include <KConfigGroup>
#include <KSharedConfig>
namespace
{
static const char myEmoticonRecentUsedFilterProxyModelGroupName[] = "EmoticonRecentUsed";
}
using namespace KPIMTextEdit;
EmoticonRecentUsedFilterProxyModel::EmoticonRecentUsedFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
loadRecentUsed();
}
EmoticonRecentUsedFilterProxyModel::~EmoticonRecentUsedFilterProxyModel()
{
writeRecentUsed();
}
void EmoticonRecentUsedFilterProxyModel::loadRecentUsed()
{
KConfigGroup group(KSharedConfig::openConfig(), myEmoticonRecentUsedFilterProxyModelGroupName);
const QStringList recentUsed = group.readEntry("Recents", QStringList());
setUsedIdentifier(recentUsed);
}
void EmoticonRecentUsedFilterProxyModel::writeRecentUsed()
{
KConfigGroup group(KSharedConfig::openConfig(), myEmoticonRecentUsedFilterProxyModelGroupName);
group.writeEntry("Recents", mUsedIdentifier);
group.sync();
}
QStringList EmoticonRecentUsedFilterProxyModel::usedIdentifier() const
{
return mUsedIdentifier;
}
void EmoticonRecentUsedFilterProxyModel::setUsedIdentifier(const QStringList &usedIdentifier)
{
if (mUsedIdentifier != usedIdentifier) {
mUsedIdentifier = usedIdentifier;
writeRecentUsed();
invalidateFilter();
}
}
void EmoticonRecentUsedFilterProxyModel::addIdentifier(const QString &identifier)
{
if (!mUsedIdentifier.contains(identifier)) {
mUsedIdentifier.append(identifier);
writeRecentUsed();
invalidateFilter();
}
}
bool EmoticonRecentUsedFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
const QModelIndex sourceIndex = sourceModel()->index(source_row, 0, source_parent);
const QString identifier = sourceIndex.data(EmoticonUnicodeModel::Identifier).toString();
if (mUsedIdentifier.contains(identifier)) {
return true;
}
return false;
}
/*
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 EmoticonRecentUsedFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit EmoticonRecentUsedFilterProxyModel(QObject *parent = nullptr);
~EmoticonRecentUsedFilterProxyModel() override;
Q_REQUIRED_RESULT QStringList usedIdentifier() const;
void setUsedIdentifier(const QStringList &usedIdentifier);
void addIdentifier(const QString &identifier);
void loadRecentUsed();
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
private:
void writeRecentUsed();
QStringList mUsedIdentifier;
};
}
Markdown is supported
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