Skip to content
Permalink
Browse files

Merge pull request #7893 from jordan-woyak/mapping-ui-cleanup

DolphinQ: Mapping UI cleanups.
  • Loading branch information...
JMC47 committed Mar 27, 2019
2 parents e222b91 + 9cb17b0 commit a1f53716dc96fa5eccf1702b4f6e91861bdb407d
@@ -40,7 +40,7 @@ IOWindow::IOWindow(QWidget* parent, ControllerEmu::EmulatedController* controlle
setWindowTitle(type == IOWindow::Type::Input ? tr("Configure Input") : tr("Configure Output"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

Update();
ConfigChanged();
}

void IOWindow::CreateMainLayout()
@@ -115,8 +115,10 @@ void IOWindow::CreateMainLayout()
setLayout(m_main_layout);
}

void IOWindow::Update()
void IOWindow::ConfigChanged()
{
const auto old_state = blockSignals(true);

m_expression_text->setPlainText(QString::fromStdString(m_reference->GetExpression()));
m_expression_text->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
m_range_spinbox->setValue(m_reference->range * SLIDER_TICK_COUNT);
@@ -126,6 +128,8 @@ void IOWindow::Update()

UpdateDeviceList();
UpdateOptionList();

blockSignals(old_state);
}

void IOWindow::ConnectWidgets()
@@ -173,6 +177,7 @@ void IOWindow::OnDialogButtonPressed(QAbstractButton* button)
}

m_reference->SetExpression(m_expression_text->toPlainText().toStdString());
m_controller->UpdateReferences(g_controller_interface);

if (button != m_apply_button)
accept();
@@ -234,21 +239,9 @@ void IOWindow::UpdateDeviceList()
{
m_devices_combo->clear();

Core::RunAsCPUThread([&] {
g_controller_interface.RefreshDevices();
m_controller->UpdateReferences(g_controller_interface);

// Adding default device regardless if it's currently connected or not
const auto default_device = m_controller->GetDefaultDevice().ToString();

m_devices_combo->addItem(QString::fromStdString(default_device));

for (const auto& name : g_controller_interface.GetAllDeviceStrings())
{
if (name != default_device)
m_devices_combo->addItem(QString::fromStdString(name));
}
for (const auto& name : g_controller_interface.GetAllDeviceStrings())
m_devices_combo->addItem(QString::fromStdString(name));

m_devices_combo->setCurrentIndex(0);
});
m_devices_combo->setCurrentText(
QString::fromStdString(m_controller->GetDefaultDevice().ToString()));
}
@@ -43,7 +43,7 @@ class IOWindow final : public QDialog
private:
void CreateMainLayout();
void ConnectWidgets();
void Update();
void ConfigChanged();

void OnDialogButtonPressed(QAbstractButton* button);
void OnDeviceChanged(const QString& device);
@@ -10,23 +10,20 @@
#include "InputCommon/ControllerEmu/Setting/BooleanSetting.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"

MappingBool::MappingBool(MappingWidget* widget, ControllerEmu::BooleanSetting* setting)
: QCheckBox(tr(setting->m_ui_name.c_str())), m_parent(widget), m_setting(setting)
MappingBool::MappingBool(MappingWidget* parent, ControllerEmu::BooleanSetting* setting)
: QCheckBox(tr(setting->m_ui_name.c_str())), m_setting(*setting)
{
Update();
Connect();
}

void MappingBool::Connect()
{
connect(this, &QCheckBox::stateChanged, this, [this](int value) {
m_setting->SetValue(value);
m_parent->SaveSettings();
m_parent->GetController()->UpdateReferences(g_controller_interface);
connect(this, &QCheckBox::stateChanged, this, [this, parent](int value) {
m_setting.SetValue(value);
parent->SaveSettings();
});

connect(parent, &MappingWidget::ConfigChanged, this, &MappingBool::ConfigChanged);
}

void MappingBool::Update()
void MappingBool::ConfigChanged()
{
setChecked(m_setting->GetValue());
const bool old_state = blockSignals(true);
setChecked(m_setting.GetValue());
blockSignals(old_state);
}
@@ -18,11 +18,8 @@ class MappingBool : public QCheckBox
public:
MappingBool(MappingWidget* widget, ControllerEmu::BooleanSetting* setting);

void Update();

private:
void Connect();
void ConfigChanged();

MappingWidget* m_parent;
ControllerEmu::BooleanSetting* m_setting;
ControllerEmu::BooleanSetting& m_setting;
};
@@ -9,7 +9,6 @@
#include <QMouseEvent>
#include <QRegExp>
#include <QString>
#include <QTimer>

#include "Common/Thread.h"
#include "Core/Core.h"
@@ -42,8 +41,8 @@ bool MappingButton::IsInput() const
return m_reference->IsInput();
}

