fix: disable resizing and moving in maximized or fullscreen window

This commit is contained in:
yyc12345 2023-06-24 16:43:31 +08:00
parent 6fc9534184
commit 1e3d68df1c
2 changed files with 19 additions and 17 deletions

View File

@ -68,24 +68,26 @@ bool FramelessWindow::eventFilter(QObject* o, QEvent* e)
bool FramelessWindow::mouseHover(QHoverEvent* event, QWidget* wg) bool FramelessWindow::mouseHover(QHoverEvent* event, QWidget* wg)
{ {
QWindow* win = window()->windowHandle(); if (!isMaximized() && !isFullScreen()) {
Qt::Edges edges = this->getEdgesByPos(wg->mapToGlobal(event->oldPos()), win->frameGeometry()); QWindow* win = window()->windowHandle();
Qt::Edges edges = this->getEdgesByPos(wg->mapToGlobal(event->oldPos()), win->frameGeometry());
// backup & restore cursor shape // backup & restore cursor shape
if (edges && !m_oldEdges) if (edges && !m_oldEdges)
// entering the edge. backup cursor shape // entering the edge. backup cursor shape
m_oldCursorShape = win->cursor().shape(); m_oldCursorShape = win->cursor().shape();
if (!edges && m_oldEdges) if (!edges && m_oldEdges)
// leaving the edge. restore cursor shape // leaving the edge. restore cursor shape
win->setCursor(m_oldCursorShape); win->setCursor(m_oldCursorShape);
// save the latest edges status // save the latest edges status
m_oldEdges = edges; m_oldEdges = edges;
// show resize cursor shape if cursor is within border // show resize cursor shape if cursor is within border
if (edges) { if (edges) {
win->setCursor(this->getCursorByEdge(edges, Qt::ArrowCursor)); win->setCursor(this->getCursorByEdge(edges, Qt::ArrowCursor));
return true; return true;
}
} }
return false; return false;
@ -93,7 +95,7 @@ bool FramelessWindow::mouseHover(QHoverEvent* event, QWidget* wg)
bool FramelessWindow::mousePress(QMouseEvent* event) bool FramelessWindow::mousePress(QMouseEvent* event)
{ {
if (event->buttons() & Qt::LeftButton && !isMaximized()) { if (event->buttons() & Qt::LeftButton && !isMaximized() && !isFullScreen()) {
QWindow* win = window()->windowHandle(); QWindow* win = window()->windowHandle();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Qt::Edges edges = this->getEdgesByPos(event->globalPosition().toPoint(), win->frameGeometry()); Qt::Edges edges = this->getEdgesByPos(event->globalPosition().toPoint(), win->frameGeometry());

View File

@ -328,7 +328,7 @@ void MainWindow::mousePressEvent(QMouseEvent *event)
void MainWindow::mouseMoveEvent(QMouseEvent *event) void MainWindow::mouseMoveEvent(QMouseEvent *event)
{ {
if (event->buttons() & Qt::LeftButton && m_clickedOnWindow && !isMaximized()) { if (event->buttons() & Qt::LeftButton && m_clickedOnWindow && !isMaximized() && !isFullScreen()) {
if (!window()->windowHandle()->startSystemMove()) { if (!window()->windowHandle()->startSystemMove()) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
move(event->globalPosition().toPoint() - m_oldMousePos); move(event->globalPosition().toPoint() - m_oldMousePos);