From 67e580059c4ec5aae5de2e25651ebea4e5f54193 Mon Sep 17 00:00:00 2001 From: fourtf Date: Wed, 23 May 2018 12:24:18 +0200 Subject: [PATCH] show settings and user button when it's not available in the window frame --- src/widgets/notebook.cpp | 45 +++++++++++++++++++++++++++++++++++++--- src/widgets/notebook.hpp | 4 +++- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index b52abe62c..818a885a1 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -251,8 +251,6 @@ void Notebook::scaleChangedEvent(float scale) { float h = NOTEBOOK_TAB_HEIGHT * this->getScale(); - // this->settingsButton.setFixedSize(h, h); - // this->userButton.setFixedSize(h, h); this->addButton.setFixedSize(h, h); for (auto &i : this->items) { @@ -297,6 +295,14 @@ void Notebook::performLayout(bool animated) // x += (int)(scale * 2); // } + float h = NOTEBOOK_TAB_HEIGHT * this->getScale(); + + for (auto *btn : this->customButtons) { + btn->setFixedSize(h, h); + btn->move(x, 0); + x += h; + } + int tabHeight = static_cast(NOTEBOOK_TAB_HEIGHT * scale); bool first = true; @@ -361,6 +367,16 @@ NotebookButton *Notebook::getAddButton() return &this->addButton; } +NotebookButton *Notebook::addCustomButton() +{ + NotebookButton *btn = new NotebookButton(this); + + this->customButtons.push_back(btn); + + this->performLayout(); + return btn; +} + NotebookTab *Notebook::getTabFromPage(QWidget *page) { for (auto &it : this->items) { @@ -372,11 +388,34 @@ NotebookTab *Notebook::getTabFromPage(QWidget *page) return nullptr; } -SplitNotebook::SplitNotebook(QWidget *parent) +SplitNotebook::SplitNotebook(Window *parent) : Notebook(parent) { this->connect(this->getAddButton(), &NotebookButton::clicked, [this]() { QTimer::singleShot(80, this, [this] { this->addPage(true); }); }); + + bool customFrame = parent->hasCustomWindowFrame(); + + if (!customFrame) { + auto *settingsBtn = this->addCustomButton(); + auto *userBtn = this->addCustomButton(); + + // app->settings->hidePreferencesButton.connectSimple( + // [this](bool hide) { this->performLayout(); }); + // app->settings->hideUserButton.connectSimple([this](auto) { this->performLayout(); + // }); + + settingsBtn->icon = NotebookButton::IconSettings; + userBtn->icon = NotebookButton::IconUser; + + QObject::connect(settingsBtn, &NotebookButton::clicked, + [this] { getApp()->windows->showSettingsDialog(); }); + + QObject::connect(userBtn, &NotebookButton::clicked, [this, userBtn] { + getApp()->windows->showAccountSelectPopup( + this->mapToGlobal(userBtn->rect().bottomRight())); + }); + } } SplitContainer *SplitNotebook::addPage(bool select) diff --git a/src/widgets/notebook.hpp b/src/widgets/notebook.hpp index e9b2e72b7..e578e17a8 100644 --- a/src/widgets/notebook.hpp +++ b/src/widgets/notebook.hpp @@ -53,6 +53,7 @@ protected: virtual void paintEvent(QPaintEvent *) override; NotebookButton *getAddButton(); + NotebookButton *addCustomButton(); private: struct Item { @@ -64,6 +65,7 @@ private: QWidget *selectedPage = nullptr; NotebookButton addButton; + std::vector customButtons; bool allowUserTabManagement = false; bool showAddButton = false; @@ -75,7 +77,7 @@ private: class SplitNotebook : public Notebook { public: - SplitNotebook(QWidget *parent); + SplitNotebook(Window *parent); SplitContainer *addPage(bool select = false); SplitContainer *getOrAddSelectedPage();