diff --git a/Source/Core/DolphinQt/GBAWidget.cpp b/Source/Core/DolphinQt/GBAWidget.cpp index 93e1f4620e..289812f93c 100644 --- a/Source/Core/DolphinQt/GBAWidget.cpp +++ b/Source/Core/DolphinQt/GBAWidget.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "AudioCommon/AudioCommon.h" @@ -63,7 +64,7 @@ GBAWidget::GBAWidget(std::weak_ptr core, const HW::GBA::CoreInfo& const std::optional& netplay_pad) : QWidget(nullptr, LoadWindowFlags(netplay_pad ? netplay_pad->local_pad : info.device_number)), m_core(std::move(core)), m_core_info(info), m_local_pad(info.device_number), - m_is_local_pad(true), m_volume(0), m_muted(false), m_force_disconnect(false) + m_is_local_pad(true), m_volume(0), m_muted(false), m_force_disconnect(false), m_moving(false) { bool visible = true; if (netplay_pad) @@ -399,6 +400,29 @@ void GBAWidget::mouseDoubleClickEvent(QMouseEvent* event) SetBorderless(!IsBorderless()); } +void GBAWidget::mousePressEvent(QMouseEvent* event) +{ + if (event->button() != Qt::MouseButton::LeftButton || + !windowFlags().testFlag(Qt::FramelessWindowHint)) + return; + m_moving = true; + m_move_pos = event->pos(); +} + +void GBAWidget::mouseReleaseEvent(QMouseEvent* event) +{ + if (event->button() != Qt::MouseButton::LeftButton) + return; + m_moving = false; +} + +void GBAWidget::mouseMoveEvent(QMouseEvent* event) +{ + if (!m_moving) + return; + move(event->globalPos() - m_move_pos - (geometry().topLeft() - pos())); +} + void GBAWidget::paintEvent(QPaintEvent* event) { QPainter painter(this); diff --git a/Source/Core/DolphinQt/GBAWidget.h b/Source/Core/DolphinQt/GBAWidget.h index 510839f6e9..8248339766 100644 --- a/Source/Core/DolphinQt/GBAWidget.h +++ b/Source/Core/DolphinQt/GBAWidget.h @@ -9,6 +9,7 @@ #include #include +#include #include #include "Common/CommonTypes.h" @@ -68,6 +69,9 @@ private: void closeEvent(QCloseEvent* event) override; void contextMenuEvent(QContextMenuEvent* event) override; void mouseDoubleClickEvent(QMouseEvent* event) override; + void mousePressEvent(QMouseEvent* event) override; + void mouseReleaseEvent(QMouseEvent* event) override; + void mouseMoveEvent(QMouseEvent* event) override; void paintEvent(QPaintEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override; @@ -82,6 +86,8 @@ private: int m_volume; bool m_muted; bool m_force_disconnect; + bool m_moving; + QPoint m_move_pos; }; class GBAWidgetController : public QObject