Element editor: add ellipse is managed by an esevent

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3461 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-11-07 09:39:19 +00:00
parent a7192fcda6
commit 8892828f87
6 changed files with 161 additions and 30 deletions

View File

@@ -79,14 +79,6 @@ void ElementScene::slot_addCircle() {
if (m_event_interface) delete m_event_interface; m_event_interface = nullptr; if (m_event_interface) delete m_event_interface; m_event_interface = nullptr;
} }
/**
Passe la scene en mode "ajout d'ellipse"
*/
void ElementScene::slot_addEllipse() {
behavior = Ellipse;
if (m_event_interface) delete m_event_interface; m_event_interface = nullptr;
}
/** /**
Passe la scene en mode "ajout de polygone" Passe la scene en mode "ajout de polygone"
*/ */
@@ -160,11 +152,6 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
QPolygonF temp_polygon; QPolygonF temp_polygon;
if (e -> buttons() & Qt::LeftButton) { if (e -> buttons() & Qt::LeftButton) {
switch(behavior) { switch(behavior) {
case Ellipse:
temp_rect = current_ellipse -> rect();
temp_rect.setBottomRight(event_pos);
current_ellipse -> setRect(temp_rect);
break;
case Arc: case Arc:
temp_rect = current_arc -> rect(); temp_rect = current_arc -> rect();
temp_rect.setBottomRight(event_pos); temp_rect.setBottomRight(event_pos);
@@ -211,11 +198,6 @@ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
QPolygonF temp_polygon; QPolygonF temp_polygon;
if (e -> button() & Qt::LeftButton) { if (e -> button() & Qt::LeftButton) {
switch(behavior) { switch(behavior) {
case Ellipse:
current_ellipse = new PartEllipse(element_editor, 0, this);
current_ellipse -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
current_ellipse -> setProperty("antialias", true);
break;
case Arc: case Arc:
current_arc = new PartArc(element_editor, 0, this); current_arc = new PartArc(element_editor, 0, this);
current_arc -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0))); current_arc -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
@@ -272,13 +254,6 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
if (e -> button() & Qt::LeftButton) { if (e -> button() & Qt::LeftButton) {
switch(behavior) { switch(behavior) {
case Ellipse:
if (qgiManager().manages(current_ellipse)) break;
current_ellipse -> setRect(current_ellipse -> rect().normalized());
undo_stack.push(new AddPartCommand(tr("ellipse"), this, current_ellipse));
emit(partsAdded());
endCurrentBehavior(e);
break;
case Arc: case Arc:
if (qgiManager().manages(current_arc)) break; if (qgiManager().manages(current_arc)) break;
current_arc-> setRect(current_arc -> rect().normalized()); current_arc-> setRect(current_arc -> rect().normalized());

View File

@@ -28,7 +28,6 @@ class CustomElementPart;
class ElementEditionCommand; class ElementEditionCommand;
class ElementPrimitiveDecorator; class ElementPrimitiveDecorator;
class QETElementEditor; class QETElementEditor;
class PartEllipse;
class PartPolygon; class PartPolygon;
class PartArc; class PartArc;
class ESEventInterface; class ESEventInterface;
@@ -44,7 +43,7 @@ class ElementScene : public QGraphicsScene {
// enum // enum
public: public:
enum Behavior { Normal, Circle, Ellipse, Polygon, Text, Terminal, Arc, TextField, PasteArea }; enum Behavior { Normal, Circle, Polygon, Text, Terminal, Arc, TextField, PasteArea };
enum ItemOption { enum ItemOption {
SortByZValue = 1, SortByZValue = 1,
IncludeTerminals = 2, IncludeTerminals = 2,
@@ -89,7 +88,6 @@ class ElementScene : public QGraphicsScene {
/// Variables related to drawing /// Variables related to drawing
ESEventInterface *m_event_interface; ESEventInterface *m_event_interface;
Behavior behavior; Behavior behavior;
PartEllipse *current_ellipse;
PartPolygon *current_polygon; PartPolygon *current_polygon;
PartArc *current_arc; PartArc *current_arc;
QETElementEditor *element_editor; QETElementEditor *element_editor;
@@ -167,7 +165,6 @@ class ElementScene : public QGraphicsScene {
public slots: public slots:
void slot_move(); void slot_move();
void slot_addCircle(); void slot_addCircle();
void slot_addEllipse();
void slot_addPolygon(); void slot_addPolygon();
void slot_addText(); void slot_addText();
void slot_addArc(); void slot_addArc();

View File

@@ -0,0 +1,106 @@
/*
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 "eseventaddellipse.h"
#include "partellipse.h"
#include "editorcommands.h"
#include "elementscene.h"
/**
* @brief ESEventAddEllipse::ESEventAddEllipse
* @param scene
*/
ESEventAddEllipse::ESEventAddEllipse(ElementScene *scene) :
ESEventInterface(scene),
m_ellipse(nullptr)
{}
/**
* @brief ESEventAddEllipse::~ESEventAddEllipse
*/
ESEventAddEllipse::~ESEventAddEllipse() {
if (m_running || m_abort){
delete m_ellipse;
}
}
/**
* @brief ESEventAddEllipse::mousePressEvent
* @param event
* @return
*/
bool ESEventAddEllipse::mousePressEvent(QGraphicsSceneMouseEvent *event) {
if (event -> button() == Qt::LeftButton) {
if(!m_running) m_running = true;
QPointF pos = m_scene->snapToGrid(event -> scenePos());
//create new ellpise
if (!m_ellipse) {
m_ellipse = new PartEllipse(m_editor, 0, m_scene);
m_ellipse -> setRect(QRectF(pos, pos));
m_origin = pos;
return true;
}
//Add ellipse to scene
m_ellipse -> setRect(m_ellipse -> rect().normalized());
m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Rectangle"), m_scene, m_ellipse));
//Set m_ellipse to nullptr for create new ellipse at next mouse press
m_ellipse = nullptr;
return true;
}
return false;
}
/**
* @brief ESEventAddRect::mouseMoveEvent
* @param event
* @return
*/
bool ESEventAddEllipse::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
updateHelpCross(event -> scenePos());
if (!m_ellipse) return false;
QPointF mouse_pos = m_scene -> snapToGrid(event -> scenePos());
qreal width = (mouse_pos.x() - m_origin.x())*2;
qreal height = (mouse_pos.y() - m_origin.y())*2;
QPointF pos(m_origin.x() - width/2,
m_origin.y() - height/2);
m_ellipse -> setRect(QRectF(pos, QSizeF(width, height)));
return true;
}
/**
* @brief ESEventAddEllipse::mouseReleaseEvent
* @param event
* @return
*/
bool ESEventAddEllipse::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
if (event -> button() == Qt::RightButton) {
if (m_ellipse) {delete m_ellipse; m_ellipse = nullptr;}
else {m_running = false;}
return true;
}
return false;
}

View File

@@ -0,0 +1,43 @@
/*
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 ESEVENTADDELLIPSE_H
#define ESEVENTADDELLIPSE_H
#include "eseventinterface.h"
#include <QPointF>
class ElementScene;
class PartEllipse;
class QGraphicsSceneMouseEvent;
class ESEventAddEllipse : public ESEventInterface
{
public:
ESEventAddEllipse(ElementScene *scene);
~ESEventAddEllipse();
virtual bool mousePressEvent (QGraphicsSceneMouseEvent *event);
virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event);
virtual bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
private:
PartEllipse *m_ellipse;
QPointF m_origin;
};
#endif // ESEVENTADDELLIPSE_H

View File

@@ -43,6 +43,7 @@
#include "eseventaddline.h" #include "eseventaddline.h"
#include "eseventaddrect.h" #include "eseventaddrect.h"
#include "eseventaddellipse.h"
#include <QMessageBox> #include <QMessageBox>
/* /*
@@ -249,7 +250,7 @@ void QETElementEditor::setupActions() {
connect(add_line, SIGNAL(triggered()), this, SLOT(addLine())); connect(add_line, SIGNAL(triggered()), this, SLOT(addLine()));
connect(add_rectangle, SIGNAL(triggered()), this, SLOT(addRect())); connect(add_rectangle, SIGNAL(triggered()), this, SLOT(addRect()));
connect(add_ellipse, SIGNAL(triggered()), ce_scene, SLOT(slot_addEllipse())); connect(add_ellipse, SIGNAL(triggered()), this, SLOT(addEllipse()));
connect(add_polygon, SIGNAL(triggered()), ce_scene, SLOT(slot_addPolygon())); connect(add_polygon, SIGNAL(triggered()), ce_scene, SLOT(slot_addPolygon()));
connect(add_text, SIGNAL(triggered()), ce_scene, SLOT(slot_addText())); 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()), ce_scene, SLOT(slot_addArc()));
@@ -939,6 +940,14 @@ void QETElementEditor::addRect() {
ce_scene -> setEventInterface(new ESEventAddRect(ce_scene)); ce_scene -> setEventInterface(new ESEventAddRect(ce_scene));
} }
/**
* @brief QETElementEditor::addEllipse
* Set ellipse creation interface to scene
*/
void QETElementEditor::addEllipse() {
ce_scene -> setEventInterface(new ESEventAddEllipse(ce_scene));
}
/** /**
Lance l'assistant de creation d'un nouvel element. Lance l'assistant de creation d'un nouvel element.
*/ */

View File

@@ -128,6 +128,7 @@ class QETElementEditor : public QETMainWindow {
public slots: public slots:
void addLine(); void addLine();
void addRect(); void addRect();
void addEllipse();
void slot_new(); void slot_new();
void slot_open(); void slot_open();