2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/Notebook.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
|
|
|
#include "debug/Log.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
2018-06-28 20:03:04 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "singletons/WindowManager.hpp"
|
2018-07-05 12:52:36 +02:00
|
|
|
#include "util/InitUpdateButton.hpp"
|
2018-06-26 17:20:03 +02:00
|
|
|
#include "widgets/Window.hpp"
|
|
|
|
#include "widgets/dialogs/SettingsDialog.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/helper/NotebookButton.hpp"
|
|
|
|
#include "widgets/helper/NotebookTab.hpp"
|
2018-11-22 22:10:29 +01:00
|
|
|
#include "util/Shortcut.hpp"
|
2018-10-20 13:25:24 +02:00
|
|
|
#include "widgets/splits/Split.hpp"
|
2018-06-26 14:39:22 +02:00
|
|
|
#include "widgets/splits/SplitContainer.hpp"
|
2016-12-29 17:31:07 +01:00
|
|
|
|
2017-01-28 22:35:23 +01:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QFile>
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QLayout>
|
|
|
|
#include <QList>
|
2017-05-29 21:26:55 +02:00
|
|
|
#include <QShortcut>
|
2017-01-28 22:35:23 +01:00
|
|
|
#include <QStandardPaths>
|
2017-12-22 14:44:31 +01:00
|
|
|
#include <QUuid>
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QWidget>
|
2017-01-28 22:35:23 +01:00
|
|
|
#include <boost/foreach.hpp>
|
2017-01-18 04:52:47 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
Notebook::Notebook(QWidget *parent)
|
2018-04-27 22:11:19 +02:00
|
|
|
: BaseWidget(parent)
|
2018-08-11 22:23:06 +02:00
|
|
|
, addButton_(new NotebookButton(this))
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-08-11 22:23:06 +02:00
|
|
|
this->addButton_->setIcon(NotebookButton::Icon::Plus);
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
this->addButton_->setHidden(true);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
auto *shortcut_next = new QShortcut(QKeySequence("Ctrl+Tab"), this);
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(shortcut_next, &QShortcut::activated,
|
|
|
|
[this] { this->selectNextTab(); });
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
auto *shortcut_prev = new QShortcut(QKeySequence("Ctrl+Shift+Tab"), this);
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(shortcut_prev, &QShortcut::activated,
|
|
|
|
[this] { this->selectPreviousTab(); });
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
NotebookTab *Notebook::addPage(QWidget *page, QString title, bool select)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-07 18:27:40 +02:00
|
|
|
// Queue up save because: Tab added
|
|
|
|
getApp()->windows->queueSave();
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
auto *tab = new NotebookTab(this);
|
2018-04-18 09:12:29 +02:00
|
|
|
tab->page = page;
|
|
|
|
|
2018-06-01 16:01:49 +02:00
|
|
|
tab->setCustomTitle(title);
|
2018-04-18 17:51:53 +02:00
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
Item item;
|
|
|
|
item.page = page;
|
|
|
|
item.tab = tab;
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->items_.append(item);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
page->hide();
|
|
|
|
page->setParent(this);
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (select || this->items_.count() == 1)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
this->select(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->performLayout();
|
|
|
|
|
2018-06-04 12:54:09 +02:00
|
|
|
tab->show();
|
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::removePage(QWidget *page)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-07 18:27:40 +02:00
|
|
|
// Queue up save because: Tab removed
|
|
|
|
getApp()->windows->queueSave();
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (int i = 0; i < this->items_.count(); i++)
|
|
|
|
{
|
|
|
|
if (this->items_[i].page == page)
|
|
|
|
{
|
|
|
|
if (this->items_.count() == 1)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
this->select(nullptr);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (i == this->items_.count() - 1)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->select(this->items_[i - 1].page);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->select(this->items_[i + 1].page);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->items_[i].page->deleteLater();
|
|
|
|
this->items_[i].tab->deleteLater();
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
// if (this->items.empty()) {
|
|
|
|
// this->addNewPage();
|
|
|
|
// }
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->items_.removeAt(i);
|
2018-04-18 09:12:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-05-23 04:22:17 +02:00
|
|
|
|
2018-06-01 14:46:41 +02:00
|
|
|
this->performLayout(true);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::removeCurrentPage()
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->selectedPage_ != nullptr)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->removePage(this->selectedPage_);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
int Notebook::indexOf(QWidget *page) const
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
for (int i = 0; i < this->items_.count(); i++)
|
|
|
|
{
|
|
|
|
if (this->items_[i].page == page)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::select(QWidget *page)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (page == this->selectedPage_)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (page != nullptr)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
page->setHidden(false);
|
|
|
|
|
2018-05-31 16:02:20 +02:00
|
|
|
assert(this->containsPage(page));
|
|
|
|
Item &item = this->findItem(page);
|
|
|
|
|
|
|
|
item.tab->setSelected(true);
|
|
|
|
item.tab->raise();
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (item.selectedWidget == nullptr)
|
|
|
|
{
|
2018-05-31 16:02:20 +02:00
|
|
|
item.page->setFocus();
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (containsChild(page, item.selectedWidget))
|
|
|
|
{
|
2018-05-31 16:02:20 +02:00
|
|
|
qDebug() << item.selectedWidget;
|
|
|
|
item.selectedWidget->setFocus(Qt::MouseFocusReason);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
qDebug()
|
|
|
|
<< "Notebook: selected child of page doesn't exist anymore";
|
2018-05-31 16:02:20 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->selectedPage_ != nullptr)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->selectedPage_->setHidden(true);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
Item &item = this->findItem(selectedPage_);
|
2018-05-31 16:02:20 +02:00
|
|
|
item.tab->setSelected(false);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
// for (auto split : this->selectedPage->getSplits()) {
|
|
|
|
// split->updateLastReadMessage();
|
|
|
|
// }
|
2018-05-31 16:02:20 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
item.selectedWidget = this->selectedPage_->focusWidget();
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->selectedPage_ = page;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
this->performLayout();
|
|
|
|
}
|
|
|
|
|
2018-05-31 16:02:20 +02:00
|
|
|
bool Notebook::containsPage(QWidget *page)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return std::any_of(this->items_.begin(), this->items_.end(),
|
2018-05-31 16:02:20 +02:00
|
|
|
[page](const auto &item) { return item.page == page; });
|
|
|
|
}
|
|
|
|
|
|
|
|
Notebook::Item &Notebook::findItem(QWidget *page)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
auto it =
|
|
|
|
std::find_if(this->items_.begin(), this->items_.end(),
|
|
|
|
[page](const auto &item) { return page == item.page; });
|
2018-07-06 19:23:47 +02:00
|
|
|
assert(it != this->items_.end());
|
2018-05-31 16:02:20 +02:00
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Notebook::containsChild(const QObject *obj, const QObject *child)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
return std::any_of(obj->children().begin(), obj->children().end(),
|
|
|
|
[child](const QObject *o) {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (o == child)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
2018-05-31 16:02:20 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
return containsChild(o, child);
|
|
|
|
});
|
2018-05-31 16:02:20 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::selectIndex(int index)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (index < 0 || this->items_.count() <= index)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->select(this->items_[index].page);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::selectNextTab()
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->items_.size() <= 1)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
auto index =
|
|
|
|
(this->indexOf(this->selectedPage_) + 1) % this->items_.count();
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->select(this->items_[index].page);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::selectPreviousTab()
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->items_.size() <= 1)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
int index = this->indexOf(this->selectedPage_) - 1;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (index < 0)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
index += this->items_.count();
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->select(this->items_[index].page);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
int Notebook::getPageCount() const
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->items_.count();
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
QWidget *Notebook::getPageAt(int index) const
|
2018-05-23 04:22:17 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->items_[index].page;
|
2018-05-23 04:22:17 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
int Notebook::getSelectedIndex() const
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->indexOf(this->selectedPage_);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
QWidget *Notebook::getSelectedPage() const
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->selectedPage_;
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
QWidget *Notebook::tabAt(QPoint point, int &index, int maxWidth)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 12:13:09 +02:00
|
|
|
auto i = 0;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &item : this->items_)
|
|
|
|
{
|
2018-10-21 12:13:09 +02:00
|
|
|
auto rect = item.tab->getDesiredRect();
|
2018-11-21 21:37:41 +01:00
|
|
|
rect.setHeight(int(this->scale() * 24));
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
rect.setWidth(std::min(maxWidth, rect.width()));
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (rect.contains(point))
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
index = i;
|
|
|
|
return item.page;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = -1;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::rearrangePage(QWidget *page, int index)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-07 18:27:40 +02:00
|
|
|
// Queue up save because: Tab rearranged
|
|
|
|
getApp()->windows->queueSave();
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->items_.move(this->indexOf(page), index);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-06-01 14:46:41 +02:00
|
|
|
this->performLayout(true);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
bool Notebook::getAllowUserTabManagement() const
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->allowUserTabManagement_;
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::setAllowUserTabManagement(bool value)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->allowUserTabManagement_ = value;
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
bool Notebook::getShowAddButton() const
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->showAddButton_;
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::setShowAddButton(bool value)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->showAddButton_ = value;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
this->addButton_->setHidden(!value);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::scaleChangedEvent(float scale)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-11-21 21:37:41 +01:00
|
|
|
float h = (NOTEBOOK_TAB_HEIGHT - 1) * this->scale();
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
this->addButton_->setFixedSize(h, h);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &i : this->items_)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
i.tab->updateSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::resizeEvent(QResizeEvent *)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
|
|
|
this->performLayout();
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::performLayout(bool animated)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-11-21 21:37:41 +01:00
|
|
|
const auto left = int(2 * this->scale());
|
|
|
|
const auto scale = this->scale();
|
2018-10-21 12:13:09 +02:00
|
|
|
const auto tabHeight = int(NOTEBOOK_TAB_HEIGHT * scale);
|
|
|
|
const auto addButtonWidth = this->showAddButton_ ? tabHeight : 0;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
auto x = left;
|
|
|
|
auto y = 0;
|
2018-05-23 12:24:18 +02:00
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
// set size of custom buttons (settings, user, ...)
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto *btn : this->customButtons_)
|
|
|
|
{
|
|
|
|
if (!btn->isVisible())
|
|
|
|
{
|
2018-06-04 15:36:48 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-10-22 19:57:02 +02:00
|
|
|
btn->setFixedSize(tabHeight, tabHeight - 1);
|
2018-05-23 12:24:18 +02:00
|
|
|
btn->move(x, 0);
|
2018-10-21 12:13:09 +02:00
|
|
|
x += tabHeight;
|
2018-05-23 12:24:18 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
// layout tabs
|
|
|
|
/// Notebook tabs need to know if they are in the last row.
|
|
|
|
auto firstInBottomRow =
|
|
|
|
this->items_.size() ? &this->items_.front() : nullptr;
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &item : this->items_)
|
|
|
|
{
|
2018-10-21 12:13:09 +02:00
|
|
|
/// Break line if element doesn't fit.
|
|
|
|
auto isFirst = &item == &this->items_.front();
|
|
|
|
auto isLast = &item == &this->items_.back();
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
auto fitsInLine =
|
|
|
|
((isLast ? addButtonWidth : 0) + x + item.tab->width()) <= width();
|
2018-06-01 14:46:41 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!isFirst && !fitsInLine)
|
|
|
|
{
|
2018-10-21 12:13:09 +02:00
|
|
|
y += item.tab->height();
|
|
|
|
x = left;
|
|
|
|
firstInBottomRow = &item;
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
/// Layout tab
|
|
|
|
item.tab->moveAnimated(QPoint(x, y), animated);
|
2018-11-01 10:16:55 +01:00
|
|
|
x += item.tab->width() + std::max<int>(1, int(scale * 1));
|
2018-10-21 12:13:09 +02:00
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
/// Update which tabs are in the last row
|
|
|
|
auto inLastRow = false;
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const auto &item : this->items_)
|
|
|
|
{
|
|
|
|
if (&item == firstInBottomRow)
|
|
|
|
{
|
2018-10-21 12:13:09 +02:00
|
|
|
inLastRow = true;
|
|
|
|
}
|
|
|
|
item.tab->setInLastRow(inLastRow);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
// move misc buttons
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->showAddButton_)
|
|
|
|
{
|
2018-08-11 22:23:06 +02:00
|
|
|
this->addButton_->move(x, y);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->lineY_ != y + tabHeight)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->lineY_ = y + tabHeight;
|
2018-04-18 09:12:29 +02:00
|
|
|
this->update();
|
|
|
|
}
|
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
/// Increment for the line at the bottom
|
|
|
|
y += int(2 * scale);
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
// raise elements
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &i : this->items_)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
i.tab->raise();
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->showAddButton_)
|
|
|
|
{
|
2018-08-11 22:23:06 +02:00
|
|
|
this->addButton_->raise();
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
// set page bounds
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->selectedPage_ != nullptr)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->selectedPage_->move(0, y + tabHeight);
|
|
|
|
this->selectedPage_->resize(width(), height() - y - tabHeight);
|
|
|
|
this->selectedPage_->raise();
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
void Notebook::paintEvent(QPaintEvent *event)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
|
|
|
BaseWidget::paintEvent(event);
|
|
|
|
|
|
|
|
QPainter painter(this);
|
2018-11-21 21:37:41 +01:00
|
|
|
painter.fillRect(0, this->lineY_, this->width(), int(2 * this->scale()),
|
2018-10-21 12:13:09 +02:00
|
|
|
this->theme->tabs.bottomLine);
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
NotebookButton *Notebook::getAddButton()
|
2018-05-23 04:22:17 +02:00
|
|
|
{
|
2018-08-11 22:23:06 +02:00
|
|
|
return this->addButton_;
|
2018-05-23 04:22:17 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 12:24:18 +02:00
|
|
|
NotebookButton *Notebook::addCustomButton()
|
|
|
|
{
|
|
|
|
NotebookButton *btn = new NotebookButton(this);
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->customButtons_.push_back(btn);
|
2018-05-23 12:24:18 +02:00
|
|
|
|
|
|
|
this->performLayout();
|
|
|
|
return btn;
|
|
|
|
}
|
|
|
|
|
2018-05-23 11:59:37 +02:00
|
|
|
NotebookTab *Notebook::getTabFromPage(QWidget *page)
|
2018-04-18 09:12:29 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &it : this->items_)
|
|
|
|
{
|
|
|
|
if (it.page == page)
|
|
|
|
{
|
2018-04-18 09:12:29 +02:00
|
|
|
return it.tab;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-23 12:24:18 +02:00
|
|
|
SplitNotebook::SplitNotebook(Window *parent)
|
2018-05-23 11:59:37 +02:00
|
|
|
: Notebook(parent)
|
2016-12-29 17:31:07 +01:00
|
|
|
{
|
2018-10-21 16:13:26 +02:00
|
|
|
this->connect(this->getAddButton(), &NotebookButton::leftClicked, [this]() {
|
2018-08-06 21:17:03 +02:00
|
|
|
QTimer::singleShot(80, this, [this] { this->addPage(true); });
|
|
|
|
});
|
2018-05-23 12:24:18 +02:00
|
|
|
|
2018-10-21 12:13:09 +02:00
|
|
|
// add custom buttons if they are not in the parent window frame
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!parent->hasCustomWindowFrame())
|
|
|
|
{
|
2018-07-05 12:52:36 +02:00
|
|
|
this->addCustomButtons();
|
2018-05-23 12:24:18 +02:00
|
|
|
}
|
2017-01-01 18:43:52 +01:00
|
|
|
}
|
|
|
|
|
2018-07-05 12:52:36 +02:00
|
|
|
void SplitNotebook::addCustomButtons()
|
|
|
|
{
|
|
|
|
// settings
|
|
|
|
auto settingsBtn = this->addCustomButton();
|
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
settingsBtn->setVisible(!getSettings()->hidePreferencesButton.getValue());
|
2018-07-05 12:52:36 +02:00
|
|
|
|
2018-08-12 12:56:28 +02:00
|
|
|
getSettings()->hidePreferencesButton.connect(
|
2018-08-06 21:17:03 +02:00
|
|
|
[settingsBtn](bool hide, auto) { settingsBtn->setVisible(!hide); },
|
|
|
|
this->connections_);
|
2018-07-05 12:52:36 +02:00
|
|
|
|
2018-07-05 13:25:10 +02:00
|
|
|
settingsBtn->setIcon(NotebookButton::Settings);
|
2018-07-05 12:52:36 +02:00
|
|
|
|
2018-10-21 16:13:26 +02:00
|
|
|
QObject::connect(settingsBtn, &NotebookButton::leftClicked,
|
2018-07-05 12:52:36 +02:00
|
|
|
[] { getApp()->windows->showSettingsDialog(); });
|
|
|
|
|
|
|
|
// account
|
|
|
|
auto userBtn = this->addCustomButton();
|
2018-08-12 12:56:28 +02:00
|
|
|
userBtn->setVisible(!getSettings()->hideUserButton.getValue());
|
|
|
|
getSettings()->hideUserButton.connect(
|
2018-08-06 21:17:03 +02:00
|
|
|
[userBtn](bool hide, auto) { userBtn->setVisible(!hide); },
|
|
|
|
this->connections_);
|
2018-07-05 12:52:36 +02:00
|
|
|
|
2018-07-05 13:25:10 +02:00
|
|
|
userBtn->setIcon(NotebookButton::User);
|
2018-10-21 16:13:26 +02:00
|
|
|
QObject::connect(userBtn, &NotebookButton::leftClicked, [this, userBtn] {
|
2018-08-06 21:17:03 +02:00
|
|
|
getApp()->windows->showAccountSelectPopup(
|
|
|
|
this->mapToGlobal(userBtn->rect().bottomRight()));
|
2018-07-05 12:52:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// updates
|
|
|
|
auto updateBtn = this->addCustomButton();
|
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
initUpdateButton(*updateBtn, this->signalHolder_);
|
2018-07-05 12:52:36 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
SplitContainer *SplitNotebook::addPage(bool select)
|
2017-12-22 14:44:31 +01:00
|
|
|
{
|
2018-10-21 12:13:09 +02:00
|
|
|
auto container = new SplitContainer(this);
|
|
|
|
auto tab = Notebook::addPage(container, QString(), select);
|
2018-05-23 04:22:17 +02:00
|
|
|
container->setTab(tab);
|
|
|
|
tab->setParent(this);
|
2017-01-22 12:46:35 +01:00
|
|
|
tab->show();
|
2018-05-23 04:22:17 +02:00
|
|
|
return container;
|
2016-12-29 17:31:07 +01:00
|
|
|
}
|
2016-12-30 12:20:26 +01:00
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
SplitContainer *SplitNotebook::getOrAddSelectedPage()
|
2017-01-22 05:58:23 +01:00
|
|
|
{
|
2018-05-23 04:22:17 +02:00
|
|
|
auto *selectedPage = this->getSelectedPage();
|
2018-01-22 21:31:45 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
return selectedPage != nullptr ? (SplitContainer *)selectedPage
|
|
|
|
: this->addPage();
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
2017-01-28 22:35:23 +01:00
|
|
|
|
2018-10-20 13:25:24 +02:00
|
|
|
void SplitNotebook::select(QWidget *page)
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (auto selectedPage = this->getSelectedPage())
|
|
|
|
{
|
|
|
|
if (auto splitContainer = dynamic_cast<SplitContainer *>(selectedPage))
|
|
|
|
{
|
|
|
|
for (auto split : splitContainer->getSplits())
|
|
|
|
{
|
2018-10-20 13:25:24 +02:00
|
|
|
split->updateLastReadMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->Notebook::select(page);
|
|
|
|
}
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|