mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
added emote loading
This commit is contained in:
parent
0fbc40a52a
commit
4dbe2b0254
Binary file not shown.
|
@ -9,11 +9,11 @@ Channel Channel::mentions(QString("/mentions"));
|
|||
QMap<QString, Channel *> Channel::channels = QMap<QString, Channel *>();
|
||||
|
||||
Channel::Channel(QString channel)
|
||||
: m_name((channel.length() > 0 && channel[0] == '#') ? channel.mid(1)
|
||||
: m_messages()
|
||||
, m_name((channel.length() > 0 && channel[0] == '#') ? channel.mid(1)
|
||||
: channel)
|
||||
, m_bttvChannelEmotes()
|
||||
, m_ffzChannelEmotes()
|
||||
, m_messages()
|
||||
, m_messageMutex()
|
||||
, m_subLink("https://www.twitch.tv/" + m_name +
|
||||
"/subscribe?ref=in_chat_subscriber_link")
|
||||
|
|
|
@ -104,10 +104,6 @@ public:
|
|||
private:
|
||||
Channel(QString channel);
|
||||
|
||||
ConcurrentMap<QString, LazyLoadedImage *> m_bttvChannelEmotes;
|
||||
ConcurrentMap<QString, LazyLoadedImage *> m_ffzChannelEmotes;
|
||||
QMutex m_messageMutex;
|
||||
|
||||
int m_referenceCount = 0;
|
||||
|
||||
QVector<std::shared_ptr<Message>> m_messages;
|
||||
|
@ -115,6 +111,10 @@ private:
|
|||
QString m_name;
|
||||
int m_roomID;
|
||||
|
||||
ConcurrentMap<QString, LazyLoadedImage *> m_bttvChannelEmotes;
|
||||
ConcurrentMap<QString, LazyLoadedImage *> m_ffzChannelEmotes;
|
||||
QMutex m_messageMutex;
|
||||
|
||||
QString m_subLink;
|
||||
QString m_channelLink;
|
||||
QString m_popoutPlayerLink;
|
||||
|
|
|
@ -8,6 +8,9 @@ QT += core gui network
|
|||
CONFIG += communi
|
||||
COMMUNI += core model util
|
||||
|
||||
win32:LIBS += -LC:/OpenSSL-Win32/lib/openssl.lib
|
||||
INCLUDEPATH += C:/OpenSSL-Win32/include
|
||||
|
||||
include(lib/libcommuni/src/src.pri)
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
@ -28,7 +31,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
|||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp \
|
||||
mainwindow.cpp \
|
||||
chatwidget.cpp \
|
||||
notebook.cpp \
|
||||
notebooktab.cpp \
|
||||
|
@ -57,7 +60,8 @@ SOURCES += main.cpp\
|
|||
fonts.cpp \
|
||||
appsettings.cpp \
|
||||
emojis.cpp \
|
||||
wordpart.cpp
|
||||
wordpart.cpp \
|
||||
resources.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
chatwidget.h \
|
||||
|
@ -91,7 +95,8 @@ HEADERS += mainwindow.h \
|
|||
appsettings.h \
|
||||
emojis.h \
|
||||
wordpart.h \
|
||||
common.h
|
||||
common.h \
|
||||
resources.h
|
||||
|
||||
PRECOMPILED_HEADER =
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@ ChatWidgetView::resizeEvent(QResizeEvent *)
|
|||
auto messages = c->getMessagesClone();
|
||||
|
||||
for (std::shared_ptr<Message> &message : messages) {
|
||||
message.get()->layout(width(), true);
|
||||
qInfo(QString::number(width()).toStdString().c_str());
|
||||
message.get()->layout(this->width(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,18 +49,22 @@ ChatWidgetView::paintEvent(QPaintEvent *)
|
|||
|
||||
auto messages = c->getMessagesClone();
|
||||
|
||||
int y = 0;
|
||||
int y = 32;
|
||||
|
||||
for (std::shared_ptr<Message> const &message : messages) {
|
||||
for (WordPart const &wordPart : message.get()->wordParts()) {
|
||||
painter.setPen(QColor(255, 0, 0));
|
||||
painter.drawRect(wordPart.x(), wordPart.y() + y, wordPart.width(),
|
||||
wordPart.height());
|
||||
|
||||
// image
|
||||
if (wordPart.word().isImage()) {
|
||||
LazyLoadedImage &lli = wordPart.word().getImage();
|
||||
|
||||
const QImage *image = lli.image();
|
||||
const QPixmap *image = lli.pixmap();
|
||||
|
||||
if (image != NULL) {
|
||||
painter.drawImage(
|
||||
painter.drawPixmap(
|
||||
QRect(wordPart.x(), wordPart.y() + y, wordPart.width(),
|
||||
wordPart.height()),
|
||||
*image);
|
||||
|
@ -70,8 +75,10 @@ ChatWidgetView::paintEvent(QPaintEvent *)
|
|||
painter.setPen(wordPart.word().color());
|
||||
painter.setFont(wordPart.word().getFont());
|
||||
|
||||
painter.drawText(wordPart.x(), wordPart.y() + y,
|
||||
wordPart.getText());
|
||||
painter.drawText(
|
||||
QRectF(wordPart.x(), wordPart.y() + y, 10000, 10000),
|
||||
wordPart.getText(),
|
||||
QTextOption(Qt::AlignLeft | Qt::AlignTop));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ Emojis::parseEmojis(std::vector<std::tuple<LazyLoadedImage *, QString>> &vector,
|
|||
}
|
||||
|
||||
void
|
||||
Emojis::initEmojis()
|
||||
Emojis::loadEmojis()
|
||||
{
|
||||
QFile file(":/emojidata.txt");
|
||||
file.open(QFile::ReadOnly);
|
||||
|
|
2
emojis.h
2
emojis.h
|
@ -16,7 +16,7 @@ public:
|
|||
std::vector<std::tuple<LazyLoadedImage *, QString>> &vector,
|
||||
const QString &text);
|
||||
|
||||
static void initEmojis();
|
||||
static void loadEmojis();
|
||||
|
||||
static QString replaceShortCodes(const QString &text);
|
||||
|
||||
|
|
70
emotes.cpp
70
emotes.cpp
|
@ -1,35 +1,17 @@
|
|||
#include "emotes.h"
|
||||
#include "resources.h"
|
||||
|
||||
ConcurrentMap<QString, TwitchEmoteValue *> *Emotes::m_twitchEmotes =
|
||||
new ConcurrentMap<QString, TwitchEmoteValue *>();
|
||||
ConcurrentMap<QString, LazyLoadedImage *> *Emotes::m_bttvEmotes =
|
||||
new ConcurrentMap<QString, LazyLoadedImage *>();
|
||||
ConcurrentMap<QString, LazyLoadedImage *> *Emotes::m_ffzEmotes =
|
||||
new ConcurrentMap<QString, LazyLoadedImage *>();
|
||||
ConcurrentMap<QString, LazyLoadedImage *> *Emotes::m_chatterinoEmotes =
|
||||
new ConcurrentMap<QString, LazyLoadedImage *>();
|
||||
ConcurrentMap<QString, LazyLoadedImage *>
|
||||
*Emotes::m_bttvChannelEmoteFromCaches =
|
||||
new ConcurrentMap<QString, LazyLoadedImage *>();
|
||||
ConcurrentMap<QString, LazyLoadedImage *> *Emotes::m_ffzChannelEmoteFromCaches =
|
||||
new ConcurrentMap<QString, LazyLoadedImage *>();
|
||||
ConcurrentMap<int, LazyLoadedImage *> *Emotes::m_twitchEmoteFromCache =
|
||||
new ConcurrentMap<int, LazyLoadedImage *>();
|
||||
ConcurrentMap<QString, LazyLoadedImage *> *Emotes::m_miscImageFromCache =
|
||||
new ConcurrentMap<QString, LazyLoadedImage *>();
|
||||
QString Emotes::m_twitchEmoteTemplate(
|
||||
"http://static-cdn.jtvnw.net/emoticons/v1/{id}/{scale}.0");
|
||||
|
||||
LazyLoadedImage *Emotes::m_cheerBadge100000 =
|
||||
new LazyLoadedImage(new QImage(":/cheer100000"));
|
||||
LazyLoadedImage *Emotes::m_cheerBadge10000 =
|
||||
new LazyLoadedImage(new QImage(":/cheer10000"));
|
||||
LazyLoadedImage *Emotes::m_cheerBadge5000 =
|
||||
new LazyLoadedImage(new QImage(":/cheer5000"));
|
||||
LazyLoadedImage *Emotes::m_cheerBadge1000 =
|
||||
new LazyLoadedImage(new QImage(":/cheer1000"));
|
||||
LazyLoadedImage *Emotes::m_cheerBadge100 =
|
||||
new LazyLoadedImage(new QImage(":/cheer100"));
|
||||
LazyLoadedImage *Emotes::m_cheerBadge1 =
|
||||
new LazyLoadedImage(new QImage(":/cheer1"));
|
||||
ConcurrentMap<QString, TwitchEmoteValue *> Emotes::m_twitchEmotes;
|
||||
ConcurrentMap<QString, LazyLoadedImage *> Emotes::m_bttvEmotes;
|
||||
ConcurrentMap<QString, LazyLoadedImage *> Emotes::m_ffzEmotes;
|
||||
ConcurrentMap<QString, LazyLoadedImage *> Emotes::m_chatterinoEmotes;
|
||||
ConcurrentMap<QString, LazyLoadedImage *> Emotes::m_bttvChannelEmoteFromCaches;
|
||||
ConcurrentMap<QString, LazyLoadedImage *> Emotes::m_ffzChannelEmoteFromCaches;
|
||||
ConcurrentMap<long, LazyLoadedImage *> Emotes::m_twitchEmoteFromCache;
|
||||
ConcurrentMap<QString, LazyLoadedImage *> Emotes::m_miscImageFromCache;
|
||||
|
||||
Emotes::Emotes()
|
||||
{
|
||||
|
@ -38,9 +20,21 @@ Emotes::Emotes()
|
|||
LazyLoadedImage *
|
||||
Emotes::getTwitchEmoteById(const QString &name, long id)
|
||||
{
|
||||
#pragma message WARN("xD")
|
||||
return new LazyLoadedImage(NULL);
|
||||
// return m_twitchEmoteFromCache->getOrAdd()
|
||||
return m_twitchEmoteFromCache.getOrAdd(id, [&name, id] {
|
||||
qreal scale;
|
||||
QString url = getTwitchEmoteLink(id, scale);
|
||||
|
||||
return new LazyLoadedImage(url, scale, name, name + "\nTwitch Emote");
|
||||
});
|
||||
}
|
||||
|
||||
QString
|
||||
Emotes::getTwitchEmoteLink(long id, qreal &scale)
|
||||
{
|
||||
scale = .5;
|
||||
|
||||
return m_twitchEmoteTemplate.replace("{id}", QString::number(id))
|
||||
.replace("{scale}", "2");
|
||||
}
|
||||
|
||||
LazyLoadedImage *
|
||||
|
@ -54,16 +48,16 @@ LazyLoadedImage *
|
|||
Emotes::getCheerBadge(long long amount)
|
||||
{
|
||||
if (amount >= 100000) {
|
||||
return m_cheerBadge100000;
|
||||
return Resources::cheerBadge100000();
|
||||
} else if (amount >= 10000) {
|
||||
return m_cheerBadge10000;
|
||||
return Resources::cheerBadge10000();
|
||||
} else if (amount >= 5000) {
|
||||
return m_cheerBadge5000;
|
||||
return Resources::cheerBadge5000();
|
||||
} else if (amount >= 1000) {
|
||||
return m_cheerBadge1000;
|
||||
return Resources::cheerBadge1000();
|
||||
} else if (amount >= 100) {
|
||||
return m_cheerBadge100;
|
||||
return Resources::cheerBadge100();
|
||||
} else {
|
||||
return m_cheerBadge1;
|
||||
return Resources::cheerBadge1();
|
||||
}
|
||||
}
|
||||
|
|
54
emotes.h
54
emotes.h
|
@ -13,42 +13,49 @@ public:
|
|||
static ConcurrentMap<QString, TwitchEmoteValue *> &
|
||||
twitchEmotes()
|
||||
{
|
||||
return *m_twitchEmotes;
|
||||
return m_twitchEmotes;
|
||||
}
|
||||
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> &
|
||||
bttvEmotes()
|
||||
{
|
||||
return *m_bttvEmotes;
|
||||
return m_bttvEmotes;
|
||||
}
|
||||
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> &
|
||||
ffzEmotes()
|
||||
{
|
||||
return *m_ffzEmotes;
|
||||
return m_ffzEmotes;
|
||||
}
|
||||
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> &
|
||||
chatterinoEmotes()
|
||||
{
|
||||
return *m_chatterinoEmotes;
|
||||
return m_chatterinoEmotes;
|
||||
}
|
||||
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> &
|
||||
bttvChannelEmoteFromCaches()
|
||||
{
|
||||
return *m_bttvChannelEmoteFromCaches;
|
||||
return m_bttvChannelEmoteFromCaches;
|
||||
}
|
||||
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> &
|
||||
ffzChannelEmoteFromCaches()
|
||||
{
|
||||
return *m_ffzChannelEmoteFromCaches;
|
||||
return m_ffzChannelEmoteFromCaches;
|
||||
}
|
||||
static ConcurrentMap<int, LazyLoadedImage *> &
|
||||
|
||||
static ConcurrentMap<long, LazyLoadedImage *> &
|
||||
twitchEmoteFromCache()
|
||||
{
|
||||
return *m_twitchEmoteFromCache;
|
||||
return m_twitchEmoteFromCache;
|
||||
}
|
||||
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> &
|
||||
miscImageFromCache()
|
||||
{
|
||||
return *m_miscImageFromCache;
|
||||
return m_miscImageFromCache;
|
||||
}
|
||||
|
||||
static void loadGlobalEmotes();
|
||||
|
@ -62,23 +69,20 @@ public:
|
|||
private:
|
||||
Emotes();
|
||||
|
||||
static ConcurrentMap<QString, TwitchEmoteValue *> *m_twitchEmotes;
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> *m_bttvEmotes;
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> *m_ffzEmotes;
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> *m_chatterinoEmotes;
|
||||
static ConcurrentMap<QString, LazyLoadedImage *>
|
||||
*m_bttvChannelEmoteFromCaches;
|
||||
static ConcurrentMap<QString, LazyLoadedImage *>
|
||||
*m_ffzChannelEmoteFromCaches;
|
||||
static ConcurrentMap<int, LazyLoadedImage *> *m_twitchEmoteFromCache;
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> *m_miscImageFromCache;
|
||||
static QString m_twitchEmoteTemplate;
|
||||
|
||||
static LazyLoadedImage *m_cheerBadge100000;
|
||||
static LazyLoadedImage *m_cheerBadge10000;
|
||||
static LazyLoadedImage *m_cheerBadge5000;
|
||||
static LazyLoadedImage *m_cheerBadge1000;
|
||||
static LazyLoadedImage *m_cheerBadge100;
|
||||
static LazyLoadedImage *m_cheerBadge1;
|
||||
static ConcurrentMap<QString, TwitchEmoteValue *> m_twitchEmotes;
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> m_bttvEmotes;
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> m_ffzEmotes;
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> m_chatterinoEmotes;
|
||||
static ConcurrentMap<QString, LazyLoadedImage *>
|
||||
m_bttvChannelEmoteFromCaches;
|
||||
static ConcurrentMap<QString, LazyLoadedImage *>
|
||||
m_ffzChannelEmoteFromCaches;
|
||||
static ConcurrentMap<long, LazyLoadedImage *> m_twitchEmoteFromCache;
|
||||
static ConcurrentMap<QString, LazyLoadedImage *> m_miscImageFromCache;
|
||||
|
||||
static QString getTwitchEmoteLink(long id, qreal &scale);
|
||||
};
|
||||
|
||||
#endif // EMOTES_H
|
||||
|
|
|
@ -121,6 +121,7 @@ IrcManager::beginConnecting()
|
|||
c->setRealName("justinfan123");
|
||||
c->sendRaw("JOIN #fourtf");
|
||||
c->sendRaw("JOIN #ian678");
|
||||
c->sendRaw("JOIN #nuuls");
|
||||
|
||||
c->sendCommand(IrcCommand::createCapability("REQ", "twitch.tv/commands"));
|
||||
c->sendCommand(IrcCommand::createCapability("REQ", "twitch.tv/tags"));
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
LazyLoadedImage::LazyLoadedImage(const QString &url, qreal scale,
|
||||
const QString &name, const QString &tooltip,
|
||||
const QMargins &margin, bool isHat)
|
||||
: m_image(NULL)
|
||||
: m_pixmap(NULL)
|
||||
, m_url(url)
|
||||
, m_name(name)
|
||||
, m_tooltip(tooltip)
|
||||
|
@ -23,16 +23,17 @@ LazyLoadedImage::LazyLoadedImage(const QString &url, qreal scale,
|
|||
{
|
||||
}
|
||||
|
||||
LazyLoadedImage::LazyLoadedImage(QImage *image, qreal scale,
|
||||
LazyLoadedImage::LazyLoadedImage(QPixmap *image, qreal scale,
|
||||
const QString &name, const QString &tooltip,
|
||||
const QMargins &margin, bool isHat)
|
||||
: m_name(name)
|
||||
: m_pixmap(image)
|
||||
, m_url()
|
||||
, m_name(name)
|
||||
, m_tooltip(tooltip)
|
||||
, m_animated(false)
|
||||
, m_margin(margin)
|
||||
, m_ishat(isHat)
|
||||
, m_scale(scale)
|
||||
, m_image(image)
|
||||
, m_isLoading(true)
|
||||
{
|
||||
}
|
||||
|
@ -40,13 +41,21 @@ LazyLoadedImage::LazyLoadedImage(QImage *image, qreal scale,
|
|||
void
|
||||
LazyLoadedImage::loadImage()
|
||||
{
|
||||
QString url = m_url;
|
||||
// QThreadPool::globalInstance()->start(new LambdaQRunnable([=] {
|
||||
QUrl url(m_url);
|
||||
QNetworkRequest request(url);
|
||||
|
||||
async_exec([url] {
|
||||
QNetworkRequest req(QUrl(url));
|
||||
QNetworkReply *reply = IrcManager::accessManager().get(request);
|
||||
|
||||
QNetworkReply *reply = IrcManager::accessManager().get(req);
|
||||
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
||||
QPixmap *pixmap = new QPixmap();
|
||||
pixmap->loadFromData(reply->readAll());
|
||||
|
||||
QObject::connect(reply, &QNetworkReply::finished, [=] {});
|
||||
})
|
||||
if (pixmap->isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_pixmap = pixmap;
|
||||
});
|
||||
//}));
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef LAZYLOADEDIMAGE_H
|
||||
#define LAZYLOADEDIMAGE_H
|
||||
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
|
||||
class LazyLoadedImage
|
||||
|
@ -10,19 +10,19 @@ public:
|
|||
LazyLoadedImage(const QString &url, qreal scale = 1,
|
||||
const QString &name = "", const QString &tooltip = "",
|
||||
const QMargins &margin = QMargins(), bool isHat = false);
|
||||
LazyLoadedImage(QImage *image, qreal scale = 1, const QString &name = "",
|
||||
LazyLoadedImage(QPixmap *pixmap, qreal scale = 1, const QString &name = "",
|
||||
const QString &tooltip = "",
|
||||
const QMargins &margin = QMargins(), bool isHat = false);
|
||||
|
||||
const QImage *
|
||||
image()
|
||||
const QPixmap *
|
||||
pixmap()
|
||||
{
|
||||
if (!m_isLoading) {
|
||||
m_isLoading = true;
|
||||
|
||||
loadImage();
|
||||
}
|
||||
return m_image;
|
||||
return m_pixmap;
|
||||
}
|
||||
|
||||
qreal
|
||||
|
@ -67,27 +67,26 @@ public:
|
|||
return m_ishat;
|
||||
}
|
||||
|
||||
const long
|
||||
int
|
||||
width() const
|
||||
{
|
||||
if (m_image == NULL) {
|
||||
if (m_pixmap == NULL) {
|
||||
return 16;
|
||||
}
|
||||
return m_image->width();
|
||||
return m_pixmap->width();
|
||||
}
|
||||
|
||||
const long
|
||||
int
|
||||
height() const
|
||||
{
|
||||
if (m_image == NULL) {
|
||||
if (m_pixmap == NULL) {
|
||||
return 16;
|
||||
}
|
||||
return m_image->height();
|
||||
return m_pixmap->height();
|
||||
}
|
||||
|
||||
private:
|
||||
QImage *m_image;
|
||||
qreal m_scale;
|
||||
QPixmap *m_pixmap;
|
||||
|
||||
QString m_url;
|
||||
QString m_name;
|
||||
|
@ -95,6 +94,7 @@ private:
|
|||
bool m_animated;
|
||||
QMargins m_margin;
|
||||
bool m_ishat;
|
||||
qreal m_scale;
|
||||
|
||||
bool m_isLoading;
|
||||
|
||||
|
|
11
main.cpp
11
main.cpp
|
@ -1,16 +1,19 @@
|
|||
#include "mainwindow.h"
|
||||
#include "colorscheme.h"
|
||||
#include "ircmanager.h"
|
||||
#include "emojis.h"
|
||||
#include "ircmanager.h"
|
||||
#include "mainwindow.h"
|
||||
#include "resources.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
Emojis::initEmojis();
|
||||
Resources::load();
|
||||
Emojis::loadEmojis();
|
||||
|
||||
ColorScheme::instance().setColors(0, -0.8);
|
||||
|
||||
|
|
174
message.cpp
174
message.cpp
|
@ -7,6 +7,7 @@
|
|||
#include "ircmanager.h"
|
||||
#include "link.h"
|
||||
#include "qcolor.h"
|
||||
#include "resources.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <ctime>
|
||||
|
@ -18,21 +19,6 @@
|
|||
#define MARGIN_TOP 8
|
||||
#define MARGIN_BOTTOM 8
|
||||
|
||||
LazyLoadedImage *Message::badgeStaff =
|
||||
new LazyLoadedImage(new QImage(":/images/staff_bg.png"));
|
||||
LazyLoadedImage *Message::badgeAdmin =
|
||||
new LazyLoadedImage(new QImage(":/images/admin_bg.png"));
|
||||
LazyLoadedImage *Message::badgeModerator =
|
||||
new LazyLoadedImage(new QImage(":/images/moderator_bg.png"));
|
||||
LazyLoadedImage *Message::badgeGlobalmod =
|
||||
new LazyLoadedImage(new QImage(":/images/globalmod_bg.png"));
|
||||
LazyLoadedImage *Message::badgeTurbo =
|
||||
new LazyLoadedImage(new QImage(":/images/turbo_bg.png"));
|
||||
LazyLoadedImage *Message::badgeBroadcaster =
|
||||
new LazyLoadedImage(new QImage(":/images/broadcaster_bg.png"));
|
||||
LazyLoadedImage *Message::badgePremium =
|
||||
new LazyLoadedImage(new QImage(":/images/twitchprime_bg.png"));
|
||||
|
||||
QRegularExpression *Message::cheerRegex =
|
||||
new QRegularExpression("cheer[1-9][0-9]*");
|
||||
|
||||
|
@ -60,12 +46,14 @@ Message::Message(const IrcPrivateMessage &ircMessage, const Channel &channel,
|
|||
|
||||
// timestamps
|
||||
iterator = tags.find("tmi-sent-ts");
|
||||
|
||||
std::time_t time = std::time(NULL);
|
||||
|
||||
if (iterator != tags.end()) {
|
||||
time = strtoll(iterator.value().toString().toStdString().c_str(), NULL,
|
||||
10);
|
||||
}
|
||||
// if (iterator != tags.end()) {
|
||||
// time = strtoll(iterator.value().toString().toStdString().c_str(),
|
||||
// NULL,
|
||||
// 10);
|
||||
// }
|
||||
|
||||
char timeStampBuffer[69];
|
||||
|
||||
|
@ -96,29 +84,31 @@ Message::Message(const IrcPrivateMessage &ircMessage, const Channel &channel,
|
|||
Emotes::getCheerBadge(cheer), Word::BadgeCheer, QString(),
|
||||
QString("Twitch Cheer" + QString::number(cheer))));
|
||||
} else if (badge == "staff/1") {
|
||||
words.push_back(Word(badgeStaff, Word::BadgeStaff, QString(),
|
||||
QString("Twitch Staff")));
|
||||
words.push_back(Word(Resources::badgeStaff(), Word::BadgeStaff,
|
||||
QString(), QString("Twitch Staff")));
|
||||
} else if (badge == "admin/1") {
|
||||
words.push_back(Word(badgeAdmin, Word::BadgeAdmin, QString(),
|
||||
QString("Twitch Admin")));
|
||||
words.push_back(Word(Resources::badgeAdmin(), Word::BadgeAdmin,
|
||||
QString(), QString("Twitch Admin")));
|
||||
} else if (badge == "global_mod/1") {
|
||||
words.push_back(Word(badgeGlobalmod, Word::BadgeGlobalMod,
|
||||
QString(), QString("Global Moderator")));
|
||||
words.push_back(Word(Resources::badgeGlobalmod(),
|
||||
Word::BadgeGlobalMod, QString(),
|
||||
QString("Global Moderator")));
|
||||
} else if (badge == "moderator/1") {
|
||||
#pragma message WARN("xD")
|
||||
words.push_back(
|
||||
Word(badgeTurbo, Word::BadgeModerator, QString(),
|
||||
QString("Channel Moderator"))); // custom badge
|
||||
words.push_back(Word(
|
||||
Resources::badgeTurbo(), Word::BadgeModerator, QString(),
|
||||
QString("Channel Moderator"))); // custom badge
|
||||
} else if (badge == "turbo/1") {
|
||||
words.push_back(Word(badgeStaff, Word::BadgeTurbo, QString(),
|
||||
QString("Turbo Subscriber")));
|
||||
words.push_back(Word(Resources::badgeStaff(), Word::BadgeTurbo,
|
||||
QString(), QString("Turbo Subscriber")));
|
||||
} else if (badge == "broadcaster/1") {
|
||||
words.push_back(Word(badgeBroadcaster, Word::BadgeBroadcaster,
|
||||
QString(),
|
||||
words.push_back(Word(Resources::badgeBroadcaster(),
|
||||
Word::BadgeBroadcaster, QString(),
|
||||
QString("Channel Broadcaster")));
|
||||
} else if (badge == "premium/1") {
|
||||
words.push_back(Word(badgePremium, Word::BadgePremium,
|
||||
QString(), QString("Twitch Prime")));
|
||||
words.push_back(Word(Resources::badgePremium(),
|
||||
Word::BadgePremium, QString(),
|
||||
QString("Twitch Prime")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -390,14 +380,13 @@ Message::Message(const IrcPrivateMessage &ircMessage, const Channel &channel,
|
|||
// }
|
||||
}
|
||||
|
||||
// static void normalize
|
||||
|
||||
bool
|
||||
Message::layout(int width, bool enableEmoteMargins)
|
||||
{
|
||||
width = width - (width % 2);
|
||||
|
||||
int mediumTextLineHeight = Fonts::getFontMetrics(Fonts::Medium).height();
|
||||
int spaceWidth = 4;
|
||||
|
||||
bool redraw = width != m_currentLayoutWidth || m_relayoutRequested;
|
||||
|
||||
|
@ -436,56 +425,103 @@ Message::layout(int width, bool enableEmoteMargins)
|
|||
m_recalculateText = false;
|
||||
}
|
||||
|
||||
if (redraw) {
|
||||
int x = MARGIN_LEFT;
|
||||
int y = MARGIN_TOP;
|
||||
if (!redraw) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int right = width - MARGIN_RIGHT;
|
||||
int x = MARGIN_LEFT;
|
||||
int y = MARGIN_TOP;
|
||||
|
||||
std::list<WordPart> *parts = new std::list<WordPart>();
|
||||
int right = width - MARGIN_RIGHT - MARGIN_LEFT;
|
||||
|
||||
auto lineStart = m_wordParts->begin();
|
||||
int lineHeight = 0;
|
||||
std::list<WordPart> *parts = new std::list<WordPart>();
|
||||
|
||||
for (auto it = m_words.begin(); it != m_words.end(); ++it) {
|
||||
Word &word = *it;
|
||||
auto lineStart = parts->begin();
|
||||
int lineHeight = 0;
|
||||
|
||||
int xOffset = 0, yOffset = 0;
|
||||
auto alignParts = [&lineStart, &lineHeight, &parts, this] {
|
||||
for (auto it2 = lineStart; true; it2++) {
|
||||
WordPart &wordPart2 = *it2;
|
||||
|
||||
if (enableEmoteMargins) {
|
||||
if (word.isImage() && word.getImage().isHat()) {
|
||||
xOffset = -word.width() + 2;
|
||||
} else {
|
||||
xOffset = word.xOffset();
|
||||
yOffset = word.yOffset();
|
||||
}
|
||||
wordPart2.setY(wordPart2.y() + lineHeight);
|
||||
|
||||
lineHeight = std::max(word.height(), lineHeight);
|
||||
if (it2 == parts->end()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (x + word.width() + xOffset <= right) {
|
||||
parts->push_back(WordPart(word, x, y, word.copyText()));
|
||||
x += word.width() + xOffset;
|
||||
}
|
||||
// else if (word.isText() && word.getText().length() > 2)
|
||||
// {
|
||||
int flags = AppSettings::wordTypeMask();
|
||||
|
||||
// }
|
||||
else {
|
||||
parts->push_back(WordPart(word, x, y, word.copyText()));
|
||||
for (auto it = m_words.begin(); it != m_words.end(); ++it) {
|
||||
Word &word = *it;
|
||||
|
||||
lineHeight = std::max(word.height(), lineHeight);
|
||||
if ((word.type() & flags) == Word::None) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int xOffset = 0, yOffset = 0;
|
||||
|
||||
if (enableEmoteMargins) {
|
||||
if (word.isImage() && word.getImage().isHat()) {
|
||||
xOffset = -word.width() + 2;
|
||||
} else {
|
||||
xOffset = word.xOffset();
|
||||
yOffset = word.yOffset();
|
||||
}
|
||||
}
|
||||
|
||||
auto tmp = m_wordParts;
|
||||
m_wordParts = parts;
|
||||
delete tmp;
|
||||
// fits in the line
|
||||
if (x + word.width() + xOffset <= right) {
|
||||
parts->push_back(
|
||||
WordPart(word, x, y - word.height(), word.copyText()));
|
||||
|
||||
m_height = y + lineHeight;
|
||||
x += word.width() + xOffset;
|
||||
|
||||
if (word.hasTrailingSpace()) {
|
||||
x += spaceWidth;
|
||||
}
|
||||
|
||||
lineHeight = std::max(word.height(), lineHeight);
|
||||
}
|
||||
|
||||
// else if (word.isText() && word.getText().length()
|
||||
// > 2)
|
||||
// {
|
||||
// }
|
||||
|
||||
// doesn't fit in the line
|
||||
else {
|
||||
alignParts();
|
||||
|
||||
y += lineHeight;
|
||||
|
||||
parts->push_back(WordPart(word, MARGIN_LEFT, y - word.height(),
|
||||
word.copyText()));
|
||||
|
||||
lineStart = parts->end();
|
||||
|
||||
lineHeight = word.height();
|
||||
|
||||
x = word.width();
|
||||
|
||||
if (word.hasTrailingSpace()) {
|
||||
x += spaceWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return redraw;
|
||||
alignParts();
|
||||
|
||||
qInfo("words: %d, parts: %d", m_words.size(), parts->size());
|
||||
|
||||
auto tmp = m_wordParts;
|
||||
m_wordParts = parts;
|
||||
delete tmp;
|
||||
|
||||
m_height = y + lineHeight;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
46
resources.cpp
Normal file
46
resources.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include "resources.h"
|
||||
#include "QPixmap"
|
||||
|
||||
LazyLoadedImage *Resources::m_badgeStaff;
|
||||
LazyLoadedImage *Resources::m_badgeAdmin;
|
||||
LazyLoadedImage *Resources::m_badgeModerator;
|
||||
LazyLoadedImage *Resources::m_badgeGlobalmod;
|
||||
LazyLoadedImage *Resources::m_badgeTurbo;
|
||||
LazyLoadedImage *Resources::m_badgeBroadcaster;
|
||||
LazyLoadedImage *Resources::m_badgePremium;
|
||||
|
||||
LazyLoadedImage *Resources::m_cheerBadge100000;
|
||||
LazyLoadedImage *Resources::m_cheerBadge10000;
|
||||
LazyLoadedImage *Resources::m_cheerBadge5000;
|
||||
LazyLoadedImage *Resources::m_cheerBadge1000;
|
||||
LazyLoadedImage *Resources::m_cheerBadge100;
|
||||
LazyLoadedImage *Resources::m_cheerBadge1;
|
||||
|
||||
Resources::Resources()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Resources::load()
|
||||
{
|
||||
// badges
|
||||
m_badgeStaff = new LazyLoadedImage(new QPixmap(":/images/staff_bg.png"));
|
||||
m_badgeAdmin = new LazyLoadedImage(new QPixmap(":/images/admin_bg.png"));
|
||||
m_badgeModerator =
|
||||
new LazyLoadedImage(new QPixmap(":/images/moderator_bg.png"));
|
||||
m_badgeGlobalmod =
|
||||
new LazyLoadedImage(new QPixmap(":/images/globalmod_bg.png"));
|
||||
m_badgeTurbo = new LazyLoadedImage(new QPixmap(":/images/turbo_bg.png"));
|
||||
m_badgeBroadcaster =
|
||||
new LazyLoadedImage(new QPixmap(":/images/broadcaster_bg.png"));
|
||||
m_badgePremium =
|
||||
new LazyLoadedImage(new QPixmap(":/images/twitchprime_bg.png"));
|
||||
|
||||
// cheer badges
|
||||
m_cheerBadge100000 = new LazyLoadedImage(new QPixmap(":/cheer100000"));
|
||||
m_cheerBadge10000 = new LazyLoadedImage(new QPixmap(":/cheer10000"));
|
||||
m_cheerBadge5000 = new LazyLoadedImage(new QPixmap(":/cheer5000"));
|
||||
m_cheerBadge1000 = new LazyLoadedImage(new QPixmap(":/cheer1000"));
|
||||
m_cheerBadge100 = new LazyLoadedImage(new QPixmap(":/cheer100"));
|
||||
m_cheerBadge1 = new LazyLoadedImage(new QPixmap(":/cheer1"));
|
||||
}
|
110
resources.h
Normal file
110
resources.h
Normal file
|
@ -0,0 +1,110 @@
|
|||
#ifndef RESOURCES_H
|
||||
#define RESOURCES_H
|
||||
|
||||
#include <lazyloadedimage.h>
|
||||
|
||||
class Resources
|
||||
{
|
||||
public:
|
||||
static void load();
|
||||
|
||||
// badges
|
||||
static LazyLoadedImage *
|
||||
badgeStaff()
|
||||
{
|
||||
return m_badgeStaff;
|
||||
}
|
||||
|
||||
static LazyLoadedImage *
|
||||
badgeAdmin()
|
||||
{
|
||||
return m_badgeAdmin;
|
||||
}
|
||||
|
||||
static LazyLoadedImage *
|
||||
badgeGlobalmod()
|
||||
{
|
||||
return m_badgeGlobalmod;
|
||||
}
|
||||
|
||||
static LazyLoadedImage *
|
||||
badgeModerator()
|
||||
{
|
||||
return m_badgeModerator;
|
||||
}
|
||||
|
||||
static LazyLoadedImage *
|
||||
badgeTurbo()
|
||||
{
|
||||
return m_badgeTurbo;
|
||||
}
|
||||
|
||||
static LazyLoadedImage *
|
||||
badgeBroadcaster()
|
||||
{
|
||||
return m_badgeBroadcaster;
|
||||
}
|
||||
|
||||
static LazyLoadedImage *
|
||||
badgePremium()
|
||||
{
|
||||
return m_badgePremium;
|
||||
}
|
||||
|
||||
// cheer badges
|
||||
static LazyLoadedImage *
|
||||
cheerBadge100000()
|
||||
{
|
||||
return m_cheerBadge100000;
|
||||
}
|
||||
|
||||
static LazyLoadedImage *
|
||||
cheerBadge10000()
|
||||
{
|
||||
return m_cheerBadge10000;
|
||||
}
|
||||
|
||||
static LazyLoadedImage *
|
||||
cheerBadge5000()
|
||||
{
|
||||
return m_cheerBadge5000;
|
||||
}
|
||||
|
||||
static LazyLoadedImage *
|
||||
cheerBadge1000()
|
||||
{
|
||||
return m_cheerBadge1000;
|
||||
}
|
||||
|
||||
static LazyLoadedImage *
|
||||
cheerBadge100()
|
||||
{
|
||||
return m_cheerBadge100;
|
||||
}
|
||||
|
||||
static LazyLoadedImage *
|
||||
cheerBadge1()
|
||||
{
|
||||
return m_cheerBadge1;
|
||||
}
|
||||
|
||||
private:
|
||||
Resources();
|
||||
|
||||
static LazyLoadedImage *m_badgeStaff;
|
||||
static LazyLoadedImage *m_badgeAdmin;
|
||||
static LazyLoadedImage *m_badgeGlobalmod;
|
||||
static LazyLoadedImage *m_badgeModerator;
|
||||
static LazyLoadedImage *m_badgeTurbo;
|
||||
static LazyLoadedImage *m_badgeBroadcaster;
|
||||
static LazyLoadedImage *m_badgePremium;
|
||||
|
||||
static LazyLoadedImage *m_cheerBadge100000;
|
||||
static LazyLoadedImage *m_cheerBadge10000;
|
||||
static LazyLoadedImage *m_cheerBadge5000;
|
||||
static LazyLoadedImage *m_cheerBadge1000;
|
||||
static LazyLoadedImage *m_cheerBadge100;
|
||||
static LazyLoadedImage *m_cheerBadge1;
|
||||
};
|
||||
|
||||
#endif // RESOURCES_H
|
10
word.h
10
word.h
|
@ -51,7 +51,7 @@ public:
|
|||
|
||||
Default = TimestampNoSeconds | Badges | Username | Bits |
|
||||
FfzEmoteImage | BttvEmoteImage | BttvGifEmoteImage |
|
||||
TwitchEmoteImage | BitsAmount
|
||||
TwitchEmoteImage | BitsAmount | Text
|
||||
};
|
||||
|
||||
explicit Word(LazyLoadedImage *m_image, Type type, const QString ©text,
|
||||
|
@ -180,10 +180,10 @@ private:
|
|||
QString m_copyText;
|
||||
QString m_tooltip;
|
||||
|
||||
int m_width;
|
||||
int m_height;
|
||||
int m_xOffset;
|
||||
int m_yOffset;
|
||||
int m_width = 16;
|
||||
int m_height = 16;
|
||||
int m_xOffset = 0;
|
||||
int m_yOffset = 0;
|
||||
|
||||
bool m_hasTrailingSpace;
|
||||
Fonts::Type m_font = Fonts::Medium;
|
||||
|
|
|
@ -49,6 +49,12 @@ public:
|
|||
m_y = y;
|
||||
}
|
||||
|
||||
void
|
||||
setY(int y)
|
||||
{
|
||||
m_y = y;
|
||||
}
|
||||
|
||||
int
|
||||
right() const
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue