fix: 布局调整

chen^2
cbwu
parent 01c4ad2a20
commit 1d4c950828

@ -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"

@ -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);
}

@ -4,8 +4,7 @@
#include <QUdpSocket>
#include <QWidget>
#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;
};

@ -13,40 +13,24 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QToolButton" name="settingToolBtn">
<property name="text">
<string>通信设置</string>
</property>
<property name="icon">
<iconset>
<normaloff>res/settings.png</normaloff>res/settings.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="startConnectionToolBtn">
<property name="text">
<string>连接</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="stopConnectionToolBtn">
<property name="text">
<string>断开</string>
</property>
</widget>
</item>
<property name="spacing">
<number>14</number>
</property>
<item row="1" column="0">
<widget class="QPushButton" name="pushButton">
<property name="text">
@ -166,8 +150,61 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QToolButton" name="startConnectionToolBtn">
<property name="text">
<string>连接</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="videoLayout1TBtn">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="videoLayout4TBtn">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>

@ -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) {}

@ -50,6 +50,7 @@ signals:
private:
void initSignalConnection();
void initNotifyMessageConnection();
void initChangeVideoLayoutConnection();
void initNotifyManager();
void showMessageSlots(QString message, int type);

@ -14,13 +14,31 @@
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout_6" stretch="9,2">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="10,2">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout" stretch="15,1,1">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>4</number>
</property>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="page_3">
<layout class="QHBoxLayout" name="horizontalLayout_7">
@ -80,7 +98,10 @@
</item>
<item>
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
@ -94,107 +115,61 @@
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0,0">
<property name="spacing">
<number>14</number>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,10,1">
<property name="verticalSpacing">
<number>4</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>00:00:00</string>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="minimumSize">
<size>
<width>854</width>
<height>0</height>
</size>
</property>
<property name="value">
<number>24</number>
</property>
<property name="textVisible">
<bool>false</bool>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<item row="0" column="1">
<widget class="WProgressBar" name="widget_2" native="true"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>00:00:00</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<item row="1" column="0">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
<width>37</width>
<height>17</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="1,10,1">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<item row="1" column="1">
<widget class="VideoControl" name="widget" native="true"/>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
@ -234,6 +209,12 @@
<header>videoControl.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>WProgressBar</class>
<extends>QWidget</extends>
<header>wprogressbar.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 522 B

After

Width:  |  Height:  |  Size: 511 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 801 B

After

Width:  |  Height:  |  Size: 820 B

@ -88,7 +88,7 @@
<number>4</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout" columnstretch="1,4,1,4,0">
<layout class="QGridLayout" name="gridLayout" columnstretch="1,4,1,4">
<property name="topMargin">
<number>4</number>
</property>

@ -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;
}

@ -6,18 +6,30 @@
<rect>
<x>0</x>
<y>0</y>
<width>713</width>
<height>91</height>
<width>450</width>
<height>53</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,5,1">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@ -28,65 +40,49 @@
</spacer>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0">
<property name="spacing">
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QPushButton" name="pbSlow">
<property name="text">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbPlayer">
<property name="text">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbStop">
<property name="text">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbFast">
<property name="text">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
<widget class="QPushButton" name="pbSlow">
<property name="text">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbPlayer">
<property name="text">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbStop">
<property name="text">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbFast">
<property name="text">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>

@ -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);
}

@ -0,0 +1,40 @@
#ifndef WPROGRESSBAR_H
#define WPROGRESSBAR_H
#include <QDebug>
#include <QHBoxLayout>
#include <QLabel>
#include <QMouseEvent>
#include <QPainter>
#include <QShowEvent>
#include <QWidget>
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
Loading…
Cancel
Save