2006-10-27 15:47:22 +00:00
# ifndef BORNE_H
2007-04-09 02:56:47 +00:00
# define BORNE_H
# define TAILLE_BORNE 4
# include <QtGui>
# include <QtXml>
2007-06-30 17:41:07 +00:00
# include "qet.h"
2007-04-09 02:56:47 +00:00
class Conducer ;
class Diagram ;
2007-04-12 03:13:13 +00:00
class Element ;
2007-04-09 02:56:47 +00:00
/**
Classe modelisant la <EFBFBD> borne <EFBFBD> d ' un appareil , c ' est - a - dire un
branchement possible pour un Conducteur .
*/
class Terminal : public QGraphicsItem {
2007-04-12 03:13:13 +00:00
// constructeurs, destructeur
2007-04-09 02:56:47 +00:00
public :
Terminal ( ) ;
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 :
// permet de caster un QGraphicsItem en Borne avec qgraphicsitem_cast
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
bool addConducer ( Conducer * ) ;
void removeConducer ( Conducer * ) ;
int nbConducers ( ) const ;
2007-09-25 23:24:36 +00:00
Diagram * diagram ( ) const ;
2007-04-09 02:56:47 +00:00
// methodes de lecture
2007-04-12 03:13:13 +00:00
QList < Conducer * > conducers ( ) const ;
2007-06-30 17:41:07 +00:00
QET : : Orientation orientation ( ) const ;
2007-04-09 02:56:47 +00:00
QPointF amarrageConducer ( ) const ;
void updateConducer ( QPointF = QPointF ( ) ) ;
// 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-06-30 17:41:07 +00:00
// differentes couleurs statiques utilisables pour l'effet "hover"
static QColor couleur_neutre ;
static QColor couleur_autorise ;
static QColor couleur_prudence ;
static QColor couleur_interdit ;
2007-04-09 02:56:47 +00:00
private :
// coordonnees des points d'amarrage
QPointF amarrage_conducer ;
QPointF amarrage_elmt ;
// orientation de la borne
2007-06-30 17:41:07 +00:00
QET : : Orientation sens ;
2007-04-09 02:56:47 +00:00
// liste des conducers lies a cette borne
QList < Conducer * > liste_conducers ;
// 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 ;
Terminal * terminal_precedente ;
bool hovered ;
// methode initialisant les differents membres de la borne
2007-06-30 17:41:07 +00:00
void initialise ( QPointF , QET : : Orientation ) ;
// couleur de l'effet hover de la patte
2007-04-09 02:56:47 +00:00
QColor couleur_hovered ;
} ;
/**
@ return Le nombre de conducteurs associes a la borne
*/
inline int Terminal : : nbConducers ( ) const {
return ( liste_conducers . size ( ) ) ;
}
/**
@ return La position du point d ' amarrage de la borne
*/
inline QPointF Terminal : : amarrageConducer ( ) const {
return ( mapToScene ( amarrage_conducer ) ) ;
}
2006-10-27 15:47:22 +00:00
# endif