2006-10-27 15:47:22 +00:00
|
|
|
#ifndef ELEMENT_H
|
|
|
|
#define ELEMENT_H
|
|
|
|
#include <QtGui>
|
|
|
|
#include "borne.h"
|
|
|
|
class Schema;
|
|
|
|
class Element : public QGraphicsItem {
|
|
|
|
public:
|
|
|
|
enum { Type = UserType + 1000 };
|
|
|
|
virtual int type() const { return Type; }
|
|
|
|
Element(QGraphicsItem * = 0, Schema * = 0);
|
|
|
|
|
|
|
|
virtual int nbBornes() const = 0;
|
|
|
|
virtual int nbBornesMin() const = 0;
|
|
|
|
virtual int nbBornesMax() const = 0;
|
|
|
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0;
|
|
|
|
virtual QString typeId() = 0;
|
|
|
|
|
|
|
|
virtual QString nom() = 0;
|
|
|
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
|
|
|
QRectF boundingRect() const;
|
|
|
|
QSize setSize(int, int);
|
|
|
|
QPoint setHotspot(QPoint);
|
|
|
|
QPoint hotspot() const;
|
|
|
|
void select();
|
|
|
|
void deselect();
|
|
|
|
QPixmap pixmap();
|
|
|
|
QVariant itemChange(GraphicsItemChange, const QVariant &);
|
|
|
|
bool orientation() const;
|
|
|
|
bool invertOrientation();
|
|
|
|
void setPos(const QPointF &);
|
|
|
|
void setPos(qreal, qreal);
|
2006-11-04 13:57:40 +00:00
|
|
|
inline bool connexionsInternesAcceptees() { return(peut_relier_ses_propres_bornes); }
|
|
|
|
inline void setConnexionsInternesAcceptees(bool cia) { peut_relier_ses_propres_bornes = cia; }
|
2006-10-27 15:47:22 +00:00
|
|
|
static bool valideXml(QDomElement &);
|
|
|
|
virtual bool fromXml(QDomElement &, QHash<int, Borne *>&) = 0;
|
2006-11-09 19:19:51 +00:00
|
|
|
// methodes d'acces aux possibilites d'orientation
|
|
|
|
inline Borne::Orientation orientation() { return(ori); }
|
|
|
|
inline bool acceptOrientation(Borne::Orientation o) {
|
|
|
|
switch(o) {
|
|
|
|
case Borne::Nord: return(ori_n);
|
|
|
|
case Borne::Est: return(ori_e);
|
|
|
|
case Borne::Sud: return(ori_s);
|
|
|
|
case Borne::Ouest: return(ori_w);
|
|
|
|
default: return(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inline Borne::Orientation defaultOrientation() { return(ori_d); }
|
|
|
|
inline Borne::Orientation nextAcceptableOrientation() {
|
|
|
|
Borne::Orientation retour = nextOrientation(ori);
|
|
|
|
for (int i = 0 ; i < 4 ; ++ i) {
|
|
|
|
if (acceptOrientation(retour)) return(retour);
|
|
|
|
retour = nextOrientation(retour);
|
|
|
|
}
|
|
|
|
// on ne devrait pas arriver la : renvoi d'une valeur par defaut = nord
|
|
|
|
return(Borne::Nord);
|
|
|
|
}
|
|
|
|
inline Borne::Orientation previousAcceptableOrientation() {
|
|
|
|
Borne::Orientation retour = previousOrientation(ori);
|
|
|
|
for (int i = 0 ; i < 4 ; ++ i) {
|
|
|
|
if (acceptOrientation(retour)) return(retour);
|
|
|
|
retour = previousOrientation(retour);
|
|
|
|
}
|
|
|
|
// on ne devrait pas arriver la : renvoi d'une valeur par defaut = nord
|
|
|
|
return(Borne::Nord);
|
|
|
|
}
|
|
|
|
bool setOrientation(Borne::Orientation o);
|
2006-10-27 15:47:22 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
2006-11-09 19:19:51 +00:00
|
|
|
bool ori_n;
|
|
|
|
bool ori_s;
|
|
|
|
bool ori_e;
|
|
|
|
bool ori_w;
|
|
|
|
Borne::Orientation ori_d;
|
|
|
|
Borne::Orientation ori;
|
2006-10-27 15:47:22 +00:00
|
|
|
|
|
|
|
private:
|
2006-11-04 13:57:40 +00:00
|
|
|
bool peut_relier_ses_propres_bornes;
|
2006-10-27 15:47:22 +00:00
|
|
|
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
|
|
|
|
void updatePixmap();
|
2006-11-09 19:19:51 +00:00
|
|
|
inline Borne::Orientation nextOrientation(Borne::Orientation o) {
|
|
|
|
if (o < 0 || o > 2) return(Borne::Nord);
|
|
|
|
return((Borne::Orientation)(o + 1));
|
|
|
|
}
|
|
|
|
inline Borne::Orientation previousOrientation(Borne::Orientation o) {
|
|
|
|
if (o < 0 || o > 3) return(Borne::Nord);
|
|
|
|
if (o == Borne::Nord) return(Borne::Ouest);
|
|
|
|
return((Borne::Orientation)(o - 1));
|
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
QSize dimensions;
|
|
|
|
QPoint hotspot_coord;
|
|
|
|
QPixmap apercu;
|
|
|
|
QMenu menu;
|
|
|
|
};
|
|
|
|
#endif
|