Add the ability to lock NotebookTab layout (#3627)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Infinitay 2022-03-26 09:16:45 -04:00 committed by GitHub
parent 8247ce72fb
commit 554313d645
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 12 deletions

View file

@ -60,6 +60,7 @@
- Minor: Make Tab Layout setting only accept predefined values (#3564) - Minor: Make Tab Layout setting only accept predefined values (#3564)
- Minor: Added librewolf, icecat, and waterfox incognito support. (#3588) - Minor: Added librewolf, icecat, and waterfox incognito support. (#3588)
- Minor: Updated to Emoji v14.0 (#3612) - Minor: Updated to Emoji v14.0 (#3612)
- Minor: Add support for locking tab arrangement (#3627)
- Bugfix: Fix Split Input hotkeys not being available when input is hidden (#3362) - Bugfix: Fix Split Input hotkeys not being available when input is hidden (#3362)
- Bugfix: Fixed colored usernames sometimes not working. (#3170) - Bugfix: Fixed colored usernames sometimes not working. (#3170)
- Bugfix: Restored ability to send duplicate `/me` messages. (#3166) - Bugfix: Restored ability to send duplicate `/me` messages. (#3166)

View file

@ -386,6 +386,7 @@ public:
BoolSetting askOnImageUpload = {"/misc/askOnImageUpload", true}; BoolSetting askOnImageUpload = {"/misc/askOnImageUpload", true};
BoolSetting informOnTabVisibilityToggle = {"/misc/askOnTabVisibilityToggle", BoolSetting informOnTabVisibilityToggle = {"/misc/askOnTabVisibilityToggle",
true}; true};
BoolSetting lockNotebookLayout = {"/misc/lockNotebookLayout", false};
/// Debug /// Debug
BoolSetting showUnhandledIrcMessages = {"/debug/showUnhandledIrcMessages", BoolSetting showUnhandledIrcMessages = {"/debug/showUnhandledIrcMessages",

View file

@ -34,12 +34,21 @@ Notebook::Notebook(QWidget *parent)
this->addButton_->setHidden(true); this->addButton_->setHidden(true);
this->menu_.addAction( this->lockNotebookLayoutAction_ = new QAction("Lock Tab Layout", this);
"Toggle visibility of tabs",
[this]() { // Load lock notebook layout state from settings
this->setShowTabs(!this->getShowTabs()); this->setLockNotebookLayout(getSettings()->lockNotebookLayout.getValue());
},
QKeySequence("Ctrl+U")); 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);
});
this->addNotebookActionsToMenu(&this->menu_);
} }
NotebookTab *Notebook::addPage(QWidget *page, QString title, bool select) NotebookTab *Notebook::addPage(QWidget *page, QString title, bool select)
@ -316,6 +325,11 @@ QWidget *Notebook::tabAt(QPoint point, int &index, int maxWidth)
void Notebook::rearrangePage(QWidget *page, int index) void Notebook::rearrangePage(QWidget *page, int index)
{ {
if (this->isNotebookLayoutLocked())
{
return;
}
// Queue up save because: Tab rearranged // Queue up save because: Tab rearranged
getApp()->windows->queueSave(); getApp()->windows->queueSave();
@ -673,6 +687,30 @@ void Notebook::paintEvent(QPaintEvent *event)
} }
} }
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)
{
menu->addAction(
"Toggle visibility of tabs",
[this]() {
this->setShowTabs(!this->getShowTabs());
},
QKeySequence("Ctrl+U"));
menu->addAction(this->lockNotebookLayoutAction_);
}
NotebookButton *Notebook::getAddButton() NotebookButton *Notebook::getAddButton()
{ {
return this->addButton_; return this->addButton_;

View file

@ -60,6 +60,11 @@ public:
void setTabDirection(NotebookTabDirection direction); void setTabDirection(NotebookTabDirection direction);
bool isNotebookLayoutLocked() const;
void setLockNotebookLayout(bool value);
void addNotebookActionsToMenu(QMenu *menu);
protected: protected:
virtual void scaleChangedEvent(float scale_) override; virtual void scaleChangedEvent(float scale_) override;
virtual void resizeEvent(QResizeEvent *) override; virtual void resizeEvent(QResizeEvent *) override;
@ -98,7 +103,9 @@ private:
bool showTabs_ = true; bool showTabs_ = true;
bool showAddButton_ = false; bool showAddButton_ = false;
int lineOffset_ = 20; int lineOffset_ = 20;
bool lockNotebookLayout_ = false;
NotebookTabDirection tabDirection_ = NotebookTabDirection::Horizontal; NotebookTabDirection tabDirection_ = NotebookTabDirection::Horizontal;
QAction *lockNotebookLayoutAction_;
}; };
class SplitNotebook : public Notebook class SplitNotebook : public Notebook

View file

@ -89,12 +89,7 @@ NotebookTab::NotebookTab(Notebook *notebook)
this->menu_.addSeparator(); this->menu_.addSeparator();
this->menu_.addAction( this->notebook_->addNotebookActionsToMenu(&this->menu_);
"Toggle visibility of tabs",
[this]() {
this->notebook_->setShowTabs(!this->notebook_->getShowTabs());
},
QKeySequence("Ctrl+U"));
} }
void NotebookTab::showRenameDialog() void NotebookTab::showRenameDialog()