Check if resize area is null

This commit is contained in:
Ilya Fedin 2021-02-17 22:04:17 +04:00 committed by John Preston
parent 0b74c396cb
commit 492121950d

View file

@ -149,10 +149,11 @@ void DefaultWindowHelper::init() {
window()->widthValue( window()->widthValue(
) | rpl::start_with_next([=](int width) { ) | rpl::start_with_next([=](int width) {
const auto area = resizeArea();
_title->setGeometry( _title->setGeometry(
resizeArea().left(), area.left(),
resizeArea().top(), area.top(),
width - resizeArea().left() - resizeArea().right(), width - area.left() - area.right(),
_title->st()->height); _title->st()->height);
}, _title->lifetime()); }, _title->lifetime());
@ -160,20 +161,24 @@ void DefaultWindowHelper::init() {
window()->sizeValue(), window()->sizeValue(),
_title->heightValue() _title->heightValue()
) | rpl::start_with_next([=](QSize size, int titleHeight) { ) | rpl::start_with_next([=](QSize size, int titleHeight) {
const auto area = resizeArea();
const auto sizeWithoutMargins = size const auto sizeWithoutMargins = size
.shrunkBy({ 0, titleHeight, 0, 0 }) .shrunkBy({ 0, titleHeight, 0, 0 })
.shrunkBy(resizeArea()); .shrunkBy(area);
const auto topLeft = QPoint( const auto topLeft = QPoint(
resizeArea().left(), area.left(),
resizeArea().top() + titleHeight); area.top() + titleHeight);
_body->setGeometry(QRect(topLeft, sizeWithoutMargins)); _body->setGeometry(QRect(topLeft, sizeWithoutMargins));
}, _body->lifetime()); }, _body->lifetime());
window()->paintRequest( window()->paintRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
if (resizeArea().isNull()) { const auto area = resizeArea();
if (area.isNull()) {
return; return;
} }
@ -182,7 +187,7 @@ void DefaultWindowHelper::init() {
if (hasShadow()) { if (hasShadow()) {
Ui::Shadow::paint( Ui::Shadow::paint(
p, p,
QRect(QPoint(), window()->size()).marginsRemoved(resizeArea()), QRect(QPoint(), window()->size()).marginsRemoved(area),
window()->width(), window()->width(),
Shadow()); Shadow());
} else { } else {
@ -234,29 +239,33 @@ QMargins DefaultWindowHelper::resizeArea() const {
} }
Qt::Edges DefaultWindowHelper::edgesFromPos(const QPoint &pos) const { Qt::Edges DefaultWindowHelper::edgesFromPos(const QPoint &pos) const {
if (pos.x() <= resizeArea().left()) { const auto area = resizeArea();
if (pos.y() <= resizeArea().top()) {
if (area.isNull()) {
return Qt::Edges();
} else if (pos.x() <= area.left()) {
if (pos.y() <= area.top()) {
return Qt::LeftEdge | Qt::TopEdge; return Qt::LeftEdge | Qt::TopEdge;
} else if (pos.y() >= (window()->height() - resizeArea().bottom())) { } else if (pos.y() >= (window()->height() - area.bottom())) {
return Qt::LeftEdge | Qt::BottomEdge; return Qt::LeftEdge | Qt::BottomEdge;
} }
return Qt::LeftEdge; return Qt::LeftEdge;
} else if (pos.x() >= (window()->width() - resizeArea().right())) { } else if (pos.x() >= (window()->width() - area.right())) {
if (pos.y() <= resizeArea().top()) { if (pos.y() <= area.top()) {
return Qt::RightEdge | Qt::TopEdge; return Qt::RightEdge | Qt::TopEdge;
} else if (pos.y() >= (window()->height() - resizeArea().bottom())) { } else if (pos.y() >= (window()->height() - area.bottom())) {
return Qt::RightEdge | Qt::BottomEdge; return Qt::RightEdge | Qt::BottomEdge;
} }
return Qt::RightEdge; return Qt::RightEdge;
} else if (pos.y() <= resizeArea().top()) { } else if (pos.y() <= area.top()) {
return Qt::TopEdge; return Qt::TopEdge;
} else if (pos.y() >= (window()->height() - resizeArea().bottom())) { } else if (pos.y() >= (window()->height() - area.bottom())) {
return Qt::BottomEdge; return Qt::BottomEdge;
} else {
return Qt::Edges();
} }
return Qt::Edges();
} }
bool DefaultWindowHelper::eventFilter(QObject *obj, QEvent *e) { bool DefaultWindowHelper::eventFilter(QObject *obj, QEvent *e) {
@ -282,11 +291,12 @@ void DefaultWindowHelper::setTitle(const QString &title) {
} }
void DefaultWindowHelper::setTitleStyle(const style::WindowTitle &st) { void DefaultWindowHelper::setTitleStyle(const style::WindowTitle &st) {
const auto area = resizeArea();
_title->setStyle(st); _title->setStyle(st);
_title->setGeometry( _title->setGeometry(
resizeArea().left(), area.left(),
resizeArea().top(), area.top(),
window()->width() - resizeArea().left() - resizeArea().right(), window()->width() - area.left() - area.right(),
_title->st()->height); _title->st()->height);
} }
@ -324,32 +334,34 @@ void DefaultWindowHelper::paintBorders(QPainter &p) {
? titleBackground ? titleBackground
: defaultTitleBackground; : defaultTitleBackground;
const auto area = resizeArea();
p.fillRect( p.fillRect(
0, 0,
resizeArea().top(), area.top(),
resizeArea().left(), area.left(),
window()->height() - resizeArea().top() - resizeArea().bottom(), window()->height() - area.top() - area.bottom(),
borderColor); borderColor);
p.fillRect( p.fillRect(
window()->width() - resizeArea().right(), window()->width() - area.right(),
resizeArea().top(), area.top(),
resizeArea().right(), area.right(),
window()->height() - resizeArea().top() - resizeArea().bottom(), window()->height() - area.top() - area.bottom(),
borderColor); borderColor);
p.fillRect( p.fillRect(
0, 0,
0, 0,
window()->width(), window()->width(),
resizeArea().top(), area.top(),
borderColor); borderColor);
p.fillRect( p.fillRect(
0, 0,
window()->height() - resizeArea().bottom(), window()->height() - area.bottom(),
window()->width(), window()->width(),
resizeArea().bottom(), area.bottom(),
borderColor); borderColor);
} }