Fix crash happening when QuickSwitcher is used with popout window (#4187)

Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com>
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
kornes 2022-11-25 09:34:01 +00:00 committed by GitHub
parent b3e400a049
commit 330e0a99fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 31 deletions

View file

@ -2,6 +2,7 @@
## Unversioned
- Bugfix: Fixed crash happening when QuickSwitcher is used with a popout window. (#4187)
- Bugfix: Fixed low contrast of text in settings tooltips. (#4188)
- Bugfix: Fixed being unable to see the usercard of VIPs who have Asian language display names. (#4174)
- Bugfix: Fixed the wrong right-click menu showing in the chat input box. (#4177)

View file

@ -156,54 +156,58 @@ int Notebook::indexOf(QWidget *page) const
void Notebook::select(QWidget *page, bool focusPage)
{
if (!page)
{
return;
}
if (page == this->selectedPage_)
{
return;
}
if (page != nullptr)
auto *item = this->findItem(page);
if (!item)
{
page->setHidden(false);
return;
}
assert(this->containsPage(page));
Item &item = this->findItem(page);
page->show();
item.tab->setSelected(true);
item.tab->raise();
item->tab->setSelected(true);
item->tab->raise();
if (focusPage)
if (focusPage)
{
if (item->selectedWidget == nullptr)
{
if (item.selectedWidget == nullptr)
item->page->setFocus();
}
else
{
if (containsChild(page, item->selectedWidget))
{
item.page->setFocus();
item->selectedWidget->setFocus(Qt::MouseFocusReason);
}
else
{
if (containsChild(page, item.selectedWidget))
{
item.selectedWidget->setFocus(Qt::MouseFocusReason);
}
else
{
qCDebug(chatterinoWidget) << "Notebook: selected child of "
"page doesn't exist anymore";
}
qCDebug(chatterinoWidget) << "Notebook: selected child of "
"page doesn't exist anymore";
}
}
}
if (this->selectedPage_ != nullptr)
{
this->selectedPage_->setHidden(true);
this->selectedPage_->hide();
Item &item = this->findItem(selectedPage_);
item.tab->setSelected(false);
// for (auto split : this->selectedPage->getSplits()) {
// split->updateLastReadMessage();
// }
item.selectedWidget = this->selectedPage_->focusWidget();
auto *item = this->findItem(selectedPage_);
if (!item)
{
return;
}
item->tab->setSelected(false);
item->selectedWidget = this->selectedPage_->focusWidget();
}
this->selectedPage_ = page;
@ -219,14 +223,17 @@ bool Notebook::containsPage(QWidget *page)
});
}
Notebook::Item &Notebook::findItem(QWidget *page)
Notebook::Item *Notebook::findItem(QWidget *page)
{
auto it = std::find_if(this->items_.begin(), this->items_.end(),
[page](const auto &item) {
return page == item.page;
});
assert(it != this->items_.end());
return *it;
if (it != this->items_.end())
{
return &(*it);
}
return nullptr;
}
bool Notebook::containsChild(const QObject *obj, const QObject *child)

View file

@ -90,7 +90,7 @@ private:
void resizeAddButton();
bool containsPage(QWidget *page);
Item &findItem(QWidget *page);
Item *findItem(QWidget *page);
static bool containsChild(const QObject *obj, const QObject *child);
NotebookTab *getTabFromPage(QWidget *page);