Add full emoji support
This commit is contained in:
parent
ebbce440bf
commit
42bb9bb63a
40 changed files with 2715 additions and 17 deletions
62
include/EmojiCategory.h
Normal file
62
include/EmojiCategory.h
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef EMOJI_CATEGORY_H
|
||||
#define EMOJI_CATEGORY_H
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QListView>
|
||||
#include <QStandardItemModel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
#include "EmojiItemDelegate.h"
|
||||
#include "EmojiProvider.h"
|
||||
|
||||
class EmojiCategory : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EmojiCategory(QString category, QList<Emoji> emoji, QWidget *parent = nullptr);
|
||||
~EmojiCategory();
|
||||
|
||||
signals:
|
||||
void emojiSelected(const QString &emoji);
|
||||
|
||||
private slots:
|
||||
inline void clickIndex(const QModelIndex &);
|
||||
|
||||
private:
|
||||
QVBoxLayout *mainLayout_;
|
||||
|
||||
QStandardItemModel *itemModel_;
|
||||
QListView *emojiListView_;
|
||||
|
||||
Emoji *data_;
|
||||
EmojiItemDelegate *delegate_;
|
||||
|
||||
QLabel *category_;
|
||||
};
|
||||
|
||||
inline void EmojiCategory::clickIndex(const QModelIndex &index)
|
||||
{
|
||||
emit emojiSelected(index.data(Qt::UserRole).toString());
|
||||
}
|
||||
|
||||
#endif // EMOJI_CATEGORY_H
|
||||
41
include/EmojiItemDelegate.h
Normal file
41
include/EmojiItemDelegate.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef EMOJI_ITEM_DELEGATE_H
|
||||
#define EMOJI_ITEM_DELEGATE_H
|
||||
|
||||
#include <QModelIndex>
|
||||
#include <QStandardItemModel>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include "EmojiProvider.h"
|
||||
|
||||
class EmojiItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EmojiItemDelegate(QObject *parent = nullptr);
|
||||
~EmojiItemDelegate();
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
private:
|
||||
Emoji *data_;
|
||||
};
|
||||
|
||||
#endif // EMOJI_ITEM_DELEGATE_H
|
||||
60
include/EmojiPanel.h
Normal file
60
include/EmojiPanel.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef EMOJI_PANEL_H
|
||||
#define EMOJI_PANEL_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QGraphicsOpacityEffect>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QScrollArea>
|
||||
#include <QWidget>
|
||||
|
||||
#include "EmojiCategory.h"
|
||||
#include "EmojiProvider.h"
|
||||
|
||||
class EmojiPanel : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EmojiPanel(QWidget *parent = nullptr);
|
||||
|
||||
void fadeOut();
|
||||
void fadeIn();
|
||||
|
||||
signals:
|
||||
void mouseLeft();
|
||||
void emojiSelected(const QString &emoji);
|
||||
|
||||
protected:
|
||||
void leaveEvent(QEvent *event);
|
||||
|
||||
private:
|
||||
void showEmojiCategory(const EmojiCategory *category);
|
||||
|
||||
QPropertyAnimation *animation_;
|
||||
QGraphicsOpacityEffect *opacity_;
|
||||
|
||||
EmojiProvider emoji_provider_;
|
||||
|
||||
QScrollArea *scroll_area_;
|
||||
|
||||
const int category_icon_size_ = 20;
|
||||
};
|
||||
|
||||
#endif // EMOJI_PANEL_H
|
||||
50
include/EmojiPickButton.h
Normal file
50
include/EmojiPickButton.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef EMOJI_PICK_BUTTON_H
|
||||
#define EMOJI_PICK_BUTTON_H
|
||||
|
||||
#include <QEvent>
|
||||
#include <QWidget>
|
||||
|
||||
#include "EmojiPanel.h"
|
||||
#include "FlatButton.h"
|
||||
|
||||
class EmojiPickButton : public FlatButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit EmojiPickButton(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void emojiSelected(const QString &emoji);
|
||||
|
||||
protected:
|
||||
void enterEvent(QEvent *e) override;
|
||||
void leaveEvent(QEvent *e) override;
|
||||
|
||||
private:
|
||||
// Vertical distance from panel's bottom.
|
||||
int vertical_distance_ = 10;
|
||||
|
||||
// Horizontal distance from panel's bottom right corner.
|
||||
int horizontal_distance_ = 70;
|
||||
|
||||
EmojiPanel *panel_;
|
||||
};
|
||||
|
||||
#endif // EMOJI_PICK_BUTTON_H
|
||||
45
include/EmojiProvider.h
Normal file
45
include/EmojiProvider.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef EMOJI_PROVIDER_H
|
||||
#define EMOJI_PROVIDER_H
|
||||
|
||||
#include <QFile>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
|
||||
struct Emoji {
|
||||
// Unicode code.
|
||||
QString unicode;
|
||||
// Keyboard shortcut e.g :emoji:
|
||||
QString shortname;
|
||||
};
|
||||
|
||||
class EmojiProvider
|
||||
{
|
||||
public:
|
||||
static const QList<Emoji> people;
|
||||
static const QList<Emoji> nature;
|
||||
static const QList<Emoji> food;
|
||||
static const QList<Emoji> activity;
|
||||
static const QList<Emoji> travel;
|
||||
static const QList<Emoji> objects;
|
||||
static const QList<Emoji> symbols;
|
||||
static const QList<Emoji> flags;
|
||||
};
|
||||
|
||||
#endif // EMOJI_PROVIDER_H
|
||||
|
|
@ -19,12 +19,24 @@
|
|||
#define TEXT_INPUT_WIDGET_H
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QPaintEvent>
|
||||
#include <QTextEdit>
|
||||
#include <QWidget>
|
||||
|
||||
#include "EmojiPickButton.h"
|
||||
#include "FlatButton.h"
|
||||
|
||||
class FilteredTextEdit : public QTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FilteredTextEdit(QWidget *parent = nullptr);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
signals:
|
||||
void enterPressed();
|
||||
};
|
||||
|
||||
class TextInputWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -36,6 +48,9 @@ public:
|
|||
public slots:
|
||||
void onSendButtonClicked();
|
||||
|
||||
private slots:
|
||||
void addSelectedEmoji(const QString &emoji);
|
||||
|
||||
signals:
|
||||
void sendTextMessage(QString msg);
|
||||
|
||||
|
|
@ -44,10 +59,11 @@ protected:
|
|||
|
||||
private:
|
||||
QHBoxLayout *top_layout_;
|
||||
QLineEdit *input_;
|
||||
FilteredTextEdit *input_;
|
||||
|
||||
FlatButton *send_file_button_;
|
||||
FlatButton *send_message_button_;
|
||||
EmojiPickButton *emoji_button_;
|
||||
};
|
||||
|
||||
#endif // TEXT_INPUT_WIDGET_H
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ public:
|
|||
|
||||
protected:
|
||||
enum {
|
||||
IconPadding = 12
|
||||
IconPadding = 0
|
||||
};
|
||||
|
||||
void checkStateSet() override;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue