added a setting to collapse long messages by default

This commit is contained in:
fourtf
2018-05-24 11:35:50 +02:00
parent 2ac9b4d0e7
commit 4de2a6b65f
8 changed files with 91 additions and 21 deletions
+17 -3
View File
@@ -107,12 +107,20 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
return true; 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()) { 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()) { if (this->height != this->container.getHeight()) {
@@ -121,6 +129,12 @@ void MessageLayout::actuallyLayout(int width, MessageElement::Flags flags)
this->container.end(); this->container.end();
this->height = this->container.getHeight(); this->height = this->container.getHeight();
// collapsed state
this->flags &= ~Flags::Collapsed;
if (this->container.isCollapsed()) {
this->flags |= Flags::Collapsed;
}
} }
// Painting // Painting
+3 -1
View File
@@ -22,7 +22,9 @@ public:
enum Flags : uint8_t { enum Flags : uint8_t {
RequiresBufferUpdate = 1 << 1, RequiresBufferUpdate = 1 << 1,
RequiresLayout = 1 << 2, RequiresLayout = 1 << 2,
AlternateBackground = 1 << 3 AlternateBackground = 1 << 3,
Collapsed = 1 << 4,
Expanded = 1 << 5,
}; };
MessageLayout(MessagePtr message); MessageLayout(MessagePtr message);
@@ -9,6 +9,7 @@
#include <QPainter> #include <QPainter>
#define COMPACT_EMOTES_OFFSET 6 #define COMPACT_EMOTES_OFFSET 6
#define MAX_UNCOLLAPSED_LINES 3
namespace chatterino { namespace chatterino {
namespace messages { namespace messages {
@@ -39,6 +40,9 @@ void MessageLayoutContainer::begin(int _width, float _scale, Message::MessageFla
auto mediumFontMetrics = getApp()->fonts->getFontMetrics(FontStyle::ChatMedium, _scale); auto mediumFontMetrics = getApp()->fonts->getFontMetrics(FontStyle::ChatMedium, _scale);
this->textLineHeight = mediumFontMetrics.height(); this->textLineHeight = mediumFontMetrics.height();
this->spaceWidth = mediumFontMetrics.width(' '); this->spaceWidth = mediumFontMetrics.width(' ');
this->dotdotdotWidth = mediumFontMetrics.width("...");
this->_canAddMessages = true;
this->_isCollapsed = false;
} }
void MessageLayoutContainer::clear() void MessageLayoutContainer::clear()
@@ -71,12 +75,12 @@ void MessageLayoutContainer::addElementNoLineBreak(MessageLayoutElement *element
bool MessageLayoutContainer::canAddElements() 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; delete element;
return; return;
} }
@@ -154,12 +158,18 @@ void MessageLayoutContainer::breakLine()
this->lineStart = this->elements.size(); this->lineStart = this->elements.size();
// this->currentX = (int)(this->scale * 8); // this->currentX = (int)(this->scale * 8);
if (this->canCollapse() && line + 1 >= MAX_UNCOLLAPSED_LINES) {
this->_canAddMessages = false;
return;
}
this->currentX = 0; this->currentX = 0;
this->currentY += this->lineHeight; this->currentY += this->lineHeight;
this->height = this->currentY + (this->margin.bottom * this->scale); this->height = this->currentY + (this->margin.bottom * this->scale);
this->lineHeight = 0; this->lineHeight = 0;
this->line++; this->line++;
} // namespace layouts }
bool MessageLayoutContainer::atStartOfLine() bool MessageLayoutContainer::atStartOfLine()
{ {
@@ -168,15 +178,32 @@ bool MessageLayoutContainer::atStartOfLine()
bool MessageLayoutContainer::fitsInLine(int _width) 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() 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()) { if (!this->atStartOfLine()) {
this->breakLine(); this->breakLine();
} }
this->height += this->lineHeight;
if (this->lines.size() != 0) { if (this->lines.size() != 0) {
this->lines[0].rect.setTop(-100000); this->lines[0].rect.setTop(-100000);
this->lines.back().rect.setBottom(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) MessageLayoutElement *MessageLayoutContainer::getElementAt(QPoint point)
{ {
for (std::unique_ptr<MessageLayoutElement> &element : this->elements) { for (std::unique_ptr<MessageLayoutElement> &element : this->elements) {
@@ -76,6 +76,8 @@ struct MessageLayoutContainer {
int getLastCharacterIndex() const; int getLastCharacterIndex() const;
void addSelectionText(QString &str, int from, int to); void addSelectionText(QString &str, int from, int to);
bool isCollapsed();
private: private:
struct Line { struct Line {
int startIndex; int startIndex;
@@ -86,7 +88,7 @@ private:
}; };
// helpers // helpers
void _addElement(MessageLayoutElement *element); void _addElement(MessageLayoutElement *element, bool forceAdd = false);
// variables // variables
float scale = 1.f; float scale = 1.f;
@@ -101,6 +103,11 @@ private:
int lineHeight = 0; int lineHeight = 0;
int spaceWidth = 4; int spaceWidth = 4;
int textLineHeight = 0; int textLineHeight = 0;
int dotdotdotWidth = 0;
bool _canAddMessages = true;
bool _isCollapsed = false;
bool canCollapse();
std::vector<std::unique_ptr<MessageLayoutElement>> elements; std::vector<std::unique_ptr<MessageLayoutElement>> elements;
std::vector<Line> lines; std::vector<Line> lines;
@@ -97,12 +97,14 @@ MessagePtr TwitchMessageBuilder::build()
// PARSING // PARSING
this->parseUsername(); this->parseUsername();
#ifdef XD //#ifdef XD
if (this->originalMessage.length() > 100) { // if (this->originalMessage.length() > 100) {
this->message->flags |= Message::Collapsed; // this->message->flags |= Message::Collapsed;
this->emplace<EmoteElement>(getApp()->resources->badgeCollapsed, MessageElement::Collapsed); // this->emplace<EmoteElement>(getApp()->resources->badgeCollapsed,
} // MessageElement::Collapsed);
#endif // }
//#endif
this->message->flags |= Message::Collapsed;
// PARSING // PARSING
this->parseMessageID(); this->parseMessageID();
+1
View File
@@ -40,6 +40,7 @@ public:
BoolSetting hideEmptyInput = {"/appearance/hideEmptyInputBox", false}; BoolSetting hideEmptyInput = {"/appearance/hideEmptyInputBox", false};
BoolSetting showMessageLength = {"/appearance/messages/showMessageLength", false}; BoolSetting showMessageLength = {"/appearance/messages/showMessageLength", false};
BoolSetting seperateMessages = {"/appearance/messages/separateMessages", false}; BoolSetting seperateMessages = {"/appearance/messages/separateMessages", false};
BoolSetting collapseLongMessages = {"/appearance/messages/collapseLongMessages", false};
BoolSetting alternateMessageBackground = {"/appearance/messages/alternateMessageBackground", BoolSetting alternateMessageBackground = {"/appearance/messages/alternateMessageBackground",
false}; false};
BoolSetting windowTopMost = {"/appearance/windowAlwaysOnTop", false}; BoolSetting windowTopMost = {"/appearance/windowAlwaysOnTop", false};
+5 -5
View File
@@ -778,7 +778,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
} }
// message under cursor is collapsed // message under cursor is collapsed
if (layout->getMessage()->flags & Message::Collapsed) { if (layout->flags & MessageLayout::Collapsed) {
this->setCursor(Qt::PointingHandCursor); this->setCursor(Qt::PointingHandCursor);
tooltipWidget->hide(); tooltipWidget->hide();
return; return;
@@ -856,7 +856,7 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
} }
// check if message is collapsed // check if message is collapsed
if (layout->getMessage()->flags & Message::Collapsed) { if (layout->flags & MessageLayout::Collapsed) {
return; return;
} }
@@ -923,8 +923,8 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
} }
// message under cursor is collapsed // message under cursor is collapsed
if (layout->getMessage()->flags & Message::MessageFlags::Collapsed) { if (layout->flags & MessageLayout::Collapsed) {
layout->getMessage()->flags &= ~Message::MessageFlags::Collapsed; layout->flags |= MessageLayout::Expanded;
this->layoutMessages(); this->layoutMessages();
return; return;
@@ -1038,7 +1038,7 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event)
} }
// message under cursor is collapsed // message under cursor is collapsed
if (layout->getMessage()->flags & Message::Collapsed) { if (layout->flags & MessageLayout::Collapsed) {
return; return;
} }
@@ -77,6 +77,12 @@ AppearancePage::AppearancePage()
} }
messages.append(this->createCheckBox("Show badges", app->settings->showBadges)); 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 = auto checkbox =
this->createCheckBox("Seperate messages", app->settings->seperateMessages); this->createCheckBox("Seperate messages", app->settings->seperateMessages);