mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
added a setting to collapse long messages by default
This commit is contained in:
parent
2ac9b4d0e7
commit
4de2a6b65f
|
@ -107,12 +107,20 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
|
|||
return true;
|
||||
}
|
||||
|
||||
void MessageLayout::actuallyLayout(int width, MessageElement::Flags flags)
|
||||
void MessageLayout::actuallyLayout(int width, MessageElement::Flags _flags)
|
||||
{
|
||||
this->container.begin(width, this->scale, this->message->flags.value);
|
||||
auto messageFlags = this->message->flags.value;
|
||||
|
||||
if (this->flags & MessageLayout::Expanded ||
|
||||
(_flags & MessageElement::ModeratorTools &&
|
||||
!(this->message->flags & Message::MessageFlags::Disabled))) {
|
||||
messageFlags = (Message::MessageFlags)(messageFlags & ~Message::MessageFlags::Collapsed);
|
||||
}
|
||||
|
||||
this->container.begin(width, this->scale, messageFlags);
|
||||
|
||||
for (const std::unique_ptr<MessageElement> &element : this->message->getElements()) {
|
||||
element->addToContainer(this->container, flags);
|
||||
element->addToContainer(this->container, _flags);
|
||||
}
|
||||
|
||||
if (this->height != this->container.getHeight()) {
|
||||
|
@ -121,6 +129,12 @@ void MessageLayout::actuallyLayout(int width, MessageElement::Flags flags)
|
|||
|
||||
this->container.end();
|
||||
this->height = this->container.getHeight();
|
||||
|
||||
// collapsed state
|
||||
this->flags &= ~Flags::Collapsed;
|
||||
if (this->container.isCollapsed()) {
|
||||
this->flags |= Flags::Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
// Painting
|
||||
|
|
|
@ -22,7 +22,9 @@ public:
|
|||
enum Flags : uint8_t {
|
||||
RequiresBufferUpdate = 1 << 1,
|
||||
RequiresLayout = 1 << 2,
|
||||
AlternateBackground = 1 << 3
|
||||
AlternateBackground = 1 << 3,
|
||||
Collapsed = 1 << 4,
|
||||
Expanded = 1 << 5,
|
||||
};
|
||||
|
||||
MessageLayout(MessagePtr message);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <QPainter>
|
||||
|
||||
#define COMPACT_EMOTES_OFFSET 6
|
||||
#define MAX_UNCOLLAPSED_LINES 3
|
||||
|
||||
namespace chatterino {
|
||||
namespace messages {
|
||||
|
@ -39,6 +40,9 @@ void MessageLayoutContainer::begin(int _width, float _scale, Message::MessageFla
|
|||
auto mediumFontMetrics = getApp()->fonts->getFontMetrics(FontStyle::ChatMedium, _scale);
|
||||
this->textLineHeight = mediumFontMetrics.height();
|
||||
this->spaceWidth = mediumFontMetrics.width(' ');
|
||||
this->dotdotdotWidth = mediumFontMetrics.width("...");
|
||||
this->_canAddMessages = true;
|
||||
this->_isCollapsed = false;
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::clear()
|
||||
|
@ -71,12 +75,12 @@ void MessageLayoutContainer::addElementNoLineBreak(MessageLayoutElement *element
|
|||
|
||||
bool MessageLayoutContainer::canAddElements()
|
||||
{
|
||||
return !(this->flags & Message::MessageFlags::Collapsed && line >= 3);
|
||||
return this->_canAddMessages;
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::_addElement(MessageLayoutElement *element)
|
||||
void MessageLayoutContainer::_addElement(MessageLayoutElement *element, bool forceAdd)
|
||||
{
|
||||
if (!this->canAddElements()) {
|
||||
if (!this->canAddElements() && !forceAdd) {
|
||||
delete element;
|
||||
return;
|
||||
}
|
||||
|
@ -154,12 +158,18 @@ void MessageLayoutContainer::breakLine()
|
|||
|
||||
this->lineStart = this->elements.size();
|
||||
// this->currentX = (int)(this->scale * 8);
|
||||
|
||||
if (this->canCollapse() && line + 1 >= MAX_UNCOLLAPSED_LINES) {
|
||||
this->_canAddMessages = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this->currentX = 0;
|
||||
this->currentY += this->lineHeight;
|
||||
this->height = this->currentY + (this->margin.bottom * this->scale);
|
||||
this->lineHeight = 0;
|
||||
this->line++;
|
||||
} // namespace layouts
|
||||
}
|
||||
|
||||
bool MessageLayoutContainer::atStartOfLine()
|
||||
{
|
||||
|
@ -168,15 +178,32 @@ bool MessageLayoutContainer::atStartOfLine()
|
|||
|
||||
bool MessageLayoutContainer::fitsInLine(int _width)
|
||||
{
|
||||
return this->currentX + _width <= this->width - this->margin.left - this->margin.right;
|
||||
return this->currentX + _width <=
|
||||
(this->width - this->margin.left - this->margin.right -
|
||||
(this->line + 1 == MAX_UNCOLLAPSED_LINES ? this->dotdotdotWidth : 0));
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::end()
|
||||
{
|
||||
if (!this->canAddElements()) {
|
||||
static TextElement dotdotdot("...", MessageElement::Collapsed, MessageColor::Link);
|
||||
static QString dotdotdotText("...");
|
||||
|
||||
auto *element = new TextLayoutElement(
|
||||
dotdotdot, dotdotdotText, QSize(this->dotdotdotWidth, this->textLineHeight),
|
||||
QColor("#00D80A"), FontStyle::ChatMediumBold, this->scale);
|
||||
|
||||
// getApp()->themes->messages.textColors.system
|
||||
this->_addElement(element, true);
|
||||
this->_isCollapsed = true;
|
||||
}
|
||||
|
||||
if (!this->atStartOfLine()) {
|
||||
this->breakLine();
|
||||
}
|
||||
|
||||
this->height += this->lineHeight;
|
||||
|
||||
if (this->lines.size() != 0) {
|
||||
this->lines[0].rect.setTop(-100000);
|
||||
this->lines.back().rect.setBottom(100000);
|
||||
|
@ -185,6 +212,17 @@ void MessageLayoutContainer::end()
|
|||
}
|
||||
}
|
||||
|
||||
bool MessageLayoutContainer::canCollapse()
|
||||
{
|
||||
return getApp()->settings->collapseLongMessages.getValue() &&
|
||||
this->flags & Message::MessageFlags::Collapsed;
|
||||
}
|
||||
|
||||
bool MessageLayoutContainer::isCollapsed()
|
||||
{
|
||||
return this->_isCollapsed;
|
||||
}
|
||||
|
||||
MessageLayoutElement *MessageLayoutContainer::getElementAt(QPoint point)
|
||||
{
|
||||
for (std::unique_ptr<MessageLayoutElement> &element : this->elements) {
|
||||
|
|
|
@ -76,6 +76,8 @@ struct MessageLayoutContainer {
|
|||
int getLastCharacterIndex() const;
|
||||
void addSelectionText(QString &str, int from, int to);
|
||||
|
||||
bool isCollapsed();
|
||||
|
||||
private:
|
||||
struct Line {
|
||||
int startIndex;
|
||||
|
@ -86,7 +88,7 @@ private:
|
|||
};
|
||||
|
||||
// helpers
|
||||
void _addElement(MessageLayoutElement *element);
|
||||
void _addElement(MessageLayoutElement *element, bool forceAdd = false);
|
||||
|
||||
// variables
|
||||
float scale = 1.f;
|
||||
|
@ -101,6 +103,11 @@ private:
|
|||
int lineHeight = 0;
|
||||
int spaceWidth = 4;
|
||||
int textLineHeight = 0;
|
||||
int dotdotdotWidth = 0;
|
||||
bool _canAddMessages = true;
|
||||
bool _isCollapsed = false;
|
||||
|
||||
bool canCollapse();
|
||||
|
||||
std::vector<std::unique_ptr<MessageLayoutElement>> elements;
|
||||
std::vector<Line> lines;
|
||||
|
|
|
@ -97,12 +97,14 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
// PARSING
|
||||
this->parseUsername();
|
||||
|
||||
#ifdef XD
|
||||
if (this->originalMessage.length() > 100) {
|
||||
this->message->flags |= Message::Collapsed;
|
||||
this->emplace<EmoteElement>(getApp()->resources->badgeCollapsed, MessageElement::Collapsed);
|
||||
}
|
||||
#endif
|
||||
//#ifdef XD
|
||||
// if (this->originalMessage.length() > 100) {
|
||||
// this->message->flags |= Message::Collapsed;
|
||||
// this->emplace<EmoteElement>(getApp()->resources->badgeCollapsed,
|
||||
// MessageElement::Collapsed);
|
||||
// }
|
||||
//#endif
|
||||
this->message->flags |= Message::Collapsed;
|
||||
|
||||
// PARSING
|
||||
this->parseMessageID();
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
BoolSetting hideEmptyInput = {"/appearance/hideEmptyInputBox", false};
|
||||
BoolSetting showMessageLength = {"/appearance/messages/showMessageLength", false};
|
||||
BoolSetting seperateMessages = {"/appearance/messages/separateMessages", false};
|
||||
BoolSetting collapseLongMessages = {"/appearance/messages/collapseLongMessages", false};
|
||||
BoolSetting alternateMessageBackground = {"/appearance/messages/alternateMessageBackground",
|
||||
false};
|
||||
BoolSetting windowTopMost = {"/appearance/windowAlwaysOnTop", false};
|
||||
|
|
|
@ -778,7 +778,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
|||
}
|
||||
|
||||
// message under cursor is collapsed
|
||||
if (layout->getMessage()->flags & Message::Collapsed) {
|
||||
if (layout->flags & MessageLayout::Collapsed) {
|
||||
this->setCursor(Qt::PointingHandCursor);
|
||||
tooltipWidget->hide();
|
||||
return;
|
||||
|
@ -856,7 +856,7 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
|
|||
}
|
||||
|
||||
// check if message is collapsed
|
||||
if (layout->getMessage()->flags & Message::Collapsed) {
|
||||
if (layout->flags & MessageLayout::Collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -923,8 +923,8 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
|||
}
|
||||
|
||||
// message under cursor is collapsed
|
||||
if (layout->getMessage()->flags & Message::MessageFlags::Collapsed) {
|
||||
layout->getMessage()->flags &= ~Message::MessageFlags::Collapsed;
|
||||
if (layout->flags & MessageLayout::Collapsed) {
|
||||
layout->flags |= MessageLayout::Expanded;
|
||||
|
||||
this->layoutMessages();
|
||||
return;
|
||||
|
@ -1038,7 +1038,7 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event)
|
|||
}
|
||||
|
||||
// message under cursor is collapsed
|
||||
if (layout->getMessage()->flags & Message::Collapsed) {
|
||||
if (layout->flags & MessageLayout::Collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,12 @@ AppearancePage::AppearancePage()
|
|||
}
|
||||
|
||||
messages.append(this->createCheckBox("Show badges", app->settings->showBadges));
|
||||
|
||||
auto *collapseMessages = this->createCheckBox("Collapse large messages (3+ lines)",
|
||||
app->settings->collapseLongMessages);
|
||||
QObject::connect(collapseMessages, &QCheckBox::toggled,
|
||||
[] { getApp()->windows->layoutVisibleChatWidgets(); });
|
||||
messages.append(collapseMessages);
|
||||
{
|
||||
auto checkbox =
|
||||
this->createCheckBox("Seperate messages", app->settings->seperateMessages);
|
||||
|
|
Loading…
Reference in a new issue