enabled compact emtoes again

This commit is contained in:
fourtf 2018-01-28 16:29:47 +01:00
parent 3d479e4c83
commit 643486da14
7 changed files with 64 additions and 38 deletions

View file

@ -276,7 +276,6 @@ HEADERS += \
src/widgets/settingspages/ignoreuserspage.hpp \ src/widgets/settingspages/ignoreuserspage.hpp \
src/widgets/settingspages/ignoremessagespage.hpp \ src/widgets/settingspages/ignoremessagespage.hpp \
src/widgets/settingspages/specialchannelspage.hpp \ src/widgets/settingspages/specialchannelspage.hpp \
src/widgets/settingspages/keyboardsettings.hpp \
src/widgets/settingspages/keyboardsettingspage.hpp \ src/widgets/settingspages/keyboardsettingspage.hpp \
src/widgets/helper/titlebarbutton.hpp \ src/widgets/helper/titlebarbutton.hpp \
src/widgets/helper/label.hpp \ src/widgets/helper/label.hpp \

View file

@ -107,9 +107,7 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
void MessageLayout::actuallyLayout(int width, MessageElement::Flags flags) void MessageLayout::actuallyLayout(int width, MessageElement::Flags flags)
{ {
this->container.clear(); this->container.begin(width, this->scale, this->message->flags.value);
this->container.width = width;
this->container.scale = this->scale;
for (const std::unique_ptr<MessageElement> &element : this->message->getElements()) { for (const std::unique_ptr<MessageElement> &element : this->message->getElements()) {
element->addToContainer(this->container, flags); element->addToContainer(this->container, flags);
@ -138,7 +136,7 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection
(int)(this->container.getHeight() * painter.device()->devicePixelRatioF())); (int)(this->container.getHeight() * painter.device()->devicePixelRatioF()));
pixmap->setDevicePixelRatio(painter.device()->devicePixelRatioF()); pixmap->setDevicePixelRatio(painter.device()->devicePixelRatioF());
#else #else
pixmap = new QPixmap(this->container.width, std::max(16, this->container.getHeight())); pixmap = new QPixmap(this->container.getWidth(), std::max(16, this->container.getHeight()));
#endif #endif
this->buffer = std::shared_ptr<QPixmap>(pixmap); this->buffer = std::shared_ptr<QPixmap>(pixmap);
@ -168,7 +166,8 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection
QBrush brush = QBrush(color, Qt::VerPattern); QBrush brush = QBrush(color, Qt::VerPattern);
painter.fillRect(0, y + this->container.getHeight() - 1, this->container.width, 1, brush); painter.fillRect(0, y + this->container.getHeight() - 1, this->container.getWidth(), 1,
brush);
} }
this->bufferValid = true; this->bufferValid = true;

View file

