controller.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <QAction>
  5. #include <QLayout>
  6. #include <QString>
  7. #include "core/settings.h"
  8. #include "yuzu/configuration/configure_input_player_widget.h"
  9. #include "yuzu/debugger/controller.h"
  10. ControllerDialog::ControllerDialog(QWidget* parent) : QWidget(parent, Qt::Dialog) {
  11. setObjectName(QStringLiteral("Controller"));
  12. setWindowTitle(tr("Controller P1"));
  13. resize(500, 350);
  14. setMinimumSize(500, 350);
  15. // Remove the "?" button from the titlebar and enable the maximize button
  16. setWindowFlags((windowFlags() & ~Qt::WindowContextHelpButtonHint) |
  17. Qt::WindowMaximizeButtonHint);
  18. widget = new PlayerControlPreview(this);
  19. refreshConfiguration();
  20. QLayout* layout = new QVBoxLayout(this);
  21. layout->setContentsMargins(0, 0, 0, 0);
  22. layout->addWidget(widget);
  23. setLayout(layout);
  24. // Configure focus so that widget is focusable and the dialog automatically forwards focus to
  25. // it.
  26. setFocusProxy(widget);
  27. widget->setFocusPolicy(Qt::StrongFocus);
  28. widget->setFocus();
  29. }
  30. void ControllerDialog::refreshConfiguration() {
  31. const auto& players = Settings::values.players.GetValue();
  32. constexpr std::size_t player = 0;
  33. widget->SetPlayerInputRaw(player, players[player].buttons, players[player].analogs);
  34. widget->SetConnectedStatus(players[player].connected);
  35. widget->SetControllerType(players[player].controller_type);
  36. }
  37. QAction* ControllerDialog::toggleViewAction() {
  38. if (toggle_view_action == nullptr) {
  39. toggle_view_action = new QAction(tr("&Controller P1"), this);
  40. toggle_view_action->setCheckable(true);
  41. toggle_view_action->setChecked(isVisible());
  42. connect(toggle_view_action, &QAction::toggled, this, &ControllerDialog::setVisible);
  43. }
  44. return toggle_view_action;
  45. }
  46. void ControllerDialog::showEvent(QShowEvent* ev) {
  47. if (toggle_view_action) {
  48. toggle_view_action->setChecked(isVisible());
  49. }
  50. QWidget::showEvent(ev);
  51. }
  52. void ControllerDialog::hideEvent(QHideEvent* ev) {
  53. if (toggle_view_action) {
  54. toggle_view_action->setChecked(isVisible());
  55. }
  56. QWidget::hideEvent(ev);
  57. }