qrcodewindow.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include "qrcodewindow.h"
  2. #include "ECSDKToolKit.h"
  3. QRCodeWindow::QRCodeWindow(QWidget *parent) : QWidget(parent)
  4. {
  5. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  6. QPalette pal(this->palette());
  7. pal.setColor(QPalette::Background, Qt::white);
  8. this->setAutoFillBackground(true);
  9. this->setPalette(pal);
  10. int screen_width = 1920;
  11. int screen_height = 720;
  12. setGeometry(0, 0, screen_width, screen_height);
  13. m_IosQRCode = new QPushButton(QString("IOS"), this);
  14. m_IosQRCode->setGeometry(width() / 4 * 3, 0, width() / 4, height()/2);
  15. QObject::connect(m_IosQRCode, SIGNAL(clicked()), this, SLOT(onClicked()));
  16. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  17. m_AndroidQRCode = new QPushButton(QString("Android"), this);
  18. m_AndroidQRCode->setGeometry(width() / 4 * 3, height() / 2 * 1, width() / 4, height()/2);
  19. QObject::connect(m_AndroidQRCode, SIGNAL(clicked()), this, SLOT(onClicked()));
  20. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  21. m_Close = new QPushButton(QString("Close"), this);
  22. m_Close->setGeometry(width() / 4 * 2, height(), width() / 4, height());
  23. QObject::connect(m_Close, SIGNAL(clicked()), this, SLOT(onClicked()));
  24. m_Label = new QLabel(QString(""),this);
  25. m_Label->setGeometry(width() / 4 * 0, 0, 3* width() / 4, height());
  26. m_Label->setText("select phone type,please scan code!");
  27. m_Label->show();
  28. //p2p
  29. }
  30. void QRCodeWindow::resizeEvent(QResizeEvent *event)
  31. {
  32. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  33. resize(1920, 720);
  34. }
  35. void QRCodeWindow::onQrcodeInfo(char *qrcode)
  36. {
  37. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  38. string str = qrcode;
  39. m_Label->setPixmap(createQRCode(str));
  40. }
  41. void QRCodeWindow::getPlayer(IUserLinkPlayer *player)
  42. {
  43. mPlayer = player;
  44. }
  45. void QRCodeWindow::onUIChanged(bool visible)
  46. {
  47. if(visible){
  48. }
  49. else{
  50. }
  51. }
  52. QPixmap QRCodeWindow::createQRCode(string str)
  53. {
  54. #ifdef SCAN_QRCODE
  55. int margin = 2;
  56. if (str.length() == 0)
  57. return QPixmap();
  58. QRcode *qrcode = QRcode_encodeString(str.c_str(), 2, QR_ECLEVEL_L, QR_MODE_8, 0);
  59. if (qrcode == NULL) {
  60. return QPixmap();
  61. }
  62. unsigned char *p, *q;
  63. p = NULL;
  64. q = NULL;
  65. int x, y, bit;
  66. int realwidth;
  67. realwidth = qrcode->width;
  68. QImage image = QImage(realwidth, realwidth, QImage::Format_Indexed8);
  69. QRgb value;
  70. value = qRgb(255, 255, 255);
  71. image.setColor(0, value);
  72. value = qRgb(0, 0, 0);
  73. image.setColor(1, value);
  74. image.setColor(2, value);
  75. image.fill(0);
  76. p = qrcode->data;
  77. for (y = 0; y<qrcode->width; y++) {
  78. bit = 7;
  79. q += margin / 8;
  80. bit = 7 - (margin % 8);
  81. for (x = 0; x<qrcode->width; x++) {
  82. if ((*p & 1) << bit)
  83. image.setPixel(x, y, 1);
  84. else
  85. image.setPixel(x, y, 0);
  86. bit--;
  87. if (bit < 0)
  88. {
  89. q++;
  90. bit = 7;
  91. }
  92. p++;
  93. }
  94. }
  95. return QPixmap::fromImage(image.scaledToWidth(200));
  96. #endif
  97. }
  98. void QRCodeWindow::onClicked()
  99. {
  100. const QPushButton* const ptr = static_cast<const QPushButton* const >(sender());
  101. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  102. if (ptr == m_IosQRCode) {
  103. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  104. #ifdef SCAN_QRCODE
  105. ECQRInfo info;
  106. info.ssid = "ark169_wifi";
  107. info.pwd = "12345678";
  108. info.action = EC_QR_ACTION_WIFI_AP_MODE_CUSTOMIZED;
  109. info.auth = "WPA-PSK";
  110. info.name = "ark169_wifi";
  111. info.mac = "34:72:4a:00:1a:e9";
  112. ECSDKToolKit::getInstance()->generateQRCodeUrl(info);
  113. //mPlayer->RequestStatus(QUERYQRCODE);
  114. #endif
  115. } else if (ptr == m_AndroidQRCode) {
  116. #ifdef SCAN_QRCODE
  117. ECQRInfo info ;
  118. info.ssid = "";
  119. info.pwd = "";
  120. info.action = EC_QR_ACTION_WIFI_P2P_MODE;
  121. info.auth = "";
  122. info.name = "ark169_wifi";
  123. info.mac = "36:72:4A:00:1A:E9";
  124. ECSDKToolKit::getInstance()->generateQRCodeUrl(info);
  125. #endif
  126. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  127. }
  128. else if(ptr == m_Close){
  129. close();
  130. }
  131. }