enlarge the resize corner area

This commit is contained in:
Altair Wei 2021-09-20 16:45:30 +08:00
parent 96f49ded2f
commit 0964483b20
1 changed files with 21 additions and 8 deletions

View File

@ -122,6 +122,15 @@ bool FramelessHelper::isInTitlebarArea(const QPoint& pos)
return titleBarRegion().contains(pos); return titleBarRegion().contains(pos);
} }
const int kCornerFactor = 2;
/*!
\brief Determine window frame section by coordinates.
Returns the window frame section at position \a pos, or \c Qt::NoSection
if there is no window frame section at this position.
*/
Qt::WindowFrameSection FramelessHelper::mapPosToFrameSection(const QPoint& pos) Qt::WindowFrameSection FramelessHelper::mapPosToFrameSection(const QPoint& pos)
{ {
int border = 0; int border = 0;
@ -141,30 +150,34 @@ Qt::WindowFrameSection FramelessHelper::mapPosToFrameSection(const QPoint& pos)
if (windowRect.contains(pos)) if (windowRect.contains(pos))
{ {
QPoint mappedPos = pos - windowRect.topLeft(); QPoint mappedPos = pos - windowRect.topLeft();
if (QRect(0, 0, border, border).contains(mappedPos))
// The corner is kCornerFactor times the size of the border
if (QRect(0, 0, border * kCornerFactor, border * kCornerFactor).contains(mappedPos))
return Qt::TopLeftSection; return Qt::TopLeftSection;
if (QRect(border, 0, windowRect.width() - border * 2, border).contains(mappedPos)) if (QRect(border * kCornerFactor, 0, windowRect.width() - border * 2 * kCornerFactor, border).contains(mappedPos))
return Qt::TopSection; return Qt::TopSection;
if (QRect(windowRect.width() - border, 0, border, border).contains(mappedPos)) if (QRect(windowRect.width() - border * kCornerFactor, 0, border * kCornerFactor, border * kCornerFactor).contains(mappedPos))
return Qt::TopRightSection; return Qt::TopRightSection;
if (QRect(windowRect.width() - border, border, border, windowRect.height() - border * 2).contains(mappedPos)) if (QRect(windowRect.width() - border, border * kCornerFactor, border, windowRect.height() - border * 2 * kCornerFactor).contains(mappedPos))
return Qt::RightSection; return Qt::RightSection;
if (QRect(windowRect.width() - border, windowRect.height() - border, border, border).contains(mappedPos)) if (QRect(windowRect.width() - border * kCornerFactor, windowRect.height() - border * kCornerFactor, border * kCornerFactor, border * kCornerFactor).contains(mappedPos))
return Qt::BottomRightSection; return Qt::BottomRightSection;
if (QRect(border, windowRect.height() - border, windowRect.width() - border * 2, border).contains(mappedPos)) if (QRect(border * kCornerFactor, windowRect.height() - border, windowRect.width() - border * 2 * kCornerFactor, border).contains(mappedPos))
return Qt::BottomSection; return Qt::BottomSection;
if (QRect(0, windowRect.height() - border, border, border).contains(mappedPos)) if (QRect(0, windowRect.height() - border * kCornerFactor, border * kCornerFactor, border * kCornerFactor).contains(mappedPos))
return Qt::BottomLeftSection; return Qt::BottomLeftSection;
if (QRect(0, border, border, windowRect.height() - border * 2).contains(mappedPos)) if (QRect(0, border * kCornerFactor, border, windowRect.height() - border * 2 * kCornerFactor).contains(mappedPos))
return Qt::LeftSection; return Qt::LeftSection;
// Determining window frame secion is the highest priority,
// so the determination of the title bar area can be simpler.
if (isInTitlebarArea(pos)) if (isInTitlebarArea(pos))
return Qt::TitleBarArea; return Qt::TitleBarArea;
} }