Canorus  0.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
/home/iurt/rpm/BUILD/canorus-0.7.R1002/src/drawable/drawable.h
Go to the documentation of this file.
00001 
00008 #ifndef DRAWABLE_H_
00009 #define DRAWABLE_H_
00010 
00011 #include <QRect>
00012 #include <QColor>
00013 
00014 class QPainter;
00015 
00016 struct CADrawSettings {
00017                 float z;       // zoom level
00018                 int x;         // painter x pos in pixels
00019                 int y;         // painter y pos in pixels
00020                 int w;         // canvas width in pixels
00021                 int h;         // canvas height in pixels
00022                 QColor color;  // pen color
00023                 double worldX; // x coordinate of the view
00024                 double worldY; // y coordinate of the view
00025 };
00026 
00027 class CADrawable {
00028 public:
00029         enum CADrawableType {
00030                 DrawableMusElement,
00031                 DrawableContext
00032         };
00033 
00034         enum CADirection {
00035                 Undefined,
00036                 Top,
00037                 Bottom,
00038                 Left,
00039                 Right,
00040                 TopLeft,
00041                 TopRight,
00042                 BottomLeft,
00043                 BottomRight
00044         };
00045 
00046         CADrawable( double x, double y );       // x and y position of an element in absolute world units
00047         virtual ~CADrawable() { }
00048         virtual void draw(QPainter *p, const CADrawSettings s) = 0;
00049         virtual CADrawable *clone();
00050 
00051         void drawHScaleHandles( QPainter *p, const CADrawSettings s );
00052         void drawVScaleHandles( QPainter *p, const CADrawSettings s );
00053 
00054         inline CADrawableType drawableType() { return _drawableType; }
00055         inline double xPos() { return _xPos; }
00056         inline double yPos() { return _yPos; }
00057         inline double width() { return _width; }
00058         inline double height() { return _height; }
00059         inline double neededSpaceWidth() { return _neededSpaceWidth; }
00060         inline double neededSpaceHeight() { return _neededSpaceHeight; }
00061         inline double neededWidth() { return _width+_neededSpaceWidth; }
00062         inline double neededHeight() { return _height+_neededSpaceHeight; }
00063         inline double xCenter() { return _xPos + (_width)/2; }
00064         inline double yCenter() { return _yPos + (_height)/2; }
00065         inline const QRect bBox() { return QRect(_xPos, _yPos, _width, _height); }
00066         inline bool isVisible() { return _visible; }
00067         inline bool isSelectable() { return _selectable; }
00068         inline bool isHScalable() { return _hScalable; }
00069         inline bool isVScalable() { return _vScalable; }
00070 
00071         inline void setXPos(double xPos) { _xPos = xPos; }
00072         inline void setYPos(double yPos) { _yPos = yPos; }
00073         inline void setWidth(double width) { _width = width; }
00074         inline void setHeight(double height) { _height = height; }
00075         inline void setNeededSpaceWidth( double width ) { _neededSpaceWidth = width; }
00076         inline void setNeededSpaceHeight( double height ) { _neededSpaceHeight = height; }
00077         inline void setVisible(bool v) { _visible = v; }
00078         inline void setSelectable(bool s) { _selectable = s; }
00079         inline void setHScalable(bool s) { _hScalable = s; }
00080         inline void setVScalable(bool s) { _vScalable = s; }
00081 
00082 protected:
00083         void setDrawableType( CADrawableType t ) { _drawableType = t; };
00084 
00085         CADrawableType _drawableType; // DrawableMusElement or DrawableContext.
00086         double _xPos;
00087         double _yPos;
00088         double _width;             // Element's width as it appears on the screen
00089         double _height;            // Element's height as it appears on the screen
00090         double _neededSpaceWidth;  // Minimum width the next element should be placed next to it by engraver
00091         double _neededSpaceHeight; // Minimum height the next element should be placed next to it by engraver
00092         bool _visible;
00093         bool _selectable;       // Can the element be clicked on and is then selected
00094         bool _hScalable;    // Can the element be streched horizontally
00095         bool _vScalable;    // Can the element be streched vertically
00096 
00097         static const int SCALE_HANDLES_SIZE; // Width and Height of the scale handles squares in pixels
00098 };
00099 
00100 #endif /* DRAWABLE_H_ */