re-enable link resolver, but fix the underlying issue in the "link changed" signal.

The feature itself still doesn't work for me, but this code does the same thing.
only thing that's really different is it also disconnects the signal properly once
the TextLayoutElement is deleted
This commit is contained in:
Rasmus Karlsson
2018-10-23 10:32:13 +02:00
parent afee4d9d37
commit 0f44a2e0f4
5 changed files with 18 additions and 5 deletions
+1 -2
View File
@@ -183,8 +183,7 @@ void TextElement::addToContainer(MessageLayoutContainer &container,
// Should update it in MessageLayoutElement too!
if (this->getLink().type == Link::Url)
{
this->linkChanged.connect(
[this, e]() { e->setLink(this->getLink()); });
static_cast<TextLayoutElement *>(e)->listenToLinkChanges();
}
return e;
};
+2 -1
View File
@@ -135,10 +135,11 @@ public:
virtual void addToContainer(MessageLayoutContainer &container,
MessageElementFlags flags) = 0;
pajlada::Signals::NoArgSignal linkChanged;
protected:
MessageElement(MessageElementFlags flags);
bool trailingSpace = true;
pajlada::Signals::NoArgSignal linkChanged;
private:
QString text_;
@@ -181,6 +181,17 @@ TextLayoutElement::TextLayoutElement(MessageElement &_creator, QString &_text,
this->setText(_text);
}
void TextLayoutElement::listenToLinkChanges()
{
this->managedConnections_.emplace_back(
static_cast<TextElement &>(this->getCreator())
.linkChanged.connect([this]() {
// log("Old link: {}", this->getCreator().getLink().value);
// log("This link: {}", this->getLink().value);
this->setLink(this->getCreator().getLink()); //
}));
}
void TextLayoutElement::addCopyTextToString(QString &str, int from,
int to) const
{
@@ -83,6 +83,8 @@ public:
const QSize &size, QColor color, FontStyle style,
float scale);
void listenToLinkChanges();
protected:
void addCopyTextToString(QString &str, int from = 0,
int to = INT_MAX) const override;
@@ -96,6 +98,8 @@ private:
QColor color;
FontStyle style;
float scale;
std::vector<pajlada::Signals::ScopedConnection> managedConnections_;
};
// TEXT ICON
-2
View File
@@ -12,8 +12,6 @@ namespace chatterino {
void LinkResolver::getLinkInfo(
const QString url, std::function<void(QString, Link)> successCallback)
{
return;
QString requestUrl("https://braize.pajlada.com/chatterino/link_resolver/" +
QUrl::toPercentEncoding(url, "", "/:"));