element editor, add rect is managed by esevent

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3457 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-11-06 10:46:14 +00:00
parent 97bf2333ae
commit ceea767f26
6 changed files with 152 additions and 31 deletions

View File

@@ -71,14 +71,6 @@ void ElementScene::slot_move() {
if (m_event_interface) delete m_event_interface; m_event_interface = nullptr;
}
/**
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"
*/
@@ -168,11 +160,6 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
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 @@ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
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 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
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());

View File

@@ -28,7 +28,6 @@ class CustomElementPart;
class ElementEditionCommand;
class ElementPrimitiveDecorator;
class QETElementEditor;
class PartRectangle;
class PartEllipse;
class PartPolygon;
class PartArc;
@@ -45,7 +44,7 @@ class ElementScene : public QGraphicsScene {
// 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 @@ class ElementScene : public QGraphicsScene {
NonSelected = 16,
SelectedOrNot = 24
};
Q_DECLARE_FLAGS(ItemOptions, ItemOption);
Q_DECLARE_FLAGS(ItemOptions, ItemOption)
// constructors, destructor
public:
@@ -90,7 +89,6 @@ class ElementScene : public QGraphicsScene {
/// 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 @@ class ElementScene : public QGraphicsScene {
public slots:
void slot_move();
void slot_addRectangle();
void slot_addCircle();
void slot_addEllipse();
void slot_addPolygon();

View File

@@ -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;
}

View File

@@ -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

View File

@@ -42,6 +42,7 @@
#include "parttextfield.h"
#include "eseventaddline.h"
#include "eseventaddrect.h"
#include <QMessageBox>
/*
@@ -247,7 +248,7 @@ void QETElementEditor::setupActions() {
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_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()));
@@ -930,6 +931,14 @@ void QETElementEditor::addLine() {
ce_scene -> setEventInterface(new ESEventAddLine(ce_scene));
}
/**
* @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.
*/

View File

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