Add a shortcut bar that opens at the cursor with S

Pressing S on a folio opens the element picker at the cursor with a row
of commands above it, chosen by what is selected, like the SolidWorks
shortcut bar:

  nothing selected     insert last element, element picker, text, line,
                       rectangle, terminal strip plan, paste, folio
                       properties
  elements selected    rotate, rotate texts, edit, copy, cut, delete
  only conductors      reset path, edit, delete

Each row is a list of ShortcutManager ids, so any registered command can
go on it and the bar carries no command list of its own. The lists are
in QSettings (diagrameditor/shortcut_bar/<context>); a context the user
has not changed follows the defaults. A disabled command keeps its
place, greyed, so a row looks the same each time. Clicking a button
closes the bar and triggers the action.

A new configuration page, "Barre de raccourcis", edits the three lists:
add, remove and reorder any diagram editor command.

To make that possible:
- ShortcutManager::action(id, owner) returns the action a given window
  registered under an id, since each editor window registers its own.
- The add-item actions (text, image, shapes, terminal strip plan) are
  registered as diagrameditor.add_<kind>, with no default key. They also
  appear in the Shortcuts page and can now be bound.

Discussion #1033.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
(cherry picked from commit 53c1e213282b9f7226ca1c09e81703113236bb88)
This commit is contained in:
ispyisail
2026-09-26 12:38:40 +12:00
parent 07501d604e
commit 2da101ca90
12 changed files with 659 additions and 13 deletions
+33
View File
@@ -197,3 +197,36 @@ bool ShortcutManager::trigger(const QString &id) const
}
return false;
}
/**
@return the QAction registered under @a id that belongs to @a owner --
that is, has @a owner among its ancestors -- or nullptr. Several windows
of the same kind each register their own action under one id, so a
window asking for "its" action has to say which window it is.
@param id
@param owner : the window, or nullptr for the first live action
*/
QAction *ShortcutManager::action(const QString &id, const QObject *owner) const
{
auto it = m_entries.find(id);
if (it == m_entries.end()) {
return nullptr;
}
for (const QPointer<QObject> &target : qAsConst(it->targets))
{
auto *action = qobject_cast<QAction *>(target.data());
if (!action) {
continue;
}
if (!owner) {
return action;
}
for (const QObject *o = action->parent(); o; o = o->parent()) {
if (o == owner) {
return action;
}
}
}
return nullptr;
}