From ea9f9e7f183de68e9458421e5bdd0f54e3770a7e Mon Sep 17 00:00:00 2001 From: fourtf Date: Mon, 11 Jun 2018 15:04:54 +0200 Subject: [PATCH] added ui scaling --- chatterino.pro | 9 +- src/singletons/fontmanager.cpp | 2 +- src/singletons/settingsmanager.hpp | 1 + src/singletons/windowmanager.cpp | 49 ++++++ src/singletons/windowmanager.hpp | 6 + src/util/clamp.hpp | 23 +++ src/widgets/basewindow.cpp | 150 ++++++++++++------- src/widgets/basewindow.hpp | 24 ++- src/widgets/helper/channelview.cpp | 5 + src/widgets/helper/label.cpp | 86 ----------- src/widgets/helper/label.hpp | 34 ----- src/widgets/helper/notebooktab.cpp | 7 +- src/widgets/helper/splitheader.cpp | 16 +- src/widgets/helper/splitheader.hpp | 4 +- src/widgets/helper/splitinput.cpp | 1 + src/widgets/label.cpp | 121 +++++++++++++++ src/widgets/label.hpp | 46 ++++++ src/widgets/notebook.cpp | 2 +- src/widgets/qualitypopup.cpp | 22 +-- src/widgets/qualitypopup.hpp | 2 +- src/widgets/selectchanneldialog.cpp | 58 +++---- src/widgets/selectchanneldialog.hpp | 2 +- src/widgets/settingsdialog.cpp | 38 ++--- src/widgets/settingsdialog.hpp | 2 +- src/widgets/settingspages/appearancepage.cpp | 28 ++++ src/widgets/settingspages/appearancepage.hpp | 4 + src/widgets/window.cpp | 17 +++ 27 files changed, 488 insertions(+), 271 deletions(-) create mode 100644 src/util/clamp.hpp delete mode 100644 src/widgets/helper/label.cpp delete mode 100644 src/widgets/helper/label.hpp create mode 100644 src/widgets/label.cpp create mode 100644 src/widgets/label.hpp diff --git a/chatterino.pro b/chatterino.pro index 5b93269fd..8e251f257 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -140,7 +140,6 @@ SOURCES += \ src/widgets/emotepopup.cpp \ src/widgets/helper/channelview.cpp \ src/widgets/helper/droppreview.cpp \ - src/widgets/helper/label.cpp \ src/widgets/helper/notebookbutton.cpp \ src/widgets/helper/notebooktab.cpp \ src/widgets/helper/resizingtextedit.cpp \ @@ -217,7 +216,8 @@ SOURCES += \ src/util/emotemap.cpp \ src/providers/irc/ircconnection2.cpp \ src/widgets/userinfopopup.cpp \ - src/widgets/welcomedialog.cpp + src/widgets/welcomedialog.cpp \ + src/widgets/label.cpp HEADERS += \ src/precompiled_header.hpp \ @@ -285,7 +285,6 @@ HEADERS += \ src/widgets/emotepopup.hpp \ src/widgets/helper/channelview.hpp \ src/widgets/helper/droppreview.hpp \ - src/widgets/helper/label.hpp \ src/widgets/helper/notebookbutton.hpp \ src/widgets/helper/notebooktab.hpp \ src/widgets/helper/resizingtextedit.hpp \ @@ -377,7 +376,9 @@ HEADERS += \ src/providers/irc/ircconnection2.hpp \ src/widgets/helper/line.hpp \ src/widgets/userinfopopup.hpp \ - src/widgets/welcomedialog.hpp + src/widgets/welcomedialog.hpp \ + src/util/clamp.hpp \ + src/widgets/label.hpp RESOURCES += \ resources/resources.qrc diff --git a/src/singletons/fontmanager.cpp b/src/singletons/fontmanager.cpp index 240492484..f733979a7 100644 --- a/src/singletons/fontmanager.cpp +++ b/src/singletons/fontmanager.cpp @@ -121,7 +121,7 @@ FontManager::FontData FontManager::createFontData(Type type, float scale) static std::unordered_map defaultSize{ {Tiny, {8, "Monospace", false, QFont::Normal}}, - {UiMedium, {int(12 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}}, + {UiMedium, {int(9 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}}, {UiTabs, {int(9 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}}, }; diff --git a/src/singletons/settingsmanager.hpp b/src/singletons/settingsmanager.hpp index 2e71ab748..6120f001a 100644 --- a/src/singletons/settingsmanager.hpp +++ b/src/singletons/settingsmanager.hpp @@ -44,6 +44,7 @@ public: IntSetting collpseMessagesMinLines = {"/appearance/messages/collapseMessagesMinLines", 0}; BoolSetting alternateMessageBackground = {"/appearance/messages/alternateMessageBackground", false}; + IntSetting uiScale = {"/appearance/uiScale", 0}; BoolSetting windowTopMost = {"/appearance/windowAlwaysOnTop", false}; BoolSetting showTabCloseButton = {"/appearance/showTabCloseButton", true}; BoolSetting hidePreferencesButton = {"/appearance/hidePreferencesButton", false}; diff --git a/src/singletons/windowmanager.cpp b/src/singletons/windowmanager.cpp index 69e0046b7..8478bf9a6 100644 --- a/src/singletons/windowmanager.cpp +++ b/src/singletons/windowmanager.cpp @@ -7,6 +7,7 @@ #include "singletons/pathmanager.hpp" #include "singletons/thememanager.hpp" #include "util/assertinguithread.hpp" +#include "util/clamp.hpp" #include "widgets/accountswitchpopupwidget.hpp" #include "widgets/settingsdialog.hpp" @@ -410,5 +411,53 @@ void WindowManager::incGeneration() this->generation++; } +int WindowManager::clampUiScale(int scale) +{ + return util::clamp(scale, uiScaleMin, uiScaleMax); +} + +float WindowManager::getUiScaleValue() +{ + return getUiScaleValue(getApp()->settings->uiScale.getValue()); +} + +float WindowManager::getUiScaleValue(int scale) +{ + switch (clampUiScale(scale)) { + case -5: + return 0.5f; + case -4: + return 0.6f; + case -3: + return 0.7f; + case -2: + return 0.8f; + case -1: + return 0.9f; + case 0: + return 1; + case 1: + return 1.2f; + case 2: + return 1.4f; + case 3: + return 1.6f; + case 4: + return 1.6f; + case 5: + return 2; + case 6: + return 2.33f; + case 7: + return 2.66f; + case 8: + return 3; + case 9: + return 3.5f; + case 10: + return 4; + } +} + } // namespace singletons } // namespace chatterino diff --git a/src/singletons/windowmanager.hpp b/src/singletons/windowmanager.hpp index ccee1d875..7f237568e 100644 --- a/src/singletons/windowmanager.hpp +++ b/src/singletons/windowmanager.hpp @@ -42,6 +42,12 @@ public: pajlada::Signals::NoArgSignal repaintGifs; pajlada::Signals::Signal layout; + static const int uiScaleMin = -5; + static const int uiScaleMax = 10; + static int clampUiScale(int scale); + static float getUiScaleValue(); + static float getUiScaleValue(int scale); + private: bool initialized = false; diff --git a/src/util/clamp.hpp b/src/util/clamp.hpp new file mode 100644 index 000000000..66fe46fdc --- /dev/null +++ b/src/util/clamp.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include + +namespace chatterino { +namespace util { + +// http://en.cppreference.com/w/cpp/algorithm/clamp + +template +constexpr const T &clamp(const T &v, const T &lo, const T &hi) +{ + return clamp(v, lo, hi, std::less<>()); +} + +template +constexpr const T &clamp(const T &v, const T &lo, const T &hi, Compare comp) +{ + return assert(!comp(hi, lo)), comp(v, lo) ? lo : comp(hi, v) ? hi : v; +} + +} // namespace util +} // namespace chatterino diff --git a/src/widgets/basewindow.cpp b/src/widgets/basewindow.cpp index 6ede48551..9792c6aa2 100644 --- a/src/widgets/basewindow.cpp +++ b/src/widgets/basewindow.cpp @@ -1,10 +1,15 @@ #include "basewindow.hpp" #include "application.hpp" +#include "boost/algorithm/algorithm.hpp" #include "debug/log.hpp" #include "singletons/settingsmanager.hpp" +#include "singletons/windowmanager.hpp" #include "util/nativeeventhelper.hpp" +#include "util/posttothread.hpp" #include "widgets/helper/rippleeffectlabel.hpp" +#include "widgets/helper/shortcut.hpp" +#include "widgets/label.hpp" #include "widgets/tooltipwidget.hpp" #include @@ -35,25 +40,33 @@ namespace widgets { BaseWindow::BaseWindow(QWidget *parent, Flags _flags) : BaseWidget(parent, Qt::Window | ((_flags & TopMost) ? Qt::WindowStaysOnTopHint : Qt::WindowFlags())) - , enableCustomFrame(_flags & EnableCustomFrame) - , frameless(_flags & Frameless) - , flags(_flags) + , enableCustomFrame_(_flags & EnableCustomFrame) + , frameless_(_flags & Frameless) + , flags_(_flags) { - if (this->frameless) { - this->enableCustomFrame = false; + if (this->frameless_) { + this->enableCustomFrame_ = false; this->setWindowFlag(Qt::FramelessWindowHint); } - if (this->flags & DeleteOnFocusOut) { + if (this->flags_ & DeleteOnFocusOut) { this->setAttribute(Qt::WA_DeleteOnClose); } this->init(); + + this->connections_.managedConnect( + getApp()->settings->uiScale.getValueChangedSignal(), + [this](auto, auto) { util::postToThread([this] { this->updateScale(); }); }); + + this->updateScale(); + + CreateWindowShortcut(this, "CTRL+0", [] { getApp()->settings->uiScale.setValue(1); }); } BaseWindow::Flags BaseWindow::getFlags() { - return this->flags; + return this->flags_; } void BaseWindow::init() @@ -68,23 +81,23 @@ void BaseWindow::init() layout->setSpacing(0); this->setLayout(layout); { - if (!this->frameless) { - QHBoxLayout *buttonLayout = this->ui.titlebarBox = new QHBoxLayout(); + if (!this->frameless_) { + QHBoxLayout *buttonLayout = this->ui_.titlebarBox = new QHBoxLayout(); buttonLayout->setMargin(0); layout->addLayout(buttonLayout); // title - QLabel *title = new QLabel(" Chatterino"); + Label *title = new Label("Chatterino"); QObject::connect(this, &QWidget::windowTitleChanged, - [title](const QString &text) { title->setText(" " + text); }); + [title](const QString &text) { title->setText(text); }); QSizePolicy policy(QSizePolicy::Ignored, QSizePolicy::Preferred); policy.setHorizontalStretch(1); // title->setBaseSize(0, 0); - title->setScaledContents(true); + // title->setScaledContents(true); title->setSizePolicy(policy); buttonLayout->addWidget(title); - this->ui.titleLabel = title; + this->ui_.titleLabel = title; // buttons TitleBarButton *_minButton = new TitleBarButton; @@ -105,13 +118,13 @@ void BaseWindow::init() QObject::connect(_exitButton, &TitleBarButton::clicked, this, [this] { this->close(); }); - this->ui.minButton = _minButton; - this->ui.maxButton = _maxButton; - this->ui.exitButton = _exitButton; + this->ui_.minButton = _minButton; + this->ui_.maxButton = _maxButton; + this->ui_.exitButton = _exitButton; - this->ui.buttons.push_back(_minButton); - this->ui.buttons.push_back(_maxButton); - this->ui.buttons.push_back(_exitButton); + this->ui_.buttons.push_back(_minButton); + this->ui_.buttons.push_back(_maxButton); + this->ui_.buttons.push_back(_exitButton); // buttonLayout->addStretch(1); buttonLayout->addWidget(_minButton); @@ -120,8 +133,8 @@ void BaseWindow::init() buttonLayout->setSpacing(0); } } - this->ui.layoutBase = new BaseWidget(this); - layout->addWidget(this->ui.layoutBase); + this->ui_.layoutBase = new BaseWidget(this); + layout->addWidget(this->ui_.layoutBase); } // DPI @@ -134,7 +147,7 @@ void BaseWindow::init() #ifdef USEWINSDK // fourtf: don't ask me why we need to delay this - if (!(this->flags & Flags::TopMost)) { + if (!(this->flags_ & Flags::TopMost)) { QTimer::singleShot(1, this, [this] { getApp()->settings->windowTopMost.connect([this](bool topMost, auto) { ::SetWindowPos(HWND(this->winId()), topMost ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, @@ -151,18 +164,18 @@ void BaseWindow::init() void BaseWindow::setStayInScreenRect(bool value) { - this->stayInScreenRect = value; + this->stayInScreenRect_ = value; } bool BaseWindow::getStayInScreenRect() const { - return this->stayInScreenRect; + return this->stayInScreenRect_; } QWidget *BaseWindow::getLayoutContainer() { if (this->hasCustomWindowFrame()) { - return this->ui.layoutBase; + return this->ui_.layoutBase; } else { return this; } @@ -173,7 +186,7 @@ bool BaseWindow::hasCustomWindowFrame() #ifdef USEWINSDK static bool isWin8 = IsWindows8OrGreater(); - return isWin8 && this->enableCustomFrame; + return isWin8 && this->enableCustomFrame_; #else return false; #endif @@ -187,14 +200,14 @@ void BaseWindow::themeRefreshEvent() palette.setColor(QPalette::Foreground, this->themeManager->window.text); this->setPalette(palette); - if (this->ui.titleLabel) { + if (this->ui_.titleLabel) { QPalette palette_title; palette_title.setColor(QPalette::Foreground, this->themeManager->isLightTheme() ? "#333" : "#ccc"); - this->ui.titleLabel->setPalette(palette_title); + this->ui_.titleLabel->setPalette(palette_title); } - for (RippleEffectButton *button : this->ui.buttons) { + for (RippleEffectButton *button : this->ui_.buttons) { button->setMouseEffectColor(this->themeManager->window.text); } } else { @@ -208,7 +221,7 @@ void BaseWindow::themeRefreshEvent() bool BaseWindow::event(QEvent *event) { if (event->type() == QEvent::WindowDeactivate /*|| event->type() == QEvent::FocusOut*/) { - if (this->flags & DeleteOnFocusOut) { + if (this->flags_ & DeleteOnFocusOut) { this->close(); } } @@ -216,14 +229,27 @@ bool BaseWindow::event(QEvent *event) return QWidget::event(event); } +void BaseWindow::wheelEvent(QWheelEvent *event) +{ + if (event->modifiers() & Qt::ControlModifier) { + if (event->delta() > 0) { + getApp()->settings->uiScale.setValue(singletons::WindowManager::clampUiScale( + getApp()->settings->uiScale.getValue() + 1)); + } else { + getApp()->settings->uiScale.setValue(singletons::WindowManager::clampUiScale( + getApp()->settings->uiScale.getValue() - 1)); + } + } +} + void BaseWindow::addTitleBarButton(const TitleBarButton::Style &style, std::function onClicked) { TitleBarButton *button = new TitleBarButton; button->setScaleIndependantSize(30, 30); - this->ui.buttons.push_back(button); - this->ui.titlebarBox->insertWidget(1, button); + this->ui_.buttons.push_back(button); + this->ui_.titlebarBox->insertWidget(1, button); button->setButtonStyle(style); QObject::connect(button, &TitleBarButton::clicked, this, [onClicked] { onClicked(); }); @@ -234,8 +260,8 @@ RippleEffectLabel *BaseWindow::addTitleBarLabel(std::function onClicked) RippleEffectLabel *button = new RippleEffectLabel; button->setScaleIndependantHeight(30); - this->ui.buttons.push_back(button); - this->ui.titlebarBox->insertWidget(1, button); + this->ui_.buttons.push_back(button); + this->ui_.titlebarBox->insertWidget(1, button); QObject::connect(button, &RippleEffectLabel::clicked, this, [onClicked] { onClicked(); }); @@ -247,10 +273,10 @@ void BaseWindow::changeEvent(QEvent *) TooltipWidget::getInstance()->hide(); #ifdef USEWINSDK - if (this->ui.maxButton) { - this->ui.maxButton->setButtonStyle(this->windowState() & Qt::WindowMaximized - ? TitleBarButton::Unmaximize - : TitleBarButton::Maximize); + if (this->ui_.maxButton) { + this->ui_.maxButton->setButtonStyle(this->windowState() & Qt::WindowMaximized + ? TitleBarButton::Unmaximize + : TitleBarButton::Maximize); } #endif @@ -284,7 +310,7 @@ void BaseWindow::resizeEvent(QResizeEvent *) void BaseWindow::moveIntoDesktopRect(QWidget *parent) { - if (!this->stayInScreenRect) + if (!this->stayInScreenRect_) return; // move the widget into the screen geometry if it's not already in there @@ -326,7 +352,8 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r this->resize(static_cast(this->width() * resizeScale), static_cast(this->height() * resizeScale)); - this->setScale(_scale); + this->nativeScale_ = _scale; + this->updateScale(); return true; } @@ -419,13 +446,13 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r bool client = false; QPoint point(x - winrect.left, y - winrect.top); - for (QWidget *widget : this->ui.buttons) { + for (QWidget *widget : this->ui_.buttons) { if (widget->geometry().contains(point)) { client = true; } } - if (this->ui.layoutBase->geometry().contains(point)) { + if (this->ui_.layoutBase->geometry().contains(point)) { client = true; } @@ -449,8 +476,8 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r void BaseWindow::showEvent(QShowEvent *event) { - if (!this->shown && this->isVisible() && this->hasCustomWindowFrame()) { - this->shown = true; + if (!this->shown_ && this->isVisible() && this->hasCustomWindowFrame()) { + this->shown_ = true; // SetWindowLongPtr((HWND)this->winId(), GWL_STYLE, // WS_POPUP | WS_CAPTION | WS_THICKFRAME | WS_MAXIMIZEBOX | // WS_MINIMIZEBOX); @@ -470,7 +497,7 @@ void BaseWindow::scaleChangedEvent(float) void BaseWindow::paintEvent(QPaintEvent *) { - if (this->frameless) { + if (this->frameless_) { QPainter painter(this); painter.setPen(QColor("#999")); @@ -489,25 +516,32 @@ void BaseWindow::paintEvent(QPaintEvent *) #endif } +void BaseWindow::updateScale() +{ + this->setScale(this->nativeScale_ * (this->flags_ & DisableCustomScaling + ? 1 + : getApp()->windows->getUiScaleValue())); +} + void BaseWindow::calcButtonsSizes() { - if (!this->shown) { + if (!this->shown_) { return; } if ((this->width() / this->getScale()) < 300) { - if (this->ui.minButton) - this->ui.minButton->setScaleIndependantSize(30, 30); - if (this->ui.maxButton) - this->ui.maxButton->setScaleIndependantSize(30, 30); - if (this->ui.exitButton) - this->ui.exitButton->setScaleIndependantSize(30, 30); + if (this->ui_.minButton) + this->ui_.minButton->setScaleIndependantSize(30, 30); + if (this->ui_.maxButton) + this->ui_.maxButton->setScaleIndependantSize(30, 30); + if (this->ui_.exitButton) + this->ui_.exitButton->setScaleIndependantSize(30, 30); } else { - if (this->ui.minButton) - this->ui.minButton->setScaleIndependantSize(46, 30); - if (this->ui.maxButton) - this->ui.maxButton->setScaleIndependantSize(46, 30); - if (this->ui.exitButton) - this->ui.exitButton->setScaleIndependantSize(46, 30); + if (this->ui_.minButton) + this->ui_.minButton->setScaleIndependantSize(46, 30); + if (this->ui_.maxButton) + this->ui_.maxButton->setScaleIndependantSize(46, 30); + if (this->ui_.exitButton) + this->ui_.exitButton->setScaleIndependantSize(46, 30); } } } // namespace widgets diff --git a/src/widgets/basewindow.hpp b/src/widgets/basewindow.hpp index d970e9677..0839385d7 100644 --- a/src/widgets/basewindow.hpp +++ b/src/widgets/basewindow.hpp @@ -4,6 +4,7 @@ #include "widgets/helper/titlebarbutton.hpp" #include +#include class QHBoxLayout; @@ -24,10 +25,11 @@ public: EnableCustomFrame = 1, Frameless = 2, TopMost = 4, - DeleteOnFocusOut = 8 + DeleteOnFocusOut = 8, + DisableCustomScaling = 16, }; - explicit BaseWindow(QWidget *parent = nullptr, Flags flags = None); + explicit BaseWindow(QWidget *parent = nullptr, Flags flags_ = None); QWidget *getLayoutContainer(); bool hasCustomWindowFrame(); @@ -56,17 +58,21 @@ protected: virtual void themeRefreshEvent() override; virtual bool event(QEvent *event) override; + virtual void wheelEvent(QWheelEvent *event) override; + + void updateScale(); private: void init(); void moveIntoDesktopRect(QWidget *parent); void calcButtonsSizes(); - bool enableCustomFrame; - bool frameless; - bool stayInScreenRect = false; - bool shown = false; - Flags flags; + bool enableCustomFrame_; + bool frameless_; + bool stayInScreenRect_ = false; + bool shown_ = false; + Flags flags_; + float nativeScale_ = 1; struct { QHBoxLayout *titlebarBox = nullptr; @@ -76,7 +82,9 @@ private: TitleBarButton *exitButton = nullptr; QWidget *layoutBase = nullptr; std::vector buttons; - } ui; + } ui_; + + pajlada::Signals::SignalHolder connections_; }; } // namespace widgets diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index 0ddd41d28..8de62b6d3 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -660,6 +660,11 @@ void ChannelView::drawMessages(QPainter &painter) void ChannelView::wheelEvent(QWheelEvent *event) { + if (event->modifiers() & Qt::ControlModifier) { + event->ignore(); + return; + } + this->pausedBySelection = false; this->pausedTemporarily = false; diff --git a/src/widgets/helper/label.cpp b/src/widgets/helper/label.cpp deleted file mode 100644 index 45dadf3d6..000000000 --- a/src/widgets/helper/label.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "label.hpp" - -#include "application.hpp" -#include "singletons/fontmanager.hpp" - -#include - -namespace chatterino { -namespace widgets { - -Label::Label(BaseWidget *parent) - : BaseWidget(parent) -{ - auto app = getApp(); - - app->fonts->fontChanged.connect([=]() { - this->scaleChangedEvent(this->getScale()); // - }); -} - -const QString &Label::getText() const -{ - return this->text; -} - -void Label::setText(const QString &value) -{ - this->text = value; - this->scaleChangedEvent(this->getScale()); -} - -FontStyle Label::getFontStyle() const -{ - return this->fontStyle; -} - -void Label::setFontStyle(FontStyle style) -{ - this->fontStyle = style; - this->scaleChangedEvent(this->getScale()); -} - -void Label::scaleChangedEvent(float scale) -{ - auto app = getApp(); - - QFontMetrics metrics = app->fonts->getFontMetrics(this->fontStyle, scale); - - this->preferedSize = QSize(metrics.width(this->text), metrics.height()); - - this->updateGeometry(); -} - -QSize Label::sizeHint() const -{ - return this->preferedSize; -} - -QSize Label::minimumSizeHint() const -{ - return this->preferedSize; -} - -void Label::paintEvent(QPaintEvent *) -{ - auto app = getApp(); - - QPainter painter(this); - painter.setFont(app->fonts->getFont(this->fontStyle, - this->getScale() / painter.device()->devicePixelRatioF())); - - int width = app->fonts->getFontMetrics(this->fontStyle, this->getScale()).width(this->text); - - int flags = Qt::TextSingleLine; - - if (this->width() < width) { - flags |= Qt::AlignLeft | Qt::AlignVCenter; - } else { - flags |= Qt::AlignCenter; - } - - painter.drawText(this->rect(), flags, this->text); -} - -} // namespace widgets -} // namespace chatterino diff --git a/src/widgets/helper/label.hpp b/src/widgets/helper/label.hpp deleted file mode 100644 index 3af4eadfb..000000000 --- a/src/widgets/helper/label.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "singletons/fontmanager.hpp" -#include "widgets/basewidget.hpp" - -namespace chatterino { -namespace widgets { - -class Label : public BaseWidget -{ -public: - Label(BaseWidget *parent); - - const QString &getText() const; - void setText(const QString &text); - - FontStyle getFontStyle() const; - void setFontStyle(FontStyle style); - -protected: - virtual void scaleChangedEvent(float scale) override; - virtual void paintEvent(QPaintEvent *event) override; - - virtual QSize sizeHint() const override; - virtual QSize minimumSizeHint() const override; - -private: - QSize preferedSize; - QString text; - FontStyle fontStyle = FontStyle::ChatMedium; -}; - -} // namespace widgets -} // namespace chatterino diff --git a/src/widgets/helper/notebooktab.cpp b/src/widgets/helper/notebooktab.cpp index 3c89639cc..fb48ffd6f 100644 --- a/src/widgets/helper/notebooktab.cpp +++ b/src/widgets/helper/notebooktab.cpp @@ -5,6 +5,7 @@ #include "debug/log.hpp" #include "singletons/settingsmanager.hpp" #include "singletons/thememanager.hpp" +#include "util/clamp.hpp" #include "util/helpers.hpp" #include "widgets/notebook.hpp" #include "widgets/settingsdialog.hpp" @@ -78,12 +79,12 @@ void NotebookTab::updateSize() FontStyle::UiTabs, float(qreal(this->getScale()) * this->devicePixelRatioF())); if (this->hasXButton()) { - width = int((metrics.width(this->getTitle()) + 32) * scale); + width = (metrics.width(this->getTitle()) + int(32 * scale)); } else { - width = int((metrics.width(this->getTitle()) + 16) * scale); + width = (metrics.width(this->getTitle()) + int(16 * scale)); } - width = std::max(this->height(), std::min(int(150 * scale), width)); + width = util::clamp(width, this->height(), int(150 * scale)); if (this->width() != width) { this->resize(width, int(NOTEBOOK_TAB_HEIGHT * scale)); diff --git a/src/widgets/helper/splitheader.cpp b/src/widgets/helper/splitheader.cpp index 7c178cf24..8c3897131 100644 --- a/src/widgets/helper/splitheader.cpp +++ b/src/widgets/helper/splitheader.cpp @@ -7,7 +7,7 @@ #include "singletons/thememanager.hpp" #include "util/layoutcreator.hpp" #include "util/urlfetch.hpp" -#include "widgets/helper/label.hpp" +#include "widgets/label.hpp" #include "widgets/split.hpp" #include "widgets/splitcontainer.hpp" #include "widgets/tooltipwidget.hpp" @@ -48,19 +48,11 @@ SplitHeader::SplitHeader(Split *_split) }); }); - layout->addStretch(1); - // channel name label - // auto title = layout.emplace