class ColorUtil
{
public:
ColorUtil();
~ColorUtil(){}
};
ColorUtil::ColorUtil()
{
brushYellow.
setColor(QColor::fromRgb(255,
255,
0,
125));
brushRed.
setColor(QColor::fromRgb(255,
125,
125,
255));
brushBlue.
setColor(QColor::fromRgb(0,
0,
255,
125));
}
class ColorUtil
{
public:
ColorUtil();
~ColorUtil(){}
QBrush brushYellow;
QBrush brushRed;
QBrush brushBlue;
};
ColorUtil::ColorUtil()
{
brushYellow.setColor(QColor::fromRgb(255,255,0,125));
brushRed.setColor(QColor::fromRgb(255,125,125,255));
brushBlue.setColor(QColor::fromRgb(0,0,255,125));
}
To copy to clipboard, switch view to plain text mode
{
Q_OBJECT
public:
public:
~PocScene(){}
};
{
setSceneRect(-1000, -1000, 2000, 2000);
double wheelRadius = 0.05;
double carHeight = 0.15;
double carWidth = 0.3;
pen.setCosmetic(true);
pen.setWidth(2);
ColorUtil colorUtil;
car = addRect(-0.5*carWidth, -0.5*carHeight, carWidth, carHeight, pen, yellowBrush);
lWheel = addEllipse(-wheelRadius, -wheelRadius, 2.0*wheelRadius, 2.0*wheelRadius, pen, colorUtil.brushRed); // ColorUtil used here!
rWheel = addEllipse(-wheelRadius, -wheelRadius, 2.0*wheelRadius, 2.0*wheelRadius, pen, blueBrush);
}
class PocScene : public QGraphicsScene
{
Q_OBJECT
public:
QGraphicsRectItem* car;
QGraphicsEllipseItem* lWheel;
QGraphicsEllipseItem* rWheel;
public:
PocScene(QObject *parent = 0);
~PocScene(){}
};
PocScene::PocScene(QObject *parent) : QGraphicsScene(parent)
{
setSceneRect(-1000, -1000, 2000, 2000);
double wheelRadius = 0.05;
double carHeight = 0.15;
double carWidth = 0.3;
QPen pen;
pen.setCosmetic(true);
pen.setWidth(2);
QBrush yellowBrush(QColor::fromRgb(255,255,0,125));
QBrush redBrush(QColor::fromRgb(255,125,125,255));
QBrush blueBrush(QColor::fromRgb(0,0,255,125));
ColorUtil colorUtil;
car = addRect(-0.5*carWidth, -0.5*carHeight, carWidth, carHeight, pen, yellowBrush);
lWheel = addEllipse(-wheelRadius, -wheelRadius, 2.0*wheelRadius, 2.0*wheelRadius, pen, colorUtil.brushRed); // ColorUtil used here!
rWheel = addEllipse(-wheelRadius, -wheelRadius, 2.0*wheelRadius, 2.0*wheelRadius, pen, blueBrush);
}
To copy to clipboard, switch view to plain text mode
Bookmarks