[qet] [3457] element editor, add rect is managed by esevent |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 3457
Author: blacksun
Date: 2014-11-06 11:46:14 +0100 (Thu, 06 Nov 2014)
Log Message:
-----------
element editor, add rect is managed by 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/eseventaddrect.cpp
trunk/sources/editor/esevent/eseventaddrect.h
Modified: trunk/sources/editor/elementscene.cpp
===================================================================
--- trunk/sources/editor/elementscene.cpp 2014-11-06 09:44:20 UTC (rev 3456)
+++ trunk/sources/editor/elementscene.cpp 2014-11-06 10:46:14 UTC (rev 3457)
@@ -72,14 +72,6 @@
}
/**
- Passe la scene en mode "ajout de rectangle"
-*/
-void ElementScene::slot_addRectangle() {
- behavior = Rectangle;
- if (m_event_interface) delete m_event_interface; m_event_interface = nullptr;
-}
-
-/**
Passe la scene en mode "ajout de cercle"
*/
void ElementScene::slot_addCircle() {
@@ -168,11 +160,6 @@
QPolygonF temp_polygon;
if (e -> buttons() & Qt::LeftButton) {
switch(behavior) {
- case Rectangle:
- temp_rect = current_rectangle -> rect();
- temp_rect.setBottomRight(event_pos);
- current_rectangle -> setRect(temp_rect);
- break;
case Ellipse:
temp_rect = current_ellipse -> rect();
temp_rect.setBottomRight(event_pos);
@@ -224,10 +211,6 @@
QPolygonF temp_polygon;
if (e -> button() & Qt::LeftButton) {
switch(behavior) {
- case Rectangle:
- current_rectangle = new PartRectangle(element_editor, 0, this);
- current_rectangle -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
- break;
case Ellipse:
current_ellipse = new PartEllipse(element_editor, 0, this);
current_ellipse -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
@@ -289,13 +272,6 @@
if (e -> button() & Qt::LeftButton) {
switch(behavior) {
- case Rectangle:
- if (qgiManager().manages(current_rectangle)) break;
- current_rectangle -> setRect(current_rectangle -> rect().normalized());
- undo_stack.push(new AddPartCommand(tr("rectangle"), this, current_rectangle));
- emit(partsAdded());
- endCurrentBehavior(e);
- break;
case Ellipse:
if (qgiManager().manages(current_ellipse)) break;
current_ellipse -> setRect(current_ellipse -> rect().normalized());
Modified: trunk/sources/editor/elementscene.h
===================================================================
--- trunk/sources/editor/elementscene.h 2014-11-06 09:44:20 UTC (rev 3456)
+++ trunk/sources/editor/elementscene.h 2014-11-06 10:46:14 UTC (rev 3457)
@@ -28,7 +28,6 @@
class ElementEditionCommand;
class ElementPrimitiveDecorator;
class QETElementEditor;
-class PartRectangle;
class PartEllipse;
class PartPolygon;
class PartArc;
@@ -45,7 +44,7 @@
// enum
public:
- enum Behavior { Normal, Rectangle, Circle, Ellipse, Polygon, Text, Terminal, Arc, TextField, PasteArea };
+ enum Behavior { Normal, Circle, Ellipse, Polygon, Text, Terminal, Arc, TextField, PasteArea };
enum ItemOption {
SortByZValue = 1,
IncludeTerminals = 2,
@@ -54,7 +53,7 @@
NonSelected = 16,
SelectedOrNot = 24
};
- Q_DECLARE_FLAGS(ItemOptions, ItemOption);
+ Q_DECLARE_FLAGS(ItemOptions, ItemOption)
// constructors, destructor
public:
@@ -90,7 +89,6 @@
/// Variables related to drawing
ESEventInterface *m_event_interface;
Behavior behavior;
- PartRectangle *current_rectangle;
PartEllipse *current_ellipse;
PartPolygon *current_polygon;
PartArc *current_arc;
@@ -168,7 +166,6 @@
public slots:
void slot_move();
- void slot_addRectangle();
void slot_addCircle();
void slot_addEllipse();
void slot_addPolygon();
Added: trunk/sources/editor/esevent/eseventaddrect.cpp
===================================================================
--- trunk/sources/editor/esevent/eseventaddrect.cpp (rev 0)
+++ trunk/sources/editor/esevent/eseventaddrect.cpp 2014-11-06 10:46:14 UTC (rev 3457)
@@ -0,0 +1,97 @@
+/*
+ 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 "eseventaddrect.h"
+#include "elementscene.h"
+#include "partrectangle.h"
+#include "editorcommands.h"
+
+/**
+ * @brief ESEventAddRect::ESEventAddRect
+ * @param scene
+ */
+ESEventAddRect::ESEventAddRect(ElementScene *scene) :
+ ESEventInterface(scene),
+ m_rect(nullptr)
+{}
+
+/**
+ * @brief ESEventAddRect::~ESEventAddRect
+ */
+ESEventAddRect::~ESEventAddRect() {
+ if (m_running || m_abort)
+ delete m_rect;
+}
+
+/**
+ * @brief ESEventAddRect::mousePressEvent
+ * @param event
+ * @return
+ */
+bool ESEventAddRect::mousePressEvent(QGraphicsSceneMouseEvent *event) {
+ if (event -> button() == Qt::LeftButton) {
+ if(!m_running) m_running = true;
+ QPointF pos = m_scene->snapToGrid(event -> scenePos());
+
+ //create new rectangle
+ if (!m_rect) {
+ m_rect = new PartRectangle(m_editor, 0, m_scene);
+ m_rect -> setRect(QRectF(pos, pos));
+ return true;
+ }
+
+ //Add rectangle to scene
+ m_rect -> setRect(m_rect -> rect().normalized());
+ m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Rectangle"), m_scene, m_rect));
+
+ //Set m_rect to nullptr for create new rectangle at next mouse press
+ m_rect = nullptr;
+
+ return true;
+ }
+ return false;
+}
+
+/**
+ * @brief ESEventAddRect::mouseMoveEvent
+ * @param event
+ * @return
+ */
+bool ESEventAddRect::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
+ updateHelpCross(event -> scenePos());
+ if (!m_rect) return false;
+
+ QRectF rect(m_rect -> rect().topLeft(), m_scene->snapToGrid(event -> scenePos()));
+ m_rect -> setRect(rect);
+ return true;
+}
+
+/**
+ * @brief ESEventAddRect::mouseReleaseEvent
+ * @param event
+ * @return
+ */
+bool ESEventAddRect::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
+ if (event -> button() == Qt::RightButton) {
+ if (m_rect) {delete m_rect; m_rect = nullptr;}
+ else {m_running = false;}
+ return true;
+ }
+ return false;
+}
Added: trunk/sources/editor/esevent/eseventaddrect.h
===================================================================
--- trunk/sources/editor/esevent/eseventaddrect.h (rev 0)
+++ trunk/sources/editor/esevent/eseventaddrect.h 2014-11-06 10:46:14 UTC (rev 3457)
@@ -0,0 +1,41 @@
+/*
+ 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 ESEVENTADDRECT_H
+#define ESEVENTADDRECT_H
+
+#include "eseventinterface.h"
+
+class ElementScene;
+class PartRectangle;
+class QGraphicsSceneMouseEvent;
+
+class ESEventAddRect : public ESEventInterface
+{
+ public:
+ ESEventAddRect(ElementScene *scene);
+ virtual ~ESEventAddRect();
+
+ virtual bool mousePressEvent (QGraphicsSceneMouseEvent *event);
+ virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event);
+ virtual bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
+
+ private:
+ PartRectangle *m_rect;
+};
+
+#endif // ESEVENTADDRECT_H
Modified: trunk/sources/editor/qetelementeditor.cpp
===================================================================
--- trunk/sources/editor/qetelementeditor.cpp 2014-11-06 09:44:20 UTC (rev 3456)
+++ trunk/sources/editor/qetelementeditor.cpp 2014-11-06 10:46:14 UTC (rev 3457)
@@ -42,6 +42,7 @@
#include "parttextfield.h"
#include "eseventaddline.h"
+#include "eseventaddrect.h"
#include <QMessageBox>
/*
@@ -246,8 +247,8 @@
connect(edit_backward, SIGNAL(triggered()), ce_scene, SLOT(slot_sendBackward()));
connect(move, SIGNAL(triggered()), ce_scene, SLOT(slot_move()));
- connect(add_line, SIGNAL(triggered()), this, SLOT(addLine()));
- connect(add_rectangle, SIGNAL(triggered()), ce_scene, SLOT(slot_addRectangle()));
+ 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_polygon, SIGNAL(triggered()), ce_scene, SLOT(slot_addPolygon()));
connect(add_text, SIGNAL(triggered()), ce_scene, SLOT(slot_addText()));
@@ -931,6 +932,14 @@
}
/**
+ * @brief QETElementEditor::addRect
+ * Set rectangle creation interface to scene
+ */
+void QETElementEditor::addRect() {
+ ce_scene -> setEventInterface(new ESEventAddRect(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 09:44:20 UTC (rev 3456)
+++ trunk/sources/editor/qetelementeditor.h 2014-11-06 10:46:14 UTC (rev 3457)
@@ -127,6 +127,7 @@
public slots:
void addLine();
+ void addRect();
void slot_new();
void slot_open();