Qt: Hide cursor opportunistically

This commit is contained in:
Jeffrey Pfau 2015-07-12 17:42:30 -07:00
parent 8a66ee0d56
commit 4d5c1f9849
5 changed files with 28 additions and 0 deletions

View File

@ -51,6 +51,10 @@ Display::Display(QWidget* parent)
{
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::filter(bool filter) {
void Display::showMessage(const QString& message) {
m_messagePainter.showMessage(message);
}
void Display::mouseMoveEvent(QMouseEvent*) {
emit showCursor();
m_mouseTimer.stop();
m_mouseTimer.start();
}

View File

@ -33,6 +33,10 @@ public:
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 @@ public slots:
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;
};
}

View File

@ -21,6 +21,8 @@ DisplayGL::DisplayGL(const QGLFormat& format, QWidget* parent)
, m_drawThread(nullptr)
, m_context(nullptr)
{
m_gl->setMouseTracking(true);
m_gl->setAttribute(Qt::WA_TransparentForMouseEvents); // This doesn't seem to work?
}
DisplayGL::~DisplayGL() {

View File

@ -9,6 +9,7 @@
#include "Display.h"
#include <QGLWidget>
#include <QMouseEvent>
#include <QThread>
#include <QTimer>
@ -27,6 +28,7 @@ public:
protected:
void paintEvent(QPaintEvent*) override {}
void resizeEvent(QResizeEvent*) override {}
void mouseMoveEvent(QMouseEvent* event) override { event->ignore(); }
};
class PainterGL;

View File

@ -128,6 +128,12 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
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);