mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Qt: Make GBA widgets movable with left click in borderless mode
This commit is contained in:
@ -15,6 +15,7 @@
|
|||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "AudioCommon/AudioCommon.h"
|
#include "AudioCommon/AudioCommon.h"
|
||||||
@ -63,7 +64,7 @@ GBAWidget::GBAWidget(std::weak_ptr<HW::GBA::Core> core, const HW::GBA::CoreInfo&
|
|||||||
const std::optional<NetPlay::PadDetails>& netplay_pad)
|
const std::optional<NetPlay::PadDetails>& netplay_pad)
|
||||||
: QWidget(nullptr, LoadWindowFlags(netplay_pad ? netplay_pad->local_pad : info.device_number)),
|
: 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_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;
|
bool visible = true;
|
||||||
if (netplay_pad)
|
if (netplay_pad)
|
||||||
@ -399,6 +400,29 @@ void GBAWidget::mouseDoubleClickEvent(QMouseEvent* event)
|
|||||||
SetBorderless(!IsBorderless());
|
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)
|
void GBAWidget::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <QPoint>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
@ -68,6 +69,9 @@ private:
|
|||||||
void closeEvent(QCloseEvent* event) override;
|
void closeEvent(QCloseEvent* event) override;
|
||||||
void contextMenuEvent(QContextMenuEvent* event) override;
|
void contextMenuEvent(QContextMenuEvent* event) override;
|
||||||
void mouseDoubleClickEvent(QMouseEvent* 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 paintEvent(QPaintEvent* event) override;
|
||||||
|
|
||||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||||
@ -82,6 +86,8 @@ private:
|
|||||||
int m_volume;
|
int m_volume;
|
||||||
bool m_muted;
|
bool m_muted;
|
||||||
bool m_force_disconnect;
|
bool m_force_disconnect;
|
||||||
|
bool m_moving;
|
||||||
|
QPoint m_move_pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GBAWidgetController : public QObject
|
class GBAWidgetController : public QObject
|
||||||
|
Reference in New Issue
Block a user