fixed tab name sometimes not changing

This commit is contained in:
fourtf 2018-06-01 16:01:49 +02:00
parent 9e36af26fa
commit 04b7cc5ce8
6 changed files with 64 additions and 44 deletions

View file

@ -195,8 +195,7 @@ void WindowManager::initialize()
// set custom title // set custom title
QJsonValue title_val = tab_obj.value("title"); QJsonValue title_val = tab_obj.value("title");
if (title_val.isString()) { if (title_val.isString()) {
page->getTab()->setTitle(title_val.toString()); page->getTab()->setCustomTitle(title_val.toString());
page->getTab()->useDefaultTitle = false;
} }
// selected // selected
@ -275,8 +274,8 @@ void WindowManager::save()
assert(tab != nullptr); assert(tab != nullptr);
// custom tab title // custom tab title
if (!tab->getTab()->useDefaultTitle) { if (tab->getTab()->hasCustomTitle()) {
tab_obj.insert("title", tab->getTab()->getTitle()); tab_obj.insert("title", tab->getTab()->getCustomTitle());
} }
// selected // selected

View file

@ -41,24 +41,12 @@ NotebookTab::NotebookTab(Notebook *notebook)
TextInputDialog d(this); TextInputDialog d(this);
d.setWindowTitle("Change tab title (Leave empty for default behaviour)"); d.setWindowTitle("Change tab title (Leave empty for default behaviour)");
if (this->useDefaultTitle) { d.setText(this->getCustomTitle());
d.setText(""); d.highlightText();
} else {
d.setText(this->getTitle());
d.highlightText();
}
if (d.exec() == QDialog::Accepted) { if (d.exec() == QDialog::Accepted) {
QString newTitle = d.getText(); QString newTitle = d.getText();
if (newTitle.isEmpty()) { this->setCustomTitle(newTitle);
this->useDefaultTitle = true;
// fourtf: xD
// this->page->refreshTitle();
} else {
this->useDefaultTitle = false;
this->setTitle(newTitle);
}
} }
}); });
@ -90,9 +78,9 @@ void NotebookTab::updateSize()
FontStyle::UiTabs, float(qreal(this->getScale()) * this->devicePixelRatioF())); FontStyle::UiTabs, float(qreal(this->getScale()) * this->devicePixelRatioF()));
if (this->hasXButton()) { if (this->hasXButton()) {
width = int((metrics.width(this->title_) + 32) * scale); width = int((metrics.width(this->getTitle()) + 32) * scale);
} else { } else {
width = int((metrics.width(this->title_) + 16) * scale); width = int((metrics.width(this->getTitle()) + 16) * scale);
} }
width = std::max<int>(this->height(), std::min(int(150 * scale), width)); width = std::max<int>(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) { if (this->customTitle_ != newTitle) {
this->title_ = newTitle; this->customTitle_ = newTitle;
this->updateSize(); this->titleUpdated();
this->update();
} }
} }
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 bool NotebookTab::isSelected() const
{ {
return this->selected_; return this->selected_;

View file

@ -28,8 +28,14 @@ public:
QWidget *page; 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; const QString &getTitle() const;
void setTitle(const QString &newTitle);
bool isSelected() const; bool isSelected() const;
void setSelected(bool value); void setSelected(bool value);
@ -63,12 +69,9 @@ private:
Notebook *notebook_; Notebook *notebook_;
QString title_; QString customTitle_;
QString defaultTitle_;
public:
bool useDefaultTitle = true;
private:
bool selected_ = false; bool selected_ = false;
bool mouseOver_ = false; bool mouseOver_ = false;
bool mouseDown_ = false; bool mouseDown_ = false;
@ -83,6 +86,7 @@ private:
QMenu menu_; QMenu menu_;
QRect getXRect(); QRect getXRect();
void titleUpdated();
}; };
} // namespace widgets } // namespace widgets

View file

@ -43,10 +43,7 @@ NotebookTab *Notebook::addPage(QWidget *page, QString title, bool select)
auto *tab = new NotebookTab(this); auto *tab = new NotebookTab(this);
tab->page = page; tab->page = page;
if (!title.isEmpty()) { tab->setCustomTitle(title);
tab->setTitle(title);
tab->useDefaultTitle = false;
}
Item item; Item item;
item.page = page; item.page = page;

View file

@ -100,7 +100,7 @@ SelectChannelDialog::SelectChannelDialog()
// tab // tab
NotebookTab *tab = notebook->addPage(obj.getElement()); NotebookTab *tab = notebook->addPage(obj.getElement());
tab->setTitle("Twitch"); tab->setCustomTitle("Twitch");
} }
// irc // irc

View file

@ -506,10 +506,6 @@ void SplitContainer::refreshTabTitle()
return; return;
} }
if (!this->tab->useDefaultTitle) {
return;
}
QString newTitle = ""; QString newTitle = "";
bool first = true; bool first = true;
@ -531,7 +527,7 @@ void SplitContainer::refreshTabTitle()
newTitle = "empty"; newTitle = "empty";
} }
this->tab->setTitle(newTitle); this->tab->setDefaultTitle(newTitle);
} }
int SplitContainer::getSplitCount() int SplitContainer::getSplitCount()