zhuizhu пре 9 месеци
родитељ
комит
e3c35379ae

+ 1 - 2
AvRecorder/ui/audio_render.cpp

@@ -4,8 +4,7 @@
 
 AudioRender::AudioRender(QLabel* parent)
     : QLabel(parent)
-{
-}
+{}
 void AudioRender::setLevel(float volume)
 {
     float val = 0;

+ 63 - 9
AvRecorder/ui/audio_widget.cpp

@@ -8,27 +8,81 @@ AudioWidget::AudioWidget(QWidget* parent)
     _CreateUi();
     _CreateConnect();
     _mutebox->setChecked(true);
+
+    // setMinimumHeight(10);
+    // setMaximumHeight(24);
 }
 
 void AudioWidget::_CreateUi()
 {
+    // auto hLayout = new QHBoxLayout;
+    // hLayout->setContentsMargins(0, 0, 0, 0);
+    // hLayout->setSpacing(2);
+
+    // _nameLabel = new QLabel;
+    // QFont smallFont = _nameLabel->font();
+    // smallFont.setPointSize(smallFont.pointSize() - 1);
+    // _nameLabel->setFont(smallFont);
+
+    // _mutebox = new QCheckBox("静音");
+    // _mutebox->setFont(smallFont);
+
+    // _render = new AudioRender;
+    // _render->setMaximumHeight(14); // 更小的高度
+
+    // _volumeBox = new QDoubleSpinBox;
+    // _volumeBox->setMinimum(0);
+    // _volumeBox->setValue(1);
+    // _volumeBox->setFont(smallFont);
+    // _volumeBox->setFixedHeight(18);
+
+    // hLayout->addWidget(_nameLabel);
+    // hLayout->addWidget(_mutebox);
+
+    // auto scaleLayout = new QHBoxLayout;
+    // scaleLayout->setContentsMargins(0, 0, 0, 0);
+    // scaleLayout->setSpacing(2);
+    // QLabel* scaleLabel = new QLabel("调幅:");
+    // scaleLabel->setFont(smallFont);
+    // scaleLayout->addWidget(scaleLabel);
+    // scaleLayout->addWidget(_volumeBox);
+    // hLayout->addLayout(scaleLayout);
+
+    // auto vLayout = new QVBoxLayout;
+    // vLayout->setContentsMargins(0, 0, 0, 0);
+    // vLayout->setSpacing(2);
+    // vLayout->addLayout(hLayout);
+    // vLayout->addWidget(_render);
+    // setLayout(vLayout);
+    // setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
+
     auto hLayout = new QHBoxLayout;
+    hLayout->setContentsMargins(0, 0, 0, 0);
+    hLayout->setSpacing(6);
+
     _nameLabel = new QLabel;
-    _mutebox = new QCheckBox("静音");
     _render = new AudioRender;
+    _render->setMaximumHeight(14);
+    _render->setMinimumWidth(60);
+    _render->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+
+    _mutebox = new QCheckBox("静音");
     _volumeBox = new QDoubleSpinBox;
     _volumeBox->setMinimum(0);
     _volumeBox->setValue(1);
+    _volumeBox->setFixedHeight(18);
+    _volumeBox->setMaximumWidth(48);
+
+    QLabel* scaleLabel = new QLabel("调幅:");
+
     hLayout->addWidget(_nameLabel);
+    hLayout->addWidget(_render, 1); // 音量条居中拉伸
     hLayout->addWidget(_mutebox);
-    auto scaleLayout = new QHBoxLayout;
-    scaleLayout->addWidget(new QLabel("调幅:"));
-    scaleLayout->addWidget(_volumeBox);
-    hLayout->addLayout(scaleLayout);
-    auto vLayout = new QVBoxLayout;
-    vLayout->addLayout(hLayout);
-    vLayout->addWidget(_render);
-    setLayout(vLayout);
+    hLayout->addWidget(scaleLabel);
+    hLayout->addWidget(_volumeBox);
+
+    setLayout(hLayout);
+    setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
 }
 
 void AudioWidget::_CreateConnect()

+ 85 - 58
AvRecorder/ui/av_recorder.cpp

