Qt open source works 42 - video surveillance layout

1, Foreword

Since the establishment of the monitoring system, it has always been planned to separate this function into a class. In this way, many systems use this kind of layout switching, and the general class is OK. In addition, in the later stage, this layout will add other special-shaped layouts, and even generate layouts according to the ratio of 16:9. Previously, this function was directly written in the UI class of the function interface, which is inconvenient to expand, Many systems use this function. Once the 64 channel layout and 128 channel layout are added, they need to make corresponding changes, which is very annoying. Therefore, it is necessary to completely separate this function to lay the foundation for the subsequent 256 channel, special-shaped layout and custom layout.

Channel switching is the most basic and necessary function in the video monitoring system. It generally provides channel switching of 1 channel, 4 channel, 6 channel, 8 channel, 9 channel and 16 channel. It may also provide 24 channel, 32 channel and 64 channel. This may have certain requirements for the configuration of the computer. Generally speaking, more than 9 channels display video streams in real time, Basically, the sub code stream will be used for display. If the main code stream is used, the computer pressure is very huge, the CPU occupation is very high, and the memory is also high. However, the computer configuration is getting higher and higher. Basically, the desktop computer with more than 4000 yuan has been configured very well, and there is no pressure to display 16 channels of real-time video.

The layout in Qt is very easy to use, especially the QGridLayout table layout. You can specify rows and columns to place controls, and you can also set how many rows and columns each control occupies, so that various channel layouts can be perfectly realized. For example, for channel 6, it can be set that channel 1 occupies two rows and two columns, and each station of other channels has one row and one column. When switching the layout, other channels can be hidden.

2, Main functions

  1. Centralize all channel switching processing into one class.
  2. The general integer multiple layout switching function can be easily extended to 100, 255 channels, etc.
  3. General special-shaped layout switching function, you can refer to custom special-shaped layout.
  4. Signaling for channel layout switching.
  5. Control whether each layout switching menu is enabled.
  6. Support self defined submenu layout content.
  7. It supports setting the corresponding menu ID, such as changing the default channel word to device.

3, Renderings

4, Open source Homepage

  • The complete source code of the above works is downloaded on the open source homepage. The quantity and quality of works will be continuously updated. You are welcome to pay attention.
  • This open source project has been successfully upgraded to version V2.0. It is classified and illustrated to ensure that you are cool to explosion.
  • Qt open source Wulin secret script development experience, after reading and learning, 20K starting salary, didn't find me!
  1. Domestic sites: https://gitee.com/feiyangqingyun/QWidgetDemo
  2. International sites: https://github.com/feiyangqingyun/QWidgetDemo
  3. Open source script: https://gitee.com/feiyangqingyun/qtkaifajingyan
  4. Personal homepage: https://qtchina.blog.csdn.net/
  5. Zhihu homepage: https://www.zhihu.com/people/feiyangqingyun/

5, Core code

void VideoBox::change_video_normal(int index, int flag)
{
    //Hide all channels first
    hide_video_all();
    int count = 0;
    int row = 0;
    int column = 0;

    //If the number of rows and columns is the same, such as 2 * 2 3 * 4 4 * 4 5 * 5, you can directly apply the general formula
    //According to this function, you can easily expand the 10 * 10 16 * 16 = 256 channel interface
    for (int i = 0; i < videoCount; i++) {
        if (i >= index) {
            //Add to the corresponding layout and set visible
            gridLayout->addWidget(widgets.at(i), row, column);
            widgets.at(i)->setVisible(true);

            count++;
            column++;
            if (column == flag) {
                row++;
                column = 0;
            }
        }

        if (count == (flag * flag)) {
            break;
        }
    }
}

void VideoBox::change_video_custom(int index, int type)
{
    //How many channels are derived from the start index
    QList<int> indexs;
    for (int i = index; i < (index + type); ++i) {
        indexs << i;
    }

    if (type == 6) {
        change_video_6(indexs);
    } else if (type == 8) {
        change_video_8(indexs);
    } else if (type == 13) {
        change_video_13(indexs);
    }
}

void VideoBox::change_video_6(const QList<int> &indexs)
{
    //Filtering prevents index overruns
    if (indexs.count() < 6) {
        return;
    }

    //Hide all channels first
    hide_video_all();
    //Re add to layout one by one
    gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 2, 2);
    gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 2, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(2)), 1, 2, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(3)), 2, 2, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(4)), 2, 1, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(5)), 2, 0, 1, 1);
    //Set channel controls visible
    for (int i = indexs.first(); i <= indexs.last(); i++) {
        widgets.at(i)->setVisible(true);
    }
}

void VideoBox::change_video_8(const QList<int> &indexs)
{
    //Filtering prevents index overruns
    if (indexs.count() < 8) {
        return;
    }

    //Hide all channels first
    hide_video_all();
    //Re add to layout one by one
    gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 3, 3);
    gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 3, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(2)), 1, 3, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(3)), 2, 3, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(4)), 3, 3, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(5)), 3, 2, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(6)), 3, 1, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(7)), 3, 0, 1, 1);
    //Set channel controls visible
    for (int i = indexs.first(); i <= indexs.last(); i++) {
        widgets.at(i)->setVisible(true);
    }
}

void VideoBox::change_video_13(const QList<int> &indexs)
{
    //Filtering prevents index overruns
    if (indexs.count() < 13) {
        return;
    }

    //Hide all channels first
    hide_video_all();
    //Re add to layout one by one
    gridLayout->addWidget(widgets.at(indexs.at(0)), 0, 0, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(1)), 0, 1, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(2)), 0, 2, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(3)), 0, 3, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(4)), 1, 0, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(5)), 2, 0, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(6)), 1, 1, 2, 2);
    gridLayout->addWidget(widgets.at(indexs.at(7)), 1, 3, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(8)), 2, 3, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(9)), 3, 0, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(10)), 3, 1, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(11)), 3, 2, 1, 1);
    gridLayout->addWidget(widgets.at(indexs.at(12)), 3, 3, 1, 1);
    //Set channel controls visible
    for (int i = indexs.first(); i <= indexs.last(); i++) {
        widgets.at(i)->setVisible(true);
    }
}

void VideoBox::change_video_1(int index)
{
    //Hide all channels first
    hide_video_all();
    //Add channel to layout
    gridLayout->addWidget(widgets.at(index), 0, 0);
    //Set visible
    widgets.at(index)->setVisible(true);
}

void VideoBox::change_video_4(int index)
{
    change_video_normal(index, 2);
}

void VideoBox::change_video_6(int index)
{
    change_video_custom(index, 6);
}

void VideoBox::change_video_8(int index)
{
    change_video_custom(index, 8);
}

void VideoBox::change_video_9(int index)
{
    change_video_normal(index, 3);
}

void VideoBox::change_video_13(int index)
{
    change_video_custom(index, 13);
}

void VideoBox::change_video_16(int index)
{
    change_video_normal(index, 4);
}

void VideoBox::change_video_25(int index)
{
    change_video_normal(index, 5);
}

void VideoBox::change_video_36(int index)
{
    change_video_normal(index, 6);
}

void VideoBox::change_video_64(int index)
{
    change_video_normal(index, 8);
}

Tags: Qt

Posted on Mon, 29 Nov 2021 01:53:29 -0500 by Sware