citra/src/citra_qt/applets/mii_selector.cpp

73 lines
2.7 KiB
C++
Raw Normal View History

// Copyright 2018 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <QComboBox>
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QString>
#include <QVBoxLayout>
#include "citra_qt/applets/mii_selector.h"
2019-04-07 14:58:42 +01:00
#include "common/string_util.h"
QtMiiSelectorDialog::QtMiiSelectorDialog(QWidget* parent, QtMiiSelector* mii_selector_)
: QDialog(parent), mii_selector(mii_selector_) {
2019-02-15 18:20:06 +00:00
using namespace Frontend;
const auto config = mii_selector->config;
layout = new QVBoxLayout;
combobox = new QComboBox;
buttons = new QDialogButtonBox;
// Initialize buttons
2019-02-15 18:20:06 +00:00
buttons->addButton(tr(MII_BUTTON_OKAY), QDialogButtonBox::ButtonRole::AcceptRole);
if (config.enable_cancel_button) {
2019-02-15 18:20:06 +00:00
buttons->addButton(tr(MII_BUTTON_CANCEL), QDialogButtonBox::ButtonRole::RejectRole);
}
2019-02-26 22:36:58 +00:00
setWindowTitle(config.title.empty() || config.title.at(0) == '\x0000'
? tr("Mii Selector")
2019-04-07 14:58:42 +01:00
: QString::fromStdString(config.title));
2019-02-15 18:20:06 +00:00
miis.push_back(HLE::Applets::MiiSelector::GetStandardMiiResult().selected_mii_data);
combobox->addItem(tr("Standard Mii"));
for (const auto& mii : Frontend::LoadMiis()) {
miis.push_back(mii);
combobox->addItem(QString::fromStdString(Common::UTF16BufferToUTF8(mii.mii_name)));
}
if (combobox->count() > static_cast<int>(config.initially_selected_mii_index)) {
combobox->setCurrentIndex(static_cast<int>(config.initially_selected_mii_index));
}
connect(buttons, &QDialogButtonBox::accepted, this, [this] { accept(); });
connect(buttons, &QDialogButtonBox::rejected, this, [this] {
return_code = 1;
accept();
});
layout->addWidget(combobox);
layout->addWidget(buttons);
setLayout(layout);
}
QtMiiSelector::QtMiiSelector(QWidget& parent_) : parent(parent_) {}
2019-02-15 18:20:06 +00:00
void QtMiiSelector::Setup(const Frontend::MiiSelectorConfig& config) {
MiiSelector::Setup(config);
QMetaObject::invokeMethod(this, "OpenDialog", Qt::BlockingQueuedConnection);
}
void QtMiiSelector::OpenDialog() {
QtMiiSelectorDialog dialog(&parent, this);
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
dialog.setWindowModality(Qt::WindowModal);
dialog.exec();
2019-02-15 18:20:06 +00:00
const auto index = dialog.combobox->currentIndex();
LOG_INFO(Frontend, "Mii Selector dialog finished (return_code={}, index={})",
dialog.return_code, index);
2019-02-15 18:20:06 +00:00
const auto mii_data = dialog.miis.at(index);
Finalize(dialog.return_code,
dialog.return_code == 0 ? std::move(mii_data) : HLE::Applets::MiiData{});
}