From f474db94431aecc6dfb09228ab956adbc7d59599 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 28 Jan 2018 04:07:45 +0100 Subject: [PATCH] minor changes in MessageLayout --- src/messages/layouts/messagelayout.cpp | 27 +++----------------------- src/messages/layouts/messagelayout.hpp | 18 +++++------------ src/widgets/helper/channelview.cpp | 10 +++++----- 3 files changed, 13 insertions(+), 42 deletions(-) diff --git a/src/messages/layouts/messagelayout.cpp b/src/messages/layouts/messagelayout.cpp index 164d5785..2253ae0f 100644 --- a/src/messages/layouts/messagelayout.cpp +++ b/src/messages/layouts/messagelayout.cpp @@ -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(); diff --git a/src/messages/layouts/messagelayout.hpp b/src/messages/layouts/messagelayout.hpp index e4ed0511..bcbf3f01 100644 --- a/src/messages/layouts/messagelayout.hpp +++ b/src/messages/layouts/messagelayout.hpp @@ -4,6 +4,7 @@ #include "messages/layouts/messagelayoutelement.hpp" #include "messages/message.hpp" #include "messages/selection.hpp" +#include "util/flagsenum.h" #include @@ -14,15 +15,9 @@ namespace chatterino { namespace messages { namespace layouts { - -struct MessageLayout; -typedef std::shared_ptr 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; // Layout bool layout(int width, float scale, MessageElement::Flags flags); @@ -61,7 +53,6 @@ private: MessageLayoutContainer container; std::shared_ptr 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 MessageLayoutPtr; } // namespace layouts } // namespace messages } // namespace chatterino diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index 7c704902..4b99d488 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -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; }