1 Star 0 Fork 0

qinxude/rk3568ui

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
toweranalog.cpp 5.38 KB
一键复制 编辑 原始数据 按行查看 历史
qinxude 提交于 2024-09-03 09:38 . 3568ui base
#include "toweranalog.h"
#include "ui_toweranalog.h"
#include <QDebug>
TowerAnalog::TowerAnalog(QWidget *parent , bool Style, int32_t BaseAnagle , bool ScopeEnable) :
QWidget(parent),
m_BaseAnagle(BaseAnagle),
m_Style(Style),
m_ScopeEnable(ScopeEnable),
ui(new Ui::TowerAnalog)
{
ui->setupUi(this);
m_R = 0;
m_R1 = 0;
m_ScopeRate = 0;
m_Anagle = m_BaseAnagle;
m_Len = 0;
m_Wight = 0;
font.setPointSize(10);//字体大小设置为10
setFont(font);
for(int i = 0;i < 8;i++)
{
m_DangerZone[i].DrawFlag = false;
}
// m_Id = new QLabel(this);
// m_Id->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
// m_Id->setStyleSheet("background-color: rgb(11, 29, 69);\
// font: 12pt 'Ubuntu';\
// color: rgb(255, 255, 255);\
// border:0px solid;\
// border-color: rgb(10, 94, 180);");
// m_Id->resize(50,20);
// m_Id->hide();
}
TowerAnalog::~TowerAnalog()
{
delete ui;
}
bool TowerAnalog::SetRadius(uint32_t R,uint32_t R1)
{
bool Result = false;
if(R > R1)
{
m_R = R;
m_R1 = R1;
Result = true;
//m_Id->move(m_R-m_Id->width()/2,m_R + m_R1);
//m_Id->show();
}
return Result;
}
bool TowerAnalog::SetAnagle(uint32_t A)
{
bool Result = false;
if(A <= 360)
{
m_Anagle = A + m_BaseAnagle;
Result = true;
//update();
}
return Result;
}
void TowerAnalog::CalDangerZone(uint32_t Index,uint32_t StartA,uint32_t EndA,int32_t StartS,int32_t EndS)
{
if(Index >= 8)
{
return ;
}
if(StartS > m_R)
{
m_DangerZone[Index].DrawFlag = false;
return ;
}
else if(EndS > m_R)
{
EndS = m_R;
}
if(EndA - StartA < 180 && EndA > StartA && EndS > StartS && Index < 8)
{
m_DangerZone[Index].StartAnagle = StartA;
m_DangerZone[Index].EndAnagle = EndA;
m_DangerZone[Index].RotateAnagle = m_BaseAnagle + StartA + (EndA - StartA)/2;
// m_DangerZone[Index].OutRect.setRect(-EndS,-EndS,EndS*2,EndS*2);
// m_DangerZone[Index].InRect.setRect(-StartS,-StartS,StartS*2,StartS*2);
m_DangerZone[Index].DrawFlag = true;
QPainterPath A;
QPainterPath B;
QPainterPath C;
QPainterPath D;
A.addRect(-EndS,-m_R,EndS*2,m_R*2);
B.addRect(-StartS,-m_R,StartS*2,m_R*2);
m_DangerZone[Index].m_PainterPath= A - B;
C.arcTo(QRectF(-m_R,-m_R,m_R*2,m_R*2),0,-((m_DangerZone[Index].EndAnagle - m_DangerZone[Index].StartAnagle)/2));
D.arcTo(QRectF(-m_R,-m_R,m_R*2,m_R*2),0,(m_DangerZone[Index].EndAnagle - m_DangerZone[Index].StartAnagle)/2);
m_DangerZone[Index].m_PainterPath = m_DangerZone[Index].m_PainterPath.intersected(C+D);
update();
}
else
{
m_DangerZone[Index].DrawFlag = false;
}
}
bool TowerAnalog::SetLineLen(uint32_t Len,uint32_t Wight)
{
bool Result = false;
if(Len < m_R*2 && Wight < m_R)
{
m_Len = Len;
m_Wight = Wight;
Result = true;
}
return Result;
}
bool TowerAnalog::SetId(QString id)
{
//m_Id->setText(id + "#");
m_IdText = id;
}
bool TowerAnalog::SetScopeEnable(bool Enable)
{
m_ScopeEnable = Enable;
}
bool TowerAnalog::SetScopeRate(double Rate)
{
if(Rate > 1)
Rate = 1;
m_ScopeRate = Rate;
}
void TowerAnalog::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QBrush brush;
brush.setColor(QColor(0, 0, 0 , 0));
// brush.setColor(QColor(255, 195, 9 , 255));
brush.setStyle(Qt::SolidPattern);
//空心矩形
painter.setRenderHint(QPainter::Antialiasing, true);
if(m_Style)
painter.setPen(QPen(QColor(251, 160, 57 , 255),2,Qt::DashLine));
else
painter.setPen(QPen(QColor(251, 160, 57 , 255),2));
painter.drawEllipse(1,1,m_R*2,m_R*2);
painter.setPen(QPen(QColor(251, 160, 57 , 255),2));
painter.translate(m_R+1,m_R+1);
for(int i = 0;i < 8;i++)
{
if(m_DangerZone[i].DrawFlag)
{
painter.save();
painter.rotate(m_DangerZone[i].RotateAnagle);
painter.setPen(QPen(QColor(204,0,0 , 255)));
painter.setBrush(QBrush(QColor(204,0,0 , 255)));
painter.drawPath(m_DangerZone[i].m_PainterPath);
painter.restore();
}
}
painter.save();
painter.rotate(m_Anagle);
painter.setBrush(brush);
if(m_Len > m_R){
painter.drawRect(-(m_Len-m_R),-(m_Wight/2),m_Len,m_Wight);
}
else {
painter.drawRect(0,-(m_Wight/2),m_Len,m_Wight);
if(m_ScopeEnable)
{
int Offset = (m_R - m_R1)*m_ScopeRate;
painter.save();
painter.setBrush(brush);
painter.drawEllipse(-m_R1 + Offset,-m_R1,m_R1*2,m_R1*2);
painter.restore();
}
}
painter.restore();
painter.save();
painter.setPen(QPen(Qt::white));
painter.drawText(-(50/2),m_R1,50,20,Qt::AlignHCenter | Qt::AlignVCenter,m_IdText+"#");
painter.restore();
painter.save();
painter.setBrush(brush);
painter.drawEllipse(-m_R1,-m_R1,m_R1*2,m_R1*2);
painter.restore();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/qinxude/rk3568ui.git
[email protected]:qinxude/rk3568ui.git
qinxude
rk3568ui
rk3568ui
master

搜索帮助