You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
6.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "ReportRecordWidget.h"
  2. reportRecordWidget::reportRecordWidget(QWidget *parent):QWidget(parent){
  3. memset( m_pErrorMsg, 0, CTEXT );
  4. m_bErrorMode = false;
  5. m_bUpdateIsPending = false;
  6. //setFixedSize(240, 180);
  7. setMouseTracking(true);
  8. //m_eStreamAspectRatio = FAR_UNKNOWN;
  9. //m_eWidgetAspectRatio = detectAspectRatio(width(), height());
  10. //setGeometry(m_nPosX, m_nPosY, m_nWidth+1, m_nHeight+1);
  11. //setMinimumSize(QSize(320, 240));
  12. //setSizeIncrement(QSize(20, 20));
  13. //m_backingStore = new QBackingStore( );
  14. //setBackgroundRole(QPalette::Window);
  15. setAutoFillBackground(false);
  16. setAttribute(Qt::WA_OpaquePaintEvent);
  17. setCursor(QCursor(Qt::PointingHandCursor));
  18. //create();
  19. m_pPixmap = NULL;
  20. m_pOverlayPixmap = NULL;
  21. //m_pGraber = NULL;
  22. //m_mFrame = NULL;
  23. m_mOutput = NULL;
  24. m_pTimer = NULL;
  25. //m_bMouseActive = false;
  26. //m_bSelected = false;
  27. m_bErrorMode = false;
  28. //m_pErrorMsg = NULL;
  29. //m_nMouseX = 0;
  30. //m_nMouseY = 0;
  31. //m_pPropertiesProtectorMutex = new basicMutex();
  32. //m_pWidgetProtectorMutex = new basicMutex();
  33. //m_pPropertiesProtectorMutex->lock();
  34. //m_pWidgetProtectorMutex->lock();
  35. videoIn = NULL;
  36. };
  37. reportRecordWidget::~reportRecordWidget(){
  38. if (m_pTimer) {
  39. m_pTimer->stop();
  40. delete(m_pTimer);
  41. };
  42. };
  43. bool reportRecordWidget::setReport( REPORT_RECORD *ptr ){
  44. if (ptr != NULL) {
  45. if (ptr->media_count) {
  46. if (videoIn != NULL) {
  47. delete(videoIn);
  48. };
  49. videoIn = new videoAVLIBSource();
  50. videoIn->attachDestination(this);
  51. videoIn->_open(ptr->media_names[0]);
  52. videoIn->init();
  53. setError(false, "");
  54. } else {
  55. setError(true, "No Media Data");
  56. };
  57. } else {
  58. setError(true, "No Report Data");
  59. };
  60. return true;
  61. };
  62. void reportRecordWidget::setError(bool AAA, CSTR Message){
  63. m_bErrorMode = AAA;
  64. memcpy( m_pErrorMsg, Message, CTEXT );
  65. m_pErrorMsg[CTEXT - 1] = (char)0;
  66. //if (AAA) LOG("ERROR TRUE"); else LOG("ERROR FALSE");
  67. };
  68. void reportRecordWidget::render(QPainter* painter) {
  69. if (painter != NULL) {
  70. try {
  71. //char buffer[64];
  72. //sprintf(buffer, "Coords: %dx%d %d %d ? %d %d", pos().x(), pos().y(), width(), height(), m_nMouseX, m_nMouseY);
  73. painter->save();
  74. //painter->fillRect(QRect(0, 0, width(), height()), Qt::green);
  75. QPen BgPen(Qt::SolidPattern, 3);
  76. BgPen.setColor(Qt::black);
  77. if (m_bErrorMode && m_pOverlayPixmap != NULL) {
  78. painter->drawPixmap(QRect(0, 0, width(), height()), *m_pOverlayPixmap);
  79. if (m_pErrorMsg != NULL) {
  80. QPen FgPen(Qt::SolidPattern, 0);
  81. FgPen.setColor(Qt::yellow);
  82. painter->setPen(BgPen);
  83. painter->drawText(QRect(0, 0, width(), height()), Qt::AlignHCenter | Qt::AlignBaseline, m_pErrorMsg);
  84. painter->setPen(FgPen);
  85. painter->drawText(QRect(0, 0, width(), height()), Qt::AlignHCenter | Qt::AlignBaseline, m_pErrorMsg);
  86. };
  87. } else {
  88. painter->drawPixmap(QRect(0, 0, width(), height()), *m_pPixmap);
  89. };
  90. //if (m_bSelected) {
  91. // BgPen.setColor(Qt::blue);
  92. // painter->setPen(BgPen);
  93. // painter->drawRect(QRect(2, 2, width() - 4, height() - 4));
  94. //};
  95. //if (m_bMouseActive){
  96. // if (m_pOverlayPixmap != NULL){
  97. // painter->drawPixmap(QRect(0, 0, width(), height()), *m_pOverlayPixmap);
  98. // };
  99. //};
  100. painter->restore();
  101. } catch (std::exception& e) {
  102. //LOG_ERROR("Render exception!");
  103. };
  104. };
  105. };
  106. bool reportRecordWidget::init(void) {
  107. //LOG("init.");
  108. m_pPixmap = new QPixmap(width(), height()); //, QImage::Format_RGB888 );
  109. if (m_pPixmap == NULL) return false;
  110. m_pOverlayPixmap = new QPixmap(":pictures/43a.png", "PNG");
  111. m_pTimer = new QTimer();
  112. if (m_pTimer != NULL) {
  113. QObject::connect(m_pTimer, SIGNAL(timeout()), this, SLOT(update()));
  114. m_pTimer->start(100);
  115. };
  116. m_pPixmap->fill(Qt::black);
  117. //m_pPropertiesProtectorMutex->unlock();
  118. //m_pWidgetProtectorMutex->unlock();
  119. return false;
  120. };
  121. void reportRecordWidget::pushFrame(cv::Mat* Frame, void* src) {
  122. if (Frame != NULL && m_pPixmap != NULL) {
  123. m_mOutput = Frame;
  124. try {
  125. assert(m_mOutput->isContinuous());
  126. //m_pWidgetProtectorMutex->lock();
  127. assert(m_pPixmap);
  128. QPainter dbPainter(m_pPixmap);
  129. if ( 0 ) { //m_eStreamAspectRatio != m_eWidgetAspectRatio) {
  130. /* int tOffset;
  131. if (m_eStreamAspectRatio > m_eWidgetAspectRatio) {
  132. int tHeight;
  133. tHeight = (int)((float)m_pPixmap->width() / m_eStreamAspectRatio);
  134. tOffset = (m_pPixmap->height() - tHeight) >> 1;
  135. dbPainter.drawImage(QRect(0, tOffset, width(), tHeight),
  136. QImage((unsigned char*)m_mOutput->data, m_mOutput->cols, m_mOutput->rows, QImage::Format_RGB888),
  137. QRect(0, 0, m_mOutput->cols, m_mOutput->rows));
  138. } else {
  139. int tWidth;
  140. tWidth = (int)((float)m_pPixmap->height() * m_eStreamAspectRatio);
  141. tOffset = (m_pPixmap->width() - tWidth) >> 1;
  142. dbPainter.drawImage(QRect(tOffset, 0, tWidth, height()),
  143. QImage((unsigned char*)m_mOutput->data, m_mOutput->cols, m_mOutput->rows, QImage::Format_RGB888),
  144. QRect(0, 0, m_mOutput->cols, m_mOutput->rows));
  145. };*/
  146. } else {
  147. dbPainter.drawImage(QRect(0, 0, width(), height()), QImage((unsigned char*)m_mOutput->data, m_mOutput->cols, m_mOutput->rows, QImage::Format_RGB888), QRect(0, 0, m_mOutput->cols, m_mOutput->rows));
  148. };
  149. //m_pWidgetProtectorMutex->unlock();
  150. } catch (std::exception& e) {
  151. //LOG_ERROR("Exception catched:");
  152. //LOG_ERROR(e.what());
  153. };
  154. };
  155. };
  156. void reportRecordWidget::renderLater() {
  157. if (!m_bUpdateIsPending) {
  158. m_bUpdateIsPending = true;
  159. QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
  160. //LOG("Delayed Rendering Request");
  161. }
  162. };
  163. void reportRecordWidget::paintEvent(QPaintEvent* evt) {
  164. renderNow();
  165. }
  166. void reportRecordWidget::renderNow() {
  167. //m_pWidgetProtectorMutex->lock();
  168. try {
  169. //if (m_nMenuActivityCounter)m_nMenuActivityCounter--;
  170. //else if (m_bMouseActive)m_bMouseActive = false;
  171. QPainter painter(this);
  172. painter.setRenderHint(QPainter::Antialiasing);
  173. //painter.begin(this);
  174. render(&painter);
  175. //painter.end();
  176. } catch (std::exception& e) {
  177. //LOG_ERROR("RenderNow exception!");
  178. };
  179. //m_pWidgetProtectorMutex->unlock();
  180. };
  181. bool reportRecordWidget::event(QEvent* event) {
  182. if (event->type() == QEvent::UpdateRequest) {
  183. m_bUpdateIsPending = false;
  184. renderNow();
  185. return true;
  186. }
  187. if (event->type() == QEvent::MouseButtonRelease) {
  188. //m_bSelected = (m_bSelected) ? false : true;
  189. //if (((QMouseEvent*)event)->button() == Qt::RightButton) {
  190. // ShowContextMenu(QPoint(((QMouseEvent*)event)->x(), ((QMouseEvent*)event)->y()));
  191. //} else selected(m_pSignalParameter);
  192. return true;
  193. }
  194. if (event->type() == QEvent::MouseButtonDblClick) {
  195. //m_bEnhanced = (m_bEnhanced) ? false : true;
  196. renderLater();
  197. return true;
  198. }
  199. if (event->type() == QEvent::MouseMove) {
  200. //m_nMouseX = ((QMouseEvent*)event)->x();
  201. //m_nMouseY = ((QMouseEvent*)event)->y();
  202. //m_bMouseActive = true;
  203. //m_nMenuActivityCounter = 75;// 3 Sec
  204. };
  205. return QWidget::event(event);
  206. };