//-----------------------------------------------------------------------------------
{
Q_OBJECT
public:
};
CMapView
::CMapView(QWidget * parent
){
setDragMode( ScrollHandDrag );
}
//-----------------------------------------------------------------------------------
{
Q_OBJECT
public:
CFlightPath();
private slots:
protected:
void placeAircraft();
CMapView * view;
};
CFlightPath::CFlightPath()
{
placeAircraft();
view = new CMapView();
view->setScene(scene);
setCentralWidget(view);
setWindowTitle("Flight Path");
mainClose = false;
}
void CFlightPath::placeAircraft()
{
CAircraft * airplane = new CAircraft();
ownship->setPos( 200, 300 );
scene->addItem( airplane );
}
//-----------------------------------------------------------------------------------
{
Q_OBJECT
public:
CAircraft();
private slots:
void moveAircraft();
private:
float xPos, yPos, deg, prevDeg;
int count;
};
CAircraft::CAircraft()
{
double localX = -24.0;
double localY = -14.0;
aircraft <<
QPointF( (localX
+24.0),
(localY
+0.0) ) <<
QPointF( (localX
+25.0),
(localY
+1.0) ) <<
QPointF( (localX
+26.0),
(localY
+2.0) ) <<
QPointF( (localX
+27.0),
(localY
+3.0) ) <<
QPointF( (localX
+27.0),
(localY
+9.0) ) <<
QPointF( (localX
+32.0),
(localY
+9.0) ) <<
QPointF( (localX
+32.0),
(localY
+8.0) ) <<
QPointF( (localX
+35.0),
(localY
+8.0) ) <<
QPointF( (localX
+35.0),
(localY
+9.0) ) <<
QPointF( (localX
+38.0),
(localY
+9.0) ) <<
QPointF( (localX
+38.0),
(localY
+8.0) ) <<
QPointF( (localX
+41.0),
(localY
+8.0) ) <<
QPointF( (localX
+41.0),
(localY
+9.0) ) <<
QPointF( (localX
+47.0),
(localY
+9.0) ) <<
QPointF( (localX
+48.0),
(localY
+10.0) ) <<
QPointF( (localX
+47.0),
(localY
+11.0) ) <<
QPointF( (localX
+36.0),
(localY
+13.0) ) <<
QPointF( (localX
+27.0),
(localY
+16.0) ) <<
QPointF( (localX
+26.0),
(localY
+31.0) ) <<
QPointF( (localX
+30.0),
(localY
+31.0) ) <<
QPointF( (localX
+31.0),
(localY
+32.0) ) <<
QPointF( (localX
+25.0),
(localY
+34.0) ) <<
QPointF( (localX
+23.0),
(localY
+34.0) ) <<
QPointF( (localX
+17.0),
(localY
+32.0) ) <<
QPointF( (localX
+18.0),
(localY
+31.0) ) <<
QPointF( (localX
+22.0),
(localY
+31.0) ) <<
QPointF( (localX
+21.0),
(localY
+16.0) ) <<
QPointF( (localX
+12.0),
(localY
+13.0) ) <<
QPointF( (localX
+1.0),
(localY
+11.0) ) <<
QPointF( (localX
+0.0),
(localY
+10.0) ) <<
QPointF( (localX
+1.0),
(localY
+9.0) ) <<
QPointF( (localX
+7.0),
(localY
+9.0) ) <<
QPointF( (localX
+7.0),
(localY
+8.0) ) <<
QPointF( (localX
+10.0),
(localY
+8.0) ) <<
QPointF( (localX
+10.0),
(localY
+9.0) ) <<
QPointF( (localX
+13.0),
(localY
+9.0) ) <<
QPointF( (localX
+13.0),
(localY
+8.0) ) <<
QPointF( (localX
+16.0),
(localY
+8.0) ) <<
QPointF( (localX
+16.0),
(localY
+9.0) ) <<
QPointF( (localX
+21.0),
(localY
+9.0) ) <<
QPointF( (localX
+21.0),
(localY
+3.0) ) <<
QPointF( (localX
+22.0),
(localY
+2.0) ) <<
QPointF( (localX
+23.0),
(localY
+1.0) );
shape.addPolygon( aircraft );
setFlag(ItemIgnoresTransformations, true);
updateTimer->setInterval( 50 );
connect( updateTimer, SIGNAL(timeout()), this, SLOT(moveAircraft()));
updateTimer->start();
xPos = 200.0;
yPos = 300.0;
deg = 270.0;
prevDeg = 0.0;
count = 0;
};
QRectF CAircraft
::boundingRect() const {
}
{
painter->setWindow(-100,-100, 200, 200);
painter->fillPath( shape, Qt::darkGray );
}
void CAircraft::moveAircraft()
{
float x, y;
if ( count < 50 )
xPos -= 1.0;
else if (count < 100 )
yPos += 1.0;
else if (count < 150 )
xPos += 1.0;
else if (count < 200 )
yPos -= 1.0;
else if (count < 250 )
{
yPos += 1.0;
xPos -= 1.0;
}
else if (count < 300 )
{
yPos -= 1.0;
xPos += 1.0;
}
count++;
x = xPos;
y = yPos;
setPos(x, y);
}
//-----------------------------------------------------------------------------------
class CMapView : public QGraphicsView
{
Q_OBJECT
public:
CMapView(QWidget * parent = 0);
};
CMapView::CMapView(QWidget * parent)
: QGraphicsView(parent)
{
setDragMode( ScrollHandDrag );
}
//-----------------------------------------------------------------------------------
CFlightPath : public QMainWindow
{
Q_OBJECT
public:
CFlightPath();
private slots:
protected:
void placeAircraft();
QGraphicsScene * scene;
CMapView * view;
};
CFlightPath::CFlightPath()
{
scene = new QGraphicsScene(0,0,400,400);
placeAircraft();
view = new CMapView();
view->setScene(scene);
setCentralWidget(view);
setWindowTitle("Flight Path");
mainClose = false;
}
void CFlightPath::placeAircraft()
{
CAircraft * airplane = new CAircraft();
ownship->setPos( 200, 300 );
scene->addItem( airplane );
}
//-----------------------------------------------------------------------------------
class CAircraft : public QObject, public QGraphicsItem
{
Q_OBJECT
public:
CAircraft();
QRectF boundingRect() const;
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
private slots:
void moveAircraft();
private:
QPainterPath shape;
QTimer * updateTimer;
float xPos, yPos, deg, prevDeg;
int count;
};
CAircraft::CAircraft()
{
double localX = -24.0;
double localY = -14.0;
QPolygonF aircraft;
aircraft << QPointF( (localX+24.0), (localY+0.0) )
<< QPointF( (localX+25.0), (localY+1.0) )
<< QPointF( (localX+26.0), (localY+2.0) )
<< QPointF( (localX+27.0), (localY+3.0) )
<< QPointF( (localX+27.0), (localY+9.0) )
<< QPointF( (localX+32.0), (localY+9.0) )
<< QPointF( (localX+32.0), (localY+8.0) )
<< QPointF( (localX+35.0), (localY+8.0) )
<< QPointF( (localX+35.0), (localY+9.0) )
<< QPointF( (localX+38.0), (localY+9.0) )
<< QPointF( (localX+38.0), (localY+8.0) )
<< QPointF( (localX+41.0), (localY+8.0) )
<< QPointF( (localX+41.0), (localY+9.0) )
<< QPointF( (localX+47.0), (localY+9.0) )
<< QPointF( (localX+48.0), (localY+10.0) )
<< QPointF( (localX+47.0), (localY+11.0) )
<< QPointF( (localX+36.0), (localY+13.0) )
<< QPointF( (localX+27.0), (localY+16.0) )
<< QPointF( (localX+26.0), (localY+31.0) )
<< QPointF( (localX+30.0), (localY+31.0) )
<< QPointF( (localX+31.0), (localY+32.0) )
<< QPointF( (localX+25.0), (localY+34.0) )
<< QPointF( (localX+23.0), (localY+34.0) )
<< QPointF( (localX+17.0), (localY+32.0) )
<< QPointF( (localX+18.0), (localY+31.0) )
<< QPointF( (localX+22.0), (localY+31.0) )
<< QPointF( (localX+21.0), (localY+16.0) )
<< QPointF( (localX+12.0), (localY+13.0) )
<< QPointF( (localX+1.0), (localY+11.0) )
<< QPointF( (localX+0.0), (localY+10.0) )
<< QPointF( (localX+1.0), (localY+9.0) )
<< QPointF( (localX+7.0), (localY+9.0) )
<< QPointF( (localX+7.0), (localY+8.0) )
<< QPointF( (localX+10.0), (localY+8.0) )
<< QPointF( (localX+10.0), (localY+9.0) )
<< QPointF( (localX+13.0), (localY+9.0) )
<< QPointF( (localX+13.0), (localY+8.0) )
<< QPointF( (localX+16.0), (localY+8.0) )
<< QPointF( (localX+16.0), (localY+9.0) )
<< QPointF( (localX+21.0), (localY+9.0) )
<< QPointF( (localX+21.0), (localY+3.0) )
<< QPointF( (localX+22.0), (localY+2.0) )
<< QPointF( (localX+23.0), (localY+1.0) );
shape.addPolygon( aircraft );
setFlag(ItemIgnoresTransformations, true);
updateTimer = new QTimer();
updateTimer->setInterval( 50 );
connect( updateTimer, SIGNAL(timeout()), this, SLOT(moveAircraft()));
updateTimer->start();
xPos = 200.0;
yPos = 300.0;
deg = 270.0;
prevDeg = 0.0;
count = 0;
};
QRectF CAircraft::boundingRect() const
{
return QRectF(-24,-14,48,34);
}
void CAircraft::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * /*widget*/)
{
painter->setWindow(-100,-100, 200, 200);
painter->fillPath( shape, Qt::darkGray );
}
void CAircraft::moveAircraft()
{
float x, y;
if ( count < 50 )
xPos -= 1.0;
else if (count < 100 )
yPos += 1.0;
else if (count < 150 )
xPos += 1.0;
else if (count < 200 )
yPos -= 1.0;
else if (count < 250 )
{
yPos += 1.0;
xPos -= 1.0;
}
else if (count < 300 )
{
yPos -= 1.0;
xPos += 1.0;
}
count++;
x = xPos;
y = yPos;
setPos(x, y);
}
To copy to clipboard, switch view to plain text mode
Bookmarks