linkwidget.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "linkwidget.h"
  2. #include <QPainter>
  3. #include "BusinessLogic/carback.h"
  4. #include <QDebug>
  5. LinkWidget *pthis = NULL;
  6. LinkWidget::LinkWidget(QWidget *parent) : QOpenGLWidget(parent)
  7. {
  8. m_ReverseStatus = RS_Off;
  9. m_USBStatus = US_PullOut;
  10. pthis = this;
  11. pixBackground.load(":/images/LinkBackground.png");
  12. m_Timer = new QTimer(this);
  13. m_Timer->setInterval(3000); //Elink startup too fast will cause Segmentation fault
  14. m_Timer->setSingleShot(true);
  15. QObject::connect(m_Timer, SIGNAL(timeout()),
  16. this, SLOT(onTimeout()));
  17. m_Timer->start();
  18. qDebug() << "***************Timer start!!!";
  19. QObject::connect(g_Carback, &Carback::CarbackStatusChange, this, &LinkWidget::onCarbackStatusChange);
  20. }
  21. LinkWidget::~LinkWidget()
  22. {
  23. #ifdef ECLINK
  24. delete m_ECLinkplayer;
  25. #endif
  26. }
  27. void LinkWidget::initializeGL()
  28. {
  29. initializeOpenGLFunctions();
  30. glClearColor(0.0,0.0,0.0,0.0);
  31. glBlendFunc(GL_SRC_ALPHA,GL_ONE);
  32. glEnable(GL_BLEND);
  33. }
  34. void LinkWidget::resizeGL(int width, int height)
  35. {
  36. }
  37. void LinkWidget::paintGL()
  38. {
  39. // qDebug() << __PRETTY_FUNCTION__ << __LINE__ << "######## m_USBStatus:" << m_USBStatus;
  40. // qDebug() << __PRETTY_FUNCTION__ << __LINE__ << "######## m_ReverseStatus:" << m_ReverseStatus;
  41. if ((m_USBStatus == US_PullOut) && (m_ReverseStatus == RS_Off)) {
  42. QPainter painter;
  43. painter.begin(this);
  44. painter.drawPixmap(0, 0, pixBackground);
  45. painter.end();
  46. // qDebug() << __PRETTY_FUNCTION__ << __LINE__ << "pixBackground";
  47. } else {
  48. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//清除屏幕和深度缓存
  49. // qDebug() << __PRETTY_FUNCTION__ << __LINE__ << "glClearBackground";
  50. }
  51. }
  52. void LinkWidget::usbscan(bool status)
  53. {
  54. qDebug() << "********************** USB Status:" << status;
  55. if (status) {
  56. pthis->m_USBStatus = US_Inset;
  57. } else {
  58. pthis->m_USBStatus = US_PullOut;
  59. }
  60. pthis->update();
  61. }
  62. void LinkWidget::onTimeout()
  63. {
  64. #ifdef ECLINK
  65. m_ECLinkplayer = new ECLinkplayer();
  66. qDebug() << "ECLinkplayer111 :";
  67. m_ECLinkplayer->register_usbevent(usbscan);
  68. qDebug() << "ECLinkplayer222";
  69. m_ECLinkplayer->init(654, 214, 616, 436);
  70. qDebug() << "ECLinkplayer333";
  71. #endif
  72. }
  73. void LinkWidget::onCarbackStatusChange(int status)
  74. {
  75. qDebug() << __PRETTY_FUNCTION__ << __LINE__ << "########### ReverseStatus:" << status;
  76. if (status) {
  77. m_ReverseStatus = RS_On;
  78. } else {
  79. m_ReverseStatus = RS_Off;
  80. }
  81. update();
  82. }