Files
qelectrotech-source-mirror/sources/ElementsCollection/elementpickerpopup.h
T
ispyisail 2da101ca90 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)
2026-09-26 21:40:19 +12:00

83 lines
2.5 KiB
C++

/*
Copyright 2006-2026 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ELEMENTPICKERPOPUP_H
#define ELEMENTPICKERPOPUP_H
#include "elementslocation.h"
#include <QFrame>
class ElementsCollectionWidget;
class QLineEdit;
class QListView;
class QStandardItemModel;
class QLabel;
class QAction;
class QHBoxLayout;
/**
@brief A cursor-anchored element picker.
Opens where the mouse is, focused on its search field: type to filter,
Enter to place, Esc to close. It is a recall tool, as opposed to the
Collections dock, which is a browsing tool.
It deliberately does not build its own ElementsCollectionModel. Loading the
collection is already the slow part of startup and a second copy would
double it, so the picker asks the dock's widget to run the query -- see
ElementsCollectionWidget::rankedSearch(). That also means the two always
agree on results and ranking.
*/
class ElementPickerPopup : public QFrame
{
Q_OBJECT
public:
explicit ElementPickerPopup(ElementsCollectionWidget *source,
QWidget *parent = nullptr);
void popUpAt(const QPoint &global_pos,
const QList<QAction *> &commands = {});
signals:
/// Emitted when the user picks an element; the popup has closed
void elementChosen(const ElementsLocation &location);
protected:
void keyPressEvent(QKeyEvent *event) override;
private:
void runSearch();
void chooseCurrent();
void showPalette();
void setCommands(const QList<QAction *> &commands);
int loadPaletteDir(const QString &dir_path, const QString &prefix,
int depth);
ElementsCollectionWidget *m_source = nullptr;
QLineEdit *m_search = nullptr;
QListView *m_view = nullptr;
QStandardItemModel *m_model = nullptr;
QLabel *m_hint = nullptr;
QWidget *m_commands = nullptr;
QHBoxLayout *m_commands_layout = nullptr;
bool m_palette_mode = true;
};
#endif // ELEMENTPICKERPOPUP_H