Added ability to toggle visibility of tabs (#2600)

This can be done by right-clicking the tab area or pressing the keyboard shortcut (default: Ctrl+U).

Co-authored-by: Leon Richardt <leon.richardt@gmail.com>
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Paweł
2021-05-30 13:39:34 +02:00
committed by GitHub
parent 01bda9c2f6
commit 57354283ec
7 changed files with 188 additions and 87 deletions
+1
View File
@@ -2,6 +2,7 @@
## Unversioned ## Unversioned
- Major: Added ability to toggle visibility of Channel Tabs - This can be done by right-clicking the tab area or pressing the keyboard shortcut (default: Ctrl+U). (#2600)
- Minor: Added moderation buttons to search popup when searching in a split with moderation mode enabled. (#2148, #2803) - Minor: Added moderation buttons to search popup when searching in a split with moderation mode enabled. (#2148, #2803)
- Minor: Made "#channel" in `/mentions` tab show in usercards and in the search popup. (#2802) - Minor: Made "#channel" in `/mentions` tab show in usercards and in the search popup. (#2802)
- Minor: Added settings to disable custom FrankerFaceZ VIP/mod badges. (#2693, #2759) - Minor: Added settings to disable custom FrankerFaceZ VIP/mod badges. (#2693, #2759)
+2
View File
@@ -360,6 +360,8 @@ public:
BoolSetting attachExtensionToAnyProcess = { BoolSetting attachExtensionToAnyProcess = {
"/misc/attachExtensionToAnyProcess", false}; "/misc/attachExtensionToAnyProcess", false};
BoolSetting askOnImageUpload = {"/misc/askOnImageUpload", true}; BoolSetting askOnImageUpload = {"/misc/askOnImageUpload", true};
BoolSetting informOnTabVisibilityToggle = {"/misc/askOnTabVisibilityToggle",
true};
/// Debug /// Debug
BoolSetting showUnhandledIrcMessages = {"/debug/showUnhandledIrcMessages", BoolSetting showUnhandledIrcMessages = {"/debug/showUnhandledIrcMessages",
+92 -12
View File
@@ -29,11 +29,16 @@ namespace chatterino {
Notebook::Notebook(QWidget *parent) Notebook::Notebook(QWidget *parent)
: BaseWidget(parent) : BaseWidget(parent)
, menu_(this)
, addButton_(new NotebookButton(this)) , addButton_(new NotebookButton(this))
{ {
this->addButton_->setIcon(NotebookButton::Icon::Plus); this->addButton_->setIcon(NotebookButton::Icon::Plus);
this->addButton_->setHidden(true); this->addButton_->setHidden(true);
this->menu_.addAction("Toggle visibility of tabs", [this]() {
this->setShowTabs(!this->getShowTabs());
});
} }
NotebookTab *Notebook::addPage(QWidget *page, QString title, bool select) NotebookTab *Notebook::addPage(QWidget *page, QString title, bool select)
@@ -325,6 +330,48 @@ void Notebook::setAllowUserTabManagement(bool value)
this->allowUserTabManagement_ = value; this->allowUserTabManagement_ = value;
} }
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())
{
QMessageBox msgBox;
msgBox.window()->setWindowTitle("Chatterino - hidden tabs");
msgBox.setText("You've just hidden your tabs");
msgBox.setInformativeText(
"You can toggle tabs by using the keyboard shortcut (Ctrl + U by "
"default) or right-clicking on the tab area and selecting \"Toggle "
"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);
}
}
}
bool Notebook::getShowAddButton() const bool Notebook::getShowAddButton() const
{ {
return this->showAddButton_; return this->showAddButton_;
@@ -359,12 +406,14 @@ void Notebook::performLayout(bool animated)
const auto left = int(2 * this->scale()); const auto left = int(2 * this->scale());
const auto scale = this->scale(); const auto scale = this->scale();
const auto tabHeight = int(NOTEBOOK_TAB_HEIGHT * scale); const auto tabHeight = int(NOTEBOOK_TAB_HEIGHT * scale);
const auto minimumTabAreaSpace = int(tabHeight * 0.5);
const auto addButtonWidth = this->showAddButton_ ? tabHeight : 0; const auto addButtonWidth = this->showAddButton_ ? tabHeight : 0;
if (this->tabDirection_ == NotebookTabDirection::Horizontal) if (this->tabDirection_ == NotebookTabDirection::Horizontal)
{ {
auto x = left; auto x = left;
auto y = 0; auto y = 0;
auto buttonHeight = 0;
// set size of custom buttons (settings, user, ...) // set size of custom buttons (settings, user, ...)
for (auto *btn : this->customButtons_) for (auto *btn : this->customButtons_)
@@ -377,8 +426,12 @@ void Notebook::performLayout(bool animated)
btn->setFixedSize(tabHeight, tabHeight - 1); btn->setFixedSize(tabHeight, tabHeight - 1);
btn->move(x, 0); btn->move(x, 0);
x += tabHeight; x += tabHeight;
buttonHeight = tabHeight;
} }
if (this->showTabs_)
{
// layout tabs // layout tabs
/// Notebook tabs need to know if they are in the last row. /// Notebook tabs need to know if they are in the last row.
auto firstInBottomRow = auto firstInBottomRow =
@@ -423,14 +476,7 @@ void Notebook::performLayout(bool animated)
this->addButton_->move(x, y); this->addButton_->move(x, y);
} }
if (this->lineOffset_ != y + tabHeight) y += tabHeight;
{
this->lineOffset_ = y + tabHeight;
this->update();
}
/// Increment for the line at the bottom
y += int(2 * scale);
// raise elements // raise elements
for (auto &i : this->items_) for (auto &i : this->items_)
@@ -442,12 +488,24 @@ void Notebook::performLayout(bool animated)
{ {
this->addButton_->raise(); this->addButton_->raise();
} }
}
y = std::max({y, buttonHeight, minimumTabAreaSpace});
if (this->lineOffset_ != y)
{
this->lineOffset_ = y;
this->update();
}
/// Increment for the line at the bottom
y += int(2 * scale);
// set page bounds // set page bounds
if (this->selectedPage_ != nullptr) if (this->selectedPage_ != nullptr)
{ {
this->selectedPage_->move(0, y + tabHeight); this->selectedPage_->move(0, y);
this->selectedPage_->resize(width(), height() - y - tabHeight); this->selectedPage_->resize(width(), height() - y);
this->selectedPage_->raise(); this->selectedPage_->raise();
} }
} }
@@ -477,12 +535,19 @@ void Notebook::performLayout(bool animated)
int top = y; int top = y;
x = left; x = left;
// zneix: if we were to remove buttons when tabs are hidden
// stuff below to "set page bounds" part should be in conditional statement
int verticalRowSpace = (this->height() - top) / tabHeight; int verticalRowSpace = (this->height() - top) / tabHeight;
if (verticalRowSpace == 0) // window hasn't properly rendered yet if (verticalRowSpace == 0) // window hasn't properly rendered yet
{
return; return;
}
int count = this->items_.size() + (this->showAddButton_ ? 1 : 0); int count = this->items_.size() + (this->showAddButton_ ? 1 : 0);
int columnCount = ceil((float)count / verticalRowSpace); int columnCount = ceil((float)count / verticalRowSpace);
// only add width of all the tabs if they are not hidden
if (this->showTabs_)
{
for (int col = 0; col < columnCount; col++) for (int col = 0; col < columnCount; col++)
{ {
auto largestWidth = 0; auto largestWidth = 0;
@@ -523,8 +588,9 @@ void Notebook::performLayout(bool animated)
x += largestWidth + lineThickness; x += largestWidth + lineThickness;
y = top; y = top;
} }
}
x = std::max(x, buttonWidth); x = std::max({x, buttonWidth, minimumTabAreaSpace});
if (this->lineOffset_ != x - lineThickness) if (this->lineOffset_ != x - lineThickness)
{ {
@@ -553,6 +619,20 @@ void Notebook::performLayout(bool animated)
} }
} }
void Notebook::mousePressEvent(QMouseEvent *event)
{
this->update();
switch (event->button())
{
case Qt::RightButton: {
this->menu_.popup(event->globalPos() + QPoint(0, 8));
}
break;
default:;
}
}
void Notebook::setTabDirection(NotebookTabDirection direction) void Notebook::setTabDirection(NotebookTabDirection direction)
{ {
if (direction != this->tabDirection_) if (direction != this->tabDirection_)
@@ -713,7 +793,7 @@ SplitContainer *SplitNotebook::addPage(bool select)
auto tab = Notebook::addPage(container, QString(), select); auto tab = Notebook::addPage(container, QString(), select);
container->setTab(tab); container->setTab(tab);
tab->setParent(this); tab->setParent(this);
tab->show(); tab->setVisible(this->getShowTabs());
return container; return container;
} }
+7
View File
@@ -4,6 +4,7 @@
#include "widgets/BaseWidget.hpp" #include "widgets/BaseWidget.hpp"
#include <QList> #include <QList>
#include <QMenu>
#include <QMessageBox> #include <QMessageBox>
#include <QWidget> #include <QWidget>
#include <pajlada/signals/signalholder.hpp> #include <pajlada/signals/signalholder.hpp>
@@ -49,6 +50,9 @@ public:
bool getAllowUserTabManagement() const; bool getAllowUserTabManagement() const;
void setAllowUserTabManagement(bool value); void setAllowUserTabManagement(bool value);
bool getShowTabs() const;
void setShowTabs(bool value);
bool getShowAddButton() const; bool getShowAddButton() const;
void setShowAddButton(bool value); void setShowAddButton(bool value);
@@ -59,6 +63,7 @@ public:
protected: protected:
virtual void scaleChangedEvent(float scale_) override; virtual void scaleChangedEvent(float scale_) override;
virtual void resizeEvent(QResizeEvent *) override; virtual void resizeEvent(QResizeEvent *) override;
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void paintEvent(QPaintEvent *) override; virtual void paintEvent(QPaintEvent *) override;
NotebookButton *getAddButton(); NotebookButton *getAddButton();
@@ -83,12 +88,14 @@ private:
NotebookTab *getTabFromPage(QWidget *page); NotebookTab *getTabFromPage(QWidget *page);
QList<Item> items_; QList<Item> items_;
QMenu menu_;
QWidget *selectedPage_ = nullptr; QWidget *selectedPage_ = nullptr;
NotebookButton *addButton_; NotebookButton *addButton_;
std::vector<NotebookButton *> customButtons_; std::vector<NotebookButton *> customButtons_;
bool allowUserTabManagement_ = false; bool allowUserTabManagement_ = false;
bool showTabs_ = true;
bool showAddButton_ = false; bool showAddButton_ = false;
int lineOffset_ = 20; int lineOffset_ = 20;
NotebookTabDirection tabDirection_ = NotebookTabDirection::Horizontal; NotebookTabDirection tabDirection_ = NotebookTabDirection::Horizontal;
+4
View File
@@ -401,6 +401,10 @@ void Window::addShortcuts()
new QuickSwitcherPopup(&getApp()->windows->getMainWindow()); new QuickSwitcherPopup(&getApp()->windows->getMainWindow());
quickSwitcher->show(); quickSwitcher->show();
}); });
createWindowShortcut(this, "CTRL+U", [this] {
this->notebook_->setShowTabs(!this->notebook_->getShowTabs());
});
} }
void Window::addMenuBar() void Window::addMenuBar()
+6
View File
@@ -73,6 +73,12 @@ NotebookTab::NotebookTab(Notebook *notebook)
this->highlightEnabled_ = checked; this->highlightEnabled_ = checked;
}); });
this->menu_.addAction(highlightNewMessagesAction_); this->menu_.addAction(highlightNewMessagesAction_);
this->menu_.addSeparator();
this->menu_.addAction("Toggle visibility of tabs", [this]() {
this->notebook_->setShowTabs(!this->notebook_->getShowTabs());
});
} }
void NotebookTab::showRenameDialog() void NotebookTab::showRenameDialog()
@@ -57,6 +57,7 @@ KeyboardSettingsPage::KeyboardSettingsPage()
form->addRow(new QLabel("Alt + ←/↑/→/↓"), form->addRow(new QLabel("Alt + ←/↑/→/↓"),
new QLabel("Select left/upper/right/bottom split")); new QLabel("Select left/upper/right/bottom split"));
form->addRow(new QLabel("Ctrl+U"), new QLabel("Toggle visibility of tabs"));
form->addItem(new QSpacerItem(16, 16)); form->addItem(new QSpacerItem(16, 16));
form->addRow(new QLabel("Ctrl + R"), new QLabel("Change channel")); form->addRow(new QLabel("Ctrl + R"), new QLabel("Change channel"));