mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-27 06:35:39 +00:00
Hide mouse cursor after delay in DolphinQt
This commit is contained in:
parent
3095f585dd
commit
d38987e1e8
@ -3,6 +3,7 @@
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QTimer>
|
||||
|
||||
#include "DolphinQt2/Host.h"
|
||||
#include "DolphinQt2/RenderWidget.h"
|
||||
@ -19,9 +20,15 @@ RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent)
|
||||
connect(this, &RenderWidget::HandleChanged, Host::GetInstance(), &Host::SetRenderHandle);
|
||||
emit HandleChanged((void*)winId());
|
||||
|
||||
m_mouse_timer = new QTimer(this);
|
||||
connect(m_mouse_timer, &QTimer::timeout, this, &RenderWidget::HandleCursorTimer);
|
||||
m_mouse_timer->setSingleShot(true);
|
||||
setMouseTracking(true);
|
||||
|
||||
connect(&Settings::Instance(), &Settings::HideCursorChanged, this,
|
||||
&RenderWidget::OnHideCursorChanged);
|
||||
OnHideCursorChanged();
|
||||
m_mouse_timer->start(MOUSE_HIDE_DELAY);
|
||||
}
|
||||
|
||||
void RenderWidget::OnHideCursorChanged()
|
||||
@ -29,6 +36,12 @@ void RenderWidget::OnHideCursorChanged()
|
||||
setCursor(Settings::Instance().GetHideCursor() ? Qt::BlankCursor : Qt::ArrowCursor);
|
||||
}
|
||||
|
||||
void RenderWidget::HandleCursorTimer()
|
||||
{
|
||||
if (isActiveWindow())
|
||||
setCursor(Qt::BlankCursor);
|
||||
}
|
||||
|
||||
bool RenderWidget::event(QEvent* event)
|
||||
{
|
||||
switch (event->type())
|
||||
@ -40,6 +53,14 @@ bool RenderWidget::event(QEvent* event)
|
||||
emit EscapePressed();
|
||||
break;
|
||||
}
|
||||
case QEvent::MouseMove:
|
||||
case QEvent::MouseButtonPress:
|
||||
if (!Settings::Instance().GetHideCursor() && isActiveWindow())
|
||||
{
|
||||
setCursor(Qt::ArrowCursor);
|
||||
m_mouse_timer->start(MOUSE_HIDE_DELAY);
|
||||
}
|
||||
break;
|
||||
case QEvent::WinIdChange:
|
||||
emit HandleChanged((void*)winId());
|
||||
break;
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <QEvent>
|
||||
#include <QWidget>
|
||||
|
||||
class QTimer;
|
||||
|
||||
class RenderWidget final : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -24,5 +26,9 @@ signals:
|
||||
void StateChanged(bool fullscreen);
|
||||
|
||||
private:
|
||||
void HandleCursorTimer();
|
||||
void OnHideCursorChanged();
|
||||
|
||||
static constexpr int MOUSE_HIDE_DELAY = 3000;
|
||||
QTimer* m_mouse_timer;
|
||||
};
|
||||
|
@ -91,7 +91,7 @@ void InterfacePane::CreateInGame()
|
||||
m_checkbox_enable_osd = new QCheckBox(tr("Enable On Screen Messages"));
|
||||
m_checkbox_show_active_title = new QCheckBox(tr("Show Active Title in Window Title"));
|
||||
m_checkbox_pause_on_focus_lost = new QCheckBox(tr("Pause on Focus Loss"));
|
||||
m_checkbox_hide_mouse = new QCheckBox(tr("Hide Mouse Cursor"));
|
||||
m_checkbox_hide_mouse = new QCheckBox(tr("Always Hide Mouse Cursor"));
|
||||
|
||||
groupbox_layout->addWidget(m_checkbox_confirm_on_stop);
|
||||
groupbox_layout->addWidget(m_checkbox_use_panic_handlers);
|
||||
|
Loading…
x
Reference in New Issue
Block a user