diff --git a/src/singletons/windowmanager.cpp b/src/singletons/windowmanager.cpp index 3cbfa9f5c..294a03d33 100644 --- a/src/singletons/windowmanager.cpp +++ b/src/singletons/windowmanager.cpp @@ -195,8 +195,7 @@ void WindowManager::initialize() // set custom title QJsonValue title_val = tab_obj.value("title"); if (title_val.isString()) { - page->getTab()->setTitle(title_val.toString()); - page->getTab()->useDefaultTitle = false; + page->getTab()->setCustomTitle(title_val.toString()); } // selected @@ -275,8 +274,8 @@ void WindowManager::save() assert(tab != nullptr); // custom tab title - if (!tab->getTab()->useDefaultTitle) { - tab_obj.insert("title", tab->getTab()->getTitle()); + if (tab->getTab()->hasCustomTitle()) { + tab_obj.insert("title", tab->getTab()->getCustomTitle()); } // selected diff --git a/src/widgets/helper/notebooktab.cpp b/src/widgets/helper/notebooktab.cpp index 75f49e789..880fe3010 100644 --- a/src/widgets/helper/notebooktab.cpp +++ b/src/widgets/helper/notebooktab.cpp @@ -41,24 +41,12 @@ NotebookTab::NotebookTab(Notebook *notebook) TextInputDialog d(this); d.setWindowTitle("Change tab title (Leave empty for default behaviour)"); - if (this->useDefaultTitle) { - d.setText(""); - } else { - d.setText(this->getTitle()); - d.highlightText(); - } + d.setText(this->getCustomTitle()); + d.highlightText(); if (d.exec() == QDialog::Accepted) { QString newTitle = d.getText(); - if (newTitle.isEmpty()) { - this->useDefaultTitle = true; - - // fourtf: xD - // this->page->refreshTitle(); - } else { - this->useDefaultTitle = false; - this->setTitle(newTitle); - } + this->setCustomTitle(newTitle); } }); @@ -90,9 +78,9 @@ void NotebookTab::updateSize() FontStyle::UiTabs, float(qreal(this->getScale()) * this->devicePixelRatioF())); if (this->hasXButton()) { - width = int((metrics.width(this->title_) + 32) * scale); + width = int((metrics.width(this->getTitle()) + 32) * scale); } else { - width = int((metrics.width(this->title_) + 16) * scale); + width = int((metrics.width(this->getTitle()) + 16) * scale); } width = std::max(this->height(), std::min(int(150 * scale), width)); @@ -103,20 +91,56 @@ void NotebookTab::updateSize() } } -const QString &NotebookTab::getTitle() const +const QString &NotebookTab::getCustomTitle() const { - return this->title_; + return this->customTitle_; } -void NotebookTab::setTitle(const QString &newTitle) +void NotebookTab::setCustomTitle(const QString &newTitle) { - if (this->title_ != newTitle) { - this->title_ = newTitle; - this->updateSize(); - this->update(); + if (this->customTitle_ != newTitle) { + this->customTitle_ = newTitle; + this->titleUpdated(); } } +void NotebookTab::resetCustomTitle() +{ + this->setCustomTitle(QString()); +} + +bool NotebookTab::hasCustomTitle() const +{ + return !this->customTitle_.isEmpty(); +} + +void NotebookTab::setDefaultTitle(const QString &title) +{ + if (this->defaultTitle_ != title) { + this->defaultTitle_ = title; + + if (this->customTitle_.isEmpty()) { + this->titleUpdated(); + } + } +} + +const QString &NotebookTab::getDefaultTitle() const +{ + return this->defaultTitle_; +} + +const QString &NotebookTab::getTitle() const +{ + return this->customTitle_.isEmpty() ? this->defaultTitle_ : this->customTitle_; +} + +void NotebookTab::titleUpdated() +{ + this->updateSize(); + this->update(); +} + bool NotebookTab::isSelected() const { return this->selected_; diff --git a/src/widgets/helper/notebooktab.hpp b/src/widgets/helper/notebooktab.hpp index a1a5971b6..93cb971f5 100644 --- a/src/widgets/helper/notebooktab.hpp +++ b/src/widgets/helper/notebooktab.hpp @@ -28,8 +28,14 @@ public: QWidget *page; + void setCustomTitle(const QString &title); + void resetCustomTitle(); + bool hasCustomTitle() const; + const QString &getCustomTitle() const; + void setDefaultTitle(const QString &title); + const QString &getDefaultTitle() const; const QString &getTitle() const; - void setTitle(const QString &newTitle); + bool isSelected() const; void setSelected(bool value); @@ -63,12 +69,9 @@ private: Notebook *notebook_; - QString title_; + QString customTitle_; + QString defaultTitle_; -public: - bool useDefaultTitle = true; - -private: bool selected_ = false; bool mouseOver_ = false; bool mouseDown_ = false; @@ -83,6 +86,7 @@ private: QMenu menu_; QRect getXRect(); + void titleUpdated(); }; } // namespace widgets diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index 0e9539e2e..f83aa38d6 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -43,10 +43,7 @@ NotebookTab *Notebook::addPage(QWidget *page, QString title, bool select) auto *tab = new NotebookTab(this); tab->page = page; - if (!title.isEmpty()) { - tab->setTitle(title); - tab->useDefaultTitle = false; - } + tab->setCustomTitle(title); Item item; item.page = page; diff --git a/src/widgets/selectchanneldialog.cpp b/src/widgets/selectchanneldialog.cpp index 6850625dc..fceb59c84 100644 --- a/src/widgets/selectchanneldialog.cpp +++ b/src/widgets/selectchanneldialog.cpp @@ -100,7 +100,7 @@ SelectChannelDialog::SelectChannelDialog() // tab NotebookTab *tab = notebook->addPage(obj.getElement()); - tab->setTitle("Twitch"); + tab->setCustomTitle("Twitch"); } // irc diff --git a/src/widgets/splitcontainer.cpp b/src/widgets/splitcontainer.cpp index 535e1f475..3969c95f1 100644 --- a/src/widgets/splitcontainer.cpp +++ b/src/widgets/splitcontainer.cpp @@ -506,10 +506,6 @@ void SplitContainer::refreshTabTitle() return; } - if (!this->tab->useDefaultTitle) { - return; - } - QString newTitle = ""; bool first = true; @@ -531,7 +527,7 @@ void SplitContainer::refreshTabTitle() newTitle = "empty"; } - this->tab->setTitle(newTitle); + this->tab->setDefaultTitle(newTitle); } int SplitContainer::getSplitCount()