Fix Ui::RpWidget geometry constraints.

This commit is contained in:
John Preston 2021-07-29 18:12:44 +03:00
parent d452ae8ba6
commit 868f2671fa
4 changed files with 27 additions and 17 deletions

View file

@ -146,6 +146,7 @@ DefaultWindowHelper::DefaultWindowHelper(not_null<RpWidget*> window)
}
void DefaultWindowHelper::init() {
_title->show(); // Be consistent with _nativeFrame == false.
window()->setWindowFlag(Qt::FramelessWindowHint);
if (WindowExtentsSupported()) {
@ -327,24 +328,18 @@ void DefaultWindowHelper::setNativeFrame(bool enabled) {
}
void DefaultWindowHelper::setMinimumSize(QSize size) {
const auto sizeWithMargins = size
.grownBy({ 0, _title->isVisible() ? _title->height() : 0, 0, 0 })
.grownBy(resizeArea());
const auto sizeWithMargins = size.grownBy(bodyPadding());
window()->setMinimumSize(sizeWithMargins);
}
void DefaultWindowHelper::setFixedSize(QSize size) {
const auto sizeWithMargins = size
.grownBy({ 0, _title->isVisible() ? _title->height() : 0, 0, 0 })
.grownBy(resizeArea());
const auto sizeWithMargins = size.grownBy(bodyPadding());
window()->setFixedSize(sizeWithMargins);
_title->setResizeEnabled(false);
}
void DefaultWindowHelper::setGeometry(QRect rect) {
window()->setGeometry(rect
.marginsAdded({ 0, _title->isVisible() ? _title->height() : 0, 0, 0 })
.marginsAdded(resizeArea()));
window()->setGeometry(rect.marginsAdded(bodyPadding()));
}
void DefaultWindowHelper::paintBorders(QPainter &p) {
@ -404,6 +399,14 @@ void DefaultWindowHelper::updateWindowExtents() {
}
}
int DefaultWindowHelper::titleHeight() const {
return _title->isHidden() ? 0 : _title->height();
}
QMargins DefaultWindowHelper::bodyPadding() const {
return resizeArea() + QMargins{ 0, titleHeight(), 0, 0 };
}
void DefaultWindowHelper::updateCursor(Qt::Edges edges) {
if (((edges & Qt::LeftEdge) && (edges & Qt::TopEdge))
|| ((edges & Qt::RightEdge) && (edges & Qt::BottomEdge))) {

View file

@ -84,6 +84,8 @@ private:
void paintBorders(QPainter &p);
void updateWindowExtents();
void updateCursor(Qt::Edges edges);
[[nodiscard]] int titleHeight() const;
[[nodiscard]] QMargins bodyPadding() const;
const not_null<DefaultTitleWidget*> _title;
const not_null<RpWidget*> _body;

View file

@ -151,7 +151,6 @@ WindowHelper::WindowHelper(not_null<RpWidget*> window)
, _shadow(std::in_place, window, st::windowShadowFg->c) {
Expects(_handle != nullptr);
GetNativeFilter()->registerWindow(_handle, this);
init();
}
@ -186,13 +185,11 @@ void WindowHelper::setNativeFrame(bool enabled) {
}
void WindowHelper::setMinimumSize(QSize size) {
const auto titleHeight = _title->isVisible() ? _title->height() : 0;
window()->setMinimumSize(size.width(), titleHeight + size.height());
window()->setMinimumSize(size.width(), titleHeight() + size.height());
}
void WindowHelper::setFixedSize(QSize size) {
const auto titleHeight = _title->isVisible() ? _title->height() : 0;
window()->setFixedSize(size.width(), titleHeight + size.height());
window()->setFixedSize(size.width(), titleHeight() + size.height());
_title->setResizeEnabled(false);
if (_shadow) {
_shadow->setResizeEnabled(false);
@ -200,8 +197,7 @@ void WindowHelper::setFixedSize(QSize size) {
}
void WindowHelper::setGeometry(QRect rect) {
const auto titleHeight = _title->isVisible() ? _title->height() : 0;
window()->setGeometry(rect.marginsAdded({ 0, titleHeight, 0, 0 }));
window()->setGeometry(rect.marginsAdded({ 0, titleHeight(), 0, 0 }));
}
void WindowHelper::showFullScreen() {
@ -221,6 +217,9 @@ void WindowHelper::showNormal() {
}
void WindowHelper::init() {
_title->show(); // Be consistent with _nativeFrame == false.
GetNativeFilter()->registerWindow(_handle, this);
style::PaletteChanged(
) | rpl::start_with_next([=] {
if (_shadow) {
@ -429,7 +428,8 @@ bool WindowHelper::handleNativeEvent(
p.y - r.top + _marginsDelta.top());
if (!window()->rect().contains(mapped)) {
*result = HTTRANSPARENT;
} else if (!_title->isVisible() || !_title->geometry().contains(mapped)) {
} else if (_title->isHidden()
|| !_title->geometry().contains(mapped)) {
*result = HTCLIENT;
} else switch (_title->hitTest(_title->pos() + mapped)) {
case HitTestResult::Client:
@ -502,6 +502,10 @@ bool WindowHelper::fixedSize() const {
return window()->minimumSize() == window()->maximumSize();
}
int WindowHelper::titleHeight() const {
return _title->isHidden() ? 0 : _title->height();
}
void WindowHelper::updateMargins() {
if (_updatingMargins) return;

View file

@ -47,6 +47,7 @@ private:
LRESULT *result);
[[nodiscard]] bool fixedSize() const;
[[nodiscard]] int titleHeight() const;
static not_null<NativeFilter*> GetNativeFilter();
const HWND _handle = nullptr;