added wip effect for (dis/re)connected messages

This commit is contained in:
fourtf 2018-12-04 21:07:55 +01:00
parent 96328a5e25
commit fc93d7b738
9 changed files with 172 additions and 22 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -231,8 +231,11 @@ void AbstractIrcServer::onConnected()
{
std::lock_guard<std::mutex> 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<Channel> &weak : this->channels.values())
{
@ -244,14 +247,13 @@ void AbstractIrcServer::onConnected()
LimitedQueueSnapshot<MessagePtr> 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<std::mutex> lock(this->channelMutex);
MessageBuilder b(systemMessage, "disconnected from chat");
MessageBuilder b(systemMessage, "disconnected");
b->flags.set(MessageFlag::DisconnectedMessage);
auto disconnected = b.release();

View file

@ -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<milliseconds>(max - SteadyClock::now()));
duration_cast<milliseconds>(pauseEnd - SteadyClock::now()));
}
}
}