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) , buffer(nullptr)
{ {
if (_message->flags & Message::Collapsed) { if (_message->flags & Message::Collapsed) {
this->addFlags(MessageLayout::Collapsed); this->flags &= MessageLayout::Collapsed;
} }
} }
@ -38,27 +38,6 @@ int MessageLayout::getHeight() const
return container.getHeight(); 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 // Layout
// return true if redraw is required // return true if redraw is required
bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags) 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 // update word sizes if needed
if (imagesChanged) { if (imagesChanged) {
// this->container.updateImages(); // this->container.updateImages();
this->addFlags(MessageLayout::RequiresBufferUpdate); this->flags &= MessageLayout::RequiresBufferUpdate;
} }
if (textChanged) { if (textChanged) {
// this->container.updateText(); // this->container.updateText();
this->addFlags(MessageLayout::RequiresBufferUpdate); this->flags &= MessageLayout::RequiresBufferUpdate;
} }
if (widthChanged || wordMaskChanged) { if (widthChanged || wordMaskChanged) {
this->deleteBuffer(); this->deleteBuffer();

View file

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

View file

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