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
5 changed files with 54 additions and 12 deletions
+44 -6
View File
@@ -34,12 +34,21 @@ Notebook::Notebook(QWidget *parent)
this->addButton_->setHidden(true);
this->menu_.addAction(
"Toggle visibility of tabs",
[this]() {
this->setShowTabs(!this->getShowTabs());
},
QKeySequence("Ctrl+U"));
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);
});
this->addNotebookActionsToMenu(&this->menu_);
}
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)
{
if (this->isNotebookLayoutLocked())
{
return;
}
// Queue up save because: Tab rearranged
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()
{
return this->addButton_;