添加了公交车动画函数
This commit is contained in:
@@ -2,11 +2,17 @@
|
||||
// Created by ricardo on 2022/6/28.
|
||||
//
|
||||
|
||||
#include "BusWidget.h"
|
||||
#include "moc_BusWidget.cpp"
|
||||
|
||||
BusItem::BusItem(const QPixmap &pixmap) : QGraphicsPixmapItem(pixmap)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
BusWidget::BusWidget()
|
||||
{
|
||||
item = new QGraphicsPixmapItem(QPixmap(":/picture/bus.png"));
|
||||
item = new BusItem(QPixmap(":/picture/bus.png"));
|
||||
animation = new QPropertyAnimation(item, "pos");
|
||||
|
||||
// 设置缩放
|
||||
double bus_scale = 0.1;
|
||||
@@ -20,9 +26,48 @@ BusWidget::~BusWidget()
|
||||
delete item;
|
||||
}
|
||||
|
||||
void BusWidget::ResetBusPos(PosPair *s)
|
||||
void BusWidget::ResetBusPos(PosPair *s, int num)
|
||||
{
|
||||
pos_pairs = s;
|
||||
pos = 0;
|
||||
node_num = num;
|
||||
|
||||
item->setPos(s[0].GetBusPosX(), s[0].GetBusPosY());
|
||||
item->setPos(pos_pairs[0].GetBusPosX(), pos_pairs[0].GetBusPosY());
|
||||
}
|
||||
|
||||
void BusWidget::StartAnimation(int direction, int duration)
|
||||
{
|
||||
bool is_animate = false;
|
||||
|
||||
animation->setDuration(duration);
|
||||
animation->setStartValue(QPointF(pos_pairs[pos].GetBusPosX(), pos_pairs[pos].GetBusPosY()));
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case BUS_CLOCK_WISE:
|
||||
pos++;
|
||||
is_animate = true;
|
||||
// 处理环绕一圈的情况
|
||||
if(pos == node_num)
|
||||
{
|
||||
pos = pos - node_num;
|
||||
}
|
||||
break;
|
||||
case BUS_COUNTER_CLOCK_WISE:
|
||||
pos--;
|
||||
is_animate = true;
|
||||
// 处理环绕一圈的情况
|
||||
if(pos == -1)
|
||||
{
|
||||
pos = pos + node_num;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(is_animate)
|
||||
{
|
||||
animation->setEndValue(QPointF(pos_pairs[pos].GetBusPosX(), pos_pairs[pos].GetBusPosY()));
|
||||
animation->start();
|
||||
}
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ void SceneManager::SetStopScene(int node_number)
|
||||
}
|
||||
|
||||
// 设置公交车图像
|
||||
bus->ResetBusPos(stop_pos_pairs);
|
||||
bus->ResetBusPos(stop_pos_pairs, node_number);
|
||||
scene->addItem(bus->item);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user