diff --git a/settings.cpp b/settings.cpp index 874c655d7..808f850b9 100644 --- a/settings.cpp +++ b/settings.cpp @@ -48,6 +48,8 @@ Settings::Settings() , inlineWhispers(this->settingsItems, "inlineWhispers", true) , windowTopMost(this->settingsItems, "windowTopMost", false) , hideTabX(this->settingsItems, "hideTabX", false) + , hidePreferencesButton(this->settingsItems, "hidePreferencesButton", false) + , hideUserButton(this->settingsItems, "hideUserButton", false) { this->showTimestamps.valueChanged.connect( [this](const auto &) { this->updateWordTypeMask(); }); diff --git a/settings.h b/settings.h index f147dfd35..94d605a1c 100644 --- a/settings.h +++ b/settings.h @@ -108,6 +108,8 @@ public: Setting inlineWhispers; Setting windowTopMost; Setting hideTabX; + Setting hidePreferencesButton; + Setting hideUserButton; }; } // namespace chatterino diff --git a/widgets/notebook.cpp b/widgets/notebook.cpp index cf1ddb8f3..83fe60af4 100644 --- a/widgets/notebook.cpp +++ b/widgets/notebook.cpp @@ -39,6 +39,11 @@ Notebook::Notebook(QWidget *parent) this->userButton.icon = NotebookButton::IconUser; this->addButton.resize(24, 24); + + Settings::getInstance().hidePreferencesButton.valueChanged.connect( + [this](const bool &) { this->performLayout(); }); + Settings::getInstance().hideUserButton.valueChanged.connect( + [this](const bool &) { this->performLayout(); }); } NotebookPage * @@ -140,7 +145,21 @@ Notebook::rearrangePage(NotebookPage *page, int index) void Notebook::performLayout(bool animated) { - int x = 48, y = 0; + int x = 0, y = 0; + + if (Settings::getInstance().hidePreferencesButton.get()) { + settingsButton.hide(); + } else { + settingsButton.show(); + x += 24; + } + if (Settings::getInstance().hideUserButton.get()) { + userButton.hide(); + } else { + userButton.show(); + x += 24; + } + int tabHeight = 16; bool first = true; diff --git a/widgets/notebookpage.cpp b/widgets/notebookpage.cpp index 591ecdbe1..51b44fb16 100644 --- a/widgets/notebookpage.cpp +++ b/widgets/notebookpage.cpp @@ -76,8 +76,9 @@ NotebookPage::removeFromLayout(ChatWidget *widget) } void -NotebookPage::addToLayout(ChatWidget *widget, std::pair position = - std::pair(-1, -1)) +NotebookPage::addToLayout( + ChatWidget *widget, + std::pair position = std::pair(-1, -1)) { this->chatWidgets.push_back(widget); diff --git a/widgets/notebookpage.h b/widgets/notebookpage.h index 50c04cc9e..c1dde3af2 100644 --- a/widgets/notebookpage.h +++ b/widgets/notebookpage.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace chatterino { namespace widgets { diff --git a/widgets/notebooktab.cpp b/widgets/notebooktab.cpp index 2ba6d5693..03c8085bc 100644 --- a/widgets/notebooktab.cpp +++ b/widgets/notebooktab.cpp @@ -27,25 +27,16 @@ NotebookTab::NotebookTab(Notebook *notebook) posAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic)); - /* XXX(pajlada): Fix this - QObject::connect(&Settings::getInstance().getHideTabX(), - &BoolSetting::valueChanged, this, - &NotebookTab::hideTabXChanged); - */ - - // Settings::getInstance().hideTabX.valueChanged.connect( - // boost::bind(&NotebookTab::hideTabXChanged, this)); + this->hideXConnection = + Settings::getInstance().hideTabX.valueChanged.connect( + boost::bind(&NotebookTab::hideTabXChanged, this, _1)); this->setMouseTracking(true); } NotebookTab::~NotebookTab() { - /* XXX(pajlada): Fix this - QObject::disconnect(&Settings::getInstance().getHideTabX(), - &BoolSetting::valueChanged, this, - &NotebookTab::hideTabXChanged); - */ + this->hideXConnection.disconnect(); } void @@ -56,13 +47,15 @@ NotebookTab::calcSize() } else { this->resize(this->fontMetrics().width(this->title) + 8 + 24, 24); } + + if (this->parent() != nullptr) { + ((Notebook *)this->parent())->performLayout(true); + } } void NotebookTab::moveAnimated(QPoint pos, bool animated) { - // move(pos); - posAnimationDesired = pos; if ((this->window() != NULL && !this->window()->isVisible()) || !animated || @@ -151,7 +144,8 @@ NotebookTab::mouseReleaseEvent(QMouseEvent *event) { this->mouseDown = false; - if (this->mouseDownX && this->getXRect().contains(event->pos())) { + if (!Settings::getInstance().hideTabX.get() && this->mouseDownX && + this->getXRect().contains(event->pos())) { this->mouseDownX = false; this->notebook->removePage(this->page); @@ -188,7 +182,7 @@ NotebookTab::mouseMoveEvent(QMouseEvent *event) bool overX = this->getXRect().contains(event->pos()); if (overX != this->mouseOverX) { - this->mouseOverX = overX; + this->mouseOverX = overX && !Settings::getInstance().hideTabX.get(); this->update(); } diff --git a/widgets/notebooktab.h b/widgets/notebooktab.h index 4a4dc6e59..fa90d9a99 100644 --- a/widgets/notebooktab.h +++ b/widgets/notebooktab.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include namespace chatterino { namespace widgets { @@ -76,6 +78,13 @@ public: return QRect(posAnimationDesired, this->size()); } + void + hideTabXChanged(bool) + { + calcSize(); + update(); + } + protected: void paintEvent(QPaintEvent *) override; @@ -89,6 +98,8 @@ protected: void mouseMoveEvent(QMouseEvent *event) override; private: + boost::signals2::connection hideXConnection; + QPropertyAnimation posAnimation; bool posAnimated; QPoint posAnimationDesired; @@ -111,14 +122,6 @@ private: return QRect(this->width() - 20, 4, 16, 16); } -private slots: - void - hideTabXChanged(bool) - { - calcSize(); - update(); - } - public: void load(const boost::property_tree::ptree &tree); boost::property_tree::ptree save(); diff --git a/widgets/settingsdialog.cpp b/widgets/settingsdialog.cpp index a23844f5f..dc1603774 100644 --- a/widgets/settingsdialog.cpp +++ b/widgets/settingsdialog.cpp @@ -76,10 +76,19 @@ SettingsDialog::addTabs() auto combo = new QComboBox(); auto slider = new QSlider(Qt::Horizontal); auto font = new QPushButton("select"); + auto compactTabs = createCheckbox("Hide tab X", settings.hideTabX); + auto hidePreferencesButton = + createCheckbox("Hide preferences button (ctrl+p to show)", + settings.hidePreferencesButton); + auto hideUserButton = + createCheckbox("Hide user button", settings.hideUserButton); form->addRow("Theme:", combo); form->addRow("Theme color:", slider); form->addRow("Font:", font); + form->addRow("", compactTabs); + form->addRow("", hidePreferencesButton); + form->addRow("", hideUserButton); // theme combo->addItem("White");