mirror of
https://github.com/overte-org/overte.git
synced 2025-06-19 08:40:17 +02:00
fixed input devices menu exclusivity
This commit is contained in:
parent
65b76869fa
commit
5fe4d06562
2 changed files with 40 additions and 36 deletions
|
@ -555,6 +555,18 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
container->setFocus();
|
container->setFocus();
|
||||||
container->installEventFilter(DependencyManager::get<OffscreenUi>().data());
|
container->installEventFilter(DependencyManager::get<OffscreenUi>().data());
|
||||||
|
|
||||||
|
// must be before initializeGL()
|
||||||
|
_activeInputPlugins.clear();
|
||||||
|
auto inputPlugins = getInputPlugins();
|
||||||
|
foreach(auto inputPlugin, inputPlugins) {
|
||||||
|
QString name = inputPlugin->getName();
|
||||||
|
if (name == KeyboardMouseDevice::NAME) {
|
||||||
|
_keyboardMouseDevice = static_cast<KeyboardMouseDevice*>(inputPlugin.data()); // TODO: this seems super hacky
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateInputModes();
|
||||||
|
|
||||||
_offscreenContext->makeCurrent();
|
_offscreenContext->makeCurrent();
|
||||||
initializeGL();
|
initializeGL();
|
||||||
// initialization continues in initializeGL when OpenGL context is ready
|
// initialization continues in initializeGL when OpenGL context is ready
|
||||||
|
@ -617,16 +629,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
connect(userInputMapper.data(), &UserInputMapper::actionEvent, &_controllerScriptingInterface, &AbstractControllerScriptingInterface::actionEvent);
|
connect(userInputMapper.data(), &UserInputMapper::actionEvent, &_controllerScriptingInterface, &AbstractControllerScriptingInterface::actionEvent);
|
||||||
|
|
||||||
auto inputPlugins = getInputPlugins();
|
|
||||||
foreach(auto inputPlugin, inputPlugins) {
|
|
||||||
QString name = inputPlugin->getName();
|
|
||||||
if (name == KeyboardMouseDevice::NAME) {
|
|
||||||
_keyboardMouseDevice = static_cast<KeyboardMouseDevice*>(inputPlugin.data()); // TODO: this seems super hacky
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//updateInputModes(); // TODO: shouldn't have to call this explicitly
|
|
||||||
|
|
||||||
// Setup the keyboardMouseDevice and the user input mapper with the default bindings
|
// Setup the keyboardMouseDevice and the user input mapper with the default bindings
|
||||||
_keyboardMouseDevice->registerToUserInputMapper(*userInputMapper);
|
_keyboardMouseDevice->registerToUserInputMapper(*userInputMapper);
|
||||||
_keyboardMouseDevice->assignDefaultInputMapping(*userInputMapper);
|
_keyboardMouseDevice->assignDefaultInputMapping(*userInputMapper);
|
||||||
|
@ -5153,42 +5155,45 @@ void Application::updateInputModes() {
|
||||||
auto inputPlugins = getInputPlugins();
|
auto inputPlugins = getInputPlugins();
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
|
|
||||||
InputPluginPointer newInputPlugin = InputPluginPointer(nullptr);
|
InputPluginList newInputPlugins;
|
||||||
InputPluginPointer removedInputPlugin = InputPluginPointer(nullptr);
|
InputPluginList removedInputPlugins;
|
||||||
foreach(InputPluginPointer inputPlugin, inputPlugins) {
|
foreach(auto inputPlugin, inputPlugins) {
|
||||||
QString name = inputPlugin->getName();
|
QString name = inputPlugin->getName();
|
||||||
QAction* action = menu->getActionForOption(name);
|
QAction* action = menu->getActionForOption(name);
|
||||||
if (action->isChecked() && !_activeInputPlugins.contains(inputPlugin)) {
|
if (action->isChecked() && !_activeInputPlugins.contains(inputPlugin)) {
|
||||||
_activeInputPlugins.append(inputPlugin);
|
_activeInputPlugins.append(inputPlugin);
|
||||||
newInputPlugin = inputPlugin;
|
newInputPlugins.append(inputPlugin);
|
||||||
break;
|
|
||||||
} else if (!action->isChecked() && _activeInputPlugins.contains(inputPlugin)) {
|
} else if (!action->isChecked() && _activeInputPlugins.contains(inputPlugin)) {
|
||||||
_activeInputPlugins.removeOne(inputPlugin);
|
_activeInputPlugins.removeOne(inputPlugin);
|
||||||
removedInputPlugin = inputPlugin;
|
removedInputPlugins.append(inputPlugin);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A plugin was checked
|
// A plugin was checked
|
||||||
if (newInputPlugin) {
|
if (newInputPlugins.size() > 0) {
|
||||||
|
foreach(auto newInputPlugin, newInputPlugins) {
|
||||||
newInputPlugin->activate(this);
|
newInputPlugin->activate(this);
|
||||||
newInputPlugin->installEventFilter(qApp);
|
//newInputPlugin->installEventFilter(qApp);
|
||||||
newInputPlugin->installEventFilter(offscreenUi.data());
|
//newInputPlugin->installEventFilter(offscreenUi.data());
|
||||||
} else if (removedInputPlugin) { // A plugin was unchecked
|
}
|
||||||
|
}
|
||||||
|
if (removedInputPlugins.size() > 0) { // A plugin was unchecked
|
||||||
|
foreach(auto removedInputPlugin, removedInputPlugins) {
|
||||||
removedInputPlugin->deactivate();
|
removedInputPlugin->deactivate();
|
||||||
removedInputPlugin->removeEventFilter(qApp);
|
//removedInputPlugin->removeEventFilter(qApp);
|
||||||
removedInputPlugin->removeEventFilter(offscreenUi.data());
|
//removedInputPlugin->removeEventFilter(offscreenUi.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newInputPlugin || removedInputPlugin) {
|
//if (newInputPlugins.size() > 0 || removedInputPlugins.size() > 0) {
|
||||||
if (!_currentInputPluginActions.isEmpty()) {
|
// if (!_currentInputPluginActions.isEmpty()) {
|
||||||
auto menu = Menu::getInstance();
|
// auto menu = Menu::getInstance();
|
||||||
foreach(auto itemInfo, _currentInputPluginActions) {
|
// foreach(auto itemInfo, _currentInputPluginActions) {
|
||||||
menu->removeMenuItem(itemInfo.first, itemInfo.second);
|
// menu->removeMenuItem(itemInfo.first, itemInfo.second);
|
||||||
}
|
// }
|
||||||
_currentInputPluginActions.clear();
|
// _currentInputPluginActions.clear();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::addMenuItem(const QString& path, const QString& name, std::function<void()> onClicked, bool checkable, bool checked, const QString& groupName) {
|
void Application::addMenuItem(const QString& path, const QString& name, std::function<void()> onClicked, bool checkable, bool checked, const QString& groupName) {
|
||||||
|
|
|
@ -31,9 +31,8 @@ static void addInputPluginToMenu(InputPluginPointer inputPlugin, bool active = f
|
||||||
name, 0, true, qApp,
|
name, 0, true, qApp,
|
||||||
SLOT(updateInputModes()));
|
SLOT(updateInputModes()));
|
||||||
inputPluginGroup->addAction(action);
|
inputPluginGroup->addAction(action);
|
||||||
|
inputPluginGroup->setExclusive(false);
|
||||||
Q_ASSERT(menu->menuItemExists(MenuOption::InputMenu, name));
|
Q_ASSERT(menu->menuItemExists(MenuOption::InputMenu, name));
|
||||||
|
|
||||||
qApp->updateInputModes(); // TODO: this should be called automatically
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME move to a plugin manager class
|
// FIXME move to a plugin manager class
|
||||||
|
|
Loading…
Reference in a new issue