mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Element editor: add terminal is managed by esevent
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3475 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -72,16 +72,8 @@ void ElementScene::slot_move() {
|
||||
}
|
||||
|
||||
/**
|
||||
Passe la scene en mode "ajout de borne"
|
||||
*/
|
||||
void ElementScene::slot_addTerminal() {
|
||||
behavior = Terminal;
|
||||
if (m_event_interface) delete m_event_interface; m_event_interface = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
Gere les mouvements de la souris
|
||||
@param e objet decrivant l'evenement
|
||||
* @brief ElementScene::mouseMoveEvent
|
||||
* @param e
|
||||
*/
|
||||
void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
if (m_event_interface) {
|
||||
@@ -109,8 +101,8 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
}
|
||||
|
||||
/**
|
||||
Gere les appuis sur les boutons de la souris
|
||||
@param e objet decrivant l'evenement
|
||||
* @brief ElementScene::mousePressEvent
|
||||
* @param e
|
||||
*/
|
||||
void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
if (m_event_interface) {
|
||||
@@ -128,8 +120,8 @@ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||
}
|
||||
|
||||
/**
|
||||
Gere les relachements de boutons de la souris
|
||||
@param e objet decrivant l'evenement
|
||||
* @brief ElementScene::mouseReleaseEvent
|
||||
* @param e
|
||||
*/
|
||||
void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
if (m_event_interface) {
|
||||
@@ -143,11 +135,6 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
}
|
||||
}
|
||||
|
||||
QPointF event_pos = e -> scenePos();
|
||||
if (mustSnapToGrid(e)) event_pos = snapToGrid(event_pos);
|
||||
|
||||
PartTerminal *terminal;
|
||||
|
||||
if (behavior == PasteArea) {
|
||||
defined_paste_area_ = paste_area_ -> rect();
|
||||
removeItem(paste_area_);
|
||||
@@ -156,25 +143,13 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e -> button() & Qt::LeftButton) {
|
||||
switch(behavior) {
|
||||
case Terminal:
|
||||
terminal = new PartTerminal(element_editor, 0, this);
|
||||
terminal -> setPos(event_pos);
|
||||
undo_stack.push(new AddPartCommand(tr("borne"), this, terminal));
|
||||
emit(partsAdded());
|
||||
endCurrentBehavior(e);
|
||||
break;
|
||||
case Normal:
|
||||
default:
|
||||
// detecte les deplacements de parties
|
||||
QGraphicsScene::mouseReleaseEvent(e);
|
||||
moving_parts_ = false;
|
||||
}
|
||||
}
|
||||
else QGraphicsScene::mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementScene::mouseDoubleClickEvent
|
||||
* @param event
|
||||
*/
|
||||
void ElementScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if (m_event_interface) {
|
||||
if (m_event_interface -> mouseDoubleClickEvent(event)) {
|
||||
@@ -230,20 +205,6 @@ void ElementScene::drawForeground(QPainter *p, const QRectF &rect) {
|
||||
p -> restore();
|
||||
}
|
||||
|
||||
/**
|
||||
A partir d'un evenement souris, cette methode regarde si la touche shift est
|
||||
enfoncee ou non. Si oui, elle laisse le comportement en cours (cercle,
|
||||
texte, polygone, ...). Si non, elle repasse en mode normal / selection.
|
||||
@param event objet decrivant l'evenement souris
|
||||
*/
|
||||
void ElementScene::endCurrentBehavior(const QGraphicsSceneMouseEvent *event) {
|
||||
if (!(event -> modifiers() & Qt::ShiftModifier)) {
|
||||
// la touche Shift n'est pas enfoncee : on demande le mode normal
|
||||
behavior = Normal;
|
||||
emit(needNormalMode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementScene::setEventInterface
|
||||
* Set a new event interface
|
||||
@@ -504,14 +465,6 @@ void ElementScene::copy() {
|
||||
last_copied_ = clipboard_content;
|
||||
}
|
||||
|
||||
/**
|
||||
Gere le fait de coller le contenu du presse-papier = l'importer dans le
|
||||
presse-papier a une position donnee.
|
||||
*/
|
||||
void ElementScene::paste() {
|
||||
|
||||
}
|
||||
|
||||
void ElementScene::contextMenu(QContextMenuEvent *event) {
|
||||
if (behavior == ElementScene::Normal)
|
||||
element_editor -> contextMenu(event);
|
||||
|
||||
@@ -41,7 +41,7 @@ class ElementScene : public QGraphicsScene {
|
||||
|
||||
// enum
|
||||
public:
|
||||
enum Behavior { Normal, Terminal, PasteArea };
|
||||
enum Behavior { Normal, PasteArea };
|
||||
enum ItemOption {
|
||||
SortByZValue = 1,
|
||||
IncludeTerminals = 2,
|
||||
@@ -81,7 +81,6 @@ class ElementScene : public QGraphicsScene {
|
||||
*/
|
||||
QPointF fsi_pos;
|
||||
QPointF moving_press_pos;
|
||||
bool moving_parts_;
|
||||
|
||||
/// Variables related to drawing
|
||||
ESEventInterface *m_event_interface;
|
||||
@@ -132,7 +131,6 @@ class ElementScene : public QGraphicsScene {
|
||||
bool wasCopiedFromThisElement(const QString &);
|
||||
void cut();
|
||||
void copy();
|
||||
void paste();
|
||||
void contextMenu (QContextMenuEvent *event);
|
||||
QETElementEditor* editor() const;
|
||||
|
||||
@@ -144,7 +142,6 @@ class ElementScene : public QGraphicsScene {
|
||||
virtual void keyPressEvent (QKeyEvent *event);
|
||||
|
||||
virtual void drawForeground(QPainter *, const QRectF &);
|
||||
virtual void endCurrentBehavior(const QGraphicsSceneMouseEvent *);
|
||||
|
||||
private:
|
||||
QRectF elementContentBoundingRect(const ElementContent &) const;
|
||||
@@ -161,7 +158,6 @@ class ElementScene : public QGraphicsScene {
|
||||
|
||||
public slots:
|
||||
void slot_move();
|
||||
void slot_addTerminal();
|
||||
void slot_select(const ElementContent &);
|
||||
void slot_selectAll();
|
||||
void slot_deselectAll();
|
||||
|
||||
91
sources/editor/esevent/eseventaddterminal.cpp
Normal file
91
sources/editor/esevent/eseventaddterminal.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
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 "partterminal.h"
|
||||
#include "editorcommands.h"
|
||||
#include "elementscene.h"
|
||||
#include "eseventaddterminal.h"
|
||||
|
||||
/**
|
||||
* @brief ESEventAddTerminal::ESEventAddTerminal
|
||||
* @param scene
|
||||
*/
|
||||
ESEventAddTerminal::ESEventAddTerminal(ElementScene *scene) :
|
||||
ESEventInterface(scene)
|
||||
{
|
||||
m_terminal = new PartTerminal(m_editor, 0, m_scene);
|
||||
m_running = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddTerminal::~ESEventAddTerminal
|
||||
*/
|
||||
ESEventAddTerminal::~ESEventAddTerminal() {
|
||||
delete m_terminal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddTerminal::mouseMoveEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddTerminal::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
QPointF pos = m_scene -> snapToGrid(event -> scenePos());
|
||||
updateHelpCross(pos);
|
||||
m_terminal -> setPos(pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddTerminal::mouseReleaseEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddTerminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if (event -> button() == Qt::LeftButton) {
|
||||
m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Borne"), m_scene, m_terminal));
|
||||
|
||||
//Set new terminal with same rotation
|
||||
qreal rotation = m_terminal -> rotation();
|
||||
m_terminal = new PartTerminal(m_editor, 0, m_scene);
|
||||
m_terminal -> setRotation(rotation);
|
||||
m_terminal -> setPos(m_scene -> snapToGrid(event -> scenePos()));
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (event -> button() == Qt::RightButton) {
|
||||
m_running = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddTerminal::keyPressEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddTerminal::keyPressEvent(QKeyEvent *event) {
|
||||
if (event -> key() == Qt::Key_Space) {
|
||||
m_terminal -> setRotation(m_terminal -> rotation() + 90);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
45
sources/editor/esevent/eseventaddterminal.h
Normal file
45
sources/editor/esevent/eseventaddterminal.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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 ESEVENTADDTERMINAL_H
|
||||
#define ESEVENTADDTERMINAL_H
|
||||
|
||||
#include "eseventinterface.h"
|
||||
|
||||
class ElementScene;
|
||||
class PartTerminal;
|
||||
class QGraphicsSceneMouseEvent;
|
||||
|
||||
/**
|
||||
* @brief The ESEventAddTerminal class
|
||||
* This ESEvent manage creation of terminal in an ElementScene
|
||||
*/
|
||||
class ESEventAddTerminal : public ESEventInterface
|
||||
{
|
||||
public:
|
||||
ESEventAddTerminal(ElementScene *scene);
|
||||
virtual ~ESEventAddTerminal();
|
||||
|
||||
virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event);
|
||||
virtual bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
|
||||
virtual bool keyPressEvent (QKeyEvent *event);
|
||||
|
||||
private:
|
||||
PartTerminal *m_terminal;
|
||||
};
|
||||
|
||||
#endif // ESEVENTADDTERMINAL_H
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "eseventaddarc.h"
|
||||
#include "eseventaddtext.h"
|
||||
#include "eseventaddtextfield.h"
|
||||
#include "eseventaddterminal.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
/*
|
||||
@@ -258,7 +259,7 @@ void QETElementEditor::setupActions() {
|
||||
connect(add_polygon, SIGNAL(triggered()), this, SLOT(addPolygon()));
|
||||
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_terminal, SIGNAL(triggered()), this, SLOT(addTerminal()));
|
||||
connect(add_textfield, SIGNAL(triggered()), this, SLOT(addTextField()));
|
||||
|
||||
connect(move, SIGNAL(triggered()), this, SLOT(slot_setRubberBandToView()));
|
||||
@@ -978,12 +979,20 @@ void QETElementEditor::addText() {
|
||||
|
||||
/**
|
||||
* @brief QETElementEditor::addTextField
|
||||
* Set text field interface to scene
|
||||
* Set text field creation interface to scene
|
||||
*/
|
||||
void QETElementEditor::addTextField() {
|
||||
ce_scene -> setEventInterface(new ESEventAddTextField(ce_scene));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETElementEditor::addTerminal
|
||||
* Set terminal creation interface to scene
|
||||
*/
|
||||
void QETElementEditor::addTerminal() {
|
||||
ce_scene -> setEventInterface(new ESEventAddTerminal(ce_scene));
|
||||
}
|
||||
|
||||
/**
|
||||
Lance l'assistant de creation d'un nouvel element.
|
||||
*/
|
||||
|
||||
@@ -135,6 +135,7 @@ class QETElementEditor : public QETMainWindow {
|
||||
void addArc();
|
||||
void addText();
|
||||
void addTextField();
|
||||
void addTerminal();
|
||||
|
||||
void slot_new();
|
||||
void slot_open();
|
||||
|
||||
Reference in New Issue
Block a user