mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
improved new tabs
This commit is contained in:
parent
57e0e85d77
commit
700b15c483
5 changed files with 47 additions and 20 deletions
|
@ -90,6 +90,8 @@ void ThemeManager::actuallyUpdate(double hue, double multiplier)
|
||||||
// tabs
|
// tabs
|
||||||
// text, {regular, hover, unfocused}
|
// text, {regular, hover, unfocused}
|
||||||
this->windowBg = "#ccc";
|
this->windowBg = "#ccc";
|
||||||
|
|
||||||
|
this->tabs.border = "#999";
|
||||||
this->tabs.regular = {tabFg, {windowBg, blendColors(windowBg, "#999", 0.5), windowBg}};
|
this->tabs.regular = {tabFg, {windowBg, blendColors(windowBg, "#999", 0.5), windowBg}};
|
||||||
|
|
||||||
this->tabs.selected = {"#fff", {themeColor, themeColor, QColor::fromHslF(hue, 0, 0.5)}};
|
this->tabs.selected = {"#fff", {themeColor, themeColor, QColor::fromHslF(hue, 0, 0.5)}};
|
||||||
|
@ -104,6 +106,7 @@ void ThemeManager::actuallyUpdate(double hue, double multiplier)
|
||||||
tabFg,
|
tabFg,
|
||||||
{blendColors(themeColor, windowBg, 0.7), blendColors(themeColor, windowBg, 0.5),
|
{blendColors(themeColor, windowBg, 0.7), blendColors(themeColor, windowBg, 0.5),
|
||||||
blendColors(themeColorNoSat, windowBg, 0.7)}};
|
blendColors(themeColorNoSat, windowBg, 0.7)}};
|
||||||
|
|
||||||
this->windowBg = "#fff";
|
this->windowBg = "#fff";
|
||||||
|
|
||||||
// Split
|
// Split
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
TabColors selected;
|
TabColors selected;
|
||||||
TabColors highlighted;
|
TabColors highlighted;
|
||||||
TabColors newMessage;
|
TabColors newMessage;
|
||||||
|
QColor border;
|
||||||
} tabs;
|
} tabs;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
|
@ -38,7 +38,7 @@ void NotebookButton::paintEvent(QPaintEvent *)
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
painter.fillRect(this->rect(), background);
|
// painter.fillRect(this->rect(), background);
|
||||||
|
|
||||||
float h = height(), w = width();
|
float h = height(), w = width();
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QLinearGradient>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
@ -78,15 +79,16 @@ void NotebookTab::updateSize()
|
||||||
{
|
{
|
||||||
float scale = getScale();
|
float scale = getScale();
|
||||||
|
|
||||||
this->resize((int)(150 * scale), (int)(24 * scale));
|
int width;
|
||||||
|
|
||||||
// QString qTitle(qS(this->title));
|
QString qTitle(qS(this->title));
|
||||||
// if (singletons::SettingManager::getInstance().hideTabX) {
|
if (singletons::SettingManager::getInstance().hideTabX) {
|
||||||
// this->resize((int)((fontMetrics().width(qTitle) + 16) * scale), (int)(24 * scale));
|
width = (int)((fontMetrics().width(qTitle) + 16 + 16) * scale);
|
||||||
// } else {
|
} else {
|
||||||
// this->resize((int)((fontMetrics().width(qTitle) + 8 + 24) * scale), (int)(24 *
|
width = (int)((fontMetrics().width(qTitle) + 8 + 24 + 16) * scale);
|
||||||
// scale));
|
}
|
||||||
// }
|
|
||||||
|
this->resize(std::min((int)(150 * scale), width), (int)(48 * scale));
|
||||||
|
|
||||||
if (this->parent() != nullptr) {
|
if (this->parent() != nullptr) {
|
||||||
(static_cast<Notebook *>(this->parent()))->performLayout(true);
|
(static_cast<Notebook *>(this->parent()))->performLayout(true);
|
||||||
|
@ -173,6 +175,9 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
float scale = this->getScale();
|
float scale = this->getScale();
|
||||||
|
|
||||||
|
int height = (int)(scale * 24);
|
||||||
|
int fullHeight = (int)(scale * 48);
|
||||||
|
|
||||||
// select the right tab colors
|
// select the right tab colors
|
||||||
singletons::ThemeManager::TabColors colors;
|
singletons::ThemeManager::TabColors colors;
|
||||||
singletons::ThemeManager::TabColors regular = this->themeManager.tabs.regular;
|
singletons::ThemeManager::TabColors regular = this->themeManager.tabs.regular;
|
||||||
|
@ -190,32 +195,39 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
||||||
bool windowFocused = this->window() == QApplication::activeWindow();
|
bool windowFocused = this->window() == QApplication::activeWindow();
|
||||||
// || SettingsDialog::getHandle() == QApplication::activeWindow();
|
// || SettingsDialog::getHandle() == QApplication::activeWindow();
|
||||||
|
|
||||||
|
QBrush tabBackground = this->mouseOver ? colors.backgrounds.hover
|
||||||
|
: (windowFocused ? colors.backgrounds.regular
|
||||||
|
: colors.backgrounds.unfocused);
|
||||||
|
|
||||||
if (false) {
|
if (false) {
|
||||||
painter.fillRect(rect(), this->mouseOver ? regular.backgrounds.hover
|
painter.fillRect(rect(), this->mouseOver ? regular.backgrounds.hover
|
||||||
: (windowFocused ? regular.backgrounds.regular
|
: (windowFocused ? regular.backgrounds.regular
|
||||||
: regular.backgrounds.unfocused));
|
: regular.backgrounds.unfocused));
|
||||||
|
|
||||||
// fill the tab background
|
// fill the tab background
|
||||||
painter.fillRect(rect(), this->mouseOver ? colors.backgrounds.hover
|
painter.fillRect(rect(), tabBackground);
|
||||||
: (windowFocused ? colors.backgrounds.regular
|
|
||||||
: colors.backgrounds.unfocused));
|
|
||||||
} else {
|
} else {
|
||||||
QPainterPath path(QPointF(0, this->height()));
|
QPainterPath path(QPointF(0, height));
|
||||||
path.lineTo(8 * scale, 0);
|
path.lineTo(8 * scale, 0);
|
||||||
path.lineTo(this->width() - 8 * scale, 0);
|
path.lineTo(this->width() - 8 * scale, 0);
|
||||||
path.lineTo(this->width(), this->height());
|
path.lineTo(this->width(), height);
|
||||||
painter.fillPath(path, this->mouseOver ? regular.backgrounds.hover
|
painter.fillPath(path, this->mouseOver ? regular.backgrounds.hover
|
||||||
: (windowFocused ? regular.backgrounds.regular
|
: (windowFocused ? regular.backgrounds.regular
|
||||||
: regular.backgrounds.unfocused));
|
: regular.backgrounds.unfocused));
|
||||||
|
|
||||||
// fill the tab background
|
// fill the tab background
|
||||||
painter.fillPath(path, this->mouseOver ? colors.backgrounds.hover
|
painter.fillPath(path, tabBackground);
|
||||||
: (windowFocused ? colors.backgrounds.regular
|
|
||||||
: colors.backgrounds.unfocused));
|
|
||||||
painter.setPen(QColor("#FFF"));
|
painter.setPen(QColor("#FFF"));
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
painter.drawPath(path);
|
painter.drawPath(path);
|
||||||
// painter.setBrush(QColor("#000"));
|
// 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
|
// set the pen color
|
||||||
|
@ -223,7 +235,7 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
||||||
|
|
||||||
// set area for text
|
// set area for text
|
||||||
int rectW = (settingManager.hideTabX ? 0 : static_cast<int>(16) * scale);
|
int rectW = (settingManager.hideTabX ? 0 : static_cast<int>(16) * scale);
|
||||||
QRect rect(0, 0, this->width() - rectW, this->height());
|
QRect rect(0, 0, this->width() - rectW, height);
|
||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
if (false) { // legacy
|
if (false) { // legacy
|
||||||
|
@ -232,7 +244,7 @@ void NotebookTab::paintEvent(QPaintEvent *)
|
||||||
QTextOption option(Qt::AlignLeft | Qt::AlignVCenter);
|
QTextOption option(Qt::AlignLeft | Qt::AlignVCenter);
|
||||||
option.setWrapMode(QTextOption::NoWrap);
|
option.setWrapMode(QTextOption::NoWrap);
|
||||||
int offset = (int)(scale * 16);
|
int offset = (int)(scale * 16);
|
||||||
QRect textRect(offset, 0, this->width() - offset - offset, this->height());
|
QRect textRect(offset, 0, this->width() - offset - offset, height);
|
||||||
painter.drawText(textRect, this->getTitle(), option);
|
painter.drawText(textRect, this->getTitle(), option);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,6 +162,8 @@ SplitContainer *Notebook::tabAt(QPoint point, int &index, int maxWidth)
|
||||||
|
|
||||||
for (auto *page : this->pages) {
|
for (auto *page : this->pages) {
|
||||||
QRect rect = page->getTab()->getDesiredRect();
|
QRect rect = page->getTab()->getDesiredRect();
|
||||||
|
rect.setHeight((int)(this->getScale() * 22));
|
||||||
|
|
||||||
rect.setWidth(std::min(maxWidth, rect.width()));
|
rect.setWidth(std::min(maxWidth, rect.width()));
|
||||||
|
|
||||||
if (rect.contains(point)) {
|
if (rect.contains(point)) {
|
||||||
|
@ -242,7 +244,8 @@ void Notebook::performLayout(bool animated)
|
||||||
for (auto &i : this->pages) {
|
for (auto &i : this->pages) {
|
||||||
if (!first &&
|
if (!first &&
|
||||||
(i == this->pages.last() ? tabHeight : 0) + x + i->getTab()->width() > width()) {
|
(i == this->pages.last() ? tabHeight : 0) + x + i->getTab()->width() > width()) {
|
||||||
y += i->getTab()->height();
|
// y += i->getTab()->height();
|
||||||
|
y += 20;
|
||||||
i->getTab()->moveAnimated(QPoint(0, y), animated);
|
i->getTab()->moveAnimated(QPoint(0, y), animated);
|
||||||
x = i->getTab()->width();
|
x = i->getTab()->width();
|
||||||
} else {
|
} else {
|
||||||
|
@ -255,8 +258,16 @@ void Notebook::performLayout(bool animated)
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
x += (int)(8 * scale);
|
||||||
|
|
||||||
this->addButton.move(x, y);
|
this->addButton.move(x, y);
|
||||||
|
|
||||||
|
for (auto &i : this->pages) {
|
||||||
|
i->getTab()->raise();
|
||||||
|
}
|
||||||
|
|
||||||
|
this->addButton.raise();
|
||||||
|
|
||||||
if (this->selectedPage != nullptr) {
|
if (this->selectedPage != nullptr) {
|
||||||
this->selectedPage->move(0, y + tabHeight);
|
this->selectedPage->move(0, y + tabHeight);
|
||||||
this->selectedPage->resize(width(), height() - y - tabHeight);
|
this->selectedPage->resize(width(), height() - y - tabHeight);
|
||||||
|
|
Loading…
Reference in a new issue