all repos — mgba @ 4d5c1f98497b90e5abb79bdaf7af0c0ad5b606bf

mGBA Game Boy Advance Emulator

Qt: Hide cursor opportunistically
Jeffrey Pfau jeffrey@endrift.com
Sun, 12 Jul 2015 17:42:30 -0700
commit

4d5c1f98497b90e5abb79bdaf7af0c0ad5b606bf

parent

8a66ee0d5673ff5f701fd3b3bf73876da2aeefcd

M src/platform/qt/Display.cppsrc/platform/qt/Display.cpp

@@ -51,6 +51,10 @@ , m_filter(false)

{ setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); setMinimumSize(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS); + connect(&m_mouseTimer, SIGNAL(timeout()), this, SIGNAL(hideCursor())); + m_mouseTimer.setSingleShot(true); + m_mouseTimer.setInterval(MOUSE_DISAPPEAR_TIMER); + setMouseTracking(true); } void Display::resizeEvent(QResizeEvent*) {

@@ -69,3 +73,9 @@

void Display::showMessage(const QString& message) { m_messagePainter.showMessage(message); } + +void Display::mouseMoveEvent(QMouseEvent*) { + emit showCursor(); + m_mouseTimer.stop(); + m_mouseTimer.start(); +}
M src/platform/qt/Display.hsrc/platform/qt/Display.h

@@ -33,6 +33,10 @@

bool isAspectRatioLocked() const { return m_lockAspectRatio; } bool isFiltered() const { return m_filter; } +signals: + void showCursor(); + void hideCursor(); + public slots: virtual void startDrawing(GBAThread* context) = 0; virtual void stopDrawing() = 0;

@@ -47,15 +51,19 @@ void showMessage(const QString& message);

protected: void resizeEvent(QResizeEvent*); + virtual void mouseMoveEvent(QMouseEvent*) override; MessagePainter* messagePainter() { return &m_messagePainter; } + private: static Driver s_driver; + static const int MOUSE_DISAPPEAR_TIMER = 2000; MessagePainter m_messagePainter; bool m_lockAspectRatio; bool m_filter; + QTimer m_mouseTimer; }; }
M src/platform/qt/DisplayGL.cppsrc/platform/qt/DisplayGL.cpp

@@ -21,6 +21,8 @@ , m_painter(new PainterGL(m_gl))

, m_drawThread(nullptr) , m_context(nullptr) { + m_gl->setMouseTracking(true); + m_gl->setAttribute(Qt::WA_TransparentForMouseEvents); // This doesn't seem to work? } DisplayGL::~DisplayGL() {
M src/platform/qt/DisplayGL.hsrc/platform/qt/DisplayGL.h

@@ -9,6 +9,7 @@

#include "Display.h" #include <QGLWidget> +#include <QMouseEvent> #include <QThread> #include <QTimer>

@@ -27,6 +28,7 @@

protected: void paintEvent(QPaintEvent*) override {} void resizeEvent(QResizeEvent*) override {} + void mouseMoveEvent(QMouseEvent* event) override { event->ignore(); } }; class PainterGL;
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -128,6 +128,12 @@ connect(this, SIGNAL(shutdown()), m_logView, SLOT(hide()));

connect(this, SIGNAL(audioBufferSamplesChanged(int)), m_controller, SLOT(setAudioBufferSamples(int))); connect(this, SIGNAL(fpsTargetChanged(float)), m_controller, SLOT(setFPSTarget(float))); connect(&m_fpsTimer, SIGNAL(timeout()), this, SLOT(showFPS())); + connect(m_display, &Display::hideCursor, [this]() { + setCursor(Qt::BlankCursor); + }); + connect(m_display, &Display::showCursor, [this]() { + unsetCursor(); + }); m_log.setLevels(GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL | GBA_LOG_STATUS); m_fpsTimer.setInterval(FPS_TIMER_INTERVAL);