refactor: Turn link-info into its own element and class (#5178)

This commit is contained in:
nerix
2024-02-18 13:34:00 +01:00
committed by GitHub
parent 42e4559910
commit e130c48f76
22 changed files with 752 additions and 314 deletions
+8 -12
View File
@@ -77,9 +77,9 @@ MessageLayoutElement *MessageLayoutElement::setTrailingSpace(bool value)
return this;
}
MessageLayoutElement *MessageLayoutElement::setLink(const Link &_link)
MessageLayoutElement *MessageLayoutElement::setLink(const Link &link)
{
this->link_ = _link;
this->link_ = link;
return this;
}
@@ -89,9 +89,13 @@ MessageLayoutElement *MessageLayoutElement::setText(const QString &_text)
return this;
}
const Link &MessageLayoutElement::getLink() const
Link MessageLayoutElement::getLink() const
{
return this->link_;
if (this->link_)
{
return *this->link_;
}
return this->creator_.getLink();
}
const QString &MessageLayoutElement::getText() const
@@ -406,14 +410,6 @@ TextLayoutElement::TextLayoutElement(MessageElement &_creator, QString &_text,
this->setText(_text);
}
void TextLayoutElement::listenToLinkChanges()
{
this->managedConnections_.managedConnect(
static_cast<TextElement &>(this->getCreator()).linkChanged, [this]() {
this->setLink(this->getCreator().getLink());
});
}
void TextLayoutElement::addCopyTextToString(QString &str, uint32_t from,
uint32_t to) const
{
+13 -3
View File
@@ -44,7 +44,12 @@ public:
void setLine(size_t line);
MessageLayoutElement *setTrailingSpace(bool value);
MessageLayoutElement *setLink(const Link &link_);
/// @brief Overwrites the link for this layout element
///
/// @sa #getLink()
MessageLayoutElement *setLink(const Link &link);
MessageLayoutElement *setText(const QString &text_);
virtual void addCopyTextToString(QString &str, uint32_t from = 0,
@@ -57,7 +62,12 @@ public:
virtual int getMouseOverIndex(const QPoint &abs) const = 0;
virtual int getXFromIndex(size_t index) = 0;
const Link &getLink() const;
/// @brief Returns the link this layout element has
///
/// If there isn't any, an empty link is returned (type: None).
/// The link is sourced from the creator, but can be overwritten with
/// #setLink().
Link getLink() const;
const QString &getText() const;
FlagsEnum<MessageElementFlag> getFlags() const;
@@ -67,7 +77,7 @@ protected:
private:
QString text_;
QRect rect_;
Link link_;
std::optional<Link> link_;
MessageElement &creator_;
/**
* The line of the container this element is laid out at