From ec349f5978e5a8f5a12889d5c4b65155c12a2ac8 Mon Sep 17 00:00:00 2001 From: fourtf Date: Fri, 30 Mar 2018 13:44:01 +0200 Subject: [PATCH] added experimental new tabs --- src/singletons/thememanager.cpp | 2 + src/widgets/helper/notebooktab.cpp | 60 ++++++++++++++++++++++-------- src/widgets/notebook.cpp | 2 + 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/singletons/thememanager.cpp b/src/singletons/thememanager.cpp index d425cb19b..c9e02d5b0 100644 --- a/src/singletons/thememanager.cpp +++ b/src/singletons/thememanager.cpp @@ -89,6 +89,7 @@ void ThemeManager::actuallyUpdate(double hue, double multiplier) // tabs // text, {regular, hover, unfocused} + this->windowBg = "#ccc"; this->tabs.regular = {tabFg, {windowBg, blendColors(windowBg, "#999", 0.5), windowBg}}; this->tabs.selected = {"#fff", {themeColor, themeColor, QColor::fromHslF(hue, 0, 0.5)}}; @@ -103,6 +104,7 @@ void ThemeManager::actuallyUpdate(double hue, double multiplier) tabFg, {blendColors(themeColor, windowBg, 0.7), blendColors(themeColor, windowBg, 0.5), blendColors(themeColorNoSat, windowBg, 0.7)}}; + this->windowBg = "#fff"; // Split bool flat = isLight; diff --git a/src/widgets/helper/notebooktab.cpp b/src/widgets/helper/notebooktab.cpp index 0034dc76e..432a44b4e 100644 --- a/src/widgets/helper/notebooktab.cpp +++ b/src/widgets/helper/notebooktab.cpp @@ -77,13 +77,16 @@ void NotebookTab::themeRefreshEvent() void NotebookTab::updateSize() { float scale = getScale(); - QString qTitle(qS(this->title)); - if (singletons::SettingManager::getInstance().hideTabX) { - this->resize((int)((fontMetrics().width(qTitle) + 16) * scale), (int)(24 * scale)); - } else { - this->resize((int)((fontMetrics().width(qTitle) + 8 + 24) * scale), (int)(24 * scale)); - } + this->resize((int)(150 * scale), (int)(24 * scale)); + + // QString qTitle(qS(this->title)); + // if (singletons::SettingManager::getInstance().hideTabX) { + // this->resize((int)((fontMetrics().width(qTitle) + 16) * scale), (int)(24 * scale)); + // } else { + // this->resize((int)((fontMetrics().width(qTitle) + 8 + 24) * scale), (int)(24 * + // scale)); + // } if (this->parent() != nullptr) { (static_cast(this->parent()))->performLayout(true); @@ -168,6 +171,7 @@ void NotebookTab::paintEvent(QPaintEvent *) { singletons::SettingManager &settingManager = singletons::SettingManager::getInstance(); QPainter painter(this); + float scale = this->getScale(); // select the right tab colors singletons::ThemeManager::TabColors colors; @@ -186,25 +190,51 @@ void NotebookTab::paintEvent(QPaintEvent *) bool windowFocused = this->window() == QApplication::activeWindow(); // || SettingsDialog::getHandle() == QApplication::activeWindow(); - painter.fillRect(rect(), this->mouseOver ? regular.backgrounds.hover - : (windowFocused ? regular.backgrounds.regular - : regular.backgrounds.unfocused)); + if (false) { + painter.fillRect(rect(), this->mouseOver ? regular.backgrounds.hover + : (windowFocused ? regular.backgrounds.regular + : regular.backgrounds.unfocused)); - // fill the tab background - painter.fillRect(rect(), this->mouseOver ? colors.backgrounds.hover - : (windowFocused ? colors.backgrounds.regular - : colors.backgrounds.unfocused)); + // fill the tab background + painter.fillRect(rect(), this->mouseOver ? colors.backgrounds.hover + : (windowFocused ? colors.backgrounds.regular + : colors.backgrounds.unfocused)); + } else { + QPainterPath path(QPointF(0, this->height())); + path.lineTo(8 * scale, 0); + path.lineTo(this->width() - 8 * scale, 0); + path.lineTo(this->width(), this->height()); + painter.fillPath(path, this->mouseOver ? regular.backgrounds.hover + : (windowFocused ? regular.backgrounds.regular + : regular.backgrounds.unfocused)); + + // fill the tab background + painter.fillPath(path, this->mouseOver ? colors.backgrounds.hover + : (windowFocused ? colors.backgrounds.regular + : colors.backgrounds.unfocused)); + painter.setPen(QColor("#FFF")); + painter.setRenderHint(QPainter::Antialiasing); + painter.drawPath(path); + // painter.setBrush(QColor("#000")); + } // set the pen color painter.setPen(colors.text); // set area for text - float scale = this->getScale(); int rectW = (settingManager.hideTabX ? 0 : static_cast(16) * scale); QRect rect(0, 0, this->width() - rectW, this->height()); // draw text - painter.drawText(rect, this->getTitle(), QTextOption(Qt::AlignCenter)); + if (false) { // legacy + painter.drawText(rect, this->getTitle(), QTextOption(Qt::AlignCenter)); + } else { + QTextOption option(Qt::AlignLeft | Qt::AlignVCenter); + option.setWrapMode(QTextOption::NoWrap); + int offset = (int)(scale * 16); + QRect textRect(offset, 0, this->width() - offset - offset, this->height()); + painter.drawText(textRect, this->getTitle(), option); + } // draw close x if (!settingManager.hideTabX && (mouseOver || selected)) { diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index b3082f470..f790e62a9 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -250,6 +250,8 @@ void Notebook::performLayout(bool animated) x += i->getTab()->width(); } + x -= (int)(8 * scale); + first = false; }