diff --git a/chatterino.pro b/chatterino.pro index 02e098dd6..0c4dfa014 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -195,7 +195,8 @@ HEADERS += \ src/util/emotemap.hpp \ src/singletons/helper/ircmessagehandler.hpp \ src/util/serialize-custom.hpp \ - src/messages/highlightphrase.hpp + src/messages/highlightphrase.hpp \ + src/messages/selection.hpp PRECOMPILED_HEADER = diff --git a/src/messages/selection.hpp b/src/messages/selection.hpp new file mode 100644 index 000000000..f49dbbbd5 --- /dev/null +++ b/src/messages/selection.hpp @@ -0,0 +1,64 @@ +#pragma once + +namespace chatterino { +namespace messages { +struct SelectionItem { + int messageIndex; + int charIndex; + + SelectionItem() + { + messageIndex = charIndex = 0; + } + + SelectionItem(int _messageIndex, int _charIndex) + { + this->messageIndex = _messageIndex; + this->charIndex = _charIndex; + } + + bool isSmallerThan(const SelectionItem &other) const + { + return this->messageIndex < other.messageIndex || + (this->messageIndex == other.messageIndex && this->charIndex < other.charIndex); + } + + bool equals(const SelectionItem &other) const + { + return this->messageIndex == other.messageIndex && this->charIndex == other.charIndex; + } +}; + +struct Selection { + SelectionItem start; + SelectionItem end; + SelectionItem min; + SelectionItem max; + + Selection() + { + } + + Selection(const SelectionItem &start, const SelectionItem &end) + : start(start) + , end(end) + , min(start) + , max(end) + { + if (max.isSmallerThan(min)) { + std::swap(this->min, this->max); + } + } + + bool isEmpty() const + { + return this->start.equals(this->end); + } + + bool isSingleMessage() const + { + return this->min.messageIndex == this->max.messageIndex; + } +}; +} +} diff --git a/src/widgets/helper/channelview.hpp b/src/widgets/helper/channelview.hpp index 7910836e5..9e73f3c50 100644 --- a/src/widgets/helper/channelview.hpp +++ b/src/widgets/helper/channelview.hpp @@ -4,6 +4,7 @@ #include "messages/lazyloadedimage.hpp" #include "messages/limitedqueuesnapshot.hpp" #include "messages/messageref.hpp" +#include "messages/selection.hpp" #include "messages/word.hpp" #include "widgets/accountpopup.hpp" #include "widgets/basewidget.hpp" @@ -22,65 +23,6 @@ namespace chatterino { namespace widgets { -struct SelectionItem { - int messageIndex; - int charIndex; - - SelectionItem() - { - messageIndex = charIndex = 0; - } - - SelectionItem(int _messageIndex, int _charIndex) - { - this->messageIndex = _messageIndex; - this->charIndex = _charIndex; - } - - bool isSmallerThan(const SelectionItem &other) const - { - return this->messageIndex < other.messageIndex || - (this->messageIndex == other.messageIndex && this->charIndex < other.charIndex); - } - - bool equals(const SelectionItem &other) const - { - return this->messageIndex == other.messageIndex && this->charIndex == other.charIndex; - } -}; - -struct Selection { - SelectionItem start; - SelectionItem end; - SelectionItem min; - SelectionItem max; - - Selection() - { - } - - Selection(const SelectionItem &start, const SelectionItem &end) - : start(start) - , end(end) - , min(start) - , max(end) - { - if (max.isSmallerThan(min)) { - std::swap(this->min, this->max); - } - } - - bool isEmpty() const - { - return this->start.equals(this->end); - } - - bool isSingleMessage() const - { - return this->min.messageIndex == this->max.messageIndex; - } -}; - class ChannelView : public BaseWidget { Q_OBJECT @@ -137,7 +79,7 @@ private: void updateMessageBuffer(messages::MessageRef *messageRef, QPixmap *buffer, int messageIndex); void drawMessageSelection(QPainter &painter, messages::MessageRef *messageRef, int messageIndex, int bufferHeight); - void setSelection(const SelectionItem &start, const SelectionItem &end); + void setSelection(const messages::SelectionItem &start, const messages::SelectionItem &end); std::shared_ptr channel; @@ -158,7 +100,7 @@ private: bool isMouseDown = false; QPointF lastPressPosition; - Selection selection; + messages::Selection selection; bool selecting = false; messages::LimitedQueue messages;