From 20f54fd9edd9423b9375f8ce95b4344b953d36c8 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Wed, 31 May 2017 00:16:23 -0700 Subject: [PATCH] DolphinQt2: add DoubleClickEventFilter This is an easy way to get a `doubleClicked` signal for any type of widget without creating custom classes for each one. --- Source/Core/DolphinQt2/CMakeLists.txt | 1 + Source/Core/DolphinQt2/DolphinQt2.vcxproj | 5 ++++- .../Core/DolphinQt2/DolphinQt2.vcxproj.filters | 9 +++++++++ .../QtUtils/DoubleClickEventFilter.cpp | 15 +++++++++++++++ .../DolphinQt2/QtUtils/DoubleClickEventFilter.h | 17 +++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Source/Core/DolphinQt2/QtUtils/DoubleClickEventFilter.cpp create mode 100644 Source/Core/DolphinQt2/QtUtils/DoubleClickEventFilter.h diff --git a/Source/Core/DolphinQt2/CMakeLists.txt b/Source/Core/DolphinQt2/CMakeLists.txt index feaac4a090..1e71a266ef 100644 --- a/Source/Core/DolphinQt2/CMakeLists.txt +++ b/Source/Core/DolphinQt2/CMakeLists.txt @@ -40,6 +40,7 @@ set(SRCS GameList/GameListModel.cpp GameList/GameTracker.cpp GameList/ListProxyModel.cpp + QtUtils/DoubleClickEventFilter.cpp QtUtils/ElidedButton.cpp Settings/GeneralPane.cpp Settings/InterfacePane.cpp diff --git a/Source/Core/DolphinQt2/DolphinQt2.vcxproj b/Source/Core/DolphinQt2/DolphinQt2.vcxproj index 113637506c..3c17f53b28 100644 --- a/Source/Core/DolphinQt2/DolphinQt2.vcxproj +++ b/Source/Core/DolphinQt2/DolphinQt2.vcxproj @@ -52,7 +52,7 @@ /NODEFAULTLIB:libcmt %(AdditionalOptions) - $(ProjectDir)\VideoInterface;$(ProjectDir)\GameList;$(ProjectDir)\Settings;$(ProjectDir)\Config;$(ProjectDir)\Config\Mapping;%(AdditionalIncludeDirectories) + $(ProjectDir)\VideoInterface;$(ProjectDir)\GameList;$(ProjectDir)\Settings;$(ProjectDir)\Config;$(ProjectDir)\Config\Mapping;$(ProjectDir)\QtUtils;%(AdditionalIncludeDirectories) DolphinQt2.manifest;%(AdditionalManifestFiles) @@ -88,6 +88,7 @@ + @@ -114,6 +115,7 @@ + @@ -146,6 +148,7 @@ + diff --git a/Source/Core/DolphinQt2/DolphinQt2.vcxproj.filters b/Source/Core/DolphinQt2/DolphinQt2.vcxproj.filters index e3d6e53cec..f051b6a93f 100644 --- a/Source/Core/DolphinQt2/DolphinQt2.vcxproj.filters +++ b/Source/Core/DolphinQt2/DolphinQt2.vcxproj.filters @@ -29,6 +29,9 @@ Generated Files + + Generated Files + Generated Files @@ -116,6 +119,9 @@ + + QtUtils + QtUtils @@ -160,6 +166,9 @@ + + QtUtils + diff --git a/Source/Core/DolphinQt2/QtUtils/DoubleClickEventFilter.cpp b/Source/Core/DolphinQt2/QtUtils/DoubleClickEventFilter.cpp new file mode 100644 index 0000000000..3a626e1203 --- /dev/null +++ b/Source/Core/DolphinQt2/QtUtils/DoubleClickEventFilter.cpp @@ -0,0 +1,15 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include + +#include "DolphinQt2/QtUtils/DoubleClickEventFilter.h" + +bool DoubleClickEventFilter::eventFilter(QObject* object, QEvent* event) +{ + if (event->type() == QEvent::MouseButtonDblClick) + emit doubleClicked(); + + return false; +} diff --git a/Source/Core/DolphinQt2/QtUtils/DoubleClickEventFilter.h b/Source/Core/DolphinQt2/QtUtils/DoubleClickEventFilter.h new file mode 100644 index 0000000000..1e2da4a960 --- /dev/null +++ b/Source/Core/DolphinQt2/QtUtils/DoubleClickEventFilter.h @@ -0,0 +1,17 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +class DoubleClickEventFilter : public QObject +{ + Q_OBJECT +signals: + void doubleClicked(); + +private: + bool eventFilter(QObject* object, QEvent* event) override; +};