|
|
|
|
@ -10,6 +10,7 @@
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
|
|
#include "videoform.h"
|
|
|
|
|
#include "qyuvopenglwidget.h"
|
|
|
|
|
#include "mousetap/mousetap.h"
|
|
|
|
|
#include "ui_videoform.h"
|
|
|
|
|
#include "iconhelper.h"
|
|
|
|
|
@ -59,15 +60,20 @@ void VideoForm::initUI()
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_videoWidget = new QYUVOpenGLWidget();
|
|
|
|
|
m_videoWidget->hide();
|
|
|
|
|
ui->keepRadioWidget->setWidget(m_videoWidget);
|
|
|
|
|
ui->keepRadioWidget->setWidthHeightRadio(m_widthHeightRatio);
|
|
|
|
|
|
|
|
|
|
setMouseTracking(true);
|
|
|
|
|
ui->videoWidget->setMouseTracking(true);
|
|
|
|
|
ui->videoWidget->hide();
|
|
|
|
|
m_videoWidget->setMouseTracking(true);
|
|
|
|
|
ui->keepRadioWidget->setMouseTracking(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoForm::onGrabCursor(bool grab)
|
|
|
|
|
{
|
|
|
|
|
#if defined(Q_OS_WIN32) || defined(Q_OS_OSX)
|
|
|
|
|
MouseTap::getInstance()->enableMouseEventTap(ui->videoWidget, grab);
|
|
|
|
|
MouseTap::getInstance()->enableMouseEventTap(m_videoWidget, grab);
|
|
|
|
|
#else
|
|
|
|
|
Q_UNUSED(grab)
|
|
|
|
|
#endif
|
|
|
|
|
@ -75,16 +81,16 @@ void VideoForm::onGrabCursor(bool grab)
|
|
|
|
|
|
|
|
|
|
void VideoForm::updateRender(const AVFrame *frame)
|
|
|
|
|
{
|
|
|
|
|
if (ui->videoWidget->isHidden()) {
|
|
|
|
|
if (m_videoWidget->isHidden()) {
|
|
|
|
|
if (m_loadingWidget) {
|
|
|
|
|
m_loadingWidget->close();
|
|
|
|
|
}
|
|
|
|
|
ui->videoWidget->show();
|
|
|
|
|
m_videoWidget->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateShowSize(QSize(frame->width, frame->height));
|
|
|
|
|
ui->videoWidget->setFrameSize(QSize(frame->width, frame->height));
|
|
|
|
|
ui->videoWidget->updateTextures(frame->data[0], frame->data[1], frame->data[2],
|
|
|
|
|
m_videoWidget->setFrameSize(QSize(frame->width, frame->height));
|
|
|
|
|
m_videoWidget->updateTextures(frame->data[0], frame->data[1], frame->data[2],
|
|
|
|
|
frame->linesize[0], frame->linesize[1], frame->linesize[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -98,6 +104,18 @@ void VideoForm::showToolForm(bool show)
|
|
|
|
|
m_toolForm->setVisible(show);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoForm::moveCenter()
|
|
|
|
|
{
|
|
|
|
|
QDesktopWidget* desktop = QApplication::desktop();
|
|
|
|
|
if (!desktop) {
|
|
|
|
|
qWarning() << "QApplication::desktop() is nullptr";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QRect screenRect = desktop->availableGeometry();
|
|
|
|
|
// 窗口居中
|
|
|
|
|
move(screenRect.center() - QRect(0, 0, size().width(), size().height()).center());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoForm::updateStyleSheet(bool vertical)
|
|
|
|
|
{
|
|
|
|
|
if (vertical) {
|
|
|
|
|
@ -129,45 +147,37 @@ QMargins VideoForm::getMargins(bool vertical)
|
|
|
|
|
return margins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoForm::updateScreenRatio(const QSize &newSize)
|
|
|
|
|
{
|
|
|
|
|
m_widthHeightRatio = 1.0f * qMin(newSize.width(),newSize.height()) / qMax(newSize.width(),newSize.height());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoForm::updateShowSize(const QSize &newSize)
|
|
|
|
|
{
|
|
|
|
|
if (m_frameSize != newSize) {
|
|
|
|
|
m_frameSize = newSize;
|
|
|
|
|
bool vertical = newSize.height() > newSize.width();
|
|
|
|
|
QSize showSize = newSize;
|
|
|
|
|
QDesktopWidget* desktop = QApplication::desktop();
|
|
|
|
|
if (desktop) {
|
|
|
|
|
QRect screenRect = desktop->availableGeometry();
|
|
|
|
|
if (vertical) {
|
|
|
|
|
showSize.setHeight(qMin(newSize.height(), screenRect.height() - 200));
|
|
|
|
|
showSize.setWidth(showSize.height() * m_widthHeightRatio);
|
|
|
|
|
} else {
|
|
|
|
|
showSize.setWidth(qMin(newSize.width(), screenRect.width()/2));
|
|
|
|
|
showSize.setHeight(showSize.width() * m_widthHeightRatio);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isFullScreen()) {
|
|
|
|
|
switchFullScreen();
|
|
|
|
|
}
|
|
|
|
|
if (m_skin) {
|
|
|
|
|
QMargins m = getMargins(vertical);
|
|
|
|
|
showSize.setWidth(showSize.width() + m.left() + m.right());
|
|
|
|
|
showSize.setHeight(showSize.height() + m.top() + m.bottom());
|
|
|
|
|
}
|
|
|
|
|
m_widthHeightRatio = 1.0f * newSize.width() / newSize.height();
|
|
|
|
|
ui->keepRadioWidget->setWidthHeightRadio(m_widthHeightRatio);
|
|
|
|
|
|
|
|
|
|
// 窗口居中
|
|
|
|
|
move(screenRect.center() - QRect(0, 0, showSize.width(), showSize.height()).center());
|
|
|
|
|
bool vertical = m_widthHeightRatio < 1.0f ? true : false;
|
|
|
|
|
QSize showSize = newSize;
|
|
|
|
|
QDesktopWidget* desktop = QApplication::desktop();
|
|
|
|
|
if (!desktop) {
|
|
|
|
|
qWarning() << "QApplication::desktop() is nullptr";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QRect screenRect = desktop->availableGeometry();
|
|
|
|
|
if (vertical) {
|
|
|
|
|
showSize.setHeight(qMin(newSize.height(), screenRect.height() - 200));
|
|
|
|
|
showSize.setWidth(showSize.height() * m_widthHeightRatio);
|
|
|
|
|
} else {
|
|
|
|
|
showSize.setWidth(qMin(newSize.width(), screenRect.width()/2));
|
|
|
|
|
showSize.setHeight(showSize.width() / m_widthHeightRatio);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_skin) {
|
|
|
|
|
// 减去标题栏高度
|
|
|
|
|
int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight);
|
|
|
|
|
showSize.setHeight(showSize.height() - titleBarHeight);
|
|
|
|
|
if (isFullScreen()) {
|
|
|
|
|
switchFullScreen();
|
|
|
|
|
}
|
|
|
|
|
if (m_skin) {
|
|
|
|
|
QMargins m = getMargins(vertical);
|
|
|
|
|
showSize.setWidth(showSize.width() + m.left() + m.right());
|
|
|
|
|
showSize.setHeight(showSize.height() + m.top() + m.bottom());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showSize != size()) {
|
|
|
|
|
@ -175,6 +185,7 @@ void VideoForm::updateShowSize(const QSize &newSize)
|
|
|
|
|
if (m_skin) {
|
|
|
|
|
updateStyleSheet(vertical);
|
|
|
|
|
}
|
|
|
|
|
moveCenter();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -182,7 +193,14 @@ void VideoForm::updateShowSize(const QSize &newSize)
|
|
|
|
|
void VideoForm::switchFullScreen()
|
|
|
|
|
{
|
|
|
|
|
if (isFullScreen()) {
|
|
|
|
|
// 横屏全屏铺满全屏,恢复时,恢复保持宽高比
|
|
|
|
|
if (m_widthHeightRatio > 1.0f) {
|
|
|
|
|
ui->keepRadioWidget->setWidthHeightRadio(m_widthHeightRatio);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showNormal();
|
|
|
|
|
// fullscreen window will move (0,0). qt bug?
|
|
|
|
|
move(m_fullScreenBeforePos);
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_OSX
|
|
|
|
|
//setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
|
|
|
|
|
@ -196,6 +214,12 @@ void VideoForm::switchFullScreen()
|
|
|
|
|
::SetThreadExecutionState(ES_CONTINUOUS);
|
|
|
|
|
#endif
|
|
|
|
|
} else {
|
|
|
|
|
// 横屏全屏铺满全屏,不保持宽高比
|
|
|
|
|
if (m_widthHeightRatio > 1.0f) {
|
|
|
|
|
ui->keepRadioWidget->setWidthHeightRadio(-1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_fullScreenBeforePos = pos();
|
|
|
|
|
// 这种临时增加标题栏再全屏的方案会导致收不到mousemove事件,导致setmousetrack失效
|
|
|
|
|
// mac fullscreen must show title bar
|
|
|
|
|
#ifdef Q_OS_OSX
|
|
|
|
|
@ -256,12 +280,12 @@ void VideoForm::setController(Controller *controller)
|
|
|
|
|
|
|
|
|
|
void VideoForm::mousePressEvent(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (ui->videoWidget->geometry().contains(event->pos())) {
|
|
|
|
|
if (m_videoWidget->geometry().contains(event->pos())) {
|
|
|
|
|
if (!m_controller) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event->setLocalPos(ui->videoWidget->mapFrom(this, event->localPos().toPoint()));
|
|
|
|
|
m_controller->mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size());
|
|
|
|
|
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint()));
|
|
|
|
|
m_controller->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
|
|
|
|
} else {
|
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
|
m_dragPosition = event->globalPos() - frameGeometry().topLeft();
|
|
|
|
|
@ -276,23 +300,23 @@ void VideoForm::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
|
if (!m_controller) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event->setLocalPos(ui->videoWidget->mapFrom(this, event->localPos().toPoint()));
|
|
|
|
|
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint()));
|
|
|
|
|
// local check
|
|
|
|
|
QPointF local = event->localPos();
|
|
|
|
|
if (local.x() < 0) {
|
|
|
|
|
local.setX(0);
|
|
|
|
|
}
|
|
|
|
|
if (local.x() > ui->videoWidget->width()) {
|
|
|
|
|
local.setX(ui->videoWidget->width());
|
|
|
|
|
if (local.x() > m_videoWidget->width()) {
|
|
|
|
|
local.setX(m_videoWidget->width());
|
|
|
|
|
}
|
|
|
|
|
if (local.y() < 0) {
|
|
|
|
|
local.setY(0);
|
|
|
|
|
}
|
|
|
|
|
if (local.y() > ui->videoWidget->height()) {
|
|
|
|
|
local.setY(ui->videoWidget->height());
|
|
|
|
|
if (local.y() > m_videoWidget->height()) {
|
|
|
|
|
local.setY(m_videoWidget->height());
|
|
|
|
|
}
|
|
|
|
|
event->setLocalPos(local);
|
|
|
|
|
m_controller->mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size());
|
|
|
|
|
m_controller->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
|
|
|
|
} else {
|
|
|
|
|
m_dragPosition = QPoint(0, 0);
|
|
|
|
|
}
|
|
|
|
|
@ -300,12 +324,12 @@ void VideoForm::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
|
|
|
|
|
|
void VideoForm::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (ui->videoWidget->geometry().contains(event->pos())) {
|
|
|
|
|
if (m_videoWidget->geometry().contains(event->pos())) {
|
|
|
|
|
if (!m_controller) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event->setLocalPos(ui->videoWidget->mapFrom(this, event->localPos().toPoint()));
|
|
|
|
|
m_controller->mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size());
|
|
|
|
|
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint()));
|
|
|
|
|
m_controller->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
|
|
|
|
} else if (!m_dragPosition.isNull()){
|
|
|
|
|
if (event->buttons() & Qt::LeftButton) {
|
|
|
|
|
move(event->globalPos() - m_dragPosition);
|
|
|
|
|
@ -316,11 +340,11 @@ void VideoForm::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
|
|
|
|
|
|
void VideoForm::wheelEvent(QWheelEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (ui->videoWidget->geometry().contains(event->pos())) {
|
|
|
|
|
if (m_videoWidget->geometry().contains(event->pos())) {
|
|
|
|
|
if (!m_controller) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QPointF pos = ui->videoWidget->mapFrom(this, event->pos());
|
|
|
|
|
QPointF pos = m_videoWidget->mapFrom(this, event->pos());
|
|
|
|
|
/*
|
|
|
|
|
QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta,
|
|
|
|
|
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
|
|
|
|
|
@ -328,7 +352,7 @@ void VideoForm::wheelEvent(QWheelEvent *event)
|
|
|
|
|
*/
|
|
|
|
|
QWheelEvent wheelEvent(pos, event->globalPosF(), event->delta(),
|
|
|
|
|
event->buttons(), event->modifiers(), event->orientation());
|
|
|
|
|
m_controller->wheelEvent(&wheelEvent, ui->videoWidget->frameSize(), ui->videoWidget->size());
|
|
|
|
|
m_controller->wheelEvent(&wheelEvent, m_videoWidget->frameSize(), m_videoWidget->size());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -354,7 +378,7 @@ void VideoForm::keyPressEvent(QKeyEvent *event)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_controller->keyEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size());
|
|
|
|
|
m_controller->keyEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoForm::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
|
@ -362,7 +386,7 @@ void VideoForm::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
|
if (!m_controller) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_controller->keyEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size());
|
|
|
|
|
m_controller->keyEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoForm::paintEvent(QPaintEvent *paint)
|
|
|
|
|
@ -382,6 +406,32 @@ void VideoForm::showEvent(QShowEvent *event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoForm::resizeEvent(QResizeEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event)
|
|
|
|
|
QSize goodSize = ui->keepRadioWidget->goodSize();
|
|
|
|
|
if (goodSize.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QSize curSize = size();
|
|
|
|
|
// 限制VideoForm尺寸不能小于keepRadioWidget good size
|
|
|
|
|
if (m_widthHeightRatio > 1.0f) {
|
|
|
|
|
// hor
|
|
|
|
|
if (curSize.height() <= goodSize.height()) {
|
|
|
|
|
setMinimumHeight(goodSize.height());
|
|
|
|
|
} else {
|
|
|
|
|
setMinimumHeight(0);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// ver
|
|
|
|
|
if (curSize.width() <= goodSize.width()) {
|
|
|
|
|
setMinimumWidth(goodSize.width());
|
|
|
|
|
} else {
|
|
|
|
|
setMinimumWidth(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoForm::dragEnterEvent(QDragEnterEvent *event)
|
|
|
|
|
{
|
|
|
|
|
event->acceptProposedAction();
|
|
|
|
|
|