mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-23 07:04:14 +02:00
Pin elements to the shortcut bar
The bar's customising window gets an element search next to the command list. Type part of a name, then drag a hit onto the bar, double-click it, or press Enter to pin the best one. A pinned element shows as its icon among the commands, and clicking it places the element, as the picker does. Pinned elements are saved in the same list as the commands, by collection path (common://, custom://, company://), so the row keeps the user's order. Elements embedded in a project are not offered: their path names the project as loaded now. Elements are offered for the empty-folio bar only; with something selected the bar is for acting on it. Once any element is pinned there, the palette folder grid under the bar is hidden, and comes back while typing a search. Dragging a pinned element off the bar onto the commands, or a double click, removes it. The Preferences page shows pinned elements by name and icon, and removing one there drops it instead of listing it as a command. The customising window is now kept on screen, since it is taller than before. Discussion #1033. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#include "shortcutbarconfigpage.h"
|
||||
|
||||
#include "../../ElementsCollection/elementslocation.h"
|
||||
#include "../../qeticons.h"
|
||||
#include "../../shortcutmanager.h"
|
||||
|
||||
@@ -180,7 +181,14 @@ void ShortcutBarConfigPage::addSelected()
|
||||
void ShortcutBarConfigPage::removeSelected()
|
||||
{
|
||||
for (QListWidgetItem *item : m_chosen->selectedItems()) {
|
||||
m_available->addItem(m_chosen->takeItem(m_chosen->row(item)));
|
||||
QListWidgetItem *taken = m_chosen->takeItem(m_chosen->row(item));
|
||||
//A removed element is not a command to list; it is pinned
|
||||
//again from the bar's own customising window
|
||||
if (ShortcutBarSettings::isElement(taken->data(Qt::UserRole).toString())) {
|
||||
delete taken;
|
||||
} else {
|
||||
m_available->addItem(taken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,15 +216,25 @@ void ShortcutBarConfigPage::resetContext()
|
||||
|
||||
/**
|
||||
@brief ShortcutBarConfigPage::appendItem
|
||||
Add @a id to @a list with the command's text and icon. An id no live
|
||||
action carries (a command from a build without it) is still listed, by
|
||||
its id, so saving does not silently drop it.
|
||||
Add @a id to @a list with the command's text and icon, or a pinned
|
||||
element's name and icon. An id no live action carries (a command from a
|
||||
build without it) is still listed, by its id, so saving does not
|
||||
silently drop it.
|
||||
*/
|
||||
void ShortcutBarConfigPage::appendItem(QListWidget *list, const QString &id)
|
||||
{
|
||||
QAction *action = ShortcutManager::instance().action(id, nullptr);
|
||||
const QString text = m_descriptions.value(id, id);
|
||||
auto *item = new QListWidgetItem(action ? action->icon() : QIcon(), text);
|
||||
QString text = m_descriptions.value(id, id);
|
||||
QIcon icon;
|
||||
if (ShortcutBarSettings::isElement(id)) {
|
||||
const ElementsLocation location(id);
|
||||
if (location.exist()) {
|
||||
text = location.name();
|
||||
icon = location.icon();
|
||||
}
|
||||
} else if (QAction *action = ShortcutManager::instance().action(id, nullptr)) {
|
||||
icon = action->icon();
|
||||
}
|
||||
auto *item = new QListWidgetItem(icon, text);
|
||||
item->setData(Qt::UserRole, id);
|
||||
list->addItem(item);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user