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.
762 lines
26 KiB
762 lines
26 KiB
#include "VideoWidget.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "VideoWidget", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "VideoWidget", this, _LOG_ERROR, X )
|
|
|
|
VideoWidget::VideoWidget(QWidget *parent) :
|
|
QWidget(parent),
|
|
basicMediaDestination(){
|
|
m_bGrayScale = false;
|
|
m_bEnhanced = false;
|
|
m_bDirectDrawing = true;
|
|
m_bUpdateIsPending = false;
|
|
|
|
//setFixedSize( 500, 375 );
|
|
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
|
|
setMouseTracking( true );
|
|
//grabKeyboard();
|
|
m_nKeyCode = 0;
|
|
m_nOldKeyCode = 0;
|
|
m_nManualControlMode = CD_AUTO;
|
|
m_pCamera = NULL;
|
|
//setKeyboardTracking( true );
|
|
m_eStreamAspectRatio = FAR_UNKNOWN;
|
|
m_eWidgetAspectRatio = FAR_4X3;//detectAspectRatio(width(), height());
|
|
//setGeometry(m_nPosX, m_nPosY, m_nWidth+1, m_nHeight+1);
|
|
//setMinimumSize(QSize(320, 240));
|
|
//setSizeIncrement(QSize(20, 20));
|
|
//m_backingStore = new QBackingStore( );
|
|
//setBackgroundRole(QPalette::Window);
|
|
m_pBorder = new QFrame(this);
|
|
m_pBorder->setFrameShape(QFrame::Panel);
|
|
m_pBorder->setFrameShadow(QFrame::Sunken);
|
|
m_pBorder->setGeometry(0, 0, 200, 200);
|
|
|
|
setAutoFillBackground(false);
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
setCursor(QCursor(Qt::PointingHandCursor));
|
|
//create();
|
|
m_pManualMode = NULL;
|
|
m_pPixUp = NULL;
|
|
m_pPixDown = NULL;
|
|
m_pPixLeft = NULL;
|
|
m_pPixRight = NULL;
|
|
m_pPixWide = NULL;
|
|
m_pPixTele = NULL;
|
|
m_pPixmap = NULL;
|
|
//m_pOverlayPixmap = NULL;
|
|
m_pGraber = NULL;
|
|
m_mFrame = NULL;
|
|
m_mOutput = NULL;
|
|
m_pTimer = NULL;
|
|
m_pFullScreenView = NULL;
|
|
m_bMouseActive = false;
|
|
m_bFullScreenView = false;
|
|
m_nMouseX = 0;
|
|
m_nMouseY = 0;
|
|
m_pPropertiesProtectorMutex = new basicMutex();
|
|
m_pWidgetProtectorMutex = new basicMutex();
|
|
#ifndef NO_JOYSTICK
|
|
m_pJO = NULL;
|
|
#endif
|
|
};
|
|
|
|
|
|
bool VideoWidget::event(QEvent *event){
|
|
if( event->type() == QEvent::UpdateRequest ){
|
|
m_bUpdateIsPending = false;
|
|
renderNow();
|
|
return true;
|
|
}
|
|
if (event->type() == QEvent::MouseButtonRelease ){
|
|
//Beep(1024, 10);
|
|
if (((QMouseEvent*)event)->button() == Qt::LeftButton){
|
|
if (m_nManualControlMode & CD_MANUAL){
|
|
#ifndef NO_PTZ_CAMERAS
|
|
if (m_nManualControlMode&(CD_TELE | CD_WIDE)) ((basicCameraPTZ *)m_pCamera)->cmdEndManualZoom();
|
|
if (m_nManualControlMode&(CD_UP | CD_DOWN)) ((basicCameraPTZ *)m_pCamera)->cmdEndManualZoom();
|
|
if (m_nManualControlMode&(CD_LEFT | CD_RIGHT)) ((basicCameraPTZ *)m_pCamera)->cmdEndManualZoom();
|
|
#endif
|
|
m_nManualControlMode = CD_AUTO;
|
|
releaseKeyboard();
|
|
}else{
|
|
m_nManualControlMode = CD_MANUAL;
|
|
m_nMenuActivityCounter = 75;
|
|
grabKeyboard();
|
|
};
|
|
return true;
|
|
};
|
|
};
|
|
if (event->type() == QEvent::MouseButtonDblClick){
|
|
showFullScreen();
|
|
return true;
|
|
}
|
|
if (m_nManualControlMode & CD_MANUAL){
|
|
if (event->type() == QEvent::KeyPress){
|
|
m_nKeyCode = ((QKeyEvent *)event)->key();
|
|
switch (m_nKeyCode){
|
|
case 32:
|
|
showFullScreen();
|
|
break;
|
|
case 87://w
|
|
if (m_nCameraCaps & OC_ZOOM_CONTROLL){
|
|
if ((m_nManualControlMode & CD_TELE) == 0){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_WIDE));
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode | CD_TELE);
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdBeginZoomTele();
|
|
#endif
|
|
}
|
|
else {
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_TELE));
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdEndManualZoom();
|
|
#endif
|
|
};
|
|
m_nMenuActivityCounter = 75;
|
|
};
|
|
break;
|
|
case 65://A
|
|
if (m_nCameraCaps & OC_ZOOM_CONTROLL){
|
|
if ((m_nManualControlMode & CD_WIDE) == 0){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_TELE));
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode | CD_WIDE);
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdBeginZoomWide();
|
|
#endif
|
|
}
|
|
else {
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_WIDE));
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdEndManualZoom();
|
|
#endif
|
|
};
|
|
m_nMenuActivityCounter = 75;
|
|
};
|
|
break;
|
|
case 0x01000012://Left
|
|
if (m_nCameraCaps & OC_PAN_CONTROLL){
|
|
if ((m_nManualControlMode & CD_LEFT) == 0){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_RIGHT));
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode | CD_LEFT);
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdBeginPanLeft();
|
|
#endif
|
|
} else {
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_LEFT));
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdEndManualPan();
|
|
#endif
|
|
};
|
|
m_nMenuActivityCounter = 75;
|
|
};
|
|
break;
|
|
case 0x01000013://Up
|
|
if (m_nCameraCaps & OC_TILT_CONTROLL){
|
|
if ((m_nManualControlMode & CD_UP) == 0){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_DOWN));
|
|
m_nManualControlMode = (ControlDirection) (m_nManualControlMode | CD_UP );
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdBeginTiltUp();
|
|
#endif
|
|
} else {
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_UP));
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdEndManualTilt();
|
|
#endif
|
|
};
|
|
m_nMenuActivityCounter = 75;
|
|
};
|
|
break;
|
|
case 0x01000014://Right
|
|
if (m_nCameraCaps & OC_PAN_CONTROLL){
|
|
if ((m_nManualControlMode & CD_RIGHT) == 0){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_LEFT));
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode | CD_RIGHT);
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdBeginPanRight();
|
|
#endif
|
|
} else {
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_RIGHT));
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdEndManualPan();
|
|
#endif
|
|
};
|
|
m_nMenuActivityCounter = 75;
|
|
};
|
|
break;
|
|
case 0x01000015://Down
|
|
if (m_nCameraCaps & OC_TILT_CONTROLL){
|
|
if ((m_nManualControlMode & CD_DOWN) == 0){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_UP));
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode | CD_DOWN);
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdBeginTiltDown();
|
|
#endif
|
|
} else {
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_DOWN));
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdEndManualTilt();
|
|
#endif
|
|
};
|
|
m_nMenuActivityCounter = 75;
|
|
};
|
|
break;
|
|
};
|
|
m_nOldKeyCode = m_nKeyCode;
|
|
return true;
|
|
};
|
|
};
|
|
return QWidget::event(event);
|
|
}
|
|
|
|
void VideoWidget::setCameraControl(basicCamera *C, objectCaps CC){
|
|
if (m_pCamera != NULL){
|
|
#ifndef NO_PTZ_CAMERAS
|
|
if (m_nCameraCaps & OC_PAN_CONTROLL){
|
|
if (m_nManualControlMode&CD_LEFT)((basicCameraPTZ *)m_pCamera)->cmdEndManualPan();
|
|
if (m_nManualControlMode&CD_RIGHT)((basicCameraPTZ *)m_pCamera)->cmdEndManualPan();
|
|
};
|
|
if (m_nCameraCaps & OC_TILT_CONTROLL){
|
|
if (m_nManualControlMode&CD_UP)((basicCameraPTZ *)m_pCamera)->cmdEndManualTilt();
|
|
if (m_nManualControlMode&CD_DOWN)((basicCameraPTZ *)m_pCamera)->cmdEndManualTilt();
|
|
};
|
|
if (m_nCameraCaps & OC_ZOOM_CONTROLL){
|
|
if (m_nManualControlMode&CD_TELE)((basicCameraPTZ *)m_pCamera)->cmdEndManualZoom();
|
|
if (m_nManualControlMode&CD_WIDE)((basicCameraPTZ *)m_pCamera)->cmdEndManualZoom();
|
|
};
|
|
#endif
|
|
m_nManualControlMode = CD_AUTO;
|
|
#ifndef NO_JOYSTICK
|
|
m_pJO = joysticObject::getInstance();
|
|
#endif
|
|
};
|
|
m_nCameraCaps = CC;
|
|
m_pCamera = C;
|
|
};
|
|
|
|
void VideoWidget::renderLater(){
|
|
if (!m_bUpdateIsPending) {
|
|
m_bUpdateIsPending = true;
|
|
QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
|
|
#ifdef DEBUG
|
|
LOG("Delayed Rendering Request");
|
|
#endif
|
|
}
|
|
}
|
|
//! [6]
|
|
|
|
|
|
//! [5]
|
|
//void VideoWidget::resizeEvent(QResizeEvent *resizeEvent){
|
|
// //m_backingStore->resize(resizeEvent->size());
|
|
// this->backingStore()->resize(resizeEvent->size());
|
|
// if( this->isEnabled() )
|
|
// renderNow();
|
|
//}
|
|
//! [5]
|
|
|
|
//! [2]
|
|
void VideoWidget::exposeEvent(QExposeEvent *){
|
|
LOG_ERROR("Expose EVT!");
|
|
}
|
|
//! [2]
|
|
|
|
void VideoWidget::paintEvent(QPaintEvent *evt){
|
|
renderNow();
|
|
}
|
|
|
|
//! [3]
|
|
void VideoWidget::renderNow(){
|
|
m_pWidgetProtectorMutex->lock();
|
|
try{
|
|
if ((m_nManualControlMode & CD_JOYSTICK) != 0){
|
|
#ifndef NO_JOYSTICK
|
|
if (m_pJO != NULL){
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->setDirectSpeedControl(true);
|
|
#endif
|
|
long tParam;
|
|
tParam = m_pJO->getHat();
|
|
if (tParam > 200){
|
|
if (m_nCameraCaps & OC_ZOOM_CONTROLL){
|
|
if ((m_nManualControlMode & CD_TELE) == 0){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_WIDE));
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode | CD_TELE);
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdBeginZoomTele(((float)tParam) / 1000.f);
|
|
#endif
|
|
};
|
|
m_nMenuActivityCounter = 75;
|
|
};
|
|
} else if (tParam < -200){
|
|
if (m_nCameraCaps & OC_ZOOM_CONTROLL){
|
|
if ((m_nManualControlMode & CD_WIDE) == 0){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_TELE));
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode | CD_WIDE);
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdBeginZoomWide(((float)-tParam) / 1000.f);
|
|
#endif
|
|
};
|
|
m_nMenuActivityCounter = 75;
|
|
};
|
|
} else {
|
|
if (m_nCameraCaps & OC_ZOOM_CONTROLL){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~(CD_TELE | CD_WIDE)));
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdEndManualZoom();
|
|
#endif
|
|
};
|
|
};
|
|
tParam = m_pJO->getAxisX();
|
|
if (tParam < -200){
|
|
if (m_nCameraCaps & OC_PAN_CONTROLL){
|
|
if ((m_nManualControlMode & CD_LEFT) == 0){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_RIGHT));
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode | CD_LEFT);
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdBeginPanLeft(((float)-tParam) / 1000.f);
|
|
#endif
|
|
};
|
|
m_nMenuActivityCounter = 75;
|
|
};
|
|
} else if (tParam > 200){
|
|
if (m_nCameraCaps & OC_PAN_CONTROLL){
|
|
if ((m_nManualControlMode & CD_RIGHT) == 0){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_LEFT));
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode | CD_RIGHT);
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdBeginPanRight(((float)tParam) / 1000.f);
|
|
#endif
|
|
};
|
|
m_nMenuActivityCounter = 75;
|
|
};
|
|
} else {
|
|
if (m_nCameraCaps & OC_PAN_CONTROLL){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~(CD_LEFT | CD_RIGHT)));
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdEndManualPan();
|
|
#endif
|
|
};
|
|
};
|
|
tParam = m_pJO->getAxisY();
|
|
if (tParam > 200){
|
|
if (m_nCameraCaps & OC_TILT_CONTROLL){
|
|
if ((m_nManualControlMode & CD_UP) == 0){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_DOWN));
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode | CD_UP);
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdBeginTiltUp(((float)tParam) / 1000.f);
|
|
#endif
|
|
};
|
|
m_nMenuActivityCounter = 75;
|
|
};
|
|
} else if (tParam < -200){//Down
|
|
if (m_nCameraCaps & OC_TILT_CONTROLL){
|
|
if ((m_nManualControlMode & CD_DOWN) == 0){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_UP));
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode | CD_DOWN);
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdBeginTiltDown(((float)-tParam) / 1000.f);
|
|
#endif
|
|
};
|
|
m_nMenuActivityCounter = 75;
|
|
};
|
|
} else {
|
|
if (m_nCameraCaps & OC_TILT_CONTROLL){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~(CD_UP | CD_DOWN)));
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->cmdEndManualTilt();
|
|
#endif
|
|
};
|
|
};
|
|
} else {
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_JOYSTICK));
|
|
#ifndef NO_PTZ_CAMERAS
|
|
((basicCameraPTZ *)m_pCamera)->setDirectSpeedControl(false);
|
|
#endif
|
|
};
|
|
#endif //#ifndef NO_JOYSTICK
|
|
};
|
|
if ((m_nManualControlMode & CD_MOVIN ) == 0){
|
|
if ( m_nMenuActivityCounter) m_nMenuActivityCounter--;
|
|
else if ((m_nManualControlMode & CD_AUTO) == 0){
|
|
if (m_nManualControlMode & CD_MANUAL) releaseKeyboard();
|
|
#ifndef NO_PTZ_CAMERAS
|
|
if(m_pCamera!= NULL)((basicCameraPTZ *)m_pCamera)->setDirectSpeedControl(false);
|
|
#endif
|
|
m_nManualControlMode = CD_AUTO;
|
|
};
|
|
};
|
|
QPainter painter(this);
|
|
//painter.setRenderHint(QPainter::Antialiasing);
|
|
painter.setRenderHint((QPainter::RenderHint)7);// QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing
|
|
//if( !painter.isActive() ) painter.begin(this);
|
|
render(&painter);
|
|
//if (pa inter.isActive()) painter.end();
|
|
}catch (std::exception& e){
|
|
LOG_ERROR("RenderNow exception!");
|
|
};
|
|
m_pWidgetProtectorMutex->unlock();
|
|
}
|
|
//! [3]
|
|
|
|
//! [4]
|
|
void VideoWidget::render(QPainter *painter){
|
|
if( painter != NULL ){
|
|
try{
|
|
char buffer[64];
|
|
sprintf(buffer, "Coords: %d %d Key: %d PM: %dx%d", m_nMouseX, m_nMouseY, m_nKeyCode, m_pPixmap->width(),m_pPixmap->height() );
|
|
painter->save();
|
|
painter->drawPixmap(QRect(1, 1, m_pPixmap->width(), m_pPixmap->height()), *m_pPixmap);
|
|
QPen BgPen(Qt::SolidPattern,2);
|
|
BgPen.setColor(Qt::black);
|
|
QPen FgPen(Qt::SolidPattern,0);
|
|
FgPen.setColor(Qt::yellow);
|
|
painter->setPen(BgPen);
|
|
painter->drawText(QRect(0, 0, width(), height()), Qt::AlignHCenter | Qt::AlignBaseline, buffer);
|
|
painter->setPen(FgPen);
|
|
painter->drawText(QRect(0, 0, width(), height()), Qt::AlignHCenter | Qt::AlignBaseline , buffer);
|
|
if (m_pCamera != NULL){
|
|
uint8_t cnt;
|
|
if (cnt = m_pCamera->getLabelCount()){
|
|
osdLabel *pLabel;
|
|
for (uint8_t index = 0; index < cnt; index++){
|
|
pLabel = m_pCamera->getLabel(index);
|
|
if (pLabel != NULL){
|
|
FgPen.setColor(QColor(pLabel->color[0], pLabel->color[1], pLabel->color[2], pLabel->color[3]));
|
|
painter->setPen(FgPen);
|
|
painter->drawText(pLabel->x, pLabel->y, pLabel->text );
|
|
};
|
|
};
|
|
FgPen.setColor(Qt::yellow);
|
|
painter->setPen(FgPen);
|
|
};
|
|
if ((m_nManualControlMode & CD_AUTO) == 0){
|
|
QRect ManualRect(10, height() - m_pManualMode->height() - 10, m_pManualMode->width(), m_pManualMode->height());
|
|
if (m_nCameraCaps & OC_TILT_CONTROLL){
|
|
QRect UpRect(
|
|
(width() - m_pPixUp->width()) / 2,
|
|
(height() / 2) - m_pPixUp->height() - 10,
|
|
m_pPixUp->width(),
|
|
m_pPixUp->height());
|
|
QRect DownRect(
|
|
(width() - m_pPixDown->width()) / 2,
|
|
(height() / 2) + 10,
|
|
m_pPixDown->width(),
|
|
m_pPixDown->height());
|
|
if (m_nManualControlMode & CD_UP) {
|
|
painter->fillRect(UpRect, QColor(255, 255, 255, 63));
|
|
} else {
|
|
painter->drawRect(UpRect);
|
|
};
|
|
if (m_nManualControlMode & CD_DOWN){
|
|
painter->fillRect(DownRect, QColor(255, 255, 255, 63));
|
|
} else {
|
|
painter->drawRect(DownRect);
|
|
};
|
|
painter->drawPixmap(UpRect, *m_pPixUp);
|
|
painter->drawPixmap(DownRect, *m_pPixDown);
|
|
};
|
|
if (m_nCameraCaps & OC_PAN_CONTROLL){
|
|
QRect LeftRect(
|
|
(width() / 2) - m_pPixLeft->width() - 10 - (m_pPixLeft->width() / 2),
|
|
(height() / 2) - (m_pPixLeft->height() / 2),
|
|
m_pPixLeft->width(),
|
|
m_pPixLeft->height());
|
|
QRect RightRect(
|
|
(width() / 2) + 10 + (m_pPixRight->width() / 2),
|
|
(height() / 2) - (m_pPixRight->height() / 2),
|
|
m_pPixRight->width(),
|
|
m_pPixRight->height());
|
|
if (m_nManualControlMode & CD_RIGHT){
|
|
painter->fillRect(RightRect, QColor(255, 255, 255, 63));
|
|
} else {
|
|
painter->drawRect(RightRect);
|
|
};
|
|
if (m_nManualControlMode & CD_LEFT){
|
|
painter->fillRect(LeftRect, QColor(255, 255, 255, 63));
|
|
} else {
|
|
painter->drawRect(LeftRect);
|
|
};
|
|
painter->drawPixmap(LeftRect, *m_pPixLeft);
|
|
painter->drawPixmap(RightRect, *m_pPixRight);
|
|
};
|
|
if (m_nCameraCaps & OC_ZOOM_CONTROLL){
|
|
QRect WideRect(
|
|
25,
|
|
25,
|
|
m_pManualMode->width(),
|
|
m_pManualMode->height());
|
|
QRect TeleRect(
|
|
width() - m_pPixTele->height() - 25,
|
|
25,
|
|
m_pPixTele->width(),
|
|
m_pPixTele->height());
|
|
if (m_nManualControlMode & CD_WIDE){
|
|
painter->fillRect(WideRect, QColor(255, 255, 255, 63));
|
|
} else {
|
|
painter->drawRect(WideRect);
|
|
};
|
|
if (m_nManualControlMode & CD_TELE){
|
|
painter->fillRect(TeleRect, QColor(255, 255, 255, 63));
|
|
} else {
|
|
painter->drawRect(TeleRect);
|
|
};
|
|
painter->drawPixmap(WideRect, *m_pPixWide);
|
|
painter->drawPixmap(TeleRect, *m_pPixTele);
|
|
};
|
|
#ifndef NO_JOYSTICK
|
|
if( m_pJO!= NULL ){
|
|
if( m_pJO->isPresent() ){
|
|
if( m_pJO->isActive() ){
|
|
m_nManualControlMode = (ControlDirection)(m_nManualControlMode | CD_JOYSTICK);
|
|
painter->fillRect(ManualRect, QColor(255, 255, 255, 63));
|
|
m_nMenuActivityCounter = 75;
|
|
} else {
|
|
//m_nManualControlMode = (ControlDirection)(m_nManualControlMode & (~CD_JOYSTICK));
|
|
painter->drawRect(ManualRect);
|
|
};
|
|
} else {
|
|
painter->drawRect(ManualRect);
|
|
};
|
|
} else {
|
|
painter->drawRect(ManualRect);
|
|
};
|
|
#endif
|
|
painter->drawPixmap(ManualRect, *m_pManualMode);
|
|
};
|
|
};
|
|
painter->restore();
|
|
}catch (std::exception& e){
|
|
LOG_ERROR("Render exception!");
|
|
};
|
|
};
|
|
}
|
|
|
|
QSize VideoWidget::sizeHint() const {
|
|
QSize s = size();
|
|
//lastHeight = s.height();
|
|
s.setWidth((s.height() * 4) / 3);
|
|
s.setHeight(s.height());// QGroupBox::sizeHint().height());
|
|
return s;
|
|
};
|
|
|
|
void VideoWidget::resizeEvent(QResizeEvent *event){
|
|
if (m_pPixmap == NULL) return;
|
|
int w, h;
|
|
w = width();
|
|
h = height();
|
|
if ( abs( (width() * 3 ) - (height() * 4) ) > 4 ){
|
|
setFixedWidth((4 * height()) / 3);
|
|
//event->ignore();
|
|
//return;
|
|
};
|
|
m_pBorder->setGeometry(0, 0, width(), height());
|
|
m_pPropertiesProtectorMutex->lock();
|
|
delete(m_pPixmap);
|
|
m_pPixmap = new QPixmap(width()-2, height()-2);
|
|
if( m_mOutput != NULL ){
|
|
try{
|
|
assert(m_mOutput->isContinuous());
|
|
m_pWidgetProtectorMutex->lock();
|
|
m_pPixmap->fill(Qt::black);
|
|
QPainter dbPainter(m_pPixmap);
|
|
if (m_eStreamAspectRatio != m_eWidgetAspectRatio){
|
|
int tOffset;
|
|
if (m_eStreamAspectRatio > m_eWidgetAspectRatio){
|
|
int tHeight;
|
|
tHeight = (int)((float)m_pPixmap->width() / m_eStreamAspectRatio);
|
|
tOffset = (m_pPixmap->height() - tHeight) >> 1;
|
|
dbPainter.drawImage(QRect(0, tOffset, m_pPixmap->width(), tHeight),
|
|
QImage((unsigned char*)m_mOutput->data, m_mOutput->cols, m_mOutput->rows, QImage::Format_RGB888),
|
|
QRect(0, 0, m_mOutput->cols, m_mOutput->rows));
|
|
} else {
|
|
int tWidth;
|
|
tWidth = (int)((float)m_pPixmap->height() * m_eStreamAspectRatio);
|
|
tOffset = (m_pPixmap->width() - tWidth) >> 1;
|
|
dbPainter.drawImage(QRect(tOffset, 0, tWidth, m_pPixmap->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));
|
|
};
|
|
} else {
|
|
dbPainter.drawImage(QRect(0, 0, m_pPixmap->width(), m_pPixmap->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));
|
|
};
|
|
m_pWidgetProtectorMutex->unlock();
|
|
} catch (std::exception& e){
|
|
LOG_ERROR("Exception catched:");
|
|
LOG_ERROR(e.what());
|
|
};
|
|
} else {
|
|
m_pWidgetProtectorMutex->lock();
|
|
m_pPixmap->fill(Qt::black);
|
|
m_pWidgetProtectorMutex->unlock();
|
|
};
|
|
m_pPropertiesProtectorMutex->unlock();
|
|
event->accept();
|
|
};
|
|
|
|
bool VideoWidget::init( void ){
|
|
LOG("init.");
|
|
//int a;
|
|
//a = height();
|
|
//setFixedWidth( ( height() * 4 )/ 3 );
|
|
m_pPixmap = new QPixmap(width()-2, height()-2); //, QImage::Format_RGB888 );
|
|
if( m_pPixmap==NULL ) return false;
|
|
//m_pOverlayPixmap = new QPixmap("640x480.png", "PNG");
|
|
m_pManualMode = new QPixmap(":pictures/appbar.controller.snes.png", "PNG");
|
|
m_pPixUp = new QPixmap(":pictures/appbar.chevron.up.png", "PNG");
|
|
m_pPixDown = new QPixmap(":pictures/appbar.chevron.down.png", "PNG");
|
|
m_pPixLeft = new QPixmap(":pictures/appbar.chevron.left.png", "PNG");
|
|
m_pPixRight = new QPixmap(":pictures/appbar.chevron.right.png", "PNG");
|
|
m_pPixWide = new QPixmap(":pictures/appbar.arrow.expand.png", "PNG");
|
|
m_pPixTele = new QPixmap(":pictures/appbar.arrow.collapsed.png", "PNG");
|
|
m_pTimer = new QTimer();
|
|
if (m_pTimer != NULL){
|
|
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(update()));
|
|
m_pTimer->start(40);
|
|
};
|
|
m_pPixmap->fill(Qt::black);
|
|
m_pPropertiesProtectorMutex->lock();
|
|
m_pPropertiesProtectorMutex->unlock();
|
|
return false;
|
|
};
|
|
|
|
VideoWidget::~VideoWidget(){
|
|
if (m_pTimer){
|
|
m_pTimer->stop();
|
|
delete(m_pTimer);
|
|
};
|
|
delete( m_pPropertiesProtectorMutex );
|
|
delete( m_pWidgetProtectorMutex );
|
|
};
|
|
|
|
void VideoWidget::setGrayScale( bool AAA ){
|
|
m_pPropertiesProtectorMutex->lock();
|
|
m_bGrayScale = AAA;
|
|
m_pPropertiesProtectorMutex->unlock();
|
|
LOG("GRAYSCALE");
|
|
};
|
|
|
|
void VideoWidget::setEnhanced( bool AAA ){
|
|
m_pPropertiesProtectorMutex->lock();
|
|
m_bEnhanced = AAA;
|
|
m_pPropertiesProtectorMutex->unlock();
|
|
LOG("ENHANCED");
|
|
};
|
|
void VideoWidget::showFullScreen(void){
|
|
m_pWidgetProtectorMutex->lock();
|
|
if (m_pFullScreenView == NULL){
|
|
m_pFullScreenView = new QDialog(NULL);
|
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
#ifdef USE_OPENGL
|
|
m_pFSVideoWidget = new FSGLVideoWidget(m_pFullScreenView, 640,480, QColor(200, 150, 11));
|
|
#else
|
|
m_pFSVideoWidget = new FSVideoWidget(m_pFullScreenView);
|
|
#endif
|
|
m_pFSVideoWidget->init();
|
|
m_pFSVideoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
|
mainLayout->setSizeConstraint(QLayout::SizeConstraint::SetMaximumSize);
|
|
mainLayout->addWidget(m_pFSVideoWidget);
|
|
m_pFullScreenView->setLayout(mainLayout);
|
|
};
|
|
releaseKeyboard();
|
|
m_pFullScreenView->showFullScreen();
|
|
m_pFSVideoWidget->setCameraControl(m_pCamera, m_nCameraCaps);
|
|
m_pFSVideoWidget->setBindingSize( this, m_pFullScreenView->width(), m_pFullScreenView->height());
|
|
m_bFullScreenView = true;
|
|
m_pWidgetProtectorMutex->unlock();
|
|
};
|
|
void VideoWidget::hideFullScreen(void){
|
|
m_pWidgetProtectorMutex->lock();
|
|
if (m_pFullScreenView != NULL){
|
|
m_pFullScreenView->hide();
|
|
//grabKeyboard();
|
|
};
|
|
m_bFullScreenView = false;
|
|
m_pWidgetProtectorMutex->unlock();
|
|
};
|
|
/*
|
|
QImage Mat2QImage(cv::Mat const& src){
|
|
cv::Mat temp; // make the same cv::Mat
|
|
cvtColor(src, temp, CV_BGR2RGB); // cvtColor Makes a copt, that what i need
|
|
QImage dest((const uchar *)temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
|
|
dest.bits(); // enforce deep copy, see documentation
|
|
// of QImage::QImage ( const uchar * data, int width, int height, Format format )
|
|
return dest;
|
|
}
|
|
|
|
cv::Mat QImage2Mat(QImage const& src){
|
|
cv::Mat tmp(src.height(), src.width(), CV_8UC3, (uchar*)src.bits(), src.bytesPerLine());
|
|
cv::Mat result; // deep copy just in case (my lack of knowledge with open cv)
|
|
cvtColor(tmp, result, CV_BGR2RGB);
|
|
return result;
|
|
}
|
|
*/
|
|
|
|
void VideoWidget::pushFrame(cv::Mat *Frame, void *src){
|
|
if( Frame != NULL ){
|
|
if (m_bFullScreenView){
|
|
m_pFSVideoWidget->pushFrame(Frame);
|
|
return;
|
|
};
|
|
m_eStreamAspectRatio = detectAspectRatio(Frame->cols, Frame->rows);
|
|
/*if (m_bGrayScale) {
|
|
cvtColor(*Frame, *Frame, CV_BGR2GRAY);
|
|
};
|
|
if (m_bEnhanced) {
|
|
if (!m_bGrayScale) {
|
|
vector<cv::Mat> channels;
|
|
cv::Mat img_hist_equalized;
|
|
cvtColor(*Frame, img_hist_equalized, CV_BGR2YCrCb); //change the color image from BGR to YCrCb format
|
|
cv::split(img_hist_equalized, channels); //split the image into channels
|
|
cv::equalizeHist(channels[0], channels[0]); //equalize histogram on the 1st channel (Y)
|
|
merge(channels, img_hist_equalized); //merge 3 channels including the modified 1st channel into one image
|
|
cvtColor(img_hist_equalized, *Frame, CV_YCrCb2BGR); //change the color image from YCrCb to BGR format (to display image properly)
|
|
}
|
|
else {
|
|
equalizeHist(*Frame, *Frame);
|
|
};
|
|
};*/
|
|
//if (!m_bGrayScale) cvtColor(*Frame, *Frame, CV_BGR2RGB);
|
|
m_mOutput = Frame;
|
|
try{
|
|
assert(m_mOutput->isContinuous());
|
|
m_pWidgetProtectorMutex->lock();
|
|
m_pPixmap->fill(Qt::black);
|
|
QPainter dbPainter(m_pPixmap);
|
|
if (m_eStreamAspectRatio != m_eWidgetAspectRatio){
|
|
int tOffset;
|
|
if (m_eStreamAspectRatio > m_eWidgetAspectRatio){
|
|
int tHeight;
|
|
tHeight = (int)((float)m_pPixmap->width() / m_eStreamAspectRatio);
|
|
tOffset = (m_pPixmap->height() - tHeight) >> 1;
|
|
dbPainter.drawImage(QRect(0, tOffset, m_pPixmap->width(), tHeight),
|
|
QImage((unsigned char*)m_mOutput->data, m_mOutput->cols, m_mOutput->rows, QImage::Format_RGB888),
|
|
QRect(0, 0, m_mOutput->cols, m_mOutput->rows));
|
|
} else {
|
|
int tWidth;
|
|
tWidth = (int)((float)m_pPixmap->height() * m_eStreamAspectRatio);
|
|
tOffset = (m_pPixmap->width() - tWidth) >> 1;
|
|
dbPainter.drawImage(QRect(tOffset, 0, tWidth, m_pPixmap->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));
|
|
};
|
|
} else {
|
|
dbPainter.drawImage(QRect(0, 0, m_pPixmap->width(), m_pPixmap->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));
|
|
};
|
|
m_pWidgetProtectorMutex->unlock();
|
|
}
|
|
catch (std::exception& e){
|
|
LOG_ERROR("Exception catched:");
|
|
LOG_ERROR(e.what());
|
|
};
|
|
m_pPropertiesProtectorMutex->unlock();
|
|
//delete(Frame);
|
|
};
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|