Files
qelectrotech-source-mirror/sources/editor/esevent/eseventinterface.cpp
T
ispyisail 367d168c6f Fix #1177: Space rotated the selection, not the part being added
In the symbol editor, Space is the shortcut of the Rotate action, which
rotates the selected parts. The action is enabled whenever something is
selected, and a window shortcut is handled before the key reaches the
scene, so while a terminal or arc was being placed with something already
selected, Space rotated the selection and never reached ESEventAddTerminal /
ESEventAddArc. With nothing selected the action was disabled and the key
fell through, which is why it only happened with a selection.

The scene now emits behaviorChanged() when it enters or leaves AddPart,
and updateAction() keeps the selection actions (rotate, fine rotate, flip,
mirror, cut, delete, depth) disabled while a part is being added. They come
back when the tool ends. The selection itself is left alone.

ESEventInterface::init() also gives the view keyboard focus: a selection
made in the parts list left the focus there, so Space still never reached
the tool.

~ElementScene blocks its signals before deleting the event interface,
whose destructor resets the behavior while the editor is being destroyed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 08:17:38 +13:00

144 lines
3.4 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/>.
*/
#include "eseventinterface.h"
#include "../elementscene.h"
#include "../ui/qetelementeditor.h"
#include "../elementview.h"
#include <QGraphicsSceneMouseEvent>
ESEventInterface::ESEventInterface(ElementScene *scene) :
m_scene (scene),
m_editor (scene->editor()),
m_help_horiz (nullptr),
m_help_verti (nullptr),
m_running (false),
m_abort (false)
{
init();
}
/**
@brief ESEventInterface::init
Init this event interface
*/
void ESEventInterface::init()
{
m_scene->setBehavior(ElementScene::Behavior::AddPart);
m_editor->elementView()->setDragMode(QGraphicsView::NoDrag);
//Keys such as Space must reach the part being added, even when
//the focus was left in the parts list (#1177)
m_editor->elementView()->setFocus();
}
/**
@brief ESEventInterface::~ESEventInterface
Destructor
*/
ESEventInterface::~ESEventInterface()
{
delete m_help_horiz;
delete m_help_verti;
m_scene->setBehavior(ElementScene::Behavior::Normal);
m_editor->elementView()->setDragMode(QGraphicsView::RubberBandDrag);
}
bool ESEventInterface::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event)
return false;
}
bool ESEventInterface::mousePressEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event)
return false;
}
bool ESEventInterface::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event)
return false;
}
bool ESEventInterface::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event)
return false;
}
bool ESEventInterface::wheelEvent(QGraphicsSceneWheelEvent *event) {
Q_UNUSED (event)
return false;
}
/**
@brief ESEventInterface::keyPressEvent
By default, press escape key abort the current action
@param event
@return
*/
bool ESEventInterface::keyPressEvent(QKeyEvent *event) {
if (event->key() == Qt::Key_Escape) {
m_running = false;
m_abort = true;
return true;
}
return false;
}
bool ESEventInterface::KeyReleaseEvent(QKeyEvent *event) {
Q_UNUSED (event)
return false;
}
bool ESEventInterface::isRunning() const
{
return m_running;
}
bool ESEventInterface::isFinish() const
{
return !m_running;
}
void ESEventInterface::updateHelpCross(const QPointF &p) {
//If line isn't created yet, we create it.
if (!m_help_horiz || !m_help_verti) {
QPen pen;
pen.setWidthF(0.4);
pen.setCosmetic(true);
pen.setColor(Qt::darkGray);
if (!m_help_horiz) {
m_help_horiz = new QGraphicsLineItem(-10000, 0, 10000, 0);
m_help_horiz -> setPen(pen);
m_scene -> addItem(m_help_horiz);
}
if (!m_help_verti) {
m_help_verti = new QGraphicsLineItem(0, -10000, 0, 10000);
m_help_verti -> setPen(pen);
m_scene -> addItem(m_help_verti);
}
}
//Update the position of the cross
QPointF point = m_scene -> snapToGrid(p);
m_help_horiz -> setY(point.y());
m_help_verti -> setX(point.x());
}