Qt: Fix mouse cursor handling

This commit is contained in:
Vicki Pfau 2017-04-05 00:22:32 -07:00
parent adaf8d6224
commit 50ddcda8f0
1 changed files with 6 additions and 14 deletions

View File

@ -680,11 +680,13 @@ void Window::dropEvent(QDropEvent* event) {
} }
void Window::mouseMoveEvent(QMouseEvent* event) { void Window::mouseMoveEvent(QMouseEvent* event) {
QPoint pos = event->pos();
pos = m_screenWidget->mapFrom(this, pos);
QSize dimensions = m_controller->screenDimensions(); QSize dimensions = m_controller->screenDimensions();
QSize viewportDimensions = m_display->viewportSize(); QSize viewportDimensions = m_display->viewportSize();
QSize screenDimensions = m_screenWidget->size(); QSize screenDimensions = m_screenWidget->size();
int x = dimensions.width() * (event->x() - (screenDimensions.width() - viewportDimensions.width()) / 2) / viewportDimensions.width(); int x = dimensions.width() * (pos.x() - (screenDimensions.width() - viewportDimensions.width()) / 2) / viewportDimensions.width();
int y = dimensions.height() * (event->y() - (screenDimensions.height() - viewportDimensions.height()) / 2) / viewportDimensions.height(); int y = dimensions.height() * (pos.y() - (screenDimensions.height() - viewportDimensions.height()) / 2) / viewportDimensions.height();
m_controller->cursorLocation(x, y); m_controller->cursorLocation(x, y);
event->accept(); event->accept();
} }
@ -693,12 +695,7 @@ void Window::mousePressEvent(QMouseEvent* event) {
if (event->button() != Qt::LeftButton) { if (event->button() != Qt::LeftButton) {
return; return;
} }
QSize dimensions = m_controller->screenDimensions(); mouseMoveEvent(event);
QSize viewportDimensions = m_display->viewportSize();
QSize screenDimensions = m_screenWidget->size();
int x = dimensions.width() * (event->x() - (screenDimensions.width() - viewportDimensions.width()) / 2) / viewportDimensions.width();
int y = dimensions.height() * (event->y() - (screenDimensions.height() - viewportDimensions.height()) / 2) / viewportDimensions.height();
m_controller->cursorLocation(x, y);
m_controller->cursorDown(true); m_controller->cursorDown(true);
} }
@ -706,12 +703,7 @@ void Window::mouseReleaseEvent(QMouseEvent* event) {
if (event->button() != Qt::LeftButton) { if (event->button() != Qt::LeftButton) {
return; return;
} }
QSize dimensions = m_controller->screenDimensions(); mouseMoveEvent(event);
QSize viewportDimensions = m_display->viewportSize();
QSize screenDimensions = m_screenWidget->size();
int x = dimensions.width() * (event->x() - (screenDimensions.width() - viewportDimensions.width()) / 2) / viewportDimensions.width();
int y = dimensions.height() * (event->y() - (screenDimensions.height() - viewportDimensions.height()) / 2) / viewportDimensions.height();
m_controller->cursorLocation(x, y);
m_controller->cursorDown(false); m_controller->cursorDown(false);
} }