2018-06-26 14:09:39 +02:00
|
|
|
#include "EmotePopup.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
|
|
|
#include "messages/MessageBuilder.hpp"
|
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
|
|
|
#include "widgets/Notebook.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
#include <QHBoxLayout>
|
2018-05-23 13:54:42 +02:00
|
|
|
#include <QShortcut>
|
2018-04-27 22:11:19 +02:00
|
|
|
#include <QTabWidget>
|
|
|
|
|
2017-09-15 17:23:49 +02:00
|
|
|
namespace chatterino {
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
EmotePopup::EmotePopup()
|
2018-05-23 22:27:29 +02:00
|
|
|
: BaseWindow(nullptr, BaseWindow::EnableCustomFrame)
|
2017-09-15 17:23:49 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->viewEmotes_ = new ChannelView();
|
|
|
|
this->viewEmojis_ = new ChannelView();
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
this->viewEmotes_->setOverrideFlags(MessageElementFlags{
|
|
|
|
MessageElementFlag::Default, MessageElementFlag::AlwaysShow,
|
|
|
|
MessageElementFlag::EmoteImages});
|
|
|
|
this->viewEmojis_->setOverrideFlags(MessageElementFlags{
|
|
|
|
MessageElementFlag::Default, MessageElementFlag::AlwaysShow,
|
|
|
|
MessageElementFlag::EmoteImages});
|
2018-01-27 21:13:22 +01:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->viewEmotes_->setEnableScrollingToBottom(false);
|
|
|
|
this->viewEmojis_->setEnableScrollingToBottom(false);
|
2017-12-28 00:48:21 +01:00
|
|
|
|
2018-04-18 17:51:53 +02:00
|
|
|
auto *layout = new QVBoxLayout(this);
|
|
|
|
this->getLayoutContainer()->setLayout(layout);
|
2017-12-19 03:18:00 +01:00
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
Notebook *notebook = new Notebook(this);
|
2018-04-18 17:51:53 +02:00
|
|
|
layout->addWidget(notebook);
|
|
|
|
layout->setMargin(0);
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
notebook->addPage(this->viewEmotes_, "Emotes");
|
|
|
|
notebook->addPage(this->viewEmojis_, "Emojis");
|
2017-12-19 03:18:00 +01:00
|
|
|
|
|
|
|
this->loadEmojis();
|
2018-01-24 20:58:53 +01:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->viewEmotes_->linkClicked.connect(
|
2018-01-24 20:58:53 +01:00
|
|
|
[this](const Link &link) { this->linkClicked.invoke(link); });
|
2018-07-06 19:23:47 +02:00
|
|
|
this->viewEmojis_->linkClicked.connect(
|
2018-01-24 20:58:53 +01:00
|
|
|
[this](const Link &link) { this->linkClicked.invoke(link); });
|
2017-09-15 17:23:49 +02:00
|
|
|
}
|
|
|
|
|
2018-01-24 13:15:41 +01:00
|
|
|
void EmotePopup::loadChannel(ChannelPtr _channel)
|
2017-09-15 17:23:49 +02:00
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
this->setWindowTitle("Emotes from " + _channel->getName());
|
2018-04-18 18:55:49 +02:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
TwitchChannel *channel = dynamic_cast<TwitchChannel *>(_channel.get());
|
|
|
|
|
|
|
|
if (channel == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:30:12 +02:00
|
|
|
ChannelPtr emoteChannel(new Channel("", Channel::Type::None));
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
auto addEmotes = [&](const EmoteMap &map, const QString &title,
|
|
|
|
const QString &emoteDesc) {
|
2017-09-16 00:05:06 +02:00
|
|
|
// TITLE
|
2018-06-28 19:38:57 +02:00
|
|
|
MessageBuilder builder1;
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
builder1.emplace<TextElement>(title, MessageElementFlag::Text);
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
builder1->flags.set(MessageFlag::Centered);
|
2018-08-07 01:35:24 +02:00
|
|
|
emoteChannel->addMessage(builder1.release());
|
2017-09-16 00:05:06 +02:00
|
|
|
|
|
|
|
// EMOTES
|
2018-06-28 19:38:57 +02:00
|
|
|
MessageBuilder builder2;
|
2018-08-07 07:55:31 +02:00
|
|
|
builder2->flags.set(MessageFlag::Centered);
|
|
|
|
builder2->flags.set(MessageFlag::DisableCompactEmotes);
|
2018-01-07 02:56:45 +01:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
for (auto emote : map) {
|
2018-08-07 01:35:24 +02:00
|
|
|
builder2
|
|
|
|
.emplace<EmoteElement>(emote.second,
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElementFlag::AlwaysShow)
|
2018-08-07 01:35:24 +02:00
|
|
|
->setLink(Link(Link::InsertText, emote.first.string));
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
emoteChannel->addMessage(builder2.release());
|
2017-09-16 00:05:06 +02:00
|
|
|
};
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2017-12-17 02:18:13 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
// fourtf: the entire emote manager needs to be refactored so there's no
|
|
|
|
// point in trying to fix this pile of garbage
|
|
|
|
for (const auto &set :
|
|
|
|
app->accounts->twitch.getCurrent()->accessEmotes()->emoteSets) {
|
2018-05-31 16:20:46 +02:00
|
|
|
// TITLE
|
2018-06-28 19:38:57 +02:00
|
|
|
MessageBuilder builder1;
|
2018-05-31 16:20:46 +02:00
|
|
|
|
2018-06-24 14:42:40 +02:00
|
|
|
QString setText;
|
|
|
|
if (set->text.isEmpty()) {
|
|
|
|
if (set->channelName.isEmpty()) {
|
|
|
|
setText = "Twitch Account Emotes";
|
|
|
|
} else {
|
|
|
|
setText = "Twitch Account Emotes (" + set->channelName + ")";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setText = set->text;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
builder1.emplace<TextElement>(setText, MessageElementFlag::Text);
|
2018-05-31 16:20:46 +02:00
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
builder1->flags.set(MessageFlag::Centered);
|
2018-08-07 01:35:24 +02:00
|
|
|
emoteChannel->addMessage(builder1.release());
|
2018-05-31 16:20:46 +02:00
|
|
|
|
|
|
|
// EMOTES
|
2018-06-28 19:38:57 +02:00
|
|
|
MessageBuilder builder2;
|
2018-08-07 07:55:31 +02:00
|
|
|
builder2->flags.set(MessageFlag::Centered);
|
|
|
|
builder2->flags.set(MessageFlag::DisableCompactEmotes);
|
2018-05-31 16:20:46 +02:00
|
|
|
|
2018-06-24 14:42:40 +02:00
|
|
|
for (const auto &emote : set->emotes) {
|
2018-08-07 01:35:24 +02:00
|
|
|
builder2
|
|
|
|
.emplace<EmoteElement>(
|
|
|
|
app->emotes->twitch.getOrCreateEmote(emote.id, emote.name),
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElementFlag::AlwaysShow)
|
2018-08-07 01:35:24 +02:00
|
|
|
->setLink(Link(Link::InsertText, emote.name.string));
|
2018-05-31 16:20:46 +02:00
|
|
|
}
|
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
emoteChannel->addMessage(builder2.release());
|
2018-05-31 16:20:46 +02:00
|
|
|
}
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
addEmotes(*app->emotes->bttv.accessGlobalEmotes(),
|
|
|
|
"BetterTTV Global Emotes", "BetterTTV Global Emote");
|
|
|
|
addEmotes(*channel->accessBttvEmotes(), "BetterTTV Channel Emotes",
|
|
|
|
"BetterTTV Channel Emote");
|
|
|
|
// addEmotes(*app->emotes->ffz.accessGlobalEmotes(), "FrankerFaceZ Global
|
|
|
|
// Emotes",
|
2018-08-02 14:23:27 +02:00
|
|
|
// "FrankerFaceZ Global Emote");
|
|
|
|
addEmotes(*channel->accessFfzEmotes(), "FrankerFaceZ Channel Emotes",
|
|
|
|
"FrankerFaceZ Channel Emote");
|
2017-09-15 17:23:49 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->viewEmotes_->setChannel(emoteChannel);
|
2017-12-19 03:18:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmotePopup::loadEmojis()
|
|
|
|
{
|
2018-06-05 18:53:49 +02:00
|
|
|
auto &emojis = getApp()->emotes->emojis.emojis;
|
2017-12-19 03:18:00 +01:00
|
|
|
|
2018-07-06 17:30:12 +02:00
|
|
|
ChannelPtr emojiChannel(new Channel("", Channel::Type::None));
|
2017-12-19 03:18:00 +01:00
|
|
|
|
|
|
|
// title
|
2018-06-28 19:38:57 +02:00
|
|
|
MessageBuilder builder1;
|
2017-12-19 03:18:00 +01:00
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
builder1.emplace<TextElement>("emojis", MessageElementFlag::Text);
|
|
|
|
builder1->flags.set(MessageFlag::Centered);
|
2018-08-07 01:35:24 +02:00
|
|
|
emojiChannel->addMessage(builder1.release());
|
2017-12-19 03:18:00 +01:00
|
|
|
|
|
|
|
// emojis
|
2018-06-28 19:38:57 +02:00
|
|
|
MessageBuilder builder;
|
2018-08-07 07:55:31 +02:00
|
|
|
builder->flags.set(MessageFlag::Centered);
|
|
|
|
builder->flags.set(MessageFlag::DisableCompactEmotes);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
emojis.each([&builder](const auto &key, const auto &value) {
|
2018-08-07 01:35:24 +02:00
|
|
|
builder
|
2018-08-07 07:55:31 +02:00
|
|
|
.emplace<EmoteElement>(value->emote, MessageElementFlag::AlwaysShow)
|
2018-08-07 01:35:24 +02:00
|
|
|
->setLink(
|
|
|
|
Link(Link::Type::InsertText, ":" + value->shortCodes[0] + ":"));
|
2018-01-11 20:16:25 +01:00
|
|
|
});
|
2018-08-07 01:35:24 +02:00
|
|
|
emojiChannel->addMessage(builder.release());
|
2017-09-16 16:20:10 +02:00
|
|
|
|
2018-07-06 19:23:47 +02: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 chatterino
|