3 Commits

Author SHA1 Message Date
a8aa5b5c30 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
2026-07-18 01:27:36 +08:00
Tech-Tac
a10bbb4e8d chore: allow dragging window from titlebar when maximized (#178)
This better matches titlebar behavior of Windows and KDE, and probably a lot more other environments, it also allows for easier unmaximizing because the current titlebar has no dedicated maximize/restore button.

Note: This is somewhat problematic on Windows, thus we only apply the change to other platforms for now.
2026-07-18 00:38:01 +08:00
Tech-Tac
033e48044c fix: maximize the window when the image size matches the screen size (#179)
This is to avoid the window appearing maximized while not actually being maximized which leads to some frustration and confusion about window borders and breaking Fitts' law on the close button.

This is common for example when viewing screenshots of the same screen size.
2026-07-16 22:45:58 +08:00
4 changed files with 31 additions and 17 deletions

View File

@@ -229,15 +229,22 @@ void MainWindow::adjustWindowSizeBySceneRect()
// we can show the picture by increase the window size. // we can show the picture by increase the window size.
QSize finalSize = (screenSize.expandedTo(sceneSizeWithMargins) == screenSize) ? QSize finalSize = (screenSize.expandedTo(sceneSizeWithMargins) == screenSize) ?
sceneSizeWithMargins : screenSize; sceneSizeWithMargins : screenSize;
// to avoid the window appearing maximized while not being actually maximized
// which is common when viewing screenshots of the same screen size
if (finalSize == screenSize) {
showMaximized();
} else {
// We have a very reasonable sizeHint() value ;P // We have a very reasonable sizeHint() value ;P
this->resize(finalSize.expandedTo(this->sizeHint())); this->resize(finalSize.expandedTo(this->sizeHint()));
centerWindow();
}
// We're sure the window can display the whole thing with 1:1 scale. // We're sure the window can display the whole thing with 1:1 scale.
// The old window size may cause fitInView call from resize() and the // The old window size may cause fitInView call from resize() and the
// above resize() call won't reset the scale back to 1:1, so we // above resize() call won't reset the scale back to 1:1, so we
// just call resetScale() here to ensure the thing is no longer scaled. // just call resetScale() here to ensure the thing is no longer scaled.
m_graphicsView->resetScale(); m_graphicsView->resetScale();
centerWindow();
} else { } else {
// toggle maximum // toggle maximum
showMaximized(); showMaximized();
@@ -346,11 +353,14 @@ void MainWindow::leaveEvent(QEvent *event)
void MainWindow::mousePressEvent(QMouseEvent *event) void MainWindow::mousePressEvent(QMouseEvent *event)
{ {
if (event->buttons() & Qt::LeftButton && !isMaximized()) { #if defined(Q_OS_WIN)
const bool shouldAcceptDrag = !isMaximized() && !isFullScreen();
#else
const bool shouldAcceptDrag = !isFullScreen();
#endif
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();
} }
@@ -359,9 +369,9 @@ void MainWindow::mousePressEvent(QMouseEvent *event)
void MainWindow::mouseMoveEvent(QMouseEvent *event) void MainWindow::mouseMoveEvent(QMouseEvent *event)
{ {
if (event->buttons() & Qt::LeftButton && m_clickedOnWindow && !isMaximized() && !isFullScreen()) { 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();
} }

View File

@@ -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;

View File

@@ -115,7 +115,6 @@ void TitleBar::mousePressEvent(QMouseEvent *event)
} }
m_dragPending = true; m_dragPending = true;
m_moveStartPos = event->pos();
event->accept(); event->accept();
} }
@@ -129,11 +128,18 @@ void TitleBar::mouseMoveEvent(QMouseEvent *event)
} }
} }
if (event->buttons() & Qt::LeftButton && m_dragPending #if defined(Q_OS_WIN)
&& !window()->isMaximized() && !window()->isFullScreen()) { const bool shouldAcceptDrag = !window()->isMaximized() && !window()->isFullScreen();
#else
const bool shouldAcceptDrag = !window()->isFullScreen();
#endif
if (event->buttons() & Qt::LeftButton && m_dragPending && shouldAcceptDrag) {
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();
} }

View File

@@ -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