qt_demoe/video/videopanel/videopanel.cpp

161 lines
4.0 KiB
C++
Raw Normal View History

2020-04-15 02:22:08 +00:00
#pragma execution_character_set("utf-8")
#include "videopanel.h"
2021-11-09 12:39:42 +00:00
#include "videobox.h"
2020-04-15 02:22:08 +00:00
#include "qevent.h"
#include "qmenu.h"
#include "qlayout.h"
#include "qlabel.h"
#include "qtimer.h"
#include "qdebug.h"
VideoPanel::VideoPanel(QWidget *parent) : QWidget(parent)
{
this->initControl();
this->initForm();
this->initMenu();
2024-02-26 02:34:39 +00:00
QTimer::singleShot(1000, this, SLOT(playAll()));
2020-04-15 02:22:08 +00:00
}
bool VideoPanel::eventFilter(QObject *watched, QEvent *event)
{
2023-12-15 04:55:21 +00:00
int type = event->type();
if (type == QEvent::MouseButtonDblClick) {
2020-04-15 02:22:08 +00:00
QLabel *widget = (QLabel *) watched;
if (!videoMax) {
videoMax = true;
2024-02-26 02:34:39 +00:00
videoBox->hide_all();
2020-04-15 02:22:08 +00:00
gridLayout->addWidget(widget, 0, 0);
widget->setVisible(true);
} else {
videoMax = false;
2024-02-26 02:34:39 +00:00
videoBox->show_all();
2020-04-15 02:22:08 +00:00
}
widget->setFocus();
2023-12-15 04:55:21 +00:00
} else if (type == QEvent::MouseButtonPress) {
2020-04-15 02:22:08 +00:00
QMouseEvent *mouseEvent = (QMouseEvent *)event;
if (mouseEvent->button() == Qt::RightButton) {
videoMenu->exec(QCursor::pos());
}
}
return QWidget::eventFilter(watched, event);
}
QSize VideoPanel::sizeHint() const
{
return QSize(800, 600);
}
QSize VideoPanel::minimumSizeHint() const
{
return QSize(80, 60);
}
void VideoPanel::initControl()
{
gridLayout = new QGridLayout;
gridLayout->setSpacing(1);
2020-12-24 10:00:09 +00:00
gridLayout->setContentsMargins(0, 0, 0, 0);
2020-04-15 02:22:08 +00:00
this->setLayout(gridLayout);
}
void VideoPanel::initForm()
{
//设置样式表
2021-06-04 05:33:16 +00:00
#ifndef no_style
2020-04-15 02:22:08 +00:00
QStringList qss;
qss.append("QFrame{border:2px solid #000000;}");
2021-03-20 05:54:55 +00:00
qss.append("QLabel{font:75 25px;color:#F0F0F0;border:2px solid #AAAAAA;background:#303030;}");
2020-04-15 02:22:08 +00:00
qss.append("QLabel:focus{border:2px solid #00BB9E;background:#555555;}");
this->setStyleSheet(qss.join(""));
2021-06-04 05:33:16 +00:00
#endif
2020-04-15 02:22:08 +00:00
videoMax = false;
videoCount = 64;
2024-02-26 02:34:39 +00:00
layoutType = "1_16";
2020-04-15 02:22:08 +00:00
for (int i = 0; i < videoCount; ++i) {
2020-04-15 02:22:08 +00:00
QLabel *widget = new QLabel;
widget->setObjectName(QString("video%1").arg(i + 1));
widget->installEventFilter(this);
widget->setFocusPolicy(Qt::StrongFocus);
widget->setAlignment(Qt::AlignCenter);
2022-01-13 03:27:55 +00:00
widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
2020-04-15 02:22:08 +00:00
//二选一可以选择显示文字,也可以选择显示背景图片
widget->setText(QString("通道 %1").arg(i + 1));
//widget->setPixmap(QPixmap(":/bg_novideo.png"));
2021-11-09 12:39:42 +00:00
widgets << widget;
2020-04-15 02:22:08 +00:00
}
}
void VideoPanel::initMenu()
{
videoMenu = new QMenu(this);
2021-11-09 12:39:42 +00:00
//单独关联信号槽
2020-04-15 02:22:08 +00:00
actionFull = new QAction("切换全屏模式", videoMenu);
connect(actionFull, SIGNAL(triggered(bool)), this, SLOT(full()));
actionPoll = new QAction("启动轮询视频", videoMenu);
connect(actionPoll, SIGNAL(triggered(bool)), this, SLOT(poll()));
2021-11-09 12:39:42 +00:00
//通过QAction类方式添加子菜单
2020-04-15 02:22:08 +00:00
videoMenu->addAction(actionFull);
videoMenu->addAction(actionPoll);
videoMenu->addSeparator();
2021-11-09 12:39:42 +00:00
//直接通过文字的形式添加子菜单
2024-02-26 02:34:39 +00:00
videoMenu->addAction("截图当前视频", this, SLOT(snapOne()));
videoMenu->addAction("截图所有视频", this, SLOT(snapAll()));
2020-04-15 02:22:08 +00:00
videoMenu->addSeparator();
2021-11-09 12:39:42 +00:00
//实例化通道布局类
videoBox = new VideoBox(this);
2023-12-23 05:30:26 +00:00
videoBox->initMenu(videoMenu);
2024-02-26 02:34:39 +00:00
videoBox->setLayoutType(layoutType);
2021-11-09 12:39:42 +00:00
videoBox->setLayout(gridLayout);
videoBox->setWidgets(widgets);
2024-02-26 02:34:39 +00:00
videoBox->show_all();
2020-04-15 02:22:08 +00:00
}
void VideoPanel::full()
{
if (actionFull->text() == "切换全屏模式") {
2023-12-06 11:15:52 +00:00
Q_EMIT fullScreen(true);
2020-04-15 02:22:08 +00:00
actionFull->setText("切换正常模式");
} else {
2023-12-06 11:15:52 +00:00
Q_EMIT fullScreen(false);
2020-04-15 02:22:08 +00:00
actionFull->setText("切换全屏模式");
}
//执行全屏处理
}
void VideoPanel::poll()
{
if (actionPoll->text() == "启动轮询视频") {
actionPoll->setText("停止轮询视频");
} else {
actionPoll->setText("启动轮询视频");
}
//执行轮询处理
}
2024-02-26 02:34:39 +00:00
void VideoPanel::playAll()
2020-04-15 02:22:08 +00:00
{
}
2024-02-26 02:34:39 +00:00
void VideoPanel::snapOne()
2020-04-15 02:22:08 +00:00
{
}
2024-02-26 02:34:39 +00:00
void VideoPanel::snapAll()
2020-04-15 02:22:08 +00:00
{
}