Add an element picker that opens at the cursor

Insert opens a small picker where the mouse is, with its search field
focused. Type to search the whole collection, Enter to place the best
hit (it is preselected), Up/Down to choose another, Esc to close. The
chosen element goes into the usual placement mode, so it can be placed
several times and repeated with A.

With the field empty the picker shows a palette: the elements of a
folder, as an icon grid. The palette is a folder rather than a setting
or a file format. Subfolders are read in, the 01_/02_ filename prefixes
the shipped collection already uses give the order, and sharing it is
putting it in the company collection. Only the path is stored,
"elementscollection/palette-path", defaulting to the user collection.
It is read each time the picker opens, capped at 60 entries and three
folder levels.

The picker builds no second collection model. It asks the Collections
panel's rankedSearch(), so both give the same results in the same order
and startup is unchanged.

"Insérer un élément…" is in the Édition menu, registered with
ShortcutManager on Insert, which nothing else uses, and disabled with no
folio open or on a read-only project.

Discussion #676.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
(cherry picked from commit 01e1e0303b96380e710da8d4bb2300b21d01e938)
This commit is contained in:
ispyisail
2026-08-08 17:50:43 +12:00
parent 73ad43bd8f
commit 07501d604e
5 changed files with 455 additions and 0 deletions
+42
View File
@@ -22,6 +22,7 @@
#include <QCoreApplication>
#include <QToolButton>
#include "ElementsCollection/elementscollectionwidget.h"
#include "ElementsCollection/elementpickerpopup.h"
#include "QWidgetAnimation/qwidgetanimation.h"
#include "autoNum/ui/autonumberingdockwidget.h"
#include "conductornumexport.h"
@@ -823,6 +824,22 @@ void QETDiagramEditor::setUpActions()
this, &QETDiagramEditor::insertLastElement);
addAction(m_insert_last_element);
//Cursor-anchored picker. Insert is unbound anywhere in the tree and
//reads correctly for the action, which keeps A free for the far more
//frequent "place the same symbol again".
m_show_element_picker = new QAction(QET::Icons::Add,
tr("Insérer un élément…"), this);
m_show_element_picker->setStatusTip(
tr("Ouvre le sélecteur d'éléments à la position du curseur",
"status bar tip"));
m_show_element_picker->setData("show_element_picker");
ShortcutManager::instance().registerAction(
m_show_element_picker, "diagrameditor.show_element_picker",
tr("Éditeur de schémas"), Qt::Key_Insert);
connect(m_show_element_picker, &QAction::triggered,
this, &QETDiagramEditor::showElementPicker);
addAction(m_show_element_picker);
m_delete_selection->setStatusTip( tr("Enlève les éléments sélectionnés du folio", "status bar tip"));
m_rotate_selection->setStatusTip( tr("Pivote les éléments et textes sélectionnés", "status bar tip"));
m_rotate_group_selection->setStatusTip( tr("Pivote la sélection comme un groupe autour de son centre, au lieu de chaque élément sur place", "status bar tip"));
@@ -1108,6 +1125,7 @@ void QETDiagramEditor::setUpMenu()
menu_edition -> addAction(m_duplicate);
menu_edition -> addAction(m_configure_duplicate);
menu_edition -> addAction(m_insert_last_element);
menu_edition -> addAction(m_show_element_picker);
menu_edition -> addSeparator();
//The same actions the "Ajouter" toolbar holds. They were toolbar-only,
//which left them unreachable for anyone working without a mouse: a
@@ -2016,6 +2034,7 @@ void QETDiagramEditor::slot_updateActions()
m_select_actions_group. setEnabled(opened_diagram);
m_add_item_actions_group. setEnabled(editable_project);
m_insert_last_element-> setEnabled(opened_diagram && editable_project && !m_last_inserted_element.isNull());
m_show_element_picker-> setEnabled(opened_diagram && editable_project);
m_row_column_actions_group. setEnabled(editable_project);
m_background_color_button-> setEnabled(opened_diagram);
m_draw_grid-> setEnabled(opened_diagram);
@@ -3067,6 +3086,29 @@ void QETDiagramEditor::insertLastElement()
insertElementFromCollection(m_last_inserted_element);
}
/**
@brief QETDiagramEditor::showElementPicker
Open the element picker where the mouse is.
Built lazily: most sessions of the diagram editor never open it, and it
holds a list view and a model of its own.
*/
void QETDiagramEditor::showElementPicker()
{
if (!currentDiagramView()) {
return;
}
if (!m_element_picker)
{
m_element_picker = new ElementPickerPopup(m_element_collection_widget,
this);
connect(m_element_picker, &ElementPickerPopup::elementChosen,
this, &QETDiagramEditor::insertElementFromCollection);
}
m_element_picker->popUpAt(QCursor::pos());
}
/**
@brief QETDiagramEditor::generateTerminalBlock
*/