#include "recorder_main_widget.h"
#include "../../base/logger.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QScreen>
#include <QStandardPaths>
#include <QDir>
#include <QDateTime>
#include <QScrollArea>
#include <QTabWidget>

extern "C" {
#include <libavutil/pixfmt.h>
}

RecorderMainWidget::RecorderMainWidget(QWidget* parent)
    : QWidget(parent)
    , m_recorder(nullptr)
    , m_isInitialized(false)
    , m_isRecording(false)
    , m_isPaused(false)
    , m_isPreviewActive(false)
    , m_recordDuration(0)
    , m_settingsDialog(nullptr)
    , m_independentControlGroup(nullptr)
    , m_audioStartButton(nullptr)
    , m_audioStopButton(nullptr)
    , m_videoCaptureButton(nullptr)
    , m_videoStopButton(nullptr)
    , m_audioEnableCheck(nullptr)
    , m_videoEnableCheck(nullptr) {
    
    setWindowTitle("AV录制器");
    setMinimumSize(1050, 650);  // 调整尺寸适应音频控制的空间需求
    resize(1250, 750);          // 调整默认尺寸
    
    initUI();
    initConnections();
    updateUIState();
}

RecorderMainWidget::~RecorderMainWidget() {
    cleanup();
}

bool RecorderMainWidget::initialize() {
    if (m_isInitialized) {
        return true;
    }

    AV_LOGGER_INFO("Initializing RecorderMainWidget");

    // 初始化录制器模块
    auto result = RecorderModule::initialize();
    if (result != av::ErrorCode::SUCCESS) {
        AV_LOGGER_ERROR("Failed to initialize recorder module");
        QMessageBox::critical(this, "错误", "初始化录制器模块失败");
        return false;
    }
    
    // 创建录制器
    m_recorder = utils::createAVRecorder();
    if (!m_recorder) {
        AV_LOGGER_ERROR("Failed to create AV recorder");
        QMessageBox::critical(this, "错误", "创建录制器失败");
        return false;
    }
    
    // 更新设备列表
    updateCaptureDevices();
    
    // 设置默认输出路径
    QString defaultPath = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
    if (defaultPath.isEmpty()) {
        defaultPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
    }
    QString fileName = QString("录制_%1.mp4").arg(QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss"));
    m_outputPathEdit->setText(QDir(defaultPath).filePath(fileName));
    
    m_isInitialized = true;
    updateUIState();

    AV_LOGGER_INFO("RecorderMainWidget initialized successfully");
    return true;
}

void RecorderMainWidget::cleanup() {
    if (!m_isInitialized) {
        return;
    }

    AV_LOGGER_INFO("Cleaning up RecorderMainWidget");

    // 停止所有操作
    if (m_isRecording) {
        stopRecording();
    }
    if (m_isPreviewActive) {
        stopPreview();
    }
    
    // 停止定时器
    if (m_updateTimer) {
        m_updateTimer->stop();
    }
    if (m_previewTimer) {
        m_previewTimer->stop();
    }
    if (m_audioLevelTimer) {
        m_audioLevelTimer->stop();
    }
    
    // 清理录制器
    m_recorder.reset();
    
    // 清理模块
    RecorderModule::cleanup();
    
    m_isInitialized = false;

    AV_LOGGER_INFO("RecorderMainWidget cleaned up");
}

void RecorderMainWidget::startRecording() {
    if (!m_isInitialized || m_isRecording) {
        return;
    }

    AV_LOGGER_INFO("Starting recording");

    // 获取录制参数
    auto params = getCurrentParams();
    
    // 验证输出路径
    if (!utils::isValidOutputPath(params.outputPath)) {
        QMessageBox::warning(this, "警告", "输出路径无效，请选择有效的输出文件");
        return;
    }
    
    // 初始化录制器
    auto result = m_recorder->initialize(params);
    if (result != av::ErrorCode::SUCCESS) {
        AV_LOGGER_ERROR("Failed to initialize recorder");
        QMessageBox::critical(this, "错误", "初始化录制器失败");
        return;
    }
    
    // 开始录制
    result = m_recorder->startRecording();
    if (result != av::ErrorCode::SUCCESS) {
        AV_LOGGER_ERROR("Failed to start recording");
        QMessageBox::critical(this, "错误", "开始录制失败");
        return;
    }
    
    m_isRecording = true;
    m_isPaused = false;
    m_recordStartTime = QTime::currentTime();
    
    // 启动更新定时器
    if (!m_updateTimer->isActive()) {
        m_updateTimer->start(UPDATE_INTERVAL_MS);
    }
    
    updateUIState();
    m_statusLabel->setText("录制中...");

    AV_LOGGER_INFO("Recording started successfully");
}

void RecorderMainWidget::stopRecording() {
    if (!m_isRecording) {
        return;
    }

    AV_LOGGER_INFO("Stopping recording");

    auto result = m_recorder->stopRecording();
    if (result != av::ErrorCode::SUCCESS) {
        AV_LOGGER_ERROR("Failed to stop recording");
        QMessageBox::warning(this, "警告", "停止录制时出现错误");
    }
    
    m_isRecording = false;
    m_isPaused = false;
    m_recordDuration = 0;
    
    // 停止更新定时器
    if (m_updateTimer && m_updateTimer->isActive()) {
        m_updateTimer->stop();
    }
    
    updateUIState();
    m_statusLabel->setText("录制已停止");
    
    // 显示录制完成信息
    auto combinedStats = m_recorder->getCombinedStats();
    auto& videoStats = combinedStats.videoStats;
    QString message = QString("录制完成\n文件: %1\n时长: %2\n帧数: %3")
        .arg(QString::fromStdString(getCurrentParams().outputPath))
        .arg(formatTime(static_cast<int64_t>(videoStats.recordingTime * 1000)))
        .arg(videoStats.recordedFrames);
    
    QMessageBox::information(this, "录制完成", message);

    // 重置录制器状态，以便可以重新启动
    resetRecorderForRestart();

    AV_LOGGER_INFO("Recording stopped successfully");
}

void RecorderMainWidget::pauseRecording() {
    if (!m_isRecording || m_isPaused) {
        return;
    }

    AV_LOGGER_INFO("Pausing recording");

    auto result = m_recorder->pauseRecording();
    if (result != av::ErrorCode::SUCCESS) {
        AV_LOGGER_ERROR("Failed to pause recording");
        QMessageBox::warning(this, "警告", "暂停录制失败");
        return;
    }
    
    m_isPaused = true;
    updateUIState();
    m_statusLabel->setText("录制已暂停");

    AV_LOGGER_INFO("Recording paused successfully");
}

void RecorderMainWidget::resumeRecording() {
    if (!m_isRecording || !m_isPaused) {
        return;
    }

    AV_LOGGER_INFO("Resuming recording");

    auto result = m_recorder->resumeRecording();
    if (result != av::ErrorCode::SUCCESS) {
        AV_LOGGER_ERROR("Failed to resume recording");
        QMessageBox::warning(this, "警告", "恢复录制失败");
        return;
    }
    
    m_isPaused = false;
    updateUIState();
    m_statusLabel->setText("录制中...");

    AV_LOGGER_INFO("Recording resumed successfully");
}

void RecorderMainWidget::startPreview() {
    if (!m_isInitialized || m_isPreviewActive) {
        return;
    }

    AV_LOGGER_INFO("Starting preview");

    // 获取预览参数（只需要视频参数）
    auto params = getCurrentParams();
    params.outputPath = "./preview_temp.mp4";   // 预览使用临时文件
    params.enableAudio = false; // 预览通常不需要音频录制
    
    // 初始化录制器用于预览
    auto result = m_recorder->initialize(params);
    if (result != av::ErrorCode::SUCCESS) {
        AV_LOGGER_ERROR("Failed to initialize recorder for preview");
        QMessageBox::warning(this, "警告", "初始化预览失败");
        return;
    }
    
    // 开始预览（实际上是开始捕获但不录制到文件）
    result = m_recorder->startRecording();
    if (result != av::ErrorCode::SUCCESS) {
        AV_LOGGER_ERROR("Failed to start preview");
        QMessageBox::warning(this, "警告", "开始预览失败");
        return;
    }
    
    m_isPreviewActive = true;
    
    // 启动预览更新定时器
    if (!m_previewTimer->isActive()) {
        m_previewTimer->start(PREVIEW_INTERVAL_MS);
    }
    
    updateUIState();
    m_statusLabel->setText("预览中...");

    AV_LOGGER_INFO("Preview started successfully");
}

void RecorderMainWidget::stopPreview() {
    if (!m_isPreviewActive) {
        return;
    }

    AV_LOGGER_INFO("Stopping preview");

    m_recorder->stopRecording();
    m_isPreviewActive = false;
    
    // 停止预览定时器
    if (m_previewTimer->isActive()) {
        m_previewTimer->stop();
    }
    
    // 清空预览窗口
    m_videoWidget->clearFrame();
    
    updateUIState();
    m_statusLabel->setText("预览已停止");

    // 重置录制器状态，以便可以重新启动
    resetRecorderForRestart();

    AV_LOGGER_INFO("Preview stopped successfully");
}

void RecorderMainWidget::openSettings() {
    if (!m_settingsDialog) {
        m_settingsDialog = new RecorderSettingsDialog(nullptr, this);
    }
    
    // TODO: 设置当前参数
    // m_settingsDialog->setSettings(getCurrentSettings());
    
    if (m_settingsDialog->exec() == QDialog::Accepted) {
        // 应用新参数
        auto settings = m_settingsDialog->getSettings();
        // TODO: 将settings转换为AVRecorderParams
        // applyRecorderParams(convertSettingsToParams(settings));

        AV_LOGGER_INFO("Settings applied");
        m_statusLabel->setText("设置已应用");
    }
}

void RecorderMainWidget::selectOutputFile() {
    QString currentPath = m_outputPathEdit->text();
    QString dir = QFileInfo(currentPath).absolutePath();
    
    QString fileName = QFileDialog::getSaveFileName(
        this,
        "选择输出文件",
        currentPath,
        "视频文件 (*.mp4 *.avi *.mkv *.mov);;音频文件 (*.mp3 *.wav *.aac);;所有文件 (*.*)"
    );
    
    if (!fileName.isEmpty()) {
        m_outputPathEdit->setText(fileName);
    }
}

void RecorderMainWidget::updateCaptureDevices() {
    AV_LOGGER_INFO("Updating capture devices");

    // 更新采集方法
    m_captureMethodCombo->clear();
    m_captureMethodCombo->addItem("屏幕录制", static_cast<int>(VideoCaptureMethod::SCREEN_CAPTURE));
    m_captureMethodCombo->addItem("窗口录制", static_cast<int>(VideoCaptureMethod::WINDOW_CAPTURE));
    m_captureMethodCombo->addItem("摄像头录制", static_cast<int>(VideoCaptureMethod::CAMERA_CAPTURE));
    
    // 更新采集源（这里简化处理，实际应该查询系统）
    onCaptureMethodChanged();
    
    // 更新音频设备（这里简化处理，实际应该查询系统）
    m_audioDeviceCombo->clear();
    m_audioDeviceCombo->addItem("默认麦克风", 0);
    m_audioDeviceCombo->addItem("默认扬声器", 1);

    AV_LOGGER_INFO("Capture devices updated");
}

void RecorderMainWidget::onCaptureSourceChanged() {
    // 采集源改变时的处理
    updateUIState();
}

void RecorderMainWidget::onCaptureMethodChanged() {
    // 根据采集方法更新采集源列表
    m_captureSourceCombo->clear();
    
    int method = m_captureMethodCombo->currentData().toInt();
    switch (static_cast<VideoCaptureMethod>(method)) {
    case VideoCaptureMethod::SCREEN_CAPTURE:
        // 添加屏幕列表（简化处理）
        m_captureSourceCombo->addItem("主屏幕", 0);
        m_captureSourceCombo->addItem("扩展屏幕", 1);
        break;
        
    case VideoCaptureMethod::WINDOW_CAPTURE:
        // 添加窗口列表（简化处理）
        m_captureSourceCombo->addItem("当前窗口", 0);
        break;
        
    case VideoCaptureMethod::CAMERA_CAPTURE:
        // 添加摄像头列表（简化处理）
        m_captureSourceCombo->addItem("默认摄像头", 0);
        break;
    }
}

void RecorderMainWidget::onAudioDeviceChanged() {
    // 音频设备改变时的处理
    updateUIState();
}

void RecorderMainWidget::onVolumeChanged(double volume) {
    // 音量改变时的处理
    AV_LOGGER_DEBUGF("Volume changed to {}", volume);
}

void RecorderMainWidget::onMuteChanged(bool muted) {
    // 静音状态改变时的处理
    AV_LOGGER_DEBUGF("Mute changed to {}", muted);
}

void RecorderMainWidget::updateRecordingStatus() {
    if (!m_isRecording) {
        m_recordTimeLabel->setText("00:00:00");
        return;
    }
    
    // 计算录制时间
    int elapsed = m_recordStartTime.msecsTo(QTime::currentTime());
    if (m_isPaused) {
        elapsed = m_recordDuration;
    } else {
        m_recordDuration = elapsed;
    }
    
    m_recordTimeLabel->setText(formatTime(elapsed));
    
    // 更新统计信息
    if (m_recorder) {
        auto combinedStats = m_recorder->getCombinedStats();
        auto& videoStats = combinedStats.videoStats;
        m_framesLabel->setText(QString("帧数: %1").arg(videoStats.recordedFrames));
        m_droppedFramesLabel->setText(QString("丢帧: %1").arg(videoStats.droppedFrames));
        
        // 计算码率 (总字节数 / 录制时长 * 8)
        double bitrate = videoStats.recordingTime > 0 ? (videoStats.totalBytes * 8.0 / videoStats.recordingTime) : 0;
        m_bitrateLabel->setText(QString("码率: %1").arg(formatBitrate(static_cast<int64_t>(bitrate))));
        
        // 显示文件大小
        m_fileSizeLabel->setText(QString("大小: %1").arg(formatFileSize(videoStats.totalBytes)));
    }
}

void RecorderMainWidget::updatePreviewFrame() {
    if (!m_isPreviewActive || !m_recorder) {
        return;
    }
    
    try {
        // 获取当前预览帧
        auto frame = m_recorder->getCurrentVideoFrame();
        if (frame && frame->data[0]) {
            AV_LOGGER_DEBUGF("更新预览帧: width={}, height={}, format={}, data_ptr={}", 
                            frame->width, frame->height, frame->format, 
                            static_cast<void*>(frame->data[0]));
            bool updated = m_videoWidget->updateFrame(frame.get());
            if (!updated) {
                AV_LOGGER_WARNING("视频预览组件更新失败");
            }
        } else {
            AV_LOGGER_DEBUG("未获取到有效的预览帧");
        }
    } catch (const std::exception& e) {
        AV_LOGGER_ERRORF("Error updating preview frame: {}", e.what());
        // 预览错误不应该影响录制，继续运行
    }
}

void RecorderMainWidget::updateAudioLevel() {
    if (!m_recorder) {
        return;
    }
    
    // 获取音频电平（这里需要录制器提供音频电平接口）
    // auto level = m_recorder->getCurrentAudioLevel();
    // m_microphoneWidget->setLevel(level.micLevel);
    // m_speakerWidget->setLevel(level.speakerLevel);
}

void RecorderMainWidget::onRecorderStateChanged(RecorderState state) {
    AV_LOGGER_INFOF("Recorder state changed to {}", static_cast<int>(state));
    updateUIState();
}

void RecorderMainWidget::onRecorderError(const QString& error) {
    AV_LOGGER_ERRORF("Recorder error: {}", error.toStdString());
    QMessageBox::critical(this, "录制器错误", error);
    
    // 停止当前操作
    if (m_isRecording) {
        stopRecording();
    }
    if (m_isPreviewActive) {
        stopPreview();
    }
}

void RecorderMainWidget::onStatisticsUpdated() {
    // 统计信息更新时的处理
    updateRecordingStatus();
}

void RecorderMainWidget::initUI() {
    // 创建主分割器
    m_mainSplitter = new QSplitter(Qt::Horizontal, this);
    
    // 创建左面板滚动区域
    auto leftScrollArea = new QScrollArea();
    leftScrollArea->setWidgetResizable(true);
    leftScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    leftScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    leftScrollArea->setMinimumWidth(350);  // 增加最小宽度，给音频控件更多空间
    leftScrollArea->setMaximumWidth(420);  // 增加最大宽度
    
    // 创建实际的左面板内容widget
    m_leftPanel = new QWidget();
    leftScrollArea->setWidget(m_leftPanel);
    
    // 创建右面板
    m_rightPanel = new QWidget();
    
    m_mainSplitter->addWidget(leftScrollArea);
    m_mainSplitter->addWidget(m_rightPanel);
    m_mainSplitter->setStretchFactor(0, 0);  // 左面板固定大小
    m_mainSplitter->setStretchFactor(1, 1);  // 右面板占用剩余空间
    
    // 初始化各个面板
    initControlPanel();
    initIndependentControlPanel();
    initPreviewPanel();
    initAudioPanel();
    initSettingsPanel();
    initStatusBar();
    
    // 设置左面板紧凑布局
    auto leftLayout = new QVBoxLayout(m_leftPanel);
    leftLayout->setContentsMargins(4, 4, 4, 4);
    leftLayout->setSpacing(6);  // 稍微增加间距，让组件更清晰
    
    // 按重要性和空间需求设置各个组件
    leftLayout->addWidget(m_controlGroup, 0);           // 录制控制 - 最重要，固定大小
    leftLayout->addWidget(m_independentControlGroup, 0); // 独立控制面板，固定大小
    leftLayout->addWidget(m_captureGroup, 0);           // 采集设置，固定大小
    leftLayout->addWidget(m_outputGroup, 0);            // 输出设置，固定大小
    leftLayout->addWidget(m_audioGroup, 1);             // 音频控制 - 给予优先扩展空间
    leftLayout->addWidget(m_statsGroup, 0);             // 统计信息，固定大小
    leftLayout->addStretch(0);                          // 底部填充空间
    
    // 设置右面板布局
    auto rightLayout = new QVBoxLayout(m_rightPanel);
    rightLayout->setContentsMargins(4, 4, 4, 4);
    rightLayout->addWidget(m_previewGroup);
    
    // 设置主布局
    auto mainLayout = new QVBoxLayout(this);
    mainLayout->setContentsMargins(2, 2, 2, 0);  // 底部边距设为0，让状态栏贴底
    mainLayout->setSpacing(0);  // 减少组件间距
    mainLayout->addWidget(m_mainSplitter, 1);  // 主分割器占用主要空间
    mainLayout->addWidget(m_statusBar, 0);     // 状态栏固定大小
    
    // 创建定时器
    m_updateTimer = new QTimer(this);
    m_previewTimer = new QTimer(this);
    m_audioLevelTimer = new QTimer(this);
}

void RecorderMainWidget::initControlPanel() {
    m_controlGroup = new QGroupBox("录制控制");
    m_controlGroup->setMaximumHeight(140);
    
    // 创建按钮
    m_recordButton = new QPushButton("开始录制");
    m_pauseButton = new QPushButton("暂停");
    m_stopButton = new QPushButton("停止");
    m_previewButton = new QPushButton("预览");
    m_settingsButton = new QPushButton("设置");
    
    // 设置按钮最小高度和样式
    const int buttonHeight = 28;
    m_recordButton->setMinimumHeight(buttonHeight);
    m_pauseButton->setMinimumHeight(buttonHeight);
    m_stopButton->setMinimumHeight(buttonHeight);
    m_previewButton->setMinimumHeight(buttonHeight);
    m_settingsButton->setMinimumHeight(buttonHeight);
    
    // 创建状态标签
    m_recordTimeLabel = new QLabel("00:00:00");
    m_recordTimeLabel->setStyleSheet("QLabel { font-weight: bold; color: #0066cc; }");
    m_recordStatusLabel = new QLabel("就绪");
    
    // 紧凑布局
    auto layout = new QGridLayout(m_controlGroup);
    layout->setContentsMargins(6, 8, 6, 6);
    layout->setSpacing(4);
    layout->addWidget(m_recordButton, 0, 0);
    layout->addWidget(m_pauseButton, 0, 1);
    layout->addWidget(m_stopButton, 0, 2);
    layout->addWidget(m_previewButton, 1, 0);
    layout->addWidget(m_settingsButton, 1, 1, 1, 2);
    
    // 状态信息用更紧凑的布局
    auto statusLayout = new QHBoxLayout();
    statusLayout->setSpacing(8);
    statusLayout->addWidget(new QLabel("时间:"));
    statusLayout->addWidget(m_recordTimeLabel);
    statusLayout->addWidget(new QLabel("状态:"));
    statusLayout->addWidget(m_recordStatusLabel);
    statusLayout->addStretch();
    
    layout->addLayout(statusLayout, 2, 0, 1, 3);
}

void RecorderMainWidget::initIndependentControlPanel() {
    m_independentControlGroup = new QGroupBox("独立采集控制");
    m_independentControlGroup->setMaximumHeight(120);
    
    // 创建控制按钮
    m_audioStartButton = new QPushButton("启动音频");
    m_audioStopButton = new QPushButton("停止音频");
    m_videoCaptureButton = new QPushButton("启动视频");
    m_videoStopButton = new QPushButton("停止视频");
    
    // 设置按钮高度
    const int buttonHeight = 26;
    m_audioStartButton->setMinimumHeight(buttonHeight);
    m_audioStopButton->setMinimumHeight(buttonHeight);
    m_videoCaptureButton->setMinimumHeight(buttonHeight);
    m_videoStopButton->setMinimumHeight(buttonHeight);
    
    // 创建启用检查框
    m_audioEnableCheck = new QCheckBox("启用音频录制");
    m_videoEnableCheck = new QCheckBox("启用视频录制");
    
    // 设置默认状态
    m_audioEnableCheck->setChecked(true);
    m_videoEnableCheck->setChecked(true);
    
    // 设置按钮样式
    m_audioStartButton->setStyleSheet("QPushButton { background-color: #34c759; color: white; }");
    m_audioStopButton->setStyleSheet("QPushButton { background-color: #ff3b30; color: white; }");
    m_videoCaptureButton->setStyleSheet("QPushButton { background-color: #007aff; color: white; }");
    m_videoStopButton->setStyleSheet("QPushButton { background-color: #ff9500; color: white; }");
    
    // 紧凑布局
    auto layout = new QGridLayout(m_independentControlGroup);
    layout->setContentsMargins(6, 8, 6, 6);
    layout->setSpacing(3);
    
    // 第一行：启用选项（水平布局）
    auto enableLayout = new QHBoxLayout();
    enableLayout->setSpacing(10);
    enableLayout->addWidget(m_audioEnableCheck);
    enableLayout->addWidget(m_videoEnableCheck);
    layout->addLayout(enableLayout, 0, 0, 1, 4);
    
    // 第二行：音频控制
    layout->addWidget(new QLabel("音频:"), 1, 0);
    layout->addWidget(m_audioStartButton, 1, 1);
    layout->addWidget(m_audioStopButton, 1, 2);
    
    // 第三行：视频控制
    layout->addWidget(new QLabel("视频:"), 2, 0);
    layout->addWidget(m_videoCaptureButton, 2, 1);
    layout->addWidget(m_videoStopButton, 2, 2);
}

void RecorderMainWidget::initPreviewPanel() {
    m_previewGroup = new QGroupBox("预览窗口");
    
    // 创建视频预览组件
    m_videoWidget = new RecorderVideoWidget();
    m_videoWidget->setMinimumSize(640, 480);
    
    // 初始化VideoWidget（默认参数：1920x1080, YUV420P）
    if (!m_videoWidget->initialize(1920, 1080, AV_PIX_FMT_YUV420P)) {
        AV_LOGGER_WARNING("Failed to initialize video widget with default parameters");
        // 尝试RGB格式作为后备
        if (!m_videoWidget->initialize(1920, 1080, AV_PIX_FMT_RGB24)) {
            AV_LOGGER_ERROR("Failed to initialize video widget with RGB format");
        }
    }
    
    // 布局
    auto layout = new QVBoxLayout(m_previewGroup);
    layout->addWidget(m_videoWidget);
}

void RecorderMainWidget::initAudioPanel() {
    m_audioGroup = new QGroupBox("音频控制");
    m_audioGroup->setMinimumHeight(240);  // 给音频控制足够的最小高度
    m_audioGroup->setMaximumHeight(280);  // 设置合理的最大高度
    m_audioGroup->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    
    // 创建音频控制组件
    m_microphoneWidget = new RecorderAudioWidget(this);
    m_speakerWidget = new RecorderAudioWidget(this);
    
    // 设置widget标题和大小 - 给予充足空间
    m_microphoneWidget->setObjectName("麦克风");
    m_microphoneWidget->setMinimumHeight(100);  // 确保有足够高度显示所有控件
    m_microphoneWidget->setMaximumHeight(120);
    m_microphoneWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    
    m_speakerWidget->setObjectName("扬声器");
    m_speakerWidget->setMinimumHeight(100);  // 确保有足够高度显示所有控件
    m_speakerWidget->setMaximumHeight(120);
    m_speakerWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    
    // 调整布局
    auto layout = new QVBoxLayout(m_audioGroup);
    layout->setContentsMargins(6, 10, 6, 6);  // 给顶部更多空间
    layout->setSpacing(6);  // 增加适当间距
    
    // 添加标签来区分麦克风和扬声器
    auto micLabel = new QLabel("麦克风");
    micLabel->setStyleSheet("font-weight: bold; color: #0a84ff; font-size: 12px; margin-bottom: 2px;");
    layout->addWidget(micLabel);
    layout->addWidget(m_microphoneWidget);
    
    auto speakerLabel = new QLabel("扬声器");
    speakerLabel->setStyleSheet("font-weight: bold; color: #34c759; font-size: 12px; margin-top: 6px; margin-bottom: 2px;");
    layout->addWidget(speakerLabel);
    layout->addWidget(m_speakerWidget);
}

void RecorderMainWidget::initSettingsPanel() {
    // 采集设置组 - 紧凑布局
    m_captureGroup = new QGroupBox("采集设置");
    m_captureGroup->setMaximumHeight(160);
    
    m_captureMethodCombo = new QComboBox();
    m_captureSourceCombo = new QComboBox();
    m_audioDeviceCombo = new QComboBox();
    m_refreshDevicesButton = new QPushButton("刷新设备");
    m_drawCursorCheck = new QCheckBox("绘制光标");
    m_captureAudioCheck = new QCheckBox("录制音频");
    
    // 设置控件高度
    m_captureMethodCombo->setMaximumHeight(24);
    m_captureSourceCombo->setMaximumHeight(24);
    m_audioDeviceCombo->setMaximumHeight(24);
    m_refreshDevicesButton->setMaximumHeight(26);
    
    m_drawCursorCheck->setChecked(true);
    m_captureAudioCheck->setChecked(true);
    
    auto captureLayout = new QGridLayout(m_captureGroup);
    captureLayout->setContentsMargins(6, 8, 6, 6);
    captureLayout->setSpacing(3);
    captureLayout->addWidget(new QLabel("采集方法:"), 0, 0);
    captureLayout->addWidget(m_captureMethodCombo, 0, 1);
    captureLayout->addWidget(new QLabel("采集源:"), 1, 0);
    captureLayout->addWidget(m_captureSourceCombo, 1, 1);
    captureLayout->addWidget(new QLabel("音频设备:"), 2, 0);
    captureLayout->addWidget(m_audioDeviceCombo, 2, 1);
    captureLayout->addWidget(m_refreshDevicesButton, 3, 0, 1, 2);
    
    // 选项水平布局
    auto optionsLayout = new QHBoxLayout();
    optionsLayout->setSpacing(10);
    optionsLayout->addWidget(m_drawCursorCheck);
    optionsLayout->addWidget(m_captureAudioCheck);
    captureLayout->addLayout(optionsLayout, 4, 0, 1, 2);
    
    // 输出设置组 - 紧凑布局
    m_outputGroup = new QGroupBox("输出设置");
    m_outputGroup->setMaximumHeight(80);
    
    m_outputPathEdit = new QLineEdit();
    m_browseOutputButton = new QPushButton("浏览...");
    m_outputFormatCombo = new QComboBox();
    
    // 设置控件高度
    m_outputPathEdit->setMaximumHeight(24);
    m_browseOutputButton->setMaximumHeight(26);
    m_outputFormatCombo->setMaximumHeight(24);
    
    m_outputFormatCombo->addItems({"MP4", "AVI", "MKV", "MOV"});
    
    auto outputLayout = new QGridLayout(m_outputGroup);
    outputLayout->setContentsMargins(6, 8, 6, 6);
    outputLayout->setSpacing(3);
    outputLayout->addWidget(new QLabel("输出文件:"), 0, 0);
    outputLayout->addWidget(m_outputPathEdit, 0, 1);
    outputLayout->addWidget(m_browseOutputButton, 0, 2);
    outputLayout->addWidget(new QLabel("格式:"), 1, 0);
    outputLayout->addWidget(m_outputFormatCombo, 1, 1, 1, 2);
    
    // 统计信息组 - 紧凑布局
    m_statsGroup = new QGroupBox("统计信息");
    m_statsGroup->setMaximumHeight(120);
    
    m_fpsLabel = new QLabel("帧率: 0 fps");
    m_bitrateLabel = new QLabel("码率: 0 bps");
    m_framesLabel = new QLabel("帧数: 0");
    m_droppedFramesLabel = new QLabel("丢帧: 0");
    m_fileSizeLabel = new QLabel("大小: 0 B");
    
    // 设置标签样式
    QString labelStyle = "QLabel { font-size: 11px; margin: 1px; }";
    m_fpsLabel->setStyleSheet(labelStyle);
    m_bitrateLabel->setStyleSheet(labelStyle);
    m_framesLabel->setStyleSheet(labelStyle);
    m_droppedFramesLabel->setStyleSheet(labelStyle);
    m_fileSizeLabel->setStyleSheet(labelStyle);
    
    auto statsLayout = new QVBoxLayout(m_statsGroup);
    statsLayout->setContentsMargins(6, 8, 6, 6);
    statsLayout->setSpacing(2);
    statsLayout->addWidget(m_fpsLabel);
    statsLayout->addWidget(m_bitrateLabel);
    statsLayout->addWidget(m_framesLabel);
    statsLayout->addWidget(m_droppedFramesLabel);
    statsLayout->addWidget(m_fileSizeLabel);
}

void RecorderMainWidget::initStatusBar() {
    m_statusBar = new QStatusBar();
    m_statusBar->setMaximumHeight(26);  // 限制状态栏最大高度
    m_statusBar->setSizeGripEnabled(false);  // 禁用大小调整手柄
    
    m_statusLabel = new QLabel("就绪");
    m_statusLabel->setStyleSheet("QLabel { padding: 2px 4px; margin: 0px; font-size: 12px; }");  // 减少内边距和字体大小
    m_statusLabel->setMaximumHeight(22);  // 限制标签高度
    
    m_progressBar = new QProgressBar();
    m_progressBar->setVisible(false);
    m_progressBar->setMaximumHeight(18);  // 限制进度条高度
    
    m_statusBar->addWidget(m_statusLabel);
    m_statusBar->addPermanentWidget(m_progressBar);
}

void RecorderMainWidget::initConnections() {
    // 控制按钮连接
    connect(m_recordButton, &QPushButton::clicked, this, &RecorderMainWidget::startRecording);
    connect(m_pauseButton, &QPushButton::clicked, this, [this]() {
        if (m_isPaused) {
            resumeRecording();
        } else {
            pauseRecording();
        }
    });
    connect(m_stopButton, &QPushButton::clicked, this, &RecorderMainWidget::stopRecording);
    connect(m_previewButton, &QPushButton::clicked, this, [this]() {
        if (m_isPreviewActive) {
            stopPreview();
        } else {
            startPreview();
        }
    });
    connect(m_settingsButton, &QPushButton::clicked, this, &RecorderMainWidget::openSettings);
    
    // 设置控件连接
    connect(m_captureMethodCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
            this, &RecorderMainWidget::onCaptureMethodChanged);
    connect(m_captureSourceCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
            this, &RecorderMainWidget::onCaptureSourceChanged);
    connect(m_audioDeviceCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
            this, &RecorderMainWidget::onAudioDeviceChanged);
    connect(m_refreshDevicesButton, &QPushButton::clicked, this, &RecorderMainWidget::updateCaptureDevices);
    connect(m_browseOutputButton, &QPushButton::clicked, this, &RecorderMainWidget::selectOutputFile);
    
    // 音频控件连接
    connect(m_microphoneWidget, &RecorderAudioWidget::volumeChanged, this, &RecorderMainWidget::onVolumeChanged);
    connect(m_microphoneWidget, &RecorderAudioWidget::mutedChanged, this, &RecorderMainWidget::onMuteChanged);
    connect(m_speakerWidget, &RecorderAudioWidget::volumeChanged, this, &RecorderMainWidget::onVolumeChanged);
    connect(m_speakerWidget, &RecorderAudioWidget::mutedChanged, this, &RecorderMainWidget::onMuteChanged);
    
    // 独立控制连接
    connect(m_audioStartButton, &QPushButton::clicked, this, &RecorderMainWidget::onAudioStartClicked);
    connect(m_audioStopButton, &QPushButton::clicked, this, &RecorderMainWidget::onAudioStopClicked);
    connect(m_videoCaptureButton, &QPushButton::clicked, this, &RecorderMainWidget::onVideoCaptureClicked);
    connect(m_videoStopButton, &QPushButton::clicked, this, &RecorderMainWidget::onVideoStopClicked);
    connect(m_audioEnableCheck, &QCheckBox::toggled, this, &RecorderMainWidget::onAudioEnableChanged);
    connect(m_videoEnableCheck, &QCheckBox::toggled, this, &RecorderMainWidget::onVideoEnableChanged);
    
    // 定时器连接
    connect(m_updateTimer, &QTimer::timeout, this, &RecorderMainWidget::updateRecordingStatus);
    connect(m_previewTimer, &QTimer::timeout, this, &RecorderMainWidget::updatePreviewFrame);
    connect(m_audioLevelTimer, &QTimer::timeout, this, &RecorderMainWidget::updateAudioLevel);
}

void RecorderMainWidget::updateUIState() {
    bool canRecord = m_isInitialized && !m_isRecording;
    bool canStop = m_isRecording;
    bool canPause = m_isRecording && !m_isPaused;
    bool canResume = m_isRecording && m_isPaused;
    bool canPreview = m_isInitialized && !m_isRecording;
    
    m_recordButton->setEnabled(canRecord);
    m_stopButton->setEnabled(canStop);
    m_pauseButton->setEnabled(canPause || canResume);
    m_pauseButton->setText(m_isPaused ? "恢复" : "暂停");
    m_previewButton->setEnabled(canPreview);
    m_previewButton->setText(m_isPreviewActive ? "停止预览" : "开始预览");
    
    // 更新录制状态标签
    if (m_isRecording) {
        if (m_isPaused) {
            m_recordStatusLabel->setText("已暂停");
        } else {
            m_recordStatusLabel->setText("录制中");
        }
    } else if (m_isPreviewActive) {
        m_recordStatusLabel->setText("预览中");
    } else {
        m_recordStatusLabel->setText("就绪");
    }
    
    // 禁用/启用设置控件
    bool canChangeSettings = !m_isRecording && !m_isPreviewActive;
    m_captureMethodCombo->setEnabled(canChangeSettings);
    m_captureSourceCombo->setEnabled(canChangeSettings);
    m_audioDeviceCombo->setEnabled(canChangeSettings);
    m_outputPathEdit->setEnabled(canChangeSettings);
    m_outputFormatCombo->setEnabled(canChangeSettings);
    
    // 控制音频/视频启用复选框的状态
    bool canChangeEnableState = m_isInitialized && !m_isRecording && !m_isPreviewActive;
    if (m_audioEnableCheck) {
        m_audioEnableCheck->setEnabled(canChangeEnableState);
    }
    if (m_videoEnableCheck) {
        m_videoEnableCheck->setEnabled(canChangeEnableState);
    }
    
    // 更新独立控制按钮状态
    updateIndependentControlButtons();
}

AVRecorderParams RecorderMainWidget::getCurrentParams() {
    auto params = utils::getDefaultAVParams();
    
    // 设置输出路径
    params.outputPath = m_outputPathEdit->text().toStdString();
    
    // 设置格式
    QString format = m_outputFormatCombo->currentText().toLower();
    params.format = format.toStdString();
    params.audioParams.format = format.toStdString();
    params.videoParams.format = format.toStdString();
    
    // 设置采集方法
    int method = m_captureMethodCombo->currentData().toInt();
    params.videoParams.captureMethod = static_cast<VideoCaptureMethod>(method);
    
    // 设置采集源
    int source = m_captureSourceCombo->currentData().toInt();
    if (params.videoParams.captureMethod == VideoCaptureMethod::SCREEN_CAPTURE) {
        params.videoParams.monitorIndex = source;
    }
    
    // 设置其他选项
    params.videoParams.drawCursor = m_drawCursorCheck->isChecked();
    params.enableAudio = m_captureAudioCheck->isChecked();
    params.enableVideo = true;
    params.enableSync = true;
    
    return params;
}

void RecorderMainWidget::applyRecorderParams(const AVRecorderParams& params) {
    // 应用参数到UI控件
    m_outputPathEdit->setText(QString::fromStdString(params.outputPath));
    
    // 设置格式
    QString format = QString::fromStdString(params.format).toUpper();
    int formatIndex = m_outputFormatCombo->findText(format);
    if (formatIndex >= 0) {
        m_outputFormatCombo->setCurrentIndex(formatIndex);
    }
    
    // 设置采集方法
    int methodIndex = m_captureMethodCombo->findData(static_cast<int>(params.videoParams.captureMethod));
    if (methodIndex >= 0) {
        m_captureMethodCombo->setCurrentIndex(methodIndex);
        onCaptureMethodChanged();
    }
    
    // 设置其他选项
    m_drawCursorCheck->setChecked(params.videoParams.drawCursor);
    m_captureAudioCheck->setChecked(params.enableAudio);
}

QString RecorderMainWidget::formatTime(int64_t ms) {
    int seconds = ms / 1000;
    int minutes = seconds / 60;
    int hours = minutes / 60;
    
    seconds %= 60;
    minutes %= 60;
    
    return QString("%1:%2:%3")
        .arg(hours, 2, 10, QChar('0'))
        .arg(minutes, 2, 10, QChar('0'))
        .arg(seconds, 2, 10, QChar('0'));
}

QString RecorderMainWidget::formatFileSize(int64_t bytes) {
    const char* units[] = {"B", "KB", "MB", "GB", "TB"};
    int unitIndex = 0;
    double size = bytes;
    
    while (size >= 1024 && unitIndex < 4) {
        size /= 1024;
        unitIndex++;
    }
    
    return QString("%1 %2").arg(size, 0, 'f', 1).arg(units[unitIndex]);
}

QString RecorderMainWidget::formatBitrate(int64_t bps) {
    if (bps < 1000) {
        return QString("%1 bps").arg(bps);
    } else if (bps < 1000000) {
        return QString("%1 Kbps").arg(bps / 1000.0, 0, 'f', 1);
    } else {
        return QString("%1 Mbps").arg(bps / 1000000.0, 0, 'f', 1);
    }
}

// 独立音频/视频控制实现
void RecorderMainWidget::onAudioStartClicked() {
    if (!m_recorder) {
        QMessageBox::warning(this, "警告", "录制器未初始化");
        return;
    }
    
    auto result = m_recorder->startAudioCapture();
    if (result == av::ErrorCode::SUCCESS) {
        m_statusLabel->setText("音频采集已启动");
        updateIndependentControlButtons();
        AV_LOGGER_INFO("Audio capture started independently from UI");
    } else {
        QMessageBox::warning(this, "错误", "启动音频采集失败");
        AV_LOGGER_ERRORF("Failed to start audio capture: {}", static_cast<int>(result));
    }
}

void RecorderMainWidget::onAudioStopClicked() {
    if (!m_recorder) {
        return;
    }
    
    auto result = m_recorder->stopAudioCapture();
    if (result == av::ErrorCode::SUCCESS) {
        m_statusLabel->setText("音频采集已停止");
        updateIndependentControlButtons();
        AV_LOGGER_INFO("Audio capture stopped independently from UI");
    } else {
        QMessageBox::warning(this, "错误", "停止音频采集失败");
    }
}

void RecorderMainWidget::onVideoCaptureClicked() {
    if (!m_recorder) {
        QMessageBox::warning(this, "警告", "录制器未初始化");
        return;
    }
    
    auto result = m_recorder->startVideoCapture();
    if (result == av::ErrorCode::SUCCESS) {
        m_statusLabel->setText("视频采集已启动");
        updateIndependentControlButtons();
        AV_LOGGER_INFO("Video capture started independently from UI");
    } else {
        QMessageBox::warning(this, "错误", "启动视频采集失败");
        AV_LOGGER_ERRORF("Failed to start video capture: {}", static_cast<int>(result));
    }
}

void RecorderMainWidget::onVideoStopClicked() {
    if (!m_recorder) {
        return;
    }
    
    auto result = m_recorder->stopVideoCapture();
    if (result == av::ErrorCode::SUCCESS) {
        m_statusLabel->setText("视频采集已停止");
        updateIndependentControlButtons();
        AV_LOGGER_INFO("Video capture stopped independently from UI");
    } else {
        QMessageBox::warning(this, "错误", "停止视频采集失败");
    }
}

void RecorderMainWidget::onAudioEnableChanged(bool enabled) {
    if (!m_recorder) {
        AV_LOGGER_ERROR("Recorder not initialized when trying to change audio enable state");
        // 阻止信号递归，安全地恢复checkbox状态
        m_audioEnableCheck->blockSignals(true);
        m_audioEnableCheck->setChecked(!enabled);
        m_audioEnableCheck->blockSignals(false);
        QMessageBox::warning(this, "错误", "录制器未初始化，无法更改音频设置");
        return;
    }
    
    // 检查录制器状态，如果正在录制则不允许更改
    if (m_isRecording) {
        AV_LOGGER_WARNING("Cannot change audio enable state while recording");
        // 阻止信号递归，安全地恢复checkbox状态
        m_audioEnableCheck->blockSignals(true);
        m_audioEnableCheck->setChecked(!enabled);
        m_audioEnableCheck->blockSignals(false);
        QMessageBox::warning(this, "警告", "录制过程中无法更改音频启用状态");
        return;
    }
    
    auto result = m_recorder->setAudioEnabled(enabled);
    if (result == av::ErrorCode::SUCCESS) {
        updateIndependentControlButtons();
        AV_LOGGER_INFOF("Audio recording {} from UI", enabled ? "enabled" : "disabled");
        
        if (enabled) {
            m_statusLabel->setText("音频录制已启用");
        } else {
            m_statusLabel->setText("音频录制已禁用");
        }
    } else {
        // 记录详细的错误信息
        AV_LOGGER_ERRORF("Failed to {} audio recording: error code {}", 
                        enabled ? "enable" : "disable", static_cast<int>(result));
        
        // 阻止信号递归，安全地恢复checkbox状态
        m_audioEnableCheck->blockSignals(true);
        m_audioEnableCheck->setChecked(!enabled);
        m_audioEnableCheck->blockSignals(false);
        
        // 根据错误类型显示不同的错误信息
        QString errorMsg;
        switch (result) {
            case av::ErrorCode::INVALID_STATE:
                errorMsg = "录制器状态无效，无法更改音频设置";
                break;
            case av::ErrorCode::NOT_INITIALIZED:
                errorMsg = "音频模块未初始化";
                break;
            case av::ErrorCode::DEVICE_NOT_FOUND:
                errorMsg = "未找到音频设备";
                break;
            default:
                errorMsg = enabled ? "启用音频录制失败" : "禁用音频录制失败";
                errorMsg += QString("（错误代码：%1）").arg(static_cast<int>(result));
                break;
        }
        
        QMessageBox::warning(this, "错误", errorMsg);
    }
}

void RecorderMainWidget::onVideoEnableChanged(bool enabled) {
    if (!m_recorder) {
        AV_LOGGER_ERROR("Recorder not initialized when trying to change video enable state");
        // 阻止信号递归，安全地恢复checkbox状态
        m_videoEnableCheck->blockSignals(true);
        m_videoEnableCheck->setChecked(!enabled);
        m_videoEnableCheck->blockSignals(false);
        QMessageBox::warning(this, "错误", "录制器未初始化，无法更改视频设置");
        return;
    }
    
    // 检查录制器状态，如果正在录制则不允许更改
    if (m_isRecording) {
        AV_LOGGER_WARNING("Cannot change video enable state while recording");
        // 阻止信号递归，安全地恢复checkbox状态
        m_videoEnableCheck->blockSignals(true);
        m_videoEnableCheck->setChecked(!enabled);
        m_videoEnableCheck->blockSignals(false);
        QMessageBox::warning(this, "警告", "录制过程中无法更改视频启用状态");
        return;
    }
    
    auto result = m_recorder->setVideoEnabled(enabled);
    if (result == av::ErrorCode::SUCCESS) {
        updateIndependentControlButtons();
        AV_LOGGER_INFOF("Video recording {} from UI", enabled ? "enabled" : "disabled");
        
        if (enabled) {
            m_statusLabel->setText("视频录制已启用");
        } else {
            m_statusLabel->setText("视频录制已禁用");
        }
    } else {
        // 记录详细的错误信息
        AV_LOGGER_ERRORF("Failed to {} video recording: error code {}", 
                        enabled ? "enable" : "disable", static_cast<int>(result));
        
        // 阻止信号递归，安全地恢复checkbox状态
        m_videoEnableCheck->blockSignals(true);
        m_videoEnableCheck->setChecked(!enabled);
        m_videoEnableCheck->blockSignals(false);
        
        // 根据错误类型显示不同的错误信息
        QString errorMsg;
        switch (result) {
            case av::ErrorCode::INVALID_STATE:
                errorMsg = "录制器状态无效，无法更改视频设置";
                break;
            case av::ErrorCode::NOT_INITIALIZED:
                errorMsg = "视频模块未初始化";
                break;
            case av::ErrorCode::DEVICE_NOT_FOUND:
                errorMsg = "未找到视频设备";
                break;
            default:
                errorMsg = enabled ? "启用视频录制失败" : "禁用视频录制失败";
                errorMsg += QString("（错误代码：%1）").arg(static_cast<int>(result));
                break;
        }
        
        QMessageBox::warning(this, "错误", errorMsg);
    }
}

void RecorderMainWidget::updateIndependentControlButtons() {
    if (!m_recorder) {
        return;
    }
    
    // 更新音频按钮状态
    bool audioRecording = m_recorder->isAudioRecording();
    bool audioCapturing = m_recorder->isAudioCapturing();
    
    m_audioStartButton->setEnabled(!audioRecording && m_audioEnableCheck->isChecked());
    m_audioStopButton->setEnabled(audioCapturing);
    
    if (audioRecording) {
        m_audioStartButton->setText("音频录制中");
        m_audioStopButton->setText("停止音频");
    } else if (audioCapturing) {
        m_audioStartButton->setText("启动音频");
        m_audioStopButton->setText("停止音频");
    } else {
        m_audioStartButton->setText("启动音频");
        m_audioStopButton->setText("停止音频");
    }
    
    // 更新视频按钮状态
    bool videoRecording = m_recorder->isVideoRecording();
    bool videoCapturing = m_recorder->isVideoCapturing();
    
    m_videoCaptureButton->setEnabled(!videoRecording && m_videoEnableCheck->isChecked());
    m_videoStopButton->setEnabled(videoCapturing);
    
    if (videoRecording) {
        m_videoCaptureButton->setText("视频录制中");
        m_videoStopButton->setText("停止视频");
    } else if (videoCapturing) {
        m_videoCaptureButton->setText("启动视频");
        m_videoStopButton->setText("停止视频");
    } else {
        m_videoCaptureButton->setText("启动视频");
        m_videoStopButton->setText("停止视频");
    }
}

void RecorderMainWidget::resetRecorderForRestart() {
    AV_LOGGER_INFO("Resetting recorder for restart");
    
    // 确保录制器处于正确的状态
    if (m_recorder) {
        // 强制停止录制器（如果还在运行）
        m_recorder->close();
        
        // 重新创建录制器实例
        m_recorder = utils::createAVRecorder();
        if (!m_recorder) {
            AV_LOGGER_ERROR("Failed to recreate recorder");
            QMessageBox::critical(this, "错误", "重新创建录制器失败");
            return;
        }
    }
    
    // 重置UI状态
    m_isRecording = false;
    m_isPaused = false;
    m_isPreviewActive = false;
    m_recordDuration = 0;
    
    // 更新UI
    updateUIState();
    m_statusLabel->setText("就绪");
    
    AV_LOGGER_INFO("Recorder reset completed");
}

// #include "recorder_main_widget.moc"
