This commit is contained in:
hm
2019-12-27 17:26:08 +08:00
parent c56960fedc
commit a550735eb9
9 changed files with 190 additions and 21 deletions
+25 -12
View File
@@ -87,22 +87,23 @@ Cockpit::Cockpit(QWidget *parent): QWidget(parent)
m_LedColor = Qt::green;
setMinimumSize(QSize(10, 10));
resize(200, 200);
resize(600, 200);
}
void Cockpit::mouseReleaseEvent(QMouseEvent *e)
{
qDebug() << "release" << e;
update();
}
void Cockpit::mousePressEvent(QMouseEvent *e)
{
qDebug() << "press" << this->pos() << e->localPos() << e->screenPos();
qDebug() << "press" << e;
m_LedColor = Qt::blue;
m_c = this->pos();
update();
}
void Cockpit::mouseDoubleClickEvent(QMouseEvent *e)
@@ -119,12 +120,28 @@ void Cockpit::wheelEvent(QWheelEvent *e)
void Cockpit::setPitch(double Pitch)
{
m_Attitude.pitch = Pitch;
if(m_Attitude.pitch < -90)
{
m_Attitude.pitch += 180;
}
else if(m_Attitude.pitch > 90)
{
m_Attitude.pitch -= 180;
}
update();
}
void Cockpit::setRoll(double Roll)
{
m_Attitude.roll = Roll;
if(m_Attitude.roll < -180)
{
m_Attitude.roll += 360;
}
else if(m_Attitude.roll > 180)
{
m_Attitude.roll -= 360;
}
update();
}
@@ -141,14 +158,9 @@ void Cockpit::setYaw(double Yaw)
void Cockpit::setAttitude(double Pitch,double Roll,double Yaw)
{
m_Attitude.pitch = Pitch;
m_Attitude.roll = Roll;
m_Attitude.yaw = Yaw;
if(m_Attitude.yaw < 0)
{
m_Attitude.yaw += 360;
}
update();
setPitch(Pitch);
setRoll(Roll);
setYaw(Yaw);
}
void Cockpit::setAttitudeSpeed(double PitchSpeed,double RollSpeed,double YawSpeed)
@@ -212,7 +224,8 @@ void Cockpit::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); /* 使用反锯齿(如果可用) */
painter.translate(width() / 2, height() / 2); /* 坐标变换为窗体中心 */
painter.translate(width() / 2, 2 * height() / 5); /* 坐标变换为窗体中心 */
int side = qMin(width(), height()); /* 这一句决定了这个模块只能是方形 */
painter.scale(side / 2000.0, side / 2000.0); /* 比例缩放 */
painter.setPen(Qt::NoPen);