2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2017-01-20 10:55:49 +00:00
|
|
|
Copyright 2006-2017 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
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/>.
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
#include "terminaleditor.h"
|
|
|
|
#include "partterminal.h"
|
2009-05-01 14:41:33 +00:00
|
|
|
#include "qeticons.h"
|
2015-07-24 12:08:03 +00:00
|
|
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
2015-07-28 09:55:35 +00:00
|
|
|
#include <QDoubleSpinBox>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
2007-12-05 21:16:01 +00:00
|
|
|
@param editor L'editeur d'element concerne
|
|
|
|
@param term La borne a editer
|
2007-06-30 17:41:07 +00:00
|
|
|
@param parent QWidget parent de ce widget
|
|
|
|
*/
|
2010-02-18 00:42:41 +00:00
|
|
|
TerminalEditor::TerminalEditor(QETElementEditor *editor, PartTerminal *term, QWidget *parent) :
|
|
|
|
ElementItemEditor(editor, parent),
|
2015-07-24 12:08:03 +00:00
|
|
|
part(term),
|
|
|
|
m_locked(false)
|
2010-02-18 00:42:41 +00:00
|
|
|
{
|
2014-05-29 13:46:04 +00:00
|
|
|
qle_x = new QDoubleSpinBox();
|
|
|
|
qle_y = new QDoubleSpinBox();
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2016-08-08 08:15:22 +00:00
|
|
|
qle_x -> setRange(-5000, 5000);
|
|
|
|
qle_y -> setRange(-5000, 5000);
|
2007-12-17 20:37:10 +00:00
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
orientation = new QComboBox();
|
2014-05-29 13:46:04 +00:00
|
|
|
orientation -> addItem(QET::Icons::North, tr("Nord"), Qet::North);
|
|
|
|
orientation -> addItem(QET::Icons::East, tr("Est"), Qet::East);
|
|
|
|
orientation -> addItem(QET::Icons::South, tr("Sud"), Qet::South);
|
|
|
|
orientation -> addItem(QET::Icons::West, tr("Ouest"), Qet::West);
|
2013-11-16 19:20:15 +00:00
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
QVBoxLayout *main_layout = new QVBoxLayout();
|
2007-09-05 22:11:45 +00:00
|
|
|
main_layout -> addWidget(new QLabel(tr("Position : ")));
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
QHBoxLayout *position = new QHBoxLayout();
|
|
|
|
position -> addWidget(new QLabel(tr("x : ")));
|
|
|
|
position -> addWidget(qle_x );
|
|
|
|
position -> addWidget(new QLabel(tr("y : ")));
|
|
|
|
position -> addWidget(qle_y );
|
|
|
|
main_layout -> addLayout(position);
|
|
|
|
|
|
|
|
QHBoxLayout *ori = new QHBoxLayout();
|
|
|
|
ori -> addWidget(new QLabel(tr("Orientation : ")));
|
|
|
|
ori -> addWidget(orientation );
|
|
|
|
main_layout -> addLayout(ori);
|
2013-11-16 19:20:15 +00:00
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
main_layout -> addStretch();
|
|
|
|
setLayout(main_layout);
|
|
|
|
|
2007-08-25 03:43:05 +00:00
|
|
|
activeConnections(true);
|
2007-06-30 17:41:07 +00:00
|
|
|
updateForm();
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Destructeur
|
2007-06-30 17:41:07 +00:00
|
|
|
TerminalEditor::~TerminalEditor() {
|
|
|
|
};
|
|
|
|
|
2010-02-18 00:42:41 +00:00
|
|
|
/**
|
|
|
|
Permet de specifier a cet editeur quelle primitive il doit editer. A noter
|
|
|
|
qu'un editeur peut accepter ou refuser d'editer une primitive.
|
|
|
|
L'editeur de borne acceptera d'editer la primitive new_part s'il s'agit d'un
|
|
|
|
objet de la classe PartTerminal.
|
|
|
|
@param new_part Nouvelle primitive a editer
|
|
|
|
@return true si l'editeur a accepter d'editer la primitive, false sinon
|
|
|
|
*/
|
2015-07-24 12:08:03 +00:00
|
|
|
bool TerminalEditor::setPart(CustomElementPart *new_part)
|
|
|
|
{
|
|
|
|
if (!new_part)
|
|
|
|
{
|
|
|
|
if (part)
|
|
|
|
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
2010-02-18 00:42:41 +00:00
|
|
|
part = 0;
|
|
|
|
return(true);
|
|
|
|
}
|
2015-07-24 12:08:03 +00:00
|
|
|
if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part))
|
|
|
|
{
|
|
|
|
if(part == part_terminal) return true;
|
|
|
|
if (part)
|
|
|
|
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
2010-02-18 00:42:41 +00:00
|
|
|
part = part_terminal;
|
|
|
|
updateForm();
|
2015-07-24 12:08:03 +00:00
|
|
|
connect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
2010-02-18 00:42:41 +00:00
|
|
|
return(true);
|
|
|
|
}
|
2015-07-24 12:08:03 +00:00
|
|
|
return(false);
|
2010-02-18 00:42:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return la primitive actuellement editee, ou 0 si ce widget n'en edite pas
|
|
|
|
*/
|
|
|
|
CustomElementPart *TerminalEditor::currentPart() const {
|
|
|
|
return(part);
|
|
|
|
}
|
|
|
|
|
2015-07-24 12:08:03 +00:00
|
|
|
/// Met a jour l'orientation de la borne et cree un objet d'annulation
|
|
|
|
void TerminalEditor::updateTerminalO()
|
|
|
|
{
|
|
|
|
if (m_locked) return;
|
|
|
|
m_locked = true;
|
|
|
|
QVariant var(orientation -> itemData(orientation -> currentIndex()));
|
|
|
|
if (var != part->property("orientation"))
|
|
|
|
{
|
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "orientation", part->property("orientation"), var);
|
|
|
|
undo->setText(tr("Modifier l'orientation d'une borne"));
|
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
|
|
|
m_locked = false;
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2015-07-24 12:08:03 +00:00
|
|
|
void TerminalEditor::updatePos()
|
|
|
|
{
|
|
|
|
if (m_locked) return;
|
|
|
|
m_locked = true;
|
|
|
|
QPointF new_pos(qle_x->value(), qle_y->value());
|
|
|
|
if (new_pos != part->pos())
|
|
|
|
{
|
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "pos", part->property("pos"), new_pos);
|
|
|
|
undo->setText(tr("Déplacer une borne"));
|
|
|
|
undo->enableAnimation();
|
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
|
|
|
m_locked=false;
|
|
|
|
}
|
2013-11-16 19:20:15 +00:00
|
|
|
/// update Number and name, create cancel object
|
2014-05-29 13:46:04 +00:00
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Met a jour le formulaire d'edition
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
void TerminalEditor::updateForm() {
|
2010-02-18 00:42:41 +00:00
|
|
|
if (!part) return;
|
2007-08-25 03:43:05 +00:00
|
|
|
activeConnections(false);
|
2014-05-29 13:46:04 +00:00
|
|
|
qle_x -> setValue(part->property("x").toReal());
|
|
|
|
qle_y -> setValue(part->property("y").toReal());
|
|
|
|
orientation -> setCurrentIndex(orientation->findData(part->property("orientation")));
|
2007-08-25 03:43:05 +00:00
|
|
|
activeConnections(true);
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Active ou desactive les connexionx signaux/slots entre les widgets internes.
|
|
|
|
@param active true pour activer les connexions, false pour les desactiver
|
|
|
|
*/
|
2015-07-24 12:08:03 +00:00
|
|
|
void TerminalEditor::activeConnections(bool active)
|
|
|
|
{
|
|
|
|
if (active)
|
|
|
|
{
|
|
|
|
connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
|
|
|
|
connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
|
2007-08-25 03:43:05 +00:00
|
|
|
connect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
|
2015-07-24 12:08:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
|
|
|
|
disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
|
2007-08-25 03:43:05 +00:00
|
|
|
disconnect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
|
|
|
|
}
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|