Support title-aware Window::setGeometry.

This commit is contained in:
John Preston 2019-09-30 11:58:45 +03:00
parent 84d68e48c0
commit 11aa7bcd4e
7 changed files with 28 additions and 5 deletions

View file

@ -21,6 +21,7 @@ public:
not_null<RpWidget*> body() override;
void setTitle(const QString &title) override;
void setSizeMin(QSize size) override;
void setGeometry(QRect rect) override;
private:
class Private;

View file

@ -205,7 +205,14 @@ void WindowHelper::toggleCustomTitle(bool visible) {
}
void WindowHelper::setSizeMin(QSize size) {
_window->setMinimumSize(size.width(), _title->height() + size.height());
_window->setMinimumSize(
size.width(),
(_title ? _title->height() : 0) + size.height());
}
void WindowHelper::setGeometry(QRect rect) {
_window->setGeometry(
rect.marginsAdded({ 0, (_title ? _title->height() : 0), 0, 0 }));
}
void WindowHelper::init() {

View file

@ -17,6 +17,7 @@ public:
[[nodiscard]] virtual not_null<RpWidget*> body() = 0;
virtual void setTitle(const QString &title) = 0;
virtual void setSizeMin(QSize size) = 0;
virtual void setGeometry(QRect rect) = 0;
virtual ~BasicWindowHelper() = default;
};

View file

@ -103,6 +103,10 @@ void WindowHelper::setSizeMin(QSize size) {
_window->setMinimumSize(size.width(), _title->height() + size.height());
}
void WindowHelper::setGeometry(QRect rect) {
_window->setGeometry(rect.marginsAdded({ 0, _title->height(), 0, 0 }));
}
void WindowHelper::init() {
style::PaletteChanged(
) | rpl::start_with_next([=] {

View file

@ -24,6 +24,7 @@ public:
not_null<RpWidget*> body() override;
void setTitle(const QString &title) override;
void setSizeMin(QSize size) override;
void setGeometry(QRect rect) override;
private:
class NativeFilter;

View file

@ -42,4 +42,12 @@ void Window::setSizeMin(QSize size) {
}
}
void Window::setGeometry(QRect rect) {
if (_helper) {
_helper->setGeometry(rect);
} else {
RpWidget::setGeometry(rect);
}
}
} // namespace Ui

View file

@ -23,6 +23,7 @@ public:
void setTitle(const QString &title);
void setSizeMin(QSize size);
void setGeometry(QRect rect);
private:
const std::unique_ptr<Platform::BasicWindowHelper> _helper;