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
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

View file

@ -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.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<int>(this->height(), std::min(int(150 * scale), width));
@ -103,19 +91,55 @@ 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->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()
{
if (this->title_ != newTitle) {
this->title_ = newTitle;
this->updateSize();
this->update();
}
}
bool NotebookTab::isSelected() const
{

View file

@ -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

View file

@ -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;

View file

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

View file

@ -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()