From 63fa2c7b63031c232a54a22d6d1a623aa7a832ca Mon Sep 17 00:00:00 2001 From: "Matthew J. Milner" Date: Fri, 23 Feb 2024 11:25:44 +0100 Subject: [PATCH] WIP Add shortcuts for tools Signed-off-by: Matthew J. Milner --- avogadro/mainwindow.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/avogadro/mainwindow.cpp b/avogadro/mainwindow.cpp index e520f007..d1446339 100644 --- a/avogadro/mainwindow.cpp +++ b/avogadro/mainwindow.cpp @@ -78,6 +78,7 @@ #include #include #include +#include #include @@ -1184,10 +1185,26 @@ bool populateTools(T* glWidget) PluginManager* plugin = PluginManager::instance(); QList toolPluginFactories = plugin->pluginFactories(); + + // Initialize counter for shortcuts + int shortcutKey = Qt::Key_1; + foreach (ToolPluginFactory* factory, toolPluginFactories) { ToolPlugin* tool = factory->createInstance(QCoreApplication::instance()); if (tool) glWidget->addTool(tool); + // Create a new shortcut for the tool + QShortcut* shortcut = new QShortcut(QKeySequence(shortcutKey), glWidget); + QObject::connect(shortcut, &QShortcut::activated, [=]() { + glWidget->setActiveTool(tool->objectName()); + // Pretty sure we need one of the below but all out of scope + // this->toolActivated() + // toolActivated() + // this->setActiveTool() + }); + + // Increment the shortcut key for the next tool + ++shortcutKey; } glWidget->setDefaultTool("Navigator"); glWidget->setActiveTool("Navigator");