Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
- 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: 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

Expand Down
43 changes: 23 additions & 20 deletions src/widgets/Notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int Notebook::indexOf(QWidget *page) const
return -1;
}

void Notebook::select(QWidget *page)
void Notebook::select(QWidget *page, bool focusPage)
{
if (page == this->selectedPage_)
{
Expand All @@ -148,20 +148,23 @@ void Notebook::select(QWidget *page)
item.tab->setSelected(true);
item.tab->raise();

if (item.selectedWidget == nullptr)
if (focusPage)
{
item.page->setFocus();
}
else
{
if (containsChild(page, item.selectedWidget))
if (item.selectedWidget == nullptr)
{
item.selectedWidget->setFocus(Qt::MouseFocusReason);
item.page->setFocus();
}
else
{
qCDebug(chatterinoWidget)
<< "Notebook: selected child of page doesn't exist anymore";
if (containsChild(page, item.selectedWidget))
{
item.selectedWidget->setFocus(Qt::MouseFocusReason);
}
else
{
qCDebug(chatterinoWidget) << "Notebook: selected child of "
"page doesn't exist anymore";
}
}
}
}
Expand Down Expand Up @@ -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)
{
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)
{
Expand All @@ -236,10 +239,10 @@ void Notebook::selectNextTab()
auto index =
(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)
{
Expand All @@ -253,18 +256,18 @@ void Notebook::selectPreviousTab()
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();
if (size <= 1)
{
return;
}

this->select(this->items_[size - 1].page);
this->select(this->items_[size - 1].page, focusPage);
}

int Notebook::getPageCount() const
Expand Down Expand Up @@ -806,7 +809,7 @@ SplitContainer *SplitNotebook::getOrAddSelectedPage()
: this->addPage();
}

void SplitNotebook::select(QWidget *page)
void SplitNotebook::select(QWidget *page, bool focusPage)
{
if (auto selectedPage = this->getSelectedPage())
{
Expand All @@ -818,7 +821,7 @@ void SplitNotebook::select(QWidget *page)
}
}
}
this->Notebook::select(page);
this->Notebook::select(page, focusPage);
}

} // namespace chatterino
12 changes: 6 additions & 6 deletions src/widgets/Notebook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class Notebook : public BaseWidget
void removeCurrentPage();

int indexOf(QWidget *page) const;
virtual void select(QWidget *page);
void selectIndex(int index);
void selectNextTab();
void selectPreviousTab();
void selectLastTab();
virtual void select(QWidget *page, bool focusPage = true);
void selectIndex(int index, bool focusPage = true);
void selectNextTab(bool focusPage = true);
void selectPreviousTab(bool focusPage = true);
void selectLastTab(bool focusPage = true);

int getPageCount() const;
QWidget *getPageAt(int index) const;
Expand Down Expand Up @@ -108,7 +108,7 @@ class SplitNotebook : public Notebook

SplitContainer *addPage(bool select = false);
SplitContainer *getOrAddSelectedPage();
void select(QWidget *page) override;
void select(QWidget *page, bool focusPage = true) override;

protected:
void showEvent(QShowEvent *event) override;
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/dialogs/EmotePopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void EmotePopup::addShortcuts()
int result = target.toInt(&ok);
if (ok)
{
this->notebook_->selectIndex(result);
this->notebook_->selectIndex(result, false);
}
else
{
Expand Down