Qt Open Source Works 6-Universal Video Control

Keywords: osd Qt SDK Spring

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:

  1. Settable border size
  2. Settable border color
  3. Two-way OSD tags can be set
  4. Sets whether OSD labels are drawn
  5. Label text or picture can be set
  6. Can set OSD position top left + bottom left + top right + bottom right
  7. OSD Style Text+Date+Time+Date Time+Picture Settable
  8. Custom translucent suspended form, row of buttons
  9. Suspend button to customize settings, including background color + press color
  10. Send signal to tell which suspend button was clicked
  11. Ability to recognize dragged-in files and notify url
  12. 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.

  1. Domestic site: https://gitee.com/feiyangqingyun/QWidgetDemo
  2. International site: https://github.com/feiyangqingyun/QWidgetDemo
  3. Personal home page: https://blog.csdn.net/feiyangqingyun
  4. Knowing Home Page: https://www.zhihu.com/people/feiyangqingyun/

Posted by jimdavidson on Sun, 10 May 2020 18:09:31 -0700