MappingButton::MappingButton(MappingWidget* widget, ControlReference* ref, bool indicator)
: ElidedButton(ToDisplayString(QString::fromStdString(ref->GetExpression()))), m_parent(widget),
MappingButton::MappingButton(MappingWidget* parent, ControlReference* ref, bool indicator)
: ElidedButton(ToDisplayString(QString::fromStdString(ref->GetExpression()))), m_parent(parent),
m_reference(ref)
{
// Force all mapping buttons to stay at a minimal height.
@@ -54,50 +53,30 @@ MappingButton::MappingButton(MappingWidget* widget, ControlReference* ref, bool

setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);

Connect();
setToolTip(
tr("Left-click to detect input.\nMiddle-click to clear.\nRight-click for more options."));
if (!m_reference->IsInput() || !indicator)
return;

m_timer = new QTimer(this);
connect(m_timer, &QTimer::timeout, this, [this] {
if (!isActiveWindow())
return;

Settings::Instance().SetControllerStateNeeded(true);

if (Core::GetState() == Core::State::Uninitialized || Core::GetState() == Core::State::Paused)
g_controller_interface.UpdateInput();

auto state = m_reference->State();

QFont f = m_parent->font();
QPalette p = m_parent->palette();

if (state > ControllerEmu::Buttons::ACTIVATION_THRESHOLD)
{
f.setBold(true);
p.setColor(QPalette::ButtonText, Qt::red);
}

setFont(f);
setPalette(p);
connect(this, &MappingButton::pressed, this, &MappingButton::Detect);

Settings::Instance().SetControllerStateNeeded(false);
});
if (indicator)
connect(parent, &MappingWidget::Update, this, &MappingButton::UpdateIndicator);

m_timer->start(1000 / 30);
connect(parent, &MappingWidget::ConfigChanged, this, &MappingButton::ConfigChanged);
}

void MappingButton::Connect()
void MappingButton::AdvancedPressed()
{
connect(this, &MappingButton::pressed, this, &MappingButton::Detect);
IOWindow io(this, m_parent->GetController(), m_reference,
m_reference->IsInput() ? IOWindow::Type::Input : IOWindow::Type::Output);
io.exec();

ConfigChanged();
m_parent->SaveSettings();
}

void MappingButton::Detect()
{
if (m_parent->GetDevice() == nullptr || !m_reference->IsInput())
if (!m_reference->IsInput())
return;

const auto default_device_qualifier = m_parent->GetController()->GetDefaultDevice();
@@ -121,27 +100,48 @@ void MappingButton::Detect()
return;

m_reference->SetExpression(expression.toStdString());
m_parent->SaveSettings();
Update();
m_parent->GetController()->UpdateReferences(g_controller_interface);

ConfigChanged();
m_parent->SaveSettings();

if (m_parent->IsIterativeInput())
m_parent->NextButton(this);
}

void MappingButton::Clear()
{
m_reference->SetExpression("");
m_reference->range = 100.0 / SLIDER_TICK_COUNT;

m_reference->SetExpression("");
m_parent->GetController()->UpdateReferences(g_controller_interface);

m_parent->SaveSettings();
Update();
ConfigChanged();
}

void MappingButton::UpdateIndicator()
{
if (!isActiveWindow())
return;

const auto state = m_reference->State();

QFont f = m_parent->font();
QPalette p = m_parent->palette();

if (state > ControllerEmu::Buttons::ACTIVATION_THRESHOLD)
{
f.setBold(true);
p.setColor(QPalette::ButtonText, Qt::red);
}

setFont(f);
setPalette(p);
}

void MappingButton::Update()
void MappingButton::ConfigChanged()
{
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
m_reference->UpdateReference(g_controller_interface,
m_parent->GetController()->GetDefaultDevice());
setText(ToDisplayString(QString::fromStdString(m_reference->GetExpression())));
}

@@ -153,13 +153,13 @@ void MappingButton::mouseReleaseEvent(QMouseEvent* event)
if (m_reference->IsInput())
QPushButton::mouseReleaseEvent(event);
else
emit AdvancedPressed();
AdvancedPressed();
return;
case Qt::MouseButton::MidButton:
Clear();
return;
case Qt::MouseButton::RightButton:
emit AdvancedPressed();
AdvancedPressed();
return;
default:
return;
@@ -11,28 +11,24 @@ class ControlReference;
class MappingWidget;
class QEvent;
class QMouseEvent;
class QTimer;

class MappingButton : public ElidedButton
{
Q_OBJECT
public:
MappingButton(MappingWidget* widget, ControlReference* ref, bool indicator);

void Clear();
void Update();
void Detect();
bool IsInput() const;

signals:
private:
void Clear();
void UpdateIndicator();
void ConfigChanged();
void AdvancedPressed();

private:
void mouseReleaseEvent(QMouseEvent* event) override;

void Connect();

MappingWidget* m_parent;
ControlReference* m_reference;
QTimer* m_timer;
};
@@ -67,6 +67,7 @@ QString DetectExpression(QPushButton* button, ciface::Core::DeviceContainer& dev

std::shared_ptr<ciface::Core::Device> device;
ciface::Core::Device::Input* input;

std::tie(device, input) = device_container.DetectInput(INPUT_DETECT_TIME, device_strings);

button->releaseMouse();

0 comments on commit a1f5371

Please sign in to comment.
You can’t perform that action at this time.