00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef QSCOBJECT_H
00019 #define QSCOBJECT_H
00020
00021 #include"qsdrv.h"
00022 #include"qsserializable.h"
00023 #include<qobject.h>
00024
00025
00026 class QSCObject;
00027 template<class CHILD_OBJECT> class QSChildList;
00028
00035 class QSCObjectCollection : public QObject, public QSSerializable
00036 {
00037 Q_OBJECT
00038 public:
00043 QSCObjectCollection( QObject *parent=NULL, bool autoDelete=true );
00047 ~QSCObjectCollection();
00051 void setAutoUpdates( bool enable );
00055 bool autoUpdates() const { return m_auto_updates; }
00059 bool isEmpty() const { return count() == 0; }
00063 int count() const;
00067 void clear();
00071 void add( QSCObject *newObject );
00075 virtual void insert( int position, QSCObject *object );
00079 virtual void remove( int index );
00083 void removeDelete( int index );
00087 void raise( int index );
00091 void lower( int index );
00095 void toFront( int index );
00099 void toBack( int index );
00103 void reorder( int position, int index );
00107 int find( QSCObject *object ) const;
00111 QSCObject *object( int index ) const;
00115 void paintSkeleton( QPainter *p, double dpi = 72.0 );
00120 void paint( QPainter *p, double dpi = 72.0, bool blocking=true, bool transparent=true );
00125 void draw( QSDrv *drv, bool blocking=true, bool transparent=true );
00129 bool busy() const;
00133 void stop();
00137 QSCObject *objectAt( const QSPt2f &p, QSDrv* drv, bool recursive=false );
00141 bool contains( QSCObject *object, bool recursive=false );
00145 virtual void loadStateFromStream( QDataStream& stream, QSObjectFactory *factory );
00149 virtual void saveStateToStream( QDataStream& stream, QSObjectFactory *factory );
00150
00151 signals:
00155 void sigParametersChanging();
00159 void sigParametersChanged();
00163 void sigAdded( QSCObject *o );
00167 void sigAdded( QSCObjectCollection *collection, QSCObject *o );
00171 void sigRemoved( QSCObject *o );
00175 void sigRemoved( QSCObjectCollection *collection, QSCObject *o );
00179 void sigOrderChanged();
00183 void sigOrderChanged( QSCObjectCollection *collection );
00187 void sigListChanged();
00191 void sigListChanged( QSCObjectCollection *collection );
00196 void sigDataChildListChanged();
00200 void sigChanged();
00204 void sigDrawEnds();
00205
00206 protected:
00207 bool m_auto_updates;
00208 QSChildList<QSCObject> *m_objects;
00209 virtual void parametersChanging();
00210 virtual void parametersChanged();
00211 virtual void orderChanged();
00212 virtual void listChanged();
00213 virtual void changed();
00214 bool tempAutoUpdatesOff();
00215 void tempAutoUpdatesRestore( bool enable );
00216
00217 private slots:
00218 void slot_object_changed();
00219 void slot_data_child_list_changed();
00220 void slot_added(QSCObjectCollection*,QSCObject*);
00221 void slot_removed(QSCObjectCollection*,QSCObject*);
00222 void slot_order_changed(QSCObjectCollection*);
00223 void slot_list_changed(QSCObjectCollection*);
00224 void slot_draw_ends(QSCObject*);
00225 };
00226
00227
00228
00229 class QSAxes;
00230 class QSAxis;
00231 class QSData;
00232 class QSCGroup;
00233
00234 #define SET_COBJECT_PROPERTY( property, new_value ) if ((property)!=(new_value)) { parametersChanging(); (property)=(new_value); parametersChanged(); }
00235
00251 class QSCObject : public QObject, public QSSerializable {
00252 friend QSCObjectCollection;
00253 friend QSCGroup;
00254 Q_OBJECT
00255 Q_PROPERTY( int defaultXAxis READ defaultXAxis WRITE setDefaultXAxis )
00256 Q_PROPERTY( int defaultYAxis READ defaultYAxis WRITE setDefaultYAxis )
00257 Q_PROPERTY( int defaultZAxis READ defaultZAxis WRITE setDefaultZAxis )
00258 public:
00262 QSCObject( QObject *parent=NULL );
00266 virtual ~QSCObject();
00270 QSCGroup *group() const { return m_group; }
00275 QSCObjectCollection *collection() const { return m_collection; }
00280 QSCObjectCollection *rootCollection();
00287 virtual void setParentAxes( QSAxes *axes );
00291 QSAxes *parentAxes() const { return m_parent_axes; }
00295 enum Style { Rotateable = 1U<<0,
00296 Resizeable = 1U<<1,
00297 Moveable = 1U<<2 };
00302 virtual int style() { return 0; }
00306 virtual void setAutoUpdates( bool enabled );
00310 bool autoUpdates() const { return m_auto_updates; }
00314 virtual void raise();
00318 virtual void lower();
00322 virtual void toFront();
00326 virtual void toBack();
00330 virtual void reorder( int newPosition );
00334 virtual void paintSkeleton( QPainter *p, double dpi = 72.0 );
00339 virtual void paint( QPainter *p, double dpi = 72.0, bool blocking=true, bool transparent=true );
00344 virtual void draw( QSDrv *drv, bool blocking=true, bool transparent=true ) = 0;
00348 virtual bool busy() const { return false; }
00353 virtual void stop() {}
00357 virtual bool isHit( const QSPt2f &p, QSDrv* drv ) { return box(drv).contains(p); }
00363 virtual void setBox( const QSRectf& canvas_rect, QSDrv *drv );
00368 virtual QSRectf box( QSDrv *drv );
00372 virtual void setAngle( int deg );
00376 virtual int angle() const { return 0; }
00380 virtual QSPt2f rCenter( QSDrv *drv );
00384 virtual QString name() { return tr("Unknown object"); }
00388 virtual bool isAxesShadow() { return false; }
00392 void setDefaultAxis( QSAxis *axis );
00396 QSAxis *defaultAxis( int axisType ) const;
00402 QSPt3f mixedToCanvas( const QSPt3f& pos, int xCoordIn, int yCoordIn, int zCoordIn, double dpi );
00407 QSPt3f canvasToMixed( const QSPt3f& pos, int xCoordOut, int yCoordOut, int zCoordOut, double dpi );
00411 void setDefaultXAxis( int axisIndex );
00415 void setDefaultYAxis( int axisIndex );
00419 void setDefaultZAxis( int axisIndex );
00423 int defaultXAxis() const;
00427 int defaultYAxis() const;
00431 int defaultZAxis() const;
00435 virtual void loadStateFromStream( QDataStream& stream, QSObjectFactory *factory );
00439 virtual void saveStateToStream( QDataStream& stream, QSObjectFactory *factory );
00440
00441 public slots:
00445 virtual void parametersChanging();
00449 virtual void parametersChanged();
00453 virtual void forceUpdate();
00454
00455 signals:
00456 void sigDrawEnds( QSCObject *me );
00460 void sigUpdate( QSCObject *me );
00464 void sigUpdate();
00465
00466 protected:
00467 QSAxes *m_parent_axes;
00468 QSAxis *m_default_axis[3];
00469 bool m_auto_updates;
00470 QSCObjectCollection *m_collection;
00471 QSCGroup *m_group;
00475 virtual void setCollection( QSCObjectCollection *collection );
00479 virtual void setGroup( QSCGroup *group );
00480
00481 private slots:
00485 void axisRemoved( QSData *removedObject );
00489 void parentAxesRemoved( QSData *removedObject );
00490 };
00491
00492
00493
00499 class QSCGroup : public QSCObject
00500 {
00501 Q_OBJECT
00502 public:
00506 QSCGroup( QObject *parent=NULL );
00510 virtual ~QSCGroup();
00514 virtual void setParentAxes( QSAxes *axes );
00518 QSCObjectCollection *objects() const { return m_objects; }
00522 virtual int style() { return Moveable | Resizeable; }
00526 virtual void paintSkeleton( QPainter *p, double dpi = 72.0 );
00530 virtual void paint( QPainter *p, double dpi = 72.0, bool blocking=true, bool transparent=true );
00534 virtual void draw( QSDrv *drv, bool blocking=true, bool transparent=true );
00538 virtual bool busy() const;
00542 virtual void stop();
00546 virtual bool isHit( const QSPt2f &p, QSDrv* drv );
00550 virtual void setBox( const QSRectf& canvas_rect, QSDrv *drv );
00554 virtual QSRectf box( QSDrv *drv );
00558 virtual QString name();
00562 virtual void loadStateFromStream( QDataStream& stream, QSObjectFactory *factory );
00566 virtual void saveStateToStream( QDataStream& stream, QSObjectFactory *factory );
00567
00568 protected:
00569 QSCObjectCollection *m_objects;
00570 bool m_w_minus;
00571 bool m_h_minus;
00572
00573 protected slots:
00574 void slot_draw_ends();
00575 void slot_collection_changed();
00576 void slot_object_added( QSCObject * );
00577 void slot_object_removed( QSCObject * );
00578 };
00579
00580 #endif