2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2010-01-03 16:25:37 +00:00
|
|
|
Copyright 2006-2010 Xavier Guerrin
|
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/>.
|
|
|
|
*/
|
2010-04-18 20:48:15 +00:00
|
|
|
#ifndef TERMINAL_H
|
|
|
|
#define TERMINAL_H
|
2007-04-09 02:56:47 +00:00
|
|
|
#include <QtGui>
|
|
|
|
#include <QtXml>
|
2007-06-30 17:41:07 +00:00
|
|
|
#include "qet.h"
|
2007-10-03 17:02:39 +00:00
|
|
|
class Conductor;
|
2007-04-09 02:56:47 +00:00
|
|
|
class Diagram;
|
2007-04-12 03:13:13 +00:00
|
|
|
class Element;
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
2010-04-18 20:48:15 +00:00
|
|
|
Cette classe represente une borne d'un element, c'est-a-dire un
|
|
|
|
branchement possible pour un conducteur.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
|
|
|
class Terminal : public QGraphicsItem {
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
// constructeurs, destructeur
|
2007-04-09 02:56:47 +00:00
|
|
|
public:
|
2007-06-30 17:41:07 +00:00
|
|
|
Terminal(QPointF, QET::Orientation, Element * = 0, Diagram * = 0);
|
|
|
|
Terminal(qreal, qreal, QET::Orientation, Element * = 0, Diagram * = 0);
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual ~Terminal();
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
private:
|
|
|
|
Terminal(const Terminal &);
|
|
|
|
|
|
|
|
// methodes
|
|
|
|
public:
|
2007-10-21 16:10:21 +00:00
|
|
|
/**
|
2007-12-16 13:21:28 +00:00
|
|
|
permet de caster un QGraphicsItem en Terminal avec qgraphicsitem_cast
|
2007-10-21 16:10:21 +00:00
|
|
|
@return le type de QGraphicsItem
|
|
|
|
*/
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual int type() const { return Type; }
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
// implementation des methodes virtuelles pures de QGraphicsItem
|
|
|
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
|
|
|
QRectF boundingRect() const;
|
|
|
|
|
|
|
|
// methodes de manipulation des conducteurs lies a cette borne
|
2007-10-03 17:02:39 +00:00
|
|
|
bool addConductor(Conductor *);
|
|
|
|
void removeConductor(Conductor *);
|
2010-04-18 20:48:15 +00:00
|
|
|
int conductorsCount() const;
|
2007-09-25 23:24:36 +00:00
|
|
|
Diagram *diagram() const;
|
2010-04-18 20:48:15 +00:00
|
|
|
Element *parentElement() const;
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
// methodes de lecture
|
2007-10-03 17:02:39 +00:00
|
|
|
QList<Conductor *> conductors() const;
|
2007-06-30 17:41:07 +00:00
|
|
|
QET::Orientation orientation() const;
|
2010-04-18 20:48:15 +00:00
|
|
|
QPointF dockConductor() const;
|
2007-10-03 17:02:39 +00:00
|
|
|
void updateConductor(QPointF = QPointF());
|
2010-04-18 20:48:15 +00:00
|
|
|
bool isLinkedTo(Terminal *);
|
|
|
|
bool canBeLinkedTo(Terminal *);
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
// methodes relatives a l'import/export au format XML
|
|
|
|
static bool valideXml(QDomElement &);
|
2007-04-12 03:13:13 +00:00
|
|
|
bool fromXml (QDomElement &);
|
|
|
|
QDomElement toXml (QDomDocument &) const;
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// methodes de gestion des evenements
|
|
|
|
void hoverEnterEvent (QGraphicsSceneHoverEvent *);
|
|
|
|
void hoverMoveEvent (QGraphicsSceneHoverEvent *);
|
|
|
|
void hoverLeaveEvent (QGraphicsSceneHoverEvent *);
|
|
|
|
void mousePressEvent (QGraphicsSceneMouseEvent *);
|
|
|
|
void mouseMoveEvent (QGraphicsSceneMouseEvent *);
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
// attributs
|
|
|
|
public:
|
|
|
|
enum { Type = UserType + 1002 };
|
2007-10-21 16:10:21 +00:00
|
|
|
/// Longueur d'une borne
|
2007-10-10 22:35:32 +00:00
|
|
|
static const qreal terminalSize;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
// differentes couleurs statiques utilisables pour l'effet "hover"
|
2007-10-21 16:10:21 +00:00
|
|
|
/// couleur par defaut
|
2010-04-18 20:48:15 +00:00
|
|
|
static QColor neutralColor;
|
2007-10-21 16:10:21 +00:00
|
|
|
/// couleur indiquant une action autorisee
|
2010-04-18 20:48:15 +00:00
|
|
|
static QColor allowedColor;
|
2007-10-21 16:10:21 +00:00
|
|
|
/// couleur indiquant une action autorisee mais pas forcement recommandee
|
2010-04-18 20:48:15 +00:00
|
|
|
static QColor warningColor;
|
2007-10-21 16:10:21 +00:00
|
|
|
/// couleur indiquant une action interdite
|
2010-04-18 20:48:15 +00:00
|
|
|
static QColor forbiddenColor;
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2010-04-18 20:48:15 +00:00
|
|
|
// attributs prives
|
|
|
|
private:
|
|
|
|
/// Pointeur vers l'element parent
|
|
|
|
Element *parent_element_;
|
|
|
|
/// coordonnees du point d'amarrage du conducteur
|
|
|
|
QPointF dock_conductor_;
|
|
|
|
/// coordonnees du point d'amarrage de l'element
|
|
|
|
QPointF dock_elmt_;
|
|
|
|
/// orientation de la borne
|
|
|
|
QET::Orientation ori_;
|
|
|
|
/// liste des conductors lies a cette borne
|
|
|
|
QList<Conductor *> conductors_;
|
|
|
|
/// pointeur vers un rectangle correspondant au bounding rect
|
|
|
|
/// permet de ne calculer le bounding rect qu'une seule fois
|
|
|
|
/// le pointeur c'est parce que le compilo exige une methode const
|
|
|
|
QRectF *br_;
|
|
|
|
/// Derniere borne mise en contact avec celle-ci
|
|
|
|
Terminal *previous_terminal_;
|
|
|
|
/// Booleen indiquant si le pointeur est au-dessus de la borne ou non
|
|
|
|
bool hovered_;
|
|
|
|
/// couleur de l'effet hover de la borne
|
|
|
|
QColor hovered_color_;
|
|
|
|
|
|
|
|
// methodes privees
|
2007-04-09 02:56:47 +00:00
|
|
|
private:
|
|
|
|
// methode initialisant les differents membres de la borne
|
2010-04-18 20:48:15 +00:00
|
|
|
void init(QPointF, QET::Orientation);
|
2007-04-09 02:56:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return Le nombre de conducteurs associes a la borne
|
|
|
|
*/
|
2010-04-18 20:48:15 +00:00
|
|
|
inline int Terminal::conductorsCount() const {
|
|
|
|
return(conductors_.size());
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return La position du point d'amarrage de la borne
|
|
|
|
*/
|
2010-04-18 20:48:15 +00:00
|
|
|
inline QPointF Terminal::dockConductor() const {
|
|
|
|
return(mapToScene(dock_conductor_));
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|