Skip to content

Commit

Permalink
refactoring: make ToolTip a property of AbstractObject
Browse files Browse the repository at this point in the history
  • Loading branch information
kaa-ching committed Aug 10, 2015
1 parent dc995f5 commit 39b9f3c
Show file tree
Hide file tree
Showing 24 changed files with 39 additions and 77 deletions.
10 changes: 10 additions & 0 deletions src/model/AbstractObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ Position AbstractObject::getTempCenter (void) const
}


const QString AbstractObject::getToolTip() const
{
// if there's a property "Description", use that
// otherwise check if theToolTip is usable
QString myToolTip = theToolTip;
theProps.property2String(Property::DESCRIPTION_STRING, &myToolTip, false);
return myToolTip;
}


bool AbstractObject::isMovable ( ) const
{
if (theIsLevelEditor)
Expand Down
5 changes: 4 additions & 1 deletion src/model/AbstractObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class AbstractObject : public SensorInterface, public ImpulseInterface
{ return AbstractObjectPtr(theThisPtr); }

/// @returns the Tooltip of the object.
virtual const QString getToolTip ( ) const = 0;
virtual const QString getToolTip ( ) const;

/// @returns true if the object can be moved by the user
virtual bool isMovable ( ) const;
Expand Down Expand Up @@ -388,6 +388,9 @@ class AbstractObject : public SensorInterface, public ImpulseInterface
b2Body* theB2BodyPtr;
b2BodyDef* theB2BodyDefPtr;

/// store a tooltip string
QString theToolTip;

/// the properties of the object instance
PropertyList theProps;

Expand Down
3 changes: 2 additions & 1 deletion src/model/Butterfly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ const double Butterfly::theButterflyMass = 0.01;


Butterfly::Butterfly()
: RectObject(), theCountdown(1)
: RectObject(), theCountdown(1)
{
theToolTip = QObject::tr("Butterfly (Flappus Chaoticus Fragilius) - always in search of flowers.");
theProps.setDefaultPropertiesString(
Property::OBJECT_STRING + QString(":/") +
Property::BOUNCINESS_STRING + QString(":0/") +
Expand Down
5 changes: 0 additions & 5 deletions src/model/Butterfly.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ class Butterfly : public RectObject, public SimStepCallbackInterface
virtual const QString getName ( ) const
{ return QObject::tr("Butterfly"); }

/// returns the Name of the object.
/// overridden from parent
virtual const QString getToolTip ( ) const
{ return QObject::tr("Butterfly (Flappus Chaoticus Fragilius) - always in search of flowers."); }

/// returns whether the object can be resized by the user
/// FIXME: overridden from RectObject, whereas we should *use* rectobject
virtual SizeDirections isResizable ( ) const
Expand Down
3 changes: 2 additions & 1 deletion src/model/CircleObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ CircleObject::CircleObject (const QString& aName,
qreal aRadius,
qreal aMass,
qreal aBounciness)
: theBallName(aName), theBallTooltip(aTooltip)
: theBallName(aName)
{
DEBUG5ENTRY;
createBallShapeFixture(aRadius, aMass);
setTheBounciness(aBounciness);
theToolTip = aTooltip;
theProps.setDefaultPropertiesString(
QString("%1:%2/").arg(Property::IMAGE_NAME_STRING).arg(anImageName)
+ QString(Property::BOUNCINESS_STRING) + QString(":%1").arg(aBounciness));
Expand Down
5 changes: 0 additions & 5 deletions src/model/CircleObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ class CircleObject : public AbstractObject
virtual b2BodyType getObjectType(void) const
{ return theB2ObjectType; }

/// returns the Tooltip of the object.
virtual const QString getToolTip ( ) const
{ return theBallTooltip; }

/// returns true if the object can be rotated by the user
virtual bool isRotatable ( ) const
{ return false; }
Expand All @@ -78,7 +74,6 @@ class CircleObject : public AbstractObject

private:
QString theBallName;
QString theBallTooltip;

b2BodyType theB2ObjectType;
};
Expand Down
3 changes: 2 additions & 1 deletion src/model/Glue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Glue::Glue() : AbstractJoint()
theSecondLocalPosPtr = NULL;
theLinkPtr = NULL;

theProps.setDefaultPropertiesString(
theToolTip = QObject::tr("Glue links two objects immovably together.");
theProps.setDefaultPropertiesString(
Property::OBJECT1_STRING + QString(":/") +
Property::OBJECT2_STRING + QString(":/") +
"-" + Property::MASS_STRING + ":/" );
Expand Down
5 changes: 0 additions & 5 deletions src/model/Glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ class Glue : public AbstractJoint
*/
virtual Position getTempCenter ( ) const;

/// overridden from AbstractObject
/// returns the Tooltip of the object.
virtual const QString getToolTip ( ) const
{ return QObject::tr("Glue links two objects immovably together."); }

/// overridden from AbstractObject
/// returns whether the object can be resized by the user
virtual SizeDirections isResizable ( ) const
Expand Down
1 change: 1 addition & 0 deletions src/model/Link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Link::Link(void)
theFirstLocalPosPtr(NULL),
theSecondLocalPosPtr(NULL)
{
theToolTip=QObject::tr("A Link is a massless, bodyless connection between two objects.");
theProps.setDefaultPropertiesString(
Property::OBJECT1_STRING + QString(":/") +
Property::OBJECT2_STRING + QString(":/") +
Expand Down
5 changes: 0 additions & 5 deletions src/model/Link.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ class Link : public AbstractJoint
*/
virtual Position getTempCenter ( ) const;

/// overridden from AbstractObject
/// returns the Tooltip of the object.
virtual const QString getToolTip ( ) const
{ return QObject::tr("A Link is a massless, bodyless connection between two objects."); }

/// overridden from AbstractObject
/// returns whether the object can be resized by the user
virtual SizeDirections isResizable ( ) const
Expand Down
5 changes: 3 additions & 2 deletions src/model/PivotPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ PivotPoint::PivotPoint(AbstractObjectPtr aAbstractObject, const Vector& aRelativ
{
DEBUG4("PivotPoint::PivotPoint(aAbstractObject*=%p, aPos=(%f,%f))\n",
aAbstractObject.get(), aRelativePosition.dx, aRelativePosition.dy);
thePosRelativeToFirst = aRelativePosition;
thePosRelativeToFirst = aRelativePosition;
updateOrigCenter();
initPivotAttributes();
}
Expand Down Expand Up @@ -124,7 +124,8 @@ void PivotPoint::initPivotAttributes ( )
theSecondPtr = NULL;
areObjectsColliding=false;

theProps.setDefaultPropertiesString(
theToolTip = QObject::tr("Objects rotate around this point");
theProps.setDefaultPropertiesString(
Property::OBJECT1_STRING + QString(":/") +
Property::OBJECT2_STRING + QString(":/") +
Property::SPEED_STRING + QString(":/") +
Expand Down
5 changes: 0 additions & 5 deletions src/model/PivotPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ class PivotPoint : public AbstractJoint
virtual const QString getName ( ) const
{ return QObject::tr("PivotPoint"); }

/// overridden from AbstractObject
/// returns the Tooltip of the object.
virtual const QString getToolTip ( ) const
{ return QObject::tr("Objects rotate around this point"); }

/// overridden from AbstractObject
/// returns whether the object can be resized by the user
virtual SizeDirections isResizable ( ) const
Expand Down
3 changes: 2 additions & 1 deletion src/model/PolyObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ PolyObject::PolyObject( const QString& aDisplayName,
const QString& aImageName,
const QString& anOutline,
qreal aWidth, qreal aHeight, qreal aMass, qreal aBounciness )
: theNameString(aDisplayName), theToolTipString(aTooltip)
: theNameString(aDisplayName)
{
DEBUG5("PolyObject::PolyObject(%s, %f, %f)", ASCII(aDisplayName), aWidth, aHeight);
theToolTip = aTooltip;
theProps.setDefaultPropertiesString(
Property::FRICTION_STRING + QString(":/") +
Property::IMAGE_NAME_STRING + QString(":") + aImageName + QString("/") +
Expand Down
5 changes: 0 additions & 5 deletions src/model/PolyObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ class PolyObject : public AbstractObject
/// or b2_dynamicBody if the property mass was set
virtual b2BodyType getObjectType(void) const;

/// returns the Tooltip of the object.
virtual const QString getToolTip ( ) const
{ return theToolTipString; }

/// parse all properties
/// partially overridden from AbstractObject
virtual void parseProperties(void);
Expand All @@ -90,7 +86,6 @@ class PolyObject : public AbstractObject

protected:
QString theNameString;
QString theToolTipString;

/// AABB calculates the Axis-Aligned Bounding Box
/// which we can use for scaling
Expand Down
3 changes: 3 additions & 0 deletions src/model/PostIt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ PostIt::PostIt( )
theProps.setDefaultPropertiesString(
QString("-") + Property::IMAGE_NAME_STRING + QString(":/") +
"-" + Property::MASS_STRING + QString(":/") );
theToolTip = QObject::tr("Someone left notes all over the place.\n"
"You know, those yellow 3x3 inch pieces of paper.\n"
"You might want to read them - it may help!");

DEBUG5("PostIt::PostIt done\n");
}
Expand Down
8 changes: 0 additions & 8 deletions src/model/PostIt.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ class PostIt : public AbstractObject
virtual b2BodyType getObjectType(void) const
{ return b2_staticBody; }

/// returns the Tooltip of the object.
virtual const QString getToolTip ( ) const
{
return QObject::tr("Someone left notes all over the place.\n"
"You know, those yellow 3x3 inch pieces of paper.\n"
"You might want to read them - it may help!");
}

/// returns true if the object can be rotated by the user
/// PostIts cannot be adjusted by the player
virtual bool isRotatable ( ) const
Expand Down
12 changes: 6 additions & 6 deletions src/model/RectObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class AbstractRectObjectFactory : public ObjectFactory
qreal aHeight,
qreal aMass,
qreal aBounciness)
: theDisplayName(aDisplayName), theTooltip(aTooltip),
theImageName(anImageName), theWidth(aWidth), theHeight(aHeight),
: theDisplayName(aDisplayName), theTooltip(aTooltip),
theImageName(anImageName), theWidth(aWidth), theHeight(aHeight),
theMass(aMass), theBounciness(aBounciness)
{ announceObjectType(anInternalName, this); }

virtual AbstractObject* createObject(void) const
{ return fixObject(new RectObject(theDisplayName, theTooltip,
{ return fixObject(new RectObject(theDisplayName, theTooltip,
theImageName, theWidth, theHeight,
theMass, theBounciness)); }
private:
Expand Down Expand Up @@ -128,10 +128,11 @@ RectObject::RectObject( const QString& aDisplayName,
const QString& aTooltip,
const QString& aImageName,
qreal aWidth, qreal aHeight, qreal aMass, qreal aBounciness )
: theNameString(aDisplayName), theToolTipString(aTooltip)
: theNameString(aDisplayName)
{
theProps.setProperty(Property::IMAGE_NAME_STRING, aImageName);
setTheWidth(aWidth);
theToolTip = aTooltip;
setTheWidth(aWidth);
setTheHeight(aHeight);

if (aMass > 0.001)
Expand Down Expand Up @@ -196,7 +197,6 @@ void RectObject::parseProperties(void)
if (myString == Property::TOTALRESIZE_STRING)
resizableInfo = TOTALRESIZE;
}
theProps.property2String(Property::DESCRIPTION_STRING, &theToolTipString);

clearShapeList();
b2PolygonShape* myBoxShape = new b2PolygonShape();
Expand Down
8 changes: 0 additions & 8 deletions src/model/RectObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ class RectObject : public AbstractObject
/// or b2_dynamicBody if the property mass was set
virtual b2BodyType getObjectType(void) const;

/// returns the Tooltip of the object.
virtual const QString getToolTip ( ) const
{
return theToolTipString;
}

/// @returns whether the object can be resized by the user
virtual SizeDirections isResizable ( ) const
{ return resizableInfo; }
Expand All @@ -91,8 +85,6 @@ class RectObject : public AbstractObject

protected:
QString theNameString;
QString theToolTipString;

SizeDirections resizableInfo;
};

Expand Down
2 changes: 1 addition & 1 deletion src/model/Scenery.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Scenery : public AbstractObject
{ return b2_staticBody; }

/// returns the Tooltip of the object.
virtual const QString getToolTip ( ) const
virtual const QString getToolTip ( ) const override
{
// no tooltip, no i18n
return "";
Expand Down
6 changes: 0 additions & 6 deletions src/model/Spring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,6 @@ qreal Spring::getTempWidth() const
return myOtherEndPtr->getDistance() + getTheWidth();
}

const QString Spring::getToolTip ( ) const
{
//: Translators: The %1 will be replaced by a phone number.
return QObject::tr("Send BOOM to me");
}

void Spring::setOrigCenter ( const Position& aNewPos )
{
RectObject::setOrigCenter(aNewPos);
Expand Down
4 changes: 0 additions & 4 deletions src/model/Spring.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ class Spring : public RectObject
*/
virtual Position getTempCenter ( ) const;

/// overridden from RectObject to make sure
/// we can display the phone number
virtual const QString getToolTip ( ) const;

/// returns whether the object can be resized by the user
virtual SizeDirections isResizable ( ) const
{ return NORESIZING; }
Expand Down
3 changes: 2 additions & 1 deletion src/model/TranslationGuide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ void TranslationGuide::initTG_Attributes ( )
{
areObjectsColliding=false;

theProps.setDefaultPropertiesString(
theToolTip = QObject::tr("Objects are limited to only move along one axis");
theProps.setDefaultPropertiesString(
Property::OBJECT_STRING + QString(":/") +
Property::SPEED_STRING + QString(":/") +
Property::FORCE_STRING + QString(":/") +
Expand Down
5 changes: 0 additions & 5 deletions src/model/TranslationGuide.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ class TranslationGuide : public AbstractJoint
virtual const QString getName ( ) const
{ return QObject::tr("TranslationGuide"); }

/// overridden from AbstractObject
/// returns the Tooltip of the object.
virtual const QString getToolTip ( ) const
{ return QObject::tr("Objects are limited to only move along one axis"); }

/// overridden from AbstractObject
/// returns whether the object can be resized by the user
virtual SizeDirections isResizable ( ) const
Expand Down
2 changes: 1 addition & 1 deletion src/model/TriggerExplosion.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class Dynamite : public PolyObject, public SimStepCallbackInterface

/// overridden from PolyObject to make sure
/// we can display the phone number
virtual const QString getToolTip ( ) const;
virtual const QString getToolTip ( ) const override;

/// requests removal of a splatter from the list
void removeMe(AbstractObjectPtr aDeadSplatterPtr);
Expand Down

0 comments on commit 39b9f3c

Please sign in to comment.