2017-01-18 21:30:23 +01:00
|
|
|
#include "widgets/notebook.h"
|
2017-01-01 02:30:42 +01:00
|
|
|
#include "colorscheme.h"
|
2017-01-18 21:30:23 +01:00
|
|
|
#include "widgets/notebookbutton.h"
|
|
|
|
#include "widgets/notebookpage.h"
|
|
|
|
#include "widgets/notebooktab.h"
|
|
|
|
#include "widgets/settingsdialog.h"
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QLayout>
|
|
|
|
#include <QList>
|
|
|
|
#include <QWidget>
|
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
|
|
|
|
2016-12-29 17:31:07 +01:00
|
|
|
Notebook::Notebook(QWidget *parent)
|
2017-01-11 18:52:09 +01:00
|
|
|
: QWidget(parent)
|
2017-01-18 04:33:30 +01:00
|
|
|
, addButton(this)
|
|
|
|
, settingsButton(this)
|
|
|
|
, userButton(this)
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
connect(&this->settingsButton, SIGNAL(clicked()), this,
|
2017-01-11 18:52:09 +01:00
|
|
|
SLOT(settingsButtonClicked()));
|
2017-01-01 18:43:52 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
this->settingsButton.resize(24, 24);
|
|
|
|
this->settingsButton.icon = NotebookButton::IconSettings;
|
|
|
|
this->userButton.resize(24, 24);
|
|
|
|
this->userButton.move(24, 0);
|
|
|
|
this->userButton.icon = NotebookButton::IconUser;
|
|
|
|
this->addButton.resize(24, 24);
|
2016-12-29 17:31:07 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
Notebook::settingsButtonClicked()
|
2017-01-01 18:43:52 +01:00
|
|
|
{
|
2017-01-11 18:52:09 +01:00
|
|
|
SettingsDialog *a = new SettingsDialog();
|
2017-01-01 18:43:52 +01:00
|
|
|
|
|
|
|
a->show();
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +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);
|
2017-01-01 02:30:42 +01:00
|
|
|
auto page = new NotebookPage(this, tab);
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
if (this->pages.count() == 0) {
|
2016-12-30 18:00:25 +01:00
|
|
|
select(page);
|
|
|
|
}
|
2016-12-29 18:45:08 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
this->pages.append(page);
|
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
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
Notebook::select(NotebookPage *page)
|
2016-12-30 18:00:25 +01:00
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
if (page == this->selectedPage)
|
2017-01-11 18:52:09 +01:00
|
|
|
return;
|
2016-12-30 18:00:25 +01:00
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (page != nullptr) {
|
2017-01-01 02:30:42 +01:00
|
|
|
page->setHidden(false);
|
2016-12-30 18:00:25 +01:00
|
|
|
page->tab->setSelected(true);
|
|
|
|
}
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
if (this->selectedPage != nullptr) {
|
|
|
|
this->selectedPage->setHidden(true);
|
|
|
|
this->selectedPage->tab->setSelected(false);
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
this->selectedPage = page;
|
2016-12-30 18:00:25 +01:00
|
|
|
|
|
|
|
performLayout();
|
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
Notebook::performLayout()
|
2016-12-30 12:20:26 +01:00
|
|
|
{
|
|
|
|
int x = 48, y = 0;
|
|
|
|
int tabHeight = 16;
|
2016-12-30 18:00:25 +01:00
|
|
|
bool first = true;
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
for (auto &i : this->pages) {
|
2016-12-30 12:20:26 +01:00
|
|
|
tabHeight = i->tab->height();
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (!first &&
|
2017-01-18 04:33:30 +01:00
|
|
|
(i == this->pages.last() ? tabHeight : 0) + x + i->tab->width() >
|
2017-01-11 18:52:09 +01:00
|
|
|
width()) {
|
|
|
|
y += i->tab->height();
|
2016-12-30 12:20:26 +01:00
|
|
|
i->tab->move(0, y);
|
|
|
|
x = i->tab->width();
|
2017-01-11 18:52:09 +01:00
|
|
|
} else {
|
2016-12-30 12:20:26 +01:00
|
|
|
i->tab->move(x, y);
|
|
|
|
x += i->tab->width();
|
|
|
|
}
|
|
|
|
|
2016-12-30 18:00:25 +01:00
|
|
|
first = false;
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
this->addButton.move(x, y);
|
2016-12-30 18:00:25 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
if (this->selectedPage != nullptr) {
|
|
|
|
this->selectedPage->move(0, y + tabHeight);
|
|
|
|
this->selectedPage->resize(width(), height() - y - tabHeight);
|
2016-12-30 18:00:25 +01:00
|
|
|
}
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void
|
|
|
|
Notebook::resizeEvent(QResizeEvent *)
|
2016-12-30 12:20:26 +01:00
|
|
|
{
|
2016-12-30 18:00:25 +01:00
|
|
|
performLayout();
|
2016-12-30 12:20:26 +01:00
|
|
|
}
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
|
|
|
}
|