@@ -16,25 +16,95 @@ AvRecorder::AvRecorder(QWidget* parent)
     m_settingsParam.liveUrl = "rtmp://192.168.3.76:1935/stream/V1";
     m_settingsParam.liveName = "stream";
 
+    // 1. 视频预览区
     m_glWidget = new OpenGLVideoWidget(this);
 
-    auto layout = new QVBoxLayout;
-    auto hLayout = new QHBoxLayout;
-
-    hLayout->addLayout(initAudioUi(), 2);
-    hLayout->addLayout(initListUi(), 2);
-    hLayout->addLayout(initOtherUi(), 1);
+    // 2. 音频区
+    m_microphoneWidget = new AudioWidget;
+    m_speakerWidget = new AudioWidget;
+    m_microphoneWidget->SetName("麦克风");
+    m_speakerWidget->SetName("扬声器");
 
+    // 3. 捕获区
+    m_captureComboBox = new QComboBox;
+    m_updateListBtn = new QPushButton("刷新窗口列表");
+    QGroupBox* captureGroup = new QGroupBox("捕获源");
+    QVBoxLayout* captureLayout = new QVBoxLayout;
+    QHBoxLayout* captureRow = new QHBoxLayout;
+    captureRow->addWidget(m_captureComboBox);
+    captureRow->addWidget(m_updateListBtn);
+    captureLayout->addLayout(captureRow);
+    captureGroup->setLayout(captureLayout);
+    captureGroup->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
+
+    // 4. 音频区分组
+    QGroupBox* audioGroup = new QGroupBox("音频");
+    QVBoxLayout* audioLayout = new QVBoxLayout;
+    audioLayout->addWidget(m_microphoneWidget);
+    audioLayout->addWidget(m_speakerWidget);
+    audioGroup->setLayout(audioLayout);
+    audioGroup->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
+
+    // 5. 操作区
+    m_isDrawCursorBox = new QCheckBox("绘制鼠标指针");
+    m_isDrawCursorBox->setChecked(true);
+    m_isDrawCursorBox->setEnabled(false);
+    m_syncRecordBox = new QCheckBox("直播时同步录像");
+    m_syncRecordBox->setChecked(false);
+    m_recordBtn = new QPushButton("开始录制");
+    m_recordBtn->setEnabled(false);
+    m_liveBtn = new QPushButton("开始直播");
+    m_liveBtn->setEnabled(false);
+    m_settingsBtn = new QPushButton("设置");
+    QGroupBox* actionGroup = new QGroupBox("操作");
+    QVBoxLayout* actionLayout = new QVBoxLayout;
+    QHBoxLayout* checkBoxRow = new QHBoxLayout;
+    checkBoxRow->setContentsMargins(0, 0, 0, 0);
+    checkBoxRow->setSpacing(8);
+    checkBoxRow->addWidget(m_syncRecordBox);
+    checkBoxRow->addWidget(m_isDrawCursorBox);
+    actionLayout->addLayout(checkBoxRow);
+    actionLayout->addWidget(m_recordBtn);
+    actionLayout->addWidget(m_liveBtn);
+    actionGroup->setLayout(actionLayout);
+    actionGroup->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
+
+    // 6. 设置区
+    QHBoxLayout* utilLayout = new QHBoxLayout;
+    utilLayout->addWidget(m_settingsBtn);
+
+    // 7. 左侧功能区(捕获区在上,音频区在下)
+    QVBoxLayout* leftLayout = new QVBoxLayout;
+    leftLayout->addWidget(captureGroup);
+    leftLayout->addWidget(audioGroup);
+    leftLayout->addStretch();
+
+    // 8. 右侧功能区
+    QVBoxLayout* rightLayout = new QVBoxLayout;
+    rightLayout->addWidget(actionGroup);
+    rightLayout->addLayout(utilLayout);
+    rightLayout->addStretch();
+
+    // 9. 中部主布局
+    QHBoxLayout* centerLayout = new QHBoxLayout;
+    centerLayout->addLayout(leftLayout, 2);
+    centerLayout->addLayout(rightLayout, 3);
+
+    // 10. 状态栏
     initStatusBarUi();
 
