1 Star 0 Fork 0

qinxude/rk3568ui

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
toweranimation.cpp 5.90 KB
一键复制 编辑 原始数据 按行查看 历史
qinxude 提交于 2024-09-03 09:38 . 3568ui base
#include "toweranimation.h"
#include "ui_toweranimation.h"
TCModel::TCModel(QLabel *Top,QLabel *Mid,QLabel *Bom,int zeroX = TCMODEL_X_START,int zeroY = TCMODEL_Y_START,int initLen = 0)
:m_Top(Top),m_Mid(Mid),m_Bom(Bom),m_XZero(zeroX),m_YZero(zeroY),m_InitLen(initLen)
{
m_W = nullptr;
m_H = nullptr;
m_CurX = 0;
m_CurH = 0;
GoZeroPos();
}
TCModel::~TCModel()
{
}
void TCModel::GoZeroPos()
{
m_Top->move(m_XZero,m_YZero);
m_Mid->resize(m_Mid->width(),m_InitLen);
m_Mid->move(m_XZero+m_Top->width()/2-m_Mid->width()/2,m_YZero+m_Top->height());
m_Bom->move(m_XZero+m_Top->width()/2-m_Bom->width()/2,m_YZero+m_Top->height()+m_Mid->height());
if(m_W != nullptr){
m_W->move(m_Bom->x()+m_Bom->width()/2-m_W->width()/2,m_Bom->y()+m_Bom->height()+5);
}
if(m_H != nullptr){
m_H->move(m_Mid->x()+m_Mid->width()+5,m_Mid->y()+m_Mid->height()/2);
}
m_CurX = m_XZero;
m_CurH = m_InitLen;
}
void TCModel::Move(int x, int len)
{
m_Top->move(x,m_YZero);
m_Mid->resize(m_Mid->width(),len);
m_Mid->move(x+m_Top->width()/2-m_Mid->width()/2,m_YZero+m_Top->height());
m_Bom->move(x+m_Top->width()/2-m_Bom->width()/2,m_YZero+m_Top->height()+m_Mid->height());
if(m_W != nullptr){
m_W->move(m_Bom->x()+m_Bom->width()/2-m_W->width()/2,m_Bom->y()+m_Bom->height()+5);
}
if(m_H != nullptr){
m_H->move(m_Mid->x()+m_Mid->width()+5,m_Mid->y()+m_Mid->height()/2);
}
m_CurX = x;
m_CurH = len;
}
void TCModel::Move(double xForce, double HForce)
{
int x = 0,h = 0;
if(xForce > 1){
x = m_XZero + TCMODEL_X_MAX;
}else {
x = m_XZero + TCMODEL_X_MAX*xForce;
}
if(HForce > 1){
h = TCMODEL_Y_MAX;
}else {
h = TCMODEL_Y_MAX*HForce;
}
Move(x,h);
}
void TCModel::MoveX(double xForce)
{
int x = 0;
if(xForce > 1){
x = m_XZero + TCMODEL_X_MAX;
}else {
x = m_XZero + TCMODEL_X_MAX*xForce;
}
Move(x,m_CurH);
}
void TCModel::MoveH(double hForce)
{
int h = 0;
if(hForce > 1){
h = TCMODEL_Y_MAX;
}else {
h = TCMODEL_Y_MAX*hForce;
}
Move(m_CurX,h);
}
void TCModel::AddWeightHeightLabel(QLabel *W,QLabel *H)
{
m_W = W;
m_H = H;
m_W->move(m_Bom->x()+m_Bom->width()/2-m_W->width()/2,m_Bom->y()+m_Bom->height()+5);
m_H->move(m_Mid->x()+m_Mid->width()+5,m_Mid->y()+m_Mid->height()/2);
}
TowerAnimation::TowerAnimation(QWidget *parent) :
QWidget(parent),
ui(new Ui::TowerAnimation)
{
ui->setupUi(this);
m_DataDictionary = DataDictionary::GetInstance();
ui->WeightShow->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
m_TCModel = new TCModel(ui->Tower1,ui->Tower2,ui->Tower3);
m_TCModel->AddWeightHeightLabel(ui->WeightShow,ui->HeightRtDisplay);
//m_TCModel->Move((double)0,(double)1);
}
TowerAnimation::~TowerAnimation()
{
delete ui;
}
void TowerAnimation::showEvent(QShowEvent *event)
{
ui->TowerNum->setText(DataDictionary::GetInstance()->GetDevParamData(D_CUSTOM_NUMBER)+"#");
DevParamDataChange(D_HEIGHT);
DevParamDataChange(D_ARM_LENGTH);
connect(m_DataDictionary,SIGNAL(DevParamDataChange(DevParamDataIndex_t)),\
this,SLOT(DevParamDataChange(DevParamDataIndex_t)));
connect(m_DataDictionary,SIGNAL(MonitorRtDataChange(MonitorRtDataIndex_t)),\
this,SLOT(MonitorRtDataChange(MonitorRtDataIndex_t)));
}
void TowerAnimation::hideEvent(QHideEvent *event)
{
disconnect(m_DataDictionary,SIGNAL(DevParamDataChange(DevParamDataIndex_t)),\
this,SLOT(DevParamDataChange(DevParamDataIndex_t)));
disconnect(m_DataDictionary,SIGNAL(MonitorRtDataChange(MonitorRtDataIndex_t)),\
this,SLOT(MonitorRtDataChange(MonitorRtDataIndex_t)));
}
void TowerAnimation::DevParamDataChange(DevParamDataIndex_t Index)
{
switch (Index) {
case D_HEIGHT:
ui->TowerHeight->setText("塔高" + m_DataDictionary->GetDevParamData(Index)+"M");
SetHeightForce();
break;
case D_ARM_LENGTH:
ui->ArmLen->setText("臂长" + m_DataDictionary->GetDevParamData(Index)+"M");
SetScopeForce();
break;
default:
break;
}
}
void TowerAnimation::MonitorRtDataChange(MonitorRtDataIndex_t Index)
{
switch (Index) {
case M_HEIGHT:
SetHeightForce();
SetRtHeightDisplay();
break;
case M_SCOPE:
SetScopeForce();
break;
case M_WEIGHT:
ui->WeightShow->setText(m_DataDictionary->GetMonitorRtData(Index) + "T");
default:
break;
}
}
void TowerAnimation::SetScopeForce()
{
QString CurSc = m_DataDictionary->GetMonitorRtData(M_SCOPE);
QString RateSc = m_DataDictionary->GetDevParamData(D_ARM_LENGTH);
double Force = 0.0;
if(RateSc.toDouble() == 0.0){
Force = 1;
}else {
Force = (CurSc.toDouble()/RateSc.toDouble());
}
m_TCModel->MoveX(Force);
}
void TowerAnimation::SetHeightForce()
{
QString CurH = m_DataDictionary->GetMonitorRtData(M_HEIGHT);
QString RateH = m_DataDictionary->GetDevParamData(D_HEIGHT);
double Force = 0.0;
if(RateH.toDouble() == 0){
Force = 1;
}else {
Force = (CurH.toDouble()/RateH.toDouble());
}
//ui->HeightForceLabel->setText(QString::number(Force)+tr("%"));
if(m_DataDictionary->GetMisData(MIS_HEIGHT_ZERO_POS).toUInt() == LAND_ZERO_POS)
{
Force = 1 - Force;
}
m_TCModel->MoveH(Force);
}
void TowerAnimation::SetRtHeightDisplay()
{
double Height = 0.0;
if(m_DataDictionary->GetMisData(MIS_HEIGHT_ZERO_POS).toUInt() == LAND_ZERO_POS)
{
Height = m_DataDictionary->GetDevParamData(D_HEIGHT).toDouble() - m_DataDictionary->GetMonitorRtData(M_HEIGHT).toDouble();
}
else if(m_DataDictionary->GetMisData(MIS_HEIGHT_ZERO_POS).toUInt()== ARM_ZERO_POS)
{
Height = m_DataDictionary->GetMonitorRtData(M_HEIGHT).toDouble();
}
ui->HeightRtDisplay->setText(QString::number(Height)+tr("m"));
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/qinxude/rk3568ui.git
[email protected]:qinxude/rk3568ui.git
qinxude
rk3568ui
rk3568ui
master

搜索帮助