mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 08:10:52 +01:00
Element editor : add text is managed by esevent
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3471 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -71,22 +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 cercle"
|
||||
*/
|
||||
void ElementScene::slot_addCircle() {
|
||||
behavior = Circle;
|
||||
if (m_event_interface) delete m_event_interface; m_event_interface = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
Passe la scene en mode "ajout de texte statique"
|
||||
*/
|
||||
void ElementScene::slot_addText() {
|
||||
behavior = Text;
|
||||
if (m_event_interface) delete m_event_interface; m_event_interface = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
Passe la scene en mode "ajout de borne"
|
||||
*/
|
||||
@@ -147,8 +131,6 @@ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
QPointF event_pos = e -> scenePos();
|
||||
if (mustSnapToGrid(e)) event_pos = snapToGrid(event_pos);
|
||||
|
||||
QGraphicsScene::mousePressEvent(e);
|
||||
}
|
||||
@@ -173,7 +155,6 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
if (mustSnapToGrid(e)) event_pos = snapToGrid(event_pos);
|
||||
|
||||
PartTerminal *terminal;
|
||||
PartText *text;
|
||||
PartTextField *textfield;
|
||||
|
||||
if (behavior == PasteArea) {
|
||||
@@ -193,13 +174,6 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
emit(partsAdded());
|
||||
endCurrentBehavior(e);
|
||||
break;
|
||||
case Text:
|
||||
text = new PartText(element_editor, 0, this);
|
||||
text -> setPos(event_pos);
|
||||
undo_stack.push(new AddPartCommand(tr("texte"), this, text));
|
||||
emit(partsAdded());
|
||||
endCurrentBehavior(e);
|
||||
break;
|
||||
case TextField:
|
||||
textfield = new PartTextField(element_editor, 0, this);
|
||||
textfield -> setPos(event_pos);
|
||||
|
||||
@@ -41,7 +41,7 @@ class ElementScene : public QGraphicsScene {
|
||||
|
||||
// enum
|
||||
public:
|
||||
enum Behavior { Normal, Circle, Text, Terminal, TextField, PasteArea };
|
||||
enum Behavior { Normal, Terminal, TextField, PasteArea };
|
||||
enum ItemOption {
|
||||
SortByZValue = 1,
|
||||
IncludeTerminals = 2,
|
||||
@@ -161,8 +161,6 @@ class ElementScene : public QGraphicsScene {
|
||||
|
||||
public slots:
|
||||
void slot_move();
|
||||
void slot_addCircle();
|
||||
void slot_addText();
|
||||
void slot_addTerminal();
|
||||
void slot_addTextField();
|
||||
void slot_select(const ElementContent &);
|
||||
|
||||
76
sources/editor/esevent/eseventaddtext.cpp
Normal file
76
sources/editor/esevent/eseventaddtext.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
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 "eseventaddtext.h"
|
||||
#include "parttext.h"
|
||||
#include "editorcommands.h"
|
||||
#include "elementscene.h"
|
||||
|
||||
/**
|
||||
* @brief ESEventAddText::ESEventAddText
|
||||
* @param scene
|
||||
*/
|
||||
ESEventAddText::ESEventAddText(ElementScene *scene) :
|
||||
ESEventInterface(scene)
|
||||
{
|
||||
m_text = new PartText(m_editor, 0, m_scene);
|
||||
m_running = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddText::~ESEventAddText
|
||||
*/
|
||||
ESEventAddText::~ESEventAddText() {
|
||||
delete m_text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddText::mouseMoveEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddText::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
QPointF pos = m_scene -> snapToGrid(event -> scenePos());
|
||||
updateHelpCross(pos);
|
||||
m_text->setPos(pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddText::mouseReleaseEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddText::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Texte"), m_scene, m_text));
|
||||
|
||||
//Set new text
|
||||
m_text = new PartText(m_editor, 0, m_scene);
|
||||
m_text -> setPos(m_scene -> snapToGrid(event -> scenePos()));
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (event->button() == Qt::RightButton) {
|
||||
m_running = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
44
sources/editor/esevent/eseventaddtext.h
Normal file
44
sources/editor/esevent/eseventaddtext.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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 ESEVENTADDTEXT_H
|
||||
#define ESEVENTADDTEXT_H
|
||||
|
||||
#include "eseventinterface.h"
|
||||
|
||||
class ElementScene;
|
||||
class PartText;
|
||||
class QGraphicsSceneMouseEvent;
|
||||
|
||||
/**
|
||||
* @brief The ESEventAddText class
|
||||
* This ESEvent manage creation of text in an ElementScene
|
||||
*/
|
||||
class ESEventAddText : public ESEventInterface
|
||||
{
|
||||
public:
|
||||
ESEventAddText(ElementScene *scene);
|
||||
virtual ~ESEventAddText();
|
||||
|
||||
virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event);
|
||||
virtual bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
|
||||
|
||||
private:
|
||||
PartText *m_text;
|
||||
};
|
||||
|
||||
#endif // ESEVENTADDTEXT_H
|
||||
@@ -46,6 +46,7 @@
|
||||
#include "eseventaddellipse.h"
|
||||
#include "eseventaddpolygon.h"
|
||||
#include "eseventaddarc.h"
|
||||
#include "eseventaddtext.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
/*
|
||||
@@ -254,7 +255,7 @@ void QETElementEditor::setupActions() {
|
||||
connect(add_rectangle, SIGNAL(triggered()), this, SLOT(addRect()));
|
||||
connect(add_ellipse, SIGNAL(triggered()), this, SLOT(addEllipse()));
|
||||
connect(add_polygon, SIGNAL(triggered()), this, SLOT(addPolygon()));
|
||||
connect(add_text, SIGNAL(triggered()), ce_scene, SLOT(slot_addText()));
|
||||
connect(add_text, SIGNAL(triggered()), this, SLOT(addText()));
|
||||
connect(add_arc, SIGNAL(triggered()), this, SLOT(addArc()));
|
||||
connect(add_terminal, SIGNAL(triggered()), ce_scene, SLOT(slot_addTerminal()));
|
||||
connect(add_textfield, SIGNAL(triggered()), ce_scene, SLOT(slot_addTextField()));
|
||||
@@ -966,6 +967,14 @@ void QETElementEditor::addArc() {
|
||||
ce_scene -> setEventInterface(new ESEventAddArc(ce_scene));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETElementEditor::addText
|
||||
* Set text creation interface to scene
|
||||
*/
|
||||
void QETElementEditor::addText() {
|
||||
ce_scene -> setEventInterface(new ESEventAddText(ce_scene));
|
||||
}
|
||||
|
||||
/**
|
||||
Lance l'assistant de creation d'un nouvel element.
|
||||
*/
|
||||
|
||||
@@ -133,6 +133,7 @@ class QETElementEditor : public QETMainWindow {
|
||||
void addEllipse();
|
||||
void addPolygon();
|
||||
void addArc();
|
||||
void addText();
|
||||
|
||||
void slot_new();
|
||||
void slot_open();
|
||||
|
||||
Reference in New Issue
Block a user