@ -15,7 +15,8 @@
namespace chatterino { namespace chatterino {
namespace messages { namespace messages {
namespace layouts { namespace layouts {
struct MessageLayout : boost::noncopyable { class MessageLayout : boost::noncopyable
{
public: public:
enum Flags : uint8_t { Collapsed, RequiresBufferUpdate, RequiresLayout }; enum Flags : uint8_t { Collapsed, RequiresBufferUpdate, RequiresLayout };

View file

@ -14,8 +14,8 @@ namespace messages {
namespace layouts { namespace layouts {
MessageLayoutContainer::MessageLayoutContainer() MessageLayoutContainer::MessageLayoutContainer()
: scale(1) : scale(1)
, flags(Message::None)
, margin(4, 8, 4, 8) , margin(4, 8, 4, 8)
, centered(false)
{ {
this->clear(); this->clear();
} }
@ -25,7 +25,25 @@ int MessageLayoutContainer::getHeight() const
return this->height; return this->height;
} }
int MessageLayoutContainer::getWidth() const
{
return this->width;
}
float MessageLayoutContainer::getScale() const
{
return this->scale;
}
// methods // methods
void MessageLayoutContainer::begin(int width, float _scale, Message::MessageFlags _flags)
{
this->clear();
this->width = width;
this->scale = this->scale;
this->flags = _flags;
}
void MessageLayoutContainer::clear() void MessageLayoutContainer::clear()
{ {
this->elements.clear(); this->elements.clear();
@ -56,24 +74,31 @@ void MessageLayoutContainer::addElementNoLineBreak(MessageLayoutElement *element
void MessageLayoutContainer::_addElement(MessageLayoutElement *element) void MessageLayoutContainer::_addElement(MessageLayoutElement *element)
{ {
// top margin
if (this->elements.size() == 0) { if (this->elements.size() == 0) {
this->currentY = this->margin.top * this->scale; this->currentY = this->margin.top * this->scale;
} }
int newLineHeight = element->getRect().height(); int newLineHeight = element->getRect().height();
// fourtf: xD // compact emote offset
// bool compactEmotes = true; bool isCompactEmote = !(this->flags & Message::DisableCompactEmotes) &&
// if (compactEmotes && element->word.isImage() && word.getFlags() & element->getCreator().getFlags() & MessageElement::EmoteImages;
// MessageElement::EmoteImages) {
// newLineHeight -= COMPACT_EMOTES_OFFSET * this->scale;
// }
if (isCompactEmote) {
newLineHeight -= COMPACT_EMOTES_OFFSET * this->scale;
}
// update line height
this->lineHeight = std::max(this->lineHeight, newLineHeight); this->lineHeight = std::max(this->lineHeight, newLineHeight);
// set move element
element->setPosition(QPoint(this->currentX, this->currentY - element->getRect().height())); element->setPosition(QPoint(this->currentX, this->currentY - element->getRect().height()));
// add element
this->elements.push_back(std::unique_ptr<MessageLayoutElement>(element)); this->elements.push_back(std::unique_ptr<MessageLayoutElement>(element));
// set current x
this->currentX += element->getRect().width(); this->currentX += element->getRect().width();
if (element->hasTrailingSpace()) { if (element->hasTrailingSpace()) {
@ -85,19 +110,16 @@ void MessageLayoutContainer::breakLine()
{ {
int xOffset = 0; int xOffset = 0;
if (this->centered && this->elements.size() > 0) { if (this->flags & Message::Centered && this->elements.size() > 0) {
xOffset = (width - this->elements.at(this->elements.size() - 1)->getRect().right()) / 2; xOffset = (width - this->elements.at(this->elements.size() - 1)->getRect().right()) / 2;
} }
for (size_t i = lineStart; i < this->elements.size(); i++) { for (size_t i = lineStart; i < this->elements.size(); i++) {
MessageLayoutElement *element = this->elements.at(i).get(); MessageLayoutElement *element = this->elements.at(i).get();
bool isCompactEmote = false; bool isCompactEmote =
!(this->flags & Message::DisableCompactEmotes) &&
// fourtf: xD (this->flags & element->getCreator().getFlags()) & MessageElement::EmoteImages;
// this->enableCompactEmotes && element->getWord().isImage() &&
// element->getWord().getFlags() &
// MessageElement::EmoteImages;
int yExtra = 0; int yExtra = 0;
if (isCompactEmote) { if (isCompactEmote) {

View file

@ -6,6 +6,7 @@
#include <QPoint> #include <QPoint>
#include <QRect> #include <QRect>
#include "messages/message.hpp"
#include "messages/selection.hpp" #include "messages/selection.hpp"
class QPainter; class QPainter;
@ -41,27 +42,28 @@ struct Margin {
} }
}; };
struct MessageLayoutContainer struct MessageLayoutContainer {
{
public: public:
MessageLayoutContainer(); MessageLayoutContainer();
float scale;
Margin margin; Margin margin;
bool centered; bool centered;
bool enableCompactEmotes; bool enableCompactEmotes;
int width;
int getHeight() const; int getHeight() const;
int getWidth() const;
float getScale() const;
// methods // methods
void begin(int width, float scale, Message::MessageFlags flags);
void finish();
void clear(); void clear();
void addElement(MessageLayoutElement *element); void addElement(MessageLayoutElement *element);
void addElementNoLineBreak(MessageLayoutElement *element); void addElementNoLineBreak(MessageLayoutElement *element);
void breakLine(); void breakLine();
bool atStartOfLine(); bool atStartOfLine();
bool fitsInLine(int width); bool fitsInLine(int width);
void finish();
MessageLayoutElement *getElementAt(QPoint point); MessageLayoutElement *getElementAt(QPoint point);
// painting // painting
@ -87,6 +89,9 @@ private:
void _addElement(MessageLayoutElement *element); void _addElement(MessageLayoutElement *element);
// variables // variables
float scale;
int width;
Message::MessageFlags flags;
int line; int line;
int height; int height;
int currentX, currentY; int currentX, currentY;

View file

@ -62,8 +62,8 @@ ImageElement::ImageElement(Image *_image, MessageElement::Flags flags)
void ImageElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags) void ImageElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags)
{ {
if (_flags & this->getFlags()) { if (_flags & this->getFlags()) {
QSize size(this->image->getWidth() * this->image->getScale() * container.scale, QSize size(this->image->getWidth() * this->image->getScale() * container.getScale(),
this->image->getHeight() * this->image->getScale() * container.scale); this->image->getHeight() * this->image->getScale() * container.getScale());
container.addElement( container.addElement(
(new ImageLayoutElement(*this, this->image, size))->setLink(this->getLink())); (new ImageLayoutElement(*this, this->image, size))->setLink(this->getLink()));
@ -108,8 +108,8 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container, MessageElem
_image = this->data.image1x; _image = this->data.image1x;
} }
QSize size((int)(container.scale * _image->getScaledWidth()), QSize size((int)(container.getScale() * _image->getScaledWidth()),
(int)(container.scale * _image->getScaledHeight())); (int)(container.getScale() * _image->getScaledHeight()));
container.addElement( container.addElement(
(new ImageLayoutElement(*this, _image, size))->setLink(this->getLink())); (new ImageLayoutElement(*this, _image, size))->setLink(this->getLink()));
@ -137,8 +137,8 @@ TextElement::TextElement(const QString &text, MessageElement::Flags flags,
void TextElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags) void TextElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags)
{ {
if (_flags & this->getFlags()) { if (_flags & this->getFlags()) {
QFontMetrics &metrics = QFontMetrics &metrics = singletons::FontManager::getInstance().getFontMetrics(
singletons::FontManager::getInstance().getFontMetrics(this->style, container.scale); this->style, container.getScale());
singletons::ThemeManager &themeManager = singletons::ThemeManager &themeManager =
singletons::ThemeManager::ThemeManager::getInstance(); singletons::ThemeManager::ThemeManager::getInstance();
@ -148,7 +148,7 @@ void TextElement::addToContainer(MessageLayoutContainer &container, MessageEleme
themeManager.normalizeColor(color); themeManager.normalizeColor(color);
auto e = (new TextLayoutElement(*this, text, QSize(width, metrics.height()), color, auto e = (new TextLayoutElement(*this, text, QSize(width, metrics.height()), color,
this->style, container.scale)) this->style, container.getScale()))
->setLink(this->getLink()); ->setLink(this->getLink());
e->setTrailingSpace(trailingSpace); e->setTrailingSpace(trailingSpace);
return e; return e;
@ -265,7 +265,7 @@ void TwitchModerationElement::addToContainer(MessageLayoutContainer &container,
MessageElement::Flags _flags) MessageElement::Flags _flags)
{ {
if (_flags & MessageElement::ModeratorTools) { if (_flags & MessageElement::ModeratorTools) {
QSize size((int)(container.scale * 16), (int)(container.scale * 16)); QSize size((int)(container.getScale() * 16), (int)(container.getScale() * 16));
for (const singletons::ModerationAction &m : for (const singletons::ModerationAction &m :
singletons::SettingManager::getInstance().getModerationActions()) { singletons::SettingManager::getInstance().getModerationActions()) {
@ -274,7 +274,7 @@ void TwitchModerationElement::addToContainer(MessageLayoutContainer &container,
->setLink(Link(Link::UserAction, m.getAction()))); ->setLink(Link(Link::UserAction, m.getAction())));
} else { } else {
container.addElement((new TextIconLayoutElement(*this, m.getLine1(), m.getLine2(), container.addElement((new TextIconLayoutElement(*this, m.getLine1(), m.getLine2(),
container.scale, size)) container.getScale(), size))
->setLink(Link(Link::UserAction, m.getAction()))); ->setLink(Link(Link::UserAction, m.getAction())));
} }
} }

View file

@ -82,9 +82,9 @@ private:
QRect getXRect() QRect getXRect()
{ {
float scale = this->getScale(); float s = this->getScale();
return QRect(this->width() - static_cast<int>(20 * scale), static_cast<int>(4 * scale), return QRect(this->width() - static_cast<int>(20 * s), static_cast<int>(4 * s),
static_cast<int>(16 * scale), static_cast<int>(16 * scale)); static_cast<int>(16 * s), static_cast<int>(16 * s));
} }
}; };