Skip to content

Commit 5841022

Browse files
authored
Merge pull request #149 from godardma/master
Minor modifications on drawText and drawMotorBoat
2 parents 6021632 + 088b88b commit 5841022

2 files changed

Lines changed: 25 additions & 29 deletions

File tree

client-api/C++/examples/all_commands.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,11 @@ int main()
307307

308308
// Testing VIbes drawText function
309309
VIBES_TEST( vibes::newFigure("drawText") );
310-
VIBES_TEST( vibes::drawText(2,2,"My Text") );
310+
VIBES_TEST( vibes::newGroup("group") );
311+
VIBES_TEST( vibes::drawText(2,-1,"My Text"));
312+
VIBES_TEST( vibes::drawText(2,-2,"My Text",vibesParams("group","group"))) ;
311313
VIBES_TEST( vibes::drawText(2,2,"My Text", 0.1 , "b[k]") );
312-
VIBES_TEST( vibes::drawText(2,6,"My Text",vibesParams("FaceColor","red","EdgeColor","black","fontSize",15,"fontName","Cursive","name","Text") ) );
314+
VIBES_TEST( vibes::drawText(3,6,"My Text",vibesParams("FaceColor","red","EdgeColor","black","fontSize",15,"fontName","Cursive","name","Text") ) );
313315

314316

315317

viewer/vibesgraphicsitem.cpp

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,6 @@ bool VibesGraphicsText::parseJsonGraphics(const QJsonObject& json)
10411041
// #define GET_WITH_DEFAULT(dict,key,type,default_value) \
10421042
// dict.contains[key] ? dict[key].type
10431043

1044-
10451044
bool VibesGraphicsText::computeProjection(int dimX, int dimY)
10461045
{
10471046
const QJsonObject & json = this->_json;
@@ -1068,7 +1067,8 @@ bool VibesGraphicsText::computeProjection(int dimX, int dimY)
10681067
{
10691068
QFont textFont(fontName, fontSize);
10701069
this->setFont(textFont);
1071-
this->setTransform(QTransform(1, 0, 0, -1, pos[0].toDouble(),pos[1].toDouble()));
1070+
this->setTransform(QTransform(1, 0, 0, -1, 0., 0.));
1071+
this->setPos(pos[0].toDouble(), pos[1].toDouble() + scale);
10721072
this->setText(text);
10731073
this->setPen(pen);
10741074
this->setBrush(brush);
@@ -1542,7 +1542,6 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY)
15421542
body << QPointF(120,-80) + centerPoint;
15431543
body << QPointF(-72,-80) + centerPoint;
15441544

1545-
// Draw with the new properties
15461545
QGraphicsPolygonItem *graphics_body = new QGraphicsPolygonItem(body);
15471546
graphics_body->setPen(pen);
15481547
graphics_body->setBrush(brush);
@@ -1561,7 +1560,6 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY)
15611560
left_prop << QPointF(-72,16) + centerPoint;
15621561
left_prop << QPointF(-80,16) + centerPoint;
15631562

1564-
// Draw with the new properties
15651563
QGraphicsPolygonItem *graphics_left_prop = new QGraphicsPolygonItem(left_prop);
15661564
graphics_left_prop->setPen(pen);
15671565
graphics_left_prop->setBrush(QBrush(pen.color()));
@@ -1580,7 +1578,6 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY)
15801578
right_prop << QPointF(-72,-48) + centerPoint;
15811579
right_prop << QPointF(-80,-48) + centerPoint;
15821580

1583-
// Draw with the new properties
15841581
QGraphicsPolygonItem *graphics_right_prop = new QGraphicsPolygonItem(right_prop);
15851582
graphics_right_prop->setPen(pen);
15861583
graphics_right_prop->setBrush(QBrush(pen.color()));
@@ -1590,6 +1587,25 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY)
15901587
graphics_right_prop->setScale(length/401.);
15911588
this->addToGroup(graphics_right_prop);
15921589
}
1590+
1591+
// Hull details
1592+
{
1593+
QPainterPath hull_details;
1594+
hull_details.moveTo(120 + centerPoint.x(), 80 + centerPoint.y());
1595+
hull_details.lineTo(104 + centerPoint.x(), 64 + centerPoint.y());
1596+
hull_details.lineTo(-56 + centerPoint.x(), 64 + centerPoint.y());
1597+
hull_details.lineTo(-56 + centerPoint.x(), -64 + centerPoint.y());
1598+
hull_details.lineTo(104 + centerPoint.x(), -64 + centerPoint.y());
1599+
hull_details.lineTo(120 + centerPoint.x(), -80 + centerPoint.y());
1600+
1601+
QGraphicsPathItem *graphics_hull_details = new QGraphicsPathItem(hull_details);
1602+
graphics_hull_details->setPen(pen);
1603+
graphics_hull_details->setTransformOriginPoint(centerPoint);
1604+
graphics_hull_details->setRotation(orientation);
1605+
1606+
graphics_hull_details->setScale(length/401.);
1607+
this->addToGroup(graphics_hull_details);
1608+
}
15931609

15941610
// Engine
15951611
{
@@ -1599,7 +1615,6 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY)
15991615
engine << QPointF(30,-22.5) + centerPoint;
16001616
engine << QPointF(-15,-22.5) + centerPoint;
16011617

1602-
// Draw with the new properties
16031618
QGraphicsPolygonItem *graphics_engine = new QGraphicsPolygonItem(engine);
16041619
graphics_engine->setPen(pen);
16051620
graphics_engine->setBrush(QBrush(pen.color()));
@@ -1612,7 +1627,6 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY)
16121627

16131628
// Circle
16141629
{
1615-
// Draw with the new properties
16161630
QGraphicsEllipseItem *circle_item = new QGraphicsEllipseItem(centerPoint.x()-24+200, centerPoint.y()-24, 48, 48);
16171631
circle_item->setPen(pen);
16181632
circle_item->setTransformOriginPoint(centerPoint);
@@ -1621,26 +1635,6 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY)
16211635
circle_item->setScale(length/401.);
16221636
this->addToGroup(circle_item);
16231637
}
1624-
1625-
// Hull details
1626-
{
1627-
QPainterPath hull_details;
1628-
hull_details.moveTo(120 + centerPoint.x(), 80 + centerPoint.y());
1629-
hull_details.lineTo(104 + centerPoint.x(), 64 + centerPoint.y());
1630-
hull_details.lineTo(-56 + centerPoint.x(), 64 + centerPoint.y());
1631-
hull_details.lineTo(-56 + centerPoint.x(), -64 + centerPoint.y());
1632-
hull_details.lineTo(104 + centerPoint.x(), -64 + centerPoint.y());
1633-
hull_details.lineTo(120 + centerPoint.x(), -80 + centerPoint.y());
1634-
1635-
// Draw with the new properties
1636-
QGraphicsPathItem *graphics_hull_details = new QGraphicsPathItem(hull_details);
1637-
graphics_hull_details->setPen(pen);
1638-
graphics_hull_details->setTransformOriginPoint(centerPoint);
1639-
graphics_hull_details->setRotation(orientation);
1640-
1641-
graphics_hull_details->setScale(length/401.);
1642-
this->addToGroup(graphics_hull_details);
1643-
}
16441638
}
16451639

16461640
// Update successful

0 commit comments

Comments
 (0)