Fix signal connection nodiscard warnings (#4818)
This commit is contained in:
@@ -63,7 +63,9 @@ SplitInput::SplitInput(QWidget *parent, Split *_chatWidget,
|
||||
// misc
|
||||
this->installKeyPressedEvent();
|
||||
this->addShortcuts();
|
||||
this->ui_.textEdit->focusLost.connect([this] {
|
||||
// The textEdit's signal will be destroyed before this SplitInput is
|
||||
// destroyed, so we can safely ignore this signal's connection.
|
||||
std::ignore = this->ui_.textEdit->focusLost.connect([this] {
|
||||
this->hideCompletionPopup();
|
||||
});
|
||||
this->scaleChangedEvent(this->scale());
|
||||
@@ -293,23 +295,25 @@ void SplitInput::openEmotePopup()
|
||||
this->emotePopup_ = new EmotePopup(this);
|
||||
this->emotePopup_->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
this->emotePopup_->linkClicked.connect([this](const Link &link) {
|
||||
if (link.type == Link::InsertText)
|
||||
{
|
||||
QTextCursor cursor = this->ui_.textEdit->textCursor();
|
||||
QString textToInsert(link.value + " ");
|
||||
|
||||
// If symbol before cursor isn't space or empty
|
||||
// Then insert space before emote.
|
||||
if (cursor.position() > 0 &&
|
||||
!this->getInputText()[cursor.position() - 1].isSpace())
|
||||
// The EmotePopup is closed & destroyed when this is destroyed, meaning it's safe to ignore this connection
|
||||
std::ignore =
|
||||
this->emotePopup_->linkClicked.connect([this](const Link &link) {
|
||||
if (link.type == Link::InsertText)
|
||||
{
|
||||
textToInsert = " " + textToInsert;
|
||||
QTextCursor cursor = this->ui_.textEdit->textCursor();
|
||||
QString textToInsert(link.value + " ");
|
||||
|
||||
// If symbol before cursor isn't space or empty
|
||||
// Then insert space before emote.
|
||||
if (cursor.position() > 0 &&
|
||||
!this->getInputText()[cursor.position() - 1].isSpace())
|
||||
{
|
||||
textToInsert = " " + textToInsert;
|
||||
}
|
||||
this->insertText(textToInsert);
|
||||
this->ui_.textEdit->activateWindow();
|
||||
}
|
||||
this->insertText(textToInsert);
|
||||
this->ui_.textEdit->activateWindow();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
this->emotePopup_->resize(int(300 * this->emotePopup_->scale()),
|
||||
@@ -649,33 +653,40 @@ bool SplitInput::eventFilter(QObject *obj, QEvent *event)
|
||||
|
||||
void SplitInput::installKeyPressedEvent()
|
||||
{
|
||||
this->ui_.textEdit->keyPressed.disconnectAll();
|
||||
this->ui_.textEdit->keyPressed.connect([this](QKeyEvent *event) {
|
||||
if (auto *popup = this->inputCompletionPopup_.data())
|
||||
{
|
||||
if (popup->isVisible())
|
||||
// We can safely ignore this signal's connection because SplitInput owns
|
||||
// the textEdit object, so it will always be deleted before SplitInput
|
||||
std::ignore =
|
||||
this->ui_.textEdit->keyPressed.connect([this](QKeyEvent *event) {
|
||||
if (auto *popup = this->inputCompletionPopup_.data())
|
||||
{
|
||||
if (popup->eventFilter(nullptr, event))
|
||||
if (popup->isVisible())
|
||||
{
|
||||
event->accept();
|
||||
return;
|
||||
if (popup->eventFilter(nullptr, event))
|
||||
{
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// One of the last remaining of it's kind, the copy shortcut.
|
||||
// For some bizarre reason Qt doesn't want this key be rebound.
|
||||
// TODO(Mm2PL): Revisit in Qt6, maybe something changed?
|
||||
if ((event->key() == Qt::Key_C || event->key() == Qt::Key_Insert) &&
|
||||
event->modifiers() == Qt::ControlModifier)
|
||||
{
|
||||
if (this->channelView_->hasSelection())
|
||||
// One of the last remaining of it's kind, the copy shortcut.
|
||||
// For some bizarre reason Qt doesn't want this key be rebound.
|
||||
// TODO(Mm2PL): Revisit in Qt6, maybe something changed?
|
||||
if ((event->key() == Qt::Key_C || event->key() == Qt::Key_Insert) &&
|
||||
event->modifiers() == Qt::ControlModifier)
|
||||
{
|
||||
this->channelView_->copySelectedText();
|
||||
event->accept();
|
||||
if (this->channelView_->hasSelection())
|
||||
{
|
||||
this->channelView_->copySelectedText();
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
#ifdef DEBUG
|
||||
assert(this->keyPressedEventInstalled == false);
|
||||
this->keyPressedEventInstalled = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SplitInput::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
Reference in New Issue
Block a user