@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
After Width: | Height: | Size: 659 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 472 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 599 B |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 725 B |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 640 B |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 637 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 560 B |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 535 B |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 631 B |
@ -0,0 +1,89 @@ |
|||||||
|
#!/usr/bin/env python3 |
||||||
|
|
||||||
|
import sys |
||||||
|
import json |
||||||
|
|
||||||
|
from jinja2 import Template |
||||||
|
|
||||||
|
|
||||||
|
class Emoji(object): |
||||||
|
def __init__(self, code, shortname, category, order): |
||||||
|
self.code = ''.join(list(map(code_to_bytes, code.split('-')))) |
||||||
|
self.shortname = shortname |
||||||
|
self.category = category |
||||||
|
self.order = int(order) |
||||||
|
|
||||||
|
|
||||||
|
def code_to_bytes(codepoint): |
||||||
|
''' |
||||||
|
Convert hex unicode codepoint to hex byte array. |
||||||
|
''' |
||||||
|
bytes = chr(int(codepoint, 16)).encode('utf-8') |
||||||
|
|
||||||
|
return str(bytes)[1:].strip("'") |
||||||
|
|
||||||
|
|
||||||
|
def generate_code(emojis, category): |
||||||
|
tmpl = Template(''' |
||||||
|
const QList<Emoji> EmojiProvider::{{ category }} = { |
||||||
|
{%- for e in emoji %} |
||||||
|
Emoji{QString::fromUtf8("{{ e.code }}"), "{{ e.shortname }}"}, |
||||||
|
{%- endfor %} |
||||||
|
}; |
||||||
|
''') |
||||||
|
|
||||||
|
d = dict(category=category, emoji=emojis) |
||||||
|
print(tmpl.render(d)) |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__': |
||||||
|
if len(sys.argv) < 2: |
||||||
|
print('usage: emoji_codegen.py /path/to/emoji.json') |
||||||
|
sys.exit(1) |
||||||
|
|
||||||
|
filename = sys.argv[1] |
||||||
|
data = {} |
||||||
|
|
||||||
|
with open(filename, 'r') as filename: |
||||||
|
data = json.loads(filename.read()) |
||||||
|
|
||||||
|
emojis = [] |
||||||
|
|
||||||
|
for emoji_name in data: |
||||||
|
tmp = data[emoji_name] |
||||||
|
|
||||||
|
l = len(tmp['unicode'].split('-')) |
||||||
|
|
||||||
|
if l > 1 and tmp['category'] == 'people': |
||||||
|
continue |
||||||
|
|
||||||
|
emojis.append( |
||||||
|
Emoji( |
||||||
|
tmp['unicode'], |
||||||
|
tmp['shortname'], |
||||||
|
tmp['category'], |
||||||
|
tmp['emoji_order'] |
||||||
|
) |
||||||
|
) |
||||||
|
|
||||||
|
emojis.sort(key=lambda x: x.order) |
||||||
|
|
||||||
|
people = list(filter(lambda x: x.category == "people", emojis)) |
||||||
|
nature = list(filter(lambda x: x.category == "nature", emojis)) |
||||||
|
food = list(filter(lambda x: x.category == "food", emojis)) |
||||||
|
activity = list(filter(lambda x: x.category == "activity", emojis)) |
||||||
|
travel = list(filter(lambda x: x.category == "travel", emojis)) |
||||||
|
objects = list(filter(lambda x: x.category == "objects", emojis)) |
||||||
|
symbols = list(filter(lambda x: x.category == "symbols", emojis)) |
||||||
|
flags = list(filter(lambda x: x.category == "flags", emojis)) |
||||||
|
|
||||||
|
# Use xclip to pipe the output to clipboard. |
||||||
|
# e.g ./codegen.py emoji.json | xclip -sel clip |
||||||
|
generate_code(people, 'people') |
||||||
|
generate_code(nature, 'nature') |
||||||
|
generate_code(food, 'food') |
||||||
|
generate_code(activity, 'activity') |
||||||
|
generate_code(travel, 'travel') |
||||||
|
generate_code(objects, 'objects') |
||||||
|
generate_code(symbols, 'symbols') |
||||||
|
generate_code(flags, 'flags') |
@ -0,0 +1,84 @@ |
|||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
#include <QDebug> |
||||||
|
#include <QScrollBar> |
||||||
|
|
||||||
|
#include "EmojiCategory.h" |
||||||
|
|
||||||
|
EmojiCategory::EmojiCategory(QString category, QList<Emoji> emoji, QWidget *parent) |
||||||
|
: QWidget(parent) |
||||||
|
{ |
||||||
|
mainLayout_ = new QVBoxLayout(this); |
||||||
|
mainLayout_->setMargin(0); |
||||||
|
|
||||||
|
emojiListView_ = new QListView(); |
||||||
|
itemModel_ = new QStandardItemModel(this); |
||||||
|
|
||||||
|
delegate_ = new EmojiItemDelegate(this); |
||||||
|
data_ = new Emoji; |
||||||
|
|
||||||
|
emojiListView_->setItemDelegate(delegate_); |
||||||
|
emojiListView_->setSpacing(5); |
||||||
|
emojiListView_->setModel(itemModel_); |
||||||
|
emojiListView_->setViewMode(QListView::IconMode); |
||||||
|
emojiListView_->setFlow(QListView::LeftToRight); |
||||||
|
emojiListView_->setResizeMode(QListView::Adjust); |
||||||
|
emojiListView_->verticalScrollBar()->setEnabled(false); |
||||||
|
emojiListView_->horizontalScrollBar()->setEnabled(false); |
||||||
|
|
||||||
|
const int cols = 7; |
||||||
|
const int rows = emoji.size() / 7; |
||||||
|
|
||||||
|
// TODO: Be precise here. Take the parent into consideration.
|
||||||
|
emojiListView_->setFixedSize(cols * 50 + 20, rows * 50 + 20); |
||||||
|
emojiListView_->setGridSize(QSize(50, 50)); |
||||||
|
emojiListView_->setDragEnabled(false); |
||||||
|
emojiListView_->setEditTriggers(QAbstractItemView::NoEditTriggers); |
||||||
|
|
||||||
|
for (const auto &e : emoji) { |
||||||
|
data_->unicode = e.unicode; |
||||||
|
|
||||||
|
auto item = new QStandardItem; |
||||||
|
item->setSizeHint(QSize(24, 24)); |
||||||
|
|
||||||
|
QVariant unicode(data_->unicode); |
||||||
|
item->setData(unicode.toString(), Qt::UserRole); |
||||||
|
|
||||||
|
itemModel_->appendRow(item); |
||||||
|
} |
||||||
|
|
||||||
|
category_ = new QLabel(category, this); |
||||||
|
category_->setStyleSheet( |
||||||
|
"color: #ccc;" |
||||||
|
"margin: 20px 0px 15px 8px;" |
||||||
|
"font-weight: 500;" |
||||||
|
"font-size: 12px;"); |
||||||
|
|
||||||
|
auto labelLayout_ = new QHBoxLayout(); |
||||||
|
labelLayout_->addWidget(category_); |
||||||
|
labelLayout_->addStretch(1); |
||||||
|
|
||||||
|
mainLayout_->addLayout(labelLayout_); |
||||||
|
mainLayout_->addWidget(emojiListView_); |
||||||
|
|
||||||
|
connect(emojiListView_, &QListView::clicked, this, &EmojiCategory::clickIndex); |
||||||
|
} |
||||||
|
|
||||||
|
EmojiCategory::~EmojiCategory() |
||||||
|
{ |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
#include <QDebug> |
||||||
|
#include <QPainter> |
||||||
|
|
||||||
|
#include "EmojiItemDelegate.h" |
||||||
|
|
||||||
|
EmojiItemDelegate::EmojiItemDelegate(QObject *parent) |
||||||
|
: QStyledItemDelegate(parent) |
||||||
|
{ |
||||||
|
data_ = new Emoji; |
||||||
|
} |
||||||
|
|
||||||
|
EmojiItemDelegate::~EmojiItemDelegate() |
||||||
|
{ |
||||||
|
delete data_; |
||||||
|
} |
||||||
|
|
||||||
|
void EmojiItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
||||||
|
{ |
||||||
|
Q_UNUSED(index); |
||||||
|
|
||||||
|
QStyleOptionViewItem viewOption(option); |
||||||
|
|
||||||
|
auto emoji = index.data(Qt::UserRole).toString(); |
||||||
|
|
||||||
|
QFont font("Emoji One"); |
||||||
|
font.setPixelSize(19); |
||||||
|
|
||||||
|
painter->setFont(font); |
||||||
|
painter->drawText(viewOption.rect, emoji); |
||||||
|
} |
@ -0,0 +1,247 @@ |
|||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
#include <QDebug> |
||||||
|
#include <QLabel> |
||||||
|
#include <QPushButton> |
||||||
|
#include <QScrollArea> |
||||||
|
#include <QScrollBar> |
||||||
|
#include <QVBoxLayout> |
||||||
|
|
||||||
|
#include "Avatar.h" |
||||||
|
#include "EmojiCategory.h" |
||||||
|
#include "EmojiPanel.h" |
||||||
|
#include "FlatButton.h" |
||||||
|
|
||||||
|
EmojiPanel::EmojiPanel(QWidget *parent) |
||||||
|
: QFrame(parent) |
||||||
|
{ |
||||||
|
setStyleSheet( |
||||||
|
"QWidget {background: #f8fbfe; color: #e8e8e8; border: none;}" |
||||||
|
"QScrollBar:vertical { background-color: #f8fbfe; width: 8px; border-radius: 20px; margin: 0px 2px 0 2px; }" |
||||||
|
"QScrollBar::handle:vertical { border-radius : 50px; background-color : #d6dde3; }" |
||||||
|
"QScrollBar::add-line:vertical { border: none; background: none; }" |
||||||
|
"QScrollBar::sub-line:vertical { border: none; background: none; }"); |
||||||
|
|
||||||
|
setParent(0); // Create TopLevel-Widget
|
||||||
|
setAttribute(Qt::WA_NoSystemBackground, true); |
||||||
|
setAttribute(Qt::WA_TranslucentBackground, true); |
||||||
|
setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip); |
||||||
|
|
||||||
|
// TODO: Make it MainWindow aware
|
||||||
|
auto main_frame_ = new QFrame(this); |
||||||
|
main_frame_->setMinimumSize(370, 350); |
||||||
|
main_frame_->setMaximumSize(370, 350); |
||||||
|
|
||||||
|
auto top_layout = new QVBoxLayout(this); |
||||||
|
top_layout->addWidget(main_frame_); |
||||||
|
top_layout->setMargin(0); |
||||||
|
|
||||||
|
auto content_layout = new QVBoxLayout(main_frame_); |
||||||
|
content_layout->setMargin(0); |
||||||
|
|
||||||
|
auto emoji_categories = new QFrame(main_frame_); |
||||||
|
emoji_categories->setStyleSheet("background-color: #f2f2f2"); |
||||||
|
|
||||||
|
auto categories_layout = new QHBoxLayout(emoji_categories); |
||||||
|
categories_layout->setSpacing(6); |
||||||
|
categories_layout->setMargin(5); |
||||||
|
|
||||||
|
auto people_category = new FlatButton(emoji_categories); |
||||||
|
people_category->setIcon(QIcon(":/icons/icons/emoji-categories/people.png")); |
||||||
|
people_category->setIconSize(QSize(category_icon_size_, category_icon_size_)); |
||||||
|
people_category->setForegroundColor("gray"); |
||||||
|
|
||||||
|
auto nature_category = new FlatButton(emoji_categories); |
||||||
|
nature_category->setIcon(QIcon(":/icons/icons/emoji-categories/nature.png")); |
||||||
|
nature_category->setIconSize(QSize(category_icon_size_, category_icon_size_)); |
||||||
|
nature_category->setForegroundColor("gray"); |
||||||
|
|
||||||
|
auto food_category = new FlatButton(emoji_categories); |
||||||
|
food_category->setIcon(QIcon(":/icons/icons/emoji-categories/foods.png")); |
||||||
|
food_category->setIconSize(QSize(category_icon_size_, category_icon_size_)); |
||||||
|
food_category->setForegroundColor("gray"); |
||||||
|
|
||||||
|
auto activity_category = new FlatButton(emoji_categories); |
||||||
|
activity_category->setIcon(QIcon(":/icons/icons/emoji-categories/activity.png")); |
||||||
|
activity_category->setIconSize(QSize(category_icon_size_, category_icon_size_)); |
||||||
|
activity_category->setForegroundColor("gray"); |
||||||
|
|
||||||
|
auto travel_category = new FlatButton(emoji_categories); |
||||||
|
travel_category->setIcon(QIcon(":/icons/icons/emoji-categories/travel.png")); |
||||||
|
travel_category->setIconSize(QSize(category_icon_size_, category_icon_size_)); |
||||||
|
travel_category->setForegroundColor("gray"); |
||||||
|
|
||||||
|
auto objects_category = new FlatButton(emoji_categories); |
||||||
|
objects_category->setIcon(QIcon(":/icons/icons/emoji-categories/objects.png")); |
||||||
|
objects_category->setIconSize(QSize(category_icon_size_, category_icon_size_)); |
||||||
|
objects_category->setForegroundColor("gray"); |
||||||
|
|
||||||
|
auto symbols_category = new FlatButton(emoji_categories); |
||||||
|
symbols_category->setIcon(QIcon(":/icons/icons/emoji-categories/symbols.png")); |
||||||
|
symbols_category->setIconSize(QSize(category_icon_size_, category_icon_size_)); |
||||||
|
symbols_category->setForegroundColor("gray"); |
||||||
|
|
||||||
|
auto flags_category = new FlatButton(emoji_categories); |
||||||
|
flags_category->setIcon(QIcon(":/icons/icons/emoji-categories/flags.png")); |
||||||
|
flags_category->setIconSize(QSize(category_icon_size_, category_icon_size_)); |
||||||
|
flags_category->setForegroundColor("gray"); |
||||||
|
|
||||||
|
categories_layout->addWidget(people_category); |
||||||
|
categories_layout->addWidget(nature_category); |
||||||
|
categories_layout->addWidget(food_category); |
||||||
|
categories_layout->addWidget(activity_category); |
||||||
|
categories_layout->addWidget(travel_category); |
||||||
|
categories_layout->addWidget(objects_category); |
||||||
|
categories_layout->addWidget(symbols_category); |
||||||
|
categories_layout->addWidget(flags_category); |
||||||
|
|
||||||
|
scroll_area_ = new QScrollArea(this); |
||||||
|
scroll_area_->setWidgetResizable(true); |
||||||
|
scroll_area_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
||||||
|
|
||||||
|
auto scroll_widget_ = new QWidget(this); |
||||||
|
auto scroll_layout_ = new QVBoxLayout(scroll_widget_); |
||||||
|
|
||||||
|
scroll_layout_->setMargin(0); |
||||||
|
scroll_area_->setWidget(scroll_widget_); |
||||||
|
|
||||||
|
auto people_emoji = new EmojiCategory("Smileys & People", emoji_provider_.people, scroll_widget_); |
||||||
|
scroll_layout_->addWidget(people_emoji); |
||||||
|
|
||||||
|
auto nature_emoji = new EmojiCategory("Animals & Nature", emoji_provider_.nature, scroll_widget_); |
||||||
|
scroll_layout_->addWidget(nature_emoji); |
||||||
|
|
||||||
|
auto food_emoji = new EmojiCategory("Food & Drink", emoji_provider_.food, scroll_widget_); |
||||||
|
scroll_layout_->addWidget(food_emoji); |
||||||
|
|
||||||
|
auto activity_emoji = new EmojiCategory("Activity", emoji_provider_.activity, scroll_widget_); |
||||||
|
scroll_layout_->addWidget(activity_emoji); |
||||||
|
|
||||||
|
auto travel_emoji = new EmojiCategory("Travel & Places", emoji_provider_.travel, scroll_widget_); |
||||||
|
scroll_layout_->addWidget(travel_emoji); |
||||||
|
|
||||||
|
auto objects_emoji = new EmojiCategory("Objects", emoji_provider_.objects, scroll_widget_); |
||||||
|
scroll_layout_->addWidget(objects_emoji); |
||||||
|
|
||||||
|
auto symbols_emoji = new EmojiCategory("Symbols", emoji_provider_.symbols, scroll_widget_); |
||||||
|
scroll_layout_->addWidget(symbols_emoji); |
||||||
|
|
||||||
|
auto flags_emoji = new EmojiCategory("Flags", emoji_provider_.flags, scroll_widget_); |
||||||
|
scroll_layout_->addWidget(flags_emoji); |
||||||
|
|
||||||
|
content_layout->addStretch(1); |
||||||
|
content_layout->addWidget(scroll_area_); |
||||||
|
content_layout->addWidget(emoji_categories); |
||||||
|
|
||||||
|
setLayout(top_layout); |
||||||
|
|
||||||
|
// TODO: Add parallel animation with geometry
|
||||||
|
opacity_ = new QGraphicsOpacityEffect(this); |
||||||
|
opacity_->setOpacity(1.0); |
||||||
|
|
||||||
|
setGraphicsEffect(opacity_); |
||||||
|
|
||||||
|
animation_ = new QPropertyAnimation(opacity_, "opacity", this); |
||||||
|
animation_->setDuration(180); |
||||||
|
animation_->setStartValue(1.0); |
||||||
|
animation_->setEndValue(0.0); |
||||||
|
|
||||||
|
connect(people_emoji, &EmojiCategory::emojiSelected, this, &EmojiPanel::emojiSelected); |
||||||
|
connect(people_category, &QPushButton::clicked, [this, people_emoji]() { |
||||||
|
this->showEmojiCategory(people_emoji); |
||||||
|
}); |
||||||
|
|
||||||
|
connect(nature_emoji, &EmojiCategory::emojiSelected, this, &EmojiPanel::emojiSelected); |
||||||
|
connect(nature_category, &QPushButton::clicked, [this, nature_emoji]() { |
||||||
|
this->showEmojiCategory(nature_emoji); |
||||||
|
}); |
||||||
|
|
||||||
|
connect(food_emoji, &EmojiCategory::emojiSelected, this, &EmojiPanel::emojiSelected); |
||||||
|
connect(food_category, &QPushButton::clicked, [this, food_emoji]() { |
||||||
|
this->showEmojiCategory(food_emoji); |
||||||
|
}); |
||||||
|
|
||||||
|
connect(activity_emoji, &EmojiCategory::emojiSelected, this, &EmojiPanel::emojiSelected); |
||||||
|
connect(activity_category, &QPushButton::clicked, [this, activity_emoji]() { |
||||||
|
this->showEmojiCategory(activity_emoji); |
||||||
|
}); |
||||||
|
|
||||||
|
connect(travel_emoji, &EmojiCategory::emojiSelected, this, &EmojiPanel::emojiSelected); |
||||||
|
connect(travel_category, &QPushButton::clicked, [this, travel_emoji]() { |
||||||
|
this->showEmojiCategory(travel_emoji); |
||||||
|
}); |
||||||
|
|
||||||
|
connect(objects_emoji, &EmojiCategory::emojiSelected, this, &EmojiPanel::emojiSelected); |
||||||
|
connect(objects_category, &QPushButton::clicked, [this, objects_emoji]() { |
||||||
|
this->showEmojiCategory(objects_emoji); |
||||||
|
}); |
||||||
|
|
||||||
|
connect(symbols_emoji, &EmojiCategory::emojiSelected, this, &EmojiPanel::emojiSelected); |
||||||
|
connect(symbols_category, &QPushButton::clicked, [this, symbols_emoji]() { |
||||||
|
this->showEmojiCategory(symbols_emoji); |
||||||
|
}); |
||||||
|
|
||||||
|
connect(flags_emoji, &EmojiCategory::emojiSelected, this, &EmojiPanel::emojiSelected); |
||||||
|
connect(flags_category, &QPushButton::clicked, [this, flags_emoji]() { |
||||||
|
this->showEmojiCategory(flags_emoji); |
||||||
|
}); |
||||||
|
|
||||||
|
connect(animation_, &QPropertyAnimation::finished, [this]() { |
||||||
|
if (animation_->direction() == QAbstractAnimation::Forward) |
||||||
|
this->hide(); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
void EmojiPanel::showEmojiCategory(const EmojiCategory *category) |
||||||
|
{ |
||||||
|
auto posToGo = category->mapToParent(QPoint()).y(); |
||||||
|
auto current = scroll_area_->verticalScrollBar()->value(); |
||||||
|
|
||||||
|
if (current == posToGo) |
||||||
|
return; |
||||||
|
|
||||||
|
// HACK
|
||||||
|
// If we want to go to a previous category and position the label at the top
|
||||||
|
// the 6*50 offset won't work because not all the categories have the same height.
|
||||||
|
// To ensure the category is at the top, we move to the top
|
||||||
|
// and go as normal to the next category.
|
||||||
|
if (current > posToGo) |
||||||
|
this->scroll_area_->ensureVisible(0, 0, 0, 0); |
||||||
|
|
||||||
|
posToGo += 6 * 50; |
||||||
|
this->scroll_area_->ensureVisible(0, posToGo, 0, 0); |
||||||
|
} |
||||||
|
|
||||||
|
void EmojiPanel::leaveEvent(QEvent *event) |
||||||
|
{ |
||||||
|
Q_UNUSED(event); |
||||||
|
|
||||||
|
fadeOut(); |
||||||
|
} |
||||||
|
|
||||||
|
void EmojiPanel::fadeOut() |
||||||
|
{ |
||||||
|
animation_->setDirection(QAbstractAnimation::Forward); |
||||||
|
animation_->start(); |
||||||
|
} |
||||||
|
|
||||||
|
void EmojiPanel::fadeIn() |
||||||
|
{ |
||||||
|
animation_->setDirection(QAbstractAnimation::Backward); |
||||||
|
animation_->start(); |
||||||
|
} |
@ -0,0 +1,65 @@ |
|||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
#include <QDebug> |
||||||
|
|
||||||
|
#include "EmojiPickButton.h" |
||||||
|
|
||||||
|
EmojiPickButton::EmojiPickButton(QWidget *parent) |
||||||
|
: FlatButton(parent) |
||||||
|
, panel_{nullptr} |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void EmojiPickButton::enterEvent(QEvent *e) |
||||||
|
{ |
||||||
|
Q_UNUSED(e); |
||||||
|
|
||||||
|
if (panel_ == nullptr) { |
||||||
|
panel_ = new EmojiPanel(this); |
||||||
|
connect(panel_, &EmojiPanel::emojiSelected, this, &EmojiPickButton::emojiSelected); |
||||||
|
} |
||||||
|
|
||||||
|
QPoint pos(rect().x(), rect().y()); |
||||||
|
pos = this->mapToGlobal(pos); |
||||||
|
|
||||||
|
auto panel_size = panel_->sizeHint(); |
||||||
|
|
||||||
|
auto x = pos.x() - panel_size.width() + horizontal_distance_; |
||||||
|
auto y = pos.y() - panel_size.height() - vertical_distance_; |
||||||
|
|
||||||
|
panel_->move(x, y); |
||||||
|
panel_->fadeIn(); |
||||||
|
panel_->show(); |
||||||
|
} |
||||||
|
|
||||||
|
void EmojiPickButton::leaveEvent(QEvent *e) |
||||||
|
{ |
||||||
|
Q_UNUSED(e); |
||||||
|
|
||||||
|
if (panel_->underMouse()) |
||||||
|
return; |
||||||
|
|
||||||
|
auto pos = QCursor::pos(); |
||||||
|
auto panel_geometry = panel_->geometry(); |
||||||
|
panel_geometry.adjust(0, 0, 0, vertical_distance_); |
||||||
|
|
||||||
|
if (panel_geometry.contains(pos)) |
||||||
|
return; |
||||||
|
|
||||||
|
panel_->fadeOut(); |
||||||
|
} |