mirror of https://github.com/mgba-emu/mgba.git
Qt: Change Action* semantics to std::shared_ptr<Action>
This commit is contained in:
parent
3ee12b1a55
commit
17dbdcf57c
|
@ -61,7 +61,7 @@ void ActionMapper::rebuildMenu(const QString& menu, QMenu* qmenu, QWidget* conte
|
|||
rebuildMenu(name, newMenu, context, shortcuts);
|
||||
continue;
|
||||
}
|
||||
Action* action = &m_actions[actionName];
|
||||
auto action = getAction(actionName);
|
||||
QAction* qaction = qmenu->addAction(action->visibleName());
|
||||
qaction->setEnabled(action->isEnabled());
|
||||
qaction->setShortcutContext(Qt::WidgetShortcut);
|
||||
|
@ -100,15 +100,15 @@ void ActionMapper::rebuildMenu(const QString& menu, QMenu* qmenu, QWidget* conte
|
|||
action->trigger();
|
||||
}
|
||||
});
|
||||
QObject::connect(action, &Action::enabled, qaction, &QAction::setEnabled);
|
||||
QObject::connect(action, &Action::activated, [qaction, action](bool active) {
|
||||
QObject::connect(action.get(), &Action::enabled, qaction, &QAction::setEnabled);
|
||||
QObject::connect(action.get(), &Action::activated, [qaction, action](bool active) {
|
||||
if (qaction->isCheckable()) {
|
||||
qaction->setChecked(active);
|
||||
} else if (active) {
|
||||
action->setActive(false);
|
||||
}
|
||||
});
|
||||
QObject::connect(action, &Action::destroyed, qaction, &QAction::deleteLater);
|
||||
QObject::connect(action.get(), &Action::destroyed, qaction, &QAction::deleteLater);
|
||||
if (shortcut) {
|
||||
QObject::connect(shortcut, &Shortcut::shortcutChanged, qaction, [qaction](int shortcut) {
|
||||
qaction->setShortcut(QKeySequence(shortcut));
|
||||
|
@ -122,8 +122,8 @@ void ActionMapper::addSeparator(const QString& menu) {
|
|||
m_menus[menu].append(QString{});
|
||||
}
|
||||
|
||||
Action* ActionMapper::addAction(const Action& act, const QString& name, const QString& menu, const QKeySequence& shortcut) {
|
||||
m_actions.insert(name, act);
|
||||
std::shared_ptr<Action> ActionMapper::addAction(const Action& act, const QString& name, const QString& menu, const QKeySequence& shortcut) {
|
||||
m_actions.insert(name, std::make_shared<Action>(act));
|
||||
m_reverseMenus[name] = menu;
|
||||
m_menus[menu].append(name);
|
||||
if (!shortcut.isEmpty()) {
|
||||
|
@ -131,36 +131,36 @@ Action* ActionMapper::addAction(const Action& act, const QString& name, const QS
|
|||
}
|
||||
emit actionAdded(name);
|
||||
|
||||
return &m_actions[name];
|
||||
return getAction(name);
|
||||
}
|
||||
|
||||
Action* ActionMapper::addAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu, const QKeySequence& shortcut) {
|
||||
std::shared_ptr<Action> ActionMapper::addAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu, const QKeySequence& shortcut) {
|
||||
return addAction(Action(action, name, visibleName), name, menu, shortcut);
|
||||
}
|
||||
|
||||
Action* ActionMapper::addAction(const QString& visibleName, ConfigOption* option, const QVariant& variant, const QString& menu) {
|
||||
std::shared_ptr<Action> ActionMapper::addAction(const QString& visibleName, ConfigOption* option, const QVariant& variant, const QString& menu) {
|
||||
return addAction(Action([option, variant]() {
|
||||
option->setValue(variant);
|
||||
}, option->name(), visibleName), QString("%1.%2").arg(option->name()).arg(variant.toString()), menu, {});
|
||||
}
|
||||
|
||||
Action* ActionMapper::addBooleanAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu, const QKeySequence& shortcut) {
|
||||
std::shared_ptr<Action> ActionMapper::addBooleanAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu, const QKeySequence& shortcut) {
|
||||
return addAction(Action(action, name, visibleName), name, menu, shortcut);
|
||||
}
|
||||
|
||||
Action* ActionMapper::addBooleanAction(const QString& visibleName, ConfigOption* option, const QString& menu) {
|
||||
std::shared_ptr<Action> ActionMapper::addBooleanAction(const QString& visibleName, ConfigOption* option, const QString& menu) {
|
||||
return addAction(Action([option](bool value) {
|
||||
option->setValue(value);
|
||||
}, option->name(), visibleName), option->name(), menu, {});
|
||||
}
|
||||
|
||||
Action* ActionMapper::addHeldAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu, const QKeySequence& shortcut) {
|
||||
std::shared_ptr<Action> ActionMapper::addHeldAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu, const QKeySequence& shortcut) {
|
||||
m_hiddenActions.insert(name);
|
||||
m_heldActions.insert(name);
|
||||
return addBooleanAction(visibleName, name, action, menu, shortcut);
|
||||
}
|
||||
|
||||
Action* ActionMapper::addHiddenAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu, const QKeySequence& shortcut) {
|
||||
std::shared_ptr<Action> ActionMapper::addHiddenAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu, const QKeySequence& shortcut) {
|
||||
m_hiddenActions.insert(name);
|
||||
return addAction(visibleName, name, action, menu, shortcut);
|
||||
}
|
||||
|
@ -180,8 +180,8 @@ QString ActionMapper::menuName(const QString& menu) const {
|
|||
return m_menuNames[menu];
|
||||
}
|
||||
|
||||
Action* ActionMapper::getAction(const QString& itemName) {
|
||||
return &m_actions[itemName];
|
||||
std::shared_ptr<Action> ActionMapper::getAction(const QString& itemName) {
|
||||
return m_actions.value(itemName);
|
||||
}
|
||||
|
||||
QKeySequence ActionMapper::defaultShortcut(const QString& itemName) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <QSet>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
class QMenu;
|
||||
class QMenuBar;
|
||||
|
@ -33,17 +34,17 @@ public:
|
|||
|
||||
void addSeparator(const QString& menu);
|
||||
|
||||
Action* addAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});
|
||||
template<typename T, typename V> Action* addAction(const QString& visibleName, const QString& name, T* obj, V (T::*method)(), const QString& menu = {}, const QKeySequence& = {});
|
||||
Action* addAction(const QString& visibleName, ConfigOption* option, const QVariant& variant, const QString& menu = {});
|
||||
std::shared_ptr<Action> addAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});
|
||||
template<typename T, typename V> std::shared_ptr<Action> addAction(const QString& visibleName, const QString& name, T* obj, V (T::*method)(), const QString& menu = {}, const QKeySequence& = {});
|
||||
std::shared_ptr<Action> addAction(const QString& visibleName, ConfigOption* option, const QVariant& variant, const QString& menu = {});
|
||||
|
||||
Action* addBooleanAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu = {}, const QKeySequence& = {});
|
||||
Action* addBooleanAction(const QString& visibleName, ConfigOption* option, const QString& menu = {});
|
||||
std::shared_ptr<Action> addBooleanAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu = {}, const QKeySequence& = {});
|
||||
std::shared_ptr<Action> addBooleanAction(const QString& visibleName, ConfigOption* option, const QString& menu = {});
|
||||
|
||||
Action* addHeldAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu = {}, const QKeySequence& = {});
|
||||
std::shared_ptr<Action> addHeldAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu = {}, const QKeySequence& = {});
|
||||
|
||||
Action* addHiddenAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});
|
||||
template<typename T, typename V> Action* addHiddenAction(const QString& visibleName, const QString& name, T* obj, V (T::*method)(), const QString& menu = {}, const QKeySequence& = {});
|
||||
std::shared_ptr<Action> addHiddenAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});
|
||||
template<typename T, typename V> std::shared_ptr<Action> addHiddenAction(const QString& visibleName, const QString& name, T* obj, V (T::*method)(), const QString& menu = {}, const QKeySequence& = {});
|
||||
|
||||
bool isHeld(const QString& name) const { return m_heldActions.contains(name); }
|
||||
|
||||
|
@ -51,7 +52,7 @@ public:
|
|||
QString menuFor(const QString& action) const;
|
||||
QString menuName(const QString& menu) const;
|
||||
|
||||
Action* getAction(const QString& action);
|
||||
std::shared_ptr<Action> getAction(const QString& action);
|
||||
QKeySequence defaultShortcut(const QString& action);
|
||||
|
||||
signals:
|
||||
|
@ -60,9 +61,9 @@ signals:
|
|||
|
||||
private:
|
||||
void rebuildMenu(const QString& menu, QMenu* qmenu, QWidget* context, const ShortcutController&);
|
||||
Action* addAction(const Action& act, const QString& name, const QString& menu, const QKeySequence& shortcut);
|
||||
std::shared_ptr<Action> addAction(const Action& act, const QString& name, const QString& menu, const QKeySequence& shortcut);
|
||||
|
||||
QHash<QString, Action> m_actions;
|
||||
QHash<QString, std::shared_ptr<Action>> m_actions;
|
||||
QHash<QString, QStringList> m_menus;
|
||||
QHash<QString, QString> m_reverseMenus;
|
||||
QHash<QString, QString> m_menuNames;
|
||||
|
@ -72,14 +73,14 @@ private:
|
|||
};
|
||||
|
||||
template<typename T, typename V>
|
||||
Action* ActionMapper::addAction(const QString& visibleName, const QString& name, T* obj, V (T::*method)(), const QString& menu, const QKeySequence& shortcut) {
|
||||
std::shared_ptr<Action> ActionMapper::addAction(const QString& visibleName, const QString& name, T* obj, V (T::*method)(), const QString& menu, const QKeySequence& shortcut) {
|
||||
return addAction(visibleName, name, [method, obj]() -> void {
|
||||
(obj->*method)();
|
||||
}, menu, shortcut);
|
||||
}
|
||||
|
||||
template<typename T, typename V>
|
||||
Action* ActionMapper::addHiddenAction(const QString& visibleName, const QString& name, T* obj, V (T::*method)(), const QString& menu, const QKeySequence& shortcut) {
|
||||
std::shared_ptr<Action> ActionMapper::addHiddenAction(const QString& visibleName, const QString& name, T* obj, V (T::*method)(), const QString& menu, const QKeySequence& shortcut) {
|
||||
m_hiddenActions.insert(name);
|
||||
return addAction(visibleName, name, obj, method, menu, shortcut);
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ void ConfigOption::connect(std::function<void(const QVariant&)> slot, QObject* p
|
|||
});
|
||||
}
|
||||
|
||||
Action* ConfigOption::addValue(const QString& text, const QVariant& value, ActionMapper* actions, const QString& menu) {
|
||||
Action* action;
|
||||
std::shared_ptr<Action> ConfigOption::addValue(const QString& text, const QVariant& value, ActionMapper* actions, const QString& menu) {
|
||||
std::shared_ptr<Action> action;
|
||||
auto function = [this, value]() {
|
||||
emit valueChanged(value);
|
||||
};
|
||||
|
@ -46,32 +46,32 @@ Action* ConfigOption::addValue(const QString& text, const QVariant& value, Actio
|
|||
if (actions) {
|
||||
action = actions->addAction(text, name, function, menu);
|
||||
} else {
|
||||
action = new Action(function, name, text, this);
|
||||
action = std::make_shared<Action>(function, name, text, this);
|
||||
}
|
||||
action->setExclusive();
|
||||
QObject::connect(action, &QObject::destroyed, this, [this, action, value]() {
|
||||
QObject::connect(action.get(), &QObject::destroyed, this, [this, action, value]() {
|
||||
m_actions.removeAll(std::make_pair(action, value));
|
||||
});
|
||||
m_actions.append(std::make_pair(action, value));
|
||||
return action;
|
||||
}
|
||||
|
||||
Action* ConfigOption::addValue(const QString& text, const char* value, ActionMapper* actions, const QString& menu) {
|
||||
std::shared_ptr<Action> ConfigOption::addValue(const QString& text, const char* value, ActionMapper* actions, const QString& menu) {
|
||||
return addValue(text, QString(value), actions, menu);
|
||||
}
|
||||
|
||||
Action* ConfigOption::addBoolean(const QString& text, ActionMapper* actions, const QString& menu) {
|
||||
Action* action;
|
||||
std::shared_ptr<Action> ConfigOption::addBoolean(const QString& text, ActionMapper* actions, const QString& menu) {
|
||||
std::shared_ptr<Action> action;
|
||||
auto function = [this](bool value) {
|
||||
emit valueChanged(value);
|
||||
};
|
||||
if (actions) {
|
||||
action = actions->addBooleanAction(text, m_name, function, menu);
|
||||
} else {
|
||||
action = new Action(function, m_name, text, this);
|
||||
action = std::make_shared<Action>(function, m_name, text, this);
|
||||
}
|
||||
|
||||
QObject::connect(action, &QObject::destroyed, this, [this, action]() {
|
||||
QObject::connect(action.get(), &QObject::destroyed, this, [this, action]() {
|
||||
m_actions.removeAll(std::make_pair(action, QVariant(1)));
|
||||
});
|
||||
m_actions.append(std::make_pair(action, QVariant(1)));
|
||||
|
@ -96,7 +96,7 @@ void ConfigOption::setValue(const char* value) {
|
|||
}
|
||||
|
||||
void ConfigOption::setValue(const QVariant& value) {
|
||||
for (std::pair<Action*, QVariant>& action : m_actions) {
|
||||
for (std::pair<std::shared_ptr<Action>, QVariant>& action : m_actions) {
|
||||
action.first->setActive(value == action.second);
|
||||
}
|
||||
for (std::function<void(const QVariant&)>& slot : m_slots.values()) {
|
||||
|
|
|
@ -38,9 +38,9 @@ public:
|
|||
|
||||
void connect(std::function<void(const QVariant&)>, QObject* parent = nullptr);
|
||||
|
||||
Action* addValue(const QString& text, const QVariant& value, ActionMapper* actions = nullptr, const QString& menu = {});
|
||||
Action* addValue(const QString& text, const char* value, ActionMapper* actions = nullptr, const QString& menu = {});
|
||||
Action* addBoolean(const QString& text, ActionMapper* actions = nullptr, const QString& menu = {});
|
||||
std::shared_ptr<Action> addValue(const QString& text, const QVariant& value, ActionMapper* actions = nullptr, const QString& menu = {});
|
||||
std::shared_ptr<Action> addValue(const QString& text, const char* value, ActionMapper* actions = nullptr, const QString& menu = {});
|
||||
std::shared_ptr<Action> addBoolean(const QString& text, ActionMapper* actions = nullptr, const QString& menu = {});
|
||||
|
||||
QString name() const { return m_name; }
|
||||
|
||||
|
@ -56,7 +56,7 @@ signals:
|
|||
|
||||
private:
|
||||
QHash<QObject*, std::function<void(const QVariant&)>> m_slots;
|
||||
QList<std::pair<Action*, QVariant>> m_actions;
|
||||
QList<std::pair<std::shared_ptr<Action>, QVariant>> m_actions;
|
||||
QString m_name;
|
||||
};
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ bool ShortcutController::eventFilter(QObject* obj, QEvent* event) {
|
|||
if (item == m_buttons.end()) {
|
||||
return false;
|
||||
}
|
||||
Action* action = item.value()->action();
|
||||
auto action = item.value()->action();
|
||||
if (action) {
|
||||
if (m_actions->isHeld(action->name())) {
|
||||
action->trigger(true);
|
||||
|
@ -193,7 +193,7 @@ bool ShortcutController::eventFilter(QObject* obj, QEvent* event) {
|
|||
if (item == m_buttons.end()) {
|
||||
return false;
|
||||
}
|
||||
Action* action = item.value()->action();
|
||||
auto action = item.value()->action();
|
||||
if (action && m_actions->isHeld(action->name())) {
|
||||
action->trigger(false);
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ bool ShortcutController::eventFilter(QObject* obj, QEvent* event) {
|
|||
if (item == m_axes.end()) {
|
||||
return false;
|
||||
}
|
||||
Action* action = item.value()->action();
|
||||
auto action = item.value()->action();
|
||||
if (action) {
|
||||
if (gae->isNew()) {
|
||||
if (m_actions->isHeld(action->name())) {
|
||||
|
@ -235,7 +235,7 @@ void ShortcutController::generateItem(const QString& itemName) {
|
|||
if (itemName.isNull() || itemName[0] == '.') {
|
||||
return;
|
||||
}
|
||||
Action* action = m_actions->getAction(itemName);
|
||||
auto action = m_actions->getAction(itemName);
|
||||
if (action) {
|
||||
std::shared_ptr<Shortcut> item = std::make_shared<Shortcut>(action);
|
||||
m_items[itemName] = item;
|
||||
|
@ -462,7 +462,7 @@ int ShortcutController::count(const QString& name) const {
|
|||
return menu.count();
|
||||
}
|
||||
|
||||
Shortcut::Shortcut(Action* action)
|
||||
Shortcut::Shortcut(std::shared_ptr<Action> action)
|
||||
: m_action(action)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -27,10 +27,10 @@ class Shortcut : public QObject {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Shortcut(Action* action);
|
||||
Shortcut(std::shared_ptr<Action> action);
|
||||
|
||||
Action* action() { return m_action; }
|
||||
const Action* action() const { return m_action; }
|
||||
std::shared_ptr<Action> action() { return m_action; }
|
||||
const std::shared_ptr<Action> action() const { return m_action; }
|
||||
int shortcut() const { return m_shortcut; }
|
||||
QString visibleName() const { return m_action ? m_action->visibleName() : QString(); }
|
||||
QString name() const { return m_action ? m_action->name() : QString(); }
|
||||
|
@ -53,7 +53,7 @@ signals:
|
|||
void axisChanged(int axis, GamepadAxisEvent::Direction direction);
|
||||
|
||||
private:
|
||||
Action* m_action = nullptr;
|
||||
std::shared_ptr<Action> m_action;
|
||||
int m_shortcut = 0;
|
||||
int m_button = -1;
|
||||
int m_axis = -1;
|
||||
|
|
|
@ -416,7 +416,7 @@ void Window::multiplayerChanged() {
|
|||
attached = multiplayer->attached();
|
||||
m_playerId = multiplayer->playerId(m_controller.get());
|
||||
}
|
||||
for (Action* action : m_nonMpActions) {
|
||||
for (auto action : m_nonMpActions) {
|
||||
action->setEnabled(attached < 2);
|
||||
}
|
||||
}
|
||||
|
@ -692,7 +692,7 @@ void Window::resizeEvent(QResizeEvent*) {
|
|||
factor = newSize.width() / size.width();
|
||||
}
|
||||
m_savedScale = factor;
|
||||
for (QMap<int, Action*>::iterator iter = m_frameSizes.begin(); iter != m_frameSizes.end(); ++iter) {
|
||||
for (QMap<int, std::shared_ptr<Action>>::iterator iter = m_frameSizes.begin(); iter != m_frameSizes.end(); ++iter) {
|
||||
iter.value()->setActive(iter.key() == factor);
|
||||
}
|
||||
|
||||
|
@ -848,7 +848,7 @@ void Window::toggleFullScreen() {
|
|||
}
|
||||
|
||||
void Window::gameStarted() {
|
||||
for (Action* action : m_gameActions) {
|
||||
for (auto action : m_gameActions) {
|
||||
action->setEnabled(true);
|
||||
}
|
||||
for (auto action = m_platformActions.begin(); action != m_platformActions.end(); ++action) {
|
||||
|
@ -896,7 +896,7 @@ void Window::gameStarted() {
|
|||
|
||||
if (nVideo) {
|
||||
for (size_t i = 0; i < nVideo; ++i) {
|
||||
Action* action = m_actions.addBooleanAction(videoLayers[i].visibleName, QString("videoLayer.%1").arg(videoLayers[i].internalName), [this, videoLayers, i](bool enable) {
|
||||
auto action = m_actions.addBooleanAction(videoLayers[i].visibleName, QString("videoLayer.%1").arg(videoLayers[i].internalName), [this, videoLayers, i](bool enable) {
|
||||
m_controller->thread()->core->enableVideoLayer(m_controller->thread()->core, videoLayers[i].id, enable);
|
||||
}, "videoLayers");
|
||||
action->setActive(true);
|
||||
|
@ -904,7 +904,7 @@ void Window::gameStarted() {
|
|||
}
|
||||
if (nAudio) {
|
||||
for (size_t i = 0; i < nAudio; ++i) {
|
||||
Action* action = m_actions.addBooleanAction(audioChannels[i].visibleName, QString("audioChannel.%1").arg(audioChannels[i].internalName), [this, audioChannels, i](bool enable) {
|
||||
auto action = m_actions.addBooleanAction(audioChannels[i].visibleName, QString("audioChannel.%1").arg(audioChannels[i].internalName), [this, audioChannels, i](bool enable) {
|
||||
m_controller->thread()->core->enableAudioChannel(m_controller->thread()->core, audioChannels[i].id, enable);
|
||||
}, "audioChannels");
|
||||
action->setActive(true);
|
||||
|
@ -929,10 +929,10 @@ void Window::gameStarted() {
|
|||
}
|
||||
|
||||
void Window::gameStopped() {
|
||||
for (Action* action : m_platformActions) {
|
||||
for (auto action : m_platformActions) {
|
||||
action->setEnabled(true);
|
||||
}
|
||||
for (Action* action : m_gameActions) {
|
||||
for (auto action : m_gameActions) {
|
||||
action->setEnabled(false);
|
||||
}
|
||||
setWindowFilePath(QString());
|
||||
|
@ -1181,11 +1181,11 @@ void Window::updateTitle(float fps) {
|
|||
MultiplayerController* multiplayer = m_controller->multiplayerController();
|
||||
if (multiplayer && multiplayer->attached() > 1) {
|
||||
title += tr(" - Player %1 of %2").arg(m_playerId + 1).arg(multiplayer->attached());
|
||||
for (Action* action : m_nonMpActions) {
|
||||
for (auto action : m_nonMpActions) {
|
||||
action->setEnabled(false);
|
||||
}
|
||||
} else {
|
||||
for (Action* action : m_nonMpActions) {
|
||||
for (auto action : m_nonMpActions) {
|
||||
action->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
@ -1286,15 +1286,15 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
m_actions.addAction(tr("Convert save game..."), "convertSave", openControllerTView<SaveConverter>(), "saves");
|
||||
|
||||
#ifdef M_CORE_GBA
|
||||
Action* importShark = addGameAction(tr("Import GameShark Save..."), "importShark", this, &Window::importSharkport, "saves");
|
||||
auto importShark = addGameAction(tr("Import GameShark Save..."), "importShark", this, &Window::importSharkport, "saves");
|
||||
m_platformActions.insert(mPLATFORM_GBA, importShark);
|
||||
|
||||
Action* exportShark = addGameAction(tr("Export GameShark Save..."), "exportShark", this, &Window::exportSharkport, "saves");
|
||||
auto exportShark = addGameAction(tr("Export GameShark Save..."), "exportShark", this, &Window::exportSharkport, "saves");
|
||||
m_platformActions.insert(mPLATFORM_GBA, exportShark);
|
||||
#endif
|
||||
|
||||
m_actions.addSeparator("saves");
|
||||
Action* savePlayerAction;
|
||||
std::shared_ptr<Action> savePlayerAction;
|
||||
ConfigOption* savePlayer = m_config->addOption("savePlayerId");
|
||||
savePlayerAction = savePlayer->addValue(tr("Automatically determine"), 0, &m_actions, "saves");
|
||||
m_nonMpActions.append(savePlayerAction);
|
||||
|
@ -1317,7 +1317,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
#endif
|
||||
|
||||
#ifdef M_CORE_GBA
|
||||
Action* scanCard = addGameAction(tr("Scan e-Reader dotcodes..."), "scanCard", this, &Window::scanCard, "file");
|
||||
auto scanCard = addGameAction(tr("Scan e-Reader dotcodes..."), "scanCard", this, &Window::scanCard, "file");
|
||||
m_platformActions.insert(mPLATFORM_GBA, scanCard);
|
||||
#endif
|
||||
|
||||
|
@ -1326,22 +1326,22 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
m_actions.addMenu(tr("Recent"), "mru", "file");
|
||||
m_actions.addSeparator("file");
|
||||
|
||||
Action* loadState = addGameAction(tr("&Load state"), "loadState", [this]() {
|
||||
auto loadState = addGameAction(tr("&Load state"), "loadState", [this]() {
|
||||
this->openStateWindow(LoadSave::LOAD);
|
||||
}, "file", QKeySequence("F10"));
|
||||
m_nonMpActions.append(loadState);
|
||||
|
||||
Action* loadStateFile = addGameAction(tr("Load state file..."), "loadStateFile", [this]() {
|
||||
auto loadStateFile = addGameAction(tr("Load state file..."), "loadStateFile", [this]() {
|
||||
this->selectState(true);
|
||||
}, "file");
|
||||
m_nonMpActions.append(loadStateFile);
|
||||
|
||||
Action* saveState = addGameAction(tr("&Save state"), "saveState", [this]() {
|
||||
auto saveState = addGameAction(tr("&Save state"), "saveState", [this]() {
|
||||
this->openStateWindow(LoadSave::SAVE);
|
||||
}, "file", QKeySequence("Shift+F10"));
|
||||
m_nonMpActions.append(saveState);
|
||||
|
||||
Action* saveStateFile = addGameAction(tr("Save state file..."), "saveStateFile", [this]() {
|
||||
auto saveStateFile = addGameAction(tr("Save state file..."), "saveStateFile", [this]() {
|
||||
this->selectState(false);
|
||||
}, "file");
|
||||
m_nonMpActions.append(saveStateFile);
|
||||
|
@ -1349,12 +1349,12 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
m_actions.addMenu(tr("Quick load"), "quickLoad", "file");
|
||||
m_actions.addMenu(tr("Quick save"), "quickSave", "file");
|
||||
|
||||
Action* quickLoad = addGameAction(tr("Load recent"), "quickLoad", [this] {
|
||||
auto quickLoad = addGameAction(tr("Load recent"), "quickLoad", [this] {
|
||||
m_controller->loadState();
|
||||
}, "quickLoad");
|
||||
m_nonMpActions.append(quickLoad);
|
||||
|
||||
Action* quickSave = addGameAction(tr("Save recent"), "quickSave", [this] {
|
||||
auto quickSave = addGameAction(tr("Save recent"), "quickSave", [this] {
|
||||
m_controller->saveState();
|
||||
}, "quickSave");
|
||||
m_nonMpActions.append(quickSave);
|
||||
|
@ -1362,22 +1362,22 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
m_actions.addSeparator("quickLoad");
|
||||
m_actions.addSeparator("quickSave");
|
||||
|
||||
Action* undoLoadState = addGameAction(tr("Undo load state"), "undoLoadState", &CoreController::loadBackupState, "quickLoad", QKeySequence("F11"));
|
||||
auto undoLoadState = addGameAction(tr("Undo load state"), "undoLoadState", &CoreController::loadBackupState, "quickLoad", QKeySequence("F11"));
|
||||
m_nonMpActions.append(undoLoadState);
|
||||
|
||||
Action* undoSaveState = addGameAction(tr("Undo save state"), "undoSaveState", &CoreController::saveBackupState, "quickSave", QKeySequence("Shift+F11"));
|
||||
auto undoSaveState = addGameAction(tr("Undo save state"), "undoSaveState", &CoreController::saveBackupState, "quickSave", QKeySequence("Shift+F11"));
|
||||
m_nonMpActions.append(undoSaveState);
|
||||
|
||||
m_actions.addSeparator("quickLoad");
|
||||
m_actions.addSeparator("quickSave");
|
||||
|
||||
for (int i = 1; i < 10; ++i) {
|
||||
Action* quickLoad = addGameAction(tr("State &%1").arg(i), QString("quickLoad.%1").arg(i), [this, i]() {
|
||||
auto quickLoad = addGameAction(tr("State &%1").arg(i), QString("quickLoad.%1").arg(i), [this, i]() {
|
||||
m_controller->loadState(i);
|
||||
}, "quickLoad", QString("F%1").arg(i));
|
||||
m_nonMpActions.append(quickLoad);
|
||||
|
||||
Action* quickSave = addGameAction(tr("State &%1").arg(i), QString("quickSave.%1").arg(i), [this, i]() {
|
||||
auto quickSave = addGameAction(tr("State &%1").arg(i), QString("quickSave.%1").arg(i), [this, i]() {
|
||||
m_controller->saveState(i);
|
||||
}, "quickSave", QString("Shift+F%1").arg(i));
|
||||
m_nonMpActions.append(quickSave);
|
||||
|
@ -1387,7 +1387,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
m_multiWindow = m_actions.addAction(tr("New multiplayer window"), "multiWindow", GBAApp::app(), &GBAApp::newWindow, "file");
|
||||
|
||||
#ifdef M_CORE_GBA
|
||||
Action* dolphin = m_actions.addAction(tr("Connect to Dolphin..."), "connectDolphin", openNamedTView<DolphinConnector>(&m_dolphinView, this), "file");
|
||||
auto dolphin = m_actions.addAction(tr("Connect to Dolphin..."), "connectDolphin", openNamedTView<DolphinConnector>(&m_dolphinView, this), "file");
|
||||
m_platformActions.insert(mPLATFORM_GBA, dolphin);
|
||||
#endif
|
||||
|
||||
|
@ -1411,14 +1411,14 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
addGameAction(tr("Yank game pak"), "yank", &CoreController::yankPak, "emu");
|
||||
m_actions.addSeparator("emu");
|
||||
|
||||
Action* pause = m_actions.addBooleanAction(tr("&Pause"), "pause", [this](bool paused) {
|
||||
auto pause = m_actions.addBooleanAction(tr("&Pause"), "pause", [this](bool paused) {
|
||||
if (m_controller) {
|
||||
m_controller->setPaused(paused);
|
||||
} else {
|
||||
m_pendingPause = paused;
|
||||
}
|
||||
}, "emu", QKeySequence("Ctrl+P"));
|
||||
connect(this, &Window::paused, pause, &Action::setActive);
|
||||
connect(this, &Window::paused, pause.get(), &Action::setActive);
|
||||
|
||||
addGameAction(tr("&Next frame"), "frameAdvance", &CoreController::frameAdvance, "emu", QKeySequence("Ctrl+N"));
|
||||
|
||||
|
@ -1461,19 +1461,19 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
}
|
||||
}, "emu");
|
||||
|
||||
Action* rewindHeld = m_actions.addHeldAction(tr("Rewind (held)"), "holdRewind", [this](bool held) {
|
||||
auto rewindHeld = m_actions.addHeldAction(tr("Rewind (held)"), "holdRewind", [this](bool held) {
|
||||
if (m_controller) {
|
||||
m_controller->setRewinding(held);
|
||||
}
|
||||
}, "emu", QKeySequence("`"));
|
||||
m_nonMpActions.append(rewindHeld);
|
||||
|
||||
Action* rewind = addGameAction(tr("Re&wind"), "rewind", [this]() {
|
||||
auto rewind = addGameAction(tr("Re&wind"), "rewind", [this]() {
|
||||
m_controller->rewind();
|
||||
}, "emu", QKeySequence("~"));
|
||||
m_nonMpActions.append(rewind);
|
||||
|
||||
Action* frameRewind = addGameAction(tr("Step backwards"), "frameRewind", [this] () {
|
||||
auto frameRewind = addGameAction(tr("Step backwards"), "frameRewind", [this] () {
|
||||
m_controller->rewind(1);
|
||||
}, "emu", QKeySequence("Ctrl+B"));
|
||||
m_nonMpActions.append(frameRewind);
|
||||
|
@ -1500,7 +1500,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
#ifdef M_CORE_GB
|
||||
m_actions.addAction(tr("Load camera image..."), "loadCamImage", this, &Window::loadCamImage, "emu");
|
||||
|
||||
Action* gbPrint = addGameAction(tr("Game Boy Printer..."), "gbPrint", [this]() {
|
||||
auto gbPrint = addGameAction(tr("Game Boy Printer..."), "gbPrint", [this]() {
|
||||
PrinterView* view = new PrinterView(m_controller);
|
||||
openView(view);
|
||||
m_controller->attachPrinter();
|
||||
|
@ -1509,15 +1509,15 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
#endif
|
||||
|
||||
#ifdef M_CORE_GBA
|
||||
Action* bcGate = addGameAction(tr("BattleChip Gate..."), "bcGate", openControllerTView<BattleChipView>(this), "emu");
|
||||
auto bcGate = addGameAction(tr("BattleChip Gate..."), "bcGate", openControllerTView<BattleChipView>(this), "emu");
|
||||
m_platformActions.insert(mPLATFORM_GBA, bcGate);
|
||||
#endif
|
||||
|
||||
m_actions.addMenu(tr("Audio/&Video"), "av");
|
||||
m_actions.addMenu(tr("Frame size"), "frame", "av");
|
||||
for (int i = 1; i <= 8; ++i) {
|
||||
Action* setSize = m_actions.addAction(tr("%1×").arg(QString::number(i)), QString("frame.%1x").arg(QString::number(i)), [this, i]() {
|
||||
Action* setSize = m_frameSizes[i];
|
||||
auto setSize = m_actions.addAction(tr("%1×").arg(QString::number(i)), QString("frame.%1x").arg(QString::number(i)), [this, i]() {
|
||||
auto setSize = m_frameSizes[i];
|
||||
showNormal();
|
||||
QSize size(GBA_VIDEO_HORIZONTAL_PIXELS, GBA_VIDEO_VERTICAL_PIXELS);
|
||||
if (m_display) {
|
||||
|
@ -1598,7 +1598,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
m_actions.addSeparator("av");
|
||||
|
||||
ConfigOption* mute = m_config->addOption("mute");
|
||||
Action* muteAction = mute->addBoolean(tr("Mute"), &m_actions, "av");
|
||||
auto muteAction = mute->addBoolean(tr("Mute"), &m_actions, "av");
|
||||
muteAction->setActive(m_config->getOption("mute").toInt());
|
||||
mute->connect([this](const QVariant& value) {
|
||||
m_config->setOption("fastForwardMute", static_cast<bool>(value.toInt()));
|
||||
|
@ -1607,7 +1607,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
|
||||
m_actions.addMenu(tr("FPS target"),"target", "av");
|
||||
ConfigOption* fpsTargetOption = m_config->addOption("fpsTarget");
|
||||
QMap<double, Action*> fpsTargets;
|
||||
QMap<double, std::shared_ptr<Action>> fpsTargets;
|
||||
for (int fps : {15, 30, 45, 60, 90, 120, 240}) {
|
||||
fpsTargets[fps] = fpsTargetOption->addValue(QString::number(fps), fps, &m_actions, "target");
|
||||
}
|
||||
|
@ -1676,7 +1676,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
#ifdef USE_DEBUGGERS
|
||||
m_actions.addAction(tr("Open debugger console..."), "debuggerWindow", this, &Window::consoleOpen, "tools");
|
||||
#ifdef USE_GDB_STUB
|
||||
Action* gdbWindow = addGameAction(tr("Start &GDB server..."), "gdbWindow", this, &Window::gdbOpen, "tools");
|
||||
auto gdbWindow = addGameAction(tr("Start &GDB server..."), "gdbWindow", this, &Window::gdbOpen, "tools");
|
||||
m_platformActions.insert(mPLATFORM_GBA, gdbWindow);
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1781,7 +1781,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
}
|
||||
}, "autofire");
|
||||
|
||||
for (Action* action : m_gameActions) {
|
||||
for (auto action : m_gameActions) {
|
||||
action->setEnabled(false);
|
||||
}
|
||||
|
||||
|
@ -1973,8 +1973,8 @@ void Window::updateMRU() {
|
|||
m_actions.rebuildMenu(menuBar(), this, *m_shortcutController);
|
||||
}
|
||||
|
||||
Action* Window::addGameAction(const QString& visibleName, const QString& name, Action::Function function, const QString& menu, const QKeySequence& shortcut) {
|
||||
Action* action = m_actions.addAction(visibleName, name, [this, function]() {
|
||||
std::shared_ptr<Action> Window::addGameAction(const QString& visibleName, const QString& name, Action::Function function, const QString& menu, const QKeySequence& shortcut) {
|
||||
auto action = m_actions.addAction(visibleName, name, [this, function]() {
|
||||
if (m_controller) {
|
||||
function();
|
||||
}
|
||||
|
@ -1984,21 +1984,21 @@ Action* Window::addGameAction(const QString& visibleName, const QString& name, A
|
|||
}
|
||||
|
||||
template<typename T, typename V>
|
||||
Action* Window::addGameAction(const QString& visibleName, const QString& name, T* obj, V (T::*method)(), const QString& menu, const QKeySequence& shortcut) {
|
||||
std::shared_ptr<Action> Window::addGameAction(const QString& visibleName, const QString& name, T* obj, V (T::*method)(), const QString& menu, const QKeySequence& shortcut) {
|
||||
return addGameAction(visibleName, name, [obj, method]() {
|
||||
(obj->*method)();
|
||||
}, menu, shortcut);
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
Action* Window::addGameAction(const QString& visibleName, const QString& name, V (CoreController::*method)(), const QString& menu, const QKeySequence& shortcut) {
|
||||
std::shared_ptr<Action> Window::addGameAction(const QString& visibleName, const QString& name, V (CoreController::*method)(), const QString& menu, const QKeySequence& shortcut) {
|
||||
return addGameAction(visibleName, name, [this, method]() {
|
||||
(m_controller.get()->*method)();
|
||||
}, menu, shortcut);
|
||||
}
|
||||
|
||||
Action* Window::addGameAction(const QString& visibleName, const QString& name, Action::BooleanFunction function, const QString& menu, const QKeySequence& shortcut) {
|
||||
Action* action = m_actions.addBooleanAction(visibleName, name, [this, function](bool value) {
|
||||
std::shared_ptr<Action> Window::addGameAction(const QString& visibleName, const QString& name, Action::BooleanFunction function, const QString& menu, const QKeySequence& shortcut) {
|
||||
auto action = m_actions.addBooleanAction(visibleName, name, [this, function](bool value) {
|
||||
if (m_controller) {
|
||||
function(value);
|
||||
}
|
||||
|
|
|
@ -179,10 +179,10 @@ private:
|
|||
template <typename T, typename... A> std::function<void()> openNamedTView(std::unique_ptr<T>*, A... arg);
|
||||
template <typename T, typename... A> std::function<void()> openNamedControllerTView(std::unique_ptr<T>*, A... arg);
|
||||
|
||||
Action* addGameAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});
|
||||
template<typename T, typename V> Action* addGameAction(const QString& visibleName, const QString& name, T* obj, V (T::*action)(), const QString& menu = {}, const QKeySequence& = {});
|
||||
template<typename V> Action* addGameAction(const QString& visibleName, const QString& name, V (CoreController::*action)(), const QString& menu = {}, const QKeySequence& = {});
|
||||
Action* addGameAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu = {}, const QKeySequence& = {});
|
||||
std::shared_ptr<Action> addGameAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});
|
||||
template<typename T, typename V> std::shared_ptr<Action> addGameAction(const QString& visibleName, const QString& name, T* obj, V (T::*action)(), const QString& menu = {}, const QKeySequence& = {});
|
||||
template<typename V> std::shared_ptr<Action> addGameAction(const QString& visibleName, const QString& name, V (CoreController::*action)(), const QString& menu = {}, const QKeySequence& = {});
|
||||
std::shared_ptr<Action> addGameAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu = {}, const QKeySequence& = {});
|
||||
|
||||
void updateTitle(float fps = -1);
|
||||
|
||||
|
@ -198,13 +198,11 @@ private:
|
|||
|
||||
// TODO: Move these to a new class
|
||||
ActionMapper m_actions;
|
||||
QList<Action*> m_gameActions;
|
||||
QList<Action*> m_nonMpActions;
|
||||
#ifdef M_CORE_GBA
|
||||
QMultiMap<mPlatform, Action*> m_platformActions;
|
||||
#endif
|
||||
Action* m_multiWindow;
|
||||
QMap<int, Action*> m_frameSizes;
|
||||
QList<std::shared_ptr<Action>> m_gameActions;
|
||||
QList<std::shared_ptr<Action>> m_nonMpActions;
|
||||
QMultiMap<mPlatform, std::shared_ptr<Action>> m_platformActions;
|
||||
std::shared_ptr<Action> m_multiWindow;
|
||||
QMap<int, std::shared_ptr<Action>> m_frameSizes;
|
||||
|
||||
LogController m_log{0};
|
||||
LogView* m_logView;
|
||||
|
|
Loading…
Reference in New Issue