chore: clean up mouse drag to resize/move logic a little bit
1. No longer fallback to use move(), since all known platforms
support startSystemMove(), and it's unlikely going to work
if it's not supported on a specific platform.
2. Fix titlebar move check missing `window()->`.
This amends a10bbb4e8d
This commit is contained in:
@@ -353,16 +353,14 @@ void MainWindow::leaveEvent(QEvent *event)
|
|||||||
|
|
||||||
void MainWindow::mousePressEvent(QMouseEvent *event)
|
void MainWindow::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
bool optionalMaximized = false;
|
#if defined(Q_OS_WIN)
|
||||||
#if defined(Q_OS_WIN)
|
const bool shouldAcceptDrag = !isMaximized() && !isFullScreen();
|
||||||
optionalMaximized = isMaximized();
|
#else
|
||||||
#endif
|
const bool shouldAcceptDrag = !isFullScreen();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (event->buttons() & Qt::LeftButton && !optionalMaximized && !isFullScreen()) {
|
if (event->buttons() & Qt::LeftButton && shouldAcceptDrag) {
|
||||||
m_clickedOnWindow = true;
|
m_clickedOnWindow = true;
|
||||||
m_oldMousePos = event->pos();
|
|
||||||
// qDebug() << m_oldMousePos << m_graphicsView->transform().m11()
|
|
||||||
// << m_graphicsView->transform().m22() << m_graphicsView->matrix().m12();
|
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,8 +370,8 @@ void MainWindow::mousePressEvent(QMouseEvent *event)
|
|||||||
void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->buttons() & Qt::LeftButton && m_clickedOnWindow) {
|
if (event->buttons() & Qt::LeftButton && m_clickedOnWindow) {
|
||||||
if (!window()->windowHandle()->startSystemMove()) {
|
if (window()->windowHandle()->startSystemMove()) {
|
||||||
move(event->globalPosition().toPoint() - m_oldMousePos);
|
m_clickedOnWindow = false;
|
||||||
}
|
}
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,6 @@ private:
|
|||||||
ActionManager *m_am;
|
ActionManager *m_am;
|
||||||
PlaylistManager *m_pm;
|
PlaylistManager *m_pm;
|
||||||
|
|
||||||
QPoint m_oldMousePos;
|
|
||||||
QPropertyAnimation *m_fadeOutAnimation;
|
QPropertyAnimation *m_fadeOutAnimation;
|
||||||
QPropertyAnimation *m_floatUpAnimation;
|
QPropertyAnimation *m_floatUpAnimation;
|
||||||
QParallelAnimationGroup *m_exitAnimationGroup;
|
QParallelAnimationGroup *m_exitAnimationGroup;
|
||||||
|
|||||||
@@ -115,7 +115,6 @@ void TitleBar::mousePressEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_dragPending = true;
|
m_dragPending = true;
|
||||||
m_moveStartPos = event->pos();
|
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,17 +128,18 @@ void TitleBar::mouseMoveEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool optionalMaximized = false;
|
#if defined(Q_OS_WIN)
|
||||||
#if defined(Q_OS_WIN)
|
const bool shouldAcceptDrag = !window()->isMaximized() && !window()->isFullScreen();
|
||||||
optionalMaximized = isMaximized();
|
#else
|
||||||
#endif
|
const bool shouldAcceptDrag = !window()->isFullScreen();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (event->buttons() & Qt::LeftButton && m_dragPending
|
if (event->buttons() & Qt::LeftButton && m_dragPending && shouldAcceptDrag) {
|
||||||
&& !window()->isFullScreen() && !optionalMaximized) {
|
|
||||||
|
|
||||||
if (QWindow *wh = window()->windowHandle()) {
|
if (QWindow *wh = window()->windowHandle()) {
|
||||||
if (!wh->startSystemMove())
|
if (wh->startSystemMove()) {
|
||||||
window()->move(event->globalPosition().toPoint() - m_moveStartPos);
|
m_dragPending = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ private:
|
|||||||
bool m_closeHovered = false;
|
bool m_closeHovered = false;
|
||||||
bool m_closePressed = false;
|
bool m_closePressed = false;
|
||||||
bool m_dragPending = false;
|
bool m_dragPending = false;
|
||||||
QPoint m_moveStartPos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TITLEBAR_H
|
#endif // TITLEBAR_H
|
||||||
|
|||||||
Reference in New Issue
Block a user