mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
moved selection into its own file
This commit is contained in:
parent
4a91372f8f
commit
4a2850c4f5
3 changed files with 69 additions and 62 deletions
|
@ -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 =
|
||||
|
|
64
src/messages/selection.hpp
Normal file
64
src/messages/selection.hpp
Normal 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;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue