Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

VideoWidget.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // VideoWidget.cpp
  2. #include "VideoWidget.h"
  3. #include <iostream>
  4. #include <QThread>
  5. using namespace std;
  6. // PUBLIC SLOTS:
  7. void VideoWidget::HandleTime(int time, QObject *pSender)
  8. {
  9. if (pSender == this)
  10. return;
  11. else
  12. Pause();
  13. // block signals
  14. blockSignals(true);
  15. // Pause on user input
  16. //Pause();
  17. SetCurrentTime(time);
  18. // unblock singals
  19. blockSignals(false);
  20. }
  21. void VideoWidget::HandleToggleView()
  22. {
  23. if (!m_pEqToFov)
  24. return;
  25. if (m_toggled)
  26. {
  27. m_mediaPlayer.SetConverter(nullptr);
  28. m_toggled = false;
  29. }
  30. else
  31. {
  32. m_mediaPlayer.SetConverter(m_pEqToFov);
  33. m_toggled = true;
  34. }
  35. update();
  36. }
  37. // PRIVATE SLOTS:
  38. void VideoWidget::HandleTimeChanged(qint64 time)
  39. {
  40. const QSignalBlocker blocker(m_mediaPlayer);
  41. // convert time from ms to us
  42. if (!m_isPaused)
  43. {
  44. m_previousTime = time*1000;
  45. // emit signal
  46. emit SendTime(m_previousTime);
  47. update();
  48. }
  49. }
  50. // PUBLIC:
  51. VideoWidget::VideoWidget(QWidget *parent) : QWidget(parent), m_pPaintGaze(0), m_pEqToFov(0), m_isPaused(true), m_toggled(false)
  52. {
  53. SetCurrentTime(0);
  54. // set the following attributes to get some speed up
  55. setAttribute(Qt::WA_NoSystemBackground, true);
  56. // connect objects signal with private slot
  57. QObject::connect(&m_mediaPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(HandleTimeChanged(qint64)));
  58. }
  59. VideoWidget::~VideoWidget()
  60. {
  61. if (!m_pEqToFov)
  62. delete m_pEqToFov;
  63. }
  64. QSize VideoWidget::minimumSizeHint() const
  65. {
  66. return QSize(160, 90);
  67. }
  68. void VideoWidget::SetCurrentTime(int currentTime)
  69. {
  70. if(!m_mutex.tryLock())
  71. return;
  72. //const QSignalBlocker blocker(m_mediaPlayer);
  73. m_previousTime = currentTime;
  74. int msTime = currentTime/1000; // convert to ms
  75. m_mediaPlayer.setPosition(msTime);
  76. update();
  77. m_mutex.unlock();
  78. }
  79. bool VideoWidget::SetMedia(QString pathToFile)
  80. {
  81. return m_mediaPlayer.setMedia(QUrl::fromLocalFile(pathToFile));
  82. }
  83. void VideoWidget::SetGazePaint(PaintGaze *pPaintGaze)
  84. {
  85. m_pPaintGaze = pPaintGaze;
  86. }
  87. void VideoWidget::Play()
  88. {
  89. if (m_mediaPlayer.isVideoAvailable())
  90. {
  91. m_isPaused = false;
  92. //m_mediaPlayer.blockSignals(false);
  93. m_mediaPlayer.play();
  94. repaint();
  95. }
  96. }
  97. void VideoWidget::Pause()
  98. {
  99. if (m_mediaPlayer.isVideoAvailable())
  100. {
  101. m_isPaused = true;
  102. //m_mediaPlayer.blockSignals(true);
  103. m_mediaPlayer.pause();
  104. }
  105. }
  106. void VideoWidget::TogglePlayer()
  107. {
  108. if (m_mediaPlayer.state()==MediaPlayer::PausedState || m_mediaPlayer.state()==MediaPlayer::StoppedState)
  109. Play();
  110. else
  111. Pause();
  112. }
  113. qint64 VideoWidget::Duration()
  114. {
  115. qint64 duration = m_mediaPlayer.duration();
  116. if (duration < 0)
  117. return -1;
  118. else
  119. return 1000*duration;
  120. }
  121. void VideoWidget::ConvertToFov(Arff *pArff)
  122. {
  123. m_pEqToFov = new EquirectangularToFovVideo(pArff);
  124. }
  125. // PROTECTED:
  126. void VideoWidget::paintEvent(QPaintEvent *) /*override*/
  127. {
  128. QPainter painter(this);
  129. // paint video
  130. QRect geom = geometry();
  131. m_mediaPlayer.Paint(&painter, geom.size());
  132. // paint gaze
  133. if (m_pPaintGaze != NULL)
  134. {
  135. m_pPaintGaze->Paint(&painter, geom.size());
  136. }
  137. }
  138. void VideoWidget::resizeEvent(QResizeEvent *event) /*override*/
  139. {
  140. QWidget::resizeEvent(event);
  141. }