diff --git a/src/messages/Message.hpp b/src/messages/Message.hpp index 6b50e8399..cc716dd2f 100644 --- a/src/messages/Message.hpp +++ b/src/messages/Message.hpp @@ -22,11 +22,12 @@ enum class MessageFlag : uint16_t { Disabled = (1 << 5), DisableCompactEmotes = (1 << 6), Collapsed = (1 << 7), - DisconnectedMessage = (1 << 8), - Untimeout = (1 << 9), - PubSub = (1 << 10), - Subscription = (1 << 11), - Notification = (1 << 12), + ConnectedMessage = (1 << 8), + DisconnectedMessage = (1 << 9), + Untimeout = (1 << 10), + PubSub = (1 << 11), + Subscription = (1 << 12), + Notification = (1 << 13), }; using MessageFlags = FlagsEnum; diff --git a/src/messages/MessageElement.cpp b/src/messages/MessageElement.cpp index ae31a9492..8afe72a5a 100644 --- a/src/messages/MessageElement.cpp +++ b/src/messages/MessageElement.cpp @@ -73,6 +73,23 @@ MessageElement *MessageElement::updateLink() return this; } +// Empty +EmptyElement::EmptyElement() + : MessageElement(MessageElementFlag::None) +{ +} + +void EmptyElement::addToContainer(MessageLayoutContainer &container, + MessageElementFlags flags) +{ +} + +EmptyElement &EmptyElement::instance() +{ + static EmptyElement instance; + return instance; +} + // IMAGE ImageElement::ImageElement(ImagePtr image, MessageElementFlags flags) : MessageElement(flags) diff --git a/src/messages/MessageElement.hpp b/src/messages/MessageElement.hpp index cfd4ad3dd..4ae74d848 100644 --- a/src/messages/MessageElement.hpp +++ b/src/messages/MessageElement.hpp @@ -148,6 +148,21 @@ private: MessageElementFlags flags_; }; +// used when layout element doesn't have a creator +class EmptyElement : public MessageElement +{ +public: + EmptyElement(); + + void addToContainer(MessageLayoutContainer &container, + MessageElementFlags flags) override; + + static EmptyElement &instance(); + +private: + ImagePtr image_; +}; + // contains a simple image class ImageElement : public MessageElement { diff --git a/src/messages/layouts/MessageLayout.cpp b/src/messages/layouts/MessageLayout.cpp index 9048678bb..cf1be4a72 100644 --- a/src/messages/layouts/MessageLayout.cpp +++ b/src/messages/layouts/MessageLayout.cpp @@ -103,6 +103,9 @@ void MessageLayout::actuallyLayout(int width, MessageElementFlags _flags) { this->layoutCount_++; + const auto addTest = this->message_->flags.hasAny( + {MessageFlag::DisconnectedMessage, MessageFlag::ConnectedMessage}); + auto messageFlags = this->message_->flags; if (this->flags.has(MessageLayoutFlag::Expanded) || @@ -114,11 +117,27 @@ void MessageLayout::actuallyLayout(int width, MessageElementFlags _flags) this->container_->begin(width, this->scale_, messageFlags); + if (addTest) + { + this->container_->addElementNoLineBreak(new TestLayoutElement( + EmptyElement::instance(), QSize(width, this->scale_ * 6), + getTheme()->messages.backgrounds.regular, false)); + this->container_->breakLine(); + } + for (const auto &element : this->message_->elements) { element->addToContainer(*this->container_, _flags); } + if (addTest) + { + this->container_->breakLine(); + this->container_->addElement(new TestLayoutElement( + EmptyElement::instance(), QSize(width, this->scale_ * 6), + getTheme()->messages.backgrounds.regular, true)); + } + if (this->height_ != this->container_->getHeight()) { this->deleteBuffer(); @@ -179,6 +198,11 @@ void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex, { painter.fillRect(0, y, pixmap->width(), pixmap->height(), app->themes->messages.disabled); + // painter.fillRect(0, y, pixmap->width(), pixmap->height(), + // QBrush(QColor(64, 64, 64, 64))); + painter.fillRect(0, y, pixmap->width(), pixmap->height(), + QBrush(QColor(255, 0, 0, 63), Qt::BDiagPattern)); + // app->themes->messages.disabled); } // draw selection diff --git a/src/messages/layouts/MessageLayoutContainer.cpp b/src/messages/layouts/MessageLayoutContainer.cpp index c2b43f357..f24d05e26 100644 --- a/src/messages/layouts/MessageLayoutContainer.cpp +++ b/src/messages/layouts/MessageLayoutContainer.cpp @@ -157,7 +157,7 @@ void MessageLayoutContainer::breakLine() int yExtra = 0; if (isCompactEmote) { - yExtra = (COMPACT_EMOTES_OFFSET / 2) * this->scale_; + // yExtra = (COMPACT_EMOTES_OFFSET / 2) * this->scale_; } // if (element->getCreator().getFlags() & @@ -165,7 +165,8 @@ void MessageLayoutContainer::breakLine() // { if (element->getRect().height() < this->textLineHeight_) { - yExtra -= (this->textLineHeight_ - element->getRect().height()) / 2; + // yExtra -= (this->textLineHeight_ - element->getRect().height()) / + // 2; } element->setPosition( diff --git a/src/messages/layouts/MessageLayoutElement.cpp b/src/messages/layouts/MessageLayoutElement.cpp index a47922408..51b3b7374 100644 --- a/src/messages/layouts/MessageLayoutElement.cpp +++ b/src/messages/layouts/MessageLayoutElement.cpp @@ -366,4 +366,72 @@ int TextIconLayoutElement::getXFromIndex(int index) } } +// TestLayoutElement +TestLayoutElement::TestLayoutElement(MessageElement &element, const QSize &size, + const QColor &background, bool end) + : MessageLayoutElement(element, size) + , size_(size) + , background_(background) + , end_(end) +{ +} + +void TestLayoutElement::addCopyTextToString(QString &str, int from, + int to) const +{ +} + +int TestLayoutElement::getSelectionIndexCount() const +{ + return 0; +} + +void TestLayoutElement::paint(QPainter &painter) +{ + const auto dy = this->getRect().y(); + const auto color = end_ ? background_ : QColor(0, 0, 0, 127); + + // make zig zag + auto polygon = QPolygon(); + for (auto x = size_.height() / -2; x < size_.width() + 16; + x += size_.height()) + { + polygon.push_back({x, dy + 0}); + polygon.push_back({x + size_.height(), dy + size_.height()}); + x += size_.height(); + polygon.push_back({x, dy + size_.height()}); + polygon.push_back({x + size_.height(), dy + 0}); + } + + // finish polygon + polygon.push_back({size_.width(), 1000}); + polygon.push_back({0, 1000}); + + // finish polygon + polygon.push_back({size_.width(), 1000}); + polygon.push_back({0, 1000}); + + // turn into path + auto path = QPainterPath(); + path.addPolygon(polygon); + + // draw + painter.fillPath(path, color); + painter.strokePath(path, QColor(127, 127, 127, 127)); +} + +void TestLayoutElement::paintAnimated(QPainter &painter, int yOffset) +{ +} + +int TestLayoutElement::getMouseOverIndex(const QPoint &abs) const +{ + return 0; +} + +int TestLayoutElement::getXFromIndex(int index) +{ + return 0; +} + } // namespace chatterino diff --git a/src/messages/layouts/MessageLayoutElement.hpp b/src/messages/layouts/MessageLayoutElement.hpp index d5e11a0a3..24139be4e 100644 --- a/src/messages/layouts/MessageLayoutElement.hpp +++ b/src/messages/layouts/MessageLayoutElement.hpp @@ -125,4 +125,25 @@ private: QString line2; }; +class TestLayoutElement : public MessageLayoutElement +{ +public: + TestLayoutElement(MessageElement &creator, const QSize &size, + const QColor &background, bool end); + +protected: + void addCopyTextToString(QString &str, int from = 0, + int to = INT_MAX) const override; + int getSelectionIndexCount() const override; + void paint(QPainter &painter) override; + void paintAnimated(QPainter &painter, int yOffset) override; + int getMouseOverIndex(const QPoint &abs) const override; + int getXFromIndex(int index) override; + +private: + QSize size_; + QColor background_; + bool end_; +}; + } // namespace chatterino diff --git a/src/providers/irc/AbstractIrcServer.cpp b/src/providers/irc/AbstractIrcServer.cpp index f37e46c30..7cb45b3c7 100644 --- a/src/providers/irc/AbstractIrcServer.cpp +++ b/src/providers/irc/AbstractIrcServer.cpp @@ -231,8 +231,11 @@ void AbstractIrcServer::onConnected() { std::lock_guard lock(this->channelMutex); - auto connected = makeSystemMessage("connected to chat"); - auto reconnected = makeSystemMessage("reconnected to chat"); + auto connected = makeSystemMessage("connected"); + connected->flags.set(MessageFlag::ConnectedMessage); + connected->flags.set(MessageFlag::Centered); + auto reconnected = makeSystemMessage("reconnected"); + reconnected->flags.set(MessageFlag::ConnectedMessage); for (std::weak_ptr &weak : this->channels.values()) { @@ -244,14 +247,13 @@ void AbstractIrcServer::onConnected() LimitedQueueSnapshot snapshot = chan->getMessageSnapshot(); - bool replaceMessage = snapshot.size() > 0 && - snapshot[snapshot.size() - 1]->flags.has( - MessageFlag::DisconnectedMessage); + bool replaceMessage = + snapshot.size() > 0 && snapshot[snapshot.size() - 1]->flags.has( + MessageFlag::DisconnectedMessage); if (replaceMessage) { - chan->replaceMessage(snapshot[snapshot.size() - 1], - reconnected); + chan->replaceMessage(snapshot[snapshot.size() - 1], reconnected); continue; } @@ -265,7 +267,7 @@ void AbstractIrcServer::onDisconnected() { std::lock_guard lock(this->channelMutex); - MessageBuilder b(systemMessage, "disconnected from chat"); + MessageBuilder b(systemMessage, "disconnected"); b->flags.set(MessageFlag::DisconnectedMessage); auto disconnected = b.release(); diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 3ed4afa51..91bfed93b 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -264,17 +264,18 @@ void ChannelView::updatePauseTimer() else { /// Get the maximum pause - auto max = std::max_element( - this->pauses_.begin(), this->pauses_.end(), - [](auto &&a, auto &&b) { return a.second > b.second; }) - ->second.get(); + auto pauseEnd = + std::max_element( + this->pauses_.begin(), this->pauses_.end(), + [](auto &&a, auto &&b) { return a.second > b.second; }) + ->second.get(); - if (max != this->pauseEnd_) + if (pauseEnd != this->pauseEnd_) { /// Start the timer - this->pauseEnd_ = max; + this->pauseEnd_ = pauseEnd; this->pauseTimer_.start( - duration_cast(max - SteadyClock::now())); + duration_cast(pauseEnd - SteadyClock::now())); } } }