mirror-chatterino2/src/widgets/emotepopup.cpp

119 lines
4 KiB
C++
Raw Normal View History

#include "emotepopup.hpp"
#include <QHBoxLayout>
2017-12-19 03:18:00 +01:00
#include <QTabWidget>
#include "messages/messagebuilder.hpp"
2018-02-05 15:11:50 +01:00
#include "providers/twitch/twitchchannel.hpp"
2018-02-05 15:11:50 +01:00
using namespace chatterino::providers::twitch;
using namespace chatterino::messages;
2017-09-15 17:23:49 +02:00
namespace chatterino {
namespace widgets {
2017-12-31 22:58:35 +01:00
EmotePopup::EmotePopup(singletons::ThemeManager &themeManager)
: BaseWindow(themeManager, 0)
2017-09-15 17:23:49 +02:00
{
2017-12-19 03:18:00 +01:00
this->viewEmotes = new ChannelView();
this->viewEmojis = new ChannelView();
2018-01-27 21:13:22 +01:00
this->viewEmotes->setOverrideFlags((MessageElement::Flags)(
MessageElement::Default | MessageElement::AlwaysShow | MessageElement::EmoteImages));
this->viewEmojis->setOverrideFlags((MessageElement::Flags)(
MessageElement::Default | MessageElement::AlwaysShow | MessageElement::EmoteImages));
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();
2018-01-24 20:58:53 +01:00
this->viewEmotes->linkClicked.connect(
[this](const Link &link) { this->linkClicked.invoke(link); });
this->viewEmojis->linkClicked.connect(
[this](const Link &link) { this->linkClicked.invoke(link); });
2017-09-15 17:23:49 +02:00
}
void EmotePopup::loadChannel(ChannelPtr _channel)
2017-09-15 17:23:49 +02:00
{
TwitchChannel *channel = dynamic_cast<TwitchChannel *>(_channel.get());
if (channel == nullptr) {
return;
}
ChannelPtr emoteChannel(new Channel(""));
2017-12-31 22:58:35 +01:00
auto addEmotes = [&](util::EmoteMap &map, const QString &title, const QString &emoteDesc) {
// TITLE
messages::MessageBuilder builder1;
2018-01-28 03:48:15 +01:00
builder1.append(new TextElement(title, MessageElement::Text));
2018-01-28 03:29:42 +01:00
builder1.getMessage()->flags &= Message::Centered;
emoteChannel->addMessage(builder1.getMessage());
// EMOTES
messages::MessageBuilder builder2;
2018-01-28 03:29:42 +01:00
builder2.getMessage()->flags &= Message::Centered;
builder2.getMessage()->flags &= Message::DisableCompactEmotes;
2017-12-31 22:58:35 +01:00
map.each([&](const QString &key, const util::EmoteData &value) {
2018-01-28 03:48:15 +01:00
builder2.append((new EmoteElement(value, MessageElement::Flags::AlwaysShow))
2018-02-05 15:11:50 +01:00
->setLink(Link(Link::InsertText, key)));
});
emoteChannel->addMessage(builder2.getMessage());
};
2017-12-31 22:58:35 +01:00
singletons::EmoteManager &emoteManager = singletons::EmoteManager::getInstance();
2017-12-17 02:18:13 +01:00
addEmotes(emoteManager.bttvGlobalEmotes, "BetterTTV Global Emotes", "BetterTTV Global Emote");
addEmotes(*channel->bttvChannelEmotes.get(), "BetterTTV Channel Emotes",
"BetterTTV Channel Emote");
2017-12-17 02:18:13 +01:00
addEmotes(emoteManager.ffzGlobalEmotes, "FrankerFaceZ Global Emotes",
"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()
{
auto &emojis = singletons::EmoteManager::getInstance().getEmojis();
2017-12-19 03:18:00 +01:00
ChannelPtr emojiChannel(new Channel(""));
2017-12-19 03:18:00 +01:00
// title
messages::MessageBuilder builder1;
2018-01-28 03:48:15 +01:00
builder1.append(new TextElement("emojis", MessageElement::Text));
2018-01-28 03:29:42 +01:00
builder1.getMessage()->flags &= Message::Centered;
2017-12-19 03:18:00 +01:00
emojiChannel->addMessage(builder1.getMessage());
// emojis
messages::MessageBuilder builder;
2018-01-28 03:29:42 +01:00
builder.getMessage()->flags &= Message::Centered;
builder.getMessage()->flags &= Message::DisableCompactEmotes;
emojis.each([&builder](const QString &key, const auto &value) {
builder.append((new EmoteElement(value.emoteData, MessageElement::Flags::AlwaysShow))
->setLink(Link(Link::Type::InsertText, ":" + value.shortCode + ":")));
});
2017-12-19 03:18:00 +01:00
emojiChannel->addMessage(builder.getMessage());
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
} // namespace widgets
} // namespace chatterino