Fix signal connection nodiscard warnings (#4818)
This commit is contained in:
@@ -247,7 +247,8 @@ Split::Split(QWidget *parent)
|
||||
this->updateInputPlaceholder();
|
||||
|
||||
// clear SplitInput selection when selecting in ChannelView
|
||||
this->view_->selectionChanged.connect([this]() {
|
||||
// this connection can be ignored since the ChannelView is owned by this Split
|
||||
std::ignore = this->view_->selectionChanged.connect([this]() {
|
||||
if (this->input_->hasSelection())
|
||||
{
|
||||
this->input_->clearSelection();
|
||||
@@ -255,55 +256,60 @@ Split::Split(QWidget *parent)
|
||||
});
|
||||
|
||||
// clear ChannelView selection when selecting in SplitInput
|
||||
this->input_->selectionChanged.connect([this]() {
|
||||
// this connection can be ignored since the SplitInput is owned by this Split
|
||||
std::ignore = this->input_->selectionChanged.connect([this]() {
|
||||
if (this->view_->hasSelection())
|
||||
{
|
||||
this->view_->clearSelection();
|
||||
}
|
||||
});
|
||||
|
||||
this->view_->openChannelIn.connect([this](
|
||||
QString twitchChannel,
|
||||
FromTwitchLinkOpenChannelIn openIn) {
|
||||
ChannelPtr channel = getApp()->twitch->getOrAddChannel(twitchChannel);
|
||||
switch (openIn)
|
||||
{
|
||||
case FromTwitchLinkOpenChannelIn::Split:
|
||||
this->openSplitRequested.invoke(channel);
|
||||
break;
|
||||
case FromTwitchLinkOpenChannelIn::Tab:
|
||||
this->joinChannelInNewTab(channel);
|
||||
break;
|
||||
case FromTwitchLinkOpenChannelIn::BrowserPlayer:
|
||||
this->openChannelInBrowserPlayer(channel);
|
||||
break;
|
||||
case FromTwitchLinkOpenChannelIn::Streamlink:
|
||||
this->openChannelInStreamlink(twitchChannel);
|
||||
break;
|
||||
default:
|
||||
qCWarning(chatterinoWidget)
|
||||
<< "Unhandled \"FromTwitchLinkOpenChannelIn\" enum value: "
|
||||
<< static_cast<int>(openIn);
|
||||
}
|
||||
});
|
||||
// this connection can be ignored since the ChannelView is owned by this Split
|
||||
std::ignore = this->view_->openChannelIn.connect(
|
||||
[this](QString twitchChannel, FromTwitchLinkOpenChannelIn openIn) {
|
||||
ChannelPtr channel =
|
||||
getApp()->twitch->getOrAddChannel(twitchChannel);
|
||||
switch (openIn)
|
||||
{
|
||||
case FromTwitchLinkOpenChannelIn::Split:
|
||||
this->openSplitRequested.invoke(channel);
|
||||
break;
|
||||
case FromTwitchLinkOpenChannelIn::Tab:
|
||||
this->joinChannelInNewTab(channel);
|
||||
break;
|
||||
case FromTwitchLinkOpenChannelIn::BrowserPlayer:
|
||||
this->openChannelInBrowserPlayer(channel);
|
||||
break;
|
||||
case FromTwitchLinkOpenChannelIn::Streamlink:
|
||||
this->openChannelInStreamlink(twitchChannel);
|
||||
break;
|
||||
default:
|
||||
qCWarning(chatterinoWidget)
|
||||
<< "Unhandled \"FromTwitchLinkOpenChannelIn\" enum "
|
||||
"value: "
|
||||
<< static_cast<int>(openIn);
|
||||
}
|
||||
});
|
||||
|
||||
this->input_->textChanged.connect([this](const QString &newText) {
|
||||
if (getSettings()->showEmptyInput)
|
||||
{
|
||||
// We always show the input regardless of the text, so we can early out here
|
||||
return;
|
||||
}
|
||||
// this connection can be ignored since the SplitInput is owned by this Split
|
||||
std::ignore =
|
||||
this->input_->textChanged.connect([this](const QString &newText) {
|
||||
if (getSettings()->showEmptyInput)
|
||||
{
|
||||
// We always show the input regardless of the text, so we can early out here
|
||||
return;
|
||||
}
|
||||
|
||||
if (newText.isEmpty())
|
||||
{
|
||||
this->input_->hide();
|
||||
}
|
||||
else if (this->input_->isHidden())
|
||||
{
|
||||
// Text updated and the input was previously hidden, show it
|
||||
this->input_->show();
|
||||
}
|
||||
});
|
||||
if (newText.isEmpty())
|
||||
{
|
||||
this->input_->hide();
|
||||
}
|
||||
else if (this->input_->isHidden())
|
||||
{
|
||||
// Text updated and the input was previously hidden, show it
|
||||
this->input_->show();
|
||||
}
|
||||
});
|
||||
|
||||
getSettings()->showEmptyInput.connect(
|
||||
[this](const bool &showEmptyInput, auto) {
|
||||
@@ -367,7 +373,9 @@ Split::Split(QWidget *parent)
|
||||
// Forward textEdit's focusLost event
|
||||
this->focusLost.invoke();
|
||||
});
|
||||
this->input_->ui_.textEdit->imagePasted.connect(
|
||||
|
||||
// this connection can be ignored since the SplitInput is owned by this Split
|
||||
std::ignore = this->input_->ui_.textEdit->imagePasted.connect(
|
||||
[this](const QMimeData *source) {
|
||||
if (!getSettings()->imageUploaderEnabled)
|
||||
return;
|
||||
@@ -896,7 +904,9 @@ void Split::showChangeChannelPopup(const char *dialogTitle, bool empty,
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->setWindowTitle(dialogTitle);
|
||||
dialog->show();
|
||||
dialog->closed.connect([=, this] {
|
||||
// We can safely ignore this signal connection since the dialog will be closed before
|
||||
// this Split is closed
|
||||
std::ignore = dialog->closed.connect([=, this] {
|
||||
if (dialog->hasSeletedChannel())
|
||||
{
|
||||
this->setChannel(dialog->getSelectedChannel());
|
||||
|
||||
+124
-123
@@ -44,43 +44,45 @@ using namespace chatterino;
|
||||
// 5 minutes
|
||||
constexpr const uint64_t THUMBNAIL_MAX_AGE_MS = 5ULL * 60 * 1000;
|
||||
|
||||
auto formatRoomMode(TwitchChannel &channel) -> QString
|
||||
auto formatRoomModeUnclean(
|
||||
const SharedAccessGuard<const TwitchChannel::RoomModes> &modes) -> QString
|
||||
{
|
||||
QString text;
|
||||
|
||||
if (modes->r9k)
|
||||
{
|
||||
auto modes = channel.accessRoomModes();
|
||||
|
||||
if (modes->r9k)
|
||||
text += "r9k, ";
|
||||
}
|
||||
if (modes->slowMode > 0)
|
||||
{
|
||||
text += QString("slow(%1), ").arg(localizeNumbers(modes->slowMode));
|
||||
}
|
||||
if (modes->emoteOnly)
|
||||
{
|
||||
text += "emote, ";
|
||||
}
|
||||
if (modes->submode)
|
||||
{
|
||||
text += "sub, ";
|
||||
}
|
||||
if (modes->followerOnly != -1)
|
||||
{
|
||||
if (modes->followerOnly != 0)
|
||||
{
|
||||
text += "r9k, ";
|
||||
text += QString("follow(%1m), ")
|
||||
.arg(localizeNumbers(modes->followerOnly));
|
||||
}
|
||||
if (modes->slowMode > 0)
|
||||
else
|
||||
{
|
||||
text += QString("slow(%1), ").arg(localizeNumbers(modes->slowMode));
|
||||
}
|
||||
if (modes->emoteOnly)
|
||||
{
|
||||
text += "emote, ";
|
||||
}
|
||||
if (modes->submode)
|
||||
{
|
||||
text += "sub, ";
|
||||
}
|
||||
if (modes->followerOnly != -1)
|
||||
{
|
||||
if (modes->followerOnly != 0)
|
||||
{
|
||||
text += QString("follow(%1m), ")
|
||||
.arg(localizeNumbers(modes->followerOnly));
|
||||
}
|
||||
else
|
||||
{
|
||||
text += QString("follow, ");
|
||||
}
|
||||
text += QString("follow, ");
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
void cleanRoomModeText(QString &text, bool hasModRights)
|
||||
{
|
||||
if (text.length() > 2)
|
||||
{
|
||||
text = text.mid(0, text.size() - 2);
|
||||
@@ -97,12 +99,10 @@ auto formatRoomMode(TwitchChannel &channel) -> QString
|
||||
}
|
||||
}
|
||||
|
||||
if (text.isEmpty() && channel.hasModRights())
|
||||
if (text.isEmpty() && hasModRights)
|
||||
{
|
||||
return "none";
|
||||
text = "none";
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
auto formatTooltip(const TwitchChannel::StreamStatus &s, QString thumbnail)
|
||||
@@ -231,13 +231,16 @@ SplitHeader::SplitHeader(Split *split)
|
||||
this->handleChannelChanged();
|
||||
this->updateModerationModeIcon();
|
||||
|
||||
this->split_->focused.connect([this]() {
|
||||
// The lifetime of these signals are tied to the lifetime of the Split.
|
||||
// Since the SplitHeader is owned by the Split, they will always be destroyed
|
||||
// at the same time.
|
||||
std::ignore = this->split_->focused.connect([this]() {
|
||||
this->themeChangedEvent();
|
||||
});
|
||||
this->split_->focusLost.connect([this]() {
|
||||
std::ignore = this->split_->focusLost.connect([this]() {
|
||||
this->themeChangedEvent();
|
||||
});
|
||||
this->split_->channelChanged.connect([this]() {
|
||||
std::ignore = this->split_->channelChanged.connect([this]() {
|
||||
this->handleChannelChanged();
|
||||
});
|
||||
|
||||
@@ -257,6 +260,8 @@ SplitHeader::SplitHeader(Split *split)
|
||||
|
||||
void SplitHeader::initializeLayout()
|
||||
{
|
||||
assert(this->layout() == nullptr);
|
||||
|
||||
auto *layout = makeLayout<QHBoxLayout>({
|
||||
// space
|
||||
makeWidget<BaseWidget>([](auto w) {
|
||||
@@ -277,7 +282,6 @@ void SplitHeader::initializeLayout()
|
||||
this->modeButton_ = makeWidget<EffectLabel>([&](auto w) {
|
||||
w->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
w->hide();
|
||||
this->initializeModeSignals(*w);
|
||||
w->setMenu(this->createChatModeMenu());
|
||||
}),
|
||||
// moderator
|
||||
@@ -573,43 +577,23 @@ std::unique_ptr<QMenu> SplitHeader::createChatModeMenu()
|
||||
{
|
||||
auto menu = std::make_unique<QMenu>();
|
||||
|
||||
auto *setSub = new QAction("Subscriber only", this);
|
||||
auto *setEmote = new QAction("Emote only", this);
|
||||
auto *setSlow = new QAction("Slow", this);
|
||||
auto *setR9k = new QAction("R9K", this);
|
||||
auto *setFollowers = new QAction("Followers only", this);
|
||||
this->modeActionSetSub = new QAction("Subscriber only", this);
|
||||
this->modeActionSetEmote = new QAction("Emote only", this);
|
||||
this->modeActionSetSlow = new QAction("Slow", this);
|
||||
this->modeActionSetR9k = new QAction("R9K", this);
|
||||
this->modeActionSetFollowers = new QAction("Followers only", this);
|
||||
|
||||
setFollowers->setCheckable(true);
|
||||
setSub->setCheckable(true);
|
||||
setEmote->setCheckable(true);
|
||||
setSlow->setCheckable(true);
|
||||
setR9k->setCheckable(true);
|
||||
this->modeActionSetFollowers->setCheckable(true);
|
||||
this->modeActionSetSub->setCheckable(true);
|
||||
this->modeActionSetEmote->setCheckable(true);
|
||||
this->modeActionSetSlow->setCheckable(true);
|
||||
this->modeActionSetR9k->setCheckable(true);
|
||||
|
||||
menu->addAction(setEmote);
|
||||
menu->addAction(setSub);
|
||||
menu->addAction(setSlow);
|
||||
menu->addAction(setR9k);
|
||||
menu->addAction(setFollowers);
|
||||
|
||||
this->managedConnections_.managedConnect(
|
||||
this->modeUpdateRequested_,
|
||||
[this, setSub, setEmote, setSlow, setR9k, setFollowers]() {
|
||||
auto *twitchChannel =
|
||||
dynamic_cast<TwitchChannel *>(this->split_->getChannel().get());
|
||||
if (twitchChannel == nullptr)
|
||||
{
|
||||
this->modeButton_->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
auto roomModes = twitchChannel->accessRoomModes();
|
||||
|
||||
setR9k->setChecked(roomModes->r9k);
|
||||
setSlow->setChecked(roomModes->slowMode > 0);
|
||||
setEmote->setChecked(roomModes->emoteOnly);
|
||||
setSub->setChecked(roomModes->submode);
|
||||
setFollowers->setChecked(roomModes->followerOnly != -1);
|
||||
});
|
||||
menu->addAction(this->modeActionSetEmote);
|
||||
menu->addAction(this->modeActionSetSub);
|
||||
menu->addAction(this->modeActionSetSlow);
|
||||
menu->addAction(this->modeActionSetR9k);
|
||||
menu->addAction(this->modeActionSetFollowers);
|
||||
|
||||
auto execCommand = [this](const QString &command) {
|
||||
auto text = getApp()->getCommands()->execCommand(
|
||||
@@ -622,44 +606,44 @@ std::unique_ptr<QMenu> SplitHeader::createChatModeMenu()
|
||||
action->setChecked(!action->isChecked());
|
||||
};
|
||||
|
||||
QObject::connect(setSub, &QAction::triggered, this,
|
||||
[setSub, toggle]() mutable {
|
||||
toggle("/subscribers", setSub);
|
||||
QObject::connect(this->modeActionSetSub, &QAction::triggered, this,
|
||||
[this, toggle]() mutable {
|
||||
toggle("/subscribers", this->modeActionSetSub);
|
||||
});
|
||||
|
||||
QObject::connect(setEmote, &QAction::triggered, this,
|
||||
[setEmote, toggle]() mutable {
|
||||
toggle("/emoteonly", setEmote);
|
||||
QObject::connect(this->modeActionSetEmote, &QAction::triggered, this,
|
||||
[this, toggle]() mutable {
|
||||
toggle("/emoteonly", this->modeActionSetEmote);
|
||||
});
|
||||
|
||||
QObject::connect(
|
||||
setSlow, &QAction::triggered, this, [setSlow, this, execCommand]() {
|
||||
if (!setSlow->isChecked())
|
||||
{
|
||||
execCommand("/slowoff");
|
||||
setSlow->setChecked(false);
|
||||
return;
|
||||
};
|
||||
auto ok = bool();
|
||||
auto seconds =
|
||||
QInputDialog::getInt(this, "", "Seconds:", 10, 0, 500, 1, &ok,
|
||||
Qt::FramelessWindowHint);
|
||||
if (ok)
|
||||
{
|
||||
execCommand(QString("/slow %1").arg(seconds));
|
||||
}
|
||||
else
|
||||
{
|
||||
setSlow->setChecked(false);
|
||||
}
|
||||
});
|
||||
QObject::connect(this->modeActionSetSlow, &QAction::triggered, this,
|
||||
[this, execCommand]() {
|
||||
if (!this->modeActionSetSlow->isChecked())
|
||||
{
|
||||
execCommand("/slowoff");
|
||||
this->modeActionSetSlow->setChecked(false);
|
||||
return;
|
||||
};
|
||||
auto ok = bool();
|
||||
auto seconds = QInputDialog::getInt(
|
||||
this, "", "Seconds:", 10, 0, 500, 1, &ok,
|
||||
Qt::FramelessWindowHint);
|
||||
if (ok)
|
||||
{
|
||||
execCommand(QString("/slow %1").arg(seconds));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->modeActionSetSlow->setChecked(false);
|
||||
}
|
||||
});
|
||||
|
||||
QObject::connect(setFollowers, &QAction::triggered, this,
|
||||
[setFollowers, this, execCommand]() {
|
||||
if (!setFollowers->isChecked())
|
||||
QObject::connect(this->modeActionSetFollowers, &QAction::triggered, this,
|
||||
[this, execCommand]() {
|
||||
if (!this->modeActionSetFollowers->isChecked())
|
||||
{
|
||||
execCommand("/followersoff");
|
||||
setFollowers->setChecked(false);
|
||||
this->modeActionSetFollowers->setChecked(false);
|
||||
return;
|
||||
};
|
||||
auto ok = bool();
|
||||
@@ -673,13 +657,13 @@ std::unique_ptr<QMenu> SplitHeader::createChatModeMenu()
|
||||
}
|
||||
else
|
||||
{
|
||||
setFollowers->setChecked(false);
|
||||
this->modeActionSetFollowers->setChecked(false);
|
||||
}
|
||||
});
|
||||
|
||||
QObject::connect(setR9k, &QAction::triggered, this,
|
||||
[setR9k, toggle]() mutable {
|
||||
toggle("/r9kbeta", setR9k);
|
||||
QObject::connect(this->modeActionSetR9k, &QAction::triggered, this,
|
||||
[this, toggle]() mutable {
|
||||
toggle("/r9kbeta", this->modeActionSetR9k);
|
||||
});
|
||||
|
||||
return menu;
|
||||
@@ -687,30 +671,47 @@ std::unique_ptr<QMenu> SplitHeader::createChatModeMenu()
|
||||
|
||||
void SplitHeader::updateRoomModes()
|
||||
{
|
||||
this->modeUpdateRequested_.invoke();
|
||||
}
|
||||
assert(this->modeButton_ != nullptr);
|
||||
|
||||
void SplitHeader::initializeModeSignals(EffectLabel &label)
|
||||
{
|
||||
this->modeUpdateRequested_.connect([this, &label] {
|
||||
if (auto *twitchChannel =
|
||||
dynamic_cast<TwitchChannel *>(this->split_->getChannel().get()))
|
||||
// Update the mode button
|
||||
if (auto *twitchChannel =
|
||||
dynamic_cast<TwitchChannel *>(this->split_->getChannel().get()))
|
||||
{
|
||||
this->modeButton_->setEnable(twitchChannel->hasModRights());
|
||||
|
||||
QString text;
|
||||
{
|
||||
label.setEnable(twitchChannel->hasModRights());
|
||||
auto roomModes = twitchChannel->accessRoomModes();
|
||||
text = formatRoomModeUnclean(roomModes);
|
||||
|
||||
// set the label text
|
||||
auto text = formatRoomMode(*twitchChannel);
|
||||
// Set menu action
|
||||
this->modeActionSetR9k->setChecked(roomModes->r9k);
|
||||
this->modeActionSetSlow->setChecked(roomModes->slowMode > 0);
|
||||
this->modeActionSetEmote->setChecked(roomModes->emoteOnly);
|
||||
this->modeActionSetSub->setChecked(roomModes->submode);
|
||||
this->modeActionSetFollowers->setChecked(roomModes->followerOnly !=
|
||||
-1);
|
||||
}
|
||||
cleanRoomModeText(text, twitchChannel->hasModRights());
|
||||
|
||||
if (!text.isEmpty())
|
||||
{
|
||||
label.getLabel().setText(text);
|
||||
label.show();
|
||||
return;
|
||||
}
|
||||
// set the label text
|
||||
|
||||
if (!text.isEmpty())
|
||||
{
|
||||
this->modeButton_->getLabel().setText(text);
|
||||
this->modeButton_->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->modeButton_->hide();
|
||||
}
|
||||
|
||||
label.hide();
|
||||
});
|
||||
// Update the mode button menu actions
|
||||
}
|
||||
else
|
||||
{
|
||||
this->modeButton_->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void SplitHeader::resetThumbnail()
|
||||
|
||||
@@ -32,6 +32,8 @@ public:
|
||||
|
||||
void updateChannelText();
|
||||
void updateModerationModeIcon();
|
||||
// Invoked when SplitHeader should update anything refering to a TwitchChannel's mode
|
||||
// has changed (e.g. sub mode toggled)
|
||||
void updateRoomModes();
|
||||
|
||||
protected:
|
||||
@@ -75,7 +77,14 @@ private:
|
||||
// ui
|
||||
Button *dropdownButton_{};
|
||||
Label *titleLabel_{};
|
||||
|
||||
EffectLabel *modeButton_{};
|
||||
QAction *modeActionSetEmote{};
|
||||
QAction *modeActionSetSub{};
|
||||
QAction *modeActionSetSlow{};
|
||||
QAction *modeActionSetR9k{};
|
||||
QAction *modeActionSetFollowers{};
|
||||
|
||||
Button *moderationButton_{};
|
||||
Button *viewersButton_{};
|
||||
Button *addButton_{};
|
||||
@@ -86,8 +95,8 @@ private:
|
||||
bool doubleClicked_{false};
|
||||
bool menuVisible_{false};
|
||||
|
||||
// signals
|
||||
pajlada::Signals::NoArgSignal modeUpdateRequested_;
|
||||
// managedConnections_ contains connections for signals that are not managed by us
|
||||
// and don't change when the parent Split changes its underlying channel
|
||||
pajlada::Signals::SignalHolder managedConnections_;
|
||||
pajlada::Signals::SignalHolder channelConnections_;
|
||||
std::vector<boost::signals2::scoped_connection> bSignals_;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -91,6 +91,9 @@ protected:
|
||||
void addShortcuts() override;
|
||||
void initLayout();
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
#ifdef DEBUG
|
||||
bool keyPressedEventInstalled{};
|
||||
#endif
|
||||
void installKeyPressedEvent();
|
||||
void onCursorPositionChanged();
|
||||
void onTextChanged();
|
||||
|
||||
Reference in New Issue
Block a user