asdf
This commit is contained in:
@@ -27,7 +27,7 @@ protected:
|
||||
private:
|
||||
QSize preferedSize;
|
||||
QString text;
|
||||
FontStyle fontStyle = FontStyle::Medium;
|
||||
FontStyle fontStyle = FontStyle::ChatMedium;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
@@ -136,10 +136,12 @@ void NotebookButton::dropEvent(QDropEvent *event)
|
||||
if (SplitContainer::isDraggingSplit) {
|
||||
event->acceptProposedAction();
|
||||
|
||||
Notebook *notebook = dynamic_cast<Notebook *>(this->parentWidget());
|
||||
Notebook2 *notebook = dynamic_cast<Notebook2 *>(this->parentWidget());
|
||||
|
||||
if (notebook != nuuls) {
|
||||
SplitContainer *page = notebook->addNewPage();
|
||||
SplitContainer *page = new SplitContainer(notebook);
|
||||
auto *tab = notebook->addPage(page);
|
||||
page->setTab(tab);
|
||||
|
||||
SplitContainer::draggingSplit->setParent(page);
|
||||
page->appendSplit(SplitContainer::draggingSplit);
|
||||
|
||||
@@ -61,17 +61,18 @@ NotebookTab2::NotebookTab2(Notebook2 *_notebook)
|
||||
}
|
||||
});
|
||||
|
||||
QAction *enableHighlightsOnNewMessageAction =
|
||||
new QAction("Enable highlights on new message", &this->menu);
|
||||
enableHighlightsOnNewMessageAction->setCheckable(true);
|
||||
// QAction *enableHighlightsOnNewMessageAction =
|
||||
// new QAction("Enable highlights on new message", &this->menu);
|
||||
// enableHighlightsOnNewMessageAction->setCheckable(true);
|
||||
|
||||
this->menu.addAction("Close", [=]() { this->notebook->removePage(this->page); });
|
||||
|
||||
this->menu.addAction(enableHighlightsOnNewMessageAction);
|
||||
// this->menu.addAction(enableHighlightsOnNewMessageAction);
|
||||
|
||||
QObject::connect(enableHighlightsOnNewMessageAction, &QAction::toggled, [this](bool newValue) {
|
||||
debug::Log("New value is {}", newValue); //
|
||||
});
|
||||
// QObject::connect(enableHighlightsOnNewMessageAction, &QAction::toggled, [this](bool
|
||||
// newValue) {
|
||||
// debug::Log("New value is {}", newValue); //
|
||||
// });
|
||||
}
|
||||
|
||||
void NotebookTab2::themeRefreshEvent()
|
||||
@@ -85,15 +86,20 @@ void NotebookTab2::updateSize()
|
||||
float scale = getScale();
|
||||
|
||||
int width;
|
||||
QFontMetrics metrics(this->font());
|
||||
QFontMetrics metrics = getApp()->fonts->getFontMetrics(FontStyle::UiTabs, this->getScale());
|
||||
|
||||
if (!app->settings->showTabCloseButton) {
|
||||
width = (int)((metrics.width(this->title) + 16 /*+ 16*/) * scale);
|
||||
if (this->hasXButton()) {
|
||||
width = (int)((metrics.width(this->title) + 32) * scale);
|
||||
} else {
|
||||
width = (int)((metrics.width(this->title) + 8 + 24 /*+ 16*/) * scale);
|
||||
width = (int)((metrics.width(this->title) + 16) * scale);
|
||||
}
|
||||
|
||||
this->resize(std::min((int)(150 * scale), width), (int)(24 * scale));
|
||||
width = std::min((int)(150 * scale), width);
|
||||
|
||||
if (this->width() != width) {
|
||||
this->resize(width, (int)(NOTEBOOK_TAB_HEIGHT * scale));
|
||||
this->notebook->performLayout();
|
||||
}
|
||||
|
||||
// if (this->parent() != nullptr) {
|
||||
// (static_cast<Notebook2 *>(this->parent()))->performLayout(true);
|
||||
@@ -182,7 +188,9 @@ void NotebookTab2::paintEvent(QPaintEvent *)
|
||||
QPainter painter(this);
|
||||
float scale = this->getScale();
|
||||
|
||||
int height = (int)(scale * 24);
|
||||
painter.setFont(getApp()->fonts->getFont(FontStyle::UiTabs, scale));
|
||||
|
||||
int height = (int)(scale * NOTEBOOK_TAB_HEIGHT);
|
||||
// int fullHeight = (int)(scale * 48);
|
||||
|
||||
// select the right tab colors
|
||||
@@ -206,48 +214,28 @@ void NotebookTab2::paintEvent(QPaintEvent *)
|
||||
: (windowFocused ? colors.backgrounds.regular
|
||||
: colors.backgrounds.unfocused);
|
||||
|
||||
if (true) {
|
||||
painter.fillRect(rect(), this->mouseOver ? regular.backgrounds.hover
|
||||
: (windowFocused ? regular.backgrounds.regular
|
||||
: regular.backgrounds.unfocused));
|
||||
painter.fillRect(rect(), this->mouseOver ? regular.backgrounds.hover
|
||||
: (windowFocused ? regular.backgrounds.regular
|
||||
: regular.backgrounds.unfocused));
|
||||
|
||||
// fill the tab background
|
||||
painter.fillRect(rect(), tabBackground);
|
||||
// fill the tab background
|
||||
painter.fillRect(rect(), tabBackground);
|
||||
|
||||
// draw border
|
||||
// painter.setPen(QPen("#ccc"));
|
||||
// QPainterPath path(QPointF(0, height));
|
||||
// path.lineTo(0, 0);
|
||||
// path.lineTo(this->width() - 1, 0);
|
||||
// path.lineTo(this->width() - 1, this->height() - 1);
|
||||
// path.lineTo(0, this->height() - 1);
|
||||
// painter.drawPath(path);
|
||||
} else {
|
||||
// QPainterPath path(QPointF(0, height));
|
||||
// path.lineTo(8 * scale, 0);
|
||||
// path.lineTo(this->width() - 8 * scale, 0);
|
||||
// path.lineTo(this->width(), height);
|
||||
// painter.fillPath(path, this->mouseOver ? regular.backgrounds.hover
|
||||
// : (windowFocused ?
|
||||
// regular.backgrounds.regular
|
||||
// :
|
||||
// regular.backgrounds.unfocused));
|
||||
// draw border
|
||||
// painter.setPen(QPen("#fff"));
|
||||
// QPainterPath path(QPointF(0, height));
|
||||
// path.lineTo(0, 0);
|
||||
// path.lineTo(this->width() - 1, 0);
|
||||
// path.lineTo(this->width() - 1, this->height() - 1);
|
||||
// path.lineTo(0, this->height() - 1);
|
||||
// painter.drawPath(path);
|
||||
|
||||
// // fill the tab background
|
||||
// painter.fillPath(path, tabBackground);
|
||||
// painter.setPen(QColor("#FFF"));
|
||||
// painter.setRenderHint(QPainter::Antialiasing);
|
||||
// painter.drawPath(path);
|
||||
// // painter.setBrush(QColor("#000"));
|
||||
|
||||
// QLinearGradient gradient(0, height, 0, fullHeight);
|
||||
// gradient.setColorAt(0, tabBackground.color());
|
||||
// gradient.setColorAt(1, "#fff");
|
||||
|
||||
// QBrush brush(gradient);
|
||||
// painter.fillRect(0, height, this->width(), fullHeight - height,
|
||||
// brush);
|
||||
}
|
||||
// top line
|
||||
painter.fillRect(QRectF(0, (this->selected ? 0.f : 1.f) * scale, this->width(),
|
||||
(this->selected ? 2.f : 1.f) * scale),
|
||||
this->mouseOver
|
||||
? colors.line.hover
|
||||
: (windowFocused ? colors.line.regular : colors.line.unfocused));
|
||||
|
||||
// set the pen color
|
||||
painter.setPen(colors.text);
|
||||
@@ -260,7 +248,11 @@ void NotebookTab2::paintEvent(QPaintEvent *)
|
||||
if (true) { // legacy
|
||||
// painter.drawText(rect, this->getTitle(), QTextOption(Qt::AlignCenter));
|
||||
int offset = (int)(scale * 8);
|
||||
QRect textRect(offset, 0, this->width() - offset - offset, height);
|
||||
QRect textRect(offset, this->selected ? 0 : 1, this->width() - offset - offset, height);
|
||||
|
||||
if (this->shouldDrawXButton()) {
|
||||
textRect.setRight(textRect.right() - this->height() / 2);
|
||||
}
|
||||
|
||||
QTextOption option(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
option.setWrapMode(QTextOption::NoWrap);
|
||||
@@ -274,9 +266,11 @@ void NotebookTab2::paintEvent(QPaintEvent *)
|
||||
}
|
||||
|
||||
// draw close x
|
||||
if (!app->settings->showTabCloseButton && (mouseOver || selected)) {
|
||||
if (this->shouldDrawXButton()) {
|
||||
QRect xRect = this->getXRect();
|
||||
if (!xRect.isNull()) {
|
||||
painter.setBrush(QColor("#fff"));
|
||||
|
||||
if (mouseOverX) {
|
||||
painter.fillRect(xRect, QColor(0, 0, 0, 64));
|
||||
|
||||
@@ -291,6 +285,21 @@ void NotebookTab2::paintEvent(QPaintEvent *)
|
||||
painter.drawLine(xRect.topRight() + QPoint(-a, a), xRect.bottomLeft() + QPoint(a, -a));
|
||||
}
|
||||
}
|
||||
|
||||
// draw line at bottom
|
||||
if (!this->selected) {
|
||||
painter.fillRect(0, this->height() - 1, this->width(), 1, app->themes->window.background);
|
||||
}
|
||||
}
|
||||
|
||||
bool NotebookTab2::hasXButton()
|
||||
{
|
||||
return getApp()->settings->showTabCloseButton && this->notebook->getAllowUserTabManagement();
|
||||
}
|
||||
|
||||
bool NotebookTab2::shouldDrawXButton()
|
||||
{
|
||||
return this->hasXButton() && (mouseOver || selected);
|
||||
}
|
||||
|
||||
void NotebookTab2::mousePressEvent(QMouseEvent *event)
|
||||
@@ -320,8 +329,7 @@ void NotebookTab2::mouseReleaseEvent(QMouseEvent *event)
|
||||
this->notebook->removePage(this->page);
|
||||
}
|
||||
} else {
|
||||
if (getApp()->settings->showTabCloseButton && this->mouseDownX &&
|
||||
this->getXRect().contains(event->pos())) {
|
||||
if (this->hasXButton() && this->mouseDownX && this->getXRect().contains(event->pos())) {
|
||||
this->mouseDownX = false;
|
||||
|
||||
this->notebook->removePage(this->page);
|
||||
@@ -377,7 +385,7 @@ void NotebookTab2::mouseMoveEvent(QMouseEvent *event)
|
||||
int index;
|
||||
QWidget *clickedPage = notebook->tabAt(relPoint, index, this->width());
|
||||
|
||||
assert(clickedPage);
|
||||
// assert(clickedPage);
|
||||
|
||||
if (clickedPage != nullptr && clickedPage != this->page) {
|
||||
this->notebook->rearrangePage(this->page, index);
|
||||
@@ -387,370 +395,14 @@ void NotebookTab2::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
QRect NotebookTab2::getXRect()
|
||||
{
|
||||
if (this->notebook->getAllowUserTabManagement()) {
|
||||
return QRect();
|
||||
}
|
||||
// if (!this->notebook->getAllowUserTabManagement()) {
|
||||
// return QRect();
|
||||
// }
|
||||
|
||||
float s = this->getScale();
|
||||
return QRect(this->width() - static_cast<int>(20 * s), static_cast<int>(4 * s),
|
||||
return QRect(this->width() - static_cast<int>(20 * s), static_cast<int>(6 * s),
|
||||
static_cast<int>(16 * s), static_cast<int>(16 * s));
|
||||
}
|
||||
|
||||
// 2
|
||||
NotebookTab::NotebookTab(Notebook *_notebook)
|
||||
: BaseWidget(_notebook)
|
||||
, positionChangedAnimation(this, "pos")
|
||||
, notebook(_notebook)
|
||||
, menu(this)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
this->setAcceptDrops(true);
|
||||
|
||||
this->positionChangedAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
|
||||
|
||||
app->settings->showTabCloseButton.connect(boost::bind(&NotebookTab::hideTabXChanged, this, _1),
|
||||
this->managedConnections);
|
||||
|
||||
this->setMouseTracking(true);
|
||||
|
||||
this->menu.addAction("Rename", [this]() {
|
||||
TextInputDialog d(this);
|
||||
|
||||
d.setWindowTitle("Change tab title (Leave empty for default behaviour)");
|
||||
if (this->useDefaultTitle) {
|
||||
d.setText("");
|
||||
} else {
|
||||
d.setText(this->getTitle());
|
||||
d.highlightText();
|
||||
}
|
||||
|
||||
if (d.exec() == QDialog::Accepted) {
|
||||
QString newTitle = d.getText();
|
||||
if (newTitle.isEmpty()) {
|
||||
this->useDefaultTitle = true;
|
||||
this->page->refreshTabTitle();
|
||||
} else {
|
||||
this->useDefaultTitle = false;
|
||||
this->setTitle(newTitle);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
QAction *enableHighlightsOnNewMessageAction =
|
||||
new QAction("Enable highlights on new message", &this->menu);
|
||||
enableHighlightsOnNewMessageAction->setCheckable(true);
|
||||
|
||||
this->menu.addAction("Close", [=]() { this->notebook->removePage(this->page); });
|
||||
|
||||
this->menu.addAction(enableHighlightsOnNewMessageAction);
|
||||
|
||||
QObject::connect(enableHighlightsOnNewMessageAction, &QAction::toggled, [](bool newValue) {
|
||||
debug::Log("New value is {}", newValue); //
|
||||
});
|
||||
}
|
||||
|
||||
void NotebookTab::themeRefreshEvent()
|
||||
{
|
||||
this->update();
|
||||
}
|
||||
|
||||
void NotebookTab::updateSize()
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
float scale = getScale();
|
||||
|
||||
int width;
|
||||
|
||||
if (!app->settings->showTabCloseButton) {
|
||||
width = (int)((fontMetrics().width(this->title) + 16 /*+ 16*/) * scale);
|
||||
} else {
|
||||
width = (int)((fontMetrics().width(this->title) + 8 + 24 /*+ 16*/) * scale);
|
||||
}
|
||||
|
||||
this->resize(std::min((int)(150 * scale), width), (int)(24 * scale));
|
||||
|
||||
if (this->parent() != nullptr) {
|
||||
(static_cast<Notebook *>(this->parent()))->performLayout(true);
|
||||
}
|
||||
}
|
||||
|
||||
const QString &NotebookTab::getTitle() const
|
||||
{
|
||||
return this->title;
|
||||
}
|
||||
|
||||
void NotebookTab::setTitle(const QString &newTitle)
|
||||
{
|
||||
if (this->title != newTitle) {
|
||||
this->title = newTitle;
|
||||
this->updateSize();
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
bool NotebookTab::isSelected() const
|
||||
{
|
||||
return this->selected;
|
||||
}
|
||||
|
||||
void NotebookTab::setSelected(bool value)
|
||||
{
|
||||
this->selected = value;
|
||||
|
||||
this->highlightState = HighlightState::None;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
|
||||
{
|
||||
if (this->isSelected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->highlightState != HighlightState::Highlighted) {
|
||||
this->highlightState = newHighlightStyle;
|
||||
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
QRect NotebookTab::getDesiredRect() const
|
||||
{
|
||||
return QRect(positionAnimationDesiredPoint, size());
|
||||
}
|
||||
|
||||
void NotebookTab::hideTabXChanged(bool)
|
||||
{
|
||||
this->updateSize();
|
||||
this->update();
|
||||
}
|
||||
|
||||
void NotebookTab::moveAnimated(QPoint pos, bool animated)
|
||||
{
|
||||
this->positionAnimationDesiredPoint = pos;
|
||||
|
||||
QWidget *w = this->window();
|
||||
|
||||
if ((w != nullptr && !w->isVisible()) || !animated || !positionChangedAnimationRunning) {
|
||||
this->move(pos);
|
||||
|
||||
this->positionChangedAnimationRunning = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->positionChangedAnimation.endValue() == pos) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->positionChangedAnimation.stop();
|
||||
this->positionChangedAnimation.setDuration(75);
|
||||
this->positionChangedAnimation.setStartValue(this->pos());
|
||||
this->positionChangedAnimation.setEndValue(pos);
|
||||
this->positionChangedAnimation.start();
|
||||
}
|
||||
|
||||
void NotebookTab::paintEvent(QPaintEvent *)
|
||||
{
|
||||
auto app = getApp();
|
||||
QPainter painter(this);
|
||||
float scale = this->getScale();
|
||||
|
||||
int height = (int)(scale * 24);
|
||||
// int fullHeight = (int)(scale * 48);
|
||||
|
||||
// select the right tab colors
|
||||
singletons::ThemeManager::TabColors colors;
|
||||
singletons::ThemeManager::TabColors regular = this->themeManager->tabs.regular;
|
||||
|
||||
if (this->selected) {
|
||||
colors = this->themeManager->tabs.selected;
|
||||
} else if (this->highlightState == HighlightState::Highlighted) {
|
||||
colors = this->themeManager->tabs.highlighted;
|
||||
} else if (this->highlightState == HighlightState::NewMessage) {
|
||||
colors = this->themeManager->tabs.newMessage;
|
||||
} else {
|
||||
colors = this->themeManager->tabs.regular;
|
||||
}
|
||||
|
||||
bool windowFocused = this->window() == QApplication::activeWindow();
|
||||
// || SettingsDialog::getHandle() == QApplication::activeWindow();
|
||||
|
||||
QBrush tabBackground = this->mouseOver ? colors.backgrounds.hover
|
||||
: (windowFocused ? colors.backgrounds.regular
|
||||
: colors.backgrounds.unfocused);
|
||||
|
||||
if (true) {
|
||||
painter.fillRect(rect(), this->mouseOver ? regular.backgrounds.hover
|
||||
: (windowFocused ? regular.backgrounds.regular
|
||||
: regular.backgrounds.unfocused));
|
||||
|
||||
// fill the tab background
|
||||
painter.fillRect(rect(), tabBackground);
|
||||
|
||||
// draw border
|
||||
// painter.setPen(QPen("#ccc"));
|
||||
// QPainterPath path(QPointF(0, height));
|
||||
// path.lineTo(0, 0);
|
||||
// path.lineTo(this->width() - 1, 0);
|
||||
// path.lineTo(this->width() - 1, this->height() - 1);
|
||||
// path.lineTo(0, this->height() - 1);
|
||||
// painter.drawPath(path);
|
||||
} else {
|
||||
// QPainterPath path(QPointF(0, height));
|
||||
// path.lineTo(8 * scale, 0);
|
||||
// path.lineTo(this->width() - 8 * scale, 0);
|
||||
// path.lineTo(this->width(), height);
|
||||
// painter.fillPath(path, this->mouseOver ? regular.backgrounds.hover
|
||||
// : (windowFocused ?
|
||||
// regular.backgrounds.regular
|
||||
// :
|
||||
// regular.backgrounds.unfocused));
|
||||
|
||||
// // fill the tab background
|
||||
// painter.fillPath(path, tabBackground);
|
||||
// painter.setPen(QColor("#FFF"));
|
||||
// painter.setRenderHint(QPainter::Antialiasing);
|
||||
// painter.drawPath(path);
|
||||
// // painter.setBrush(QColor("#000"));
|
||||
|
||||
// QLinearGradient gradient(0, height, 0, fullHeight);
|
||||
// gradient.setColorAt(0, tabBackground.color());
|
||||
// gradient.setColorAt(1, "#fff");
|
||||
|
||||
// QBrush brush(gradient);
|
||||
// painter.fillRect(0, height, this->width(), fullHeight - height,
|
||||
// brush);
|
||||
}
|
||||
|
||||
// set the pen color
|
||||
painter.setPen(colors.text);
|
||||
|
||||
// set area for text
|
||||
int rectW = (!app->settings->showTabCloseButton ? 0 : static_cast<int>(16) * scale);
|
||||
QRect rect(0, 0, this->width() - rectW, height);
|
||||
|
||||
// draw text
|
||||
if (true) { // legacy
|
||||
// painter.drawText(rect, this->getTitle(), QTextOption(Qt::AlignCenter));
|
||||
int offset = (int)(scale * 8);
|
||||
QRect textRect(offset, 0, this->width() - offset - offset, height);
|
||||
|
||||
QTextOption option(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
option.setWrapMode(QTextOption::NoWrap);
|
||||
painter.drawText(textRect, this->getTitle(), option);
|
||||
} else {
|
||||
// QTextOption option(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
// option.setWrapMode(QTextOption::NoWrap);
|
||||
// int offset = (int)(scale * 16);
|
||||
// QRect textRect(offset, 0, this->width() - offset - offset, height);
|
||||
// painter.drawText(textRect, this->getTitle(), option);
|
||||
}
|
||||
|
||||
// draw close x
|
||||
if (app->settings->showTabCloseButton && (mouseOver || selected)) {
|
||||
QRect xRect = this->getXRect();
|
||||
if (mouseOverX) {
|
||||
painter.fillRect(xRect, QColor(0, 0, 0, 64));
|
||||
|
||||
if (mouseDownX) {
|
||||
painter.fillRect(xRect, QColor(0, 0, 0, 64));
|
||||
}
|
||||
}
|
||||
|
||||
int a = static_cast<int>(scale * 4);
|
||||
|
||||
painter.drawLine(xRect.topLeft() + QPoint(a, a), xRect.bottomRight() + QPoint(-a, -a));
|
||||
painter.drawLine(xRect.topRight() + QPoint(-a, a), xRect.bottomLeft() + QPoint(a, -a));
|
||||
}
|
||||
} // namespace widgets
|
||||
|
||||
void NotebookTab::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
this->mouseDown = true;
|
||||
this->mouseDownX = this->getXRect().contains(event->pos());
|
||||
|
||||
this->update();
|
||||
|
||||
this->notebook->select(page);
|
||||
|
||||
switch (event->button()) {
|
||||
case Qt::RightButton: {
|
||||
this->menu.popup(event->globalPos());
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
this->mouseDown = false;
|
||||
|
||||
if (event->button() == Qt::MiddleButton) {
|
||||
if (this->rect().contains(event->pos())) {
|
||||
this->notebook->removePage(this->page);
|
||||
}
|
||||
} else {
|
||||
if (app->settings->showTabCloseButton && this->mouseDownX &&
|
||||
this->getXRect().contains(event->pos())) {
|
||||
this->mouseDownX = false;
|
||||
|
||||
this->notebook->removePage(this->page);
|
||||
} else {
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NotebookTab::enterEvent(QEvent *)
|
||||
{
|
||||
this->mouseOver = true;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
void NotebookTab::leaveEvent(QEvent *)
|
||||
{
|
||||
this->mouseOverX = false;
|
||||
this->mouseOver = false;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
void NotebookTab::dragEnterEvent(QDragEnterEvent *)
|
||||
{
|
||||
this->notebook->select(this->page);
|
||||
}
|
||||
|
||||
void NotebookTab::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
if (app->settings->showTabCloseButton) {
|
||||
bool overX = this->getXRect().contains(event->pos());
|
||||
|
||||
if (overX != this->mouseOverX) {
|
||||
// Over X state has been changed (we either left or entered it;
|
||||
this->mouseOverX = overX;
|
||||
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
QPoint relPoint = this->mapToParent(event->pos());
|
||||
|
||||
if (this->mouseDown && !this->getDesiredRect().contains(relPoint)) {
|
||||
int index;
|
||||
SplitContainer *clickedPage = notebook->tabAt(relPoint, index, this->width());
|
||||
|
||||
if (clickedPage != nullptr && clickedPage != this->page) {
|
||||
this->notebook->rearrangePage(this->page, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
class Notebook;
|
||||
#define NOTEBOOK_TAB_HEIGHT 28
|
||||
|
||||
// class Notebook;
|
||||
class Notebook2;
|
||||
class SplitContainer;
|
||||
|
||||
@@ -73,6 +75,9 @@ private:
|
||||
bool mouseOverX = false;
|
||||
bool mouseDownX = false;
|
||||
|
||||
bool hasXButton();
|
||||
bool shouldDrawXButton();
|
||||
|
||||
HighlightState highlightState = HighlightState::None;
|
||||
|
||||
QMenu menu;
|
||||
@@ -80,75 +85,5 @@ private:
|
||||
QRect getXRect();
|
||||
};
|
||||
|
||||
class NotebookTab : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NotebookTab(Notebook *_notebook);
|
||||
|
||||
void updateSize();
|
||||
|
||||
SplitContainer *page;
|
||||
|
||||
const QString &getTitle() const;
|
||||
void setTitle(const QString &newTitle);
|
||||
bool isSelected() const;
|
||||
void setSelected(bool value);
|
||||
|
||||
void setHighlightState(HighlightState style);
|
||||
|
||||
void moveAnimated(QPoint pos, bool animated = true);
|
||||
|
||||
QRect getDesiredRect() const;
|
||||
void hideTabXChanged(bool);
|
||||
|
||||
protected:
|
||||
virtual void themeRefreshEvent() override;
|
||||
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
|
||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
virtual void enterEvent(QEvent *) override;
|
||||
virtual void leaveEvent(QEvent *) override;
|
||||
|
||||
virtual void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
|
||||
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
|
||||
|
||||
QPropertyAnimation positionChangedAnimation;
|
||||
bool positionChangedAnimationRunning = false;
|
||||
QPoint positionAnimationDesiredPoint;
|
||||
|
||||
Notebook *notebook;
|
||||
|
||||
QString title;
|
||||
|
||||
public:
|
||||
bool useDefaultTitle = true;
|
||||
|
||||
private:
|
||||
bool selected = false;
|
||||
bool mouseOver = false;
|
||||
bool mouseDown = false;
|
||||
bool mouseOverX = false;
|
||||
bool mouseDownX = false;
|
||||
|
||||
HighlightState highlightState = HighlightState::None;
|
||||
|
||||
QMenu menu;
|
||||
|
||||
QRect getXRect()
|
||||
{
|
||||
float s = this->getScale();
|
||||
return QRect(this->width() - static_cast<int>(20 * s), static_cast<int>(4 * s),
|
||||
static_cast<int>(16 * s), static_cast<int>(16 * s));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -65,11 +65,11 @@ void SplitInput::initLayout()
|
||||
|
||||
// set edit font
|
||||
this->ui.textEdit->setFont(
|
||||
app->fonts->getFont(singletons::FontManager::Type::Medium, this->getScale()));
|
||||
app->fonts->getFont(singletons::FontManager::Type::ChatMedium, this->getScale()));
|
||||
|
||||
this->managedConnections.emplace_back(app->fonts->fontChanged.connect([=]() {
|
||||
this->ui.textEdit->setFont(
|
||||
app->fonts->getFont(singletons::FontManager::Type::Medium, this->getScale()));
|
||||
app->fonts->getFont(singletons::FontManager::Type::ChatMedium, this->getScale()));
|
||||
}));
|
||||
|
||||
// open emote popup
|
||||
@@ -244,18 +244,18 @@ void SplitInput::installKeyPressedEvent()
|
||||
SplitContainer *page =
|
||||
static_cast<SplitContainer *>(this->chatWidget->parentWidget());
|
||||
|
||||
Notebook *notebook = static_cast<Notebook *>(page->parentWidget());
|
||||
Notebook2 *notebook = static_cast<Notebook2 *>(page->parentWidget());
|
||||
|
||||
notebook->nextTab();
|
||||
notebook->selectNextTab();
|
||||
}
|
||||
} else if (event->key() == Qt::Key_Backtab) {
|
||||
if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
|
||||
SplitContainer *page =
|
||||
static_cast<SplitContainer *>(this->chatWidget->parentWidget());
|
||||
|
||||
Notebook *notebook = static_cast<Notebook *>(page->parentWidget());
|
||||
Notebook2 *notebook = static_cast<Notebook2 *>(page->parentWidget());
|
||||
|
||||
notebook->previousTab();
|
||||
notebook->selectPreviousTab();
|
||||
}
|
||||
} else if (event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier) {
|
||||
if (this->chatWidget->view.hasSelection()) {
|
||||
@@ -316,14 +316,23 @@ void SplitInput::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(this->rect(), this->themeManager->splits.input.background);
|
||||
|
||||
QPen pen(this->themeManager->splits.input.border);
|
||||
if (this->themeManager->isLightTheme()) {
|
||||
pen.setWidth((int)(6 * this->getScale()));
|
||||
int s = (int)(3 * this->getScale());
|
||||
QRect rect = this->rect().marginsRemoved(QMargins(s, s, s, s));
|
||||
|
||||
painter.fillRect(rect, this->themeManager->splits.input.background);
|
||||
|
||||
painter.setPen(QColor("#ccc"));
|
||||
painter.drawRect(rect);
|
||||
} else {
|
||||
int s = (int)(1 * this->getScale());
|
||||
QRect rect = this->rect().marginsRemoved(QMargins(s, s, s, s));
|
||||
|
||||
painter.fillRect(rect, this->themeManager->splits.input.background);
|
||||
|
||||
painter.setPen(QColor("#333"));
|
||||
painter.drawRect(rect);
|
||||
}
|
||||
painter.setPen(pen);
|
||||
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
|
||||
}
|
||||
|
||||
void SplitInput::resizeEvent(QResizeEvent *)
|
||||
|
||||
+32
-308
@@ -89,6 +89,8 @@ void Notebook2::removePage(QWidget *page)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->performLayout();
|
||||
}
|
||||
|
||||
void Notebook2::removeCurrentPage()
|
||||
@@ -179,6 +181,11 @@ int Notebook2::getPageCount() const
|
||||
return this->items.count();
|
||||
}
|
||||
|
||||
QWidget *Notebook2::getPageAt(int index) const
|
||||
{
|
||||
return this->items[index].page;
|
||||
}
|
||||
|
||||
int Notebook2::getSelectedIndex() const
|
||||
{
|
||||
return this->indexOf(this->selectedPage);
|
||||
@@ -242,11 +249,11 @@ void Notebook2::setShowAddButton(bool value)
|
||||
|
||||
void Notebook2::scaleChangedEvent(float scale)
|
||||
{
|
||||
// float h = 24 * this->getScale();
|
||||
float h = NOTEBOOK_TAB_HEIGHT * this->getScale();
|
||||
|
||||
// this->settingsButton.setFixedSize(h, h);
|
||||
// this->userButton.setFixedSize(h, h);
|
||||
// this->addButton.setFixedSize(h, h);
|
||||
this->addButton.setFixedSize(h, h);
|
||||
|
||||
for (auto &i : this->items) {
|
||||
i.tab->updateSize();
|
||||
@@ -290,10 +297,12 @@ void Notebook2::performLayout(bool animated)
|
||||
// x += (int)(scale * 2);
|
||||
// }
|
||||
|
||||
int tabHeight = static_cast<int>(24 * scale);
|
||||
int tabHeight = static_cast<int>(NOTEBOOK_TAB_HEIGHT * scale);
|
||||
bool first = true;
|
||||
|
||||
for (auto i = this->items.begin(); i != this->items.end(); i++) {
|
||||
// int yOffset = i->tab->isSelected() ? 0 : 1;
|
||||
|
||||
if (!first &&
|
||||
(i == this->items.end() && this->showAddButton ? tabHeight : 0) + x + i->tab->width() >
|
||||
width()) //
|
||||
@@ -321,7 +330,7 @@ void Notebook2::performLayout(bool animated)
|
||||
this->update();
|
||||
}
|
||||
|
||||
y += (int)(1 * scale);
|
||||
y += (int)(3 * scale);
|
||||
|
||||
for (auto &i : this->items) {
|
||||
i.tab->raise();
|
||||
@@ -343,10 +352,15 @@ void Notebook2::paintEvent(QPaintEvent *event)
|
||||
BaseWidget::paintEvent(event);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.fillRect(0, this->lineY, this->width(), (int)(1 * this->getScale()),
|
||||
painter.fillRect(0, this->lineY, this->width(), (int)(3 * this->getScale()),
|
||||
this->themeManager->tabs.bottomLine);
|
||||
}
|
||||
|
||||
NotebookButton *Notebook2::getAddButton()
|
||||
{
|
||||
return &this->addButton;
|
||||
}
|
||||
|
||||
NotebookTab2 *Notebook2::getTabFromPage(QWidget *page)
|
||||
{
|
||||
for (auto &it : this->items) {
|
||||
@@ -358,318 +372,28 @@ NotebookTab2 *Notebook2::getTabFromPage(QWidget *page)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Notebook2::OLD NOTEBOOK
|
||||
Notebook::Notebook(Window *parent, bool _showButtons)
|
||||
: BaseWidget(parent)
|
||||
, parentWindow(parent)
|
||||
, addButton(this)
|
||||
, settingsButton(this)
|
||||
, userButton(this)
|
||||
, showButtons(_showButtons)
|
||||
, closeConfirmDialog(this)
|
||||
SplitNotebook::SplitNotebook(QWidget *parent)
|
||||
: Notebook2(parent)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
this->connect(&this->settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked()));
|
||||
this->connect(&this->userButton, SIGNAL(clicked()), this, SLOT(usersButtonClicked()));
|
||||
this->connect(&this->addButton, SIGNAL(clicked()), this, SLOT(addPageButtonClicked()));
|
||||
|
||||
this->settingsButton.icon = NotebookButton::IconSettings;
|
||||
|
||||
this->userButton.move(24, 0);
|
||||
this->userButton.icon = NotebookButton::IconUser;
|
||||
|
||||
app->settings->hidePreferencesButton.connectSimple([this](auto) { this->performLayout(); });
|
||||
app->settings->hideUserButton.connectSimple([this](auto) { this->performLayout(); });
|
||||
|
||||
closeConfirmDialog.setText("Are you sure you want to close this tab?");
|
||||
closeConfirmDialog.setIcon(QMessageBox::Icon::Question);
|
||||
closeConfirmDialog.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
|
||||
closeConfirmDialog.setDefaultButton(QMessageBox::Yes);
|
||||
|
||||
this->scaleChangedEvent(this->getScale());
|
||||
|
||||
// Window-wide hotkeys
|
||||
// CTRL+T: Create new split in selected notebook page
|
||||
// CreateWindowShortcut(this, "CTRL+T", [this]() {
|
||||
// if (this->selectedPage == nullptr) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// this->selectedPage->addChat(true);
|
||||
// });
|
||||
this->connect(this->getAddButton(), &NotebookButton::clicked,
|
||||
[this]() { QTimer::singleShot(80, this, [this] { this->addPage(true); }); });
|
||||
}
|
||||
|
||||
SplitContainer *Notebook::addNewPage(bool select)
|
||||
SplitContainer *SplitNotebook::addPage(bool select)
|
||||
{
|
||||
auto tab = new NotebookTab(this);
|
||||
auto page = new SplitContainer(this, tab);
|
||||
|
||||
SplitContainer *container = new SplitContainer(this);
|
||||
auto *tab = Notebook2::addPage(container, QString(), select);
|
||||
container->setTab(tab);
|
||||
tab->setParent(this);
|
||||
tab->show();
|
||||
|
||||
if (select || this->pages.count() == 0) {
|
||||
this->select(page);
|
||||
}
|
||||
|
||||
this->pages.append(page);
|
||||
|
||||
this->performLayout();
|
||||
|
||||
return page;
|
||||
return container;
|
||||
}
|
||||
|
||||
void Notebook::removePage(SplitContainer *page)
|
||||
SplitContainer *SplitNotebook::getOrAddSelectedPage()
|
||||
{
|
||||
if (page->getSplitCount() > 0 && closeConfirmDialog.exec() != QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
auto *selectedPage = this->getSelectedPage();
|
||||
|
||||
int index = this->pages.indexOf(page);
|
||||
|
||||
if (this->pages.size() == 1) {
|
||||
select(nullptr);
|
||||
} else if (index == this->pages.count() - 1) {
|
||||
select(this->pages[index - 1]);
|
||||
} else {
|
||||
select(this->pages[index + 1]);
|
||||
}
|
||||
|
||||
page->getTab()->deleteLater();
|
||||
page->deleteLater();
|
||||
|
||||
this->pages.removeOne(page);
|
||||
|
||||
if (this->pages.empty()) {
|
||||
this->addNewPage();
|
||||
}
|
||||
|
||||
this->performLayout();
|
||||
}
|
||||
|
||||
void Notebook::removeCurrentPage()
|
||||
{
|
||||
if (this->selectedPage == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->removePage(this->selectedPage);
|
||||
}
|
||||
|
||||
SplitContainer *Notebook::getOrAddSelectedPage()
|
||||
{
|
||||
if (selectedPage == nullptr) {
|
||||
this->addNewPage(true);
|
||||
}
|
||||
|
||||
return selectedPage;
|
||||
}
|
||||
|
||||
SplitContainer *Notebook::getSelectedPage()
|
||||
{
|
||||
return selectedPage;
|
||||
}
|
||||
|
||||
void Notebook::select(SplitContainer *page)
|
||||
{
|
||||
if (page == this->selectedPage) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (page != nullptr) {
|
||||
page->setHidden(false);
|
||||
page->getTab()->setSelected(true);
|
||||
page->getTab()->raise();
|
||||
}
|
||||
|
||||
if (this->selectedPage != nullptr) {
|
||||
this->selectedPage->setHidden(true);
|
||||
this->selectedPage->getTab()->setSelected(false);
|
||||
|
||||
for (Split *split : this->selectedPage->getSplits()) {
|
||||
split->updateLastReadMessage();
|
||||
}
|
||||
}
|
||||
|
||||
this->selectedPage = page;
|
||||
|
||||
this->performLayout();
|
||||
}
|
||||
|
||||
void Notebook::selectIndex(int index)
|
||||
{
|
||||
if (index < 0 || index >= this->pages.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->select(this->pages.at(index));
|
||||
}
|
||||
|
||||
int Notebook::tabCount()
|
||||
{
|
||||
return this->pages.size();
|
||||
}
|
||||
|
||||
SplitContainer *Notebook::tabAt(QPoint point, int &index, int maxWidth)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (auto *page : this->pages) {
|
||||
QRect rect = page->getTab()->getDesiredRect();
|
||||
rect.setHeight((int)(this->getScale() * 24));
|
||||
|
||||
rect.setWidth(std::min(maxWidth, rect.width()));
|
||||
|
||||
if (rect.contains(point)) {
|
||||
index = i;
|
||||
return page;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
index = -1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SplitContainer *Notebook::tabAt(int index)
|
||||
{
|
||||
return this->pages[index];
|
||||
}
|
||||
|
||||
void Notebook::rearrangePage(SplitContainer *page, int index)
|
||||
{
|
||||
this->pages.move(this->pages.indexOf(page), index);
|
||||
|
||||
this->performLayout();
|
||||
}
|
||||
|
||||
void Notebook::nextTab()
|
||||
{
|
||||
if (this->pages.size() <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
int index = (this->pages.indexOf(this->selectedPage) + 1) % this->pages.size();
|
||||
|
||||
this->select(this->pages[index]);
|
||||
}
|
||||
|
||||
void Notebook::previousTab()
|
||||
{
|
||||
if (this->pages.size() <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
int index = (this->pages.indexOf(this->selectedPage) - 1);
|
||||
|
||||
if (index < 0) {
|
||||
index += this->pages.size();
|
||||
}
|
||||
|
||||
this->select(this->pages[index]);
|
||||
}
|
||||
|
||||
void Notebook::performLayout(bool animated)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
int x = 0, y = 0;
|
||||
float scale = this->getScale();
|
||||
bool customFrame = this->parentWindow->hasCustomWindowFrame();
|
||||
|
||||
if (!this->showButtons || app->settings->hidePreferencesButton || customFrame) {
|
||||
this->settingsButton.hide();
|
||||
} else {
|
||||
this->settingsButton.show();
|
||||
x += settingsButton.width();
|
||||
}
|
||||
if (!this->showButtons || app->settings->hideUserButton || customFrame) {
|
||||
this->userButton.hide();
|
||||
} else {
|
||||
this->userButton.move(x, 0);
|
||||
this->userButton.show();
|
||||
x += userButton.width();
|
||||
}
|
||||
|
||||
if (customFrame || !this->showButtons ||
|
||||
(app->settings->hideUserButton && app->settings->hidePreferencesButton)) {
|
||||
x += (int)(scale * 2);
|
||||
}
|
||||
|
||||
int tabHeight = static_cast<int>(24 * scale);
|
||||
bool first = true;
|
||||
|
||||
for (auto &i : this->pages) {
|
||||
if (!first &&
|
||||
(i == this->pages.last() ? tabHeight : 0) + x + i->getTab()->width() > width()) {
|
||||
y += i->getTab()->height();
|
||||
// y += 20;
|
||||
i->getTab()->moveAnimated(QPoint(0, y), animated);
|
||||
x = i->getTab()->width();
|
||||
} else {
|
||||
i->getTab()->moveAnimated(QPoint(x, y), animated);
|
||||
x += i->getTab()->width();
|
||||
}
|
||||
|
||||
// x -= (int)(8 * scale);
|
||||
x += 1;
|
||||
|
||||
first = false;
|
||||
}
|
||||
|
||||
// x += (int)(8 * scale);
|
||||
// x += 1;
|
||||
|
||||
this->addButton.move(x, y);
|
||||
|
||||
y -= 1;
|
||||
|
||||
for (auto &i : this->pages) {
|
||||
i->getTab()->raise();
|
||||
}
|
||||
|
||||
this->addButton.raise();
|
||||
|
||||
if (this->selectedPage != nullptr) {
|
||||
this->selectedPage->move(0, y + tabHeight);
|
||||
this->selectedPage->resize(width(), height() - y - tabHeight);
|
||||
this->selectedPage->raise();
|
||||
}
|
||||
}
|
||||
|
||||
void Notebook::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
this->performLayout(false);
|
||||
}
|
||||
|
||||
void Notebook::scaleChangedEvent(float)
|
||||
{
|
||||
float h = 24 * this->getScale();
|
||||
|
||||
this->settingsButton.setFixedSize(h, h);
|
||||
this->userButton.setFixedSize(h, h);
|
||||
this->addButton.setFixedSize(h, h);
|
||||
|
||||
for (auto &i : this->pages) {
|
||||
i->getTab()->updateSize();
|
||||
}
|
||||
}
|
||||
|
||||
void Notebook::settingsButtonClicked()
|
||||
{
|
||||
auto app = getApp();
|
||||
app->windows->showSettingsDialog();
|
||||
}
|
||||
|
||||
void Notebook::usersButtonClicked()
|
||||
{
|
||||
auto app = getApp();
|
||||
app->windows->showAccountSelectPopup(this->mapToGlobal(this->userButton.rect().bottomRight()));
|
||||
}
|
||||
|
||||
void Notebook::addPageButtonClicked()
|
||||
{
|
||||
QTimer::singleShot(80, [this] { this->addNewPage(true); });
|
||||
return selectedPage != nullptr ? (SplitContainer *)selectedPage : this->addPage();
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
@@ -32,6 +32,7 @@ public:
|
||||
void selectPreviousTab();
|
||||
|
||||
int getPageCount() const;
|
||||
QWidget *getPageAt(int index) const;
|
||||
int getSelectedIndex() const;
|
||||
QWidget *getSelectedPage() const;
|
||||
|
||||
@@ -44,11 +45,15 @@ public:
|
||||
bool getShowAddButton() const;
|
||||
void setShowAddButton(bool value);
|
||||
|
||||
void performLayout(bool animate = true);
|
||||
|
||||
protected:
|
||||
virtual void scaleChangedEvent(float scale) override;
|
||||
virtual void resizeEvent(QResizeEvent *) override;
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
|
||||
NotebookButton *getAddButton();
|
||||
|
||||
private:
|
||||
struct Item {
|
||||
NotebookTab2 *tab;
|
||||
@@ -64,63 +69,16 @@ private:
|
||||
bool showAddButton = false;
|
||||
int lineY = 20;
|
||||
|
||||
void performLayout(bool animate = true);
|
||||
|
||||
NotebookTab2 *getTabFromPage(QWidget *page);
|
||||
};
|
||||
|
||||
class Notebook : public BaseWidget
|
||||
class SplitNotebook : public Notebook2
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Notebook(Window *parent, bool _showButtons);
|
||||
|
||||
SplitContainer *addNewPage(bool select = false);
|
||||
|
||||
void removePage(SplitContainer *page);
|
||||
void removeCurrentPage();
|
||||
void select(SplitContainer *page);
|
||||
void selectIndex(int index);
|
||||
SplitNotebook(QWidget *parent);
|
||||
|
||||
SplitContainer *addPage(bool select = false);
|
||||
SplitContainer *getOrAddSelectedPage();
|
||||
SplitContainer *getSelectedPage();
|
||||
|
||||
void performLayout(bool animate = true);
|
||||
|
||||
int tabCount();
|
||||
SplitContainer *tabAt(QPoint point, int &index, int maxWidth = 2000000000);
|
||||
SplitContainer *tabAt(int index);
|
||||
void rearrangePage(SplitContainer *page, int index);
|
||||
|
||||
void nextTab();
|
||||
void previousTab();
|
||||
|
||||
protected:
|
||||
void scaleChangedEvent(float scale);
|
||||
void resizeEvent(QResizeEvent *);
|
||||
|
||||
void settingsButtonMouseReleased(QMouseEvent *event);
|
||||
|
||||
public slots:
|
||||
void settingsButtonClicked();
|
||||
void usersButtonClicked();
|
||||
void addPageButtonClicked();
|
||||
|
||||
private:
|
||||
Window *parentWindow;
|
||||
|
||||
QList<SplitContainer *> pages;
|
||||
|
||||
NotebookButton addButton;
|
||||
NotebookButton settingsButton;
|
||||
NotebookButton userButton;
|
||||
|
||||
SplitContainer *selectedPage = nullptr;
|
||||
|
||||
bool showButtons;
|
||||
|
||||
QMessageBox closeConfirmDialog;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
@@ -165,12 +165,12 @@ QLayout *AppearancePage::createFontChanger()
|
||||
layout->addWidget(label);
|
||||
|
||||
auto updateFontFamilyLabel = [=](auto) {
|
||||
label->setText(QString::fromStdString(app->fonts->currentFontFamily.getValue()) + ", " +
|
||||
QString::number(app->fonts->currentFontSize) + "pt");
|
||||
label->setText(QString::fromStdString(app->fonts->chatFontFamily.getValue()) + ", " +
|
||||
QString::number(app->fonts->chatFontSize) + "pt");
|
||||
};
|
||||
|
||||
app->fonts->currentFontFamily.connectSimple(updateFontFamilyLabel, this->managedConnections);
|
||||
app->fonts->currentFontSize.connectSimple(updateFontFamilyLabel, this->managedConnections);
|
||||
app->fonts->chatFontFamily.connectSimple(updateFontFamilyLabel, this->managedConnections);
|
||||
app->fonts->chatFontSize.connectSimple(updateFontFamilyLabel, this->managedConnections);
|
||||
|
||||
// BUTTON
|
||||
QPushButton *button = new QPushButton("Select");
|
||||
@@ -178,11 +178,11 @@ QLayout *AppearancePage::createFontChanger()
|
||||
button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Policy::Fixed);
|
||||
|
||||
QObject::connect(button, &QPushButton::clicked, [=]() {
|
||||
QFontDialog dialog(app->fonts->getFont(singletons::FontManager::Medium, 1.));
|
||||
QFontDialog dialog(app->fonts->getFont(singletons::FontManager::ChatMedium, 1.));
|
||||
|
||||
dialog.connect(&dialog, &QFontDialog::fontSelected, [=](const QFont &font) {
|
||||
app->fonts->currentFontFamily = font.family().toStdString();
|
||||
app->fonts->currentFontSize = font.pointSize();
|
||||
app->fonts->chatFontFamily = font.family().toStdString();
|
||||
app->fonts->chatFontSize = font.pointSize();
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
|
||||
@@ -29,15 +29,13 @@ namespace widgets {
|
||||
bool SplitContainer::isDraggingSplit = false;
|
||||
Split *SplitContainer::draggingSplit = nullptr;
|
||||
|
||||
SplitContainer::SplitContainer(Notebook *parent, NotebookTab *_tab)
|
||||
SplitContainer::SplitContainer(Notebook2 *parent)
|
||||
: BaseWidget(parent)
|
||||
, tab(_tab)
|
||||
, tab(nullptr)
|
||||
, dropPreview(this)
|
||||
, mouseOverPoint(-10000, -10000)
|
||||
, overlay(this)
|
||||
{
|
||||
this->tab->page = this;
|
||||
|
||||
this->refreshTabTitle();
|
||||
|
||||
this->managedConnect(Split::modifierStatusChanged, [this](auto modifiers) {
|
||||
@@ -69,11 +67,20 @@ SplitContainer::SplitContainer(Notebook *parent, NotebookTab *_tab)
|
||||
this->setAcceptDrops(true);
|
||||
}
|
||||
|
||||
NotebookTab *SplitContainer::getTab() const
|
||||
NotebookTab2 *SplitContainer::getTab() const
|
||||
{
|
||||
return this->tab;
|
||||
}
|
||||
|
||||
void SplitContainer::setTab(NotebookTab2 *_tab)
|
||||
{
|
||||
this->tab = _tab;
|
||||
|
||||
this->tab->page = this;
|
||||
|
||||
this->refreshTabTitle();
|
||||
}
|
||||
|
||||
void SplitContainer::appendNewSplit(bool openChannelNameDialog)
|
||||
{
|
||||
Split *split = new Split(this);
|
||||
@@ -131,6 +138,12 @@ void SplitContainer::insertSplit(Split *split, Direction direction, Node *relati
|
||||
|
||||
this->refreshTabTitle();
|
||||
|
||||
split->getChannelView().tabHighlightRequested.connect([this](HighlightState state) {
|
||||
if (this->tab != nullptr) {
|
||||
this->tab->setHighlightState(state);
|
||||
}
|
||||
});
|
||||
|
||||
this->layout();
|
||||
}
|
||||
|
||||
@@ -149,6 +162,8 @@ SplitContainer::Position SplitContainer::releaseSplit(Split *split)
|
||||
|
||||
this->refreshTabTitle();
|
||||
|
||||
split->getChannelView().tabHighlightRequested.disconnectAll();
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
@@ -265,10 +280,10 @@ void SplitContainer::paintEvent(QPaintEvent *)
|
||||
|
||||
QString text = "Click to add a split";
|
||||
|
||||
Notebook *notebook = dynamic_cast<Notebook *>(this->parentWidget());
|
||||
Notebook2 *notebook = dynamic_cast<Notebook2 *>(this->parentWidget());
|
||||
|
||||
if (notebook != nullptr) {
|
||||
if (notebook->tabCount() > 1) {
|
||||
if (notebook->getPageCount() > 1) {
|
||||
text += "\n\nTip: After adding a split you can hold <Alt> to move it or split it "
|
||||
"further.";
|
||||
}
|
||||
@@ -276,7 +291,7 @@ void SplitContainer::paintEvent(QPaintEvent *)
|
||||
|
||||
painter.drawText(rect(), text, QTextOption(Qt::AlignCenter));
|
||||
} else {
|
||||
painter.fillRect(rect(), this->themeManager->splits.messageSeperator);
|
||||
painter.fillRect(rect(), QColor("#555"));
|
||||
}
|
||||
|
||||
for (DropRect &dropRect : this->dropRects) {
|
||||
@@ -326,13 +341,15 @@ void SplitContainer::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
void SplitContainer::leaveEvent(QEvent *event)
|
||||
{
|
||||
this->mouseOverPoint = QPoint(-1000, -10000);
|
||||
this->mouseOverPoint = QPoint(-10000, -10000);
|
||||
this->update();
|
||||
}
|
||||
|
||||
void SplitContainer::refreshTabTitle()
|
||||
{
|
||||
assert(this->tab != nullptr);
|
||||
if (this->tab == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->tab->useDefaultTitle) {
|
||||
return;
|
||||
|
||||
@@ -165,7 +165,7 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
SplitContainer(Notebook *parent, NotebookTab *_tab);
|
||||
SplitContainer(Notebook2 *parent);
|
||||
|
||||
void appendNewSplit(bool openChannelNameDialog);
|
||||
void appendSplit(Split *split);
|
||||
@@ -189,12 +189,14 @@ public:
|
||||
|
||||
void refreshTabTitle();
|
||||
|
||||
NotebookTab *getTab() const;
|
||||
NotebookTab2 *getTab() const;
|
||||
Node *getBaseNode()
|
||||
{
|
||||
return &this->baseNode;
|
||||
}
|
||||
|
||||
void setTab(NotebookTab2 *tab);
|
||||
|
||||
static bool isDraggingSplit;
|
||||
static Split *draggingSplit;
|
||||
|
||||
@@ -232,7 +234,7 @@ private:
|
||||
|
||||
Node baseNode;
|
||||
|
||||
NotebookTab *tab;
|
||||
NotebookTab2 *tab;
|
||||
std::vector<Split *> splits;
|
||||
|
||||
bool isDragging = false;
|
||||
|
||||
@@ -58,7 +58,7 @@ void TooltipWidget::updateFont()
|
||||
auto app = getApp();
|
||||
|
||||
this->setFont(
|
||||
app->fonts->getFont(singletons::FontManager::Type::MediumSmall, this->getScale()));
|
||||
app->fonts->getFont(singletons::FontManager::Type::ChatMediumSmall, this->getScale()));
|
||||
}
|
||||
|
||||
void TooltipWidget::setText(QString text)
|
||||
|
||||
@@ -27,7 +27,7 @@ Window::Window(WindowType _type)
|
||||
: BaseWindow(nullptr, true)
|
||||
, type(_type)
|
||||
, dpi(this->getScale())
|
||||
, notebook(this, !this->hasCustomWindowFrame())
|
||||
, notebook(this)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
@@ -81,7 +81,7 @@ Window::Window(WindowType _type)
|
||||
CreateWindowShortcut(this, "CTRL+9", [this] { this->notebook.selectIndex(8); });
|
||||
|
||||
// CTRL+SHIFT+T: New tab
|
||||
CreateWindowShortcut(this, "CTRL+SHIFT+T", [this] { this->notebook.addNewPage(true); });
|
||||
CreateWindowShortcut(this, "CTRL+SHIFT+T", [this] { this->notebook.addPage(true); });
|
||||
|
||||
// CTRL+SHIFT+W: Close current tab
|
||||
CreateWindowShortcut(this, "CTRL+SHIFT+W", [this] { this->notebook.removeCurrentPage(); });
|
||||
@@ -106,6 +106,9 @@ Window::Window(WindowType _type)
|
||||
// });
|
||||
|
||||
this->setWindowTitle("Chatterino 2 Development Build");
|
||||
|
||||
this->notebook.setAllowUserTabManagement(true);
|
||||
this->notebook.setShowAddButton(true);
|
||||
}
|
||||
|
||||
Window::WindowType Window::getType()
|
||||
@@ -128,7 +131,7 @@ void Window::repaintVisibleChatWidgets(Channel *channel)
|
||||
}
|
||||
}
|
||||
|
||||
Notebook &Window::getNotebook()
|
||||
SplitNotebook &Window::getNotebook()
|
||||
{
|
||||
return this->notebook;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
|
||||
void repaintVisibleChatWidgets(Channel *channel = nullptr);
|
||||
|
||||
Notebook &getNotebook();
|
||||
SplitNotebook &getNotebook();
|
||||
|
||||
void refreshWindowTitle(const QString &username);
|
||||
|
||||
@@ -47,9 +47,9 @@ private:
|
||||
|
||||
void loadGeometry();
|
||||
|
||||
Notebook notebook;
|
||||
SplitNotebook notebook;
|
||||
|
||||
friend class Notebook;
|
||||
friend class Notebook2;
|
||||
|
||||
public:
|
||||
void save();
|
||||
|
||||
Reference in New Issue
Block a user