mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
default window buttons resize if the window is really small
This commit is contained in:
parent
e8a948cffc
commit
fa3c812697
|
@ -65,7 +65,7 @@ void BaseWindow::init()
|
||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
this->setLayout(layout);
|
this->setLayout(layout);
|
||||||
{
|
{
|
||||||
QHBoxLayout *buttonLayout = this->titlebarBox = new QHBoxLayout();
|
QHBoxLayout *buttonLayout = this->ui.titlebarBox = new QHBoxLayout();
|
||||||
buttonLayout->setMargin(0);
|
buttonLayout->setMargin(0);
|
||||||
layout->addLayout(buttonLayout);
|
layout->addLayout(buttonLayout);
|
||||||
|
|
||||||
|
@ -77,17 +77,14 @@ void BaseWindow::init()
|
||||||
title->setBaseSize(0, 0);
|
title->setBaseSize(0, 0);
|
||||||
title->setSizePolicy(policy);
|
title->setSizePolicy(policy);
|
||||||
buttonLayout->addWidget(title);
|
buttonLayout->addWidget(title);
|
||||||
this->titleLabel = title;
|
this->ui.titleLabel = title;
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
TitleBarButton *_minButton = new TitleBarButton;
|
TitleBarButton *_minButton = new TitleBarButton;
|
||||||
_minButton->setScaleIndependantSize(46, 30);
|
|
||||||
_minButton->setButtonStyle(TitleBarButton::Minimize);
|
_minButton->setButtonStyle(TitleBarButton::Minimize);
|
||||||
TitleBarButton *_maxButton = new TitleBarButton;
|
TitleBarButton *_maxButton = new TitleBarButton;
|
||||||
_maxButton->setScaleIndependantSize(46, 30);
|
|
||||||
_maxButton->setButtonStyle(TitleBarButton::Maximize);
|
_maxButton->setButtonStyle(TitleBarButton::Maximize);
|
||||||
TitleBarButton *_exitButton = new TitleBarButton;
|
TitleBarButton *_exitButton = new TitleBarButton;
|
||||||
_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] {
|
||||||
|
@ -101,13 +98,13 @@ void BaseWindow::init()
|
||||||
QObject::connect(_exitButton, &TitleBarButton::clicked, this,
|
QObject::connect(_exitButton, &TitleBarButton::clicked, this,
|
||||||
[this] { this->close(); });
|
[this] { this->close(); });
|
||||||
|
|
||||||
this->minButton = _minButton;
|
this->ui.minButton = _minButton;
|
||||||
this->maxButton = _maxButton;
|
this->ui.maxButton = _maxButton;
|
||||||
this->exitButton = _exitButton;
|
this->ui.exitButton = _exitButton;
|
||||||
|
|
||||||
this->buttons.push_back(_minButton);
|
this->ui.buttons.push_back(_minButton);
|
||||||
this->buttons.push_back(_maxButton);
|
this->ui.buttons.push_back(_maxButton);
|
||||||
this->buttons.push_back(_exitButton);
|
this->ui.buttons.push_back(_exitButton);
|
||||||
|
|
||||||
buttonLayout->addStretch(1);
|
buttonLayout->addStretch(1);
|
||||||
buttonLayout->addWidget(_minButton);
|
buttonLayout->addWidget(_minButton);
|
||||||
|
@ -115,8 +112,8 @@ void BaseWindow::init()
|
||||||
buttonLayout->addWidget(_exitButton);
|
buttonLayout->addWidget(_exitButton);
|
||||||
buttonLayout->setSpacing(0);
|
buttonLayout->setSpacing(0);
|
||||||
}
|
}
|
||||||
this->layoutBase = new BaseWidget(this);
|
this->ui.layoutBase = new BaseWidget(this);
|
||||||
layout->addWidget(this->layoutBase);
|
layout->addWidget(this->ui.layoutBase);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DPI
|
// DPI
|
||||||
|
@ -125,8 +122,6 @@ void BaseWindow::init()
|
||||||
if (dpi) {
|
if (dpi) {
|
||||||
this->scale = dpi.value() / 96.f;
|
this->scale = dpi.value() / 96.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->scaleChangedEvent(this->scale);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (singletons::SettingManager::getInstance().windowTopMost.getValue()) {
|
if (singletons::SettingManager::getInstance().windowTopMost.getValue()) {
|
||||||
|
@ -147,7 +142,7 @@ bool BaseWindow::getStayInScreenRect() const
|
||||||
QWidget *BaseWindow::getLayoutContainer()
|
QWidget *BaseWindow::getLayoutContainer()
|
||||||
{
|
{
|
||||||
if (this->hasCustomWindowFrame()) {
|
if (this->hasCustomWindowFrame()) {
|
||||||
return this->layoutBase;
|
return this->ui.layoutBase;
|
||||||
} else {
|
} else {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +167,7 @@ void BaseWindow::themeRefreshEvent()
|
||||||
palette.setColor(QPalette::Foreground, this->themeManager.window.text);
|
palette.setColor(QPalette::Foreground, this->themeManager.window.text);
|
||||||
this->setPalette(palette);
|
this->setPalette(palette);
|
||||||
|
|
||||||
for (RippleEffectButton *button : this->buttons) {
|
for (RippleEffectButton *button : this->ui.buttons) {
|
||||||
button->setMouseEffectColor(this->themeManager.window.text);
|
button->setMouseEffectColor(this->themeManager.window.text);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -189,8 +184,8 @@ void BaseWindow::addTitleBarButton(const TitleBarButton::Style &style,
|
||||||
TitleBarButton *button = new TitleBarButton;
|
TitleBarButton *button = new TitleBarButton;
|
||||||
button->setScaleIndependantSize(30, 30);
|
button->setScaleIndependantSize(30, 30);
|
||||||
|
|
||||||
this->buttons.push_back(button);
|
this->ui.buttons.push_back(button);
|
||||||
this->titlebarBox->insertWidget(2, button);
|
this->ui.titlebarBox->insertWidget(2, button);
|
||||||
button->setButtonStyle(style);
|
button->setButtonStyle(style);
|
||||||
|
|
||||||
QObject::connect(button, &TitleBarButton::clicked, this, [onClicked] { onClicked(); });
|
QObject::connect(button, &TitleBarButton::clicked, this, [onClicked] { onClicked(); });
|
||||||
|
@ -201,8 +196,8 @@ RippleEffectLabel *BaseWindow::addTitleBarLabel(std::function<void()> onClicked)
|
||||||
RippleEffectLabel *button = new RippleEffectLabel;
|
RippleEffectLabel *button = new RippleEffectLabel;
|
||||||
button->setScaleIndependantHeight(30);
|
button->setScaleIndependantHeight(30);
|
||||||
|
|
||||||
this->buttons.push_back(button);
|
this->ui.buttons.push_back(button);
|
||||||
this->titlebarBox->insertWidget(2, button);
|
this->ui.titlebarBox->insertWidget(2, button);
|
||||||
|
|
||||||
QObject::connect(button, &RippleEffectLabel::clicked, this, [onClicked] { onClicked(); });
|
QObject::connect(button, &RippleEffectLabel::clicked, this, [onClicked] { onClicked(); });
|
||||||
|
|
||||||
|
@ -215,9 +210,9 @@ void BaseWindow::changeEvent(QEvent *)
|
||||||
|
|
||||||
#ifdef USEWINSDK
|
#ifdef USEWINSDK
|
||||||
if (this->hasCustomWindowFrame()) {
|
if (this->hasCustomWindowFrame()) {
|
||||||
this->maxButton->setButtonStyle(this->windowState() & Qt::WindowMaximized
|
this->ui.maxButton->setButtonStyle(this->windowState() & Qt::WindowMaximized
|
||||||
? TitleBarButton::Unmaximize
|
? TitleBarButton::Unmaximize
|
||||||
: TitleBarButton::Maximize);
|
: TitleBarButton::Maximize);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -243,6 +238,8 @@ void BaseWindow::moveTo(QWidget *parent, QPoint point)
|
||||||
void BaseWindow::resizeEvent(QResizeEvent *)
|
void BaseWindow::resizeEvent(QResizeEvent *)
|
||||||
{
|
{
|
||||||
this->moveIntoDesktopRect(this);
|
this->moveIntoDesktopRect(this);
|
||||||
|
|
||||||
|
this->calcButtonsSizes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWindow::moveIntoDesktopRect(QWidget *parent)
|
void BaseWindow::moveIntoDesktopRect(QWidget *parent)
|
||||||
|
@ -375,13 +372,13 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
|
||||||
bool client = false;
|
bool client = false;
|
||||||
|
|
||||||
QPoint point(x - winrect.left, y - winrect.top);
|
QPoint point(x - winrect.left, y - winrect.top);
|
||||||
for (QWidget *widget : this->buttons) {
|
for (QWidget *widget : this->ui.buttons) {
|
||||||
if (widget->geometry().contains(point)) {
|
if (widget->geometry().contains(point)) {
|
||||||
client = true;
|
client = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->layoutBase->geometry().contains(point)) {
|
if (this->ui.layoutBase->geometry().contains(point)) {
|
||||||
client = true;
|
client = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +425,27 @@ void BaseWindow::paintEvent(QPaintEvent *event)
|
||||||
this->themeManager.window.background);
|
this->themeManager.window.background);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseWindow::scaleChangedEvent(float)
|
||||||
|
{
|
||||||
|
this->calcButtonsSizes();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void BaseWindow::calcButtonsSizes()
|
||||||
|
{
|
||||||
|
if (!this->shown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((this->width() / this->getScale()) < 300) {
|
||||||
|
this->ui.minButton->setScaleIndependantSize(30, 30);
|
||||||
|
this->ui.maxButton->setScaleIndependantSize(30, 30);
|
||||||
|
this->ui.exitButton->setScaleIndependantSize(30, 30);
|
||||||
|
} else {
|
||||||
|
this->ui.minButton->setScaleIndependantSize(46, 30);
|
||||||
|
this->ui.maxButton->setScaleIndependantSize(46, 30);
|
||||||
|
this->ui.exitButton->setScaleIndependantSize(46, 30);
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace widgets
|
} // namespace widgets
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -38,7 +38,8 @@ protected:
|
||||||
#ifdef USEWINSDK
|
#ifdef USEWINSDK
|
||||||
virtual void showEvent(QShowEvent *);
|
virtual void showEvent(QShowEvent *);
|
||||||
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
||||||
virtual void paintEvent(QPaintEvent *event) override;
|
virtual void paintEvent(QPaintEvent *) override;
|
||||||
|
virtual void scaleChangedEvent(float) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virtual void changeEvent(QEvent *) override;
|
virtual void changeEvent(QEvent *) override;
|
||||||
|
@ -50,18 +51,21 @@ protected:
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
void moveIntoDesktopRect(QWidget *parent);
|
void moveIntoDesktopRect(QWidget *parent);
|
||||||
|
void calcButtonsSizes();
|
||||||
|
|
||||||
bool enableCustomFrame;
|
bool enableCustomFrame;
|
||||||
bool stayInScreenRect = false;
|
bool stayInScreenRect = false;
|
||||||
bool shown = false;
|
bool shown = false;
|
||||||
|
|
||||||
QHBoxLayout *titlebarBox;
|
struct {
|
||||||
QWidget *titleLabel;
|
QHBoxLayout *titlebarBox;
|
||||||
TitleBarButton *minButton;
|
QWidget *titleLabel;
|
||||||
TitleBarButton *maxButton;
|
TitleBarButton *minButton = nullptr;
|
||||||
TitleBarButton *exitButton;
|
TitleBarButton *maxButton = nullptr;
|
||||||
QWidget *layoutBase;
|
TitleBarButton *exitButton = nullptr;
|
||||||
std::vector<RippleEffectButton *> buttons;
|
QWidget *layoutBase;
|
||||||
|
std::vector<RippleEffectButton *> buttons;
|
||||||
|
} ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace widgets
|
} // namespace widgets
|
||||||
|
|
Loading…
Reference in a new issue