2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/Notebook.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
2020-11-21 16:20:10 +01:00
|
|
|
#include "common/QLogging.hpp"
|
2022-10-09 17:20:44 +02:00
|
|
|
#include "controllers/hotkeys/HotkeyCategory.hpp"
|
|
|
|
#include "controllers/hotkeys/HotkeyController.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
2018-06-28 20:03:04 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "singletons/WindowManager.hpp"
|
2018-07-05 12:52:36 +02:00
|
|
|
#include "util/InitUpdateButton.hpp"
|
2018-06-26 17:20:03 +02:00
|
|
|
#include "widgets/dialogs/SettingsDialog.hpp"
|
2022-09-11 16:37:13 +02:00
|
|
|
#include "widgets/helper/ChannelView.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/helper/NotebookButton.hpp"
|
|
|
|
#include "widgets/helper/NotebookTab.hpp"
|
2018-10-20 13:25:24 +02:00
|
|
|
#include "widgets/splits/Split.hpp"
|
2018-06-26 14:39:22 +02:00
|
|
|
#include "widgets/splits/SplitContainer.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "widgets/Window.hpp"
|
2016-12-29 17:31:07 +01:00
|
|
|
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include <boost/foreach.hpp>
|
2017-01-28 22:35:23 +01:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QFile>
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QLayout>
|
|
|
|
#include <QList>
|
2017-01-28 22:35:23 +01:00
|
|
|
#include <QStandardPaths>
|
2017-12-22 14:44:31 +01:00
|
|
|
#include <QUuid>
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QWidget>
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
Notebook::Notebook(QWidget *parent)
|
2018-04-27 22:11:19 +02:00
|
|
|
: BaseWidget(parent)
|
2021-05-30 13:39:34 +02:00
|
|
|
, menu_(this)
|
2018-08-11 22:23:06 +02:00
|
|
|
, addButton_(new NotebookButton(this))
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-08-11 22:23:06 +02:00
|
|
|
this->addButton_->setIcon(NotebookButton::Icon::Plus);
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
this->addButton_->setHidden(true);
|
2021-05-30 13:39:34 +02:00
|
|
|
|
2022-03-26 14:16:45 +01:00
|
|
|
this->lockNotebookLayoutAction_ = new QAction("Lock Tab Layout", this);
|
|
|
|
|
|
|
|
// Load lock notebook layout state from settings
|
|
|
|
this->setLockNotebookLayout(getSettings()->lockNotebookLayout.getValue());
|
|
|
|
|
|
|
|
this->lockNotebookLayoutAction_->setCheckable(true);
|
|
|
|
this->lockNotebookLayoutAction_->setChecked(this->lockNotebookLayout_);
|
|
|
|
|
|
|
|
// Update lockNotebookLayout_ value anytime the user changes the checkbox state
|
|
|
|
QObject::connect(this->lockNotebookLayoutAction_, &QAction::triggered,
|
|
|
|
[this](bool value) {
|
|
|
|
this->setLockNotebookLayout(value);
|
|
|
|
});
|
2022-10-09 17:20:44 +02:00
|
|
|
this->showTabsAction_ = new QAction("Toggle visibility of tabs");
|
|
|
|
QObject::connect(this->showTabsAction_, &QAction::triggered, [this]() {
|
|
|
|
this->setShowTabs(!this->getShowTabs());
|
|
|
|
});
|
|
|
|
this->updateTabVisibilityMenuAction();
|
2022-03-26 14:16:45 +01:00
|
|
|
|
|
|
|
this->addNotebookActionsToMenu(&this->menu_);
|
2022-07-23 16:09:12 +02:00
|
|
|
|
|
|
|
// Manually resize the add button so the initial paint uses the correct
|
|
|
|
// width when computing the maximum width occupied per column in vertical
|
|
|
|
// tab rendering.
|
|
|
|
this->resizeAddButton();
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
NotebookTab *Notebook::addPage(QWidget *page, QString title, bool select)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-07 18:27:40 +02:00
|
|
|
// Queue up save because: Tab added
|
|
|
|
getApp()->windows->queueSave();
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
auto *tab = new NotebookTab(this);
|
2018-04-18 09:12:29 +02:00
|
|
|
tab->page = page;
|
|
|
|
|
2018-06-01 16:01:49 +02:00
|
|
|
tab->setCustomTitle(title);
|
2022-11-08 22:46:43 +01:00
|
|
|
tab->setTabLocation(this->tabLocation_);
|
2018-04-18 17:51:53 +02:00
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
Item item;
|
|
|
|
item.page = page;
|
|
|
|
item.tab = tab;
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->items_.append(item);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
page->hide();
|
|
|
|
page->setParent(this);
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (select || this->items_.count() == 1)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
this->select(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->performLayout();
|
|
|
|
|
2018-06-04 12:54:09 +02:00
|
|
|
tab->show();
|
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::removePage(QWidget *page)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-07 18:27:40 +02:00
|
|
|
// Queue up save because: Tab removed
|
|
|
|
getApp()->windows->queueSave();
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (int i = 0; i < this->items_.count(); i++)
|
|
|
|
{
|
|
|
|
if (this->items_[i].page == page)
|
|
|
|
{
|
|
|
|
if (this->items_.count() == 1)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
this->select(nullptr);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (i == this->items_.count() - 1)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->select(this->items_[i - 1].page);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->select(this->items_[i + 1].page);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->items_[i].page->deleteLater();
|
|
|
|
this->items_[i].tab->deleteLater();
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
// if (this->items.empty()) {
|
|
|
|
// this->addNewPage();
|
|
|
|
// }
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->items_.removeAt(i);
|
2018-04-18 09:12:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-05-23 04:22:17 +02:00
|
|
|
|
2018-06-01 14:46:41 +02:00
|
|
|
this->performLayout(true);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::removeCurrentPage()
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->selectedPage_ != nullptr)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->removePage(this->selectedPage_);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
int Notebook::indexOf(QWidget *page) const
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
for (int i = 0; i < this->items_.count(); i++)
|
|
|
|
{
|
|
|
|
if (this->items_[i].page == page)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-01-02 15:00:19 +01:00
|
|
|
void Notebook::select(QWidget *page, bool focusPage)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (page == this->selectedPage_)
|
|
|
|
{
|
2022-12-29 19:15:32 +01:00
|
|
|
// Nothing has changed
|
2018-04-18 09:12:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-29 19:15:32 +01:00
|
|
|
if (page)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2022-12-29 19:15:32 +01:00
|
|
|
// A new page has been selected, mark it as selected & focus one of its splits
|
|
|
|
auto *item = this->findItem(page);
|
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2022-12-29 19:15:32 +01:00
|
|
|
page->show();
|
2018-05-31 16:02:20 +02:00
|
|
|
|
2022-12-29 19:15:32 +01:00
|
|
|
item->tab->setSelected(true);
|
|
|
|
item->tab->raise();
|
2018-05-31 16:02:20 +02:00
|
|
|
|
2022-12-29 19:15:32 +01:00
|
|
|
if (focusPage)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2022-12-29 19:15:32 +01:00
|
|
|
if (item->selectedWidget == nullptr)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2022-12-29 19:15:32 +01:00
|
|
|
item->page->setFocus();
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-29 19:15:32 +01:00
|
|
|
if (containsChild(page, item->selectedWidget))
|
|
|
|
{
|
|
|
|
item->selectedWidget->setFocus(Qt::MouseFocusReason);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qCDebug(chatterinoWidget) << "Notebook: selected child of "
|
|
|
|
"page doesn't exist anymore";
|
|
|
|
}
|
2018-05-31 16:02:20 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2022-12-29 19:15:32 +01:00
|
|
|
if (this->selectedPage_)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2022-12-29 19:15:32 +01:00
|
|
|
// Hide the previously selected page
|
2022-11-25 10:34:01 +01:00
|
|
|
this->selectedPage_->hide();
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2022-11-25 10:34:01 +01:00
|
|
|
auto *item = this->findItem(selectedPage_);
|
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
item->tab->setSelected(false);
|
|
|
|
item->selectedWidget = this->selectedPage_->focusWidget();
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->selectedPage_ = page;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
this->performLayout();
|
|
|
|
}
|
|
|
|
|
2018-05-31 16:02:20 +02:00
|
|
|
bool Notebook::containsPage(QWidget *page)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return std::any_of(this->items_.begin(), this->items_.end(),
|
2020-11-08 12:02:19 +01:00
|
|
|
[page](const auto &item) {
|
|
|
|
return item.page == page;
|
|
|
|
});
|
2018-05-31 16:02:20 +02:00
|
|
|
}
|
|
|
|
|
2022-11-25 10:34:01 +01:00
|
|
|
Notebook::Item *Notebook::findItem(QWidget *page)
|
2018-05-31 16:02:20 +02:00
|
|
|
{
|
2020-11-08 12:02:19 +01:00
|
|
|
auto it = std::find_if(this->items_.begin(), this->items_.end(),
|
|
|
|
[page](const auto &item) {
|
|
|
|
return page == item.page;
|
|
|
|
});
|
2022-11-25 10:34:01 +01:00
|
|
|
if (it != this->items_.end())
|
|
|
|
{
|
|
|
|
return &(*it);
|
|
|
|
}
|
|
|
|
return nullptr;
|
2018-05-31 16:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Notebook::containsChild(const QObject *obj, const QObject *child)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
return std::any_of(obj->children().begin(), obj->children().end(),
|
|
|
|
[child](const QObject *o) {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (o == child)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
2018-05-31 16:02:20 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
return containsChild(o, child);
|
|
|
|
});
|
2018-05-31 16:02:20 +02:00
|
|
|
}
|
|
|
|
|
2022-01-02 15:00:19 +01:00
|
|
|
void Notebook::selectIndex(int index, bool focusPage)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (index < 0 || this->items_.count() <= index)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-02 15:00:19 +01:00
|
|
|
this->select(this->items_[index].page, focusPage);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2022-01-02 15:00:19 +01:00
|
|
|
void Notebook::selectNextTab(bool focusPage)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->items_.size() <= 1)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
auto index =
|
|
|
|
(this->indexOf(this->selectedPage_) + 1) % this->items_.count();
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2022-01-02 15:00:19 +01:00
|
|
|
this->select(this->items_[index].page, focusPage);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2022-01-02 15:00:19 +01:00
|
|
|
void Notebook::selectPreviousTab(bool focusPage)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->items_.size() <= 1)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
int index = this->indexOf(this->selectedPage_) - 1;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (index < 0)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
index += this->items_.count();
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2022-01-02 15:00:19 +01:00
|
|
|
this->select(this->items_[index].page, focusPage);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2022-01-02 15:00:19 +01:00
|
|
|
void Notebook::selectLastTab(bool focusPage)
|
2019-08-04 16:22:48 +02:00
|
|
|
{
|
|
|
|
const auto size = this->items_.size();
|
|
|
|
if (size <= 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-02 15:00:19 +01:00
|
|
|
this->select(this->items_[size - 1].page, focusPage);
|
2019-08-04 16:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
int Notebook::getPageCount() const
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->items_.count();
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
QWidget *Notebook::getPageAt(int index) const
|
2018-05-23 04:22:17 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->items_[index].page;
|
2018-05-23 04:22:17 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
int Notebook::getSelectedIndex() const
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->indexOf(this->selectedPage_);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
QWidget *Notebook::getSelectedPage() const
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->selectedPage_;
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
QWidget *Notebook::tabAt(QPoint point, int &index, int maxWidth)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 12:13:09 +02:00
|
|
|
auto i = 0;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &item : this->items_)
|
|
|
|
{
|
2018-10-21 12:13:09 +02:00
|
|
|
auto rect = item.tab->getDesiredRect();
|
2018-11-21 21:37:41 +01:00
|
|
|
rect.setHeight(int(this->scale() * 24));
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
rect.setWidth(std::min(maxWidth, rect.width()));
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (rect.contains(point))
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
index = i;
|
|
|
|
return item.page;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = -1;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::rearrangePage(QWidget *page, int index)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2022-03-26 14:16:45 +01:00
|
|
|
if (this->isNotebookLayoutLocked())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-07 18:27:40 +02:00
|
|
|
// Queue up save because: Tab rearranged
|
|
|
|
getApp()->windows->queueSave();
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->items_.move(this->indexOf(page), index);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-06-01 14:46:41 +02:00
|
|
|
this->performLayout(true);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
bool Notebook::getAllowUserTabManagement() const
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->allowUserTabManagement_;
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::setAllowUserTabManagement(bool value)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->allowUserTabManagement_ = value;
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2021-05-30 13:39:34 +02:00
|
|
|
bool Notebook::getShowTabs() const
|
|
|
|
{
|
|
|
|
return this->showTabs_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Notebook::setShowTabs(bool value)
|
|
|
|
{
|
|
|
|
this->showTabs_ = value;
|
|
|
|
|
|
|
|
this->performLayout();
|
|
|
|
for (auto &item : this->items_)
|
|
|
|
{
|
|
|
|
item.tab->setHidden(!value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->setShowAddButton(value);
|
|
|
|
|
|
|
|
// show a popup upon hiding tabs
|
|
|
|
if (!value && getSettings()->informOnTabVisibilityToggle.getValue())
|
|
|
|
{
|
2022-10-09 17:20:44 +02:00
|
|
|
auto unhideSeq = getApp()->hotkeys->getDisplaySequence(
|
|
|
|
HotkeyCategory::Window, "setTabVisibility", {{}});
|
|
|
|
if (unhideSeq.isEmpty())
|
|
|
|
{
|
|
|
|
unhideSeq = getApp()->hotkeys->getDisplaySequence(
|
|
|
|
HotkeyCategory::Window, "setTabVisibility", {{"toggle"}});
|
|
|
|
}
|
|
|
|
if (unhideSeq.isEmpty())
|
|
|
|
{
|
|
|
|
unhideSeq = getApp()->hotkeys->getDisplaySequence(
|
|
|
|
HotkeyCategory::Window, "setTabVisibility", {{"on"}});
|
|
|
|
}
|
|
|
|
QString hotkeyInfo = "(currently unbound)";
|
|
|
|
if (!unhideSeq.isEmpty())
|
|
|
|
{
|
|
|
|
hotkeyInfo =
|
|
|
|
"(" +
|
|
|
|
unhideSeq.toString(QKeySequence::SequenceFormat::NativeText) +
|
|
|
|
")";
|
|
|
|
}
|
2022-04-16 10:59:20 +02:00
|
|
|
QMessageBox msgBox(this->window());
|
2021-05-30 13:39:34 +02:00
|
|
|
msgBox.window()->setWindowTitle("Chatterino - hidden tabs");
|
2021-06-21 11:35:53 +02:00
|
|
|
msgBox.setText("You've just hidden your tabs.");
|
2021-05-30 13:39:34 +02:00
|
|
|
msgBox.setInformativeText(
|
2022-10-09 17:20:44 +02:00
|
|
|
"You can toggle tabs by using the keyboard shortcut " + hotkeyInfo +
|
|
|
|
" or right-clicking the tab area and selecting \"Toggle "
|
2021-05-30 13:39:34 +02:00
|
|
|
"visibility of tabs\".");
|
|
|
|
msgBox.addButton(QMessageBox::Ok);
|
|
|
|
auto *dsaButton =
|
|
|
|
msgBox.addButton("Don't show again", QMessageBox::YesRole);
|
|
|
|
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
|
|
|
msgBox.exec();
|
|
|
|
|
|
|
|
if (msgBox.clickedButton() == dsaButton)
|
|
|
|
{
|
|
|
|
getSettings()->informOnTabVisibilityToggle.setValue(false);
|
|
|
|
}
|
|
|
|
}
|
2022-10-09 17:20:44 +02:00
|
|
|
updateTabVisibilityMenuAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Notebook::updateTabVisibilityMenuAction()
|
|
|
|
{
|
|
|
|
auto toggleSeq = getApp()->hotkeys->getDisplaySequence(
|
|
|
|
HotkeyCategory::Window, "setTabVisibility", {{}});
|
|
|
|
if (toggleSeq.isEmpty())
|
|
|
|
{
|
|
|
|
toggleSeq = getApp()->hotkeys->getDisplaySequence(
|
|
|
|
HotkeyCategory::Window, "setTabVisibility", {{"toggle"}});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toggleSeq.isEmpty())
|
|
|
|
{
|
|
|
|
// show contextual shortcuts
|
|
|
|
if (this->getShowTabs())
|
|
|
|
{
|
|
|
|
toggleSeq = getApp()->hotkeys->getDisplaySequence(
|
|
|
|
HotkeyCategory::Window, "setTabVisibility", {{"off"}});
|
|
|
|
}
|
|
|
|
else if (!this->getShowTabs())
|
|
|
|
{
|
|
|
|
toggleSeq = getApp()->hotkeys->getDisplaySequence(
|
|
|
|
HotkeyCategory::Window, "setTabVisibility", {{"on"}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->showTabsAction_->setShortcut(toggleSeq);
|
2021-05-30 13:39:34 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
bool Notebook::getShowAddButton() const
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->showAddButton_;
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::setShowAddButton(bool value)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->showAddButton_ = value;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
this->addButton_->setHidden(!value);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
void Notebook::resizeAddButton()
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-11-21 21:37:41 +01:00
|
|
|
float h = (NOTEBOOK_TAB_HEIGHT - 1) * this->scale();
|
2018-08-11 22:23:06 +02:00
|
|
|
this->addButton_->setFixedSize(h, h);
|
2022-07-23 16:09:12 +02:00
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
void Notebook::scaleChangedEvent(float)
|
|
|
|
{
|
|
|
|
this->resizeAddButton();
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &i : this->items_)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
i.tab->updateSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::resizeEvent(QResizeEvent *)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
|
|
|
this->performLayout();
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::performLayout(bool animated)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-11-21 21:37:41 +01:00
|
|
|
const auto left = int(2 * this->scale());
|
2022-07-23 16:09:12 +02:00
|
|
|
const auto right = width();
|
|
|
|
const auto bottom = height();
|
2018-11-21 21:37:41 +01:00
|
|
|
const auto scale = this->scale();
|
2018-10-21 12:13:09 +02:00
|
|
|
const auto tabHeight = int(NOTEBOOK_TAB_HEIGHT * scale);
|
2021-05-30 13:39:34 +02:00
|
|
|
const auto minimumTabAreaSpace = int(tabHeight * 0.5);
|
2018-10-21 12:13:09 +02:00
|
|
|
const auto addButtonWidth = this->showAddButton_ ? tabHeight : 0;
|
2022-07-23 16:09:12 +02:00
|
|
|
const auto lineThickness = int(2 * scale);
|
2022-11-08 22:46:43 +01:00
|
|
|
const auto tabSpacer = std::max<int>(1, int(scale * 1));
|
2022-07-23 16:09:12 +02:00
|
|
|
|
|
|
|
const auto buttonWidth = tabHeight;
|
|
|
|
const auto buttonHeight = tabHeight - 1;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
if (this->tabLocation_ == NotebookTabLocation::Top)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-08-13 15:43:08 +02:00
|
|
|
auto x = left;
|
|
|
|
auto y = 0;
|
2022-07-23 16:09:12 +02:00
|
|
|
auto consumedButtonHeights = 0;
|
2020-08-13 15:43:08 +02:00
|
|
|
|
|
|
|
// set size of custom buttons (settings, user, ...)
|
|
|
|
for (auto *btn : this->customButtons_)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-08-13 15:43:08 +02:00
|
|
|
if (!btn->isVisible())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
btn->setFixedSize(buttonWidth, buttonHeight);
|
2020-08-13 15:43:08 +02:00
|
|
|
btn->move(x, 0);
|
2022-07-23 16:09:12 +02:00
|
|
|
x += buttonWidth;
|
2018-06-04 15:36:48 +02:00
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
consumedButtonHeights = tabHeight;
|
2021-05-30 13:39:34 +02:00
|
|
|
}
|
2018-05-23 12:24:18 +02:00
|
|
|
|
2021-05-30 13:39:34 +02:00
|
|
|
if (this->showTabs_)
|
2020-08-13 15:43:08 +02:00
|
|
|
{
|
2021-05-30 13:39:34 +02:00
|
|
|
// layout tabs
|
|
|
|
/// Notebook tabs need to know if they are in the last row.
|
|
|
|
auto firstInBottomRow =
|
|
|
|
this->items_.size() ? &this->items_.front() : nullptr;
|
2018-10-21 12:13:09 +02:00
|
|
|
|
2021-05-30 13:39:34 +02:00
|
|
|
for (auto &item : this->items_)
|
|
|
|
{
|
|
|
|
/// Break line if element doesn't fit.
|
|
|
|
auto isFirst = &item == &this->items_.front();
|
|
|
|
auto isLast = &item == &this->items_.back();
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2021-05-30 13:39:34 +02:00
|
|
|
auto fitsInLine = ((isLast ? addButtonWidth : 0) + x +
|
|
|
|
item.tab->width()) <= width();
|
|
|
|
|
|
|
|
if (!isFirst && !fitsInLine)
|
|
|
|
{
|
|
|
|
y += item.tab->height();
|
|
|
|
x = left;
|
|
|
|
firstInBottomRow = &item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Layout tab
|
|
|
|
item.tab->growWidth(0);
|
|
|
|
item.tab->moveAnimated(QPoint(x, y), animated);
|
2022-11-08 22:46:43 +01:00
|
|
|
x += item.tab->width() + tabSpacer;
|
2021-05-30 13:39:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Update which tabs are in the last row
|
|
|
|
auto inLastRow = false;
|
|
|
|
for (const auto &item : this->items_)
|
2020-08-13 15:43:08 +02:00
|
|
|
{
|
2021-05-30 13:39:34 +02:00
|
|
|
if (&item == firstInBottomRow)
|
|
|
|
{
|
|
|
|
inLastRow = true;
|
|
|
|
}
|
|
|
|
item.tab->setInLastRow(inLastRow);
|
2020-08-13 15:43:08 +02:00
|
|
|
}
|
2018-06-01 14:46:41 +02:00
|
|
|
|
2021-05-30 13:39:34 +02:00
|
|
|
// move misc buttons
|
|
|
|
if (this->showAddButton_)
|
|
|
|
{
|
|
|
|
this->addButton_->move(x, y);
|
|
|
|
}
|
2020-08-13 15:43:08 +02:00
|
|
|
|
2021-05-30 13:39:34 +02:00
|
|
|
y += tabHeight;
|
2020-08-13 15:43:08 +02:00
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
y = std::max({y, consumedButtonHeights, minimumTabAreaSpace});
|
2021-05-30 13:39:34 +02:00
|
|
|
|
|
|
|
if (this->lineOffset_ != y)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2021-05-30 13:39:34 +02:00
|
|
|
this->lineOffset_ = y;
|
2020-08-13 15:43:08 +02:00
|
|
|
this->update();
|
2018-10-21 12:13:09 +02:00
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2020-08-13 15:43:08 +02:00
|
|
|
/// Increment for the line at the bottom
|
|
|
|
y += int(2 * scale);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2020-08-13 15:43:08 +02:00
|
|
|
// set page bounds
|
|
|
|
if (this->selectedPage_ != nullptr)
|
|
|
|
{
|
2021-05-30 13:39:34 +02:00
|
|
|
this->selectedPage_->move(0, y);
|
|
|
|
this->selectedPage_->resize(width(), height() - y);
|
2020-08-13 15:43:08 +02:00
|
|
|
this->selectedPage_->raise();
|
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
2022-07-23 16:09:12 +02:00
|
|
|
else if (this->tabLocation_ == NotebookTabLocation::Left)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-08-13 15:43:08 +02:00
|
|
|
auto x = left;
|
|
|
|
auto y = 0;
|
|
|
|
|
|
|
|
// set size of custom buttons (settings, user, ...)
|
|
|
|
for (auto *btn : this->customButtons_)
|
|
|
|
{
|
|
|
|
if (!btn->isVisible())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
btn->setFixedSize(buttonWidth, buttonHeight);
|
2020-08-13 15:43:08 +02:00
|
|
|
btn->move(x, y);
|
2022-07-23 16:09:12 +02:00
|
|
|
x += buttonWidth;
|
2020-08-13 15:43:08 +02:00
|
|
|
}
|
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
if (this->visibleButtonCount() > 0)
|
2022-11-08 22:46:43 +01:00
|
|
|
y = tabHeight + lineThickness; // account for divider line
|
2020-08-13 15:43:08 +02:00
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
int totalButtonWidths = x;
|
2022-11-08 22:46:43 +01:00
|
|
|
const int top = y + tabSpacer; // add margin
|
|
|
|
|
|
|
|
y = top;
|
2020-08-13 15:43:08 +02:00
|
|
|
x = left;
|
|
|
|
|
2021-05-30 13:39:34 +02:00
|
|
|
// zneix: if we were to remove buttons when tabs are hidden
|
|
|
|
// stuff below to "set page bounds" part should be in conditional statement
|
2022-11-15 08:45:10 +01:00
|
|
|
int tabsPerColumn = (this->height() - top) / (tabHeight + tabSpacer);
|
2022-07-23 16:09:12 +02:00
|
|
|
if (tabsPerColumn == 0) // window hasn't properly rendered yet
|
2021-05-30 13:39:34 +02:00
|
|
|
{
|
2020-08-13 15:43:08 +02:00
|
|
|
return;
|
2021-05-30 13:39:34 +02:00
|
|
|
}
|
2020-08-13 15:43:08 +02:00
|
|
|
int count = this->items_.size() + (this->showAddButton_ ? 1 : 0);
|
2022-07-23 16:09:12 +02:00
|
|
|
int columnCount = ceil((float)count / tabsPerColumn);
|
2020-08-13 15:43:08 +02:00
|
|
|
|
2021-05-30 13:39:34 +02:00
|
|
|
// only add width of all the tabs if they are not hidden
|
|
|
|
if (this->showTabs_)
|
2020-08-13 15:43:08 +02:00
|
|
|
{
|
2021-05-30 13:39:34 +02:00
|
|
|
for (int col = 0; col < columnCount; col++)
|
2020-08-13 15:43:08 +02:00
|
|
|
{
|
2022-07-23 16:09:12 +02:00
|
|
|
bool isLastColumn = col == columnCount - 1;
|
2021-05-30 13:39:34 +02:00
|
|
|
auto largestWidth = 0;
|
2022-07-23 16:09:12 +02:00
|
|
|
int tabStart = col * tabsPerColumn;
|
|
|
|
int tabEnd =
|
|
|
|
std::min((col + 1) * tabsPerColumn, this->items_.size());
|
2020-08-13 15:43:08 +02:00
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
for (int i = tabStart; i < tabEnd; i++)
|
2021-05-30 13:39:34 +02:00
|
|
|
{
|
|
|
|
largestWidth = std::max(
|
|
|
|
this->items_.at(i).tab->normalTabWidth(), largestWidth);
|
|
|
|
}
|
2020-08-13 15:43:08 +02:00
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
if (isLastColumn && this->showAddButton_)
|
2021-05-30 13:39:34 +02:00
|
|
|
{
|
2022-07-23 16:09:12 +02:00
|
|
|
largestWidth =
|
|
|
|
std::max(largestWidth, this->addButton_->width());
|
2021-05-30 13:39:34 +02:00
|
|
|
}
|
2020-08-13 15:43:08 +02:00
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
if (isLastColumn && largestWidth + x < totalButtonWidths)
|
|
|
|
largestWidth = totalButtonWidths - x;
|
2020-08-13 15:43:08 +02:00
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
for (int i = tabStart; i < tabEnd; i++)
|
2021-05-30 13:39:34 +02:00
|
|
|
{
|
|
|
|
auto item = this->items_.at(i);
|
2020-08-13 15:43:08 +02:00
|
|
|
|
2021-05-30 13:39:34 +02:00
|
|
|
/// Layout tab
|
|
|
|
item.tab->growWidth(largestWidth);
|
|
|
|
item.tab->moveAnimated(QPoint(x, y), animated);
|
2022-11-08 22:46:43 +01:00
|
|
|
item.tab->setInLastRow(isLastColumn);
|
|
|
|
y += tabHeight + tabSpacer;
|
2021-05-30 13:39:34 +02:00
|
|
|
}
|
2020-08-13 15:43:08 +02:00
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
if (isLastColumn && this->showAddButton_)
|
2021-05-30 13:39:34 +02:00
|
|
|
{
|
|
|
|
this->addButton_->move(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
x += largestWidth + lineThickness;
|
|
|
|
y = top;
|
|
|
|
}
|
2020-08-13 15:43:08 +02:00
|
|
|
}
|
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
x = std::max({x, totalButtonWidths, minimumTabAreaSpace});
|
2020-08-13 15:43:08 +02:00
|
|
|
|
|
|
|
if (this->lineOffset_ != x - lineThickness)
|
|
|
|
{
|
|
|
|
this->lineOffset_ = x - lineThickness;
|
|
|
|
this->update();
|
|
|
|
}
|
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
// set page bounds
|
|
|
|
if (this->selectedPage_ != nullptr)
|
2020-08-13 15:43:08 +02:00
|
|
|
{
|
2022-07-23 16:09:12 +02:00
|
|
|
this->selectedPage_->move(x, 0);
|
|
|
|
this->selectedPage_->resize(width() - x, height());
|
|
|
|
this->selectedPage_->raise();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (this->tabLocation_ == NotebookTabLocation::Right)
|
|
|
|
{
|
|
|
|
auto x = right;
|
|
|
|
auto y = 0;
|
|
|
|
|
|
|
|
// set size of custom buttons (settings, user, ...)
|
|
|
|
for (auto btnIt = this->customButtons_.rbegin();
|
|
|
|
btnIt != this->customButtons_.rend(); ++btnIt)
|
|
|
|
{
|
|
|
|
auto btn = *btnIt;
|
|
|
|
if (!btn->isVisible())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
x -= buttonWidth;
|
|
|
|
btn->setFixedSize(buttonWidth, buttonHeight);
|
|
|
|
btn->move(x, y);
|
2020-08-13 15:43:08 +02:00
|
|
|
}
|
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
if (this->visibleButtonCount() > 0)
|
2022-11-08 22:46:43 +01:00
|
|
|
y = tabHeight + lineThickness; // account for divider line
|
2022-07-23 16:09:12 +02:00
|
|
|
|
|
|
|
int consumedButtonWidths = right - x;
|
2022-11-08 22:46:43 +01:00
|
|
|
const int top = y + tabSpacer; // add margin
|
|
|
|
|
|
|
|
y = top;
|
2022-07-23 16:09:12 +02:00
|
|
|
x = right;
|
|
|
|
|
|
|
|
// zneix: if we were to remove buttons when tabs are hidden
|
|
|
|
// stuff below to "set page bounds" part should be in conditional statement
|
2022-11-15 08:45:10 +01:00
|
|
|
int tabsPerColumn = (this->height() - top) / (tabHeight + tabSpacer);
|
2022-07-23 16:09:12 +02:00
|
|
|
if (tabsPerColumn == 0) // window hasn't properly rendered yet
|
2020-08-13 15:43:08 +02:00
|
|
|
{
|
2022-07-23 16:09:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int count = this->items_.size() + (this->showAddButton_ ? 1 : 0);
|
|
|
|
int columnCount = ceil((float)count / tabsPerColumn);
|
|
|
|
|
|
|
|
// only add width of all the tabs if they are not hidden
|
|
|
|
if (this->showTabs_)
|
|
|
|
{
|
|
|
|
for (int col = 0; col < columnCount; col++)
|
|
|
|
{
|
|
|
|
bool isLastColumn = col == columnCount - 1;
|
|
|
|
auto largestWidth = 0;
|
|
|
|
int tabStart = col * tabsPerColumn;
|
|
|
|
int tabEnd =
|
|
|
|
std::min((col + 1) * tabsPerColumn, this->items_.size());
|
|
|
|
|
|
|
|
for (int i = tabStart; i < tabEnd; i++)
|
|
|
|
{
|
|
|
|
largestWidth = std::max(
|
|
|
|
this->items_.at(i).tab->normalTabWidth(), largestWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isLastColumn && this->showAddButton_)
|
|
|
|
{
|
|
|
|
largestWidth =
|
|
|
|
std::max(largestWidth, this->addButton_->width());
|
|
|
|
}
|
|
|
|
|
|
|
|
int distanceFromRight = width() - x;
|
|
|
|
|
|
|
|
if (isLastColumn &&
|
|
|
|
largestWidth + distanceFromRight < consumedButtonWidths)
|
|
|
|
largestWidth = consumedButtonWidths - distanceFromRight;
|
|
|
|
|
|
|
|
x -= largestWidth + lineThickness;
|
|
|
|
|
|
|
|
for (int i = tabStart; i < tabEnd; i++)
|
|
|
|
{
|
|
|
|
auto item = this->items_.at(i);
|
|
|
|
|
|
|
|
/// Layout tab
|
|
|
|
item.tab->growWidth(largestWidth);
|
|
|
|
item.tab->moveAnimated(QPoint(x, y), animated);
|
2022-11-08 22:46:43 +01:00
|
|
|
item.tab->setInLastRow(isLastColumn);
|
|
|
|
y += tabHeight + tabSpacer;
|
2022-07-23 16:09:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isLastColumn && this->showAddButton_)
|
|
|
|
{
|
|
|
|
this->addButton_->move(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
y = top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// subtract another lineThickness to account for vertical divider
|
|
|
|
x -= lineThickness;
|
|
|
|
int consumedRightSpace =
|
|
|
|
std::max({right - x, consumedButtonWidths, minimumTabAreaSpace});
|
|
|
|
int tabsStart = right - consumedRightSpace;
|
|
|
|
|
|
|
|
if (this->lineOffset_ != tabsStart)
|
|
|
|
{
|
|
|
|
this->lineOffset_ = tabsStart;
|
|
|
|
this->update();
|
2020-08-13 15:43:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// set page bounds
|
|
|
|
if (this->selectedPage_ != nullptr)
|
|
|
|
{
|
2022-07-23 16:09:12 +02:00
|
|
|
this->selectedPage_->move(0, 0);
|
|
|
|
this->selectedPage_->resize(tabsStart, height());
|
|
|
|
this->selectedPage_->raise();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (this->tabLocation_ == NotebookTabLocation::Bottom)
|
|
|
|
{
|
|
|
|
auto x = left;
|
|
|
|
auto y = bottom;
|
|
|
|
auto consumedButtonHeights = 0;
|
|
|
|
|
|
|
|
// set size of custom buttons (settings, user, ...)
|
|
|
|
for (auto *btn : this->customButtons_)
|
|
|
|
{
|
|
|
|
if (!btn->isVisible())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// move upward to place button below location (x, y)
|
|
|
|
y = bottom - tabHeight;
|
|
|
|
|
|
|
|
btn->setFixedSize(buttonWidth, buttonHeight);
|
|
|
|
btn->move(x, y);
|
|
|
|
x += buttonWidth;
|
|
|
|
|
|
|
|
consumedButtonHeights = tabHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->showTabs_)
|
|
|
|
{
|
|
|
|
// reset vertical position regardless
|
2022-11-08 22:46:43 +01:00
|
|
|
y = bottom - tabHeight - tabSpacer;
|
2022-07-23 16:09:12 +02:00
|
|
|
|
|
|
|
// layout tabs
|
|
|
|
/// Notebook tabs need to know if they are in the last row.
|
|
|
|
auto firstInBottomRow =
|
|
|
|
this->items_.size() ? &this->items_.front() : nullptr;
|
|
|
|
|
|
|
|
for (auto &item : this->items_)
|
|
|
|
{
|
|
|
|
/// Break line if element doesn't fit.
|
|
|
|
auto isFirst = &item == &this->items_.front();
|
|
|
|
auto isLast = &item == &this->items_.back();
|
|
|
|
|
|
|
|
auto fitsInLine = ((isLast ? addButtonWidth : 0) + x +
|
|
|
|
item.tab->width()) <= width();
|
|
|
|
|
|
|
|
if (!isFirst && !fitsInLine)
|
|
|
|
{
|
|
|
|
y -= item.tab->height();
|
|
|
|
x = left;
|
|
|
|
firstInBottomRow = &item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Layout tab
|
|
|
|
item.tab->growWidth(0);
|
|
|
|
item.tab->moveAnimated(QPoint(x, y), animated);
|
2022-11-08 22:46:43 +01:00
|
|
|
x += item.tab->width() + tabSpacer;
|
2022-07-23 16:09:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Update which tabs are in the last row
|
|
|
|
auto inLastRow = false;
|
|
|
|
for (const auto &item : this->items_)
|
|
|
|
{
|
|
|
|
if (&item == firstInBottomRow)
|
|
|
|
{
|
|
|
|
inLastRow = true;
|
|
|
|
}
|
|
|
|
item.tab->setInLastRow(inLastRow);
|
|
|
|
}
|
|
|
|
|
|
|
|
// move misc buttons
|
|
|
|
if (this->showAddButton_)
|
|
|
|
{
|
|
|
|
this->addButton_->move(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int consumedBottomSpace =
|
|
|
|
std::max({bottom - y, consumedButtonHeights, minimumTabAreaSpace});
|
2022-11-08 22:46:43 +01:00
|
|
|
int tabsStart = bottom - consumedBottomSpace - lineThickness;
|
2022-07-23 16:09:12 +02:00
|
|
|
|
|
|
|
if (this->lineOffset_ != tabsStart)
|
|
|
|
{
|
|
|
|
this->lineOffset_ = tabsStart;
|
|
|
|
this->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// set page bounds
|
|
|
|
if (this->selectedPage_ != nullptr)
|
|
|
|
{
|
|
|
|
this->selectedPage_->move(0, 0);
|
|
|
|
this->selectedPage_->resize(width(), tabsStart);
|
2020-08-13 15:43:08 +02:00
|
|
|
this->selectedPage_->raise();
|
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
2022-07-23 16:09:12 +02:00
|
|
|
|
|
|
|
if (this->showTabs_)
|
|
|
|
{
|
|
|
|
// raise elements
|
|
|
|
for (auto &i : this->items_)
|
|
|
|
{
|
|
|
|
i.tab->raise();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->showAddButton_)
|
|
|
|
{
|
|
|
|
this->addButton_->raise();
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 15:43:08 +02:00
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2021-05-30 13:39:34 +02:00
|
|
|
void Notebook::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
this->update();
|
|
|
|
|
|
|
|
switch (event->button())
|
|
|
|
{
|
|
|
|
case Qt::RightButton: {
|
|
|
|
this->menu_.popup(event->globalPos() + QPoint(0, 8));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
void Notebook::setTabLocation(NotebookTabLocation location)
|
2020-08-13 15:43:08 +02:00
|
|
|
{
|
2022-07-23 16:09:12 +02:00
|
|
|
if (location != this->tabLocation_)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2022-07-23 16:09:12 +02:00
|
|
|
this->tabLocation_ = location;
|
2022-11-08 22:46:43 +01:00
|
|
|
|
|
|
|
// Update all tabs
|
|
|
|
for (const auto &item : this->items_)
|
|
|
|
{
|
|
|
|
item.tab->setTabLocation(location);
|
|
|
|
}
|
|
|
|
|
2020-08-13 15:43:08 +02:00
|
|
|
this->performLayout();
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::paintEvent(QPaintEvent *event)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
|
|
|
BaseWidget::paintEvent(event);
|
2020-08-13 15:43:08 +02:00
|
|
|
auto scale = this->scale();
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
QPainter painter(this);
|
2022-07-23 16:09:12 +02:00
|
|
|
if (this->tabLocation_ == NotebookTabLocation::Top ||
|
|
|
|
this->tabLocation_ == NotebookTabLocation::Bottom)
|
2020-08-13 15:43:08 +02:00
|
|
|
{
|
|
|
|
/// horizontal line
|
|
|
|
painter.fillRect(0, this->lineOffset_, this->width(), int(2 * scale),
|
|
|
|
this->theme->tabs.dividerLine);
|
|
|
|
}
|
2022-07-23 16:09:12 +02:00
|
|
|
else if (this->tabLocation_ == NotebookTabLocation::Left ||
|
|
|
|
this->tabLocation_ == NotebookTabLocation::Right)
|
2020-08-13 15:43:08 +02:00
|
|
|
{
|
2022-07-23 16:09:12 +02:00
|
|
|
if (this->visibleButtonCount() > 0)
|
2020-08-13 15:43:08 +02:00
|
|
|
{
|
2022-07-23 16:09:12 +02:00
|
|
|
if (this->tabLocation_ == NotebookTabLocation::Left)
|
|
|
|
{
|
|
|
|
painter.fillRect(0, int(NOTEBOOK_TAB_HEIGHT * scale),
|
|
|
|
this->lineOffset_, int(2 * scale),
|
|
|
|
this->theme->tabs.dividerLine);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
painter.fillRect(this->lineOffset_,
|
|
|
|
int(NOTEBOOK_TAB_HEIGHT * scale),
|
|
|
|
width() - this->lineOffset_, int(2 * scale),
|
|
|
|
this->theme->tabs.dividerLine);
|
|
|
|
}
|
2020-08-13 15:43:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// vertical line
|
|
|
|
painter.fillRect(this->lineOffset_, 0, int(2 * scale), this->height(),
|
|
|
|
this->theme->tabs.dividerLine);
|
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2022-03-26 14:16:45 +01:00
|
|
|
bool Notebook::isNotebookLayoutLocked() const
|
|
|
|
{
|
|
|
|
return this->lockNotebookLayout_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Notebook::setLockNotebookLayout(bool value)
|
|
|
|
{
|
|
|
|
this->lockNotebookLayout_ = value;
|
|
|
|
this->lockNotebookLayoutAction_->setChecked(value);
|
|
|
|
getSettings()->lockNotebookLayout.setValue(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Notebook::addNotebookActionsToMenu(QMenu *menu)
|
|
|
|
{
|
2022-10-09 17:20:44 +02:00
|
|
|
menu->addAction(this->showTabsAction_);
|
2022-03-26 14:16:45 +01:00
|
|
|
|
|
|
|
menu->addAction(this->lockNotebookLayoutAction_);
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
NotebookButton *Notebook::getAddButton()
|
2018-05-23 04:22:17 +02:00
|
|
|
{
|
2018-08-11 22:23:06 +02:00
|
|
|
return this->addButton_;
|
2018-05-23 04:22:17 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 12:24:18 +02:00
|
|
|
NotebookButton *Notebook::addCustomButton()
|
|
|
|
{
|
|
|
|
NotebookButton *btn = new NotebookButton(this);
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->customButtons_.push_back(btn);
|
2018-05-23 12:24:18 +02:00
|
|
|
|
|
|
|
this->performLayout();
|
|
|
|
return btn;
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
NotebookTab *Notebook::getTabFromPage(QWidget *page)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &it : this->items_)
|
|
|
|
{
|
|
|
|
if (it.page == page)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
return it.tab;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-23 16:09:12 +02:00
|
|
|
size_t Notebook::visibleButtonCount() const
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
for (auto *btn : this->customButtons_)
|
|
|
|
{
|
|
|
|
if (btn->isVisible())
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2018-05-23 12:24:18 +02:00
|
|
|
SplitNotebook::SplitNotebook(Window *parent)
|
2018-05-23 11:59:37 +02:00
|
|
|
: Notebook(parent)
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2018-10-21 16:13:26 +02:00
|
|
|
this->connect(this->getAddButton(), &NotebookButton::leftClicked, [this]() {
|
2020-11-08 12:02:19 +01:00
|
|
|
QTimer::singleShot(80, this, [this] {
|
|
|
|
this->addPage(true);
|
|
|
|
});
|
2018-08-06 21:17:03 +02:00
|
|
|
});
|
2018-05-23 12:24:18 +02:00
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
// add custom buttons if they are not in the parent window frame
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!parent->hasCustomWindowFrame())
|
|
|
|
{
|
2018-07-05 12:52:36 +02:00
|
|
|
this->addCustomButtons();
|
2018-05-23 12:24:18 +02:00
|
|
|
}
|
2021-04-17 16:15:23 +02:00
|
|
|
|
|
|
|
this->signalHolder_.managedConnect(
|
|
|
|
getApp()->windows->selectSplit, [this](Split *split) {
|
|
|
|
for (auto &&item : this->items())
|
|
|
|
{
|
|
|
|
if (auto sc = dynamic_cast<SplitContainer *>(item.page))
|
|
|
|
{
|
|
|
|
auto &&splits = sc->getSplits();
|
|
|
|
if (std::find(splits.begin(), splits.end(), split) !=
|
|
|
|
splits.end())
|
|
|
|
{
|
|
|
|
this->select(item.page);
|
|
|
|
split->setFocus();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this->signalHolder_.managedConnect(getApp()->windows->selectSplitContainer,
|
|
|
|
[this](SplitContainer *sc) {
|
|
|
|
this->select(sc);
|
|
|
|
});
|
2022-09-11 16:37:13 +02:00
|
|
|
|
|
|
|
this->signalHolder_.managedConnect(
|
|
|
|
getApp()->windows->scrollToMessageSignal,
|
|
|
|
[this](const MessagePtr &message) {
|
|
|
|
for (auto &&item : this->items())
|
|
|
|
{
|
|
|
|
if (auto sc = dynamic_cast<SplitContainer *>(item.page))
|
|
|
|
{
|
|
|
|
for (auto *split : sc->getSplits())
|
|
|
|
{
|
|
|
|
if (split->getChannel()->getType() !=
|
|
|
|
Channel::Type::TwitchMentions)
|
|
|
|
{
|
|
|
|
if (split->getChannelView().scrollToMessage(
|
|
|
|
message))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-01-01 18:43:52 +01:00
|
|
|
}
|
|
|
|
|
2020-09-26 01:52:39 +02:00
|
|
|
void SplitNotebook::showEvent(QShowEvent *)
|
|
|
|
{
|
|
|
|
if (auto page = this->getSelectedPage())
|
|
|
|
{
|
|
|
|
if (auto split = page->findChild<Split *>())
|
|
|
|
{
|
2022-06-26 18:53:09 +02:00
|
|
|
split->setFocus(Qt::FocusReason::OtherFocusReason);
|
2020-09-26 01:52:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-05 12:52:36 +02:00
|
|
|
void SplitNotebook::addCustomButtons()
|
|
|
|
{
|
|
|
|
// settings
|
|
|
|
auto settingsBtn = this->addCustomButton();
|
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
settingsBtn->setVisible(!getSettings()->hidePreferencesButton.getValue());
|
2018-07-05 12:52:36 +02:00
|
|
|
|
2018-08-12 12:56:28 +02:00
|
|
|
getSettings()->hidePreferencesButton.connect(
|
2020-11-08 12:02:19 +01:00
|
|
|
[settingsBtn](bool hide, auto) {
|
|
|
|
settingsBtn->setVisible(!hide);
|
|
|
|
},
|
2021-12-19 15:57:56 +01:00
|
|
|
this->signalHolder_);
|
2018-07-05 12:52:36 +02:00
|
|
|
|
2018-07-05 13:25:10 +02:00
|
|
|
settingsBtn->setIcon(NotebookButton::Settings);
|
2018-07-05 12:52:36 +02:00
|
|
|
|
2020-11-08 12:02:19 +01:00
|
|
|
QObject::connect(settingsBtn, &NotebookButton::leftClicked, [this] {
|
|
|
|
getApp()->windows->showSettingsDialog(this);
|
|
|
|
});
|
2018-07-05 12:52:36 +02:00
|
|
|
|
|
|
|
// account
|
|
|
|
auto userBtn = this->addCustomButton();
|
2018-08-12 12:56:28 +02:00
|
|
|
userBtn->setVisible(!getSettings()->hideUserButton.getValue());
|
|
|
|
getSettings()->hideUserButton.connect(
|
2020-11-08 12:02:19 +01:00
|
|
|
[userBtn](bool hide, auto) {
|
|
|
|
userBtn->setVisible(!hide);
|
|
|
|
},
|
2021-12-19 15:57:56 +01:00
|
|
|
this->signalHolder_);
|
2018-07-05 12:52:36 +02:00
|
|
|
|
2018-07-05 13:25:10 +02:00
|
|
|
userBtn->setIcon(NotebookButton::User);
|
2018-10-21 16:13:26 +02:00
|
|
|
QObject::connect(userBtn, &NotebookButton::leftClicked, [this, userBtn] {
|
2018-08-06 21:17:03 +02:00
|
|
|
getApp()->windows->showAccountSelectPopup(
|
|
|
|
this->mapToGlobal(userBtn->rect().bottomRight()));
|
2018-07-05 12:52:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// updates
|
|
|
|
auto updateBtn = this->addCustomButton();
|
|
|
|
|
2019-10-03 22:17:59 +02:00
|
|
|
initUpdateButton(*updateBtn, this->signalHolder_);
|
2018-07-05 12:52:36 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
SplitContainer *SplitNotebook::addPage(bool select)
|
2017-12-22 14:44:31 +01:00
|
|
|
{
|
2018-10-21 12:13:09 +02:00
|
|
|
auto container = new SplitContainer(this);
|
|
|
|
auto tab = Notebook::addPage(container, QString(), select);
|
2018-05-23 04:22:17 +02:00
|
|
|
container->setTab(tab);
|
|
|
|
tab->setParent(this);
|
2021-05-30 13:39:34 +02:00
|
|
|
tab->setVisible(this->getShowTabs());
|
2018-05-23 04:22:17 +02:00
|
|
|
return container;
|
2016-12-29 17:31:07 +01:00
|
|
|
}
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
SplitContainer *SplitNotebook::getOrAddSelectedPage()
|
2017-01-22 05:58:23 +01:00
|
|
|
{
|
2018-05-23 04:22:17 +02:00
|
|
|
auto *selectedPage = this->getSelectedPage();
|
2018-01-22 21:31:45 +01:00
|
|
|
|
2022-12-29 19:15:32 +01:00
|
|
|
if (selectedPage)
|
|
|
|
{
|
|
|
|
return dynamic_cast<SplitContainer *>(selectedPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this->addPage();
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
2017-01-28 22:35:23 +01:00
|
|
|
|
2022-01-02 15:00:19 +01:00
|
|
|
void SplitNotebook::select(QWidget *page, bool focusPage)
|
2018-10-20 13:25:24 +02:00
|
|
|
{
|
2022-12-29 19:15:32 +01:00
|
|
|
// If there's a previously selected page, go through its splits and
|
|
|
|
// update their "last read message" indicator
|
|
|
|
if (auto *selectedPage = this->getSelectedPage())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2022-12-29 19:15:32 +01:00
|
|
|
if (auto *splitContainer = dynamic_cast<SplitContainer *>(selectedPage))
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2022-12-29 19:15:32 +01:00
|
|
|
for (auto *split : splitContainer->getSplits())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2018-10-20 13:25:24 +02:00
|
|
|
split->updateLastReadMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-29 19:15:32 +01:00
|
|
|
|
2022-01-02 15:00:19 +01:00
|
|
|
this->Notebook::select(page, focusPage);
|
2018-10-20 13:25:24 +02:00
|
|
|
}
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|