mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
fixed titlebar scaling
This commit is contained in:
parent
ac6cbe9daf
commit
56a7b05103
|
@ -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()
|
void BaseWidget::init()
|
||||||
{
|
{
|
||||||
auto connection = this->themeManager.updated.connect([this]() {
|
auto connection = this->themeManager.updated.connect([this]() {
|
||||||
|
@ -68,6 +110,7 @@ void BaseWidget::childEvent(QChildEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::setScale(float value)
|
void BaseWidget::setScale(float value)
|
||||||
{
|
{
|
||||||
// update scale value
|
// update scale value
|
||||||
|
@ -76,6 +119,8 @@ void BaseWidget::setScale(float value)
|
||||||
this->scaleChangedEvent(value);
|
this->scaleChangedEvent(value);
|
||||||
this->scaleChanged.invoke(value);
|
this->scaleChanged.invoke(value);
|
||||||
|
|
||||||
|
this->setScaleIndependantSize(this->getScaleIndependantSize());
|
||||||
|
|
||||||
// set scale for all children
|
// set scale for all children
|
||||||
BaseWidget::setScaleRecursive(value, this);
|
BaseWidget::setScaleRecursive(value, this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,16 @@ public:
|
||||||
singletons::ThemeManager &themeManager;
|
singletons::ThemeManager &themeManager;
|
||||||
|
|
||||||
float getScale() const;
|
float getScale() const;
|
||||||
|
|
||||||
pajlada::Signals::Signal<float> scaleChanged;
|
pajlada::Signals::Signal<float> 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:
|
protected:
|
||||||
virtual void childEvent(QChildEvent *) override;
|
virtual void childEvent(QChildEvent *) override;
|
||||||
|
|
||||||
|
@ -37,6 +44,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
float scale = 1.f;
|
float scale = 1.f;
|
||||||
|
QSize scaleIndependantSize;
|
||||||
|
|
||||||
std::vector<BaseWidget *> widgets;
|
std::vector<BaseWidget *> widgets;
|
||||||
|
|
||||||
|
|
|
@ -73,13 +73,13 @@ void BaseWindow::init()
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
TitleBarButton *_minButton = new TitleBarButton;
|
TitleBarButton *_minButton = new TitleBarButton;
|
||||||
_minButton->setFixedSize(46, 30);
|
_minButton->setScaleIndependantSize(46, 30);
|
||||||
_minButton->setButtonStyle(TitleBarButton::Minimize);
|
_minButton->setButtonStyle(TitleBarButton::Minimize);
|
||||||
TitleBarButton *_maxButton = new TitleBarButton;
|
TitleBarButton *_maxButton = new TitleBarButton;
|
||||||
_maxButton->setFixedSize(46, 30);
|
_maxButton->setScaleIndependantSize(46, 30);
|
||||||
_maxButton->setButtonStyle(TitleBarButton::Maximize);
|
_maxButton->setButtonStyle(TitleBarButton::Maximize);
|
||||||
TitleBarButton *_exitButton = new TitleBarButton;
|
TitleBarButton *_exitButton = new TitleBarButton;
|
||||||
_exitButton->setFixedSize(46, 30);
|
_exitButton->setScaleIndependantSize(46, 30);
|
||||||
_exitButton->setButtonStyle(TitleBarButton::Close);
|
_exitButton->setButtonStyle(TitleBarButton::Close);
|
||||||
|
|
||||||
QObject::connect(_minButton, &TitleBarButton::clicked, this, [this] {
|
QObject::connect(_minButton, &TitleBarButton::clicked, this, [this] {
|
||||||
|
@ -171,6 +171,7 @@ void BaseWindow::addTitleBarButton(const TitleBarButton::Style &style,
|
||||||
std::function<void()> onClicked)
|
std::function<void()> onClicked)
|
||||||
{
|
{
|
||||||
TitleBarButton *button = new TitleBarButton;
|
TitleBarButton *button = new TitleBarButton;
|
||||||
|
button->setScaleIndependantSize(30, 30);
|
||||||
|
|
||||||
this->buttons.push_back(button);
|
this->buttons.push_back(button);
|
||||||
this->titlebarBox->insertWidget(2, button);
|
this->titlebarBox->insertWidget(2, button);
|
||||||
|
|
|
@ -67,6 +67,7 @@ SplitHeader::SplitHeader(Split *_split)
|
||||||
// ---- misc
|
// ---- misc
|
||||||
this->layout()->setMargin(0);
|
this->layout()->setMargin(0);
|
||||||
this->themeRefreshEvent();
|
this->themeRefreshEvent();
|
||||||
|
this->scaleChangedEvent(this->getScale());
|
||||||
|
|
||||||
this->updateChannelText();
|
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->setFixedHeight(w);
|
||||||
this->dropdownButton->setFixedWidth(w);
|
this->dropdownButton->setFixedWidth(w);
|
||||||
|
|
|
@ -34,12 +34,14 @@ public:
|
||||||
void updateModerationModeIcon();
|
void updateModerationModeIcon();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void scaleChangedEvent(float) override;
|
||||||
|
virtual void themeRefreshEvent() override;
|
||||||
|
|
||||||
virtual void paintEvent(QPaintEvent *) override;
|
virtual void paintEvent(QPaintEvent *) override;
|
||||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||||
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
virtual void leaveEvent(QEvent *event) override;
|
virtual void leaveEvent(QEvent *event) override;
|
||||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||||
virtual void resizeEvent(QResizeEvent *event) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Split *const split;
|
Split *const split;
|
||||||
|
@ -57,8 +59,6 @@ private:
|
||||||
|
|
||||||
void rightButtonClicked();
|
void rightButtonClicked();
|
||||||
|
|
||||||
virtual void themeRefreshEvent() override;
|
|
||||||
|
|
||||||
void initializeChannelSignals();
|
void initializeChannelSignals();
|
||||||
|
|
||||||
QString tooltip;
|
QString tooltip;
|
||||||
|
|
|
@ -18,15 +18,6 @@ void TitleBarButton::setButtonStyle(Style _style)
|
||||||
this->update();
|
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 *)
|
void TitleBarButton::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
|
@ -16,7 +16,6 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void paintEvent(QPaintEvent *) override;
|
virtual void paintEvent(QPaintEvent *) override;
|
||||||
virtual void resizeEvent(QResizeEvent *) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Style style;
|
Style style;
|
||||||
|
|
Loading…
Reference in a new issue