1. Preface
In the previous video monitoring system, according to the needs of different users, many kinds of video monitoring cores have been made, including ffmpeg cores, vlc cores, mpv cores, and Haikang sdk cores. In order to make a common function, different cores are very convenient to switch, such as pro changing the variable name of DEFINE directly, so it is necessary to make use of various cores into oneSuch an interface, so it looks very neat, so a universal video control is deliberately extracted later. It does not have specific video playback control functions. It needs to call specific methods to implement according to different cores. Later, when Dahua sdk or other third-party manufacturers'agreements are added, the universal video control can be applied directly.
Universal video control functions:
- Settable border size
- Settable border color
- Two-way OSD tags can be set
- Sets whether OSD labels are drawn
- Label text or picture can be set
- Can set OSD position top left + bottom left + top right + bottom right
- OSD Style Text+Date+Time+Date Time+Picture Settable
- Custom translucent suspended form, row of buttons
- Suspend button to customize settings, including background color + press color
- Send signal to tell which suspend button was clicked
- Ability to recognize dragged-in files and notify url
- Provide interfaces such as open close pause
2. Code ideas
//Set suspension bar //Top Toolbar, Hide by Default, Mouse in Display Remove Hide flowPanel = new QWidget(this); flowPanel->setObjectName("flowPanel"); flowPanel->setVisible(false); //Top with layout, left spring QHBoxLayout *layout = new QHBoxLayout; layout->setSpacing(2); layout->setMargin(0); layout->addStretch(); flowPanel->setLayout(layout); //Button Collection Name, if you need to add a new button, add it here QList<QString> btns; btns << "btnFlowVideo" << "btnFlowSnap" << "btnFlowSound" << "btnFlowAlarm" << "btnFlowClose"; void VideoWidget::resizeEvent(QResizeEvent *) { //Reset the position and width of the top toolbar so that you can set the top or bottom display yourself int height = 20; flowPanel->setGeometry(borderWidth, borderWidth, this->width() - (borderWidth * 2), height); //flowPanel->setGeometry(borderWidth, this->height() - height - borderWidth, this->width() - (borderWidth * 2), height); } void VideoWidget::enterEvent(QEvent *) { //You can also add a judgment here that the focus needs to be displayed //if (this->hasFocus()) {} if (flowEnable) { flowPanel->setVisible(true); } } void VideoWidget::leaveEvent(QEvent *) { if (flowEnable) { flowPanel->setVisible(false); } } //Support drag recognition void VideoWidget::dropEvent(QDropEvent *event) { //Execute when the mouse is released after dragging and dropping //Determine the type of drag and drop, take out the file, play if(event->mimeData()->hasUrls()) { QString url = event->mimeData()->urls().first().toLocalFile(); this->close(); this->setUrl(url); this->open(); emit fileDrag(url); } else if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) { QTreeWidget *treeWidget = (QTreeWidget *)event->source(); if (treeWidget != 0) { QString url = treeWidget->currentItem()->data(0, Qt::UserRole).toString(); this->close(); this->setUrl(url); this->open(); emit fileDrag(url); } } } void VideoWidget::dragEnterEvent(QDragEnterEvent *event) { //Judge the type first when dragging in, but not the illegal type if(event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) { event->setDropAction(Qt::CopyAction); event->accept(); } else if(event->mimeData()->hasFormat("text/uri-list")) { event->setDropAction(Qt::LinkAction); event->accept(); } else { event->ignore(); } }
3. Effect Charts
4. Open Source Home Page
The complete source downloads of the above works are all on the open source homepage. The quantity and quality of the works will be continuously updated, and you are welcome to pay attention.
- Domestic site: https://gitee.com/feiyangqingyun/QWidgetDemo
- International site: https://github.com/feiyangqingyun/QWidgetDemo
- Personal home page: https://blog.csdn.net/feiyangqingyun
- Knowing Home Page: https://www.zhihu.com/people/feiyangqingyun/