diff options
| author | spycrab <spycrab@users.noreply.github.com> | 2018-07-07 00:40:15 +0200 |
|---|---|---|
| committer | spycrab <spycrab@users.noreply.github.com> | 2018-07-07 00:48:38 +0200 |
| commit | 13ba24c5a6795532c8893eccf2a21ae95682e1b7 (patch) | |
| tree | 747e394036c189c46add1b3e1451e50f48230e11 /Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp | |
| parent | 059880bb1640d5a3b0e1fbbf66e1a356df4b9f41 (diff) | |
Move DolphinQt2 to DolphinQt
Diffstat (limited to 'Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp')
| -rw-r--r-- | Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp | 49 |
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(""); +} +} |
