2016-12-29 17:31:07 +01:00
|
|
|
#include "QWidget"
|
2016-12-30 12:20:26 +01:00
|
|
|
#include "QList"
|
2016-12-29 17:31:07 +01:00
|
|
|
#include "notebook.h"
|
2016-12-30 12:20:26 +01:00
|
|
|
#include "notebooktab.h"
|
2016-12-29 17:31:07 +01:00
|
|
|
#include "notebookpage.h"
|
2016-12-30 12:20:26 +01:00
|
|
|
#include "notebookbutton.h"
|
2016-12-29 17:31:07 +01:00
|
|
|
|
|
|
|
Notebook::Notebook(QWidget *parent)
|
2016-12-30 12:20:26 +01:00
|
|
|
: QWidget(parent),
|
|
|
|
addButton(this),
|
|
|
|
settingsButton(this),
|
|
|
|
userButton(this)
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2016-12-30 12:20:26 +01:00
|
|
|
settingsButton.resize(24, 24);
|
|
|
|
settingsButton.icon = NotebookButton::IconSettings;
|
|
|
|
userButton.resize(24, 24);
|
|
|
|
userButton.move(24, 0);
|
|
|
|
userButton.icon = NotebookButton::IconUser;
|
|
|
|
addButton.resize(24, 24);
|
2016-12-29 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
2016-12-30 12:20:26 +01:00
|
|
|
NotebookPage* Notebook::addPage()
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2016-12-30 12:20:26 +01:00
|
|
|
auto tab = new NotebookTab(this);
|
|
|
|
auto page = new NotebookPage(this, tab);
|
|
|
|
|
|
|
|
this->pages.append(page);
|
2016-12-29 18:45:08 +01:00
|
|
|
|
2016-12-30 12:20:26 +01:00
|
|
|
layout();
|
2016-12-29 18:45:08 +01:00
|
|
|
|
|
|
|
return page;
|
2016-12-29 17:31:07 +01:00
|
|
|
}
|
2016-12-30 12:20:26 +01:00
|
|
|
|
|
|
|
void Notebook::layout()
|
|
|
|
{
|
|
|
|
int x = 48, y = 0;
|
|
|
|
int tabHeight = 16;
|
|
|
|
bool firstInLine = true;
|
|
|
|
|
|
|
|
for (auto &i : this->pages)
|
|
|
|
{
|
|
|
|
tabHeight = i->tab->height();
|
|
|
|
|
|
|
|
if (!firstInLine && (i == this->pages.last() ? tabHeight : 0) + x + i->width() > this->width())
|
|
|
|
{
|
|
|
|
y +=i->tab->height();
|
|
|
|
i->tab->move(0, y);
|
|
|
|
x = i->tab->width();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i->tab->move(x, y);
|
|
|
|
x += i->tab->width();
|
|
|
|
}
|
|
|
|
|
|
|
|
firstInLine = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->addButton.move(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Notebook::resizeEvent(QResizeEvent *)
|
|
|
|
{
|
|
|
|
layout();
|
|
|
|
}
|