Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual
Page 185

KTD-S0057-I
Page 181 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
QPainterPath Mouse::shape () const
{
QPainterPath
path;
path.addRect (-10, -20, 20, 40);
return
path;
}
void Mouse::paint (QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
//
Body
painter->setBrush
(color);
painter->drawEllipse (-10, -20, 20, 40);
//
Eyes
painter->setBrush
(Qt::white);
painter->drawEllipse (-10, -17, 8, 8);
painter->drawEllipse (2, -17, 8, 8);
//
Nose
painter->setBrush
(Qt::black);
painter->drawEllipse (QRectF (-2, -22, 4, 4));
//
Pupils
painter->drawEllipse (QRectF (-8.0 + mouseEyeDirection, -17, 4, 4));
painter->drawEllipse (QRectF (4.0 + mouseEyeDirection, -17, 4, 4));
//
Ears
painter->setBrush (scene ()->collidingItems (this).isEmpty () ? Qt::darkYellow : Qt::red);
painter->drawEllipse (-17, -12, 16, 16);
painter->drawEllipse (1, -12, 16, 16);
//
Tail
QPainterPath path (QPointF (0, 20));
path.cubicTo (-5, 22, -5, 22, 0, 25);
path.cubicTo (5, 27, 5, 32, 0, 30);
path.cubicTo (-5, 32, -5, 42, 0, 35);
painter->setBrush
(Qt::NoBrush);
painter->drawPath
(path);
}
void Mouse::advance (int step)
{
if (! step)
return;
// Don't move too far away
QLineF lineToCenter (QPointF (0, 0), mapFromScene (0, 0));
if (lineToCenter.length () > 150)
{
qreal angleToCenter = ::acos (lineToCenter.dx () / lineToCenter.length ());
if (lineToCenter.dy () < 0)
angleToCenter = TwoPi - angleToCenter;
angleToCenter
=
normalizeAngle
((Pi - angleToCenter) + Pi / 2);