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.

220 lines
6.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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(CSTR base, REPORT_RECORD *ptr ){
  44. if (ptr != NULL) {
  45. if (ptr->media_count) {
  46. char tBuffer[MAX_PATH];
  47. if (videoIn != NULL) {
  48. delete(videoIn);
  49. };
  50. videoIn = new videoAVLIBSource();
  51. videoIn->attachDestination(this);
  52. sprintf(tBuffer, "%s/%s", base, ptr->media_names[0]);
  53. videoIn->_open( tBuffer,false,01,01, 640,480, true );
  54. videoIn->init();
  55. setError(false, "");
  56. } else {
  57. setError(true, "No Media Data");
  58. };
  59. } else {
  60. setError(true, "No Report Data");
  61. };
  62. return true;
  63. };
  64. void reportRecordWidget::setError(bool AAA, CSTR Message){
  65. m_bErrorMode = AAA;
  66. memcpy( m_pErrorMsg, Message, CTEXT );
  67. m_pErrorMsg[CTEXT - 1] = (char)0;
  68. //if (AAA) LOG("ERROR TRUE"); else LOG("ERROR FALSE");
  69. };
  70. void reportRecordWidget::render(QPainter* painter) {
  71. if (painter != NULL) {
  72. try {
  73. //char buffer[64];
  74. //sprintf(buffer, "Coords: %dx%d %d %d ? %d %d", pos().x(), pos().y(), width(), height(), m_nMouseX, m_nMouseY);
  75. painter->save();
  76. //painter->fillRect(QRect(0, 0, width(), height()), Qt::green);
  77. QPen BgPen(Qt::SolidPattern, 3);
  78. BgPen.setColor(Qt::black);
  79. if (m_bErrorMode && m_pOverlayPixmap != NULL) {
  80. painter->drawPixmap(QRect(0, 0, width(), height()), *m_pOverlayPixmap);
  81. if (m_pErrorMsg != NULL) {
  82. QPen FgPen(Qt::SolidPattern, 0);
  83. FgPen.setColor(Qt::yellow);
  84. painter->setPen(BgPen);
  85. painter->drawText(QRect(0, 0, width(), height()), Qt::AlignHCenter | Qt::AlignBaseline, m_pErrorMsg);
  86. painter->setPen(FgPen);
  87. painter->drawText(QRect(0, 0, width(), height()), Qt::AlignHCenter | Qt::AlignBaseline, m_pErrorMsg);
  88. };
  89. } else {
  90. painter->drawPixmap(QRect(0, 0, width(), height()), *m_pPixmap);
  91. };
  92. //if (m_bSelected) {
  93. // BgPen.setColor(Qt::blue);
  94. // painter->setPen(BgPen);
  95. // painter->drawRect(QRect(2, 2, width() - 4, height() - 4));
  96. //};
  97. //if (m_bMouseActive){
  98. // if (m_pOverlayPixmap != NULL){
  99. // painter->drawPixmap(QRect(0, 0, width(), height()), *m_pOverlayPixmap);
  100. // };
  101. //};
  102. painter->restore();
  103. } catch (std::exception& e) {
  104. //LOG_ERROR("Render exception!");
  105. };
  106. };
  107. };
  108. bool reportRecordWidget::init(void) {
  109. //LOG("init.");
  110. m_pPixmap = new QPixmap(width(), height()); //, QImage::Format_RGB888 );
  111. if (m_pPixmap == NULL) return false;
  112. m_pOverlayPixmap = new QPixmap(":pictures/43a.png", "PNG");
  113. m_pTimer = new QTimer();
  114. if (m_pTimer != NULL) {
  115. QObject::connect(m_pTimer, SIGNAL(timeout()), this, SLOT(update()));
  116. m_pTimer->start(100);
  117. };
  118. m_pPixmap->fill(Qt::black);
  119. //m_pPropertiesProtectorMutex->unlock();
  120. //m_pWidgetProtectorMutex->unlock();
  121. return false;
  122. };
  123. void reportRecordWidget::pushFrame(cv::Mat* Frame, void* src) {
  124. if (Frame != NULL && m_pPixmap != NULL) {
  125. m_mOutput = Frame;
  126. try {
  127. assert(m_mOutput->isContinuous());
  128. //m_pWidgetProtectorMutex->lock();
  129. assert(m_pPixmap);
  130. QPainter dbPainter(m_pPixmap);
  131. if ( 0 ) { //m_eStreamAspectRatio != m_eWidgetAspectRatio) {
  132. /* int tOffset;
  133. if (m_eStreamAspectRatio > m_eWidgetAspectRatio) {
  134. int tHeight;
  135. tHeight = (int)((float)m_pPixmap->width() / m_eStreamAspectRatio);
  136. tOffset = (m_pPixmap->height() - tHeight) >> 1;
  137. dbPainter.drawImage(QRect(0, tOffset, width(), tHeight),
  138. QImage((unsigned char*)m_mOutput->data, m_mOutput->cols, m_mOutput->rows, QImage::Format_RGB888),
  139. QRect(0, 0, m_mOutput->cols, m_mOutput->rows));
  140. } else {
  141. int tWidth;
  142. tWidth = (int)((float)m_pPixmap->height() * m_eStreamAspectRatio);
  143. tOffset = (m_pPixmap->width() - tWidth) >> 1;
  144. dbPainter.drawImage(QRect(tOffset, 0, tWidth, height()),
  145. QImage((unsigned char*)m_mOutput->data, m_mOutput->cols, m_mOutput->rows, QImage::Format_RGB888),
  146. QRect(0, 0, m_mOutput->cols, m_mOutput->rows));
  147. };*/
  148. } else {
  149. 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));
  150. };
  151. //m_pWidgetProtectorMutex->unlock();
  152. } catch (std::exception& e) {
  153. //LOG_ERROR("Exception catched:");
  154. //LOG_ERROR(e.what());
  155. };
  156. };
  157. };
  158. void reportRecordWidget::renderLater() {
  159. if (!m_bUpdateIsPending) {
  160. m_bUpdateIsPending = true;
  161. QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
  162. //LOG("Delayed Rendering Request");
  163. }
  164. };
  165. void reportRecordWidget::paintEvent(QPaintEvent* evt) {
  166. renderNow();
  167. }
  168. void reportRecordWidget::renderNow() {
  169. //m_pWidgetProtectorMutex->lock();
  170. try {
  171. //if (m_nMenuActivityCounter)m_nMenuActivityCounter--;
  172. //else if (m_bMouseActive)m_bMouseActive = false;
  173. QPainter painter(this);
  174. painter.setRenderHint(QPainter::Antialiasing);
  175. //painter.begin(this);
  176. render(&painter);
  177. //painter.end();
  178. } catch (std::exception& e) {
  179. //LOG_ERROR("RenderNow exception!");
  180. };
  181. //m_pWidgetProtectorMutex->unlock();
  182. };
  183. bool reportRecordWidget::event(QEvent* event) {
  184. if (event->type() == QEvent::UpdateRequest) {
  185. m_bUpdateIsPending = false;
  186. renderNow();
  187. return true;
  188. }
  189. if (event->type() == QEvent::MouseButtonRelease) {
  190. //m_bSelected = (m_bSelected) ? false : true;
  191. //if (((QMouseEvent*)event)->button() == Qt::RightButton) {
  192. // ShowContextMenu(QPoint(((QMouseEvent*)event)->x(), ((QMouseEvent*)event)->y()));
  193. //} else selected(m_pSignalParameter);
  194. return true;
  195. }
  196. if (event->type() == QEvent::MouseButtonDblClick) {
  197. //m_bEnhanced = (m_bEnhanced) ? false : true;
  198. renderLater();
  199. return true;
  200. }
  201. if (event->type() == QEvent::MouseMove) {
  202. //m_nMouseX = ((QMouseEvent*)event)->x();
  203. //m_nMouseY = ((QMouseEvent*)event)->y();
  204. //m_bMouseActive = true;
  205. //m_nMenuActivityCounter = 75;// 3 Sec
  206. };
  207. return QWidget::event(event);
  208. };