mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-29 05:44:14 +02:00
Show the selection's commands beside the cursor after a click
After a click that selects something on a folio, a small row of commands appears just above and to the right of the cursor, as the SolidWorks context toolbar does. It fades as the mouse moves away and is gone past 200 pixels; a click elsewhere, the wheel, a key press or an emptied selection hide it too. Clicking a command leaves it up, so rotate can be clicked again. The commands are the shortcut bar's for that selection -- elements or conductors -- at most eight, so customising the bar customises this as well. It is a child of the view's viewport, never a window, and never takes the focus. It is not shown after a drag (moving items, a rubber band), while placing or drawing (Diagram::eventInterfaceIsRunning()), on a read-only folio, or when switched off with the new General option "Afficher les commandes près de la sélection" (diagrameditor/ context_toolbar, on by default). ShortcutBarSettings::contextFor() now decides the context for both the bar and this toolbar. Discussion #1033. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG (cherry picked from commit 78f3c1a2bc5c3cf1f7beae4bd60aefec20847d6d)
This commit is contained in:
@@ -37,6 +37,9 @@
|
||||
#include "utils/conductorcreator.h"
|
||||
#include "undocommand/addgraphicsobjectcommand.h"
|
||||
#include "diagram.h"
|
||||
#include "diagramcontexttoolbar.h"
|
||||
#include "shortcutbarsettings.h"
|
||||
#include "shortcutmanager.h"
|
||||
#include "ElementsCollection/xmlelementcollection.h"
|
||||
#include "NameList/nameslist.h"
|
||||
#include "elementdialog.h"
|
||||
@@ -104,6 +107,13 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) :
|
||||
m_separators.last()->setSeparator(true);
|
||||
}
|
||||
|
||||
m_context_toolbar = new DiagramContextToolbar(viewport());
|
||||
connect(m_diagram, &QGraphicsScene::selectionChanged, this, [this]() {
|
||||
if (m_diagram->selectedItems().isEmpty()) {
|
||||
m_context_toolbar->hide();
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_diagram, &Diagram::showDiagram, this, &DiagramView::showDiagram);
|
||||
connect(m_diagram, &QGraphicsScene::sceneRectChanged, this, &DiagramView::adjustSceneRect);
|
||||
connect(&(m_diagram -> border_and_titleblock), &BorderTitleBlock::informationChanged, this, &DiagramView::updateWindowTitle);
|
||||
@@ -621,6 +631,10 @@ void DiagramView::mousePressEvent(QMouseEvent *e)
|
||||
|
||||
if (m_event_interface && m_event_interface->mousePressEvent(e)) return;
|
||||
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
m_press_pos = e->position().toPoint();
|
||||
}
|
||||
|
||||
//Start drag view when hold the middle button
|
||||
if (e->button() == Qt::MiddleButton)
|
||||
{
|
||||
@@ -777,7 +791,46 @@ void DiagramView::mouseReleaseEvent(QMouseEvent *e)
|
||||
e->accept();
|
||||
}
|
||||
else
|
||||
{
|
||||
QGraphicsView::mouseReleaseEvent(e);
|
||||
|
||||
//A click, not a drag: moving items or a rubber band selection
|
||||
//should not be followed by a toolbar under the mouse.
|
||||
const QPoint pos = e->position().toPoint();
|
||||
if (e->button() == Qt::LeftButton
|
||||
&& (pos - m_press_pos).manhattanLength() < QApplication::startDragDistance()) {
|
||||
showContextToolbar(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief DiagramView::showContextToolbar
|
||||
After a click that leaves something selected, show the shortcut bar's
|
||||
commands for that selection beside the cursor. Not while placing or
|
||||
drawing, nor on a read-only folio, nor when switched off in the
|
||||
configuration.
|
||||
@param viewport_pos : where the click was
|
||||
*/
|
||||
void DiagramView::showContextToolbar(const QPoint &viewport_pos)
|
||||
{
|
||||
const QList<QGraphicsItem *> selection = m_diagram->selectedItems();
|
||||
QETDiagramEditor *qde = diagramEditor();
|
||||
if (selection.isEmpty() || !qde
|
||||
|| m_diagram->isReadOnly() || m_diagram->eventInterfaceIsRunning()
|
||||
|| !DiagramContextToolbar::isEnabled()) {
|
||||
m_context_toolbar->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QAction *> actions;
|
||||
const auto context = ShortcutBarSettings::contextFor(selection);
|
||||
for (const QString &id : ShortcutBarSettings::ids(context)) {
|
||||
if (QAction *action = ShortcutManager::instance().action(id, qde)) {
|
||||
actions << action;
|
||||
}
|
||||
}
|
||||
m_context_toolbar->showAt(viewport_pos, actions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user