moved selection into its own file

This commit is contained in:
fourtf 2018-01-04 23:50:30 +01:00
parent 4a91372f8f
commit 4a2850c4f5
3 changed files with 69 additions and 62 deletions

View file

@ -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 =

View file

@ -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;
}
};
}
}

View file

@ -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> channel;
@ -158,7 +100,7 @@ private:
bool isMouseDown = false;
QPointF lastPressPosition;
Selection selection;
messages::Selection selection;
bool selecting = false;
messages::LimitedQueue<messages::SharedMessageRef> messages;