summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp
diff options
context:
space:
mode:
authorspycrab <spycrab@users.noreply.github.com>2018-07-07 00:58:37 +0200
committerGitHub <noreply@github.com>2018-07-07 00:58:37 +0200
commit3d1a7737d86f4ecdf0131f5b84198f288800da3b (patch)
tree747e394036c189c46add1b3e1451e50f48230e11 /Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp
parent059880bb1640d5a3b0e1fbbf66e1a356df4b9f41 (diff)
parent13ba24c5a6795532c8893eccf2a21ae95682e1b7 (diff)
Merge pull request #7205 from spycrab/qt_rename
Move DolphinQt2 to DolphinQt
Diffstat (limited to 'Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp')
-rw-r--r--Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp
new file mode 100644
index 0000000000..49c29d29a7
--- /dev/null
+++ b/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp
@@ -0,0 +1,49 @@
+// Copyright 2017 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include "DolphinQt/Config/Mapping/MappingCommon.h"
+
+#include <QRegExp>
+#include <QString>
+
+#include "InputCommon/ControlReference/ControlReference.h"
+#include "InputCommon/ControllerInterface/Device.h"
+
+namespace MappingCommon
+{
+QString GetExpressionForControl(const QString& control_name,
+ const ciface::Core::DeviceQualifier& control_device,
+ const ciface::Core::DeviceQualifier& default_device)
+{
+ QString expr;
+
+ // non-default device
+ if (control_device != default_device)
+ {
+ expr += QString::fromStdString(control_device.ToString());
+ expr += QStringLiteral(":");
+ }
+
+ // append the control name
+ expr += control_name;
+
+ QRegExp reg(QStringLiteral("[a-zA-Z]+"));
+ if (!reg.exactMatch(expr))
+ expr = QStringLiteral("`%1`").arg(expr);
+ return expr;
+}
+
+QString DetectExpression(ControlReference* reference, ciface::Core::Device* device,
+ const ciface::Core::DeviceQualifier& default_device)
+{
+ ciface::Core::Device::Control* const ctrl = reference->Detect(5000, device);
+
+ if (ctrl)
+ {
+ return MappingCommon::GetExpressionForControl(QString::fromStdString(ctrl->GetName()),
+ default_device, default_device);
+ }
+ return QStringLiteral("");
+}
+}