Skip to content

Commit

Permalink
WIP Add shortcuts for tools
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew J. Milner <[email protected]>
  • Loading branch information
matterhorn103 committed Feb 23, 2024
1 parent 6dae73a commit 63fa2c7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions avogadro/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#include <QtWidgets/QToolBar>
#include <QtWidgets/QToolButton>
#include <QtWidgets/QTreeView>
#include <QtWidgets/QShortcut>

#include <QScreen>

Expand Down Expand Up @@ -1184,10 +1185,26 @@ bool populateTools(T* glWidget)
PluginManager* plugin = PluginManager::instance();
QList<ToolPluginFactory*> toolPluginFactories =
plugin->pluginFactories<ToolPluginFactory>();

// 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");
Expand Down

0 comments on commit 63fa2c7

Please sign in to comment.