00001 /*************************************************************************** 00002 * Copyright (C) 2004-2005 by David Saxton * 00003 * david@bluehaze.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 ***************************************************************************/ 00010 00011 #ifndef MECHANICSITEM_H 00012 #define MECHANICSITEM_H 00013 00014 #include <item.h> 00015 #include <qvaluelist.h> 00016 00017 class LibraryItem; 00018 class MechanicsItem; 00019 // class MechanicsItemOverlayItem; 00020 class MechanicsDocument; 00021 typedef QValueList<MechanicsItem*> MechanicsItemList; 00022 00027 class MechanicsInfo 00028 { 00029 public: 00030 MechanicsInfo(); 00031 00032 double mass; // Mass 00033 double momentOfInertia; // Moment of inertia 00034 }; 00035 00036 class CombinedMechanicsInfo : public MechanicsInfo 00037 { 00038 public: 00039 CombinedMechanicsInfo(); 00040 CombinedMechanicsInfo( const MechanicsInfo &info ); 00041 00042 double x; // X coordinate of center of mass 00043 double y; // Y coordinate of center of mass 00044 }; 00045 00050 class PositionInfo 00051 { 00052 public: 00053 PositionInfo(); 00059 const PositionInfo operator+( const PositionInfo &info ); 00064 const PositionInfo operator-( const PositionInfo &info ); 00068 double x() const { return m_x; } 00072 double y() const { return m_y; } 00076 double angle() const { return m_angle; } 00080 void setX( double x ) { m_x = x; } 00084 void setY( double y ) { m_y = y; } 00088 void setAngle( double angle ) { m_angle = angle; } 00092 void translate( double dx, const double dy ) { m_x += dx; m_y += dy; } 00096 void rotate( double angle ) { m_angle += angle; } 00100 void reset(); 00106 void rotateAboutPoint( double x, double y, double angle ); 00107 00108 protected: 00109 double m_x; 00110 double m_y; 00111 double m_angle; 00112 }; 00113 00114 00118 class MechanicsItem : public Item 00119 { 00120 Q_OBJECT 00121 public: 00122 MechanicsItem( MechanicsDocument *mechanicsDocument, bool newItem, const QString &id ); 00123 virtual ~MechanicsItem(); 00124 00125 enum SelectionMode 00126 { 00127 sm_move, 00128 sm_resize, 00129 sm_rotate 00130 }; 00134 int rtti() const; 00139 void setSelectionMode( SelectionMode sm ); 00140 virtual void setSelected( bool yes ); 00144 SelectionMode selectionMode() const { return m_selectionMode; } 00148 virtual void moveBy( double dx, double dy ); 00152 PositionInfo absolutePosition() const; 00157 PositionInfo relativePosition() const { return m_relativePosition; } 00162 MechanicsInfo *mechanicsInfo() { return &m_mechanicsInfo; } 00167 CombinedMechanicsInfo *mechanicsInfoCombined() { return &m_mechanicsInfoCombined; } 00173 QRect maxInnerRectangle( const QRect &outerRect ) const; 00174 00175 virtual ItemData itemData() const; 00176 00177 virtual bool mousePressEvent( const EventInfo &eventInfo ); 00178 virtual bool mouseReleaseEvent( const EventInfo &eventInfo ); 00179 virtual bool mouseDoubleClickEvent ( const EventInfo &eventInfo ); 00180 virtual bool mouseMoveEvent( const EventInfo &eventInfo ); 00181 virtual bool wheelEvent( const EventInfo &eventInfo ); 00182 virtual void enterEvent(); 00183 virtual void leaveEvent(); 00184 00185 public slots: 00189 void rotateBy( double dtheta ); 00190 void parentMoved(); 00191 00192 signals: 00196 void moved(); 00197 00198 protected slots: 00202 void updateMechanicsInfoCombined(); 00203 00204 protected: 00205 virtual void reparented( Item *oldItem, Item *newItem ); 00206 virtual void childAdded( Item *child ); 00207 virtual void childRemoved( Item *child ); 00211 virtual void itemResized() {}; 00215 void initPainter( QPainter &p ); 00219 void deinitPainter( QPainter &p ); 00220 virtual void dataChanged(); 00221 virtual void itemPointsChanged() { updateCanvasPoints(); } 00226 void updateCanvasPoints(); 00227 00228 MechanicsDocument *p_mechanicsDocument; 00229 PositionInfo m_relativePosition; // Absolution position if not attached to a parent item, or otherwise relative to parent item 00230 MechanicsInfo m_mechanicsInfo; 00231 CombinedMechanicsInfo m_mechanicsInfoCombined; 00232 00233 private: 00234 SelectionMode m_selectionMode; 00235 }; 00236 00237 #endif
1.5.1