Basic emoji history support. #96
This commit is contained in:
parent
27a279bc3c
commit
85ceec7b44
|
@ -9,7 +9,7 @@ import Spectral 0.1
|
||||||
import Spectral.Setting 0.1
|
import Spectral.Setting 0.1
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
property string emojiCategory: "people"
|
property string emojiCategory: "history"
|
||||||
property var textArea
|
property var textArea
|
||||||
property var emojiModel
|
property var emojiModel
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ ColumnLayout {
|
||||||
orientation: ListView.Horizontal
|
orientation: ListView.Horizontal
|
||||||
|
|
||||||
model: ListModel {
|
model: ListModel {
|
||||||
|
ListElement { label: "⌛️"; category: "history" }
|
||||||
ListElement { label: "😏"; category: "people" }
|
ListElement { label: "😏"; category: "people" }
|
||||||
ListElement { label: "🌲"; category: "nature" }
|
ListElement { label: "🌲"; category: "nature" }
|
||||||
ListElement { label: "🍛"; category: "food"}
|
ListElement { label: "🍛"; category: "food"}
|
||||||
|
@ -85,7 +86,29 @@ ColumnLayout {
|
||||||
|
|
||||||
clip: true
|
clip: true
|
||||||
|
|
||||||
model: emojiModel.model[emojiCategory]
|
model: {
|
||||||
|
switch (emojiCategory) {
|
||||||
|
case "history":
|
||||||
|
return emojiModel.history
|
||||||
|
case "people":
|
||||||
|
return emojiModel.people
|
||||||
|
case "nature":
|
||||||
|
return emojiModel.nature
|
||||||
|
case "food":
|
||||||
|
return emojiModel.food
|
||||||
|
case "activity":
|
||||||
|
return emojiModel.activity
|
||||||
|
case "travel":
|
||||||
|
return emojiModel.travel
|
||||||
|
case "objects":
|
||||||
|
return emojiModel.objects
|
||||||
|
case "symbols":
|
||||||
|
return emojiModel.symbols
|
||||||
|
case "flags":
|
||||||
|
return emojiModel.flags
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
delegate: ItemDelegate {
|
delegate: ItemDelegate {
|
||||||
width: 48
|
width: 48
|
||||||
|
@ -99,7 +122,10 @@ ColumnLayout {
|
||||||
text: modelData.unicode
|
text: modelData.unicode
|
||||||
}
|
}
|
||||||
|
|
||||||
onClicked: textArea.insert(textArea.cursorPosition, modelData.unicode)
|
onClicked: {
|
||||||
|
textArea.insert(textArea.cursorPosition, modelData.unicode)
|
||||||
|
emojiModel.emojiUsed(modelData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollBar.vertical: ScrollBar {}
|
ScrollBar.vertical: ScrollBar {}
|
||||||
|
|
|
@ -20,19 +20,8 @@
|
||||||
|
|
||||||
#include "emojimodel.h"
|
#include "emojimodel.h"
|
||||||
|
|
||||||
QVariantMap EmojiModel::getModel() {
|
QVariantList EmojiModel::history() {
|
||||||
QVariantMap map;
|
return m_settings->value("Editor/emojis", QVariantList()).toList();
|
||||||
|
|
||||||
map.insert("people", people);
|
|
||||||
map.insert("nature", nature);
|
|
||||||
map.insert("food", food);
|
|
||||||
map.insert("activity", activity);
|
|
||||||
map.insert("travel", travel);
|
|
||||||
map.insert("objects", objects);
|
|
||||||
map.insert("symbols", symbols);
|
|
||||||
map.insert("flags", flags);
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList EmojiModel::filterModel(const QString& filter) {
|
QVariantList EmojiModel::filterModel(const QString& filter) {
|
||||||
|
@ -90,6 +79,23 @@ QVariantList EmojiModel::filterModel(const QString& filter) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EmojiModel::emojiUsed(QVariant modelData) {
|
||||||
|
QVariantList list = history();
|
||||||
|
|
||||||
|
auto it = list.begin();
|
||||||
|
while (it != list.end()) {
|
||||||
|
if ((*it).value<Emoji>().unicode == modelData.value<Emoji>().unicode) {
|
||||||
|
it = list.erase(it);
|
||||||
|
} else
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
|
||||||
|
list.push_front(modelData);
|
||||||
|
m_settings->setValue("Editor/emojis", list);
|
||||||
|
|
||||||
|
emit historyChanged();
|
||||||
|
}
|
||||||
|
|
||||||
const QVariantList EmojiModel::people = {
|
const QVariantList EmojiModel::people = {
|
||||||
QVariant::fromValue(
|
QVariant::fromValue(
|
||||||
Emoji{QString::fromUtf8("\xf0\x9f\x98\x80"), ":grinning:"}),
|
Emoji{QString::fromUtf8("\xf0\x9f\x98\x80"), ":grinning:"}),
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define EMOJIMODEL_H
|
#define EMOJIMODEL_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QSettings>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
@ -9,6 +10,18 @@ struct Emoji {
|
||||||
Emoji(const QString& u, const QString& s) : unicode(u), shortname(s) {}
|
Emoji(const QString& u, const QString& s) : unicode(u), shortname(s) {}
|
||||||
Emoji() {}
|
Emoji() {}
|
||||||
|
|
||||||
|
friend QDataStream& operator<<(QDataStream& arch, const Emoji& object) {
|
||||||
|
arch << object.unicode;
|
||||||
|
arch << object.shortname;
|
||||||
|
return arch;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend QDataStream& operator>>(QDataStream& arch, Emoji& object) {
|
||||||
|
arch >> object.unicode;
|
||||||
|
arch >> object.shortname;
|
||||||
|
return arch;
|
||||||
|
}
|
||||||
|
|
||||||
QString unicode;
|
QString unicode;
|
||||||
QString shortname;
|
QString shortname;
|
||||||
|
|
||||||
|
@ -21,11 +34,31 @@ Q_DECLARE_METATYPE(Emoji)
|
||||||
|
|
||||||
class EmojiModel : public QObject {
|
class EmojiModel : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QVariantMap model READ getModel CONSTANT)
|
|
||||||
|
Q_PROPERTY(QVariantList history READ history NOTIFY historyChanged)
|
||||||
|
|
||||||
|
Q_PROPERTY(QVariantList people MEMBER people CONSTANT)
|
||||||
|
Q_PROPERTY(QVariantList nature MEMBER nature CONSTANT)
|
||||||
|
Q_PROPERTY(QVariantList food MEMBER food CONSTANT)
|
||||||
|
Q_PROPERTY(QVariantList activity MEMBER activity CONSTANT)
|
||||||
|
Q_PROPERTY(QVariantList travel MEMBER travel CONSTANT)
|
||||||
|
Q_PROPERTY(QVariantList objects MEMBER objects CONSTANT)
|
||||||
|
Q_PROPERTY(QVariantList symbols MEMBER symbols CONSTANT)
|
||||||
|
Q_PROPERTY(QVariantList flags MEMBER flags CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Q_INVOKABLE QVariantMap getModel();
|
explicit EmojiModel(QObject* parent = nullptr)
|
||||||
|
: QObject(parent), m_settings(new QSettings()) {}
|
||||||
|
|
||||||
|
Q_INVOKABLE QVariantList history();
|
||||||
Q_INVOKABLE QVariantList filterModel(const QString& filter);
|
Q_INVOKABLE QVariantList filterModel(const QString& filter);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void historyChanged();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void emojiUsed(QVariant modelData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const QVariantList people;
|
static const QVariantList people;
|
||||||
static const QVariantList nature;
|
static const QVariantList nature;
|
||||||
|
@ -35,6 +68,8 @@ class EmojiModel : public QObject {
|
||||||
static const QVariantList objects;
|
static const QVariantList objects;
|
||||||
static const QVariantList symbols;
|
static const QVariantList symbols;
|
||||||
static const QVariantList flags;
|
static const QVariantList flags;
|
||||||
|
|
||||||
|
QSettings* m_settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EMOJIMODEL_H
|
#endif // EMOJIMODEL_H
|
||||||
|
|
|
@ -67,6 +67,8 @@ int main(int argc, char* argv[]) {
|
||||||
qRegisterMetaType<SpectralRoom*>("SpectralRoom*");
|
qRegisterMetaType<SpectralRoom*>("SpectralRoom*");
|
||||||
qRegisterMetaType<SpectralUser*>("SpectralUser*");
|
qRegisterMetaType<SpectralUser*>("SpectralUser*");
|
||||||
|
|
||||||
|
qRegisterMetaTypeStreamOperators<Emoji>();
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
|
|
||||||
engine.addImportPath("qrc:/imports");
|
engine.addImportPath("qrc:/imports");
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
class MessageEventModel : public QAbstractListModel {
|
class MessageEventModel : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(SpectralRoom* room READ getRoom WRITE setRoom NOTIFY roomChanged)
|
Q_PROPERTY(SpectralRoom* room READ room WRITE setRoom NOTIFY roomChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum EventRoles {
|
enum EventRoles {
|
||||||
|
@ -40,7 +40,7 @@ class MessageEventModel : public QAbstractListModel {
|
||||||
explicit MessageEventModel(QObject* parent = nullptr);
|
explicit MessageEventModel(QObject* parent = nullptr);
|
||||||
~MessageEventModel();
|
~MessageEventModel();
|
||||||
|
|
||||||
SpectralRoom* getRoom() { return m_currentRoom; }
|
SpectralRoom* room() { return m_currentRoom; }
|
||||||
void setRoom(SpectralRoom* room);
|
void setRoom(SpectralRoom* room);
|
||||||
|
|
||||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
|
|
Loading…
Reference in New Issue