2007-12-01 10:47:15 +00:00
/*
2009-04-03 19:30:25 +00:00
Copyright 2006 - 2009 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/>.
*/
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-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
/**
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 :
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 * ) ;
int nbConductors ( ) const ;
2007-09-25 23:24:36 +00:00
Diagram * diagram ( ) 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 ;
2007-10-03 17:02:39 +00:00
QPointF amarrageConductor ( ) const ;
void updateConductor ( QPointF = QPointF ( ) ) ;
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
2007-06-30 17:41:07 +00:00
static QColor couleur_neutre ;
2007-10-21 16:10:21 +00:00
/// couleur indiquant une action autorisee
2007-06-30 17:41:07 +00:00
static QColor couleur_autorise ;
2007-10-21 16:10:21 +00:00
/// couleur indiquant une action autorisee mais pas forcement recommandee
2007-06-30 17:41:07 +00:00
static QColor couleur_prudence ;
2007-10-21 16:10:21 +00:00
/// couleur indiquant une action interdite
2007-06-30 17:41:07 +00:00
static QColor couleur_interdit ;
2007-04-09 02:56:47 +00:00
private :
// coordonnees des points d'amarrage
2007-10-03 17:02:39 +00:00
QPointF amarrage_conductor ;
2007-04-09 02:56:47 +00:00
QPointF amarrage_elmt ;
// orientation de la borne
2007-06-30 17:41:07 +00:00
QET : : Orientation sens ;
2007-10-03 17:02:39 +00:00
// liste des conductors lies a cette borne
QList < Conductor * > liste_conductors ;
2007-04-09 02:56:47 +00:00
// 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
*/
2007-10-03 17:02:39 +00:00
inline int Terminal : : nbConductors ( ) const {
return ( liste_conductors . size ( ) ) ;
2007-04-09 02:56:47 +00:00
}
/**
@ return La position du point d ' amarrage de la borne
*/
2007-10-03 17:02:39 +00:00
inline QPointF Terminal : : amarrageConductor ( ) const {
return ( mapToScene ( amarrage_conductor ) ) ;
2007-04-09 02:56:47 +00:00
}
2006-10-27 15:47:22 +00:00
# endif