mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
element editor: add arc is managed by ESEvent
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3470 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -95,14 +95,6 @@ void ElementScene::slot_addTerminal() {
|
||||
if (m_event_interface) delete m_event_interface; m_event_interface = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
Passe la scene en mode "ajout d'arc de cercle"
|
||||
*/
|
||||
void ElementScene::slot_addArc() {
|
||||
behavior = Arc;
|
||||
if (m_event_interface) delete m_event_interface; m_event_interface = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
Passe la scene en mode "ajout de champ de texte"
|
||||
*/
|
||||
@@ -137,20 +129,7 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
return;
|
||||
}
|
||||
|
||||
QRectF temp_rect;
|
||||
if (e -> buttons() & Qt::LeftButton) {
|
||||
switch(behavior) {
|
||||
case Arc:
|
||||
temp_rect = current_arc -> rect();
|
||||
temp_rect.setBottomRight(event_pos);
|
||||
current_arc -> setRect(temp_rect);
|
||||
break;
|
||||
case Normal:
|
||||
default:
|
||||
QGraphicsScene::mouseMoveEvent(e);
|
||||
}
|
||||
}
|
||||
else QGraphicsScene::mouseMoveEvent(e);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,18 +150,7 @@ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
QPointF event_pos = e -> scenePos();
|
||||
if (mustSnapToGrid(e)) event_pos = snapToGrid(event_pos);
|
||||
|
||||
if (e -> button() & Qt::LeftButton) {
|
||||
switch(behavior) {
|
||||
case Arc:
|
||||
current_arc = new PartArc(element_editor, 0, this);
|
||||
current_arc -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
|
||||
current_arc -> setProperty("antialias", true);
|
||||
break;
|
||||
case Normal:
|
||||
default:
|
||||
QGraphicsScene::mousePressEvent(e);
|
||||
}
|
||||
} else QGraphicsScene::mousePressEvent(e);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,13 +186,6 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
|
||||
if (e -> button() & Qt::LeftButton) {
|
||||
switch(behavior) {
|
||||
case Arc:
|
||||
if (qgiManager().manages(current_arc)) break;
|
||||
current_arc-> setRect(current_arc -> rect().normalized());
|
||||
undo_stack.push(new AddPartCommand(tr("arc"), this, current_arc));
|
||||
emit(partsAdded());
|
||||
endCurrentBehavior(e);
|
||||
break;
|
||||
case Terminal:
|
||||
terminal = new PartTerminal(element_editor, 0, this);
|
||||
terminal -> setPos(event_pos);
|
||||
|
||||
@@ -28,7 +28,6 @@ class CustomElementPart;
|
||||
class ElementEditionCommand;
|
||||
class ElementPrimitiveDecorator;
|
||||
class QETElementEditor;
|
||||
class PartArc;
|
||||
class ESEventInterface;
|
||||
class QKeyEvent;
|
||||
/**
|
||||
@@ -42,7 +41,7 @@ class ElementScene : public QGraphicsScene {
|
||||
|
||||
// enum
|
||||
public:
|
||||
enum Behavior { Normal, Circle, Text, Terminal, Arc, TextField, PasteArea };
|
||||
enum Behavior { Normal, Circle, Text, Terminal, TextField, PasteArea };
|
||||
enum ItemOption {
|
||||
SortByZValue = 1,
|
||||
IncludeTerminals = 2,
|
||||
@@ -87,7 +86,6 @@ class ElementScene : public QGraphicsScene {
|
||||
/// Variables related to drawing
|
||||
ESEventInterface *m_event_interface;
|
||||
Behavior behavior;
|
||||
PartArc *current_arc;
|
||||
QETElementEditor *element_editor;
|
||||
|
||||
/// Variables to manage the paste area on the scene
|
||||
@@ -165,7 +163,6 @@ class ElementScene : public QGraphicsScene {
|
||||
void slot_move();
|
||||
void slot_addCircle();
|
||||
void slot_addText();
|
||||
void slot_addArc();
|
||||
void slot_addTerminal();
|
||||
void slot_addTextField();
|
||||
void slot_select(const ElementContent &);
|
||||
|
||||
189
sources/editor/esevent/eseventaddarc.cpp
Normal file
189
sources/editor/esevent/eseventaddarc.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
Copyright 2006-2014 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 <QObject>
|
||||
|
||||
#include "elementscene.h"
|
||||
#include "partarc.h"
|
||||
#include "editorcommands.h"
|
||||
#include "eseventaddarc.h"
|
||||
|
||||
/**
|
||||
* @brief ESEventAddArc::ESEventAddArc
|
||||
* @param scene
|
||||
*/
|
||||
ESEventAddArc::ESEventAddArc(ElementScene *scene) :
|
||||
ESEventInterface(scene),
|
||||
m_arc(nullptr),
|
||||
m_inverted(false)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddArc::~ESEventAddArc
|
||||
*/
|
||||
ESEventAddArc::~ESEventAddArc() {
|
||||
if (m_running || m_abort)
|
||||
delete m_arc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddPolygon::mousePressEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddArc::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if (event -> button() == Qt::LeftButton) {
|
||||
if(!m_running) m_running = true;
|
||||
QPointF pos = m_scene->snapToGrid(event -> scenePos());
|
||||
|
||||
//create new arc
|
||||
if (!m_arc) {
|
||||
m_arc = new PartArc(m_editor, 0, m_scene);
|
||||
m_arc -> setRect(QRectF(pos, pos));
|
||||
m_arc -> setAngle(90);
|
||||
m_arc -> setProperty("antialias", true);
|
||||
m_origin = pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
//Add arc to scene
|
||||
m_arc -> setRect(m_arc->rect().normalized());
|
||||
m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Arc"), m_scene, m_arc));
|
||||
|
||||
//Set m_arc to nullptr for create new ellipse at next mouse press
|
||||
m_arc = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddArc::mouseMoveEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddArc::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
updateHelpCross(event -> scenePos());
|
||||
if (!m_arc) return false;
|
||||
|
||||
m_mouse_pos = m_scene -> snapToGrid(event -> scenePos());
|
||||
updateArc();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddArc::mouseReleaseEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if (event -> button() == Qt::RightButton) {
|
||||
if (m_arc) {delete m_arc; m_arc = nullptr;}
|
||||
else {m_running = false;}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddArc::keyPressEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddArc::keyPressEvent(QKeyEvent *event) {
|
||||
if (m_arc && event->key() == Qt::Key_Space) {
|
||||
m_inverted = m_inverted ? false : true;
|
||||
updateArc();
|
||||
return true;
|
||||
}
|
||||
|
||||
return (ESEventInterface::keyPressEvent(event));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddArc::updateArc
|
||||
* Redraw the arc with curent value
|
||||
*/
|
||||
void ESEventAddArc::updateArc() {
|
||||
|
||||
qreal width = (m_mouse_pos.x() - m_origin.x())*2;
|
||||
if (width < 0) width *= -1;
|
||||
qreal height = (m_mouse_pos.y() - m_origin.y())*2;
|
||||
if (height < 0) height *= -1;
|
||||
|
||||
QPointF pos_ = m_origin;
|
||||
|
||||
//Draw arc inverted
|
||||
if (m_inverted) {
|
||||
//Adjust the start angle to be snapped at the origin point of draw
|
||||
if (m_mouse_pos.y() > m_origin.y()) {
|
||||
|
||||
if (m_mouse_pos.x() > m_origin.x()) {
|
||||
pos_.ry() -= height/2;
|
||||
m_arc->setStartAngle(180);
|
||||
}
|
||||
else {
|
||||
pos_.rx() -= width/2;
|
||||
m_arc->setStartAngle(90);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (m_mouse_pos.x() > m_origin.x()) {
|
||||
pos_.ry() -= height;
|
||||
pos_.rx() -= width/2;
|
||||
m_arc->setStartAngle(270);
|
||||
}
|
||||
else {
|
||||
pos_.rx() -= width;
|
||||
pos_.ry() -= height/2;
|
||||
m_arc->setStartAngle(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Draw arc non inverted
|
||||
else {
|
||||
//Adjust the start angle to be snapped at the origin point of draw
|
||||
if (m_mouse_pos.y() > m_origin.y()) {
|
||||
|
||||
if (m_mouse_pos.x() > m_origin.x()) {
|
||||
pos_.rx() -= width/2;
|
||||
m_arc->setStartAngle(0);
|
||||
}
|
||||
else {
|
||||
pos_.rx() -= width;
|
||||
pos_.ry() -= height/2;
|
||||
m_arc->setStartAngle(270);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (m_mouse_pos.x() > m_origin.x()) {
|
||||
pos_.ry() -= height/2;
|
||||
m_arc->setStartAngle(90);
|
||||
}
|
||||
else {
|
||||
pos_.rx() -= width/2;
|
||||
pos_.ry() -= height;
|
||||
m_arc->setStartAngle(180);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_arc -> setRect(QRectF(pos_, QSizeF(width, height)));
|
||||
}
|
||||
51
sources/editor/esevent/eseventaddarc.h
Normal file
51
sources/editor/esevent/eseventaddarc.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright 2006-2014 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 ESEVENTADDARC_H
|
||||
#define ESEVENTADDARC_H
|
||||
|
||||
#include "eseventinterface.h"
|
||||
|
||||
class ElementScene;
|
||||
class PartArc;
|
||||
class QGraphicsSceneMouseEvent;
|
||||
|
||||
/**
|
||||
* @brief The ESEventAddArc class
|
||||
* This ESEvent manage creation of arc in an ElementScene
|
||||
*/
|
||||
class ESEventAddArc : public ESEventInterface
|
||||
{
|
||||
public:
|
||||
ESEventAddArc(ElementScene *scene);
|
||||
virtual ~ESEventAddArc();
|
||||
|
||||
virtual bool mousePressEvent (QGraphicsSceneMouseEvent *event);
|
||||
virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event);
|
||||
virtual bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
|
||||
virtual bool keyPressEvent (QKeyEvent *event);
|
||||
|
||||
private:
|
||||
void updateArc ();
|
||||
|
||||
private:
|
||||
PartArc *m_arc;
|
||||
QPointF m_origin, m_mouse_pos;
|
||||
bool m_inverted;
|
||||
};
|
||||
|
||||
#endif // ESEVENTADDARC_H
|
||||
@@ -54,7 +54,6 @@ bool ESEventAddEllipse::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if (!m_ellipse) {
|
||||
m_ellipse = new PartEllipse(m_editor, 0, m_scene);
|
||||
m_ellipse -> setRect(QRectF(pos, pos));
|
||||
m_ellipse -> setProperty("antialias", true);
|
||||
m_origin = pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "eseventaddrect.h"
|
||||
#include "eseventaddellipse.h"
|
||||
#include "eseventaddpolygon.h"
|
||||
#include "eseventaddarc.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
/*
|
||||
@@ -254,7 +255,7 @@ void QETElementEditor::setupActions() {
|
||||
connect(add_ellipse, SIGNAL(triggered()), this, SLOT(addEllipse()));
|
||||
connect(add_polygon, SIGNAL(triggered()), this, SLOT(addPolygon()));
|
||||
connect(add_text, SIGNAL(triggered()), ce_scene, SLOT(slot_addText()));
|
||||
connect(add_arc, SIGNAL(triggered()), ce_scene, SLOT(slot_addArc()));
|
||||
connect(add_arc, SIGNAL(triggered()), this, SLOT(addArc()));
|
||||
connect(add_terminal, SIGNAL(triggered()), ce_scene, SLOT(slot_addTerminal()));
|
||||
connect(add_textfield, SIGNAL(triggered()), ce_scene, SLOT(slot_addTextField()));
|
||||
|
||||
@@ -957,6 +958,14 @@ void QETElementEditor::addPolygon() {
|
||||
ce_scene -> setEventInterface(new ESEventAddPolygon(ce_scene));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETElementEditor::addArc
|
||||
* Set arc creation interface to scene
|
||||
*/
|
||||
void QETElementEditor::addArc() {
|
||||
ce_scene -> setEventInterface(new ESEventAddArc(ce_scene));
|
||||
}
|
||||
|
||||
/**
|
||||
Lance l'assistant de creation d'un nouvel element.
|
||||
*/
|
||||
|
||||
@@ -132,6 +132,7 @@ class QETElementEditor : public QETMainWindow {
|
||||
void addRect();
|
||||
void addEllipse();
|
||||
void addPolygon();
|
||||
void addArc();
|
||||
|
||||
void slot_new();
|
||||
void slot_open();
|
||||
|
||||
Reference in New Issue
Block a user