From 56a7b051033ce4d5152beb94fe1534cf7644428a Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 25 Jan 2018 21:11:14 +0100 Subject: [PATCH] fixed titlebar scaling --- src/widgets/basewidget.cpp | 45 +++++++++++++++++++++++++++ src/widgets/basewidget.hpp | 10 +++++- src/widgets/basewindow.cpp | 7 +++-- src/widgets/helper/splitheader.cpp | 5 +-- src/widgets/helper/splitheader.hpp | 6 ++-- src/widgets/helper/titlebarbutton.cpp | 9 ------ src/widgets/helper/titlebarbutton.hpp | 1 - 7 files changed, 64 insertions(+), 19 deletions(-) diff --git a/src/widgets/basewidget.cpp b/src/widgets/basewidget.cpp index c15ef9cbf..b915abbcb 100644 --- a/src/widgets/basewidget.cpp +++ b/src/widgets/basewidget.cpp @@ -38,6 +38,48 @@ float BaseWidget::getScale() const } } +QSize BaseWidget::getScaleIndependantSize() const +{ + return this->scaleIndependantSize; +} + +int BaseWidget::getScaleIndependantWidth() const +{ + return this->scaleIndependantSize.width(); +} + +int BaseWidget::getScaleIndependantHeight() const +{ + return this->scaleIndependantSize.height(); +} + +void BaseWidget::setScaleIndependantSize(int width, int height) +{ + this->setScaleIndependantSize(QSize(width, height)); +} + +void BaseWidget::setScaleIndependantSize(QSize size) +{ + this->scaleIndependantSize = size; + + if (size.width() > 0) { + this->setFixedWidth((int)(size.width() * this->getScale())); + } + if (size.height() > 0) { + this->setFixedHeight((int)(size.height() * this->getScale())); + } +} + +void BaseWidget::setScaleIndependantWidth(int value) +{ + this->setScaleIndependantSize(QSize(value, this->scaleIndependantSize.height())); +} + +void BaseWidget::setScaleIndependantHeight(int value) +{ + this->setScaleIndependantSize(QSize(this->scaleIndependantSize.height(), value)); +} + void BaseWidget::init() { auto connection = this->themeManager.updated.connect([this]() { @@ -68,6 +110,7 @@ void BaseWidget::childEvent(QChildEvent *event) } } } + void BaseWidget::setScale(float value) { // update scale value @@ -76,6 +119,8 @@ void BaseWidget::setScale(float value) this->scaleChangedEvent(value); this->scaleChanged.invoke(value); + this->setScaleIndependantSize(this->getScaleIndependantSize()); + // set scale for all children BaseWidget::setScaleRecursive(value, this); } diff --git a/src/widgets/basewidget.hpp b/src/widgets/basewidget.hpp index 86479ab15..376d1f210 100644 --- a/src/widgets/basewidget.hpp +++ b/src/widgets/basewidget.hpp @@ -23,9 +23,16 @@ public: singletons::ThemeManager &themeManager; float getScale() const; - pajlada::Signals::Signal scaleChanged; + QSize getScaleIndependantSize() const; + int getScaleIndependantWidth() const; + int getScaleIndependantHeight() const; + void setScaleIndependantSize(int width, int height); + void setScaleIndependantSize(QSize); + void setScaleIndependantWidth(int value); + void setScaleIndependantHeight(int value); + protected: virtual void childEvent(QChildEvent *) override; @@ -37,6 +44,7 @@ protected: private: void init(); float scale = 1.f; + QSize scaleIndependantSize; std::vector widgets; diff --git a/src/widgets/basewindow.cpp b/src/widgets/basewindow.cpp index 3bf96fd6c..c3853b41c 100644 --- a/src/widgets/basewindow.cpp +++ b/src/widgets/basewindow.cpp @@ -73,13 +73,13 @@ void BaseWindow::init() // buttons TitleBarButton *_minButton = new TitleBarButton; - _minButton->setFixedSize(46, 30); + _minButton->setScaleIndependantSize(46, 30); _minButton->setButtonStyle(TitleBarButton::Minimize); TitleBarButton *_maxButton = new TitleBarButton; - _maxButton->setFixedSize(46, 30); + _maxButton->setScaleIndependantSize(46, 30); _maxButton->setButtonStyle(TitleBarButton::Maximize); TitleBarButton *_exitButton = new TitleBarButton; - _exitButton->setFixedSize(46, 30); + _exitButton->setScaleIndependantSize(46, 30); _exitButton->setButtonStyle(TitleBarButton::Close); QObject::connect(_minButton, &TitleBarButton::clicked, this, [this] { @@ -171,6 +171,7 @@ void BaseWindow::addTitleBarButton(const TitleBarButton::Style &style, std::function onClicked) { TitleBarButton *button = new TitleBarButton; + button->setScaleIndependantSize(30, 30); this->buttons.push_back(button); this->titlebarBox->insertWidget(2, button); diff --git a/src/widgets/helper/splitheader.cpp b/src/widgets/helper/splitheader.cpp index b9f09925d..1750331f0 100644 --- a/src/widgets/helper/splitheader.cpp +++ b/src/widgets/helper/splitheader.cpp @@ -67,6 +67,7 @@ SplitHeader::SplitHeader(Split *_split) // ---- misc this->layout()->setMargin(0); this->themeRefreshEvent(); + this->scaleChangedEvent(this->getScale()); this->updateChannelText(); @@ -133,9 +134,9 @@ void SplitHeader::initializeChannelSignals() } } -void SplitHeader::resizeEvent(QResizeEvent *event) +void SplitHeader::scaleChangedEvent(float scale) { - int w = 28 * getScale(); + int w = 28 * scale; this->setFixedHeight(w); this->dropdownButton->setFixedWidth(w); diff --git a/src/widgets/helper/splitheader.hpp b/src/widgets/helper/splitheader.hpp index 568b75158..69c051d4e 100644 --- a/src/widgets/helper/splitheader.hpp +++ b/src/widgets/helper/splitheader.hpp @@ -34,12 +34,14 @@ public: void updateModerationModeIcon(); protected: + virtual void scaleChangedEvent(float) override; + virtual void themeRefreshEvent() override; + virtual void paintEvent(QPaintEvent *) override; virtual void mousePressEvent(QMouseEvent *event) override; virtual void mouseMoveEvent(QMouseEvent *event) override; virtual void leaveEvent(QEvent *event) override; virtual void mouseDoubleClickEvent(QMouseEvent *event) override; - virtual void resizeEvent(QResizeEvent *event) override; private: Split *const split; @@ -57,8 +59,6 @@ private: void rightButtonClicked(); - virtual void themeRefreshEvent() override; - void initializeChannelSignals(); QString tooltip; diff --git a/src/widgets/helper/titlebarbutton.cpp b/src/widgets/helper/titlebarbutton.cpp index df5326847..1d3f45aa4 100644 --- a/src/widgets/helper/titlebarbutton.cpp +++ b/src/widgets/helper/titlebarbutton.cpp @@ -18,15 +18,6 @@ void TitleBarButton::setButtonStyle(Style _style) this->update(); } -void TitleBarButton::resizeEvent(QResizeEvent *) -{ - if (this->style & (Maximize | Minimize | Unmaximize | Close)) { - this->setFixedWidth(this->height() * 46 / 30); - } else { - this->setFixedWidth(this->height()); - } -} - void TitleBarButton::paintEvent(QPaintEvent *) { QPainter painter(this); diff --git a/src/widgets/helper/titlebarbutton.hpp b/src/widgets/helper/titlebarbutton.hpp index 83ce40713..cdc13026f 100644 --- a/src/widgets/helper/titlebarbutton.hpp +++ b/src/widgets/helper/titlebarbutton.hpp @@ -16,7 +16,6 @@ public: protected: virtual void paintEvent(QPaintEvent *) override; - virtual void resizeEvent(QResizeEvent *) override; private: Style style;