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/ignoremessagespage.hpp \
src/widgets/settingspages/specialchannelspage.hpp \
src/widgets/settingspages/keyboardsettings.hpp \
src/widgets/settingspages/keyboardsettingspage.hpp \
src/widgets/helper/titlebarbutton.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)
{
this->container.clear();
this->container.width = width;
this->container.scale = this->scale;
this->container.begin(width, this->scale, this->message->flags.value);
for (const std::unique_ptr<MessageElement> &element : this->message->getElements()) {
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()));
pixmap->setDevicePixelRatio(painter.device()->devicePixelRatioF());
#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
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);
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;

View file

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

View file

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

View file

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

View file

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

View file

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