minor changes in MessageLayout

This commit is contained in:
fourtf 2018-01-28 04:07:45 +01:00
parent 772dc97d92
commit f474db9443
3 changed files with 13 additions and 42 deletions

View file

@ -23,7 +23,7 @@ MessageLayout::MessageLayout(MessagePtr _message)
, buffer(nullptr)
{
if (_message->flags & Message::Collapsed) {
this->addFlags(MessageLayout::Collapsed);
this->flags &= MessageLayout::Collapsed;
}
}
@ -38,27 +38,6 @@ int MessageLayout::getHeight() const
return container.getHeight();
}
// Flags
MessageLayout::Flags MessageLayout::getFlags() const
{
return this->flags;
}
bool MessageLayout::hasFlags(Flags _flags) const
{
return this->flags & _flags;
}
void MessageLayout::addFlags(Flags _flags)
{
this->flags = (Flags)((MessageLayoutFlagsType)this->flags | (MessageLayoutFlagsType)_flags);
}
void MessageLayout::removeFlags(Flags _flags)
{
this->flags = (Flags)((MessageLayoutFlagsType)this->flags & ~((MessageLayoutFlagsType)_flags));
}
// Layout
// return true if redraw is required
bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
@ -105,11 +84,11 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
// update word sizes if needed
if (imagesChanged) {
// this->container.updateImages();
this->addFlags(MessageLayout::RequiresBufferUpdate);
this->flags &= MessageLayout::RequiresBufferUpdate;
}
if (textChanged) {
// this->container.updateText();
this->addFlags(MessageLayout::RequiresBufferUpdate);
this->flags &= MessageLayout::RequiresBufferUpdate;
}
if (widthChanged || wordMaskChanged) {
this->deleteBuffer();

View file

@ -4,6 +4,7 @@
#include "messages/layouts/messagelayoutelement.hpp"
#include "messages/message.hpp"
#include "messages/selection.hpp"
#include "util/flagsenum.h"
#include <QPixmap>
@ -14,15 +15,9 @@
namespace chatterino {
namespace messages {
namespace layouts {
struct MessageLayout;
typedef std::shared_ptr<MessageLayout> MessageLayoutPtr;
typedef uint8_t MessageLayoutFlagsType;
struct MessageLayout : boost::noncopyable
{
struct MessageLayout : boost::noncopyable {
public:
enum Flags : MessageLayoutFlagsType { Collapsed, RequiresBufferUpdate, RequiresLayout };
enum Flags : uint8_t { Collapsed, RequiresBufferUpdate, RequiresLayout };
MessageLayout(MessagePtr message);
@ -32,10 +27,7 @@ public:
int getHeight() const;
// Flags
Flags getFlags() const;
bool hasFlags(Flags flags) const;
void addFlags(Flags flags);
void removeFlags(Flags flags);
util::FlagsEnum<Flags> flags;
// Layout
bool layout(int width, float scale, MessageElement::Flags flags);
@ -61,7 +53,6 @@ private:
MessageLayoutContainer container;
std::shared_ptr<QPixmap> buffer = nullptr;
bool bufferValid = false;
Flags flags;
int height = 0;
@ -81,6 +72,7 @@ private:
void updateBuffer(QPixmap *pixmap, int messageIndex, Selection &selection);
};
typedef std::shared_ptr<MessageLayout> MessageLayoutPtr;
} // namespace layouts
} // namespace messages
} // namespace chatterino

View file

@ -674,7 +674,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
}
// message under cursor is collapsed
if (layout->getFlags() & MessageLayout::Collapsed) {
if (layout->flags & MessageLayout::Collapsed) {
this->setCursor(Qt::PointingHandCursor);
tooltipWidget->hide();
return;
@ -750,7 +750,7 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
}
// check if message is collapsed
if (layout->getFlags() & MessageLayout::Collapsed) {
if (layout->flags & MessageLayout::Collapsed) {
return;
}
@ -810,8 +810,8 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
}
// message under cursor is collapsed
if (layout->getFlags() & MessageLayout::Collapsed) {
layout->addFlags(MessageLayout::Collapsed);
if (layout->flags & MessageLayout::Collapsed) {
layout->flags &= MessageLayout::Collapsed;
this->layoutMessages();
return;
}
@ -843,7 +843,7 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event)
}
// message under cursor is collapsed
if (layout->getFlags() & MessageLayout::Collapsed) {
if (layout->flags & MessageLayout::Collapsed) {
return;
}