summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-04-23 21:31:08 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-04-23 21:31:08 +0300
commit42bb9bb63a957944a032a4f48db502a7cbd9b74c (patch)
treeb0622cc93bbb60e2dbd6d16ca1c95015b3e0aabf /include
parentUpdate screen (diff)
downloadnheko-42bb9bb63a957944a032a4f48db502a7cbd9b74c.tar.xz
Add full emoji support
Diffstat (limited to 'include')
-rw-r--r--include/EmojiCategory.h62
-rw-r--r--include/EmojiItemDelegate.h41
-rw-r--r--include/EmojiPanel.h60
-rw-r--r--include/EmojiPickButton.h50
-rw-r--r--include/EmojiProvider.h45
-rw-r--r--include/TextInputWidget.h20
-rw-r--r--include/ui/FlatButton.h2
7 files changed, 277 insertions, 3 deletions
diff --git a/include/EmojiCategory.h b/include/EmojiCategory.h
new file mode 100644
index 00000000..a26711df
--- /dev/null
+++ b/include/EmojiCategory.h
@@ -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
diff --git a/include/EmojiItemDelegate.h b/include/EmojiItemDelegate.h
new file mode 100644
index 00000000..5eeb4e24
--- /dev/null
+++ b/include/EmojiItemDelegate.h
@@ -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
diff --git a/include/EmojiPanel.h b/include/EmojiPanel.h
new file mode 100644
index 00000000..5e053216
--- /dev/null
+++ b/include/EmojiPanel.h
@@ -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
diff --git a/include/EmojiPickButton.h b/include/EmojiPickButton.h
new file mode 100644
index 00000000..77bc5495
--- /dev/null
+++ b/include/EmojiPickButton.h
@@ -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
diff --git a/include/EmojiProvider.h b/include/EmojiProvider.h
new file mode 100644
index 00000000..630ea81a
--- /dev/null
+++ b/include/EmojiProvider.h
@@ -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
diff --git a/include/TextInputWidget.h b/include/TextInputWidget.h
index 35a12892..c61298bf 100644
--- a/include/TextInputWidget.h
+++ b/include/TextInputWidget.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
diff --git a/include/ui/FlatButton.h b/include/ui/FlatButton.h
index be7ce09c..8053f430 100644
--- a/include/ui/FlatButton.h
+++ b/include/ui/FlatButton.h
@@ -133,7 +133,7 @@ public:
 
 protected:
 	enum {
-		IconPadding = 12
+		IconPadding = 0
 	};
 
 	void checkStateSet() override;