Qt: Handle mouse move events properly (#678)

This commit is contained in:
wheremyfoodat 2024-12-10 00:54:06 +02:00 committed by GitHub
parent 79d24cba11
commit 4ce0768ba1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 22 deletions

View file

@ -146,12 +146,15 @@ class MainWindow : public QMainWindow {
void closeEvent(QCloseEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void loadLuaScript(const std::string& code);
void reloadShader(const std::string& shader);
void editCheat(u32 handle, const std::vector<uint8_t>& cheat, const std::function<void(u32)>& callback);
void handleScreenResize(u32 width, u32 height);
void handleTouchscreenPress(QMouseEvent* event);
};

View file

@ -487,6 +487,24 @@ void MainWindow::keyReleaseEvent(QKeyEvent* event) {
void MainWindow::mousePressEvent(QMouseEvent* event) {
if (event->button() == Qt::MouseButton::LeftButton) {
// We handle actual mouse press & movement logic inside the mouseMoveEvent handler
handleTouchscreenPress(event);
}
}
void MainWindow::mouseMoveEvent(QMouseEvent* event) {
if (event->buttons().testFlag(Qt::MouseButton::LeftButton)) {
handleTouchscreenPress(event);
}
}
void MainWindow::mouseReleaseEvent(QMouseEvent* event) {
if (event->button() == Qt::MouseButton::LeftButton) {
sendMessage(EmulatorMessage{.type = MessageType::ReleaseTouchscreen});
}
}
void MainWindow::handleTouchscreenPress(QMouseEvent* event) {
const QPointF clickPos = event->globalPosition();
const QPointF widgetPos = screen->mapFromGlobal(clickPos);
@ -511,13 +529,6 @@ void MainWindow::mousePressEvent(QMouseEvent* event) {
}
}
}
}
void MainWindow::mouseReleaseEvent(QMouseEvent* event) {
if (event->button() == Qt::MouseButton::LeftButton) {
sendMessage(EmulatorMessage{.type = MessageType::ReleaseTouchscreen});
}
}
void MainWindow::loadLuaScript(const std::string& code) {
EmulatorMessage message{.type = MessageType::LoadLuaScript};