fixed titlebar scaling

This commit is contained in:
fourtf 2018-01-25 21:11:14 +01:00
parent ac6cbe9daf
commit 56a7b05103
7 changed files with 64 additions and 19 deletions

View file

@ -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);
}

View file

@ -23,9 +23,16 @@ public:
singletons::ThemeManager &themeManager;
float getScale() const;
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:
virtual void childEvent(QChildEvent *) override;
@ -37,6 +44,7 @@ protected:
private:
void init();
float scale = 1.f;
QSize scaleIndependantSize;
std::vector<BaseWidget *> widgets;

View file

@ -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<void()> onClicked)
{
TitleBarButton *button = new TitleBarButton;
button->setScaleIndependantSize(30, 30);
this->buttons.push_back(button);
this->titlebarBox->insertWidget(2, button);

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -16,7 +16,6 @@ public:
protected:
virtual void paintEvent(QPaintEvent *) override;
virtual void resizeEvent(QResizeEvent *) override;
private:
Style style;