mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-29 22:24:13 +02:00
07501d604e
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)
77 lines
2.2 KiB
C++
77 lines
2.2 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;
|
|
|
|
/**
|
|
@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);
|
|
|
|
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();
|
|
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;
|
|
bool m_palette_mode = true;
|
|
};
|
|
|
|
#endif // ELEMENTPICKERPOPUP_H
|