-    initConnect();
+    // 让视频区尽量大
+    m_glWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
-    layout->addWidget(m_glWidget, 4);
-    layout->addLayout(hLayout, 1);
-    layout->addWidget(m_statusBar, 0);
-    setLayout(layout);
+    // 11. 总体布局
+    QVBoxLayout* mainLayout = new QVBoxLayout(this);
+    mainLayout->addWidget(m_glWidget, 100);
+    mainLayout->addLayout(centerLayout, 0);
+    mainLayout->addWidget(m_statusBar, 0);
+    setLayout(mainLayout);
 
-    // 初始化数据信息
+    // 12. 连接信号槽、初始化数据
+    initConnect();
     updateCaptureList();
 }
 
@@ -207,7 +277,7 @@ void AvRecorder::startCapture(VideoCapturer::Method method)
     if (idx < 0) {
         return;
     }
-    int monitorCnt = (int)MonitorFinder::GetList().size();
+    int monitorCnt = (int) MonitorFinder::GetList().size();
     QString type = (idx < monitorCnt) ? "monitor" : "window";
     qintptr ptrHwnd = m_captureComboBox->currentData().value<qintptr>();
     if (idx < monitorCnt) { // 捕获屏幕
@@ -220,8 +290,8 @@ void AvRecorder::startCapture(VideoCapturer::Method method)
             m_captureMethodBox->addItem("GDI");
         }
         if (type == "window") {
-            if (::IsWindow((HWND)ptrHwnd)) {
-                m_videoRecorder.Open((HWND)ptrHwnd, m_settingsParam.videoParam, method);
+            if (::IsWindow((HWND) ptrHwnd)) {
+                m_videoRecorder.Open((HWND) ptrHwnd, m_settingsParam.videoParam, method);
             }
         }
     }
@@ -350,49 +420,6 @@ void AvRecorder::updateCaptureList()
     }
 }
 
-QVBoxLayout* AvRecorder::initListUi()
-{
-    auto layout = new QVBoxLayout;
-    m_captureComboBox = new QComboBox;
-    layout->addWidget(m_captureComboBox);
-    return layout;
-}
-
-QVBoxLayout* AvRecorder::initAudioUi()
-{
-    m_microphoneWidget = new AudioWidget;
-    m_speakerWidget = new AudioWidget;
-    m_microphoneWidget->SetName("麦克风");
-    m_speakerWidget->SetName("扬声器");
-    auto layout = new QVBoxLayout;
-    layout->addWidget(m_microphoneWidget);
-    layout->addWidget(m_speakerWidget);
-    return layout;
-}
-
-QVBoxLayout* AvRecorder::initOtherUi()
-{
-    m_isDrawCursorBox = new QCheckBox("绘制鼠标指针");
-    m_isDrawCursorBox->setChecked(true);
-    m_isDrawCursorBox->setEnabled(false);
-    m_syncRecordBox = new QCheckBox("直播时同步录像");
-    m_syncRecordBox->setChecked(false);
-    m_updateListBtn = new QPushButton("刷新窗口列表");
-    m_recordBtn = new QPushButton("开始录制");
-    m_recordBtn->setEnabled(false);
-    m_liveBtn = new QPushButton("开始直播");
-    m_liveBtn->setEnabled(false);
-    m_settingsBtn = new QPushButton("设置");
-    auto layout = new QVBoxLayout;
-    layout->addWidget(m_isDrawCursorBox);
-    layout->addWidget(m_syncRecordBox);
-    layout->addWidget(m_updateListBtn);
-    layout->addWidget(m_recordBtn);
-    layout->addWidget(m_liveBtn);
-    layout->addWidget(m_settingsBtn);
-    return layout;
-}
-
 void AvRecorder::initStatusBarUi()
 {
     m_videoEncodeLabel = new QLabel;

+ 3 - 4
AvRecorder/ui/av_recorder.h

@@ -28,12 +28,11 @@ public:
 
     void setSettings(const SettingsPage::Param& param);
 
+signals:
+    void renderFrame(AVFrame* frame);
+
 private:
     SettingsPage::Param m_settingsParam;
-    QVBoxLayout* initListUi();
-    QVBoxLayout* initAudioUi();
-    QVBoxLayout* initOtherUi();
-
     void initStatusBarUi();
     void updateCaptureList();
     void startCapture(VideoCapturer::Method method);