pineapple/src/yuzu/debugger/controller.cpp

68 lines
2.2 KiB
C++
Raw Normal View History

2021-02-07 15:58:56 +01:00
// Copyright 2015 Citra Emulator Project
2021-01-26 06:32:32 +01:00
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <QAction>
#include <QLayout>
#include <QString>
2021-04-15 04:05:28 +02:00
#include "common/settings.h"
2021-01-26 06:32:32 +01:00
#include "yuzu/configuration/configure_input_player_widget.h"
#include "yuzu/debugger/controller.h"
ControllerDialog::ControllerDialog(QWidget* parent) : QWidget(parent, Qt::Dialog) {
setObjectName(QStringLiteral("Controller"));
setWindowTitle(tr("Controller P1"));
resize(500, 350);
setMinimumSize(500, 350);
// Remove the "?" button from the titlebar and enable the maximize button
setWindowFlags((windowFlags() & ~Qt::WindowContextHelpButtonHint) |
Qt::WindowMaximizeButtonHint);
2021-02-04 21:32:13 +01:00
widget = new PlayerControlPreview(this);
2021-02-07 15:58:56 +01:00
refreshConfiguration();
2021-01-26 06:32:32 +01:00
QLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(widget);
setLayout(layout);
// Configure focus so that widget is focusable and the dialog automatically forwards focus to
// it.
setFocusProxy(widget);
widget->setFocusPolicy(Qt::StrongFocus);
widget->setFocus();
}
2021-02-07 15:58:56 +01:00
void ControllerDialog::refreshConfiguration() {
2021-02-04 21:32:13 +01:00
const auto& players = Settings::values.players.GetValue();
constexpr std::size_t player = 0;
widget->SetPlayerInputRaw(player, players[player].buttons, players[player].analogs);
widget->SetConnectedStatus(players[player].connected);
widget->SetControllerType(players[player].controller_type);
2021-05-25 22:52:37 +02:00
widget->repaint();
2021-02-04 21:32:13 +01:00
}
2021-01-26 06:32:32 +01:00
QAction* ControllerDialog::toggleViewAction() {
if (toggle_view_action == nullptr) {
2021-02-15 08:17:26 +01:00
toggle_view_action = new QAction(tr("&Controller P1"), this);
2021-01-26 06:32:32 +01:00
toggle_view_action->setCheckable(true);
toggle_view_action->setChecked(isVisible());
connect(toggle_view_action, &QAction::toggled, this, &ControllerDialog::setVisible);
}
return toggle_view_action;
}
void ControllerDialog::showEvent(QShowEvent* ev) {
if (toggle_view_action) {
toggle_view_action->setChecked(isVisible());
}
QWidget::showEvent(ev);
}
void ControllerDialog::hideEvent(QHideEvent* ev) {
if (toggle_view_action) {
toggle_view_action->setChecked(isVisible());
}
QWidget::hideEvent(ev);
}