Skip to content
Permalink
Browse files

Qt/Mapping: Show current input states in advanced dialog.

  • Loading branch information...
jordan-woyak committed Jan 6, 2019
1 parent b6545ea commit 7b2252f5581052bb1623637f2fc4cc5099b85abc
@@ -10,17 +10,21 @@
#include <QDialogButtonBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QListWidget>
#include <QPainter>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QSlider>
#include <QSpinBox>
#include <QTableWidget>
#include <QVBoxLayout>

#include "Core/Core.h"

#include "DolphinQt/Config/Mapping/MappingCommon.h"
#include "DolphinQt/Config/Mapping/MappingIndicator.h"
#include "DolphinQt/Config/Mapping/MappingWidget.h"
#include "DolphinQt/Config/Mapping/MappingWindow.h"
#include "DolphinQt/QtUtils/BlockUserInputFilter.h"

@@ -30,25 +34,32 @@

constexpr int SLIDER_TICK_COUNT = 100;

IOWindow::IOWindow(QWidget* parent, ControllerEmu::EmulatedController* controller,
IOWindow::IOWindow(MappingWidget* parent, ControllerEmu::EmulatedController* controller,
ControlReference* ref, IOWindow::Type type)
: QDialog(parent), m_reference(ref), m_controller(controller), m_type(type)
{
CreateMainLayout();
ConnectWidgets();

connect(parent, &MappingWidget::Update, this, &IOWindow::Update);

setWindowTitle(type == IOWindow::Type::Input ? tr("Configure Input") : tr("Configure Output"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

ConfigChanged();
}

std::shared_ptr<ciface::Core::Device> IOWindow::GetSelectedDevice()
{
return m_selected_device;
}

void IOWindow::CreateMainLayout()
{
m_main_layout = new QVBoxLayout();

m_devices_combo = new QComboBox();
m_option_list = new QListWidget();
m_option_list = new QTableWidget();
m_select_button = new QPushButton(tr("Select"));
m_detect_button = new QPushButton(tr("Detect"));
m_or_button = new QPushButton(tr("| OR"));
@@ -78,6 +89,29 @@ void IOWindow::CreateMainLayout()
m_main_layout->addLayout(range_hbox);

// Options (Buttons, Outputs) and action buttons

if (m_type == Type::Input)
{
m_option_list->setColumnCount(2);
m_option_list->setColumnWidth(1, 64);
m_option_list->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);

m_option_list->setItemDelegate(new InputStateDelegate(this));
}
else
{
m_option_list->setColumnCount(1);
}

m_option_list->horizontalHeader()->hide();
m_option_list->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
m_option_list->verticalHeader()->hide();
m_option_list->verticalHeader()->setDefaultSectionSize(
m_option_list->verticalHeader()->minimumSectionSize());
m_option_list->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_option_list->setSelectionBehavior(QAbstractItemView::SelectRows);
m_option_list->setSelectionMode(QAbstractItemView::SingleSelection);

// macOS style doesn't support expanding buttons
#ifndef __APPLE__
for (QPushButton* button : {m_select_button, m_detect_button, m_or_button, m_and_button,
@@ -130,6 +164,11 @@ void IOWindow::ConfigChanged()
UpdateOptionList();
}

void IOWindow::Update()
{
m_option_list->viewport()->update();
}

void IOWindow::ConnectWidgets()
{
connect(m_select_button, &QPushButton::clicked, [this] { AppendSelectedOption(""); });
@@ -210,25 +249,32 @@ void IOWindow::OnRangeChanged(int value)

void IOWindow::UpdateOptionList()
{
m_option_list->clear();
m_selected_device = g_controller_interface.FindDevice(m_devq);
m_option_list->setRowCount(0);

const auto device = g_controller_interface.FindDevice(m_devq);

if (device == nullptr)
if (m_selected_device == nullptr)
return;

if (m_reference->IsInput())
{
for (const auto* input : device->Inputs())
int row = 0;
for (const auto* input : m_selected_device->Inputs())
{
m_option_list->addItem(QString::fromStdString(input->GetName()));
m_option_list->insertRow(row);
m_option_list->setItem(row, 0,
new QTableWidgetItem(QString::fromStdString(input->GetName())));
++row;
}
}
else
{
for (const auto* output : device->Outputs())
int row = 0;
for (const auto* output : m_selected_device->Outputs())
{
m_option_list->addItem(QString::fromStdString(output->GetName()));
m_option_list->insertRow(row);
m_option_list->setItem(row, 0,
new QTableWidgetItem(QString::fromStdString(output->GetName())));
++row;
}
}
}
@@ -243,3 +289,42 @@ void IOWindow::UpdateDeviceList()
m_devices_combo->setCurrentText(
QString::fromStdString(m_controller->GetDefaultDevice().ToString()));
}

InputStateDelegate::InputStateDelegate(IOWindow* parent) : QItemDelegate(parent), m_parent(parent)
{
}

void InputStateDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
QItemDelegate::paint(painter, option, index);

// Don't do anything special for the first column.
if (index.column() == 0)
return;

// Clamp off negative values but allow greater than one in the text display.
const auto state =
std::max(m_parent->GetSelectedDevice()->Inputs()[index.row()]->GetState(), 0.0);
const auto state_str = QString::number(state, 'g', 4);

QRect rect = option.rect;
rect.setWidth(rect.width() * std::clamp(state, 0.0, 1.0));

// Create a temporary indicator object to retreive color constants.
MappingIndicator indicator(nullptr);

painter->save();

painter->setPen(indicator.GetTextColor());
painter->drawText(option.rect, Qt::AlignCenter, state_str);

painter->fillRect(rect, indicator.GetAdjustedInputColor());

painter->setPen(indicator.GetAltTextColor());
painter->setClipping(true);
painter->setClipRect(rect);
painter->drawText(option.rect, Qt::AlignCenter, state_str);

painter->restore();
}
@@ -5,16 +5,18 @@
#pragma once

#include <QDialog>
#include <QItemDelegate>
#include <QString>

#include "Common/Flag.h"
#include "InputCommon/ControllerInterface/Device.h"

class ControlReference;
class MappingWidget;
class QAbstractButton;
class QComboBox;
class QDialogButtonBox;
class QListWidget;
class QTableWidget;
class QVBoxLayout;
class QWidget;
class QPlainTextEdit;
@@ -37,13 +39,16 @@ class IOWindow final : public QDialog
Output
};

explicit IOWindow(QWidget* parent, ControllerEmu::EmulatedController* m_controller,
explicit IOWindow(MappingWidget* parent, ControllerEmu::EmulatedController* m_controller,
ControlReference* ref, Type type);

std::shared_ptr<ciface::Core::Device> GetSelectedDevice();

private:
void CreateMainLayout();
void ConnectWidgets();
void ConfigChanged();
void Update();

void OnDialogButtonPressed(QAbstractButton* button);
void OnDeviceChanged(const QString& device);
@@ -62,7 +67,7 @@ class IOWindow final : public QDialog
QComboBox* m_devices_combo;

// Options
QListWidget* m_option_list;
QTableWidget* m_option_list;

// Range
QSlider* m_range_slider;
@@ -94,4 +99,18 @@ class IOWindow final : public QDialog

ciface::Core::DeviceQualifier m_devq;
Type m_type;
std::shared_ptr<ciface::Core::Device> m_selected_device;
};

class InputStateDelegate : public QItemDelegate
{
Q_OBJECT
public:
InputStateDelegate(IOWindow* parent);

void paint(QPainter* painter, const QStyleOptionViewItem& option,
const QModelIndex& index) const override;

private:
IOWindow* m_parent;
};
@@ -66,7 +66,7 @@ MappingButton::MappingButton(MappingWidget* parent, ControlReference* ref, bool

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

@@ -105,7 +105,7 @@ MappingIndicator::MappingIndicator(ControllerEmu::ControlGroup* group) : m_group
// TODO: Make these magic numbers less ugly.
int required_height = 106;

if (ControllerEmu::GroupType::MixedTriggers == group->type)
if (group && ControllerEmu::GroupType::MixedTriggers == group->type)
required_height = 64 + 1;

setFixedHeight(required_height);
@@ -33,9 +33,6 @@ class MappingIndicator : public QWidget

void SetCalibrationWidget(CalibrationWidget* widget);

protected:
WiimoteEmu::MotionState m_motion_state{};

QPen GetBBoxPen() const;
QBrush GetBBoxBrush() const;
QColor GetRawInputColor() const;
@@ -49,8 +46,11 @@ class MappingIndicator : public QWidget
QColor GetAltTextColor() const;
QColor GetGateColor() const;

protected:
double GetScale() const;

WiimoteEmu::MotionState m_motion_state{};

private:
void DrawCursor(ControllerEmu::Cursor& cursor);
void DrawReshapableInput(ControllerEmu::ReshapableInput& stick);
@@ -9,7 +9,6 @@
#include <QPushButton>
#include <QTimer>

#include "DolphinQt/Config/Mapping/IOWindow.h"
#include "DolphinQt/Config/Mapping/MappingButton.h"
#include "DolphinQt/Config/Mapping/MappingIndicator.h"
#include "DolphinQt/Config/Mapping/MappingNumeric.h"

0 comments on commit 7b2252f

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