diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 289d0f3..b6ef136 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,7 @@ qt_add_executable(VideoClient commandwidget.h commandwidget.cpp commandwidget.ui streamaddrsettingsdlg.h streamaddrsettingsdlg.cpp streamaddrsettingsdlg.ui videoControl.h videoControl.ui videoControl.cpp + wprogressbar.h wprogressbar.cpp ) qt6_add_resources(VideoClient "resources" diff --git a/src/commandwidget.cpp b/src/commandwidget.cpp index df0f79b..3bd5e7a 100644 --- a/src/commandwidget.cpp +++ b/src/commandwidget.cpp @@ -5,14 +5,11 @@ CommandWidget::CommandWidget(QWidget *parent) : QWidget(parent), ui(new Ui::CommandWidget) { ui->setupUi(this); - ui->stopConnectionToolBtn->setDisabled(true); - ui->settingToolBtn->setIcon(QIcon(":/images/settings.png")); - ui->settingToolBtn->setText("通信设置"); - ui->settingToolBtn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); udpSocket = new QUdpSocket(this); - connect(&settingDlg, &CommunicationSettingDlg::sendErrorMessage, this, - &CommandWidget::receiveMessageSlots); + + ui->videoLayout1TBtn->setIcon(QIcon(":/images/videolayout1.png")); + ui->videoLayout4TBtn->setIcon(QIcon(":/images/videolayout4.png")); } CommandWidget::~CommandWidget() { @@ -20,58 +17,63 @@ CommandWidget::~CommandWidget() { if (udpSocket) udpSocket->deleteLater(); } -void CommandWidget::on_settingToolBtn_clicked() { - settingDlg.exec(); -} - // 连接 void CommandWidget::on_startConnectionToolBtn_clicked() { ui->startConnectionToolBtn->setDisabled(true); - if (!g_networkSettingInfo) return; - int dataSourceType = g_networkSettingInfo->value("DataSource").toInt(); - QString groupName = ""; - switch (dataSourceType) { - case 0: - groupName = "LLink"; - break; - case 1: - groupName = "SATCOM1"; - break; - case 2: - groupName = "SATCOM2"; - break; - default: - break; - } + if (ui->startConnectionToolBtn->text() == "连接") { + if (!g_networkSettingInfo) return; + int dataSourceType = g_networkSettingInfo->value("DataSource").toInt(); + QString groupName = ""; + switch (dataSourceType) { + case 0: + groupName = "LLink"; + break; + case 1: + groupName = "SATCOM1"; + break; + case 2: + groupName = "SATCOM2"; + break; + default: + break; + } - m_remoteIP = - g_networkSettingInfo->value(groupName + "/remoteIP").toString(); - m_remotePort = - g_networkSettingInfo->value(groupName + "/remotePort").toInt(); - int localPort = - g_networkSettingInfo->value(groupName + "/localPort").toInt(); - QString localIP = - g_networkSettingInfo->value(groupName + "/localIP").toString(); + m_remoteIP = + g_networkSettingInfo->value(groupName + "/remoteIP").toString(); + m_remotePort = + g_networkSettingInfo->value(groupName + "/remotePort").toInt(); + int localPort = + g_networkSettingInfo->value(groupName + "/localPort").toInt(); + QString localIP = + g_networkSettingInfo->value(groupName + "/localIP").toString(); - if (dataSourceType == 0) { // 组播 - emit startConnectionSignal(m_remoteIP, m_remotePort); - } else { // 单播 - emit startConnectionSignal(localIP, localPort); - } - - ui->stopConnectionToolBtn->setDisabled(false); -} + if (dataSourceType == 0) { // 组播 + emit startConnectionSignal(m_remoteIP, m_remotePort); + } else { // 单播 + emit startConnectionSignal(localIP, localPort); + } -// 断开 -void CommandWidget::on_stopConnectionToolBtn_clicked() { - ui->stopConnectionToolBtn->setDisabled(true); - - emit stopConnectionSignal(); + ui->startConnectionToolBtn->setText("断开"); + } else { + emit stopConnectionSignal(); + ui->startConnectionToolBtn->setText("连接"); + } - // ui->stopConnectionToolBtn->setDisabled(false); ui->startConnectionToolBtn->setDisabled(false); } void CommandWidget::receiveMessageSlots(QString message, int type) { emit sendErrorMessage(message, type); } + +void CommandWidget::on_videoLayout1TBtn_clicked() { + ui->videoLayout1TBtn->setDisabled(true); + emit changeVideoLayout(0); + ui->videoLayout1TBtn->setDisabled(false); +} + +void CommandWidget::on_videoLayout4TBtn_clicked() { + ui->videoLayout4TBtn->setDisabled(true); + emit changeVideoLayout(1); + ui->videoLayout4TBtn->setDisabled(false); +} diff --git a/src/commandwidget.h b/src/commandwidget.h index c85233a..dc87aa8 100644 --- a/src/commandwidget.h +++ b/src/commandwidget.h @@ -4,8 +4,7 @@ #include #include -#include "communicationsettingdlg.h" - +#include "global.h" namespace Ui { class CommandWidget; } @@ -22,19 +21,20 @@ signals: void startConnectionSignal(QString ip, int port); void stopConnectionSignal(); void sendErrorMessage(QString message, int type); + void changeVideoLayout(int index); private slots: - void on_settingToolBtn_clicked(); void on_startConnectionToolBtn_clicked(); - void on_stopConnectionToolBtn_clicked(); - void receiveMessageSlots(QString message, int type); + void on_videoLayout1TBtn_clicked(); + + void on_videoLayout4TBtn_clicked(); + private: Ui::CommandWidget *ui; - CommunicationSettingDlg settingDlg; QString m_remoteIP; int m_remotePort; }; diff --git a/src/commandwidget.ui b/src/commandwidget.ui index b9161f4..bef71f7 100644 --- a/src/commandwidget.ui +++ b/src/commandwidget.ui @@ -13,40 +13,24 @@ Form - + + + 6 + + + 6 + + + 6 + + + 6 + - - - - 通信设置 - - - - res/settings.pngres/settings.png - - - - 32 - 32 - - - - - - - - 连接 - - - - - - - 断开 - - - + + 14 + @@ -166,8 +150,61 @@ + + + + 连接 + + + + + + + + + + ... + + + + + + + ... + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 01b4d8a..6338b60 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -55,6 +55,7 @@ MainWindow::MainWindow(QWidget *parent) initSignalConnection(); initNotifyManager(); initNotifyMessageConnection(); + initChangeVideoLayoutConnection(); setSavedVideoDir(); // ui->stackedWidget->setCurrentIndex(1); @@ -99,6 +100,13 @@ void MainWindow::initNotifyMessageConnection() { &MainWindow::showMessageSlots); } +void MainWindow::initChangeVideoLayoutConnection() { + connect(ui->commandWidget, &CommandWidget::changeVideoLayout, this, + [=](int index) { + ui->stackedWidget->setCurrentIndex(index); + }); +} + void MainWindow::initNotifyManager() { m_notifyManager = new NotifyManager(this, this); m_notifyManager->setMaxCount(5); @@ -266,7 +274,4 @@ void MainWindow::showStreamSettingsDlgSlot() { streamAddrSettingsDlg.exec(); } -void MainWindow::changeVideoLayout(int index) -{ - -} +void MainWindow::changeVideoLayout(int index) {} diff --git a/src/mainwindow.h b/src/mainwindow.h index 8743a46..e023b16 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -50,6 +50,7 @@ signals: private: void initSignalConnection(); void initNotifyMessageConnection(); + void initChangeVideoLayoutConnection(); void initNotifyManager(); void showMessageSlots(QString message, int type); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 365c6a3..112c626 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -14,13 +14,31 @@ MainWindow - + + + 4 + + + 2 + + + 2 + + + 2 + + + 2 + - + + + 4 + - 1 + 0 @@ -80,7 +98,10 @@ - + + + 4 + 2 @@ -94,107 +115,61 @@ 2 - - - 14 + + + 4 - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - + 00:00:00 - - - - - - - 854 - 0 - - - - 24 - - - false + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter - + + + + 00:00:00 - - + + Qt::Orientation::Horizontal - 40 - 20 + 37 + 17 - - - - - - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - @@ -234,6 +209,12 @@
videoControl.h
1 + + WProgressBar + QWidget +
wprogressbar.h
+ 1 +
diff --git a/src/resources/images/videolayout1.png b/src/resources/images/videolayout1.png index 5b023c7..02fa8f3 100644 Binary files a/src/resources/images/videolayout1.png and b/src/resources/images/videolayout1.png differ diff --git a/src/resources/images/videolayout4.png b/src/resources/images/videolayout4.png index 0553213..f77afbd 100644 Binary files a/src/resources/images/videolayout4.png and b/src/resources/images/videolayout4.png differ diff --git a/src/streamaddrsettingsdlg.ui b/src/streamaddrsettingsdlg.ui index 060c8f2..0526a55 100644 --- a/src/streamaddrsettingsdlg.ui +++ b/src/streamaddrsettingsdlg.ui @@ -88,7 +88,7 @@ 4 - + 4 diff --git a/src/videoControl.cpp b/src/videoControl.cpp index 02bc546..ff1c228 100644 --- a/src/videoControl.cpp +++ b/src/videoControl.cpp @@ -1,37 +1,33 @@ #include "videoControl.h" + #include "ui_videoControl.h" -VideoControl::VideoControl(QWidget *parent) : - QWidget(parent), - ui(new Ui::VideoControl) -{ +VideoControl::VideoControl(QWidget *parent) + : QWidget(parent), ui(new Ui::VideoControl) { ui->setupUi(this); // 其他初始化代码... - ui->pbPlayer->setIcon(QIcon(":/images/playMedio.png")); - ui->pbPlayer->setIconSize(QSize(56,56)); - ui->pbPlayer->setFixedSize(64, 64); + ui->pbPlayer->setIconSize(QSize(32, 32)); + ui->pbPlayer->setFixedSize(40, 40); ui->pbPlayer->setObjectName("medio"); - // ui->pbPlayer->set + // ui->pbPlayer->set ui->pbStop->setIcon(QIcon(":/images/stop.png")); - ui->pbStop->setIconSize(QSize(42,42)); - ui->pbStop->setFixedSize(50, 50); + ui->pbStop->setIconSize(QSize(24, 24)); + ui->pbStop->setFixedSize(32, 32); ui->pbStop->setObjectName("medio"); ui->pbFast->setIcon(QIcon(":/images/playFast.png")); - ui->pbFast->setIconSize(QSize(42,42)); - ui->pbFast->setFixedSize(50, 50); + ui->pbFast->setIconSize(QSize(24, 24)); + ui->pbFast->setFixedSize(32, 32); ui->pbFast->setObjectName("medio"); - ui->pbSlow->setIcon(QIcon(":/images/playSlow.png")); - ui->pbSlow->setIconSize(QSize(42,42)); - ui->pbSlow->setFixedSize(50, 50); + ui->pbSlow->setIconSize(QSize(24, 24)); + ui->pbSlow->setFixedSize(32, 32); ui->pbSlow->setObjectName("medio"); } -VideoControl::~VideoControl() -{ +VideoControl::~VideoControl() { delete ui; } diff --git a/src/videoControl.ui b/src/videoControl.ui index 710f1e6..e0eb844 100644 --- a/src/videoControl.ui +++ b/src/videoControl.ui @@ -6,18 +6,30 @@ 0 0 - 713 - 91 + 450 + 53 Form - + + + 2 + + + 2 + + + 2 + + + 2 + - Qt::Horizontal + Qt::Orientation::Horizontal @@ -28,65 +40,49 @@ - - - - - - 6 - - - QLayout::SetDefaultConstraint - - - - - - - - false - - - - - - - - - - false - - - - - - - - - - false - - - - - - - - - - false - - - - - - + + + + + + false + + + + + + + + + + false + + + + + + + + + + false + + + + + + + + + + false + - Qt::Horizontal + Qt::Orientation::Horizontal diff --git a/src/wprogressbar.cpp b/src/wprogressbar.cpp new file mode 100644 index 0000000..01b72b4 --- /dev/null +++ b/src/wprogressbar.cpp @@ -0,0 +1,86 @@ +#include "WProgressBar.h" + +WProgressBar::WProgressBar(QWidget *parent) : QWidget(parent) { + this->setWindowFlags(Qt::FramelessWindowHint); // 隐藏窗口 + this->setAttribute(Qt::WA_TranslucentBackground, true); // 窗口透明 +} + +WProgressBar::~WProgressBar() {} + +double WProgressBar::getPos() { + return m_pos; +} + +void WProgressBar::slotSetValue(double pos) { + m_pos = pos; + update(); +} + +void WProgressBar::mousePressEvent(QMouseEvent *ev) { + // double pos = (double)ev->pos().x() / (double)width(); + // if (pos >= 1) + // pos = 1; + + // if (pos <= 0) + // pos = 0; + + // m_pos = pos; + // update(); + // qDebug() << "seek pos = " << pos; + // emit sigCustomSliderValueChanged(pos); +} + +void WProgressBar::mouseMoveEvent(QMouseEvent *ev) { + double pos = (double)ev->pos().x() / (double)width(); + if (pos >= 1) pos = 1; + + if (pos <= 0) pos = 0; + + m_pos = pos; + update(); +} + +void WProgressBar::mouseReleaseEvent(QMouseEvent *ev) { + double pos = (double)ev->pos().x() / (double)width(); + emit sigCustomSliderValueChanged(pos); +} + +void WProgressBar::paintEvent(QPaintEvent *e) { + QWidget::paintEvent(e); + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + // 绘制底图矩形 + QBrush brush; + brush.setColor(QColor(233, 233, 233)); + brush.setStyle(Qt::SolidPattern); + painter.setBrush(brush); + painter.drawRoundedRect(this->rect(), 8, 8); + + // 绘制播放进度 + QLinearGradient radial; + + radial.setStart(0, 0); + radial.setFinalStop(0, 1); + + // 设置起始点颜色,0表示起始 + radial.setColorAt(0, QColor("#87CEFA")); + + // 设置终点颜色 1表示终点 + radial.setColorAt(1, QColor("#1E90FF")); + + // 设置延展方式 + radial.setSpread(QGradient::PadSpread); + + QPen pen(QBrush("#1E90FF"), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + painter.setPen(pen); + + // 设置画刷 + painter.setBrush(radial); + + QRect rect = this->rect(); + rect.setWidth(rect.width() * m_pos); + + // 画矩形 + painter.drawRoundedRect(rect, 8, 8); +} diff --git a/src/wprogressbar.h b/src/wprogressbar.h new file mode 100644 index 0000000..bb036fb --- /dev/null +++ b/src/wprogressbar.h @@ -0,0 +1,40 @@ +#ifndef WPROGRESSBAR_H +#define WPROGRESSBAR_H + +#include +#include +#include +#include +#include +#include +#include + +class WProgressBar : public QWidget { + Q_OBJECT +public: + WProgressBar(QWidget *parent = nullptr); + ~WProgressBar(); + +signals: + void sigCustomSliderValueChanged( + double pos); // 自定义的鼠标单击信号,用于捕获并处理 + +public: + // 获取pos + double getPos(); + +public slots: + // 设置0~1 + void slotSetValue(double pos); + +protected: + void mousePressEvent(QMouseEvent *ev); + void mouseMoveEvent(QMouseEvent *ev); + void mouseReleaseEvent(QMouseEvent *ev); + void paintEvent(QPaintEvent *); + +private: + double m_pos = 0; +}; + +#endif // WPROGRESSBAR_H