File indexing completed on 2024-04-21 14:43:25

0001 /*
0002  * box2dgearjoint.h
0003  * Copyright (c) 2011 Joonas Erkinheimo <joonas.erkinheimo@nokia.com>
0004  *
0005  * This file is part of the Box2D QML plugin.
0006  *
0007  * This software is provided 'as-is', without any express or implied warranty.
0008  * In no event will the authors be held liable for any damages arising from
0009  * the use of this software.
0010  *
0011  * Permission is granted to anyone to use this software for any purpose,
0012  * including commercial applications, and to alter it and redistribute it
0013  * freely, subject to the following restrictions:
0014  *
0015  * 1. The origin of this software must not be misrepresented; you must not
0016  *    claim that you wrote the original software. If you use this software in
0017  *    a product, an acknowledgment in the product documentation would be
0018  *    appreciated but is not required.
0019  *
0020  * 2. Altered source versions must be plainly marked as such, and must not be
0021  *    misrepresented as being the original software.
0022  *
0023  * 3. This notice may not be removed or altered from any source distribution.
0024  */
0025 
0026 #ifndef BOX2DGEARJOINT_H
0027 #define BOX2DGEARJOINT_H
0028 
0029 #include "box2djoint.h"
0030 #include <Box2D.h>
0031 
0032 class Box2DGearJoint : public Box2DJoint
0033 {
0034     Q_OBJECT
0035 
0036     Q_PROPERTY(Box2DJoint *joint1 READ joint1 WRITE setJoint1 NOTIFY joint1Changed)
0037     Q_PROPERTY(Box2DJoint *joint2 READ joint2 WRITE setJoint2 NOTIFY joint2Changed)
0038     Q_PROPERTY(float ratio READ ratio WRITE setRatio NOTIFY ratioChanged)
0039 
0040 public:
0041     explicit Box2DGearJoint(QObject *parent = 0);
0042 
0043     Box2DJoint *joint1() const;
0044     void setJoint1(Box2DJoint *joint1);
0045 
0046     Box2DJoint *joint2() const;
0047     void setJoint2(Box2DJoint *joint2);
0048 
0049     float ratio() const;
0050     void setRatio(float ratio);
0051 
0052     b2GearJoint *gearJoint() const;
0053 
0054 signals:
0055     void joint1Changed();
0056     void joint2Changed();
0057     void ratioChanged();
0058 
0059 protected:
0060     b2Joint *createJoint();
0061 
0062 private slots:
0063     void joint1Created();
0064     void joint2Created();
0065 
0066 private:
0067     Box2DJoint *m_joint1;
0068     Box2DJoint *m_joint2;
0069     float m_ratio;
0070 };
0071 
0072 inline Box2DJoint *Box2DGearJoint::joint1() const
0073 {
0074     return m_joint1;
0075 }
0076 
0077 inline Box2DJoint *Box2DGearJoint::joint2() const
0078 {
0079     return m_joint2;
0080 }
0081 
0082 inline float Box2DGearJoint::ratio() const
0083 {
0084     return m_ratio;
0085 }
0086 
0087 inline b2GearJoint *Box2DGearJoint::gearJoint() const
0088 {
0089     return static_cast<b2GearJoint*>(joint());
0090 }
0091 
0092 #endif // BOX2DGEARJOINT_H