2017-09-16 16:20:10 +02:00
|
|
|
#include "emotepopup.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
2017-12-19 03:18:00 +01:00
|
|
|
#include <QTabWidget>
|
2017-09-16 00:05:06 +02:00
|
|
|
|
|
|
|
#include "messages/messagebuilder.hpp"
|
|
|
|
#include "twitch/twitchchannel.hpp"
|
|
|
|
|
|
|
|
using namespace chatterino::twitch;
|
|
|
|
using namespace chatterino::messages;
|
|
|
|
|
2017-09-15 17:23:49 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
|
|
|
|
2017-12-17 02:18:13 +01:00
|
|
|
EmotePopup::EmotePopup(ColorScheme &colorScheme)
|
2017-09-16 00:05:06 +02:00
|
|
|
: BaseWidget(colorScheme, 0)
|
2017-09-15 17:23:49 +02:00
|
|
|
{
|
2017-09-23 18:37:51 +02:00
|
|
|
this->initAsWindow();
|
|
|
|
|
2017-12-19 03:18:00 +01:00
|
|
|
this->viewEmotes = new ChannelView();
|
|
|
|
this->viewEmojis = new ChannelView();
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2017-12-28 00:48:21 +01:00
|
|
|
this->viewEmotes->setEnableScrollingToBottom(false);
|
|
|
|
this->viewEmojis->setEnableScrollingToBottom(false);
|
|
|
|
|
2017-12-19 03:18:00 +01:00
|
|
|
this->setLayout(new QVBoxLayout(this));
|
|
|
|
|
|
|
|
QTabWidget *tabs = new QTabWidget(this);
|
|
|
|
this->layout()->addWidget(tabs);
|
|
|
|
this->layout()->setMargin(0);
|
|
|
|
tabs->addTab(this->viewEmotes, "Emotes");
|
|
|
|
tabs->addTab(this->viewEmojis, "Emojis");
|
|
|
|
|
|
|
|
this->loadEmojis();
|
2017-09-15 17:23:49 +02:00
|
|
|
}
|
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
void EmotePopup::loadChannel(std::shared_ptr<Channel> _channel)
|
2017-09-15 17:23:49 +02:00
|
|
|
{
|
2017-09-16 00:05:06 +02:00
|
|
|
TwitchChannel *channel = dynamic_cast<TwitchChannel *>(_channel.get());
|
|
|
|
|
|
|
|
if (channel == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
std::shared_ptr<Channel> emoteChannel(new Channel(""));
|
2017-09-16 00:05:06 +02:00
|
|
|
|
|
|
|
auto addEmotes = [&](EmoteMap &map, const QString &title, const QString &emoteDesc) {
|
|
|
|
// TITLE
|
|
|
|
messages::MessageBuilder builder1;
|
|
|
|
|
2017-12-23 21:18:13 +01:00
|
|
|
builder1.appendWord(Word(title, Word::Flags::Text, MessageColor(MessageColor::Text),
|
|
|
|
FontManager::Medium, QString(), QString()));
|
2017-09-16 00:05:06 +02:00
|
|
|
|
|
|
|
builder1.getMessage()->centered = true;
|
|
|
|
emoteChannel->addMessage(builder1.getMessage());
|
|
|
|
|
|
|
|
// EMOTES
|
|
|
|
messages::MessageBuilder builder2;
|
|
|
|
builder2.getMessage()->centered = true;
|
|
|
|
|
|
|
|
map.each([&](const QString &key, const EmoteData &value) {
|
2017-12-23 21:18:13 +01:00
|
|
|
builder2.appendWord(Word(value.image, Word::Flags::AlwaysShow, key, emoteDesc,
|
2017-09-16 00:05:06 +02:00
|
|
|
Link(Link::Type::InsertText, key)));
|
|
|
|
});
|
|
|
|
|
|
|
|
emoteChannel->addMessage(builder2.getMessage());
|
|
|
|
};
|
|
|
|
|
2017-12-17 02:18:13 +01:00
|
|
|
EmoteManager &emoteManager = EmoteManager::getInstance();
|
|
|
|
|
|
|
|
addEmotes(emoteManager.bttvGlobalEmotes, "BetterTTV Global Emotes", "BetterTTV Global Emote");
|
2017-09-16 00:05:06 +02:00
|
|
|
addEmotes(*channel->bttvChannelEmotes.get(), "BetterTTV Channel Emotes",
|
|
|
|
"BetterTTV Channel Emote");
|
2017-12-17 02:18:13 +01:00
|
|
|
addEmotes(emoteManager.ffzGlobalEmotes, "FrankerFaceZ Global Emotes",
|
2017-09-16 00:05:06 +02:00
|
|
|
"FrankerFaceZ Global Emote");
|
|
|
|
addEmotes(*channel->ffzChannelEmotes.get(), "FrankerFaceZ Channel Emotes",
|
|
|
|
"FrankerFaceZ Channel Emote");
|
2017-09-15 17:23:49 +02:00
|
|
|
|
2017-12-19 03:18:00 +01:00
|
|
|
this->viewEmotes->setChannel(emoteChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmotePopup::loadEmojis()
|
|
|
|
{
|
|
|
|
EmoteMap &emojis = EmoteManager::getInstance().getEmojis();
|
|
|
|
|
|
|
|
std::shared_ptr<Channel> emojiChannel(new Channel(""));
|
|
|
|
|
|
|
|
// title
|
|
|
|
messages::MessageBuilder builder1;
|
|
|
|
|
2017-12-23 21:18:13 +01:00
|
|
|
builder1.appendWord(Word("emojis", Word::Flags::Text, MessageColor(MessageColor::Text),
|
|
|
|
FontManager::Medium, QString(), QString()));
|
2017-12-19 03:18:00 +01:00
|
|
|
|
|
|
|
builder1.getMessage()->centered = true;
|
|
|
|
emojiChannel->addMessage(builder1.getMessage());
|
|
|
|
|
|
|
|
// emojis
|
|
|
|
messages::MessageBuilder builder;
|
|
|
|
builder.getMessage()->centered = true;
|
|
|
|
emojis.each([this, &builder](const QString &key, const EmoteData &value) {
|
2017-12-23 21:18:13 +01:00
|
|
|
builder.appendWord(Word(value.image, Word::Flags::AlwaysShow, key, "emoji",
|
2017-12-19 03:18:00 +01:00
|
|
|
Link(Link::Type::InsertText, key)));
|
|
|
|
});
|
|
|
|
emojiChannel->addMessage(builder.getMessage());
|
2017-09-16 16:20:10 +02:00
|
|
|
|
2017-12-19 03:18:00 +01:00
|
|
|
this->viewEmojis->setChannel(emojiChannel);
|
2017-09-15 17:23:49 +02:00
|
|
|
}
|
2017-12-17 02:10:35 +01:00
|
|
|
|
2017-09-23 18:37:51 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|