Notebook::select now takes the optional parameter "focusPage". (#3446)

This commit is contained in:
pajlada 2022-01-02 15:00:19 +01:00 committed by GitHub
parent b031fc41ef
commit 2b9e2bd1b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 27 deletions

View file

@ -82,6 +82,7 @@
- Dev: Renamed CMake's build option `USE_SYSTEM_QT5KEYCHAIN` to `USE_SYSTEM_QTKEYCHAIN`. (#3103) - Dev: Renamed CMake's build option `USE_SYSTEM_QT5KEYCHAIN` to `USE_SYSTEM_QTKEYCHAIN`. (#3103)
- Dev: Add benchmarks that can be compiled with the `BUILD_BENCHMARKS` CMake flag. Off by default. (#3038) - Dev: Add benchmarks that can be compiled with the `BUILD_BENCHMARKS` CMake flag. Off by default. (#3038)
- Dev: Added CMake build option `BUILD_WITH_QTKEYCHAIN` to build with or without Qt5Keychain support (On by default). (#3318) - Dev: Added CMake build option `BUILD_WITH_QTKEYCHAIN` to build with or without Qt5Keychain support (On by default). (#3318)
- Dev: Notebook::select\* functions now take an optional `focusPage` parameter (true by default) which keeps the default behaviour of selecting the page after it has been selected. If set to false, the page is _not_ focused after being selected. (#3446)
## 2.3.4 ## 2.3.4

View file

@ -131,7 +131,7 @@ int Notebook::indexOf(QWidget *page) const
return -1; return -1;
} }
void Notebook::select(QWidget *page) void Notebook::select(QWidget *page, bool focusPage)
{ {
if (page == this->selectedPage_) if (page == this->selectedPage_)
{ {
@ -148,20 +148,23 @@ void Notebook::select(QWidget *page)
item.tab->setSelected(true); item.tab->setSelected(true);
item.tab->raise(); item.tab->raise();
if (item.selectedWidget == nullptr) if (focusPage)
{ {
item.page->setFocus(); if (item.selectedWidget == nullptr)
}
else
{
if (containsChild(page, item.selectedWidget))
{ {
item.selectedWidget->setFocus(Qt::MouseFocusReason); item.page->setFocus();
} }
else else
{ {
qCDebug(chatterinoWidget) if (containsChild(page, item.selectedWidget))
<< "Notebook: selected child of page doesn't exist anymore"; {
item.selectedWidget->setFocus(Qt::MouseFocusReason);
}
else
{
qCDebug(chatterinoWidget) << "Notebook: selected child of "
"page doesn't exist anymore";
}
} }
} }
} }
@ -216,17 +219,17 @@ bool Notebook::containsChild(const QObject *obj, const QObject *child)
}); });
} }
void Notebook::selectIndex(int index) void Notebook::selectIndex(int index, bool focusPage)
{ {
if (index < 0 || this->items_.count() <= index) if (index < 0 || this->items_.count() <= index)
{ {
return; return;
} }
this->select(this->items_[index].page); this->select(this->items_[index].page, focusPage);
} }
void Notebook::selectNextTab() void Notebook::selectNextTab(bool focusPage)
{ {
if (this->items_.size() <= 1) if (this->items_.size() <= 1)
{ {
@ -236,10 +239,10 @@ void Notebook::selectNextTab()
auto index = auto index =
(this->indexOf(this->selectedPage_) + 1) % this->items_.count(); (this->indexOf(this->selectedPage_) + 1) % this->items_.count();
this->select(this->items_[index].page); this->select(this->items_[index].page, focusPage);
} }
void Notebook::selectPreviousTab() void Notebook::selectPreviousTab(bool focusPage)
{ {
if (this->items_.size() <= 1) if (this->items_.size() <= 1)
{ {
@ -253,10 +256,10 @@ void Notebook::selectPreviousTab()
index += this->items_.count(); index += this->items_.count();
} }
this->select(this->items_[index].page); this->select(this->items_[index].page, focusPage);
} }
void Notebook::selectLastTab() void Notebook::selectLastTab(bool focusPage)
{ {
const auto size = this->items_.size(); const auto size = this->items_.size();
if (size <= 1) if (size <= 1)
@ -264,7 +267,7 @@ void Notebook::selectLastTab()
return; return;
} }
this->select(this->items_[size - 1].page); this->select(this->items_[size - 1].page, focusPage);
} }
int Notebook::getPageCount() const int Notebook::getPageCount() const
@ -806,7 +809,7 @@ SplitContainer *SplitNotebook::getOrAddSelectedPage()
: this->addPage(); : this->addPage();
} }
void SplitNotebook::select(QWidget *page) void SplitNotebook::select(QWidget *page, bool focusPage)
{ {
if (auto selectedPage = this->getSelectedPage()) if (auto selectedPage = this->getSelectedPage())
{ {
@ -818,7 +821,7 @@ void SplitNotebook::select(QWidget *page)
} }
} }
} }
this->Notebook::select(page); this->Notebook::select(page, focusPage);
} }
} // namespace chatterino } // namespace chatterino

View file

@ -33,11 +33,11 @@ public:
void removeCurrentPage(); void removeCurrentPage();
int indexOf(QWidget *page) const; int indexOf(QWidget *page) const;
virtual void select(QWidget *page); virtual void select(QWidget *page, bool focusPage = true);
void selectIndex(int index); void selectIndex(int index, bool focusPage = true);
void selectNextTab(); void selectNextTab(bool focusPage = true);
void selectPreviousTab(); void selectPreviousTab(bool focusPage = true);
void selectLastTab(); void selectLastTab(bool focusPage = true);
int getPageCount() const; int getPageCount() const;
QWidget *getPageAt(int index) const; QWidget *getPageAt(int index) const;
@ -108,7 +108,7 @@ public:
SplitContainer *addPage(bool select = false); SplitContainer *addPage(bool select = false);
SplitContainer *getOrAddSelectedPage(); SplitContainer *getOrAddSelectedPage();
void select(QWidget *page) override; void select(QWidget *page, bool focusPage = true) override;
protected: protected:
void showEvent(QShowEvent *event) override; void showEvent(QShowEvent *event) override;

View file

@ -203,7 +203,7 @@ void EmotePopup::addShortcuts()
int result = target.toInt(&ok); int result = target.toInt(&ok);
if (ok) if (ok)
{ {
this->notebook_->selectIndex(result); this->notebook_->selectIndex(result, false);
} }
else else
{ {