[qet] [3461] Element editor: add ellipse is managed by an esevent |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 3461
Author: blacksun
Date: 2014-11-07 10:39:19 +0100 (Fri, 07 Nov 2014)
Log Message:
-----------
Element editor: add ellipse is managed by an esevent
Modified Paths:
--------------
trunk/sources/editor/elementscene.cpp
trunk/sources/editor/elementscene.h
trunk/sources/editor/qetelementeditor.cpp
trunk/sources/editor/qetelementeditor.h
Added Paths:
-----------
trunk/sources/editor/esevent/eseventaddellipse.cpp
trunk/sources/editor/esevent/eseventaddellipse.h
Modified: trunk/sources/editor/elementscene.cpp
===================================================================
--- trunk/sources/editor/elementscene.cpp 2014-11-06 21:08:45 UTC (rev 3460)
+++ trunk/sources/editor/elementscene.cpp 2014-11-07 09:39:19 UTC (rev 3461)
@@ -80,14 +80,6 @@
}
/**
- 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"
*/
void ElementScene::slot_addPolygon() {
@@ -160,11 +152,6 @@
QPolygonF temp_polygon;
if (e -> buttons() & Qt::LeftButton) {
switch(behavior) {
- case Ellipse:
- temp_rect = current_ellipse -> rect();
- temp_rect.setBottomRight(event_pos);
- current_ellipse -> setRect(temp_rect);
- break;
case Arc:
temp_rect = current_arc -> rect();
temp_rect.setBottomRight(event_pos);
@@ -211,11 +198,6 @@
QPolygonF temp_polygon;
if (e -> button() & Qt::LeftButton) {
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:
current_arc = new PartArc(element_editor, 0, this);
current_arc -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
@@ -272,13 +254,6 @@
if (e -> button() & Qt::LeftButton) {
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:
if (qgiManager().manages(current_arc)) break;
current_arc-> setRect(current_arc -> rect().normalized());
Modified: trunk/sources/editor/elementscene.h
===================================================================
--- trunk/sources/editor/elementscene.h 2014-11-06 21:08:45 UTC (rev 3460)
+++ trunk/sources/editor/elementscene.h 2014-11-07 09:39:19 UTC (rev 3461)
@@ -28,7 +28,6 @@
class ElementEditionCommand;
class ElementPrimitiveDecorator;
class QETElementEditor;
-class PartEllipse;
class PartPolygon;
class PartArc;
class ESEventInterface;
@@ -44,7 +43,7 @@
// enum
public:
- enum Behavior { Normal, Circle, Ellipse, Polygon, Text, Terminal, Arc, TextField, PasteArea };
+ enum Behavior { Normal, Circle, Polygon, Text, Terminal, Arc, TextField, PasteArea };
enum ItemOption {
SortByZValue = 1,
IncludeTerminals = 2,
@@ -89,7 +88,6 @@
/// Variables related to drawing
ESEventInterface *m_event_interface;
Behavior behavior;
- PartEllipse *current_ellipse;
PartPolygon *current_polygon;
PartArc *current_arc;
QETElementEditor *element_editor;
@@ -167,7 +165,6 @@
public slots:
void slot_move();
void slot_addCircle();
- void slot_addEllipse();
void slot_addPolygon();
void slot_addText();
void slot_addArc();
Added: trunk/sources/editor/esevent/eseventaddellipse.cpp
===================================================================
--- trunk/sources/editor/esevent/eseventaddellipse.cpp (rev 0)
+++ trunk/sources/editor/esevent/eseventaddellipse.cpp 2014-11-07 09:39:19 UTC (rev 3461)
@@ -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;
+}
Added: trunk/sources/editor/esevent/eseventaddellipse.h
===================================================================
--- trunk/sources/editor/esevent/eseventaddellipse.h (rev 0)
+++ trunk/sources/editor/esevent/eseventaddellipse.h 2014-11-07 09:39:19 UTC (rev 3461)
@@ -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
Modified: trunk/sources/editor/qetelementeditor.cpp
===================================================================
--- trunk/sources/editor/qetelementeditor.cpp 2014-11-06 21:08:45 UTC (rev 3460)
+++ trunk/sources/editor/qetelementeditor.cpp 2014-11-07 09:39:19 UTC (rev 3461)
@@ -43,6 +43,7 @@
#include "eseventaddline.h"
#include "eseventaddrect.h"
+#include "eseventaddellipse.h"
#include <QMessageBox>
/*
@@ -249,7 +250,7 @@
connect(add_line, SIGNAL(triggered()), this, SLOT(addLine()));
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_text, SIGNAL(triggered()), ce_scene, SLOT(slot_addText()));
connect(add_arc, SIGNAL(triggered()), ce_scene, SLOT(slot_addArc()));
@@ -940,6 +941,14 @@
}
/**
+ * @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.
*/
void QETElementEditor::slot_new() {
Modified: trunk/sources/editor/qetelementeditor.h
===================================================================
--- trunk/sources/editor/qetelementeditor.h 2014-11-06 21:08:45 UTC (rev 3460)
+++ trunk/sources/editor/qetelementeditor.h 2014-11-07 09:39:19 UTC (rev 3461)
@@ -128,6 +128,7 @@
public slots:
void addLine();
void addRect();
+ void addEllipse();
void slot_new();
void slot_open();