From fe9f1299a6ebb4d1811572a9267248d547b1cdba Mon Sep 17 00:00:00 2001 From: feiyangqingyun Date: Wed, 15 Apr 2020 10:22:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E25=2036=2064=E7=94=BB?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- videopanel/bg_novideo.png | Bin 4851 -> 0 bytes videopanel/frmmain.cpp | 378 ----------------------- videopanel/frmmain.h | 59 ---- videopanel/frmmain.ui | 64 ---- videopanel/frmvideopanel.cpp | 13 + videopanel/frmvideopanel.h | 22 ++ videopanel/frmvideopanel.ui | 32 ++ videopanel/main.cpp | 19 +- videopanel/main.qrc | 5 - videopanel/videopanel.cpp | 570 +++++++++++++++++++++++++++++++++++ videopanel/videopanel.h | 89 ++++++ videopanel/videopanel.pro | 27 +- 12 files changed, 749 insertions(+), 529 deletions(-) delete mode 100644 videopanel/bg_novideo.png delete mode 100644 videopanel/frmmain.cpp delete mode 100644 videopanel/frmmain.h delete mode 100644 videopanel/frmmain.ui create mode 100644 videopanel/frmvideopanel.cpp create mode 100644 videopanel/frmvideopanel.h create mode 100644 videopanel/frmvideopanel.ui delete mode 100644 videopanel/main.qrc create mode 100644 videopanel/videopanel.cpp create mode 100644 videopanel/videopanel.h diff --git a/videopanel/bg_novideo.png b/videopanel/bg_novideo.png deleted file mode 100644 index bdacfb28f24c279c925f7185cee7dfca6716fc23..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4851 zcmVOV7IZ~ebVG7wVRUJ4ZXi@?ZDjy4FfTDV zFEKY2U?nC10019!MObuGZ)S9NVRB^vO<`klZ*65{X<;BnX>w(EZ*psMAUL&X(s%#> z5=cozK~#90?VNp>Rn>LIe`gqE7=alG8dL&A28lKW!HOC+iZw(@C9x%bV5r(!Q5(~W zA!)=IKQMmOkJey}_K6siM_V*X5`sh|S~d6uN)j~&ji9k22#PR*48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t14U><}cue(t$^l%yZ zFAEgGc4QV_1P(%f1#kq4A-#yg1X&Bg*O_HX;(O!JF2_|=o}-VEMCHvzVU5F4Aaw{5 z_;})XC!C?5iDG~d_-?$T0!cCs36-JaQ9j(Xz?D6nYQgdgbtyVVJqpcj6N+IS24ThB ziUjLyo(3)T>1s=H8pWp>81wXhGBhv>?p z0Zr*Jc3~LMO^9r zjOSLSevd$_#S2+8(yFyw^#l!+AK0>sA`86w_#nt&YjZRotX!MVEI?0o&*jgN#>(Sb4!5=Ji4eB zti?#0dr|BR6o|u&Mv-LS*)D3IeDtr1eUGphhURB4j0P0Pdj^>xP+Y9Lr&~Sx0pCS| z$HVI6_3$SS#t{1WYAVm~k(bttIM37W{#|I%T}b88|6jM+wU*=LY`ea>OceH89o*=9tqYHl!F(n34}@S&dG=vZ=v9B12W%dBhn07#c^ya z{oFfb?|*JVg6iKjd8T-v+?){uHDQ+5ZVyi8*+h?0=)# z&ov-xb$<<=<-zgxX;c!*ij7M&$XS}qo5C*>wx9lp`qABg6Z8Sn4X(}sXaRWdwinsL z<--P>sTQs#-+=@%kI(ubZ#x=` zzJ%azFPGL;>)&RML&t54B5SYF$4Z{1I-vIu;q~>Rn1LoC-Dt0|rV#{dGZL(setupUi(this); - this->initForm(); - this->initMenu(); - this->show_video_all(); - QTimer::singleShot(1000, this, SLOT(play_video_all())); -} - -frmMain::~frmMain() -{ - delete ui; -} - -bool frmMain::eventFilter(QObject *watched, QEvent *event) -{ - if (event->type() == QEvent::MouseButtonDblClick) { - QLabel *widget = (QLabel *) watched; - if (!videoMax) { - videoMax = true; - hide_video_all(); - ui->gridLayout->addWidget(widget, 0, 0); - widget->setVisible(true); - } else { - videoMax = false; - show_video_all(); - } - - widget->setFocus(); - } else if (event->type() == QEvent::MouseButtonPress) { - if (qApp->mouseButtons() == Qt::RightButton) { - videoMenu->exec(QCursor::pos()); - } - } - - return QWidget::eventFilter(watched, event); -} - -void frmMain::initForm() -{ - //设置样式表 - QStringList qss; - qss.append("QFrame{border:2px solid #000000;}"); - qss.append("QLabel{font:75 25px;color:#F0F0F0;border:2px solid #AAAAAA;background:#000000;}"); - qss.append("QLabel:focus{border:2px solid #00BB9E;background:#555555;}"); - ui->frame->setStyleSheet(qss.join("")); - - videoMax = false; - videoCount = 16; - videoType = "1_16"; - - for (int i = 0; i < videoCount; i++) { - QLabel *widget = new QLabel; - widget->setObjectName(QString("video%1").arg(i + 1)); - widget->installEventFilter(this); - widget->setFocusPolicy(Qt::StrongFocus); - widget->setAlignment(Qt::AlignCenter); - - //二选一可以选择显示文字,也可以选择显示背景图片 - //widget->setText(QString("通道 %1").arg(i + 1)); - widget->setPixmap(QPixmap(":/bg_novideo.png")); - widgets.append(widget); - } -} - -void frmMain::initMenu() -{ - videoMenu = new QMenu(this); - videoMenu->addAction("截图当前视频", this, SLOT(snapshot_video_one())); - videoMenu->addAction("截图所有视频", this, SLOT(snapshot_video_all())); - videoMenu->addSeparator(); - - QMenu *menu4 = videoMenu->addMenu("切换到4画面"); - menu4->addAction("通道1-通道4", this, SLOT(show_video_4())); - menu4->addAction("通道5-通道8", this, SLOT(show_video_4())); - menu4->addAction("通道9-通道12", this, SLOT(show_video_4())); - menu4->addAction("通道13-通道16", this, SLOT(show_video_4())); - - QMenu *menu6 = videoMenu->addMenu("切换到6画面"); - menu6->addAction("通道1-通道6", this, SLOT(show_video_6())); - menu6->addAction("通道6-通道11", this, SLOT(show_video_6())); - menu6->addAction("通道11-通道16", this, SLOT(show_video_6())); - - QMenu *menu8 = videoMenu->addMenu("切换到8画面"); - menu8->addAction("通道1-通道8", this, SLOT(show_video_8())); - menu8->addAction("通道9-通道16", this, SLOT(show_video_8())); - - QMenu *menu9 = videoMenu->addMenu("切换到9画面"); - menu9->addAction("通道1-通道9", this, SLOT(show_video_9())); - menu9->addAction("通道8-通道16", this, SLOT(show_video_9())); - - videoMenu->addAction("切换到16画面", this, SLOT(show_video_16())); -} - -void frmMain::play_video_all() -{ - -} - -void frmMain::snapshot_video_one() -{ - -} - -void frmMain::snapshot_video_all() -{ - -} - -void frmMain::show_video_all() -{ - if (videoType == "1_4") { - change_video_4(0); - } else if (videoType == "5_8") { - change_video_4(4); - } else if (videoType == "9_12") { - change_video_4(8); - } else if (videoType == "13_16") { - change_video_4(12); - } else if (videoType == "1_6") { - change_video_6(0); - } else if (videoType == "6_11") { - change_video_6(5); - } else if (videoType == "11_16") { - change_video_6(10); - } else if (videoType == "1_8") { - change_video_8(0); - } else if (videoType == "9_16") { - change_video_8(8); - } else if (videoType == "1_9") { - change_video_9(0); - } else if (videoType == "8_16") { - change_video_9(7); - } else if (videoType == "1_16") { - change_video_16(0); - } -} - -void frmMain::show_video_4() -{ - videoMax = false; - QString videoType; - int index = 0; - - QAction *action = (QAction *)sender(); - QString name = action->text(); - - if (name == "通道1-通道4") { - index = 0; - videoType = "1_4"; - } else if (name == "通道5-通道8") { - index = 4; - videoType = "5_8"; - } else if (name == "通道9-通道12") { - index = 8; - videoType = "9_12"; - } else if (name == "通道13-通道16") { - index = 12; - videoType = "13_16"; - } - - if (this->videoType != videoType) { - this->videoType = videoType; - change_video_4(index); - } -} - -void frmMain::show_video_6() -{ - videoMax = false; - QString videoType; - int index = 0; - - QAction *action = (QAction *)sender(); - QString name = action->text(); - - if (name == "通道1-通道6") { - index = 0; - videoType = "1_6"; - } else if (name == "通道6-通道11") { - index = 5; - videoType = "6_11"; - } else if (name == "通道11-通道16") { - index = 10; - videoType = "11_16"; - } - - if (this->videoType != videoType) { - this->videoType = videoType; - change_video_6(index); - } -} - -void frmMain::show_video_8() -{ - videoMax = false; - QString videoType; - int index = 0; - - QAction *action = (QAction *)sender(); - QString name = action->text(); - - if (name == "通道1-通道8") { - index = 0; - videoType = "1_8"; - } else if (name == "通道9-通道16") { - index = 8; - videoType = "9_16"; - } - - if (this->videoType != videoType) { - this->videoType = videoType; - change_video_8(index); - } -} - -void frmMain::show_video_9() -{ - videoMax = false; - QString videoType; - int index = 0; - - QAction *action = (QAction *)sender(); - QString name = action->text(); - - if (name == "通道1-通道9") { - index = 0; - videoType = "1_9"; - } else if (name == "通道8-通道16") { - index = 7; - videoType = "8_16"; - } - - if (this->videoType != videoType) { - this->videoType = videoType; - change_video_9(index); - } -} - -void frmMain::show_video_16() -{ - videoMax = false; - QString videoType; - int index = 0; - videoType = "1_16"; - - if (this->videoType != videoType) { - this->videoType = videoType; - change_video_16(index); - } -} - -void frmMain::hide_video_all() -{ - for (int i = 0; i < videoCount; i++) { - ui->gridLayout->removeWidget(widgets.at(i)); - widgets.at(i)->setVisible(false); - } -} - -void frmMain::change_video(int index, int flag) -{ - int count = 0; - int row = 0; - int column = 0; - - for (int i = 0; i < videoCount; i++) { - if (i >= index) { - ui->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 frmMain::change_video_4(int index) -{ - hide_video_all(); - change_video(index, 2); -} - -void frmMain::change_video_6(int index) -{ - hide_video_all(); - if (index == 0) { - ui->gridLayout->addWidget(widgets.at(0), 0, 0, 2, 2); - ui->gridLayout->addWidget(widgets.at(1), 0, 2, 1, 1); - ui->gridLayout->addWidget(widgets.at(2), 1, 2, 1, 1); - ui->gridLayout->addWidget(widgets.at(3), 2, 2, 1, 1); - ui->gridLayout->addWidget(widgets.at(4), 2, 1, 1, 1); - ui->gridLayout->addWidget(widgets.at(5), 2, 0, 1, 1); - - for (int i = 0; i < 6; i++) { - widgets.at(i)->setVisible(true); - } - } else if (index == 5) { - ui->gridLayout->addWidget(widgets.at(5), 0, 0, 2, 2); - ui->gridLayout->addWidget(widgets.at(6), 0, 2, 1, 1); - ui->gridLayout->addWidget(widgets.at(7), 1, 2, 1, 1); - ui->gridLayout->addWidget(widgets.at(8), 2, 2, 1, 1); - ui->gridLayout->addWidget(widgets.at(9), 2, 1, 1, 1); - ui->gridLayout->addWidget(widgets.at(10), 2, 0, 1, 1); - - for (int i = 5; i < 11; i++) { - widgets.at(i)->setVisible(true); - } - } else if (index == 10) { - ui->gridLayout->addWidget(widgets.at(10), 0, 0, 2, 2); - ui->gridLayout->addWidget(widgets.at(11), 0, 2, 1, 1); - ui->gridLayout->addWidget(widgets.at(12), 1, 2, 1, 1); - ui->gridLayout->addWidget(widgets.at(13), 2, 2, 1, 1); - ui->gridLayout->addWidget(widgets.at(14), 2, 1, 1, 1); - ui->gridLayout->addWidget(widgets.at(15), 2, 0, 1, 1); - - for (int i = 10; i < 16; i++) { - widgets.at(i)->setVisible(true); - } - } -} - -void frmMain::change_video_8(int index) -{ - hide_video_all(); - if (index == 0) { - ui->gridLayout->addWidget(widgets.at(0), 0, 0, 3, 3); - ui->gridLayout->addWidget(widgets.at(1), 0, 3, 1, 1); - ui->gridLayout->addWidget(widgets.at(2), 1, 3, 1, 1); - ui->gridLayout->addWidget(widgets.at(3), 2, 3, 1, 1); - ui->gridLayout->addWidget(widgets.at(4), 3, 3, 1, 1); - ui->gridLayout->addWidget(widgets.at(5), 3, 2, 1, 1); - ui->gridLayout->addWidget(widgets.at(6), 3, 1, 1, 1); - ui->gridLayout->addWidget(widgets.at(7), 3, 0, 1, 1); - - for (int i = 0; i < 8; i++) { - widgets.at(i)->setVisible(true); - } - } else if (index == 8) { - ui->gridLayout->addWidget(widgets.at(8), 0, 0, 3, 3); - ui->gridLayout->addWidget(widgets.at(9), 0, 3, 1, 1); - ui->gridLayout->addWidget(widgets.at(10), 1, 3, 1, 1); - ui->gridLayout->addWidget(widgets.at(11), 2, 3, 1, 1); - ui->gridLayout->addWidget(widgets.at(12), 3, 3, 1, 1); - ui->gridLayout->addWidget(widgets.at(13), 3, 2, 1, 1); - ui->gridLayout->addWidget(widgets.at(14), 3, 1, 1, 1); - ui->gridLayout->addWidget(widgets.at(15), 3, 0, 1, 1); - - for (int i = 8; i < 16; i++) { - widgets.at(i)->setVisible(true); - } - } -} - -void frmMain::change_video_9(int index) -{ - hide_video_all(); - change_video(index, 3); -} - -void frmMain::change_video_16(int index) -{ - hide_video_all(); - change_video(index, 4); -} diff --git a/videopanel/frmmain.h b/videopanel/frmmain.h deleted file mode 100644 index 949adc7..0000000 --- a/videopanel/frmmain.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef FRMMAIN_H -#define FRMMAIN_H - -#include -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) -#include -#endif - -namespace Ui -{ -class frmMain; -} - -class frmMain : public QWidget -{ - Q_OBJECT - -public: - explicit frmMain(QWidget *parent = 0); - ~frmMain(); - -protected: - bool eventFilter(QObject *watched, QEvent *event); - -private: - Ui::frmMain *ui; - - bool videoMax; - int videoCount; - QString videoType; - QMenu *videoMenu; - QList widgets; - -private slots: - void initForm(); - void initMenu(); - -private slots: - void play_video_all(); - void snapshot_video_one(); - void snapshot_video_all(); - - void show_video_all(); - void show_video_4(); - void show_video_6(); - void show_video_8(); - void show_video_9(); - void show_video_16(); - - void hide_video_all(); - void change_video(int index, int flag); - void change_video_4(int index); - void change_video_6(int index); - void change_video_8(int index); - void change_video_9(int index); - void change_video_16(int index); -}; - -#endif // FRMMAIN_H diff --git a/videopanel/frmmain.ui b/videopanel/frmmain.ui deleted file mode 100644 index feac423..0000000 --- a/videopanel/frmmain.ui +++ /dev/null @@ -1,64 +0,0 @@ - - - frmMain - - - - 0 - 0 - 1000 - 750 - - - - Form - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 1 - - - 1 - - - 1 - - - 1 - - - - - 1 - - - - - - - - - - - diff --git a/videopanel/frmvideopanel.cpp b/videopanel/frmvideopanel.cpp new file mode 100644 index 0000000..fbe326f --- /dev/null +++ b/videopanel/frmvideopanel.cpp @@ -0,0 +1,13 @@ +#pragma execution_character_set("utf-8") +#include "frmvideopanel.h" +#include "ui_frmvideopanel.h" + +frmVideoPanel::frmVideoPanel(QWidget *parent) : QWidget(parent), ui(new Ui::frmVideoPanel) +{ + ui->setupUi(this); +} + +frmVideoPanel::~frmVideoPanel() +{ + delete ui; +} diff --git a/videopanel/frmvideopanel.h b/videopanel/frmvideopanel.h new file mode 100644 index 0000000..cb145cd --- /dev/null +++ b/videopanel/frmvideopanel.h @@ -0,0 +1,22 @@ +#ifndef FRMVIDEOPANEL_H +#define FRMVIDEOPANEL_H + +#include + +namespace Ui { +class frmVideoPanel; +} + +class frmVideoPanel : public QWidget +{ + Q_OBJECT + +public: + explicit frmVideoPanel(QWidget *parent = 0); + ~frmVideoPanel(); + +private: + Ui::frmVideoPanel *ui; +}; + +#endif // FRMVIDEOPANEL_H diff --git a/videopanel/frmvideopanel.ui b/videopanel/frmvideopanel.ui new file mode 100644 index 0000000..8e10325 --- /dev/null +++ b/videopanel/frmvideopanel.ui @@ -0,0 +1,32 @@ + + + frmVideoPanel + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + VideoPanel + QWidget +
videopanel.h
+ 1 +
+
+ + +
diff --git a/videopanel/main.cpp b/videopanel/main.cpp index 7bb71e4..bb45590 100644 --- a/videopanel/main.cpp +++ b/videopanel/main.cpp @@ -1,14 +1,13 @@ -#include "frmmain.h" -#include "qcoreapplication.h" +#pragma execution_character_set("utf-8") + +#include "frmvideopanel.h" +#include +#include int main(int argc, char *argv[]) { QApplication a(argc, argv); - - QFont font; - font.setFamily("MicroSoft Yahei"); - font.setPixelSize(12); - a.setFont(font); + a.setFont(QFont("Microsoft Yahei", 9)); #if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) #if _MSC_VER @@ -24,8 +23,10 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForLocale(codec); #endif - frmMain w; - w.showMaximized(); + frmVideoPanel w; + w.setWindowTitle("视频监控画面"); + w.resize(800, 600); + w.show(); return a.exec(); } diff --git a/videopanel/main.qrc b/videopanel/main.qrc deleted file mode 100644 index fdc0fea..0000000 --- a/videopanel/main.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - bg_novideo.png - - diff --git a/videopanel/videopanel.cpp b/videopanel/videopanel.cpp new file mode 100644 index 0000000..61f46fe --- /dev/null +++ b/videopanel/videopanel.cpp @@ -0,0 +1,570 @@ +#pragma execution_character_set("utf-8") + +#include "videopanel.h" +#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(); + this->show_video_all(); + QTimer::singleShot(1000, this, SLOT(play_video_all())); +} + +bool VideoPanel::eventFilter(QObject *watched, QEvent *event) +{ + if (event->type() == QEvent::MouseButtonDblClick) { + QLabel *widget = (QLabel *) watched; + if (!videoMax) { + videoMax = true; + hide_video_all(); + gridLayout->addWidget(widget, 0, 0); + widget->setVisible(true); + } else { + videoMax = false; + show_video_all(); + } + + widget->setFocus(); + } else if (event->type() == QEvent::MouseButtonPress) { + 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); + gridLayout->setMargin(0); + gridLayout->setObjectName("gridLayout"); + this->setLayout(gridLayout); +} + +void VideoPanel::initForm() +{ + //设置样式表 + QStringList qss; + qss.append("QFrame{border:2px solid #000000;}"); + qss.append("QLabel{font:75 25px;color:#F0F0F0;border:2px solid #AAAAAA;background:#000000;}"); + qss.append("QLabel:focus{border:2px solid #00BB9E;background:#555555;}"); + this->setStyleSheet(qss.join("")); + + videoMax = false; + videoCount = 64; + videoType = "1_16"; + + for (int i = 0; i < videoCount; i++) { + QLabel *widget = new QLabel; + widget->setObjectName(QString("video%1").arg(i + 1)); + widget->installEventFilter(this); + widget->setFocusPolicy(Qt::StrongFocus); + widget->setAlignment(Qt::AlignCenter); + + //二选一可以选择显示文字,也可以选择显示背景图片 + widget->setText(QString("通道 %1").arg(i + 1)); + //widget->setPixmap(QPixmap(":/bg_novideo.png")); + widgets.append(widget); + } +} + +void VideoPanel::initMenu() +{ + videoMenu = new QMenu(this); + + actionFull = new QAction("切换全屏模式", videoMenu); + connect(actionFull, SIGNAL(triggered(bool)), this, SLOT(full())); + actionPoll = new QAction("启动轮询视频", videoMenu); + connect(actionPoll, SIGNAL(triggered(bool)), this, SLOT(poll())); + + videoMenu->addAction(actionFull); + videoMenu->addAction(actionPoll); + videoMenu->addSeparator(); + + videoMenu->addAction("截图当前视频", this, SLOT(snapshot_video_one())); + videoMenu->addAction("截图所有视频", this, SLOT(snapshot_video_all())); + videoMenu->addSeparator(); + + QMenu *menu4 = videoMenu->addMenu("切换到4画面"); + menu4->addAction("通道1-通道4", this, SLOT(show_video_4())); + menu4->addAction("通道5-通道8", this, SLOT(show_video_4())); + menu4->addAction("通道9-通道12", this, SLOT(show_video_4())); + menu4->addAction("通道13-通道16", this, SLOT(show_video_4())); + + QMenu *menu6 = videoMenu->addMenu("切换到6画面"); + menu6->addAction("通道1-通道6", this, SLOT(show_video_6())); + menu6->addAction("通道6-通道11", this, SLOT(show_video_6())); + menu6->addAction("通道11-通道16", this, SLOT(show_video_6())); + + QMenu *menu8 = videoMenu->addMenu("切换到8画面"); + menu8->addAction("通道1-通道8", this, SLOT(show_video_8())); + menu8->addAction("通道9-通道16", this, SLOT(show_video_8())); + + QMenu *menu9 = videoMenu->addMenu("切换到9画面"); + menu9->addAction("通道1-通道9", this, SLOT(show_video_9())); + menu9->addAction("通道8-通道16", this, SLOT(show_video_9())); + + QMenu *menu13 = videoMenu->addMenu("切换到13画面"); + menu13->addAction("通道1-通道13", this, SLOT(show_video_13())); + menu13->addAction("通道4-通道16", this, SLOT(show_video_13())); + + videoMenu->addAction("切换到16画面", this, SLOT(show_video_16())); + videoMenu->addAction("切换到25画面", this, SLOT(show_video_25())); + videoMenu->addAction("切换到36画面", this, SLOT(show_video_36())); + videoMenu->addAction("切换到64画面", this, SLOT(show_video_64())); +} + +void VideoPanel::full() +{ + if (actionFull->text() == "切换全屏模式") { + emit fullScreen(true); + actionFull->setText("切换正常模式"); + } else { + emit fullScreen(false); + actionFull->setText("切换全屏模式"); + } + + //执行全屏处理 +} + +void VideoPanel::poll() +{ + if (actionPoll->text() == "启动轮询视频") { + actionPoll->setText("停止轮询视频"); + } else { + actionPoll->setText("启动轮询视频"); + } + + //执行轮询处理 +} + +void VideoPanel::play_video_all() +{ + +} + +void VideoPanel::snapshot_video_one() +{ + +} + +void VideoPanel::snapshot_video_all() +{ + +} + +void VideoPanel::show_video_all() +{ + if (videoType == "1_4") { + change_video_4(0); + } else if (videoType == "5_8") { + change_video_4(4); + } else if (videoType == "9_12") { + change_video_4(8); + } else if (videoType == "13_16") { + change_video_4(12); + } else if (videoType == "1_6") { + change_video_6(0); + } else if (videoType == "6_11") { + change_video_6(5); + } else if (videoType == "11_16") { + change_video_6(10); + } else if (videoType == "1_8") { + change_video_8(0); + } else if (videoType == "9_16") { + change_video_8(8); + } else if (videoType == "1_9") { + change_video_9(0); + } else if (videoType == "8_16") { + change_video_9(7); + } else if (videoType == "1_13") { + change_video_13(0); + } else if (videoType == "4_16") { + change_video_13(3); + } else if (videoType == "1_16") { + change_video_16(0); + } else if (videoType == "1_25") { + change_video_25(0); + } else if (videoType == "1_36") { + change_video_36(0); + } else if (videoType == "1_64") { + change_video_64(0); + } +} + +void VideoPanel::show_video_4() +{ + videoMax = false; + QString videoType; + int index = 0; + + QAction *action = (QAction *)sender(); + QString name = action->text(); + + if (name == "通道1-通道4") { + index = 0; + videoType = "1_4"; + } else if (name == "通道5-通道8") { + index = 4; + videoType = "5_8"; + } else if (name == "通道9-通道12") { + index = 8; + videoType = "9_12"; + } else if (name == "通道13-通道16") { + index = 12; + videoType = "13_16"; + } + + if (this->videoType != videoType) { + this->videoType = videoType; + change_video_4(index); + } +} + +void VideoPanel::show_video_6() +{ + videoMax = false; + QString videoType; + int index = 0; + + QAction *action = (QAction *)sender(); + QString name = action->text(); + + if (name == "通道1-通道6") { + index = 0; + videoType = "1_6"; + } else if (name == "通道6-通道11") { + index = 5; + videoType = "6_11"; + } else if (name == "通道11-通道16") { + index = 10; + videoType = "11_16"; + } + + if (this->videoType != videoType) { + this->videoType = videoType; + change_video_6(index); + } +} + +void VideoPanel::show_video_8() +{ + videoMax = false; + QString videoType; + int index = 0; + + QAction *action = (QAction *)sender(); + QString name = action->text(); + + if (name == "通道1-通道8") { + index = 0; + videoType = "1_8"; + } else if (name == "通道9-通道16") { + index = 8; + videoType = "9_16"; + } + + if (this->videoType != videoType) { + this->videoType = videoType; + change_video_8(index); + } +} + +void VideoPanel::show_video_9() +{ + videoMax = false; + QString videoType; + int index = 0; + + QAction *action = (QAction *)sender(); + QString name = action->text(); + + if (name == "通道1-通道9") { + index = 0; + videoType = "1_9"; + } else if (name == "通道8-通道16") { + index = 7; + videoType = "8_16"; + } + + if (this->videoType != videoType) { + this->videoType = videoType; + change_video_9(index); + } +} + +void VideoPanel::show_video_13() +{ + QString videoType; + int index = 0; + + QAction *action = (QAction *)sender(); + QString name = action->text(); + + if (name == "通道1-通道13") { + index = 0; + videoType = "1_13"; + } else if (name == "通道4-通道16") { + index = 3; + videoType = "4_16"; + } + + if (this->videoType != videoType) { + this->videoType = videoType; + change_video_13(index); + } +} + +void VideoPanel::show_video_16() +{ + videoMax = false; + QString videoType; + int index = 0; + videoType = "1_16"; + + if (this->videoType != videoType) { + this->videoType = videoType; + change_video_16(index); + } +} + +void VideoPanel::show_video_25() +{ + videoMax = false; + QString videoType; + int index = 0; + videoType = "1_25"; + + if (this->videoType != videoType) { + this->videoType = videoType; + change_video_25(index); + } +} + +void VideoPanel::show_video_36() +{ + videoMax = false; + QString videoType; + int index = 0; + videoType = "1_36"; + + if (this->videoType != videoType) { + this->videoType = videoType; + change_video_36(index); + } +} + +void VideoPanel::show_video_64() +{ + videoMax = false; + QString videoType; + int index = 0; + videoType = "1_64"; + + if (this->videoType != videoType) { + this->videoType = videoType; + change_video_64(index); + } +} + +void VideoPanel::hide_video_all() +{ + for (int i = 0; i < videoCount; i++) { + gridLayout->removeWidget(widgets.at(i)); + widgets.at(i)->setVisible(false); + } +} + +void VideoPanel::change_video(int index, int flag) +{ + int count = 0; + int row = 0; + int column = 0; + + for (int i = 0; i < videoCount; i++) { + if (i >= index) { + 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 VideoPanel::change_video_4(int index) +{ + hide_video_all(); + change_video(index, 2); +} + +void VideoPanel::change_video_6(int index) +{ + hide_video_all(); + if (index == 0) { + gridLayout->addWidget(widgets.at(0), 0, 0, 2, 2); + gridLayout->addWidget(widgets.at(1), 0, 2, 1, 1); + gridLayout->addWidget(widgets.at(2), 1, 2, 1, 1); + gridLayout->addWidget(widgets.at(3), 2, 2, 1, 1); + gridLayout->addWidget(widgets.at(4), 2, 1, 1, 1); + gridLayout->addWidget(widgets.at(5), 2, 0, 1, 1); + + for (int i = 0; i < 6; i++) { + widgets.at(i)->setVisible(true); + } + } else if (index == 5) { + gridLayout->addWidget(widgets.at(5), 0, 0, 2, 2); + gridLayout->addWidget(widgets.at(6), 0, 2, 1, 1); + gridLayout->addWidget(widgets.at(7), 1, 2, 1, 1); + gridLayout->addWidget(widgets.at(8), 2, 2, 1, 1); + gridLayout->addWidget(widgets.at(9), 2, 1, 1, 1); + gridLayout->addWidget(widgets.at(10), 2, 0, 1, 1); + + for (int i = 5; i < 11; i++) { + widgets.at(i)->setVisible(true); + } + } else if (index == 10) { + gridLayout->addWidget(widgets.at(10), 0, 0, 2, 2); + gridLayout->addWidget(widgets.at(11), 0, 2, 1, 1); + gridLayout->addWidget(widgets.at(12), 1, 2, 1, 1); + gridLayout->addWidget(widgets.at(13), 2, 2, 1, 1); + gridLayout->addWidget(widgets.at(14), 2, 1, 1, 1); + gridLayout->addWidget(widgets.at(15), 2, 0, 1, 1); + + for (int i = 10; i < 16; i++) { + widgets.at(i)->setVisible(true); + } + } +} + +void VideoPanel::change_video_8(int index) +{ + hide_video_all(); + if (index == 0) { + gridLayout->addWidget(widgets.at(0), 0, 0, 3, 3); + gridLayout->addWidget(widgets.at(1), 0, 3, 1, 1); + gridLayout->addWidget(widgets.at(2), 1, 3, 1, 1); + gridLayout->addWidget(widgets.at(3), 2, 3, 1, 1); + gridLayout->addWidget(widgets.at(4), 3, 3, 1, 1); + gridLayout->addWidget(widgets.at(5), 3, 2, 1, 1); + gridLayout->addWidget(widgets.at(6), 3, 1, 1, 1); + gridLayout->addWidget(widgets.at(7), 3, 0, 1, 1); + + for (int i = 0; i < 8; i++) { + widgets.at(i)->setVisible(true); + } + } else if (index == 8) { + gridLayout->addWidget(widgets.at(8), 0, 0, 3, 3); + gridLayout->addWidget(widgets.at(9), 0, 3, 1, 1); + gridLayout->addWidget(widgets.at(10), 1, 3, 1, 1); + gridLayout->addWidget(widgets.at(11), 2, 3, 1, 1); + gridLayout->addWidget(widgets.at(12), 3, 3, 1, 1); + gridLayout->addWidget(widgets.at(13), 3, 2, 1, 1); + gridLayout->addWidget(widgets.at(14), 3, 1, 1, 1); + gridLayout->addWidget(widgets.at(15), 3, 0, 1, 1); + + for (int i = 8; i < 16; i++) { + widgets.at(i)->setVisible(true); + } + } +} + +void VideoPanel::change_video_9(int index) +{ + hide_video_all(); + change_video(index, 3); +} + +void VideoPanel::change_video_13(int index) +{ + hide_video_all(); + if (index == 0) { + gridLayout->addWidget(widgets.at(0), 0, 0, 1, 1); + gridLayout->addWidget(widgets.at(1), 0, 1, 1, 1); + gridLayout->addWidget(widgets.at(2), 0, 2, 1, 1); + gridLayout->addWidget(widgets.at(3), 0, 3, 1, 1); + gridLayout->addWidget(widgets.at(4), 1, 0, 1, 1); + gridLayout->addWidget(widgets.at(5), 2, 0, 1, 1); + gridLayout->addWidget(widgets.at(6), 1, 1, 2, 2); + gridLayout->addWidget(widgets.at(7), 1, 3, 1, 1); + gridLayout->addWidget(widgets.at(8), 2, 3, 1, 1); + gridLayout->addWidget(widgets.at(9), 3, 0, 1, 1); + gridLayout->addWidget(widgets.at(10), 3, 1, 1, 1); + gridLayout->addWidget(widgets.at(11), 3, 2, 1, 1); + gridLayout->addWidget(widgets.at(12), 3, 3, 1, 1); + + for (int i = 0; i < 13; i++) { + widgets.at(i)->setVisible(true); + } + } else if (index == 3) { + gridLayout->addWidget(widgets.at(3), 0, 0, 1, 1); + gridLayout->addWidget(widgets.at(4), 0, 1, 1, 1); + gridLayout->addWidget(widgets.at(5), 0, 2, 1, 1); + gridLayout->addWidget(widgets.at(6), 0, 3, 1, 1); + gridLayout->addWidget(widgets.at(7), 1, 0, 1, 1); + gridLayout->addWidget(widgets.at(8), 2, 0, 1, 1); + gridLayout->addWidget(widgets.at(9), 1, 1, 2, 2); + gridLayout->addWidget(widgets.at(10), 1, 3, 1, 1); + gridLayout->addWidget(widgets.at(11), 2, 3, 1, 1); + gridLayout->addWidget(widgets.at(12), 3, 0, 1, 1); + gridLayout->addWidget(widgets.at(13), 3, 1, 1, 1); + gridLayout->addWidget(widgets.at(14), 3, 2, 1, 1); + gridLayout->addWidget(widgets.at(15), 3, 3, 1, 1); + + for (int i = 3; i < 16; i++) { + widgets.at(i)->setVisible(true); + } + } +} + +void VideoPanel::change_video_16(int index) +{ + hide_video_all(); + change_video(index, 4); +} + +void VideoPanel::change_video_25(int index) +{ + hide_video_all(); + change_video(index, 5); +} + +void VideoPanel::change_video_36(int index) +{ + hide_video_all(); + change_video(index, 6); +} + +void VideoPanel::change_video_64(int index) +{ + hide_video_all(); + change_video(index, 8); +} diff --git a/videopanel/videopanel.h b/videopanel/videopanel.h new file mode 100644 index 0000000..3dd335e --- /dev/null +++ b/videopanel/videopanel.h @@ -0,0 +1,89 @@ +#ifndef VIDEOPANEL_H +#define VIDEOPANEL_H + +/** + * 视频监控画面控件 整理:feiyangqingyun(QQ:517216493) 2019-4-11 + * 1:目前颜色都写死在样式表,可自行更改或者拓展属性设置 + */ + +#include + +class QMenu; +class QLabel; +class QGridLayout; + +#ifdef quc +#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) +#include +#else +#include +#endif + +class QDESIGNER_WIDGET_EXPORT VideoPanel : public QWidget +#else +class VideoPanel : public QWidget +#endif + +{ + Q_OBJECT + +public: + explicit VideoPanel(QWidget *parent = 0); + +protected: + bool eventFilter(QObject *watched, QEvent *event); + +private: + QGridLayout *gridLayout; //表格布局存放视频标签 + bool videoMax; //是否最大化 + int videoCount; //视频通道个数 + QString videoType; //当前画面类型 + QMenu *videoMenu; //右键菜单 + QAction *actionFull; //全屏动作 + QAction *actionPoll; //轮询动作 + QList widgets; //视频标签集合 + +public: + QSize sizeHint() const; + QSize minimumSizeHint() const; + +private slots: + void initControl(); + void initForm(); + void initMenu(); + void full(); + void poll(); + +private slots: + void play_video_all(); + void snapshot_video_one(); + void snapshot_video_all(); + + void show_video_all(); + void show_video_4(); + void show_video_6(); + void show_video_8(); + void show_video_9(); + void show_video_13(); + void show_video_16(); + void show_video_25(); + void show_video_36(); + void show_video_64(); + + void hide_video_all(); + void change_video(int index, int flag); + void change_video_4(int index); + void change_video_6(int index); + void change_video_8(int index); + void change_video_9(int index); + void change_video_13(int index); + void change_video_16(int index); + void change_video_25(int index); + void change_video_36(int index); + void change_video_64(int index); + +signals: + void fullScreen(bool full); +}; + +#endif // VIDEOPANEL_H diff --git a/videopanel/videopanel.pro b/videopanel/videopanel.pro index e5fa2e6..4d59fff 100644 --- a/videopanel/videopanel.pro +++ b/videopanel/videopanel.pro @@ -1,6 +1,6 @@ #------------------------------------------------- # -# Project created by QtCreator 2016-09-29T09:37:26 +# Project created by QtCreator 2017-01-05T22:11:54 # #------------------------------------------------- @@ -8,17 +8,16 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -TARGET = videopanel -TEMPLATE = app -MOC_DIR = temp/moc -RCC_DIR = temp/rcc -UI_DIR = temp/ui -OBJECTS_DIR = temp/obj -DESTDIR = bin +TARGET = videopanel +TEMPLATE = app +DESTDIR = $$PWD/../bin +CONFIG += warn_off -SOURCES += main.cpp -SOURCES += frmmain.cpp -HEADERS += frmmain.h -FORMS += frmmain.ui -RESOURCES += main.qrc -CONFIG += warn_off +SOURCES += main.cpp +SOURCES += frmvideopanel.cpp +SOURCES += videopanel.cpp + +HEADERS += frmvideopanel.h +HEADERS += videopanel.h + +FORMS += frmvideopanel.ui