mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
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:
@@ -71,14 +71,6 @@ void ElementScene::slot_move() {
|
|||||||
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 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"
|
Passe la scene en mode "ajout de cercle"
|
||||||
*/
|
*/
|
||||||
@@ -168,11 +160,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 Rectangle:
|
|
||||||
temp_rect = current_rectangle -> rect();
|
|
||||||
temp_rect.setBottomRight(event_pos);
|
|
||||||
current_rectangle -> setRect(temp_rect);
|
|
||||||
break;
|
|
||||||
case Ellipse:
|
case Ellipse:
|
||||||
temp_rect = current_ellipse -> rect();
|
temp_rect = current_ellipse -> rect();
|
||||||
temp_rect.setBottomRight(event_pos);
|
temp_rect.setBottomRight(event_pos);
|
||||||
@@ -224,10 +211,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 Rectangle:
|
|
||||||
current_rectangle = new PartRectangle(element_editor, 0, this);
|
|
||||||
current_rectangle -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
|
|
||||||
break;
|
|
||||||
case Ellipse:
|
case Ellipse:
|
||||||
current_ellipse = new PartEllipse(element_editor, 0, this);
|
current_ellipse = new PartEllipse(element_editor, 0, this);
|
||||||
current_ellipse -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
|
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) {
|
if (e -> button() & Qt::LeftButton) {
|
||||||
switch(behavior) {
|
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:
|
case Ellipse:
|
||||||
if (qgiManager().manages(current_ellipse)) break;
|
if (qgiManager().manages(current_ellipse)) break;
|
||||||
current_ellipse -> setRect(current_ellipse -> rect().normalized());
|
current_ellipse -> setRect(current_ellipse -> rect().normalized());
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ class CustomElementPart;
|
|||||||
class ElementEditionCommand;
|
class ElementEditionCommand;
|
||||||
class ElementPrimitiveDecorator;
|
class ElementPrimitiveDecorator;
|
||||||
class QETElementEditor;
|
class QETElementEditor;
|
||||||
class PartRectangle;
|
|
||||||
class PartEllipse;
|
class PartEllipse;
|
||||||
class PartPolygon;
|
class PartPolygon;
|
||||||
class PartArc;
|
class PartArc;
|
||||||
@@ -45,7 +44,7 @@ class ElementScene : public QGraphicsScene {
|
|||||||
|
|
||||||
// enum
|
// enum
|
||||||
public:
|
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 {
|
enum ItemOption {
|
||||||
SortByZValue = 1,
|
SortByZValue = 1,
|
||||||
IncludeTerminals = 2,
|
IncludeTerminals = 2,
|
||||||
@@ -54,7 +53,7 @@ class ElementScene : public QGraphicsScene {
|
|||||||
NonSelected = 16,
|
NonSelected = 16,
|
||||||
SelectedOrNot = 24
|
SelectedOrNot = 24
|
||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(ItemOptions, ItemOption);
|
Q_DECLARE_FLAGS(ItemOptions, ItemOption)
|
||||||
|
|
||||||
// constructors, destructor
|
// constructors, destructor
|
||||||
public:
|
public:
|
||||||
@@ -90,7 +89,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;
|
||||||
PartRectangle *current_rectangle;
|
|
||||||
PartEllipse *current_ellipse;
|
PartEllipse *current_ellipse;
|
||||||
PartPolygon *current_polygon;
|
PartPolygon *current_polygon;
|
||||||
PartArc *current_arc;
|
PartArc *current_arc;
|
||||||
@@ -168,7 +166,6 @@ class ElementScene : public QGraphicsScene {
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slot_move();
|
void slot_move();
|
||||||
void slot_addRectangle();
|
|
||||||
void slot_addCircle();
|
void slot_addCircle();
|
||||||
void slot_addEllipse();
|
void slot_addEllipse();
|
||||||
void slot_addPolygon();
|
void slot_addPolygon();
|
||||||
|
|||||||
97
sources/editor/esevent/eseventaddrect.cpp
Normal file
97
sources/editor/esevent/eseventaddrect.cpp
Normal 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;
|
||||||
|
}
|
||||||
41
sources/editor/esevent/eseventaddrect.h
Normal file
41
sources/editor/esevent/eseventaddrect.h
Normal 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
|
||||||
@@ -42,6 +42,7 @@
|
|||||||
#include "parttextfield.h"
|
#include "parttextfield.h"
|
||||||
|
|
||||||
#include "eseventaddline.h"
|
#include "eseventaddline.h"
|
||||||
|
#include "eseventaddrect.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
/*
|
/*
|
||||||
@@ -246,8 +247,8 @@ void QETElementEditor::setupActions() {
|
|||||||
connect(edit_backward, SIGNAL(triggered()), ce_scene, SLOT(slot_sendBackward()));
|
connect(edit_backward, SIGNAL(triggered()), ce_scene, SLOT(slot_sendBackward()));
|
||||||
connect(move, SIGNAL(triggered()), ce_scene, SLOT(slot_move()));
|
connect(move, SIGNAL(triggered()), ce_scene, SLOT(slot_move()));
|
||||||
|
|
||||||
connect(add_line, SIGNAL(triggered()), this, SLOT(addLine()));
|
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_ellipse, SIGNAL(triggered()), ce_scene, SLOT(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()));
|
||||||
@@ -930,6 +931,14 @@ void QETElementEditor::addLine() {
|
|||||||
ce_scene -> setEventInterface(new ESEventAddLine(ce_scene));
|
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.
|
Lance l'assistant de creation d'un nouvel element.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ class QETElementEditor : public QETMainWindow {
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void addLine();
|
void addLine();
|
||||||
|
void addRect();
|
||||||
|
|
||||||
void slot_new();
|
void slot_new();
|
||||||
void slot_open();
|
void slot_open();
|
||||||
|
|||||||
Reference in New Issue
Block a user