show settings and user button when it's not available in the window

frame
This commit is contained in:
fourtf 2018-05-23 12:24:18 +02:00
parent 8b3fb691a7
commit 67e580059c
2 changed files with 45 additions and 4 deletions

View file

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

View file

@ -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<NotebookButton *> 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();